137b6f646SAnirudh Venkataramanan /* SPDX-License-Identifier: GPL-2.0 */
237b6f646SAnirudh Venkataramanan /* Copyright (c) 2019, Intel Corporation. */
337b6f646SAnirudh Venkataramanan 
437b6f646SAnirudh Venkataramanan #ifndef _ICE_DCB_LIB_H_
537b6f646SAnirudh Venkataramanan #define _ICE_DCB_LIB_H_
637b6f646SAnirudh Venkataramanan 
737b6f646SAnirudh Venkataramanan #include "ice.h"
8eff380aaSAnirudh Venkataramanan #include "ice_base.h"
937b6f646SAnirudh Venkataramanan #include "ice_lib.h"
1037b6f646SAnirudh Venkataramanan 
1137b6f646SAnirudh Venkataramanan #ifdef CONFIG_DCB
12b832c2f6SAnirudh Venkataramanan #define ICE_TC_MAX_BW		100 /* Default Max BW percentage */
13b94b013eSDave Ertman #define ICE_DCB_HW_CHG_RST	0 /* DCB configuration changed with reset */
14b94b013eSDave Ertman #define ICE_DCB_NO_HW_CHG	1 /* DCB configuration did not change */
15b94b013eSDave Ertman #define ICE_DCB_HW_CHG		2 /* DCB configuration changed, no reset */
16b832c2f6SAnirudh Venkataramanan 
17b832c2f6SAnirudh Venkataramanan void ice_dcb_rebuild(struct ice_pf *pf);
182a87bd73SDave Ertman int ice_dcb_sw_dflt_cfg(struct ice_pf *pf, bool ets_willing, bool locked);
197b9ffc76SAnirudh Venkataramanan u8 ice_dcb_get_num_tc(struct ice_dcbx_cfg *dcbcfg);
20610ed0e9SAvinash JD void ice_vsi_set_dcb_tc_cfg(struct ice_vsi *vsi);
21610ed0e9SAvinash JD bool ice_is_pfc_causing_hung_q(struct ice_pf *pf, unsigned int txqueue);
221ddef455SUsha Ketineni u8 ice_dcb_get_tc(struct ice_vsi *vsi, int queue_index);
23b94b013eSDave Ertman int
24b94b013eSDave Ertman ice_pf_dcb_cfg(struct ice_pf *pf, struct ice_dcbx_cfg *new_cfg, bool locked);
25a29a912dSAvinash Dayanand int ice_dcb_bwchk(struct ice_pf *pf, struct ice_dcbx_cfg *dcbcfg);
26*a6a0974aSDave Ertman void ice_pf_dcb_recfg(struct ice_pf *pf, bool locked);
27a629cf0aSAnirudh Venkataramanan void ice_vsi_cfg_dcb_rings(struct ice_vsi *vsi);
28e223eaecSDave Ertman int ice_init_pf_dcb(struct ice_pf *pf, bool locked);
294b0fdcebSAnirudh Venkataramanan void ice_update_dcb_stats(struct ice_pf *pf);
302bb19d6eSBrett Creeley void
31e72bba21SMaciej Fijalkowski ice_tx_prepare_vlan_flags_dcb(struct ice_tx_ring *tx_ring,
325f6aa50eSAnirudh Venkataramanan 			      struct ice_tx_buf *first);
3300cc3f1bSAnirudh Venkataramanan void
3400cc3f1bSAnirudh Venkataramanan ice_dcb_process_lldp_set_mib_change(struct ice_pf *pf,
3500cc3f1bSAnirudh Venkataramanan 				    struct ice_rq_event_info *event);
36610ed0e9SAvinash JD /**
37610ed0e9SAvinash JD  * ice_find_q_in_range
38610ed0e9SAvinash JD  * @low: start of queue range for a TC i.e. offset of TC
39610ed0e9SAvinash JD  * @high: start of queue for next TC
40610ed0e9SAvinash JD  * @tx_q: hung_queue/tx_queue
41610ed0e9SAvinash JD  *
42610ed0e9SAvinash JD  * finds if queue 'tx_q' falls between the two offsets of any given TC
43610ed0e9SAvinash JD  */
ice_find_q_in_range(u16 low,u16 high,unsigned int tx_q)44610ed0e9SAvinash JD static inline bool ice_find_q_in_range(u16 low, u16 high, unsigned int tx_q)
45610ed0e9SAvinash JD {
46610ed0e9SAvinash JD 	return (tx_q >= low) && (tx_q < high);
47610ed0e9SAvinash JD }
48610ed0e9SAvinash JD 
49a629cf0aSAnirudh Venkataramanan static inline void
ice_set_cgd_num(struct ice_tlan_ctx * tlan_ctx,u8 dcb_tc)50e72bba21SMaciej Fijalkowski ice_set_cgd_num(struct ice_tlan_ctx *tlan_ctx, u8 dcb_tc)
51a629cf0aSAnirudh Venkataramanan {
52e72bba21SMaciej Fijalkowski 	tlan_ctx->cgd_num = dcb_tc;
53a629cf0aSAnirudh Venkataramanan }
547d9c9b79SDave Ertman 
ice_is_dcb_active(struct ice_pf * pf)557d9c9b79SDave Ertman static inline bool ice_is_dcb_active(struct ice_pf *pf)
567d9c9b79SDave Ertman {
577d9c9b79SDave Ertman 	return (test_bit(ICE_FLAG_FW_LLDP_AGENT, pf->flags) ||
587d9c9b79SDave Ertman 		test_bit(ICE_FLAG_DCB_ENA, pf->flags));
597d9c9b79SDave Ertman }
602a87bd73SDave Ertman 
ice_get_pfc_mode(struct ice_pf * pf)612a87bd73SDave Ertman static inline u8 ice_get_pfc_mode(struct ice_pf *pf)
622a87bd73SDave Ertman {
632a87bd73SDave Ertman 	return pf->hw.port_info->qos_cfg.local_dcbx_cfg.pfc_mode;
642a87bd73SDave Ertman }
652a87bd73SDave Ertman 
6637b6f646SAnirudh Venkataramanan #else
ice_dcb_rebuild(struct ice_pf * pf)6796cf4f68SJesse Brandeburg static inline void ice_dcb_rebuild(struct ice_pf *pf) { }
68b832c2f6SAnirudh Venkataramanan 
ice_vsi_set_dcb_tc_cfg(struct ice_vsi * vsi)690754d65bSKiran Patil static inline void ice_vsi_set_dcb_tc_cfg(struct ice_vsi *vsi)
700754d65bSKiran Patil {
710754d65bSKiran Patil 	vsi->tc_cfg.ena_tc = ICE_DFLT_TRAFFIC_CLASS;
720754d65bSKiran Patil 	vsi->tc_cfg.numtc = 1;
730754d65bSKiran Patil }
740754d65bSKiran Patil 
ice_dcb_get_ena_tc(struct ice_dcbx_cfg __always_unused * dcbcfg)757b9ffc76SAnirudh Venkataramanan static inline u8 ice_dcb_get_ena_tc(struct ice_dcbx_cfg __always_unused *dcbcfg)
767b9ffc76SAnirudh Venkataramanan {
777b9ffc76SAnirudh Venkataramanan 	return ICE_DFLT_TRAFFIC_CLASS;
787b9ffc76SAnirudh Venkataramanan }
797b9ffc76SAnirudh Venkataramanan 
ice_dcb_get_num_tc(struct ice_dcbx_cfg __always_unused * dcbcfg)807b9ffc76SAnirudh Venkataramanan static inline u8 ice_dcb_get_num_tc(struct ice_dcbx_cfg __always_unused *dcbcfg)
817b9ffc76SAnirudh Venkataramanan {
827b9ffc76SAnirudh Venkataramanan 	return 1;
837b9ffc76SAnirudh Venkataramanan }
847b9ffc76SAnirudh Venkataramanan 
851ddef455SUsha Ketineni static inline u8
ice_dcb_get_tc(struct ice_vsi __always_unused * vsi,int __always_unused queue_index)861ddef455SUsha Ketineni ice_dcb_get_tc(struct ice_vsi __always_unused *vsi,
871ddef455SUsha Ketineni 	       int __always_unused queue_index)
881ddef455SUsha Ketineni {
891ddef455SUsha Ketineni 	return 0;
901ddef455SUsha Ketineni }
911ddef455SUsha Ketineni 
92e223eaecSDave Ertman static inline int
ice_init_pf_dcb(struct ice_pf * pf,bool __always_unused locked)93e223eaecSDave Ertman ice_init_pf_dcb(struct ice_pf *pf, bool __always_unused locked)
9437b6f646SAnirudh Venkataramanan {
954015d11eSBrett Creeley 	dev_dbg(ice_pf_to_dev(pf), "DCB not supported\n");
9637b6f646SAnirudh Venkataramanan 	return -EOPNOTSUPP;
9737b6f646SAnirudh Venkataramanan }
987b9ffc76SAnirudh Venkataramanan 
995f6aa50eSAnirudh Venkataramanan static inline int
ice_pf_dcb_cfg(struct ice_pf __always_unused * pf,struct ice_dcbx_cfg __always_unused * new_cfg,bool __always_unused locked)100b94b013eSDave Ertman ice_pf_dcb_cfg(struct ice_pf __always_unused *pf,
101b94b013eSDave Ertman 	       struct ice_dcbx_cfg __always_unused *new_cfg,
102b94b013eSDave Ertman 	       bool __always_unused locked)
103b94b013eSDave Ertman {
104b94b013eSDave Ertman 	return -EOPNOTSUPP;
105b94b013eSDave Ertman }
106b94b013eSDave Ertman 
107b94b013eSDave Ertman static inline int
ice_tx_prepare_vlan_flags_dcb(struct ice_tx_ring __always_unused * tx_ring,struct ice_tx_buf __always_unused * first)108e72bba21SMaciej Fijalkowski ice_tx_prepare_vlan_flags_dcb(struct ice_tx_ring __always_unused *tx_ring,
1095f6aa50eSAnirudh Venkataramanan 			      struct ice_tx_buf __always_unused *first)
1105f6aa50eSAnirudh Venkataramanan {
1115f6aa50eSAnirudh Venkataramanan 	return 0;
1125f6aa50eSAnirudh Venkataramanan }
1135f6aa50eSAnirudh Venkataramanan 
ice_is_dcb_active(struct ice_pf __always_unused * pf)1147d9c9b79SDave Ertman static inline bool ice_is_dcb_active(struct ice_pf __always_unused *pf)
1157d9c9b79SDave Ertman {
1167d9c9b79SDave Ertman 	return false;
1177d9c9b79SDave Ertman }
1187d9c9b79SDave Ertman 
119610ed0e9SAvinash JD static inline bool
ice_is_pfc_causing_hung_q(struct ice_pf __always_unused * pf,unsigned int __always_unused txqueue)120610ed0e9SAvinash JD ice_is_pfc_causing_hung_q(struct ice_pf __always_unused *pf,
121610ed0e9SAvinash JD 			  unsigned int __always_unused txqueue)
122610ed0e9SAvinash JD {
123610ed0e9SAvinash JD 	return false;
124610ed0e9SAvinash JD }
125610ed0e9SAvinash JD 
ice_get_pfc_mode(struct ice_pf * pf)1262a87bd73SDave Ertman static inline u8 ice_get_pfc_mode(struct ice_pf *pf)
1272a87bd73SDave Ertman {
1282a87bd73SDave Ertman 	return 0;
1292a87bd73SDave Ertman }
1302a87bd73SDave Ertman 
ice_pf_dcb_recfg(struct ice_pf * pf,bool locked)131*a6a0974aSDave Ertman static inline void ice_pf_dcb_recfg(struct ice_pf *pf, bool locked) { }
ice_vsi_cfg_dcb_rings(struct ice_vsi * vsi)13296cf4f68SJesse Brandeburg static inline void ice_vsi_cfg_dcb_rings(struct ice_vsi *vsi) { }
ice_update_dcb_stats(struct ice_pf * pf)13396cf4f68SJesse Brandeburg static inline void ice_update_dcb_stats(struct ice_pf *pf) { }
13496cf4f68SJesse Brandeburg static inline void
ice_dcb_process_lldp_set_mib_change(struct ice_pf * pf,struct ice_rq_event_info * event)13596cf4f68SJesse Brandeburg ice_dcb_process_lldp_set_mib_change(struct ice_pf *pf, struct ice_rq_event_info *event) { }
ice_set_cgd_num(struct ice_tlan_ctx * tlan_ctx,u8 dcb_tc)136e72bba21SMaciej Fijalkowski static inline void ice_set_cgd_num(struct ice_tlan_ctx *tlan_ctx, u8 dcb_tc) { }
13737b6f646SAnirudh Venkataramanan #endif /* CONFIG_DCB */
13837b6f646SAnirudh Venkataramanan #endif /* _ICE_DCB_LIB_H_ */
139