1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2020 Intel Corporation
6 #include "ixgbe_type.h"
8 #include "ixgbe_dcb_82599.h"
11 * ixgbe_dcb_get_tc_stats_82599 - Returns status for each traffic class
12 * @hw: pointer to hardware structure
13 * @stats: pointer to statistics structure
14 * @tc_count: Number of elements in bwg_array.
16 * This function returns the status data for each of the Traffic Classes in use.
18 s32
ixgbe_dcb_get_tc_stats_82599(struct ixgbe_hw
*hw
,
19 struct ixgbe_hw_stats
*stats
,
24 DEBUGFUNC("dcb_get_tc_stats");
26 if (tc_count
> IXGBE_DCB_MAX_TRAFFIC_CLASS
)
27 return IXGBE_ERR_PARAM
;
29 /* Statistics pertaining to each traffic class */
30 for (tc
= 0; tc
< tc_count
; tc
++) {
31 /* Transmitted Packets */
32 stats
->qptc
[tc
] += IXGBE_READ_REG(hw
, IXGBE_QPTC(tc
));
33 /* Transmitted Bytes (read low first to prevent missed carry) */
34 stats
->qbtc
[tc
] += IXGBE_READ_REG(hw
, IXGBE_QBTC_L(tc
));
36 (((u64
)(IXGBE_READ_REG(hw
, IXGBE_QBTC_H(tc
)))) << 32);
37 /* Received Packets */
38 stats
->qprc
[tc
] += IXGBE_READ_REG(hw
, IXGBE_QPRC(tc
));
39 /* Received Bytes (read low first to prevent missed carry) */
40 stats
->qbrc
[tc
] += IXGBE_READ_REG(hw
, IXGBE_QBRC_L(tc
));
42 (((u64
)(IXGBE_READ_REG(hw
, IXGBE_QBRC_H(tc
)))) << 32);
44 /* Received Dropped Packet */
45 stats
->qprdc
[tc
] += IXGBE_READ_REG(hw
, IXGBE_QPRDC(tc
));
52 * ixgbe_dcb_get_pfc_stats_82599 - Return CBFC status data
53 * @hw: pointer to hardware structure
54 * @stats: pointer to statistics structure
55 * @tc_count: Number of elements in bwg_array.
57 * This function returns the CBFC status data for each of the Traffic Classes.
59 s32
ixgbe_dcb_get_pfc_stats_82599(struct ixgbe_hw
*hw
,
60 struct ixgbe_hw_stats
*stats
,
65 DEBUGFUNC("dcb_get_pfc_stats");
67 if (tc_count
> IXGBE_DCB_MAX_TRAFFIC_CLASS
)
68 return IXGBE_ERR_PARAM
;
70 for (tc
= 0; tc
< tc_count
; tc
++) {
71 /* Priority XOFF Transmitted */
72 stats
->pxofftxc
[tc
] += IXGBE_READ_REG(hw
, IXGBE_PXOFFTXC(tc
));
73 /* Priority XOFF Received */
74 stats
->pxoffrxc
[tc
] += IXGBE_READ_REG(hw
, IXGBE_PXOFFRXCNT(tc
));
81 * ixgbe_dcb_config_rx_arbiter_82599 - Config Rx Data arbiter
82 * @hw: pointer to hardware structure
83 * @refill: refill credits index by traffic class
84 * @max: max credits index by traffic class
85 * @bwg_id: bandwidth grouping indexed by traffic class
86 * @tsa: transmission selection algorithm indexed by traffic class
87 * @map: priority to tc assignments indexed by priority
89 * Configure Rx Packet Arbiter and credits for each traffic class.
91 s32
ixgbe_dcb_config_rx_arbiter_82599(struct ixgbe_hw
*hw
, u16
*refill
,
92 u16
*max
, u8
*bwg_id
, u8
*tsa
,
96 u32 credit_refill
= 0;
101 * Disable the arbiter before changing parameters
102 * (always enable recycle mode; WSP)
104 reg
= IXGBE_RTRPCS_RRM
| IXGBE_RTRPCS_RAC
| IXGBE_RTRPCS_ARBDIS
;
105 IXGBE_WRITE_REG(hw
, IXGBE_RTRPCS
, reg
);
108 * map all UPs to TCs. up_to_tc_bitmap for each TC has corresponding
109 * bits sets for the UPs that needs to be mappped to that TC.
110 * e.g if priorities 6 and 7 are to be mapped to a TC then the
111 * up_to_tc_bitmap value for that TC will be 11000000 in binary.
114 for (i
= 0; i
< IXGBE_DCB_MAX_USER_PRIORITY
; i
++)
115 reg
|= (map
[i
] << (i
* IXGBE_RTRUP2TC_UP_SHIFT
));
117 IXGBE_WRITE_REG(hw
, IXGBE_RTRUP2TC
, reg
);
119 /* Configure traffic class credits and priority */
120 for (i
= 0; i
< IXGBE_DCB_MAX_TRAFFIC_CLASS
; i
++) {
121 credit_refill
= refill
[i
];
123 reg
= credit_refill
| (credit_max
<< IXGBE_RTRPT4C_MCL_SHIFT
);
125 reg
|= (u32
)(bwg_id
[i
]) << IXGBE_RTRPT4C_BWG_SHIFT
;
127 if (tsa
[i
] == ixgbe_dcb_tsa_strict
)
128 reg
|= IXGBE_RTRPT4C_LSP
;
130 IXGBE_WRITE_REG(hw
, IXGBE_RTRPT4C(i
), reg
);
134 * Configure Rx packet plane (recycle mode; WSP) and
137 reg
= IXGBE_RTRPCS_RRM
| IXGBE_RTRPCS_RAC
;
138 IXGBE_WRITE_REG(hw
, IXGBE_RTRPCS
, reg
);
140 return IXGBE_SUCCESS
;
144 * ixgbe_dcb_config_tx_desc_arbiter_82599 - Config Tx Desc. arbiter
145 * @hw: pointer to hardware structure
146 * @refill: refill credits index by traffic class
147 * @max: max credits index by traffic class
148 * @bwg_id: bandwidth grouping indexed by traffic class
149 * @tsa: transmission selection algorithm indexed by traffic class
151 * Configure Tx Descriptor Arbiter and credits for each traffic class.
153 s32
ixgbe_dcb_config_tx_desc_arbiter_82599(struct ixgbe_hw
*hw
, u16
*refill
,
154 u16
*max
, u8
*bwg_id
, u8
*tsa
)
156 u32 reg
, max_credits
;
159 /* Clear the per-Tx queue credits; we use per-TC instead */
160 for (i
= 0; i
< 128; i
++) {
161 IXGBE_WRITE_REG(hw
, IXGBE_RTTDQSEL
, i
);
162 IXGBE_WRITE_REG(hw
, IXGBE_RTTDT1C
, 0);
165 /* Configure traffic class credits and priority */
166 for (i
= 0; i
< IXGBE_DCB_MAX_TRAFFIC_CLASS
; i
++) {
167 max_credits
= max
[i
];
168 reg
= max_credits
<< IXGBE_RTTDT2C_MCL_SHIFT
;
170 reg
|= (u32
)(bwg_id
[i
]) << IXGBE_RTTDT2C_BWG_SHIFT
;
172 if (tsa
[i
] == ixgbe_dcb_tsa_group_strict_cee
)
173 reg
|= IXGBE_RTTDT2C_GSP
;
175 if (tsa
[i
] == ixgbe_dcb_tsa_strict
)
176 reg
|= IXGBE_RTTDT2C_LSP
;
178 IXGBE_WRITE_REG(hw
, IXGBE_RTTDT2C(i
), reg
);
182 * Configure Tx descriptor plane (recycle mode; WSP) and
185 reg
= IXGBE_RTTDCS_TDPAC
| IXGBE_RTTDCS_TDRM
;
186 IXGBE_WRITE_REG(hw
, IXGBE_RTTDCS
, reg
);
188 return IXGBE_SUCCESS
;
192 * ixgbe_dcb_config_tx_data_arbiter_82599 - Config Tx Data arbiter
193 * @hw: pointer to hardware structure
194 * @refill: refill credits index by traffic class
195 * @max: max credits index by traffic class
196 * @bwg_id: bandwidth grouping indexed by traffic class
197 * @tsa: transmission selection algorithm indexed by traffic class
198 * @map: priority to tc assignments indexed by priority
200 * Configure Tx Packet Arbiter and credits for each traffic class.
202 s32
ixgbe_dcb_config_tx_data_arbiter_82599(struct ixgbe_hw
*hw
, u16
*refill
,
203 u16
*max
, u8
*bwg_id
, u8
*tsa
,
210 * Disable the arbiter before changing parameters
211 * (always enable recycle mode; SP; arb delay)
213 reg
= IXGBE_RTTPCS_TPPAC
| IXGBE_RTTPCS_TPRM
|
214 (IXGBE_RTTPCS_ARBD_DCB
<< IXGBE_RTTPCS_ARBD_SHIFT
) |
216 IXGBE_WRITE_REG(hw
, IXGBE_RTTPCS
, reg
);
219 * map all UPs to TCs. up_to_tc_bitmap for each TC has corresponding
220 * bits sets for the UPs that needs to be mappped to that TC.
221 * e.g if priorities 6 and 7 are to be mapped to a TC then the
222 * up_to_tc_bitmap value for that TC will be 11000000 in binary.
225 for (i
= 0; i
< IXGBE_DCB_MAX_USER_PRIORITY
; i
++)
226 reg
|= (map
[i
] << (i
* IXGBE_RTTUP2TC_UP_SHIFT
));
228 IXGBE_WRITE_REG(hw
, IXGBE_RTTUP2TC
, reg
);
230 /* Configure traffic class credits and priority */
231 for (i
= 0; i
< IXGBE_DCB_MAX_TRAFFIC_CLASS
; i
++) {
233 reg
|= (u32
)(max
[i
]) << IXGBE_RTTPT2C_MCL_SHIFT
;
234 reg
|= (u32
)(bwg_id
[i
]) << IXGBE_RTTPT2C_BWG_SHIFT
;
236 if (tsa
[i
] == ixgbe_dcb_tsa_group_strict_cee
)
237 reg
|= IXGBE_RTTPT2C_GSP
;
239 if (tsa
[i
] == ixgbe_dcb_tsa_strict
)
240 reg
|= IXGBE_RTTPT2C_LSP
;
242 IXGBE_WRITE_REG(hw
, IXGBE_RTTPT2C(i
), reg
);
246 * Configure Tx packet plane (recycle mode; SP; arb delay) and
249 reg
= IXGBE_RTTPCS_TPPAC
| IXGBE_RTTPCS_TPRM
|
250 (IXGBE_RTTPCS_ARBD_DCB
<< IXGBE_RTTPCS_ARBD_SHIFT
);
251 IXGBE_WRITE_REG(hw
, IXGBE_RTTPCS
, reg
);
253 return IXGBE_SUCCESS
;
257 * ixgbe_dcb_config_pfc_82599 - Configure priority flow control
258 * @hw: pointer to hardware structure
259 * @pfc_en: enabled pfc bitmask
260 * @map: priority to tc assignments indexed by priority
262 * Configure Priority Flow Control (PFC) for each traffic class.
264 s32
ixgbe_dcb_config_pfc_82599(struct ixgbe_hw
*hw
, u8 pfc_en
, u8
*map
)
266 u32 i
, j
, fcrtl
, reg
;
269 /* Enable Transmit Priority Flow Control */
270 IXGBE_WRITE_REG(hw
, IXGBE_FCCFG
, IXGBE_FCCFG_TFCE_PRIORITY
);
272 /* Enable Receive Priority Flow Control */
273 reg
= IXGBE_READ_REG(hw
, IXGBE_MFLCN
);
274 reg
|= IXGBE_MFLCN_DPF
;
277 * X540 supports per TC Rx priority flow control. So
278 * clear all TCs and only enable those that should be
281 reg
&= ~(IXGBE_MFLCN_RPFCE_MASK
| IXGBE_MFLCN_RFCE
);
283 if (hw
->mac
.type
>= ixgbe_mac_X540
)
284 reg
|= pfc_en
<< IXGBE_MFLCN_RPFCE_SHIFT
;
287 reg
|= IXGBE_MFLCN_RPFCE
;
289 IXGBE_WRITE_REG(hw
, IXGBE_MFLCN
, reg
);
291 for (i
= 0; i
< IXGBE_DCB_MAX_USER_PRIORITY
; i
++) {
297 /* Configure PFC Tx thresholds per TC */
298 for (i
= 0; i
<= max_tc
; i
++) {
301 for (j
= 0; j
< IXGBE_DCB_MAX_USER_PRIORITY
; j
++) {
302 if ((map
[j
] == i
) && (pfc_en
& (1 << j
))) {
309 reg
= (hw
->fc
.high_water
[i
] << 10) | IXGBE_FCRTH_FCEN
;
310 fcrtl
= (hw
->fc
.low_water
[i
] << 10) | IXGBE_FCRTL_XONE
;
311 IXGBE_WRITE_REG(hw
, IXGBE_FCRTL_82599(i
), fcrtl
);
314 * In order to prevent Tx hangs when the internal Tx
315 * switch is enabled we must set the high water mark
316 * to the Rx packet buffer size - 24KB. This allows
317 * the Tx switch to function even under heavy Rx
320 reg
= IXGBE_READ_REG(hw
, IXGBE_RXPBSIZE(i
)) - 24576;
321 IXGBE_WRITE_REG(hw
, IXGBE_FCRTL_82599(i
), 0);
324 IXGBE_WRITE_REG(hw
, IXGBE_FCRTH_82599(i
), reg
);
327 for (; i
< IXGBE_DCB_MAX_TRAFFIC_CLASS
; i
++) {
328 IXGBE_WRITE_REG(hw
, IXGBE_FCRTL_82599(i
), 0);
329 IXGBE_WRITE_REG(hw
, IXGBE_FCRTH_82599(i
), 0);
332 /* Configure pause time (2 TCs per register) */
333 reg
= hw
->fc
.pause_time
| (hw
->fc
.pause_time
<< 16);
334 for (i
= 0; i
< (IXGBE_DCB_MAX_TRAFFIC_CLASS
/ 2); i
++)
335 IXGBE_WRITE_REG(hw
, IXGBE_FCTTV(i
), reg
);
337 /* Configure flow control refresh threshold value */
338 IXGBE_WRITE_REG(hw
, IXGBE_FCRTV
, hw
->fc
.pause_time
/ 2);
340 return IXGBE_SUCCESS
;
344 * ixgbe_dcb_config_tc_stats_82599 - Config traffic class statistics
345 * @hw: pointer to hardware structure
346 * @dcb_config: pointer to ixgbe_dcb_config structure
348 * Configure queue statistics registers, all queues belonging to same traffic
349 * class uses a single set of queue statistics counters.
351 s32
ixgbe_dcb_config_tc_stats_82599(struct ixgbe_hw
*hw
,
352 struct ixgbe_dcb_config
*dcb_config
)
357 bool vt_mode
= false;
359 if (dcb_config
!= NULL
) {
360 tc_count
= dcb_config
->num_tcs
.pg_tcs
;
361 vt_mode
= dcb_config
->vt_mode
;
364 if (!((tc_count
== 8 && vt_mode
== false) || tc_count
== 4))
365 return IXGBE_ERR_PARAM
;
367 if (tc_count
== 8 && vt_mode
== false) {
369 * Receive Queues stats setting
370 * 32 RQSMR registers, each configuring 4 queues.
372 * Set all 16 queues of each TC to the same stat
373 * with TC 'n' going to stat 'n'.
375 for (i
= 0; i
< 32; i
++) {
376 reg
= 0x01010101 * (i
/ 4);
377 IXGBE_WRITE_REG(hw
, IXGBE_RQSMR(i
), reg
);
380 * Transmit Queues stats setting
381 * 32 TQSM registers, each controlling 4 queues.
383 * Set all queues of each TC to the same stat
384 * with TC 'n' going to stat 'n'.
385 * Tx queues are allocated non-uniformly to TCs:
386 * 32, 32, 16, 16, 8, 8, 8, 8.
388 for (i
= 0; i
< 32; i
++) {
405 IXGBE_WRITE_REG(hw
, IXGBE_TQSM(i
), reg
);
407 } else if (tc_count
== 4 && vt_mode
== false) {
409 * Receive Queues stats setting
410 * 32 RQSMR registers, each configuring 4 queues.
412 * Set all 16 queues of each TC to the same stat
413 * with TC 'n' going to stat 'n'.
415 for (i
= 0; i
< 32; i
++) {
417 /* In 4 TC mode, odd 16-queue ranges are
421 reg
= 0x01010101 * (i
/ 8);
422 IXGBE_WRITE_REG(hw
, IXGBE_RQSMR(i
), reg
);
425 * Transmit Queues stats setting
426 * 32 TQSM registers, each controlling 4 queues.
428 * Set all queues of each TC to the same stat
429 * with TC 'n' going to stat 'n'.
430 * Tx queues are allocated non-uniformly to TCs:
433 for (i
= 0; i
< 32; i
++) {
442 IXGBE_WRITE_REG(hw
, IXGBE_TQSM(i
), reg
);
444 } else if (tc_count
== 4 && vt_mode
== true) {
446 * Receive Queues stats setting
447 * 32 RQSMR registers, each configuring 4 queues.
449 * Queue Indexing in 32 VF with DCB mode maps 4 TC's to each
450 * pool. Set all 32 queues of each TC across pools to the same
451 * stat with TC 'n' going to stat 'n'.
453 for (i
= 0; i
< 32; i
++)
454 IXGBE_WRITE_REG(hw
, IXGBE_RQSMR(i
), 0x03020100);
456 * Transmit Queues stats setting
457 * 32 TQSM registers, each controlling 4 queues.
459 * Queue Indexing in 32 VF with DCB mode maps 4 TC's to each
460 * pool. Set all 32 queues of each TC across pools to the same
461 * stat with TC 'n' going to stat 'n'.
463 for (i
= 0; i
< 32; i
++)
464 IXGBE_WRITE_REG(hw
, IXGBE_TQSM(i
), 0x03020100);
467 return IXGBE_SUCCESS
;
471 * ixgbe_dcb_config_82599 - Configure general DCB parameters
472 * @hw: pointer to hardware structure
473 * @dcb_config: pointer to ixgbe_dcb_config structure
475 * Configure general DCB parameters.
477 s32
ixgbe_dcb_config_82599(struct ixgbe_hw
*hw
,
478 struct ixgbe_dcb_config
*dcb_config
)
483 /* Disable the Tx desc arbiter so that MTQC can be changed */
484 reg
= IXGBE_READ_REG(hw
, IXGBE_RTTDCS
);
485 reg
|= IXGBE_RTTDCS_ARBDIS
;
486 IXGBE_WRITE_REG(hw
, IXGBE_RTTDCS
, reg
);
488 reg
= IXGBE_READ_REG(hw
, IXGBE_MRQC
);
489 if (dcb_config
->num_tcs
.pg_tcs
== 8) {
490 /* Enable DCB for Rx with 8 TCs */
491 switch (reg
& IXGBE_MRQC_MRQE_MASK
) {
493 case IXGBE_MRQC_RT4TCEN
:
494 /* RSS disabled cases */
495 reg
= (reg
& ~IXGBE_MRQC_MRQE_MASK
) |
498 case IXGBE_MRQC_RSSEN
:
499 case IXGBE_MRQC_RTRSS4TCEN
:
500 /* RSS enabled cases */
501 reg
= (reg
& ~IXGBE_MRQC_MRQE_MASK
) |
502 IXGBE_MRQC_RTRSS8TCEN
;
506 * Unsupported value, assume stale data,
510 reg
= (reg
& ~IXGBE_MRQC_MRQE_MASK
) |
514 if (dcb_config
->num_tcs
.pg_tcs
== 4) {
515 /* We support both VT-on and VT-off with 4 TCs. */
516 if (dcb_config
->vt_mode
)
517 reg
= (reg
& ~IXGBE_MRQC_MRQE_MASK
) |
518 IXGBE_MRQC_VMDQRT4TCEN
;
520 reg
= (reg
& ~IXGBE_MRQC_MRQE_MASK
) |
521 IXGBE_MRQC_RTRSS4TCEN
;
523 IXGBE_WRITE_REG(hw
, IXGBE_MRQC
, reg
);
525 /* Enable DCB for Tx with 8 TCs */
526 if (dcb_config
->num_tcs
.pg_tcs
== 8)
527 reg
= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_8TC_8TQ
;
529 /* We support both VT-on and VT-off with 4 TCs. */
530 reg
= IXGBE_MTQC_RT_ENA
| IXGBE_MTQC_4TC_4TQ
;
531 if (dcb_config
->vt_mode
)
532 reg
|= IXGBE_MTQC_VT_ENA
;
534 IXGBE_WRITE_REG(hw
, IXGBE_MTQC
, reg
);
536 /* Disable drop for all queues */
537 for (q
= 0; q
< 128; q
++)
538 IXGBE_WRITE_REG(hw
, IXGBE_QDE
,
539 (IXGBE_QDE_WRITE
| (q
<< IXGBE_QDE_IDX_SHIFT
)));
541 /* Enable the Tx desc arbiter */
542 reg
= IXGBE_READ_REG(hw
, IXGBE_RTTDCS
);
543 reg
&= ~IXGBE_RTTDCS_ARBDIS
;
544 IXGBE_WRITE_REG(hw
, IXGBE_RTTDCS
, reg
);
546 /* Enable Security TX Buffer IFG for DCB */
547 reg
= IXGBE_READ_REG(hw
, IXGBE_SECTXMINIFG
);
548 reg
|= IXGBE_SECTX_DCB
;
549 IXGBE_WRITE_REG(hw
, IXGBE_SECTXMINIFG
, reg
);
551 return IXGBE_SUCCESS
;
555 * ixgbe_dcb_hw_config_82599 - Configure and enable DCB
556 * @hw: pointer to hardware structure
557 * @link_speed: unused
558 * @refill: refill credits index by traffic class
559 * @max: max credits index by traffic class
560 * @bwg_id: bandwidth grouping indexed by traffic class
561 * @tsa: transmission selection algorithm indexed by traffic class
562 * @map: priority to tc assignments indexed by priority
564 * Configure dcb settings and enable dcb mode.
566 s32
ixgbe_dcb_hw_config_82599(struct ixgbe_hw
*hw
, int link_speed
,
567 u16
*refill
, u16
*max
, u8
*bwg_id
, u8
*tsa
,
570 UNREFERENCED_1PARAMETER(link_speed
);
572 ixgbe_dcb_config_rx_arbiter_82599(hw
, refill
, max
, bwg_id
, tsa
,
574 ixgbe_dcb_config_tx_desc_arbiter_82599(hw
, refill
, max
, bwg_id
,
576 ixgbe_dcb_config_tx_data_arbiter_82599(hw
, refill
, max
, bwg_id
,
579 return IXGBE_SUCCESS
;