aboutsummaryrefslogtreecommitdiff
path: root/src/vendorcode/cavium/bdk/libbdk-hal/if/bdk-if-phy-vetesse-xfi.c
blob: 77ba4c42333b8171a64bd497d4200b70f2d70a24 (plain)
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
/***********************license start***********************************
* Copyright (c) 2003-2017  Cavium Inc. (support@cavium.com). All rights
* reserved.
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
*   * Redistributions of source code must retain the above copyright
*     notice, this list of conditions and the following disclaimer.
*
*   * Redistributions in binary form must reproduce the above
*     copyright notice, this list of conditions and the following
*     disclaimer in the documentation and/or other materials provided
*     with the distribution.
*
*   * Neither the name of Cavium Inc. nor the names of
*     its contributors may be used to endorse or promote products
*     derived from this software without specific prior written
*     permission.
*
* This Software, including technical data, may be subject to U.S. export
* control laws, including the U.S. Export Administration Act and its
* associated regulations, and may be subject to export or import
* regulations in other countries.
*
* TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS"
* AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR
* WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT
* TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY
* REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT
* DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES
* OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR
* PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT,
* QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE  RISK
* ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU.
***********************license end**************************************/
#include <bdk.h>
#include <libbdk-hal/if/bdk-if.h>
#include <libbdk-hal/bdk-mdio.h>
#include <libbdk-hal/bdk-twsi.h>

/* This code is an optional part of the BDK. It is only linked in
 *     if BDK_REQUIRE() needs it */
//BDK_REQUIRE(TWSI);
BDK_REQUIRE_DEFINE(XFI);

/*
Rate Select Settings
Mode State			: 6/8
Rate Select State	: 0
RSEL1				: 0
RSEL0				: 0
Ref Clock Gen(MHz)	: 156.25
Data Rate(Gbps)		: 10.3125
Description			: 10 GbE


Data Rate Detection Configuration Registers

Mode Pin Settings:
Mode State	: 0
MODE1		: 0
MODE0		: 0
Mode		: Two-wire serial interface mode

LOS Pin Strap Mode Settings
Mode State			: 2/6/8
State				: 4
LOS1				: Float
LOS0				: Float
LOS Amplitude(mVpp)	: 20
LOS Hysteresis(dB)	: 2

Input Equalization Retimer Mode Settings
Mode State		: 6/8
EQ State		: 0
EQ1				: 0
EQ0				: 0
EQ(dB)			: Auto
DFE				: Auto
Comment			: Full Auto

Input Equalization Re-Driver Mode Settings
Mode State		:
EQ State		: 0
EQ1				: 0
EQ0				: 0
EQ(dB)			: Auto
DFE				: APowered Down
Comment			: Analog EQ Only



Output De-Emphasis Retimer Mode Settings
Mode State		: 6/8
DE State		: 3
TX1				: Float
TX0				: 0
PRE  c(-1) mA	: -1
MAIN c( 0) mA	: 15
POST c(+1) mA	: 4
DC Amplitude(mV): 500
De-Emphasis(dB)	: -6.02
Comment			:


Output De-Emphasis Re-Driver Mode Settings
Mode State		: 2
DE State		: 3
TX1				: Float
TX0				: 0
Frequency(Gbps)	: 10.3125
DC Amplitude(mV): 600
De-Emphasis(dB)	: 4
Comment			: 10GbE


*/

static int debug = 0;

