1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright(c) 1999 - 2018 Intel Corporation. */
5 #include "ixgbe_type.h"
7 #include "ixgbe_dcb_82599.h"
10 * ixgbe_dcb_config_rx_arbiter_82599 - Config Rx Data arbiter
11 * @hw: pointer to hardware structure
12 * @refill: refill credits index by traffic class
13 * @max: max credits index by traffic class
14 * @bwg_id: bandwidth grouping indexed by traffic class
15 * @prio_type: priority type indexed by traffic class
16 * @prio_tc: priority to tc assignments indexed by priority
18 * Configure Rx Packet Arbiter and credits for each traffic class.
20 s32
ixgbe_dcb_config_rx_arbiter_82599(struct ixgbe_hw
*hw
,
28 u32 credit_refill
= 0;
33 * Disable the arbiter before changing parameters
34 * (always enable recycle mode; WSP)
36 reg
= IXGBE_RTRPCS_RRM
| IXGBE_RTRPCS_RAC
| IXGBE_RTRPCS_ARBDIS
;
37 IXGBE_WRITE_REG(hw
, IXGBE_RTRPCS
, reg
);
39 /* Map all traffic classes to their UP */
41 for (i
= 0; i
< MAX_USER_PRIORITY
; i
++)
42 reg
|= (prio_tc
[i
] << (i
* IXGBE_RTRUP2TC_UP_SHIFT
));
43 IXGBE_WRITE_REG(hw
, IXGBE_RTRUP2TC
, reg
);
45 /* Configure traffic class credits and priority */
46 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
47 credit_refill
= refill
[i
];
49 reg
= credit_refill
| (credit_max
<< IXGBE_RTRPT4C_MCL_SHIFT
);
51 reg
|= (u32
)(bwg_id
[i
]) << IXGBE_RTRPT4C_BWG_SHIFT
;
53 if (prio_type
[i
] == prio_link
)
54 reg
|= IXGBE_RTRPT4C_LSP
;
56 IXGBE_WRITE_REG(hw
, IXGBE_RTRPT4C(i
), reg
);
60 * Configure Rx packet plane (recycle mode; WSP) and
63 reg
= IXGBE_RTRPCS_RRM
| IXGBE_RTRPCS_RAC
;
64 IXGBE_WRITE_REG(hw
, IXGBE_RTRPCS
, reg
);
70 * ixgbe_dcb_config_tx_desc_arbiter_82599 - Config Tx Desc. arbiter
71 * @hw: pointer to hardware structure
72 * @refill: refill credits index by traffic class
73 * @max: max credits index by traffic class
74 * @bwg_id: bandwidth grouping indexed by traffic class
75 * @prio_type: priority type indexed by traffic class
77 * Configure Tx Descriptor Arbiter and credits for each traffic class.
79 s32
ixgbe_dcb_config_tx_desc_arbiter_82599(struct ixgbe_hw
*hw
,
88 /* Clear the per-Tx queue credits; we use per-TC instead */
89 for (i
= 0; i
< 128; i
++) {
90 IXGBE_WRITE_REG(hw
, IXGBE_RTTDQSEL
, i
);
91 IXGBE_WRITE_REG(hw
, IXGBE_RTTDT1C
, 0);
94 /* Configure traffic class credits and priority */
95 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
97 reg
= max_credits
<< IXGBE_RTTDT2C_MCL_SHIFT
;
99 reg
|= (u32
)(bwg_id
[i
]) << IXGBE_RTTDT2C_BWG_SHIFT
;
101 if (prio_type
[i
] == prio_group
)
102 reg
|= IXGBE_RTTDT2C_GSP
;
104 if (prio_type
[i
] == prio_link
)
105 reg
|= IXGBE_RTTDT2C_LSP
;
107 IXGBE_WRITE_REG(hw
, IXGBE_RTTDT2C(i
), reg
);
111 * Configure Tx descriptor plane (recycle mode; WSP) and
114 reg
= IXGBE_RTTDCS_TDPAC
| IXGBE_RTTDCS_TDRM
;
115 IXGBE_WRITE_REG(hw
, IXGBE_RTTDCS
, reg
);
121 * ixgbe_dcb_config_tx_data_arbiter_82599 - Config Tx Data arbiter
122 * @hw: pointer to hardware structure
123 * @refill: refill credits index by traffic class
124 * @max: max credits index by traffic class
125 * @bwg_id: bandwidth grouping indexed by traffic class
126 * @prio_type: priority type indexed by traffic class
127 * @prio_tc: priority to tc assignments indexed by priority
129 * Configure Tx Packet Arbiter and credits for each traffic class.
131 s32
ixgbe_dcb_config_tx_data_arbiter_82599(struct ixgbe_hw
*hw
,
142 * Disable the arbiter before changing parameters
143 * (always enable recycle mode; SP; arb delay)
145 reg
= IXGBE_RTTPCS_TPPAC
| IXGBE_RTTPCS_TPRM
|
146 (IXGBE_RTTPCS_ARBD_DCB
<< IXGBE_RTTPCS_ARBD_SHIFT
) |
148 IXGBE_WRITE_REG(hw
, IXGBE_RTTPCS
, reg
);
150 /* Map all traffic classes to their UP */
152 for (i
= 0; i
< MAX_USER_PRIORITY
; i
++)
153 reg
|= (prio_tc
[i
] << (i
* IXGBE_RTTUP2TC_UP_SHIFT
));
154 IXGBE_WRITE_REG(hw
, IXGBE_RTTUP2TC
, reg
);
156 /* Configure traffic class credits and priority */
157 for (i
= 0; i
< MAX_TRAFFIC_CLASS
; i
++) {
159 reg
|= (u32
)(max
[i
]) << IXGBE_RTTPT2C_MCL_SHIFT
;
160 reg
|= (u32
)(bwg_id
[i
]) << IXGBE_RTTPT2C_BWG_SHIFT
;
162 if (prio_type
[i
] == prio_group
)
163 reg
|= IXGBE_RTTPT2C_GSP
;
165 if (prio_type
[i
] == prio_link
)
166 reg
|= IXGBE_RTTPT2C_LSP
;
168 IXGBE_WRITE_REG(hw
, IXGBE_RTTPT2C(i
), reg
);
172 * Configure Tx packet plane (recycle mode; SP; arb delay) and
175 reg
= IXGBE_RTTPCS_TPPAC
| IXGBE_RTTPCS_TPRM
|
176 (IXGBE_RTTPCS_ARBD_DCB
<< IXGBE_RTTPCS_ARBD_SHIFT
);
177 IXGBE_WRITE_REG(hw
, IXGBE_RTTPCS
, reg
);
183 * ixgbe_dcb_config_pfc_82599 - Configure priority flow control
184 * @hw: pointer to hardware structure
185 * @pfc_en: enabled pfc bitmask
186 * @prio_tc: priority to tc assignments indexed by priority
188 * Configure Priority Flow Control (PFC) for each traffic class.
190 s32
ixgbe_dcb_config_pfc_82599(struct ixgbe_hw
*hw
, u8 pfc_en
, u8
*prio_tc
)
192 u32 i
, j
, fcrtl
, reg
;
195 /* Enable Transmit Priority Flow Control */
196 IXGBE_WRITE_REG(hw
, IXGBE_FCCFG
, IXGBE_FCCFG_TFCE_PRIORITY
);
198 /* Enable Receive Priority Flow Control */
199 reg
= IXGBE_READ_REG(hw
, IXGBE_MFLCN
);
200 reg
|= IXGBE_MFLCN_DPF
;
203 * X540 & X550 supports per TC Rx priority flow control.
204 * So clear all TCs and only enable those that should be
207 reg
&= ~(IXGBE_MFLCN_RPFCE_MASK
| IXGBE_MFLCN_RFCE
);
209 if (hw
->mac
.type
>= ixgbe_mac_X540
)
210 reg
|= pfc_en
<< IXGBE_MFLCN_RPFCE_SHIFT
;
213 reg
|= IXGBE_MFLCN_RPFCE
;
215 IXGBE_WRITE_REG(hw
, IXGBE_MFLCN
, reg
);
217 for (i
= 0; i
< MAX_USER_PRIORITY
; i
++) {
218 if (prio_tc
[i
] > max_tc
)
223 /* Configure PFC Tx thresholds per TC */
224 for (i
= 0; i
<= max_tc
; i
++) {
227 for (j
= 0; j
< MAX_USER_PRIORITY
; j
++) {
228 if ((prio_tc
[j
] == i
) && (pfc_en
& BIT(j
))) {
235 reg
= (hw
->fc
.high_water
[i
] << 10) | IXGBE_FCRTH_FCEN
;
236 fcrtl
= (hw
->fc
.low_water
[i
] << 10) | IXGBE_FCRTL_XONE
;
237 IXGBE_WRITE_REG(hw
, IXGBE_FCRTL_82599(i
), fcrtl
);
239 /* In order to prevent Tx hangs when the internal Tx
240 * switch is enabled we must set the high water mark
241 * to the Rx packet buffer size - 24KB. This allows
242 * the Tx switch to function even under heavy Rx
245 reg
= IXGBE_READ_REG(hw
, IXGBE_RXPBSIZE(i
)) - 24576;
246 IXGBE_WRITE_REG(hw
, IXGBE_FCRTL_82599(i
), 0);
249 IXGBE_WRITE_REG(hw
, IXGBE_FCRTH_82599(i
), reg
);
252 for (; i
< MAX_TRAFFIC_CLASS
; i
++) {
253 IXGBE_WRITE_REG(hw
, IXGBE_FCRTL_82599(i
), 0);
254 IXGBE_WRITE_REG(hw
, IXGBE_FCRTH_82599(i
), 0);
257 /* Configure pause time (2 TCs per register) */
258 reg
= hw
->fc
.pause_time
* 0x00010001;
259 for (i
= 0; i
< (MAX_TRAFFIC_CLASS
/ 2); i
++)
260 IXGBE_WRITE_REG(hw
, IXGBE_FCTTV(i
), reg
);
262 /* Configure flow control refresh threshold value */
263 IXGBE_WRITE_REG(hw
, IXGBE_FCRTV
, hw
->fc
.pause_time
/ 2);
269 * ixgbe_dcb_config_tc_stats_82599 - Config traffic class statistics
270 * @hw: pointer to hardware structure
272 * Configure queue statistics registers, all queues belonging to same traffic
273 * class uses a single set of queue statistics counters.
275 static s32
ixgbe_dcb_config_tc_stats_82599(struct ixgbe_hw
*hw
)
281 * Receive Queues stats setting
282 * 32 RQSMR registers, each configuring 4 queues.
283 * Set all 16 queues of each TC to the same stat
284 * with TC 'n' going to stat 'n'.
286 for (i
= 0; i
< 32; i
++) {
287 reg
= 0x01010101 * (i
/ 4);
288 IXGBE_WRITE_REG(hw
, IXGBE_RQSMR(i
), reg
);
291 * Transmit Queues stats setting
292 * 32 TQSM registers, each controlling 4 queues.
293 * Set all queues of each TC to the same stat
294 * with TC 'n' going to stat 'n'.
295 * Tx queues are allocated non-uniformly to TCs:
296 * 32, 32, 16, 16, 8, 8, 8, 8.
298 for (i
= 0; i
< 32; i
++) {
315 IXGBE_WRITE_REG(hw
, IXGBE_TQSM(i
), reg
);
322 * ixgbe_dcb_hw_config_82599 - Configure and enable DCB
323 * @hw: pointer to hardware structure
324 * @pfc_en: enabled pfc bitmask
325 * @refill: refill credits index by traffic class
326 * @max: max credits index by traffic class
327 * @bwg_id: bandwidth grouping indexed by traffic class
328 * @prio_type: priority type indexed by traffic class
329 * @prio_tc: priority to tc assignments indexed by priority
331 * Configure dcb settings and enable dcb mode.
333 s32
ixgbe_dcb_hw_config_82599(struct ixgbe_hw
*hw
, u8 pfc_en
, u16
*refill
,
334 u16
*max
, u8
*bwg_id
, u8
*prio_type
, u8
*prio_tc
)
336 ixgbe_dcb_config_rx_arbiter_82599(hw
, refill
, max
, bwg_id
,
338 ixgbe_dcb_config_tx_desc_arbiter_82599(hw
, refill
, max
,
340 ixgbe_dcb_config_tx_data_arbiter_82599(hw
, refill
, max
,
341 bwg_id
, prio_type
, prio_tc
);
342 ixgbe_dcb_config_pfc_82599(hw
, pfc_en
, prio_tc
);
343 ixgbe_dcb_config_tc_stats_82599(hw
);