1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 1999 - 2018 Intel Corporation. */
5 #include "ixgbe_type.h"
7 #include "ixgbe_dcb_82598.h"
8 #include "ixgbe_dcb_82599.h"
11 * ixgbe_ieee_credits - This calculates the ieee traffic class
12 * credits from the configured bandwidth percentages. Credits
13 * are the smallest unit programmable into the underlying
14 * hardware. The IEEE 802.1Qaz specification do not use bandwidth
15 * groups so this is much simplified from the CEE case.
16 * @bw: bandwidth index by traffic class
17 * @refill: refill credits index by traffic class
18 * @max: max credits by traffic class
19 * @max_frame: maximum frame size
21 static s32
ixgbe_ieee_credits(__u8
*bw
, __u16
*refill
,
22 __u16
*max
, int max_frame
)
24 int min_percent
= 100;
25 int min_credit
, multiplier
;
28 min_credit
= ((max_frame
/ 2) + DCB_CREDIT_QUANTUM
- 1) /
31 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
32 if (bw
[i
] < min_percent
&& bw
[i
])
36 multiplier
= (min_credit
/ min_percent
) + 1;
38 /* Find out the hw credits for each TC */
39 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
40 int val
= min(bw
[i
] * multiplier
, MAX_CREDIT_REFILL
);
46 max
[i
] = bw
[i
] ? (bw
[i
] * MAX_CREDIT
)/100 : min_credit
;
52 * ixgbe_dcb_calculate_tc_credits - Calculates traffic class credits
53 * @hw: pointer to hardware structure
54 * @dcb_config: Struct containing DCB settings
55 * @max_frame: Maximum frame size
56 * @direction: Configuring either Tx or Rx
58 * This function calculates the credits allocated to each traffic class.
59 * It should be called only after the rules are checked by
60 * ixgbe_dcb_check_config().
62 s32
ixgbe_dcb_calculate_tc_credits(struct ixgbe_hw
*hw
,
63 struct ixgbe_dcb_config
*dcb_config
,
64 int max_frame
, u8 direction
)
66 struct tc_bw_alloc
*p
;
69 int min_percent
= 100;
70 /* Initialization values default for Tx settings */
71 u32 credit_refill
= 0;
73 u16 link_percentage
= 0;
78 return DCB_ERR_CONFIG
;
80 min_credit
= ((max_frame
/ 2) + DCB_CREDIT_QUANTUM
- 1) /
83 /* Find smallest link percentage */
84 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
85 p
= &dcb_config
->tc_config
[i
].path
[direction
];
86 bw_percent
= dcb_config
->bw_percentage
[direction
][p
->bwg_id
];
87 link_percentage
= p
->bwg_percent
;
89 link_percentage
= (link_percentage
* bw_percent
) / 100;
91 if (link_percentage
&& link_percentage
< min_percent
)
92 min_percent
= link_percentage
;
96 * The ratio between traffic classes will control the bandwidth
97 * percentages seen on the wire. To calculate this ratio we use
98 * a multiplier. It is required that the refill credits must be
99 * larger than the max frame size so here we find the smallest
100 * multiplier that will allow all bandwidth percentages to be
101 * greater than the max frame size.
103 min_multiplier
= (min_credit
/ min_percent
) + 1;
105 /* Find out the link percentage for each TC first */
106 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
107 p
= &dcb_config
->tc_config
[i
].path
[direction
];
108 bw_percent
= dcb_config
->bw_percentage
[direction
][p
->bwg_id
];
110 link_percentage
= p
->bwg_percent
;
111 /* Must be careful of integer division for very small nums */
112 link_percentage
= (link_percentage
* bw_percent
) / 100;
113 if (p
->bwg_percent
> 0 && link_percentage
== 0)
116 /* Save link_percentage for reference */
117 p
->link_percent
= (u8
)link_percentage
;
119 /* Calculate credit refill ratio using multiplier */
120 credit_refill
= min(link_percentage
* min_multiplier
,
123 /* Refill at least minimum credit */
124 if (credit_refill
< min_credit
)
125 credit_refill
= min_credit
;
127 p
->data_credits_refill
= (u16
)credit_refill
;
129 /* Calculate maximum credit for the TC */
130 credit_max
= (link_percentage
* MAX_CREDIT
) / 100;
133 * Adjustment based on rule checking, if the percentage
134 * of a TC is too small, the maximum credit may not be
135 * enough to send out a jumbo frame in data plane arbitration.
137 if (credit_max
< min_credit
)
138 credit_max
= min_credit
;
140 if (direction
== DCB_TX_CONFIG
) {
142 * Adjustment based on rule checking, if the
143 * percentage of a TC is too small, the maximum
144 * credit may not be enough to send out a TSO
145 * packet in descriptor plane arbitration.
147 if ((hw
->mac
.type
== ixgbe_mac_82598EB
) &&
149 (credit_max
< MINIMUM_CREDIT_FOR_TSO
))
150 credit_max
= MINIMUM_CREDIT_FOR_TSO
;
152 dcb_config
->tc_config
[i
].desc_credits_max
=
156 p
->data_credits_max
= (u16
)credit_max
;
162 void ixgbe_dcb_unpack_pfc(struct ixgbe_dcb_config
*cfg
, u8
*pfc_en
)
164 struct tc_configuration
*tc_config
= &cfg
->tc_config
[0];
167 for (*pfc_en
= 0, tc
= 0; tc
< MAX_TRAFFIC_CLASS
; tc
++) {
168 if (tc_config
[tc
].dcb_pfc
!= pfc_disabled
)
173 void ixgbe_dcb_unpack_refill(struct ixgbe_dcb_config
*cfg
, int direction
,
176 struct tc_configuration
*tc_config
= &cfg
->tc_config
[0];
179 for (tc
= 0; tc
< MAX_TRAFFIC_CLASS
; tc
++)
180 refill
[tc
] = tc_config
[tc
].path
[direction
].data_credits_refill
;
183 void ixgbe_dcb_unpack_max(struct ixgbe_dcb_config
*cfg
, u16
*max
)
185 struct tc_configuration
*tc_config
= &cfg
->tc_config
[0];
188 for (tc
= 0; tc
< MAX_TRAFFIC_CLASS
; tc
++)
189 max
[tc
] = tc_config
[tc
].desc_credits_max
;
192 void ixgbe_dcb_unpack_bwgid(struct ixgbe_dcb_config
*cfg
, int direction
,
195 struct tc_configuration
*tc_config
= &cfg
->tc_config
[0];
198 for (tc
= 0; tc
< MAX_TRAFFIC_CLASS
; tc
++)
199 bwgid
[tc
] = tc_config
[tc
].path
[direction
].bwg_id
;
202 void ixgbe_dcb_unpack_prio(struct ixgbe_dcb_config
*cfg
, int direction
,
205 struct tc_configuration
*tc_config
= &cfg
->tc_config
[0];
208 for (tc
= 0; tc
< MAX_TRAFFIC_CLASS
; tc
++)
209 ptype
[tc
] = tc_config
[tc
].path
[direction
].prio_type
;
212 u8
ixgbe_dcb_get_tc_from_up(struct ixgbe_dcb_config
*cfg
, int direction
, u8 up
)
214 struct tc_configuration
*tc_config
= &cfg
->tc_config
[0];
215 u8 prio_mask
= BIT(up
);
216 u8 tc
= cfg
->num_tcs
.pg_tcs
;
218 /* If tc is 0 then DCB is likely not enabled or supported */
223 * Test from maximum TC to 1 and report the first match we find. If
224 * we find no match we can assume that the TC is 0 since the TC must
225 * be set for all user priorities
227 for (tc
--; tc
; tc
--) {
228 if (prio_mask
& tc_config
[tc
].path
[direction
].up_to_tc_bitmap
)
235 void ixgbe_dcb_unpack_map(struct ixgbe_dcb_config
*cfg
, int direction
, u8
*map
)
239 for (up
= 0; up
< MAX_USER_PRIORITY
; up
++)
240 map
[up
] = ixgbe_dcb_get_tc_from_up(cfg
, direction
, up
);
244 * ixgbe_dcb_hw_config - Config and enable DCB
245 * @hw: pointer to hardware structure
246 * @dcb_config: pointer to ixgbe_dcb_config structure
248 * Configure dcb settings and enable dcb mode.
250 s32
ixgbe_dcb_hw_config(struct ixgbe_hw
*hw
,
251 struct ixgbe_dcb_config
*dcb_config
)
254 u8 ptype
[MAX_TRAFFIC_CLASS
];
255 u8 bwgid
[MAX_TRAFFIC_CLASS
];
256 u8 prio_tc
[MAX_TRAFFIC_CLASS
];
257 u16 refill
[MAX_TRAFFIC_CLASS
];
258 u16 max
[MAX_TRAFFIC_CLASS
];
260 /* Unpack CEE standard containers */
261 ixgbe_dcb_unpack_pfc(dcb_config
, &pfc_en
);
262 ixgbe_dcb_unpack_refill(dcb_config
, DCB_TX_CONFIG
, refill
);
263 ixgbe_dcb_unpack_max(dcb_config
, max
);
264 ixgbe_dcb_unpack_bwgid(dcb_config
, DCB_TX_CONFIG
, bwgid
);
265 ixgbe_dcb_unpack_prio(dcb_config
, DCB_TX_CONFIG
, ptype
);
266 ixgbe_dcb_unpack_map(dcb_config
, DCB_TX_CONFIG
, prio_tc
);
268 switch (hw
->mac
.type
) {
269 case ixgbe_mac_82598EB
:
270 return ixgbe_dcb_hw_config_82598(hw
, pfc_en
, refill
, max
,
272 case ixgbe_mac_82599EB
:
275 case ixgbe_mac_X550EM_x
:
276 case ixgbe_mac_x550em_a
:
277 return ixgbe_dcb_hw_config_82599(hw
, pfc_en
, refill
, max
,
278 bwgid
, ptype
, prio_tc
);
285 /* Helper routines to abstract HW specifics from DCB netlink ops */
286 s32
ixgbe_dcb_hw_pfc_config(struct ixgbe_hw
*hw
, u8 pfc_en
, u8
*prio_tc
)
288 switch (hw
->mac
.type
) {
289 case ixgbe_mac_82598EB
:
290 return ixgbe_dcb_config_pfc_82598(hw
, pfc_en
);
291 case ixgbe_mac_82599EB
:
294 case ixgbe_mac_X550EM_x
:
295 case ixgbe_mac_x550em_a
:
296 return ixgbe_dcb_config_pfc_82599(hw
, pfc_en
, prio_tc
);
303 s32
ixgbe_dcb_hw_ets(struct ixgbe_hw
*hw
, struct ieee_ets
*ets
, int max_frame
)
305 __u16 refill
[IEEE_8021QAZ_MAX_TCS
], max
[IEEE_8021QAZ_MAX_TCS
];
306 __u8 prio_type
[IEEE_8021QAZ_MAX_TCS
];
309 /* naively give each TC a bwg to map onto CEE hardware */
310 __u8 bwg_id
[IEEE_8021QAZ_MAX_TCS
] = {0, 1, 2, 3, 4, 5, 6, 7};
312 /* Map TSA onto CEE prio type */
313 for (i
= 0; i
< IEEE_8021QAZ_MAX_TCS
; i
++) {
314 switch (ets
->tc_tsa
[i
]) {
315 case IEEE_8021QAZ_TSA_STRICT
:
318 case IEEE_8021QAZ_TSA_ETS
:
322 /* Hardware only supports priority strict or
323 * ETS transmission selection algorithms if
324 * we receive some other value from dcbnl
331 ixgbe_ieee_credits(ets
->tc_tx_bw
, refill
, max
, max_frame
);
332 return ixgbe_dcb_hw_ets_config(hw
, refill
, max
,
333 bwg_id
, prio_type
, ets
->prio_tc
);
336 s32
ixgbe_dcb_hw_ets_config(struct ixgbe_hw
*hw
,
337 u16
*refill
, u16
*max
, u8
*bwg_id
,
338 u8
*prio_type
, u8
*prio_tc
)
340 switch (hw
->mac
.type
) {
341 case ixgbe_mac_82598EB
:
342 ixgbe_dcb_config_rx_arbiter_82598(hw
, refill
, max
,
344 ixgbe_dcb_config_tx_desc_arbiter_82598(hw
, refill
, max
,
346 ixgbe_dcb_config_tx_data_arbiter_82598(hw
, refill
, max
,
349 case ixgbe_mac_82599EB
:
352 case ixgbe_mac_X550EM_x
:
353 case ixgbe_mac_x550em_a
:
354 ixgbe_dcb_config_rx_arbiter_82599(hw
, refill
, max
,
355 bwg_id
, prio_type
, prio_tc
);
356 ixgbe_dcb_config_tx_desc_arbiter_82599(hw
, refill
, max
,
358 ixgbe_dcb_config_tx_data_arbiter_82599(hw
, refill
, max
, bwg_id
,
367 static void ixgbe_dcb_read_rtrup2tc_82599(struct ixgbe_hw
*hw
, u8
*map
)
371 reg
= IXGBE_READ_REG(hw
, IXGBE_RTRUP2TC
);
372 for (i
= 0; i
< MAX_USER_PRIORITY
; i
++)
373 map
[i
] = IXGBE_RTRUP2TC_UP_MASK
&
374 (reg
>> (i
* IXGBE_RTRUP2TC_UP_SHIFT
));
377 void ixgbe_dcb_read_rtrup2tc(struct ixgbe_hw
*hw
, u8
*map
)
379 switch (hw
->mac
.type
) {
380 case ixgbe_mac_82599EB
:
383 case ixgbe_mac_X550EM_x
:
384 case ixgbe_mac_x550em_a
:
385 ixgbe_dcb_read_rtrup2tc_82599(hw
, map
);