This source file includes following definitions.
- __cvmx_helper_sgmii_hardware_init_one_time
- __cvmx_helper_sgmii_hardware_init_link
- __cvmx_helper_sgmii_hardware_init_link_speed
- __cvmx_helper_sgmii_hardware_init
- __cvmx_helper_sgmii_enumerate
- __cvmx_helper_sgmii_probe
- __cvmx_helper_sgmii_enable
- __cvmx_helper_sgmii_link_get
- __cvmx_helper_sgmii_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
33 #include <asm/octeon/octeon.h>
34
35 #include <asm/octeon/cvmx-config.h>
36
37 #include <asm/octeon/cvmx-helper.h>
38 #include <asm/octeon/cvmx-helper-board.h>
39
40 #include <asm/octeon/cvmx-gmxx-defs.h>
41 #include <asm/octeon/cvmx-pcsx-defs.h>
42 #include <asm/octeon/cvmx-pcsxx-defs.h>
43
44
45
46
47
48
49
50
51
52 static int __cvmx_helper_sgmii_hardware_init_one_time(int interface, int index)
53 {
54 const uint64_t clock_mhz = cvmx_sysinfo_get()->cpu_clock_hz / 1000000;
55 union cvmx_pcsx_miscx_ctl_reg pcs_misc_ctl_reg;
56 union cvmx_pcsx_linkx_timer_count_reg pcsx_linkx_timer_count_reg;
57 union cvmx_gmxx_prtx_cfg gmxx_prtx_cfg;
58
59
60 gmxx_prtx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
61 gmxx_prtx_cfg.s.en = 0;
62 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmxx_prtx_cfg.u64);
63
64
65
66
67
68
69 pcs_misc_ctl_reg.u64 =
70 cvmx_read_csr(CVMX_PCSX_MISCX_CTL_REG(index, interface));
71 pcsx_linkx_timer_count_reg.u64 =
72 cvmx_read_csr(CVMX_PCSX_LINKX_TIMER_COUNT_REG(index, interface));
73 if (pcs_misc_ctl_reg.s.mode) {
74
75 pcsx_linkx_timer_count_reg.s.count =
76 (10000ull * clock_mhz) >> 10;
77 } else {
78
79 pcsx_linkx_timer_count_reg.s.count =
80 (1600ull * clock_mhz) >> 10;
81 }
82 cvmx_write_csr(CVMX_PCSX_LINKX_TIMER_COUNT_REG(index, interface),
83 pcsx_linkx_timer_count_reg.u64);
84
85
86
87
88
89
90
91
92
93
94 if (pcs_misc_ctl_reg.s.mode) {
95
96 union cvmx_pcsx_anx_adv_reg pcsx_anx_adv_reg;
97 pcsx_anx_adv_reg.u64 =
98 cvmx_read_csr(CVMX_PCSX_ANX_ADV_REG(index, interface));
99 pcsx_anx_adv_reg.s.rem_flt = 0;
100 pcsx_anx_adv_reg.s.pause = 3;
101 pcsx_anx_adv_reg.s.hfd = 1;
102 pcsx_anx_adv_reg.s.fd = 1;
103 cvmx_write_csr(CVMX_PCSX_ANX_ADV_REG(index, interface),
104 pcsx_anx_adv_reg.u64);
105 } else {
106 union cvmx_pcsx_miscx_ctl_reg pcsx_miscx_ctl_reg;
107 pcsx_miscx_ctl_reg.u64 =
108 cvmx_read_csr(CVMX_PCSX_MISCX_CTL_REG(index, interface));
109 if (pcsx_miscx_ctl_reg.s.mac_phy) {
110
111 union cvmx_pcsx_sgmx_an_adv_reg pcsx_sgmx_an_adv_reg;
112 pcsx_sgmx_an_adv_reg.u64 =
113 cvmx_read_csr(CVMX_PCSX_SGMX_AN_ADV_REG
114 (index, interface));
115 pcsx_sgmx_an_adv_reg.s.link = 1;
116 pcsx_sgmx_an_adv_reg.s.dup = 1;
117 pcsx_sgmx_an_adv_reg.s.speed = 2;
118 cvmx_write_csr(CVMX_PCSX_SGMX_AN_ADV_REG
119 (index, interface),
120 pcsx_sgmx_an_adv_reg.u64);
121 } else {
122
123 }
124 }
125 return 0;
126 }
127
128
129
130
131
132
133
134
135
136
137 static int __cvmx_helper_sgmii_hardware_init_link(int interface, int index)
138 {
139 union cvmx_pcsx_mrx_control_reg control_reg;
140
141
142
143
144
145
146
147
148
149 control_reg.u64 =
150 cvmx_read_csr(CVMX_PCSX_MRX_CONTROL_REG(index, interface));
151 if (cvmx_sysinfo_get()->board_type != CVMX_BOARD_TYPE_SIM) {
152 control_reg.s.reset = 1;
153 cvmx_write_csr(CVMX_PCSX_MRX_CONTROL_REG(index, interface),
154 control_reg.u64);
155 if (CVMX_WAIT_FOR_FIELD64
156 (CVMX_PCSX_MRX_CONTROL_REG(index, interface),
157 union cvmx_pcsx_mrx_control_reg, reset, ==, 0, 10000)) {
158 cvmx_dprintf("SGMII%d: Timeout waiting for port %d "
159 "to finish reset\n",
160 interface, index);
161 return -1;
162 }
163 }
164
165
166
167
168
169 control_reg.s.rst_an = 1;
170 control_reg.s.an_en = 1;
171 control_reg.s.pwr_dn = 0;
172 cvmx_write_csr(CVMX_PCSX_MRX_CONTROL_REG(index, interface),
173 control_reg.u64);
174
175
176
177
178
179
180
181 if ((cvmx_sysinfo_get()->board_type != CVMX_BOARD_TYPE_SIM) &&
182 CVMX_WAIT_FOR_FIELD64(CVMX_PCSX_MRX_STATUS_REG(index, interface),
183 union cvmx_pcsx_mrx_status_reg, an_cpt, ==, 1,
184 10000)) {
185
186 return -1;
187 }
188 return 0;
189 }
190
191
192
193
194
195
196
197
198
199
200
201 static int __cvmx_helper_sgmii_hardware_init_link_speed(int interface,
202 int index,
203 cvmx_helper_link_info_t
204 link_info)
205 {
206 int is_enabled;
207 union cvmx_gmxx_prtx_cfg gmxx_prtx_cfg;
208 union cvmx_pcsx_miscx_ctl_reg pcsx_miscx_ctl_reg;
209
210
211 gmxx_prtx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
212 is_enabled = gmxx_prtx_cfg.s.en;
213 gmxx_prtx_cfg.s.en = 0;
214 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmxx_prtx_cfg.u64);
215
216
217 if (CVMX_WAIT_FOR_FIELD64
218 (CVMX_GMXX_PRTX_CFG(index, interface), union cvmx_gmxx_prtx_cfg,
219 rx_idle, ==, 1, 10000)
220 || CVMX_WAIT_FOR_FIELD64(CVMX_GMXX_PRTX_CFG(index, interface),
221 union cvmx_gmxx_prtx_cfg, tx_idle, ==, 1,
222 10000)) {
223 cvmx_dprintf
224 ("SGMII%d: Timeout waiting for port %d to be idle\n",
225 interface, index);
226 return -1;
227 }
228
229
230 gmxx_prtx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
231
232
233
234
235
236 pcsx_miscx_ctl_reg.u64 =
237 cvmx_read_csr(CVMX_PCSX_MISCX_CTL_REG(index, interface));
238
239
240
241
242
243 pcsx_miscx_ctl_reg.s.gmxeno = !link_info.s.link_up;
244
245
246 if (link_info.s.link_up)
247 gmxx_prtx_cfg.s.duplex = link_info.s.full_duplex;
248
249
250 switch (link_info.s.speed) {
251 case 10:
252 gmxx_prtx_cfg.s.speed = 0;
253 gmxx_prtx_cfg.s.speed_msb = 1;
254 gmxx_prtx_cfg.s.slottime = 0;
255
256 pcsx_miscx_ctl_reg.s.samp_pt = 25;
257 cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 64);
258 cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0);
259 break;
260 case 100:
261 gmxx_prtx_cfg.s.speed = 0;
262 gmxx_prtx_cfg.s.speed_msb = 0;
263 gmxx_prtx_cfg.s.slottime = 0;
264 pcsx_miscx_ctl_reg.s.samp_pt = 0x5;
265 cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 64);
266 cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0);
267 break;
268 case 1000:
269 gmxx_prtx_cfg.s.speed = 1;
270 gmxx_prtx_cfg.s.speed_msb = 0;
271 gmxx_prtx_cfg.s.slottime = 1;
272 pcsx_miscx_ctl_reg.s.samp_pt = 1;
273 cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 512);
274 cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 8192);
275 break;
276 default:
277 break;
278 }
279
280
281 cvmx_write_csr(CVMX_PCSX_MISCX_CTL_REG(index, interface),
282 pcsx_miscx_ctl_reg.u64);
283
284
285 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmxx_prtx_cfg.u64);
286
287
288 gmxx_prtx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
289
290
291 gmxx_prtx_cfg.s.en = is_enabled;
292 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmxx_prtx_cfg.u64);
293
294 return 0;
295 }
296
297
298
299
300
301
302
303
304
305
306
307 static int __cvmx_helper_sgmii_hardware_init(int interface, int num_ports)
308 {
309 int index;
310
311 __cvmx_helper_setup_gmx(interface, num_ports);
312
313 for (index = 0; index < num_ports; index++) {
314 int ipd_port = cvmx_helper_get_ipd_port(interface, index);
315 __cvmx_helper_sgmii_hardware_init_one_time(interface, index);
316
317
318
319
320
321 if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_SIM)
322 __cvmx_helper_sgmii_link_set(ipd_port,
323 __cvmx_helper_sgmii_link_get(ipd_port));
324 }
325
326 return 0;
327 }
328
329 int __cvmx_helper_sgmii_enumerate(int interface)
330 {
331 return 4;
332 }
333
334
335
336
337
338
339
340
341
342 int __cvmx_helper_sgmii_probe(int interface)
343 {
344 union cvmx_gmxx_inf_mode mode;
345
346
347
348
349
350
351 mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
352 mode.s.en = 1;
353 cvmx_write_csr(CVMX_GMXX_INF_MODE(interface), mode.u64);
354 return __cvmx_helper_sgmii_enumerate(interface);
355 }
356
357
358
359
360
361
362
363
364
365
366 int __cvmx_helper_sgmii_enable(int interface)
367 {
368 int num_ports = cvmx_helper_ports_on_interface(interface);
369 int index;
370
371 __cvmx_helper_sgmii_hardware_init(interface, num_ports);
372
373 for (index = 0; index < num_ports; index++) {
374 union cvmx_gmxx_prtx_cfg gmxx_prtx_cfg;
375 gmxx_prtx_cfg.u64 =
376 cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
377 gmxx_prtx_cfg.s.en = 1;
378 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface),
379 gmxx_prtx_cfg.u64);
380 __cvmx_interrupt_pcsx_intx_en_reg_enable(index, interface);
381 }
382 __cvmx_interrupt_pcsxx_int_en_reg_enable(interface);
383 __cvmx_interrupt_gmxx_enable(interface);
384 return 0;
385 }
386
387
388
389
390
391
392
393
394
395
396
397 cvmx_helper_link_info_t __cvmx_helper_sgmii_link_get(int ipd_port)
398 {
399 cvmx_helper_link_info_t result;
400 union cvmx_pcsx_miscx_ctl_reg pcs_misc_ctl_reg;
401 int interface = cvmx_helper_get_interface_num(ipd_port);
402 int index = cvmx_helper_get_interface_index_num(ipd_port);
403 union cvmx_pcsx_mrx_control_reg pcsx_mrx_control_reg;
404
405 result.u64 = 0;
406
407 if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_SIM) {
408
409 result.s.link_up = 1;
410 result.s.full_duplex = 1;
411 result.s.speed = 1000;
412 return result;
413 }
414
415 pcsx_mrx_control_reg.u64 =
416 cvmx_read_csr(CVMX_PCSX_MRX_CONTROL_REG(index, interface));
417 if (pcsx_mrx_control_reg.s.loopbck1) {
418
419 result.s.link_up = 1;
420 result.s.full_duplex = 1;
421 result.s.speed = 1000;
422 return result;
423 }
424
425 pcs_misc_ctl_reg.u64 =
426 cvmx_read_csr(CVMX_PCSX_MISCX_CTL_REG(index, interface));
427 if (pcs_misc_ctl_reg.s.mode) {
428
429
430 } else {
431 union cvmx_pcsx_miscx_ctl_reg pcsx_miscx_ctl_reg;
432 pcsx_miscx_ctl_reg.u64 =
433 cvmx_read_csr(CVMX_PCSX_MISCX_CTL_REG(index, interface));
434 if (pcsx_miscx_ctl_reg.s.mac_phy) {
435
436 union cvmx_pcsx_mrx_status_reg pcsx_mrx_status_reg;
437 union cvmx_pcsx_anx_results_reg pcsx_anx_results_reg;
438
439
440
441
442
443 pcsx_mrx_status_reg.u64 =
444 cvmx_read_csr(CVMX_PCSX_MRX_STATUS_REG
445 (index, interface));
446 if (pcsx_mrx_status_reg.s.lnk_st == 0) {
447 if (__cvmx_helper_sgmii_hardware_init_link
448 (interface, index) != 0)
449 return result;
450 }
451
452
453 pcsx_anx_results_reg.u64 =
454 cvmx_read_csr(CVMX_PCSX_ANX_RESULTS_REG
455 (index, interface));
456 if (pcsx_anx_results_reg.s.an_cpt) {
457
458
459
460
461 result.s.full_duplex =
462 pcsx_anx_results_reg.s.dup;
463 result.s.link_up =
464 pcsx_anx_results_reg.s.link_ok;
465 switch (pcsx_anx_results_reg.s.spd) {
466 case 0:
467 result.s.speed = 10;
468 break;
469 case 1:
470 result.s.speed = 100;
471 break;
472 case 2:
473 result.s.speed = 1000;
474 break;
475 default:
476 result.s.speed = 0;
477 result.s.link_up = 0;
478 break;
479 }
480 } else {
481
482
483
484
485 result.s.speed = 0;
486 result.s.link_up = 0;
487 }
488 } else {
489
490 result = __cvmx_helper_board_link_get(ipd_port);
491 }
492 }
493 return result;
494 }
495
496
497
498
499
500
501
502
503
504
505
506
507 int __cvmx_helper_sgmii_link_set(int ipd_port,
508 cvmx_helper_link_info_t link_info)
509 {
510 int interface = cvmx_helper_get_interface_num(ipd_port);
511 int index = cvmx_helper_get_interface_index_num(ipd_port);
512 __cvmx_helper_sgmii_hardware_init_link(interface, index);
513 return __cvmx_helper_sgmii_hardware_init_link_speed(interface, index,
514 link_info);
515 }