Commit d724bd8f authored by Alessandro Rubini's avatar Alessandro Rubini

arch-wrs: use new headers from wr-switch-sw; fix use of sfp delta_[tr]x

delta_tx and delta_rx in the SFP information are differences from
the values in the "calibration" SFP model. Thus they are signed
not uint32_t.  Fortunately nobody used negative values so far.

I also renamed the fields, to ensure the compiler would find all uses.

(there are other irrelevant changes in upstream headers; this commits
puts them in sync again).
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 4dbc6b0b
......@@ -151,7 +151,6 @@ extern int halexp_check_running(void);
extern int halexp_reset_port(const char *port_name);
extern int halexp_calibration_cmd(const char *port_name, int command, int on_off);
extern int halexp_lock_cmd(const char *port_name, int command, int priority);
extern int halexp_query_ports(hexp_port_list_t *list);
extern int halexp_get_port_state(hexp_port_state_t *state, const char *port_name);
extern int halexp_pps_cmd(int cmd, hexp_pps_params_t *params);
extern int halexp_get_timing_state(hexp_timing_state_t *state);
......@@ -203,15 +202,6 @@ struct minipc_pd __rpcdef_lock_cmd = {
},
};
//int halexp_query_ports(hexp_port_list_t *list);
struct minipc_pd __rpcdef_query_ports = {
.name = "query_ports",
.retval = MINIPC_ARG_ENCODE(MINIPC_ATYPE_STRUCT, hexp_port_list_t),
.args = {
MINIPC_ARG_END,
},
};
//int halexp_get_port_state(hexp_port_state_t *state, const char *port_name);
struct minipc_pd __rpcdef_get_port_state = {
.name = "get_port_state",
......
......@@ -3,6 +3,7 @@
#include <hal_exports.h>
#include <libwr/sfp_lib.h>
#include <string.h>
/* Port state machine states */
#define HAL_PORT_STATE_DISABLED 0
......@@ -70,8 +71,8 @@ struct hal_port_state {
/* port FSM state (HAL_PORT_STATE_xxxx) */
int state;
/* unused */
int index;
/* fiber type, used to get alpha for SFP frequency */
int fiber_index;
/* 1: PLL is locked to this port */
int locked;
......@@ -91,7 +92,7 @@ struct hal_port_state {
};
/* This is the overall structure stored in shared memory */
#define HAL_SHMEM_VERSION 2 /* Version 2 because sfp calib changed */
#define HAL_SHMEM_VERSION 3 /* Version 3 because sfp delta is signed */
struct hal_shmem_header {
int nports;
struct hal_port_state *ports;
......@@ -105,10 +106,26 @@ struct hal_shmem_header {
*/
struct hal_port_state *hal_port_lookup(struct hal_port_state *ports,
const char *name);
int hal_port_query_ports(struct hexp_port_list *list,
const struct hal_port_state *ports);
int hal_port_get_exported_state(struct hexp_port_state *state,
struct hal_port_state *ports,
const char *port_name);
static inline int state_up(int state)
{
return (state != HAL_PORT_STATE_LINK_DOWN
&& state != HAL_PORT_STATE_DISABLED);
}
static inline struct hal_port_state *hal_lookup_port(
struct hal_port_state *ports, int nports, char *name)
{
int i;
for (i = 0; i < nports; i++)
if (ports[i].in_use && (!strcmp(name, ports[i].name)))
return ports + i;
return NULL;
}
#endif /* __LIBWR_HAL_SHMEM_H__ */
......@@ -32,8 +32,8 @@ struct shw_sfp_caldata {
char vendor_serial[16];
/* Callibration data */
double alpha;
uint32_t delta_tx;
uint32_t delta_rx;
int delta_tx_ps; /* "delta" of this SFP type WRT calibration type */
int delta_rx_ps;
/* wavelengths, used to get alpha from fiber type */
int tx_wl;
int rx_wl;
......
......@@ -36,8 +36,9 @@ struct wrs_shm_head {
};
/* flags */
#define WRS_SHM_READ 0x0000
#define WRS_SHM_WRITE 0x0001
#define WRS_SHM_READ 0x0000
#define WRS_SHM_WRITE 0x0001
#define WRS_SHM_LOCKED 0x0002 /* at init time: writers locks, readers wait */
/* get vs. put, like in the kernel. Errors are in errno (see source) */
void *wrs_shm_get(enum wrs_shm_name name_id, char *name, unsigned long flags);
......@@ -50,7 +51,9 @@ void *wrs_shm_alloc(void *headptr, size_t size);
void *wrs_shm_follow(void *headptr, void *ptr);
/* Before and after writing a chunk of data, act on sequence and stamp */
extern void wrs_shm_write(void *headptr, int begin);
#define WRS_SHM_WRITE_BEGIN 1
#define WRS_SHM_WRITE_END 0
extern void wrs_shm_write(void *headptr, int flags);
/* A reader can rely on the sequence number (in the <linux/seqlock.h> way) */
extern unsigned wrs_shm_seqbegin(void *headptr);
......
......@@ -36,9 +36,9 @@ int wrs_read_calibration_data(struct pp_instance *ppi,
* Formulas copied from libwr/hal_shmem.c (get_exported_state).
*/
port_delta_tx = p->calib.delta_tx_phy
+ p->calib.sfp.delta_tx + p->calib.delta_tx_board;
+ p->calib.sfp.delta_tx_ps + p->calib.delta_tx_board;
port_delta_rx = p->calib.delta_rx_phy
+ p->calib.sfp.delta_rx + p->calib.delta_rx_board;
+ p->calib.sfp.delta_rx_ps + p->calib.delta_rx_board;
port_fix_alpha = (double)pow(2.0, 40.0) *
((p->calib.sfp.alpha + 1.0) / (p->calib.sfp.alpha + 2.0)
- 0.5);
......
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