blob: 39ac2feca1f1124df5f56c6fa98ca28a91868953 [file] [log] [blame]
Alexander Duyck2f90b862008-11-20 20:52:10 -08001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore94971822012-01-06 03:24:16 +00004 Copyright(c) 1999 - 2012 Intel Corporation.
Alexander Duyck2f90b862008-11-20 20:52:10 -08005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
23 Linux NICS <linux.nics@intel.com>
24 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26
27*******************************************************************************/
28
29
30#include "ixgbe.h"
31#include "ixgbe_type.h"
32#include "ixgbe_dcb.h"
33#include "ixgbe_dcb_82598.h"
PJ Waskiewicz235ea822009-02-27 15:44:48 +000034#include "ixgbe_dcb_82599.h"
Alexander Duyck2f90b862008-11-20 20:52:10 -080035
36/**
John Fastabendd033d522011-02-10 14:40:01 +000037 * ixgbe_ieee_credits - This calculates the ieee traffic class
38 * credits from the configured bandwidth percentages. Credits
Lucas De Marchi25985ed2011-03-30 22:57:33 -030039 * are the smallest unit programmable into the underlying
John Fastabendd033d522011-02-10 14:40:01 +000040 * hardware. The IEEE 802.1Qaz specification do not use bandwidth
41 * groups so this is much simplified from the CEE case.
42 */
John Fastabend4c09f3a2011-08-04 05:47:07 +000043static s32 ixgbe_ieee_credits(__u8 *bw, __u16 *refill,
44 __u16 *max, int max_frame)
John Fastabendd033d522011-02-10 14:40:01 +000045{
46 int min_percent = 100;
47 int min_credit, multiplier;
48 int i;
49
50 min_credit = ((max_frame / 2) + DCB_CREDIT_QUANTUM - 1) /
51 DCB_CREDIT_QUANTUM;
52
53 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
54 if (bw[i] < min_percent && bw[i])
55 min_percent = bw[i];
56 }
57
58 multiplier = (min_credit / min_percent) + 1;
59
60 /* Find out the hw credits for each TC */
61 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
62 int val = min(bw[i] * multiplier, MAX_CREDIT_REFILL);
63
64 if (val < min_credit)
65 val = min_credit;
66 refill[i] = val;
67
John Fastabend1390a592011-03-09 04:46:16 +000068 max[i] = bw[i] ? (bw[i] * MAX_CREDIT)/100 : min_credit;
John Fastabendd033d522011-02-10 14:40:01 +000069 }
70 return 0;
71}
72
73/**
Alexander Duyck2f90b862008-11-20 20:52:10 -080074 * ixgbe_dcb_calculate_tc_credits - Calculates traffic class credits
75 * @ixgbe_dcb_config: Struct containing DCB settings.
76 * @direction: Configuring either Tx or Rx.
77 *
78 * This function calculates the credits allocated to each traffic class.
79 * It should be called only after the rules are checked by
80 * ixgbe_dcb_check_config().
81 */
John Fastabend80ab1932010-11-16 19:26:45 -080082s32 ixgbe_dcb_calculate_tc_credits(struct ixgbe_hw *hw,
83 struct ixgbe_dcb_config *dcb_config,
John Fastabend98063072010-10-28 00:59:57 +000084 int max_frame, u8 direction)
Alexander Duyck2f90b862008-11-20 20:52:10 -080085{
86 struct tc_bw_alloc *p;
John Fastabend98063072010-10-28 00:59:57 +000087 int min_credit;
88 int min_multiplier;
89 int min_percent = 100;
Alexander Duyck2f90b862008-11-20 20:52:10 -080090 s32 ret_val = 0;
91 /* Initialization values default for Tx settings */
92 u32 credit_refill = 0;
93 u32 credit_max = 0;
94 u16 link_percentage = 0;
95 u8 bw_percent = 0;
96 u8 i;
97
98 if (dcb_config == NULL) {
99 ret_val = DCB_ERR_CONFIG;
100 goto out;
101 }
102
John Fastabend98063072010-10-28 00:59:57 +0000103 min_credit = ((max_frame / 2) + DCB_CREDIT_QUANTUM - 1) /
104 DCB_CREDIT_QUANTUM;
105
106 /* Find smallest link percentage */
107 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
108 p = &dcb_config->tc_config[i].path[direction];
109 bw_percent = dcb_config->bw_percentage[direction][p->bwg_id];
110 link_percentage = p->bwg_percent;
111
112 link_percentage = (link_percentage * bw_percent) / 100;
113
114 if (link_percentage && link_percentage < min_percent)
115 min_percent = link_percentage;
116 }
117
118 /*
119 * The ratio between traffic classes will control the bandwidth
120 * percentages seen on the wire. To calculate this ratio we use
121 * a multiplier. It is required that the refill credits must be
122 * larger than the max frame size so here we find the smallest
123 * multiplier that will allow all bandwidth percentages to be
124 * greater than the max frame size.
125 */
126 min_multiplier = (min_credit / min_percent) + 1;
127
Alexander Duyck2f90b862008-11-20 20:52:10 -0800128 /* Find out the link percentage for each TC first */
129 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
130 p = &dcb_config->tc_config[i].path[direction];
131 bw_percent = dcb_config->bw_percentage[direction][p->bwg_id];
132
133 link_percentage = p->bwg_percent;
134 /* Must be careful of integer division for very small nums */
135 link_percentage = (link_percentage * bw_percent) / 100;
136 if (p->bwg_percent > 0 && link_percentage == 0)
137 link_percentage = 1;
138
139 /* Save link_percentage for reference */
140 p->link_percent = (u8)link_percentage;
141
John Fastabend98063072010-10-28 00:59:57 +0000142 /* Calculate credit refill ratio using multiplier */
143 credit_refill = min(link_percentage * min_multiplier,
144 MAX_CREDIT_REFILL);
Alexander Duyck2f90b862008-11-20 20:52:10 -0800145 p->data_credits_refill = (u16)credit_refill;
146
147 /* Calculate maximum credit for the TC */
148 credit_max = (link_percentage * MAX_CREDIT) / 100;
149
150 /*
151 * Adjustment based on rule checking, if the percentage
152 * of a TC is too small, the maximum credit may not be
153 * enough to send out a jumbo frame in data plane arbitration.
154 */
John Fastabend98063072010-10-28 00:59:57 +0000155 if (credit_max && (credit_max < min_credit))
156 credit_max = min_credit;
Alexander Duyck2f90b862008-11-20 20:52:10 -0800157
158 if (direction == DCB_TX_CONFIG) {
159 /*
160 * Adjustment based on rule checking, if the
161 * percentage of a TC is too small, the maximum
162 * credit may not be enough to send out a TSO
163 * packet in descriptor plane arbitration.
164 */
John Fastabend80ab1932010-11-16 19:26:45 -0800165 if ((hw->mac.type == ixgbe_mac_82598EB) &&
166 credit_max &&
Alexander Duyck2f90b862008-11-20 20:52:10 -0800167 (credit_max < MINIMUM_CREDIT_FOR_TSO))
168 credit_max = MINIMUM_CREDIT_FOR_TSO;
169
170 dcb_config->tc_config[i].desc_credits_max =
171 (u16)credit_max;
172 }
173
174 p->data_credits_max = (u16)credit_max;
175 }
176
177out:
178 return ret_val;
179}
180
John Fastabend55320cb2011-01-05 04:47:43 +0000181void ixgbe_dcb_unpack_pfc(struct ixgbe_dcb_config *cfg, u8 *pfc_en)
182{
Alexander Duyckdf0676d2012-05-17 05:14:39 +0000183 struct tc_configuration *tc_config = &cfg->tc_config[0];
184 int tc;
John Fastabend55320cb2011-01-05 04:47:43 +0000185
Alexander Duyckdf0676d2012-05-17 05:14:39 +0000186 for (*pfc_en = 0, tc = 0; tc < MAX_TRAFFIC_CLASS; tc++) {
187 if (tc_config[tc].dcb_pfc != pfc_disabled)
188 *pfc_en |= 1 << tc;
189 }
John Fastabend55320cb2011-01-05 04:47:43 +0000190}
191
192void ixgbe_dcb_unpack_refill(struct ixgbe_dcb_config *cfg, int direction,
193 u16 *refill)
194{
Alexander Duyckdf0676d2012-05-17 05:14:39 +0000195 struct tc_configuration *tc_config = &cfg->tc_config[0];
196 int tc;
John Fastabend55320cb2011-01-05 04:47:43 +0000197
Alexander Duyckdf0676d2012-05-17 05:14:39 +0000198 for (tc = 0; tc < MAX_TRAFFIC_CLASS; tc++)
199 refill[tc] = tc_config[tc].path[direction].data_credits_refill;
John Fastabend55320cb2011-01-05 04:47:43 +0000200}
201
202void ixgbe_dcb_unpack_max(struct ixgbe_dcb_config *cfg, u16 *max)
203{
Alexander Duyckdf0676d2012-05-17 05:14:39 +0000204 struct tc_configuration *tc_config = &cfg->tc_config[0];
205 int tc;
John Fastabend55320cb2011-01-05 04:47:43 +0000206
Alexander Duyckdf0676d2012-05-17 05:14:39 +0000207 for (tc = 0; tc < MAX_TRAFFIC_CLASS; tc++)
208 max[tc] = tc_config[tc].desc_credits_max;
John Fastabend55320cb2011-01-05 04:47:43 +0000209}
210
211void ixgbe_dcb_unpack_bwgid(struct ixgbe_dcb_config *cfg, int direction,
212 u8 *bwgid)
213{
Alexander Duyckdf0676d2012-05-17 05:14:39 +0000214 struct tc_configuration *tc_config = &cfg->tc_config[0];
215 int tc;
John Fastabend55320cb2011-01-05 04:47:43 +0000216
Alexander Duyckdf0676d2012-05-17 05:14:39 +0000217 for (tc = 0; tc < MAX_TRAFFIC_CLASS; tc++)
218 bwgid[tc] = tc_config[tc].path[direction].bwg_id;
John Fastabend55320cb2011-01-05 04:47:43 +0000219}
220
221void ixgbe_dcb_unpack_prio(struct ixgbe_dcb_config *cfg, int direction,
222 u8 *ptype)
223{
Alexander Duyckdf0676d2012-05-17 05:14:39 +0000224 struct tc_configuration *tc_config = &cfg->tc_config[0];
225 int tc;
John Fastabend55320cb2011-01-05 04:47:43 +0000226
Alexander Duyckdf0676d2012-05-17 05:14:39 +0000227 for (tc = 0; tc < MAX_TRAFFIC_CLASS; tc++)
228 ptype[tc] = tc_config[tc].path[direction].prio_type;
John Fastabend55320cb2011-01-05 04:47:43 +0000229}
230
Alexander Duyck15cbc702012-05-17 05:14:34 +0000231static u8 ixgbe_dcb_get_tc_from_up(struct ixgbe_dcb_config *cfg,
232 int direction, u8 up)
233{
234 struct tc_configuration *tc_config = &cfg->tc_config[0];
235 u8 prio_mask = 1 << up;
236 u8 tc;
237
238 /*
239 * Test for TCs 7 through 1 and report the first match we find. If
240 * we find no match we can assume that the TC is 0 since the TC must
241 * be set for all user priorities
242 */
243 for (tc = MAX_TRAFFIC_CLASS - 1; tc; tc--) {
244 if (prio_mask & tc_config[tc].path[direction].up_to_tc_bitmap)
245 break;
246 }
247
248 return tc;
249}
250
John Fastabend32701dc2011-09-27 03:51:56 +0000251void ixgbe_dcb_unpack_map(struct ixgbe_dcb_config *cfg, int direction, u8 *map)
252{
Alexander Duyck15cbc702012-05-17 05:14:34 +0000253 u8 up;
John Fastabend32701dc2011-09-27 03:51:56 +0000254
Alexander Duyck15cbc702012-05-17 05:14:34 +0000255 for (up = 0; up < MAX_USER_PRIORITY; up++)
256 map[up] = ixgbe_dcb_get_tc_from_up(cfg, direction, up);
John Fastabend32701dc2011-09-27 03:51:56 +0000257}
258
Alexander Duyck2f90b862008-11-20 20:52:10 -0800259/**
Alexander Duyck2f90b862008-11-20 20:52:10 -0800260 * ixgbe_dcb_hw_config - Config and enable DCB
261 * @hw: pointer to hardware structure
262 * @dcb_config: pointer to ixgbe_dcb_config structure
263 *
264 * Configure dcb settings and enable dcb mode.
265 */
266s32 ixgbe_dcb_hw_config(struct ixgbe_hw *hw,
267 struct ixgbe_dcb_config *dcb_config)
268{
269 s32 ret = 0;
John Fastabend55320cb2011-01-05 04:47:43 +0000270 u8 pfc_en;
271 u8 ptype[MAX_TRAFFIC_CLASS];
272 u8 bwgid[MAX_TRAFFIC_CLASS];
John Fastabend32701dc2011-09-27 03:51:56 +0000273 u8 prio_tc[MAX_TRAFFIC_CLASS];
John Fastabend55320cb2011-01-05 04:47:43 +0000274 u16 refill[MAX_TRAFFIC_CLASS];
275 u16 max[MAX_TRAFFIC_CLASS];
276
277 /* Unpack CEE standard containers */
278 ixgbe_dcb_unpack_pfc(dcb_config, &pfc_en);
279 ixgbe_dcb_unpack_refill(dcb_config, DCB_TX_CONFIG, refill);
280 ixgbe_dcb_unpack_max(dcb_config, max);
281 ixgbe_dcb_unpack_bwgid(dcb_config, DCB_TX_CONFIG, bwgid);
282 ixgbe_dcb_unpack_prio(dcb_config, DCB_TX_CONFIG, ptype);
John Fastabend32701dc2011-09-27 03:51:56 +0000283 ixgbe_dcb_unpack_map(dcb_config, DCB_TX_CONFIG, prio_tc);
John Fastabend55320cb2011-01-05 04:47:43 +0000284
Don Skidmoreb93a2222010-11-16 19:27:17 -0800285 switch (hw->mac.type) {
286 case ixgbe_mac_82598EB:
John Fastabend80605c652011-05-02 12:34:10 +0000287 ret = ixgbe_dcb_hw_config_82598(hw, pfc_en, refill, max,
288 bwgid, ptype);
Don Skidmoreb93a2222010-11-16 19:27:17 -0800289 break;
290 case ixgbe_mac_82599EB:
291 case ixgbe_mac_X540:
John Fastabend80605c652011-05-02 12:34:10 +0000292 ret = ixgbe_dcb_hw_config_82599(hw, pfc_en, refill, max,
293 bwgid, ptype, prio_tc);
Don Skidmoreb93a2222010-11-16 19:27:17 -0800294 break;
295 default:
296 break;
297 }
Alexander Duyck2f90b862008-11-20 20:52:10 -0800298 return ret;
299}
300
John Fastabendd033d522011-02-10 14:40:01 +0000301/* Helper routines to abstract HW specifics from DCB netlink ops */
John Fastabend32701dc2011-09-27 03:51:56 +0000302s32 ixgbe_dcb_hw_pfc_config(struct ixgbe_hw *hw, u8 pfc_en, u8 *prio_tc)
John Fastabendd033d522011-02-10 14:40:01 +0000303{
304 int ret = -EINVAL;
305
306 switch (hw->mac.type) {
307 case ixgbe_mac_82598EB:
308 ret = ixgbe_dcb_config_pfc_82598(hw, pfc_en);
309 break;
310 case ixgbe_mac_82599EB:
311 case ixgbe_mac_X540:
John Fastabend32701dc2011-09-27 03:51:56 +0000312 ret = ixgbe_dcb_config_pfc_82599(hw, pfc_en, prio_tc);
John Fastabendd033d522011-02-10 14:40:01 +0000313 break;
314 default:
315 break;
316 }
317 return ret;
318}
319
John Fastabend4c09f3a2011-08-04 05:47:07 +0000320s32 ixgbe_dcb_hw_ets(struct ixgbe_hw *hw, struct ieee_ets *ets, int max_frame)
321{
322 __u16 refill[IEEE_8021QAZ_MAX_TCS], max[IEEE_8021QAZ_MAX_TCS];
323 __u8 prio_type[IEEE_8021QAZ_MAX_TCS];
324 int i;
325
326 /* naively give each TC a bwg to map onto CEE hardware */
327 __u8 bwg_id[IEEE_8021QAZ_MAX_TCS] = {0, 1, 2, 3, 4, 5, 6, 7};
328
329 /* Map TSA onto CEE prio type */
330 for (i = 0; i < IEEE_8021QAZ_MAX_TCS; i++) {
331 switch (ets->tc_tsa[i]) {
332 case IEEE_8021QAZ_TSA_STRICT:
333 prio_type[i] = 2;
334 break;
335 case IEEE_8021QAZ_TSA_ETS:
336 prio_type[i] = 0;
337 break;
338 default:
339 /* Hardware only supports priority strict or
340 * ETS transmission selection algorithms if
341 * we receive some other value from dcbnl
342 * throw an error
343 */
344 return -EINVAL;
345 }
346 }
347
348 ixgbe_ieee_credits(ets->tc_tx_bw, refill, max, max_frame);
349 return ixgbe_dcb_hw_ets_config(hw, refill, max,
350 bwg_id, prio_type, ets->prio_tc);
351}
352
John Fastabendd033d522011-02-10 14:40:01 +0000353s32 ixgbe_dcb_hw_ets_config(struct ixgbe_hw *hw,
John Fastabend17049d32011-02-23 05:58:19 +0000354 u16 *refill, u16 *max, u8 *bwg_id,
355 u8 *prio_type, u8 *prio_tc)
John Fastabendd033d522011-02-10 14:40:01 +0000356{
John Fastabendd033d522011-02-10 14:40:01 +0000357 switch (hw->mac.type) {
358 case ixgbe_mac_82598EB:
359 ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max,
360 prio_type);
361 ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max,
362 bwg_id, prio_type);
363 ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max,
364 bwg_id, prio_type);
365 break;
366 case ixgbe_mac_82599EB:
367 case ixgbe_mac_X540:
368 ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max,
John Fastabend17049d32011-02-23 05:58:19 +0000369 bwg_id, prio_type, prio_tc);
John Fastabendd033d522011-02-10 14:40:01 +0000370 ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max,
371 bwg_id, prio_type);
John Fastabend17049d32011-02-23 05:58:19 +0000372 ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max, bwg_id,
373 prio_type, prio_tc);
John Fastabendd033d522011-02-10 14:40:01 +0000374 break;
375 default:
376 break;
377 }
378 return 0;
379}