56 static int __cvmx_helper_sgmii_hardware_init_one_time(
int interface,
int index)
64 gmxx_prtx_cfg.
u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
65 gmxx_prtx_cfg.s.en = 0;
66 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmxx_prtx_cfg.u64);
73 pcs_misc_ctl_reg.u64 =
74 cvmx_read_csr(CVMX_PCSX_MISCX_CTL_REG(index, interface));
75 pcsx_linkx_timer_count_reg.u64 =
76 cvmx_read_csr(CVMX_PCSX_LINKX_TIMER_COUNT_REG(index, interface));
77 if (pcs_misc_ctl_reg.s.mode) {
79 pcsx_linkx_timer_count_reg.s.count =
80 (10000ull * clock_mhz) >> 10;
83 pcsx_linkx_timer_count_reg.s.count =
84 (1600ull * clock_mhz) >> 10;
86 cvmx_write_csr(CVMX_PCSX_LINKX_TIMER_COUNT_REG(index, interface),
87 pcsx_linkx_timer_count_reg.u64);
98 if (pcs_misc_ctl_reg.s.mode) {
101 pcsx_anx_adv_reg.
u64 =
102 cvmx_read_csr(CVMX_PCSX_ANX_ADV_REG(index, interface));
103 pcsx_anx_adv_reg.s.rem_flt = 0;
104 pcsx_anx_adv_reg.s.pause = 3;
105 pcsx_anx_adv_reg.s.hfd = 1;
106 pcsx_anx_adv_reg.s.fd = 1;
107 cvmx_write_csr(CVMX_PCSX_ANX_ADV_REG(index, interface),
108 pcsx_anx_adv_reg.u64);
111 pcsx_miscx_ctl_reg.
u64 =
112 cvmx_read_csr(CVMX_PCSX_MISCX_CTL_REG(index, interface));
113 if (pcsx_miscx_ctl_reg.s.mac_phy) {
116 pcsx_sgmx_an_adv_reg.
u64 =
117 cvmx_read_csr(CVMX_PCSX_SGMX_AN_ADV_REG
119 pcsx_sgmx_an_adv_reg.s.link = 1;
120 pcsx_sgmx_an_adv_reg.s.dup = 1;
121 pcsx_sgmx_an_adv_reg.s.speed = 2;
122 cvmx_write_csr(CVMX_PCSX_SGMX_AN_ADV_REG
124 pcsx_sgmx_an_adv_reg.u64);
141 static int __cvmx_helper_sgmii_hardware_init_link(
int interface,
int index)
154 cvmx_read_csr(CVMX_PCSX_MRX_CONTROL_REG(index, interface));
156 control_reg.s.reset = 1;
157 cvmx_write_csr(CVMX_PCSX_MRX_CONTROL_REG(index, interface),
160 (CVMX_PCSX_MRX_CONTROL_REG(index, interface),
173 control_reg.s.rst_an = 1;
174 control_reg.s.an_en = 1;
175 control_reg.s.pwr_dn = 0;
176 cvmx_write_csr(CVMX_PCSX_MRX_CONTROL_REG(index, interface),
205 static int __cvmx_helper_sgmii_hardware_init_link_speed(
int interface,
215 gmxx_prtx_cfg.
u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
216 is_enabled = gmxx_prtx_cfg.s.en;
217 gmxx_prtx_cfg.s.en = 0;
218 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmxx_prtx_cfg.u64);
223 rx_idle, ==, 1, 10000)
228 (
"SGMII%d: Timeout waiting for port %d to be idle\n",
234 gmxx_prtx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
240 pcsx_miscx_ctl_reg.u64 =
241 cvmx_read_csr(CVMX_PCSX_MISCX_CTL_REG(index, interface));
247 pcsx_miscx_ctl_reg.s.gmxeno = !link_info.
s.link_up;
250 if (link_info.
s.link_up)
251 gmxx_prtx_cfg.s.duplex = link_info.
s.full_duplex;
254 switch (link_info.
s.speed) {
256 gmxx_prtx_cfg.s.speed = 0;
257 gmxx_prtx_cfg.s.speed_msb = 1;
258 gmxx_prtx_cfg.s.slottime = 0;
260 pcsx_miscx_ctl_reg.s.samp_pt = 25;
261 cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 64);
262 cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0);
265 gmxx_prtx_cfg.s.speed = 0;
266 gmxx_prtx_cfg.s.speed_msb = 0;
267 gmxx_prtx_cfg.s.slottime = 0;
268 pcsx_miscx_ctl_reg.s.samp_pt = 0x5;
269 cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 64);
270 cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 0);
273 gmxx_prtx_cfg.s.speed = 1;
274 gmxx_prtx_cfg.s.speed_msb = 0;
275 gmxx_prtx_cfg.s.slottime = 1;
276 pcsx_miscx_ctl_reg.s.samp_pt = 1;
277 cvmx_write_csr(CVMX_GMXX_TXX_SLOT(index, interface), 512);
278 cvmx_write_csr(CVMX_GMXX_TXX_BURST(index, interface), 8192);
285 cvmx_write_csr(CVMX_PCSX_MISCX_CTL_REG(index, interface),
286 pcsx_miscx_ctl_reg.u64);
289 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmxx_prtx_cfg.u64);
292 gmxx_prtx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(index, interface));
296 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(index, interface), gmxx_prtx_cfg.u64);
311 static int __cvmx_helper_sgmii_hardware_init(
int interface,
int num_ports)
317 for (index = 0; index < num_ports; index++) {
319 __cvmx_helper_sgmii_hardware_init_one_time(interface, index);
351 mode.
u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
353 cvmx_write_csr(CVMX_GMXX_INF_MODE(interface), mode.
u64);
371 __cvmx_helper_sgmii_hardware_init(interface, num_ports);
373 for (index = 0; index < num_ports; index++) {
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),
401 int interface = cvmx_helper_get_interface_num(ipd_port);
409 result.
s.link_up = 1;
410 result.
s.full_duplex = 1;
411 result.
s.speed = 1000;
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) {
419 result.
s.link_up = 1;
420 result.
s.full_duplex = 1;
421 result.
s.speed = 1000;
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) {
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) {
443 pcsx_mrx_status_reg.
u64 =
444 cvmx_read_csr(CVMX_PCSX_MRX_STATUS_REG
446 if (pcsx_mrx_status_reg.
s.lnk_st == 0) {
447 if (__cvmx_helper_sgmii_hardware_init_link
448 (interface, index) != 0)
453 pcsx_anx_results_reg.
u64 =
454 cvmx_read_csr(CVMX_PCSX_ANX_RESULTS_REG
456 if (pcsx_anx_results_reg.
s.an_cpt) {
461 result.
s.full_duplex =
462 pcsx_anx_results_reg.
s.dup;
464 pcsx_anx_results_reg.
s.link_ok;
465 switch (pcsx_anx_results_reg.
s.spd) {
470 result.
s.speed = 100;
473 result.
s.speed = 1000;
477 result.
s.link_up = 0;
486 result.
s.link_up = 0;
511 int interface = cvmx_helper_get_interface_num(ipd_port);
513 __cvmx_helper_sgmii_hardware_init_link(interface, index);
514 return __cvmx_helper_sgmii_hardware_init_link_speed(interface, index,
535 int interface = cvmx_helper_get_interface_num(ipd_port);
540 pcsx_mrx_control_reg.
u64 =
541 cvmx_read_csr(CVMX_PCSX_MRX_CONTROL_REG(index, interface));
542 pcsx_mrx_control_reg.
s.loopbck1 = enable_internal;
543 cvmx_write_csr(CVMX_PCSX_MRX_CONTROL_REG(index, interface),
544 pcsx_mrx_control_reg.
u64);
546 pcsx_miscx_ctl_reg.
u64 =
547 cvmx_read_csr(CVMX_PCSX_MISCX_CTL_REG(index, interface));
548 pcsx_miscx_ctl_reg.
s.loopbck2 = enable_external;
549 cvmx_write_csr(CVMX_PCSX_MISCX_CTL_REG(index, interface),
550 pcsx_miscx_ctl_reg.
u64);
552 __cvmx_helper_sgmii_hardware_init_link(interface, index);