This source file includes following definitions.
- __cvmx_helper_rgmii_probe
- cvmx_helper_rgmii_internal_loopback
- __cvmx_helper_errata_asx_pass1
- __cvmx_helper_rgmii_enable
- __cvmx_helper_rgmii_link_get
- __cvmx_helper_rgmii_link_set
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
32 #include <asm/octeon/octeon.h>
33
34 #include <asm/octeon/cvmx-config.h>
35
36 #include <asm/octeon/cvmx-pko.h>
37 #include <asm/octeon/cvmx-helper.h>
38 #include <asm/octeon/cvmx-helper-board.h>
39
40 #include <asm/octeon/cvmx-npi-defs.h>
41 #include <asm/octeon/cvmx-gmxx-defs.h>
42 #include <asm/octeon/cvmx-asxx-defs.h>
43 #include <asm/octeon/cvmx-dbg-defs.h>
44
45
46
47
48
49
50
51
52 int __cvmx_helper_rgmii_probe(int interface)
53 {
54 int num_ports = 0;
55 union cvmx_gmxx_inf_mode mode;
56 mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
57
58 if (mode.s.type) {
59 if (OCTEON_IS_MODEL(OCTEON_CN38XX)
60 || OCTEON_IS_MODEL(OCTEON_CN58XX)) {
61 cvmx_dprintf("ERROR: RGMII initialize called in "
62 "SPI interface\n");
63 } else if (OCTEON_IS_MODEL(OCTEON_CN31XX)
64 || OCTEON_IS_MODEL(OCTEON_CN30XX)
65 || OCTEON_IS_MODEL(OCTEON_CN50XX)) {
66
67
68
69
70 num_ports = 2;
71 } else {
72 cvmx_dprintf("ERROR: Unsupported Octeon model in %s\n",
73 __func__);
74 }
75 } else {
76 if (OCTEON_IS_MODEL(OCTEON_CN38XX)
77 || OCTEON_IS_MODEL(OCTEON_CN58XX)) {
78 num_ports = 4;
79 } else if (OCTEON_IS_MODEL(OCTEON_CN31XX)
80 || OCTEON_IS_MODEL(OCTEON_CN30XX)
81 || OCTEON_IS_MODEL(OCTEON_CN50XX)) {
82 num_ports = 3;
83 } else {
84 cvmx_dprintf("ERROR: Unsupported Octeon model in %s\n",
85 __func__);
86 }
87 }
88 return num_ports;
89 }
90
91
92
93
94
95
96
97
98 void cvmx_helper_rgmii_internal_loopback(int port)
99 {
100 int interface = (port >> 4) & 1;
101 int index = port & 0xf;
102 uint64_t tmp;
103
104 union cvmx_gmxx_prtx_cfg gmx_cfg;
105 gmx_cfg.u64 = 0;
106 gmx_cfg.s.duplex = 1;
107 gmx_cfg.s.slottime = 1;
108 gmx_cfg.s.speed = 1;
109 cvmx_write_csr(CVMX_GMXX_TXX_CLK(index, interface), 1);
110 cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 0x200);
111 cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0x2000);
112 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmx_cfg.u64);
113 tmp = cvmx_read_csr(CVMX_ASXX_PRT_LOOP(interface));
114 cvmx_write_csr(CVMX_ASXX_PRT_LOOP(interface), (1 << index) | tmp);
115 tmp = cvmx_read_csr(CVMX_ASXX_TX_PRT_EN(interface));
116 cvmx_write_csr(CVMX_ASXX_TX_PRT_EN(interface), (1 << index) | tmp);
117 tmp = cvmx_read_csr(CVMX_ASXX_RX_PRT_EN(interface));
118 cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(interface), (1 << index) | tmp);
119 gmx_cfg.s.en = 1;
120 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmx_cfg.u64);
121 }
122
123
124
125
126
127
128
129
130
131
132
133 static int __cvmx_helper_errata_asx_pass1(int interface, int port,
134 int cpu_clock_hz)
135 {
136
137 if (cpu_clock_hz >= 325000000 && cpu_clock_hz < 375000000)
138 cvmx_write_csr(CVMX_ASXX_TX_HI_WATERX(port, interface), 12);
139 else if (cpu_clock_hz >= 375000000 && cpu_clock_hz < 437000000)
140 cvmx_write_csr(CVMX_ASXX_TX_HI_WATERX(port, interface), 11);
141 else if (cpu_clock_hz >= 437000000 && cpu_clock_hz < 550000000)
142 cvmx_write_csr(CVMX_ASXX_TX_HI_WATERX(port, interface), 10);
143 else if (cpu_clock_hz >= 550000000 && cpu_clock_hz < 687000000)
144 cvmx_write_csr(CVMX_ASXX_TX_HI_WATERX(port, interface), 9);
145 else
146 cvmx_dprintf("Illegal clock frequency (%d). "
147 "CVMX_ASXX_TX_HI_WATERX not set\n", cpu_clock_hz);
148 return 0;
149 }
150
151
152
153
154
155
156
157
158
159 int __cvmx_helper_rgmii_enable(int interface)
160 {
161 int num_ports = cvmx_helper_ports_on_interface(interface);
162 int port;
163 struct cvmx_sysinfo *sys_info_ptr = cvmx_sysinfo_get();
164 union cvmx_gmxx_inf_mode mode;
165 union cvmx_asxx_tx_prt_en asx_tx;
166 union cvmx_asxx_rx_prt_en asx_rx;
167
168 mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
169
170 if (mode.s.en == 0)
171 return -1;
172 if ((OCTEON_IS_MODEL(OCTEON_CN38XX) ||
173 OCTEON_IS_MODEL(OCTEON_CN58XX)) && mode.s.type == 1)
174
175 return -1;
176
177
178 asx_tx.u64 = 0;
179 asx_tx.s.prt_en = cvmx_build_mask(num_ports);
180 cvmx_write_csr(CVMX_ASXX_TX_PRT_EN(interface), asx_tx.u64);
181
182 asx_rx.u64 = 0;
183 asx_rx.s.prt_en = cvmx_build_mask(num_ports);
184 cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(interface), asx_rx.u64);
185
186
187 for (port = 0; port < num_ports; port++) {
188
189
190
191 if (cvmx_octeon_is_pass1())
192 __cvmx_helper_errata_asx_pass1(interface, port,
193 sys_info_ptr->
194 cpu_clock_hz);
195 else {
196
197
198
199
200
201 union cvmx_gmxx_rxx_frm_ctl frm_ctl;
202 frm_ctl.u64 =
203 cvmx_read_csr(CVMX_GMXX_RXX_FRM_CTL
204 (port, interface));
205
206 frm_ctl.s.pre_free = 1;
207 cvmx_write_csr(CVMX_GMXX_RXX_FRM_CTL(port, interface),
208 frm_ctl.u64);
209 }
210
211
212
213
214
215
216
217
218 cvmx_write_csr(CVMX_GMXX_TXX_PAUSE_PKT_TIME(port, interface),
219 20000);
220 cvmx_write_csr(CVMX_GMXX_TXX_PAUSE_PKT_INTERVAL
221 (port, interface), 19000);
222
223 if (OCTEON_IS_MODEL(OCTEON_CN50XX)) {
224 cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(port, interface),
225 16);
226 cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(port, interface),
227 16);
228 } else {
229 cvmx_write_csr(CVMX_ASXX_TX_CLK_SETX(port, interface),
230 24);
231 cvmx_write_csr(CVMX_ASXX_RX_CLK_SETX(port, interface),
232 24);
233 }
234 }
235
236 __cvmx_helper_setup_gmx(interface, num_ports);
237
238
239 for (port = 0; port < num_ports; port++) {
240 union cvmx_gmxx_prtx_cfg gmx_cfg;
241
242 gmx_cfg.u64 =
243 cvmx_read_csr(CVMX_GMXX_PRTX_CFG(port, interface));
244 gmx_cfg.s.en = 1;
245 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(port, interface),
246 gmx_cfg.u64);
247 }
248 __cvmx_interrupt_asxx_enable(interface);
249 __cvmx_interrupt_gmxx_enable(interface);
250
251 return 0;
252 }
253
254
255
256
257
258
259
260
261
262
263
264 cvmx_helper_link_info_t __cvmx_helper_rgmii_link_get(int ipd_port)
265 {
266 int interface = cvmx_helper_get_interface_num(ipd_port);
267 int index = cvmx_helper_get_interface_index_num(ipd_port);
268 union cvmx_asxx_prt_loop asxx_prt_loop;
269
270 asxx_prt_loop.u64 = cvmx_read_csr(CVMX_ASXX_PRT_LOOP(interface));
271 if (asxx_prt_loop.s.int_loop & (1 << index)) {
272
273 cvmx_helper_link_info_t result;
274 result.u64 = 0;
275 result.s.full_duplex = 1;
276 result.s.link_up = 1;
277 result.s.speed = 1000;
278 return result;
279 } else
280 return __cvmx_helper_board_link_get(ipd_port);
281 }
282
283
284
285
286
287
288
289
290
291
292
293
294 int __cvmx_helper_rgmii_link_set(int ipd_port,
295 cvmx_helper_link_info_t link_info)
296 {
297 int result = 0;
298 int interface = cvmx_helper_get_interface_num(ipd_port);
299 int index = cvmx_helper_get_interface_index_num(ipd_port);
300 union cvmx_gmxx_prtx_cfg original_gmx_cfg;
301 union cvmx_gmxx_prtx_cfg new_gmx_cfg;
302 union cvmx_pko_mem_queue_qos pko_mem_queue_qos;
303 union cvmx_pko_mem_queue_qos pko_mem_queue_qos_save[16];
304 union cvmx_gmxx_tx_ovr_bp gmx_tx_ovr_bp;
305 union cvmx_gmxx_tx_ovr_bp gmx_tx_ovr_bp_save;
306 int i;
307
308
309 if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_SIM)
310 return 0;
311
312
313 original_gmx_cfg.u64 =
314 cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
315 new_gmx_cfg = original_gmx_cfg;
316
317
318 cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(interface),
319 cvmx_read_csr(CVMX_ASXX_RX_PRT_EN(interface)) &
320 ~(1 << index));
321
322 memset(pko_mem_queue_qos_save, 0, sizeof(pko_mem_queue_qos_save));
323
324 for (i = 0; i < cvmx_pko_get_num_queues(ipd_port); i++) {
325 int queue = cvmx_pko_get_base_queue(ipd_port) + i;
326 cvmx_write_csr(CVMX_PKO_REG_READ_IDX, queue);
327 pko_mem_queue_qos.u64 = cvmx_read_csr(CVMX_PKO_MEM_QUEUE_QOS);
328 pko_mem_queue_qos.s.pid = ipd_port;
329 pko_mem_queue_qos.s.qid = queue;
330 pko_mem_queue_qos_save[i] = pko_mem_queue_qos;
331 pko_mem_queue_qos.s.qos_mask = 0;
332 cvmx_write_csr(CVMX_PKO_MEM_QUEUE_QOS, pko_mem_queue_qos.u64);
333 }
334
335
336 gmx_tx_ovr_bp.u64 = cvmx_read_csr(CVMX_GMXX_TX_OVR_BP(interface));
337 gmx_tx_ovr_bp_save = gmx_tx_ovr_bp;
338 gmx_tx_ovr_bp.s.bp &= ~(1 << index);
339 gmx_tx_ovr_bp.s.en |= 1 << index;
340 cvmx_write_csr(CVMX_GMXX_TX_OVR_BP(interface), gmx_tx_ovr_bp.u64);
341 cvmx_read_csr(CVMX_GMXX_TX_OVR_BP(interface));
342
343
344
345
346
347
348
349
350 cvmx_write_csr(CVMX_NPI_DBG_SELECT,
351 interface * 0x800 + index * 0x100 + 0x880);
352 CVMX_WAIT_FOR_FIELD64(CVMX_DBG_DATA, union cvmx_dbg_data, data & 7,
353 ==, 0, 10000);
354 CVMX_WAIT_FOR_FIELD64(CVMX_DBG_DATA, union cvmx_dbg_data, data & 0xf,
355 ==, 0, 10000);
356
357
358 new_gmx_cfg.s.en = 0;
359 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), new_gmx_cfg.u64);
360 cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
361
362
363 if (cvmx_octeon_is_pass1())
364
365 new_gmx_cfg.s.duplex = 1;
366 else if (!link_info.s.link_up)
367
368 new_gmx_cfg.s.duplex = 1;
369 else
370 new_gmx_cfg.s.duplex = link_info.s.full_duplex;
371
372
373 if (link_info.s.speed == 10) {
374 new_gmx_cfg.s.slottime = 0;
375 new_gmx_cfg.s.speed = 0;
376 } else if (link_info.s.speed == 100) {
377 new_gmx_cfg.s.slottime = 0;
378 new_gmx_cfg.s.speed = 0;
379 } else {
380 new_gmx_cfg.s.slottime = 1;
381 new_gmx_cfg.s.speed = 1;
382 }
383
384
385 if (link_info.s.speed == 10) {
386 cvmx_write_csr(CVMX_GMXX_TXX_CLK(index, interface), 50);
387 cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 0x40);
388 cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0);
389 } else if (link_info.s.speed == 100) {
390 cvmx_write_csr(CVMX_GMXX_TXX_CLK(index, interface), 5);
391 cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 0x40);
392 cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0);
393 } else {
394 cvmx_write_csr(CVMX_GMXX_TXX_CLK(index, interface), 1);
395 cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 0x200);
396 cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0x2000);
397 }
398
399 if (OCTEON_IS_MODEL(OCTEON_CN30XX) || OCTEON_IS_MODEL(OCTEON_CN50XX)) {
400 if ((link_info.s.speed == 10) || (link_info.s.speed == 100)) {
401 union cvmx_gmxx_inf_mode mode;
402 mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
403
404
405
406
407
408
409
410
411
412
413
414
415
416 if (((index == 0) && (mode.s.p0mii == 1))
417 || ((index != 0) && (mode.s.type == 1))) {
418 cvmx_write_csr(CVMX_GMXX_TXX_CLK
419 (index, interface), 1);
420 }
421 }
422 }
423
424
425 cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
426
427
428 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), new_gmx_cfg.u64);
429
430
431 cvmx_write_csr(CVMX_ASXX_RX_PRT_EN(interface),
432 cvmx_read_csr(CVMX_ASXX_RX_PRT_EN(interface)) | (1 <<
433 index));
434
435
436 for (i = 0; i < cvmx_pko_get_num_queues(ipd_port); i++) {
437 int queue = cvmx_pko_get_base_queue(ipd_port) + i;
438 cvmx_write_csr(CVMX_PKO_REG_READ_IDX, queue);
439 cvmx_write_csr(CVMX_PKO_MEM_QUEUE_QOS,
440 pko_mem_queue_qos_save[i].u64);
441 }
442
443
444 cvmx_write_csr(CVMX_GMXX_TX_OVR_BP(interface), gmx_tx_ovr_bp_save.u64);
445
446
447 new_gmx_cfg.s.en = original_gmx_cfg.s.en;
448 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), new_gmx_cfg.u64);
449
450 return result;
451 }