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
34#include <asm/octeon/octeon.h>
35
36#include <asm/octeon/cvmx-config.h>
37
38#include <asm/octeon/cvmx-helper.h>
39
40#include <asm/octeon/cvmx-pko-defs.h>
41#include <asm/octeon/cvmx-gmxx-defs.h>
42#include <asm/octeon/cvmx-pcsx-defs.h>
43#include <asm/octeon/cvmx-pcsxx-defs.h>
44
45int __cvmx_helper_xaui_enumerate(int interface)
46{
47 union cvmx_gmxx_hg2_control gmx_hg2_control;
48
49
50 gmx_hg2_control.u64 = cvmx_read_csr(CVMX_GMXX_HG2_CONTROL(interface));
51 if (gmx_hg2_control.s.hg2tx_en)
52 return 16;
53 else
54 return 1;
55}
56
57
58
59
60
61
62
63
64
65
66int __cvmx_helper_xaui_probe(int interface)
67{
68 int i;
69 union cvmx_gmxx_inf_mode mode;
70
71
72
73
74
75
76 mode.u64 = cvmx_read_csr(CVMX_GMXX_INF_MODE(interface));
77 mode.s.en = 1;
78 cvmx_write_csr(CVMX_GMXX_INF_MODE(interface), mode.u64);
79
80 __cvmx_helper_setup_gmx(interface, 1);
81
82
83
84
85
86
87
88 for (i = 0; i < 16; i++) {
89 union cvmx_pko_mem_port_ptrs pko_mem_port_ptrs;
90 pko_mem_port_ptrs.u64 = 0;
91
92
93
94
95 pko_mem_port_ptrs.s.static_p = 0;
96 pko_mem_port_ptrs.s.qos_mask = 0xff;
97
98 pko_mem_port_ptrs.s.eid = interface * 4;
99 pko_mem_port_ptrs.s.pid = interface * 16 + i;
100 cvmx_write_csr(CVMX_PKO_MEM_PORT_PTRS, pko_mem_port_ptrs.u64);
101 }
102 return __cvmx_helper_xaui_enumerate(interface);
103}
104
105
106
107
108
109
110
111
112
113
114int __cvmx_helper_xaui_enable(int interface)
115{
116 union cvmx_gmxx_prtx_cfg gmx_cfg;
117 union cvmx_pcsxx_control1_reg xauiCtl;
118 union cvmx_pcsxx_misc_ctl_reg xauiMiscCtl;
119 union cvmx_gmxx_tx_xaui_ctl gmxXauiTxCtl;
120 union cvmx_gmxx_rxx_int_en gmx_rx_int_en;
121 union cvmx_gmxx_tx_int_en gmx_tx_int_en;
122 union cvmx_pcsxx_int_en_reg pcsx_int_en_reg;
123
124
125 if (octeon_has_feature(OCTEON_FEATURE_PKND)) {
126 gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
127 gmx_cfg.s.pknd = cvmx_helper_get_ipd_port(interface, 0);
128 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
129 }
130
131
132
133
134 xauiMiscCtl.u64 = cvmx_read_csr(CVMX_PCSXX_MISC_CTL_REG(interface));
135 xauiMiscCtl.s.gmxeno = 1;
136 cvmx_write_csr(CVMX_PCSXX_MISC_CTL_REG(interface), xauiMiscCtl.u64);
137
138
139 gmx_rx_int_en.u64 = cvmx_read_csr(CVMX_GMXX_RXX_INT_EN(0, interface));
140 cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), 0x0);
141 gmx_tx_int_en.u64 = cvmx_read_csr(CVMX_GMXX_TX_INT_EN(interface));
142 cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), 0x0);
143 pcsx_int_en_reg.u64 = cvmx_read_csr(CVMX_PCSXX_INT_EN_REG(interface));
144 cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), 0x0);
145
146
147
148
149 gmxXauiTxCtl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface));
150
151 gmxXauiTxCtl.s.dic_en = 1;
152 gmxXauiTxCtl.s.uni_en = 0;
153 cvmx_write_csr(CVMX_GMXX_TX_XAUI_CTL(interface), gmxXauiTxCtl.u64);
154
155
156 xauiCtl.u64 = cvmx_read_csr(CVMX_PCSXX_CONTROL1_REG(interface));
157 xauiCtl.s.lo_pwr = 0;
158
159
160 if (!OCTEON_IS_MODEL(OCTEON_CN68XX_PASS1_X) &&
161 !OCTEON_IS_MODEL(OCTEON_CN68XX_PASS2_X))
162 xauiCtl.s.reset = 1;
163
164 cvmx_write_csr(CVMX_PCSXX_CONTROL1_REG(interface), xauiCtl.u64);
165
166
167 if (CVMX_WAIT_FOR_FIELD64
168 (CVMX_PCSXX_CONTROL1_REG(interface), union cvmx_pcsxx_control1_reg,
169 reset, ==, 0, 10000))
170 return -1;
171
172 if (CVMX_WAIT_FOR_FIELD64
173 (CVMX_PCSXX_10GBX_STATUS_REG(interface),
174 union cvmx_pcsxx_10gbx_status_reg, alignd, ==, 1, 10000))
175 return -1;
176
177 if (CVMX_WAIT_FOR_FIELD64
178 (CVMX_GMXX_RX_XAUI_CTL(interface), union cvmx_gmxx_rx_xaui_ctl,
179 status, ==, 0, 10000))
180 return -1;
181
182
183 gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
184 gmx_cfg.s.en = 0;
185 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
186
187
188 if (CVMX_WAIT_FOR_FIELD64
189 (CVMX_GMXX_PRTX_CFG(0, interface), union cvmx_gmxx_prtx_cfg,
190 rx_idle, ==, 1, 10000))
191 return -1;
192
193 if (CVMX_WAIT_FOR_FIELD64
194 (CVMX_GMXX_PRTX_CFG(0, interface), union cvmx_gmxx_prtx_cfg,
195 tx_idle, ==, 1, 10000))
196 return -1;
197
198
199 gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
200 gmx_cfg.s.speed = 1;
201 gmx_cfg.s.speed_msb = 0;
202 gmx_cfg.s.slottime = 1;
203 cvmx_write_csr(CVMX_GMXX_TX_PRTS(interface), 1);
204 cvmx_write_csr(CVMX_GMXX_TXX_SLOT(0, interface), 512);
205 cvmx_write_csr(CVMX_GMXX_TXX_BURST(0, interface), 8192);
206 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
207
208
209 cvmx_write_csr(CVMX_GMXX_RXX_INT_REG(0, interface),
210 cvmx_read_csr(CVMX_GMXX_RXX_INT_REG(0, interface)));
211 cvmx_write_csr(CVMX_GMXX_TX_INT_REG(interface),
212 cvmx_read_csr(CVMX_GMXX_TX_INT_REG(interface)));
213 cvmx_write_csr(CVMX_PCSXX_INT_REG(interface),
214 cvmx_read_csr(CVMX_PCSXX_INT_REG(interface)));
215
216
217 if (CVMX_WAIT_FOR_FIELD64
218 (CVMX_PCSXX_STATUS1_REG(interface), union cvmx_pcsxx_status1_reg,
219 rcv_lnk, ==, 1, 10000))
220 return -1;
221 if (CVMX_WAIT_FOR_FIELD64
222 (CVMX_PCSXX_STATUS2_REG(interface), union cvmx_pcsxx_status2_reg,
223 xmtflt, ==, 0, 10000))
224 return -1;
225 if (CVMX_WAIT_FOR_FIELD64
226 (CVMX_PCSXX_STATUS2_REG(interface), union cvmx_pcsxx_status2_reg,
227 rcvflt, ==, 0, 10000))
228 return -1;
229
230 cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), gmx_rx_int_en.u64);
231 cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), gmx_tx_int_en.u64);
232 cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), pcsx_int_en_reg.u64);
233
234
235 xauiMiscCtl.s.gmxeno = 0;
236 cvmx_write_csr(CVMX_PCSXX_MISC_CTL_REG(interface), xauiMiscCtl.u64);
237
238 gmx_cfg.u64 = cvmx_read_csr(CVMX_GMXX_PRTX_CFG(0, interface));
239 gmx_cfg.s.en = 1;
240 cvmx_write_csr(CVMX_GMXX_PRTX_CFG(0, interface), gmx_cfg.u64);
241
242 __cvmx_interrupt_pcsx_intx_en_reg_enable(0, interface);
243 __cvmx_interrupt_pcsx_intx_en_reg_enable(1, interface);
244 __cvmx_interrupt_pcsx_intx_en_reg_enable(2, interface);
245 __cvmx_interrupt_pcsx_intx_en_reg_enable(3, interface);
246 __cvmx_interrupt_pcsxx_int_en_reg_enable(interface);
247 __cvmx_interrupt_gmxx_enable(interface);
248
249 return 0;
250}
251
252
253
254
255
256
257
258
259
260
261
262cvmx_helper_link_info_t __cvmx_helper_xaui_link_get(int ipd_port)
263{
264 int interface = cvmx_helper_get_interface_num(ipd_port);
265 union cvmx_gmxx_tx_xaui_ctl gmxx_tx_xaui_ctl;
266 union cvmx_gmxx_rx_xaui_ctl gmxx_rx_xaui_ctl;
267 union cvmx_pcsxx_status1_reg pcsxx_status1_reg;
268 cvmx_helper_link_info_t result;
269
270 gmxx_tx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface));
271 gmxx_rx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_RX_XAUI_CTL(interface));
272 pcsxx_status1_reg.u64 =
273 cvmx_read_csr(CVMX_PCSXX_STATUS1_REG(interface));
274 result.u64 = 0;
275
276
277 if ((gmxx_tx_xaui_ctl.s.ls == 0) && (gmxx_rx_xaui_ctl.s.status == 0) &&
278 (pcsxx_status1_reg.s.rcv_lnk == 1)) {
279 result.s.link_up = 1;
280 result.s.full_duplex = 1;
281 result.s.speed = 10000;
282 } else {
283
284 cvmx_write_csr(CVMX_GMXX_RXX_INT_EN(0, interface), 0x0);
285 cvmx_write_csr(CVMX_GMXX_TX_INT_EN(interface), 0x0);
286 cvmx_write_csr(CVMX_PCSXX_INT_EN_REG(interface), 0x0);
287 }
288 return result;
289}
290
291
292
293
294
295
296
297
298
299
300
301
302int __cvmx_helper_xaui_link_set(int ipd_port, cvmx_helper_link_info_t link_info)
303{
304 int interface = cvmx_helper_get_interface_num(ipd_port);
305 union cvmx_gmxx_tx_xaui_ctl gmxx_tx_xaui_ctl;
306 union cvmx_gmxx_rx_xaui_ctl gmxx_rx_xaui_ctl;
307
308 gmxx_tx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_TX_XAUI_CTL(interface));
309 gmxx_rx_xaui_ctl.u64 = cvmx_read_csr(CVMX_GMXX_RX_XAUI_CTL(interface));
310
311
312 if (!link_info.s.link_up)
313 return 0;
314
315
316 if ((gmxx_tx_xaui_ctl.s.ls == 0) && (gmxx_rx_xaui_ctl.s.status == 0))
317 return 0;
318
319
320 return __cvmx_helper_xaui_enable(interface);
321}
322