Commit fdf43f19 authored by Alessandro Rubini's avatar Alessandro Rubini

userspace: hal and libwr: change prototypes for exports

This has no effect on the code functionality.

Even if it affects libwr, this is a hal-only change.  The functions
in libwr that the hal itself uses, now receive a pointer to ports[],
which is thus back a static pointer within wrsw_hal/hal_ports.c.

This change allows moving the RPC queries to be shared memory lookups,
by using the ports[] pointer in the client; so both the client and
the server can access the same shared mamory using libwr functions.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 7ec3a948
......@@ -11,7 +11,8 @@
extern struct hal_port_state *ports; /* FIXME: temporarily */
extern int hal_port_nports;
struct hal_port_state *hal_port_lookup(const char *name)
struct hal_port_state *hal_port_lookup(struct hal_port_state *ports,
const char *name)
{
int i;
for (i = 0; i < HAL_MAX_PORTS; i++)
......@@ -23,9 +24,10 @@ struct hal_port_state *hal_port_lookup(const char *name)
int hal_port_get_exported_state(struct hexp_port_state *state,
struct hal_port_state *ports,
const char *port_name)
{
struct hal_port_state *p = hal_port_lookup(port_name);
const struct hal_port_state *p = hal_port_lookup(ports, port_name);
// TRACE(TRACE_INFO, "GetPortState %s [lup %x]\n", port_name, p);
......@@ -66,7 +68,8 @@ int hal_port_get_exported_state(struct hexp_port_state *state,
/* Public API function - returns the array of names of all WR network
* interfaces */
int hal_port_query_ports(struct hexp_port_list *list)
int hal_port_query_ports(struct hexp_port_list *list,
const struct hal_port_state *ports)
{
int i;
int n = 0;
......@@ -75,7 +78,7 @@ int hal_port_query_ports(struct hexp_port_list *list)
if (ports[i].in_use)
strcpy(list->port_names[n++], ports[i].name);
list->num_physical_ports = hal_port_nports;
list->num_physical_ports = 18; /* was hal_port_nports */
list->num_ports = n;
return 0;
}
......
......@@ -98,18 +98,17 @@ struct hal_shmem_header {
};
/*
* The following two functions were in userspace/wrsw_hal/hal_ports.c,
* The following functions were in userspace/wrsw_hal/hal_ports.c,
* and are used to marshall data for the RPC format. Now that we
* offer shared memory, it is the caller who must convert data to
* the expected format (which remains the RPC one as I write this).
*/
extern struct hal_port_state *hal_port_lookup(const char *name);
extern int hal_port_query_ports(struct hexp_port_list *list);
extern int hal_port_get_exported_state(struct hexp_port_state *state,
const char *port_name);
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);
#endif /* __LIBWR_HAL_SHMEM_H__ */
......@@ -15,6 +15,7 @@
#include <hal/hal_exports.h> /* for exported structs/function protos */
static struct minipc_ch *hal_ch;
static struct hal_port_state *ports;
/* Locking call - controls the HAL locking state machine. Called by
the PTPd during the WR Link Setup phase, when it has detected a
......@@ -171,7 +172,8 @@ static int export_get_port_state(const struct minipc_pd *pd,
{
hexp_port_state_t *state = ret;
return hal_port_get_exported_state(state, (char *)args /* name */ );
return hal_port_get_exported_state(state, ports,
(char *)args /* name */ );
}
static int export_lock_cmd(const struct minipc_pd *pd,
......@@ -192,7 +194,7 @@ static int export_query_ports(const struct minipc_pd *pd,
uint32_t * args, void *ret)
{
hexp_port_list_t *list = ret;
hal_port_query_ports(list);
hal_port_query_ports(list, ports);
return 0;
}
......@@ -204,8 +206,10 @@ static int export_get_timing_state(const struct minipc_pd *pd,
}
/* Creates a wripc server and exports all public API functions */
int hal_init_wripc()
int hal_init_wripc(struct hal_port_state *hal_ports)
{
ports = hal_ports; /* static pointer used later */
hal_ch = minipc_server_create(WRSW_HAL_SERVER_ADDR, 0);
if (hal_ch < 0) {
......
......@@ -107,12 +107,9 @@ static int hal_init()
assert_init(hal_init_timing());
/* Initialize port FSMs - see hal_ports.c */
/* Initialize port FSMs and IPC/RPC - see hal_ports.c */
assert_init(hal_port_init_all());
/* Create a WRIPC server for HAL public API */
assert_init(hal_init_wripc());
//everything is fine up to here, we can blink green LED
shw_io_write(shw_io_led_state_o, 0);
shw_io_write(shw_io_led_state_g, 1);
......
......@@ -38,7 +38,7 @@
static void *hal_port_shmem;
/* Port table: the only item which is not "hal_port_*", as it's much used */
struct hal_port_state *ports;
static struct hal_port_state *ports;
/* An fd of always opened raw sockets for ioctl()-ing Ethernet devices */
static int hal_port_fd;
......@@ -49,7 +49,7 @@ static int hal_port_rts_state_valid = 0;
/* Polling timeouts (RT Subsystem & SFP detection) */
static timeout_t hal_port_tmo_rts, hal_port_tmo_sfp;
int hal_port_nports;
static int hal_port_nports;
int hal_port_check_lock(const char *port_name);
......@@ -265,6 +265,9 @@ int hal_port_init_all()
hal_hdr->nports = hal_port_nports;
head->version = HAL_SHMEM_VERSION;
/* Create a WRIPC server for HAL public API */
return hal_init_wripc(ports);
return 0;
}
......@@ -547,7 +550,7 @@ void hal_port_update_all()
int hal_port_enable_tracking(const char *port_name)
{
struct hal_port_state *p = hal_port_lookup(port_name);
const struct hal_port_state *p = hal_port_lookup(ports, port_name);
if (!p)
return -1;
......@@ -559,7 +562,7 @@ int hal_port_enable_tracking(const char *port_name)
* WR link setup phase. */
int hal_port_start_lock(const char *port_name, int priority)
{
struct hal_port_state *p = hal_port_lookup(port_name);
struct hal_port_state *p = hal_port_lookup(ports, port_name);
if (!p)
return -1;
......@@ -581,7 +584,7 @@ int hal_port_start_lock(const char *port_name, int priority)
/* Returns 1 if the port is locked */
int hal_port_check_lock(const char *port_name)
{
struct hal_port_state *p = hal_port_lookup(port_name);
const struct hal_port_state *p = hal_port_lookup(ports, port_name);
struct rts_pll_state *hs = &hal_port_rts_state;
if (!p)
......
......@@ -19,10 +19,13 @@ int hal_config_iterate(const char *section, int index,
int hal_port_init_all();
void hal_port_update_all();
struct hexp_port_state;
struct hal_port_state;
int hal_port_get_exported_state(struct hexp_port_state *state,
struct hal_port_state *ports,
const char *port_name);
struct hexp_port_list;
int hal_port_query_ports(struct hexp_port_list *list);
int hal_port_query_ports(struct hexp_port_list *list,
const struct hal_port_state *ports);
int hal_init_wripc();
......
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