New upstream version 18.11-rc1
[deb_dpdk.git] / drivers / net / ixgbe / base / ixgbe_dcb_82598.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2001-2018
3  */
4
5
6 #include "ixgbe_type.h"
7 #include "ixgbe_dcb.h"
8 #include "ixgbe_dcb_82598.h"
9
10 /**
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.
15  *
16  * This function returns the status data for each of the Traffic Classes in use.
17  */
18 s32 ixgbe_dcb_get_tc_stats_82598(struct ixgbe_hw *hw,
19                                  struct ixgbe_hw_stats *stats,
20                                  u8 tc_count)
21 {
22         int tc;
23
24         DEBUGFUNC("dcb_get_tc_stats");
25
26         if (tc_count > IXGBE_DCB_MAX_TRAFFIC_CLASS)
27                 return IXGBE_ERR_PARAM;
28
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));
37                 /* Received Bytes */
38                 stats->qbrc[tc] += IXGBE_READ_REG(hw, IXGBE_QBRC(tc));
39
40 #if 0
41                 /* Can we get rid of these??  Consequently, getting rid
42                  * of the tc_stats structure.
43                  */
44                 tc_stats_array[up]->in_overflow_discards = 0;
45                 tc_stats_array[up]->out_overflow_discards = 0;
46 #endif
47         }
48
49         return IXGBE_SUCCESS;
50 }
51
52 /**
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.
57  *
58  * This function returns the CBFC status data for each of the Traffic Classes.
59  */
60 s32 ixgbe_dcb_get_pfc_stats_82598(struct ixgbe_hw *hw,
61                                   struct ixgbe_hw_stats *stats,
62                                   u8 tc_count)
63 {
64         int tc;
65
66         DEBUGFUNC("dcb_get_pfc_stats");
67
68         if (tc_count > IXGBE_DCB_MAX_TRAFFIC_CLASS)
69                 return IXGBE_ERR_PARAM;
70
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));
76         }
77
78         return IXGBE_SUCCESS;
79 }
80
81 /**
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
87  *
88  * Configure Rx Data Arbiter and credits for each traffic class.
89  */
90 s32 ixgbe_dcb_config_rx_arbiter_82598(struct ixgbe_hw *hw, u16 *refill,
91                                       u16 *max, u8 *tsa)
92 {
93         u32 reg = 0;
94         u32 credit_refill = 0;
95         u32 credit_max = 0;
96         u8 i = 0;
97
98         reg = IXGBE_READ_REG(hw, IXGBE_RUPPBMR) | IXGBE_RUPPBMR_MQA;
99         IXGBE_WRITE_REG(hw, IXGBE_RUPPBMR, reg);
100
101         reg = IXGBE_READ_REG(hw, IXGBE_RMCS);
102         /* Enable Arbiter */
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;
108
109         IXGBE_WRITE_REG(hw, IXGBE_RMCS, reg);
110
111         /* Configure traffic class credits and priority */
112         for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
113                 credit_refill = refill[i];
114                 credit_max = max[i];
115
116                 reg = credit_refill | (credit_max << IXGBE_RT2CR_MCL_SHIFT);
117
118                 if (tsa[i] == ixgbe_dcb_tsa_strict)
119                         reg |= IXGBE_RT2CR_LSP;
120
121                 IXGBE_WRITE_REG(hw, IXGBE_RT2CR(i), reg);
122         }
123
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);
129
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);
134
135         return IXGBE_SUCCESS;
136 }
137
138 /**
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
145  *
146  * Configure Tx Descriptor Arbiter and credits for each traffic class.
147  */
148 s32 ixgbe_dcb_config_tx_desc_arbiter_82598(struct ixgbe_hw *hw,
149                                            u16 *refill, u16 *max, u8 *bwg_id,
150                                            u8 *tsa)
151 {
152         u32 reg, max_credits;
153         u8 i;
154
155         reg = IXGBE_READ_REG(hw, IXGBE_DPMCS);
156
157         /* Enable arbiter */
158         reg &= ~IXGBE_DPMCS_ARBDIS;
159         reg |= IXGBE_DPMCS_TSOEF;
160
161         /* Configure Max TSO packet size 34KB including payload and headers */
162         reg |= (0x4 << IXGBE_DPMCS_MTSOS_SHIFT);
163
164         IXGBE_WRITE_REG(hw, IXGBE_DPMCS, reg);
165
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;
170                 reg |= refill[i];
171                 reg |= (u32)(bwg_id[i]) << IXGBE_TDTQ2TCCR_BWG_SHIFT;
172
173                 if (tsa[i] == ixgbe_dcb_tsa_group_strict_cee)
174                         reg |= IXGBE_TDTQ2TCCR_GSP;
175
176                 if (tsa[i] == ixgbe_dcb_tsa_strict)
177                         reg |= IXGBE_TDTQ2TCCR_LSP;
178
179                 IXGBE_WRITE_REG(hw, IXGBE_TDTQ2TCCR(i), reg);
180         }
181
182         return IXGBE_SUCCESS;
183 }
184
185 /**
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
192  *
193  * Configure Tx Data Arbiter and credits for each traffic class.
194  */
195 s32 ixgbe_dcb_config_tx_data_arbiter_82598(struct ixgbe_hw *hw,
196                                            u16 *refill, u16 *max, u8 *bwg_id,
197                                            u8 *tsa)
198 {
199         u32 reg;
200         u8 i;
201
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);
207
208         IXGBE_WRITE_REG(hw, IXGBE_PDPMCS, reg);
209
210         /* Configure traffic class credits and priority */
211         for (i = 0; i < IXGBE_DCB_MAX_TRAFFIC_CLASS; i++) {
212                 reg = refill[i];
213                 reg |= (u32)(max[i]) << IXGBE_TDPT2TCCR_MCL_SHIFT;
214                 reg |= (u32)(bwg_id[i]) << IXGBE_TDPT2TCCR_BWG_SHIFT;
215
216                 if (tsa[i] == ixgbe_dcb_tsa_group_strict_cee)
217                         reg |= IXGBE_TDPT2TCCR_GSP;
218
219                 if (tsa[i] == ixgbe_dcb_tsa_strict)
220                         reg |= IXGBE_TDPT2TCCR_LSP;
221
222                 IXGBE_WRITE_REG(hw, IXGBE_TDPT2TCCR(i), reg);
223         }
224
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);
229
230         return IXGBE_SUCCESS;
231 }
232
233 /**
234  * ixgbe_dcb_config_pfc_82598 - Config priority flow control
235  * @hw: pointer to hardware structure
236  * @pfc_en: enabled pfc bitmask
237  *
238  * Configure Priority Flow Control for each traffic class.
239  */
240 s32 ixgbe_dcb_config_pfc_82598(struct ixgbe_hw *hw, u8 pfc_en)
241 {
242         u32 fcrtl, reg;
243         u8 i;
244
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);
250
251         /* Enable Receive Priority Flow Control */
252         reg = IXGBE_READ_REG(hw, IXGBE_FCTRL);
253         reg &= ~(IXGBE_FCTRL_RPFCE | IXGBE_FCTRL_RFCE);
254
255         if (pfc_en)
256                 reg |= IXGBE_FCTRL_RPFCE;
257
258         IXGBE_WRITE_REG(hw, IXGBE_FCTRL, reg);
259
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);
265                         continue;
266                 }
267
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);
272         }
273
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);
278
279         /* Configure flow control refresh threshold value */
280         IXGBE_WRITE_REG(hw, IXGBE_FCRTV, hw->fc.pause_time / 2);
281
282         return IXGBE_SUCCESS;
283 }
284
285 /**
286  * ixgbe_dcb_config_tc_stats_82598 - Configure traffic class statistics
287  * @hw: pointer to hardware structure
288  *
289  * Configure queue statistics registers, all queues belonging to same traffic
290  * class uses a single set of queue statistics counters.
291  */
292 s32 ixgbe_dcb_config_tc_stats_82598(struct ixgbe_hw *hw)
293 {
294         u32 reg = 0;
295         u8 i = 0;
296         u8 j = 0;
297
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);
306         }
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);
312         }
313
314         return IXGBE_SUCCESS;
315 }
316
317 /**
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
325  *
326  * Configure dcb settings and enable dcb mode.
327  */
328 s32 ixgbe_dcb_hw_config_82598(struct ixgbe_hw *hw, int link_speed,
329                               u16 *refill, u16 *max, u8 *bwg_id,
330                               u8 *tsa)
331 {
332         UNREFERENCED_1PARAMETER(link_speed);
333
334         ixgbe_dcb_config_rx_arbiter_82598(hw, refill, max, tsa);
335         ixgbe_dcb_config_tx_desc_arbiter_82598(hw, refill, max, bwg_id,
336                                                tsa);
337         ixgbe_dcb_config_tx_data_arbiter_82598(hw, refill, max, bwg_id,
338                                                tsa);
339         ixgbe_dcb_config_tc_stats_82598(hw);
340
341
342         return IXGBE_SUCCESS;
343 }