Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
W
White Rabbit Switch - Software
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
86
Issues
86
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
White Rabbit Switch - Software
Commits
77b9c399
Commit
77b9c399
authored
Apr 19, 2012
by
Tomasz Wlostowski
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'v3-minibackplane-i2c' into v3-rts-slave
parents
b4b9e764
8ffbd130
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
86 additions
and
57 deletions
+86
-57
sfp_lib.h
userspace/include/hw/sfp_lib.h
+40
-1
Makefile
userspace/libswitchhw/Makefile
+1
-1
i2c_bitbang.c
userspace/libswitchhw/i2c_bitbang.c
+1
-1
i2c_sfp.c
userspace/libswitchhw/i2c_sfp.c
+32
-19
i2c_sfp.h
userspace/libswitchhw/i2c_sfp.h
+3
-32
i2cscan.c
userspace/libswitchhw/i2cscan.c
+2
-1
sfpdb.lua
userspace/libswitchhw/sfpdb.lua
+7
-2
No files found.
userspace/include/hw/sfp_lib.h
View file @
77b9c399
...
...
@@ -26,12 +26,45 @@ struct shw_sfp_caldata {
char
part_num
[
16
];
/* part number of device as found in DB */
char
vendor_serial
[
16
];
/* Callibration data */
uint32_t
alpha
;
double
alpha
;
uint32_t
delta_tx
;
uint32_t
delta_rx
;
struct
shw_sfp_caldata
*
next
;
};
struct
shw_sfp_header
{
uint8_t
id
;
uint8_t
ext_id
;
uint8_t
connector
;
uint8_t
transciever
[
8
];
uint8_t
encoding
;
uint8_t
br_nom
;
uint8_t
reserved1
;
uint8_t
length1
;
/* Link length supported for 9/125 mm fiber (km) */
uint8_t
length2
;
/* Link length supported for 9/125 mm fiber (100m) */
uint8_t
length3
;
/* Link length supported for 50/125 mm fiber (10m) */
uint8_t
length4
;
/* Link length supported for 62.5/125 mm fiber (10m) */
uint8_t
length5
;
/* Link length supported for copper (1m) */
uint8_t
reserved2
;
uint8_t
vendor_name
[
16
];
uint8_t
reserved3
;
uint8_t
vendor_oui
[
3
];
uint8_t
vendor_pn
[
16
];
uint8_t
vendor_rev
[
4
];
uint8_t
reserved4
[
3
];
uint8_t
cc_base
;
/* extended ID fields start here */
uint8_t
options
[
2
];
uint8_t
br_max
;
uint8_t
br_min
;
uint8_t
vendor_serial
[
16
];
uint8_t
date_code
[
8
];
uint8_t
reserved
[
3
];
uint8_t
cc_ext
;
}
__attribute__
((
packed
));
/* Public API */
/*
...
...
@@ -58,7 +91,13 @@ static inline void shw_sfp_set_generic(int num, int status, int type)
/* Load the db from a file */
int
shw_sfp_read_db
(
char
*
filename
);
/* Read and verify the header all at once. returns -1 on failure */
int
shw_sfp_read_verify_header
(
int
num
,
struct
shw_sfp_header
*
head
);
/* return NULL if no data found */
struct
shw_sfp_caldata
*
shw_sfp_get_cal_data
(
int
num
);
/* Read and verify the header all at once. returns -1 on failure */
int
shw_sfp_read_verify_header
(
int
num
,
struct
shw_sfp_header
*
head
);
#endif // __SHW_SFPLIB_H
userspace/libswitchhw/Makefile
View file @
77b9c399
...
...
@@ -6,7 +6,7 @@ OBJS = trace.o init.o fpga_io.o util.o pps_gen.o i2c.o pio_pins.o i2c_bitbang.o
SCAN_OBJS
=
i2cscan.o
LIB
=
libswitchhw.a
LDFLAGS
+=
-lm
liblua.a
LDFLAGS
+=
-lm
-ldl
liblua.a
all
:
$(LIB)
...
...
userspace/libswitchhw/i2c_bitbang.c
View file @
77b9c399
...
...
@@ -37,7 +37,7 @@ int i2c_bitbang_init_bus(struct i2c_bus *bus)
return
0
;
}
#define I2C_DELAY
100
#define I2C_DELAY
4
void
mi2c_pin_out
(
pio_pin_t
*
pin
,
int
state
)
{
...
...
userspace/libswitchhw/i2c_sfp.c
View file @
77b9c399
...
...
@@ -505,6 +505,17 @@ int shw_sfp_read_header(int num, struct shw_sfp_header *head)
return
0
;
}
int
shw_sfp_read_verify_header
(
int
num
,
struct
shw_sfp_header
*
head
)
{
int
ret
;
ret
=
shw_sfp_read_header
(
num
,
head
);
if
(
ret
<
0
)
return
ret
;
return
shw_sfp_header_verify
(
head
);
}
static
struct
shw_sfp_caldata
*
shw_sfp_cal_list
=
NULL
;
int
shw_sfp_read_db
(
char
*
filename
)
...
...
@@ -512,10 +523,7 @@ int shw_sfp_read_db(char *filename)
lua_State
*
L
=
luaL_newstate
();
struct
shw_sfp_caldata
*
sfp
;
luaopen_base
(
L
);
luaopen_io
(
L
);
luaopen_string
(
L
);
luaopen_math
(
L
);
luaL_openlibs
(
L
);
if
(
luaL_loadfile
(
L
,
filename
)
||
lua_pcall
(
L
,
0
,
0
,
0
))
{
printf
(
"cannot run configuration file: %s"
,
...
...
@@ -535,21 +543,27 @@ int shw_sfp_read_db(char *filename)
continue
;
}
int
i
=
0
;
const
char
*
sfp_pn
;
const
char
*
sfp_vs
;
int
vals
[
3
];
const
char
*
sfp_pn
=
0
;
const
char
*
sfp_vs
=
0
;
int
vals
[
2
];
double
alpha
;
lua_pushnil
(
L
);
while
(
lua_next
(
L
,
-
2
))
{
if
(
i
==
0
)
sfp_pn
=
(
const
char
*
)
lua_tostring
(
L
,
-
1
);
else
if
(
i
==
1
)
sfp_vs
=
(
const
char
*
)
lua_tostring
(
L
,
-
1
);
else
vals
[
i
-
2
]
=
(
int
)
lua_tonumber
(
L
,
-
1
);
i
++
;
const
char
*
key
=
lua_tostring
(
L
,
-
2
);
if
(
strcmp
(
key
,
"part_num"
)
==
0
)
sfp_pn
=
lua_tostring
(
L
,
-
1
);
else
if
(
strcmp
(
key
,
"part_serial"
)
==
0
)
sfp_vs
=
lua_tostring
(
L
,
-
1
);
else
if
(
strcmp
(
key
,
"alpha"
)
==
0
)
alpha
=
lua_tonumber
(
L
,
-
1
);
else
if
(
strcmp
(
key
,
"delta_tx"
)
==
0
)
vals
[
0
]
=
lua_tointeger
(
L
,
-
1
);
else
if
(
strcmp
(
key
,
"delta_rx"
)
==
0
)
vals
[
1
]
=
lua_tointeger
(
L
,
-
1
);
lua_pop
(
L
,
1
);
}
lua_pop
(
L
,
1
);
sfp
=
malloc
(
sizeof
(
struct
shw_sfp_caldata
));
strcpy
(
sfp
->
part_num
,
sfp_pn
);
if
(
strcmp
(
sfp_vs
,
""
)
==
0
)
{
...
...
@@ -559,12 +573,11 @@ int shw_sfp_read_db(char *filename)
strcpy
(
sfp
->
vendor_serial
,
sfp_vs
);
sfp
->
flags
|=
SFP_FLAG_DEVICE_DATA
;
}
sfp
->
alpha
=
vals
[
0
]
;
sfp
->
delta_tx
=
vals
[
1
];
sfp
->
delta_rx
=
vals
[
2
];
sfp
->
alpha
=
alpha
;
sfp
->
delta_tx
=
vals
[
0
];
sfp
->
delta_rx
=
vals
[
1
];
sfp
->
next
=
shw_sfp_cal_list
;
shw_sfp_cal_list
=
sfp
;
printf
(
"registered cal data
\n
"
);
}
lua_pop
(
L
,
1
);
lua_close
(
L
);
...
...
@@ -601,7 +614,7 @@ struct shw_sfp_caldata *shw_sfp_get_cal_data(int num)
t
=
shw_sfp_cal_list
;
/* In the first pass, look for serial number */
while
(
t
)
{
printf
(
"search1 %s %s
\n
"
,
t
->
part_num
,
t
->
vendor_serial
);
//
printf("search1 %s %s\n", t->part_num, t->vendor_serial);
if
(
strcmp
(
pn
,
t
->
part_num
)
==
0
&&
strcmp
(
t
->
vendor_serial
,
""
)
==
0
)
other
=
t
;
else
if
(
strcmp
(
pn
,
t
->
part_num
)
==
0
&&
strcmp
(
vs
,
t
->
vendor_serial
)
==
0
)
...
...
userspace/libswitchhw/i2c_sfp.h
View file @
77b9c399
...
...
@@ -17,38 +17,6 @@
#define WR_SFP0_BUS 3
#define WR_SFP1_BUS 4
struct
shw_sfp_header
{
uint8_t
id
;
uint8_t
ext_id
;
uint8_t
connector
;
uint8_t
transciever
[
8
];
uint8_t
encoding
;
uint8_t
br_nom
;
uint8_t
reserved1
;
uint8_t
length1
;
/* Link length supported for 9/125 mm fiber (km) */
uint8_t
length2
;
/* Link length supported for 9/125 mm fiber (100m) */
uint8_t
length3
;
/* Link length supported for 50/125 mm fiber (10m) */
uint8_t
length4
;
/* Link length supported for 62.5/125 mm fiber (10m) */
uint8_t
length5
;
/* Link length supported for copper (1m) */
uint8_t
reserved2
;
uint8_t
vendor_name
[
16
];
uint8_t
reserved3
;
uint8_t
vendor_oui
[
3
];
uint8_t
vendor_pn
[
16
];
uint8_t
vendor_rev
[
4
];
uint8_t
reserved4
[
3
];
uint8_t
cc_base
;
/* extended ID fields start here */
uint8_t
options
[
2
];
uint8_t
br_max
;
uint8_t
br_min
;
uint8_t
vendor_serial
[
16
];
uint8_t
date_code
[
8
];
uint8_t
reserved
[
3
];
uint8_t
cc_ext
;
}
__attribute__
((
packed
));
extern
struct
i2c_bus
i2c_buses
[];
/**
...
...
@@ -98,5 +66,8 @@ void shw_sfp_header_dump(struct shw_sfp_header *head);
int32_t
shw_sfp_read
(
int
num
,
uint32_t
addr
,
int
off
,
int
len
,
uint8_t
*
buf
);
int32_t
shw_sfp_write
(
int
num
,
uint32_t
addr
,
int
off
,
int
len
,
uint8_t
*
buf
);
/* Set/get the 4 GPIO's connected to PCA9554's for a particular SFP */
void
shw_sfp_gpio_set
(
int
num
,
uint8_t
state
);
uint8_t
shw_sfp_gpio_get
(
int
num
);
#endif //I2C_SFP_H
userspace/libswitchhw/i2cscan.c
View file @
77b9c399
...
...
@@ -15,6 +15,7 @@
#include "i2c_fpga_reg.h"
#include "i2c_sfp.h"
#include <hw/sfp_lib.h>
#include "libshw_i2c.h"
...
...
@@ -78,7 +79,7 @@ int main()
d
=
NULL
;
d
=
shw_sfp_get_cal_data
(
i
);
if
(
d
)
printf
(
"Callibration (%s): alpha = %
d
, dtx = %d, drx = %d
\n
"
,
printf
(
"Callibration (%s): alpha = %
lf
, dtx = %d, drx = %d
\n
"
,
(
d
->
flags
&
SFP_FLAG_CLASS_DATA
)
?
"CLASS"
:
"DEVICE"
,
d
->
alpha
,
d
->
delta_tx
,
d
->
delta_rx
);
printf
(
"
\n
"
);
...
...
userspace/libswitchhw/sfpdb.lua
View file @
77b9c399
...
...
@@ -3,6 +3,11 @@
sfpdb
=
{
--{ PART_NUM, VENDOR_SERIAL, ALPHA, DELTA_TX, DELTA_RX }
{
"MGBT1"
,
""
,
8
,
9
,
10
},
{
"MGBT1"
,
"FSZ15311600"
,
5
,
6
,
7
}
{
part_num
=
"MGBT1"
,
part_serial
=
"FSZ15311600"
,
alpha
=
5
.
055223
,
delta_tx
=
6
,
delta_rx
=
7
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment