1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2001-2018
6 #include "ixgbe_type.h"
8 #include "ixgbe_dcb_82598.h"
11 * ixgbe_dcb_get_tc_stats_82598 - Return status data 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_82598(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 */
34 stats->qbtc[tc] += IXGBE_READ_REG(hw, IXGBE_QBTC(tc));
35 /* Received Packets */
36 stats->qprc[tc] += IXGBE_READ_REG(hw, IXGBE_QPRC(tc));
38 stats->qbrc[tc] += IXGBE_READ_REG(hw, IXGBE_QBRC(tc));
41 /* Can we get rid of these?? Consequently, getting rid
42 * of the tc_stats structure.
44 tc_stats_array[up]->in_overflow_discards = 0;
45 tc_stats_array[up]->out_overflow_discards = 0;
53 * ixgbe_dcb_get_pfc_stats_82598 - Returns CBFC status data
54 * @hw: pointer to hardware structure
55 * @stats: pointer to statistics structure
56 * @tc_count: Number of elements in bwg_array.
58 * This function returns the CBFC status data for each of the Traffic Classes.
60 s32 ixgbe_dcb_get_pfc_stats_82598(struct ixgbe_hw *hw,
61 struct ixgbe_hw_stats *stats,
66 DEBUGFUNC("dcb_get_pfc_stats");
68 if (tc_count > IXGBE_DCB_MAX_TRAFFIC_CLASS)
69 return IXGBE_ERR_PARAM;
71 for (tc = 0; tc < tc_count; tc++) {
72 /* Priority XOFF Transmitted */
73 stats->pxofftxc[tc] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(tc));
74 /* Priority XOFF Received */
75 stats->pxoffrxc[tc] += IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(tc));
82 * ixgbe_dcb_config_rx_arbiter_82598 - Config Rx data arbiter
83 * @hw: pointer to hardware structure
84 * @refill: refill credits index by traffic class
85 * @max: max credits index by traffic class
86 * @tsa: transmission selection algorithm indexed by traffic class
88 * Configure Rx Data Arbiter and credits for each traffic class.
90 s32 ixgbe_dcb_config_rx_arbiter_82598(struct ixgbe_hw *hw, u16 *refill,
94 u32 credit_refill = 0;
98 reg = IXGBE_READ_REG(hw, IXGBE_RUPPBMR) | IXGBE_RUPPBMR_MQA;
99 IXGBE_WRITE_REG(hw, IXGBE_RUPPBMR, reg);
101 reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
103 reg &= ~IXGBE_RMCS_ARBDIS;
104 /* Enable Receive Recycle within the BWG */
105 reg |= IXGBE_RMCS_RRM;
106 /* Enable Deficit Fixed Priority arbitration*/
107 reg |= IXGBE_RMCS_DFP;
109 IXGBE_WRITE_REG(hw, IXGBE_RMCS, reg);
111 /* Configure traffic class credits and priority */
112 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
113 credit_refill = refill[i];
116 reg = credit_refill | (credit_max << IXGBE_RT2CR_MCL_SHIFT);
118 if (tsa[i] == ixgbe_dcb_tsa_strict)
119 reg |= IXGBE_RT2CR_LSP;
121 IXGBE_WRITE_REG(hw, IXGBE_RT2CR(i), reg);
124 reg = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
125 reg |= IXGBE_RDRXCTL_RDMTS_1_2;
126 reg |= IXGBE_RDRXCTL_MPBEN;
127 reg |= IXGBE_RDRXCTL_MCEN;
128 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, reg);
130 reg = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
131 /* Make sure there is enough descriptors before arbitration */
132 reg &= ~IXGBE_RXCTRL_DMBYPS;
133 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, reg);
135 return IXGBE_SUCCESS;
139 * ixgbe_dcb_config_tx_desc_arbiter_82598 - Config Tx Desc. arbiter
140 * @hw: pointer to hardware structure
141 * @refill: refill credits index by traffic class
142 * @max: max credits index by traffic class
143 * @bwg_id: bandwidth grouping indexed by traffic class
144 * @tsa: transmission selection algorithm indexed by traffic class
146 * Configure Tx Descriptor Arbiter and credits for each traffic class.
148 s32 ixgbe_dcb_config_tx_desc_arbiter_82598(struct ixgbe_hw *hw,
149 u16 *refill, u16 *max, u8 *bwg_id,
152 u32 reg, max_credits;
155 reg = IXGBE_READ_REG(hw, IXGBE_DPMCS);
158 reg &= ~IXGBE_DPMCS_ARBDIS;
159 reg |= IXGBE_DPMCS_TSOEF;
161 /* Configure Max TSO packet size 34KB including payload and headers */
162 reg |= (0x4 << IXGBE_DPMCS_MTSOS_SHIFT);
164 IXGBE_WRITE_REG(hw, IXGBE_DPMCS, reg);
166 /* Configure traffic class credits and priority */
167 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
168 max_credits = max[i];
169 reg = max_credits << IXGBE_TDTQ2TCCR_MCL_SHIFT;
171 reg |= (u32)(bwg_id[i]) << IXGBE_TDTQ2TCCR_BWG_SHIFT;
173 if (tsa[i] == ixgbe_dcb_tsa_group_strict_cee)
174 reg |= IXGBE_TDTQ2TCCR_GSP;
176 if (tsa[i] == ixgbe_dcb_tsa_strict)
177 reg |= IXGBE_TDTQ2TCCR_LSP;
179 IXGBE_WRITE_REG(hw, IXGBE_TDTQ2TCCR(i), reg);
182 return IXGBE_SUCCESS;
186 * ixgbe_dcb_config_tx_data_arbiter_82598 - Config Tx data arbiter
187 * @hw: pointer to hardware structure
188 * @refill: refill credits index by traffic class
189 * @max: max credits index by traffic class
190 * @bwg_id: bandwidth grouping indexed by traffic class
191 * @tsa: transmission selection algorithm indexed by traffic class
193 * Configure Tx Data Arbiter and credits for each traffic class.
195 s32 ixgbe_dcb_config_tx_data_arbiter_82598(struct ixgbe_hw *hw,
196 u16 *refill, u16 *max, u8 *bwg_id,
202 reg = IXGBE_READ_REG(hw, IXGBE_PDPMCS);
203 /* Enable Data Plane Arbiter */
204 reg &= ~IXGBE_PDPMCS_ARBDIS;
205 /* Enable DFP and Transmit Recycle Mode */
206 reg |= (IXGBE_PDPMCS_TPPAC | IXGBE_PDPMCS_TRM);
208 IXGBE_WRITE_REG(hw, IXGBE_PDPMCS, reg);
210 /* Configure traffic class credits and priority */
211 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
213 reg |= (u32)(max[i]) << IXGBE_TDPT2TCCR_MCL_SHIFT;
214 reg |= (u32)(bwg_id[i]) << IXGBE_TDPT2TCCR_BWG_SHIFT;
216 if (tsa[i] == ixgbe_dcb_tsa_group_strict_cee)
217 reg |= IXGBE_TDPT2TCCR_GSP;
219 if (tsa[i] == ixgbe_dcb_tsa_strict)
220 reg |= IXGBE_TDPT2TCCR_LSP;
222 IXGBE_WRITE_REG(hw, IXGBE_TDPT2TCCR(i), reg);
225 /* Enable Tx packet buffer division */
226 reg = IXGBE_READ_REG(hw, IXGBE_DTXCTL);
227 reg |= IXGBE_DTXCTL_ENDBUBD;
228 IXGBE_WRITE_REG(hw, IXGBE_DTXCTL, reg);
230 return IXGBE_SUCCESS;
234 * ixgbe_dcb_config_pfc_82598 - Config priority flow control
235 * @hw: pointer to hardware structure
236 * @pfc_en: enabled pfc bitmask
238 * Configure Priority Flow Control for each traffic class.
240 s32 ixgbe_dcb_config_pfc_82598(struct ixgbe_hw *hw, u8 pfc_en)
245 /* Enable Transmit Priority Flow Control */
246 reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
247 reg &= ~IXGBE_RMCS_TFCE_802_3X;
248 reg |= IXGBE_RMCS_TFCE_PRIORITY;
249 IXGBE_WRITE_REG(hw, IXGBE_RMCS, reg);
251 /* Enable Receive Priority Flow Control */
252 reg = IXGBE_READ_REG(hw, IXGBE_FCTRL);
253 reg &= ~(IXGBE_FCTRL_RPFCE | IXGBE_FCTRL_RFCE);
256 reg |= IXGBE_FCTRL_RPFCE;
258 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, reg);
260 /* Configure PFC Tx thresholds per TC */
261 for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
262 if (!(pfc_en & (1 << i))) {
263 IXGBE_WRITE_REG(hw, IXGBE_FCRTL(i), 0);
264 IXGBE_WRITE_REG(hw, IXGBE_FCRTH(i), 0);
268 fcrtl = (hw->fc.low_water[i] << 10) | IXGBE_FCRTL_XONE;
269 reg = (hw->fc.high_water[i] << 10) | IXGBE_FCRTH_FCEN;
270 IXGBE_WRITE_REG(hw, IXGBE_FCRTL(i), fcrtl);
271 IXGBE_WRITE_REG(hw, IXGBE_FCRTH(i), reg);
274 /* Configure pause time */
275 reg = hw->fc.pause_time | (hw->fc.pause_time << 16);
276 for (i = 0; i < (IXGBE_DCB_MAX_TRAFFIC_CLASS / 2); i++)
277 IXGBE_WRITE_REG(hw, IXGBE_FCTTV(i), reg);
279 /* Configure flow control refresh threshold value */
280 IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
282 return IXGBE_SUCCESS;
286 * ixgbe_dcb_config_tc_stats_82598 - Configure traffic class statistics
287 * @hw: pointer to hardware structure
289 * Configure queue statistics registers, all queues belonging to same traffic
290 * class uses a single set of queue statistics counters.
292 s32 ixgbe_dcb_config_tc_stats_82598(struct ixgbe_hw *hw)
298 /* Receive Queues stats setting - 8 queues per statistics reg */
299 for (i = 0, j = 0; i < 15 && j < 8; i = i + 2, j++) {
300 reg = IXGBE_READ_REG(hw, IXGBE_RQSMR(i));
301 reg |= ((0x1010101) * j);
302 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), reg);
303 reg = IXGBE_READ_REG(hw, IXGBE_RQSMR(i + 1));
304 reg |= ((0x1010101) * j);
305 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i + 1), reg);
307 /* Transmit Queues stats setting - 4 queues per statistics reg*/
308 for (i = 0; i < 8; i++) {
309 reg = IXGBE_READ_REG(hw, IXGBE_TQSMR(i));
310 reg |= ((0x1010101) * i);
311 IXGBE_WRITE_REG(hw, IXGBE_TQSMR(i), reg);
314 return IXGBE_SUCCESS;
318 * ixgbe_dcb_hw_config_82598 - Config and enable DCB
319 * @hw: pointer to hardware structure
320 * @link_speed: unused
321 * @refill: refill credits index by traffic class
322 * @max: max credits index by traffic class
323 * @bwg_id: bandwidth grouping indexed by traffic class
324 * @tsa: transmission selection algorithm indexed by traffic class
326 * Configure dcb settings and enable dcb mode.
328 s32 ixgbe_dcb_hw_config_82598(struct ixgbe_hw *hw, int link_speed,
329 u16 *refill, u16 *max, u8 *bwg_id,
332 UNREFERENCED_1PARAMETER(link_speed);
334 ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max, tsa);
335 ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max, bwg_id,
337 ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max, bwg_id,
339 ixgbe_dcb_config_tc_stats_82598(hw);
342 return IXGBE_SUCCESS;