1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31#include <linux/kernel.h>
32
33#include <asm/octeon/octeon.h>
34
35#include <asm/octeon/cvmx-config.h>
36
37#include <asm/octeon/cvmx-fpa.h>
38#include <asm/octeon/cvmx-pip.h>
39#include <asm/octeon/cvmx-pko.h>
40#include <asm/octeon/cvmx-ipd.h>
41#include <asm/octeon/cvmx-spi.h>
42
43#include <asm/octeon/cvmx-helper.h>
44#include <asm/octeon/cvmx-helper-util.h>
45
46#include <asm/octeon/cvmx-ipd-defs.h>
47
48
49
50
51
52
53
54
55const char *cvmx_helper_interface_mode_to_string(cvmx_helper_interface_mode_t
56 mode)
57{
58 switch (mode) {
59 case CVMX_HELPER_INTERFACE_MODE_DISABLED:
60 return "DISABLED";
61 case CVMX_HELPER_INTERFACE_MODE_RGMII:
62 return "RGMII";
63 case CVMX_HELPER_INTERFACE_MODE_GMII:
64 return "GMII";
65 case CVMX_HELPER_INTERFACE_MODE_SPI:
66 return "SPI";
67 case CVMX_HELPER_INTERFACE_MODE_PCIE:
68 return "PCIE";
69 case CVMX_HELPER_INTERFACE_MODE_XAUI:
70 return "XAUI";
71 case CVMX_HELPER_INTERFACE_MODE_SGMII:
72 return "SGMII";
73 case CVMX_HELPER_INTERFACE_MODE_PICMG:
74 return "PICMG";
75 case CVMX_HELPER_INTERFACE_MODE_NPI:
76 return "NPI";
77 case CVMX_HELPER_INTERFACE_MODE_LOOP:
78 return "LOOP";
79 }
80 return "UNKNOWN";
81}
82
83
84
85
86
87
88
89
90
91
92
93
94
95static int cvmx_helper_setup_red_queue(int queue, int pass_thresh,
96 int drop_thresh)
97{
98 union cvmx_ipd_qosx_red_marks red_marks;
99 union cvmx_ipd_red_quex_param red_param;
100
101
102
103
104 red_marks.u64 = 0;
105 red_marks.s.drop = drop_thresh;
106 red_marks.s.pass = pass_thresh;
107 cvmx_write_csr(CVMX_IPD_QOSX_RED_MARKS(queue), red_marks.u64);
108
109
110 red_param.u64 = 0;
111 red_param.s.prb_con =
112 (255ul << 24) / (red_marks.s.pass - red_marks.s.drop);
113 red_param.s.avg_con = 1;
114 red_param.s.new_con = 255;
115 red_param.s.use_pcnt = 1;
116 cvmx_write_csr(CVMX_IPD_RED_QUEX_PARAM(queue), red_param.u64);
117 return 0;
118}
119
120
121
122
123
124
125
126
127
128
129
130
131int cvmx_helper_setup_red(int pass_thresh, int drop_thresh)
132{
133 union cvmx_ipd_portx_bp_page_cnt page_cnt;
134 union cvmx_ipd_bp_prt_red_end ipd_bp_prt_red_end;
135 union cvmx_ipd_red_port_enable red_port_enable;
136 int queue;
137 int interface;
138 int port;
139
140
141 page_cnt.u64 = 0;
142 page_cnt.s.bp_enb = 0;
143 page_cnt.s.page_cnt = 100;
144 for (interface = 0; interface < 2; interface++) {
145 for (port = cvmx_helper_get_first_ipd_port(interface);
146 port < cvmx_helper_get_last_ipd_port(interface); port++)
147 cvmx_write_csr(CVMX_IPD_PORTX_BP_PAGE_CNT(port),
148 page_cnt.u64);
149 }
150
151 for (queue = 0; queue < 8; queue++)
152 cvmx_helper_setup_red_queue(queue, pass_thresh, drop_thresh);
153
154
155
156 ipd_bp_prt_red_end.u64 = 0;
157 ipd_bp_prt_red_end.s.prt_enb = 0;
158 cvmx_write_csr(CVMX_IPD_BP_PRT_RED_END, ipd_bp_prt_red_end.u64);
159
160 red_port_enable.u64 = 0;
161 red_port_enable.s.prt_enb = 0xfffffffffull;
162 red_port_enable.s.avg_dly = 10000;
163 red_port_enable.s.prb_dly = 10000;
164 cvmx_write_csr(CVMX_IPD_RED_PORT_ENABLE, red_port_enable.u64);
165
166 return 0;
167}
168EXPORT_SYMBOL_GPL(cvmx_helper_setup_red);
169
170
171
172
173
174
175
176
177
178
179
180int __cvmx_helper_setup_gmx(int interface, int num_ports)
181{
182 union cvmx_gmxx_tx_prts gmx_tx_prts;
183 union cvmx_gmxx_rx_prts gmx_rx_prts;
184 union cvmx_pko_reg_gmx_port_mode pko_mode;
185 union cvmx_gmxx_txx_thresh gmx_tx_thresh;
186 int index;
187
188
189 gmx_tx_prts.u64 = cvmx_read_csr(CVMX_GMXX_TX_PRTS(interface));
190 gmx_tx_prts.s.prts = num_ports;
191 cvmx_write_csr(CVMX_GMXX_TX_PRTS(interface), gmx_tx_prts.u64);
192
193
194
195 if (cvmx_helper_interface_get_mode(interface) ==
196 CVMX_HELPER_INTERFACE_MODE_RGMII
197 || cvmx_helper_interface_get_mode(interface) ==
198 CVMX_HELPER_INTERFACE_MODE_SGMII
199 || cvmx_helper_interface_get_mode(interface) ==
200 CVMX_HELPER_INTERFACE_MODE_GMII
201 || cvmx_helper_interface_get_mode(interface) ==
202 CVMX_HELPER_INTERFACE_MODE_XAUI) {
203 if (num_ports > 4) {
204 cvmx_dprintf("__cvmx_helper_setup_gmx: Illegal "
205 "num_ports\n");
206 return -1;
207 }
208
209 gmx_rx_prts.u64 = cvmx_read_csr(CVMX_GMXX_RX_PRTS(interface));
210 gmx_rx_prts.s.prts = num_ports;
211 cvmx_write_csr(CVMX_GMXX_RX_PRTS(interface), gmx_rx_prts.u64);
212 }
213
214
215 if (!OCTEON_IS_MODEL(OCTEON_CN30XX) && !OCTEON_IS_MODEL(OCTEON_CN31XX)
216 && !OCTEON_IS_MODEL(OCTEON_CN50XX)) {
217
218 pko_mode.u64 = cvmx_read_csr(CVMX_PKO_REG_GMX_PORT_MODE);
219 if (interface == 0) {
220 if (num_ports == 1)
221 pko_mode.s.mode0 = 4;
222 else if (num_ports == 2)
223 pko_mode.s.mode0 = 3;
224 else if (num_ports <= 4)
225 pko_mode.s.mode0 = 2;
226 else if (num_ports <= 8)
227 pko_mode.s.mode0 = 1;
228 else
229 pko_mode.s.mode0 = 0;
230 } else {
231 if (num_ports == 1)
232 pko_mode.s.mode1 = 4;
233 else if (num_ports == 2)
234 pko_mode.s.mode1 = 3;
235 else if (num_ports <= 4)
236 pko_mode.s.mode1 = 2;
237 else if (num_ports <= 8)
238 pko_mode.s.mode1 = 1;
239 else
240 pko_mode.s.mode1 = 0;
241 }
242 cvmx_write_csr(CVMX_PKO_REG_GMX_PORT_MODE, pko_mode.u64);
243 }
244
245
246
247
248
249
250
251
252 gmx_tx_thresh.u64 = cvmx_read_csr(CVMX_GMXX_TXX_THRESH(0, interface));
253 if (OCTEON_IS_MODEL(OCTEON_CN30XX) || OCTEON_IS_MODEL(OCTEON_CN31XX)
254 || OCTEON_IS_MODEL(OCTEON_CN50XX)) {
255
256 gmx_tx_thresh.s.cnt = 0x40;
257 } else {
258
259 if (num_ports <= 1)
260 gmx_tx_thresh.s.cnt = 0x100 / 1;
261 else if (num_ports == 2)
262 gmx_tx_thresh.s.cnt = 0x100 / 2;
263 else
264 gmx_tx_thresh.s.cnt = 0x100 / 4;
265 }
266
267
268
269
270 if (num_ports > 4)
271 num_ports = 4;
272 for (index = 0; index < num_ports; index++)
273 cvmx_write_csr(CVMX_GMXX_TXX_THRESH(index, interface),
274 gmx_tx_thresh.u64);
275
276 return 0;
277}
278
279
280
281
282
283
284
285
286
287
288int cvmx_helper_get_ipd_port(int interface, int port)
289{
290 switch (interface) {
291 case 0:
292 return port;
293 case 1:
294 return port + 16;
295 case 2:
296 return port + 32;
297 case 3:
298 return port + 36;
299 case 4:
300 return port + 40;
301 case 5:
302 return port + 44;
303 }
304 return -1;
305}
306EXPORT_SYMBOL_GPL(cvmx_helper_get_ipd_port);
307
308
309
310
311
312
313
314
315int cvmx_helper_get_interface_num(int ipd_port)
316{
317 if (ipd_port < 16)
318 return 0;
319 else if (ipd_port < 32)
320 return 1;
321 else if (ipd_port < 36)
322 return 2;
323 else if (ipd_port < 40)
324 return 3;
325 else if (ipd_port < 44)
326 return 4;
327 else if (ipd_port < 48)
328 return 5;
329 else
330 cvmx_dprintf("cvmx_helper_get_interface_num: Illegal IPD "
331 "port number\n");
332
333 return -1;
334}
335EXPORT_SYMBOL_GPL(cvmx_helper_get_interface_num);
336
337
338
339
340
341
342
343
344
345int cvmx_helper_get_interface_index_num(int ipd_port)
346{
347 if (ipd_port < 32)
348 return ipd_port & 15;
349 else if (ipd_port < 36)
350 return ipd_port & 3;
351 else if (ipd_port < 40)
352 return ipd_port & 3;
353 else if (ipd_port < 44)
354 return ipd_port & 3;
355 else if (ipd_port < 48)
356 return ipd_port & 3;
357 else
358 cvmx_dprintf("cvmx_helper_get_interface_index_num: "
359 "Illegal IPD port number\n");
360
361 return -1;
362}
363EXPORT_SYMBOL_GPL(cvmx_helper_get_interface_index_num);
364