Merge branches 'pm-cpuidle', 'pm-core' and 'pm-sleep'
[linux-block.git] / drivers / net / ethernet / intel / ice / ice_dcb_lib.h
CommitLineData
37b6f646
AV
1/* SPDX-License-Identifier: GPL-2.0 */
2/* Copyright (c) 2019, Intel Corporation. */
3
4#ifndef _ICE_DCB_LIB_H_
5#define _ICE_DCB_LIB_H_
6
7#include "ice.h"
eff380aa 8#include "ice_base.h"
37b6f646
AV
9#include "ice_lib.h"
10
11#ifdef CONFIG_DCB
b94b013e
DE
12#define ICE_TC_MAX_BW 100 /* Default Max BW percentage */
13#define ICE_DCB_HW_CHG_RST 0 /* DCB configuration changed with reset */
14#define ICE_DCB_NO_HW_CHG 1 /* DCB configuration did not change */
15#define ICE_DCB_HW_CHG 2 /* DCB configuration changed, no reset */
b832c2f6
AV
16
17void ice_dcb_rebuild(struct ice_pf *pf);
2a87bd73 18int ice_dcb_sw_dflt_cfg(struct ice_pf *pf, bool ets_willing, bool locked);
7b9ffc76 19u8 ice_dcb_get_num_tc(struct ice_dcbx_cfg *dcbcfg);
610ed0e9
AJ
20void ice_vsi_set_dcb_tc_cfg(struct ice_vsi *vsi);
21bool ice_is_pfc_causing_hung_q(struct ice_pf *pf, unsigned int txqueue);
1ddef455 22u8 ice_dcb_get_tc(struct ice_vsi *vsi, int queue_index);
b94b013e
DE
23int
24ice_pf_dcb_cfg(struct ice_pf *pf, struct ice_dcbx_cfg *new_cfg, bool locked);
a29a912d 25int ice_dcb_bwchk(struct ice_pf *pf, struct ice_dcbx_cfg *dcbcfg);
a6a0974a 26void ice_pf_dcb_recfg(struct ice_pf *pf, bool locked);
a629cf0a 27void ice_vsi_cfg_dcb_rings(struct ice_vsi *vsi);
e223eaec 28int ice_init_pf_dcb(struct ice_pf *pf, bool locked);
4b0fdceb 29void ice_update_dcb_stats(struct ice_pf *pf);
2bb19d6e 30void
e72bba21 31ice_tx_prepare_vlan_flags_dcb(struct ice_tx_ring *tx_ring,
5f6aa50e 32 struct ice_tx_buf *first);
00cc3f1b
AV
33void
34ice_dcb_process_lldp_set_mib_change(struct ice_pf *pf,
35 struct ice_rq_event_info *event);
610ed0e9
AJ
36/**
37 * ice_find_q_in_range
38 * @low: start of queue range for a TC i.e. offset of TC
39 * @high: start of queue for next TC
40 * @tx_q: hung_queue/tx_queue
41 *
42 * finds if queue 'tx_q' falls between the two offsets of any given TC
43 */
44static inline bool ice_find_q_in_range(u16 low, u16 high, unsigned int tx_q)
45{
46 return (tx_q >= low) && (tx_q < high);
47}
48
a629cf0a 49static inline void
e72bba21 50ice_set_cgd_num(struct ice_tlan_ctx *tlan_ctx, u8 dcb_tc)
a629cf0a 51{
e72bba21 52 tlan_ctx->cgd_num = dcb_tc;
a629cf0a 53}
7d9c9b79
DE
54
55static inline bool ice_is_dcb_active(struct ice_pf *pf)
56{
57 return (test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags) ||
58 test_bit(ICE_FLAG_DCB_ENA, pf->flags));
59}
2a87bd73
DE
60
61static inline u8 ice_get_pfc_mode(struct ice_pf *pf)
62{
63 return pf->hw.port_info->qos_cfg.local_dcbx_cfg.pfc_mode;
64}
65
37b6f646 66#else
96cf4f68 67static inline void ice_dcb_rebuild(struct ice_pf *pf) { }
b832c2f6 68
0754d65b
KP
69static inline void ice_vsi_set_dcb_tc_cfg(struct ice_vsi *vsi)
70{
71 vsi->tc_cfg.ena_tc = ICE_DFLT_TRAFFIC_CLASS;
72 vsi->tc_cfg.numtc = 1;
73}
74
7b9ffc76
AV
75static inline u8 ice_dcb_get_ena_tc(struct ice_dcbx_cfg __always_unused *dcbcfg)
76{
77 return ICE_DFLT_TRAFFIC_CLASS;
78}
79
80static inline u8 ice_dcb_get_num_tc(struct ice_dcbx_cfg __always_unused *dcbcfg)
81{
82 return 1;
83}
84
1ddef455
UK
85static inline u8
86ice_dcb_get_tc(struct ice_vsi __always_unused *vsi,
87 int __always_unused queue_index)
88{
89 return 0;
90}
91
e223eaec
DE
92static inline int
93ice_init_pf_dcb(struct ice_pf *pf, bool __always_unused locked)
37b6f646 94{
4015d11e 95 dev_dbg(ice_pf_to_dev(pf), "DCB not supported\n");
37b6f646
AV
96 return -EOPNOTSUPP;
97}
7b9ffc76 98
b94b013e
DE
99static inline int
100ice_pf_dcb_cfg(struct ice_pf __always_unused *pf,
101 struct ice_dcbx_cfg __always_unused *new_cfg,
102 bool __always_unused locked)
103{
104 return -EOPNOTSUPP;
105}
106
5f6aa50e 107static inline int
e72bba21 108ice_tx_prepare_vlan_flags_dcb(struct ice_tx_ring __always_unused *tx_ring,
5f6aa50e
AV
109 struct ice_tx_buf __always_unused *first)
110{
111 return 0;
112}
113
7d9c9b79
DE
114static inline bool ice_is_dcb_active(struct ice_pf __always_unused *pf)
115{
116 return false;
117}
118
610ed0e9
AJ
119static inline bool
120ice_is_pfc_causing_hung_q(struct ice_pf __always_unused *pf,
121 unsigned int __always_unused txqueue)
122{
123 return false;
124}
125
2a87bd73
DE
126static inline u8 ice_get_pfc_mode(struct ice_pf *pf)
127{
128 return 0;
129}
130
a6a0974a 131static inline void ice_pf_dcb_recfg(struct ice_pf *pf, bool locked) { }
96cf4f68
JB
132static inline void ice_vsi_cfg_dcb_rings(struct ice_vsi *vsi) { }
133static inline void ice_update_dcb_stats(struct ice_pf *pf) { }
134static inline void
135ice_dcb_process_lldp_set_mib_change(struct ice_pf *pf, struct ice_rq_event_info *event) { }
e72bba21 136static inline void ice_set_cgd_num(struct ice_tlan_ctx *tlan_ctx, u8 dcb_tc) { }
37b6f646
AV
137#endif /* CONFIG_DCB */
138#endif /* _ICE_DCB_LIB_H_ */