1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2024 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
23 /* See Fibre Channel protocol T11 FC-LS for details */
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
28 #include <linux/delay.h>
30 #include <scsi/scsi.h>
31 #include <scsi/scsi_device.h>
32 #include <scsi/scsi_host.h>
33 #include <scsi/scsi_transport_fc.h>
34 #include <uapi/scsi/fc/fc_fs.h>
35 #include <uapi/scsi/fc/fc_els.h>
40 #include "lpfc_sli4.h"
42 #include "lpfc_disc.h"
43 #include "lpfc_scsi.h"
45 #include "lpfc_logmsg.h"
46 #include "lpfc_crtn.h"
47 #include "lpfc_vport.h"
48 #include "lpfc_debugfs.h"
50 static int lpfc_els_retry(struct lpfc_hba
*, struct lpfc_iocbq
*,
52 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba
*, struct lpfc_iocbq
*,
54 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
);
55 static int lpfc_issue_els_fdisc(struct lpfc_vport
*vport
,
56 struct lpfc_nodelist
*ndlp
, uint8_t retry
);
57 static int lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
,
58 struct lpfc_iocbq
*iocb
);
59 static void lpfc_cmpl_els_edc(struct lpfc_hba
*phba
,
60 struct lpfc_iocbq
*cmdiocb
,
61 struct lpfc_iocbq
*rspiocb
);
62 static void lpfc_cmpl_els_uvem(struct lpfc_hba
*, struct lpfc_iocbq
*,
65 static int lpfc_max_els_tries
= 3;
67 static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport
*vport
);
68 static void lpfc_vmid_set_cs_ctl_range(struct lpfc_vport
*vport
, u32 min
, u32 max
);
69 static void lpfc_vmid_put_cs_ctl(struct lpfc_vport
*vport
, u32 ctcl_vmid
);
72 * lpfc_els_chk_latt - Check host link attention event for a vport
73 * @vport: pointer to a host virtual N_Port data structure.
75 * This routine checks whether there is an outstanding host link
76 * attention event during the discovery process with the @vport. It is done
77 * by reading the HBA's Host Attention (HA) register. If there is any host
78 * link attention events during this @vport's discovery process, the @vport
79 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
80 * be issued if the link state is not already in host link cleared state,
81 * and a return code shall indicate whether the host link attention event
84 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
85 * state in LPFC_VPORT_READY, the request for checking host link attention
86 * event will be ignored and a return code shall indicate no host link
87 * attention event had happened.
90 * 0 - no host link attention event happened
91 * 1 - host link attention event happened
94 lpfc_els_chk_latt(struct lpfc_vport
*vport
)
96 struct lpfc_hba
*phba
= vport
->phba
;
99 if (vport
->port_state
>= LPFC_VPORT_READY
||
100 phba
->link_state
== LPFC_LINK_DOWN
||
101 phba
->sli_rev
> LPFC_SLI_REV3
)
104 /* Read the HBA Host Attention Register */
105 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
108 if (!(ha_copy
& HA_LATT
))
111 /* Pending Link Event during Discovery */
112 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
113 "0237 Pending Link Event during "
114 "Discovery: State x%x\n",
115 phba
->pport
->port_state
);
117 /* CLEAR_LA should re-enable link attention events and
118 * we should then immediately take a LATT event. The
119 * LATT processing should call lpfc_linkdown() which
120 * will cleanup any left over in-progress discovery
123 set_bit(FC_ABORT_DISCOVERY
, &vport
->fc_flag
);
125 if (phba
->link_state
!= LPFC_CLEAR_LA
)
126 lpfc_issue_clear_la(phba
, vport
);
131 static bool lpfc_is_els_acc_rsp(struct lpfc_dmabuf
*buf
)
133 struct fc_els_ls_acc
*rsp
= buf
->virt
;
135 if (rsp
&& rsp
->la_cmd
== ELS_LS_ACC
)
141 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
142 * @vport: pointer to a host virtual N_Port data structure.
143 * @expect_rsp: flag indicating whether response is expected.
144 * @cmd_size: size of the ELS command.
145 * @retry: number of retries to the command when it fails.
146 * @ndlp: pointer to a node-list data structure.
147 * @did: destination identifier.
148 * @elscmd: the ELS command code.
150 * This routine is used for allocating a lpfc-IOCB data structure from
151 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
152 * passed into the routine for discovery state machine to issue an Extended
153 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
154 * and preparation routine that is used by all the discovery state machine
155 * routines and the ELS command-specific fields will be later set up by
156 * the individual discovery machine routines after calling this routine
157 * allocating and preparing a generic IOCB data structure. It fills in the
158 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
159 * payload and response payload (if expected). The reference count on the
160 * ndlp is incremented by 1 and the reference to the ndlp is put into
161 * ndlp of the IOCB data structure for this IOCB to hold the ndlp
162 * reference for the command's callback function to access later.
165 * Pointer to the newly allocated/prepared els iocb data structure
166 * NULL - when els iocb data structure allocation/preparation failed
169 lpfc_prep_els_iocb(struct lpfc_vport
*vport
, u8 expect_rsp
,
170 u16 cmd_size
, u8 retry
,
171 struct lpfc_nodelist
*ndlp
, u32 did
,
174 struct lpfc_hba
*phba
= vport
->phba
;
175 struct lpfc_iocbq
*elsiocb
;
176 struct lpfc_dmabuf
*pcmd
, *prsp
, *pbuflist
, *bmp
;
177 struct ulp_bde64_le
*bpl
;
180 if (!lpfc_is_link_up(phba
))
183 /* Allocate buffer for command iocb */
184 elsiocb
= lpfc_sli_get_iocbq(phba
);
189 * If this command is for fabric controller and HBA running
190 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
192 if (did
== Fabric_DID
&&
193 test_bit(HBA_FIP_SUPPORT
, &phba
->hba_flag
) &&
194 (elscmd
== ELS_CMD_FLOGI
||
195 elscmd
== ELS_CMD_FDISC
||
196 elscmd
== ELS_CMD_LOGO
))
200 ((LPFC_ELS_ID_FLOGI
<< LPFC_FIP_ELS_ID_SHIFT
)
201 & LPFC_FIP_ELS_ID_MASK
);
205 ((LPFC_ELS_ID_FDISC
<< LPFC_FIP_ELS_ID_SHIFT
)
206 & LPFC_FIP_ELS_ID_MASK
);
210 ((LPFC_ELS_ID_LOGO
<< LPFC_FIP_ELS_ID_SHIFT
)
211 & LPFC_FIP_ELS_ID_MASK
);
215 elsiocb
->cmd_flag
&= ~LPFC_FIP_ELS_ID_MASK
;
217 /* fill in BDEs for command */
218 /* Allocate buffer for command payload */
219 pcmd
= kmalloc(sizeof(*pcmd
), GFP_KERNEL
);
221 pcmd
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &pcmd
->phys
);
222 if (!pcmd
|| !pcmd
->virt
)
223 goto els_iocb_free_pcmb_exit
;
225 INIT_LIST_HEAD(&pcmd
->list
);
227 /* Allocate buffer for response payload */
229 prsp
= kmalloc(sizeof(*prsp
), GFP_KERNEL
);
231 prsp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
233 if (!prsp
|| !prsp
->virt
)
234 goto els_iocb_free_prsp_exit
;
235 INIT_LIST_HEAD(&prsp
->list
);
240 /* Allocate buffer for Buffer ptr list */
241 pbuflist
= kmalloc(sizeof(*pbuflist
), GFP_KERNEL
);
243 pbuflist
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
245 if (!pbuflist
|| !pbuflist
->virt
)
246 goto els_iocb_free_pbuf_exit
;
248 INIT_LIST_HEAD(&pbuflist
->list
);
253 timeout
= FF_DEF_RATOV
* 2;
256 timeout
= phba
->fc_ratov
;
259 timeout
= phba
->fc_ratov
* 2;
262 /* Fill SGE for the num bde count */
263 elsiocb
->num_bdes
= 2;
266 if (phba
->sli_rev
== LPFC_SLI_REV4
)
271 lpfc_sli_prep_els_req_rsp(phba
, elsiocb
, vport
, bmp
, cmd_size
, did
,
272 elscmd
, timeout
, expect_rsp
);
274 bpl
= (struct ulp_bde64_le
*)pbuflist
->virt
;
275 bpl
->addr_low
= cpu_to_le32(putPaddrLow(pcmd
->phys
));
276 bpl
->addr_high
= cpu_to_le32(putPaddrHigh(pcmd
->phys
));
277 bpl
->type_size
= cpu_to_le32(cmd_size
);
278 bpl
->type_size
|= cpu_to_le32(ULP_BDE64_TYPE_BDE_64
);
282 bpl
->addr_low
= cpu_to_le32(putPaddrLow(prsp
->phys
));
283 bpl
->addr_high
= cpu_to_le32(putPaddrHigh(prsp
->phys
));
284 bpl
->type_size
= cpu_to_le32(FCELSSIZE
);
285 bpl
->type_size
|= cpu_to_le32(ULP_BDE64_TYPE_BDE_64
);
288 elsiocb
->cmd_dmabuf
= pcmd
;
289 elsiocb
->bpl_dmabuf
= pbuflist
;
290 elsiocb
->retry
= retry
;
291 elsiocb
->vport
= vport
;
292 elsiocb
->drvrTimeout
= (phba
->fc_ratov
<< 1) + LPFC_DRVR_TIMEOUT
;
295 list_add(&prsp
->list
, &pcmd
->list
);
297 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
298 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
299 "0116 Xmit ELS command x%x to remote "
300 "NPORT x%x I/O tag: x%x, port state:x%x "
301 "rpi x%x fc_flag:x%lx\n",
302 elscmd
, did
, elsiocb
->iotag
,
303 vport
->port_state
, ndlp
->nlp_rpi
,
306 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
307 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
308 "0117 Xmit ELS response x%x to remote "
309 "NPORT x%x I/O tag: x%x, size: x%x "
310 "port_state x%x rpi x%x fc_flag x%lx\n",
311 elscmd
, ndlp
->nlp_DID
, elsiocb
->iotag
,
312 cmd_size
, vport
->port_state
,
313 ndlp
->nlp_rpi
, vport
->fc_flag
);
318 els_iocb_free_pbuf_exit
:
320 lpfc_mbuf_free(phba
, prsp
->virt
, prsp
->phys
);
323 els_iocb_free_prsp_exit
:
324 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
327 els_iocb_free_pcmb_exit
:
329 lpfc_sli_release_iocbq(phba
, elsiocb
);
334 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
335 * @vport: pointer to a host virtual N_Port data structure.
337 * This routine issues a fabric registration login for a @vport. An
338 * active ndlp node with Fabric_DID must already exist for this @vport.
339 * The routine invokes two mailbox commands to carry out fabric registration
340 * login through the HBA firmware: the first mailbox command requests the
341 * HBA to perform link configuration for the @vport; and the second mailbox
342 * command requests the HBA to perform the actual fabric registration login
346 * 0 - successfully issued fabric registration login for @vport
347 * -ENXIO -- failed to issue fabric registration login for @vport
350 lpfc_issue_fabric_reglogin(struct lpfc_vport
*vport
)
352 struct lpfc_hba
*phba
= vport
->phba
;
354 struct lpfc_nodelist
*ndlp
;
355 struct serv_parm
*sp
;
359 sp
= &phba
->fc_fabparam
;
360 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
366 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
372 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
373 lpfc_config_link(phba
, mbox
);
374 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
377 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
378 if (rc
== MBX_NOT_FINISHED
) {
383 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
388 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, Fabric_DID
, (uint8_t *)sp
, mbox
,
395 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fabric_reg_login
;
397 /* increment the reference count on ndlp to hold reference
398 * for the callback routine.
400 mbox
->ctx_ndlp
= lpfc_nlp_get(ndlp
);
401 if (!mbox
->ctx_ndlp
) {
406 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
407 if (rc
== MBX_NOT_FINISHED
) {
409 goto fail_issue_reg_login
;
414 fail_issue_reg_login
:
415 /* decrement the reference count on ndlp just incremented
416 * for the failed mbox command.
420 lpfc_mbox_rsrc_cleanup(phba
, mbox
, MBOX_THD_UNLOCKED
);
422 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
423 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
424 "0249 Cannot issue Register Fabric login: Err %d\n",
430 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
431 * @vport: pointer to a host virtual N_Port data structure.
433 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
434 * the @vport. This mailbox command is necessary for SLI4 port only.
437 * 0 - successfully issued REG_VFI for @vport
438 * A failure code otherwise.
441 lpfc_issue_reg_vfi(struct lpfc_vport
*vport
)
443 struct lpfc_hba
*phba
= vport
->phba
;
444 LPFC_MBOXQ_t
*mboxq
= NULL
;
445 struct lpfc_nodelist
*ndlp
;
446 struct lpfc_dmabuf
*dmabuf
= NULL
;
449 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
450 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
451 !(phba
->link_flag
& LS_LOOPBACK_MODE
) &&
452 !test_bit(FC_PT2PT
, &vport
->fc_flag
)) {
453 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
460 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
466 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
467 if (test_bit(FC_FABRIC
, &vport
->fc_flag
) ||
468 test_bit(FC_PT2PT
, &vport
->fc_flag
)) {
469 rc
= lpfc_mbox_rsrc_prep(phba
, mboxq
);
474 dmabuf
= mboxq
->ctx_buf
;
475 memcpy(dmabuf
->virt
, &phba
->fc_fabparam
,
476 sizeof(struct serv_parm
));
479 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
481 lpfc_reg_vfi(mboxq
, vport
, dmabuf
->phys
);
482 /* lpfc_reg_vfi memsets the mailbox. Restore the ctx_buf. */
483 mboxq
->ctx_buf
= dmabuf
;
485 lpfc_reg_vfi(mboxq
, vport
, 0);
488 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vfi
;
489 mboxq
->vport
= vport
;
490 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
491 if (rc
== MBX_NOT_FINISHED
) {
498 lpfc_mbox_rsrc_cleanup(phba
, mboxq
, MBOX_THD_UNLOCKED
);
500 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
501 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
502 "0289 Issue Register VFI failed: Err %d\n", rc
);
507 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
508 * @vport: pointer to a host virtual N_Port data structure.
510 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
511 * the @vport. This mailbox command is necessary for SLI4 port only.
514 * 0 - successfully issued REG_VFI for @vport
515 * A failure code otherwise.
518 lpfc_issue_unreg_vfi(struct lpfc_vport
*vport
)
520 struct lpfc_hba
*phba
= vport
->phba
;
524 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
526 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
527 "2556 UNREG_VFI mbox allocation failed"
528 "HBA state x%x\n", phba
->pport
->port_state
);
532 lpfc_unreg_vfi(mboxq
, vport
);
533 mboxq
->vport
= vport
;
534 mboxq
->mbox_cmpl
= lpfc_unregister_vfi_cmpl
;
536 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
537 if (rc
== MBX_NOT_FINISHED
) {
538 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
539 "2557 UNREG_VFI issue mbox failed rc x%x "
541 rc
, phba
->pport
->port_state
);
542 mempool_free(mboxq
, phba
->mbox_mem_pool
);
546 clear_bit(FC_VFI_REGISTERED
, &vport
->fc_flag
);
551 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
552 * @vport: pointer to a host virtual N_Port data structure.
553 * @sp: pointer to service parameter data structure.
555 * This routine is called from FLOGI/FDISC completion handler functions.
556 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
557 * node nodename is changed in the completion service parameter else return
558 * 0. This function also set flag in the vport data structure to delay
559 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
560 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
561 * node nodename is changed in the completion service parameter.
564 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
565 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
569 lpfc_check_clean_addr_bit(struct lpfc_vport
*vport
,
570 struct serv_parm
*sp
)
572 struct lpfc_hba
*phba
= vport
->phba
;
573 uint8_t fabric_param_changed
= 0;
575 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) ||
576 memcmp(&vport
->fabric_portname
, &sp
->portName
,
577 sizeof(struct lpfc_name
)) ||
578 memcmp(&vport
->fabric_nodename
, &sp
->nodeName
,
579 sizeof(struct lpfc_name
)) ||
580 (vport
->vport_flag
& FAWWPN_PARAM_CHG
)) {
581 fabric_param_changed
= 1;
582 vport
->vport_flag
&= ~FAWWPN_PARAM_CHG
;
585 * Word 1 Bit 31 in common service parameter is overloaded.
586 * Word 1 Bit 31 in FLOGI request is multiple NPort request
587 * Word 1 Bit 31 in FLOGI response is clean address bit
589 * If fabric parameter is changed and clean address bit is
590 * cleared delay nport discovery if
591 * - vport->fc_prevDID != 0 (not initial discovery) OR
592 * - lpfc_delay_discovery module parameter is set.
594 if (fabric_param_changed
&& !sp
->cmn
.clean_address_bit
&&
595 (vport
->fc_prevDID
|| phba
->cfg_delay_discovery
))
596 set_bit(FC_DISC_DELAYED
, &vport
->fc_flag
);
598 return fabric_param_changed
;
603 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
604 * @vport: pointer to a host virtual N_Port data structure.
605 * @ndlp: pointer to a node-list data structure.
606 * @sp: pointer to service parameter data structure.
607 * @ulp_word4: command response value
609 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
610 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
611 * port in a fabric topology. It properly sets up the parameters to the @ndlp
612 * from the IOCB response. It also check the newly assigned N_Port ID to the
613 * @vport against the previously assigned N_Port ID. If it is different from
614 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
615 * is invoked on all the remaining nodes with the @vport to unregister the
616 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
617 * is invoked to register login to the fabric.
620 * 0 - Success (currently, always return 0)
623 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
624 struct serv_parm
*sp
, uint32_t ulp_word4
)
626 struct lpfc_hba
*phba
= vport
->phba
;
627 struct lpfc_nodelist
*np
;
628 struct lpfc_nodelist
*next_np
;
629 uint8_t fabric_param_changed
;
631 set_bit(FC_FABRIC
, &vport
->fc_flag
);
633 phba
->fc_edtov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
634 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
635 phba
->fc_edtov
= (phba
->fc_edtov
+ 999999) / 1000000;
637 phba
->fc_edtovResol
= sp
->cmn
.edtovResolution
;
638 phba
->fc_ratov
= (be32_to_cpu(sp
->cmn
.w2
.r_a_tov
) + 999) / 1000;
640 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
)
641 set_bit(FC_PUBLIC_LOOP
, &vport
->fc_flag
);
643 vport
->fc_myDID
= ulp_word4
& Mask_DID
;
644 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof(struct lpfc_name
));
645 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof(struct lpfc_name
));
646 ndlp
->nlp_class_sup
= 0;
647 if (sp
->cls1
.classValid
)
648 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
649 if (sp
->cls2
.classValid
)
650 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
651 if (sp
->cls3
.classValid
)
652 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
653 if (sp
->cls4
.classValid
)
654 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
655 ndlp
->nlp_maxframe
= ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
656 sp
->cmn
.bbRcvSizeLsb
;
658 fabric_param_changed
= lpfc_check_clean_addr_bit(vport
, sp
);
659 if (fabric_param_changed
) {
660 /* Reset FDMI attribute masks based on config parameter */
661 if (phba
->cfg_enable_SmartSAN
||
662 (phba
->cfg_fdmi_on
== LPFC_FDMI_SUPPORT
)) {
663 /* Setup appropriate attribute masks */
664 vport
->fdmi_hba_mask
= LPFC_FDMI2_HBA_ATTR
;
665 if (phba
->cfg_enable_SmartSAN
)
666 vport
->fdmi_port_mask
= LPFC_FDMI2_SMART_ATTR
;
668 vport
->fdmi_port_mask
= LPFC_FDMI2_PORT_ATTR
;
670 vport
->fdmi_hba_mask
= 0;
671 vport
->fdmi_port_mask
= 0;
675 memcpy(&vport
->fabric_portname
, &sp
->portName
,
676 sizeof(struct lpfc_name
));
677 memcpy(&vport
->fabric_nodename
, &sp
->nodeName
,
678 sizeof(struct lpfc_name
));
679 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
681 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
682 if (sp
->cmn
.response_multiple_NPort
) {
683 lpfc_printf_vlog(vport
, KERN_WARNING
,
685 "1816 FLOGI NPIV supported, "
686 "response data 0x%x\n",
687 sp
->cmn
.response_multiple_NPort
);
688 spin_lock_irq(&phba
->hbalock
);
689 phba
->link_flag
|= LS_NPIV_FAB_SUPPORTED
;
690 spin_unlock_irq(&phba
->hbalock
);
692 /* Because we asked f/w for NPIV it still expects us
693 to call reg_vnpid at least for the physical host */
694 lpfc_printf_vlog(vport
, KERN_WARNING
,
696 "1817 Fabric does not support NPIV "
697 "- configuring single port mode.\n");
698 spin_lock_irq(&phba
->hbalock
);
699 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
700 spin_unlock_irq(&phba
->hbalock
);
705 * For FC we need to do some special processing because of the SLI
706 * Port's default settings of the Common Service Parameters.
708 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
709 (phba
->sli4_hba
.lnk_info
.lnk_tp
== LPFC_LNK_TYPE_FC
)) {
710 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
711 if (fabric_param_changed
)
712 lpfc_unregister_fcf_prep(phba
);
714 /* This should just update the VFI CSPs*/
715 if (test_bit(FC_VFI_REGISTERED
, &vport
->fc_flag
))
716 lpfc_issue_reg_vfi(vport
);
719 if (fabric_param_changed
&&
720 !test_bit(FC_VPORT_NEEDS_REG_VPI
, &vport
->fc_flag
)) {
722 /* If our NportID changed, we need to ensure all
723 * remaining NPORTs get unreg_login'ed.
725 list_for_each_entry_safe(np
, next_np
,
726 &vport
->fc_nodes
, nlp_listp
) {
727 if ((np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
728 !(np
->nlp_flag
& NLP_NPR_ADISC
))
730 spin_lock_irq(&np
->lock
);
731 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
732 spin_unlock_irq(&np
->lock
);
733 lpfc_unreg_rpi(vport
, np
);
735 lpfc_cleanup_pending_mbox(vport
);
737 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
738 lpfc_sli4_unreg_all_rpis(vport
);
739 lpfc_mbx_unreg_vpi(vport
);
740 set_bit(FC_VPORT_NEEDS_INIT_VPI
, &vport
->fc_flag
);
744 * For SLI3 and SLI4, the VPI needs to be reregistered in
745 * response to this fabric parameter change event.
747 set_bit(FC_VPORT_NEEDS_REG_VPI
, &vport
->fc_flag
);
748 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
749 !test_bit(FC_VPORT_NEEDS_REG_VPI
, &vport
->fc_flag
)) {
751 * Driver needs to re-reg VPI in order for f/w
752 * to update the MAC address.
754 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
755 lpfc_register_new_vport(phba
, vport
, ndlp
);
759 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
760 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_REG_LOGIN_ISSUE
);
761 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
&&
762 test_bit(FC_VPORT_NEEDS_REG_VPI
, &vport
->fc_flag
))
763 lpfc_register_new_vport(phba
, vport
, ndlp
);
765 lpfc_issue_fabric_reglogin(vport
);
767 ndlp
->nlp_type
|= NLP_FABRIC
;
768 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
769 if ((!test_bit(FC_VPORT_NEEDS_REG_VPI
, &vport
->fc_flag
)) &&
770 (vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
771 lpfc_start_fdiscs(phba
);
772 lpfc_do_scr_ns_plogi(phba
, vport
);
773 } else if (test_bit(FC_VFI_REGISTERED
, &vport
->fc_flag
))
774 lpfc_issue_init_vpi(vport
);
776 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
777 "3135 Need register VFI: (x%x/%x)\n",
778 vport
->fc_prevDID
, vport
->fc_myDID
);
779 lpfc_issue_reg_vfi(vport
);
786 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
787 * @vport: pointer to a host virtual N_Port data structure.
788 * @ndlp: pointer to a node-list data structure.
789 * @sp: pointer to service parameter data structure.
791 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
792 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
793 * in a point-to-point topology. First, the @vport's N_Port Name is compared
794 * with the received N_Port Name: if the @vport's N_Port Name is greater than
795 * the received N_Port Name lexicographically, this node shall assign local
796 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
797 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
798 * this node shall just wait for the remote node to issue PLOGI and assign
806 lpfc_cmpl_els_flogi_nport(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
807 struct serv_parm
*sp
)
809 struct lpfc_hba
*phba
= vport
->phba
;
813 clear_bit(FC_FABRIC
, &vport
->fc_flag
);
814 clear_bit(FC_PUBLIC_LOOP
, &vport
->fc_flag
);
815 set_bit(FC_PT2PT
, &vport
->fc_flag
);
817 /* If we are pt2pt with another NPort, force NPIV off! */
818 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
820 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
821 if ((phba
->sli_rev
== LPFC_SLI_REV4
) && phba
->fc_topology_changed
) {
822 lpfc_unregister_fcf_prep(phba
);
823 clear_bit(FC_VFI_REGISTERED
, &vport
->fc_flag
);
824 phba
->fc_topology_changed
= 0;
827 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
828 sizeof(vport
->fc_portname
));
831 /* This side will initiate the PLOGI */
832 set_bit(FC_PT2PT_PLOGI
, &vport
->fc_flag
);
835 * N_Port ID cannot be 0, set our Id to LocalID
836 * the other side will be RemoteID.
841 vport
->fc_myDID
= PT2PT_LocalID
;
843 /* If not registered with a transport, decrement ndlp reference
844 * count indicating that ndlp can be safely released when other
845 * references are removed.
847 if (!(ndlp
->fc4_xpt_flags
& (SCSI_XPT_REGD
| NVME_XPT_REGD
)))
850 ndlp
= lpfc_findnode_did(vport
, PT2PT_RemoteID
);
853 * Cannot find existing Fabric ndlp, so allocate a
856 ndlp
= lpfc_nlp_init(vport
, PT2PT_RemoteID
);
861 memcpy(&ndlp
->nlp_portname
, &sp
->portName
,
862 sizeof(struct lpfc_name
));
863 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
,
864 sizeof(struct lpfc_name
));
865 /* Set state will put ndlp onto node list if not already done */
866 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
867 spin_lock_irq(&ndlp
->lock
);
868 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
869 spin_unlock_irq(&ndlp
->lock
);
871 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
875 lpfc_config_link(phba
, mbox
);
877 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_local_config_link
;
879 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
880 if (rc
== MBX_NOT_FINISHED
) {
881 mempool_free(mbox
, phba
->mbox_mem_pool
);
885 /* This side will wait for the PLOGI. If not registered with
886 * a transport, decrement node reference count indicating that
887 * ndlp can be released when other references are removed.
889 if (!(ndlp
->fc4_xpt_flags
& (SCSI_XPT_REGD
| NVME_XPT_REGD
)))
892 /* Start discovery - this should just do CLEAR_LA */
893 lpfc_disc_start(vport
);
902 * lpfc_cmpl_els_flogi - Completion callback function for flogi
903 * @phba: pointer to lpfc hba data structure.
904 * @cmdiocb: pointer to lpfc command iocb data structure.
905 * @rspiocb: pointer to lpfc response iocb data structure.
907 * This routine is the top-level completion callback function for issuing
908 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
909 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
910 * retry has been made (either immediately or delayed with lpfc_els_retry()
911 * returning 1), the command IOCB will be released and function returned.
912 * If the retry attempt has been given up (possibly reach the maximum
913 * number of retries), one additional decrement of ndlp reference shall be
914 * invoked before going out after releasing the command IOCB. This will
915 * actually release the remote node (Note, lpfc_els_free_iocb() will also
916 * invoke one decrement of ndlp reference count). If no error reported in
917 * the IOCB status, the command Port ID field is used to determine whether
918 * this is a point-to-point topology or a fabric topology: if the Port ID
919 * field is assigned, it is a fabric topology; otherwise, it is a
920 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
921 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
922 * specific topology completion conditions.
925 lpfc_cmpl_els_flogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
926 struct lpfc_iocbq
*rspiocb
)
928 struct lpfc_vport
*vport
= cmdiocb
->vport
;
929 struct lpfc_nodelist
*ndlp
= cmdiocb
->ndlp
;
931 struct lpfc_dmabuf
*pcmd
= cmdiocb
->cmd_dmabuf
, *prsp
;
932 struct serv_parm
*sp
;
935 u32 ulp_status
, ulp_word4
, tmo
;
936 bool flogi_in_retry
= false;
938 /* Check to see if link went down during discovery */
939 if (lpfc_els_chk_latt(vport
)) {
940 /* One additional decrement on node reference count to
941 * trigger the release of the node
943 if (!(ndlp
->fc4_xpt_flags
& SCSI_XPT_REGD
))
948 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
949 ulp_word4
= get_job_word4(phba
, rspiocb
);
951 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
952 tmo
= get_wqe_tmo(cmdiocb
);
954 irsp
= &rspiocb
->iocb
;
955 tmo
= irsp
->ulpTimeout
;
958 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
959 "FLOGI cmpl: status:x%x/x%x state:x%x",
960 ulp_status
, ulp_word4
,
965 * In case of FIP mode, perform roundrobin FCF failover
966 * due to new FCF discovery
968 if (test_bit(HBA_FIP_SUPPORT
, &phba
->hba_flag
) &&
969 (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
)) {
970 if (phba
->link_state
< LPFC_LINK_UP
)
971 goto stop_rr_fcf_flogi
;
972 if ((phba
->fcoe_cvl_eventtag_attn
==
973 phba
->fcoe_cvl_eventtag
) &&
974 (ulp_status
== IOSTAT_LOCAL_REJECT
) &&
975 ((ulp_word4
& IOERR_PARAM_MASK
) ==
977 goto stop_rr_fcf_flogi
;
979 phba
->fcoe_cvl_eventtag_attn
=
980 phba
->fcoe_cvl_eventtag
;
981 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
| LOG_ELS
,
982 "2611 FLOGI FCF (x%x), "
983 "status:x%x/x%x, tmo:x%x, perform "
984 "roundrobin FCF failover\n",
985 phba
->fcf
.current_rec
.fcf_indx
,
986 ulp_status
, ulp_word4
, tmo
);
987 lpfc_sli4_set_fcf_flogi_fail(phba
,
988 phba
->fcf
.current_rec
.fcf_indx
);
989 fcf_index
= lpfc_sli4_fcf_rr_next_index_get(phba
);
990 rc
= lpfc_sli4_fcf_rr_next_proc(vport
, fcf_index
);
997 if (!(ulp_status
== IOSTAT_LOCAL_REJECT
&&
998 ((ulp_word4
& IOERR_PARAM_MASK
) ==
999 IOERR_LOOP_OPEN_FAILURE
)))
1000 lpfc_vlog_msg(vport
, KERN_WARNING
, LOG_ELS
,
1001 "2858 FLOGI Status:x%x/x%x TMO"
1002 ":x%x Data x%lx x%x\n",
1003 ulp_status
, ulp_word4
, tmo
,
1004 phba
->hba_flag
, phba
->fcf
.fcf_flag
);
1006 /* Check for retry */
1007 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1008 /* Address a timing race with dev_loss. If dev_loss
1009 * is active on this FPort node, put the initial ref
1010 * count back to stop premature node release actions.
1012 lpfc_check_nlp_post_devloss(vport
, ndlp
);
1013 flogi_in_retry
= true;
1017 /* The FLOGI will not be retried. If the FPort node is not
1018 * registered with the SCSI transport, remove the initial
1019 * reference to trigger node release.
1021 if (!(ndlp
->nlp_flag
& NLP_IN_DEV_LOSS
) &&
1022 !(ndlp
->fc4_xpt_flags
& SCSI_XPT_REGD
))
1025 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
1026 "0150 FLOGI Status:x%x/x%x "
1027 "xri x%x TMO:x%x refcnt %d\n",
1028 ulp_status
, ulp_word4
, cmdiocb
->sli4_xritag
,
1029 tmo
, kref_read(&ndlp
->kref
));
1031 /* If this is not a loop open failure, bail out */
1032 if (!(ulp_status
== IOSTAT_LOCAL_REJECT
&&
1033 ((ulp_word4
& IOERR_PARAM_MASK
) ==
1034 IOERR_LOOP_OPEN_FAILURE
))) {
1035 /* Warn FLOGI status */
1036 lpfc_vlog_msg(vport
, KERN_WARNING
, LOG_ELS
,
1037 "0100 FLOGI Status:x%x/x%x "
1039 ulp_status
, ulp_word4
, tmo
);
1043 /* FLOGI failed, so there is no fabric */
1044 clear_bit(FC_FABRIC
, &vport
->fc_flag
);
1045 clear_bit(FC_PUBLIC_LOOP
, &vport
->fc_flag
);
1046 clear_bit(FC_PT2PT_NO_NVME
, &vport
->fc_flag
);
1048 /* If private loop, then allow max outstanding els to be
1049 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1050 * alpa map would take too long otherwise.
1052 if (phba
->alpa_map
[0] == 0)
1053 vport
->cfg_discovery_threads
= LPFC_MAX_DISC_THREADS
;
1054 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
1055 (!test_bit(FC_VFI_REGISTERED
, &vport
->fc_flag
) ||
1056 (vport
->fc_prevDID
!= vport
->fc_myDID
) ||
1057 phba
->fc_topology_changed
)) {
1058 if (test_bit(FC_VFI_REGISTERED
, &vport
->fc_flag
)) {
1059 if (phba
->fc_topology_changed
) {
1060 lpfc_unregister_fcf_prep(phba
);
1061 clear_bit(FC_VFI_REGISTERED
,
1063 phba
->fc_topology_changed
= 0;
1065 lpfc_sli4_unreg_all_rpis(vport
);
1069 /* Do not register VFI if the driver aborted FLOGI */
1070 if (!lpfc_error_lost_link(vport
, ulp_status
, ulp_word4
))
1071 lpfc_issue_reg_vfi(vport
);
1077 clear_bit(FC_VPORT_CVL_RCVD
, &vport
->fc_flag
);
1078 clear_bit(FC_VPORT_LOGO_RCVD
, &vport
->fc_flag
);
1081 * The FLOGI succeeded. Sync the data for the CPU before
1084 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
1087 if (!lpfc_is_els_acc_rsp(prsp
))
1089 sp
= prsp
->virt
+ sizeof(uint32_t);
1091 /* FLOGI completes successfully */
1092 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1093 "0101 FLOGI completes successfully, I/O tag:x%x "
1094 "xri x%x Data: x%x x%x x%x x%x x%x x%lx x%x %d\n",
1095 cmdiocb
->iotag
, cmdiocb
->sli4_xritag
,
1096 ulp_word4
, sp
->cmn
.e_d_tov
,
1097 sp
->cmn
.w2
.r_a_tov
, sp
->cmn
.edtovResolution
,
1098 vport
->port_state
, vport
->fc_flag
,
1099 sp
->cmn
.priority_tagging
, kref_read(&ndlp
->kref
));
1101 /* reinitialize the VMID datastructure before returning */
1102 if (lpfc_is_vmid_enabled(phba
)) {
1103 lpfc_reinit_vmid(vport
);
1104 vport
->vmid_flag
= 0;
1106 if (sp
->cmn
.priority_tagging
)
1107 vport
->phba
->pport
->vmid_flag
|= (LPFC_VMID_ISSUE_QFPA
|
1108 LPFC_VMID_TYPE_PRIO
);
1111 * Address a timing race with dev_loss. If dev_loss is active on
1112 * this FPort node, put the initial ref count back to stop premature
1113 * node release actions.
1115 lpfc_check_nlp_post_devloss(vport
, ndlp
);
1116 if (vport
->port_state
== LPFC_FLOGI
) {
1118 * If Common Service Parameters indicate Nport
1119 * we are point to point, if Fport we are Fabric.
1122 rc
= lpfc_cmpl_els_flogi_fabric(vport
, ndlp
, sp
,
1124 else if (!test_bit(HBA_FCOE_MODE
, &phba
->hba_flag
))
1125 rc
= lpfc_cmpl_els_flogi_nport(vport
, ndlp
, sp
);
1127 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1128 "2831 FLOGI response with cleared Fabric "
1129 "bit fcf_index 0x%x "
1130 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1132 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1133 phba
->fcf
.current_rec
.fcf_indx
,
1134 phba
->fcf
.current_rec
.switch_name
[0],
1135 phba
->fcf
.current_rec
.switch_name
[1],
1136 phba
->fcf
.current_rec
.switch_name
[2],
1137 phba
->fcf
.current_rec
.switch_name
[3],
1138 phba
->fcf
.current_rec
.switch_name
[4],
1139 phba
->fcf
.current_rec
.switch_name
[5],
1140 phba
->fcf
.current_rec
.switch_name
[6],
1141 phba
->fcf
.current_rec
.switch_name
[7],
1142 phba
->fcf
.current_rec
.fabric_name
[0],
1143 phba
->fcf
.current_rec
.fabric_name
[1],
1144 phba
->fcf
.current_rec
.fabric_name
[2],
1145 phba
->fcf
.current_rec
.fabric_name
[3],
1146 phba
->fcf
.current_rec
.fabric_name
[4],
1147 phba
->fcf
.current_rec
.fabric_name
[5],
1148 phba
->fcf
.current_rec
.fabric_name
[6],
1149 phba
->fcf
.current_rec
.fabric_name
[7]);
1152 spin_lock_irq(&phba
->hbalock
);
1153 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
1154 spin_unlock_irq(&phba
->hbalock
);
1155 clear_bit(FCF_RR_INPROG
, &phba
->hba_flag
);
1156 clear_bit(HBA_DEVLOSS_TMO
, &phba
->hba_flag
);
1157 phba
->fcf
.fcf_redisc_attempted
= 0; /* reset */
1161 /* Mark the FCF discovery process done */
1162 if (test_bit(HBA_FIP_SUPPORT
, &phba
->hba_flag
))
1163 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FIP
|
1165 "2769 FLOGI to FCF (x%x) "
1166 "completed successfully\n",
1167 phba
->fcf
.current_rec
.fcf_indx
);
1168 spin_lock_irq(&phba
->hbalock
);
1169 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
1170 spin_unlock_irq(&phba
->hbalock
);
1171 clear_bit(FCF_RR_INPROG
, &phba
->hba_flag
);
1172 clear_bit(HBA_DEVLOSS_TMO
, &phba
->hba_flag
);
1173 phba
->fcf
.fcf_redisc_attempted
= 0; /* reset */
1176 } else if (vport
->port_state
> LPFC_FLOGI
&&
1177 test_bit(FC_PT2PT
, &vport
->fc_flag
)) {
1179 * In a p2p topology, it is possible that discovery has
1180 * already progressed, and this completion can be ignored.
1181 * Recheck the indicated topology.
1188 spin_lock_irq(&phba
->hbalock
);
1189 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
1190 spin_unlock_irq(&phba
->hbalock
);
1192 if (!lpfc_error_lost_link(vport
, ulp_status
, ulp_word4
)) {
1193 /* FLOGI failed, so just use loop map to make discovery list */
1194 lpfc_disc_list_loopmap(vport
);
1196 /* Start discovery */
1197 lpfc_disc_start(vport
);
1198 } else if (((ulp_status
!= IOSTAT_LOCAL_REJECT
) ||
1199 (((ulp_word4
& IOERR_PARAM_MASK
) !=
1200 IOERR_SLI_ABORTED
) &&
1201 ((ulp_word4
& IOERR_PARAM_MASK
) !=
1202 IOERR_SLI_DOWN
))) &&
1203 (phba
->link_state
!= LPFC_CLEAR_LA
)) {
1204 /* If FLOGI failed enable link interrupt. */
1205 lpfc_issue_clear_la(phba
, vport
);
1208 if (!flogi_in_retry
)
1209 clear_bit(HBA_FLOGI_OUTSTANDING
, &phba
->hba_flag
);
1211 lpfc_els_free_iocb(phba
, cmdiocb
);
1216 * lpfc_cmpl_els_link_down - Completion callback function for ELS command
1217 * aborted during a link down
1218 * @phba: pointer to lpfc hba data structure.
1219 * @cmdiocb: pointer to lpfc command iocb data structure.
1220 * @rspiocb: pointer to lpfc response iocb data structure.
1224 lpfc_cmpl_els_link_down(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1225 struct lpfc_iocbq
*rspiocb
)
1229 u32 ulp_status
, ulp_word4
;
1231 pcmd
= (uint32_t *)cmdiocb
->cmd_dmabuf
->virt
;
1234 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
1235 ulp_word4
= get_job_word4(phba
, rspiocb
);
1237 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
1238 "6445 ELS completes after LINK_DOWN: "
1239 " Status %x/%x cmd x%x flg x%x\n",
1240 ulp_status
, ulp_word4
, cmd
,
1243 if (cmdiocb
->cmd_flag
& LPFC_IO_FABRIC
) {
1244 cmdiocb
->cmd_flag
&= ~LPFC_IO_FABRIC
;
1245 atomic_dec(&phba
->fabric_iocb_count
);
1247 lpfc_els_free_iocb(phba
, cmdiocb
);
1251 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1252 * @vport: pointer to a host virtual N_Port data structure.
1253 * @ndlp: pointer to a node-list data structure.
1254 * @retry: number of retries to the command IOCB.
1256 * This routine issues a Fabric Login (FLOGI) Request ELS command
1257 * for a @vport. The initiator service parameters are put into the payload
1258 * of the FLOGI Request IOCB and the top-level callback function pointer
1259 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1260 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1261 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1263 * Note that the ndlp reference count will be incremented by 1 for holding the
1264 * ndlp and the reference to ndlp will be stored into the ndlp field of
1265 * the IOCB for the completion callback function to the FLOGI ELS command.
1268 * 0 - successfully issued flogi iocb for @vport
1269 * 1 - failed to issue flogi iocb for @vport
1272 lpfc_issue_els_flogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1275 struct lpfc_hba
*phba
= vport
->phba
;
1276 struct serv_parm
*sp
;
1277 union lpfc_wqe128
*wqe
= NULL
;
1278 IOCB_t
*icmd
= NULL
;
1279 struct lpfc_iocbq
*elsiocb
;
1280 struct lpfc_iocbq defer_flogi_acc
;
1286 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1287 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1288 ndlp
->nlp_DID
, ELS_CMD_FLOGI
);
1293 wqe
= &elsiocb
->wqe
;
1294 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
1295 icmd
= &elsiocb
->iocb
;
1297 /* For FLOGI request, remainder of payload is service parameters */
1298 *((uint32_t *) (pcmd
)) = ELS_CMD_FLOGI
;
1299 pcmd
+= sizeof(uint32_t);
1300 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1301 sp
= (struct serv_parm
*) pcmd
;
1303 /* Setup CSPs accordingly for Fabric */
1304 sp
->cmn
.e_d_tov
= 0;
1305 sp
->cmn
.w2
.r_a_tov
= 0;
1306 sp
->cmn
.virtual_fabric_support
= 0;
1307 sp
->cls1
.classValid
= 0;
1308 if (sp
->cmn
.fcphLow
< FC_PH3
)
1309 sp
->cmn
.fcphLow
= FC_PH3
;
1310 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1311 sp
->cmn
.fcphHigh
= FC_PH3
;
1313 /* Determine if switch supports priority tagging */
1314 if (phba
->cfg_vmid_priority_tagging
) {
1315 sp
->cmn
.priority_tagging
= 1;
1316 /* lpfc_vmid_host_uuid is combination of wwpn and wwnn */
1317 if (!memchr_inv(vport
->lpfc_vmid_host_uuid
, 0,
1318 sizeof(vport
->lpfc_vmid_host_uuid
))) {
1319 memcpy(vport
->lpfc_vmid_host_uuid
, phba
->wwpn
,
1320 sizeof(phba
->wwpn
));
1321 memcpy(&vport
->lpfc_vmid_host_uuid
[8], phba
->wwnn
,
1322 sizeof(phba
->wwnn
));
1326 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1327 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
1328 LPFC_SLI_INTF_IF_TYPE_0
) {
1329 /* FLOGI needs to be 3 for WQE FCFI */
1331 bf_set(wqe_ct
, &wqe
->els_req
.wqe_com
, ct
);
1333 /* Set the fcfi to the fcfi we registered with */
1334 bf_set(wqe_ctxt_tag
, &wqe
->els_req
.wqe_com
,
1338 /* Can't do SLI4 class2 without support sequence coalescing */
1339 sp
->cls2
.classValid
= 0;
1340 sp
->cls2
.seqDelivery
= 0;
1342 /* Historical, setting sequential-delivery bit for SLI3 */
1343 sp
->cls2
.seqDelivery
= (sp
->cls2
.classValid
) ? 1 : 0;
1344 sp
->cls3
.seqDelivery
= (sp
->cls3
.classValid
) ? 1 : 0;
1345 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
1346 sp
->cmn
.request_multiple_Nport
= 1;
1347 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1351 sp
->cmn
.request_multiple_Nport
= 0;
1354 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) {
1355 icmd
->un
.elsreq64
.myID
= 0;
1356 icmd
->un
.elsreq64
.fl
= 1;
1360 tmo
= phba
->fc_ratov
;
1361 phba
->fc_ratov
= LPFC_DISC_FLOGI_TMO
;
1362 lpfc_set_disctmo(vport
);
1363 phba
->fc_ratov
= tmo
;
1365 phba
->fc_stat
.elsXmitFLOGI
++;
1366 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_flogi
;
1368 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1369 "Issue FLOGI: opt:x%x",
1370 phba
->sli3_options
, 0, 0);
1372 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
1373 if (!elsiocb
->ndlp
) {
1374 lpfc_els_free_iocb(phba
, elsiocb
);
1378 /* Avoid race with FLOGI completion and hba_flags. */
1379 set_bit(HBA_FLOGI_ISSUED
, &phba
->hba_flag
);
1380 set_bit(HBA_FLOGI_OUTSTANDING
, &phba
->hba_flag
);
1382 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
1383 if (rc
== IOCB_ERROR
) {
1384 clear_bit(HBA_FLOGI_ISSUED
, &phba
->hba_flag
);
1385 clear_bit(HBA_FLOGI_OUTSTANDING
, &phba
->hba_flag
);
1386 lpfc_els_free_iocb(phba
, elsiocb
);
1391 /* Clear external loopback plug detected flag */
1392 phba
->link_flag
&= ~LS_EXTERNAL_LOOPBACK
;
1394 /* Check for a deferred FLOGI ACC condition */
1395 if (phba
->defer_flogi_acc
.flag
) {
1396 /* lookup ndlp for received FLOGI */
1397 ndlp
= lpfc_findnode_did(vport
, 0);
1401 did
= vport
->fc_myDID
;
1402 vport
->fc_myDID
= Fabric_DID
;
1404 memset(&defer_flogi_acc
, 0, sizeof(struct lpfc_iocbq
));
1406 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1407 bf_set(wqe_ctxt_tag
,
1408 &defer_flogi_acc
.wqe
.xmit_els_rsp
.wqe_com
,
1409 phba
->defer_flogi_acc
.rx_id
);
1411 &defer_flogi_acc
.wqe
.xmit_els_rsp
.wqe_com
,
1412 phba
->defer_flogi_acc
.ox_id
);
1414 icmd
= &defer_flogi_acc
.iocb
;
1415 icmd
->ulpContext
= phba
->defer_flogi_acc
.rx_id
;
1416 icmd
->unsli3
.rcvsli3
.ox_id
=
1417 phba
->defer_flogi_acc
.ox_id
;
1420 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1421 "3354 Xmit deferred FLOGI ACC: rx_id: x%x,"
1422 " ox_id: x%x, hba_flag x%lx\n",
1423 phba
->defer_flogi_acc
.rx_id
,
1424 phba
->defer_flogi_acc
.ox_id
, phba
->hba_flag
);
1426 /* Send deferred FLOGI ACC */
1427 lpfc_els_rsp_acc(vport
, ELS_CMD_FLOGI
, &defer_flogi_acc
,
1430 phba
->defer_flogi_acc
.flag
= false;
1432 /* Decrement the held ndlp that was incremented when the
1433 * deferred flogi acc flag was set.
1435 if (phba
->defer_flogi_acc
.ndlp
) {
1436 lpfc_nlp_put(phba
->defer_flogi_acc
.ndlp
);
1437 phba
->defer_flogi_acc
.ndlp
= NULL
;
1440 vport
->fc_myDID
= did
;
1447 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1448 * @phba: pointer to lpfc hba data structure.
1450 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1451 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1452 * list and issues an abort IOCB commond on each outstanding IOCB that
1453 * contains a active Fabric_DID ndlp. Note that this function is to issue
1454 * the abort IOCB command on all the outstanding IOCBs, thus when this
1455 * function returns, it does not guarantee all the IOCBs are actually aborted.
1458 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1461 lpfc_els_abort_flogi(struct lpfc_hba
*phba
)
1463 struct lpfc_sli_ring
*pring
;
1464 struct lpfc_iocbq
*iocb
, *next_iocb
;
1465 struct lpfc_nodelist
*ndlp
;
1468 /* Abort outstanding I/O on NPort <nlp_DID> */
1469 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
1470 "0201 Abort outstanding I/O on NPort x%x\n",
1473 pring
= lpfc_phba_elsring(phba
);
1474 if (unlikely(!pring
))
1478 * Check the txcmplq for an iocb that matches the nport the driver is
1481 spin_lock_irq(&phba
->hbalock
);
1482 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
1483 ulp_command
= get_job_cmnd(phba
, iocb
);
1484 if (ulp_command
== CMD_ELS_REQUEST64_CR
) {
1486 if (ndlp
&& ndlp
->nlp_DID
== Fabric_DID
) {
1487 if (test_bit(FC_PT2PT
, &phba
->pport
->fc_flag
) &&
1488 !test_bit(FC_PT2PT_PLOGI
,
1489 &phba
->pport
->fc_flag
))
1490 iocb
->fabric_cmd_cmpl
=
1491 lpfc_ignore_els_cmpl
;
1492 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
,
1497 /* Make sure HBA is alive */
1498 lpfc_issue_hb_tmo(phba
);
1500 spin_unlock_irq(&phba
->hbalock
);
1506 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1507 * @vport: pointer to a host virtual N_Port data structure.
1509 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1510 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1511 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1512 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1513 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1514 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1518 * 0 - failed to issue initial flogi for @vport
1519 * 1 - successfully issued initial flogi for @vport
1522 lpfc_initial_flogi(struct lpfc_vport
*vport
)
1524 struct lpfc_nodelist
*ndlp
;
1526 vport
->port_state
= LPFC_FLOGI
;
1527 lpfc_set_disctmo(vport
);
1529 /* First look for the Fabric ndlp */
1530 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1532 /* Cannot find existing Fabric ndlp, so allocate a new one */
1533 ndlp
= lpfc_nlp_init(vport
, Fabric_DID
);
1536 /* Set the node type */
1537 ndlp
->nlp_type
|= NLP_FABRIC
;
1539 /* Put ndlp onto node list */
1540 lpfc_enqueue_node(vport
, ndlp
);
1543 /* Reset the Fabric flag, topology change may have happened */
1544 clear_bit(FC_FABRIC
, &vport
->fc_flag
);
1545 if (lpfc_issue_els_flogi(vport
, ndlp
, 0)) {
1546 /* A node reference should be retained while registered with a
1547 * transport or dev-loss-evt work is pending.
1548 * Otherwise, decrement node reference to trigger release.
1550 if (!(ndlp
->fc4_xpt_flags
& (SCSI_XPT_REGD
| NVME_XPT_REGD
)) &&
1551 !(ndlp
->nlp_flag
& NLP_IN_DEV_LOSS
))
1559 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1560 * @vport: pointer to a host virtual N_Port data structure.
1562 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1563 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1564 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1565 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1566 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1567 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1571 * 0 - failed to issue initial fdisc for @vport
1572 * 1 - successfully issued initial fdisc for @vport
1575 lpfc_initial_fdisc(struct lpfc_vport
*vport
)
1577 struct lpfc_nodelist
*ndlp
;
1579 /* First look for the Fabric ndlp */
1580 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1582 /* Cannot find existing Fabric ndlp, so allocate a new one */
1583 ndlp
= lpfc_nlp_init(vport
, Fabric_DID
);
1587 /* NPIV is only supported in Fabrics. */
1588 ndlp
->nlp_type
|= NLP_FABRIC
;
1590 /* Put ndlp onto node list */
1591 lpfc_enqueue_node(vport
, ndlp
);
1594 if (lpfc_issue_els_fdisc(vport
, ndlp
, 0)) {
1595 /* A node reference should be retained while registered with a
1596 * transport or dev-loss-evt work is pending.
1597 * Otherwise, decrement node reference to trigger release.
1599 if (!(ndlp
->fc4_xpt_flags
& (SCSI_XPT_REGD
| NVME_XPT_REGD
)) &&
1600 !(ndlp
->nlp_flag
& NLP_IN_DEV_LOSS
))
1608 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1609 * @vport: pointer to a host virtual N_Port data structure.
1611 * This routine checks whether there are more remaining Port Logins
1612 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1613 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1614 * to issue ELS PLOGIs up to the configured discover threads with the
1615 * @vport (@vport->cfg_discovery_threads). The function also decrement
1616 * the @vport's num_disc_node by 1 if it is not already 0.
1619 lpfc_more_plogi(struct lpfc_vport
*vport
)
1621 if (vport
->num_disc_nodes
)
1622 vport
->num_disc_nodes
--;
1624 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1625 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1626 "0232 Continue discovery with %d PLOGIs to go "
1627 "Data: x%x x%lx x%x\n",
1628 vport
->num_disc_nodes
,
1629 atomic_read(&vport
->fc_plogi_cnt
),
1630 vport
->fc_flag
, vport
->port_state
);
1631 /* Check to see if there are more PLOGIs to be sent */
1632 if (test_bit(FC_NLP_MORE
, &vport
->fc_flag
))
1633 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1634 lpfc_els_disc_plogi(vport
);
1640 * lpfc_plogi_confirm_nport - Confirm plogi wwpn matches stored ndlp
1641 * @phba: pointer to lpfc hba data structure.
1642 * @prsp: pointer to response IOCB payload.
1643 * @ndlp: pointer to a node-list data structure.
1645 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1646 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1647 * The following cases are considered N_Port confirmed:
1648 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1649 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1650 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1651 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1652 * 1) if there is a node on vport list other than the @ndlp with the same
1653 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1654 * on that node to release the RPI associated with the node; 2) if there is
1655 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1656 * into, a new node shall be allocated (or activated). In either case, the
1657 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1658 * be released and the new_ndlp shall be put on to the vport node list and
1659 * its pointer returned as the confirmed node.
1661 * Note that before the @ndlp got "released", the keepDID from not-matching
1662 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1663 * of the @ndlp. This is because the release of @ndlp is actually to put it
1664 * into an inactive state on the vport node list and the vport node list
1665 * management algorithm does not allow two node with a same DID.
1668 * pointer to the PLOGI N_Port @ndlp
1670 static struct lpfc_nodelist
*
1671 lpfc_plogi_confirm_nport(struct lpfc_hba
*phba
, uint32_t *prsp
,
1672 struct lpfc_nodelist
*ndlp
)
1674 struct lpfc_vport
*vport
= ndlp
->vport
;
1675 struct lpfc_nodelist
*new_ndlp
;
1676 struct serv_parm
*sp
;
1677 uint8_t name
[sizeof(struct lpfc_name
)];
1678 uint32_t keepDID
= 0, keep_nlp_flag
= 0;
1680 uint32_t keep_new_nlp_flag
= 0;
1681 uint16_t keep_nlp_state
;
1682 u32 keep_nlp_fc4_type
= 0;
1683 struct lpfc_nvme_rport
*keep_nrport
= NULL
;
1684 unsigned long *active_rrqs_xri_bitmap
= NULL
;
1686 sp
= (struct serv_parm
*) ((uint8_t *) prsp
+ sizeof(uint32_t));
1687 memset(name
, 0, sizeof(struct lpfc_name
));
1689 /* Now we find out if the NPort we are logging into, matches the WWPN
1690 * we have for that ndlp. If not, we have some work to do.
1692 new_ndlp
= lpfc_findnode_wwpn(vport
, &sp
->portName
);
1694 /* return immediately if the WWPN matches ndlp */
1695 if (new_ndlp
== ndlp
)
1698 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1699 active_rrqs_xri_bitmap
= mempool_alloc(phba
->active_rrq_pool
,
1701 if (active_rrqs_xri_bitmap
)
1702 memset(active_rrqs_xri_bitmap
, 0,
1703 phba
->cfg_rrq_xri_bitmap_sz
);
1706 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
| LOG_NODE
,
1707 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1708 "new_ndlp x%x x%x x%x\n",
1709 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_fc4_type
,
1710 (new_ndlp
? new_ndlp
->nlp_DID
: 0),
1711 (new_ndlp
? new_ndlp
->nlp_flag
: 0),
1712 (new_ndlp
? new_ndlp
->nlp_fc4_type
: 0));
1715 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1716 sizeof(struct lpfc_name
));
1718 if (active_rrqs_xri_bitmap
)
1719 mempool_free(active_rrqs_xri_bitmap
,
1720 phba
->active_rrq_pool
);
1723 new_ndlp
= lpfc_nlp_init(vport
, ndlp
->nlp_DID
);
1725 if (active_rrqs_xri_bitmap
)
1726 mempool_free(active_rrqs_xri_bitmap
,
1727 phba
->active_rrq_pool
);
1731 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
1732 active_rrqs_xri_bitmap
)
1733 memcpy(active_rrqs_xri_bitmap
,
1734 new_ndlp
->active_rrqs_xri_bitmap
,
1735 phba
->cfg_rrq_xri_bitmap_sz
);
1738 * Unregister from backend if not done yet. Could have been
1739 * skipped due to ADISC
1741 lpfc_nlp_unreg_node(vport
, new_ndlp
);
1744 keepDID
= new_ndlp
->nlp_DID
;
1746 /* At this point in this routine, we know new_ndlp will be
1747 * returned. however, any previous GID_FTs that were done
1748 * would have updated nlp_fc4_type in ndlp, so we must ensure
1749 * new_ndlp has the right value.
1751 if (test_bit(FC_FABRIC
, &vport
->fc_flag
)) {
1752 keep_nlp_fc4_type
= new_ndlp
->nlp_fc4_type
;
1753 new_ndlp
->nlp_fc4_type
= ndlp
->nlp_fc4_type
;
1756 lpfc_unreg_rpi(vport
, new_ndlp
);
1757 new_ndlp
->nlp_DID
= ndlp
->nlp_DID
;
1758 new_ndlp
->nlp_prev_state
= ndlp
->nlp_prev_state
;
1759 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1760 memcpy(new_ndlp
->active_rrqs_xri_bitmap
,
1761 ndlp
->active_rrqs_xri_bitmap
,
1762 phba
->cfg_rrq_xri_bitmap_sz
);
1764 /* Lock both ndlps */
1765 spin_lock_irq(&ndlp
->lock
);
1766 spin_lock_irq(&new_ndlp
->lock
);
1767 keep_new_nlp_flag
= new_ndlp
->nlp_flag
;
1768 keep_nlp_flag
= ndlp
->nlp_flag
;
1769 new_ndlp
->nlp_flag
= ndlp
->nlp_flag
;
1771 /* if new_ndlp had NLP_UNREG_INP set, keep it */
1772 if (keep_new_nlp_flag
& NLP_UNREG_INP
)
1773 new_ndlp
->nlp_flag
|= NLP_UNREG_INP
;
1775 new_ndlp
->nlp_flag
&= ~NLP_UNREG_INP
;
1777 /* if new_ndlp had NLP_RPI_REGISTERED set, keep it */
1778 if (keep_new_nlp_flag
& NLP_RPI_REGISTERED
)
1779 new_ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
1781 new_ndlp
->nlp_flag
&= ~NLP_RPI_REGISTERED
;
1784 * Retain the DROPPED flag. This will take care of the init
1785 * refcount when affecting the state change
1787 if (keep_new_nlp_flag
& NLP_DROPPED
)
1788 new_ndlp
->nlp_flag
|= NLP_DROPPED
;
1790 new_ndlp
->nlp_flag
&= ~NLP_DROPPED
;
1792 ndlp
->nlp_flag
= keep_new_nlp_flag
;
1794 /* if ndlp had NLP_UNREG_INP set, keep it */
1795 if (keep_nlp_flag
& NLP_UNREG_INP
)
1796 ndlp
->nlp_flag
|= NLP_UNREG_INP
;
1798 ndlp
->nlp_flag
&= ~NLP_UNREG_INP
;
1800 /* if ndlp had NLP_RPI_REGISTERED set, keep it */
1801 if (keep_nlp_flag
& NLP_RPI_REGISTERED
)
1802 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
1804 ndlp
->nlp_flag
&= ~NLP_RPI_REGISTERED
;
1807 * Retain the DROPPED flag. This will take care of the init
1808 * refcount when affecting the state change
1810 if (keep_nlp_flag
& NLP_DROPPED
)
1811 ndlp
->nlp_flag
|= NLP_DROPPED
;
1813 ndlp
->nlp_flag
&= ~NLP_DROPPED
;
1815 spin_unlock_irq(&new_ndlp
->lock
);
1816 spin_unlock_irq(&ndlp
->lock
);
1818 /* Set nlp_states accordingly */
1819 keep_nlp_state
= new_ndlp
->nlp_state
;
1820 lpfc_nlp_set_state(vport
, new_ndlp
, ndlp
->nlp_state
);
1822 /* interchange the nvme remoteport structs */
1823 keep_nrport
= new_ndlp
->nrport
;
1824 new_ndlp
->nrport
= ndlp
->nrport
;
1826 /* Move this back to NPR state */
1827 if (memcmp(&ndlp
->nlp_portname
, name
, sizeof(struct lpfc_name
)) == 0) {
1828 /* The ndlp doesn't have a portname yet, but does have an
1829 * NPort ID. The new_ndlp portname matches the Rport's
1830 * portname. Reinstantiate the new_ndlp and reset the ndlp.
1832 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1833 "3179 PLOGI confirm NEW: %x %x\n",
1834 new_ndlp
->nlp_DID
, keepDID
);
1836 /* Two ndlps cannot have the same did on the nodelist.
1837 * The KeepDID and keep_nlp_fc4_type need to be swapped
1838 * because ndlp is inflight with no WWPN.
1840 ndlp
->nlp_DID
= keepDID
;
1841 ndlp
->nlp_fc4_type
= keep_nlp_fc4_type
;
1842 lpfc_nlp_set_state(vport
, ndlp
, keep_nlp_state
);
1843 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
1844 active_rrqs_xri_bitmap
)
1845 memcpy(ndlp
->active_rrqs_xri_bitmap
,
1846 active_rrqs_xri_bitmap
,
1847 phba
->cfg_rrq_xri_bitmap_sz
);
1850 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1851 "3180 PLOGI confirm SWAP: %x %x\n",
1852 new_ndlp
->nlp_DID
, keepDID
);
1854 lpfc_unreg_rpi(vport
, ndlp
);
1856 /* The ndlp and new_ndlp both have WWPNs but are swapping
1857 * NPort Ids and attributes.
1859 ndlp
->nlp_DID
= keepDID
;
1860 ndlp
->nlp_fc4_type
= keep_nlp_fc4_type
;
1862 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
1863 active_rrqs_xri_bitmap
)
1864 memcpy(ndlp
->active_rrqs_xri_bitmap
,
1865 active_rrqs_xri_bitmap
,
1866 phba
->cfg_rrq_xri_bitmap_sz
);
1868 /* Since we are switching over to the new_ndlp,
1869 * reset the old ndlp state
1871 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
1872 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
))
1873 keep_nlp_state
= NLP_STE_NPR_NODE
;
1874 lpfc_nlp_set_state(vport
, ndlp
, keep_nlp_state
);
1875 ndlp
->nrport
= keep_nrport
;
1879 * If ndlp is not associated with any rport we can drop it here else
1880 * let dev_loss_tmo_callbk trigger DEVICE_RM event
1882 if (!ndlp
->rport
&& (ndlp
->nlp_state
== NLP_STE_NPR_NODE
))
1883 lpfc_disc_state_machine(vport
, ndlp
, NULL
, NLP_EVT_DEVICE_RM
);
1885 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
1886 active_rrqs_xri_bitmap
)
1887 mempool_free(active_rrqs_xri_bitmap
,
1888 phba
->active_rrq_pool
);
1890 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
| LOG_NODE
,
1891 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1892 new_ndlp
->nlp_DID
, new_ndlp
->nlp_flag
,
1893 new_ndlp
->nlp_fc4_type
);
1899 * lpfc_end_rscn - Check and handle more rscn for a vport
1900 * @vport: pointer to a host virtual N_Port data structure.
1902 * This routine checks whether more Registration State Change
1903 * Notifications (RSCNs) came in while the discovery state machine was in
1904 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1905 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1906 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1907 * handling the RSCNs.
1910 lpfc_end_rscn(struct lpfc_vport
*vport
)
1913 if (test_bit(FC_RSCN_MODE
, &vport
->fc_flag
)) {
1915 * Check to see if more RSCNs came in while we were
1916 * processing this one.
1918 if (vport
->fc_rscn_id_cnt
||
1919 test_bit(FC_RSCN_DISCOVERY
, &vport
->fc_flag
))
1920 lpfc_els_handle_rscn(vport
);
1922 clear_bit(FC_RSCN_MODE
, &vport
->fc_flag
);
1927 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1928 * @phba: pointer to lpfc hba data structure.
1929 * @cmdiocb: pointer to lpfc command iocb data structure.
1930 * @rspiocb: pointer to lpfc response iocb data structure.
1932 * This routine will call the clear rrq function to free the rrq and
1933 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1934 * exist then the clear_rrq is still called because the rrq needs to
1939 lpfc_cmpl_els_rrq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1940 struct lpfc_iocbq
*rspiocb
)
1942 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1943 struct lpfc_nodelist
*ndlp
= cmdiocb
->ndlp
;
1944 struct lpfc_node_rrq
*rrq
;
1945 u32 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
1946 u32 ulp_word4
= get_job_word4(phba
, rspiocb
);
1948 /* we pass cmdiocb to state machine which needs rspiocb as well */
1949 rrq
= cmdiocb
->context_un
.rrq
;
1950 cmdiocb
->rsp_iocb
= rspiocb
;
1952 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1953 "RRQ cmpl: status:x%x/x%x did:x%x",
1954 ulp_status
, ulp_word4
,
1955 get_job_els_rsp64_did(phba
, cmdiocb
));
1958 /* rrq completes to NPort <nlp_DID> */
1959 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1960 "2880 RRQ completes to DID x%x "
1961 "Data: x%x x%x x%x x%x x%x\n",
1962 ndlp
->nlp_DID
, ulp_status
, ulp_word4
,
1963 get_wqe_tmo(cmdiocb
), rrq
->xritag
, rrq
->rxid
);
1966 /* Check for retry */
1967 /* Warn RRQ status Don't print the vport to vport rjts */
1968 if (ulp_status
!= IOSTAT_LS_RJT
||
1969 (((ulp_word4
) >> 16 != LSRJT_INVALID_CMD
) &&
1970 ((ulp_word4
) >> 16 != LSRJT_UNABLE_TPC
)) ||
1971 (phba
)->pport
->cfg_log_verbose
& LOG_ELS
)
1972 lpfc_vlog_msg(vport
, KERN_WARNING
, LOG_ELS
,
1973 "2881 RRQ DID:%06X Status:"
1975 ndlp
->nlp_DID
, ulp_status
,
1979 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
1980 lpfc_els_free_iocb(phba
, cmdiocb
);
1985 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1986 * @phba: pointer to lpfc hba data structure.
1987 * @cmdiocb: pointer to lpfc command iocb data structure.
1988 * @rspiocb: pointer to lpfc response iocb data structure.
1990 * This routine is the completion callback function for issuing the Port
1991 * Login (PLOGI) command. For PLOGI completion, there must be an active
1992 * ndlp on the vport node list that matches the remote node ID from the
1993 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1994 * ignored and command IOCB released. The PLOGI response IOCB status is
1995 * checked for error conditions. If there is error status reported, PLOGI
1996 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1997 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1998 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1999 * (DSM) is set for this PLOGI completion. Finally, it checks whether
2000 * there are additional N_Port nodes with the vport that need to perform
2001 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
2005 lpfc_cmpl_els_plogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2006 struct lpfc_iocbq
*rspiocb
)
2008 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2010 struct lpfc_nodelist
*ndlp
, *free_ndlp
;
2011 struct lpfc_dmabuf
*prsp
;
2013 struct serv_parm
*sp
= NULL
;
2014 u32 ulp_status
, ulp_word4
, did
, iotag
;
2015 bool release_node
= false;
2017 /* we pass cmdiocb to state machine which needs rspiocb as well */
2018 cmdiocb
->rsp_iocb
= rspiocb
;
2020 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
2021 ulp_word4
= get_job_word4(phba
, rspiocb
);
2022 did
= get_job_els_rsp64_did(phba
, cmdiocb
);
2024 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2025 iotag
= get_wqe_reqtag(cmdiocb
);
2027 irsp
= &rspiocb
->iocb
;
2028 iotag
= irsp
->ulpIoTag
;
2031 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2032 "PLOGI cmpl: status:x%x/x%x did:x%x",
2033 ulp_status
, ulp_word4
, did
);
2035 ndlp
= lpfc_findnode_did(vport
, did
);
2037 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
2038 "0136 PLOGI completes to NPort x%x "
2039 "with no ndlp. Data: x%x x%x x%x\n",
2040 did
, ulp_status
, ulp_word4
, iotag
);
2044 /* Since ndlp can be freed in the disc state machine, note if this node
2045 * is being used during discovery.
2047 spin_lock_irq(&ndlp
->lock
);
2048 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
2049 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
2050 spin_unlock_irq(&ndlp
->lock
);
2052 /* PLOGI completes to NPort <nlp_DID> */
2053 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2054 "0102 PLOGI completes to NPort x%06x "
2055 "IoTag x%x Data: x%x x%x x%x x%x x%x\n",
2056 ndlp
->nlp_DID
, iotag
,
2058 ulp_status
, ulp_word4
,
2059 disc
, vport
->num_disc_nodes
);
2061 /* Check to see if link went down during discovery */
2062 if (lpfc_els_chk_latt(vport
)) {
2063 spin_lock_irq(&ndlp
->lock
);
2064 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2065 spin_unlock_irq(&ndlp
->lock
);
2070 /* Check for retry */
2071 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
2072 /* ELS command is being retried */
2074 spin_lock_irq(&ndlp
->lock
);
2075 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2076 spin_unlock_irq(&ndlp
->lock
);
2080 /* Warn PLOGI status Don't print the vport to vport rjts */
2081 if (ulp_status
!= IOSTAT_LS_RJT
||
2082 (((ulp_word4
) >> 16 != LSRJT_INVALID_CMD
) &&
2083 ((ulp_word4
) >> 16 != LSRJT_UNABLE_TPC
)) ||
2084 (phba
)->pport
->cfg_log_verbose
& LOG_ELS
)
2085 lpfc_vlog_msg(vport
, KERN_WARNING
, LOG_ELS
,
2086 "2753 PLOGI DID:%06X "
2088 ndlp
->nlp_DID
, ulp_status
,
2091 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2092 if (!lpfc_error_lost_link(vport
, ulp_status
, ulp_word4
))
2093 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2094 NLP_EVT_CMPL_PLOGI
);
2096 /* If a PLOGI collision occurred, the node needs to continue
2097 * with the reglogin process.
2099 spin_lock_irq(&ndlp
->lock
);
2100 if ((ndlp
->nlp_flag
& (NLP_ACC_REGLOGIN
| NLP_RCV_PLOGI
)) &&
2101 ndlp
->nlp_state
== NLP_STE_REG_LOGIN_ISSUE
) {
2102 spin_unlock_irq(&ndlp
->lock
);
2106 /* No PLOGI collision and the node is not registered with the
2107 * scsi or nvme transport. It is no longer an active node. Just
2108 * start the device remove process.
2110 if (!(ndlp
->fc4_xpt_flags
& (SCSI_XPT_REGD
| NVME_XPT_REGD
))) {
2111 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
2112 if (!(ndlp
->nlp_flag
& NLP_IN_DEV_LOSS
))
2113 release_node
= true;
2115 spin_unlock_irq(&ndlp
->lock
);
2118 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2121 /* Good status, call state machine */
2122 prsp
= list_get_first(&cmdiocb
->cmd_dmabuf
->list
,
2123 struct lpfc_dmabuf
, list
);
2126 if (!lpfc_is_els_acc_rsp(prsp
))
2128 ndlp
= lpfc_plogi_confirm_nport(phba
, prsp
->virt
, ndlp
);
2130 sp
= (struct serv_parm
*)((u8
*)prsp
->virt
+
2133 ndlp
->vmid_support
= 0;
2134 if ((phba
->cfg_vmid_app_header
&& sp
->cmn
.app_hdr_support
) ||
2135 (phba
->cfg_vmid_priority_tagging
&&
2136 sp
->cmn
.priority_tagging
)) {
2137 lpfc_printf_log(phba
, KERN_DEBUG
, LOG_ELS
,
2138 "4018 app_hdr_support %d tagging %d DID x%x\n",
2139 sp
->cmn
.app_hdr_support
,
2140 sp
->cmn
.priority_tagging
,
2142 /* if the dest port supports VMID, mark it in ndlp */
2143 ndlp
->vmid_support
= 1;
2146 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2147 NLP_EVT_CMPL_PLOGI
);
2150 if (disc
&& vport
->num_disc_nodes
) {
2151 /* Check to see if there are more PLOGIs to be sent */
2152 lpfc_more_plogi(vport
);
2154 if (vport
->num_disc_nodes
== 0) {
2155 clear_bit(FC_NDISC_ACTIVE
, &vport
->fc_flag
);
2157 lpfc_can_disctmo(vport
);
2158 lpfc_end_rscn(vport
);
2163 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
2164 "PLOGI Cmpl PUT: did:x%x refcnt %d",
2165 ndlp
->nlp_DID
, kref_read(&ndlp
->kref
), 0);
2168 /* Release the reference on the original I/O request. */
2169 free_ndlp
= cmdiocb
->ndlp
;
2171 lpfc_els_free_iocb(phba
, cmdiocb
);
2172 lpfc_nlp_put(free_ndlp
);
2177 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
2178 * @vport: pointer to a host virtual N_Port data structure.
2179 * @did: destination port identifier.
2180 * @retry: number of retries to the command IOCB.
2182 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2183 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2184 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2185 * This routine constructs the proper fields of the PLOGI IOCB and invokes
2186 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2188 * Note that the ndlp reference count will be incremented by 1 for holding
2189 * the ndlp and the reference to ndlp will be stored into the ndlp field
2190 * of the IOCB for the completion callback function to the PLOGI ELS command.
2193 * 0 - Successfully issued a plogi for @vport
2194 * 1 - failed to issue a plogi for @vport
2197 lpfc_issue_els_plogi(struct lpfc_vport
*vport
, uint32_t did
, uint8_t retry
)
2199 struct lpfc_hba
*phba
= vport
->phba
;
2200 struct serv_parm
*sp
;
2201 struct lpfc_nodelist
*ndlp
;
2202 struct lpfc_iocbq
*elsiocb
;
2207 ndlp
= lpfc_findnode_did(vport
, did
);
2211 /* Defer the processing of the issue PLOGI until after the
2212 * outstanding UNREG_RPI mbox command completes, unless we
2213 * are going offline. This logic does not apply for Fabric DIDs
2215 if ((ndlp
->nlp_flag
& (NLP_IGNR_REG_CMPL
| NLP_UNREG_INP
)) &&
2216 ((ndlp
->nlp_DID
& Fabric_DID_MASK
) != Fabric_DID_MASK
) &&
2217 !test_bit(FC_OFFLINE_MODE
, &vport
->fc_flag
)) {
2218 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2219 "4110 Issue PLOGI x%x deferred "
2220 "on NPort x%x rpi x%x flg x%x Data:"
2222 ndlp
->nlp_defer_did
, ndlp
->nlp_DID
,
2223 ndlp
->nlp_rpi
, ndlp
->nlp_flag
, ndlp
);
2225 /* We can only defer 1st PLOGI */
2226 if (ndlp
->nlp_defer_did
== NLP_EVT_NOTHING_PENDING
)
2227 ndlp
->nlp_defer_did
= did
;
2231 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
2232 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
2237 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
2239 /* For PLOGI request, remainder of payload is service parameters */
2240 *((uint32_t *) (pcmd
)) = ELS_CMD_PLOGI
;
2241 pcmd
+= sizeof(uint32_t);
2242 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
2243 sp
= (struct serv_parm
*) pcmd
;
2246 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2247 * to device on remote loops work.
2249 if (test_bit(FC_FABRIC
, &vport
->fc_flag
) &&
2250 !test_bit(FC_PUBLIC_LOOP
, &vport
->fc_flag
))
2251 sp
->cmn
.altBbCredit
= 1;
2253 if (sp
->cmn
.fcphLow
< FC_PH_4_3
)
2254 sp
->cmn
.fcphLow
= FC_PH_4_3
;
2256 if (sp
->cmn
.fcphHigh
< FC_PH3
)
2257 sp
->cmn
.fcphHigh
= FC_PH3
;
2259 sp
->cmn
.valid_vendor_ver_level
= 0;
2260 memset(sp
->un
.vendorVersion
, 0, sizeof(sp
->un
.vendorVersion
));
2261 sp
->cmn
.bbRcvSizeMsb
&= 0xF;
2263 /* Check if the destination port supports VMID */
2264 ndlp
->vmid_support
= 0;
2265 if (vport
->vmid_priority_tagging
)
2266 sp
->cmn
.priority_tagging
= 1;
2267 else if (phba
->cfg_vmid_app_header
&&
2268 bf_get(lpfc_ftr_ashdr
, &phba
->sli4_hba
.sli4_flags
))
2269 sp
->cmn
.app_hdr_support
= 1;
2271 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2272 "Issue PLOGI: did:x%x",
2275 /* If our firmware supports this feature, convey that
2276 * information to the target using the vendor specific field.
2278 if (phba
->sli
.sli_flag
& LPFC_SLI_SUPPRESS_RSP
) {
2279 sp
->cmn
.valid_vendor_ver_level
= 1;
2280 sp
->un
.vv
.vid
= cpu_to_be32(LPFC_VV_EMLX_ID
);
2281 sp
->un
.vv
.flags
= cpu_to_be32(LPFC_VV_SUPPRESS_RSP
);
2284 phba
->fc_stat
.elsXmitPLOGI
++;
2285 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_plogi
;
2287 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2288 "Issue PLOGI: did:x%x refcnt %d",
2289 did
, kref_read(&ndlp
->kref
), 0);
2290 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
2291 if (!elsiocb
->ndlp
) {
2292 lpfc_els_free_iocb(phba
, elsiocb
);
2296 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
2298 lpfc_els_free_iocb(phba
, elsiocb
);
2307 * lpfc_cmpl_els_prli - Completion callback function for prli
2308 * @phba: pointer to lpfc hba data structure.
2309 * @cmdiocb: pointer to lpfc command iocb data structure.
2310 * @rspiocb: pointer to lpfc response iocb data structure.
2312 * This routine is the completion callback function for a Process Login
2313 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2314 * status. If there is error status reported, PRLI retry shall be attempted
2315 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2316 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2317 * ndlp to mark the PRLI completion.
2320 lpfc_cmpl_els_prli(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2321 struct lpfc_iocbq
*rspiocb
)
2323 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2324 struct lpfc_nodelist
*ndlp
;
2328 bool release_node
= false;
2330 /* we pass cmdiocb to state machine which needs rspiocb as well */
2331 cmdiocb
->rsp_iocb
= rspiocb
;
2333 ndlp
= cmdiocb
->ndlp
;
2335 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
2336 ulp_word4
= get_job_word4(phba
, rspiocb
);
2338 spin_lock_irq(&ndlp
->lock
);
2339 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
2341 /* Driver supports multiple FC4 types. Counters matter. */
2342 vport
->fc_prli_sent
--;
2343 ndlp
->fc4_prli_sent
--;
2344 spin_unlock_irq(&ndlp
->lock
);
2346 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2347 "PRLI cmpl: status:x%x/x%x did:x%x",
2348 ulp_status
, ulp_word4
,
2351 /* PRLI completes to NPort <nlp_DID> */
2352 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2353 "0103 PRLI completes to NPort x%06x "
2354 "Data: x%x x%x x%x x%x x%x\n",
2355 ndlp
->nlp_DID
, ulp_status
, ulp_word4
,
2356 vport
->num_disc_nodes
, ndlp
->fc4_prli_sent
,
2357 ndlp
->fc4_xpt_flags
);
2359 /* Check to see if link went down during discovery */
2360 if (lpfc_els_chk_latt(vport
))
2364 /* Check for retry */
2365 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
2366 /* ELS command is being retried */
2370 /* If we don't send GFT_ID to Fabric, a PRLI error
2371 * could be expected.
2373 if (test_bit(FC_FABRIC
, &vport
->fc_flag
) ||
2374 vport
->cfg_enable_fc4_type
!= LPFC_ENABLE_BOTH
)
2375 mode
= KERN_WARNING
;
2379 /* Warn PRLI status */
2380 lpfc_printf_vlog(vport
, mode
, LOG_ELS
,
2381 "2754 PRLI DID:%06X Status:x%x/x%x, "
2382 "data: x%x x%x x%x\n",
2383 ndlp
->nlp_DID
, ulp_status
,
2384 ulp_word4
, ndlp
->nlp_state
,
2385 ndlp
->fc4_prli_sent
, ndlp
->nlp_flag
);
2387 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2388 if (!lpfc_error_lost_link(vport
, ulp_status
, ulp_word4
))
2389 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2392 /* The following condition catches an inflight transition
2393 * mismatch typically caused by an RSCN. Skip any
2394 * processing to allow recovery.
2396 if ((ndlp
->nlp_state
>= NLP_STE_PLOGI_ISSUE
&&
2397 ndlp
->nlp_state
<= NLP_STE_REG_LOGIN_ISSUE
) ||
2398 (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
2399 ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2400 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NODE
,
2401 "2784 PRLI cmpl: Allow Node recovery "
2402 "DID x%06x nstate x%x nflag x%x\n",
2403 ndlp
->nlp_DID
, ndlp
->nlp_state
,
2409 * For P2P topology, retain the node so that PLOGI can be
2410 * attempted on it again.
2412 if (test_bit(FC_PT2PT
, &vport
->fc_flag
))
2415 /* As long as this node is not registered with the SCSI
2416 * or NVMe transport and no other PRLIs are outstanding,
2417 * it is no longer an active node. Otherwise devloss
2418 * handles the final cleanup.
2420 spin_lock_irq(&ndlp
->lock
);
2421 if (!(ndlp
->fc4_xpt_flags
& (SCSI_XPT_REGD
| NVME_XPT_REGD
)) &&
2422 !ndlp
->fc4_prli_sent
) {
2423 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
2424 if (!(ndlp
->nlp_flag
& NLP_IN_DEV_LOSS
))
2425 release_node
= true;
2427 spin_unlock_irq(&ndlp
->lock
);
2430 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2433 /* Good status, call state machine. However, if another
2434 * PRLI is outstanding, don't call the state machine
2435 * because final disposition to Mapped or Unmapped is
2438 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2443 lpfc_els_free_iocb(phba
, cmdiocb
);
2449 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2450 * @vport: pointer to a host virtual N_Port data structure.
2451 * @ndlp: pointer to a node-list data structure.
2452 * @retry: number of retries to the command IOCB.
2454 * This routine issues a Process Login (PRLI) ELS command for the
2455 * @vport. The PRLI service parameters are set up in the payload of the
2456 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2457 * is put to the IOCB completion callback func field before invoking the
2458 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2460 * Note that the ndlp reference count will be incremented by 1 for holding the
2461 * ndlp and the reference to ndlp will be stored into the ndlp field of
2462 * the IOCB for the completion callback function to the PRLI ELS command.
2465 * 0 - successfully issued prli iocb command for @vport
2466 * 1 - failed to issue prli iocb command for @vport
2469 lpfc_issue_els_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2473 struct lpfc_hba
*phba
= vport
->phba
;
2475 struct lpfc_nvme_prli
*npr_nvme
;
2476 struct lpfc_iocbq
*elsiocb
;
2479 u32 local_nlp_type
, elscmd
;
2482 * If we are in RSCN mode, the FC4 types supported from a
2483 * previous GFT_ID command may not be accurate. So, if we
2484 * are a NVME Initiator, always look for the possibility of
2485 * the remote NPort beng a NVME Target.
2487 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
2488 test_bit(FC_RSCN_MODE
, &vport
->fc_flag
) &&
2489 vport
->nvmei_support
)
2490 ndlp
->nlp_fc4_type
|= NLP_FC4_NVME
;
2491 local_nlp_type
= ndlp
->nlp_fc4_type
;
2493 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2494 * fields here before any of them can complete.
2496 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
2497 ndlp
->nlp_type
&= ~(NLP_NVME_TARGET
| NLP_NVME_INITIATOR
);
2498 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
2499 ndlp
->nlp_flag
&= ~(NLP_FIRSTBURST
| NLP_NPR_2B_DISC
);
2500 ndlp
->nvme_fb_size
= 0;
2503 if (local_nlp_type
& NLP_FC4_FCP
) {
2504 /* Payload is 4 + 16 = 20 x14 bytes. */
2505 cmdsize
= (sizeof(uint32_t) + sizeof(PRLI
));
2506 elscmd
= ELS_CMD_PRLI
;
2507 } else if (local_nlp_type
& NLP_FC4_NVME
) {
2508 /* Payload is 4 + 20 = 24 x18 bytes. */
2509 cmdsize
= (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli
));
2510 elscmd
= ELS_CMD_NVMEPRLI
;
2512 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2513 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2514 ndlp
->nlp_fc4_type
, ndlp
->nlp_DID
);
2518 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2519 * FC4 type, implicitly LOGO.
2521 if (phba
->sli_rev
== LPFC_SLI_REV3
&&
2522 ndlp
->nlp_fc4_type
== NLP_FC4_NVME
) {
2523 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2524 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2526 lpfc_disc_state_machine(vport
, ndlp
, NULL
, NLP_EVT_DEVICE_RM
);
2530 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2531 ndlp
->nlp_DID
, elscmd
);
2535 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
2537 /* For PRLI request, remainder of payload is service parameters */
2538 memset(pcmd
, 0, cmdsize
);
2540 if (local_nlp_type
& NLP_FC4_FCP
) {
2541 /* Remainder of payload is FCP PRLI parameter page.
2542 * Note: this data structure is defined as
2543 * BE/LE in the structure definition so no
2544 * byte swap call is made.
2546 *((uint32_t *)(pcmd
)) = ELS_CMD_PRLI
;
2547 pcmd
+= sizeof(uint32_t);
2551 * If our firmware version is 3.20 or later,
2552 * set the following bits for FC-TAPE support.
2554 if (phba
->vpd
.rev
.feaLevelHigh
>= 0x02) {
2555 npr
->ConfmComplAllowed
= 1;
2557 npr
->TaskRetryIdReq
= 1;
2559 npr
->estabImagePair
= 1;
2560 npr
->readXferRdyDis
= 1;
2561 if (vport
->cfg_first_burst_size
)
2562 npr
->writeXferRdyDis
= 1;
2564 /* For FCP support */
2565 npr
->prliType
= PRLI_FCP_TYPE
;
2566 npr
->initiatorFunc
= 1;
2567 elsiocb
->cmd_flag
|= LPFC_PRLI_FCP_REQ
;
2569 /* Remove FCP type - processed. */
2570 local_nlp_type
&= ~NLP_FC4_FCP
;
2571 } else if (local_nlp_type
& NLP_FC4_NVME
) {
2572 /* Remainder of payload is NVME PRLI parameter page.
2573 * This data structure is the newer definition that
2574 * uses bf macros so a byte swap is required.
2576 *((uint32_t *)(pcmd
)) = ELS_CMD_NVMEPRLI
;
2577 pcmd
+= sizeof(uint32_t);
2578 npr_nvme
= (struct lpfc_nvme_prli
*)pcmd
;
2579 bf_set(prli_type_code
, npr_nvme
, PRLI_NVME_TYPE
);
2580 bf_set(prli_estabImagePair
, npr_nvme
, 0); /* Should be 0 */
2582 bf_set(prli_nsler
, npr_nvme
, 1);
2583 bf_set(prli_conf
, npr_nvme
, 1);
2586 /* Only initiators request first burst. */
2587 if ((phba
->cfg_nvme_enable_fb
) &&
2588 !phba
->nvmet_support
)
2589 bf_set(prli_fba
, npr_nvme
, 1);
2591 if (phba
->nvmet_support
) {
2592 bf_set(prli_tgt
, npr_nvme
, 1);
2593 bf_set(prli_disc
, npr_nvme
, 1);
2595 bf_set(prli_init
, npr_nvme
, 1);
2596 bf_set(prli_conf
, npr_nvme
, 1);
2599 npr_nvme
->word1
= cpu_to_be32(npr_nvme
->word1
);
2600 npr_nvme
->word4
= cpu_to_be32(npr_nvme
->word4
);
2601 elsiocb
->cmd_flag
|= LPFC_PRLI_NVME_REQ
;
2603 /* Remove NVME type - processed. */
2604 local_nlp_type
&= ~NLP_FC4_NVME
;
2607 phba
->fc_stat
.elsXmitPRLI
++;
2608 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_prli
;
2610 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2611 "Issue PRLI: did:x%x refcnt %d",
2612 ndlp
->nlp_DID
, kref_read(&ndlp
->kref
), 0);
2613 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
2614 if (!elsiocb
->ndlp
) {
2615 lpfc_els_free_iocb(phba
, elsiocb
);
2619 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
2620 if (rc
== IOCB_ERROR
) {
2621 lpfc_els_free_iocb(phba
, elsiocb
);
2626 /* The vport counters are used for lpfc_scan_finished, but
2627 * the ndlp is used to track outstanding PRLIs for different
2630 spin_lock_irq(&ndlp
->lock
);
2631 ndlp
->nlp_flag
|= NLP_PRLI_SND
;
2632 vport
->fc_prli_sent
++;
2633 ndlp
->fc4_prli_sent
++;
2634 spin_unlock_irq(&ndlp
->lock
);
2636 /* The driver supports 2 FC4 types. Make sure
2637 * a PRLI is issued for all types before exiting.
2639 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
2640 local_nlp_type
& (NLP_FC4_FCP
| NLP_FC4_NVME
))
2641 goto send_next_prli
;
2647 * lpfc_rscn_disc - Perform rscn discovery for a vport
2648 * @vport: pointer to a host virtual N_Port data structure.
2650 * This routine performs Registration State Change Notification (RSCN)
2651 * discovery for a @vport. If the @vport's node port recovery count is not
2652 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2653 * the nodes that need recovery. If none of the PLOGI were needed through
2654 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2655 * invoked to check and handle possible more RSCN came in during the period
2656 * of processing the current ones.
2659 lpfc_rscn_disc(struct lpfc_vport
*vport
)
2661 lpfc_can_disctmo(vport
);
2663 /* RSCN discovery */
2664 /* go thru NPR nodes and issue ELS PLOGIs */
2665 if (atomic_read(&vport
->fc_npr_cnt
))
2666 if (lpfc_els_disc_plogi(vport
))
2669 lpfc_end_rscn(vport
);
2673 * lpfc_adisc_done - Complete the adisc phase of discovery
2674 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2676 * This function is called when the final ADISC is completed during discovery.
2677 * This function handles clearing link attention or issuing reg_vpi depending
2678 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2680 * This function is called with no locks held.
2683 lpfc_adisc_done(struct lpfc_vport
*vport
)
2685 struct lpfc_hba
*phba
= vport
->phba
;
2688 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2689 * and continue discovery.
2691 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2692 !test_bit(FC_RSCN_MODE
, &vport
->fc_flag
) &&
2693 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
2696 * If link is down, clear_la and reg_vpi will be done after
2697 * flogi following a link up event
2699 if (!lpfc_is_link_up(phba
))
2702 /* The ADISCs are complete. Doesn't matter if they
2703 * succeeded or failed because the ADISC completion
2704 * routine guarantees to call the state machine and
2705 * the RPI is either unregistered (failed ADISC response)
2706 * or the RPI is still valid and the node is marked
2707 * mapped for a target. The exchanges should be in the
2708 * correct state. This code is specific to SLI3.
2710 lpfc_issue_clear_la(phba
, vport
);
2711 lpfc_issue_reg_vpi(phba
, vport
);
2715 * For SLI2, we need to set port_state to READY
2716 * and continue discovery.
2718 if (vport
->port_state
< LPFC_VPORT_READY
) {
2719 /* If we get here, there is nothing to ADISC */
2720 lpfc_issue_clear_la(phba
, vport
);
2721 if (!test_bit(FC_ABORT_DISCOVERY
, &vport
->fc_flag
)) {
2722 vport
->num_disc_nodes
= 0;
2723 /* go thru NPR list, issue ELS PLOGIs */
2724 if (atomic_read(&vport
->fc_npr_cnt
))
2725 lpfc_els_disc_plogi(vport
);
2726 if (!vport
->num_disc_nodes
) {
2727 clear_bit(FC_NDISC_ACTIVE
, &vport
->fc_flag
);
2728 lpfc_can_disctmo(vport
);
2729 lpfc_end_rscn(vport
);
2732 vport
->port_state
= LPFC_VPORT_READY
;
2734 lpfc_rscn_disc(vport
);
2738 * lpfc_more_adisc - Issue more adisc as needed
2739 * @vport: pointer to a host virtual N_Port data structure.
2741 * This routine determines whether there are more ndlps on a @vport
2742 * node list need to have Address Discover (ADISC) issued. If so, it will
2743 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2744 * remaining nodes which need to have ADISC sent.
2747 lpfc_more_adisc(struct lpfc_vport
*vport
)
2749 if (vport
->num_disc_nodes
)
2750 vport
->num_disc_nodes
--;
2751 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2752 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2753 "0210 Continue discovery with %d ADISCs to go "
2754 "Data: x%x x%lx x%x\n",
2755 vport
->num_disc_nodes
,
2756 atomic_read(&vport
->fc_adisc_cnt
),
2757 vport
->fc_flag
, vport
->port_state
);
2758 /* Check to see if there are more ADISCs to be sent */
2759 if (test_bit(FC_NLP_MORE
, &vport
->fc_flag
)) {
2760 lpfc_set_disctmo(vport
);
2761 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2762 lpfc_els_disc_adisc(vport
);
2764 if (!vport
->num_disc_nodes
)
2765 lpfc_adisc_done(vport
);
2770 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2771 * @phba: pointer to lpfc hba data structure.
2772 * @cmdiocb: pointer to lpfc command iocb data structure.
2773 * @rspiocb: pointer to lpfc response iocb data structure.
2775 * This routine is the completion function for issuing the Address Discover
2776 * (ADISC) command. It first checks to see whether link went down during
2777 * the discovery process. If so, the node will be marked as node port
2778 * recovery for issuing discover IOCB by the link attention handler and
2779 * exit. Otherwise, the response status is checked. If error was reported
2780 * in the response status, the ADISC command shall be retried by invoking
2781 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2782 * the response status, the state machine is invoked to set transition
2783 * with respect to NLP_EVT_CMPL_ADISC event.
2786 lpfc_cmpl_els_adisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2787 struct lpfc_iocbq
*rspiocb
)
2789 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2791 struct lpfc_nodelist
*ndlp
;
2793 u32 ulp_status
, ulp_word4
, tmo
, iotag
;
2794 bool release_node
= false;
2796 /* we pass cmdiocb to state machine which needs rspiocb as well */
2797 cmdiocb
->rsp_iocb
= rspiocb
;
2799 ndlp
= cmdiocb
->ndlp
;
2801 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
2802 ulp_word4
= get_job_word4(phba
, rspiocb
);
2804 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2805 tmo
= get_wqe_tmo(cmdiocb
);
2806 iotag
= get_wqe_reqtag(cmdiocb
);
2808 irsp
= &rspiocb
->iocb
;
2809 tmo
= irsp
->ulpTimeout
;
2810 iotag
= irsp
->ulpIoTag
;
2813 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2814 "ADISC cmpl: status:x%x/x%x did:x%x",
2815 ulp_status
, ulp_word4
,
2818 /* Since ndlp can be freed in the disc state machine, note if this node
2819 * is being used during discovery.
2821 spin_lock_irq(&ndlp
->lock
);
2822 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
2823 ndlp
->nlp_flag
&= ~(NLP_ADISC_SND
| NLP_NPR_2B_DISC
);
2824 spin_unlock_irq(&ndlp
->lock
);
2825 /* ADISC completes to NPort <nlp_DID> */
2826 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2827 "0104 ADISC completes to NPort x%x "
2828 "IoTag x%x Data: x%x x%x x%x x%x x%x\n",
2829 ndlp
->nlp_DID
, iotag
,
2830 ulp_status
, ulp_word4
,
2831 tmo
, disc
, vport
->num_disc_nodes
);
2833 /* Check to see if link went down during discovery */
2834 if (lpfc_els_chk_latt(vport
)) {
2835 spin_lock_irq(&ndlp
->lock
);
2836 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2837 spin_unlock_irq(&ndlp
->lock
);
2842 /* Check for retry */
2843 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
2844 /* ELS command is being retried */
2846 spin_lock_irq(&ndlp
->lock
);
2847 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2848 spin_unlock_irq(&ndlp
->lock
);
2849 lpfc_set_disctmo(vport
);
2853 /* Warn ADISC status */
2854 lpfc_vlog_msg(vport
, KERN_WARNING
, LOG_ELS
,
2855 "2755 ADISC DID:%06X Status:x%x/x%x\n",
2856 ndlp
->nlp_DID
, ulp_status
,
2858 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2859 NLP_EVT_CMPL_ADISC
);
2861 /* As long as this node is not registered with the SCSI or NVMe
2862 * transport, it is no longer an active node. Otherwise
2863 * devloss handles the final cleanup.
2865 spin_lock_irq(&ndlp
->lock
);
2866 if (!(ndlp
->fc4_xpt_flags
& (SCSI_XPT_REGD
| NVME_XPT_REGD
))) {
2867 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
2868 if (!(ndlp
->nlp_flag
& NLP_IN_DEV_LOSS
))
2869 release_node
= true;
2871 spin_unlock_irq(&ndlp
->lock
);
2874 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2877 /* Good status, call state machine */
2878 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2879 NLP_EVT_CMPL_ADISC
);
2881 /* Check to see if there are more ADISCs to be sent */
2882 if (disc
&& vport
->num_disc_nodes
)
2883 lpfc_more_adisc(vport
);
2885 lpfc_els_free_iocb(phba
, cmdiocb
);
2891 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2892 * @vport: pointer to a virtual N_Port data structure.
2893 * @ndlp: pointer to a node-list data structure.
2894 * @retry: number of retries to the command IOCB.
2896 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2897 * @vport. It prepares the payload of the ADISC ELS command, updates the
2898 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2899 * to issue the ADISC ELS command.
2901 * Note that the ndlp reference count will be incremented by 1 for holding the
2902 * ndlp and the reference to ndlp will be stored into the ndlp field of
2903 * the IOCB for the completion callback function to the ADISC ELS command.
2906 * 0 - successfully issued adisc
2907 * 1 - failed to issue adisc
2910 lpfc_issue_els_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2914 struct lpfc_hba
*phba
= vport
->phba
;
2916 struct lpfc_iocbq
*elsiocb
;
2920 cmdsize
= (sizeof(uint32_t) + sizeof(ADISC
));
2921 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2922 ndlp
->nlp_DID
, ELS_CMD_ADISC
);
2926 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
2928 /* For ADISC request, remainder of payload is service parameters */
2929 *((uint32_t *) (pcmd
)) = ELS_CMD_ADISC
;
2930 pcmd
+= sizeof(uint32_t);
2932 /* Fill in ADISC payload */
2933 ap
= (ADISC
*) pcmd
;
2934 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
2935 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2936 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2937 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
2939 phba
->fc_stat
.elsXmitADISC
++;
2940 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_adisc
;
2941 spin_lock_irq(&ndlp
->lock
);
2942 ndlp
->nlp_flag
|= NLP_ADISC_SND
;
2943 spin_unlock_irq(&ndlp
->lock
);
2944 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
2945 if (!elsiocb
->ndlp
) {
2946 lpfc_els_free_iocb(phba
, elsiocb
);
2950 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2951 "Issue ADISC: did:x%x refcnt %d",
2952 ndlp
->nlp_DID
, kref_read(&ndlp
->kref
), 0);
2954 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
2955 if (rc
== IOCB_ERROR
) {
2956 lpfc_els_free_iocb(phba
, elsiocb
);
2964 spin_lock_irq(&ndlp
->lock
);
2965 ndlp
->nlp_flag
&= ~NLP_ADISC_SND
;
2966 spin_unlock_irq(&ndlp
->lock
);
2971 * lpfc_cmpl_els_logo - Completion callback function for logo
2972 * @phba: pointer to lpfc hba data structure.
2973 * @cmdiocb: pointer to lpfc command iocb data structure.
2974 * @rspiocb: pointer to lpfc response iocb data structure.
2976 * This routine is the completion function for issuing the ELS Logout (LOGO)
2977 * command. If no error status was reported from the LOGO response, the
2978 * state machine of the associated ndlp shall be invoked for transition with
2979 * respect to NLP_EVT_CMPL_LOGO event.
2982 lpfc_cmpl_els_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2983 struct lpfc_iocbq
*rspiocb
)
2985 struct lpfc_nodelist
*ndlp
= cmdiocb
->ndlp
;
2986 struct lpfc_vport
*vport
= ndlp
->vport
;
2988 unsigned long flags
;
2989 uint32_t skip_recovery
= 0;
2990 int wake_up_waiter
= 0;
2995 /* we pass cmdiocb to state machine which needs rspiocb as well */
2996 cmdiocb
->rsp_iocb
= rspiocb
;
2998 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
2999 ulp_word4
= get_job_word4(phba
, rspiocb
);
3001 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3002 tmo
= get_wqe_tmo(cmdiocb
);
3003 iotag
= get_wqe_reqtag(cmdiocb
);
3005 irsp
= &rspiocb
->iocb
;
3006 tmo
= irsp
->ulpTimeout
;
3007 iotag
= irsp
->ulpIoTag
;
3010 spin_lock_irq(&ndlp
->lock
);
3011 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
3012 if (ndlp
->save_flags
& NLP_WAIT_FOR_LOGO
) {
3014 ndlp
->save_flags
&= ~NLP_WAIT_FOR_LOGO
;
3016 spin_unlock_irq(&ndlp
->lock
);
3018 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3019 "LOGO cmpl: status:x%x/x%x did:x%x",
3020 ulp_status
, ulp_word4
,
3023 /* LOGO completes to NPort <nlp_DID> */
3024 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3025 "0105 LOGO completes to NPort x%x "
3026 "IoTag x%x refcnt %d nflags x%x xflags x%x "
3027 "Data: x%x x%x x%x x%x\n",
3028 ndlp
->nlp_DID
, iotag
,
3029 kref_read(&ndlp
->kref
), ndlp
->nlp_flag
,
3030 ndlp
->fc4_xpt_flags
, ulp_status
, ulp_word4
,
3031 tmo
, vport
->num_disc_nodes
);
3033 if (lpfc_els_chk_latt(vport
)) {
3038 /* The LOGO will not be retried on failure. A LOGO was
3039 * issued to the remote rport and a ACC or RJT or no Answer are
3040 * all acceptable. Note the failure and move forward with
3041 * discovery. The PLOGI will retry.
3044 /* Warn LOGO status */
3045 lpfc_vlog_msg(vport
, KERN_WARNING
, LOG_ELS
,
3046 "2756 LOGO, No Retry DID:%06X "
3048 ndlp
->nlp_DID
, ulp_status
,
3051 if (lpfc_error_lost_link(vport
, ulp_status
, ulp_word4
))
3055 /* Call state machine. This will unregister the rpi if needed. */
3056 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
, NLP_EVT_CMPL_LOGO
);
3061 /* The driver sets this flag for an NPIV instance that doesn't want to
3062 * log into the remote port.
3064 if (ndlp
->nlp_flag
& NLP_TARGET_REMOVE
) {
3065 spin_lock_irq(&ndlp
->lock
);
3066 if (phba
->sli_rev
== LPFC_SLI_REV4
)
3067 ndlp
->nlp_flag
|= NLP_RELEASE_RPI
;
3068 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
3069 spin_unlock_irq(&ndlp
->lock
);
3070 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
3076 /* At this point, the LOGO processing is complete. NOTE: For a
3077 * pt2pt topology, we are assuming the NPortID will only change
3078 * on link up processing. For a LOGO / PLOGI initiated by the
3079 * Initiator, we are assuming the NPortID is not going to change.
3082 if (wake_up_waiter
&& ndlp
->logo_waitq
)
3083 wake_up(ndlp
->logo_waitq
);
3085 * If the node is a target, the handling attempts to recover the port.
3086 * For any other port type, the rpi is unregistered as an implicit
3089 if (ndlp
->nlp_type
& (NLP_FCP_TARGET
| NLP_NVME_TARGET
) &&
3090 skip_recovery
== 0) {
3091 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
3092 spin_lock_irqsave(&ndlp
->lock
, flags
);
3093 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
3094 spin_unlock_irqrestore(&ndlp
->lock
, flags
);
3096 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3097 "3187 LOGO completes to NPort x%x: Start "
3098 "Recovery Data: x%x x%x x%x x%x\n",
3099 ndlp
->nlp_DID
, ulp_status
,
3101 vport
->num_disc_nodes
);
3103 lpfc_els_free_iocb(phba
, cmdiocb
);
3106 lpfc_disc_start(vport
);
3110 /* Cleanup path for failed REG_RPI handling. If REG_RPI fails, the
3111 * driver sends a LOGO to the rport to cleanup. For fabric and
3112 * initiator ports cleanup the node as long as it the node is not
3113 * register with the transport.
3115 if (!(ndlp
->fc4_xpt_flags
& (SCSI_XPT_REGD
| NVME_XPT_REGD
))) {
3116 spin_lock_irq(&ndlp
->lock
);
3117 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
3118 spin_unlock_irq(&ndlp
->lock
);
3119 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
3123 /* Driver is done with the I/O. */
3124 lpfc_els_free_iocb(phba
, cmdiocb
);
3129 * lpfc_issue_els_logo - Issue a logo to an node on a vport
3130 * @vport: pointer to a virtual N_Port data structure.
3131 * @ndlp: pointer to a node-list data structure.
3132 * @retry: number of retries to the command IOCB.
3134 * This routine constructs and issues an ELS Logout (LOGO) iocb command
3135 * to a remote node, referred by an @ndlp on a @vport. It constructs the
3136 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
3137 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
3139 * Note that the ndlp reference count will be incremented by 1 for holding the
3140 * ndlp and the reference to ndlp will be stored into the ndlp field of
3141 * the IOCB for the completion callback function to the LOGO ELS command.
3143 * Callers of this routine are expected to unregister the RPI first
3146 * 0 - successfully issued logo
3147 * 1 - failed to issue logo
3150 lpfc_issue_els_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
3153 struct lpfc_hba
*phba
= vport
->phba
;
3154 struct lpfc_iocbq
*elsiocb
;
3159 spin_lock_irq(&ndlp
->lock
);
3160 if (ndlp
->nlp_flag
& NLP_LOGO_SND
) {
3161 spin_unlock_irq(&ndlp
->lock
);
3164 spin_unlock_irq(&ndlp
->lock
);
3166 cmdsize
= (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name
);
3167 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
3168 ndlp
->nlp_DID
, ELS_CMD_LOGO
);
3172 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
3173 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
3174 pcmd
+= sizeof(uint32_t);
3176 /* Fill in LOGO payload */
3177 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
3178 pcmd
+= sizeof(uint32_t);
3179 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
3181 phba
->fc_stat
.elsXmitLOGO
++;
3182 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_logo
;
3183 spin_lock_irq(&ndlp
->lock
);
3184 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
3185 ndlp
->nlp_flag
&= ~NLP_ISSUE_LOGO
;
3186 spin_unlock_irq(&ndlp
->lock
);
3187 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
3188 if (!elsiocb
->ndlp
) {
3189 lpfc_els_free_iocb(phba
, elsiocb
);
3193 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3194 "Issue LOGO: did:x%x refcnt %d",
3195 ndlp
->nlp_DID
, kref_read(&ndlp
->kref
), 0);
3197 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3198 if (rc
== IOCB_ERROR
) {
3199 lpfc_els_free_iocb(phba
, elsiocb
);
3204 spin_lock_irq(&ndlp
->lock
);
3205 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3206 spin_unlock_irq(&ndlp
->lock
);
3207 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_LOGO_ISSUE
);
3211 spin_lock_irq(&ndlp
->lock
);
3212 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
3213 spin_unlock_irq(&ndlp
->lock
);
3218 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
3219 * @phba: pointer to lpfc hba data structure.
3220 * @cmdiocb: pointer to lpfc command iocb data structure.
3221 * @rspiocb: pointer to lpfc response iocb data structure.
3223 * This routine is a generic completion callback function for ELS commands.
3224 * Specifically, it is the callback function which does not need to perform
3225 * any command specific operations. It is currently used by the ELS command
3226 * issuing routines for RSCN, lpfc_issue_els_rscn, and the ELS Fibre Channel
3227 * Address Resolution Protocol Response (FARPR) routine, lpfc_issue_els_farpr().
3228 * Other than certain debug loggings, this callback function simply invokes the
3229 * lpfc_els_chk_latt() routine to check whether link went down during the
3230 * discovery process.
3233 lpfc_cmpl_els_cmd(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3234 struct lpfc_iocbq
*rspiocb
)
3236 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3237 struct lpfc_nodelist
*free_ndlp
;
3239 u32 ulp_status
, ulp_word4
, tmo
, did
, iotag
;
3241 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
3242 ulp_word4
= get_job_word4(phba
, rspiocb
);
3243 did
= get_job_els_rsp64_did(phba
, cmdiocb
);
3245 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3246 tmo
= get_wqe_tmo(cmdiocb
);
3247 iotag
= get_wqe_reqtag(cmdiocb
);
3249 irsp
= &rspiocb
->iocb
;
3250 tmo
= irsp
->ulpTimeout
;
3251 iotag
= irsp
->ulpIoTag
;
3254 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3255 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3256 ulp_status
, ulp_word4
, did
);
3258 /* ELS cmd tag <ulpIoTag> completes */
3259 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3260 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
3261 iotag
, ulp_status
, ulp_word4
, tmo
);
3263 /* Check to see if link went down during discovery */
3264 lpfc_els_chk_latt(vport
);
3266 free_ndlp
= cmdiocb
->ndlp
;
3268 lpfc_els_free_iocb(phba
, cmdiocb
);
3269 lpfc_nlp_put(free_ndlp
);
3273 * lpfc_reg_fab_ctrl_node - RPI register the fabric controller node.
3274 * @vport: pointer to lpfc_vport data structure.
3275 * @fc_ndlp: pointer to the fabric controller (0xfffffd) node.
3277 * This routine registers the rpi assigned to the fabric controller
3278 * NPort_ID (0xfffffd) with the port and moves the node to UNMAPPED
3279 * state triggering a registration with the SCSI transport.
3281 * This routine is single out because the fabric controller node
3282 * does not receive a PLOGI. This routine is consumed by the
3283 * SCR and RDF ELS commands. Callers are expected to qualify
3287 lpfc_reg_fab_ctrl_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*fc_ndlp
)
3290 struct lpfc_hba
*phba
= vport
->phba
;
3291 struct lpfc_nodelist
*ns_ndlp
;
3294 if (fc_ndlp
->nlp_flag
& NLP_RPI_REGISTERED
)
3297 ns_ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
3301 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
3302 "0935 %s: Reg FC RPI x%x on FC DID x%x NSSte: x%x\n",
3303 __func__
, fc_ndlp
->nlp_rpi
, fc_ndlp
->nlp_DID
,
3304 ns_ndlp
->nlp_state
);
3305 if (ns_ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
)
3308 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3310 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
3311 "0936 %s: no memory for reg_login "
3312 "Data: x%x x%x x%x x%x\n", __func__
,
3313 fc_ndlp
->nlp_DID
, fc_ndlp
->nlp_state
,
3314 fc_ndlp
->nlp_flag
, fc_ndlp
->nlp_rpi
);
3317 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, fc_ndlp
->nlp_DID
,
3318 (u8
*)&vport
->fc_sparam
, mbox
, fc_ndlp
->nlp_rpi
);
3324 fc_ndlp
->nlp_flag
|= NLP_REG_LOGIN_SEND
;
3325 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fc_reg_login
;
3326 mbox
->ctx_ndlp
= lpfc_nlp_get(fc_ndlp
);
3327 if (!mbox
->ctx_ndlp
) {
3332 mbox
->vport
= vport
;
3333 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
3334 if (rc
== MBX_NOT_FINISHED
) {
3336 lpfc_nlp_put(fc_ndlp
);
3339 /* Success path. Exit. */
3340 lpfc_nlp_set_state(vport
, fc_ndlp
,
3341 NLP_STE_REG_LOGIN_ISSUE
);
3345 lpfc_mbox_rsrc_cleanup(phba
, mbox
, MBOX_THD_UNLOCKED
);
3346 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
3347 "0938 %s: failed to format reg_login "
3348 "Data: x%x x%x x%x x%x\n", __func__
,
3349 fc_ndlp
->nlp_DID
, fc_ndlp
->nlp_state
,
3350 fc_ndlp
->nlp_flag
, fc_ndlp
->nlp_rpi
);
3355 * lpfc_cmpl_els_disc_cmd - Completion callback function for Discovery ELS cmd
3356 * @phba: pointer to lpfc hba data structure.
3357 * @cmdiocb: pointer to lpfc command iocb data structure.
3358 * @rspiocb: pointer to lpfc response iocb data structure.
3360 * This routine is a generic completion callback function for Discovery ELS cmd.
3361 * Currently used by the ELS command issuing routines for the ELS State Change
3362 * Request (SCR), lpfc_issue_els_scr() and the ELS RDF, lpfc_issue_els_rdf().
3363 * These commands will be retried once only for ELS timeout errors.
3366 lpfc_cmpl_els_disc_cmd(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3367 struct lpfc_iocbq
*rspiocb
)
3369 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3371 struct lpfc_els_rdf_rsp
*prdf
;
3372 struct lpfc_dmabuf
*pcmd
, *prsp
;
3375 struct lpfc_nodelist
*ndlp
= cmdiocb
->ndlp
;
3376 u32 ulp_status
, ulp_word4
, tmo
, did
, iotag
;
3378 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
3379 ulp_word4
= get_job_word4(phba
, rspiocb
);
3380 did
= get_job_els_rsp64_did(phba
, cmdiocb
);
3382 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3383 tmo
= get_wqe_tmo(cmdiocb
);
3384 iotag
= get_wqe_reqtag(cmdiocb
);
3386 irsp
= &rspiocb
->iocb
;
3387 tmo
= irsp
->ulpTimeout
;
3388 iotag
= irsp
->ulpIoTag
;
3391 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3392 "ELS cmd cmpl: status:x%x/x%x did:x%x",
3393 ulp_status
, ulp_word4
, did
);
3395 /* ELS cmd tag <ulpIoTag> completes */
3396 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
| LOG_CGN_MGMT
,
3397 "0217 ELS cmd tag x%x completes Data: x%x x%x x%x x%x\n",
3398 iotag
, ulp_status
, ulp_word4
, tmo
, cmdiocb
->retry
);
3400 pcmd
= cmdiocb
->cmd_dmabuf
;
3404 pdata
= (u32
*)pcmd
->virt
;
3409 /* Only 1 retry for ELS Timeout only */
3410 if (ulp_status
== IOSTAT_LOCAL_REJECT
&&
3411 ((ulp_word4
& IOERR_PARAM_MASK
) ==
3412 IOERR_SEQUENCE_TIMEOUT
)) {
3414 if (cmdiocb
->retry
<= 1) {
3417 lpfc_issue_els_scr(vport
, cmdiocb
->retry
);
3420 lpfc_issue_els_edc(vport
, cmdiocb
->retry
);
3423 lpfc_issue_els_rdf(vport
, cmdiocb
->retry
);
3428 phba
->fc_stat
.elsRetryExceeded
++;
3430 if (cmd
== ELS_CMD_EDC
) {
3431 /* must be called before checking uplStatus and returning */
3432 lpfc_cmpl_els_edc(phba
, cmdiocb
, rspiocb
);
3436 /* ELS discovery cmd completes with error */
3437 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
| LOG_CGN_MGMT
,
3438 "4203 ELS cmd x%x error: x%x x%X\n", cmd
,
3439 ulp_status
, ulp_word4
);
3443 /* The RDF response doesn't have any impact on the running driver
3444 * but the notification descriptors are dumped here for support.
3446 if (cmd
== ELS_CMD_RDF
) {
3449 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
3453 prdf
= (struct lpfc_els_rdf_rsp
*)prsp
->virt
;
3456 if (!lpfc_is_els_acc_rsp(prsp
))
3459 for (i
= 0; i
< ELS_RDF_REG_TAG_CNT
&&
3460 i
< be32_to_cpu(prdf
->reg_d1
.reg_desc
.count
); i
++)
3461 lpfc_printf_vlog(vport
, KERN_INFO
,
3462 LOG_ELS
| LOG_CGN_MGMT
,
3463 "4677 Fabric RDF Notification Grant "
3464 "Data: 0x%08x Reg: %x %x\n",
3466 prdf
->reg_d1
.desc_tags
[i
]),
3467 phba
->cgn_reg_signal
,
3468 phba
->cgn_reg_fpin
);
3472 /* Check to see if link went down during discovery */
3473 lpfc_els_chk_latt(vport
);
3474 lpfc_els_free_iocb(phba
, cmdiocb
);
3480 * lpfc_issue_els_scr - Issue a scr to an node on a vport
3481 * @vport: pointer to a host virtual N_Port data structure.
3482 * @retry: retry counter for the command IOCB.
3484 * This routine issues a State Change Request (SCR) to a fabric node
3485 * on a @vport. The remote node is Fabric Controller (0xfffffd). It
3486 * first search the @vport node list to find the matching ndlp. If no such
3487 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
3488 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
3489 * routine is invoked to send the SCR IOCB.
3491 * Note that the ndlp reference count will be incremented by 1 for holding the
3492 * ndlp and the reference to ndlp will be stored into the ndlp field of
3493 * the IOCB for the completion callback function to the SCR ELS command.
3496 * 0 - Successfully issued scr command
3497 * 1 - Failed to issue scr command
3500 lpfc_issue_els_scr(struct lpfc_vport
*vport
, uint8_t retry
)
3503 struct lpfc_hba
*phba
= vport
->phba
;
3504 struct lpfc_iocbq
*elsiocb
;
3507 struct lpfc_nodelist
*ndlp
;
3509 cmdsize
= (sizeof(uint32_t) + sizeof(SCR
));
3511 ndlp
= lpfc_findnode_did(vport
, Fabric_Cntl_DID
);
3513 ndlp
= lpfc_nlp_init(vport
, Fabric_Cntl_DID
);
3516 lpfc_enqueue_node(vport
, ndlp
);
3519 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
3520 ndlp
->nlp_DID
, ELS_CMD_SCR
);
3524 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3525 rc
= lpfc_reg_fab_ctrl_node(vport
, ndlp
);
3527 lpfc_els_free_iocb(phba
, elsiocb
);
3528 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_NODE
,
3529 "0937 %s: Failed to reg fc node, rc %d\n",
3534 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
3536 *((uint32_t *) (pcmd
)) = ELS_CMD_SCR
;
3537 pcmd
+= sizeof(uint32_t);
3539 /* For SCR, remainder of payload is SCR parameter page */
3540 memset(pcmd
, 0, sizeof(SCR
));
3541 ((SCR
*) pcmd
)->Function
= SCR_FUNC_FULL
;
3543 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3544 "Issue SCR: did:x%x",
3545 ndlp
->nlp_DID
, 0, 0);
3547 phba
->fc_stat
.elsXmitSCR
++;
3548 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_disc_cmd
;
3549 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
3550 if (!elsiocb
->ndlp
) {
3551 lpfc_els_free_iocb(phba
, elsiocb
);
3555 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3556 "Issue SCR: did:x%x refcnt %d",
3557 ndlp
->nlp_DID
, kref_read(&ndlp
->kref
), 0);
3559 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3560 if (rc
== IOCB_ERROR
) {
3561 lpfc_els_free_iocb(phba
, elsiocb
);
3570 * lpfc_issue_els_rscn - Issue an RSCN to the Fabric Controller (Fabric)
3571 * or the other nport (pt2pt).
3572 * @vport: pointer to a host virtual N_Port data structure.
3573 * @retry: number of retries to the command IOCB.
3575 * This routine issues a RSCN to the Fabric Controller (DID 0xFFFFFD)
3576 * when connected to a fabric, or to the remote port when connected
3577 * in point-to-point mode. When sent to the Fabric Controller, it will
3578 * replay the RSCN to registered recipients.
3580 * Note that the ndlp reference count will be incremented by 1 for holding the
3581 * ndlp and the reference to ndlp will be stored into the ndlp field of
3582 * the IOCB for the completion callback function to the RSCN ELS command.
3585 * 0 - Successfully issued RSCN command
3586 * 1 - Failed to issue RSCN command
3589 lpfc_issue_els_rscn(struct lpfc_vport
*vport
, uint8_t retry
)
3592 struct lpfc_hba
*phba
= vport
->phba
;
3593 struct lpfc_iocbq
*elsiocb
;
3594 struct lpfc_nodelist
*ndlp
;
3596 struct fc_els_rscn rscn
;
3597 struct fc_els_rscn_page portid
;
3600 uint16_t cmdsize
= sizeof(*event
);
3602 /* Not supported for private loop */
3603 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
&&
3604 !test_bit(FC_PUBLIC_LOOP
, &vport
->fc_flag
))
3607 if (test_bit(FC_PT2PT
, &vport
->fc_flag
)) {
3608 /* find any mapped nport - that would be the other nport */
3609 ndlp
= lpfc_findnode_mapped(vport
);
3613 nportid
= FC_FID_FCTRL
;
3614 /* find the fabric controller node */
3615 ndlp
= lpfc_findnode_did(vport
, nportid
);
3617 /* if one didn't exist, make one */
3618 ndlp
= lpfc_nlp_init(vport
, nportid
);
3621 lpfc_enqueue_node(vport
, ndlp
);
3625 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
3626 ndlp
->nlp_DID
, ELS_CMD_RSCN_XMT
);
3631 event
= elsiocb
->cmd_dmabuf
->virt
;
3633 event
->rscn
.rscn_cmd
= ELS_RSCN
;
3634 event
->rscn
.rscn_page_len
= sizeof(struct fc_els_rscn_page
);
3635 event
->rscn
.rscn_plen
= cpu_to_be16(cmdsize
);
3637 nportid
= vport
->fc_myDID
;
3638 /* appears that page flags must be 0 for fabric to broadcast RSCN */
3639 event
->portid
.rscn_page_flags
= 0;
3640 event
->portid
.rscn_fid
[0] = (nportid
& 0x00FF0000) >> 16;
3641 event
->portid
.rscn_fid
[1] = (nportid
& 0x0000FF00) >> 8;
3642 event
->portid
.rscn_fid
[2] = nportid
& 0x000000FF;
3644 phba
->fc_stat
.elsXmitRSCN
++;
3645 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_cmd
;
3646 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
3647 if (!elsiocb
->ndlp
) {
3648 lpfc_els_free_iocb(phba
, elsiocb
);
3652 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3653 "Issue RSCN: did:x%x",
3654 ndlp
->nlp_DID
, 0, 0);
3656 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3657 if (rc
== IOCB_ERROR
) {
3658 lpfc_els_free_iocb(phba
, elsiocb
);
3667 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
3668 * @vport: pointer to a host virtual N_Port data structure.
3669 * @nportid: N_Port identifier to the remote node.
3670 * @retry: number of retries to the command IOCB.
3672 * This routine issues a Fibre Channel Address Resolution Response
3673 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3674 * is passed into the function. It first search the @vport node list to find
3675 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3676 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3677 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3679 * Note that the ndlp reference count will be incremented by 1 for holding the
3680 * ndlp and the reference to ndlp will be stored into the ndlp field of
3681 * the IOCB for the completion callback function to the FARPR ELS command.
3684 * 0 - Successfully issued farpr command
3685 * 1 - Failed to issue farpr command
3688 lpfc_issue_els_farpr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
3691 struct lpfc_hba
*phba
= vport
->phba
;
3692 struct lpfc_iocbq
*elsiocb
;
3697 struct lpfc_nodelist
*ondlp
;
3698 struct lpfc_nodelist
*ndlp
;
3700 cmdsize
= (sizeof(uint32_t) + sizeof(FARP
));
3702 ndlp
= lpfc_findnode_did(vport
, nportid
);
3704 ndlp
= lpfc_nlp_init(vport
, nportid
);
3707 lpfc_enqueue_node(vport
, ndlp
);
3710 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
3711 ndlp
->nlp_DID
, ELS_CMD_FARPR
);
3715 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
3717 *((uint32_t *) (pcmd
)) = ELS_CMD_FARPR
;
3718 pcmd
+= sizeof(uint32_t);
3720 /* Fill in FARPR payload */
3721 fp
= (FARP
*) (pcmd
);
3722 memset(fp
, 0, sizeof(FARP
));
3723 lp
= (uint32_t *) pcmd
;
3724 *lp
++ = be32_to_cpu(nportid
);
3725 *lp
++ = be32_to_cpu(vport
->fc_myDID
);
3727 fp
->Mflags
= (FARP_MATCH_PORT
| FARP_MATCH_NODE
);
3729 memcpy(&fp
->RportName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
3730 memcpy(&fp
->RnodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
3731 ondlp
= lpfc_findnode_did(vport
, nportid
);
3733 memcpy(&fp
->OportName
, &ondlp
->nlp_portname
,
3734 sizeof(struct lpfc_name
));
3735 memcpy(&fp
->OnodeName
, &ondlp
->nlp_nodename
,
3736 sizeof(struct lpfc_name
));
3739 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3740 "Issue FARPR: did:x%x",
3741 ndlp
->nlp_DID
, 0, 0);
3743 phba
->fc_stat
.elsXmitFARPR
++;
3744 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_cmd
;
3745 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
3746 if (!elsiocb
->ndlp
) {
3747 lpfc_els_free_iocb(phba
, elsiocb
);
3751 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3752 if (rc
== IOCB_ERROR
) {
3753 /* The additional lpfc_nlp_put will cause the following
3754 * lpfc_els_free_iocb routine to trigger the release of
3757 lpfc_els_free_iocb(phba
, elsiocb
);
3761 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3762 * trigger the release of the node.
3764 /* Don't release reference count as RDF is likely outstanding */
3769 * lpfc_issue_els_rdf - Register for diagnostic functions from the fabric.
3770 * @vport: pointer to a host virtual N_Port data structure.
3771 * @retry: retry counter for the command IOCB.
3773 * This routine issues an ELS RDF to the Fabric Controller to register
3774 * for diagnostic functions.
3776 * Note that the ndlp reference count will be incremented by 1 for holding the
3777 * ndlp and the reference to ndlp will be stored into the ndlp field of
3778 * the IOCB for the completion callback function to the RDF ELS command.
3781 * 0 - Successfully issued rdf command
3782 * 1 - Failed to issue rdf command
3785 lpfc_issue_els_rdf(struct lpfc_vport
*vport
, uint8_t retry
)
3787 struct lpfc_hba
*phba
= vport
->phba
;
3788 struct lpfc_iocbq
*elsiocb
;
3789 struct lpfc_els_rdf_req
*prdf
;
3790 struct lpfc_nodelist
*ndlp
;
3794 cmdsize
= sizeof(*prdf
);
3796 ndlp
= lpfc_findnode_did(vport
, Fabric_Cntl_DID
);
3798 ndlp
= lpfc_nlp_init(vport
, Fabric_Cntl_DID
);
3801 lpfc_enqueue_node(vport
, ndlp
);
3804 /* RDF ELS is not required on an NPIV VN_Port. */
3805 if (vport
->port_type
== LPFC_NPIV_PORT
)
3808 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
3809 ndlp
->nlp_DID
, ELS_CMD_RDF
);
3813 /* Configure the payload for the supported FPIN events. */
3814 prdf
= (struct lpfc_els_rdf_req
*)elsiocb
->cmd_dmabuf
->virt
;
3815 memset(prdf
, 0, cmdsize
);
3816 prdf
->rdf
.fpin_cmd
= ELS_RDF
;
3817 prdf
->rdf
.desc_len
= cpu_to_be32(sizeof(struct lpfc_els_rdf_req
) -
3818 sizeof(struct fc_els_rdf
));
3819 prdf
->reg_d1
.reg_desc
.desc_tag
= cpu_to_be32(ELS_DTAG_FPIN_REGISTER
);
3820 prdf
->reg_d1
.reg_desc
.desc_len
= cpu_to_be32(
3821 FC_TLV_DESC_LENGTH_FROM_SZ(prdf
->reg_d1
));
3822 prdf
->reg_d1
.reg_desc
.count
= cpu_to_be32(ELS_RDF_REG_TAG_CNT
);
3823 prdf
->reg_d1
.desc_tags
[0] = cpu_to_be32(ELS_DTAG_LNK_INTEGRITY
);
3824 prdf
->reg_d1
.desc_tags
[1] = cpu_to_be32(ELS_DTAG_DELIVERY
);
3825 prdf
->reg_d1
.desc_tags
[2] = cpu_to_be32(ELS_DTAG_PEER_CONGEST
);
3826 prdf
->reg_d1
.desc_tags
[3] = cpu_to_be32(ELS_DTAG_CONGESTION
);
3828 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
| LOG_CGN_MGMT
,
3829 "6444 Xmit RDF to remote NPORT x%x Reg: %x %x\n",
3830 ndlp
->nlp_DID
, phba
->cgn_reg_signal
,
3831 phba
->cgn_reg_fpin
);
3833 phba
->cgn_fpin_frequency
= LPFC_FPIN_INIT_FREQ
;
3834 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_disc_cmd
;
3835 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
3836 if (!elsiocb
->ndlp
) {
3837 lpfc_els_free_iocb(phba
, elsiocb
);
3841 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3842 "Issue RDF: did:x%x refcnt %d",
3843 ndlp
->nlp_DID
, kref_read(&ndlp
->kref
), 0);
3845 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3846 if (rc
== IOCB_ERROR
) {
3847 lpfc_els_free_iocb(phba
, elsiocb
);
3855 * lpfc_els_rcv_rdf - Receive RDF ELS request from the fabric.
3856 * @vport: pointer to a host virtual N_Port data structure.
3857 * @cmdiocb: pointer to lpfc command iocb data structure.
3858 * @ndlp: pointer to a node-list data structure.
3860 * A received RDF implies a possible change to fabric supported diagnostic
3861 * functions. This routine sends LS_ACC and then has the Nx_Port issue a new
3862 * RDF request to reregister for supported diagnostic functions.
3866 * -EIO - Failed to process received RDF
3869 lpfc_els_rcv_rdf(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3870 struct lpfc_nodelist
*ndlp
)
3873 if (lpfc_els_rsp_acc(vport
, ELS_CMD_RDF
, cmdiocb
, ndlp
, NULL
)) {
3874 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
| LOG_CGN_MGMT
,
3875 "1623 Failed to RDF_ACC from x%x for x%x\n",
3876 ndlp
->nlp_DID
, vport
->fc_myDID
);
3880 /* Issue new RDF for reregistering */
3881 if (lpfc_issue_els_rdf(vport
, 0)) {
3882 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
| LOG_CGN_MGMT
,
3883 "2623 Failed to re register RDF for x%x\n",
3892 * lpfc_least_capable_settings - helper function for EDC rsp processing
3893 * @phba: pointer to lpfc hba data structure.
3894 * @pcgd: pointer to congestion detection descriptor in EDC rsp.
3896 * This helper routine determines the least capable setting for
3897 * congestion signals, signal freq, including scale, from the
3898 * congestion detection descriptor in the EDC rsp. The routine
3899 * sets @phba values in preparation for a set_featues mailbox.
3902 lpfc_least_capable_settings(struct lpfc_hba
*phba
,
3903 struct fc_diag_cg_sig_desc
*pcgd
)
3905 u32 rsp_sig_cap
= 0, drv_sig_cap
= 0;
3906 u32 rsp_sig_freq_cyc
= 0, rsp_sig_freq_scale
= 0;
3908 /* Get rsp signal and frequency capabilities. */
3909 rsp_sig_cap
= be32_to_cpu(pcgd
->xmt_signal_capability
);
3910 rsp_sig_freq_cyc
= be16_to_cpu(pcgd
->xmt_signal_frequency
.count
);
3911 rsp_sig_freq_scale
= be16_to_cpu(pcgd
->xmt_signal_frequency
.units
);
3913 /* If the Fport does not support signals. Set FPIN only */
3914 if (rsp_sig_cap
== EDC_CG_SIG_NOTSUPPORTED
)
3915 goto out_no_support
;
3917 /* Apply the xmt scale to the xmt cycle to get the correct frequency.
3918 * Adapter default is 100 millisSeconds. Convert all xmt cycle values
3921 switch (rsp_sig_freq_scale
) {
3922 case EDC_CG_SIGFREQ_SEC
:
3923 rsp_sig_freq_cyc
*= MSEC_PER_SEC
;
3925 case EDC_CG_SIGFREQ_MSEC
:
3926 rsp_sig_freq_cyc
= 1;
3929 goto out_no_support
;
3932 /* Convenient shorthand. */
3933 drv_sig_cap
= phba
->cgn_reg_signal
;
3935 /* Choose the least capable frequency. */
3936 if (rsp_sig_freq_cyc
> phba
->cgn_sig_freq
)
3937 phba
->cgn_sig_freq
= rsp_sig_freq_cyc
;
3939 /* Should be some common signals support. Settle on least capable
3940 * signal and adjust FPIN values. Initialize defaults to ease the
3943 phba
->cgn_reg_fpin
= LPFC_CGN_FPIN_WARN
| LPFC_CGN_FPIN_ALARM
;
3944 phba
->cgn_reg_signal
= EDC_CG_SIG_NOTSUPPORTED
;
3945 if (rsp_sig_cap
== EDC_CG_SIG_WARN_ONLY
&&
3946 (drv_sig_cap
== EDC_CG_SIG_WARN_ONLY
||
3947 drv_sig_cap
== EDC_CG_SIG_WARN_ALARM
)) {
3948 phba
->cgn_reg_signal
= EDC_CG_SIG_WARN_ONLY
;
3949 phba
->cgn_reg_fpin
&= ~LPFC_CGN_FPIN_WARN
;
3951 if (rsp_sig_cap
== EDC_CG_SIG_WARN_ALARM
) {
3952 if (drv_sig_cap
== EDC_CG_SIG_WARN_ALARM
) {
3953 phba
->cgn_reg_signal
= EDC_CG_SIG_WARN_ALARM
;
3954 phba
->cgn_reg_fpin
= LPFC_CGN_FPIN_NONE
;
3956 if (drv_sig_cap
== EDC_CG_SIG_WARN_ONLY
) {
3957 phba
->cgn_reg_signal
= EDC_CG_SIG_WARN_ONLY
;
3958 phba
->cgn_reg_fpin
&= ~LPFC_CGN_FPIN_WARN
;
3962 /* We are NOT recording signal frequency in congestion info buffer */
3966 phba
->cgn_reg_signal
= EDC_CG_SIG_NOTSUPPORTED
;
3967 phba
->cgn_sig_freq
= 0;
3968 phba
->cgn_reg_fpin
= LPFC_CGN_FPIN_ALARM
| LPFC_CGN_FPIN_WARN
;
3971 DECLARE_ENUM2STR_LOOKUP(lpfc_get_tlv_dtag_nm
, fc_ls_tlv_dtag
,
3972 FC_LS_TLV_DTAG_INIT
);
3975 * lpfc_cmpl_els_edc - Completion callback function for EDC
3976 * @phba: pointer to lpfc hba data structure.
3977 * @cmdiocb: pointer to lpfc command iocb data structure.
3978 * @rspiocb: pointer to lpfc response iocb data structure.
3980 * This routine is the completion callback function for issuing the Exchange
3981 * Diagnostic Capabilities (EDC) command. The driver issues an EDC to
3982 * notify the FPort of its Congestion and Link Fault capabilities. This
3983 * routine parses the FPort's response and decides on the least common
3984 * values applicable to both FPort and NPort for Warnings and Alarms that
3985 * are communicated via hardware signals.
3988 lpfc_cmpl_els_edc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3989 struct lpfc_iocbq
*rspiocb
)
3992 struct fc_els_edc_resp
*edc_rsp
;
3993 struct fc_tlv_desc
*tlv
;
3994 struct fc_diag_cg_sig_desc
*pcgd
;
3995 struct fc_diag_lnkflt_desc
*plnkflt
;
3996 struct lpfc_dmabuf
*pcmd
, *prsp
;
3997 const char *dtag_nm
;
3999 int desc_cnt
= 0, bytes_remain
;
4000 bool rcv_cap_desc
= false;
4001 struct lpfc_nodelist
*ndlp
;
4002 u32 ulp_status
, ulp_word4
, tmo
, did
, iotag
;
4004 ndlp
= cmdiocb
->ndlp
;
4006 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
4007 ulp_word4
= get_job_word4(phba
, rspiocb
);
4008 did
= get_job_els_rsp64_did(phba
, rspiocb
);
4010 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4011 tmo
= get_wqe_tmo(rspiocb
);
4012 iotag
= get_wqe_reqtag(rspiocb
);
4014 irsp_iocb
= &rspiocb
->iocb
;
4015 tmo
= irsp_iocb
->ulpTimeout
;
4016 iotag
= irsp_iocb
->ulpIoTag
;
4019 lpfc_debugfs_disc_trc(phba
->pport
, LPFC_DISC_TRC_ELS_CMD
,
4020 "EDC cmpl: status:x%x/x%x did:x%x",
4021 ulp_status
, ulp_word4
, did
);
4023 /* ELS cmd tag <ulpIoTag> completes */
4024 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
| LOG_CGN_MGMT
,
4025 "4201 EDC cmd tag x%x completes Data: x%x x%x x%x\n",
4026 iotag
, ulp_status
, ulp_word4
, tmo
);
4028 pcmd
= cmdiocb
->cmd_dmabuf
;
4032 pdata
= (u32
*)pcmd
->virt
;
4036 /* Need to clear signal values, send features MB and RDF with FPIN. */
4040 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
4044 edc_rsp
= prsp
->virt
;
4048 /* ELS cmd tag <ulpIoTag> completes */
4049 lpfc_printf_log(phba
, KERN_INFO
,
4050 LOG_ELS
| LOG_CGN_MGMT
| LOG_LDS_EVENT
,
4051 "4676 Fabric EDC Rsp: "
4053 edc_rsp
->acc_hdr
.la_cmd
,
4054 be32_to_cpu(edc_rsp
->desc_list_len
));
4056 if (!lpfc_is_els_acc_rsp(prsp
))
4060 * Payload length in bytes is the response descriptor list
4061 * length minus the 12 bytes of Link Service Request
4062 * Information descriptor in the reply.
4064 bytes_remain
= be32_to_cpu(edc_rsp
->desc_list_len
) -
4065 sizeof(struct fc_els_lsri_desc
);
4066 if (bytes_remain
<= 0)
4069 tlv
= edc_rsp
->desc
;
4072 * cycle through EDC diagnostic descriptors to find the
4073 * congestion signaling capability descriptor
4075 while (bytes_remain
) {
4076 if (bytes_remain
< FC_TLV_DESC_HDR_SZ
) {
4077 lpfc_printf_log(phba
, KERN_WARNING
, LOG_CGN_MGMT
,
4078 "6461 Truncated TLV hdr on "
4079 "Diagnostic descriptor[%d]\n",
4084 dtag
= be32_to_cpu(tlv
->desc_tag
);
4086 case ELS_DTAG_LNK_FAULT_CAP
:
4087 if (bytes_remain
< FC_TLV_DESC_SZ_FROM_LENGTH(tlv
) ||
4088 FC_TLV_DESC_SZ_FROM_LENGTH(tlv
) !=
4089 sizeof(struct fc_diag_lnkflt_desc
)) {
4090 lpfc_printf_log(phba
, KERN_WARNING
,
4091 LOG_ELS
| LOG_CGN_MGMT
| LOG_LDS_EVENT
,
4092 "6462 Truncated Link Fault Diagnostic "
4093 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
4094 desc_cnt
, bytes_remain
,
4095 FC_TLV_DESC_SZ_FROM_LENGTH(tlv
),
4096 sizeof(struct fc_diag_lnkflt_desc
));
4099 plnkflt
= (struct fc_diag_lnkflt_desc
*)tlv
;
4100 lpfc_printf_log(phba
, KERN_INFO
,
4101 LOG_ELS
| LOG_LDS_EVENT
,
4102 "4617 Link Fault Desc Data: 0x%08x 0x%08x "
4103 "0x%08x 0x%08x 0x%08x\n",
4104 be32_to_cpu(plnkflt
->desc_tag
),
4105 be32_to_cpu(plnkflt
->desc_len
),
4107 plnkflt
->degrade_activate_threshold
),
4109 plnkflt
->degrade_deactivate_threshold
),
4110 be32_to_cpu(plnkflt
->fec_degrade_interval
));
4112 case ELS_DTAG_CG_SIGNAL_CAP
:
4113 if (bytes_remain
< FC_TLV_DESC_SZ_FROM_LENGTH(tlv
) ||
4114 FC_TLV_DESC_SZ_FROM_LENGTH(tlv
) !=
4115 sizeof(struct fc_diag_cg_sig_desc
)) {
4117 phba
, KERN_WARNING
, LOG_CGN_MGMT
,
4118 "6463 Truncated Cgn Signal Diagnostic "
4119 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
4120 desc_cnt
, bytes_remain
,
4121 FC_TLV_DESC_SZ_FROM_LENGTH(tlv
),
4122 sizeof(struct fc_diag_cg_sig_desc
));
4126 pcgd
= (struct fc_diag_cg_sig_desc
*)tlv
;
4128 phba
, KERN_INFO
, LOG_ELS
| LOG_CGN_MGMT
,
4129 "4616 CGN Desc Data: 0x%08x 0x%08x "
4130 "0x%08x 0x%04x 0x%04x 0x%08x 0x%04x 0x%04x\n",
4131 be32_to_cpu(pcgd
->desc_tag
),
4132 be32_to_cpu(pcgd
->desc_len
),
4133 be32_to_cpu(pcgd
->xmt_signal_capability
),
4134 be16_to_cpu(pcgd
->xmt_signal_frequency
.count
),
4135 be16_to_cpu(pcgd
->xmt_signal_frequency
.units
),
4136 be32_to_cpu(pcgd
->rcv_signal_capability
),
4137 be16_to_cpu(pcgd
->rcv_signal_frequency
.count
),
4138 be16_to_cpu(pcgd
->rcv_signal_frequency
.units
));
4140 /* Compare driver and Fport capabilities and choose
4143 lpfc_least_capable_settings(phba
, pcgd
);
4144 rcv_cap_desc
= true;
4147 dtag_nm
= lpfc_get_tlv_dtag_nm(dtag
);
4148 lpfc_printf_log(phba
, KERN_WARNING
, LOG_CGN_MGMT
,
4149 "4919 unknown Diagnostic "
4150 "Descriptor[%d]: tag x%x (%s)\n",
4151 desc_cnt
, dtag
, dtag_nm
);
4154 bytes_remain
-= FC_TLV_DESC_SZ_FROM_LENGTH(tlv
);
4155 tlv
= fc_tlv_next_desc(tlv
);
4160 if (!rcv_cap_desc
) {
4161 phba
->cgn_reg_fpin
= LPFC_CGN_FPIN_ALARM
| LPFC_CGN_FPIN_WARN
;
4162 phba
->cgn_reg_signal
= EDC_CG_SIG_NOTSUPPORTED
;
4163 phba
->cgn_sig_freq
= 0;
4164 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
| LOG_CGN_MGMT
,
4165 "4202 EDC rsp error - sending RDF "
4166 "for FPIN only.\n");
4169 lpfc_config_cgn_signal(phba
);
4171 /* Check to see if link went down during discovery */
4172 lpfc_els_chk_latt(phba
->pport
);
4173 lpfc_debugfs_disc_trc(phba
->pport
, LPFC_DISC_TRC_ELS_CMD
,
4174 "EDC Cmpl: did:x%x refcnt %d",
4175 ndlp
->nlp_DID
, kref_read(&ndlp
->kref
), 0);
4176 lpfc_els_free_iocb(phba
, cmdiocb
);
4181 lpfc_format_edc_lft_desc(struct lpfc_hba
*phba
, struct fc_tlv_desc
*tlv
)
4183 struct fc_diag_lnkflt_desc
*lft
= (struct fc_diag_lnkflt_desc
*)tlv
;
4185 lft
->desc_tag
= cpu_to_be32(ELS_DTAG_LNK_FAULT_CAP
);
4186 lft
->desc_len
= cpu_to_be32(
4187 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_diag_lnkflt_desc
));
4189 lft
->degrade_activate_threshold
=
4190 cpu_to_be32(phba
->degrade_activate_threshold
);
4191 lft
->degrade_deactivate_threshold
=
4192 cpu_to_be32(phba
->degrade_deactivate_threshold
);
4193 lft
->fec_degrade_interval
= cpu_to_be32(phba
->fec_degrade_interval
);
4197 lpfc_format_edc_cgn_desc(struct lpfc_hba
*phba
, struct fc_tlv_desc
*tlv
)
4199 struct fc_diag_cg_sig_desc
*cgd
= (struct fc_diag_cg_sig_desc
*)tlv
;
4201 /* We are assuming cgd was zero'ed before calling this routine */
4203 /* Configure the congestion detection capability */
4204 cgd
->desc_tag
= cpu_to_be32(ELS_DTAG_CG_SIGNAL_CAP
);
4206 /* Descriptor len doesn't include the tag or len fields. */
4207 cgd
->desc_len
= cpu_to_be32(
4208 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_diag_cg_sig_desc
));
4210 /* xmt_signal_capability already set to EDC_CG_SIG_NOTSUPPORTED.
4211 * xmt_signal_frequency.count already set to 0.
4212 * xmt_signal_frequency.units already set to 0.
4215 if (phba
->cmf_active_mode
== LPFC_CFG_OFF
) {
4216 /* rcv_signal_capability already set to EDC_CG_SIG_NOTSUPPORTED.
4217 * rcv_signal_frequency.count already set to 0.
4218 * rcv_signal_frequency.units already set to 0.
4220 phba
->cgn_sig_freq
= 0;
4223 switch (phba
->cgn_reg_signal
) {
4224 case EDC_CG_SIG_WARN_ONLY
:
4225 cgd
->rcv_signal_capability
= cpu_to_be32(EDC_CG_SIG_WARN_ONLY
);
4227 case EDC_CG_SIG_WARN_ALARM
:
4228 cgd
->rcv_signal_capability
= cpu_to_be32(EDC_CG_SIG_WARN_ALARM
);
4231 /* rcv_signal_capability left 0 thus no support */
4235 /* We start negotiation with lpfc_fabric_cgn_frequency, after
4236 * the completion we settle on the higher frequency.
4238 cgd
->rcv_signal_frequency
.count
=
4239 cpu_to_be16(lpfc_fabric_cgn_frequency
);
4240 cgd
->rcv_signal_frequency
.units
=
4241 cpu_to_be16(EDC_CG_SIGFREQ_MSEC
);
4245 lpfc_link_is_lds_capable(struct lpfc_hba
*phba
)
4247 if (!(phba
->lmt
& LMT_64Gb
))
4249 if (phba
->sli_rev
!= LPFC_SLI_REV4
)
4252 if (phba
->sli4_hba
.conf_trunk
) {
4253 if (phba
->trunk_link
.phy_lnk_speed
== LPFC_USER_LINK_SPEED_64G
)
4255 } else if (phba
->fc_linkspeed
== LPFC_LINK_SPEED_64GHZ
) {
4262 * lpfc_issue_els_edc - Exchange Diagnostic Capabilities with the fabric.
4263 * @vport: pointer to a host virtual N_Port data structure.
4264 * @retry: retry counter for the command iocb.
4266 * This routine issues an ELS EDC to the F-Port Controller to communicate
4267 * this N_Port's support of hardware signals in its Congestion
4268 * Capabilities Descriptor.
4270 * Note: This routine does not check if one or more signals are
4271 * set in the cgn_reg_signal parameter. The caller makes the
4272 * decision to enforce cgn_reg_signal as nonzero or zero depending
4273 * on the conditions. During Fabric requests, the driver
4274 * requires cgn_reg_signals to be nonzero. But a dynamic request
4275 * to set the congestion mode to OFF from Monitor or Manage
4276 * would correctly issue an EDC with no signals enabled to
4277 * turn off switch functionality and then update the FW.
4280 * 0 - Successfully issued edc command
4281 * 1 - Failed to issue edc command
4284 lpfc_issue_els_edc(struct lpfc_vport
*vport
, uint8_t retry
)
4286 struct lpfc_hba
*phba
= vport
->phba
;
4287 struct lpfc_iocbq
*elsiocb
;
4288 struct fc_els_edc
*edc_req
;
4289 struct fc_tlv_desc
*tlv
;
4291 struct lpfc_nodelist
*ndlp
;
4293 u32 cgn_desc_size
, lft_desc_size
;
4296 if (vport
->port_type
== LPFC_NPIV_PORT
)
4299 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
4300 if (!ndlp
|| ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
)
4303 cgn_desc_size
= (phba
->cgn_init_reg_signal
) ?
4304 sizeof(struct fc_diag_cg_sig_desc
) : 0;
4305 lft_desc_size
= (lpfc_link_is_lds_capable(phba
)) ?
4306 sizeof(struct fc_diag_lnkflt_desc
) : 0;
4307 cmdsize
= cgn_desc_size
+ lft_desc_size
;
4309 /* Skip EDC if no applicable descriptors */
4313 cmdsize
+= sizeof(struct fc_els_edc
);
4314 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
4315 ndlp
->nlp_DID
, ELS_CMD_EDC
);
4319 /* Configure the payload for the supported Diagnostics capabilities. */
4320 pcmd
= (u8
*)elsiocb
->cmd_dmabuf
->virt
;
4321 memset(pcmd
, 0, cmdsize
);
4322 edc_req
= (struct fc_els_edc
*)pcmd
;
4323 edc_req
->desc_len
= cpu_to_be32(cgn_desc_size
+ lft_desc_size
);
4324 edc_req
->edc_cmd
= ELS_EDC
;
4325 tlv
= edc_req
->desc
;
4327 if (cgn_desc_size
) {
4328 lpfc_format_edc_cgn_desc(phba
, tlv
);
4329 phba
->cgn_sig_freq
= lpfc_fabric_cgn_frequency
;
4330 tlv
= fc_tlv_next_desc(tlv
);
4334 lpfc_format_edc_lft_desc(phba
, tlv
);
4336 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
| LOG_CGN_MGMT
,
4337 "4623 Xmit EDC to remote "
4338 "NPORT x%x reg_sig x%x reg_fpin:x%x\n",
4339 ndlp
->nlp_DID
, phba
->cgn_reg_signal
,
4340 phba
->cgn_reg_fpin
);
4342 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_disc_cmd
;
4343 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
4344 if (!elsiocb
->ndlp
) {
4345 lpfc_els_free_iocb(phba
, elsiocb
);
4349 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4350 "Issue EDC: did:x%x refcnt %d",
4351 ndlp
->nlp_DID
, kref_read(&ndlp
->kref
), 0);
4352 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4353 if (rc
== IOCB_ERROR
) {
4354 /* The additional lpfc_nlp_put will cause the following
4355 * lpfc_els_free_iocb routine to trigger the rlease of
4358 lpfc_els_free_iocb(phba
, elsiocb
);
4364 phba
->cgn_reg_fpin
= LPFC_CGN_FPIN_WARN
| LPFC_CGN_FPIN_ALARM
;
4365 phba
->cgn_reg_signal
= EDC_CG_SIG_NOTSUPPORTED
;
4366 rc
= lpfc_issue_els_rdf(vport
, 0);
4371 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
4372 * @vport: pointer to a host virtual N_Port data structure.
4373 * @nlp: pointer to a node-list data structure.
4375 * This routine cancels the timer with a delayed IOCB-command retry for
4376 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
4377 * removes the ELS retry event if it presents. In addition, if the
4378 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
4379 * commands are sent for the @vport's nodes that require issuing discovery
4383 lpfc_cancel_retry_delay_tmo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*nlp
)
4385 struct lpfc_work_evt
*evtp
;
4387 if (!(nlp
->nlp_flag
& NLP_DELAY_TMO
))
4389 spin_lock_irq(&nlp
->lock
);
4390 nlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
4391 spin_unlock_irq(&nlp
->lock
);
4392 del_timer_sync(&nlp
->nlp_delayfunc
);
4393 nlp
->nlp_last_elscmd
= 0;
4394 if (!list_empty(&nlp
->els_retry_evt
.evt_listp
)) {
4395 list_del_init(&nlp
->els_retry_evt
.evt_listp
);
4396 /* Decrement nlp reference count held for the delayed retry */
4397 evtp
= &nlp
->els_retry_evt
;
4398 lpfc_nlp_put((struct lpfc_nodelist
*)evtp
->evt_arg1
);
4400 if (nlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
4401 spin_lock_irq(&nlp
->lock
);
4402 nlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
4403 spin_unlock_irq(&nlp
->lock
);
4404 if (vport
->num_disc_nodes
) {
4405 if (vport
->port_state
< LPFC_VPORT_READY
) {
4406 /* Check if there are more ADISCs to be sent */
4407 lpfc_more_adisc(vport
);
4409 /* Check if there are more PLOGIs to be sent */
4410 lpfc_more_plogi(vport
);
4411 if (vport
->num_disc_nodes
== 0) {
4412 clear_bit(FC_NDISC_ACTIVE
,
4414 lpfc_can_disctmo(vport
);
4415 lpfc_end_rscn(vport
);
4424 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
4425 * @t: pointer to the timer function associated data (ndlp).
4427 * This routine is invoked by the ndlp delayed-function timer to check
4428 * whether there is any pending ELS retry event(s) with the node. If not, it
4429 * simply returns. Otherwise, if there is at least one ELS delayed event, it
4430 * adds the delayed events to the HBA work list and invokes the
4431 * lpfc_worker_wake_up() routine to wake up worker thread to process the
4432 * event. Note that lpfc_nlp_get() is called before posting the event to
4433 * the work list to hold reference count of ndlp so that it guarantees the
4434 * reference to ndlp will still be available when the worker thread gets
4435 * to the event associated with the ndlp.
4438 lpfc_els_retry_delay(struct timer_list
*t
)
4440 struct lpfc_nodelist
*ndlp
= from_timer(ndlp
, t
, nlp_delayfunc
);
4441 struct lpfc_vport
*vport
= ndlp
->vport
;
4442 struct lpfc_hba
*phba
= vport
->phba
;
4443 unsigned long flags
;
4444 struct lpfc_work_evt
*evtp
= &ndlp
->els_retry_evt
;
4446 /* Hold a node reference for outstanding queued work */
4447 if (!lpfc_nlp_get(ndlp
))
4450 spin_lock_irqsave(&phba
->hbalock
, flags
);
4451 if (!list_empty(&evtp
->evt_listp
)) {
4452 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4457 evtp
->evt_arg1
= ndlp
;
4458 evtp
->evt
= LPFC_EVT_ELS_RETRY
;
4459 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
4460 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4462 lpfc_worker_wake_up(phba
);
4466 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
4467 * @ndlp: pointer to a node-list data structure.
4469 * This routine is the worker-thread handler for processing the @ndlp delayed
4470 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
4471 * the last ELS command from the associated ndlp and invokes the proper ELS
4472 * function according to the delayed ELS command to retry the command.
4475 lpfc_els_retry_delay_handler(struct lpfc_nodelist
*ndlp
)
4477 struct lpfc_vport
*vport
= ndlp
->vport
;
4478 uint32_t cmd
, retry
;
4480 spin_lock_irq(&ndlp
->lock
);
4481 cmd
= ndlp
->nlp_last_elscmd
;
4482 ndlp
->nlp_last_elscmd
= 0;
4484 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
4485 spin_unlock_irq(&ndlp
->lock
);
4489 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
4490 spin_unlock_irq(&ndlp
->lock
);
4492 * If a discovery event readded nlp_delayfunc after timer
4493 * firing and before processing the timer, cancel the
4496 del_timer_sync(&ndlp
->nlp_delayfunc
);
4497 retry
= ndlp
->nlp_retry
;
4498 ndlp
->nlp_retry
= 0;
4502 lpfc_issue_els_flogi(vport
, ndlp
, retry
);
4505 if (!lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, retry
)) {
4506 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4507 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4511 if (!lpfc_issue_els_adisc(vport
, ndlp
, retry
)) {
4512 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4513 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
4517 case ELS_CMD_NVMEPRLI
:
4518 if (!lpfc_issue_els_prli(vport
, ndlp
, retry
)) {
4519 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4520 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
4524 if (!lpfc_issue_els_logo(vport
, ndlp
, retry
)) {
4525 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4526 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_LOGO_ISSUE
);
4530 if (!test_bit(FC_VPORT_NEEDS_INIT_VPI
, &vport
->fc_flag
))
4531 lpfc_issue_els_fdisc(vport
, ndlp
, retry
);
4538 * lpfc_link_reset - Issue link reset
4539 * @vport: pointer to a virtual N_Port data structure.
4541 * This routine performs link reset by sending INIT_LINK mailbox command.
4542 * For SLI-3 adapter, link attention interrupt is enabled before issuing
4543 * INIT_LINK mailbox command.
4546 * 0 - Link reset initiated successfully
4547 * 1 - Failed to initiate link reset
4550 lpfc_link_reset(struct lpfc_vport
*vport
)
4552 struct lpfc_hba
*phba
= vport
->phba
;
4557 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4558 "2851 Attempt link reset\n");
4559 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4561 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
4562 "2852 Failed to allocate mbox memory");
4566 /* Enable Link attention interrupts */
4567 if (phba
->sli_rev
<= LPFC_SLI_REV3
) {
4568 spin_lock_irq(&phba
->hbalock
);
4569 phba
->sli
.sli_flag
|= LPFC_PROCESS_LA
;
4570 control
= readl(phba
->HCregaddr
);
4571 control
|= HC_LAINT_ENA
;
4572 writel(control
, phba
->HCregaddr
);
4573 readl(phba
->HCregaddr
); /* flush */
4574 spin_unlock_irq(&phba
->hbalock
);
4577 lpfc_init_link(phba
, mbox
, phba
->cfg_topology
,
4578 phba
->cfg_link_speed
);
4579 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4580 mbox
->vport
= vport
;
4581 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4582 if ((rc
!= MBX_BUSY
) && (rc
!= MBX_SUCCESS
)) {
4583 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
4584 "2853 Failed to issue INIT_LINK "
4585 "mbox command, rc:x%x\n", rc
);
4586 mempool_free(mbox
, phba
->mbox_mem_pool
);
4594 * lpfc_els_retry - Make retry decision on an els command iocb
4595 * @phba: pointer to lpfc hba data structure.
4596 * @cmdiocb: pointer to lpfc command iocb data structure.
4597 * @rspiocb: pointer to lpfc response iocb data structure.
4599 * This routine makes a retry decision on an ELS command IOCB, which has
4600 * failed. The following ELS IOCBs use this function for retrying the command
4601 * when previously issued command responsed with error status: FLOGI, PLOGI,
4602 * PRLI, ADISC and FDISC. Based on the ELS command type and the
4603 * returned error status, it makes the decision whether a retry shall be
4604 * issued for the command, and whether a retry shall be made immediately or
4605 * delayed. In the former case, the corresponding ELS command issuing-function
4606 * is called to retry the command. In the later case, the ELS command shall
4607 * be posted to the ndlp delayed event and delayed function timer set to the
4608 * ndlp for the delayed command issusing.
4611 * 0 - No retry of els command is made
4612 * 1 - Immediate or delayed retry of els command is made
4615 lpfc_els_retry(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
4616 struct lpfc_iocbq
*rspiocb
)
4618 struct lpfc_vport
*vport
= cmdiocb
->vport
;
4619 union lpfc_wqe128
*irsp
= &rspiocb
->wqe
;
4620 struct lpfc_nodelist
*ndlp
= cmdiocb
->ndlp
;
4621 struct lpfc_dmabuf
*pcmd
= cmdiocb
->cmd_dmabuf
;
4624 int retry
= 0, maxretry
= lpfc_max_els_tries
, delay
= 0;
4628 int link_reset
= 0, rc
;
4629 u32 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
4630 u32 ulp_word4
= get_job_word4(phba
, rspiocb
);
4633 /* Note: cmd_dmabuf may be 0 for internal driver abort
4634 * of delays ELS command.
4637 if (pcmd
&& pcmd
->virt
) {
4638 elscmd
= (uint32_t *) (pcmd
->virt
);
4643 did
= ndlp
->nlp_DID
;
4645 /* We should only hit this case for retrying PLOGI */
4646 did
= get_job_els_rsp64_did(phba
, rspiocb
);
4647 ndlp
= lpfc_findnode_did(vport
, did
);
4648 if (!ndlp
&& (cmd
!= ELS_CMD_PLOGI
))
4652 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4653 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
4654 *(((uint32_t *)irsp
) + 7), ulp_word4
, did
);
4656 switch (ulp_status
) {
4657 case IOSTAT_FCP_RSP_ERROR
:
4659 case IOSTAT_REMOTE_STOP
:
4660 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
4661 /* This IO was aborted by the target, we don't
4662 * know the rxid and because we did not send the
4663 * ABTS we cannot generate and RRQ.
4665 lpfc_set_rrq_active(phba
, ndlp
,
4666 cmdiocb
->sli4_lxritag
, 0, 0);
4669 case IOSTAT_LOCAL_REJECT
:
4670 switch ((ulp_word4
& IOERR_PARAM_MASK
)) {
4671 case IOERR_LOOP_OPEN_FAILURE
:
4672 if (cmd
== ELS_CMD_PLOGI
&& cmdiocb
->retry
== 0)
4677 case IOERR_ILLEGAL_COMMAND
:
4678 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
4679 "0124 Retry illegal cmd x%x "
4680 "retry:x%x delay:x%x\n",
4681 cmd
, cmdiocb
->retry
, delay
);
4683 /* All command's retry policy */
4685 if (cmdiocb
->retry
> 2)
4689 case IOERR_NO_RESOURCES
:
4690 logerr
= 1; /* HBA out of resources */
4692 if (cmdiocb
->retry
> 100)
4697 case IOERR_ILLEGAL_FRAME
:
4702 case IOERR_INVALID_RPI
:
4703 if (cmd
== ELS_CMD_PLOGI
&&
4704 did
== NameServer_DID
) {
4705 /* Continue forever if plogi to */
4706 /* the nameserver fails */
4709 } else if (cmd
== ELS_CMD_PRLI
&&
4710 ndlp
->nlp_state
!= NLP_STE_PRLI_ISSUE
) {
4711 /* State-command disagreement. The PRLI was
4712 * failed with an invalid rpi meaning there
4713 * some unexpected state change. Don't retry.
4722 case IOERR_SEQUENCE_TIMEOUT
:
4723 if (cmd
== ELS_CMD_PLOGI
&&
4724 did
== NameServer_DID
&&
4725 (cmdiocb
->retry
+ 1) == maxretry
) {
4726 /* Reset the Link */
4733 case IOERR_SLI_ABORTED
:
4734 /* Retry ELS PLOGI command?
4735 * Possibly the rport just wasn't ready.
4737 if (cmd
== ELS_CMD_PLOGI
) {
4738 /* No retry if state change */
4740 ndlp
->nlp_state
!= NLP_STE_PLOGI_ISSUE
)
4749 case IOSTAT_NPORT_RJT
:
4750 case IOSTAT_FABRIC_RJT
:
4751 if (ulp_word4
& RJT_UNAVAIL_TEMP
) {
4757 case IOSTAT_NPORT_BSY
:
4758 case IOSTAT_FABRIC_BSY
:
4759 logerr
= 1; /* Fabric / Remote NPort out of resources */
4764 stat
.un
.ls_rjt_error_be
= cpu_to_be32(ulp_word4
);
4765 /* Added for Vendor specifc support
4766 * Just keep retrying for these Rsn / Exp codes
4768 if (test_bit(FC_PT2PT
, &vport
->fc_flag
) &&
4769 cmd
== ELS_CMD_NVMEPRLI
) {
4770 switch (stat
.un
.b
.lsRjtRsnCode
) {
4771 case LSRJT_UNABLE_TPC
:
4772 case LSRJT_INVALID_CMD
:
4773 case LSRJT_LOGICAL_ERR
:
4774 case LSRJT_CMD_UNSUPPORTED
:
4775 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
4776 "0168 NVME PRLI LS_RJT "
4777 "reason %x port doesn't "
4778 "support NVME, disabling NVME\n",
4779 stat
.un
.b
.lsRjtRsnCode
);
4781 set_bit(FC_PT2PT_NO_NVME
, &vport
->fc_flag
);
4785 switch (stat
.un
.b
.lsRjtRsnCode
) {
4786 case LSRJT_UNABLE_TPC
:
4787 /* Special case for PRLI LS_RJTs. Recall that lpfc
4788 * uses a single routine to issue both PRLI FC4 types.
4789 * If the PRLI is rejected because that FC4 type
4790 * isn't really supported, don't retry and cause
4791 * multiple transport registrations. Otherwise, parse
4792 * the reason code/reason code explanation and take the
4793 * appropriate action.
4795 lpfc_printf_vlog(vport
, KERN_INFO
,
4796 LOG_DISCOVERY
| LOG_ELS
| LOG_NODE
,
4797 "0153 ELS cmd x%x LS_RJT by x%x. "
4798 "RsnCode x%x RsnCodeExp x%x\n",
4799 cmd
, did
, stat
.un
.b
.lsRjtRsnCode
,
4800 stat
.un
.b
.lsRjtRsnCodeExp
);
4802 switch (stat
.un
.b
.lsRjtRsnCodeExp
) {
4803 case LSEXP_CANT_GIVE_DATA
:
4804 case LSEXP_CMD_IN_PROGRESS
:
4805 if (cmd
== ELS_CMD_PLOGI
) {
4811 case LSEXP_REQ_UNSUPPORTED
:
4812 case LSEXP_NO_RSRC_ASSIGN
:
4813 /* These explanation codes get no retry. */
4814 if (cmd
== ELS_CMD_PRLI
||
4815 cmd
== ELS_CMD_NVMEPRLI
)
4819 /* Limit the delay and retry action to a limited
4820 * cmd set. There are other ELS commands where
4821 * a retry is not expected.
4823 if (cmd
== ELS_CMD_PLOGI
||
4824 cmd
== ELS_CMD_PRLI
||
4825 cmd
== ELS_CMD_NVMEPRLI
) {
4827 maxretry
= lpfc_max_els_tries
+ 1;
4833 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
4834 (cmd
== ELS_CMD_FDISC
) &&
4835 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_OUT_OF_RESOURCE
)){
4836 lpfc_vlog_msg(vport
, KERN_WARNING
, LOG_ELS
,
4837 "0125 FDISC (x%x). "
4838 "Fabric out of resources\n",
4839 stat
.un
.lsRjtError
);
4840 lpfc_vport_set_state(vport
,
4841 FC_VPORT_NO_FABRIC_RSCS
);
4845 case LSRJT_LOGICAL_BSY
:
4846 if ((cmd
== ELS_CMD_PLOGI
) ||
4847 (cmd
== ELS_CMD_PRLI
) ||
4848 (cmd
== ELS_CMD_NVMEPRLI
)) {
4851 } else if (cmd
== ELS_CMD_FDISC
) {
4852 /* FDISC retry policy */
4854 if (cmdiocb
->retry
>= 32)
4860 case LSRJT_LOGICAL_ERR
:
4861 /* There are some cases where switches return this
4862 * error when they are not ready and should be returning
4863 * Logical Busy. We should delay every time.
4865 if (cmd
== ELS_CMD_FDISC
&&
4866 stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_PORT_LOGIN_REQ
) {
4870 } else if (cmd
== ELS_CMD_FLOGI
&&
4871 stat
.un
.b
.lsRjtRsnCodeExp
==
4872 LSEXP_NOTHING_MORE
) {
4873 vport
->fc_sparam
.cmn
.bbRcvSizeMsb
&= 0xf;
4875 lpfc_vlog_msg(vport
, KERN_WARNING
, LOG_ELS
,
4876 "0820 FLOGI (x%x). "
4877 "BBCredit Not Supported\n",
4878 stat
.un
.lsRjtError
);
4882 case LSRJT_PROTOCOL_ERR
:
4883 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
4884 (cmd
== ELS_CMD_FDISC
) &&
4885 ((stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_PNAME
) ||
4886 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_NPORT_ID
))
4888 lpfc_vlog_msg(vport
, KERN_WARNING
, LOG_ELS
,
4889 "0122 FDISC (x%x). "
4890 "Fabric Detected Bad WWN\n",
4891 stat
.un
.lsRjtError
);
4892 lpfc_vport_set_state(vport
,
4893 FC_VPORT_FABRIC_REJ_WWN
);
4896 case LSRJT_VENDOR_UNIQUE
:
4897 if ((stat
.un
.b
.vendorUnique
== 0x45) &&
4898 (cmd
== ELS_CMD_FLOGI
)) {
4902 case LSRJT_CMD_UNSUPPORTED
:
4903 /* lpfc nvmet returns this type of LS_RJT when it
4904 * receives an FCP PRLI because lpfc nvmet only
4905 * support NVME. ELS request is terminated for FCP4
4908 if (stat
.un
.b
.lsRjtRsnCodeExp
==
4909 LSEXP_REQ_UNSUPPORTED
) {
4910 if (cmd
== ELS_CMD_PRLI
)
4917 case IOSTAT_INTERMED_RSP
:
4926 rc
= lpfc_link_reset(vport
);
4928 /* Do not give up. Retry PLOGI one more time and attempt
4929 * link reset if PLOGI fails again.
4938 if (did
== FDMI_DID
)
4941 if ((cmd
== ELS_CMD_FLOGI
) &&
4942 (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) &&
4943 !lpfc_error_lost_link(vport
, ulp_status
, ulp_word4
)) {
4944 /* FLOGI retry policy */
4946 /* retry FLOGI forever */
4947 if (phba
->link_flag
!= LS_LOOPBACK_MODE
)
4952 if (cmdiocb
->retry
>= 100)
4954 else if (cmdiocb
->retry
>= 32)
4956 } else if ((cmd
== ELS_CMD_FDISC
) &&
4957 !lpfc_error_lost_link(vport
, ulp_status
, ulp_word4
)) {
4958 /* retry FDISCs every second up to devloss */
4960 maxretry
= vport
->cfg_devloss_tmo
;
4965 if (maxretry
&& (cmdiocb
->retry
>= maxretry
)) {
4966 phba
->fc_stat
.elsRetryExceeded
++;
4970 if (test_bit(FC_UNLOADING
, &vport
->load_flag
))
4975 if ((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_FDISC
)) {
4976 /* Stop retrying PLOGI and FDISC if in FCF discovery */
4977 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
4978 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4979 "2849 Stop retry ELS command "
4980 "x%x to remote NPORT x%x, "
4981 "Data: x%x x%x\n", cmd
, did
,
4982 cmdiocb
->retry
, delay
);
4987 /* Retry ELS command <elsCmd> to remote NPORT <did> */
4988 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4989 "0107 Retry ELS command x%x to remote "
4990 "NPORT x%x Data: x%x x%x\n",
4991 cmd
, did
, cmdiocb
->retry
, delay
);
4993 if (((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_ADISC
)) &&
4994 ((ulp_status
!= IOSTAT_LOCAL_REJECT
) ||
4995 ((ulp_word4
& IOERR_PARAM_MASK
) !=
4996 IOERR_NO_RESOURCES
))) {
4997 /* Don't reset timer for no resources */
4999 /* If discovery / RSCN timer is running, reset it */
5000 if (timer_pending(&vport
->fc_disctmo
) ||
5001 test_bit(FC_RSCN_MODE
, &vport
->fc_flag
))
5002 lpfc_set_disctmo(vport
);
5005 phba
->fc_stat
.elsXmitRetry
++;
5006 if (ndlp
&& delay
) {
5007 phba
->fc_stat
.elsDelayRetry
++;
5008 ndlp
->nlp_retry
= cmdiocb
->retry
;
5010 /* delay is specified in milliseconds */
5011 mod_timer(&ndlp
->nlp_delayfunc
,
5012 jiffies
+ msecs_to_jiffies(delay
));
5013 spin_lock_irq(&ndlp
->lock
);
5014 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
5015 spin_unlock_irq(&ndlp
->lock
);
5017 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5018 if ((cmd
== ELS_CMD_PRLI
) ||
5019 (cmd
== ELS_CMD_NVMEPRLI
))
5020 lpfc_nlp_set_state(vport
, ndlp
,
5021 NLP_STE_PRLI_ISSUE
);
5022 else if (cmd
!= ELS_CMD_ADISC
)
5023 lpfc_nlp_set_state(vport
, ndlp
,
5025 ndlp
->nlp_last_elscmd
= cmd
;
5031 lpfc_issue_els_flogi(vport
, ndlp
, cmdiocb
->retry
);
5034 lpfc_issue_els_fdisc(vport
, ndlp
, cmdiocb
->retry
);
5038 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5039 lpfc_nlp_set_state(vport
, ndlp
,
5040 NLP_STE_PLOGI_ISSUE
);
5042 lpfc_issue_els_plogi(vport
, did
, cmdiocb
->retry
);
5045 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5046 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
5047 lpfc_issue_els_adisc(vport
, ndlp
, cmdiocb
->retry
);
5050 case ELS_CMD_NVMEPRLI
:
5051 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5052 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
5053 lpfc_issue_els_prli(vport
, ndlp
, cmdiocb
->retry
);
5056 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5057 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_LOGO_ISSUE
);
5058 lpfc_issue_els_logo(vport
, ndlp
, cmdiocb
->retry
);
5062 /* No retry ELS command <elsCmd> to remote NPORT <did> */
5064 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
5065 "0137 No retry ELS command x%x to remote "
5066 "NPORT x%x: Out of Resources: Error:x%x/%x "
5068 cmd
, did
, ulp_status
, ulp_word4
,
5072 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5073 "0108 No retry ELS command x%x to remote "
5074 "NPORT x%x Retried:%d Error:x%x/%x "
5075 "IoTag x%x nflags x%x\n",
5076 cmd
, did
, cmdiocb
->retry
, ulp_status
,
5077 ulp_word4
, cmdiocb
->iotag
,
5078 (ndlp
? ndlp
->nlp_flag
: 0));
5084 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
5085 * @phba: pointer to lpfc hba data structure.
5086 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
5088 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
5089 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
5090 * checks to see whether there is a lpfc DMA buffer associated with the
5091 * response of the command IOCB. If so, it will be released before releasing
5092 * the lpfc DMA buffer associated with the IOCB itself.
5095 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
5098 lpfc_els_free_data(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr1
)
5100 struct lpfc_dmabuf
*buf_ptr
;
5102 /* Free the response before processing the command. */
5103 if (!list_empty(&buf_ptr1
->list
)) {
5104 list_remove_head(&buf_ptr1
->list
, buf_ptr
,
5107 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
5110 lpfc_mbuf_free(phba
, buf_ptr1
->virt
, buf_ptr1
->phys
);
5116 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
5117 * @phba: pointer to lpfc hba data structure.
5118 * @buf_ptr: pointer to the lpfc dma buffer data structure.
5120 * This routine releases the lpfc Direct Memory Access (DMA) buffer
5121 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
5125 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
5128 lpfc_els_free_bpl(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr
)
5130 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
5136 * lpfc_els_free_iocb - Free a command iocb and its associated resources
5137 * @phba: pointer to lpfc hba data structure.
5138 * @elsiocb: pointer to lpfc els command iocb data structure.
5140 * This routine frees a command IOCB and its associated resources. The
5141 * command IOCB data structure contains the reference to various associated
5142 * resources, these fields must be set to NULL if the associated reference
5144 * cmd_dmabuf - reference to cmd.
5145 * cmd_dmabuf->next - reference to rsp
5146 * rsp_dmabuf - unused
5147 * bpl_dmabuf - reference to bpl
5149 * It first properly decrements the reference count held on ndlp for the
5150 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
5151 * set, it invokes the lpfc_els_free_data() routine to release the Direct
5152 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
5153 * adds the DMA buffer the @phba data structure for the delayed release.
5154 * If reference to the Buffer Pointer List (BPL) is present, the
5155 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
5156 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
5157 * invoked to release the IOCB data structure back to @phba IOCBQ list.
5160 * 0 - Success (currently, always return 0)
5163 lpfc_els_free_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*elsiocb
)
5165 struct lpfc_dmabuf
*buf_ptr
, *buf_ptr1
;
5167 /* The I/O iocb is complete. Clear the node and first dmbuf */
5168 elsiocb
->ndlp
= NULL
;
5170 /* cmd_dmabuf = cmd, cmd_dmabuf->next = rsp, bpl_dmabuf = bpl */
5171 if (elsiocb
->cmd_dmabuf
) {
5172 if (elsiocb
->cmd_flag
& LPFC_DELAY_MEM_FREE
) {
5173 /* Firmware could still be in progress of DMAing
5174 * payload, so don't free data buffer till after
5177 elsiocb
->cmd_flag
&= ~LPFC_DELAY_MEM_FREE
;
5178 buf_ptr
= elsiocb
->cmd_dmabuf
;
5179 elsiocb
->cmd_dmabuf
= NULL
;
5182 spin_lock_irq(&phba
->hbalock
);
5183 if (!list_empty(&buf_ptr
->list
)) {
5184 list_remove_head(&buf_ptr
->list
,
5185 buf_ptr1
, struct lpfc_dmabuf
,
5187 INIT_LIST_HEAD(&buf_ptr1
->list
);
5188 list_add_tail(&buf_ptr1
->list
,
5192 INIT_LIST_HEAD(&buf_ptr
->list
);
5193 list_add_tail(&buf_ptr
->list
, &phba
->elsbuf
);
5195 spin_unlock_irq(&phba
->hbalock
);
5198 buf_ptr1
= elsiocb
->cmd_dmabuf
;
5199 lpfc_els_free_data(phba
, buf_ptr1
);
5200 elsiocb
->cmd_dmabuf
= NULL
;
5204 if (elsiocb
->bpl_dmabuf
) {
5205 buf_ptr
= elsiocb
->bpl_dmabuf
;
5206 lpfc_els_free_bpl(phba
, buf_ptr
);
5207 elsiocb
->bpl_dmabuf
= NULL
;
5209 lpfc_sli_release_iocbq(phba
, elsiocb
);
5214 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
5215 * @phba: pointer to lpfc hba data structure.
5216 * @cmdiocb: pointer to lpfc command iocb data structure.
5217 * @rspiocb: pointer to lpfc response iocb data structure.
5219 * This routine is the completion callback function to the Logout (LOGO)
5220 * Accept (ACC) Response ELS command. This routine is invoked to indicate
5221 * the completion of the LOGO process. If the node has transitioned to NPR,
5222 * this routine unregisters the RPI if it is still registered. The
5223 * lpfc_els_free_iocb() is invoked to release the IOCB data structure.
5226 lpfc_cmpl_els_logo_acc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
5227 struct lpfc_iocbq
*rspiocb
)
5229 struct lpfc_nodelist
*ndlp
= cmdiocb
->ndlp
;
5230 struct lpfc_vport
*vport
= cmdiocb
->vport
;
5231 u32 ulp_status
, ulp_word4
;
5233 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
5234 ulp_word4
= get_job_word4(phba
, rspiocb
);
5236 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
5237 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
5238 ulp_status
, ulp_word4
, ndlp
->nlp_DID
);
5239 /* ACC to LOGO completes to NPort <nlp_DID> */
5240 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5241 "0109 ACC to LOGO completes to NPort x%x refcnt %d "
5242 "last els x%x Data: x%x x%x x%x\n",
5243 ndlp
->nlp_DID
, kref_read(&ndlp
->kref
),
5244 ndlp
->nlp_last_elscmd
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5247 /* This clause allows the LOGO ACC to complete and free resources
5248 * for the Fabric Domain Controller. It does deliberately skip
5249 * the unreg_rpi and release rpi because some fabrics send RDP
5250 * requests after logging out from the initiator.
5252 if (ndlp
->nlp_type
& NLP_FABRIC
&&
5253 ((ndlp
->nlp_DID
& WELL_KNOWN_DID_MASK
) != WELL_KNOWN_DID_MASK
))
5256 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
) {
5257 if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
)
5258 lpfc_unreg_rpi(vport
, ndlp
);
5260 /* If came from PRLO, then PRLO_ACC is done.
5261 * Start rediscovery now.
5263 if (ndlp
->nlp_last_elscmd
== ELS_CMD_PRLO
) {
5264 spin_lock_irq(&ndlp
->lock
);
5265 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
5266 spin_unlock_irq(&ndlp
->lock
);
5267 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5268 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
5269 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
5275 * The driver received a LOGO from the rport and has ACK'd it.
5276 * At this point, the driver is done so release the IOCB
5278 lpfc_els_free_iocb(phba
, cmdiocb
);
5283 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
5284 * @phba: pointer to lpfc hba data structure.
5285 * @pmb: pointer to the driver internal queue element for mailbox command.
5287 * This routine is the completion callback function for unregister default
5288 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
5289 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
5290 * decrements the ndlp reference count held for this completion callback
5291 * function. After that, it invokes the lpfc_drop_node to check
5292 * whether it is appropriate to release the node.
5295 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
5297 struct lpfc_nodelist
*ndlp
= pmb
->ctx_ndlp
;
5298 u32 mbx_flag
= pmb
->mbox_flag
;
5299 u32 mbx_cmd
= pmb
->u
.mb
.mbxCommand
;
5302 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
5303 "0006 rpi x%x DID:%x flg:%x %d x%px "
5304 "mbx_cmd x%x mbx_flag x%x x%px\n",
5305 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
,
5306 kref_read(&ndlp
->kref
), ndlp
, mbx_cmd
,
5309 /* This ends the default/temporary RPI cleanup logic for this
5310 * ndlp and the node and rpi needs to be released. Free the rpi
5311 * first on an UNREG_LOGIN and then release the final
5314 spin_lock_irq(&ndlp
->lock
);
5315 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
5316 if (mbx_cmd
== MBX_UNREG_LOGIN
)
5317 ndlp
->nlp_flag
&= ~NLP_UNREG_INP
;
5318 spin_unlock_irq(&ndlp
->lock
);
5320 lpfc_drop_node(ndlp
->vport
, ndlp
);
5323 lpfc_mbox_rsrc_cleanup(phba
, pmb
, MBOX_THD_UNLOCKED
);
5327 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
5328 * @phba: pointer to lpfc hba data structure.
5329 * @cmdiocb: pointer to lpfc command iocb data structure.
5330 * @rspiocb: pointer to lpfc response iocb data structure.
5332 * This routine is the completion callback function for ELS Response IOCB
5333 * command. In normal case, this callback function just properly sets the
5334 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
5335 * field in the command IOCB is not NULL, the referred mailbox command will
5336 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
5340 lpfc_cmpl_els_rsp(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
5341 struct lpfc_iocbq
*rspiocb
)
5343 struct lpfc_nodelist
*ndlp
= cmdiocb
->ndlp
;
5344 struct lpfc_vport
*vport
= ndlp
? ndlp
->vport
: NULL
;
5345 struct Scsi_Host
*shost
= vport
? lpfc_shost_from_vport(vport
) : NULL
;
5347 LPFC_MBOXQ_t
*mbox
= NULL
;
5348 u32 ulp_status
, ulp_word4
, tmo
, did
, iotag
;
5351 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
,
5352 "3177 null vport in ELS rsp\n");
5355 if (cmdiocb
->context_un
.mbox
)
5356 mbox
= cmdiocb
->context_un
.mbox
;
5358 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
5359 ulp_word4
= get_job_word4(phba
, rspiocb
);
5360 did
= get_job_els_rsp64_did(phba
, cmdiocb
);
5362 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
5363 tmo
= get_wqe_tmo(cmdiocb
);
5364 iotag
= get_wqe_reqtag(cmdiocb
);
5366 irsp
= &rspiocb
->iocb
;
5367 tmo
= irsp
->ulpTimeout
;
5368 iotag
= irsp
->ulpIoTag
;
5371 /* Check to see if link went down during discovery */
5372 if (!ndlp
|| lpfc_els_chk_latt(vport
)) {
5374 lpfc_mbox_rsrc_cleanup(phba
, mbox
, MBOX_THD_UNLOCKED
);
5378 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
5379 "ELS rsp cmpl: status:x%x/x%x did:x%x",
5380 ulp_status
, ulp_word4
, did
);
5381 /* ELS response tag <ulpIoTag> completes */
5382 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5383 "0110 ELS response tag x%x completes "
5384 "Data: x%x x%x x%x x%x x%x x%x x%x x%x %p %p\n",
5385 iotag
, ulp_status
, ulp_word4
, tmo
,
5386 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5387 ndlp
->nlp_rpi
, kref_read(&ndlp
->kref
), mbox
, ndlp
);
5390 && (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
)) {
5391 if (!lpfc_unreg_rpi(vport
, ndlp
) &&
5392 !test_bit(FC_PT2PT
, &vport
->fc_flag
)) {
5393 if (ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
5395 NLP_STE_REG_LOGIN_ISSUE
) {
5396 lpfc_printf_vlog(vport
, KERN_INFO
,
5400 "Data: x%x x%x x%x\n",
5409 /* Increment reference count to ndlp to hold the
5410 * reference to ndlp for the callback function.
5412 mbox
->ctx_ndlp
= lpfc_nlp_get(ndlp
);
5413 if (!mbox
->ctx_ndlp
)
5416 mbox
->vport
= vport
;
5417 if (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
) {
5418 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
5419 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
5422 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
5423 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5424 lpfc_nlp_set_state(vport
, ndlp
,
5425 NLP_STE_REG_LOGIN_ISSUE
);
5428 ndlp
->nlp_flag
|= NLP_REG_LOGIN_SEND
;
5429 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
5430 != MBX_NOT_FINISHED
)
5433 /* Decrement the ndlp reference count we
5434 * set for this failed mailbox command.
5437 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
5439 /* ELS rsp: Cannot issue reg_login for <NPortid> */
5440 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
5441 "0138 ELS rsp: Cannot issue reg_login for x%x "
5442 "Data: x%x x%x x%x\n",
5443 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5447 lpfc_mbox_rsrc_cleanup(phba
, mbox
, MBOX_THD_UNLOCKED
);
5450 if (ndlp
&& shost
) {
5451 spin_lock_irq(&ndlp
->lock
);
5453 ndlp
->nlp_flag
&= ~NLP_ACC_REGLOGIN
;
5454 ndlp
->nlp_flag
&= ~NLP_RM_DFLT_RPI
;
5455 spin_unlock_irq(&ndlp
->lock
);
5458 /* An SLI4 NPIV instance wants to drop the node at this point under
5459 * these conditions and release the RPI.
5461 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
5462 vport
&& vport
->port_type
== LPFC_NPIV_PORT
&&
5463 !(ndlp
->fc4_xpt_flags
& SCSI_XPT_REGD
)) {
5464 if (ndlp
->nlp_flag
& NLP_RELEASE_RPI
) {
5465 if (ndlp
->nlp_state
!= NLP_STE_PLOGI_ISSUE
&&
5466 ndlp
->nlp_state
!= NLP_STE_REG_LOGIN_ISSUE
) {
5467 lpfc_sli4_free_rpi(phba
, ndlp
->nlp_rpi
);
5468 spin_lock_irq(&ndlp
->lock
);
5469 ndlp
->nlp_rpi
= LPFC_RPI_ALLOC_ERROR
;
5470 ndlp
->nlp_flag
&= ~NLP_RELEASE_RPI
;
5471 spin_unlock_irq(&ndlp
->lock
);
5473 lpfc_drop_node(vport
, ndlp
);
5474 } else if (ndlp
->nlp_state
!= NLP_STE_PLOGI_ISSUE
&&
5475 ndlp
->nlp_state
!= NLP_STE_REG_LOGIN_ISSUE
&&
5476 ndlp
->nlp_state
!= NLP_STE_PRLI_ISSUE
) {
5477 /* Drop ndlp if there is no planned or outstanding
5480 * In cases when the ndlp is acting as both an initiator
5481 * and target function, let our issued PRLI determine
5482 * the final ndlp kref drop.
5484 lpfc_drop_node(vport
, ndlp
);
5488 /* Release the originating I/O reference. */
5489 lpfc_els_free_iocb(phba
, cmdiocb
);
5495 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
5496 * @vport: pointer to a host virtual N_Port data structure.
5497 * @flag: the els command code to be accepted.
5498 * @oldiocb: pointer to the original lpfc command iocb data structure.
5499 * @ndlp: pointer to a node-list data structure.
5500 * @mbox: pointer to the driver internal queue element for mailbox command.
5502 * This routine prepares and issues an Accept (ACC) response IOCB
5503 * command. It uses the @flag to properly set up the IOCB field for the
5504 * specific ACC response command to be issued and invokes the
5505 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
5506 * @mbox pointer is passed in, it will be put into the context_un.mbox
5507 * field of the IOCB for the completion callback function to issue the
5508 * mailbox command to the HBA later when callback is invoked.
5510 * Note that the ndlp reference count will be incremented by 1 for holding the
5511 * ndlp and the reference to ndlp will be stored into the ndlp field of
5512 * the IOCB for the completion callback function to the corresponding
5513 * response ELS IOCB command.
5516 * 0 - Successfully issued acc response
5517 * 1 - Failed to issue acc response
5520 lpfc_els_rsp_acc(struct lpfc_vport
*vport
, uint32_t flag
,
5521 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
5524 struct lpfc_hba
*phba
= vport
->phba
;
5527 union lpfc_wqe128
*wqe
;
5528 union lpfc_wqe128
*oldwqe
= &oldiocb
->wqe
;
5529 struct lpfc_iocbq
*elsiocb
;
5531 struct serv_parm
*sp
;
5534 ELS_PKT
*els_pkt_ptr
;
5535 struct fc_els_rdf_resp
*rdf_resp
;
5539 cmdsize
= sizeof(uint32_t);
5540 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
5541 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
5543 spin_lock_irq(&ndlp
->lock
);
5544 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
5545 spin_unlock_irq(&ndlp
->lock
);
5549 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
5550 wqe
= &elsiocb
->wqe
;
5552 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
5553 bf_get(wqe_ctxt_tag
,
5554 &oldwqe
->xmit_els_rsp
.wqe_com
));
5557 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
5559 &oldwqe
->xmit_els_rsp
.wqe_com
));
5561 icmd
= &elsiocb
->iocb
;
5562 oldcmd
= &oldiocb
->iocb
;
5563 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
5564 icmd
->unsli3
.rcvsli3
.ox_id
=
5565 oldcmd
->unsli3
.rcvsli3
.ox_id
;
5568 pcmd
= elsiocb
->cmd_dmabuf
->virt
;
5569 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5570 pcmd
+= sizeof(uint32_t);
5572 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
5573 "Issue ACC: did:x%x flg:x%x",
5574 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
5578 cmdsize
= (sizeof(struct serv_parm
) + sizeof(uint32_t));
5579 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
5580 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
5584 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
5585 wqe
= &elsiocb
->wqe
;
5587 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
5588 bf_get(wqe_ctxt_tag
,
5589 &oldwqe
->xmit_els_rsp
.wqe_com
));
5592 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
5594 &oldwqe
->xmit_els_rsp
.wqe_com
));
5596 icmd
= &elsiocb
->iocb
;
5597 oldcmd
= &oldiocb
->iocb
;
5598 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
5599 icmd
->unsli3
.rcvsli3
.ox_id
=
5600 oldcmd
->unsli3
.rcvsli3
.ox_id
;
5603 pcmd
= (u8
*)elsiocb
->cmd_dmabuf
->virt
;
5606 elsiocb
->context_un
.mbox
= mbox
;
5608 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5609 pcmd
+= sizeof(uint32_t);
5610 sp
= (struct serv_parm
*)pcmd
;
5612 if (flag
== ELS_CMD_FLOGI
) {
5613 /* Copy the received service parameters back */
5614 memcpy(sp
, &phba
->fc_fabparam
,
5615 sizeof(struct serv_parm
));
5617 /* Clear the F_Port bit */
5620 /* Mark all class service parameters as invalid */
5621 sp
->cls1
.classValid
= 0;
5622 sp
->cls2
.classValid
= 0;
5623 sp
->cls3
.classValid
= 0;
5624 sp
->cls4
.classValid
= 0;
5626 /* Copy our worldwide names */
5627 memcpy(&sp
->portName
, &vport
->fc_sparam
.portName
,
5628 sizeof(struct lpfc_name
));
5629 memcpy(&sp
->nodeName
, &vport
->fc_sparam
.nodeName
,
5630 sizeof(struct lpfc_name
));
5632 memcpy(pcmd
, &vport
->fc_sparam
,
5633 sizeof(struct serv_parm
));
5635 sp
->cmn
.valid_vendor_ver_level
= 0;
5636 memset(sp
->un
.vendorVersion
, 0,
5637 sizeof(sp
->un
.vendorVersion
));
5638 sp
->cmn
.bbRcvSizeMsb
&= 0xF;
5640 /* If our firmware supports this feature, convey that
5641 * info to the target using the vendor specific field.
5643 if (phba
->sli
.sli_flag
& LPFC_SLI_SUPPRESS_RSP
) {
5644 sp
->cmn
.valid_vendor_ver_level
= 1;
5645 sp
->un
.vv
.vid
= cpu_to_be32(LPFC_VV_EMLX_ID
);
5647 cpu_to_be32(LPFC_VV_SUPPRESS_RSP
);
5651 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
5652 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
5653 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
5656 cmdsize
= sizeof(uint32_t) + sizeof(PRLO
);
5657 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
5658 ndlp
, ndlp
->nlp_DID
, ELS_CMD_PRLO
);
5662 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
5663 wqe
= &elsiocb
->wqe
;
5665 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
5666 bf_get(wqe_ctxt_tag
,
5667 &oldwqe
->xmit_els_rsp
.wqe_com
));
5670 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
5672 &oldwqe
->xmit_els_rsp
.wqe_com
));
5674 icmd
= &elsiocb
->iocb
;
5675 oldcmd
= &oldiocb
->iocb
;
5676 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
5677 icmd
->unsli3
.rcvsli3
.ox_id
=
5678 oldcmd
->unsli3
.rcvsli3
.ox_id
;
5681 pcmd
= (u8
*) elsiocb
->cmd_dmabuf
->virt
;
5683 memcpy(pcmd
, oldiocb
->cmd_dmabuf
->virt
,
5684 sizeof(uint32_t) + sizeof(PRLO
));
5685 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLO_ACC
;
5686 els_pkt_ptr
= (ELS_PKT
*) pcmd
;
5687 els_pkt_ptr
->un
.prlo
.acceptRspCode
= PRLO_REQ_EXECUTED
;
5689 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
5690 "Issue ACC PRLO: did:x%x flg:x%x",
5691 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
5694 cmdsize
= sizeof(*rdf_resp
);
5695 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
5696 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
5700 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
5701 wqe
= &elsiocb
->wqe
;
5703 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
5704 bf_get(wqe_ctxt_tag
,
5705 &oldwqe
->xmit_els_rsp
.wqe_com
));
5708 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
5710 &oldwqe
->xmit_els_rsp
.wqe_com
));
5712 icmd
= &elsiocb
->iocb
;
5713 oldcmd
= &oldiocb
->iocb
;
5714 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
5715 icmd
->unsli3
.rcvsli3
.ox_id
=
5716 oldcmd
->unsli3
.rcvsli3
.ox_id
;
5719 pcmd
= (u8
*)elsiocb
->cmd_dmabuf
->virt
;
5720 rdf_resp
= (struct fc_els_rdf_resp
*)pcmd
;
5721 memset(rdf_resp
, 0, sizeof(*rdf_resp
));
5722 rdf_resp
->acc_hdr
.la_cmd
= ELS_LS_ACC
;
5724 /* FC-LS-5 specifies desc_list_len shall be set to 12 */
5725 rdf_resp
->desc_list_len
= cpu_to_be32(12);
5727 /* FC-LS-5 specifies LS REQ Information descriptor */
5728 rdf_resp
->lsri
.desc_tag
= cpu_to_be32(1);
5729 rdf_resp
->lsri
.desc_len
= cpu_to_be32(sizeof(u32
));
5730 rdf_resp
->lsri
.rqst_w0
.cmd
= ELS_RDF
;
5735 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
5736 spin_lock_irq(&ndlp
->lock
);
5737 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
||
5738 ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
))
5739 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
5740 spin_unlock_irq(&ndlp
->lock
);
5741 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_logo_acc
;
5743 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_rsp
;
5746 phba
->fc_stat
.elsXmitACC
++;
5747 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
5748 if (!elsiocb
->ndlp
) {
5749 lpfc_els_free_iocb(phba
, elsiocb
);
5753 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5754 if (rc
== IOCB_ERROR
) {
5755 lpfc_els_free_iocb(phba
, elsiocb
);
5760 /* Xmit ELS ACC response tag <ulpIoTag> */
5761 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5762 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
5763 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5764 "RPI: x%x, fc_flag x%lx refcnt %d\n",
5765 rc
, elsiocb
->iotag
, elsiocb
->sli4_xritag
,
5766 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5767 ndlp
->nlp_rpi
, vport
->fc_flag
, kref_read(&ndlp
->kref
));
5772 * lpfc_els_rsp_reject - Prepare and issue a rjt response iocb command
5773 * @vport: pointer to a virtual N_Port data structure.
5774 * @rejectError: reject response to issue
5775 * @oldiocb: pointer to the original lpfc command iocb data structure.
5776 * @ndlp: pointer to a node-list data structure.
5777 * @mbox: pointer to the driver internal queue element for mailbox command.
5779 * This routine prepares and issue an Reject (RJT) response IOCB
5780 * command. If a @mbox pointer is passed in, it will be put into the
5781 * context_un.mbox field of the IOCB for the completion callback function
5782 * to issue to the HBA later.
5784 * Note that the ndlp reference count will be incremented by 1 for holding the
5785 * ndlp and the reference to ndlp will be stored into the ndlp field of
5786 * the IOCB for the completion callback function to the reject response
5790 * 0 - Successfully issued reject response
5791 * 1 - Failed to issue reject response
5794 lpfc_els_rsp_reject(struct lpfc_vport
*vport
, uint32_t rejectError
,
5795 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
5799 struct lpfc_hba
*phba
= vport
->phba
;
5802 union lpfc_wqe128
*wqe
;
5803 struct lpfc_iocbq
*elsiocb
;
5807 cmdsize
= 2 * sizeof(uint32_t);
5808 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
5809 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
5813 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
5814 wqe
= &elsiocb
->wqe
;
5815 bf_set(wqe_ctxt_tag
, &wqe
->generic
.wqe_com
,
5816 get_job_ulpcontext(phba
, oldiocb
)); /* Xri / rx_id */
5817 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
5818 get_job_rcvoxid(phba
, oldiocb
));
5820 icmd
= &elsiocb
->iocb
;
5821 oldcmd
= &oldiocb
->iocb
;
5822 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
5823 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
5826 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
5828 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
5829 pcmd
+= sizeof(uint32_t);
5830 *((uint32_t *) (pcmd
)) = rejectError
;
5833 elsiocb
->context_un
.mbox
= mbox
;
5835 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
5836 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5837 "0129 Xmit ELS RJT x%x response tag x%x "
5838 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5840 rejectError
, elsiocb
->iotag
,
5841 get_job_ulpcontext(phba
, elsiocb
), ndlp
->nlp_DID
,
5842 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
5843 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
5844 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
5845 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rejectError
);
5847 phba
->fc_stat
.elsXmitLSRJT
++;
5848 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_rsp
;
5849 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
5850 if (!elsiocb
->ndlp
) {
5851 lpfc_els_free_iocb(phba
, elsiocb
);
5855 /* The NPIV instance is rejecting this unsolicited ELS. Make sure the
5856 * node's assigned RPI gets released provided this node is not already
5857 * registered with the transport.
5859 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
5860 vport
->port_type
== LPFC_NPIV_PORT
&&
5861 !(ndlp
->fc4_xpt_flags
& SCSI_XPT_REGD
)) {
5862 spin_lock_irq(&ndlp
->lock
);
5863 ndlp
->nlp_flag
|= NLP_RELEASE_RPI
;
5864 spin_unlock_irq(&ndlp
->lock
);
5867 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5868 if (rc
== IOCB_ERROR
) {
5869 lpfc_els_free_iocb(phba
, elsiocb
);
5878 * lpfc_issue_els_edc_rsp - Exchange Diagnostic Capabilities with the fabric.
5879 * @vport: pointer to a host virtual N_Port data structure.
5880 * @cmdiocb: pointer to the original lpfc command iocb data structure.
5881 * @ndlp: NPort to where rsp is directed
5883 * This routine issues an EDC ACC RSP to the F-Port Controller to communicate
5884 * this N_Port's support of hardware signals in its Congestion
5885 * Capabilities Descriptor.
5888 * 0 - Successfully issued edc rsp command
5889 * 1 - Failed to issue edc rsp command
5892 lpfc_issue_els_edc_rsp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5893 struct lpfc_nodelist
*ndlp
)
5895 struct lpfc_hba
*phba
= vport
->phba
;
5896 struct fc_els_edc_resp
*edc_rsp
;
5897 struct fc_tlv_desc
*tlv
;
5898 struct lpfc_iocbq
*elsiocb
;
5900 union lpfc_wqe128
*wqe
;
5901 u32 cgn_desc_size
, lft_desc_size
;
5906 cmdsize
= sizeof(struct fc_els_edc_resp
);
5907 cgn_desc_size
= sizeof(struct fc_diag_cg_sig_desc
);
5908 lft_desc_size
= (lpfc_link_is_lds_capable(phba
)) ?
5909 sizeof(struct fc_diag_lnkflt_desc
) : 0;
5910 cmdsize
+= cgn_desc_size
+ lft_desc_size
;
5911 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, cmdiocb
->retry
,
5912 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
5916 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
5917 wqe
= &elsiocb
->wqe
;
5918 bf_set(wqe_ctxt_tag
, &wqe
->generic
.wqe_com
,
5919 get_job_ulpcontext(phba
, cmdiocb
)); /* Xri / rx_id */
5920 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
5921 get_job_rcvoxid(phba
, cmdiocb
));
5923 icmd
= &elsiocb
->iocb
;
5924 cmd
= &cmdiocb
->iocb
;
5925 icmd
->ulpContext
= cmd
->ulpContext
; /* Xri / rx_id */
5926 icmd
->unsli3
.rcvsli3
.ox_id
= cmd
->unsli3
.rcvsli3
.ox_id
;
5929 pcmd
= elsiocb
->cmd_dmabuf
->virt
;
5930 memset(pcmd
, 0, cmdsize
);
5932 edc_rsp
= (struct fc_els_edc_resp
*)pcmd
;
5933 edc_rsp
->acc_hdr
.la_cmd
= ELS_LS_ACC
;
5934 edc_rsp
->desc_list_len
= cpu_to_be32(sizeof(struct fc_els_lsri_desc
) +
5935 cgn_desc_size
+ lft_desc_size
);
5936 edc_rsp
->lsri
.desc_tag
= cpu_to_be32(ELS_DTAG_LS_REQ_INFO
);
5937 edc_rsp
->lsri
.desc_len
= cpu_to_be32(
5938 FC_TLV_DESC_LENGTH_FROM_SZ(struct fc_els_lsri_desc
));
5939 edc_rsp
->lsri
.rqst_w0
.cmd
= ELS_EDC
;
5940 tlv
= edc_rsp
->desc
;
5941 lpfc_format_edc_cgn_desc(phba
, tlv
);
5942 tlv
= fc_tlv_next_desc(tlv
);
5944 lpfc_format_edc_lft_desc(phba
, tlv
);
5946 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
5947 "Issue EDC ACC: did:x%x flg:x%x refcnt %d",
5948 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
5949 kref_read(&ndlp
->kref
));
5950 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_rsp
;
5952 phba
->fc_stat
.elsXmitACC
++;
5953 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
5954 if (!elsiocb
->ndlp
) {
5955 lpfc_els_free_iocb(phba
, elsiocb
);
5959 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5960 if (rc
== IOCB_ERROR
) {
5961 lpfc_els_free_iocb(phba
, elsiocb
);
5966 /* Xmit ELS ACC response tag <ulpIoTag> */
5967 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5968 "0152 Xmit EDC ACC response Status: x%x, IoTag: x%x, "
5969 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
5970 "RPI: x%x, fc_flag x%lx\n",
5971 rc
, elsiocb
->iotag
, elsiocb
->sli4_xritag
,
5972 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5973 ndlp
->nlp_rpi
, vport
->fc_flag
);
5979 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
5980 * @vport: pointer to a virtual N_Port data structure.
5981 * @oldiocb: pointer to the original lpfc command iocb data structure.
5982 * @ndlp: pointer to a node-list data structure.
5984 * This routine prepares and issues an Accept (ACC) response to Address
5985 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
5986 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
5988 * Note that the ndlp reference count will be incremented by 1 for holding the
5989 * ndlp and the reference to ndlp will be stored into the ndlp field of
5990 * the IOCB for the completion callback function to the ADISC Accept response
5994 * 0 - Successfully issued acc adisc response
5995 * 1 - Failed to issue adisc acc response
5998 lpfc_els_rsp_adisc_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
5999 struct lpfc_nodelist
*ndlp
)
6001 struct lpfc_hba
*phba
= vport
->phba
;
6003 IOCB_t
*icmd
, *oldcmd
;
6004 union lpfc_wqe128
*wqe
;
6005 struct lpfc_iocbq
*elsiocb
;
6011 cmdsize
= sizeof(uint32_t) + sizeof(ADISC
);
6012 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
6013 ndlp
->nlp_DID
, ELS_CMD_ACC
);
6017 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
6018 wqe
= &elsiocb
->wqe
;
6020 bf_set(wqe_ctxt_tag
, &wqe
->generic
.wqe_com
,
6021 get_job_ulpcontext(phba
, oldiocb
));
6022 ulp_context
= get_job_ulpcontext(phba
, elsiocb
);
6024 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
6025 get_job_rcvoxid(phba
, oldiocb
));
6027 icmd
= &elsiocb
->iocb
;
6028 oldcmd
= &oldiocb
->iocb
;
6029 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
6030 ulp_context
= elsiocb
->iocb
.ulpContext
;
6031 icmd
->unsli3
.rcvsli3
.ox_id
=
6032 oldcmd
->unsli3
.rcvsli3
.ox_id
;
6035 /* Xmit ADISC ACC response tag <ulpIoTag> */
6036 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6037 "0130 Xmit ADISC ACC response iotag x%x xri: "
6038 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
6039 elsiocb
->iotag
, ulp_context
,
6040 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
6042 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
6044 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
6045 pcmd
+= sizeof(uint32_t);
6047 ap
= (ADISC
*) (pcmd
);
6048 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
6049 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
6050 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
6051 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
6053 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
6054 "Issue ACC ADISC: did:x%x flg:x%x refcnt %d",
6055 ndlp
->nlp_DID
, ndlp
->nlp_flag
, kref_read(&ndlp
->kref
));
6057 phba
->fc_stat
.elsXmitACC
++;
6058 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_rsp
;
6059 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
6060 if (!elsiocb
->ndlp
) {
6061 lpfc_els_free_iocb(phba
, elsiocb
);
6065 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
6066 if (rc
== IOCB_ERROR
) {
6067 lpfc_els_free_iocb(phba
, elsiocb
);
6076 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
6077 * @vport: pointer to a virtual N_Port data structure.
6078 * @oldiocb: pointer to the original lpfc command iocb data structure.
6079 * @ndlp: pointer to a node-list data structure.
6081 * This routine prepares and issues an Accept (ACC) response to Process
6082 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
6083 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
6085 * Note that the ndlp reference count will be incremented by 1 for holding the
6086 * ndlp and the reference to ndlp will be stored into the ndlp field of
6087 * the IOCB for the completion callback function to the PRLI Accept response
6091 * 0 - Successfully issued acc prli response
6092 * 1 - Failed to issue acc prli response
6095 lpfc_els_rsp_prli_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
6096 struct lpfc_nodelist
*ndlp
)
6098 struct lpfc_hba
*phba
= vport
->phba
;
6100 struct lpfc_nvme_prli
*npr_nvme
;
6104 union lpfc_wqe128
*wqe
;
6105 struct lpfc_iocbq
*elsiocb
;
6108 uint32_t prli_fc4_req
, *req_payload
;
6109 struct lpfc_dmabuf
*req_buf
;
6111 u32 elsrspcmd
, ulp_context
;
6113 /* Need the incoming PRLI payload to determine if the ACC is for an
6114 * FC4 or NVME PRLI type. The PRLI type is at word 1.
6116 req_buf
= oldiocb
->cmd_dmabuf
;
6117 req_payload
= (((uint32_t *)req_buf
->virt
) + 1);
6119 /* PRLI type payload is at byte 3 for FCP or NVME. */
6120 prli_fc4_req
= be32_to_cpu(*req_payload
);
6121 prli_fc4_req
= (prli_fc4_req
>> 24) & 0xff;
6122 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6123 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
6124 prli_fc4_req
, *((uint32_t *)req_payload
));
6126 if (prli_fc4_req
== PRLI_FCP_TYPE
) {
6127 cmdsize
= sizeof(uint32_t) + sizeof(PRLI
);
6128 elsrspcmd
= (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
));
6129 } else if (prli_fc4_req
== PRLI_NVME_TYPE
) {
6130 cmdsize
= sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli
);
6131 elsrspcmd
= (ELS_CMD_ACC
| (ELS_CMD_NVMEPRLI
& ~ELS_RSP_MASK
));
6136 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
6137 ndlp
->nlp_DID
, elsrspcmd
);
6141 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
6142 wqe
= &elsiocb
->wqe
;
6143 bf_set(wqe_ctxt_tag
, &wqe
->generic
.wqe_com
,
6144 get_job_ulpcontext(phba
, oldiocb
)); /* Xri / rx_id */
6145 ulp_context
= get_job_ulpcontext(phba
, elsiocb
);
6146 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
6147 get_job_rcvoxid(phba
, oldiocb
));
6149 icmd
= &elsiocb
->iocb
;
6150 oldcmd
= &oldiocb
->iocb
;
6151 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
6152 ulp_context
= elsiocb
->iocb
.ulpContext
;
6153 icmd
->unsli3
.rcvsli3
.ox_id
=
6154 oldcmd
->unsli3
.rcvsli3
.ox_id
;
6157 /* Xmit PRLI ACC response tag <ulpIoTag> */
6158 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6159 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
6160 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6161 elsiocb
->iotag
, ulp_context
,
6162 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
6164 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
6165 memset(pcmd
, 0, cmdsize
);
6167 *((uint32_t *)(pcmd
)) = elsrspcmd
;
6168 pcmd
+= sizeof(uint32_t);
6170 /* For PRLI, remainder of payload is PRLI parameter page */
6173 if (prli_fc4_req
== PRLI_FCP_TYPE
) {
6175 * If the remote port is a target and our firmware version
6176 * is 3.20 or later, set the following bits for FC-TAPE
6179 npr
= (PRLI
*) pcmd
;
6180 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
6181 (vpd
->rev
.feaLevelHigh
>= 0x02)) {
6182 npr
->ConfmComplAllowed
= 1;
6184 npr
->TaskRetryIdReq
= 1;
6186 npr
->acceptRspCode
= PRLI_REQ_EXECUTED
;
6188 /* Set image pair for complementary pairs only. */
6189 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
6190 npr
->estabImagePair
= 1;
6192 npr
->estabImagePair
= 0;
6193 npr
->readXferRdyDis
= 1;
6194 npr
->ConfmComplAllowed
= 1;
6195 npr
->prliType
= PRLI_FCP_TYPE
;
6196 npr
->initiatorFunc
= 1;
6198 /* Xmit PRLI ACC response tag <ulpIoTag> */
6199 lpfc_printf_vlog(vport
, KERN_INFO
,
6200 LOG_ELS
| LOG_NODE
| LOG_DISCOVERY
,
6201 "6014 FCP issue PRLI ACC imgpair %d "
6202 "retry %d task %d\n",
6203 npr
->estabImagePair
,
6204 npr
->Retry
, npr
->TaskRetryIdReq
);
6206 } else if (prli_fc4_req
== PRLI_NVME_TYPE
) {
6207 /* Respond with an NVME PRLI Type */
6208 npr_nvme
= (struct lpfc_nvme_prli
*) pcmd
;
6209 bf_set(prli_type_code
, npr_nvme
, PRLI_NVME_TYPE
);
6210 bf_set(prli_estabImagePair
, npr_nvme
, 0); /* Should be 0 */
6211 bf_set(prli_acc_rsp_code
, npr_nvme
, PRLI_REQ_EXECUTED
);
6212 if (phba
->nvmet_support
) {
6213 bf_set(prli_tgt
, npr_nvme
, 1);
6214 bf_set(prli_disc
, npr_nvme
, 1);
6215 if (phba
->cfg_nvme_enable_fb
) {
6216 bf_set(prli_fba
, npr_nvme
, 1);
6218 /* TBD. Target mode needs to post buffers
6219 * that support the configured first burst
6222 bf_set(prli_fb_sz
, npr_nvme
,
6223 phba
->cfg_nvmet_fb_size
);
6226 bf_set(prli_init
, npr_nvme
, 1);
6229 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NVME_DISC
,
6230 "6015 NVME issue PRLI ACC word1 x%08x "
6231 "word4 x%08x word5 x%08x flag x%x, "
6232 "fcp_info x%x nlp_type x%x\n",
6233 npr_nvme
->word1
, npr_nvme
->word4
,
6234 npr_nvme
->word5
, ndlp
->nlp_flag
,
6235 ndlp
->nlp_fcp_info
, ndlp
->nlp_type
);
6236 npr_nvme
->word1
= cpu_to_be32(npr_nvme
->word1
);
6237 npr_nvme
->word4
= cpu_to_be32(npr_nvme
->word4
);
6238 npr_nvme
->word5
= cpu_to_be32(npr_nvme
->word5
);
6240 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
6241 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
6242 prli_fc4_req
, ndlp
->nlp_fc4_type
,
6245 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
6246 "Issue ACC PRLI: did:x%x flg:x%x",
6247 ndlp
->nlp_DID
, ndlp
->nlp_flag
, kref_read(&ndlp
->kref
));
6249 phba
->fc_stat
.elsXmitACC
++;
6250 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_rsp
;
6251 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
6252 if (!elsiocb
->ndlp
) {
6253 lpfc_els_free_iocb(phba
, elsiocb
);
6257 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
6258 if (rc
== IOCB_ERROR
) {
6259 lpfc_els_free_iocb(phba
, elsiocb
);
6268 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
6269 * @vport: pointer to a virtual N_Port data structure.
6270 * @format: rnid command format.
6271 * @oldiocb: pointer to the original lpfc command iocb data structure.
6272 * @ndlp: pointer to a node-list data structure.
6274 * This routine issues a Request Node Identification Data (RNID) Accept
6275 * (ACC) response. It constructs the RNID ACC response command according to
6276 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
6277 * issue the response.
6279 * Note that the ndlp reference count will be incremented by 1 for holding the
6280 * ndlp and the reference to ndlp will be stored into the ndlp field of
6281 * the IOCB for the completion callback function.
6284 * 0 - Successfully issued acc rnid response
6285 * 1 - Failed to issue acc rnid response
6288 lpfc_els_rsp_rnid_acc(struct lpfc_vport
*vport
, uint8_t format
,
6289 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
6291 struct lpfc_hba
*phba
= vport
->phba
;
6293 IOCB_t
*icmd
, *oldcmd
;
6294 union lpfc_wqe128
*wqe
;
6295 struct lpfc_iocbq
*elsiocb
;
6301 cmdsize
= sizeof(uint32_t) + sizeof(uint32_t)
6302 + (2 * sizeof(struct lpfc_name
));
6304 cmdsize
+= sizeof(RNID_TOP_DISC
);
6306 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
6307 ndlp
->nlp_DID
, ELS_CMD_ACC
);
6311 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
6312 wqe
= &elsiocb
->wqe
;
6313 bf_set(wqe_ctxt_tag
, &wqe
->generic
.wqe_com
,
6314 get_job_ulpcontext(phba
, oldiocb
)); /* Xri / rx_id */
6315 ulp_context
= get_job_ulpcontext(phba
, elsiocb
);
6316 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
6317 get_job_rcvoxid(phba
, oldiocb
));
6319 icmd
= &elsiocb
->iocb
;
6320 oldcmd
= &oldiocb
->iocb
;
6321 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
6322 ulp_context
= elsiocb
->iocb
.ulpContext
;
6323 icmd
->unsli3
.rcvsli3
.ox_id
=
6324 oldcmd
->unsli3
.rcvsli3
.ox_id
;
6327 /* Xmit RNID ACC response tag <ulpIoTag> */
6328 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6329 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
6330 elsiocb
->iotag
, ulp_context
);
6331 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
6332 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
6333 pcmd
+= sizeof(uint32_t);
6335 memset(pcmd
, 0, sizeof(RNID
));
6336 rn
= (RNID
*) (pcmd
);
6337 rn
->Format
= format
;
6338 rn
->CommonLen
= (2 * sizeof(struct lpfc_name
));
6339 memcpy(&rn
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
6340 memcpy(&rn
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
6343 rn
->SpecificLen
= 0;
6345 case RNID_TOPOLOGY_DISC
:
6346 rn
->SpecificLen
= sizeof(RNID_TOP_DISC
);
6347 memcpy(&rn
->un
.topologyDisc
.portName
,
6348 &vport
->fc_portname
, sizeof(struct lpfc_name
));
6349 rn
->un
.topologyDisc
.unitType
= RNID_HBA
;
6350 rn
->un
.topologyDisc
.physPort
= 0;
6351 rn
->un
.topologyDisc
.attachedNodes
= 0;
6355 rn
->SpecificLen
= 0;
6359 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
6360 "Issue ACC RNID: did:x%x flg:x%x refcnt %d",
6361 ndlp
->nlp_DID
, ndlp
->nlp_flag
, kref_read(&ndlp
->kref
));
6363 phba
->fc_stat
.elsXmitACC
++;
6364 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_rsp
;
6365 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
6366 if (!elsiocb
->ndlp
) {
6367 lpfc_els_free_iocb(phba
, elsiocb
);
6371 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
6372 if (rc
== IOCB_ERROR
) {
6373 lpfc_els_free_iocb(phba
, elsiocb
);
6382 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
6383 * @vport: pointer to a virtual N_Port data structure.
6384 * @iocb: pointer to the lpfc command iocb data structure.
6385 * @ndlp: pointer to a node-list data structure.
6390 lpfc_els_clear_rrq(struct lpfc_vport
*vport
,
6391 struct lpfc_iocbq
*iocb
, struct lpfc_nodelist
*ndlp
)
6393 struct lpfc_hba
*phba
= vport
->phba
;
6398 struct lpfc_node_rrq
*prrq
;
6401 pcmd
= (uint8_t *)iocb
->cmd_dmabuf
->virt
;
6402 pcmd
+= sizeof(uint32_t);
6403 rrq
= (struct RRQ
*)pcmd
;
6404 rrq
->rrq_exchg
= be32_to_cpu(rrq
->rrq_exchg
);
6405 rxid
= bf_get(rrq_rxid
, rrq
);
6407 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6408 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
6410 be32_to_cpu(bf_get(rrq_did
, rrq
)),
6411 bf_get(rrq_oxid
, rrq
),
6413 get_wqe_reqtag(iocb
),
6414 get_job_ulpcontext(phba
, iocb
));
6416 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
6417 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
6418 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rrq
->rrq_exchg
);
6419 if (vport
->fc_myDID
== be32_to_cpu(bf_get(rrq_did
, rrq
)))
6420 xri
= bf_get(rrq_oxid
, rrq
);
6423 prrq
= lpfc_get_active_rrq(vport
, xri
, ndlp
->nlp_DID
);
6425 lpfc_clr_rrq_active(phba
, xri
, prrq
);
6430 * lpfc_els_rsp_echo_acc - Issue echo acc response
6431 * @vport: pointer to a virtual N_Port data structure.
6432 * @data: pointer to echo data to return in the accept.
6433 * @oldiocb: pointer to the original lpfc command iocb data structure.
6434 * @ndlp: pointer to a node-list data structure.
6437 * 0 - Successfully issued acc echo response
6438 * 1 - Failed to issue acc echo response
6441 lpfc_els_rsp_echo_acc(struct lpfc_vport
*vport
, uint8_t *data
,
6442 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
6444 struct lpfc_hba
*phba
= vport
->phba
;
6445 IOCB_t
*icmd
, *oldcmd
;
6446 union lpfc_wqe128
*wqe
;
6447 struct lpfc_iocbq
*elsiocb
;
6453 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6454 cmdsize
= oldiocb
->wcqe_cmpl
.total_data_placed
;
6456 cmdsize
= oldiocb
->iocb
.unsli3
.rcvsli3
.acc_len
;
6458 /* The accumulated length can exceed the BPL_SIZE. For
6459 * now, use this as the limit
6461 if (cmdsize
> LPFC_BPL_SIZE
)
6462 cmdsize
= LPFC_BPL_SIZE
;
6463 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
6464 ndlp
->nlp_DID
, ELS_CMD_ACC
);
6468 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
6469 wqe
= &elsiocb
->wqe
;
6470 bf_set(wqe_ctxt_tag
, &wqe
->generic
.wqe_com
,
6471 get_job_ulpcontext(phba
, oldiocb
)); /* Xri / rx_id */
6472 ulp_context
= get_job_ulpcontext(phba
, elsiocb
);
6473 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
6474 get_job_rcvoxid(phba
, oldiocb
));
6476 icmd
= &elsiocb
->iocb
;
6477 oldcmd
= &oldiocb
->iocb
;
6478 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
6479 ulp_context
= elsiocb
->iocb
.ulpContext
;
6480 icmd
->unsli3
.rcvsli3
.ox_id
=
6481 oldcmd
->unsli3
.rcvsli3
.ox_id
;
6484 /* Xmit ECHO ACC response tag <ulpIoTag> */
6485 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6486 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
6487 elsiocb
->iotag
, ulp_context
);
6488 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
6489 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
6490 pcmd
+= sizeof(uint32_t);
6491 memcpy(pcmd
, data
, cmdsize
- sizeof(uint32_t));
6493 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
6494 "Issue ACC ECHO: did:x%x flg:x%x refcnt %d",
6495 ndlp
->nlp_DID
, ndlp
->nlp_flag
, kref_read(&ndlp
->kref
));
6497 phba
->fc_stat
.elsXmitACC
++;
6498 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_rsp
;
6499 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
6500 if (!elsiocb
->ndlp
) {
6501 lpfc_els_free_iocb(phba
, elsiocb
);
6505 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
6506 if (rc
== IOCB_ERROR
) {
6507 lpfc_els_free_iocb(phba
, elsiocb
);
6516 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
6517 * @vport: pointer to a host virtual N_Port data structure.
6519 * This routine issues Address Discover (ADISC) ELS commands to those
6520 * N_Ports which are in node port recovery state and ADISC has not been issued
6521 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
6522 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
6523 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
6524 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
6525 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
6526 * IOCBs quit for later pick up. On the other hand, after walking through
6527 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
6528 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
6529 * no more ADISC need to be sent.
6532 * The number of N_Ports with adisc issued.
6535 lpfc_els_disc_adisc(struct lpfc_vport
*vport
)
6537 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
6540 /* go thru NPR nodes and issue any remaining ELS ADISCs */
6541 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
6543 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
||
6544 !(ndlp
->nlp_flag
& NLP_NPR_ADISC
))
6547 spin_lock_irq(&ndlp
->lock
);
6548 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
6549 spin_unlock_irq(&ndlp
->lock
);
6551 if (!(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
6552 /* This node was marked for ADISC but was not picked
6553 * for discovery. This is possible if the node was
6554 * missing in gidft response.
6556 * At time of marking node for ADISC, we skipped unreg
6559 lpfc_nlp_unreg_node(vport
, ndlp
);
6560 lpfc_unreg_rpi(vport
, ndlp
);
6564 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
6565 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
6566 lpfc_issue_els_adisc(vport
, ndlp
, 0);
6568 vport
->num_disc_nodes
++;
6569 if (vport
->num_disc_nodes
>=
6570 vport
->cfg_discovery_threads
) {
6571 set_bit(FC_NLP_MORE
, &vport
->fc_flag
);
6577 clear_bit(FC_NLP_MORE
, &vport
->fc_flag
);
6582 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
6583 * @vport: pointer to a host virtual N_Port data structure.
6585 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
6586 * which are in node port recovery state, with a @vport. Each time an ELS
6587 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
6588 * the per @vport number of discover count (num_disc_nodes) shall be
6589 * incremented. If the num_disc_nodes reaches a pre-configured threshold
6590 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
6591 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
6592 * later pick up. On the other hand, after walking through all the ndlps with
6593 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
6594 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
6595 * PLOGI need to be sent.
6598 * The number of N_Ports with plogi issued.
6601 lpfc_els_disc_plogi(struct lpfc_vport
*vport
)
6603 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
6606 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
6607 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
6608 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
6609 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
6610 (ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0 &&
6611 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) == 0) {
6612 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
6613 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
6614 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
6616 vport
->num_disc_nodes
++;
6617 if (vport
->num_disc_nodes
>=
6618 vport
->cfg_discovery_threads
) {
6619 set_bit(FC_NLP_MORE
, &vport
->fc_flag
);
6625 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
6626 "6452 Discover PLOGI %d flag x%lx\n",
6627 sentplogi
, vport
->fc_flag
);
6630 lpfc_set_disctmo(vport
);
6632 clear_bit(FC_NLP_MORE
, &vport
->fc_flag
);
6637 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc
*desc
,
6641 desc
->tag
= cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG
);
6642 desc
->payload
.els_req
= word0
;
6643 desc
->length
= cpu_to_be32(sizeof(desc
->payload
));
6645 return sizeof(struct fc_rdp_link_service_desc
);
6649 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc
*desc
,
6650 uint8_t *page_a0
, uint8_t *page_a2
)
6652 uint16_t wavelength
;
6653 uint16_t temperature
;
6659 struct sff_trasnceiver_codes_byte4
*trasn_code_byte4
;
6660 struct sff_trasnceiver_codes_byte5
*trasn_code_byte5
;
6662 desc
->tag
= cpu_to_be32(RDP_SFP_DESC_TAG
);
6664 trasn_code_byte4
= (struct sff_trasnceiver_codes_byte4
*)
6665 &page_a0
[SSF_TRANSCEIVER_CODE_B4
];
6666 trasn_code_byte5
= (struct sff_trasnceiver_codes_byte5
*)
6667 &page_a0
[SSF_TRANSCEIVER_CODE_B5
];
6669 if ((trasn_code_byte4
->fc_sw_laser
) ||
6670 (trasn_code_byte5
->fc_sw_laser_sl
) ||
6671 (trasn_code_byte5
->fc_sw_laser_sn
)) { /* check if its short WL */
6672 flag
|= (SFP_FLAG_PT_SWLASER
<< SFP_FLAG_PT_SHIFT
);
6673 } else if (trasn_code_byte4
->fc_lw_laser
) {
6674 wavelength
= (page_a0
[SSF_WAVELENGTH_B1
] << 8) |
6675 page_a0
[SSF_WAVELENGTH_B0
];
6676 if (wavelength
== SFP_WAVELENGTH_LC1310
)
6677 flag
|= SFP_FLAG_PT_LWLASER_LC1310
<< SFP_FLAG_PT_SHIFT
;
6678 if (wavelength
== SFP_WAVELENGTH_LL1550
)
6679 flag
|= SFP_FLAG_PT_LWLASER_LL1550
<< SFP_FLAG_PT_SHIFT
;
6681 /* check if its SFP+ */
6682 flag
|= ((page_a0
[SSF_IDENTIFIER
] == SFF_PG0_IDENT_SFP
) ?
6683 SFP_FLAG_CT_SFP_PLUS
: SFP_FLAG_CT_UNKNOWN
)
6684 << SFP_FLAG_CT_SHIFT
;
6686 /* check if its OPTICAL */
6687 flag
|= ((page_a0
[SSF_CONNECTOR
] == SFF_PG0_CONNECTOR_LC
) ?
6688 SFP_FLAG_IS_OPTICAL_PORT
: 0)
6689 << SFP_FLAG_IS_OPTICAL_SHIFT
;
6691 temperature
= (page_a2
[SFF_TEMPERATURE_B1
] << 8 |
6692 page_a2
[SFF_TEMPERATURE_B0
]);
6693 vcc
= (page_a2
[SFF_VCC_B1
] << 8 |
6694 page_a2
[SFF_VCC_B0
]);
6695 tx_power
= (page_a2
[SFF_TXPOWER_B1
] << 8 |
6696 page_a2
[SFF_TXPOWER_B0
]);
6697 tx_bias
= (page_a2
[SFF_TX_BIAS_CURRENT_B1
] << 8 |
6698 page_a2
[SFF_TX_BIAS_CURRENT_B0
]);
6699 rx_power
= (page_a2
[SFF_RXPOWER_B1
] << 8 |
6700 page_a2
[SFF_RXPOWER_B0
]);
6701 desc
->sfp_info
.temperature
= cpu_to_be16(temperature
);
6702 desc
->sfp_info
.rx_power
= cpu_to_be16(rx_power
);
6703 desc
->sfp_info
.tx_bias
= cpu_to_be16(tx_bias
);
6704 desc
->sfp_info
.tx_power
= cpu_to_be16(tx_power
);
6705 desc
->sfp_info
.vcc
= cpu_to_be16(vcc
);
6707 desc
->sfp_info
.flags
= cpu_to_be16(flag
);
6708 desc
->length
= cpu_to_be32(sizeof(desc
->sfp_info
));
6710 return sizeof(struct fc_rdp_sfp_desc
);
6714 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc
*desc
,
6719 desc
->tag
= cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG
);
6721 type
= VN_PT_PHY_PF_PORT
<< VN_PT_PHY_SHIFT
;
6723 desc
->info
.port_type
= cpu_to_be32(type
);
6725 desc
->info
.link_status
.link_failure_cnt
=
6726 cpu_to_be32(stat
->linkFailureCnt
);
6727 desc
->info
.link_status
.loss_of_synch_cnt
=
6728 cpu_to_be32(stat
->lossSyncCnt
);
6729 desc
->info
.link_status
.loss_of_signal_cnt
=
6730 cpu_to_be32(stat
->lossSignalCnt
);
6731 desc
->info
.link_status
.primitive_seq_proto_err
=
6732 cpu_to_be32(stat
->primSeqErrCnt
);
6733 desc
->info
.link_status
.invalid_trans_word
=
6734 cpu_to_be32(stat
->invalidXmitWord
);
6735 desc
->info
.link_status
.invalid_crc_cnt
= cpu_to_be32(stat
->crcCnt
);
6737 desc
->length
= cpu_to_be32(sizeof(desc
->info
));
6739 return sizeof(struct fc_rdp_link_error_status_desc
);
6743 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc
*desc
, READ_LNK_VAR
*stat
,
6744 struct lpfc_vport
*vport
)
6748 desc
->tag
= cpu_to_be32(RDP_BBC_DESC_TAG
);
6750 bbCredit
= vport
->fc_sparam
.cmn
.bbCreditLsb
|
6751 (vport
->fc_sparam
.cmn
.bbCreditMsb
<< 8);
6752 desc
->bbc_info
.port_bbc
= cpu_to_be32(bbCredit
);
6753 if (vport
->phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) {
6754 bbCredit
= vport
->phba
->fc_fabparam
.cmn
.bbCreditLsb
|
6755 (vport
->phba
->fc_fabparam
.cmn
.bbCreditMsb
<< 8);
6756 desc
->bbc_info
.attached_port_bbc
= cpu_to_be32(bbCredit
);
6758 desc
->bbc_info
.attached_port_bbc
= 0;
6761 desc
->bbc_info
.rtt
= 0;
6762 desc
->length
= cpu_to_be32(sizeof(desc
->bbc_info
));
6764 return sizeof(struct fc_rdp_bbc_desc
);
6768 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba
*phba
,
6769 struct fc_rdp_oed_sfp_desc
*desc
, uint8_t *page_a2
)
6773 desc
->tag
= cpu_to_be32(RDP_OED_DESC_TAG
);
6775 desc
->oed_info
.hi_alarm
= page_a2
[SSF_TEMP_HIGH_ALARM
];
6776 desc
->oed_info
.lo_alarm
= page_a2
[SSF_TEMP_LOW_ALARM
];
6777 desc
->oed_info
.hi_warning
= page_a2
[SSF_TEMP_HIGH_WARNING
];
6778 desc
->oed_info
.lo_warning
= page_a2
[SSF_TEMP_LOW_WARNING
];
6780 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_HIGH_TEMPERATURE
)
6781 flags
|= RDP_OET_HIGH_ALARM
;
6782 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_LOW_TEMPERATURE
)
6783 flags
|= RDP_OET_LOW_ALARM
;
6784 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_HIGH_TEMPERATURE
)
6785 flags
|= RDP_OET_HIGH_WARNING
;
6786 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_LOW_TEMPERATURE
)
6787 flags
|= RDP_OET_LOW_WARNING
;
6789 flags
|= ((0xf & RDP_OED_TEMPERATURE
) << RDP_OED_TYPE_SHIFT
);
6790 desc
->oed_info
.function_flags
= cpu_to_be32(flags
);
6791 desc
->length
= cpu_to_be32(sizeof(desc
->oed_info
));
6792 return sizeof(struct fc_rdp_oed_sfp_desc
);
6796 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba
*phba
,
6797 struct fc_rdp_oed_sfp_desc
*desc
,
6802 desc
->tag
= cpu_to_be32(RDP_OED_DESC_TAG
);
6804 desc
->oed_info
.hi_alarm
= page_a2
[SSF_VOLTAGE_HIGH_ALARM
];
6805 desc
->oed_info
.lo_alarm
= page_a2
[SSF_VOLTAGE_LOW_ALARM
];
6806 desc
->oed_info
.hi_warning
= page_a2
[SSF_VOLTAGE_HIGH_WARNING
];
6807 desc
->oed_info
.lo_warning
= page_a2
[SSF_VOLTAGE_LOW_WARNING
];
6809 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_HIGH_VOLTAGE
)
6810 flags
|= RDP_OET_HIGH_ALARM
;
6811 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_LOW_VOLTAGE
)
6812 flags
|= RDP_OET_LOW_ALARM
;
6813 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_HIGH_VOLTAGE
)
6814 flags
|= RDP_OET_HIGH_WARNING
;
6815 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_LOW_VOLTAGE
)
6816 flags
|= RDP_OET_LOW_WARNING
;
6818 flags
|= ((0xf & RDP_OED_VOLTAGE
) << RDP_OED_TYPE_SHIFT
);
6819 desc
->oed_info
.function_flags
= cpu_to_be32(flags
);
6820 desc
->length
= cpu_to_be32(sizeof(desc
->oed_info
));
6821 return sizeof(struct fc_rdp_oed_sfp_desc
);
6825 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba
*phba
,
6826 struct fc_rdp_oed_sfp_desc
*desc
,
6831 desc
->tag
= cpu_to_be32(RDP_OED_DESC_TAG
);
6833 desc
->oed_info
.hi_alarm
= page_a2
[SSF_BIAS_HIGH_ALARM
];
6834 desc
->oed_info
.lo_alarm
= page_a2
[SSF_BIAS_LOW_ALARM
];
6835 desc
->oed_info
.hi_warning
= page_a2
[SSF_BIAS_HIGH_WARNING
];
6836 desc
->oed_info
.lo_warning
= page_a2
[SSF_BIAS_LOW_WARNING
];
6838 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_HIGH_TXBIAS
)
6839 flags
|= RDP_OET_HIGH_ALARM
;
6840 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_LOW_TXBIAS
)
6841 flags
|= RDP_OET_LOW_ALARM
;
6842 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_HIGH_TXBIAS
)
6843 flags
|= RDP_OET_HIGH_WARNING
;
6844 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_LOW_TXBIAS
)
6845 flags
|= RDP_OET_LOW_WARNING
;
6847 flags
|= ((0xf & RDP_OED_TXBIAS
) << RDP_OED_TYPE_SHIFT
);
6848 desc
->oed_info
.function_flags
= cpu_to_be32(flags
);
6849 desc
->length
= cpu_to_be32(sizeof(desc
->oed_info
));
6850 return sizeof(struct fc_rdp_oed_sfp_desc
);
6854 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba
*phba
,
6855 struct fc_rdp_oed_sfp_desc
*desc
,
6860 desc
->tag
= cpu_to_be32(RDP_OED_DESC_TAG
);
6862 desc
->oed_info
.hi_alarm
= page_a2
[SSF_TXPOWER_HIGH_ALARM
];
6863 desc
->oed_info
.lo_alarm
= page_a2
[SSF_TXPOWER_LOW_ALARM
];
6864 desc
->oed_info
.hi_warning
= page_a2
[SSF_TXPOWER_HIGH_WARNING
];
6865 desc
->oed_info
.lo_warning
= page_a2
[SSF_TXPOWER_LOW_WARNING
];
6867 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_HIGH_TXPOWER
)
6868 flags
|= RDP_OET_HIGH_ALARM
;
6869 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_LOW_TXPOWER
)
6870 flags
|= RDP_OET_LOW_ALARM
;
6871 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_HIGH_TXPOWER
)
6872 flags
|= RDP_OET_HIGH_WARNING
;
6873 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_LOW_TXPOWER
)
6874 flags
|= RDP_OET_LOW_WARNING
;
6876 flags
|= ((0xf & RDP_OED_TXPOWER
) << RDP_OED_TYPE_SHIFT
);
6877 desc
->oed_info
.function_flags
= cpu_to_be32(flags
);
6878 desc
->length
= cpu_to_be32(sizeof(desc
->oed_info
));
6879 return sizeof(struct fc_rdp_oed_sfp_desc
);
6884 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba
*phba
,
6885 struct fc_rdp_oed_sfp_desc
*desc
,
6890 desc
->tag
= cpu_to_be32(RDP_OED_DESC_TAG
);
6892 desc
->oed_info
.hi_alarm
= page_a2
[SSF_RXPOWER_HIGH_ALARM
];
6893 desc
->oed_info
.lo_alarm
= page_a2
[SSF_RXPOWER_LOW_ALARM
];
6894 desc
->oed_info
.hi_warning
= page_a2
[SSF_RXPOWER_HIGH_WARNING
];
6895 desc
->oed_info
.lo_warning
= page_a2
[SSF_RXPOWER_LOW_WARNING
];
6897 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_HIGH_RXPOWER
)
6898 flags
|= RDP_OET_HIGH_ALARM
;
6899 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_LOW_RXPOWER
)
6900 flags
|= RDP_OET_LOW_ALARM
;
6901 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_HIGH_RXPOWER
)
6902 flags
|= RDP_OET_HIGH_WARNING
;
6903 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_LOW_RXPOWER
)
6904 flags
|= RDP_OET_LOW_WARNING
;
6906 flags
|= ((0xf & RDP_OED_RXPOWER
) << RDP_OED_TYPE_SHIFT
);
6907 desc
->oed_info
.function_flags
= cpu_to_be32(flags
);
6908 desc
->length
= cpu_to_be32(sizeof(desc
->oed_info
));
6909 return sizeof(struct fc_rdp_oed_sfp_desc
);
6913 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc
*desc
,
6914 uint8_t *page_a0
, struct lpfc_vport
*vport
)
6916 desc
->tag
= cpu_to_be32(RDP_OPD_DESC_TAG
);
6917 memcpy(desc
->opd_info
.vendor_name
, &page_a0
[SSF_VENDOR_NAME
], 16);
6918 memcpy(desc
->opd_info
.model_number
, &page_a0
[SSF_VENDOR_PN
], 16);
6919 memcpy(desc
->opd_info
.serial_number
, &page_a0
[SSF_VENDOR_SN
], 16);
6920 memcpy(desc
->opd_info
.revision
, &page_a0
[SSF_VENDOR_REV
], 4);
6921 memcpy(desc
->opd_info
.date
, &page_a0
[SSF_DATE_CODE
], 8);
6922 desc
->length
= cpu_to_be32(sizeof(desc
->opd_info
));
6923 return sizeof(struct fc_rdp_opd_sfp_desc
);
6927 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc
*desc
, READ_LNK_VAR
*stat
)
6929 if (bf_get(lpfc_read_link_stat_gec2
, stat
) == 0)
6931 desc
->tag
= cpu_to_be32(RDP_FEC_DESC_TAG
);
6933 desc
->info
.CorrectedBlocks
=
6934 cpu_to_be32(stat
->fecCorrBlkCount
);
6935 desc
->info
.UncorrectableBlocks
=
6936 cpu_to_be32(stat
->fecUncorrBlkCount
);
6938 desc
->length
= cpu_to_be32(sizeof(desc
->info
));
6940 return sizeof(struct fc_fec_rdp_desc
);
6944 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc
*desc
, struct lpfc_hba
*phba
)
6946 uint16_t rdp_cap
= 0;
6949 desc
->tag
= cpu_to_be32(RDP_PORT_SPEED_DESC_TAG
);
6951 switch (phba
->fc_linkspeed
) {
6952 case LPFC_LINK_SPEED_1GHZ
:
6953 rdp_speed
= RDP_PS_1GB
;
6955 case LPFC_LINK_SPEED_2GHZ
:
6956 rdp_speed
= RDP_PS_2GB
;
6958 case LPFC_LINK_SPEED_4GHZ
:
6959 rdp_speed
= RDP_PS_4GB
;
6961 case LPFC_LINK_SPEED_8GHZ
:
6962 rdp_speed
= RDP_PS_8GB
;
6964 case LPFC_LINK_SPEED_10GHZ
:
6965 rdp_speed
= RDP_PS_10GB
;
6967 case LPFC_LINK_SPEED_16GHZ
:
6968 rdp_speed
= RDP_PS_16GB
;
6970 case LPFC_LINK_SPEED_32GHZ
:
6971 rdp_speed
= RDP_PS_32GB
;
6973 case LPFC_LINK_SPEED_64GHZ
:
6974 rdp_speed
= RDP_PS_64GB
;
6976 case LPFC_LINK_SPEED_128GHZ
:
6977 rdp_speed
= RDP_PS_128GB
;
6979 case LPFC_LINK_SPEED_256GHZ
:
6980 rdp_speed
= RDP_PS_256GB
;
6983 rdp_speed
= RDP_PS_UNKNOWN
;
6987 desc
->info
.port_speed
.speed
= cpu_to_be16(rdp_speed
);
6989 if (phba
->lmt
& LMT_256Gb
)
6990 rdp_cap
|= RDP_PS_256GB
;
6991 if (phba
->lmt
& LMT_128Gb
)
6992 rdp_cap
|= RDP_PS_128GB
;
6993 if (phba
->lmt
& LMT_64Gb
)
6994 rdp_cap
|= RDP_PS_64GB
;
6995 if (phba
->lmt
& LMT_32Gb
)
6996 rdp_cap
|= RDP_PS_32GB
;
6997 if (phba
->lmt
& LMT_16Gb
)
6998 rdp_cap
|= RDP_PS_16GB
;
6999 if (phba
->lmt
& LMT_10Gb
)
7000 rdp_cap
|= RDP_PS_10GB
;
7001 if (phba
->lmt
& LMT_8Gb
)
7002 rdp_cap
|= RDP_PS_8GB
;
7003 if (phba
->lmt
& LMT_4Gb
)
7004 rdp_cap
|= RDP_PS_4GB
;
7005 if (phba
->lmt
& LMT_2Gb
)
7006 rdp_cap
|= RDP_PS_2GB
;
7007 if (phba
->lmt
& LMT_1Gb
)
7008 rdp_cap
|= RDP_PS_1GB
;
7011 rdp_cap
= RDP_CAP_UNKNOWN
;
7012 if (phba
->cfg_link_speed
!= LPFC_USER_LINK_SPEED_AUTO
)
7013 rdp_cap
|= RDP_CAP_USER_CONFIGURED
;
7015 desc
->info
.port_speed
.capabilities
= cpu_to_be16(rdp_cap
);
7016 desc
->length
= cpu_to_be32(sizeof(desc
->info
));
7017 return sizeof(struct fc_rdp_port_speed_desc
);
7021 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc
*desc
,
7022 struct lpfc_vport
*vport
)
7025 desc
->tag
= cpu_to_be32(RDP_PORT_NAMES_DESC_TAG
);
7027 memcpy(desc
->port_names
.wwnn
, &vport
->fc_nodename
,
7028 sizeof(desc
->port_names
.wwnn
));
7030 memcpy(desc
->port_names
.wwpn
, &vport
->fc_portname
,
7031 sizeof(desc
->port_names
.wwpn
));
7033 desc
->length
= cpu_to_be32(sizeof(desc
->port_names
));
7034 return sizeof(struct fc_rdp_port_name_desc
);
7038 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc
*desc
,
7039 struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
7042 desc
->tag
= cpu_to_be32(RDP_PORT_NAMES_DESC_TAG
);
7043 if (test_bit(FC_FABRIC
, &vport
->fc_flag
)) {
7044 memcpy(desc
->port_names
.wwnn
, &vport
->fabric_nodename
,
7045 sizeof(desc
->port_names
.wwnn
));
7047 memcpy(desc
->port_names
.wwpn
, &vport
->fabric_portname
,
7048 sizeof(desc
->port_names
.wwpn
));
7049 } else { /* Point to Point */
7050 memcpy(desc
->port_names
.wwnn
, &ndlp
->nlp_nodename
,
7051 sizeof(desc
->port_names
.wwnn
));
7053 memcpy(desc
->port_names
.wwpn
, &ndlp
->nlp_portname
,
7054 sizeof(desc
->port_names
.wwpn
));
7057 desc
->length
= cpu_to_be32(sizeof(desc
->port_names
));
7058 return sizeof(struct fc_rdp_port_name_desc
);
7062 lpfc_els_rdp_cmpl(struct lpfc_hba
*phba
, struct lpfc_rdp_context
*rdp_context
,
7065 struct lpfc_nodelist
*ndlp
= rdp_context
->ndlp
;
7066 struct lpfc_vport
*vport
= ndlp
->vport
;
7067 struct lpfc_iocbq
*elsiocb
;
7068 struct ulp_bde64
*bpl
;
7070 union lpfc_wqe128
*wqe
;
7072 struct ls_rjt
*stat
;
7073 struct fc_rdp_res_frame
*rdp_res
;
7074 uint32_t cmdsize
, len
;
7079 if (status
!= SUCCESS
)
7082 /* This will change once we know the true size of the RDP payload */
7083 cmdsize
= sizeof(struct fc_rdp_res_frame
);
7085 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
,
7086 lpfc_max_els_tries
, rdp_context
->ndlp
,
7087 rdp_context
->ndlp
->nlp_DID
, ELS_CMD_ACC
);
7089 goto free_rdp_context
;
7091 ulp_context
= get_job_ulpcontext(phba
, elsiocb
);
7092 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
7093 wqe
= &elsiocb
->wqe
;
7094 /* ox-id of the frame */
7095 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
7096 rdp_context
->ox_id
);
7097 bf_set(wqe_ctxt_tag
, &wqe
->xmit_els_rsp
.wqe_com
,
7098 rdp_context
->rx_id
);
7100 icmd
= &elsiocb
->iocb
;
7101 icmd
->ulpContext
= rdp_context
->rx_id
;
7102 icmd
->unsli3
.rcvsli3
.ox_id
= rdp_context
->ox_id
;
7105 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7106 "2171 Xmit RDP response tag x%x xri x%x, "
7107 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
7108 elsiocb
->iotag
, ulp_context
,
7109 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
7111 rdp_res
= (struct fc_rdp_res_frame
*)elsiocb
->cmd_dmabuf
->virt
;
7112 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
7113 memset(pcmd
, 0, sizeof(struct fc_rdp_res_frame
));
7114 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
7116 /* Update Alarm and Warning */
7117 flag_ptr
= (uint16_t *)(rdp_context
->page_a2
+ SSF_ALARM_FLAGS
);
7118 phba
->sfp_alarm
|= *flag_ptr
;
7119 flag_ptr
= (uint16_t *)(rdp_context
->page_a2
+ SSF_WARNING_FLAGS
);
7120 phba
->sfp_warning
|= *flag_ptr
;
7122 /* For RDP payload */
7124 len
+= lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc
*)
7125 (len
+ pcmd
), ELS_CMD_RDP
);
7127 len
+= lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc
*)(len
+ pcmd
),
7128 rdp_context
->page_a0
, rdp_context
->page_a2
);
7129 len
+= lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc
*)(len
+ pcmd
),
7131 len
+= lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc
*)
7132 (len
+ pcmd
), &rdp_context
->link_stat
);
7133 len
+= lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc
*)
7134 (len
+ pcmd
), vport
);
7135 len
+= lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc
*)
7136 (len
+ pcmd
), vport
, ndlp
);
7137 len
+= lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc
*)(len
+ pcmd
),
7138 &rdp_context
->link_stat
);
7139 len
+= lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc
*)(len
+ pcmd
),
7140 &rdp_context
->link_stat
, vport
);
7141 len
+= lpfc_rdp_res_oed_temp_desc(phba
,
7142 (struct fc_rdp_oed_sfp_desc
*)(len
+ pcmd
),
7143 rdp_context
->page_a2
);
7144 len
+= lpfc_rdp_res_oed_voltage_desc(phba
,
7145 (struct fc_rdp_oed_sfp_desc
*)(len
+ pcmd
),
7146 rdp_context
->page_a2
);
7147 len
+= lpfc_rdp_res_oed_txbias_desc(phba
,
7148 (struct fc_rdp_oed_sfp_desc
*)(len
+ pcmd
),
7149 rdp_context
->page_a2
);
7150 len
+= lpfc_rdp_res_oed_txpower_desc(phba
,
7151 (struct fc_rdp_oed_sfp_desc
*)(len
+ pcmd
),
7152 rdp_context
->page_a2
);
7153 len
+= lpfc_rdp_res_oed_rxpower_desc(phba
,
7154 (struct fc_rdp_oed_sfp_desc
*)(len
+ pcmd
),
7155 rdp_context
->page_a2
);
7156 len
+= lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc
*)(len
+ pcmd
),
7157 rdp_context
->page_a0
, vport
);
7159 rdp_res
->length
= cpu_to_be32(len
- 8);
7160 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_rsp
;
7162 /* Now that we know the true size of the payload, update the BPL */
7163 bpl
= (struct ulp_bde64
*)elsiocb
->bpl_dmabuf
->virt
;
7164 bpl
->tus
.f
.bdeSize
= len
;
7165 bpl
->tus
.f
.bdeFlags
= 0;
7166 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
7168 phba
->fc_stat
.elsXmitACC
++;
7169 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
7170 if (!elsiocb
->ndlp
) {
7171 lpfc_els_free_iocb(phba
, elsiocb
);
7172 goto free_rdp_context
;
7175 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
7176 if (rc
== IOCB_ERROR
) {
7177 lpfc_els_free_iocb(phba
, elsiocb
);
7181 goto free_rdp_context
;
7184 cmdsize
= 2 * sizeof(uint32_t);
7185 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, lpfc_max_els_tries
,
7186 ndlp
, ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
7188 goto free_rdp_context
;
7190 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
7191 wqe
= &elsiocb
->wqe
;
7192 /* ox-id of the frame */
7193 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
7194 rdp_context
->ox_id
);
7195 bf_set(wqe_ctxt_tag
,
7196 &wqe
->xmit_els_rsp
.wqe_com
,
7197 rdp_context
->rx_id
);
7199 icmd
= &elsiocb
->iocb
;
7200 icmd
->ulpContext
= rdp_context
->rx_id
;
7201 icmd
->unsli3
.rcvsli3
.ox_id
= rdp_context
->ox_id
;
7204 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
7206 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
7207 stat
= (struct ls_rjt
*)(pcmd
+ sizeof(uint32_t));
7208 stat
->un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
7210 phba
->fc_stat
.elsXmitLSRJT
++;
7211 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_rsp
;
7212 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
7213 if (!elsiocb
->ndlp
) {
7214 lpfc_els_free_iocb(phba
, elsiocb
);
7215 goto free_rdp_context
;
7218 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
7219 if (rc
== IOCB_ERROR
) {
7220 lpfc_els_free_iocb(phba
, elsiocb
);
7225 /* This reference put is for the original unsolicited RDP. If the
7226 * prep failed, there is no reference to remove.
7233 lpfc_get_rdp_info(struct lpfc_hba
*phba
, struct lpfc_rdp_context
*rdp_context
)
7235 LPFC_MBOXQ_t
*mbox
= NULL
;
7238 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
7240 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_ELS
,
7241 "7105 failed to allocate mailbox memory");
7245 if (lpfc_sli4_dump_page_a0(phba
, mbox
))
7247 mbox
->vport
= rdp_context
->ndlp
->vport
;
7248 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_rdp_page_a0
;
7249 mbox
->ctx_u
.rdp
= rdp_context
;
7250 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
7251 if (rc
== MBX_NOT_FINISHED
) {
7252 lpfc_mbox_rsrc_cleanup(phba
, mbox
, MBOX_THD_UNLOCKED
);
7259 mempool_free(mbox
, phba
->mbox_mem_pool
);
7263 int lpfc_get_sfp_info_wait(struct lpfc_hba
*phba
,
7264 struct lpfc_rdp_context
*rdp_context
)
7266 LPFC_MBOXQ_t
*mbox
= NULL
;
7268 struct lpfc_dmabuf
*mp
;
7269 struct lpfc_dmabuf
*mpsave
;
7273 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
7275 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_ELS
,
7276 "7205 failed to allocate mailbox memory");
7280 if (lpfc_sli4_dump_page_a0(phba
, mbox
))
7285 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
7287 mb
->un
.varDmp
.cv
= 1;
7288 mb
->un
.varDmp
.co
= 1;
7289 mb
->un
.varWords
[2] = 0;
7290 mb
->un
.varWords
[3] = DMP_SFF_PAGE_A0_SIZE
/ 4;
7291 mb
->un
.varWords
[4] = 0;
7292 mb
->un
.varWords
[5] = 0;
7293 mb
->un
.varWords
[6] = 0;
7294 mb
->un
.varWords
[7] = 0;
7295 mb
->un
.varWords
[8] = 0;
7296 mb
->un
.varWords
[9] = 0;
7297 mb
->un
.varWords
[10] = 0;
7298 mbox
->in_ext_byte_len
= DMP_SFF_PAGE_A0_SIZE
;
7299 mbox
->out_ext_byte_len
= DMP_SFF_PAGE_A0_SIZE
;
7300 mbox
->mbox_offset_word
= 5;
7301 mbox
->ext_buf
= virt
;
7303 bf_set(lpfc_mbx_memory_dump_type3_length
,
7304 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_SFF_PAGE_A0_SIZE
);
7305 mbox
->u
.mqe
.un
.mem_dump_type3
.addr_lo
= putPaddrLow(mp
->phys
);
7306 mbox
->u
.mqe
.un
.mem_dump_type3
.addr_hi
= putPaddrHigh(mp
->phys
);
7308 mbox
->vport
= phba
->pport
;
7309 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_SLI4_CONFIG_TMO
);
7310 if (rc
== MBX_NOT_FINISHED
) {
7314 if (rc
== MBX_TIMEOUT
)
7316 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7321 if (bf_get(lpfc_mqe_status
, &mbox
->u
.mqe
)) {
7326 lpfc_sli_bemem_bcopy(mp
->virt
, &rdp_context
->page_a0
,
7327 DMP_SFF_PAGE_A0_SIZE
);
7329 memset(mbox
, 0, sizeof(*mbox
));
7330 memset(mp
->virt
, 0, DMP_SFF_PAGE_A2_SIZE
);
7331 INIT_LIST_HEAD(&mp
->list
);
7333 /* save address for completion */
7335 mbox
->vport
= phba
->pport
;
7337 bf_set(lpfc_mqe_command
, &mbox
->u
.mqe
, MBX_DUMP_MEMORY
);
7338 bf_set(lpfc_mbx_memory_dump_type3_type
,
7339 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_LMSD
);
7340 bf_set(lpfc_mbx_memory_dump_type3_link
,
7341 &mbox
->u
.mqe
.un
.mem_dump_type3
, phba
->sli4_hba
.physical_port
);
7342 bf_set(lpfc_mbx_memory_dump_type3_page_no
,
7343 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_PAGE_A2
);
7344 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
7346 mb
->un
.varDmp
.cv
= 1;
7347 mb
->un
.varDmp
.co
= 1;
7348 mb
->un
.varWords
[2] = 0;
7349 mb
->un
.varWords
[3] = DMP_SFF_PAGE_A2_SIZE
/ 4;
7350 mb
->un
.varWords
[4] = 0;
7351 mb
->un
.varWords
[5] = 0;
7352 mb
->un
.varWords
[6] = 0;
7353 mb
->un
.varWords
[7] = 0;
7354 mb
->un
.varWords
[8] = 0;
7355 mb
->un
.varWords
[9] = 0;
7356 mb
->un
.varWords
[10] = 0;
7357 mbox
->in_ext_byte_len
= DMP_SFF_PAGE_A2_SIZE
;
7358 mbox
->out_ext_byte_len
= DMP_SFF_PAGE_A2_SIZE
;
7359 mbox
->mbox_offset_word
= 5;
7360 mbox
->ext_buf
= virt
;
7362 bf_set(lpfc_mbx_memory_dump_type3_length
,
7363 &mbox
->u
.mqe
.un
.mem_dump_type3
, DMP_SFF_PAGE_A2_SIZE
);
7364 mbox
->u
.mqe
.un
.mem_dump_type3
.addr_lo
= putPaddrLow(mp
->phys
);
7365 mbox
->u
.mqe
.un
.mem_dump_type3
.addr_hi
= putPaddrHigh(mp
->phys
);
7368 rc
= lpfc_sli_issue_mbox_wait(phba
, mbox
, LPFC_MBOX_SLI4_CONFIG_TMO
);
7370 if (rc
== MBX_TIMEOUT
)
7372 if (bf_get(lpfc_mqe_status
, &mbox
->u
.mqe
)) {
7378 lpfc_sli_bemem_bcopy(mp
->virt
, &rdp_context
->page_a2
,
7379 DMP_SFF_PAGE_A2_SIZE
);
7382 if (mbox
->mbox_flag
& LPFC_MBX_WAKE
) {
7383 mbox
->ctx_buf
= mpsave
;
7384 lpfc_mbox_rsrc_cleanup(phba
, mbox
, MBOX_THD_UNLOCKED
);
7390 mempool_free(mbox
, phba
->mbox_mem_pool
);
7395 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
7396 * @vport: pointer to a host virtual N_Port data structure.
7397 * @cmdiocb: pointer to lpfc command iocb data structure.
7398 * @ndlp: pointer to a node-list data structure.
7400 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
7401 * IOCB. First, the payload of the unsolicited RDP is checked.
7402 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
7403 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
7404 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
7405 * gather all data and send RDP response.
7408 * 0 - Sent the acc response
7409 * 1 - Sent the reject response.
7412 lpfc_els_rcv_rdp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
7413 struct lpfc_nodelist
*ndlp
)
7415 struct lpfc_hba
*phba
= vport
->phba
;
7416 struct lpfc_dmabuf
*pcmd
;
7417 uint8_t rjt_err
, rjt_expl
= LSEXP_NOTHING_MORE
;
7418 struct fc_rdp_req_frame
*rdp_req
;
7419 struct lpfc_rdp_context
*rdp_context
;
7420 union lpfc_wqe128
*cmd
= NULL
;
7423 if (phba
->sli_rev
< LPFC_SLI_REV4
||
7424 bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) <
7425 LPFC_SLI_INTF_IF_TYPE_2
) {
7426 rjt_err
= LSRJT_UNABLE_TPC
;
7427 rjt_expl
= LSEXP_REQ_UNSUPPORTED
;
7431 if (phba
->sli_rev
< LPFC_SLI_REV4
||
7432 test_bit(HBA_FCOE_MODE
, &phba
->hba_flag
)) {
7433 rjt_err
= LSRJT_UNABLE_TPC
;
7434 rjt_expl
= LSEXP_REQ_UNSUPPORTED
;
7438 pcmd
= cmdiocb
->cmd_dmabuf
;
7439 rdp_req
= (struct fc_rdp_req_frame
*) pcmd
->virt
;
7441 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7442 "2422 ELS RDP Request "
7443 "dec len %d tag x%x port_id %d len %d\n",
7444 be32_to_cpu(rdp_req
->rdp_des_length
),
7445 be32_to_cpu(rdp_req
->nport_id_desc
.tag
),
7446 be32_to_cpu(rdp_req
->nport_id_desc
.nport_id
),
7447 be32_to_cpu(rdp_req
->nport_id_desc
.length
));
7449 if (sizeof(struct fc_rdp_nport_desc
) !=
7450 be32_to_cpu(rdp_req
->rdp_des_length
))
7452 if (RDP_N_PORT_DESC_TAG
!= be32_to_cpu(rdp_req
->nport_id_desc
.tag
))
7454 if (RDP_NPORT_ID_SIZE
!=
7455 be32_to_cpu(rdp_req
->nport_id_desc
.length
))
7457 rdp_context
= kzalloc(sizeof(struct lpfc_rdp_context
), GFP_KERNEL
);
7459 rjt_err
= LSRJT_UNABLE_TPC
;
7463 cmd
= &cmdiocb
->wqe
;
7464 rdp_context
->ndlp
= lpfc_nlp_get(ndlp
);
7465 if (!rdp_context
->ndlp
) {
7467 rjt_err
= LSRJT_UNABLE_TPC
;
7470 rdp_context
->ox_id
= bf_get(wqe_rcvoxid
,
7471 &cmd
->xmit_els_rsp
.wqe_com
);
7472 rdp_context
->rx_id
= bf_get(wqe_ctxt_tag
,
7473 &cmd
->xmit_els_rsp
.wqe_com
);
7474 rdp_context
->cmpl
= lpfc_els_rdp_cmpl
;
7475 if (lpfc_get_rdp_info(phba
, rdp_context
)) {
7476 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_ELS
,
7477 "2423 Unable to send mailbox");
7479 rjt_err
= LSRJT_UNABLE_TPC
;
7487 rjt_err
= LSRJT_LOGICAL_ERR
;
7490 memset(&stat
, 0, sizeof(stat
));
7491 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
7492 stat
.un
.b
.lsRjtRsnCodeExp
= rjt_expl
;
7493 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
7499 lpfc_els_lcb_rsp(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
7503 union lpfc_wqe128
*wqe
;
7505 struct lpfc_iocbq
*elsiocb
;
7506 struct lpfc_nodelist
*ndlp
;
7507 struct ls_rjt
*stat
;
7508 union lpfc_sli4_cfg_shdr
*shdr
;
7509 struct lpfc_lcb_context
*lcb_context
;
7510 struct fc_lcb_res_frame
*lcb_res
;
7511 uint32_t cmdsize
, shdr_status
, shdr_add_status
;
7515 lcb_context
= pmb
->ctx_u
.lcb
;
7516 ndlp
= lcb_context
->ndlp
;
7517 memset(&pmb
->ctx_u
, 0, sizeof(pmb
->ctx_u
));
7518 pmb
->ctx_buf
= NULL
;
7520 shdr
= (union lpfc_sli4_cfg_shdr
*)
7521 &pmb
->u
.mqe
.un
.beacon_config
.header
.cfg_shdr
;
7522 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
7523 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
7525 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
,
7526 "0194 SET_BEACON_CONFIG mailbox "
7527 "completed with status x%x add_status x%x,"
7528 " mbx status x%x\n",
7529 shdr_status
, shdr_add_status
, mb
->mbxStatus
);
7531 if ((mb
->mbxStatus
!= MBX_SUCCESS
) || shdr_status
||
7532 (shdr_add_status
== ADD_STATUS_OPERATION_ALREADY_ACTIVE
) ||
7533 (shdr_add_status
== ADD_STATUS_INVALID_REQUEST
)) {
7534 mempool_free(pmb
, phba
->mbox_mem_pool
);
7538 mempool_free(pmb
, phba
->mbox_mem_pool
);
7539 cmdsize
= sizeof(struct fc_lcb_res_frame
);
7540 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
7541 lpfc_max_els_tries
, ndlp
,
7542 ndlp
->nlp_DID
, ELS_CMD_ACC
);
7544 /* Decrement the ndlp reference count from previous mbox command */
7548 goto free_lcb_context
;
7550 lcb_res
= (struct fc_lcb_res_frame
*)elsiocb
->cmd_dmabuf
->virt
;
7552 memset(lcb_res
, 0, sizeof(struct fc_lcb_res_frame
));
7554 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
7555 wqe
= &elsiocb
->wqe
;
7556 bf_set(wqe_ctxt_tag
, &wqe
->generic
.wqe_com
, lcb_context
->rx_id
);
7557 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
7558 lcb_context
->ox_id
);
7560 icmd
= &elsiocb
->iocb
;
7561 icmd
->ulpContext
= lcb_context
->rx_id
;
7562 icmd
->unsli3
.rcvsli3
.ox_id
= lcb_context
->ox_id
;
7565 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
7566 *((uint32_t *)(pcmd
)) = ELS_CMD_ACC
;
7567 lcb_res
->lcb_sub_command
= lcb_context
->sub_command
;
7568 lcb_res
->lcb_type
= lcb_context
->type
;
7569 lcb_res
->capability
= lcb_context
->capability
;
7570 lcb_res
->lcb_frequency
= lcb_context
->frequency
;
7571 lcb_res
->lcb_duration
= lcb_context
->duration
;
7572 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_rsp
;
7573 phba
->fc_stat
.elsXmitACC
++;
7575 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
7576 if (!elsiocb
->ndlp
) {
7577 lpfc_els_free_iocb(phba
, elsiocb
);
7581 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
7582 if (rc
== IOCB_ERROR
) {
7583 lpfc_els_free_iocb(phba
, elsiocb
);
7591 cmdsize
= sizeof(struct fc_lcb_res_frame
);
7592 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
7593 lpfc_max_els_tries
, ndlp
,
7594 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
7597 goto free_lcb_context
;
7599 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
7600 wqe
= &elsiocb
->wqe
;
7601 bf_set(wqe_ctxt_tag
, &wqe
->generic
.wqe_com
, lcb_context
->rx_id
);
7602 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
7603 lcb_context
->ox_id
);
7605 icmd
= &elsiocb
->iocb
;
7606 icmd
->ulpContext
= lcb_context
->rx_id
;
7607 icmd
->unsli3
.rcvsli3
.ox_id
= lcb_context
->ox_id
;
7610 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
7612 *((uint32_t *)(pcmd
)) = ELS_CMD_LS_RJT
;
7613 stat
= (struct ls_rjt
*)(pcmd
+ sizeof(uint32_t));
7614 stat
->un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
7616 if (shdr_add_status
== ADD_STATUS_OPERATION_ALREADY_ACTIVE
)
7617 stat
->un
.b
.lsRjtRsnCodeExp
= LSEXP_CMD_IN_PROGRESS
;
7619 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_rsp
;
7620 phba
->fc_stat
.elsXmitLSRJT
++;
7621 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
7622 if (!elsiocb
->ndlp
) {
7623 lpfc_els_free_iocb(phba
, elsiocb
);
7624 goto free_lcb_context
;
7627 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
7628 if (rc
== IOCB_ERROR
) {
7629 lpfc_els_free_iocb(phba
, elsiocb
);
7637 lpfc_sli4_set_beacon(struct lpfc_vport
*vport
,
7638 struct lpfc_lcb_context
*lcb_context
,
7639 uint32_t beacon_state
)
7641 struct lpfc_hba
*phba
= vport
->phba
;
7642 union lpfc_sli4_cfg_shdr
*cfg_shdr
;
7643 LPFC_MBOXQ_t
*mbox
= NULL
;
7647 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
7651 cfg_shdr
= &mbox
->u
.mqe
.un
.sli4_config
.header
.cfg_shdr
;
7652 len
= sizeof(struct lpfc_mbx_set_beacon_config
) -
7653 sizeof(struct lpfc_sli4_cfg_mhdr
);
7654 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
7655 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG
, len
,
7656 LPFC_SLI4_MBX_EMBED
);
7657 mbox
->ctx_u
.lcb
= lcb_context
;
7658 mbox
->vport
= phba
->pport
;
7659 mbox
->mbox_cmpl
= lpfc_els_lcb_rsp
;
7660 bf_set(lpfc_mbx_set_beacon_port_num
, &mbox
->u
.mqe
.un
.beacon_config
,
7661 phba
->sli4_hba
.physical_port
);
7662 bf_set(lpfc_mbx_set_beacon_state
, &mbox
->u
.mqe
.un
.beacon_config
,
7664 mbox
->u
.mqe
.un
.beacon_config
.word5
= 0; /* Reserved */
7667 * Check bv1s bit before issuing the mailbox
7668 * if bv1s == 1, LCB V1 supported
7669 * else, LCB V0 supported
7672 if (phba
->sli4_hba
.pc_sli4_params
.bv1s
) {
7673 /* COMMON_SET_BEACON_CONFIG_V1 */
7674 cfg_shdr
->request
.word9
= BEACON_VERSION_V1
;
7675 lcb_context
->capability
|= LCB_CAPABILITY_DURATION
;
7676 bf_set(lpfc_mbx_set_beacon_port_type
,
7677 &mbox
->u
.mqe
.un
.beacon_config
, 0);
7678 bf_set(lpfc_mbx_set_beacon_duration_v1
,
7679 &mbox
->u
.mqe
.un
.beacon_config
,
7680 be16_to_cpu(lcb_context
->duration
));
7682 /* COMMON_SET_BEACON_CONFIG_V0 */
7683 if (be16_to_cpu(lcb_context
->duration
) != 0) {
7684 mempool_free(mbox
, phba
->mbox_mem_pool
);
7687 cfg_shdr
->request
.word9
= BEACON_VERSION_V0
;
7688 lcb_context
->capability
&= ~(LCB_CAPABILITY_DURATION
);
7689 bf_set(lpfc_mbx_set_beacon_state
,
7690 &mbox
->u
.mqe
.un
.beacon_config
, beacon_state
);
7691 bf_set(lpfc_mbx_set_beacon_port_type
,
7692 &mbox
->u
.mqe
.un
.beacon_config
, 1);
7693 bf_set(lpfc_mbx_set_beacon_duration
,
7694 &mbox
->u
.mqe
.un
.beacon_config
,
7695 be16_to_cpu(lcb_context
->duration
));
7698 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
7699 if (rc
== MBX_NOT_FINISHED
) {
7700 mempool_free(mbox
, phba
->mbox_mem_pool
);
7709 * lpfc_els_rcv_lcb - Process an unsolicited LCB
7710 * @vport: pointer to a host virtual N_Port data structure.
7711 * @cmdiocb: pointer to lpfc command iocb data structure.
7712 * @ndlp: pointer to a node-list data structure.
7714 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
7715 * First, the payload of the unsolicited LCB is checked.
7716 * Then based on Subcommand beacon will either turn on or off.
7719 * 0 - Sent the acc response
7720 * 1 - Sent the reject response.
7723 lpfc_els_rcv_lcb(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
7724 struct lpfc_nodelist
*ndlp
)
7726 struct lpfc_hba
*phba
= vport
->phba
;
7727 struct lpfc_dmabuf
*pcmd
;
7729 struct fc_lcb_request_frame
*beacon
;
7730 struct lpfc_lcb_context
*lcb_context
;
7731 u8 state
, rjt_err
= 0;
7734 pcmd
= cmdiocb
->cmd_dmabuf
;
7735 lp
= (uint8_t *)pcmd
->virt
;
7736 beacon
= (struct fc_lcb_request_frame
*)pcmd
->virt
;
7738 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7739 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
7740 "type x%x frequency %x duration x%x\n",
7741 lp
[0], lp
[1], lp
[2],
7742 beacon
->lcb_command
,
7743 beacon
->lcb_sub_command
,
7745 beacon
->lcb_frequency
,
7746 be16_to_cpu(beacon
->lcb_duration
));
7748 if (beacon
->lcb_sub_command
!= LPFC_LCB_ON
&&
7749 beacon
->lcb_sub_command
!= LPFC_LCB_OFF
) {
7750 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
7754 if (phba
->sli_rev
< LPFC_SLI_REV4
||
7755 test_bit(HBA_FCOE_MODE
, &phba
->hba_flag
) ||
7756 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) <
7757 LPFC_SLI_INTF_IF_TYPE_2
)) {
7758 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
7762 lcb_context
= kmalloc(sizeof(*lcb_context
), GFP_KERNEL
);
7764 rjt_err
= LSRJT_UNABLE_TPC
;
7768 state
= (beacon
->lcb_sub_command
== LPFC_LCB_ON
) ? 1 : 0;
7769 lcb_context
->sub_command
= beacon
->lcb_sub_command
;
7770 lcb_context
->capability
= 0;
7771 lcb_context
->type
= beacon
->lcb_type
;
7772 lcb_context
->frequency
= beacon
->lcb_frequency
;
7773 lcb_context
->duration
= beacon
->lcb_duration
;
7774 lcb_context
->ox_id
= get_job_rcvoxid(phba
, cmdiocb
);
7775 lcb_context
->rx_id
= get_job_ulpcontext(phba
, cmdiocb
);
7776 lcb_context
->ndlp
= lpfc_nlp_get(ndlp
);
7777 if (!lcb_context
->ndlp
) {
7778 rjt_err
= LSRJT_UNABLE_TPC
;
7782 if (lpfc_sli4_set_beacon(vport
, lcb_context
, state
)) {
7783 lpfc_printf_vlog(ndlp
->vport
, KERN_ERR
, LOG_TRACE_EVENT
,
7784 "0193 failed to send mail box");
7786 rjt_err
= LSRJT_UNABLE_TPC
;
7794 memset(&stat
, 0, sizeof(stat
));
7795 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
7796 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
7802 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
7803 * @vport: pointer to a host virtual N_Port data structure.
7805 * This routine cleans up any Registration State Change Notification
7806 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
7807 * @vport together with the host_lock is used to prevent multiple thread
7808 * trying to access the RSCN array on a same @vport at the same time.
7811 lpfc_els_flush_rscn(struct lpfc_vport
*vport
)
7813 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7814 struct lpfc_hba
*phba
= vport
->phba
;
7817 spin_lock_irq(shost
->host_lock
);
7818 if (vport
->fc_rscn_flush
) {
7819 /* Another thread is walking fc_rscn_id_list on this vport */
7820 spin_unlock_irq(shost
->host_lock
);
7823 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
7824 vport
->fc_rscn_flush
= 1;
7825 spin_unlock_irq(shost
->host_lock
);
7827 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
7828 lpfc_in_buf_free(phba
, vport
->fc_rscn_id_list
[i
]);
7829 vport
->fc_rscn_id_list
[i
] = NULL
;
7831 clear_bit(FC_RSCN_MODE
, &vport
->fc_flag
);
7832 clear_bit(FC_RSCN_DISCOVERY
, &vport
->fc_flag
);
7833 spin_lock_irq(shost
->host_lock
);
7834 vport
->fc_rscn_id_cnt
= 0;
7835 spin_unlock_irq(shost
->host_lock
);
7836 lpfc_can_disctmo(vport
);
7837 /* Indicate we are done walking this fc_rscn_id_list */
7838 vport
->fc_rscn_flush
= 0;
7842 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
7843 * @vport: pointer to a host virtual N_Port data structure.
7844 * @did: remote destination port identifier.
7846 * This routine checks whether there is any pending Registration State
7847 * Configuration Notification (RSCN) to a @did on @vport.
7850 * None zero - The @did matched with a pending rscn
7851 * 0 - not able to match @did with a pending rscn
7854 lpfc_rscn_payload_check(struct lpfc_vport
*vport
, uint32_t did
)
7859 uint32_t payload_len
, i
;
7860 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7862 ns_did
.un
.word
= did
;
7864 /* Never match fabric nodes for RSCNs */
7865 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
7868 /* If we are doing a FULL RSCN rediscovery, match everything */
7869 if (test_bit(FC_RSCN_DISCOVERY
, &vport
->fc_flag
))
7872 spin_lock_irq(shost
->host_lock
);
7873 if (vport
->fc_rscn_flush
) {
7874 /* Another thread is walking fc_rscn_id_list on this vport */
7875 spin_unlock_irq(shost
->host_lock
);
7878 /* Indicate we are walking fc_rscn_id_list on this vport */
7879 vport
->fc_rscn_flush
= 1;
7880 spin_unlock_irq(shost
->host_lock
);
7881 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
7882 lp
= vport
->fc_rscn_id_list
[i
]->virt
;
7883 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
7884 payload_len
-= sizeof(uint32_t); /* take off word 0 */
7885 while (payload_len
) {
7886 rscn_did
.un
.word
= be32_to_cpu(*lp
++);
7887 payload_len
-= sizeof(uint32_t);
7888 switch (rscn_did
.un
.b
.resv
& RSCN_ADDRESS_FORMAT_MASK
) {
7889 case RSCN_ADDRESS_FORMAT_PORT
:
7890 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
7891 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
)
7892 && (ns_did
.un
.b
.id
== rscn_did
.un
.b
.id
))
7893 goto return_did_out
;
7895 case RSCN_ADDRESS_FORMAT_AREA
:
7896 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
7897 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
))
7898 goto return_did_out
;
7900 case RSCN_ADDRESS_FORMAT_DOMAIN
:
7901 if (ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
7902 goto return_did_out
;
7904 case RSCN_ADDRESS_FORMAT_FABRIC
:
7905 goto return_did_out
;
7909 /* Indicate we are done with walking fc_rscn_id_list on this vport */
7910 vport
->fc_rscn_flush
= 0;
7913 /* Indicate we are done with walking fc_rscn_id_list on this vport */
7914 vport
->fc_rscn_flush
= 0;
7919 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
7920 * @vport: pointer to a host virtual N_Port data structure.
7922 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
7923 * state machine for a @vport's nodes that are with pending RSCN (Registration
7924 * State Change Notification).
7927 * 0 - Successful (currently alway return 0)
7930 lpfc_rscn_recovery_check(struct lpfc_vport
*vport
)
7932 struct lpfc_nodelist
*ndlp
= NULL
, *n
;
7934 /* Move all affected nodes by pending RSCNs to NPR state. */
7935 list_for_each_entry_safe(ndlp
, n
, &vport
->fc_nodes
, nlp_listp
) {
7936 if ((ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) ||
7937 !lpfc_rscn_payload_check(vport
, ndlp
->nlp_DID
))
7940 /* NVME Target mode does not do RSCN Recovery. */
7941 if (vport
->phba
->nvmet_support
)
7944 /* If we are in the process of doing discovery on this
7945 * NPort, let it continue on its own.
7947 switch (ndlp
->nlp_state
) {
7948 case NLP_STE_PLOGI_ISSUE
:
7949 case NLP_STE_ADISC_ISSUE
:
7950 case NLP_STE_REG_LOGIN_ISSUE
:
7951 case NLP_STE_PRLI_ISSUE
:
7952 case NLP_STE_LOGO_ISSUE
:
7956 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
7957 NLP_EVT_DEVICE_RECOVERY
);
7958 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
7964 * lpfc_send_rscn_event - Send an RSCN event to management application
7965 * @vport: pointer to a host virtual N_Port data structure.
7966 * @cmdiocb: pointer to lpfc command iocb data structure.
7968 * lpfc_send_rscn_event sends an RSCN netlink event to management
7972 lpfc_send_rscn_event(struct lpfc_vport
*vport
,
7973 struct lpfc_iocbq
*cmdiocb
)
7975 struct lpfc_dmabuf
*pcmd
;
7976 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7977 uint32_t *payload_ptr
;
7978 uint32_t payload_len
;
7979 struct lpfc_rscn_event_header
*rscn_event_data
;
7981 pcmd
= cmdiocb
->cmd_dmabuf
;
7982 payload_ptr
= (uint32_t *) pcmd
->virt
;
7983 payload_len
= be32_to_cpu(*payload_ptr
& ~ELS_CMD_MASK
);
7985 rscn_event_data
= kmalloc(sizeof(struct lpfc_rscn_event_header
) +
7986 payload_len
, GFP_KERNEL
);
7987 if (!rscn_event_data
) {
7988 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
7989 "0147 Failed to allocate memory for RSCN event\n");
7992 rscn_event_data
->event_type
= FC_REG_RSCN_EVENT
;
7993 rscn_event_data
->payload_length
= payload_len
;
7994 memcpy(rscn_event_data
->rscn_payload
, payload_ptr
,
7997 fc_host_post_vendor_event(shost
,
7998 fc_get_event_number(),
7999 sizeof(struct lpfc_rscn_event_header
) + payload_len
,
8000 (char *)rscn_event_data
,
8003 kfree(rscn_event_data
);
8007 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
8008 * @vport: pointer to a host virtual N_Port data structure.
8009 * @cmdiocb: pointer to lpfc command iocb data structure.
8010 * @ndlp: pointer to a node-list data structure.
8012 * This routine processes an unsolicited RSCN (Registration State Change
8013 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
8014 * to invoke fc_host_post_event() routine to the FC transport layer. If the
8015 * discover state machine is about to begin discovery, it just accepts the
8016 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
8017 * contains N_Port IDs for other vports on this HBA, it just accepts the
8018 * RSCN and ignore processing it. If the state machine is in the recovery
8019 * state, the fc_rscn_id_list of this @vport is walked and the
8020 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
8021 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
8022 * routine is invoked to handle the RSCN event.
8025 * 0 - Just sent the acc response
8026 * 1 - Sent the acc response and waited for name server completion
8029 lpfc_els_rcv_rscn(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
8030 struct lpfc_nodelist
*ndlp
)
8032 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8033 struct lpfc_hba
*phba
= vport
->phba
;
8034 struct lpfc_dmabuf
*pcmd
;
8035 uint32_t *lp
, *datap
;
8036 uint32_t payload_len
, length
, nportid
, *cmd
;
8038 int rscn_id
= 0, hba_id
= 0;
8041 pcmd
= cmdiocb
->cmd_dmabuf
;
8042 lp
= (uint32_t *) pcmd
->virt
;
8044 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
8045 payload_len
-= sizeof(uint32_t); /* take off word 0 */
8047 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
8048 "0214 RSCN received Data: x%lx x%x x%x x%x\n",
8049 vport
->fc_flag
, payload_len
, *lp
,
8050 vport
->fc_rscn_id_cnt
);
8052 /* Send an RSCN event to the management application */
8053 lpfc_send_rscn_event(vport
, cmdiocb
);
8055 for (i
= 0; i
< payload_len
/sizeof(uint32_t); i
++)
8056 fc_host_post_event(shost
, fc_get_event_number(),
8057 FCH_EVT_RSCN
, lp
[i
]);
8059 /* Check if RSCN is coming from a direct-connected remote NPort */
8060 if (test_bit(FC_PT2PT
, &vport
->fc_flag
)) {
8061 /* If so, just ACC it, no other action needed for now */
8062 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
8063 "2024 pt2pt RSCN %08x Data: x%lx x%x\n",
8064 *lp
, vport
->fc_flag
, payload_len
);
8065 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
8067 /* Check to see if we need to NVME rescan this target
8070 if (ndlp
->nlp_fc4_type
& NLP_FC4_NVME
&&
8071 ndlp
->nlp_type
& (NLP_NVME_TARGET
| NLP_NVME_DISCOVERY
))
8072 lpfc_nvme_rescan_port(vport
, ndlp
);
8076 /* If we are about to begin discovery, just ACC the RSCN.
8077 * Discovery processing will satisfy it.
8079 if (vport
->port_state
<= LPFC_NS_QRY
) {
8080 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8081 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
8082 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
8084 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
8088 /* If this RSCN just contains NPortIDs for other vports on this HBA,
8089 * just ACC and ignore it.
8091 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
8092 !(vport
->cfg_peer_port_login
)) {
8097 nportid
= ((be32_to_cpu(nportid
)) & Mask_DID
);
8098 i
-= sizeof(uint32_t);
8100 if (lpfc_find_vport_by_did(phba
, nportid
))
8103 if (rscn_id
== hba_id
) {
8104 /* ALL NPortIDs in RSCN are on HBA */
8105 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
8107 "Data: x%lx x%x x%x x%x\n",
8108 vport
->fc_flag
, payload_len
,
8109 *lp
, vport
->fc_rscn_id_cnt
);
8110 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8111 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
8112 ndlp
->nlp_DID
, vport
->port_state
,
8115 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
,
8117 /* Restart disctmo if its already running */
8118 if (test_bit(FC_DISC_TMO
, &vport
->fc_flag
)) {
8119 tmo
= ((phba
->fc_ratov
* 3) + 3);
8120 mod_timer(&vport
->fc_disctmo
,
8122 msecs_to_jiffies(1000 * tmo
));
8128 spin_lock_irq(shost
->host_lock
);
8129 if (vport
->fc_rscn_flush
) {
8130 /* Another thread is walking fc_rscn_id_list on this vport */
8131 spin_unlock_irq(shost
->host_lock
);
8132 set_bit(FC_RSCN_DISCOVERY
, &vport
->fc_flag
);
8134 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
8137 /* Indicate we are walking fc_rscn_id_list on this vport */
8138 vport
->fc_rscn_flush
= 1;
8139 spin_unlock_irq(shost
->host_lock
);
8140 /* Get the array count after successfully have the token */
8141 rscn_cnt
= vport
->fc_rscn_id_cnt
;
8142 /* If we are already processing an RSCN, save the received
8143 * RSCN payload buffer, cmdiocb->cmd_dmabuf to process later.
8145 if (test_bit(FC_RSCN_MODE
, &vport
->fc_flag
) ||
8146 test_bit(FC_NDISC_ACTIVE
, &vport
->fc_flag
)) {
8147 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8148 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
8149 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
8151 set_bit(FC_RSCN_DEFERRED
, &vport
->fc_flag
);
8153 /* Restart disctmo if its already running */
8154 if (test_bit(FC_DISC_TMO
, &vport
->fc_flag
)) {
8155 tmo
= ((phba
->fc_ratov
* 3) + 3);
8156 mod_timer(&vport
->fc_disctmo
,
8157 jiffies
+ msecs_to_jiffies(1000 * tmo
));
8159 if ((rscn_cnt
< FC_MAX_HOLD_RSCN
) &&
8160 !test_bit(FC_RSCN_DISCOVERY
, &vport
->fc_flag
)) {
8161 set_bit(FC_RSCN_MODE
, &vport
->fc_flag
);
8163 cmd
= vport
->fc_rscn_id_list
[rscn_cnt
-1]->virt
;
8164 length
= be32_to_cpu(*cmd
& ~ELS_CMD_MASK
);
8167 (payload_len
+ length
<= LPFC_BPL_SIZE
)) {
8168 *cmd
&= ELS_CMD_MASK
;
8169 *cmd
|= cpu_to_be32(payload_len
+ length
);
8170 memcpy(((uint8_t *)cmd
) + length
, lp
,
8173 vport
->fc_rscn_id_list
[rscn_cnt
] = pcmd
;
8174 vport
->fc_rscn_id_cnt
++;
8175 /* If we zero, cmdiocb->cmd_dmabuf, the calling
8176 * routine will not try to free it.
8178 cmdiocb
->cmd_dmabuf
= NULL
;
8181 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
8182 "0235 Deferred RSCN "
8183 "Data: x%x x%lx x%x\n",
8184 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
8187 set_bit(FC_RSCN_DISCOVERY
, &vport
->fc_flag
);
8188 /* ReDiscovery RSCN */
8189 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
8190 "0234 ReDiscovery RSCN "
8191 "Data: x%x x%lx x%x\n",
8192 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
8195 /* Indicate we are done walking fc_rscn_id_list on this vport */
8196 vport
->fc_rscn_flush
= 0;
8198 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
8199 /* send RECOVERY event for ALL nodes that match RSCN payload */
8200 lpfc_rscn_recovery_check(vport
);
8203 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8204 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
8205 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
8207 set_bit(FC_RSCN_MODE
, &vport
->fc_flag
);
8208 vport
->fc_rscn_id_list
[vport
->fc_rscn_id_cnt
++] = pcmd
;
8209 /* Indicate we are done walking fc_rscn_id_list on this vport */
8210 vport
->fc_rscn_flush
= 0;
8212 * If we zero, cmdiocb->cmd_dmabuf, the calling routine will
8213 * not try to free it.
8215 cmdiocb
->cmd_dmabuf
= NULL
;
8216 lpfc_set_disctmo(vport
);
8218 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
8219 /* send RECOVERY event for ALL nodes that match RSCN payload */
8220 lpfc_rscn_recovery_check(vport
);
8221 return lpfc_els_handle_rscn(vport
);
8225 * lpfc_els_handle_rscn - Handle rscn for a vport
8226 * @vport: pointer to a host virtual N_Port data structure.
8228 * This routine handles the Registration State Configuration Notification
8229 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
8230 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
8231 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
8232 * NameServer shall be issued. If CT command to the NameServer fails to be
8233 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
8234 * RSCN activities with the @vport.
8237 * 0 - Cleaned up rscn on the @vport
8238 * 1 - Wait for plogi to name server before proceed
8241 lpfc_els_handle_rscn(struct lpfc_vport
*vport
)
8243 struct lpfc_nodelist
*ndlp
;
8244 struct lpfc_hba
*phba
= vport
->phba
;
8246 /* Ignore RSCN if the port is being torn down. */
8247 if (test_bit(FC_UNLOADING
, &vport
->load_flag
)) {
8248 lpfc_els_flush_rscn(vport
);
8252 /* Start timer for RSCN processing */
8253 lpfc_set_disctmo(vport
);
8255 /* RSCN processed */
8256 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
8257 "0215 RSCN processed Data: x%lx x%x x%x x%x x%x x%x\n",
8258 vport
->fc_flag
, 0, vport
->fc_rscn_id_cnt
,
8259 vport
->port_state
, vport
->num_disc_nodes
,
8262 /* To process RSCN, first compare RSCN data with NameServer */
8263 vport
->fc_ns_retry
= 0;
8264 vport
->num_disc_nodes
= 0;
8266 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
8267 if (ndlp
&& ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
8268 /* Good ndlp, issue CT Request to NameServer. Need to
8269 * know how many gidfts were issued. If none, then just
8270 * flush the RSCN. Otherwise, the outstanding requests
8273 if (phba
->cfg_ns_query
== LPFC_NS_QUERY_GID_FT
) {
8274 if (lpfc_issue_gidft(vport
) > 0)
8276 } else if (phba
->cfg_ns_query
== LPFC_NS_QUERY_GID_PT
) {
8277 if (lpfc_issue_gidpt(vport
) > 0)
8283 /* Nameserver login in question. Revalidate. */
8285 ndlp
->nlp_prev_state
= NLP_STE_UNUSED_NODE
;
8286 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
8288 ndlp
= lpfc_nlp_init(vport
, NameServer_DID
);
8290 lpfc_els_flush_rscn(vport
);
8293 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
8294 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
8296 ndlp
->nlp_type
|= NLP_FABRIC
;
8297 lpfc_issue_els_plogi(vport
, NameServer_DID
, 0);
8298 /* Wait for NameServer login cmpl before we can
8304 lpfc_els_flush_rscn(vport
);
8309 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
8310 * @vport: pointer to a host virtual N_Port data structure.
8311 * @cmdiocb: pointer to lpfc command iocb data structure.
8312 * @ndlp: pointer to a node-list data structure.
8314 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
8315 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
8316 * point topology. As an unsolicited FLOGI should not be received in a loop
8317 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
8318 * lpfc_check_sparm() routine is invoked to check the parameters in the
8319 * unsolicited FLOGI. If parameters validation failed, the routine
8320 * lpfc_els_rsp_reject() shall be called with reject reason code set to
8321 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
8322 * FLOGI shall be compared with the Port WWN of the @vport to determine who
8323 * will initiate PLOGI. The higher lexicographical value party shall has
8324 * higher priority (as the winning port) and will initiate PLOGI and
8325 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
8326 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
8327 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
8330 * 0 - Successfully processed the unsolicited flogi
8331 * 1 - Failed to process the unsolicited flogi
8334 lpfc_els_rcv_flogi(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
8335 struct lpfc_nodelist
*ndlp
)
8337 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8338 struct lpfc_hba
*phba
= vport
->phba
;
8339 struct lpfc_dmabuf
*pcmd
= cmdiocb
->cmd_dmabuf
;
8340 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
8341 union lpfc_wqe128
*wqe
= &cmdiocb
->wqe
;
8342 struct serv_parm
*sp
;
8346 unsigned long fc_flag
= 0;
8347 uint32_t port_state
= 0;
8349 /* Clear external loopback plug detected flag */
8350 phba
->link_flag
&= ~LS_EXTERNAL_LOOPBACK
;
8353 sp
= (struct serv_parm
*) lp
;
8355 /* FLOGI received */
8357 lpfc_set_disctmo(vport
);
8359 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
8360 /* We should never receive a FLOGI in loop mode, ignore it */
8361 did
= bf_get(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
);
8363 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
8365 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
8366 "0113 An FLOGI ELS command x%x was "
8367 "received from DID x%x in Loop Mode\n",
8372 (void) lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 1);
8375 * If our portname is greater than the remote portname,
8376 * then we initiate Nport login.
8379 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
8380 sizeof(struct lpfc_name
));
8383 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
8384 mbox
= mempool_alloc(phba
->mbox_mem_pool
,
8388 lpfc_linkdown(phba
);
8389 lpfc_init_link(phba
, mbox
,
8391 phba
->cfg_link_speed
);
8392 mbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
8393 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
8394 mbox
->vport
= vport
;
8395 rc
= lpfc_sli_issue_mbox(phba
, mbox
,
8397 lpfc_set_loopback_flag(phba
);
8398 if (rc
== MBX_NOT_FINISHED
)
8399 mempool_free(mbox
, phba
->mbox_mem_pool
);
8403 /* External loopback plug insertion detected */
8404 phba
->link_flag
|= LS_EXTERNAL_LOOPBACK
;
8406 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
| LOG_LIBDFC
,
8407 "1119 External Loopback plug detected\n");
8409 /* abort the flogi coming back to ourselves
8410 * due to external loopback on the port.
8412 lpfc_els_abort_flogi(phba
);
8415 } else if (rc
> 0) { /* greater than */
8416 set_bit(FC_PT2PT_PLOGI
, &vport
->fc_flag
);
8418 /* If we have the high WWPN we can assign our own
8419 * myDID; otherwise, we have to WAIT for a PLOGI
8420 * from the remote NPort to find out what it
8423 vport
->fc_myDID
= PT2PT_LocalID
;
8425 vport
->fc_myDID
= PT2PT_RemoteID
;
8429 * The vport state should go to LPFC_FLOGI only
8430 * AFTER we issue a FLOGI, not receive one.
8432 spin_lock_irq(shost
->host_lock
);
8433 fc_flag
= vport
->fc_flag
;
8434 port_state
= vport
->port_state
;
8435 /* Acking an unsol FLOGI. Count 1 for link bounce
8438 vport
->rcv_flogi_cnt
++;
8439 spin_unlock_irq(shost
->host_lock
);
8440 set_bit(FC_PT2PT
, &vport
->fc_flag
);
8441 clear_bit(FC_FABRIC
, &vport
->fc_flag
);
8442 clear_bit(FC_PUBLIC_LOOP
, &vport
->fc_flag
);
8443 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
8444 "3311 Rcv Flogi PS x%x new PS x%x "
8445 "fc_flag x%lx new fc_flag x%lx\n",
8446 port_state
, vport
->port_state
,
8447 fc_flag
, vport
->fc_flag
);
8450 * We temporarily set fc_myDID to make it look like we are
8451 * a Fabric. This is done just so we end up with the right
8452 * did / sid on the FLOGI ACC rsp.
8454 did
= vport
->fc_myDID
;
8455 vport
->fc_myDID
= Fabric_DID
;
8457 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
8459 /* Defer ACC response until AFTER we issue a FLOGI */
8460 if (!test_bit(HBA_FLOGI_ISSUED
, &phba
->hba_flag
)) {
8461 phba
->defer_flogi_acc
.rx_id
= bf_get(wqe_ctxt_tag
,
8462 &wqe
->xmit_els_rsp
.wqe_com
);
8463 phba
->defer_flogi_acc
.ox_id
= bf_get(wqe_rcvoxid
,
8464 &wqe
->xmit_els_rsp
.wqe_com
);
8466 vport
->fc_myDID
= did
;
8468 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
8469 "3344 Deferring FLOGI ACC: rx_id: x%x,"
8470 " ox_id: x%x, hba_flag x%lx\n",
8471 phba
->defer_flogi_acc
.rx_id
,
8472 phba
->defer_flogi_acc
.ox_id
, phba
->hba_flag
);
8474 phba
->defer_flogi_acc
.flag
= true;
8476 /* This nlp_get is paired with nlp_puts that reset the
8477 * defer_flogi_acc.flag back to false. We need to retain
8478 * a kref on the ndlp until the deferred FLOGI ACC is
8479 * processed or cancelled.
8481 phba
->defer_flogi_acc
.ndlp
= lpfc_nlp_get(ndlp
);
8486 lpfc_els_rsp_acc(vport
, ELS_CMD_FLOGI
, cmdiocb
, ndlp
, NULL
);
8488 /* Now lets put fc_myDID back to what its supposed to be */
8489 vport
->fc_myDID
= did
;
8495 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
8496 * @vport: pointer to a host virtual N_Port data structure.
8497 * @cmdiocb: pointer to lpfc command iocb data structure.
8498 * @ndlp: pointer to a node-list data structure.
8500 * This routine processes Request Node Identification Data (RNID) IOCB
8501 * received as an ELS unsolicited event. Only when the RNID specified format
8502 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
8503 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
8504 * Accept (ACC) the RNID ELS command. All the other RNID formats are
8505 * rejected by invoking the lpfc_els_rsp_reject() routine.
8508 * 0 - Successfully processed rnid iocb (currently always return 0)
8511 lpfc_els_rcv_rnid(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
8512 struct lpfc_nodelist
*ndlp
)
8514 struct lpfc_dmabuf
*pcmd
;
8519 pcmd
= cmdiocb
->cmd_dmabuf
;
8520 lp
= (uint32_t *) pcmd
->virt
;
8527 switch (rn
->Format
) {
8529 case RNID_TOPOLOGY_DISC
:
8531 lpfc_els_rsp_rnid_acc(vport
, rn
->Format
, cmdiocb
, ndlp
);
8534 /* Reject this request because format not supported */
8535 stat
.un
.b
.lsRjtRsvd0
= 0;
8536 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
8537 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
8538 stat
.un
.b
.vendorUnique
= 0;
8539 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
8546 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
8547 * @vport: pointer to a host virtual N_Port data structure.
8548 * @cmdiocb: pointer to lpfc command iocb data structure.
8549 * @ndlp: pointer to a node-list data structure.
8552 * 0 - Successfully processed echo iocb (currently always return 0)
8555 lpfc_els_rcv_echo(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
8556 struct lpfc_nodelist
*ndlp
)
8560 pcmd
= (uint8_t *)cmdiocb
->cmd_dmabuf
->virt
;
8562 /* skip over first word of echo command to find echo data */
8563 pcmd
+= sizeof(uint32_t);
8565 lpfc_els_rsp_echo_acc(vport
, pcmd
, cmdiocb
, ndlp
);
8570 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
8571 * @vport: pointer to a host virtual N_Port data structure.
8572 * @cmdiocb: pointer to lpfc command iocb data structure.
8573 * @ndlp: pointer to a node-list data structure.
8575 * This routine processes a Link Incident Report Registration(LIRR) IOCB
8576 * received as an ELS unsolicited event. Currently, this function just invokes
8577 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
8580 * 0 - Successfully processed lirr iocb (currently always return 0)
8583 lpfc_els_rcv_lirr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
8584 struct lpfc_nodelist
*ndlp
)
8588 /* For now, unconditionally reject this command */
8589 stat
.un
.b
.lsRjtRsvd0
= 0;
8590 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
8591 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
8592 stat
.un
.b
.vendorUnique
= 0;
8593 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
8598 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
8599 * @vport: pointer to a host virtual N_Port data structure.
8600 * @cmdiocb: pointer to lpfc command iocb data structure.
8601 * @ndlp: pointer to a node-list data structure.
8603 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
8604 * received as an ELS unsolicited event. A request to RRQ shall only
8605 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
8606 * Nx_Port N_Port_ID of the target Exchange is the same as the
8607 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
8608 * not accepted, an LS_RJT with reason code "Unable to perform
8609 * command request" and reason code explanation "Invalid Originator
8610 * S_ID" shall be returned. For now, we just unconditionally accept
8611 * RRQ from the target.
8614 lpfc_els_rcv_rrq(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
8615 struct lpfc_nodelist
*ndlp
)
8617 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
8618 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
)
8619 lpfc_els_clear_rrq(vport
, cmdiocb
, ndlp
);
8623 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
8624 * @phba: pointer to lpfc hba data structure.
8625 * @pmb: pointer to the driver internal queue element for mailbox command.
8627 * This routine is the completion callback function for the MBX_READ_LNK_STAT
8628 * mailbox command. This callback function is to actually send the Accept
8629 * (ACC) response to a Read Link Status (RLS) unsolicited IOCB event. It
8630 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
8631 * mailbox command, constructs the RLS response with the link statistics
8632 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
8633 * response to the RLS.
8635 * Note that the ndlp reference count will be incremented by 1 for holding the
8636 * ndlp and the reference to ndlp will be stored into the ndlp field of
8637 * the IOCB for the completion callback function to the RLS Accept Response
8642 lpfc_els_rsp_rls_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
8647 union lpfc_wqe128
*wqe
;
8648 struct RLS_RSP
*rls_rsp
;
8650 struct lpfc_iocbq
*elsiocb
;
8651 struct lpfc_nodelist
*ndlp
;
8659 ndlp
= pmb
->ctx_ndlp
;
8660 rxid
= (uint16_t)(pmb
->ctx_u
.ox_rx_id
& 0xffff);
8661 oxid
= (uint16_t)((pmb
->ctx_u
.ox_rx_id
>> 16) & 0xffff);
8662 memset(&pmb
->ctx_u
, 0, sizeof(pmb
->ctx_u
));
8663 pmb
->ctx_ndlp
= NULL
;
8665 if (mb
->mbxStatus
) {
8666 mempool_free(pmb
, phba
->mbox_mem_pool
);
8670 cmdsize
= sizeof(struct RLS_RSP
) + sizeof(uint32_t);
8671 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
8672 lpfc_max_els_tries
, ndlp
,
8673 ndlp
->nlp_DID
, ELS_CMD_ACC
);
8675 /* Decrement the ndlp reference count from previous mbox command */
8679 mempool_free(pmb
, phba
->mbox_mem_pool
);
8683 ulp_context
= get_job_ulpcontext(phba
, elsiocb
);
8684 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
8685 wqe
= &elsiocb
->wqe
;
8687 bf_set(wqe_ctxt_tag
, &wqe
->generic
.wqe_com
, rxid
);
8688 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
, oxid
);
8690 icmd
= &elsiocb
->iocb
;
8691 icmd
->ulpContext
= rxid
;
8692 icmd
->unsli3
.rcvsli3
.ox_id
= oxid
;
8695 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
8696 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
8697 pcmd
+= sizeof(uint32_t); /* Skip past command */
8698 rls_rsp
= (struct RLS_RSP
*)pcmd
;
8700 rls_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
8701 rls_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
8702 rls_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
8703 rls_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
8704 rls_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
8705 rls_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
8706 mempool_free(pmb
, phba
->mbox_mem_pool
);
8707 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
8708 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
8709 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
8710 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
8711 elsiocb
->iotag
, ulp_context
,
8712 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
8714 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_rsp
;
8715 phba
->fc_stat
.elsXmitACC
++;
8716 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
8717 if (!elsiocb
->ndlp
) {
8718 lpfc_els_free_iocb(phba
, elsiocb
);
8722 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
8723 if (rc
== IOCB_ERROR
) {
8724 lpfc_els_free_iocb(phba
, elsiocb
);
8731 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
8732 * @vport: pointer to a host virtual N_Port data structure.
8733 * @cmdiocb: pointer to lpfc command iocb data structure.
8734 * @ndlp: pointer to a node-list data structure.
8736 * This routine processes Read Link Status (RLS) IOCB received as an
8737 * ELS unsolicited event. It first checks the remote port state. If the
8738 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
8739 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
8740 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
8741 * for reading the HBA link statistics. It is for the callback function,
8742 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
8743 * to actually sending out RPL Accept (ACC) response.
8746 * 0 - Successfully processed rls iocb (currently always return 0)
8749 lpfc_els_rcv_rls(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
8750 struct lpfc_nodelist
*ndlp
)
8752 struct lpfc_hba
*phba
= vport
->phba
;
8755 u32 ctx
= get_job_ulpcontext(phba
, cmdiocb
);
8756 u32 ox_id
= get_job_rcvoxid(phba
, cmdiocb
);
8758 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
8759 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
8760 /* reject the unsolicited RLS request and done with it */
8763 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
8765 lpfc_read_lnk_stat(phba
, mbox
);
8766 mbox
->ctx_u
.ox_rx_id
= ox_id
<< 16 | ctx
;
8767 mbox
->ctx_ndlp
= lpfc_nlp_get(ndlp
);
8768 if (!mbox
->ctx_ndlp
)
8770 mbox
->vport
= vport
;
8771 mbox
->mbox_cmpl
= lpfc_els_rsp_rls_acc
;
8772 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
8773 != MBX_NOT_FINISHED
)
8774 /* Mbox completion will send ELS Response */
8776 /* Decrement reference count used for the failed mbox
8781 mempool_free(mbox
, phba
->mbox_mem_pool
);
8784 /* issue rejection response */
8785 stat
.un
.b
.lsRjtRsvd0
= 0;
8786 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
8787 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
8788 stat
.un
.b
.vendorUnique
= 0;
8789 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
8794 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
8795 * @vport: pointer to a host virtual N_Port data structure.
8796 * @cmdiocb: pointer to lpfc command iocb data structure.
8797 * @ndlp: pointer to a node-list data structure.
8799 * This routine processes Read Timout Value (RTV) IOCB received as an
8800 * ELS unsolicited event. It first checks the remote port state. If the
8801 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
8802 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
8803 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
8804 * Value (RTV) unsolicited IOCB event.
8806 * Note that the ndlp reference count will be incremented by 1 for holding the
8807 * ndlp and the reference to ndlp will be stored into the ndlp field of
8808 * the IOCB for the completion callback function to the RTV Accept Response
8812 * 0 - Successfully processed rtv iocb (currently always return 0)
8815 lpfc_els_rcv_rtv(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
8816 struct lpfc_nodelist
*ndlp
)
8820 union lpfc_wqe128
*wqe
;
8821 struct lpfc_hba
*phba
= vport
->phba
;
8823 struct RTV_RSP
*rtv_rsp
;
8825 struct lpfc_iocbq
*elsiocb
;
8829 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
8830 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
8831 /* reject the unsolicited RTV request and done with it */
8834 cmdsize
= sizeof(struct RTV_RSP
) + sizeof(uint32_t);
8835 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
8836 lpfc_max_els_tries
, ndlp
,
8837 ndlp
->nlp_DID
, ELS_CMD_ACC
);
8842 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
8843 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
8844 pcmd
+= sizeof(uint32_t); /* Skip past command */
8846 ulp_context
= get_job_ulpcontext(phba
, elsiocb
);
8847 /* use the command's xri in the response */
8848 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
8849 wqe
= &elsiocb
->wqe
;
8850 bf_set(wqe_ctxt_tag
, &wqe
->generic
.wqe_com
,
8851 get_job_ulpcontext(phba
, cmdiocb
));
8852 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
8853 get_job_rcvoxid(phba
, cmdiocb
));
8855 icmd
= &elsiocb
->iocb
;
8856 icmd
->ulpContext
= get_job_ulpcontext(phba
, cmdiocb
);
8857 icmd
->unsli3
.rcvsli3
.ox_id
= get_job_rcvoxid(phba
, cmdiocb
);
8860 rtv_rsp
= (struct RTV_RSP
*)pcmd
;
8862 /* populate RTV payload */
8863 rtv_rsp
->ratov
= cpu_to_be32(phba
->fc_ratov
* 1000); /* report msecs */
8864 rtv_rsp
->edtov
= cpu_to_be32(phba
->fc_edtov
);
8865 bf_set(qtov_edtovres
, rtv_rsp
, phba
->fc_edtovResol
? 1 : 0);
8866 bf_set(qtov_rttov
, rtv_rsp
, 0); /* Field is for FC ONLY */
8867 rtv_rsp
->qtov
= cpu_to_be32(rtv_rsp
->qtov
);
8869 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
8870 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
8871 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
8872 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
8873 "Data: x%x x%x x%x\n",
8874 elsiocb
->iotag
, ulp_context
,
8875 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
8877 rtv_rsp
->ratov
, rtv_rsp
->edtov
, rtv_rsp
->qtov
);
8878 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_rsp
;
8879 phba
->fc_stat
.elsXmitACC
++;
8880 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
8881 if (!elsiocb
->ndlp
) {
8882 lpfc_els_free_iocb(phba
, elsiocb
);
8886 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
8887 if (rc
== IOCB_ERROR
) {
8888 lpfc_els_free_iocb(phba
, elsiocb
);
8894 /* issue rejection response */
8895 stat
.un
.b
.lsRjtRsvd0
= 0;
8896 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
8897 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
8898 stat
.un
.b
.vendorUnique
= 0;
8899 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
8903 /* lpfc_issue_els_rrq - Process an unsolicited rrq iocb
8904 * @vport: pointer to a host virtual N_Port data structure.
8905 * @ndlp: pointer to a node-list data structure.
8906 * @did: DID of the target.
8907 * @rrq: Pointer to the rrq struct.
8909 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
8910 * successful, the completion handler will clear the RRQ.
8913 * 0 - Successfully sent rrq els iocb.
8914 * 1 - Failed to send rrq els iocb.
8917 lpfc_issue_els_rrq(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
8918 uint32_t did
, struct lpfc_node_rrq
*rrq
)
8920 struct lpfc_hba
*phba
= vport
->phba
;
8921 struct RRQ
*els_rrq
;
8922 struct lpfc_iocbq
*elsiocb
;
8930 /* If ndlp is not NULL, we will bump the reference count on it */
8931 cmdsize
= (sizeof(uint32_t) + sizeof(struct RRQ
));
8932 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, did
,
8937 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
8939 /* For RRQ request, remainder of payload is Exchange IDs */
8940 *((uint32_t *) (pcmd
)) = ELS_CMD_RRQ
;
8941 pcmd
+= sizeof(uint32_t);
8942 els_rrq
= (struct RRQ
*) pcmd
;
8944 bf_set(rrq_oxid
, els_rrq
, phba
->sli4_hba
.xri_ids
[rrq
->xritag
]);
8945 bf_set(rrq_rxid
, els_rrq
, rrq
->rxid
);
8946 bf_set(rrq_did
, els_rrq
, vport
->fc_myDID
);
8947 els_rrq
->rrq
= cpu_to_be32(els_rrq
->rrq
);
8948 els_rrq
->rrq_exchg
= cpu_to_be32(els_rrq
->rrq_exchg
);
8951 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
8952 "Issue RRQ: did:x%x",
8953 did
, rrq
->xritag
, rrq
->rxid
);
8954 elsiocb
->context_un
.rrq
= rrq
;
8955 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_rrq
;
8957 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
8961 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
8962 if (ret
== IOCB_ERROR
) {
8969 lpfc_els_free_iocb(phba
, elsiocb
);
8974 * lpfc_send_rrq - Sends ELS RRQ if needed.
8975 * @phba: pointer to lpfc hba data structure.
8976 * @rrq: pointer to the active rrq.
8978 * This routine will call the lpfc_issue_els_rrq if the rrq is
8979 * still active for the xri. If this function returns a failure then
8980 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
8982 * Returns 0 Success.
8986 lpfc_send_rrq(struct lpfc_hba
*phba
, struct lpfc_node_rrq
*rrq
)
8988 struct lpfc_nodelist
*ndlp
= lpfc_findnode_did(rrq
->vport
,
8993 if (lpfc_test_rrq_active(phba
, ndlp
, rrq
->xritag
))
8994 return lpfc_issue_els_rrq(rrq
->vport
, ndlp
,
9001 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
9002 * @vport: pointer to a host virtual N_Port data structure.
9003 * @cmdsize: size of the ELS command.
9004 * @oldiocb: pointer to the original lpfc command iocb data structure.
9005 * @ndlp: pointer to a node-list data structure.
9007 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
9008 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
9010 * Note that the ndlp reference count will be incremented by 1 for holding the
9011 * ndlp and the reference to ndlp will be stored into the ndlp field of
9012 * the IOCB for the completion callback function to the RPL Accept Response
9016 * 0 - Successfully issued ACC RPL ELS command
9017 * 1 - Failed to issue ACC RPL ELS command
9020 lpfc_els_rsp_rpl_acc(struct lpfc_vport
*vport
, uint16_t cmdsize
,
9021 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
9024 struct lpfc_hba
*phba
= vport
->phba
;
9026 union lpfc_wqe128
*wqe
;
9028 struct lpfc_iocbq
*elsiocb
;
9032 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
9033 ndlp
->nlp_DID
, ELS_CMD_ACC
);
9038 ulp_context
= get_job_ulpcontext(phba
, elsiocb
);
9039 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9040 wqe
= &elsiocb
->wqe
;
9042 bf_set(wqe_ctxt_tag
, &wqe
->generic
.wqe_com
,
9043 get_job_ulpcontext(phba
, oldiocb
));
9044 bf_set(wqe_rcvoxid
, &wqe
->xmit_els_rsp
.wqe_com
,
9045 get_job_rcvoxid(phba
, oldiocb
));
9047 icmd
= &elsiocb
->iocb
;
9048 icmd
->ulpContext
= get_job_ulpcontext(phba
, oldiocb
);
9049 icmd
->unsli3
.rcvsli3
.ox_id
= get_job_rcvoxid(phba
, oldiocb
);
9052 pcmd
= elsiocb
->cmd_dmabuf
->virt
;
9053 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
9054 pcmd
+= sizeof(uint16_t);
9055 *((uint16_t *)(pcmd
)) = be16_to_cpu(cmdsize
);
9056 pcmd
+= sizeof(uint16_t);
9058 /* Setup the RPL ACC payload */
9059 rpl_rsp
.listLen
= be32_to_cpu(1);
9061 rpl_rsp
.port_num_blk
.portNum
= 0;
9062 rpl_rsp
.port_num_blk
.portID
= be32_to_cpu(vport
->fc_myDID
);
9063 memcpy(&rpl_rsp
.port_num_blk
.portName
, &vport
->fc_portname
,
9064 sizeof(struct lpfc_name
));
9065 memcpy(pcmd
, &rpl_rsp
, cmdsize
- sizeof(uint32_t));
9066 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
9067 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
9068 "0120 Xmit ELS RPL ACC response tag x%x "
9069 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
9071 elsiocb
->iotag
, ulp_context
,
9072 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
9074 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_rsp
;
9075 phba
->fc_stat
.elsXmitACC
++;
9076 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
9077 if (!elsiocb
->ndlp
) {
9078 lpfc_els_free_iocb(phba
, elsiocb
);
9082 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
9083 if (rc
== IOCB_ERROR
) {
9084 lpfc_els_free_iocb(phba
, elsiocb
);
9093 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
9094 * @vport: pointer to a host virtual N_Port data structure.
9095 * @cmdiocb: pointer to lpfc command iocb data structure.
9096 * @ndlp: pointer to a node-list data structure.
9098 * This routine processes Read Port List (RPL) IOCB received as an ELS
9099 * unsolicited event. It first checks the remote port state. If the remote
9100 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
9101 * invokes the lpfc_els_rsp_reject() routine to send reject response.
9102 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
9103 * to accept the RPL.
9106 * 0 - Successfully processed rpl iocb (currently always return 0)
9109 lpfc_els_rcv_rpl(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
9110 struct lpfc_nodelist
*ndlp
)
9112 struct lpfc_dmabuf
*pcmd
;
9119 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
9120 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
9121 /* issue rejection response */
9122 stat
.un
.b
.lsRjtRsvd0
= 0;
9123 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
9124 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
9125 stat
.un
.b
.vendorUnique
= 0;
9126 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
9128 /* rejected the unsolicited RPL request and done with it */
9132 pcmd
= cmdiocb
->cmd_dmabuf
;
9133 lp
= (uint32_t *) pcmd
->virt
;
9134 rpl
= (RPL
*) (lp
+ 1);
9135 maxsize
= be32_to_cpu(rpl
->maxsize
);
9137 /* We support only one port */
9138 if ((rpl
->index
== 0) &&
9140 ((maxsize
* sizeof(uint32_t)) >= sizeof(RPL_RSP
)))) {
9141 cmdsize
= sizeof(uint32_t) + sizeof(RPL_RSP
);
9143 cmdsize
= sizeof(uint32_t) + maxsize
* sizeof(uint32_t);
9145 lpfc_els_rsp_rpl_acc(vport
, cmdsize
, cmdiocb
, ndlp
);
9151 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
9152 * @vport: pointer to a virtual N_Port data structure.
9153 * @cmdiocb: pointer to lpfc command iocb data structure.
9154 * @ndlp: pointer to a node-list data structure.
9156 * This routine processes Fibre Channel Address Resolution Protocol
9157 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
9158 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
9159 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
9160 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
9161 * remote PortName is compared against the FC PortName stored in the @vport
9162 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
9163 * compared against the FC NodeName stored in the @vport data structure.
9164 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
9165 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
9166 * invoked to send out FARP Response to the remote node. Before sending the
9167 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
9168 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
9169 * routine is invoked to log into the remote port first.
9172 * 0 - Either the FARP Match Mode not supported or successfully processed
9175 lpfc_els_rcv_farp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
9176 struct lpfc_nodelist
*ndlp
)
9178 struct lpfc_dmabuf
*pcmd
;
9183 did
= get_job_els_rsp64_did(vport
->phba
, cmdiocb
);
9184 pcmd
= cmdiocb
->cmd_dmabuf
;
9185 lp
= (uint32_t *) pcmd
->virt
;
9189 /* FARP-REQ received from DID <did> */
9190 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
9191 "0601 FARP-REQ received from DID x%x\n", did
);
9192 /* We will only support match on WWPN or WWNN */
9193 if (fp
->Mflags
& ~(FARP_MATCH_NODE
| FARP_MATCH_PORT
)) {
9198 /* If this FARP command is searching for my portname */
9199 if (fp
->Mflags
& FARP_MATCH_PORT
) {
9200 if (memcmp(&fp
->RportName
, &vport
->fc_portname
,
9201 sizeof(struct lpfc_name
)) == 0)
9205 /* If this FARP command is searching for my nodename */
9206 if (fp
->Mflags
& FARP_MATCH_NODE
) {
9207 if (memcmp(&fp
->RnodeName
, &vport
->fc_nodename
,
9208 sizeof(struct lpfc_name
)) == 0)
9213 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
9214 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)) {
9215 /* Log back into the node before sending the FARP. */
9216 if (fp
->Rflags
& FARP_REQUEST_PLOGI
) {
9217 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
9218 lpfc_nlp_set_state(vport
, ndlp
,
9219 NLP_STE_PLOGI_ISSUE
);
9220 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
9223 /* Send a FARP response to that node */
9224 if (fp
->Rflags
& FARP_REQUEST_FARPR
)
9225 lpfc_issue_els_farpr(vport
, did
, 0);
9232 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
9233 * @vport: pointer to a host virtual N_Port data structure.
9234 * @cmdiocb: pointer to lpfc command iocb data structure.
9235 * @ndlp: pointer to a node-list data structure.
9237 * This routine processes Fibre Channel Address Resolution Protocol
9238 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
9239 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
9240 * the FARP response request.
9243 * 0 - Successfully processed FARPR IOCB (currently always return 0)
9246 lpfc_els_rcv_farpr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
9247 struct lpfc_nodelist
*ndlp
)
9251 did
= get_job_els_rsp64_did(vport
->phba
, cmdiocb
);
9253 /* FARP-RSP received from DID <did> */
9254 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
9255 "0600 FARP-RSP received from DID x%x\n", did
);
9256 /* ACCEPT the Farp resp request */
9257 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
9263 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
9264 * @vport: pointer to a host virtual N_Port data structure.
9265 * @cmdiocb: pointer to lpfc command iocb data structure.
9266 * @fan_ndlp: pointer to a node-list data structure.
9268 * This routine processes a Fabric Address Notification (FAN) IOCB
9269 * command received as an ELS unsolicited event. The FAN ELS command will
9270 * only be processed on a physical port (i.e., the @vport represents the
9271 * physical port). The fabric NodeName and PortName from the FAN IOCB are
9272 * compared against those in the phba data structure. If any of those is
9273 * different, the lpfc_initial_flogi() routine is invoked to initialize
9274 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
9275 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
9276 * is invoked to register login to the fabric.
9279 * 0 - Successfully processed fan iocb (currently always return 0).
9282 lpfc_els_rcv_fan(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
9283 struct lpfc_nodelist
*fan_ndlp
)
9285 struct lpfc_hba
*phba
= vport
->phba
;
9289 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
, "0265 FAN received\n");
9290 lp
= (uint32_t *)cmdiocb
->cmd_dmabuf
->virt
;
9292 /* FAN received; Fan does not have a reply sequence */
9293 if ((vport
== phba
->pport
) &&
9294 (vport
->port_state
== LPFC_LOCAL_CFG_LINK
)) {
9295 if ((memcmp(&phba
->fc_fabparam
.nodeName
, &fp
->FnodeName
,
9296 sizeof(struct lpfc_name
))) ||
9297 (memcmp(&phba
->fc_fabparam
.portName
, &fp
->FportName
,
9298 sizeof(struct lpfc_name
)))) {
9299 /* This port has switched fabrics. FLOGI is required */
9300 lpfc_issue_init_vfi(vport
);
9302 /* FAN verified - skip FLOGI */
9303 vport
->fc_myDID
= vport
->fc_prevDID
;
9304 if (phba
->sli_rev
< LPFC_SLI_REV4
)
9305 lpfc_issue_fabric_reglogin(vport
);
9307 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
9308 "3138 Need register VFI: (x%x/%x)\n",
9309 vport
->fc_prevDID
, vport
->fc_myDID
);
9310 lpfc_issue_reg_vfi(vport
);
9318 * lpfc_els_rcv_edc - Process an unsolicited EDC iocb
9319 * @vport: pointer to a host virtual N_Port data structure.
9320 * @cmdiocb: pointer to lpfc command iocb data structure.
9321 * @ndlp: pointer to a node-list data structure.
9324 * 0 - Successfully processed echo iocb (currently always return 0)
9327 lpfc_els_rcv_edc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
9328 struct lpfc_nodelist
*ndlp
)
9330 struct lpfc_hba
*phba
= vport
->phba
;
9331 struct fc_els_edc
*edc_req
;
9332 struct fc_tlv_desc
*tlv
;
9334 uint32_t *ptr
, dtag
;
9335 const char *dtag_nm
;
9336 int desc_cnt
= 0, bytes_remain
;
9337 struct fc_diag_lnkflt_desc
*plnkflt
;
9339 payload
= cmdiocb
->cmd_dmabuf
->virt
;
9341 edc_req
= (struct fc_els_edc
*)payload
;
9342 bytes_remain
= be32_to_cpu(edc_req
->desc_len
);
9344 ptr
= (uint32_t *)payload
;
9345 lpfc_printf_vlog(vport
, KERN_INFO
,
9346 LOG_ELS
| LOG_CGN_MGMT
| LOG_LDS_EVENT
,
9347 "3319 Rcv EDC payload len %d: x%x x%x x%x\n",
9348 bytes_remain
, be32_to_cpu(*ptr
),
9349 be32_to_cpu(*(ptr
+ 1)), be32_to_cpu(*(ptr
+ 2)));
9351 /* No signal support unless there is a congestion descriptor */
9352 phba
->cgn_reg_signal
= EDC_CG_SIG_NOTSUPPORTED
;
9353 phba
->cgn_sig_freq
= 0;
9354 phba
->cgn_reg_fpin
= LPFC_CGN_FPIN_ALARM
| LPFC_CGN_FPIN_WARN
;
9356 if (bytes_remain
<= 0)
9359 tlv
= edc_req
->desc
;
9362 * cycle through EDC diagnostic descriptors to find the
9363 * congestion signaling capability descriptor
9365 while (bytes_remain
) {
9366 if (bytes_remain
< FC_TLV_DESC_HDR_SZ
) {
9367 lpfc_printf_log(phba
, KERN_WARNING
,
9368 LOG_ELS
| LOG_CGN_MGMT
| LOG_LDS_EVENT
,
9369 "6464 Truncated TLV hdr on "
9370 "Diagnostic descriptor[%d]\n",
9375 dtag
= be32_to_cpu(tlv
->desc_tag
);
9377 case ELS_DTAG_LNK_FAULT_CAP
:
9378 if (bytes_remain
< FC_TLV_DESC_SZ_FROM_LENGTH(tlv
) ||
9379 FC_TLV_DESC_SZ_FROM_LENGTH(tlv
) !=
9380 sizeof(struct fc_diag_lnkflt_desc
)) {
9381 lpfc_printf_log(phba
, KERN_WARNING
,
9382 LOG_ELS
| LOG_CGN_MGMT
| LOG_LDS_EVENT
,
9383 "6465 Truncated Link Fault Diagnostic "
9384 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
9385 desc_cnt
, bytes_remain
,
9386 FC_TLV_DESC_SZ_FROM_LENGTH(tlv
),
9387 sizeof(struct fc_diag_lnkflt_desc
));
9390 plnkflt
= (struct fc_diag_lnkflt_desc
*)tlv
;
9391 lpfc_printf_log(phba
, KERN_INFO
,
9392 LOG_ELS
| LOG_LDS_EVENT
,
9393 "4626 Link Fault Desc Data: x%08x len x%x "
9394 "da x%x dd x%x interval x%x\n",
9395 be32_to_cpu(plnkflt
->desc_tag
),
9396 be32_to_cpu(plnkflt
->desc_len
),
9398 plnkflt
->degrade_activate_threshold
),
9400 plnkflt
->degrade_deactivate_threshold
),
9401 be32_to_cpu(plnkflt
->fec_degrade_interval
));
9403 case ELS_DTAG_CG_SIGNAL_CAP
:
9404 if (bytes_remain
< FC_TLV_DESC_SZ_FROM_LENGTH(tlv
) ||
9405 FC_TLV_DESC_SZ_FROM_LENGTH(tlv
) !=
9406 sizeof(struct fc_diag_cg_sig_desc
)) {
9408 phba
, KERN_WARNING
, LOG_CGN_MGMT
,
9409 "6466 Truncated cgn signal Diagnostic "
9410 "descriptor[%d]: %d vs 0x%zx 0x%zx\n",
9411 desc_cnt
, bytes_remain
,
9412 FC_TLV_DESC_SZ_FROM_LENGTH(tlv
),
9413 sizeof(struct fc_diag_cg_sig_desc
));
9417 phba
->cgn_reg_fpin
= phba
->cgn_init_reg_fpin
;
9418 phba
->cgn_reg_signal
= phba
->cgn_init_reg_signal
;
9420 /* We start negotiation with lpfc_fabric_cgn_frequency.
9421 * When we process the EDC, we will settle on the
9424 phba
->cgn_sig_freq
= lpfc_fabric_cgn_frequency
;
9426 lpfc_least_capable_settings(
9427 phba
, (struct fc_diag_cg_sig_desc
*)tlv
);
9430 dtag_nm
= lpfc_get_tlv_dtag_nm(dtag
);
9431 lpfc_printf_log(phba
, KERN_WARNING
,
9432 LOG_ELS
| LOG_CGN_MGMT
| LOG_LDS_EVENT
,
9433 "6467 unknown Diagnostic "
9434 "Descriptor[%d]: tag x%x (%s)\n",
9435 desc_cnt
, dtag
, dtag_nm
);
9437 bytes_remain
-= FC_TLV_DESC_SZ_FROM_LENGTH(tlv
);
9438 tlv
= fc_tlv_next_desc(tlv
);
9442 /* Need to send back an ACC */
9443 lpfc_issue_els_edc_rsp(vport
, cmdiocb
, ndlp
);
9445 lpfc_config_cgn_signal(phba
);
9450 * lpfc_els_timeout - Handler funciton to the els timer
9451 * @t: timer context used to obtain the vport.
9453 * This routine is invoked by the ELS timer after timeout. It posts the ELS
9454 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
9455 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
9456 * up the worker thread. It is for the worker thread to invoke the routine
9457 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
9460 lpfc_els_timeout(struct timer_list
*t
)
9462 struct lpfc_vport
*vport
= from_timer(vport
, t
, els_tmofunc
);
9463 struct lpfc_hba
*phba
= vport
->phba
;
9464 uint32_t tmo_posted
;
9465 unsigned long iflag
;
9467 spin_lock_irqsave(&vport
->work_port_lock
, iflag
);
9468 tmo_posted
= vport
->work_port_events
& WORKER_ELS_TMO
;
9469 if (!tmo_posted
&& !test_bit(FC_UNLOADING
, &vport
->load_flag
))
9470 vport
->work_port_events
|= WORKER_ELS_TMO
;
9471 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
9473 if (!tmo_posted
&& !test_bit(FC_UNLOADING
, &vport
->load_flag
))
9474 lpfc_worker_wake_up(phba
);
9480 * lpfc_els_timeout_handler - Process an els timeout event
9481 * @vport: pointer to a virtual N_Port data structure.
9483 * This routine is the actual handler function that processes an ELS timeout
9484 * event. It walks the ELS ring to get and abort all the IOCBs (except the
9485 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
9486 * invoking the lpfc_sli_issue_abort_iotag() routine.
9489 lpfc_els_timeout_handler(struct lpfc_vport
*vport
)
9491 struct lpfc_hba
*phba
= vport
->phba
;
9492 struct lpfc_sli_ring
*pring
;
9493 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
9495 struct lpfc_dmabuf
*pcmd
;
9496 uint32_t els_command
= 0;
9498 uint32_t remote_ID
= 0xffffffff;
9499 LIST_HEAD(abort_list
);
9500 u32 ulp_command
= 0, ulp_context
= 0, did
= 0, iotag
= 0;
9503 timeout
= (uint32_t)(phba
->fc_ratov
<< 1);
9505 pring
= lpfc_phba_elsring(phba
);
9506 if (unlikely(!pring
))
9509 if (test_bit(FC_UNLOADING
, &phba
->pport
->load_flag
))
9512 spin_lock_irq(&phba
->hbalock
);
9513 if (phba
->sli_rev
== LPFC_SLI_REV4
)
9514 spin_lock(&pring
->ring_lock
);
9516 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
9517 ulp_command
= get_job_cmnd(phba
, piocb
);
9518 ulp_context
= get_job_ulpcontext(phba
, piocb
);
9519 did
= get_job_els_rsp64_did(phba
, piocb
);
9521 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
9522 iotag
= get_wqe_reqtag(piocb
);
9525 iotag
= cmd
->ulpIoTag
;
9528 if ((piocb
->cmd_flag
& LPFC_IO_LIBDFC
) != 0 ||
9529 ulp_command
== CMD_ABORT_XRI_CX
||
9530 ulp_command
== CMD_ABORT_XRI_CN
||
9531 ulp_command
== CMD_CLOSE_XRI_CN
)
9534 if (piocb
->vport
!= vport
)
9537 pcmd
= piocb
->cmd_dmabuf
;
9539 els_command
= *(uint32_t *) (pcmd
->virt
);
9541 if (els_command
== ELS_CMD_FARP
||
9542 els_command
== ELS_CMD_FARPR
||
9543 els_command
== ELS_CMD_FDISC
)
9546 if (piocb
->drvrTimeout
> 0) {
9547 if (piocb
->drvrTimeout
>= timeout
)
9548 piocb
->drvrTimeout
-= timeout
;
9550 piocb
->drvrTimeout
= 0;
9554 remote_ID
= 0xffffffff;
9555 if (ulp_command
!= CMD_GEN_REQUEST64_CR
) {
9558 struct lpfc_nodelist
*ndlp
;
9559 ndlp
= __lpfc_findnode_rpi(vport
, ulp_context
);
9561 remote_ID
= ndlp
->nlp_DID
;
9563 list_add_tail(&piocb
->dlist
, &abort_list
);
9565 if (phba
->sli_rev
== LPFC_SLI_REV4
)
9566 spin_unlock(&pring
->ring_lock
);
9567 spin_unlock_irq(&phba
->hbalock
);
9569 list_for_each_entry_safe(piocb
, tmp_iocb
, &abort_list
, dlist
) {
9570 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
9571 "0127 ELS timeout Data: x%x x%x x%x "
9572 "x%x\n", els_command
,
9573 remote_ID
, ulp_command
, iotag
);
9575 spin_lock_irq(&phba
->hbalock
);
9576 list_del_init(&piocb
->dlist
);
9577 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
, NULL
);
9578 spin_unlock_irq(&phba
->hbalock
);
9581 /* Make sure HBA is alive */
9582 lpfc_issue_hb_tmo(phba
);
9584 if (!list_empty(&pring
->txcmplq
))
9585 if (!test_bit(FC_UNLOADING
, &phba
->pport
->load_flag
))
9586 mod_timer(&vport
->els_tmofunc
,
9587 jiffies
+ msecs_to_jiffies(1000 * timeout
));
9591 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
9592 * @vport: pointer to a host virtual N_Port data structure.
9594 * This routine is used to clean up all the outstanding ELS commands on a
9595 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
9596 * routine. After that, it walks the ELS transmit queue to remove all the
9597 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
9598 * the IOCBs with a non-NULL completion callback function, the callback
9599 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
9600 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
9601 * callback function, the IOCB will simply be released. Finally, it walks
9602 * the ELS transmit completion queue to issue an abort IOCB to any transmit
9603 * completion queue IOCB that is associated with the @vport and is not
9604 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
9605 * part of the discovery state machine) out to HBA by invoking the
9606 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
9607 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
9608 * the IOCBs are aborted when this function returns.
9611 lpfc_els_flush_cmd(struct lpfc_vport
*vport
)
9613 LIST_HEAD(abort_list
);
9614 LIST_HEAD(cancel_list
);
9615 struct lpfc_hba
*phba
= vport
->phba
;
9616 struct lpfc_sli_ring
*pring
;
9617 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
9619 unsigned long iflags
= 0;
9622 lpfc_fabric_abort_vport(vport
);
9625 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
9626 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
9627 * ultimately grabs the ring_lock, the driver must splice the list into
9628 * a working list and release the locks before calling the abort.
9630 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9631 pring
= lpfc_phba_elsring(phba
);
9633 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
9634 if (unlikely(!pring
)) {
9635 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9639 if (phba
->sli_rev
== LPFC_SLI_REV4
)
9640 spin_lock(&pring
->ring_lock
);
9642 mbx_tmo_err
= test_bit(MBX_TMO_ERR
, &phba
->bit_flags
);
9643 /* First we need to issue aborts to outstanding cmds on txcmpl */
9644 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
9645 if (piocb
->cmd_flag
& LPFC_IO_LIBDFC
&& !mbx_tmo_err
)
9648 if (piocb
->vport
!= vport
)
9651 if (piocb
->cmd_flag
& LPFC_DRIVER_ABORTED
&& !mbx_tmo_err
)
9654 /* On the ELS ring we can have ELS_REQUESTs, ELS_RSPs,
9655 * or GEN_REQUESTs waiting for a CQE response.
9657 ulp_command
= get_job_cmnd(phba
, piocb
);
9658 if (ulp_command
== CMD_ELS_REQUEST64_WQE
||
9659 ulp_command
== CMD_XMIT_ELS_RSP64_WQE
) {
9660 list_add_tail(&piocb
->dlist
, &abort_list
);
9662 /* If the link is down when flushing ELS commands
9663 * the firmware will not complete them till after
9664 * the link comes back up. This may confuse
9665 * discovery for the new link up, so we need to
9666 * change the compl routine to just clean up the iocb
9667 * and avoid any retry logic.
9669 if (phba
->link_state
== LPFC_LINK_DOWN
)
9670 piocb
->cmd_cmpl
= lpfc_cmpl_els_link_down
;
9671 } else if (ulp_command
== CMD_GEN_REQUEST64_CR
||
9673 list_add_tail(&piocb
->dlist
, &abort_list
);
9676 if (phba
->sli_rev
== LPFC_SLI_REV4
)
9677 spin_unlock(&pring
->ring_lock
);
9678 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9680 /* Abort each txcmpl iocb on aborted list and remove the dlist links. */
9681 list_for_each_entry_safe(piocb
, tmp_iocb
, &abort_list
, dlist
) {
9682 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9683 list_del_init(&piocb
->dlist
);
9684 if (mbx_tmo_err
|| !(phba
->sli
.sli_flag
& LPFC_SLI_ACTIVE
))
9685 list_move_tail(&piocb
->list
, &cancel_list
);
9687 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
, NULL
);
9689 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9691 if (!list_empty(&cancel_list
))
9692 lpfc_sli_cancel_iocbs(phba
, &cancel_list
, IOSTAT_LOCAL_REJECT
,
9695 /* Make sure HBA is alive */
9696 lpfc_issue_hb_tmo(phba
);
9698 if (!list_empty(&abort_list
))
9699 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
9700 "3387 abort list for txq not empty\n");
9701 INIT_LIST_HEAD(&abort_list
);
9703 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9704 if (phba
->sli_rev
== LPFC_SLI_REV4
)
9705 spin_lock(&pring
->ring_lock
);
9707 /* No need to abort the txq list,
9708 * just queue them up for lpfc_sli_cancel_iocbs
9710 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
9711 ulp_command
= get_job_cmnd(phba
, piocb
);
9713 if (piocb
->cmd_flag
& LPFC_IO_LIBDFC
)
9716 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
9717 if (ulp_command
== CMD_QUE_RING_BUF_CN
||
9718 ulp_command
== CMD_QUE_RING_BUF64_CN
||
9719 ulp_command
== CMD_CLOSE_XRI_CN
||
9720 ulp_command
== CMD_ABORT_XRI_CN
||
9721 ulp_command
== CMD_ABORT_XRI_CX
)
9724 if (piocb
->vport
!= vport
)
9727 list_del_init(&piocb
->list
);
9728 list_add_tail(&piocb
->list
, &abort_list
);
9731 /* The same holds true for any FLOGI/FDISC on the fabric_iocb_list */
9732 if (vport
== phba
->pport
) {
9733 list_for_each_entry_safe(piocb
, tmp_iocb
,
9734 &phba
->fabric_iocb_list
, list
) {
9735 list_del_init(&piocb
->list
);
9736 list_add_tail(&piocb
->list
, &abort_list
);
9740 if (phba
->sli_rev
== LPFC_SLI_REV4
)
9741 spin_unlock(&pring
->ring_lock
);
9742 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9744 /* Cancel all the IOCBs from the completions list */
9745 lpfc_sli_cancel_iocbs(phba
, &abort_list
,
9746 IOSTAT_LOCAL_REJECT
, IOERR_SLI_ABORTED
);
9752 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
9753 * @phba: pointer to lpfc hba data structure.
9755 * This routine is used to clean up all the outstanding ELS commands on a
9756 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
9757 * routine. After that, it walks the ELS transmit queue to remove all the
9758 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
9759 * the IOCBs with the completion callback function associated, the callback
9760 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
9761 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
9762 * callback function associated, the IOCB will simply be released. Finally,
9763 * it walks the ELS transmit completion queue to issue an abort IOCB to any
9764 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
9765 * management plane IOCBs that are not part of the discovery state machine)
9766 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
9769 lpfc_els_flush_all_cmd(struct lpfc_hba
*phba
)
9771 struct lpfc_vport
*vport
;
9773 spin_lock_irq(&phba
->port_list_lock
);
9774 list_for_each_entry(vport
, &phba
->port_list
, listentry
)
9775 lpfc_els_flush_cmd(vport
);
9776 spin_unlock_irq(&phba
->port_list_lock
);
9782 * lpfc_send_els_failure_event - Posts an ELS command failure event
9783 * @phba: Pointer to hba context object.
9784 * @cmdiocbp: Pointer to command iocb which reported error.
9785 * @rspiocbp: Pointer to response iocb which reported error.
9787 * This function sends an event when there is an ELS command
9791 lpfc_send_els_failure_event(struct lpfc_hba
*phba
,
9792 struct lpfc_iocbq
*cmdiocbp
,
9793 struct lpfc_iocbq
*rspiocbp
)
9795 struct lpfc_vport
*vport
= cmdiocbp
->vport
;
9796 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
9797 struct lpfc_lsrjt_event lsrjt_event
;
9798 struct lpfc_fabric_event_header fabric_event
;
9800 struct lpfc_nodelist
*ndlp
;
9802 u32 ulp_status
, ulp_word4
;
9804 ndlp
= cmdiocbp
->ndlp
;
9808 ulp_status
= get_job_ulpstatus(phba
, rspiocbp
);
9809 ulp_word4
= get_job_word4(phba
, rspiocbp
);
9811 if (ulp_status
== IOSTAT_LS_RJT
) {
9812 lsrjt_event
.header
.event_type
= FC_REG_ELS_EVENT
;
9813 lsrjt_event
.header
.subcategory
= LPFC_EVENT_LSRJT_RCV
;
9814 memcpy(lsrjt_event
.header
.wwpn
, &ndlp
->nlp_portname
,
9815 sizeof(struct lpfc_name
));
9816 memcpy(lsrjt_event
.header
.wwnn
, &ndlp
->nlp_nodename
,
9817 sizeof(struct lpfc_name
));
9818 pcmd
= (uint32_t *)cmdiocbp
->cmd_dmabuf
->virt
;
9819 lsrjt_event
.command
= (pcmd
!= NULL
) ? *pcmd
: 0;
9820 stat
.un
.ls_rjt_error_be
= cpu_to_be32(ulp_word4
);
9821 lsrjt_event
.reason_code
= stat
.un
.b
.lsRjtRsnCode
;
9822 lsrjt_event
.explanation
= stat
.un
.b
.lsRjtRsnCodeExp
;
9823 fc_host_post_vendor_event(shost
,
9824 fc_get_event_number(),
9825 sizeof(lsrjt_event
),
9826 (char *)&lsrjt_event
,
9830 if (ulp_status
== IOSTAT_NPORT_BSY
||
9831 ulp_status
== IOSTAT_FABRIC_BSY
) {
9832 fabric_event
.event_type
= FC_REG_FABRIC_EVENT
;
9833 if (ulp_status
== IOSTAT_NPORT_BSY
)
9834 fabric_event
.subcategory
= LPFC_EVENT_PORT_BUSY
;
9836 fabric_event
.subcategory
= LPFC_EVENT_FABRIC_BUSY
;
9837 memcpy(fabric_event
.wwpn
, &ndlp
->nlp_portname
,
9838 sizeof(struct lpfc_name
));
9839 memcpy(fabric_event
.wwnn
, &ndlp
->nlp_nodename
,
9840 sizeof(struct lpfc_name
));
9841 fc_host_post_vendor_event(shost
,
9842 fc_get_event_number(),
9843 sizeof(fabric_event
),
9844 (char *)&fabric_event
,
9852 * lpfc_send_els_event - Posts unsolicited els event
9853 * @vport: Pointer to vport object.
9854 * @ndlp: Pointer FC node object.
9855 * @payload: ELS command code type.
9857 * This function posts an event when there is an incoming
9858 * unsolicited ELS command.
9861 lpfc_send_els_event(struct lpfc_vport
*vport
,
9862 struct lpfc_nodelist
*ndlp
,
9865 struct lpfc_els_event_header
*els_data
= NULL
;
9866 struct lpfc_logo_event
*logo_data
= NULL
;
9867 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
9869 if (*payload
== ELS_CMD_LOGO
) {
9870 logo_data
= kmalloc(sizeof(struct lpfc_logo_event
), GFP_KERNEL
);
9872 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
9873 "0148 Failed to allocate memory "
9874 "for LOGO event\n");
9877 els_data
= &logo_data
->header
;
9879 els_data
= kmalloc(sizeof(struct lpfc_els_event_header
),
9882 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
9883 "0149 Failed to allocate memory "
9888 els_data
->event_type
= FC_REG_ELS_EVENT
;
9891 els_data
->subcategory
= LPFC_EVENT_PLOGI_RCV
;
9894 els_data
->subcategory
= LPFC_EVENT_PRLO_RCV
;
9897 els_data
->subcategory
= LPFC_EVENT_ADISC_RCV
;
9900 els_data
->subcategory
= LPFC_EVENT_LOGO_RCV
;
9901 /* Copy the WWPN in the LOGO payload */
9902 memcpy(logo_data
->logo_wwpn
, &payload
[2],
9903 sizeof(struct lpfc_name
));
9909 memcpy(els_data
->wwpn
, &ndlp
->nlp_portname
, sizeof(struct lpfc_name
));
9910 memcpy(els_data
->wwnn
, &ndlp
->nlp_nodename
, sizeof(struct lpfc_name
));
9911 if (*payload
== ELS_CMD_LOGO
) {
9912 fc_host_post_vendor_event(shost
,
9913 fc_get_event_number(),
9914 sizeof(struct lpfc_logo_event
),
9919 fc_host_post_vendor_event(shost
,
9920 fc_get_event_number(),
9921 sizeof(struct lpfc_els_event_header
),
9931 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_li_event_nm
, fc_fpin_li_event_types
,
9932 FC_FPIN_LI_EVT_TYPES_INIT
);
9934 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_deli_event_nm
, fc_fpin_deli_event_types
,
9935 FC_FPIN_DELI_EVT_TYPES_INIT
);
9937 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_event_nm
, fc_fpin_congn_event_types
,
9938 FC_FPIN_CONGN_EVT_TYPES_INIT
);
9940 DECLARE_ENUM2STR_LOOKUP(lpfc_get_fpin_congn_severity_nm
,
9941 fc_fpin_congn_severity_types
,
9942 FC_FPIN_CONGN_SEVERITY_INIT
);
9946 * lpfc_display_fpin_wwpn - Display WWPNs accessible by the attached port
9947 * @phba: Pointer to phba object.
9948 * @wwnlist: Pointer to list of WWPNs in FPIN payload
9949 * @cnt: count of WWPNs in FPIN payload
9951 * This routine is called by LI and PC descriptors.
9952 * Limit the number of WWPNs displayed to 6 log messages, 6 per log message
9955 lpfc_display_fpin_wwpn(struct lpfc_hba
*phba
, __be64
*wwnlist
, u32 cnt
)
9957 char buf
[LPFC_FPIN_WWPN_LINE_SZ
];
9965 len
= scnprintf(buf
, LPFC_FPIN_WWPN_LINE_SZ
, "Accessible WWPNs:");
9966 for (i
= 0; i
< cnt
; i
++) {
9967 /* Are we on the last WWPN */
9971 /* Extract the next WWPN from the payload */
9973 wwpn
= be64_to_cpu(wwn
);
9974 len
+= scnprintf(buf
+ len
, LPFC_FPIN_WWPN_LINE_SZ
- len
,
9977 /* Log a message if we are on the last WWPN
9978 * or if we hit the max allowed per message.
9981 if (wcnt
== LPFC_FPIN_WWPN_LINE_CNT
|| endit
) {
9983 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
9986 /* Check if we reached the last WWPN */
9990 /* Limit the number of log message displayed per FPIN */
9992 if (line
== LPFC_FPIN_WWPN_NUM_LINE
) {
9993 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
9994 "4687 %d WWPNs Truncated\n",
9999 /* Start over with next log message */
10001 len
= scnprintf(buf
, LPFC_FPIN_WWPN_LINE_SZ
,
10002 "Additional WWPNs:");
10008 * lpfc_els_rcv_fpin_li - Process an FPIN Link Integrity Event.
10009 * @phba: Pointer to phba object.
10010 * @tlv: Pointer to the Link Integrity Notification Descriptor.
10012 * This function processes a Link Integrity FPIN event by logging a message.
10015 lpfc_els_rcv_fpin_li(struct lpfc_hba
*phba
, struct fc_tlv_desc
*tlv
)
10017 struct fc_fn_li_desc
*li
= (struct fc_fn_li_desc
*)tlv
;
10018 const char *li_evt_str
;
10021 li_evt
= be16_to_cpu(li
->event_type
);
10022 li_evt_str
= lpfc_get_fpin_li_event_nm(li_evt
);
10023 cnt
= be32_to_cpu(li
->pname_count
);
10025 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
10026 "4680 FPIN Link Integrity %s (x%x) "
10027 "Detecting PN x%016llx Attached PN x%016llx "
10028 "Duration %d mSecs Count %d Port Cnt %d\n",
10029 li_evt_str
, li_evt
,
10030 be64_to_cpu(li
->detecting_wwpn
),
10031 be64_to_cpu(li
->attached_wwpn
),
10032 be32_to_cpu(li
->event_threshold
),
10033 be32_to_cpu(li
->event_count
), cnt
);
10035 lpfc_display_fpin_wwpn(phba
, (__be64
*)&li
->pname_list
, cnt
);
10039 * lpfc_els_rcv_fpin_del - Process an FPIN Delivery Event.
10040 * @phba: Pointer to hba object.
10041 * @tlv: Pointer to the Delivery Notification Descriptor TLV
10043 * This function processes a Delivery FPIN event by logging a message.
10046 lpfc_els_rcv_fpin_del(struct lpfc_hba
*phba
, struct fc_tlv_desc
*tlv
)
10048 struct fc_fn_deli_desc
*del
= (struct fc_fn_deli_desc
*)tlv
;
10049 const char *del_rsn_str
;
10053 del_rsn
= be16_to_cpu(del
->deli_reason_code
);
10054 del_rsn_str
= lpfc_get_fpin_deli_event_nm(del_rsn
);
10056 /* Skip over desc_tag/desc_len header to payload */
10057 frame
= (__be32
*)(del
+ 1);
10059 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
10060 "4681 FPIN Delivery %s (x%x) "
10061 "Detecting PN x%016llx Attached PN x%016llx "
10063 "DiscHdr1 x%08x DiscHdr2 x%08x DiscHdr3 x%08x "
10064 "DiscHdr4 x%08x DiscHdr5 x%08x\n",
10065 del_rsn_str
, del_rsn
,
10066 be64_to_cpu(del
->detecting_wwpn
),
10067 be64_to_cpu(del
->attached_wwpn
),
10068 be32_to_cpu(frame
[0]),
10069 be32_to_cpu(frame
[1]),
10070 be32_to_cpu(frame
[2]),
10071 be32_to_cpu(frame
[3]),
10072 be32_to_cpu(frame
[4]),
10073 be32_to_cpu(frame
[5]));
10077 * lpfc_els_rcv_fpin_peer_cgn - Process a FPIN Peer Congestion Event.
10078 * @phba: Pointer to hba object.
10079 * @tlv: Pointer to the Peer Congestion Notification Descriptor TLV
10081 * This function processes a Peer Congestion FPIN event by logging a message.
10084 lpfc_els_rcv_fpin_peer_cgn(struct lpfc_hba
*phba
, struct fc_tlv_desc
*tlv
)
10086 struct fc_fn_peer_congn_desc
*pc
= (struct fc_fn_peer_congn_desc
*)tlv
;
10087 const char *pc_evt_str
;
10090 pc_evt
= be16_to_cpu(pc
->event_type
);
10091 pc_evt_str
= lpfc_get_fpin_congn_event_nm(pc_evt
);
10092 cnt
= be32_to_cpu(pc
->pname_count
);
10094 /* Capture FPIN frequency */
10095 phba
->cgn_fpin_frequency
= be32_to_cpu(pc
->event_period
);
10097 lpfc_printf_log(phba
, KERN_INFO
, LOG_CGN_MGMT
| LOG_ELS
,
10098 "4684 FPIN Peer Congestion %s (x%x) "
10099 "Duration %d mSecs "
10100 "Detecting PN x%016llx Attached PN x%016llx "
10101 "Impacted Port Cnt %d\n",
10102 pc_evt_str
, pc_evt
,
10103 be32_to_cpu(pc
->event_period
),
10104 be64_to_cpu(pc
->detecting_wwpn
),
10105 be64_to_cpu(pc
->attached_wwpn
),
10108 lpfc_display_fpin_wwpn(phba
, (__be64
*)&pc
->pname_list
, cnt
);
10112 * lpfc_els_rcv_fpin_cgn - Process an FPIN Congestion notification
10113 * @phba: Pointer to hba object.
10114 * @tlv: Pointer to the Congestion Notification Descriptor TLV
10116 * This function processes an FPIN Congestion Notifiction. The notification
10117 * could be an Alarm or Warning. This routine feeds that data into driver's
10118 * running congestion algorithm. It also processes the FPIN by
10119 * logging a message. It returns 1 to indicate deliver this message
10120 * to the upper layer or 0 to indicate don't deliver it.
10123 lpfc_els_rcv_fpin_cgn(struct lpfc_hba
*phba
, struct fc_tlv_desc
*tlv
)
10125 struct lpfc_cgn_info
*cp
;
10126 struct fc_fn_congn_desc
*cgn
= (struct fc_fn_congn_desc
*)tlv
;
10127 const char *cgn_evt_str
;
10129 const char *cgn_sev_str
;
10133 bool nm_log
= false;
10136 cgn_evt
= be16_to_cpu(cgn
->event_type
);
10137 cgn_evt_str
= lpfc_get_fpin_congn_event_nm(cgn_evt
);
10138 cgn_sev
= cgn
->severity
;
10139 cgn_sev_str
= lpfc_get_fpin_congn_severity_nm(cgn_sev
);
10141 /* The driver only takes action on a Credit Stall or Oversubscription
10142 * event type to engage the IO algorithm. The driver prints an
10143 * unmaskable message only for Lost Credit and Credit Stall.
10144 * TODO: Still need to have definition of host action on clear,
10145 * lost credit and device specific event types.
10148 case FPIN_CONGN_LOST_CREDIT
:
10151 case FPIN_CONGN_CREDIT_STALL
:
10154 case FPIN_CONGN_OVERSUBSCRIPTION
:
10155 if (cgn_evt
== FPIN_CONGN_OVERSUBSCRIPTION
)
10158 case FPIN_CONGN_SEVERITY_ERROR
:
10159 /* Take action here for an Alarm event */
10160 if (phba
->cmf_active_mode
!= LPFC_CFG_OFF
) {
10161 if (phba
->cgn_reg_fpin
& LPFC_CGN_FPIN_ALARM
) {
10162 /* Track of alarm cnt for SYNC_WQE */
10163 atomic_inc(&phba
->cgn_sync_alarm_cnt
);
10165 /* Track alarm cnt for cgn_info regardless
10166 * of whether CMF is configured for Signals
10169 atomic_inc(&phba
->cgn_fabric_alarm_cnt
);
10173 case FPIN_CONGN_SEVERITY_WARNING
:
10174 /* Take action here for a Warning event */
10175 if (phba
->cmf_active_mode
!= LPFC_CFG_OFF
) {
10176 if (phba
->cgn_reg_fpin
& LPFC_CGN_FPIN_WARN
) {
10177 /* Track of warning cnt for SYNC_WQE */
10178 atomic_inc(&phba
->cgn_sync_warn_cnt
);
10180 /* Track warning cnt and freq for cgn_info
10181 * regardless of whether CMF is configured for
10182 * Signals or FPINs.
10184 atomic_inc(&phba
->cgn_fabric_warn_cnt
);
10186 /* Save frequency in ms */
10187 phba
->cgn_fpin_frequency
=
10188 be32_to_cpu(cgn
->event_period
);
10189 value
= phba
->cgn_fpin_frequency
;
10191 cp
= (struct lpfc_cgn_info
*)
10193 cp
->cgn_alarm_freq
=
10194 cpu_to_le16(value
);
10195 cp
->cgn_warn_freq
=
10196 cpu_to_le16(value
);
10197 crc
= lpfc_cgn_calc_crc32
10200 LPFC_CGN_CRC32_SEED
);
10201 cp
->cgn_info_crc
= cpu_to_le32(crc
);
10204 /* Don't deliver to upper layer since
10205 * driver took action on this tlv.
10214 /* Change the log level to unmaskable for the following event types. */
10215 lpfc_printf_log(phba
, (nm_log
? KERN_WARNING
: KERN_INFO
),
10216 LOG_CGN_MGMT
| LOG_ELS
,
10217 "4683 FPIN CONGESTION %s type %s (x%x) Event "
10218 "Duration %d mSecs\n",
10219 cgn_sev_str
, cgn_evt_str
, cgn_evt
,
10220 be32_to_cpu(cgn
->event_period
));
10225 lpfc_els_rcv_fpin(struct lpfc_vport
*vport
, void *p
, u32 fpin_length
)
10227 struct lpfc_hba
*phba
= vport
->phba
;
10228 struct fc_els_fpin
*fpin
= (struct fc_els_fpin
*)p
;
10229 struct fc_tlv_desc
*tlv
, *first_tlv
, *current_tlv
;
10230 const char *dtag_nm
;
10231 int desc_cnt
= 0, bytes_remain
, cnt
;
10232 u32 dtag
, deliver
= 0;
10235 /* FPINs handled only if we are in the right discovery state */
10236 if (vport
->port_state
< LPFC_DISC_AUTH
)
10239 /* make sure there is the full fpin header */
10240 if (fpin_length
< sizeof(struct fc_els_fpin
))
10243 /* Sanity check descriptor length. The desc_len value does not
10244 * include space for the ELS command and the desc_len fields.
10246 len
= be32_to_cpu(fpin
->desc_len
);
10247 if (fpin_length
< len
+ sizeof(struct fc_els_fpin
)) {
10248 lpfc_printf_log(phba
, KERN_WARNING
, LOG_CGN_MGMT
,
10249 "4671 Bad ELS FPIN length %d: %d\n",
10254 tlv
= (struct fc_tlv_desc
*)&fpin
->fpin_desc
[0];
10256 bytes_remain
= fpin_length
- offsetof(struct fc_els_fpin
, fpin_desc
);
10257 bytes_remain
= min_t(u32
, bytes_remain
, be32_to_cpu(fpin
->desc_len
));
10259 /* process each descriptor separately */
10260 while (bytes_remain
>= FC_TLV_DESC_HDR_SZ
&&
10261 bytes_remain
>= FC_TLV_DESC_SZ_FROM_LENGTH(tlv
)) {
10262 dtag
= be32_to_cpu(tlv
->desc_tag
);
10264 case ELS_DTAG_LNK_INTEGRITY
:
10265 lpfc_els_rcv_fpin_li(phba
, tlv
);
10268 case ELS_DTAG_DELIVERY
:
10269 lpfc_els_rcv_fpin_del(phba
, tlv
);
10272 case ELS_DTAG_PEER_CONGEST
:
10273 lpfc_els_rcv_fpin_peer_cgn(phba
, tlv
);
10276 case ELS_DTAG_CONGESTION
:
10277 deliver
= lpfc_els_rcv_fpin_cgn(phba
, tlv
);
10280 dtag_nm
= lpfc_get_tlv_dtag_nm(dtag
);
10281 lpfc_printf_log(phba
, KERN_WARNING
, LOG_CGN_MGMT
,
10282 "4678 unknown FPIN descriptor[%d]: "
10284 desc_cnt
, dtag
, dtag_nm
);
10286 /* If descriptor is bad, drop the rest of the data */
10289 lpfc_cgn_update_stat(phba
, dtag
);
10290 cnt
= be32_to_cpu(tlv
->desc_len
);
10292 /* Sanity check descriptor length. The desc_len value does not
10293 * include space for the desc_tag and the desc_len fields.
10295 len
-= (cnt
+ sizeof(struct fc_tlv_desc
));
10297 dtag_nm
= lpfc_get_tlv_dtag_nm(dtag
);
10298 lpfc_printf_log(phba
, KERN_WARNING
, LOG_CGN_MGMT
,
10299 "4672 Bad FPIN descriptor TLV length "
10301 cnt
, len
, fpin_length
, dtag_nm
);
10306 bytes_remain
-= FC_TLV_DESC_SZ_FROM_LENGTH(tlv
);
10307 tlv
= fc_tlv_next_desc(tlv
);
10309 /* Format payload such that the FPIN delivered to the
10310 * upper layer is a single descriptor FPIN.
10313 memcpy(first_tlv
, current_tlv
,
10314 (cnt
+ sizeof(struct fc_els_fpin
)));
10316 /* Adjust the length so that it only reflects a
10317 * single descriptor FPIN.
10319 fpin_length
= cnt
+ sizeof(struct fc_els_fpin
);
10320 fpin
->desc_len
= cpu_to_be32(fpin_length
);
10321 fpin_length
+= sizeof(struct fc_els_fpin
); /* the entire FPIN */
10323 /* Send every descriptor individually to the upper layer */
10325 fc_host_fpin_rcv(lpfc_shost_from_vport(vport
),
10326 fpin_length
, (char *)fpin
, 0);
10332 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
10333 * @phba: pointer to lpfc hba data structure.
10334 * @pring: pointer to a SLI ring.
10335 * @vport: pointer to a host virtual N_Port data structure.
10336 * @elsiocb: pointer to lpfc els command iocb data structure.
10338 * This routine is used for processing the IOCB associated with a unsolicited
10339 * event. It first determines whether there is an existing ndlp that matches
10340 * the DID from the unsolicited IOCB. If not, it will create a new one with
10341 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
10342 * IOCB is then used to invoke the proper routine and to set up proper state
10343 * of the discovery state machine.
10346 lpfc_els_unsol_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10347 struct lpfc_vport
*vport
, struct lpfc_iocbq
*elsiocb
)
10349 struct lpfc_nodelist
*ndlp
;
10350 struct ls_rjt stat
;
10351 u32
*payload
, payload_len
;
10352 u32 cmd
= 0, did
= 0, newnode
, status
= 0;
10353 uint8_t rjt_exp
, rjt_err
= 0, init_link
= 0;
10354 struct lpfc_wcqe_complete
*wcqe_cmpl
= NULL
;
10355 LPFC_MBOXQ_t
*mbox
;
10357 if (!vport
|| !elsiocb
->cmd_dmabuf
)
10361 wcqe_cmpl
= &elsiocb
->wcqe_cmpl
;
10362 payload
= elsiocb
->cmd_dmabuf
->virt
;
10363 if (phba
->sli_rev
== LPFC_SLI_REV4
)
10364 payload_len
= wcqe_cmpl
->total_data_placed
;
10366 payload_len
= elsiocb
->iocb
.unsli3
.rcvsli3
.acc_len
;
10367 status
= get_job_ulpstatus(phba
, elsiocb
);
10369 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) == 0)
10370 lpfc_sli3_post_buffer(phba
, pring
, 1);
10372 did
= get_job_els_rsp64_did(phba
, elsiocb
);
10374 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10375 "RCV Unsol ELS: status:x%x/x%x did:x%x",
10376 status
, get_job_word4(phba
, elsiocb
), did
);
10380 /* Check to see if link went down during discovery */
10381 if (lpfc_els_chk_latt(vport
))
10384 /* Ignore traffic received during vport shutdown. */
10385 if (test_bit(FC_UNLOADING
, &vport
->load_flag
))
10388 /* If NPort discovery is delayed drop incoming ELS */
10389 if (test_bit(FC_DISC_DELAYED
, &vport
->fc_flag
) &&
10390 cmd
!= ELS_CMD_PLOGI
)
10393 ndlp
= lpfc_findnode_did(vport
, did
);
10395 /* Cannot find existing Fabric ndlp, so allocate a new one */
10396 ndlp
= lpfc_nlp_init(vport
, did
);
10399 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
10401 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
10402 ndlp
->nlp_type
|= NLP_FABRIC
;
10403 } else if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
10404 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
10408 phba
->fc_stat
.elsRcvFrame
++;
10411 * Do not process any unsolicited ELS commands
10412 * if the ndlp is in DEV_LOSS
10414 spin_lock_irq(&ndlp
->lock
);
10415 if (ndlp
->nlp_flag
& NLP_IN_DEV_LOSS
) {
10416 spin_unlock_irq(&ndlp
->lock
);
10418 lpfc_nlp_put(ndlp
);
10421 spin_unlock_irq(&ndlp
->lock
);
10423 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
10424 if (!elsiocb
->ndlp
)
10426 elsiocb
->vport
= vport
;
10428 if ((cmd
& ELS_CMD_MASK
) == ELS_CMD_RSCN
) {
10429 cmd
&= ELS_CMD_MASK
;
10431 /* ELS command <elsCmd> received from NPORT <did> */
10432 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
10433 "0112 ELS command x%x received from NPORT x%x "
10434 "refcnt %d Data: x%x x%lx x%x x%x\n",
10435 cmd
, did
, kref_read(&ndlp
->kref
), vport
->port_state
,
10436 vport
->fc_flag
, vport
->fc_myDID
, vport
->fc_prevDID
);
10438 /* reject till our FLOGI completes or PLOGI assigned DID via PT2PT */
10439 if ((vport
->port_state
< LPFC_FABRIC_CFG_LINK
) &&
10440 (cmd
!= ELS_CMD_FLOGI
) &&
10441 !((cmd
== ELS_CMD_PLOGI
) && test_bit(FC_PT2PT
, &vport
->fc_flag
))) {
10442 rjt_err
= LSRJT_LOGICAL_BSY
;
10443 rjt_exp
= LSEXP_NOTHING_MORE
;
10448 case ELS_CMD_PLOGI
:
10449 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10450 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
10451 did
, vport
->port_state
, ndlp
->nlp_flag
);
10453 phba
->fc_stat
.elsRcvPLOGI
++;
10454 ndlp
= lpfc_plogi_confirm_nport(phba
, payload
, ndlp
);
10455 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
10456 test_bit(FC_PT2PT
, &phba
->pport
->fc_flag
)) {
10457 vport
->fc_prevDID
= vport
->fc_myDID
;
10458 /* Our DID needs to be updated before registering
10459 * the vfi. This is done in lpfc_rcv_plogi but
10460 * that is called after the reg_vfi.
10463 bf_get(els_rsp64_sid
,
10464 &elsiocb
->wqe
.xmit_els_rsp
);
10465 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
10466 "3312 Remote port assigned DID x%x "
10467 "%x\n", vport
->fc_myDID
,
10468 vport
->fc_prevDID
);
10471 lpfc_send_els_event(vport
, ndlp
, payload
);
10473 /* If Nport discovery is delayed, reject PLOGIs */
10474 if (test_bit(FC_DISC_DELAYED
, &vport
->fc_flag
)) {
10475 rjt_err
= LSRJT_UNABLE_TPC
;
10476 rjt_exp
= LSEXP_NOTHING_MORE
;
10480 if (vport
->port_state
< LPFC_DISC_AUTH
) {
10481 if (!test_bit(FC_PT2PT
, &phba
->pport
->fc_flag
) ||
10482 test_bit(FC_PT2PT_PLOGI
, &phba
->pport
->fc_flag
)) {
10483 rjt_err
= LSRJT_UNABLE_TPC
;
10484 rjt_exp
= LSEXP_NOTHING_MORE
;
10489 spin_lock_irq(&ndlp
->lock
);
10490 ndlp
->nlp_flag
&= ~NLP_TARGET_REMOVE
;
10491 spin_unlock_irq(&ndlp
->lock
);
10493 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
10494 NLP_EVT_RCV_PLOGI
);
10497 case ELS_CMD_FLOGI
:
10498 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10499 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
10500 did
, vport
->port_state
, ndlp
->nlp_flag
);
10502 phba
->fc_stat
.elsRcvFLOGI
++;
10504 /* If the driver believes fabric discovery is done and is ready,
10505 * bounce the link. There is some descrepancy.
10507 if (vport
->port_state
>= LPFC_LOCAL_CFG_LINK
&&
10508 test_bit(FC_PT2PT
, &vport
->fc_flag
) &&
10509 vport
->rcv_flogi_cnt
>= 1) {
10510 rjt_err
= LSRJT_LOGICAL_BSY
;
10511 rjt_exp
= LSEXP_NOTHING_MORE
;
10516 lpfc_els_rcv_flogi(vport
, elsiocb
, ndlp
);
10517 /* retain node if our response is deferred */
10518 if (phba
->defer_flogi_acc
.flag
)
10521 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
10522 NLP_EVT_DEVICE_RM
);
10525 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10526 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
10527 did
, vport
->port_state
, ndlp
->nlp_flag
);
10529 phba
->fc_stat
.elsRcvLOGO
++;
10530 lpfc_send_els_event(vport
, ndlp
, payload
);
10531 if (vport
->port_state
< LPFC_DISC_AUTH
) {
10532 rjt_err
= LSRJT_UNABLE_TPC
;
10533 rjt_exp
= LSEXP_NOTHING_MORE
;
10536 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_LOGO
);
10538 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
10539 NLP_EVT_DEVICE_RM
);
10542 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10543 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
10544 did
, vport
->port_state
, ndlp
->nlp_flag
);
10546 phba
->fc_stat
.elsRcvPRLO
++;
10547 lpfc_send_els_event(vport
, ndlp
, payload
);
10548 if (vport
->port_state
< LPFC_DISC_AUTH
) {
10549 rjt_err
= LSRJT_UNABLE_TPC
;
10550 rjt_exp
= LSEXP_NOTHING_MORE
;
10553 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLO
);
10556 phba
->fc_stat
.elsRcvLCB
++;
10557 lpfc_els_rcv_lcb(vport
, elsiocb
, ndlp
);
10560 phba
->fc_stat
.elsRcvRDP
++;
10561 lpfc_els_rcv_rdp(vport
, elsiocb
, ndlp
);
10564 phba
->fc_stat
.elsRcvRSCN
++;
10565 lpfc_els_rcv_rscn(vport
, elsiocb
, ndlp
);
10567 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
10568 NLP_EVT_DEVICE_RM
);
10570 case ELS_CMD_ADISC
:
10571 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10572 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
10573 did
, vport
->port_state
, ndlp
->nlp_flag
);
10575 lpfc_send_els_event(vport
, ndlp
, payload
);
10576 phba
->fc_stat
.elsRcvADISC
++;
10577 if (vport
->port_state
< LPFC_DISC_AUTH
) {
10578 rjt_err
= LSRJT_UNABLE_TPC
;
10579 rjt_exp
= LSEXP_NOTHING_MORE
;
10582 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
10583 NLP_EVT_RCV_ADISC
);
10585 case ELS_CMD_PDISC
:
10586 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10587 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
10588 did
, vport
->port_state
, ndlp
->nlp_flag
);
10590 phba
->fc_stat
.elsRcvPDISC
++;
10591 if (vport
->port_state
< LPFC_DISC_AUTH
) {
10592 rjt_err
= LSRJT_UNABLE_TPC
;
10593 rjt_exp
= LSEXP_NOTHING_MORE
;
10596 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
10597 NLP_EVT_RCV_PDISC
);
10599 case ELS_CMD_FARPR
:
10600 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10601 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
10602 did
, vport
->port_state
, ndlp
->nlp_flag
);
10604 phba
->fc_stat
.elsRcvFARPR
++;
10605 lpfc_els_rcv_farpr(vport
, elsiocb
, ndlp
);
10608 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10609 "RCV FARP: did:x%x/ste:x%x flg:x%x",
10610 did
, vport
->port_state
, ndlp
->nlp_flag
);
10612 phba
->fc_stat
.elsRcvFARP
++;
10613 lpfc_els_rcv_farp(vport
, elsiocb
, ndlp
);
10616 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10617 "RCV FAN: did:x%x/ste:x%x flg:x%x",
10618 did
, vport
->port_state
, ndlp
->nlp_flag
);
10620 phba
->fc_stat
.elsRcvFAN
++;
10621 lpfc_els_rcv_fan(vport
, elsiocb
, ndlp
);
10624 case ELS_CMD_NVMEPRLI
:
10625 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10626 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
10627 did
, vport
->port_state
, ndlp
->nlp_flag
);
10629 phba
->fc_stat
.elsRcvPRLI
++;
10630 if ((vport
->port_state
< LPFC_DISC_AUTH
) &&
10631 test_bit(FC_FABRIC
, &vport
->fc_flag
)) {
10632 rjt_err
= LSRJT_UNABLE_TPC
;
10633 rjt_exp
= LSEXP_NOTHING_MORE
;
10636 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLI
);
10639 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10640 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
10641 did
, vport
->port_state
, ndlp
->nlp_flag
);
10643 phba
->fc_stat
.elsRcvLIRR
++;
10644 lpfc_els_rcv_lirr(vport
, elsiocb
, ndlp
);
10646 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
10647 NLP_EVT_DEVICE_RM
);
10650 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10651 "RCV RLS: did:x%x/ste:x%x flg:x%x",
10652 did
, vport
->port_state
, ndlp
->nlp_flag
);
10654 phba
->fc_stat
.elsRcvRLS
++;
10655 lpfc_els_rcv_rls(vport
, elsiocb
, ndlp
);
10657 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
10658 NLP_EVT_DEVICE_RM
);
10661 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10662 "RCV RPL: did:x%x/ste:x%x flg:x%x",
10663 did
, vport
->port_state
, ndlp
->nlp_flag
);
10665 phba
->fc_stat
.elsRcvRPL
++;
10666 lpfc_els_rcv_rpl(vport
, elsiocb
, ndlp
);
10668 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
10669 NLP_EVT_DEVICE_RM
);
10672 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10673 "RCV RNID: did:x%x/ste:x%x flg:x%x",
10674 did
, vport
->port_state
, ndlp
->nlp_flag
);
10676 phba
->fc_stat
.elsRcvRNID
++;
10677 lpfc_els_rcv_rnid(vport
, elsiocb
, ndlp
);
10679 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
10680 NLP_EVT_DEVICE_RM
);
10683 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10684 "RCV RTV: did:x%x/ste:x%x flg:x%x",
10685 did
, vport
->port_state
, ndlp
->nlp_flag
);
10686 phba
->fc_stat
.elsRcvRTV
++;
10687 lpfc_els_rcv_rtv(vport
, elsiocb
, ndlp
);
10689 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
10690 NLP_EVT_DEVICE_RM
);
10693 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10694 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
10695 did
, vport
->port_state
, ndlp
->nlp_flag
);
10697 phba
->fc_stat
.elsRcvRRQ
++;
10698 lpfc_els_rcv_rrq(vport
, elsiocb
, ndlp
);
10700 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
10701 NLP_EVT_DEVICE_RM
);
10704 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10705 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
10706 did
, vport
->port_state
, ndlp
->nlp_flag
);
10708 phba
->fc_stat
.elsRcvECHO
++;
10709 lpfc_els_rcv_echo(vport
, elsiocb
, ndlp
);
10711 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
10712 NLP_EVT_DEVICE_RM
);
10715 /* receive this due to exchange closed */
10716 rjt_err
= LSRJT_UNABLE_TPC
;
10717 rjt_exp
= LSEXP_INVALID_OX_RX
;
10720 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10721 "RCV FPIN: did:x%x/ste:x%x flg:x%x",
10722 did
, vport
->port_state
, ndlp
->nlp_flag
);
10724 lpfc_els_rcv_fpin(vport
, (struct fc_els_fpin
*)payload
,
10727 /* There are no replies, so no rjt codes */
10730 lpfc_els_rcv_edc(vport
, elsiocb
, ndlp
);
10733 phba
->fc_stat
.elsRcvRDF
++;
10734 /* Accept RDF only from fabric controller */
10735 if (did
!= Fabric_Cntl_DID
) {
10736 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
10737 "1115 Received RDF from invalid DID "
10739 rjt_err
= LSRJT_PROTOCOL_ERR
;
10740 rjt_exp
= LSEXP_NOTHING_MORE
;
10744 lpfc_els_rcv_rdf(vport
, elsiocb
, ndlp
);
10747 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
10748 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
10749 cmd
, did
, vport
->port_state
);
10751 /* Unsupported ELS command, reject */
10752 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
10753 rjt_exp
= LSEXP_NOTHING_MORE
;
10755 /* Unknown ELS command <elsCmd> received from NPORT <did> */
10756 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
10757 "0115 Unknown ELS command x%x "
10758 "received from NPORT x%x\n", cmd
, did
);
10760 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
10761 NLP_EVT_DEVICE_RM
);
10766 /* check if need to LS_RJT received ELS cmd */
10768 memset(&stat
, 0, sizeof(stat
));
10769 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
10770 stat
.un
.b
.lsRjtRsnCodeExp
= rjt_exp
;
10771 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, elsiocb
, ndlp
,
10773 /* Remove the reference from above for new nodes. */
10775 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
10776 NLP_EVT_DEVICE_RM
);
10779 /* Release the reference on this elsiocb, not the ndlp. */
10780 lpfc_nlp_put(elsiocb
->ndlp
);
10781 elsiocb
->ndlp
= NULL
;
10783 /* Special case. Driver received an unsolicited command that
10784 * unsupportable given the driver's current state. Reset the
10785 * link and start over.
10788 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
10791 lpfc_linkdown(phba
);
10792 lpfc_init_link(phba
, mbox
,
10793 phba
->cfg_topology
,
10794 phba
->cfg_link_speed
);
10795 mbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
10796 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
10797 mbox
->vport
= vport
;
10798 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
) ==
10800 mempool_free(mbox
, phba
->mbox_mem_pool
);
10806 if (vport
&& !test_bit(FC_UNLOADING
, &vport
->load_flag
))
10807 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
10808 "0111 Dropping received ELS cmd "
10809 "Data: x%x x%x x%x x%x\n",
10810 cmd
, status
, get_job_word4(phba
, elsiocb
), did
);
10812 phba
->fc_stat
.elsRcvDrop
++;
10816 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
10817 * @phba: pointer to lpfc hba data structure.
10818 * @pring: pointer to a SLI ring.
10819 * @elsiocb: pointer to lpfc els iocb data structure.
10821 * This routine is used to process an unsolicited event received from a SLI
10822 * (Service Level Interface) ring. The actual processing of the data buffer
10823 * associated with the unsolicited event is done by invoking the routine
10824 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
10825 * SLI ring on which the unsolicited event was received.
10828 lpfc_els_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
10829 struct lpfc_iocbq
*elsiocb
)
10831 struct lpfc_vport
*vport
= elsiocb
->vport
;
10832 u32 ulp_command
, status
, parameter
, bde_count
= 0;
10834 struct lpfc_wcqe_complete
*wcqe_cmpl
= NULL
;
10835 struct lpfc_dmabuf
*bdeBuf1
= elsiocb
->cmd_dmabuf
;
10836 struct lpfc_dmabuf
*bdeBuf2
= elsiocb
->bpl_dmabuf
;
10839 elsiocb
->cmd_dmabuf
= NULL
;
10840 elsiocb
->rsp_dmabuf
= NULL
;
10841 elsiocb
->bpl_dmabuf
= NULL
;
10843 wcqe_cmpl
= &elsiocb
->wcqe_cmpl
;
10844 ulp_command
= get_job_cmnd(phba
, elsiocb
);
10845 status
= get_job_ulpstatus(phba
, elsiocb
);
10846 parameter
= get_job_word4(phba
, elsiocb
);
10847 if (phba
->sli_rev
== LPFC_SLI_REV4
)
10848 bde_count
= wcqe_cmpl
->word3
;
10850 bde_count
= elsiocb
->iocb
.ulpBdeCount
;
10852 if (status
== IOSTAT_NEED_BUFFER
) {
10853 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
10854 } else if (status
== IOSTAT_LOCAL_REJECT
&&
10855 (parameter
& IOERR_PARAM_MASK
) ==
10856 IOERR_RCV_BUFFER_WAITING
) {
10857 phba
->fc_stat
.NoRcvBuf
++;
10858 /* Not enough posted buffers; Try posting more buffers */
10859 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
10860 lpfc_sli3_post_buffer(phba
, pring
, 0);
10864 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
10865 icmd
= &elsiocb
->iocb
;
10866 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
10867 (ulp_command
== CMD_IOCB_RCV_ELS64_CX
||
10868 ulp_command
== CMD_IOCB_RCV_SEQ64_CX
)) {
10869 if (icmd
->unsli3
.rcvsli3
.vpi
== 0xffff)
10870 vport
= phba
->pport
;
10872 vport
= lpfc_find_vport_by_vpid(phba
,
10873 icmd
->unsli3
.rcvsli3
.vpi
);
10877 /* If there are no BDEs associated
10878 * with this IOCB, there is nothing to do.
10880 if (bde_count
== 0)
10883 /* Account for SLI2 or SLI3 and later unsolicited buffering */
10884 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
10885 elsiocb
->cmd_dmabuf
= bdeBuf1
;
10886 if (bde_count
== 2)
10887 elsiocb
->bpl_dmabuf
= bdeBuf2
;
10889 icmd
= &elsiocb
->iocb
;
10890 paddr
= getPaddr(icmd
->un
.cont64
[0].addrHigh
,
10891 icmd
->un
.cont64
[0].addrLow
);
10892 elsiocb
->cmd_dmabuf
= lpfc_sli_ringpostbuf_get(phba
, pring
,
10894 if (bde_count
== 2) {
10895 paddr
= getPaddr(icmd
->un
.cont64
[1].addrHigh
,
10896 icmd
->un
.cont64
[1].addrLow
);
10897 elsiocb
->bpl_dmabuf
= lpfc_sli_ringpostbuf_get(phba
,
10903 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
10905 * The different unsolicited event handlers would tell us
10906 * if they are done with "mp" by setting cmd_dmabuf to NULL.
10908 if (elsiocb
->cmd_dmabuf
) {
10909 lpfc_in_buf_free(phba
, elsiocb
->cmd_dmabuf
);
10910 elsiocb
->cmd_dmabuf
= NULL
;
10913 if (elsiocb
->bpl_dmabuf
) {
10914 lpfc_in_buf_free(phba
, elsiocb
->bpl_dmabuf
);
10915 elsiocb
->bpl_dmabuf
= NULL
;
10921 lpfc_start_fdmi(struct lpfc_vport
*vport
)
10923 struct lpfc_nodelist
*ndlp
;
10925 /* If this is the first time, allocate an ndlp and initialize
10926 * it. Otherwise, make sure the node is enabled and then do the
10929 ndlp
= lpfc_findnode_did(vport
, FDMI_DID
);
10931 ndlp
= lpfc_nlp_init(vport
, FDMI_DID
);
10933 ndlp
->nlp_type
|= NLP_FABRIC
;
10939 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
10940 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
10944 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
10945 * @phba: pointer to lpfc hba data structure.
10946 * @vport: pointer to a virtual N_Port data structure.
10948 * This routine issues a Port Login (PLOGI) to the Name Server with
10949 * State Change Request (SCR) for a @vport. This routine will create an
10950 * ndlp for the Name Server associated to the @vport if such node does
10951 * not already exist. The PLOGI to Name Server is issued by invoking the
10952 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
10953 * (FDMI) is configured to the @vport, a FDMI node will be created and
10954 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
10957 lpfc_do_scr_ns_plogi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
10959 struct lpfc_nodelist
*ndlp
;
10962 * If lpfc_delay_discovery parameter is set and the clean address
10963 * bit is cleared and fc fabric parameters chenged, delay FC NPort
10966 if (test_bit(FC_DISC_DELAYED
, &vport
->fc_flag
)) {
10967 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
10968 "3334 Delay fc port discovery for %d secs\n",
10970 mod_timer(&vport
->delayed_disc_tmo
,
10971 jiffies
+ msecs_to_jiffies(1000 * phba
->fc_ratov
));
10975 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
10977 ndlp
= lpfc_nlp_init(vport
, NameServer_DID
);
10979 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
10980 lpfc_disc_start(vport
);
10983 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
10984 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
10985 "0251 NameServer login: no memory\n");
10990 ndlp
->nlp_type
|= NLP_FABRIC
;
10992 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
10994 if (lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0)) {
10995 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
10996 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
10997 "0252 Cannot issue NameServer login\n");
11001 if ((phba
->cfg_enable_SmartSAN
||
11002 phba
->cfg_fdmi_on
== LPFC_FDMI_SUPPORT
) &&
11003 test_bit(FC_ALLOW_FDMI
, &vport
->load_flag
))
11004 lpfc_start_fdmi(vport
);
11008 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
11009 * @phba: pointer to lpfc hba data structure.
11010 * @pmb: pointer to the driver internal queue element for mailbox command.
11012 * This routine is the completion callback function to register new vport
11013 * mailbox command. If the new vport mailbox command completes successfully,
11014 * the fabric registration login shall be performed on physical port (the
11015 * new vport created is actually a physical port, with VPI 0) or the port
11016 * login to Name Server for State Change Request (SCR) will be performed
11017 * on virtual port (real virtual port, with VPI greater than 0).
11020 lpfc_cmpl_reg_new_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
11022 struct lpfc_vport
*vport
= pmb
->vport
;
11023 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
11024 struct lpfc_nodelist
*ndlp
= pmb
->ctx_ndlp
;
11025 MAILBOX_t
*mb
= &pmb
->u
.mb
;
11028 clear_bit(FC_VPORT_NEEDS_REG_VPI
, &vport
->fc_flag
);
11030 if (mb
->mbxStatus
) {
11031 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
11032 "0915 Register VPI failed : Status: x%x"
11033 " upd bit: x%x \n", mb
->mbxStatus
,
11034 mb
->un
.varRegVpi
.upd
);
11035 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
11036 mb
->un
.varRegVpi
.upd
)
11037 goto mbox_err_exit
;
11039 switch (mb
->mbxStatus
) {
11040 case 0x11: /* unsupported feature */
11041 case 0x9603: /* max_vpi exceeded */
11042 case 0x9602: /* Link event since CLEAR_LA */
11043 /* giving up on vport registration */
11044 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
11045 clear_bit(FC_FABRIC
, &vport
->fc_flag
);
11046 clear_bit(FC_PUBLIC_LOOP
, &vport
->fc_flag
);
11047 lpfc_can_disctmo(vport
);
11049 /* If reg_vpi fail with invalid VPI status, re-init VPI */
11051 set_bit(FC_VPORT_NEEDS_REG_VPI
, &vport
->fc_flag
);
11052 lpfc_init_vpi(phba
, pmb
, vport
->vpi
);
11053 pmb
->vport
= vport
;
11054 pmb
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
11055 rc
= lpfc_sli_issue_mbox(phba
, pmb
,
11057 if (rc
== MBX_NOT_FINISHED
) {
11058 lpfc_printf_vlog(vport
, KERN_ERR
,
11060 "2732 Failed to issue INIT_VPI"
11061 " mailbox command\n");
11063 lpfc_nlp_put(ndlp
);
11068 /* Try to recover from this error */
11069 if (phba
->sli_rev
== LPFC_SLI_REV4
)
11070 lpfc_sli4_unreg_all_rpis(vport
);
11071 lpfc_mbx_unreg_vpi(vport
);
11072 set_bit(FC_VPORT_NEEDS_REG_VPI
, &vport
->fc_flag
);
11073 if (mb
->mbxStatus
== MBX_NOT_FINISHED
)
11075 if ((vport
->port_type
== LPFC_PHYSICAL_PORT
) &&
11076 !test_bit(FC_LOGO_RCVD_DID_CHNG
, &vport
->fc_flag
)) {
11077 if (phba
->sli_rev
== LPFC_SLI_REV4
)
11078 lpfc_issue_init_vfi(vport
);
11080 lpfc_initial_flogi(vport
);
11082 lpfc_initial_fdisc(vport
);
11087 spin_lock_irq(shost
->host_lock
);
11088 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
11089 spin_unlock_irq(shost
->host_lock
);
11090 if (vport
== phba
->pport
) {
11091 if (phba
->sli_rev
< LPFC_SLI_REV4
)
11092 lpfc_issue_fabric_reglogin(vport
);
11095 * If the physical port is instantiated using
11096 * FDISC, do not start vport discovery.
11098 if (vport
->port_state
!= LPFC_FDISC
)
11099 lpfc_start_fdiscs(phba
);
11100 lpfc_do_scr_ns_plogi(phba
, vport
);
11103 lpfc_do_scr_ns_plogi(phba
, vport
);
11107 /* Now, we decrement the ndlp reference count held for this
11108 * callback function
11110 lpfc_nlp_put(ndlp
);
11112 mempool_free(pmb
, phba
->mbox_mem_pool
);
11114 /* reinitialize the VMID datastructure before returning.
11115 * this is specifically for vport
11117 if (lpfc_is_vmid_enabled(phba
))
11118 lpfc_reinit_vmid(vport
);
11119 vport
->vmid_flag
= vport
->phba
->pport
->vmid_flag
;
11125 * lpfc_register_new_vport - Register a new vport with a HBA
11126 * @phba: pointer to lpfc hba data structure.
11127 * @vport: pointer to a host virtual N_Port data structure.
11128 * @ndlp: pointer to a node-list data structure.
11130 * This routine registers the @vport as a new virtual port with a HBA.
11131 * It is done through a registering vpi mailbox command.
11134 lpfc_register_new_vport(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
11135 struct lpfc_nodelist
*ndlp
)
11137 LPFC_MBOXQ_t
*mbox
;
11139 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
11141 lpfc_reg_vpi(vport
, mbox
);
11142 mbox
->vport
= vport
;
11143 mbox
->ctx_ndlp
= lpfc_nlp_get(ndlp
);
11144 if (!mbox
->ctx_ndlp
) {
11145 mempool_free(mbox
, phba
->mbox_mem_pool
);
11146 goto mbox_err_exit
;
11149 mbox
->mbox_cmpl
= lpfc_cmpl_reg_new_vport
;
11150 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
11151 == MBX_NOT_FINISHED
) {
11152 /* mailbox command not success, decrement ndlp
11153 * reference count for this command
11155 lpfc_nlp_put(ndlp
);
11156 mempool_free(mbox
, phba
->mbox_mem_pool
);
11158 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
11159 "0253 Register VPI: Can't send mbox\n");
11160 goto mbox_err_exit
;
11163 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
11164 "0254 Register VPI: no memory\n");
11165 goto mbox_err_exit
;
11170 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
11171 clear_bit(FC_VPORT_NEEDS_REG_VPI
, &vport
->fc_flag
);
11176 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
11177 * @phba: pointer to lpfc hba data structure.
11179 * This routine cancels the retry delay timers to all the vports.
11182 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba
*phba
)
11184 struct lpfc_vport
**vports
;
11185 struct lpfc_nodelist
*ndlp
;
11186 uint32_t link_state
;
11189 /* Treat this failure as linkdown for all vports */
11190 link_state
= phba
->link_state
;
11191 lpfc_linkdown(phba
);
11192 phba
->link_state
= link_state
;
11194 vports
= lpfc_create_vport_work_array(phba
);
11197 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
11198 ndlp
= lpfc_findnode_did(vports
[i
], Fabric_DID
);
11200 lpfc_cancel_retry_delay_tmo(vports
[i
], ndlp
);
11201 lpfc_els_flush_cmd(vports
[i
]);
11203 lpfc_destroy_vport_work_array(phba
, vports
);
11208 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
11209 * @phba: pointer to lpfc hba data structure.
11211 * This routine abort all pending discovery commands and
11212 * start a timer to retry FLOGI for the physical port
11216 lpfc_retry_pport_discovery(struct lpfc_hba
*phba
)
11218 struct lpfc_nodelist
*ndlp
;
11220 /* Cancel the all vports retry delay retry timers */
11221 lpfc_cancel_all_vport_retry_delay_timer(phba
);
11223 /* If fabric require FLOGI, then re-instantiate physical login */
11224 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
11228 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000));
11229 spin_lock_irq(&ndlp
->lock
);
11230 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
11231 spin_unlock_irq(&ndlp
->lock
);
11232 ndlp
->nlp_last_elscmd
= ELS_CMD_FLOGI
;
11233 phba
->pport
->port_state
= LPFC_FLOGI
;
11238 * lpfc_fabric_login_reqd - Check if FLOGI required.
11239 * @phba: pointer to lpfc hba data structure.
11240 * @cmdiocb: pointer to FDISC command iocb.
11241 * @rspiocb: pointer to FDISC response iocb.
11243 * This routine checks if a FLOGI is reguired for FDISC
11247 lpfc_fabric_login_reqd(struct lpfc_hba
*phba
,
11248 struct lpfc_iocbq
*cmdiocb
,
11249 struct lpfc_iocbq
*rspiocb
)
11251 u32 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
11252 u32 ulp_word4
= get_job_word4(phba
, rspiocb
);
11254 if (ulp_status
!= IOSTAT_FABRIC_RJT
||
11255 ulp_word4
!= RJT_LOGIN_REQUIRED
)
11262 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
11263 * @phba: pointer to lpfc hba data structure.
11264 * @cmdiocb: pointer to lpfc command iocb data structure.
11265 * @rspiocb: pointer to lpfc response iocb data structure.
11267 * This routine is the completion callback function to a Fabric Discover
11268 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
11269 * single threaded, each FDISC completion callback function will reset
11270 * the discovery timer for all vports such that the timers will not get
11271 * unnecessary timeout. The function checks the FDISC IOCB status. If error
11272 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
11273 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
11274 * assigned to the vport has been changed with the completion of the FDISC
11275 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
11276 * are unregistered from the HBA, and then the lpfc_register_new_vport()
11277 * routine is invoked to register new vport with the HBA. Otherwise, the
11278 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
11279 * Server for State Change Request (SCR).
11282 lpfc_cmpl_els_fdisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
11283 struct lpfc_iocbq
*rspiocb
)
11285 struct lpfc_vport
*vport
= cmdiocb
->vport
;
11286 struct lpfc_nodelist
*ndlp
= cmdiocb
->ndlp
;
11287 struct lpfc_nodelist
*np
;
11288 struct lpfc_nodelist
*next_np
;
11289 struct lpfc_iocbq
*piocb
;
11290 struct lpfc_dmabuf
*pcmd
= cmdiocb
->cmd_dmabuf
, *prsp
;
11291 struct serv_parm
*sp
;
11292 uint8_t fabric_param_changed
;
11293 u32 ulp_status
, ulp_word4
;
11295 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
11296 ulp_word4
= get_job_word4(phba
, rspiocb
);
11298 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
11299 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
11300 ulp_status
, ulp_word4
,
11301 vport
->fc_prevDID
);
11302 /* Since all FDISCs are being single threaded, we
11303 * must reset the discovery timer for ALL vports
11304 * waiting to send FDISC when one completes.
11306 list_for_each_entry(piocb
, &phba
->fabric_iocb_list
, list
) {
11307 lpfc_set_disctmo(piocb
->vport
);
11310 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
11311 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
11312 ulp_status
, ulp_word4
, vport
->fc_prevDID
);
11316 if (lpfc_fabric_login_reqd(phba
, cmdiocb
, rspiocb
)) {
11317 lpfc_retry_pport_discovery(phba
);
11321 /* Check for retry */
11322 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
11324 /* Warn FDISC status */
11325 lpfc_vlog_msg(vport
, KERN_WARNING
, LOG_ELS
,
11326 "0126 FDISC cmpl status: x%x/x%x)\n",
11327 ulp_status
, ulp_word4
);
11331 lpfc_check_nlp_post_devloss(vport
, ndlp
);
11333 clear_bit(FC_VPORT_CVL_RCVD
, &vport
->fc_flag
);
11334 clear_bit(FC_VPORT_LOGO_RCVD
, &vport
->fc_flag
);
11335 set_bit(FC_FABRIC
, &vport
->fc_flag
);
11336 if (vport
->phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
)
11337 set_bit(FC_PUBLIC_LOOP
, &vport
->fc_flag
);
11339 vport
->fc_myDID
= ulp_word4
& Mask_DID
;
11340 lpfc_vport_set_state(vport
, FC_VPORT_ACTIVE
);
11341 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
11344 if (!lpfc_is_els_acc_rsp(prsp
))
11347 sp
= prsp
->virt
+ sizeof(uint32_t);
11348 fabric_param_changed
= lpfc_check_clean_addr_bit(vport
, sp
);
11349 memcpy(&vport
->fabric_portname
, &sp
->portName
,
11350 sizeof(struct lpfc_name
));
11351 memcpy(&vport
->fabric_nodename
, &sp
->nodeName
,
11352 sizeof(struct lpfc_name
));
11353 if (fabric_param_changed
&&
11354 !test_bit(FC_VPORT_NEEDS_REG_VPI
, &vport
->fc_flag
)) {
11355 /* If our NportID changed, we need to ensure all
11356 * remaining NPORTs get unreg_login'ed so we can
11359 list_for_each_entry_safe(np
, next_np
,
11360 &vport
->fc_nodes
, nlp_listp
) {
11361 if ((np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
11362 !(np
->nlp_flag
& NLP_NPR_ADISC
))
11364 spin_lock_irq(&ndlp
->lock
);
11365 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
11366 spin_unlock_irq(&ndlp
->lock
);
11367 lpfc_unreg_rpi(vport
, np
);
11369 lpfc_cleanup_pending_mbox(vport
);
11371 if (phba
->sli_rev
== LPFC_SLI_REV4
)
11372 lpfc_sli4_unreg_all_rpis(vport
);
11374 lpfc_mbx_unreg_vpi(vport
);
11375 set_bit(FC_VPORT_NEEDS_REG_VPI
, &vport
->fc_flag
);
11376 if (phba
->sli_rev
== LPFC_SLI_REV4
)
11377 set_bit(FC_VPORT_NEEDS_INIT_VPI
, &vport
->fc_flag
);
11379 set_bit(FC_LOGO_RCVD_DID_CHNG
, &vport
->fc_flag
);
11380 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
11381 !test_bit(FC_VPORT_NEEDS_REG_VPI
, &vport
->fc_flag
)) {
11383 * Driver needs to re-reg VPI in order for f/w
11384 * to update the MAC address.
11386 lpfc_register_new_vport(phba
, vport
, ndlp
);
11387 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
11391 if (test_bit(FC_VPORT_NEEDS_INIT_VPI
, &vport
->fc_flag
))
11392 lpfc_issue_init_vpi(vport
);
11393 else if (test_bit(FC_VPORT_NEEDS_REG_VPI
, &vport
->fc_flag
))
11394 lpfc_register_new_vport(phba
, vport
, ndlp
);
11396 lpfc_do_scr_ns_plogi(phba
, vport
);
11398 /* The FDISC completed successfully. Move the fabric ndlp to
11399 * UNMAPPED state and register with the transport.
11401 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
11405 if (vport
->fc_vport
&&
11406 (vport
->fc_vport
->vport_state
!= FC_VPORT_NO_FABRIC_RSCS
))
11407 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
11408 /* Cancel discovery timer */
11409 lpfc_can_disctmo(vport
);
11411 lpfc_els_free_iocb(phba
, cmdiocb
);
11412 lpfc_nlp_put(ndlp
);
11416 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
11417 * @vport: pointer to a virtual N_Port data structure.
11418 * @ndlp: pointer to a node-list data structure.
11419 * @retry: number of retries to the command IOCB.
11421 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
11422 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
11423 * routine to issue the IOCB, which makes sure only one outstanding fabric
11424 * IOCB will be sent off HBA at any given time.
11426 * Note that the ndlp reference count will be incremented by 1 for holding the
11427 * ndlp and the reference to ndlp will be stored into the ndlp field of
11428 * the IOCB for the completion callback function to the FDISC ELS command.
11431 * 0 - Successfully issued fdisc iocb command
11432 * 1 - Failed to issue fdisc iocb command
11435 lpfc_issue_els_fdisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
11438 struct lpfc_hba
*phba
= vport
->phba
;
11440 union lpfc_wqe128
*wqe
= NULL
;
11441 struct lpfc_iocbq
*elsiocb
;
11442 struct serv_parm
*sp
;
11445 int did
= ndlp
->nlp_DID
;
11448 vport
->port_state
= LPFC_FDISC
;
11449 vport
->fc_myDID
= 0;
11450 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
11451 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
11454 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
11455 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
11456 "0255 Issue FDISC: no IOCB\n");
11460 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
11461 wqe
= &elsiocb
->wqe
;
11462 bf_set(els_req64_sid
, &wqe
->els_req
, 0);
11463 bf_set(els_req64_sp
, &wqe
->els_req
, 1);
11465 icmd
= &elsiocb
->iocb
;
11466 icmd
->un
.elsreq64
.myID
= 0;
11467 icmd
->un
.elsreq64
.fl
= 1;
11472 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
11473 *((uint32_t *) (pcmd
)) = ELS_CMD_FDISC
;
11474 pcmd
+= sizeof(uint32_t); /* CSP Word 1 */
11475 memcpy(pcmd
, &vport
->phba
->pport
->fc_sparam
, sizeof(struct serv_parm
));
11476 sp
= (struct serv_parm
*) pcmd
;
11477 /* Setup CSPs accordingly for Fabric */
11478 sp
->cmn
.e_d_tov
= 0;
11479 sp
->cmn
.w2
.r_a_tov
= 0;
11480 sp
->cmn
.virtual_fabric_support
= 0;
11481 sp
->cls1
.classValid
= 0;
11482 sp
->cls2
.seqDelivery
= 1;
11483 sp
->cls3
.seqDelivery
= 1;
11485 pcmd
+= sizeof(uint32_t); /* CSP Word 2 */
11486 pcmd
+= sizeof(uint32_t); /* CSP Word 3 */
11487 pcmd
+= sizeof(uint32_t); /* CSP Word 4 */
11488 pcmd
+= sizeof(uint32_t); /* Port Name */
11489 memcpy(pcmd
, &vport
->fc_portname
, 8);
11490 pcmd
+= sizeof(uint32_t); /* Node Name */
11491 pcmd
+= sizeof(uint32_t); /* Node Name */
11492 memcpy(pcmd
, &vport
->fc_nodename
, 8);
11493 sp
->cmn
.valid_vendor_ver_level
= 0;
11494 memset(sp
->un
.vendorVersion
, 0, sizeof(sp
->un
.vendorVersion
));
11495 lpfc_set_disctmo(vport
);
11497 phba
->fc_stat
.elsXmitFDISC
++;
11498 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_fdisc
;
11500 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
11501 "Issue FDISC: did:x%x",
11504 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
11505 if (!elsiocb
->ndlp
)
11508 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
11509 if (rc
== IOCB_ERROR
) {
11510 lpfc_nlp_put(ndlp
);
11514 lpfc_vport_set_state(vport
, FC_VPORT_INITIALIZING
);
11518 lpfc_els_free_iocb(phba
, elsiocb
);
11519 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
11520 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
11521 "0256 Issue FDISC: Cannot send IOCB\n");
11526 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
11527 * @phba: pointer to lpfc hba data structure.
11528 * @cmdiocb: pointer to lpfc command iocb data structure.
11529 * @rspiocb: pointer to lpfc response iocb data structure.
11531 * This routine is the completion callback function to the issuing of a LOGO
11532 * ELS command off a vport. It frees the command IOCB and then decrement the
11533 * reference count held on ndlp for this completion function, indicating that
11534 * the reference to the ndlp is no long needed. Note that the
11535 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
11536 * callback function and an additional explicit ndlp reference decrementation
11537 * will trigger the actual release of the ndlp.
11540 lpfc_cmpl_els_npiv_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
11541 struct lpfc_iocbq
*rspiocb
)
11543 struct lpfc_vport
*vport
= cmdiocb
->vport
;
11545 struct lpfc_nodelist
*ndlp
;
11546 u32 ulp_status
, ulp_word4
, did
, tmo
;
11548 ndlp
= cmdiocb
->ndlp
;
11550 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
11551 ulp_word4
= get_job_word4(phba
, rspiocb
);
11553 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
11554 did
= get_job_els_rsp64_did(phba
, cmdiocb
);
11555 tmo
= get_wqe_tmo(cmdiocb
);
11557 irsp
= &rspiocb
->iocb
;
11558 did
= get_job_els_rsp64_did(phba
, rspiocb
);
11559 tmo
= irsp
->ulpTimeout
;
11562 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
11563 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
11564 ulp_status
, ulp_word4
, did
);
11566 /* NPIV LOGO completes to NPort <nlp_DID> */
11567 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
11568 "2928 NPIV LOGO completes to NPort x%x "
11569 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
11570 ndlp
->nlp_DID
, ulp_status
, ulp_word4
,
11571 tmo
, vport
->num_disc_nodes
,
11572 kref_read(&ndlp
->kref
), ndlp
->nlp_flag
,
11573 ndlp
->fc4_xpt_flags
);
11575 if (ulp_status
== IOSTAT_SUCCESS
) {
11576 clear_bit(FC_NDISC_ACTIVE
, &vport
->fc_flag
);
11577 clear_bit(FC_FABRIC
, &vport
->fc_flag
);
11578 lpfc_can_disctmo(vport
);
11581 if (ndlp
->save_flags
& NLP_WAIT_FOR_LOGO
) {
11582 /* Wake up lpfc_vport_delete if waiting...*/
11583 if (ndlp
->logo_waitq
)
11584 wake_up(ndlp
->logo_waitq
);
11585 spin_lock_irq(&ndlp
->lock
);
11586 ndlp
->nlp_flag
&= ~(NLP_ISSUE_LOGO
| NLP_LOGO_SND
);
11587 ndlp
->save_flags
&= ~NLP_WAIT_FOR_LOGO
;
11588 spin_unlock_irq(&ndlp
->lock
);
11591 /* Safe to release resources now. */
11592 lpfc_els_free_iocb(phba
, cmdiocb
);
11593 lpfc_nlp_put(ndlp
);
11597 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
11598 * @vport: pointer to a virtual N_Port data structure.
11599 * @ndlp: pointer to a node-list data structure.
11601 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
11603 * Note that the ndlp reference count will be incremented by 1 for holding the
11604 * ndlp and the reference to ndlp will be stored into the ndlp field of
11605 * the IOCB for the completion callback function to the LOGO ELS command.
11608 * 0 - Successfully issued logo off the @vport
11609 * 1 - Failed to issue logo off the @vport
11612 lpfc_issue_els_npiv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
11615 struct lpfc_hba
*phba
= vport
->phba
;
11616 struct lpfc_iocbq
*elsiocb
;
11620 cmdsize
= 2 * sizeof(uint32_t) + sizeof(struct lpfc_name
);
11621 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, ndlp
->nlp_DID
,
11626 pcmd
= (uint8_t *)elsiocb
->cmd_dmabuf
->virt
;
11627 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
11628 pcmd
+= sizeof(uint32_t);
11630 /* Fill in LOGO payload */
11631 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
11632 pcmd
+= sizeof(uint32_t);
11633 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
11635 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
11636 "Issue LOGO npiv did:x%x flg:x%x",
11637 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
11639 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_npiv_logo
;
11640 spin_lock_irq(&ndlp
->lock
);
11641 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
11642 spin_unlock_irq(&ndlp
->lock
);
11643 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
11644 if (!elsiocb
->ndlp
) {
11645 lpfc_els_free_iocb(phba
, elsiocb
);
11649 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
11650 if (rc
== IOCB_ERROR
) {
11651 lpfc_els_free_iocb(phba
, elsiocb
);
11652 lpfc_nlp_put(ndlp
);
11658 spin_lock_irq(&ndlp
->lock
);
11659 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
11660 spin_unlock_irq(&ndlp
->lock
);
11665 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
11666 * @t: timer context used to obtain the lpfc hba.
11668 * This routine is invoked by the fabric iocb block timer after
11669 * timeout. It posts the fabric iocb block timeout event by setting the
11670 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
11671 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
11672 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
11673 * posted event WORKER_FABRIC_BLOCK_TMO.
11676 lpfc_fabric_block_timeout(struct timer_list
*t
)
11678 struct lpfc_hba
*phba
= from_timer(phba
, t
, fabric_block_timer
);
11679 unsigned long iflags
;
11680 uint32_t tmo_posted
;
11682 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
11683 tmo_posted
= phba
->pport
->work_port_events
& WORKER_FABRIC_BLOCK_TMO
;
11685 phba
->pport
->work_port_events
|= WORKER_FABRIC_BLOCK_TMO
;
11686 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
11689 lpfc_worker_wake_up(phba
);
11694 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
11695 * @phba: pointer to lpfc hba data structure.
11697 * This routine issues one fabric iocb from the driver internal list to
11698 * the HBA. It first checks whether it's ready to issue one fabric iocb to
11699 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
11700 * remove one pending fabric iocb from the driver internal list and invokes
11701 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
11704 lpfc_resume_fabric_iocbs(struct lpfc_hba
*phba
)
11706 struct lpfc_iocbq
*iocb
;
11707 unsigned long iflags
;
11712 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11713 /* Post any pending iocb to the SLI layer */
11714 if (atomic_read(&phba
->fabric_iocb_count
) == 0) {
11715 list_remove_head(&phba
->fabric_iocb_list
, iocb
, typeof(*iocb
),
11718 /* Increment fabric iocb count to hold the position */
11719 atomic_inc(&phba
->fabric_iocb_count
);
11721 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11723 iocb
->fabric_cmd_cmpl
= iocb
->cmd_cmpl
;
11724 iocb
->cmd_cmpl
= lpfc_cmpl_fabric_iocb
;
11725 iocb
->cmd_flag
|= LPFC_IO_FABRIC
;
11727 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
11728 "Fabric sched1: ste:x%x",
11729 iocb
->vport
->port_state
, 0, 0);
11731 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
11733 if (ret
== IOCB_ERROR
) {
11734 iocb
->cmd_cmpl
= iocb
->fabric_cmd_cmpl
;
11735 iocb
->fabric_cmd_cmpl
= NULL
;
11736 iocb
->cmd_flag
&= ~LPFC_IO_FABRIC
;
11737 set_job_ulpstatus(iocb
, IOSTAT_LOCAL_REJECT
);
11738 iocb
->wcqe_cmpl
.parameter
= IOERR_SLI_ABORTED
;
11739 iocb
->cmd_cmpl(phba
, iocb
, iocb
);
11741 atomic_dec(&phba
->fabric_iocb_count
);
11748 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
11749 * @phba: pointer to lpfc hba data structure.
11751 * This routine unblocks the issuing fabric iocb command. The function
11752 * will clear the fabric iocb block bit and then invoke the routine
11753 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
11754 * from the driver internal fabric iocb list.
11757 lpfc_unblock_fabric_iocbs(struct lpfc_hba
*phba
)
11759 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
11761 lpfc_resume_fabric_iocbs(phba
);
11766 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
11767 * @phba: pointer to lpfc hba data structure.
11769 * This routine blocks the issuing fabric iocb for a specified amount of
11770 * time (currently 100 ms). This is done by set the fabric iocb block bit
11771 * and set up a timeout timer for 100ms. When the block bit is set, no more
11772 * fabric iocb will be issued out of the HBA.
11775 lpfc_block_fabric_iocbs(struct lpfc_hba
*phba
)
11779 blocked
= test_and_set_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
11780 /* Start a timer to unblock fabric iocbs after 100ms */
11782 mod_timer(&phba
->fabric_block_timer
,
11783 jiffies
+ msecs_to_jiffies(100));
11789 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
11790 * @phba: pointer to lpfc hba data structure.
11791 * @cmdiocb: pointer to lpfc command iocb data structure.
11792 * @rspiocb: pointer to lpfc response iocb data structure.
11794 * This routine is the callback function that is put to the fabric iocb's
11795 * callback function pointer (iocb->cmd_cmpl). The original iocb's callback
11796 * function pointer has been stored in iocb->fabric_cmd_cmpl. This callback
11797 * function first restores and invokes the original iocb's callback function
11798 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
11799 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
11802 lpfc_cmpl_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
11803 struct lpfc_iocbq
*rspiocb
)
11805 struct ls_rjt stat
;
11806 u32 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
11807 u32 ulp_word4
= get_job_word4(phba
, rspiocb
);
11809 WARN_ON((cmdiocb
->cmd_flag
& LPFC_IO_FABRIC
) != LPFC_IO_FABRIC
);
11811 switch (ulp_status
) {
11812 case IOSTAT_NPORT_RJT
:
11813 case IOSTAT_FABRIC_RJT
:
11814 if (ulp_word4
& RJT_UNAVAIL_TEMP
)
11815 lpfc_block_fabric_iocbs(phba
);
11818 case IOSTAT_NPORT_BSY
:
11819 case IOSTAT_FABRIC_BSY
:
11820 lpfc_block_fabric_iocbs(phba
);
11823 case IOSTAT_LS_RJT
:
11824 stat
.un
.ls_rjt_error_be
=
11825 cpu_to_be32(ulp_word4
);
11826 if ((stat
.un
.b
.lsRjtRsnCode
== LSRJT_UNABLE_TPC
) ||
11827 (stat
.un
.b
.lsRjtRsnCode
== LSRJT_LOGICAL_BSY
))
11828 lpfc_block_fabric_iocbs(phba
);
11832 BUG_ON(atomic_read(&phba
->fabric_iocb_count
) == 0);
11834 cmdiocb
->cmd_cmpl
= cmdiocb
->fabric_cmd_cmpl
;
11835 cmdiocb
->fabric_cmd_cmpl
= NULL
;
11836 cmdiocb
->cmd_flag
&= ~LPFC_IO_FABRIC
;
11837 cmdiocb
->cmd_cmpl(phba
, cmdiocb
, rspiocb
);
11839 atomic_dec(&phba
->fabric_iocb_count
);
11840 if (!test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
)) {
11841 /* Post any pending iocbs to HBA */
11842 lpfc_resume_fabric_iocbs(phba
);
11847 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
11848 * @phba: pointer to lpfc hba data structure.
11849 * @iocb: pointer to lpfc command iocb data structure.
11851 * This routine is used as the top-level API for issuing a fabric iocb command
11852 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
11853 * function makes sure that only one fabric bound iocb will be outstanding at
11854 * any given time. As such, this function will first check to see whether there
11855 * is already an outstanding fabric iocb on the wire. If so, it will put the
11856 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
11857 * issued later. Otherwise, it will issue the iocb on the wire and update the
11858 * fabric iocb count it indicate that there is one fabric iocb on the wire.
11860 * Note, this implementation has a potential sending out fabric IOCBs out of
11861 * order. The problem is caused by the construction of the "ready" boolen does
11862 * not include the condition that the internal fabric IOCB list is empty. As
11863 * such, it is possible a fabric IOCB issued by this routine might be "jump"
11864 * ahead of the fabric IOCBs in the internal list.
11867 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
11868 * IOCB_ERROR - failed to issue fabric iocb
11871 lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocb
)
11873 unsigned long iflags
;
11877 BUG_ON(atomic_read(&phba
->fabric_iocb_count
) > 1);
11879 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11880 ready
= atomic_read(&phba
->fabric_iocb_count
) == 0 &&
11881 !test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
11884 /* Increment fabric iocb count to hold the position */
11885 atomic_inc(&phba
->fabric_iocb_count
);
11886 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11888 iocb
->fabric_cmd_cmpl
= iocb
->cmd_cmpl
;
11889 iocb
->cmd_cmpl
= lpfc_cmpl_fabric_iocb
;
11890 iocb
->cmd_flag
|= LPFC_IO_FABRIC
;
11892 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
11893 "Fabric sched2: ste:x%x",
11894 iocb
->vport
->port_state
, 0, 0);
11896 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
11898 if (ret
== IOCB_ERROR
) {
11899 iocb
->cmd_cmpl
= iocb
->fabric_cmd_cmpl
;
11900 iocb
->fabric_cmd_cmpl
= NULL
;
11901 iocb
->cmd_flag
&= ~LPFC_IO_FABRIC
;
11902 atomic_dec(&phba
->fabric_iocb_count
);
11905 spin_lock_irqsave(&phba
->hbalock
, iflags
);
11906 list_add_tail(&iocb
->list
, &phba
->fabric_iocb_list
);
11907 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
11908 ret
= IOCB_SUCCESS
;
11914 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
11915 * @vport: pointer to a virtual N_Port data structure.
11917 * This routine aborts all the IOCBs associated with a @vport from the
11918 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
11919 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
11920 * list, removes each IOCB associated with the @vport off the list, set the
11921 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function
11922 * associated with the IOCB.
11924 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
)
11926 LIST_HEAD(completions
);
11927 struct lpfc_hba
*phba
= vport
->phba
;
11928 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
11930 spin_lock_irq(&phba
->hbalock
);
11931 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
11934 if (piocb
->vport
!= vport
)
11937 list_move_tail(&piocb
->list
, &completions
);
11939 spin_unlock_irq(&phba
->hbalock
);
11941 /* Cancel all the IOCBs from the completions list */
11942 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
11943 IOERR_SLI_ABORTED
);
11947 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
11948 * @ndlp: pointer to a node-list data structure.
11950 * This routine aborts all the IOCBs associated with an @ndlp from the
11951 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
11952 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
11953 * list, removes each IOCB associated with the @ndlp off the list, set the
11954 * status field to IOSTAT_LOCAL_REJECT, and invokes the callback function
11955 * associated with the IOCB.
11957 void lpfc_fabric_abort_nport(struct lpfc_nodelist
*ndlp
)
11959 LIST_HEAD(completions
);
11960 struct lpfc_hba
*phba
= ndlp
->phba
;
11961 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
11962 struct lpfc_sli_ring
*pring
;
11964 pring
= lpfc_phba_elsring(phba
);
11966 if (unlikely(!pring
))
11969 spin_lock_irq(&phba
->hbalock
);
11970 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
11972 if ((lpfc_check_sli_ndlp(phba
, pring
, piocb
, ndlp
))) {
11974 list_move_tail(&piocb
->list
, &completions
);
11977 spin_unlock_irq(&phba
->hbalock
);
11979 /* Cancel all the IOCBs from the completions list */
11980 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
11981 IOERR_SLI_ABORTED
);
11985 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
11986 * @phba: pointer to lpfc hba data structure.
11988 * This routine aborts all the IOCBs currently on the driver internal
11989 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
11990 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
11991 * list, removes IOCBs off the list, set the status field to
11992 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
11995 void lpfc_fabric_abort_hba(struct lpfc_hba
*phba
)
11997 LIST_HEAD(completions
);
11999 spin_lock_irq(&phba
->hbalock
);
12000 list_splice_init(&phba
->fabric_iocb_list
, &completions
);
12001 spin_unlock_irq(&phba
->hbalock
);
12003 /* Cancel all the IOCBs from the completions list */
12004 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
12005 IOERR_SLI_ABORTED
);
12009 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
12010 * @vport: pointer to lpfc vport data structure.
12012 * This routine is invoked by the vport cleanup for deletions and the cleanup
12013 * for an ndlp on removal.
12016 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport
*vport
)
12018 struct lpfc_hba
*phba
= vport
->phba
;
12019 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
12020 struct lpfc_nodelist
*ndlp
= NULL
;
12021 unsigned long iflag
= 0;
12023 spin_lock_irqsave(&phba
->sli4_hba
.sgl_list_lock
, iflag
);
12024 list_for_each_entry_safe(sglq_entry
, sglq_next
,
12025 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
12026 if (sglq_entry
->ndlp
&& sglq_entry
->ndlp
->vport
== vport
) {
12027 lpfc_nlp_put(sglq_entry
->ndlp
);
12028 ndlp
= sglq_entry
->ndlp
;
12029 sglq_entry
->ndlp
= NULL
;
12031 /* If the xri on the abts_els_sgl list is for the Fport
12032 * node and the vport is unloading, the xri aborted wcqe
12033 * likely isn't coming back. Just release the sgl.
12035 if (test_bit(FC_UNLOADING
, &vport
->load_flag
) &&
12036 ndlp
->nlp_DID
== Fabric_DID
) {
12037 list_del(&sglq_entry
->list
);
12038 sglq_entry
->state
= SGL_FREED
;
12039 list_add_tail(&sglq_entry
->list
,
12040 &phba
->sli4_hba
.lpfc_els_sgl_list
);
12044 spin_unlock_irqrestore(&phba
->sli4_hba
.sgl_list_lock
, iflag
);
12049 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
12050 * @phba: pointer to lpfc hba data structure.
12051 * @axri: pointer to the els xri abort wcqe structure.
12053 * This routine is invoked by the worker thread to process a SLI4 slow-path
12057 lpfc_sli4_els_xri_aborted(struct lpfc_hba
*phba
,
12058 struct sli4_wcqe_xri_aborted
*axri
)
12060 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
12061 uint16_t rxid
= bf_get(lpfc_wcqe_xa_remote_xid
, axri
);
12064 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
12065 unsigned long iflag
= 0;
12066 struct lpfc_nodelist
*ndlp
;
12067 struct lpfc_sli_ring
*pring
;
12069 pring
= lpfc_phba_elsring(phba
);
12071 spin_lock_irqsave(&phba
->sli4_hba
.sgl_list_lock
, iflag
);
12072 list_for_each_entry_safe(sglq_entry
, sglq_next
,
12073 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
12074 if (sglq_entry
->sli4_xritag
== xri
) {
12075 list_del(&sglq_entry
->list
);
12076 ndlp
= sglq_entry
->ndlp
;
12077 sglq_entry
->ndlp
= NULL
;
12078 list_add_tail(&sglq_entry
->list
,
12079 &phba
->sli4_hba
.lpfc_els_sgl_list
);
12080 sglq_entry
->state
= SGL_FREED
;
12081 spin_unlock_irqrestore(&phba
->sli4_hba
.sgl_list_lock
,
12085 lpfc_set_rrq_active(phba
, ndlp
,
12086 sglq_entry
->sli4_lxritag
,
12088 lpfc_nlp_put(ndlp
);
12091 /* Check if TXQ queue needs to be serviced */
12092 if (pring
&& !list_empty(&pring
->txq
))
12093 lpfc_worker_wake_up(phba
);
12097 spin_unlock_irqrestore(&phba
->sli4_hba
.sgl_list_lock
, iflag
);
12098 lxri
= lpfc_sli4_xri_inrange(phba
, xri
);
12099 if (lxri
== NO_XRI
)
12102 spin_lock_irqsave(&phba
->hbalock
, iflag
);
12103 sglq_entry
= __lpfc_get_active_sglq(phba
, lxri
);
12104 if (!sglq_entry
|| (sglq_entry
->sli4_xritag
!= xri
)) {
12105 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12108 sglq_entry
->state
= SGL_XRI_ABORTED
;
12109 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
12113 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
12114 * @vport: pointer to virtual port object.
12115 * @ndlp: nodelist pointer for the impacted node.
12117 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
12118 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
12119 * the driver is required to send a LOGO to the remote node before it
12120 * attempts to recover its login to the remote node.
12123 lpfc_sli_abts_recover_port(struct lpfc_vport
*vport
,
12124 struct lpfc_nodelist
*ndlp
)
12126 struct Scsi_Host
*shost
;
12127 struct lpfc_hba
*phba
;
12128 unsigned long flags
= 0;
12130 shost
= lpfc_shost_from_vport(vport
);
12131 phba
= vport
->phba
;
12132 if (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
) {
12133 lpfc_printf_log(phba
, KERN_INFO
,
12134 LOG_SLI
, "3093 No rport recovery needed. "
12135 "rport in state 0x%x\n", ndlp
->nlp_state
);
12138 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
12139 "3094 Start rport recovery on shost id 0x%x "
12140 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
12142 shost
->host_no
, ndlp
->nlp_DID
,
12143 vport
->vpi
, ndlp
->nlp_rpi
, ndlp
->nlp_state
,
12146 * The rport is not responding. Remove the FCP-2 flag to prevent
12147 * an ADISC in the follow-up recovery code.
12149 spin_lock_irqsave(&ndlp
->lock
, flags
);
12150 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
12151 ndlp
->nlp_flag
|= NLP_ISSUE_LOGO
;
12152 spin_unlock_irqrestore(&ndlp
->lock
, flags
);
12153 lpfc_unreg_rpi(vport
, ndlp
);
12156 static void lpfc_init_cs_ctl_bitmap(struct lpfc_vport
*vport
)
12158 bitmap_zero(vport
->vmid_priority_range
, LPFC_VMID_MAX_PRIORITY_RANGE
);
12162 lpfc_vmid_set_cs_ctl_range(struct lpfc_vport
*vport
, u32 min
, u32 max
)
12166 if ((min
> max
) || (max
> LPFC_VMID_MAX_PRIORITY_RANGE
))
12169 for (i
= min
; i
<= max
; i
++)
12170 set_bit(i
, vport
->vmid_priority_range
);
12173 static void lpfc_vmid_put_cs_ctl(struct lpfc_vport
*vport
, u32 ctcl_vmid
)
12175 set_bit(ctcl_vmid
, vport
->vmid_priority_range
);
12178 u32
lpfc_vmid_get_cs_ctl(struct lpfc_vport
*vport
)
12182 i
= find_first_bit(vport
->vmid_priority_range
,
12183 LPFC_VMID_MAX_PRIORITY_RANGE
);
12185 if (i
== LPFC_VMID_MAX_PRIORITY_RANGE
)
12188 clear_bit(i
, vport
->vmid_priority_range
);
12192 #define MAX_PRIORITY_DESC 255
12195 lpfc_cmpl_els_qfpa(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
12196 struct lpfc_iocbq
*rspiocb
)
12198 struct lpfc_vport
*vport
= cmdiocb
->vport
;
12199 struct priority_range_desc
*desc
;
12200 struct lpfc_dmabuf
*prsp
= NULL
;
12201 struct lpfc_vmid_priority_range
*vmid_range
= NULL
;
12203 struct lpfc_dmabuf
*dmabuf
= cmdiocb
->cmd_dmabuf
;
12204 u32 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
12205 u32 ulp_word4
= get_job_word4(phba
, rspiocb
);
12206 u8
*pcmd
, max_desc
;
12208 struct lpfc_nodelist
*ndlp
= cmdiocb
->ndlp
;
12210 prsp
= list_get_first(&dmabuf
->list
, struct lpfc_dmabuf
, list
);
12215 data
= (u32
*)pcmd
;
12216 if (data
[0] == ELS_CMD_LS_RJT
) {
12217 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_SLI
,
12218 "3277 QFPA LS_RJT x%x x%x\n",
12223 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_SLI
,
12224 "6529 QFPA failed with status x%x x%x\n",
12225 ulp_status
, ulp_word4
);
12229 if (!vport
->qfpa_res
) {
12230 max_desc
= FCELSSIZE
/ sizeof(*vport
->qfpa_res
);
12231 vport
->qfpa_res
= kcalloc(max_desc
, sizeof(*vport
->qfpa_res
),
12233 if (!vport
->qfpa_res
)
12237 len
= *((u32
*)(pcmd
+ 4));
12238 len
= be32_to_cpu(len
);
12239 memcpy(vport
->qfpa_res
, pcmd
, len
+ 8);
12240 len
= len
/ LPFC_PRIORITY_RANGE_DESC_SIZE
;
12242 desc
= (struct priority_range_desc
*)(pcmd
+ 8);
12243 vmid_range
= vport
->vmid_priority
.vmid_range
;
12245 vmid_range
= kcalloc(MAX_PRIORITY_DESC
, sizeof(*vmid_range
),
12248 kfree(vport
->qfpa_res
);
12251 vport
->vmid_priority
.vmid_range
= vmid_range
;
12253 vport
->vmid_priority
.num_descriptors
= len
;
12255 for (i
= 0; i
< len
; i
++, vmid_range
++, desc
++) {
12256 lpfc_printf_vlog(vport
, KERN_DEBUG
, LOG_ELS
,
12257 "6539 vmid values low=%d, high=%d, qos=%d, "
12258 "local ve id=%d\n", desc
->lo_range
,
12259 desc
->hi_range
, desc
->qos_priority
,
12260 desc
->local_ve_id
);
12262 vmid_range
->low
= desc
->lo_range
<< 1;
12263 if (desc
->local_ve_id
== QFPA_ODD_ONLY
)
12265 if (desc
->qos_priority
)
12266 vport
->vmid_flag
|= LPFC_VMID_QOS_ENABLED
;
12267 vmid_range
->qos
= desc
->qos_priority
;
12269 vmid_range
->high
= desc
->hi_range
<< 1;
12270 if ((desc
->local_ve_id
== QFPA_ODD_ONLY
) ||
12271 (desc
->local_ve_id
== QFPA_EVEN_ODD
))
12272 vmid_range
->high
++;
12274 lpfc_init_cs_ctl_bitmap(vport
);
12275 for (i
= 0; i
< vport
->vmid_priority
.num_descriptors
; i
++) {
12276 lpfc_vmid_set_cs_ctl_range(vport
,
12277 vport
->vmid_priority
.vmid_range
[i
].low
,
12278 vport
->vmid_priority
.vmid_range
[i
].high
);
12281 vport
->vmid_flag
|= LPFC_VMID_QFPA_CMPL
;
12283 lpfc_els_free_iocb(phba
, cmdiocb
);
12284 lpfc_nlp_put(ndlp
);
12287 int lpfc_issue_els_qfpa(struct lpfc_vport
*vport
)
12289 struct lpfc_hba
*phba
= vport
->phba
;
12290 struct lpfc_nodelist
*ndlp
;
12291 struct lpfc_iocbq
*elsiocb
;
12295 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
12296 if (!ndlp
|| ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
)
12299 elsiocb
= lpfc_prep_els_iocb(vport
, 1, LPFC_QFPA_SIZE
, 2, ndlp
,
12300 ndlp
->nlp_DID
, ELS_CMD_QFPA
);
12304 pcmd
= (u8
*)elsiocb
->cmd_dmabuf
->virt
;
12306 *((u32
*)(pcmd
)) = ELS_CMD_QFPA
;
12309 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_qfpa
;
12311 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
12312 if (!elsiocb
->ndlp
) {
12313 lpfc_els_free_iocb(vport
->phba
, elsiocb
);
12317 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 2);
12318 if (ret
!= IOCB_SUCCESS
) {
12319 lpfc_els_free_iocb(phba
, elsiocb
);
12320 lpfc_nlp_put(ndlp
);
12323 vport
->vmid_flag
&= ~LPFC_VMID_QOS_ENABLED
;
12328 lpfc_vmid_uvem(struct lpfc_vport
*vport
,
12329 struct lpfc_vmid
*vmid
, bool instantiated
)
12331 struct lpfc_vem_id_desc
*vem_id_desc
;
12332 struct lpfc_nodelist
*ndlp
;
12333 struct lpfc_iocbq
*elsiocb
;
12334 struct instantiated_ve_desc
*inst_desc
;
12335 struct lpfc_vmid_context
*vmid_context
;
12340 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
12341 if (!ndlp
|| ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
)
12344 vmid_context
= kmalloc(sizeof(*vmid_context
), GFP_KERNEL
);
12347 elsiocb
= lpfc_prep_els_iocb(vport
, 1, LPFC_UVEM_SIZE
, 2,
12348 ndlp
, Fabric_DID
, ELS_CMD_UVEM
);
12352 lpfc_printf_vlog(vport
, KERN_DEBUG
, LOG_ELS
,
12353 "3427 Host vmid %s %d\n",
12354 vmid
->host_vmid
, instantiated
);
12355 vmid_context
->vmp
= vmid
;
12356 vmid_context
->nlp
= ndlp
;
12357 vmid_context
->instantiated
= instantiated
;
12358 elsiocb
->vmid_tag
.vmid_context
= vmid_context
;
12359 pcmd
= (u8
*)elsiocb
->cmd_dmabuf
->virt
;
12361 if (!memchr_inv(vport
->lpfc_vmid_host_uuid
, 0,
12362 sizeof(vport
->lpfc_vmid_host_uuid
)))
12363 memcpy(vport
->lpfc_vmid_host_uuid
, vmid
->host_vmid
,
12364 sizeof(vport
->lpfc_vmid_host_uuid
));
12366 *((u32
*)(pcmd
)) = ELS_CMD_UVEM
;
12367 len
= (u32
*)(pcmd
+ 4);
12368 *len
= cpu_to_be32(LPFC_UVEM_SIZE
- 8);
12370 vem_id_desc
= (struct lpfc_vem_id_desc
*)(pcmd
+ 8);
12371 vem_id_desc
->tag
= be32_to_cpu(VEM_ID_DESC_TAG
);
12372 vem_id_desc
->length
= be32_to_cpu(LPFC_UVEM_VEM_ID_DESC_SIZE
);
12373 memcpy(vem_id_desc
->vem_id
, vport
->lpfc_vmid_host_uuid
,
12374 sizeof(vem_id_desc
->vem_id
));
12376 inst_desc
= (struct instantiated_ve_desc
*)(pcmd
+ 32);
12377 inst_desc
->tag
= be32_to_cpu(INSTANTIATED_VE_DESC_TAG
);
12378 inst_desc
->length
= be32_to_cpu(LPFC_UVEM_VE_MAP_DESC_SIZE
);
12379 memcpy(inst_desc
->global_vem_id
, vmid
->host_vmid
,
12380 sizeof(inst_desc
->global_vem_id
));
12382 bf_set(lpfc_instantiated_nport_id
, inst_desc
, vport
->fc_myDID
);
12383 bf_set(lpfc_instantiated_local_id
, inst_desc
,
12384 vmid
->un
.cs_ctl_vmid
);
12385 if (instantiated
) {
12386 inst_desc
->tag
= be32_to_cpu(INSTANTIATED_VE_DESC_TAG
);
12388 inst_desc
->tag
= be32_to_cpu(DEINSTANTIATED_VE_DESC_TAG
);
12389 lpfc_vmid_put_cs_ctl(vport
, vmid
->un
.cs_ctl_vmid
);
12391 inst_desc
->word6
= cpu_to_be32(inst_desc
->word6
);
12393 elsiocb
->cmd_cmpl
= lpfc_cmpl_els_uvem
;
12395 elsiocb
->ndlp
= lpfc_nlp_get(ndlp
);
12396 if (!elsiocb
->ndlp
) {
12397 lpfc_els_free_iocb(vport
->phba
, elsiocb
);
12401 ret
= lpfc_sli_issue_iocb(vport
->phba
, LPFC_ELS_RING
, elsiocb
, 0);
12402 if (ret
!= IOCB_SUCCESS
) {
12403 lpfc_els_free_iocb(vport
->phba
, elsiocb
);
12404 lpfc_nlp_put(ndlp
);
12410 kfree(vmid_context
);
12415 lpfc_cmpl_els_uvem(struct lpfc_hba
*phba
, struct lpfc_iocbq
*icmdiocb
,
12416 struct lpfc_iocbq
*rspiocb
)
12418 struct lpfc_vport
*vport
= icmdiocb
->vport
;
12419 struct lpfc_dmabuf
*prsp
= NULL
;
12420 struct lpfc_vmid_context
*vmid_context
=
12421 icmdiocb
->vmid_tag
.vmid_context
;
12422 struct lpfc_nodelist
*ndlp
= icmdiocb
->ndlp
;
12425 u32 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
12426 u32 ulp_word4
= get_job_word4(phba
, rspiocb
);
12427 struct lpfc_dmabuf
*dmabuf
= icmdiocb
->cmd_dmabuf
;
12428 struct lpfc_vmid
*vmid
;
12430 vmid
= vmid_context
->vmp
;
12431 if (!ndlp
|| ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
)
12434 prsp
= list_get_first(&dmabuf
->list
, struct lpfc_dmabuf
, list
);
12438 data
= (u32
*)pcmd
;
12439 if (data
[0] == ELS_CMD_LS_RJT
) {
12440 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_SLI
,
12441 "4532 UVEM LS_RJT %x %x\n", data
[0], data
[1]);
12445 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_SLI
,
12446 "4533 UVEM error status %x: %x\n",
12447 ulp_status
, ulp_word4
);
12450 spin_lock(&phba
->hbalock
);
12451 /* Set IN USE flag */
12452 vport
->vmid_flag
|= LPFC_VMID_IN_USE
;
12453 phba
->pport
->vmid_flag
|= LPFC_VMID_IN_USE
;
12454 spin_unlock(&phba
->hbalock
);
12456 if (vmid_context
->instantiated
) {
12457 write_lock(&vport
->vmid_lock
);
12458 vmid
->flag
|= LPFC_VMID_REGISTERED
;
12459 vmid
->flag
&= ~LPFC_VMID_REQ_REGISTER
;
12460 write_unlock(&vport
->vmid_lock
);
12464 kfree(vmid_context
);
12465 lpfc_els_free_iocb(phba
, icmdiocb
);
12466 lpfc_nlp_put(ndlp
);