xref: /OK3568_Linux_fs/kernel/drivers/net/ethernet/intel/ixgbe/ixgbe_dcb.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /* Copyright(c) 1999 - 2018 Intel Corporation. */
3*4882a593Smuzhiyun 
4*4882a593Smuzhiyun #include "ixgbe.h"
5*4882a593Smuzhiyun #include "ixgbe_type.h"
6*4882a593Smuzhiyun #include "ixgbe_dcb.h"
7*4882a593Smuzhiyun #include "ixgbe_dcb_82598.h"
8*4882a593Smuzhiyun #include "ixgbe_dcb_82599.h"
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun /**
11*4882a593Smuzhiyun  * ixgbe_ieee_credits - This calculates the ieee traffic class
12*4882a593Smuzhiyun  * credits from the configured bandwidth percentages. Credits
13*4882a593Smuzhiyun  * are the smallest unit programmable into the underlying
14*4882a593Smuzhiyun  * hardware. The IEEE 802.1Qaz specification do not use bandwidth
15*4882a593Smuzhiyun  * groups so this is much simplified from the CEE case.
16*4882a593Smuzhiyun  * @bw: bandwidth index by traffic class
17*4882a593Smuzhiyun  * @refill: refill credits index by traffic class
18*4882a593Smuzhiyun  * @max: max credits by traffic class
19*4882a593Smuzhiyun  * @max_frame: maximum frame size
20*4882a593Smuzhiyun  */
ixgbe_ieee_credits(__u8 * bw,__u16 * refill,__u16 * max,int max_frame)21*4882a593Smuzhiyun static s32 ixgbe_ieee_credits(__u8 *bw, __u16 *refill,
22*4882a593Smuzhiyun 			      __u16 *max, int max_frame)
23*4882a593Smuzhiyun {
24*4882a593Smuzhiyun 	int min_percent = 100;
25*4882a593Smuzhiyun 	int min_credit, multiplier;
26*4882a593Smuzhiyun 	int i;
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun 	min_credit = ((max_frame / 2) + DCB_CREDIT_QUANTUM - 1) /
29*4882a593Smuzhiyun 			DCB_CREDIT_QUANTUM;
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun 	for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
32*4882a593Smuzhiyun 		if (bw[i] < min_percent && bw[i])
33*4882a593Smuzhiyun 			min_percent = bw[i];
34*4882a593Smuzhiyun 	}
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun 	multiplier = (min_credit / min_percent) + 1;
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun 	/* Find out the hw credits for each TC */
39*4882a593Smuzhiyun 	for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
40*4882a593Smuzhiyun 		int val = min(bw[i] * multiplier, MAX_CREDIT_REFILL);
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun 		if (val < min_credit)
43*4882a593Smuzhiyun 			val = min_credit;
44*4882a593Smuzhiyun 		refill[i] = val;
45*4882a593Smuzhiyun 
46*4882a593Smuzhiyun 		max[i] = bw[i] ? (bw[i] * MAX_CREDIT)/100 : min_credit;
47*4882a593Smuzhiyun 	}
48*4882a593Smuzhiyun 	return 0;
49*4882a593Smuzhiyun }
50*4882a593Smuzhiyun 
51*4882a593Smuzhiyun /**
52*4882a593Smuzhiyun  * ixgbe_dcb_calculate_tc_credits - Calculates traffic class credits
53*4882a593Smuzhiyun  * @hw: pointer to hardware structure
54*4882a593Smuzhiyun  * @dcb_config: Struct containing DCB settings
55*4882a593Smuzhiyun  * @max_frame: Maximum frame size
56*4882a593Smuzhiyun  * @direction: Configuring either Tx or Rx
57*4882a593Smuzhiyun  *
58*4882a593Smuzhiyun  * This function calculates the credits allocated to each traffic class.
59*4882a593Smuzhiyun  * It should be called only after the rules are checked by
60*4882a593Smuzhiyun  * ixgbe_dcb_check_config().
61*4882a593Smuzhiyun  */
ixgbe_dcb_calculate_tc_credits(struct ixgbe_hw * hw,struct ixgbe_dcb_config * dcb_config,int max_frame,u8 direction)62*4882a593Smuzhiyun s32 ixgbe_dcb_calculate_tc_credits(struct ixgbe_hw *hw,
63*4882a593Smuzhiyun 				   struct ixgbe_dcb_config *dcb_config,
64*4882a593Smuzhiyun 				   int max_frame, u8 direction)
65*4882a593Smuzhiyun {
66*4882a593Smuzhiyun 	struct tc_bw_alloc *p;
67*4882a593Smuzhiyun 	int min_credit;
68*4882a593Smuzhiyun 	int min_multiplier;
69*4882a593Smuzhiyun 	int min_percent = 100;
70*4882a593Smuzhiyun 	/* Initialization values default for Tx settings */
71*4882a593Smuzhiyun 	u32 credit_refill       = 0;
72*4882a593Smuzhiyun 	u32 credit_max          = 0;
73*4882a593Smuzhiyun 	u16 link_percentage     = 0;
74*4882a593Smuzhiyun 	u8  bw_percent          = 0;
75*4882a593Smuzhiyun 	u8  i;
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 	if (!dcb_config)
78*4882a593Smuzhiyun 		return DCB_ERR_CONFIG;
79*4882a593Smuzhiyun 
80*4882a593Smuzhiyun 	min_credit = ((max_frame / 2) + DCB_CREDIT_QUANTUM - 1) /
81*4882a593Smuzhiyun 			DCB_CREDIT_QUANTUM;
82*4882a593Smuzhiyun 
83*4882a593Smuzhiyun 	/* Find smallest link percentage */
84*4882a593Smuzhiyun 	for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
85*4882a593Smuzhiyun 		p = &dcb_config->tc_config[i].path[direction];
86*4882a593Smuzhiyun 		bw_percent = dcb_config->bw_percentage[direction][p->bwg_id];
87*4882a593Smuzhiyun 		link_percentage = p->bwg_percent;
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun 		link_percentage = (link_percentage * bw_percent) / 100;
90*4882a593Smuzhiyun 
91*4882a593Smuzhiyun 		if (link_percentage && link_percentage < min_percent)
92*4882a593Smuzhiyun 			min_percent = link_percentage;
93*4882a593Smuzhiyun 	}
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun 	/*
96*4882a593Smuzhiyun 	 * The ratio between traffic classes will control the bandwidth
97*4882a593Smuzhiyun 	 * percentages seen on the wire. To calculate this ratio we use
98*4882a593Smuzhiyun 	 * a multiplier. It is required that the refill credits must be
99*4882a593Smuzhiyun 	 * larger than the max frame size so here we find the smallest
100*4882a593Smuzhiyun 	 * multiplier that will allow all bandwidth percentages to be
101*4882a593Smuzhiyun 	 * greater than the max frame size.
102*4882a593Smuzhiyun 	 */
103*4882a593Smuzhiyun 	min_multiplier = (min_credit / min_percent) + 1;
104*4882a593Smuzhiyun 
105*4882a593Smuzhiyun 	/* Find out the link percentage for each TC first */
106*4882a593Smuzhiyun 	for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
107*4882a593Smuzhiyun 		p = &dcb_config->tc_config[i].path[direction];
108*4882a593Smuzhiyun 		bw_percent = dcb_config->bw_percentage[direction][p->bwg_id];
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun 		link_percentage = p->bwg_percent;
111*4882a593Smuzhiyun 		/* Must be careful of integer division for very small nums */
112*4882a593Smuzhiyun 		link_percentage = (link_percentage * bw_percent) / 100;
113*4882a593Smuzhiyun 		if (p->bwg_percent > 0 && link_percentage == 0)
114*4882a593Smuzhiyun 			link_percentage = 1;
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun 		/* Save link_percentage for reference */
117*4882a593Smuzhiyun 		p->link_percent = (u8)link_percentage;
118*4882a593Smuzhiyun 
119*4882a593Smuzhiyun 		/* Calculate credit refill ratio using multiplier */
120*4882a593Smuzhiyun 		credit_refill = min(link_percentage * min_multiplier,
121*4882a593Smuzhiyun 				    MAX_CREDIT_REFILL);
122*4882a593Smuzhiyun 
123*4882a593Smuzhiyun 		/* Refill at least minimum credit */
124*4882a593Smuzhiyun 		if (credit_refill < min_credit)
125*4882a593Smuzhiyun 			credit_refill = min_credit;
126*4882a593Smuzhiyun 
127*4882a593Smuzhiyun 		p->data_credits_refill = (u16)credit_refill;
128*4882a593Smuzhiyun 
129*4882a593Smuzhiyun 		/* Calculate maximum credit for the TC */
130*4882a593Smuzhiyun 		credit_max = (link_percentage * MAX_CREDIT) / 100;
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun 		/*
133*4882a593Smuzhiyun 		 * Adjustment based on rule checking, if the percentage
134*4882a593Smuzhiyun 		 * of a TC is too small, the maximum credit may not be
135*4882a593Smuzhiyun 		 * enough to send out a jumbo frame in data plane arbitration.
136*4882a593Smuzhiyun 		 */
137*4882a593Smuzhiyun 		if (credit_max < min_credit)
138*4882a593Smuzhiyun 			credit_max = min_credit;
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun 		if (direction == DCB_TX_CONFIG) {
141*4882a593Smuzhiyun 			/*
142*4882a593Smuzhiyun 			 * Adjustment based on rule checking, if the
143*4882a593Smuzhiyun 			 * percentage of a TC is too small, the maximum
144*4882a593Smuzhiyun 			 * credit may not be enough to send out a TSO
145*4882a593Smuzhiyun 			 * packet in descriptor plane arbitration.
146*4882a593Smuzhiyun 			 */
147*4882a593Smuzhiyun 			if ((hw->mac.type == ixgbe_mac_82598EB) &&
148*4882a593Smuzhiyun 			    credit_max &&
149*4882a593Smuzhiyun 			    (credit_max < MINIMUM_CREDIT_FOR_TSO))
150*4882a593Smuzhiyun 				credit_max = MINIMUM_CREDIT_FOR_TSO;
151*4882a593Smuzhiyun 
152*4882a593Smuzhiyun 			dcb_config->tc_config[i].desc_credits_max =
153*4882a593Smuzhiyun 				(u16)credit_max;
154*4882a593Smuzhiyun 		}
155*4882a593Smuzhiyun 
156*4882a593Smuzhiyun 		p->data_credits_max = (u16)credit_max;
157*4882a593Smuzhiyun 	}
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	return 0;
160*4882a593Smuzhiyun }
161*4882a593Smuzhiyun 
ixgbe_dcb_unpack_pfc(struct ixgbe_dcb_config * cfg,u8 * pfc_en)162*4882a593Smuzhiyun void ixgbe_dcb_unpack_pfc(struct ixgbe_dcb_config *cfg, u8 *pfc_en)
163*4882a593Smuzhiyun {
164*4882a593Smuzhiyun 	struct tc_configuration *tc_config = &cfg->tc_config[0];
165*4882a593Smuzhiyun 	int tc;
166*4882a593Smuzhiyun 
167*4882a593Smuzhiyun 	for (*pfc_en = 0, tc = 0; tc < MAX_TRAFFIC_CLASS; tc++) {
168*4882a593Smuzhiyun 		if (tc_config[tc].dcb_pfc != pfc_disabled)
169*4882a593Smuzhiyun 			*pfc_en |= BIT(tc);
170*4882a593Smuzhiyun 	}
171*4882a593Smuzhiyun }
172*4882a593Smuzhiyun 
ixgbe_dcb_unpack_refill(struct ixgbe_dcb_config * cfg,int direction,u16 * refill)173*4882a593Smuzhiyun void ixgbe_dcb_unpack_refill(struct ixgbe_dcb_config *cfg, int direction,
174*4882a593Smuzhiyun 			     u16 *refill)
175*4882a593Smuzhiyun {
176*4882a593Smuzhiyun 	struct tc_configuration *tc_config = &cfg->tc_config[0];
177*4882a593Smuzhiyun 	int tc;
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun 	for (tc = 0; tc < MAX_TRAFFIC_CLASS; tc++)
180*4882a593Smuzhiyun 		refill[tc] = tc_config[tc].path[direction].data_credits_refill;
181*4882a593Smuzhiyun }
182*4882a593Smuzhiyun 
ixgbe_dcb_unpack_max(struct ixgbe_dcb_config * cfg,u16 * max)183*4882a593Smuzhiyun void ixgbe_dcb_unpack_max(struct ixgbe_dcb_config *cfg, u16 *max)
184*4882a593Smuzhiyun {
185*4882a593Smuzhiyun 	struct tc_configuration *tc_config = &cfg->tc_config[0];
186*4882a593Smuzhiyun 	int tc;
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun 	for (tc = 0; tc < MAX_TRAFFIC_CLASS; tc++)
189*4882a593Smuzhiyun 		max[tc] = tc_config[tc].desc_credits_max;
190*4882a593Smuzhiyun }
191*4882a593Smuzhiyun 
ixgbe_dcb_unpack_bwgid(struct ixgbe_dcb_config * cfg,int direction,u8 * bwgid)192*4882a593Smuzhiyun void ixgbe_dcb_unpack_bwgid(struct ixgbe_dcb_config *cfg, int direction,
193*4882a593Smuzhiyun 			    u8 *bwgid)
194*4882a593Smuzhiyun {
195*4882a593Smuzhiyun 	struct tc_configuration *tc_config = &cfg->tc_config[0];
196*4882a593Smuzhiyun 	int tc;
197*4882a593Smuzhiyun 
198*4882a593Smuzhiyun 	for (tc = 0; tc < MAX_TRAFFIC_CLASS; tc++)
199*4882a593Smuzhiyun 		bwgid[tc] = tc_config[tc].path[direction].bwg_id;
200*4882a593Smuzhiyun }
201*4882a593Smuzhiyun 
ixgbe_dcb_unpack_prio(struct ixgbe_dcb_config * cfg,int direction,u8 * ptype)202*4882a593Smuzhiyun void ixgbe_dcb_unpack_prio(struct ixgbe_dcb_config *cfg, int direction,
203*4882a593Smuzhiyun 			    u8 *ptype)
204*4882a593Smuzhiyun {
205*4882a593Smuzhiyun 	struct tc_configuration *tc_config = &cfg->tc_config[0];
206*4882a593Smuzhiyun 	int tc;
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun 	for (tc = 0; tc < MAX_TRAFFIC_CLASS; tc++)
209*4882a593Smuzhiyun 		ptype[tc] = tc_config[tc].path[direction].prio_type;
210*4882a593Smuzhiyun }
211*4882a593Smuzhiyun 
ixgbe_dcb_get_tc_from_up(struct ixgbe_dcb_config * cfg,int direction,u8 up)212*4882a593Smuzhiyun u8 ixgbe_dcb_get_tc_from_up(struct ixgbe_dcb_config *cfg, int direction, u8 up)
213*4882a593Smuzhiyun {
214*4882a593Smuzhiyun 	struct tc_configuration *tc_config = &cfg->tc_config[0];
215*4882a593Smuzhiyun 	u8 prio_mask = BIT(up);
216*4882a593Smuzhiyun 	u8 tc = cfg->num_tcs.pg_tcs;
217*4882a593Smuzhiyun 
218*4882a593Smuzhiyun 	/* If tc is 0 then DCB is likely not enabled or supported */
219*4882a593Smuzhiyun 	if (!tc)
220*4882a593Smuzhiyun 		return 0;
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun 	/*
223*4882a593Smuzhiyun 	 * Test from maximum TC to 1 and report the first match we find.  If
224*4882a593Smuzhiyun 	 * we find no match we can assume that the TC is 0 since the TC must
225*4882a593Smuzhiyun 	 * be set for all user priorities
226*4882a593Smuzhiyun 	 */
227*4882a593Smuzhiyun 	for (tc--; tc; tc--) {
228*4882a593Smuzhiyun 		if (prio_mask & tc_config[tc].path[direction].up_to_tc_bitmap)
229*4882a593Smuzhiyun 			break;
230*4882a593Smuzhiyun 	}
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun 	return tc;
233*4882a593Smuzhiyun }
234*4882a593Smuzhiyun 
ixgbe_dcb_unpack_map(struct ixgbe_dcb_config * cfg,int direction,u8 * map)235*4882a593Smuzhiyun void ixgbe_dcb_unpack_map(struct ixgbe_dcb_config *cfg, int direction, u8 *map)
236*4882a593Smuzhiyun {
237*4882a593Smuzhiyun 	u8 up;
238*4882a593Smuzhiyun 
239*4882a593Smuzhiyun 	for (up = 0; up < MAX_USER_PRIORITY; up++)
240*4882a593Smuzhiyun 		map[up] = ixgbe_dcb_get_tc_from_up(cfg, direction, up);
241*4882a593Smuzhiyun }
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun /**
244*4882a593Smuzhiyun  * ixgbe_dcb_hw_config - Config and enable DCB
245*4882a593Smuzhiyun  * @hw: pointer to hardware structure
246*4882a593Smuzhiyun  * @dcb_config: pointer to ixgbe_dcb_config structure
247*4882a593Smuzhiyun  *
248*4882a593Smuzhiyun  * Configure dcb settings and enable dcb mode.
249*4882a593Smuzhiyun  */
ixgbe_dcb_hw_config(struct ixgbe_hw * hw,struct ixgbe_dcb_config * dcb_config)250*4882a593Smuzhiyun s32 ixgbe_dcb_hw_config(struct ixgbe_hw *hw,
251*4882a593Smuzhiyun 			struct ixgbe_dcb_config *dcb_config)
252*4882a593Smuzhiyun {
253*4882a593Smuzhiyun 	u8 pfc_en;
254*4882a593Smuzhiyun 	u8 ptype[MAX_TRAFFIC_CLASS];
255*4882a593Smuzhiyun 	u8 bwgid[MAX_TRAFFIC_CLASS];
256*4882a593Smuzhiyun 	u8 prio_tc[MAX_TRAFFIC_CLASS];
257*4882a593Smuzhiyun 	u16 refill[MAX_TRAFFIC_CLASS];
258*4882a593Smuzhiyun 	u16 max[MAX_TRAFFIC_CLASS];
259*4882a593Smuzhiyun 
260*4882a593Smuzhiyun 	/* Unpack CEE standard containers */
261*4882a593Smuzhiyun 	ixgbe_dcb_unpack_pfc(dcb_config, &pfc_en);
262*4882a593Smuzhiyun 	ixgbe_dcb_unpack_refill(dcb_config, DCB_TX_CONFIG, refill);
263*4882a593Smuzhiyun 	ixgbe_dcb_unpack_max(dcb_config, max);
264*4882a593Smuzhiyun 	ixgbe_dcb_unpack_bwgid(dcb_config, DCB_TX_CONFIG, bwgid);
265*4882a593Smuzhiyun 	ixgbe_dcb_unpack_prio(dcb_config, DCB_TX_CONFIG, ptype);
266*4882a593Smuzhiyun 	ixgbe_dcb_unpack_map(dcb_config, DCB_TX_CONFIG, prio_tc);
267*4882a593Smuzhiyun 
268*4882a593Smuzhiyun 	switch (hw->mac.type) {
269*4882a593Smuzhiyun 	case ixgbe_mac_82598EB:
270*4882a593Smuzhiyun 		return ixgbe_dcb_hw_config_82598(hw, pfc_en, refill, max,
271*4882a593Smuzhiyun 						 bwgid, ptype);
272*4882a593Smuzhiyun 	case ixgbe_mac_82599EB:
273*4882a593Smuzhiyun 	case ixgbe_mac_X540:
274*4882a593Smuzhiyun 	case ixgbe_mac_X550:
275*4882a593Smuzhiyun 	case ixgbe_mac_X550EM_x:
276*4882a593Smuzhiyun 	case ixgbe_mac_x550em_a:
277*4882a593Smuzhiyun 		return ixgbe_dcb_hw_config_82599(hw, pfc_en, refill, max,
278*4882a593Smuzhiyun 						 bwgid, ptype, prio_tc);
279*4882a593Smuzhiyun 	default:
280*4882a593Smuzhiyun 		break;
281*4882a593Smuzhiyun 	}
282*4882a593Smuzhiyun 	return 0;
283*4882a593Smuzhiyun }
284*4882a593Smuzhiyun 
285*4882a593Smuzhiyun /* Helper routines to abstract HW specifics from DCB netlink ops */
ixgbe_dcb_hw_pfc_config(struct ixgbe_hw * hw,u8 pfc_en,u8 * prio_tc)286*4882a593Smuzhiyun s32 ixgbe_dcb_hw_pfc_config(struct ixgbe_hw *hw, u8 pfc_en, u8 *prio_tc)
287*4882a593Smuzhiyun {
288*4882a593Smuzhiyun 	switch (hw->mac.type) {
289*4882a593Smuzhiyun 	case ixgbe_mac_82598EB:
290*4882a593Smuzhiyun 		return ixgbe_dcb_config_pfc_82598(hw, pfc_en);
291*4882a593Smuzhiyun 	case ixgbe_mac_82599EB:
292*4882a593Smuzhiyun 	case ixgbe_mac_X540:
293*4882a593Smuzhiyun 	case ixgbe_mac_X550:
294*4882a593Smuzhiyun 	case ixgbe_mac_X550EM_x:
295*4882a593Smuzhiyun 	case ixgbe_mac_x550em_a:
296*4882a593Smuzhiyun 		return ixgbe_dcb_config_pfc_82599(hw, pfc_en, prio_tc);
297*4882a593Smuzhiyun 	default:
298*4882a593Smuzhiyun 		break;
299*4882a593Smuzhiyun 	}
300*4882a593Smuzhiyun 	return -EINVAL;
301*4882a593Smuzhiyun }
302*4882a593Smuzhiyun 
ixgbe_dcb_hw_ets(struct ixgbe_hw * hw,struct ieee_ets * ets,int max_frame)303*4882a593Smuzhiyun s32 ixgbe_dcb_hw_ets(struct ixgbe_hw *hw, struct ieee_ets *ets, int max_frame)
304*4882a593Smuzhiyun {
305*4882a593Smuzhiyun 	__u16 refill[IEEE_8021QAZ_MAX_TCS], max[IEEE_8021QAZ_MAX_TCS];
306*4882a593Smuzhiyun 	__u8 prio_type[IEEE_8021QAZ_MAX_TCS];
307*4882a593Smuzhiyun 	int i;
308*4882a593Smuzhiyun 
309*4882a593Smuzhiyun 	/* naively give each TC a bwg to map onto CEE hardware */
310*4882a593Smuzhiyun 	__u8 bwg_id[IEEE_8021QAZ_MAX_TCS] = {0, 1, 2, 3, 4, 5, 6, 7};
311*4882a593Smuzhiyun 
312*4882a593Smuzhiyun 	/* Map TSA onto CEE prio type */
313*4882a593Smuzhiyun 	for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
314*4882a593Smuzhiyun 		switch (ets->tc_tsa[i]) {
315*4882a593Smuzhiyun 		case IEEE_8021QAZ_TSA_STRICT:
316*4882a593Smuzhiyun 			prio_type[i] = 2;
317*4882a593Smuzhiyun 			break;
318*4882a593Smuzhiyun 		case IEEE_8021QAZ_TSA_ETS:
319*4882a593Smuzhiyun 			prio_type[i] = 0;
320*4882a593Smuzhiyun 			break;
321*4882a593Smuzhiyun 		default:
322*4882a593Smuzhiyun 			/* Hardware only supports priority strict or
323*4882a593Smuzhiyun 			 * ETS transmission selection algorithms if
324*4882a593Smuzhiyun 			 * we receive some other value from dcbnl
325*4882a593Smuzhiyun 			 * throw an error
326*4882a593Smuzhiyun 			 */
327*4882a593Smuzhiyun 			return -EINVAL;
328*4882a593Smuzhiyun 		}
329*4882a593Smuzhiyun 	}
330*4882a593Smuzhiyun 
331*4882a593Smuzhiyun 	ixgbe_ieee_credits(ets->tc_tx_bw, refill, max, max_frame);
332*4882a593Smuzhiyun 	return ixgbe_dcb_hw_ets_config(hw, refill, max,
333*4882a593Smuzhiyun 				       bwg_id, prio_type, ets->prio_tc);
334*4882a593Smuzhiyun }
335*4882a593Smuzhiyun 
ixgbe_dcb_hw_ets_config(struct ixgbe_hw * hw,u16 * refill,u16 * max,u8 * bwg_id,u8 * prio_type,u8 * prio_tc)336*4882a593Smuzhiyun s32 ixgbe_dcb_hw_ets_config(struct ixgbe_hw *hw,
337*4882a593Smuzhiyun 			    u16 *refill, u16 *max, u8 *bwg_id,
338*4882a593Smuzhiyun 			    u8 *prio_type, u8 *prio_tc)
339*4882a593Smuzhiyun {
340*4882a593Smuzhiyun 	switch (hw->mac.type) {
341*4882a593Smuzhiyun 	case ixgbe_mac_82598EB:
342*4882a593Smuzhiyun 		ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max,
343*4882a593Smuzhiyun 							prio_type);
344*4882a593Smuzhiyun 		ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max,
345*4882a593Smuzhiyun 							     bwg_id, prio_type);
346*4882a593Smuzhiyun 		ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max,
347*4882a593Smuzhiyun 							     bwg_id, prio_type);
348*4882a593Smuzhiyun 		break;
349*4882a593Smuzhiyun 	case ixgbe_mac_82599EB:
350*4882a593Smuzhiyun 	case ixgbe_mac_X540:
351*4882a593Smuzhiyun 	case ixgbe_mac_X550:
352*4882a593Smuzhiyun 	case ixgbe_mac_X550EM_x:
353*4882a593Smuzhiyun 	case ixgbe_mac_x550em_a:
354*4882a593Smuzhiyun 		ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max,
355*4882a593Smuzhiyun 						  bwg_id, prio_type, prio_tc);
356*4882a593Smuzhiyun 		ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max,
357*4882a593Smuzhiyun 						       bwg_id, prio_type);
358*4882a593Smuzhiyun 		ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max, bwg_id,
359*4882a593Smuzhiyun 						       prio_type, prio_tc);
360*4882a593Smuzhiyun 		break;
361*4882a593Smuzhiyun 	default:
362*4882a593Smuzhiyun 		break;
363*4882a593Smuzhiyun 	}
364*4882a593Smuzhiyun 	return 0;
365*4882a593Smuzhiyun }
366*4882a593Smuzhiyun 
ixgbe_dcb_read_rtrup2tc_82599(struct ixgbe_hw * hw,u8 * map)367*4882a593Smuzhiyun static void ixgbe_dcb_read_rtrup2tc_82599(struct ixgbe_hw *hw, u8 *map)
368*4882a593Smuzhiyun {
369*4882a593Smuzhiyun 	u32 reg, i;
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun 	reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
372*4882a593Smuzhiyun 	for (i = 0; i < MAX_USER_PRIORITY; i++)
373*4882a593Smuzhiyun 		map[i] = IXGBE_RTRUP2TC_UP_MASK &
374*4882a593Smuzhiyun 			(reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT));
375*4882a593Smuzhiyun }
376*4882a593Smuzhiyun 
ixgbe_dcb_read_rtrup2tc(struct ixgbe_hw * hw,u8 * map)377*4882a593Smuzhiyun void ixgbe_dcb_read_rtrup2tc(struct ixgbe_hw *hw, u8 *map)
378*4882a593Smuzhiyun {
379*4882a593Smuzhiyun 	switch (hw->mac.type) {
380*4882a593Smuzhiyun 	case ixgbe_mac_82599EB:
381*4882a593Smuzhiyun 	case ixgbe_mac_X540:
382*4882a593Smuzhiyun 	case ixgbe_mac_X550:
383*4882a593Smuzhiyun 	case ixgbe_mac_X550EM_x:
384*4882a593Smuzhiyun 	case ixgbe_mac_x550em_a:
385*4882a593Smuzhiyun 		ixgbe_dcb_read_rtrup2tc_82599(hw, map);
386*4882a593Smuzhiyun 		break;
387*4882a593Smuzhiyun 	default:
388*4882a593Smuzhiyun 		break;
389*4882a593Smuzhiyun 	}
390*4882a593Smuzhiyun }
391