Commit 542f276e authored by Alessandro Rubini's avatar Alessandro Rubini

usersspace/hal: massive (manual) rename within hal_ports.c

After this commit, all symbols in hal_ports are of the form hal_port_*
(all but one, that is not used and I'll remove it in another commit).
I'm not smart enough to track the origin of the various names, so I
need this.  I need this especially in this file because I'm going to
export stuff using shmem, to avoid a lot of context switches.

Thus, the "private" structure hal_port_state is not a typedef any
more, as a first step in becoming public. It doesn't make sense to
have two almost-identical structures, where one is copied to the other
one item at a time to deal with the minor differences. (It happened
for some reason: I'm not complaining hard, but it's time to get rid of
this).

Unfortunately, two functions were called "halexp", and relied on a
prototype shared by the RPC server (this file) and the RPC client.
While the convention made sense at first, it now shows its limits, so
the exported one is called hal_port_* like everything in the file, but
for this I need to add structure names (but I left the typedef at this
point, to avoid massive name changes around).

If I didn't introduce bugs, the code is the same as it was. I did it
one symbol at a time while build-checking each steps (and I even have
the commits to track any error).
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 95e8ba67
......@@ -90,7 +90,7 @@ typedef struct {
#define HEXP_PORT_TSC_FALLING 2
*/
typedef struct {
typedef struct hexp_port_state {
/* When non-zero: port state is valid */
int valid;
......@@ -134,7 +134,7 @@ typedef struct {
int32_t fiber_fix_alpha;
} hexp_port_state_t;
typedef struct {
typedef struct hexp_port_list {
int num_ports; /* Number of ports in the list */
int num_physical_ports; /* Number of physical ports compiled into the FPGA bitstream */
char port_names[HAL_MAX_PORTS][16];
......
......@@ -29,7 +29,7 @@ int halexp_lock_cmd(const char *port_name, int command, int priority)
switch (command) {
case HEXP_LOCK_CMD_ENABLE_TRACKING:
return hal_enable_tracking(port_name);
return hal_port_enable_tracking(port_name);
/* Start locking - i.e. tell the HAL locking state
machine to use the port (port_name) as the source
......@@ -129,7 +129,7 @@ int halexp_pps_cmd(int cmd, hexp_pps_params_t * params)
delay calculation. */
case HEXP_PPSG_CMD_POLL:
busy = shw_pps_gen_busy() || hal_phase_shifter_busy();
busy = shw_pps_gen_busy() || hal_port_pshifter_busy();
return busy ? 0 : 1;
case HEXP_PPSG_CMD_SET_VALID:
......@@ -139,12 +139,12 @@ int halexp_pps_cmd(int cmd, hexp_pps_params_t * params)
return -1; /* fixme: real error code */
}
extern int any_port_locked();
extern int hal_port_any_locked();
int halexp_get_timing_state(hexp_timing_state_t * state)
{
state->timing_mode = hal_get_timing_mode();
state->locked_port = any_port_locked();
state->locked_port = hal_port_any_locked();
return 0;
}
......@@ -171,7 +171,7 @@ static int export_get_port_state(const struct minipc_pd *pd,
{
hexp_port_state_t *state = ret;
return halexp_get_port_state(state, (char *)args /* name */ );
return hal_port_get_exported_state(state, (char *)args /* name */ );
}
static int export_lock_cmd(const struct minipc_pd *pd,
......@@ -192,7 +192,7 @@ static int export_query_ports(const struct minipc_pd *pd,
uint32_t * args, void *ret)
{
hexp_port_list_t *list = ret;
halexp_query_ports(list);
hal_port_query_ports(list);
return 0;
}
......
......@@ -108,7 +108,7 @@ static int hal_init()
assert_init(hal_init_timing());
/* Initialize port FSMs - see hal_ports.c */
assert_init(hal_init_ports());
assert_init(hal_port_init_all());
/* Create a WRIPC server for HAL public API */
assert_init(hal_init_wripc());
......@@ -128,7 +128,7 @@ static int hal_init()
static void hal_update()
{
hal_update_wripc();
hal_update_ports();
hal_port_update_all();
shw_update_fans();
// usleep(1000);
}
......
......@@ -56,7 +56,7 @@
#define SFP_POLL_INTERVAL 1000 /* ms */
/* Internal port state structure */
typedef struct {
struct hal_port_state {
/* non-zero: allocated */
int in_use;
/* linux i/f name */
......@@ -96,36 +96,36 @@ typedef struct {
/* Endpoint's base address */
uint32_t ep_base;
} hal_port_state_t;
};
/* Port table */
static hal_port_state_t ports[HAL_MAX_PORTS];
/* Port table: the only item which is not "hal_port_*", as it's much used */
static struct hal_port_state ports[HAL_MAX_PORTS];
/* An fd of always opened raw sockets for ioctl()-ing Ethernet devices */
static int fd_raw;
static int hal_port_fd;
/* RT subsystem PLL state, polled regularly via mini-ipc */
static struct rts_pll_state rts_state;
static int rts_state_valid = 0;
static struct rts_pll_state hal_port_rts_state;
static int hal_port_rts_state_valid = 0;
/* Polling timeouts (RT Subsystem & SFP detection) */
static timeout_t tmo_rts, tmo_sfp;
static int num_physical_ports;
static timeout_t hal_port_tmo_rts, hal_port_tmo_sfp;
static int hal_port_nports;
int hal_port_check_lock(const char *port_name);
int any_port_locked()
int hal_port_any_locked()
{
if (!rts_state_valid)
if (!hal_port_rts_state_valid)
return -1;
if (rts_state.current_ref == REF_NONE)
if (hal_port_rts_state.current_ref == REF_NONE)
return -1;
return rts_state.current_ref;
return hal_port_rts_state.current_ref;
}
/* Resets the state variables of a port and re-starts its state machines */
static void reset_port_state(hal_port_state_t * p)
static void hal_port_reset_state(struct hal_port_state * p)
{
p->calib.rx_calibrated = 0;
p->calib.tx_calibrated = 0;
......@@ -142,7 +142,7 @@ static void reset_port_state(hal_port_state_t * p)
/* helper function for retreiving port parameters from the config
files with type checking and defaulting to a given value when the
parameter is not found */
static void cfg_get_port_param(const char *port_name, const char *param_name,
static void hal_port_cfg_get(const char *port_name, const char *param_name,
void *rval, int param_type, ...)
{
va_list ap;
......@@ -171,19 +171,19 @@ static void cfg_get_port_param(const char *port_name, const char *param_name,
}
/* checks if the port is supported by the FPGA firmware */
static int check_port_presence(const char *if_name)
static int hal_port_check_presence(const char *if_name)
{
struct ifreq ifr;
strncpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name));
if (ioctl(fd_raw, SIOCGIFHWADDR, &ifr) < 0)
if (ioctl(hal_port_fd, SIOCGIFHWADDR, &ifr) < 0)
return 0;
return 1;
}
static void enable_port(int port, int enable)
static void hal_port_enable(int port, int enable)
{
char str[50];
snprintf(str, sizeof(str), "/sbin/ifconfig wr%d %s", port,
......@@ -193,21 +193,21 @@ static void enable_port(int port, int enable)
/* Port initialization. Assigns the MAC address, WR timing mode, reads
* parameters from the config file. */
static int hal_init_port(const char *name, int index)
static int hal_port_init(const char *name, int index)
{
char key_name[128];
char val[128];
hal_port_state_t *p = &ports[index];
struct hal_port_state *p = &ports[index];
/* check if the port is compiled into the firmware, if not, ignore. */
if (!check_port_presence(name)) {
reset_port_state(p);
if (!hal_port_check_presence(name)) {
hal_port_reset_state(p);
p->in_use = 0;
return 0;
}
/* make sure the states and other variables are in their init state */
reset_port_state(p);
hal_port_reset_state(p);
p->state = HAL_PORT_STATE_DISABLED;
p->in_use = 1;
......@@ -215,19 +215,19 @@ static int hal_init_port(const char *name, int index)
strncpy(p->name, name, 16);
/* read calibraton parameters (unwrapping and constant deltas) */
cfg_get_port_param(name, "phy_rx_min", &p->calib.phy_rx_min,
hal_port_cfg_get(name, "phy_rx_min", &p->calib.phy_rx_min,
AT_INT32, 18 * 800);
cfg_get_port_param(name, "phy_tx_min", &p->calib.phy_tx_min,
hal_port_cfg_get(name, "phy_tx_min", &p->calib.phy_tx_min,
AT_INT32, 18 * 800);
cfg_get_port_param(name, "delta_tx_board", &p->calib.delta_tx_board,
hal_port_cfg_get(name, "delta_tx_board", &p->calib.delta_tx_board,
AT_INT32, 0);
cfg_get_port_param(name, "delta_rx_board", &p->calib.delta_rx_board,
hal_port_cfg_get(name, "delta_rx_board", &p->calib.delta_rx_board,
AT_INT32, 0);
sscanf(p->name + 2, "%d", &p->hw_index);
enable_port(p->hw_index, 1);
hal_port_enable(p->hw_index, 1);
/* Set up the endpoint's address (fixme: do this with the driver) */
......@@ -265,7 +265,7 @@ static int hal_init_port(const char *name, int index)
/* Interates via all the ports defined in the config file and
* intializes them one after another. */
int hal_init_ports()
int hal_port_init_all()
{
int index = 0, i;
char port_name[128];
......@@ -273,25 +273,25 @@ int hal_init_ports()
TRACE(TRACE_INFO, "Initializing switch ports...");
/* default timeouts */
tmo_init(&tmo_sfp, SFP_POLL_INTERVAL, 1);
tmo_init(&tmo_rts, RTS_POLL_INTERVAL, 1);
tmo_init(&hal_port_tmo_sfp, SFP_POLL_INTERVAL, 1);
tmo_init(&hal_port_tmo_rts, RTS_POLL_INTERVAL, 1);
/* Open a single raw socket for accessing the MAC addresses, etc. */
fd_raw = socket(AF_PACKET, SOCK_DGRAM, 0);
if (fd_raw < 0)
hal_port_fd = socket(AF_PACKET, SOCK_DGRAM, 0);
if (hal_port_fd < 0)
return -1;
/* Count the number of physical WR network interfaces */
num_physical_ports = 0;
hal_port_nports = 0;
for (i = 0; i < HAL_MAX_PORTS; i++) {
char if_name[16];
snprintf(if_name, sizeof(if_name), "wr%d", i);
if (check_port_presence(if_name))
num_physical_ports++;
if (hal_port_check_presence(if_name))
hal_port_nports++;
}
TRACE(TRACE_INFO, "Number of physical ports supported in HW: %d",
num_physical_ports);
hal_port_nports);
memset(ports, 0, sizeof(ports));
......@@ -299,20 +299,20 @@ int hal_init_ports()
if (!hal_config_iterate("ports", index++,
port_name, sizeof(port_name)))
break;
hal_init_port(port_name, index);
hal_port_init(port_name, index);
}
return 0;
}
/* Checks if the link is up on inteface (if_name). Returns non-zero if yes. */
static int check_link_up(const char *if_name)
static int hal_port_check_link(const char *if_name)
{
struct ifreq ifr;
strncpy(ifr.ifr_name, if_name, sizeof(ifr.ifr_name));
if (ioctl(fd_raw, SIOCGIFFLAGS, &ifr) > 0)
if (ioctl(hal_port_fd, SIOCGIFFLAGS, &ifr) > 0)
return -1;
return (ifr.ifr_flags & IFF_UP && ifr.ifr_flags & IFF_RUNNING);
......@@ -321,23 +321,25 @@ static int check_link_up(const char *if_name)
/* Port locking state machine - controls the HPLL/DMPLL. TODO (v3):
get rid of this code - this will all be moved to the realtime CPU
inside the FPGA and the softpll. */
static void port_locking_fsm(hal_port_state_t * p)
static void hal_port_locking_fsm(struct hal_port_state * p)
{
}
int hal_phase_shifter_busy()
int hal_port_pshifter_busy()
{
if (!rts_state_valid)
struct rts_pll_state *hs = &hal_port_rts_state;
if (!hal_port_rts_state_valid)
return 1;
if (rts_state.current_ref != REF_NONE) {
if (hs->current_ref != REF_NONE) {
int busy =
rts_state.channels[rts_state.current_ref].
hs->channels[hs->current_ref].
flags & CHAN_SHIFTING ? 1 : 0;
if (0)
TRACE(TRACE_INFO, "PSBusy %d, flags %x", busy,
rts_state.channels[rts_state.current_ref].flags);
hs->channels[hs->current_ref].flags);
return busy;
}
......@@ -348,14 +350,16 @@ int hal_phase_shifter_busy()
* port. Called by the main update function regularly. */
static void poll_rts_state()
{
if (tmo_expired(&tmo_rts)) {
rts_state_valid = rts_get_state(&rts_state) < 0 ? 0 : 1;
if (!rts_state_valid)
struct rts_pll_state *hs = &hal_port_rts_state;
if (tmo_expired(&hal_port_tmo_rts)) {
hal_port_rts_state_valid = rts_get_state(hs) < 0 ? 0 : 1;
if (!hal_port_rts_state_valid)
printf("rts_get_state failure, weird...\n");
}
}
static uint32_t pcs_readl(hal_port_state_t * p, int reg)
static uint32_t pcs_readl(struct hal_port_state * p, int reg)
{
struct ifreq ifr;
uint32_t rv;
......@@ -364,8 +368,8 @@ static uint32_t pcs_readl(hal_port_state_t * p, int reg)
rv = NIC_READ_PHY_CMD(reg);
ifr.ifr_data = (void *)&rv;
// printf("raw fd %d name %s\n", fd_raw, ifr.ifr_name);
if (ioctl(fd_raw, PRIV_IOCPHYREG, &ifr) < 0) {
// printf("raw fd %d name %s\n", hal_port_fd, ifr.ifr_name);
if (ioctl(hal_port_fd, PRIV_IOCPHYREG, &ifr) < 0) {
fprintf(stderr, "ioctl failed\n");
};
......@@ -373,7 +377,7 @@ static uint32_t pcs_readl(hal_port_state_t * p, int reg)
return NIC_RESULT_DATA(rv);
}
static int handle_link_down(hal_port_state_t * p, int link_up)
static int hal_port_link_down(struct hal_port_state * p, int link_up)
{
/* If, at any moment, the link goes down, reset the FSM and
* the port state structure. */
......@@ -389,7 +393,7 @@ static int handle_link_down(hal_port_state_t * p, int link_up)
shw_sfp_set_led_link(p->hw_index, 0);
p->state = HAL_PORT_STATE_LINK_DOWN;
reset_port_state(p);
hal_port_reset_state(p);
rts_enable_ptracker(p->hw_index, 0);
TRACE(TRACE_INFO, "%s: link down", p->name);
......@@ -400,14 +404,15 @@ static int handle_link_down(hal_port_state_t * p, int link_up)
}
/* Main port state machine */
static void port_fsm(hal_port_state_t * p)
static void hal_port_fsm(struct hal_port_state * p)
{
int link_up = check_link_up(p->name);
struct rts_pll_state *hs = &hal_port_rts_state;
int link_up = hal_port_check_link(p->name);
if (handle_link_down(p, link_up))
if (hal_port_link_down(p, link_up))
return;
/* handle the locking part */
port_locking_fsm(p);
/* handle the locking part */
hal_port_locking_fsm(p);
switch (p->state) {
......@@ -416,7 +421,7 @@ static void port_fsm(hal_port_state_t * p)
p->calib.rx_calibrated = 0;
break;
/* Default state - wait until the link goes up */
/* Default state - wait until the link goes up */
case HAL_PORT_STATE_LINK_DOWN:
{
if (link_up) {
......@@ -449,11 +454,11 @@ static void port_fsm(hal_port_state_t * p)
/* Default "on" state - just keep polling the phase value. */
case HAL_PORT_STATE_UP:
if (rts_state_valid) {
if (hal_port_rts_state_valid) {
p->phase_val =
rts_state.channels[p->hw_index].phase_loopback;
hs->channels[p->hw_index].phase_loopback;
p->phase_val_valid =
rts_state.channels[p->hw_index].
hs->channels[p->hw_index].
flags & CHAN_PMEAS_READY ? 1 : 0;
//hal_port_check_lock(p->name);
//p->locked =
......@@ -491,7 +496,7 @@ static void port_fsm(hal_port_state_t * p)
}
}
static void on_insert_sfp(hal_port_state_t * p)
static void hal_port_insert_sfp(struct hal_port_state * p)
{
struct shw_sfp_header shdr;
if (shw_sfp_read_verify_header(p->hw_index, &shdr) < 0)
......@@ -528,16 +533,16 @@ static void on_insert_sfp(hal_port_state_t * p)
}
}
static void on_remove_sfp(hal_port_state_t * p)
static void hal_port_remove_sfp(struct hal_port_state * p)
{
handle_link_down(p, 0);
hal_port_link_down(p, 0);
p->state = HAL_PORT_STATE_DISABLED;
}
/* detects insertion/removal of SFP transceivers */
static void poll_sfps()
static void hal_port_poll_sfp()
{
if (tmo_expired(&tmo_sfp)) {
if (tmo_expired(&hal_port_tmo_sfp)) {
uint32_t mask = shw_sfp_module_scan();
static int old_mask = 0;
......@@ -554,9 +559,9 @@ static void poll_sfps()
insert ? "insertion" : "removal",
ports[i].name);
if (insert)
on_insert_sfp(&ports[i]);
hal_port_insert_sfp(&ports[i]);
else
on_remove_sfp(&ports[i]);
hal_port_remove_sfp(&ports[i]);
}
}
}
......@@ -565,20 +570,20 @@ static void poll_sfps()
}
/* Executes the port FSM for all ports. Called regularly by the main loop. */
void hal_update_ports()
void hal_port_update_all()
{
int i;
poll_rts_state();
poll_sfps();
hal_port_poll_sfp();
for (i = 0; i < HAL_MAX_PORTS; i++)
if (ports[i].in_use)
port_fsm(&ports[i]);
hal_port_fsm(&ports[i]);
}
/* Queries the port state structre for a given network interface. */
static hal_port_state_t *lookup_port(const char *name)
static struct hal_port_state *hal_port_lookup(const char *name)
{
int i;
for (i = 0; i < HAL_MAX_PORTS; i++)
......@@ -588,9 +593,9 @@ static hal_port_state_t *lookup_port(const char *name)
return NULL;
}
int hal_enable_tracking(const char *port_name)
int hal_port_enable_tracking(const char *port_name)
{
hal_port_state_t *p = lookup_port(port_name);
struct hal_port_state *p = hal_port_lookup(port_name);
if (!p)
return PORT_ERROR;
......@@ -602,7 +607,7 @@ int hal_enable_tracking(const char *port_name)
* WR link setup phase. */
int hal_port_start_lock(const char *port_name, int priority)
{
hal_port_state_t *p = lookup_port(port_name);
struct hal_port_state *p = hal_port_lookup(port_name);
if (!p)
return PORT_ERROR;
......@@ -624,27 +629,29 @@ 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)
{
hal_port_state_t *p = lookup_port(port_name);
struct hal_port_state *p = hal_port_lookup(port_name);
struct rts_pll_state *hs = &hal_port_rts_state;
if (!p)
return PORT_ERROR;
if (!rts_state_valid)
if (!hal_port_rts_state_valid)
return 0;
if (rts_state.delock_count > 0)
if (hs->delock_count > 0)
return 0;
return (rts_state.current_ref == p->hw_index &&
(rts_state.flags & RTS_DMTD_LOCKED) &&
(rts_state.flags & RTS_REF_LOCKED));
return (hs->current_ref == p->hw_index &&
(hs->flags & RTS_DMTD_LOCKED) &&
(hs->flags & RTS_REF_LOCKED));
}
/* Public function for querying the state of a particular port (DMTD
* phase, calibration deltas, etc.) */
int halexp_get_port_state(hexp_port_state_t * state, const char *port_name)
int hal_port_get_exported_state(struct hexp_port_state *state,
const char *port_name)
{
hal_port_state_t *p = lookup_port(port_name);
struct hal_port_state *p = hal_port_lookup(port_name);
// TRACE(TRACE_INFO, "GetPortState %s [lup %x]\n", port_name, p);
......@@ -685,7 +692,7 @@ int halexp_get_port_state(hexp_port_state_t * state, const char *port_name)
/* Public API function - returns the array of names of all WR network
* interfaces */
int halexp_query_ports(hexp_port_list_t * list)
int hal_port_query_ports(struct hexp_port_list *list)
{
int i;
int n = 0;
......@@ -694,7 +701,7 @@ int halexp_query_ports(hexp_port_list_t * list)
if (ports[i].in_use)
strcpy(list->port_names[n++], ports[i].name);
list->num_physical_ports = num_physical_ports;
list->num_physical_ports = hal_port_nports;
list->num_ports = n;
return 0;
}
......
......@@ -57,8 +57,14 @@ int hal_config_get_string(const char *name, char *value, int max_len);
int hal_config_iterate(const char *section, int index,
char *subsection, int max_len);
int hal_init_ports();
void hal_update_ports();
int hal_port_init_all();
void hal_port_update_all();
struct hexp_port_state;
int hal_port_get_exported_state(struct hexp_port_state *state,
const char *port_name);
struct hexp_port_list;
int hal_port_query_ports(struct hexp_port_list *list);
int hal_init_wripc();
int hal_update_wripc();
......@@ -67,11 +73,11 @@ int hal_add_cleanup_callback(hal_cleanup_callback_t cb);
int hal_port_start_lock(const char *port_name, int priority);
int hal_port_check_lock(const char *port_name);
int hal_enable_tracking(const char *port_name);
int hal_port_enable_tracking(const char *port_name);
int hal_extsrc_check_lock(void); // added by ML
int hal_init_timing();
int hal_get_timing_mode();
int hal_phase_shifter_busy();
int hal_port_pshifter_busy();
#endif
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