1 /*******************************************************************************
3 Intel 10 Gigabit PCI Express Linux driver
4 Copyright(c) 1999 - 2013 Intel Corporation.
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
25 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *******************************************************************************/
30 #include "ixgbe_type.h"
31 #include "ixgbe_dcb.h"
32 #include "ixgbe_dcb_82599.h"
35 * ixgbe_dcb_config_rx_arbiter_82599 - Config Rx Data arbiter
36 * @hw: pointer to hardware structure
37 * @refill: refill credits index by traffic class
38 * @max: max credits index by traffic class
39 * @bwg_id: bandwidth grouping indexed by traffic class
40 * @prio_type: priority type indexed by traffic class
42 * Configure Rx Packet Arbiter and credits for each traffic class.
44 s32 ixgbe_dcb_config_rx_arbiter_82599(struct ixgbe_hw *hw,
52 u32 credit_refill = 0;
57 * Disable the arbiter before changing parameters
58 * (always enable recycle mode; WSP)
60 reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC | IXGBE_RTRPCS_ARBDIS;
61 IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg);
63 /* Map all traffic classes to their UP */
65 for (i = 0; i < MAX_USER_PRIORITY; i++)
66 reg |= (prio_tc[i] << (i * IXGBE_RTRUP2TC_UP_SHIFT));
67 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
69 /* Configure traffic class credits and priority */
70 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
71 credit_refill = refill[i];
73 reg = credit_refill | (credit_max << IXGBE_RTRPT4C_MCL_SHIFT);
75 reg |= (u32)(bwg_id[i]) << IXGBE_RTRPT4C_BWG_SHIFT;
77 if (prio_type[i] == prio_link)
78 reg |= IXGBE_RTRPT4C_LSP;
80 IXGBE_WRITE_REG(hw, IXGBE_RTRPT4C(i), reg);
84 * Configure Rx packet plane (recycle mode; WSP) and
87 reg = IXGBE_RTRPCS_RRM | IXGBE_RTRPCS_RAC;
88 IXGBE_WRITE_REG(hw, IXGBE_RTRPCS, reg);
94 * ixgbe_dcb_config_tx_desc_arbiter_82599 - Config Tx Desc. arbiter
95 * @hw: pointer to hardware structure
96 * @refill: refill credits index by traffic class
97 * @max: max credits index by traffic class
98 * @bwg_id: bandwidth grouping indexed by traffic class
99 * @prio_type: priority type indexed by traffic class
101 * Configure Tx Descriptor Arbiter and credits for each traffic class.
103 s32 ixgbe_dcb_config_tx_desc_arbiter_82599(struct ixgbe_hw *hw,
109 u32 reg, max_credits;
112 /* Clear the per-Tx queue credits; we use per-TC instead */
113 for (i = 0; i < 128; i++) {
114 IXGBE_WRITE_REG(hw, IXGBE_RTTDQSEL, i);
115 IXGBE_WRITE_REG(hw, IXGBE_RTTDT1C, 0);
118 /* Configure traffic class credits and priority */
119 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
120 max_credits = max[i];
121 reg = max_credits << IXGBE_RTTDT2C_MCL_SHIFT;
123 reg |= (u32)(bwg_id[i]) << IXGBE_RTTDT2C_BWG_SHIFT;
125 if (prio_type[i] == prio_group)
126 reg |= IXGBE_RTTDT2C_GSP;
128 if (prio_type[i] == prio_link)
129 reg |= IXGBE_RTTDT2C_LSP;
131 IXGBE_WRITE_REG(hw, IXGBE_RTTDT2C(i), reg);
135 * Configure Tx descriptor plane (recycle mode; WSP) and
138 reg = IXGBE_RTTDCS_TDPAC | IXGBE_RTTDCS_TDRM;
139 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, reg);
145 * ixgbe_dcb_config_tx_data_arbiter_82599 - Config Tx Data arbiter
146 * @hw: pointer to hardware structure
147 * @refill: refill credits index by traffic class
148 * @max: max credits index by traffic class
149 * @bwg_id: bandwidth grouping indexed by traffic class
150 * @prio_type: priority type indexed by traffic class
152 * Configure Tx Packet Arbiter and credits for each traffic class.
154 s32 ixgbe_dcb_config_tx_data_arbiter_82599(struct ixgbe_hw *hw,
165 * Disable the arbiter before changing parameters
166 * (always enable recycle mode; SP; arb delay)
168 reg = IXGBE_RTTPCS_TPPAC | IXGBE_RTTPCS_TPRM |
169 (IXGBE_RTTPCS_ARBD_DCB << IXGBE_RTTPCS_ARBD_SHIFT) |
171 IXGBE_WRITE_REG(hw, IXGBE_RTTPCS, reg);
173 /* Map all traffic classes to their UP */
175 for (i = 0; i < MAX_USER_PRIORITY; i++)
176 reg |= (prio_tc[i] << (i * IXGBE_RTTUP2TC_UP_SHIFT));
177 IXGBE_WRITE_REG(hw, IXGBE_RTTUP2TC, reg);
179 /* Configure traffic class credits and priority */
180 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
182 reg |= (u32)(max[i]) << IXGBE_RTTPT2C_MCL_SHIFT;
183 reg |= (u32)(bwg_id[i]) << IXGBE_RTTPT2C_BWG_SHIFT;
185 if (prio_type[i] == prio_group)
186 reg |= IXGBE_RTTPT2C_GSP;
188 if (prio_type[i] == prio_link)
189 reg |= IXGBE_RTTPT2C_LSP;
191 IXGBE_WRITE_REG(hw, IXGBE_RTTPT2C(i), reg);
195 * Configure Tx packet plane (recycle mode; SP; arb delay) and
198 reg = IXGBE_RTTPCS_TPPAC | IXGBE_RTTPCS_TPRM |
199 (IXGBE_RTTPCS_ARBD_DCB << IXGBE_RTTPCS_ARBD_SHIFT);
200 IXGBE_WRITE_REG(hw, IXGBE_RTTPCS, reg);
206 * ixgbe_dcb_config_pfc_82599 - Configure priority flow control
207 * @hw: pointer to hardware structure
208 * @pfc_en: enabled pfc bitmask
209 * @prio_tc: priority to tc assignments indexed by priority
211 * Configure Priority Flow Control (PFC) for each traffic class.
213 s32 ixgbe_dcb_config_pfc_82599(struct ixgbe_hw *hw, u8 pfc_en, u8 *prio_tc)
215 u32 i, j, fcrtl, reg;
218 /* Enable Transmit Priority Flow Control */
219 IXGBE_WRITE_REG(hw, IXGBE_FCCFG, IXGBE_FCCFG_TFCE_PRIORITY);
221 /* Enable Receive Priority Flow Control */
222 reg = IXGBE_READ_REG(hw, IXGBE_MFLCN);
223 reg |= IXGBE_MFLCN_DPF;
226 * X540 supports per TC Rx priority flow control. So
227 * clear all TCs and only enable those that should be
230 reg &= ~(IXGBE_MFLCN_RPFCE_MASK | IXGBE_MFLCN_RFCE);
232 if (hw->mac.type == ixgbe_mac_X540)
233 reg |= pfc_en << IXGBE_MFLCN_RPFCE_SHIFT;
236 reg |= IXGBE_MFLCN_RPFCE;
238 IXGBE_WRITE_REG(hw, IXGBE_MFLCN, reg);
240 for (i = 0; i < MAX_USER_PRIORITY; i++) {
241 if (prio_tc[i] > max_tc)
246 /* Configure PFC Tx thresholds per TC */
247 for (i = 0; i <= max_tc; i++) {
250 for (j = 0; j < MAX_USER_PRIORITY; j++) {
251 if ((prio_tc[j] == i) && (pfc_en & (1 << j))) {
258 reg = (hw->fc.high_water[i] << 10) | IXGBE_FCRTH_FCEN;
259 fcrtl = (hw->fc.low_water[i] << 10) | IXGBE_FCRTL_XONE;
260 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), fcrtl);
262 reg = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(i)) - 32;
263 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
266 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), reg);
269 for (; i < MAX_TRAFFIC_CLASS; i++) {
270 IXGBE_WRITE_REG(hw, IXGBE_FCRTL_82599(i), 0);
271 IXGBE_WRITE_REG(hw, IXGBE_FCRTH_82599(i), 0);
274 /* Configure pause time (2 TCs per register) */
275 reg = hw->fc.pause_time * 0x00010001;
276 for (i = 0; i < (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);
286 * ixgbe_dcb_config_tc_stats_82599 - Config 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 static s32 ixgbe_dcb_config_tc_stats_82599(struct ixgbe_hw *hw)
298 * Receive Queues stats setting
299 * 32 RQSMR registers, each configuring 4 queues.
300 * Set all 16 queues of each TC to the same stat
301 * with TC 'n' going to stat 'n'.
303 for (i = 0; i < 32; i++) {
304 reg = 0x01010101 * (i / 4);
305 IXGBE_WRITE_REG(hw, IXGBE_RQSMR(i), reg);
308 * Transmit Queues stats setting
309 * 32 TQSM registers, each controlling 4 queues.
310 * Set all queues of each TC to the same stat
311 * with TC 'n' going to stat 'n'.
312 * Tx queues are allocated non-uniformly to TCs:
313 * 32, 32, 16, 16, 8, 8, 8, 8.
315 for (i = 0; i < 32; i++) {
332 IXGBE_WRITE_REG(hw, IXGBE_TQSM(i), reg);
339 * ixgbe_dcb_hw_config_82599 - Configure and enable DCB
340 * @hw: pointer to hardware structure
341 * @refill: refill credits index by traffic class
342 * @max: max credits index by traffic class
343 * @bwg_id: bandwidth grouping indexed by traffic class
344 * @prio_type: priority type indexed by traffic class
345 * @pfc_en: enabled pfc bitmask
347 * Configure dcb settings and enable dcb mode.
349 s32 ixgbe_dcb_hw_config_82599(struct ixgbe_hw *hw, u8 pfc_en, u16 *refill,
350 u16 *max, u8 *bwg_id, u8 *prio_type, u8 *prio_tc)
352 ixgbe_dcb_config_rx_arbiter_82599(hw, refill, max, bwg_id,
354 ixgbe_dcb_config_tx_desc_arbiter_82599(hw, refill, max,
356 ixgbe_dcb_config_tx_data_arbiter_82599(hw, refill, max,
357 bwg_id, prio_type, prio_tc);
358 ixgbe_dcb_config_pfc_82599(hw, pfc_en, prio_tc);
359 ixgbe_dcb_config_tc_stats_82599(hw);