Commit 77b9c399 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski

Merge branch 'v3-minibackplane-i2c' into v3-rts-slave

parents b4b9e764 8ffbd130
......@@ -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
......@@ -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)
......
......@@ -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)
{
......
......@@ -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)
......
......@@ -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
......@@ -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");
......
......@@ -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
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment