Debian Codegraph @

src/vendorcode/cavium/bdk/libbdk-hal/if/bdk-if-phy-vetesse-xfi.c

raw symbols SCIP
1 /***********************license start***********************************
2 * Copyright (c) 2003-2017 Cavium Inc. ([email protected]). All rights
3 * reserved.
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
9 *
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 *
18 * * Neither the name of Cavium Inc. nor the names of
19 * its contributors may be used to endorse or promote products
20 * derived from this software without specific prior written
21 * permission.
22 *
23 * This Software, including technical data, may be subject to U.S. export
24 * control laws, including the U.S. Export Administration Act and its
25 * associated regulations, and may be subject to export or import
26 * regulations in other countries.
27 *
28 * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
29 * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
30 * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
31 * TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
32 * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
33 * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
34 * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
35 * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
36 * QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK
37 * ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
38 ***********************license end**************************************/
39 #include <bdk.h>
40 #include <libbdk-hal/if/bdk-if.h>
41 #include <libbdk-hal/bdk-mdio.h>
42 #include <libbdk-hal/bdk-twsi.h>
43
44 /* This code is an optional part of the BDK. It is only linked in
45 * if BDK_REQUIRE() needs it */
46 //BDK_REQUIRE(TWSI);
47 BDK_REQUIRE_DEFINE(XFI);
48
49 /*
50 Rate Select Settings
51 Mode State : 6/8
52 Rate Select State : 0
53 RSEL1 : 0
54 RSEL0 : 0
55 Ref Clock Gen(MHz) : 156.25
56 Data Rate(Gbps) : 10.3125
57 Description : 10 GbE
58
59
60 Data Rate Detection Configuration Registers
61
62 Mode Pin Settings:
63 Mode State : 0
64 MODE1 : 0
65 MODE0 : 0
66 Mode : Two-wire serial interface mode
67
68 LOS Pin Strap Mode Settings
69 Mode State : 2/6/8
70 State : 4
71 LOS1 : Float
72 LOS0 : Float
73 LOS Amplitude(mVpp) : 20
74 LOS Hysteresis(dB) : 2
75
76 Input Equalization Retimer Mode Settings
77 Mode State : 6/8
78 EQ State : 0
79 EQ1 : 0
80 EQ0 : 0
81 EQ(dB) : Auto
82 DFE : Auto
83 Comment : Full Auto
84
85 Input Equalization Re-Driver Mode Settings
86 Mode State :
87 EQ State : 0
88 EQ1 : 0
89 EQ0 : 0
90 EQ(dB) : Auto
91 DFE : APowered Down
92 Comment : Analog EQ Only
93
94
95
96 Output De-Emphasis Retimer Mode Settings
97 Mode State : 6/8
98 DE State : 3
99 TX1 : Float
100 TX0 : 0
101 PRE c(-1) mA : -1
102 MAIN c( 0) mA : 15
103 POST c(+1) mA : 4
104 DC Amplitude(mV): 500
105 De-Emphasis(dB) : -6.02
106 Comment :
107
108
109 Output De-Emphasis Re-Driver Mode Settings
110 Mode State : 2
111 DE State : 3
112 TX1 : Float
113 TX0 : 0
114 Frequency(Gbps) : 10.3125
115 DC Amplitude(mV): 600
116 De-Emphasis(dB) : 4
117 Comment : 10GbE
118
119
120 */
121
122 static int debug = 0;
123
124 #define xfi_printf(fmt, args...) \
125 do { \
126 if(debug == 1){ \
127 printf(fmt, ##args); \
128 } \
129 } while(0)
130
131
132 int bdk_xfi_vsc7224_dump(int twsi_id, int unit){
133 bdk_node_t node=0;
134 uint8_t dev_addr=0x10 + unit;
135 uint16_t internal_addr=0x7F;
136 int num_bytes=2;
137 int ia_width_bytes=1;
138 uint64_t data=0;
139 int p, i;
140 uint64_t result[0x100] = {0};
141
142 uint64_t pagenum[9] = {0x00, 0x01, 0x02, 0x03, 0x20, 0x21, 0x30, 0x31, 0x40};
143
144 for(p=0; p < ARRAY_SIZE(pagenum); p++){
145 data = pagenum[p];
146 bdk_twsix_write_ia(node, twsi_id, dev_addr, internal_addr, num_bytes, ia_width_bytes, data);
147 for(i=0x80; i<=0xFF; i++){
148 result[i] = 0x00;
149 result[i] = bdk_twsix_read_ia(node, twsi_id, dev_addr, (uint16_t)i, num_bytes, ia_width_bytes);
150 }
151 for(i=0x80; i<=0xFF; i++){
152 if(i==0x80){
153 printf("\npage_%02X[0x100] = {\n", (uint8_t)pagenum[p]);
154 }
155 if(i % 8 == 0){
156 printf("/* 0x%2X */", i);
157 }
158 printf(" 0x%04X,", (uint16_t)result[i]);
159 if(i==0xFF){
160 printf("};");
161 }
162 if((i+1) % 8 == 0){
163 printf("\n");
164 }
165 }
166 }
167
168 return 0;
169 }
170
171 /* XFI ReTimer/ReDriver Mode Settings */
172
173 /*
174 power down regs:
175 Page Reg Position Mask val RegFieldName
176 0x00 0x89 b07 0x0080 1 PD_INBUF
177 0x00 0x8A b10 0x0400 1 PD_DFECRU
178 0x00 0x8A b01 0x0002 1 PD_DFE
179 0x00 0x8A b00 0x0001 1 PD_DFEADAPT
180 0x00 0x97 b15 0x8000 1 ASYN_SYNN
181 0x00 0x97 b09 0x0200 1 PD_OD
182 0x00 0xA0 b11 0x0800 1 PD_LOS
183 0x00 0xA4 b15 0x8000 1 PD_CH
184 0x00 0xB5 b07 0x0080 1 PD_INBUF
185 0x00 0xB9 b15 0x8000 1 ASYN_SYNN
186 0x00 0xB9 b09 0x0200 1 PD_OD
187 0x00 0xBF b07 0x0080 1 PD_INBUF
188 0x00 0xF0 b15 0x8000 1 ASYN_SYNN
189 0x00 0xF0 b09 0x0200 1 PD_OD
190 0x00 0xF6 b07 0x0080 1 PD_INBUF
191 0x00 0xFA b15 0x8000 1 ASYN_SYNN
192 0x00 0xFA b09 0x0200 1 PD_OD
193 */
194 struct regmap{
195 short int page;
196 unsigned char reg;
197 unsigned short int retimer;
198 unsigned short int redriver;
199 };
200
201 /* This table only applies to SFF8104 */
202 struct regmap xfiregmap[64] = {
203 //CH 0
204 {0x00, 0x84, 0x0800, 0x0000}, //EQTABLE_DCOFF0 (0n_84)
205 {0x00, 0x8A, 0x7000, 0x0400}, //DFECRU_CTRL (0n_8A)
206 {0x00, 0x8B, 0x4060, 0x0000}, //DFECRU_CFVF_CFAP (0n_8B)
207 {0x00, 0x90, 0xDE85, 0x0000}, //DFECRU_DFEAUTO (0n_90)
208 {0x00, 0x91, 0x2020, 0x0000}, //DFECRU_BTMX_BFMX (0n_91)
209 {0x00, 0x92, 0x0860, 0x0000}, //DFECRU_DXMX_TRMX (0n_92)
210 {0x00, 0x93, 0x6000, 0x0000}, //DFECRU_TRMN_ERRI (0n_93)
211 {0x00, 0x94, 0x0001, 0x0000}, //DFECRU_DFEMODE (0n_94)
212 {0x00, 0x95, 0x0008, 0x0000}, //DFECRU_RATESEL (0n_95)
213 {0x00, 0x97, 0x0000, 0x8080}, //OUTDRVCTRL (0n_97)
214 {0x00, 0x99, 0x001E, 0x0014}, //KR_MAINTAP (0n_99)
215 {0x00, 0x9A, 0x000B, 0x0000}, //KR_PRETAP (0n_9A)
216 {0x00, 0x9B, 0x0010, 0x0000}, //KR_POSTTAP (0n_9B)
217 {0x00, 0x9E, 0x03E8, 0x07D0}, //LOSASSRT (0n_9E)
218 {0x00, 0x9F, 0x04EA, 0x09D5}, //LOSDASSRT (0n_9F)
219 {0x00, 0xB2, 0x0888, 0x0000}, //NA
220
221 //CH 1
222 {0x01, 0x84, 0x0800, 0x0000},
223 {0x01, 0x8A, 0x7000, 0x0400},
224 {0x01, 0x8B, 0x4060, 0x0000},
225 {0x01, 0x90, 0xDE85, 0x0000},
226 {0x01, 0x91, 0x2020, 0x0000},
227 {0x01, 0x92, 0x0860, 0x0000},
228 {0x01, 0x93, 0x6000, 0x0000},
229 {0x01, 0x94, 0x0001, 0x0000},
230 {0x01, 0x95, 0x0008, 0x0000},
231 {0x01, 0x97, 0x0000, 0x8080},
232 {0x01, 0x99, 0x001E, 0x0014},
233 {0x01, 0x9A, 0x000B, 0x0000},
234 {0x01, 0x9B, 0x0010, 0x0000},
235 {0x01, 0x9E, 0x03E8, 0x07D0},
236 {0x01, 0x9F, 0x04EA, 0x09D5},
237 {0x01, 0xB2, 0x0888, 0x0000},
238
239 //POWER_DOWN Channel 2 and 3
240 {0x02, 0x8A, 0x0400, 0x0400},
241 {0x02, 0xA4, 0x8000, 0x8000},
242 {0x03, 0x8A, 0x0400, 0x0400},
243 {0x03, 0xA4, 0x8000, 0x8000},
244
245 {0x30, 0x80, 0x3453, 0x0000}, //FSYNM_NVAL (3f_80)
246 {0x30, 0x81, 0x00F6, 0x0000}, //FSYNFVAL_MSB (3f_81)
247 {0x30, 0x82, 0x8800, 0x0000}, //FSYNFVAL_LSB (3f_82)
248 {0x30, 0x83, 0x000F, 0x0000}, //FSYNRVAL_MSB (3f_83)
249 {0x30, 0x84, 0xB5E0, 0x0000}, //FSYNRVAL_LSB (3f_84)
250 {0x30, 0x85, 0x0000, 0x0400}, //FSYNTST (3f_85)
251
252 {0x40, 0x80, 0x4C00, 0x0000}, //ANMUXSEL (40_80)
253 {0x40, 0x81, 0x4000, 0x0000}, //DGMUXCTRL (40_81)
254 {0x40, 0x82, 0x7800, 0xC000}, //RCKINCTRL (40_82)
255 {0x40, 0x84, 0x0020, 0x0000}, //CHRCKSEL (40_84)
256
257 {-1, 0, 0, 0},
258 };
259
260 int bdk_vsc7224_modeset(int twsi_id, int unit, int xfi_mode){
261 bdk_node_t node=0;
262 uint8_t dev_addr=0x10 + unit;
263 uint16_t internal_addr=0x7F;
264 uint16_t page=0;
265 int num_bytes=2;
266 int ia_width_bytes=1;
267 uint64_t data=0;
268 int val=0;
269 int ret = 0, r=0;
270 uint16_t reg = 0;
271
272 if(xfi_mode==0){
273 printf("XFI Mode Retimer\n");
274 }else{
275 printf("XFI Mode Redriver\n");
276 }
277
278 while(xfiregmap[r].page != -1){
279 page = xfiregmap[r].page;
280 reg = xfiregmap[r].reg;
281 if(xfi_mode==0){
282 data = xfiregmap[r].retimer;
283 }else{
284 data = xfiregmap[r].redriver;
285 }
286 ret = bdk_twsix_write_ia(node, twsi_id, dev_addr, internal_addr, num_bytes, ia_width_bytes, (uint64_t)page);
287 if(ret !=0){
288 printf("XFI init Error\n");
289 break;
290 }
291 ret = bdk_twsix_write_ia(node, twsi_id, dev_addr, reg, num_bytes, ia_width_bytes, data);
292 if(ret !=0){
293 printf("XFI init Error\n");
294 break;
295 }
296 val = bdk_twsix_read_ia(node, twsi_id, dev_addr, reg, num_bytes, ia_width_bytes);
297 if(val == -1){
298 printf("XFI Read Reg Failed @ page:reg :: %2X:%2X \n",page, reg);
299 break;
300 }else{
301 xfi_printf(" Page: reg: data: val :: %2X:%2X:%04X:%04X\n", page, reg, (uint16_t)data, val);
302 }
303 r++;
304 }
305
306 return ret;
307 }
308
309
310 int bdk_vsc7224_regmap_modeget(int twsi_id, int unit){
311 bdk_node_t node=0;
312 uint8_t dev_addr=0x10 + unit;
313 uint16_t internal_addr=0x7F;
314 uint16_t page=0;
315 int num_bytes=2;
316 int ia_width_bytes=1;
317 //uint64_t data=0;
318 uint16_t reg = 0;
319 int ret = 0, r=0;
320 int data;
321
322 printf("\n===========================================\n");
323 printf("Page :Reg :Value :Retimer :Redriver\n");
324 printf("===========================================\n");
325 while(xfiregmap[r].page != -1){
326 page = xfiregmap[r].page;
327 reg = xfiregmap[r].reg;
328
329 ret = bdk_twsix_write_ia(node, twsi_id, dev_addr, internal_addr, num_bytes, ia_width_bytes, (uint64_t)page);
330 if(ret !=0){
331 printf("XFI init Error\n");
332 break;
333 }
334 data = bdk_twsix_read_ia(node, twsi_id, dev_addr, reg, num_bytes, ia_width_bytes);
335 if(data == -1){
336 printf("XFI Read Reg Failed @ page:reg :: %2X:%2X \n",page, reg);
337 break;
338 }
339 printf(" %02X: %02X: %04X: %04X: %04X\n", page, reg, (uint16_t)data, xfiregmap[r].retimer, xfiregmap[r].redriver);
340 r++;
341 }
342 printf("=======================================\n");
343
344 return ret;
345 }
346
347 int bdk_vsc7224_wp_regs(int twsi_id, int unit, int xfi_wp){
348 bdk_node_t node=0;
349 uint8_t dev_addr=0x10 + unit;
350 uint16_t internal_addr=0x7E;
351 uint16_t data=0x0000;
352 int num_bytes=2;
353 int ia_width_bytes=1;
354 int ret =0;
355
356 if(xfi_wp == 1){
357 data = 0x0000;
358 }else{
359 data = 0xFFFF;
360 }
361
362 ret = bdk_twsix_write_ia(node, twsi_id, dev_addr, internal_addr, num_bytes, ia_width_bytes, (uint64_t)data);
363 if(ret !=0){
364 printf("XFI VSC7224 Write Protect Error\n");
365 }
366
367 return ret;
368 }
369
370 int bdk_vsc7224_set_reg(int twsi_id, int unit, int page, int reg, int val){
371 bdk_node_t node=0;
372 uint8_t dev_addr=0x10 + unit;
373 uint16_t internal_addr = reg;
374 int num_bytes=2;
375 int ia_width_bytes=1;
376 int ret=0;
377
378 xfi_printf(" Unit: Page: reg: val :: %02x:%2X:%2X:%04X\n", unit, page, reg, val & 0xFFFF);
379 ret = bdk_twsix_write_ia(node, twsi_id, dev_addr, 0x7F, num_bytes, ia_width_bytes, (uint64_t)(page & 0xFF));
380 if (ret) {
381 printf("XFI VSC7224 TWSI Set Page Register Error\n");
382 }
383
384 ret = bdk_twsix_write_ia(node, twsi_id, dev_addr, internal_addr, num_bytes, ia_width_bytes, (uint64_t)(val & 0xFFFF));
385 if (ret) {
386 printf("XFI VSC7224 TWSI Set Register Error\n");
387 }
388
389 return ret;
390 }
391
392 int bdk_vsc7224_debug(int _debug){
393 debug =_debug;
394 return 0;
395 }