#define xfi_printf(fmt, args...)		\
	do {					\
		if(debug == 1){			\
			printf(fmt, ##args);	\
		}				\
	} while(0)


int bdk_xfi_vsc7224_dump(int twsi_id, int unit){
	bdk_node_t node=0;
	uint8_t dev_addr=0x10 + unit;
	uint16_t internal_addr=0x7F;
	int num_bytes=2;
	int ia_width_bytes=1;
	uint64_t data=0;
	int p, i;
	uint64_t result[0x100] = {0};

	uint64_t pagenum[9] = {0x00, 0x01, 0x02, 0x03, 0x20, 0x21, 0x30, 0x31, 0x40};

	for(p=0; p < (sizeof(pagenum)/sizeof(pagenum[0])); p++){
		data = pagenum[p];
		bdk_twsix_write_ia(node, twsi_id, dev_addr, internal_addr, num_bytes, ia_width_bytes, data);
		for(i=0x80; i<=0xFF; i++){
			result[i] = 0x00;
			result[i] = bdk_twsix_read_ia(node, twsi_id, dev_addr, (uint16_t)i, num_bytes, ia_width_bytes);
		}
		for(i=0x80; i<=0xFF; i++){
			if(i==0x80){
				printf("\npage_%02X[0x100] = {\n", (uint8_t)pagenum[p]);
			}
			if(i % 8 == 0){
				printf("/* 0x%2X */", i);
			}
			printf(" 0x%04X,", (uint16_t)result[i]);
			if(i==0xFF){
				printf("};");
			}
			if((i+1) % 8 == 0){
				printf("\n");
			}
		}
	}

	return 0;
}

/* XFI ReTimer/ReDriver Mode Settings */

/*
power down regs:
Page Reg Position Mask val RegFieldName
0x00 0x89 b07 0x0080 1 PD_INBUF
0x00 0x8A b10 0x0400 1 PD_DFECRU
0x00 0x8A b01 0x0002 1 PD_DFE
0x00 0x8A b00 0x0001 1 PD_DFEADAPT
0x00 0x97 b15 0x8000 1 ASYN_SYNN
0x00 0x97 b09 0x0200 1 PD_OD
0x00 0xA0 b11 0x0800 1 PD_LOS
0x00 0xA4 b15 0x8000 1 PD_CH
0x00 0xB5 b07 0x0080 1 PD_INBUF
0x00 0xB9 b15 0x8000 1 ASYN_SYNN
0x00 0xB9 b09 0x0200 1 PD_OD
0x00 0xBF b07 0x0080 1 PD_INBUF
0x00 0xF0 b15 0x8000 1 ASYN_SYNN
0x00 0xF0 b09 0x0200 1 PD_OD
0x00 0xF6 b07 0x0080 1 PD_INBUF
0x00 0xFA b15 0x8000 1 ASYN_SYNN
0x00 0xFA b09 0x0200 1 PD_OD
*/
struct regmap{
	short int page;
	unsigned char reg;
	unsigned short int retimer;
	unsigned short int redriver;
};

/* This table only applies to SFF8104 */
struct regmap xfiregmap[64] = {
//CH 0
{0x00, 0x84, 0x0800, 0x0000}, //EQTABLE_DCOFF0 (0n_84)
{0x00, 0x8A, 0x7000, 0x0400}, //DFECRU_CTRL (0n_8A)
{0x00, 0x8B, 0x4060, 0x0000}, //DFECRU_CFVF_CFAP (0n_8B)
{0x00, 0x90, 0xDE85, 0x0000}, //DFECRU_DFEAUTO (0n_90)
{0x00, 0x91, 0x2020, 0x0000}, //DFECRU_BTMX_BFMX (0n_91)
{0x00, 0x92, 0x0860, 0x0000}, //DFECRU_DXMX_TRMX (0n_92)
{0x00, 0x93, 0x6000, 0x0000}, //DFECRU_TRMN_ERRI (0n_93)
{0x00, 0x94, 0x0001, 0x0000}, //DFECRU_DFEMODE (0n_94)
{0x00, 0x95, 0x0008, 0x0000}, //DFECRU_RATESEL (0n_95)
{0x00, 0x97, 0x0000, 0x8080}, //OUTDRVCTRL (0n_97)
{0x00, 0x99, 0x001E, 0x0014}, //KR_MAINTAP (0n_99)
{0x00, 0x9A, 0x000B, 0x0000}, //KR_PRETAP (0n_9A)
{0x00, 0x9B, 0x0010, 0x0000}, //KR_POSTTAP (0n_9B)
{0x00, 0x9E, 0x03E8, 0x07D0}, //LOSASSRT (0n_9E)
{0x00, 0x9F, 0x04EA, 0x09D5}, //LOSDASSRT (0n_9F)
{0x00, 0xB2, 0x0888, 0x0000}, //NA

//CH 1
{0x01, 0x84, 0x0800, 0x0000},
{0x01, 0x8A, 0x7000, 0x0400},
{0x01, 0x8B, 0x4060, 0x0000},
{0x01, 0x90, 0xDE85, 0x0000},
{0x01, 0x91, 0x2020, 0x0000},
{0x01, 0x92, 0x0860, 0x0000},
{0x01, 0x93, 0x6000, 0x0000},
{0x01, 0x94, 0x0001, 0x0000},
{0x01, 0x95, 0x0008, 0x0000},
{0x01, 0x97, 0x0000, 0x8080},
{0x01, 0x99, 0x001E, 0x0014},
{0x01, 0x9A, 0x000B, 0x0000},
{0x01, 0x9B, 0x0010, 0x0000},
{0x01, 0x9E, 0x03E8, 0x07D0},
{0x01, 0x9F, 0x04EA, 0x09D5},
{0x01, 0xB2, 0x0888, 0x0000},

//POWER_DOWN Channel 2 and 3
{0x02, 0x8A, 0x0400, 0x0400},
{0x02, 0xA4, 0x8000, 0x8000},
{0x03, 0x8A, 0x0400, 0x0400},
{0x03, 0xA4, 0x8000, 0x8000},

{0x30, 0x80, 0x3453, 0x0000}, //FSYNM_NVAL (3f_80)
{0x30, 0x81, 0x00F6, 0x0000}, //FSYNFVAL_MSB (3f_81)
{0x30, 0x82, 0x8800, 0x0000}, //FSYNFVAL_LSB (3f_82)
{0x30, 0x83, 0x000F, 0x0000}, //FSYNRVAL_MSB (3f_83)
{0x30, 0x84, 0xB5E0, 0x0000}, //FSYNRVAL_LSB (3f_84)
{0x30, 0x85, 0x0000, 0x0400}, //FSYNTST (3f_85)

{0x40, 0x80, 0x4C00, 0x0000}, //ANMUXSEL (40_80)
{0x40, 0x81, 0x4000, 0x0000}, //DGMUXCTRL (40_81)
{0x40, 0x82, 0x7800, 0xC000}, //RCKINCTRL (40_82)
{0x40, 0x84, 0x0020, 0x0000}, //CHRCKSEL (40_84)

{-1, 0, 0, 0},
};

int bdk_vsc7224_modeset(int twsi_id, int unit, int xfi_mode){
	bdk_node_t node=0;
	uint8_t dev_addr=0x10 + unit;
	uint16_t internal_addr=0x7F;
	uint16_t page=0;
	int num_bytes=2;
	int ia_width_bytes=1;
	uint64_t data=0;
	int val=0;
	int ret = 0, r=0;
	uint16_t reg = 0;

	if(xfi_mode==0){
	    printf("XFI Mode Retimer\n");
	}else{
	    printf("XFI Mode Redriver\n");
	}

	while(xfiregmap[r].page != -1){
	    page = xfiregmap[r].page;
	    reg  = xfiregmap[r].reg;
	    if(xfi_mode==0){
		data = xfiregmap[r].retimer;
	    }else{
		data = xfiregmap[r].redriver;
	    }
	    ret = bdk_twsix_write_ia(node, twsi_id, dev_addr, internal_addr, num_bytes, ia_width_bytes, (uint64_t)page);
	    if(ret !=0){
		printf("XFI init Error\n");
		break;
	    }
	    ret = bdk_twsix_write_ia(node, twsi_id, dev_addr, reg, 	   num_bytes, ia_width_bytes, data);
	    if(ret !=0){
		printf("XFI init Error\n");
		break;
	    }
	    val = bdk_twsix_read_ia(node, twsi_id, dev_addr,  reg, num_bytes, ia_width_bytes);
	    if(val == -1){
		printf("XFI Read Reg Failed @ page:reg :: %2X:%2X \n",page, reg);
		break;
	    }else{
		xfi_printf(" Page: reg: data: val :: %2X:%2X:%04X:%04X\n", page, reg, (uint16_t)data, val);
	    }
	    r++;
	}

	return ret;
}


int bdk_vsc7224_regmap_modeget(int twsi_id, int unit){
	bdk_node_t node=0;
	uint8_t dev_addr=0x10 + unit;
	uint16_t internal_addr=0x7F;
	uint16_t page=0;
	int num_bytes=2;
	int ia_width_bytes=1;
	//uint64_t data=0;
	uint16_t reg = 0;
	int ret = 0, r=0;
	int data;

	printf("\n===========================================\n");
	printf("Page  :Reg    :Value  :Retimer :Redriver\n");
	printf("===========================================\n");
	while(xfiregmap[r].page != -1){
	    page = xfiregmap[r].page;
	    reg  = xfiregmap[r].reg;

	    ret = bdk_twsix_write_ia(node, twsi_id, dev_addr, internal_addr, num_bytes, ia_width_bytes, (uint64_t)page);
	    if(ret !=0){
		printf("XFI init Error\n");
		break;
	    }
	    data = bdk_twsix_read_ia(node, twsi_id, dev_addr,  reg, num_bytes, ia_width_bytes);
	    if(data == -1){
		printf("XFI Read Reg Failed @ page:reg :: %2X:%2X \n",page, reg);
		break;
	    }
	    printf("     %02X:     %02X:   %04X:    %04X:    %04X\n", page, reg, (uint16_t)data, xfiregmap[r].retimer, xfiregmap[r].redriver);
	    r++;
	}
	printf("=======================================\n");

	return ret;
}

int bdk_vsc7224_wp_regs(int twsi_id, int unit, int xfi_wp){
	bdk_node_t node=0;
	uint8_t dev_addr=0x10 + unit;
	uint16_t internal_addr=0x7E;
	uint16_t data=0x0000;
	int num_bytes=2;
	int ia_width_bytes=1;
	int ret =0;

	if(xfi_wp == 1){
		data = 0x0000;
	}else{
		data = 0xFFFF;
	}

	ret = bdk_twsix_write_ia(node, twsi_id, dev_addr, internal_addr, num_bytes, ia_width_bytes, (uint64_t)data);
	if(ret !=0){
		printf("XFI VSC7224  Write Protect Error\n");
	}

	return ret;
}

int bdk_vsc7224_set_reg(int twsi_id, int unit, int page, int reg, int val){
	bdk_node_t node=0;
	uint8_t dev_addr=0x10 + unit;
	uint16_t internal_addr = reg;
	int num_bytes=2;
	int ia_width_bytes=1;
	int ret=0;

	xfi_printf(" Unit: Page: reg: val :: %02x:%2X:%2X:%04X\n", unit, page, reg, val & 0xFFFF);
	ret = bdk_twsix_write_ia(node, twsi_id, dev_addr, 0x7F, num_bytes, ia_width_bytes, (uint64_t)(page & 0xFF));
	if (ret) {
		printf("XFI VSC7224  TWSI Set Page Register Error\n");
	}

	ret = bdk_twsix_write_ia(node, twsi_id, dev_addr, internal_addr, num_bytes, ia_width_bytes, (uint64_t)(val & 0xFFFF));
	if (ret) {
		printf("XFI VSC7224  TWSI Set Register Error\n");
	}

	return ret;
}

int bdk_vsc7224_debug(int _debug){
	debug =_debug;
	return 0;
}