1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2015-2020 Beijing WangXun Technology Co., Ltd.
3 * Copyright(c) 2010-2017 Intel Corporation
6 #include "txgbe_type.h"
11 * txgbe_dcb_config_rx_arbiter_raptor - Config Rx Data arbiter
12 * @hw: pointer to hardware structure
13 * @refill: refill credits index by traffic class
14 * @max: max credits index by traffic class
15 * @bwg_id: bandwidth grouping indexed by traffic class
16 * @tsa: transmission selection algorithm indexed by traffic class
17 * @map: priority to tc assignments indexed by priority
19 * Configure Rx Packet Arbiter and credits for each traffic class.
21 s32 txgbe_dcb_config_rx_arbiter_raptor(struct txgbe_hw *hw, u16 *refill,
22 u16 *max, u8 *bwg_id, u8 *tsa,
26 u32 credit_refill = 0;
31 * Disable the arbiter before changing parameters
32 * (always enable recycle mode; WSP)
34 reg = TXGBE_ARBRXCTL_RRM | TXGBE_ARBRXCTL_WSP |
36 wr32(hw, TXGBE_ARBRXCTL, reg);
39 * map all UPs to TCs. up_to_tc_bitmap for each TC has corresponding
40 * bits sets for the UPs that needs to be mappped to that TC.
41 * e.g if priorities 6 and 7 are to be mapped to a TC then the
42 * up_to_tc_bitmap value for that TC will be 11000000 in binary.
45 for (i = 0; i < TXGBE_DCB_UP_MAX; i++)
46 reg |= (map[i] << (i * TXGBE_RPUP2TC_UP_SHIFT));
48 wr32(hw, TXGBE_RPUP2TC, reg);
50 /* Configure traffic class credits and priority */
51 for (i = 0; i < TXGBE_DCB_TC_MAX; i++) {
52 credit_refill = refill[i];
54 reg = TXGBE_QARBRXCFG_CRQ(credit_refill) |
55 TXGBE_QARBRXCFG_MCL(credit_max) |
56 TXGBE_QARBRXCFG_BWG(bwg_id[i]);
58 if (tsa[i] == txgbe_dcb_tsa_strict)
59 reg |= TXGBE_QARBRXCFG_LSP;
61 wr32(hw, TXGBE_QARBRXCFG(i), reg);
65 * Configure Rx packet plane (recycle mode; WSP) and
68 reg = TXGBE_ARBRXCTL_RRM | TXGBE_ARBRXCTL_WSP;
69 wr32(hw, TXGBE_ARBRXCTL, reg);
75 * txgbe_dcb_config_tx_desc_arbiter_raptor - Config Tx Desc. arbiter
76 * @hw: pointer to hardware structure
77 * @refill: refill credits index by traffic class
78 * @max: max credits index by traffic class
79 * @bwg_id: bandwidth grouping indexed by traffic class
80 * @tsa: transmission selection algorithm indexed by traffic class
82 * Configure Tx Descriptor Arbiter and credits for each traffic class.
84 s32 txgbe_dcb_config_tx_desc_arbiter_raptor(struct txgbe_hw *hw, u16 *refill,
85 u16 *max, u8 *bwg_id, u8 *tsa)
90 /* Clear the per-Tx queue credits; we use per-TC instead */
91 for (i = 0; i < 128; i++)
92 wr32(hw, TXGBE_QARBTXCRED(i), 0);
94 /* Configure traffic class credits and priority */
95 for (i = 0; i < TXGBE_DCB_TC_MAX; i++) {
97 reg = TXGBE_QARBTXCFG_MCL(max_credits) |
98 TXGBE_QARBTXCFG_CRQ(refill[i]) |
99 TXGBE_QARBTXCFG_BWG(bwg_id[i]);
101 if (tsa[i] == txgbe_dcb_tsa_group_strict_cee)
102 reg |= TXGBE_QARBTXCFG_GSP;
104 if (tsa[i] == txgbe_dcb_tsa_strict)
105 reg |= TXGBE_QARBTXCFG_LSP;
107 wr32(hw, TXGBE_QARBTXCFG(i), reg);
111 * Configure Tx descriptor plane (recycle mode; WSP) and
114 reg = TXGBE_ARBTXCTL_WSP | TXGBE_ARBTXCTL_RRM;
115 wr32(hw, TXGBE_ARBTXCTL, reg);
121 * txgbe_dcb_config_tx_data_arbiter_raptor - 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 * @tsa: transmission selection algorithm indexed by traffic class
127 * @map: priority to tc assignments indexed by priority
129 * Configure Tx Packet Arbiter and credits for each traffic class.
131 s32 txgbe_dcb_config_tx_data_arbiter_raptor(struct txgbe_hw *hw, u16 *refill,
132 u16 *max, u8 *bwg_id, u8 *tsa,
139 * Disable the arbiter before changing parameters
140 * (always enable recycle mode; SP; arb delay)
142 reg = TXGBE_PARBTXCTL_SP |
143 TXGBE_PARBTXCTL_RECYC |
145 wr32(hw, TXGBE_PARBTXCTL, reg);
148 * map all UPs to TCs. up_to_tc_bitmap for each TC has corresponding
149 * bits sets for the UPs that needs to be mappped to that TC.
150 * e.g if priorities 6 and 7 are to be mapped to a TC then the
151 * up_to_tc_bitmap value for that TC will be 11000000 in binary.
154 for (i = 0; i < TXGBE_DCB_UP_MAX; i++)
155 reg |= TXGBE_DCBUP2TC_MAP(i, map[i]);
157 wr32(hw, TXGBE_PBRXUP2TC, reg);
159 /* Configure traffic class credits and priority */
160 for (i = 0; i < TXGBE_DCB_TC_MAX; i++) {
161 reg = TXGBE_PARBTXCFG_CRQ(refill[i]) |
162 TXGBE_PARBTXCFG_MCL(max[i]) |
163 TXGBE_PARBTXCFG_BWG(bwg_id[i]);
165 if (tsa[i] == txgbe_dcb_tsa_group_strict_cee)
166 reg |= TXGBE_PARBTXCFG_GSP;
168 if (tsa[i] == txgbe_dcb_tsa_strict)
169 reg |= TXGBE_PARBTXCFG_LSP;
171 wr32(hw, TXGBE_PARBTXCFG(i), reg);
175 * Configure Tx packet plane (recycle mode; SP; arb delay) and
178 reg = TXGBE_PARBTXCTL_SP | TXGBE_PARBTXCTL_RECYC;
179 wr32(hw, TXGBE_PARBTXCTL, reg);
185 * txgbe_dcb_config_pfc_raptor - Configure priority flow control
186 * @hw: pointer to hardware structure
187 * @pfc_en: enabled pfc bitmask
188 * @map: priority to tc assignments indexed by priority
190 * Configure Priority Flow Control (PFC) for each traffic class.
192 s32 txgbe_dcb_config_pfc_raptor(struct txgbe_hw *hw, u8 pfc_en, u8 *map)
194 u32 i, j, fcrtl, reg;
197 /* Enable Transmit Priority Flow Control */
198 wr32(hw, TXGBE_TXFCCFG, TXGBE_TXFCCFG_PFC);
200 /* Enable Receive Priority Flow Control */
201 wr32m(hw, TXGBE_RXFCCFG, TXGBE_RXFCCFG_PFC,
202 pfc_en ? TXGBE_RXFCCFG_PFC : 0);
204 for (i = 0; i < TXGBE_DCB_UP_MAX; i++) {
209 /* Configure PFC Tx thresholds per TC */
210 for (i = 0; i <= max_tc; i++) {
213 for (j = 0; j < TXGBE_DCB_UP_MAX; j++) {
214 if (map[j] == i && (pfc_en & (1 << j))) {
221 reg = TXGBE_FCWTRHI_TH(hw->fc.high_water[i]) |
223 fcrtl = TXGBE_FCWTRLO_TH(hw->fc.low_water[i]) |
225 wr32(hw, TXGBE_FCWTRLO(i), fcrtl);
228 * In order to prevent Tx hangs when the internal Tx
229 * switch is enabled we must set the high water mark
230 * to the Rx packet buffer size - 24KB. This allows
231 * the Tx switch to function even under heavy Rx
234 reg = rd32(hw, TXGBE_PBRXSIZE(i)) - 24576;
235 wr32(hw, TXGBE_FCWTRLO(i), 0);
238 wr32(hw, TXGBE_FCWTRHI(i), reg);
241 for (; i < TXGBE_DCB_TC_MAX; i++) {
242 wr32(hw, TXGBE_FCWTRLO(i), 0);
243 wr32(hw, TXGBE_FCWTRHI(i), 0);
246 /* Configure pause time (2 TCs per register) */
247 reg = hw->fc.pause_time | (hw->fc.pause_time << 16);
248 for (i = 0; i < (TXGBE_DCB_TC_MAX / 2); i++)
249 wr32(hw, TXGBE_FCXOFFTM(i), reg);
251 /* Configure flow control refresh threshold value */
252 wr32(hw, TXGBE_RXFCRFSH, hw->fc.pause_time / 2);
258 * txgbe_dcb_config_tc_stats_raptor - Config traffic class statistics
259 * @hw: pointer to hardware structure
260 * @dcb_config: pointer to txgbe_dcb_config structure
262 * Configure queue statistics registers, all queues belonging to same traffic
263 * class uses a single set of queue statistics counters.
265 s32 txgbe_dcb_config_tc_stats_raptor(struct txgbe_hw *hw,
266 struct txgbe_dcb_config *dcb_config)
269 bool vt_mode = false;
271 UNREFERENCED_PARAMETER(hw);
273 if (dcb_config != NULL) {
274 tc_count = dcb_config->num_tcs.pg_tcs;
275 vt_mode = dcb_config->vt_mode;
278 if (!((tc_count == 8 && !vt_mode) || tc_count == 4))
279 return TXGBE_ERR_PARAM;