New upstream version 18.02
[deb_dpdk.git] / drivers / net / ixgbe / base / ixgbe_dcb_82599.c
1 /*******************************************************************************
2
3 Copyright (c) 2001-2015, 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_82599.h"
38
39 /**
40  * ixgbe_dcb_get_tc_stats_82599 - Returns status for each traffic class
41  * @hw: pointer to hardware structure
42  * @stats: pointer to statistics structure
43  * @tc_count:  Number of elements in bwg_array.
44  *
45  * This function returns the status data for each of the Traffic Classes in use.
46  */
47 s32 ixgbe_dcb_get_tc_stats_82599(struct ixgbe_hw *hw,
48                                  struct ixgbe_hw_stats *stats,
49                                  u8 tc_count)
50 {
51         int tc;
52
53         DEBUGFUNC("dcb_get_tc_stats");
54
55         if (tc_count > IXGBE_DCB_MAX_TRAFFIC_CLASS)
56                 return IXGBE_ERR_PARAM;
57
58         /* Statistics pertaining to each traffic class */
59         for (tc = 0; tc < tc_count; tc++) {
60                 /* Transmitted Packets */
61                 stats->qptc[tc] += IXGBE_READ_REG(hw, IXGBE_QPTC(tc));
62                 /* Transmitted Bytes (read low first to prevent missed carry) */
63                 stats->qbtc[tc] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(tc));
64                 stats->qbtc[tc] +=
65                         (((u64)(IXGBE_READ_REG(hw, IXGBE_QBTC_H(tc)))) << 32);
66                 /* Received Packets */
67                 stats->qprc[tc] += IXGBE_READ_REG(hw, IXGBE_QPRC(tc));
68                 /* Received Bytes (read low first to prevent missed carry) */
69                 stats->qbrc[tc] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(tc));
70                 stats->qbrc[tc] +=
71                         (((u64)(IXGBE_READ_REG(hw, IXGBE_QBRC_H(tc)))) << 32);
72
73                 /* Received Dropped Packet */
74                 stats->qprdc[tc] += IXGBE_READ_REG(hw, IXGBE_QPRDC(tc));
75         }
76
77         return IXGBE_SUCCESS;
78 }
79
80 /**
81  * ixgbe_dcb_get_pfc_stats_82599 - Return CBFC status data
82  * @hw: pointer to hardware structure
83  * @stats: pointer to statistics structure
84  * @tc_count:  Number of elements in bwg_array.
85  *
86  * This function returns the CBFC status data for each of the Traffic Classes.
87  */
88 s32 ixgbe_dcb_get_pfc_stats_82599(struct ixgbe_hw *hw,
89                                   struct ixgbe_hw_stats *stats,
90                                   u8 tc_count)
91 {
92         int tc;
93
94         DEBUGFUNC("dcb_get_pfc_stats");
95
96         if (tc_count > IXGBE_DCB_MAX_TRAFFIC_CLASS)
97                 return IXGBE_ERR_PARAM;
98
99         for (tc = 0; tc < tc_count; tc++) {
100                 /* Priority XOFF Transmitted */
101                 stats->pxofftxc[tc] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(tc));
102                 /* Priority XOFF Received */
103                 stats->pxoffrxc[tc] += IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(tc));
104         }
105
106         return IXGBE_SUCCESS;
107 }
108
109 /**
110  * ixgbe_dcb_config_rx_arbiter_82599 - Config Rx Data arbiter
111  * @hw: pointer to hardware structure
112  * @refill: refill credits index by traffic class
113  * @max: max credits index by traffic class
114  * @bwg_id: bandwidth grouping indexed by traffic class
115  * @tsa: transmission selection algorithm indexed by traffic class
116  * @map: priority to tc assignments indexed by priority
117  *
118  * Configure Rx Packet Arbiter and credits for each traffic class.
119  */
120 s32 ixgbe_dcb_config_rx_arbiter_82599(struct ixgbe_hw *hw, u16 *refill,
121                                       u16 *max, u8 *bwg_id, u8 *tsa,
122                                       u8 *map)
123 {
124         u32 reg = 0;
125         u32 credit_refill = 0;
126         u32 credit_max = 0;
127         u8  i = 0;
128
129         /*
130          * Disable the arbiter before changing parameters
131          * (always enable recycle mode; WSP)
132          */
133         reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC | IXGBE_RTRPCS_ARBDIS;
134         IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg);
135
136         /*
137          * map all UPs to TCs. up_to_tc_bitmap for each TC has corresponding
138          * bits sets for the UPs that needs to be mappped to that TC.
139          * e.g if priorities 6 and 7 are to be mapped to a TC then the
140          * up_to_tc_bitmap value for that TC will be 11000000 in binary.
141          */
142         reg = 0;
143         for (i = 0; i < IXGBE_DCB_MAX_USER_PRIORITY; i++)
144                 reg |= (map[i] << (i * IXGBE_RTRUP2TC_UP_SHIFT));
145
146         IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
147
148         /* Configure traffic class credits and priority */
149         for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
150                 credit_refill = refill[i];
151                 credit_max = max[i];
152                 reg = credit_refill | (credit_max << IXGBE_RTRPT4C_MCL_SHIFT);
153
154                 reg |= (u32)(bwg_id[i]) << IXGBE_RTRPT4C_BWG_SHIFT;
155
156                 if (tsa[i] == ixgbe_dcb_tsa_strict)
157                         reg |= IXGBE_RTRPT4C_LSP;
158
159                 IXGBE_WRITE_REG(hw, IXGBE_RTRPT4C(i), reg);
160         }
161
162         /*
163          * Configure Rx packet plane (recycle mode; WSP) and
164          * enable arbiter
165          */
166         reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC;
167         IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg);
168
169         return IXGBE_SUCCESS;
170 }
171
172 /**
173  * ixgbe_dcb_config_tx_desc_arbiter_82599 - Config Tx Desc. arbiter
174  * @hw: pointer to hardware structure
175  * @refill: refill credits index by traffic class
176  * @max: max credits index by traffic class
177  * @bwg_id: bandwidth grouping indexed by traffic class
178  * @tsa: transmission selection algorithm indexed by traffic class
179  *
180  * Configure Tx Descriptor Arbiter and credits for each traffic class.
181  */
182 s32 ixgbe_dcb_config_tx_desc_arbiter_82599(struct ixgbe_hw *hw, u16 *refill,
183                                            u16 *max, u8 *bwg_id, u8 *tsa)
184 {
185         u32 reg, max_credits;
186         u8  i;
187
188         /* Clear the per-Tx queue credits; we use per-TC instead */
189         for (i = 0; i < 128; i++) {
190                 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i);
191                 IXGBE_WRITE_REG(hw, IXGBE_RTTDT1C, 0);
192         }
193
194         /* Configure traffic class credits and priority */
195         for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
196                 max_credits = max[i];
197                 reg = max_credits << IXGBE_RTTDT2C_MCL_SHIFT;
198                 reg |= refill[i];
199                 reg |= (u32)(bwg_id[i]) << IXGBE_RTTDT2C_BWG_SHIFT;
200
201                 if (tsa[i] == ixgbe_dcb_tsa_group_strict_cee)
202                         reg |= IXGBE_RTTDT2C_GSP;
203
204                 if (tsa[i] == ixgbe_dcb_tsa_strict)
205                         reg |= IXGBE_RTTDT2C_LSP;
206
207                 IXGBE_WRITE_REG(hw, IXGBE_RTTDT2C(i), reg);
208         }
209
210         /*
211          * Configure Tx descriptor plane (recycle mode; WSP) and
212          * enable arbiter
213          */
214         reg = IXGBE_RTTDCS_TDPAC | IXGBE_RTTDCS_TDRM;
215         IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
216
217         return IXGBE_SUCCESS;
218 }
219
220 /**
221  * ixgbe_dcb_config_tx_data_arbiter_82599 - Config Tx Data arbiter
222  * @hw: pointer to hardware structure
223  * @refill: refill credits index by traffic class
224  * @max: max credits index by traffic class
225  * @bwg_id: bandwidth grouping indexed by traffic class
226  * @tsa: transmission selection algorithm indexed by traffic class
227  * @map: priority to tc assignments indexed by priority
228  *
229  * Configure Tx Packet Arbiter and credits for each traffic class.
230  */
231 s32 ixgbe_dcb_config_tx_data_arbiter_82599(struct ixgbe_hw *hw, u16 *refill,
232                                            u16 *max, u8 *bwg_id, u8 *tsa,
233                                            u8 *map)
234 {
235         u32 reg;
236         u8 i;
237
238         /*
239          * Disable the arbiter before changing parameters
240          * (always enable recycle mode; SP; arb delay)
241          */
242         reg = IXGBE_RTTPCS_TPPAC | IXGBE_RTTPCS_TPRM |
243               (IXGBE_RTTPCS_ARBD_DCB << IXGBE_RTTPCS_ARBD_SHIFT) |
244               IXGBE_RTTPCS_ARBDIS;
245         IXGBE_WRITE_REG(hw, IXGBE_RTTPCS, reg);
246
247         /*
248          * map all UPs to TCs. up_to_tc_bitmap for each TC has corresponding
249          * bits sets for the UPs that needs to be mappped to that TC.
250          * e.g if priorities 6 and 7 are to be mapped to a TC then the
251          * up_to_tc_bitmap value for that TC will be 11000000 in binary.
252          */
253         reg = 0;
254         for (i = 0; i < IXGBE_DCB_MAX_USER_PRIORITY; i++)
255                 reg |= (map[i] << (i * IXGBE_RTTUP2TC_UP_SHIFT));
256
257         IXGBE_WRITE_REG(hw, IXGBE_RTTUP2TC, reg);
258
259         /* Configure traffic class credits and priority */
260         for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
261                 reg = refill[i];
262                 reg |= (u32)(max[i]) << IXGBE_RTTPT2C_MCL_SHIFT;
263                 reg |= (u32)(bwg_id[i]) << IXGBE_RTTPT2C_BWG_SHIFT;
264
265                 if (tsa[i] == ixgbe_dcb_tsa_group_strict_cee)
266                         reg |= IXGBE_RTTPT2C_GSP;
267
268                 if (tsa[i] == ixgbe_dcb_tsa_strict)
269                         reg |= IXGBE_RTTPT2C_LSP;
270
271                 IXGBE_WRITE_REG(hw, IXGBE_RTTPT2C(i), reg);
272         }
273
274         /*
275          * Configure Tx packet plane (recycle mode; SP; arb delay) and
276          * enable arbiter
277          */
278         reg = IXGBE_RTTPCS_TPPAC | IXGBE_RTTPCS_TPRM |
279               (IXGBE_RTTPCS_ARBD_DCB << IXGBE_RTTPCS_ARBD_SHIFT);
280         IXGBE_WRITE_REG(hw, IXGBE_RTTPCS, reg);
281
282         return IXGBE_SUCCESS;
283 }
284
285 /**
286  * ixgbe_dcb_config_pfc_82599 - Configure priority flow control
287  * @hw: pointer to hardware structure
288  * @pfc_en: enabled pfc bitmask
289  * @map: priority to tc assignments indexed by priority
290  *
291  * Configure Priority Flow Control (PFC) for each traffic class.
292  */
293 s32 ixgbe_dcb_config_pfc_82599(struct ixgbe_hw *hw, u8 pfc_en, u8 *map)
294 {
295         u32 i, j, fcrtl, reg;
296         u8 max_tc = 0;
297
298         /* Enable Transmit Priority Flow Control */
299         IXGBE_WRITE_REG(hw, IXGBE_FCCFG, IXGBE_FCCFG_TFCE_PRIORITY);
300
301         /* Enable Receive Priority Flow Control */
302         reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
303         reg |= IXGBE_MFLCN_DPF;
304
305         /*
306          * X540 supports per TC Rx priority flow control.  So
307          * clear all TCs and only enable those that should be
308          * enabled.
309          */
310         reg &= ~(IXGBE_MFLCN_RPFCE_MASK | IXGBE_MFLCN_RFCE);
311
312         if (hw->mac.type >= ixgbe_mac_X540)
313                 reg |= pfc_en << IXGBE_MFLCN_RPFCE_SHIFT;
314
315         if (pfc_en)
316                 reg |= IXGBE_MFLCN_RPFCE;
317
318         IXGBE_WRITE_REG(hw, IXGBE_MFLCN, reg);
319
320         for (i = 0; i < IXGBE_DCB_MAX_USER_PRIORITY; i++) {
321                 if (map[i] > max_tc)
322                         max_tc = map[i];
323         }
324
325
326         /* Configure PFC Tx thresholds per TC */
327         for (i = 0; i <= max_tc; i++) {
328                 int enabled = 0;
329
330                 for (j = 0; j < IXGBE_DCB_MAX_USER_PRIORITY; j++) {
331                         if ((map[j] == i) && (pfc_en & (1 << j))) {
332                                 enabled = 1;
333                                 break;
334                         }
335                 }
336
337                 if (enabled) {
338                         reg = (hw->fc.high_water[i] << 10) | IXGBE_FCRTH_FCEN;
339                         fcrtl = (hw->fc.low_water[i] << 10) | IXGBE_FCRTL_XONE;
340                         IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), fcrtl);
341                 } else {
342                         /*
343                          * In order to prevent Tx hangs when the internal Tx
344                          * switch is enabled we must set the high water mark
345                          * to the Rx packet buffer size - 24KB.  This allows
346                          * the Tx switch to function even under heavy Rx
347                          * workloads.
348                          */
349                         reg = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)) - 24576;
350                         IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
351                 }
352
353                 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), reg);
354         }
355
356         for (; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
357                 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
358                 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), 0);
359         }
360
361         /* Configure pause time (2 TCs per register) */
362         reg = hw->fc.pause_time | (hw->fc.pause_time << 16);
363         for (i = 0; i < (IXGBE_DCB_MAX_TRAFFIC_CLASS / 2); i++)
364                 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
365
366         /* Configure flow control refresh threshold value */
367         IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
368
369         return IXGBE_SUCCESS;
370 }
371
372 /**
373  * ixgbe_dcb_config_tc_stats_82599 - Config traffic class statistics
374  * @hw: pointer to hardware structure
375  * @dcb_config: pointer to ixgbe_dcb_config structure
376  *
377  * Configure queue statistics registers, all queues belonging to same traffic
378  * class uses a single set of queue statistics counters.
379  */
380 s32 ixgbe_dcb_config_tc_stats_82599(struct ixgbe_hw *hw,
381                                     struct ixgbe_dcb_config *dcb_config)
382 {
383         u32 reg = 0;
384         u8  i   = 0;
385         u8 tc_count = 8;
386         bool vt_mode = false;
387
388         if (dcb_config != NULL) {
389                 tc_count = dcb_config->num_tcs.pg_tcs;
390                 vt_mode = dcb_config->vt_mode;
391         }
392
393         if (!((tc_count == 8 && vt_mode == false) || tc_count == 4))
394                 return IXGBE_ERR_PARAM;
395
396         if (tc_count == 8 && vt_mode == false) {
397                 /*
398                  * Receive Queues stats setting
399                  * 32 RQSMR registers, each configuring 4 queues.
400                  *
401                  * Set all 16 queues of each TC to the same stat
402                  * with TC 'n' going to stat 'n'.
403                  */
404                 for (i = 0; i < 32; i++) {
405                         reg = 0x01010101 * (i / 4);
406                         IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), reg);
407                 }
408                 /*
409                  * Transmit Queues stats setting
410                  * 32 TQSM registers, each controlling 4 queues.
411                  *
412                  * Set all queues of each TC to the same stat
413                  * with TC 'n' going to stat 'n'.
414                  * Tx queues are allocated non-uniformly to TCs:
415                  * 32, 32, 16, 16, 8, 8, 8, 8.
416                  */
417                 for (i = 0; i < 32; i++) {
418                         if (i < 8)
419                                 reg = 0x00000000;
420                         else if (i < 16)
421                                 reg = 0x01010101;
422                         else if (i < 20)
423                                 reg = 0x02020202;
424                         else if (i < 24)
425                                 reg = 0x03030303;
426                         else if (i < 26)
427                                 reg = 0x04040404;
428                         else if (i < 28)
429                                 reg = 0x05050505;
430                         else if (i < 30)
431                                 reg = 0x06060606;
432                         else
433                                 reg = 0x07070707;
434                         IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), reg);
435                 }
436         } else if (tc_count == 4 && vt_mode == false) {
437                 /*
438                  * Receive Queues stats setting
439                  * 32 RQSMR registers, each configuring 4 queues.
440                  *
441                  * Set all 16 queues of each TC to the same stat
442                  * with TC 'n' going to stat 'n'.
443                  */
444                 for (i = 0; i < 32; i++) {
445                         if (i % 8 > 3)
446                                 /* In 4 TC mode, odd 16-queue ranges are
447                                  *  not used.
448                                 */
449                                 continue;
450                         reg = 0x01010101 * (i / 8);
451                         IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), reg);
452                 }
453                 /*
454                  * Transmit Queues stats setting
455                  * 32 TQSM registers, each controlling 4 queues.
456                  *
457                  * Set all queues of each TC to the same stat
458                  * with TC 'n' going to stat 'n'.
459                  * Tx queues are allocated non-uniformly to TCs:
460                  * 64, 32, 16, 16.
461                  */
462                 for (i = 0; i < 32; i++) {
463                         if (i < 16)
464                                 reg = 0x00000000;
465                         else if (i < 24)
466                                 reg = 0x01010101;
467                         else if (i < 28)
468                                 reg = 0x02020202;
469                         else
470                                 reg = 0x03030303;
471                         IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), reg);
472                 }
473         } else if (tc_count == 4 && vt_mode == true) {
474                 /*
475                  * Receive Queues stats setting
476                  * 32 RQSMR registers, each configuring 4 queues.
477                  *
478                  * Queue Indexing in 32 VF with DCB mode maps 4 TC's to each
479                  * pool. Set all 32 queues of each TC across pools to the same
480                  * stat with TC 'n' going to stat 'n'.
481                  */
482                 for (i = 0; i < 32; i++)
483                         IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), 0x03020100);
484                 /*
485                  * Transmit Queues stats setting
486                  * 32 TQSM registers, each controlling 4 queues.
487                  *
488                  * Queue Indexing in 32 VF with DCB mode maps 4 TC's to each
489                  * pool. Set all 32 queues of each TC across pools to the same
490                  * stat with TC 'n' going to stat 'n'.
491                  */
492                 for (i = 0; i < 32; i++)
493                         IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), 0x03020100);
494         }
495
496         return IXGBE_SUCCESS;
497 }
498
499 /**
500  * ixgbe_dcb_config_82599 - Configure general DCB parameters
501  * @hw: pointer to hardware structure
502  * @dcb_config: pointer to ixgbe_dcb_config structure
503  *
504  * Configure general DCB parameters.
505  */
506 s32 ixgbe_dcb_config_82599(struct ixgbe_hw *hw,
507                            struct ixgbe_dcb_config *dcb_config)
508 {
509         u32 reg;
510         u32 q;
511
512         /* Disable the Tx desc arbiter so that MTQC can be changed */
513         reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
514         reg |= IXGBE_RTTDCS_ARBDIS;
515         IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
516
517         reg = IXGBE_READ_REG(hw, IXGBE_MRQC);
518         if (dcb_config->num_tcs.pg_tcs == 8) {
519                 /* Enable DCB for Rx with 8 TCs */
520                 switch (reg & IXGBE_MRQC_MRQE_MASK) {
521                 case 0:
522                 case IXGBE_MRQC_RT4TCEN:
523                         /* RSS disabled cases */
524                         reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
525                               IXGBE_MRQC_RT8TCEN;
526                         break;
527                 case IXGBE_MRQC_RSSEN:
528                 case IXGBE_MRQC_RTRSS4TCEN:
529                         /* RSS enabled cases */
530                         reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
531                               IXGBE_MRQC_RTRSS8TCEN;
532                         break;
533                 default:
534                         /*
535                          * Unsupported value, assume stale data,
536                          * overwrite no RSS
537                          */
538                         ASSERT(0);
539                         reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
540                               IXGBE_MRQC_RT8TCEN;
541                 }
542         }
543         if (dcb_config->num_tcs.pg_tcs == 4) {
544                 /* We support both VT-on and VT-off with 4 TCs. */
545                 if (dcb_config->vt_mode)
546                         reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
547                               IXGBE_MRQC_VMDQRT4TCEN;
548                 else
549                         reg = (reg & ~IXGBE_MRQC_MRQE_MASK) |
550                               IXGBE_MRQC_RTRSS4TCEN;
551         }
552         IXGBE_WRITE_REG(hw, IXGBE_MRQC, reg);
553
554         /* Enable DCB for Tx with 8 TCs */
555         if (dcb_config->num_tcs.pg_tcs == 8)
556                 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
557         else {
558                 /* We support both VT-on and VT-off with 4 TCs. */
559                 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
560                 if (dcb_config->vt_mode)
561                         reg |= IXGBE_MTQC_VT_ENA;
562         }
563         IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
564
565         /* Disable drop for all queues */
566         for (q = 0; q < 128; q++)
567                 IXGBE_WRITE_REG(hw, IXGBE_QDE,
568                                 (IXGBE_QDE_WRITE | (q << IXGBE_QDE_IDX_SHIFT)));
569
570         /* Enable the Tx desc arbiter */
571         reg = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
572         reg &= ~IXGBE_RTTDCS_ARBDIS;
573         IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
574
575         /* Enable Security TX Buffer IFG for DCB */
576         reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
577         reg |= IXGBE_SECTX_DCB;
578         IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
579
580         return IXGBE_SUCCESS;
581 }
582
583 /**
584  * ixgbe_dcb_hw_config_82599 - Configure and enable DCB
585  * @hw: pointer to hardware structure
586  * @link_speed: unused
587  * @refill: refill credits index by traffic class
588  * @max: max credits index by traffic class
589  * @bwg_id: bandwidth grouping indexed by traffic class
590  * @tsa: transmission selection algorithm indexed by traffic class
591  * @map: priority to tc assignments indexed by priority
592  *
593  * Configure dcb settings and enable dcb mode.
594  */
595 s32 ixgbe_dcb_hw_config_82599(struct ixgbe_hw *hw, int link_speed,
596                               u16 *refill, u16 *max, u8 *bwg_id, u8 *tsa,
597                               u8 *map)
598 {
599         UNREFERENCED_1PARAMETER(link_speed);
600
601         ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max, bwg_id, tsa,
602                                           map);
603         ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max, bwg_id,
604                                                tsa);
605         ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max, bwg_id,
606                                                tsa, map);
607
608         return IXGBE_SUCCESS;
609 }
610