i40e: move to drivers/net/
[dpdk.git] / lib / librte_pmd_ixgbe / ixgbe / ixgbe_dcb.c
1 /*******************************************************************************
2
3 Copyright (c) 2001-2014, Intel Corporation
4 All rights reserved.
5
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are met:
8
9  1. Redistributions of source code must retain the above copyright notice,
10     this list of conditions and the following disclaimer.
11
12  2. Redistributions in binary form must reproduce the above copyright
13     notice, this list of conditions and the following disclaimer in the
14     documentation and/or other materials provided with the distribution.
15
16  3. Neither the name of the Intel Corporation nor the names of its
17     contributors may be used to endorse or promote products derived from
18     this software without specific prior written permission.
19
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 POSSIBILITY OF SUCH DAMAGE.
31
32 ***************************************************************************/
33
34
35 #include "ixgbe_type.h"
36 #include "ixgbe_dcb.h"
37 #include "ixgbe_dcb_82598.h"
38 #include "ixgbe_dcb_82599.h"
39
40 /**
41  * ixgbe_dcb_calculate_tc_credits - This calculates the ieee traffic class
42  * credits from the configured bandwidth percentages. Credits
43  * are the smallest unit programmable into the underlying
44  * hardware. The IEEE 802.1Qaz specification do not use bandwidth
45  * groups so this is much simplified from the CEE case.
46  */
47 s32 ixgbe_dcb_calculate_tc_credits(u8 *bw, u16 *refill, u16 *max,
48                                    int max_frame_size)
49 {
50         int min_percent = 100;
51         int min_credit, multiplier;
52         int i;
53
54         min_credit = ((max_frame_size / 2) + IXGBE_DCB_CREDIT_QUANTUM - 1) /
55                         IXGBE_DCB_CREDIT_QUANTUM;
56
57         for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
58                 if (bw[i] < min_percent && bw[i])
59                         min_percent = bw[i];
60         }
61
62         multiplier = (min_credit / min_percent) + 1;
63
64         /* Find out the hw credits for each TC */
65         for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
66                 int val = min(bw[i] * multiplier, IXGBE_DCB_MAX_CREDIT_REFILL);
67
68                 if (val < min_credit)
69                         val = min_credit;
70                 refill[i] = (u16)val;
71
72                 max[i] = bw[i] ? (bw[i]*IXGBE_DCB_MAX_CREDIT)/100 : min_credit;
73         }
74
75         return 0;
76 }
77
78 /**
79  * ixgbe_dcb_calculate_tc_credits_cee - Calculates traffic class credits
80  * @ixgbe_dcb_config: Struct containing DCB settings.
81  * @direction: Configuring either Tx or Rx.
82  *
83  * This function calculates the credits allocated to each traffic class.
84  * It should be called only after the rules are checked by
85  * ixgbe_dcb_check_config_cee().
86  */
87 s32 ixgbe_dcb_calculate_tc_credits_cee(struct ixgbe_hw *hw,
88                                    struct ixgbe_dcb_config *dcb_config,
89                                    u32 max_frame_size, u8 direction)
90 {
91         struct ixgbe_dcb_tc_path *p;
92         u32 min_multiplier      = 0;
93         u16 min_percent         = 100;
94         s32 ret_val =           IXGBE_SUCCESS;
95         /* Initialization values default for Tx settings */
96         u32 min_credit          = 0;
97         u32 credit_refill       = 0;
98         u32 credit_max          = 0;
99         u16 link_percentage     = 0;
100         u8  bw_percent          = 0;
101         u8  i;
102
103         if (dcb_config == NULL) {
104                 ret_val = IXGBE_ERR_CONFIG;
105                 goto out;
106         }
107
108         min_credit = ((max_frame_size / 2) + IXGBE_DCB_CREDIT_QUANTUM - 1) /
109                      IXGBE_DCB_CREDIT_QUANTUM;
110
111         /* Find smallest link percentage */
112         for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
113                 p = &dcb_config->tc_config[i].path[direction];
114                 bw_percent = dcb_config->bw_percentage[direction][p->bwg_id];
115                 link_percentage = p->bwg_percent;
116
117                 link_percentage = (link_percentage * bw_percent) / 100;
118
119                 if (link_percentage && link_percentage < min_percent)
120                         min_percent = link_percentage;
121         }
122
123         /*
124          * The ratio between traffic classes will control the bandwidth
125          * percentages seen on the wire. To calculate this ratio we use
126          * a multiplier. It is required that the refill credits must be
127          * larger than the max frame size so here we find the smallest
128          * multiplier that will allow all bandwidth percentages to be
129          * greater than the max frame size.
130          */
131         min_multiplier = (min_credit / min_percent) + 1;
132
133         /* Find out the link percentage for each TC first */
134         for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
135                 p = &dcb_config->tc_config[i].path[direction];
136                 bw_percent = dcb_config->bw_percentage[direction][p->bwg_id];
137
138                 link_percentage = p->bwg_percent;
139                 /* Must be careful of integer division for very small nums */
140                 link_percentage = (link_percentage * bw_percent) / 100;
141                 if (p->bwg_percent > 0 && link_percentage == 0)
142                         link_percentage = 1;
143
144                 /* Save link_percentage for reference */
145                 p->link_percent = (u8)link_percentage;
146
147                 /* Calculate credit refill ratio using multiplier */
148                 credit_refill = min(link_percentage * min_multiplier,
149                                     (u32)IXGBE_DCB_MAX_CREDIT_REFILL);
150                 p->data_credits_refill = (u16)credit_refill;
151
152                 /* Calculate maximum credit for the TC */
153                 credit_max = (link_percentage * IXGBE_DCB_MAX_CREDIT) / 100;
154
155                 /*
156                  * Adjustment based on rule checking, if the percentage
157                  * of a TC is too small, the maximum credit may not be
158                  * enough to send out a jumbo frame in data plane arbitration.
159                  */
160                 if (credit_max && (credit_max < min_credit))
161                         credit_max = min_credit;
162
163                 if (direction == IXGBE_DCB_TX_CONFIG) {
164                         /*
165                          * Adjustment based on rule checking, if the
166                          * percentage of a TC is too small, the maximum
167                          * credit may not be enough to send out a TSO
168                          * packet in descriptor plane arbitration.
169                          */
170                         if (credit_max && (credit_max <
171                             IXGBE_DCB_MIN_TSO_CREDIT)
172                             && (hw->mac.type == ixgbe_mac_82598EB))
173                                 credit_max = IXGBE_DCB_MIN_TSO_CREDIT;
174
175                         dcb_config->tc_config[i].desc_credits_max =
176                                                                 (u16)credit_max;
177                 }
178
179                 p->data_credits_max = (u16)credit_max;
180         }
181
182 out:
183         return ret_val;
184 }
185
186 /**
187  * ixgbe_dcb_unpack_pfc_cee - Unpack dcb_config PFC info
188  * @cfg: dcb configuration to unpack into hardware consumable fields
189  * @map: user priority to traffic class map
190  * @pfc_up: u8 to store user priority PFC bitmask
191  *
192  * This unpacks the dcb configuration PFC info which is stored per
193  * traffic class into a 8bit user priority bitmask that can be
194  * consumed by hardware routines. The priority to tc map must be
195  * updated before calling this routine to use current up-to maps.
196  */
197 void ixgbe_dcb_unpack_pfc_cee(struct ixgbe_dcb_config *cfg, u8 *map, u8 *pfc_up)
198 {
199         struct ixgbe_dcb_tc_config *tc_config = &cfg->tc_config[0];
200         int up;
201
202         /*
203          * If the TC for this user priority has PFC enabled then set the
204          * matching bit in 'pfc_up' to reflect that PFC is enabled.
205          */
206         for (*pfc_up = 0, up = 0; up < IXGBE_DCB_MAX_USER_PRIORITY; up++) {
207                 if (tc_config[map[up]].pfc != ixgbe_dcb_pfc_disabled)
208                         *pfc_up |= 1 << up;
209         }
210 }
211
212 void ixgbe_dcb_unpack_refill_cee(struct ixgbe_dcb_config *cfg, int direction,
213                              u16 *refill)
214 {
215         struct ixgbe_dcb_tc_config *tc_config = &cfg->tc_config[0];
216         int tc;
217
218         for (tc = 0; tc < IXGBE_DCB_MAX_TRAFFIC_CLASS; tc++)
219                 refill[tc] = tc_config[tc].path[direction].data_credits_refill;
220 }
221
222 void ixgbe_dcb_unpack_max_cee(struct ixgbe_dcb_config *cfg, u16 *max)
223 {
224         struct ixgbe_dcb_tc_config *tc_config = &cfg->tc_config[0];
225         int tc;
226
227         for (tc = 0; tc < IXGBE_DCB_MAX_TRAFFIC_CLASS; tc++)
228                 max[tc] = tc_config[tc].desc_credits_max;
229 }
230
231 void ixgbe_dcb_unpack_bwgid_cee(struct ixgbe_dcb_config *cfg, int direction,
232                             u8 *bwgid)
233 {
234         struct ixgbe_dcb_tc_config *tc_config = &cfg->tc_config[0];
235         int tc;
236
237         for (tc = 0; tc < IXGBE_DCB_MAX_TRAFFIC_CLASS; tc++)
238                 bwgid[tc] = tc_config[tc].path[direction].bwg_id;
239 }
240
241 void ixgbe_dcb_unpack_tsa_cee(struct ixgbe_dcb_config *cfg, int direction,
242                            u8 *tsa)
243 {
244         struct ixgbe_dcb_tc_config *tc_config = &cfg->tc_config[0];
245         int tc;
246
247         for (tc = 0; tc < IXGBE_DCB_MAX_TRAFFIC_CLASS; tc++)
248                 tsa[tc] = tc_config[tc].path[direction].tsa;
249 }
250
251 u8 ixgbe_dcb_get_tc_from_up(struct ixgbe_dcb_config *cfg, int direction, u8 up)
252 {
253         struct ixgbe_dcb_tc_config *tc_config = &cfg->tc_config[0];
254         u8 prio_mask = 1 << up;
255         u8 tc = cfg->num_tcs.pg_tcs;
256
257         /* If tc is 0 then DCB is likely not enabled or supported */
258         if (!tc)
259                 goto out;
260
261         /*
262          * Test from maximum TC to 1 and report the first match we find.  If
263          * we find no match we can assume that the TC is 0 since the TC must
264          * be set for all user priorities
265          */
266         for (tc--; tc; tc--) {
267                 if (prio_mask & tc_config[tc].path[direction].up_to_tc_bitmap)
268                         break;
269         }
270 out:
271         return tc;
272 }
273
274 void ixgbe_dcb_unpack_map_cee(struct ixgbe_dcb_config *cfg, int direction,
275                               u8 *map)
276 {
277         u8 up;
278
279         for (up = 0; up < IXGBE_DCB_MAX_USER_PRIORITY; up++)
280                 map[up] = ixgbe_dcb_get_tc_from_up(cfg, direction, up);
281 }
282
283 /**
284  * ixgbe_dcb_config - Struct containing DCB settings.
285  * @dcb_config: Pointer to DCB config structure
286  *
287  * This function checks DCB rules for DCB settings.
288  * The following rules are checked:
289  * 1. The sum of bandwidth percentages of all Bandwidth Groups must total 100%.
290  * 2. The sum of bandwidth percentages of all Traffic Classes within a Bandwidth
291  *    Group must total 100.
292  * 3. A Traffic Class should not be set to both Link Strict Priority
293  *    and Group Strict Priority.
294  * 4. Link strict Bandwidth Groups can only have link strict traffic classes
295  *    with zero bandwidth.
296  */
297 s32 ixgbe_dcb_check_config_cee(struct ixgbe_dcb_config *dcb_config)
298 {
299         struct ixgbe_dcb_tc_path *p;
300         s32 ret_val = IXGBE_SUCCESS;
301         u8 i, j, bw = 0, bw_id;
302         u8 bw_sum[2][IXGBE_DCB_MAX_BW_GROUP];
303         bool link_strict[2][IXGBE_DCB_MAX_BW_GROUP];
304
305         memset(bw_sum, 0, sizeof(bw_sum));
306         memset(link_strict, 0, sizeof(link_strict));
307
308         /* First Tx, then Rx */
309         for (i = 0; i < 2; i++) {
310                 /* Check each traffic class for rule violation */
311                 for (j = 0; j < IXGBE_DCB_MAX_TRAFFIC_CLASS; j++) {
312                         p = &dcb_config->tc_config[j].path[i];
313
314                         bw = p->bwg_percent;
315                         bw_id = p->bwg_id;
316
317                         if (bw_id >= IXGBE_DCB_MAX_BW_GROUP) {
318                                 ret_val = IXGBE_ERR_CONFIG;
319                                 goto err_config;
320                         }
321                         if (p->tsa == ixgbe_dcb_tsa_strict) {
322                                 link_strict[i][bw_id] = true;
323                                 /* Link strict should have zero bandwidth */
324                                 if (bw) {
325                                         ret_val = IXGBE_ERR_CONFIG;
326                                         goto err_config;
327                                 }
328                         } else if (!bw) {
329                                 /*
330                                  * Traffic classes without link strict
331                                  * should have non-zero bandwidth.
332                                  */
333                                 ret_val = IXGBE_ERR_CONFIG;
334                                 goto err_config;
335                         }
336                         bw_sum[i][bw_id] += bw;
337                 }
338
339                 bw = 0;
340
341                 /* Check each bandwidth group for rule violation */
342                 for (j = 0; j < IXGBE_DCB_MAX_BW_GROUP; j++) {
343                         bw += dcb_config->bw_percentage[i][j];
344                         /*
345                          * Sum of bandwidth percentages of all traffic classes
346                          * within a Bandwidth Group must total 100 except for
347                          * link strict group (zero bandwidth).
348                          */
349                         if (link_strict[i][j]) {
350                                 if (bw_sum[i][j]) {
351                                         /*
352                                          * Link strict group should have zero
353                                          * bandwidth.
354                                          */
355                                         ret_val = IXGBE_ERR_CONFIG;
356                                         goto err_config;
357                                 }
358                         } else if (bw_sum[i][j] != IXGBE_DCB_BW_PERCENT &&
359                                    bw_sum[i][j] != 0) {
360                                 ret_val = IXGBE_ERR_CONFIG;
361                                 goto err_config;
362                         }
363                 }
364
365                 if (bw != IXGBE_DCB_BW_PERCENT) {
366                         ret_val = IXGBE_ERR_CONFIG;
367                         goto err_config;
368                 }
369         }
370
371 err_config:
372         DEBUGOUT2("DCB error code %d while checking %s settings.\n",
373                   ret_val, (i == IXGBE_DCB_TX_CONFIG) ? "Tx" : "Rx");
374
375         return ret_val;
376 }
377
378 /**
379  * ixgbe_dcb_get_tc_stats - Returns status of each traffic class
380  * @hw: pointer to hardware structure
381  * @stats: pointer to statistics structure
382  * @tc_count:  Number of elements in bwg_array.
383  *
384  * This function returns the status data for each of the Traffic Classes in use.
385  */
386 s32 ixgbe_dcb_get_tc_stats(struct ixgbe_hw *hw, struct ixgbe_hw_stats *stats,
387                            u8 tc_count)
388 {
389         s32 ret = IXGBE_NOT_IMPLEMENTED;
390         switch (hw->mac.type) {
391         case ixgbe_mac_82598EB:
392                 ret = ixgbe_dcb_get_tc_stats_82598(hw, stats, tc_count);
393                 break;
394         case ixgbe_mac_82599EB:
395         case ixgbe_mac_X540:
396         case ixgbe_mac_X550:
397         case ixgbe_mac_X550EM_x:
398                 ret = ixgbe_dcb_get_tc_stats_82599(hw, stats, tc_count);
399                 break;
400         default:
401                 break;
402         }
403         return ret;
404 }
405
406 /**
407  * ixgbe_dcb_get_pfc_stats - Returns CBFC status of each traffic class
408  * @hw: pointer to hardware structure
409  * @stats: pointer to statistics structure
410  * @tc_count:  Number of elements in bwg_array.
411  *
412  * This function returns the CBFC status data for each of the Traffic Classes.
413  */
414 s32 ixgbe_dcb_get_pfc_stats(struct ixgbe_hw *hw, struct ixgbe_hw_stats *stats,
415                             u8 tc_count)
416 {
417         s32 ret = IXGBE_NOT_IMPLEMENTED;
418         switch (hw->mac.type) {
419         case ixgbe_mac_82598EB:
420                 ret = ixgbe_dcb_get_pfc_stats_82598(hw, stats, tc_count);
421                 break;
422         case ixgbe_mac_82599EB:
423         case ixgbe_mac_X540:
424         case ixgbe_mac_X550:
425         case ixgbe_mac_X550EM_x:
426                 ret = ixgbe_dcb_get_pfc_stats_82599(hw, stats, tc_count);
427                 break;
428         default:
429                 break;
430         }
431         return ret;
432 }
433
434 /**
435  * ixgbe_dcb_config_rx_arbiter_cee - Config Rx arbiter
436  * @hw: pointer to hardware structure
437  * @dcb_config: pointer to ixgbe_dcb_config structure
438  *
439  * Configure Rx Data Arbiter and credits for each traffic class.
440  */
441 s32 ixgbe_dcb_config_rx_arbiter_cee(struct ixgbe_hw *hw,
442                                 struct ixgbe_dcb_config *dcb_config)
443 {
444         s32 ret = IXGBE_NOT_IMPLEMENTED;
445         u8 tsa[IXGBE_DCB_MAX_TRAFFIC_CLASS]     = { 0 };
446         u8 bwgid[IXGBE_DCB_MAX_TRAFFIC_CLASS]   = { 0 };
447         u8 map[IXGBE_DCB_MAX_USER_PRIORITY]     = { 0 };
448         u16 refill[IXGBE_DCB_MAX_TRAFFIC_CLASS] = { 0 };
449         u16 max[IXGBE_DCB_MAX_TRAFFIC_CLASS]    = { 0 };
450
451         ixgbe_dcb_unpack_refill_cee(dcb_config, IXGBE_DCB_TX_CONFIG, refill);
452         ixgbe_dcb_unpack_max_cee(dcb_config, max);
453         ixgbe_dcb_unpack_bwgid_cee(dcb_config, IXGBE_DCB_TX_CONFIG, bwgid);
454         ixgbe_dcb_unpack_tsa_cee(dcb_config, IXGBE_DCB_TX_CONFIG, tsa);
455         ixgbe_dcb_unpack_map_cee(dcb_config, IXGBE_DCB_TX_CONFIG, map);
456
457         switch (hw->mac.type) {
458         case ixgbe_mac_82598EB:
459                 ret = ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max, tsa);
460                 break;
461         case ixgbe_mac_82599EB:
462         case ixgbe_mac_X540:
463         case ixgbe_mac_X550:
464         case ixgbe_mac_X550EM_x:
465                 ret = ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max, bwgid,
466                                                         tsa, map);
467                 break;
468         default:
469                 break;
470         }
471         return ret;
472 }
473
474 /**
475  * ixgbe_dcb_config_tx_desc_arbiter_cee - Config Tx Desc arbiter
476  * @hw: pointer to hardware structure
477  * @dcb_config: pointer to ixgbe_dcb_config structure
478  *
479  * Configure Tx Descriptor Arbiter and credits for each traffic class.
480  */
481 s32 ixgbe_dcb_config_tx_desc_arbiter_cee(struct ixgbe_hw *hw,
482                                      struct ixgbe_dcb_config *dcb_config)
483 {
484         s32 ret = IXGBE_NOT_IMPLEMENTED;
485         u8 tsa[IXGBE_DCB_MAX_TRAFFIC_CLASS];
486         u8 bwgid[IXGBE_DCB_MAX_TRAFFIC_CLASS];
487         u16 refill[IXGBE_DCB_MAX_TRAFFIC_CLASS];
488         u16 max[IXGBE_DCB_MAX_TRAFFIC_CLASS];
489
490         ixgbe_dcb_unpack_refill_cee(dcb_config, IXGBE_DCB_TX_CONFIG, refill);
491         ixgbe_dcb_unpack_max_cee(dcb_config, max);
492         ixgbe_dcb_unpack_bwgid_cee(dcb_config, IXGBE_DCB_TX_CONFIG, bwgid);
493         ixgbe_dcb_unpack_tsa_cee(dcb_config, IXGBE_DCB_TX_CONFIG, tsa);
494
495         switch (hw->mac.type) {
496         case ixgbe_mac_82598EB:
497                 ret = ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max,
498                                                              bwgid, tsa);
499                 break;
500         case ixgbe_mac_82599EB:
501         case ixgbe_mac_X540:
502         case ixgbe_mac_X550:
503         case ixgbe_mac_X550EM_x:
504                 ret = ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max,
505                                                              bwgid, tsa);
506                 break;
507         default:
508                 break;
509         }
510         return ret;
511 }
512
513 /**
514  * ixgbe_dcb_config_tx_data_arbiter_cee - Config Tx data arbiter
515  * @hw: pointer to hardware structure
516  * @dcb_config: pointer to ixgbe_dcb_config structure
517  *
518  * Configure Tx Data Arbiter and credits for each traffic class.
519  */
520 s32 ixgbe_dcb_config_tx_data_arbiter_cee(struct ixgbe_hw *hw,
521                                      struct ixgbe_dcb_config *dcb_config)
522 {
523         s32 ret = IXGBE_NOT_IMPLEMENTED;
524         u8 tsa[IXGBE_DCB_MAX_TRAFFIC_CLASS];
525         u8 bwgid[IXGBE_DCB_MAX_TRAFFIC_CLASS];
526         u8 map[IXGBE_DCB_MAX_USER_PRIORITY] = { 0 };
527         u16 refill[IXGBE_DCB_MAX_TRAFFIC_CLASS];
528         u16 max[IXGBE_DCB_MAX_TRAFFIC_CLASS];
529
530         ixgbe_dcb_unpack_refill_cee(dcb_config, IXGBE_DCB_TX_CONFIG, refill);
531         ixgbe_dcb_unpack_max_cee(dcb_config, max);
532         ixgbe_dcb_unpack_bwgid_cee(dcb_config, IXGBE_DCB_TX_CONFIG, bwgid);
533         ixgbe_dcb_unpack_tsa_cee(dcb_config, IXGBE_DCB_TX_CONFIG, tsa);
534         ixgbe_dcb_unpack_map_cee(dcb_config, IXGBE_DCB_TX_CONFIG, map);
535
536         switch (hw->mac.type) {
537         case ixgbe_mac_82598EB:
538                 ret = ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max,
539                                                              bwgid, tsa);
540                 break;
541         case ixgbe_mac_82599EB:
542         case ixgbe_mac_X540:
543         case ixgbe_mac_X550:
544         case ixgbe_mac_X550EM_x:
545                 ret = ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max,
546                                                              bwgid, tsa,
547                                                              map);
548                 break;
549         default:
550                 break;
551         }
552         return ret;
553 }
554
555 /**
556  * ixgbe_dcb_config_pfc_cee - Config priority flow control
557  * @hw: pointer to hardware structure
558  * @dcb_config: pointer to ixgbe_dcb_config structure
559  *
560  * Configure Priority Flow Control for each traffic class.
561  */
562 s32 ixgbe_dcb_config_pfc_cee(struct ixgbe_hw *hw,
563                          struct ixgbe_dcb_config *dcb_config)
564 {
565         s32 ret = IXGBE_NOT_IMPLEMENTED;
566         u8 pfc_en;
567         u8 map[IXGBE_DCB_MAX_USER_PRIORITY] = { 0 };
568
569         ixgbe_dcb_unpack_map_cee(dcb_config, IXGBE_DCB_TX_CONFIG, map);
570         ixgbe_dcb_unpack_pfc_cee(dcb_config, map, &pfc_en);
571
572         switch (hw->mac.type) {
573         case ixgbe_mac_82598EB:
574                 ret = ixgbe_dcb_config_pfc_82598(hw, pfc_en);
575                 break;
576         case ixgbe_mac_82599EB:
577         case ixgbe_mac_X540:
578         case ixgbe_mac_X550:
579         case ixgbe_mac_X550EM_x:
580                 ret = ixgbe_dcb_config_pfc_82599(hw, pfc_en, map);
581                 break;
582         default:
583                 break;
584         }
585         return ret;
586 }
587
588 /**
589  * ixgbe_dcb_config_tc_stats - Config traffic class statistics
590  * @hw: pointer to hardware structure
591  *
592  * Configure queue statistics registers, all queues belonging to same traffic
593  * class uses a single set of queue statistics counters.
594  */
595 s32 ixgbe_dcb_config_tc_stats(struct ixgbe_hw *hw)
596 {
597         s32 ret = IXGBE_NOT_IMPLEMENTED;
598         switch (hw->mac.type) {
599         case ixgbe_mac_82598EB:
600                 ret = ixgbe_dcb_config_tc_stats_82598(hw);
601                 break;
602         case ixgbe_mac_82599EB:
603         case ixgbe_mac_X540:
604         case ixgbe_mac_X550:
605         case ixgbe_mac_X550EM_x:
606                 ret = ixgbe_dcb_config_tc_stats_82599(hw, NULL);
607                 break;
608         default:
609                 break;
610         }
611         return ret;
612 }
613
614 /**
615  * ixgbe_dcb_hw_config_cee - Config and enable DCB
616  * @hw: pointer to hardware structure
617  * @dcb_config: pointer to ixgbe_dcb_config structure
618  *
619  * Configure dcb settings and enable dcb mode.
620  */
621 s32 ixgbe_dcb_hw_config_cee(struct ixgbe_hw *hw,
622                         struct ixgbe_dcb_config *dcb_config)
623 {
624         s32 ret = IXGBE_NOT_IMPLEMENTED;
625         u8 pfc_en;
626         u8 tsa[IXGBE_DCB_MAX_TRAFFIC_CLASS];
627         u8 bwgid[IXGBE_DCB_MAX_TRAFFIC_CLASS];
628         u8 map[IXGBE_DCB_MAX_USER_PRIORITY] = { 0 };
629         u16 refill[IXGBE_DCB_MAX_TRAFFIC_CLASS];
630         u16 max[IXGBE_DCB_MAX_TRAFFIC_CLASS];
631
632         /* Unpack CEE standard containers */
633         ixgbe_dcb_unpack_refill_cee(dcb_config, IXGBE_DCB_TX_CONFIG, refill);
634         ixgbe_dcb_unpack_max_cee(dcb_config, max);
635         ixgbe_dcb_unpack_bwgid_cee(dcb_config, IXGBE_DCB_TX_CONFIG, bwgid);
636         ixgbe_dcb_unpack_tsa_cee(dcb_config, IXGBE_DCB_TX_CONFIG, tsa);
637         ixgbe_dcb_unpack_map_cee(dcb_config, IXGBE_DCB_TX_CONFIG, map);
638
639         switch (hw->mac.type) {
640         case ixgbe_mac_82598EB:
641                 ret = ixgbe_dcb_hw_config_82598(hw, dcb_config->link_speed,
642                                                 refill, max, bwgid, tsa);
643                 break;
644         case ixgbe_mac_82599EB:
645         case ixgbe_mac_X540:
646         case ixgbe_mac_X550:
647         case ixgbe_mac_X550EM_x:
648                 ixgbe_dcb_config_82599(hw, dcb_config);
649                 ret = ixgbe_dcb_hw_config_82599(hw, dcb_config->link_speed,
650                                                 refill, max, bwgid,
651                                                 tsa, map);
652
653                 ixgbe_dcb_config_tc_stats_82599(hw, dcb_config);
654                 break;
655         default:
656                 break;
657         }
658
659         if (!ret && dcb_config->pfc_mode_enable) {
660                 ixgbe_dcb_unpack_pfc_cee(dcb_config, map, &pfc_en);
661                 ret = ixgbe_dcb_config_pfc(hw, pfc_en, map);
662         }
663
664         return ret;
665 }
666
667 /* Helper routines to abstract HW specifics from DCB netlink ops */
668 s32 ixgbe_dcb_config_pfc(struct ixgbe_hw *hw, u8 pfc_en, u8 *map)
669 {
670         int ret = IXGBE_ERR_PARAM;
671
672         switch (hw->mac.type) {
673         case ixgbe_mac_82598EB:
674                 ret = ixgbe_dcb_config_pfc_82598(hw, pfc_en);
675                 break;
676         case ixgbe_mac_82599EB:
677         case ixgbe_mac_X540:
678         case ixgbe_mac_X550:
679         case ixgbe_mac_X550EM_x:
680                 ret = ixgbe_dcb_config_pfc_82599(hw, pfc_en, map);
681                 break;
682         default:
683                 break;
684         }
685         return ret;
686 }
687
688 s32 ixgbe_dcb_hw_config(struct ixgbe_hw *hw, u16 *refill, u16 *max,
689                             u8 *bwg_id, u8 *tsa, u8 *map)
690 {
691         switch (hw->mac.type) {
692         case ixgbe_mac_82598EB:
693                 ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max, tsa);
694                 ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max, bwg_id,
695                                                        tsa);
696                 ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max, bwg_id,
697                                                        tsa);
698                 break;
699         case ixgbe_mac_82599EB:
700         case ixgbe_mac_X540:
701         case ixgbe_mac_X550:
702         case ixgbe_mac_X550EM_x:
703                 ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max, bwg_id,
704                                                   tsa, map);
705                 ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max, bwg_id,
706                                                        tsa);
707                 ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max, bwg_id,
708                                                        tsa, map);
709                 break;
710         default:
711                 break;
712         }
713         return 0;
714 }