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"
8 #include "ice_base.h"
9 #include "ice_lib.h"
10 
11 #ifdef CONFIG_DCB
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 */
16 
17 void ice_dcb_rebuild(struct ice_pf *pf);
18 int ice_dcb_sw_dflt_cfg(struct ice_pf *pf, bool ets_willing, bool locked);
19 u8 ice_dcb_get_ena_tc(struct ice_dcbx_cfg *dcbcfg);
20 u8 ice_dcb_get_num_tc(struct ice_dcbx_cfg *dcbcfg);
21 void ice_vsi_set_dcb_tc_cfg(struct ice_vsi *vsi);
22 bool ice_is_pfc_causing_hung_q(struct ice_pf *pf, unsigned int txqueue);
23 u8 ice_dcb_get_tc(struct ice_vsi *vsi, int queue_index);
24 int
25 ice_pf_dcb_cfg(struct ice_pf *pf, struct ice_dcbx_cfg *new_cfg, bool locked);
26 int ice_dcb_bwchk(struct ice_pf *pf, struct ice_dcbx_cfg *dcbcfg);
27 void ice_pf_dcb_recfg(struct ice_pf *pf);
28 void ice_vsi_cfg_dcb_rings(struct ice_vsi *vsi);
29 int ice_init_pf_dcb(struct ice_pf *pf, bool locked);
30 void ice_update_dcb_stats(struct ice_pf *pf);
31 void
32 ice_tx_prepare_vlan_flags_dcb(struct ice_ring *tx_ring,
33 			      struct ice_tx_buf *first);
34 void
35 ice_dcb_process_lldp_set_mib_change(struct ice_pf *pf,
36 				    struct ice_rq_event_info *event);
37 void ice_vsi_cfg_netdev_tc(struct ice_vsi *vsi, u8 ena_tc);
38 
39 /**
40  * ice_find_q_in_range
41  * @low: start of queue range for a TC i.e. offset of TC
42  * @high: start of queue for next TC
43  * @tx_q: hung_queue/tx_queue
44  *
45  * finds if queue 'tx_q' falls between the two offsets of any given TC
46  */
47 static inline bool ice_find_q_in_range(u16 low, u16 high, unsigned int tx_q)
48 {
49 	return (tx_q >= low) && (tx_q < high);
50 }
51 
52 static inline void
53 ice_set_cgd_num(struct ice_tlan_ctx *tlan_ctx, struct ice_ring *ring)
54 {
55 	tlan_ctx->cgd_num = ring->dcb_tc;
56 }
57 
58 static inline bool ice_is_dcb_active(struct ice_pf *pf)
59 {
60 	return (test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags) ||
61 		test_bit(ICE_FLAG_DCB_ENA, pf->flags));
62 }
63 
64 static inline u8 ice_get_pfc_mode(struct ice_pf *pf)
65 {
66 	return pf->hw.port_info->qos_cfg.local_dcbx_cfg.pfc_mode;
67 }
68 
69 #else
70 static inline void ice_dcb_rebuild(struct ice_pf *pf) { }
71 
72 static inline u8 ice_dcb_get_ena_tc(struct ice_dcbx_cfg __always_unused *dcbcfg)
73 {
74 	return ICE_DFLT_TRAFFIC_CLASS;
75 }
76 
77 static inline u8 ice_dcb_get_num_tc(struct ice_dcbx_cfg __always_unused *dcbcfg)
78 {
79 	return 1;
80 }
81 
82 static inline u8
83 ice_dcb_get_tc(struct ice_vsi __always_unused *vsi,
84 	       int __always_unused queue_index)
85 {
86 	return 0;
87 }
88 
89 static inline int
90 ice_init_pf_dcb(struct ice_pf *pf, bool __always_unused locked)
91 {
92 	dev_dbg(ice_pf_to_dev(pf), "DCB not supported\n");
93 	return -EOPNOTSUPP;
94 }
95 
96 static inline int
97 ice_pf_dcb_cfg(struct ice_pf __always_unused *pf,
98 	       struct ice_dcbx_cfg __always_unused *new_cfg,
99 	       bool __always_unused locked)
100 {
101 	return -EOPNOTSUPP;
102 }
103 
104 static inline int
105 ice_tx_prepare_vlan_flags_dcb(struct ice_ring __always_unused *tx_ring,
106 			      struct ice_tx_buf __always_unused *first)
107 {
108 	return 0;
109 }
110 
111 static inline bool ice_is_dcb_active(struct ice_pf __always_unused *pf)
112 {
113 	return false;
114 }
115 
116 static inline bool
117 ice_is_pfc_causing_hung_q(struct ice_pf __always_unused *pf,
118 			  unsigned int __always_unused txqueue)
119 {
120 	return false;
121 }
122 
123 static inline u8 ice_get_pfc_mode(struct ice_pf *pf)
124 {
125 	return 0;
126 }
127 
128 static inline void ice_pf_dcb_recfg(struct ice_pf *pf) { }
129 static inline void ice_vsi_cfg_dcb_rings(struct ice_vsi *vsi) { }
130 static inline void ice_update_dcb_stats(struct ice_pf *pf) { }
131 static inline void
132 ice_dcb_process_lldp_set_mib_change(struct ice_pf *pf, struct ice_rq_event_info *event) { }
133 static inline void ice_vsi_cfg_netdev_tc(struct ice_vsi *vsi, u8 ena_tc) { }
134 static inline void ice_set_cgd_num(struct ice_tlan_ctx *tlan_ctx, struct ice_ring *ring) { }
135 #endif /* CONFIG_DCB */
136 #endif /* _ICE_DCB_LIB_H_ */
137