Commit 80b4fd6b authored by Alessandro Rubini's avatar Alessandro Rubini

general: remove bit fields in ppi

Bitfields are bad, so this turns them into flags and constants.
There should be no change at all in behaviour (although the code
is a little smaller).

The next commit does a change for real.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 5baefbaa
......@@ -6,8 +6,8 @@
#Warning "Please include <ppsi/constants.h> before <arch/constants.h>"
#endif
#undef PP_DEFAULT_ETHERNET_MODE
#define PP_DEFAULT_ETHERNET_MODE 1 /* We only use raw ethernet */
#undef PP_DEFAULT_PPI_FLAGS
#define PP_DEFAULT_PPI_FLAGS PPI_FLAG_RAW_PROTO /* We only use raw ethernet */
#endif /* __PPSI_ARCH_CONSTANTS_H__ */
......@@ -6,8 +6,8 @@
#Warning "Please include <ppsi/constants.h> before <arch/constants.h>"
#endif
#undef PP_DEFAULT_ETHERNET_MODE
#define PP_DEFAULT_ETHERNET_MODE 1 /* We only use raw ethernet */
#undef PP_DEFAULT_PPI_FLAGS
#define PP_DEFAULT_PPI_FLAGS PPI_FLAG_RAW_PROTO /* We only use raw ethernet */
#endif /* __PPSI_ARCH_CONSTANTS_H__ */
......@@ -142,15 +142,12 @@ int main(int argc, char **argv)
if (ppi->cfg.proto == PPSI_PROTO_RAW)
pp_printf("Warning: simulator doesn't support raw "
"ethernet. Using UDP\n");
ppi->ethernet_mode = 0;
NP(ppi)->ch[PP_NP_GEN].fd = -1;
NP(ppi)->ch[PP_NP_EVT].fd = -1;
if (ppi->cfg.role == PPSI_ROLE_MASTER) {
ppi->master_only = 1;
ppi->slave_only = 0;
ppi->flags |= PPI_FLAG_MASTER_ONLY;
} else if (ppi->cfg.role == PPSI_ROLE_SLAVE) {
ppi->master_only = 0;
ppi->slave_only = 1;
ppi->flags |= PPI_FLAG_SLAVE_ONLY;
}
ppi->t_ops = &DEFAULT_TIME_OPS;
ppi->n_ops = &DEFAULT_NET_OPS;
......
......@@ -52,7 +52,7 @@ void unix_main_loop(struct pp_globals *ppg)
* If we are sending or receiving raw ethernet frames,
* the ptp payload is one-eth-header bytes into the frame
*/
if (ppi->ethernet_mode)
if (ppi->flags & PPI_FLAG_RAW_PROTO)
NP(ppi)->ptp_offset = ETH_HLEN;
/*
......
......@@ -82,14 +82,13 @@ int main(int argc, char **argv)
ppi->iface_name = ppi->cfg.iface_name;
ppi->port_name = ppi->cfg.port_name;
/* this old-fashioned "ethernet_mode" is a single bit */
ppi->ethernet_mode = (ppi->cfg.proto == PPSI_PROTO_RAW);
if (ppi->cfg.proto == PPSI_PROTO_RAW)
ppi->flags |= PPI_FLAG_RAW_PROTO;
if (ppi->cfg.role == PPSI_ROLE_MASTER) {
ppi->master_only = 1;
ppi->slave_only = 0;
ppi->flags |= PPI_FLAG_MASTER_ONLY;
}
else if (ppi->cfg.role == PPSI_ROLE_SLAVE) {
ppi->master_only = 0;
ppi->slave_only = 1;
ppi->flags |= PPI_FLAG_SLAVE_ONLY;
}
/* FIXME set ppi ext enable as defined in its pp_link */
......
......@@ -6,8 +6,8 @@
#Warning "Please include <ppsi/constants.h> before <arch/constants.h>"
#endif
#undef PP_DEFAULT_ETHERNET_MODE
#define PP_DEFAULT_ETHERNET_MODE 1 /* We only use raw ethernet */
#undef PP_DEFAULT_PPI_FLAGS
#define PP_DEFAULT_PPI_FLAGS PPI_FLAG_RAW_PROTO /* We only use raw ethernet */
#endif /* __PPSI_ARCH_CONSTANTS_H__ */
......@@ -124,8 +124,8 @@ int wrc_ptp_set_mode(int mode)
switch (mode) {
case WRC_MODE_GM:
wrp->wrConfig = WR_M_ONLY;
ppi->master_only = TRUE;
ppi->slave_only = FALSE;
ppi->flags |= PPI_FLAG_MASTER_ONLY;
ppi->flags &= ~PPI_FLAG_SLAVE_ONLY;
*class_ptr = PP_CLASS_WR_GM_LOCKED;
spll_init(SPLL_MODE_GRAND_MASTER, 0, 1);
lock_timeout = LOCK_TIMEOUT_GM;
......@@ -133,8 +133,8 @@ int wrc_ptp_set_mode(int mode)
case WRC_MODE_MASTER:
wrp->wrConfig = WR_M_ONLY;
ppi->master_only = TRUE;
ppi->slave_only = FALSE;
ppi->flags |= PPI_FLAG_MASTER_ONLY;
ppi->flags &= ~PPI_FLAG_SLAVE_ONLY;
*class_ptr = PP_CLASS_DEFAULT;
spll_init(SPLL_MODE_FREE_RUNNING_MASTER, 0, 1);
lock_timeout = LOCK_TIMEOUT_FM;
......@@ -142,8 +142,8 @@ int wrc_ptp_set_mode(int mode)
case WRC_MODE_SLAVE:
wrp->wrConfig = WR_S_ONLY;
ppi->master_only = FALSE;
ppi->slave_only = TRUE;
ppi->flags |= PPI_FLAG_SLAVE_ONLY;
ppi->flags &= ~PPI_FLAG_MASTER_ONLY;
*class_ptr = PP_CLASS_SLAVE_ONLY;
spll_init(SPLL_MODE_SLAVE, 0, 1);
break;
......
......@@ -88,7 +88,7 @@ void wrs_main_loop(struct pp_globals *ppg)
* If we are sending or receiving raw ethernet frames,
* the ptp payload is one-eth-header bytes into the frame
*/
if (ppi->ethernet_mode)
if (ppi->flags & PPI_FLAG_RAW_PROTO)
NP(ppi)->ptp_offset = ETH_HLEN;
/*
......
......@@ -156,14 +156,13 @@ int main(int argc, char **argv)
ppi->iface_name = ppi->cfg.iface_name;
ppi->port_name = ppi->cfg.port_name;
/* this old-fashioned "ethernet_mode" is a single bit */
ppi->ethernet_mode = (ppi->cfg.proto == PPSI_PROTO_RAW);
if (ppi->cfg.proto == PPSI_PROTO_RAW)
ppi->flags |= PPI_FLAG_RAW_PROTO;
if (ppi->cfg.role == PPSI_ROLE_MASTER) {
ppi->master_only = 1;
ppi->slave_only = 0;
ppi->flags |= PPI_FLAG_MASTER_ONLY;
}
else if (ppi->cfg.role == PPSI_ROLE_SLAVE) {
ppi->master_only = 0;
ppi->slave_only = 1;
ppi->flags |= PPI_FLAG_SLAVE_ONLY;
}
ppi->portDS = calloc(1, sizeof(*ppi->portDS));
......
......@@ -13,13 +13,13 @@
#define PP_NSEC_PER_SEC (1000*1000*1000)
/* implementation specific constants */
#define PP_DEFAULT_PPI_FLAGS 0 /* UDP mode */
#define PP_MAX_LINKS 64
#define PP_DEFAULT_CONFIGFILE "/etc/ppsi.conf"
#define PP_DEFAULT_INBOUND_LATENCY 0 /* in nsec */
#define PP_DEFAULT_OUTBOUND_LATENCY 0 /* in nsec */
#define PP_DEFAULT_FLAGS 0
#define PP_DEFAULT_ETHERNET_MODE 0
#define PP_DEFAULT_DOMAIN_NUMBER 0
#define PP_DEFAULT_AP 10
#define PP_DEFAULT_AI 1000
......
......@@ -141,6 +141,7 @@ struct pp_instance {
void *arch_data; /* if arch needs it */
void *ext_data; /* if protocol ext needs it */
unsigned long d_flags; /* diagnostics, ppi-specific flags */
int flags; /* protocol flags (see below) */
/* Pointer to global instance owning this pp_instance*/
struct pp_globals *glbs;
......@@ -182,18 +183,19 @@ struct pp_instance {
UInteger16 sent_seq[__PP_NR_MESSAGES_TYPES]; /* last sent this type */
MsgHeader received_ptp_header;
MsgHeader delay_req_hdr;
UInteger32
is_from_cur_par:1,
waiting_for_follow:1,
slave_only:1,
master_only:1,
ethernet_mode:1;
char *iface_name; /* for direct actions on hardware */
char *port_name; /* for diagnostics, mainly */
int port_idx;
struct pp_instance_cfg cfg;
};
/* The following things used to be bit fields */
#define PPI_FLAG_RAW_PROTO 1 /* was: "ethernet_mode" */
#define PPI_FLAG_SLAVE_ONLY 0x0010
#define PPI_FLAG_MASTER_ONLY 0x0020
#define PPI_FLAG_FROM_CURRENT_PARENT 0x0100
#define PPI_FLAG_WAITING_FOR_F_UP 0x0200
struct pp_globals_cfg {
int cfg_items; /* Remember how many we parsed */
......
......@@ -39,7 +39,7 @@ static struct pp_instance ppi_static = {
.t_ops = &bare_time_ops,
.iface_name = "eth0",
.port_name = "eth0",
.ethernet_mode = PP_DEFAULT_ETHERNET_MODE,
.flags = PP_DEFAULT_PPI_FLAGS,
};
/* We now have a structure with all globals, and multiple ppi inside */
......
......@@ -198,7 +198,7 @@ int pp_parse_cmdline(struct pp_globals *ppg, int argc, char **argv)
= PP_CLASS_SLAVE_ONLY;
/* Apply -g option globally, to each configured link */
for (j = 0; j < ppg->nlinks; j++)
INST(ppg, j)->slave_only = 1;
INST(ppg, j)->flags |= PPI_FLAG_SLAVE_ONLY;
break;
case 'v':
a = argv[++i];
......@@ -229,7 +229,7 @@ int pp_parse_cmdline(struct pp_globals *ppg, int argc, char **argv)
case 'e':
/* Apply -e option globally, to each configured link */
for (j = 0; j < ppg->nlinks; j++)
INST(ppg, j)->ethernet_mode = 1;
INST(ppg, j)->flags |= PPI_FLAG_RAW_PROTO;
break;
case 'G':
/* gptp_mode not supported: fall through */
......
......@@ -192,10 +192,10 @@ static int bmc_state_decision(struct pp_instance *ppi,
int cmpres;
struct pp_frgn_master myself;
if (ppi->master_only)
if (ppi->flags & PPI_FLAG_MASTER_ONLY)
goto master;
if (ppi->slave_only)
if (ppi->flags & PPI_FLAG_SLAVE_ONLY)
goto slave;
if ((!ppi->frgn_rec_num) && (ppi->state == PPS_LISTENING))
......
......@@ -50,7 +50,7 @@ int st_com_execute_slave(struct pp_instance *ppi)
if (pp_timeout_z(ppi, PP_TO_ANN_RECEIPT)) {
ppi->frgn_rec_num = 0;
if (DSDEF(ppi)->clockQuality.clockClass != PP_CLASS_SLAVE_ONLY
&& !ppi->slave_only) {
&& !(ppi->flags & PPI_FLAG_SLAVE_ONLY)) {
m1(ppi);
ppi->next_state = PPS_MASTER;
} else {
......@@ -131,7 +131,7 @@ int st_com_slave_handle_sync(struct pp_instance *ppi, unsigned char *buf,
if (len < PP_SYNC_LENGTH)
return -1;
if (!ppi->is_from_cur_par)
if (!(ppi->flags & PPI_FLAG_FROM_CURRENT_PARENT))
return 0;
/* t2 may be overriden by follow-up, cField is always valid */
......@@ -139,12 +139,12 @@ int st_com_slave_handle_sync(struct pp_instance *ppi, unsigned char *buf,
cField_to_TimeInternal(&ppi->cField, hdr->correctionfield);
if ((hdr->flagField[0] & PP_TWO_STEP_FLAG) != 0) {
ppi->waiting_for_follow = TRUE;
ppi->flags |= PPI_FLAG_WAITING_FOR_F_UP;
ppi->recv_sync_sequence_id = hdr->sequenceId;
return 0;
}
msg_unpack_sync(buf, &sync);
ppi->waiting_for_follow = FALSE;
ppi->flags &= ~PPI_FLAG_WAITING_FOR_F_UP;
to_TimeInternal(&ppi->t1,
&sync.originTimestamp);
pp_servo_got_sync(ppi);
......@@ -163,13 +163,13 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
if (len < PP_FOLLOW_UP_LENGTH)
return -1;
if (!ppi->is_from_cur_par) {
if (!(ppi->flags & PPI_FLAG_FROM_CURRENT_PARENT)) {
pp_error("%s: Follow up message is not from current parent\n",
__func__);
return 0;
}
if (!ppi->waiting_for_follow) {
if (!(ppi->flags & PPI_FLAG_WAITING_FOR_F_UP)) {
pp_error("%s: Slave was not waiting a follow up message\n",
__func__);
return 0;
......@@ -182,7 +182,7 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
}
msg_unpack_follow_up(buf, &follow);
ppi->waiting_for_follow = FALSE;
ppi->flags &= ~PPI_FLAG_WAITING_FOR_F_UP;
to_TimeInternal(&ppi->t1, &follow.preciseOriginTimestamp);
/* Call the extension; it may do it all and ask to return */
......
......@@ -49,7 +49,7 @@ int msg_unpack_header(struct pp_instance *ppi, void *buf, int plen)
return -1;
/*
* This "is_from_cur_par" must be killed. Meanwhile, say it's
* This FLAG_FROM_CURRENT_PARENT must be killed. Meanwhile, say it's
* from current parent if we have no current parent, so the rest works
*/
if (!DSPAR(ppi)->parentPortIdentity.portNumber ||
......@@ -58,9 +58,9 @@ int msg_unpack_header(struct pp_instance *ppi, void *buf, int plen)
PP_CLOCK_IDENTITY_LENGTH) &&
(DSPAR(ppi)->parentPortIdentity.portNumber ==
hdr->sourcePortIdentity.portNumber)))
ppi->is_from_cur_par = 1;
ppi->flags |= PPI_FLAG_FROM_CURRENT_PARENT;
else
ppi->is_from_cur_par = 0;
ppi->flags &= ~PPI_FLAG_FROM_CURRENT_PARENT;
return 0;
}
......
......@@ -62,7 +62,7 @@ int pp_init_globals(struct pp_globals *ppg, struct pp_runtime_opts *pp_rt_opts)
sizeof(ClockQuality));
if (def->numberPorts == 1)
def->slaveOnly = INST(ppg, 0)->slave_only;
def->slaveOnly = !!(INST(ppg, 0)->flags & PPI_FLAG_SLAVE_ONLY);
else
def->slaveOnly = 1; /* the for cycle below will set it to 0 if not
* ports are not all slave_only */
......@@ -74,7 +74,7 @@ int pp_init_globals(struct pp_globals *ppg, struct pp_runtime_opts *pp_rt_opts)
for (i = 0; i < def->numberPorts; i++) {
struct pp_instance *ppi = INST(ppg, i);
if (def->slaveOnly && !ppi->slave_only)
if (def->slaveOnly && !(ppi->flags & PPI_FLAG_SLAVE_ONLY))
def->slaveOnly = 0;
ppi->state = PPS_INITIALIZING;
......
......@@ -68,7 +68,7 @@ int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
msg_pack_header(ppi, ppi->tx_ptp); /* This is used for all tx */
if (!ppi->master_only)
if (!(ppi->flags & PPI_FLAG_MASTER_ONLY))
ppi->next_state = PPS_LISTENING;
else
ppi->next_state = PPS_MASTER;
......
......@@ -98,7 +98,7 @@ int pp_master(struct pp_instance *ppi, unsigned char *pkt, int plen)
out:
if (e == 0) {
if (DSDEF(ppi)->clockQuality.clockClass == PP_CLASS_SLAVE_ONLY
|| ppi->slave_only)
|| (ppi->flags & PPI_FLAG_SLAVE_ONLY))
ppi->next_state = PPS_LISTENING;
} else {
ppi->next_state = PPS_FAULTY;
......
......@@ -24,7 +24,7 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
if (e)
goto out;
ppi->waiting_for_follow = FALSE;
ppi->flags &= ~PPI_FLAG_WAITING_FOR_F_UP;
pp_timeout_restart_annrec(ppi);
......@@ -69,7 +69,7 @@ int pp_slave(struct pp_instance *ppi, unsigned char *pkt, int plen)
hdr->sequenceId) &&
(DSPOR(ppi)->portIdentity.portNumber ==
resp.requestingPortIdentity.portNumber)
&& ppi->is_from_cur_par) {
&& (ppi->flags & PPI_FLAG_FROM_CURRENT_PARENT)) {
to_TimeInternal(&ppi->t4, &resp.receiveTimestamp);
......
......@@ -63,7 +63,7 @@ static int bare_open_ch(struct pp_instance *ppi, char *ifname)
struct bare_packet_mreq pmr;
char *context;
if (ppi->ethernet_mode) {
if (ppi->flags & PPI_FLAG_RAW_PROTO) {
/* open socket */
context = "socket()";
sock = sys_socket(PF_PACKET, SOCK_RAW, ETH_P_1588);
......@@ -141,7 +141,7 @@ static int bare_net_init(struct pp_instance *ppi)
/* The buffer is inside ppi, but we need to set pointers and align */
pp_prepare_pointers(ppi);
if (ppi->ethernet_mode) {
if (ppi->flags & PPI_FLAG_RAW_PROTO) {
pp_diag(ppi, frames, 1, "bare_net_init IEEE 802.3\n");
/* raw sockets implementation always use gen socket */
......
......@@ -106,7 +106,7 @@ static int unix_net_recv(struct pp_instance *ppi, void *pkt, int len,
struct pp_channel *ch1, *ch2;
int ret;
if (ppi->ethernet_mode) {
if (ppi->flags & PPI_FLAG_RAW_PROTO) {
int fd = NP(ppi)->ch[PP_NP_GEN].fd;
ret = unix_recv_msg(ppi, fd, pkt, len, t);
......@@ -146,7 +146,7 @@ static int unix_net_send(struct pp_instance *ppi, void *pkt, int len,
return len;
}
if (ppi->ethernet_mode) {
if (ppi->flags & PPI_FLAG_RAW_PROTO) {
hdr->h_proto = htons(ETH_P_1588);
memcpy(hdr->h_dest, PP_MCAST_MACADDRESS, ETH_ALEN);
......@@ -193,7 +193,7 @@ static int unix_open_ch(struct pp_instance *ppi, char *ifname, int chtype)
char addr_str[INET_ADDRSTRLEN];
char *context;
if (ppi->ethernet_mode) {
if (ppi->flags & PPI_FLAG_RAW_PROTO) {
/* open socket */
context = "socket()";
sock = socket(PF_PACKET, SOCK_RAW, ETH_P_1588);
......@@ -359,7 +359,7 @@ static int unix_net_init(struct pp_instance *ppi)
/* The buffer is inside ppi, but we need to set pointers and align */
pp_prepare_pointers(ppi);
if (ppi->ethernet_mode) {
if (ppi->flags & PPI_FLAG_RAW_PROTO) {
pp_diag(ppi, frames, 1, "unix_net_init IEEE 802.3\n");
/* raw sockets implementation always use gen socket */
......@@ -385,7 +385,7 @@ static int unix_net_exit(struct pp_instance *ppi)
int fd;
int i;
if (ppi->ethernet_mode) {
if (ppi->flags & PPI_FLAG_RAW_PROTO) {
fd = NP(ppi)->ch[PP_NP_GEN].fd;
if (fd > 0) {
close(fd);
......
......@@ -248,7 +248,7 @@ int wrs_net_recv(struct pp_instance *ppi, void *pkt, int len,
struct pp_channel *ch1, *ch2;
int ret = -1;
if (ppi->ethernet_mode) {
if (ppi->flags & PPI_FLAG_RAW_PROTO) {
int fd = NP(ppi)->ch[PP_NP_GEN].fd;
ret = wrs_recv_msg(ppi, fd, pkt, len, t);
......@@ -317,7 +317,7 @@ static void poll_tx_timestamp(struct pp_instance *ppi,
* a tx timestamp. Udp doesn't so don't check in udp mode
* (the pointer is only checked for non-null)
*/
if (!ppi->ethernet_mode)
if (!(ppi->flags & PPI_FLAG_RAW_PROTO))
serr = (void *)1;
for (cmsg = CMSG_FIRSTHDR(&msg);
......@@ -361,7 +361,7 @@ int wrs_net_send(struct pp_instance *ppi, void *pkt, int len,
*/
drop = ppsi_drop_tx();
if (ppi->ethernet_mode) {
if (ppi->flags & PPI_FLAG_RAW_PROTO) {
fd = NP(ppi)->ch[PP_NP_GEN].fd;
hdr->h_proto = htons(ETH_P_1588);
if (drop)
......
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