Commit 996e152b authored by Alessandro Rubini's avatar Alessandro Rubini

general: proto and role are now separate pp fields

This paves the way to the addition of a third protocol. Besides the
code is slightly smaller (around 50 bytes on all archs).
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 7850f87a
......@@ -6,8 +6,8 @@
#Warning "Please include <ppsi/constants.h> before <arch/constants.h>"
#endif
#undef PP_DEFAULT_PPI_FLAGS
#define PP_DEFAULT_PPI_FLAGS PPI_FLAG_RAW_PROTO /* We only use raw ethernet */
#undef PP_DEFAULT_PROTO
#define PP_DEFAULT_PROTO PPSI_PROTO_RAW /* 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_PPI_FLAGS
#define PP_DEFAULT_PPI_FLAGS PPI_FLAG_RAW_PROTO /* We only use raw ethernet */
#undef PP_DEFAULT_PROTO
#define PP_DEFAULT_PROTO PPSI_PROTO_RAW /* We only use raw ethernet */
#endif /* __PPSI_ARCH_CONSTANTS_H__ */
......@@ -57,6 +57,7 @@ int sim_set_global_DS(struct pp_instance *ppi)
static int sim_ppi_init(struct pp_instance *ppi, int which_ppi)
{
struct sim_ppi_arch_data *data;
ppi->proto = PP_DEFAULT_PROTO;
ppi->arch_data = calloc(1, sizeof(struct sim_ppi_arch_data));
ppi->portDS = calloc(1, sizeof(*ppi->portDS));
if ((!ppi->arch_data) || (!ppi->portDS))
......@@ -144,11 +145,7 @@ int main(int argc, char **argv)
"ethernet. Using UDP\n");
NP(ppi)->ch[PP_NP_GEN].fd = -1;
NP(ppi)->ch[PP_NP_EVT].fd = -1;
if (ppi->cfg.role == PPSI_ROLE_MASTER) {
ppi->flags |= PPI_FLAG_MASTER_ONLY;
} else if (ppi->cfg.role == PPSI_ROLE_SLAVE) {
ppi->flags |= PPI_FLAG_SLAVE_ONLY;
}
ppi->role = ppi->cfg.role;
ppi->t_ops = &DEFAULT_TIME_OPS;
ppi->n_ops = &DEFAULT_NET_OPS;
if (pp_sim_is_master(ppi))
......
......@@ -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->flags & PPI_FLAG_RAW_PROTO)
if (ppi->proto == PPSI_PROTO_RAW)
NP(ppi)->ptp_offset = ETH_HLEN;
/*
......
......@@ -55,6 +55,11 @@ int main(int argc, char **argv)
ppg->max_links = PP_MAX_LINKS;
ppg->arch_data = calloc(1, sizeof(struct unix_arch_data));
ppg->pp_instances = calloc(ppg->max_links, sizeof(struct pp_instance));
for (i = 0; i < ppg->max_links; i++) {
ppi = INST(ppg, i);
ppi->proto = PP_DEFAULT_PROTO;
ppi->role = PP_DEFAULT_ROLE;
}
if ((!ppg->arch_data) || (!ppg->pp_instances))
exit(__LINE__);
......@@ -82,14 +87,8 @@ 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 */
if (ppi->cfg.proto == PPSI_PROTO_RAW)
ppi->flags |= PPI_FLAG_RAW_PROTO;
if (ppi->cfg.role == PPSI_ROLE_MASTER) {
ppi->flags |= PPI_FLAG_MASTER_ONLY;
}
else if (ppi->cfg.role == PPSI_ROLE_SLAVE) {
ppi->flags |= PPI_FLAG_SLAVE_ONLY;
}
ppi->proto = ppi->cfg.proto;
ppi->role = ppi->cfg.role;
/* 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_PPI_FLAGS
#define PP_DEFAULT_PPI_FLAGS PPI_FLAG_RAW_PROTO /* We only use raw ethernet */
#undef PP_DEFAULT_PROTO
#define PP_DEFAULT_PROTO PPSI_PROTO_RAW /* We only use raw ethernet */
#endif /* __PPSI_ARCH_CONSTANTS_H__ */
......@@ -74,6 +74,7 @@ struct pp_instance ppi_static = {
.portDS = &portDS,
.n_ops = &wrpc_net_ops,
.t_ops = &wrpc_time_ops,
.proto = PP_DEFAULT_PROTO,
.iface_name = "wr1",
.port_name = "wr1",
};
......@@ -124,8 +125,7 @@ int wrc_ptp_set_mode(int mode)
switch (mode) {
case WRC_MODE_GM:
wrp->wrConfig = WR_M_ONLY;
ppi->flags |= PPI_FLAG_MASTER_ONLY;
ppi->flags &= ~PPI_FLAG_SLAVE_ONLY;
ppi->role = PPSI_ROLE_MASTER;
*class_ptr = PP_CLASS_WR_GM_LOCKED;
spll_init(SPLL_MODE_GRAND_MASTER, 0, 1);
lock_timeout = LOCK_TIMEOUT_GM;
......@@ -133,8 +133,7 @@ int wrc_ptp_set_mode(int mode)
case WRC_MODE_MASTER:
wrp->wrConfig = WR_M_ONLY;
ppi->flags |= PPI_FLAG_MASTER_ONLY;
ppi->flags &= ~PPI_FLAG_SLAVE_ONLY;
ppi->role = PPSI_ROLE_MASTER;
*class_ptr = PP_CLASS_DEFAULT;
spll_init(SPLL_MODE_FREE_RUNNING_MASTER, 0, 1);
lock_timeout = LOCK_TIMEOUT_FM;
......@@ -142,8 +141,7 @@ int wrc_ptp_set_mode(int mode)
case WRC_MODE_SLAVE:
wrp->wrConfig = WR_S_ONLY;
ppi->flags |= PPI_FLAG_SLAVE_ONLY;
ppi->flags &= ~PPI_FLAG_MASTER_ONLY;
ppi->role = PPSI_ROLE_SLAVE;
*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->flags & PPI_FLAG_RAW_PROTO)
if (ppi->proto == PPSI_PROTO_RAW)
NP(ppi)->ptp_offset = ETH_HLEN;
/*
......
......@@ -155,16 +155,8 @@ int main(int argc, char **argv)
ppi->glbs = ppg;
ppi->iface_name = ppi->cfg.iface_name;
ppi->port_name = ppi->cfg.port_name;
/* this old-fashioned "ethernet_mode" is a single bit */
if (ppi->cfg.proto == PPSI_PROTO_RAW)
ppi->flags |= PPI_FLAG_RAW_PROTO;
if (ppi->cfg.role == PPSI_ROLE_MASTER) {
ppi->flags |= PPI_FLAG_MASTER_ONLY;
}
else if (ppi->cfg.role == PPSI_ROLE_SLAVE) {
ppi->flags |= PPI_FLAG_SLAVE_ONLY;
}
ppi->proto = ppi->cfg.proto;
ppi->role = ppi->cfg.role;
ppi->portDS = calloc(1, sizeof(*ppi->portDS));
if (!ppi->portDS)
exit(__LINE__);
......
......@@ -20,6 +20,8 @@
#define PP_DEFAULT_INBOUND_LATENCY 0 /* in nsec */
#define PP_DEFAULT_OUTBOUND_LATENCY 0 /* in nsec */
#define PP_DEFAULT_FLAGS 0
#define PP_DEFAULT_ROLE PPSI_ROLE_AUTO
#define PP_DEFAULT_PROTO PPSI_PROTO_UDP /* overridden by arch */
#define PP_DEFAULT_DOMAIN_NUMBER 0
#define PP_DEFAULT_AP 10
#define PP_DEFAULT_AI 1000
......
......@@ -141,7 +141,9 @@ 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) */
unsigned char flags, /* protocol flags (see below) */
role, /* same as in config file */
proto; /* same as in config file */
/* Pointer to global instance owning this pp_instance*/
struct pp_globals *glbs;
......@@ -189,12 +191,9 @@ struct pp_instance {
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
/* The following things used to be bit fields. Other flags are now enums */
#define PPI_FLAG_FROM_CURRENT_PARENT 0x01
#define PPI_FLAG_WAITING_FOR_F_UP 0x02
struct pp_globals_cfg {
......
......@@ -39,7 +39,7 @@ static struct pp_instance ppi_static = {
.t_ops = &bare_time_ops,
.iface_name = "eth0",
.port_name = "eth0",
.flags = PP_DEFAULT_PPI_FLAGS,
.proto = PP_DEFAULT_PROTO,
};
/* 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)->flags |= PPI_FLAG_SLAVE_ONLY;
INST(ppg, j)->role = PPSI_ROLE_SLAVE;
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)->flags |= PPI_FLAG_RAW_PROTO;
INST(ppg, j)->proto = PPSI_PROTO_RAW;
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->flags & PPI_FLAG_MASTER_ONLY)
if (ppi->role == PPSI_ROLE_MASTER)
goto master;
if (ppi->flags & PPI_FLAG_SLAVE_ONLY)
if (ppi->role == PPSI_ROLE_SLAVE)
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->flags & PPI_FLAG_SLAVE_ONLY)) {
&& (ppi->role != PPSI_ROLE_SLAVE)) {
m1(ppi);
ppi->next_state = PPS_MASTER;
} else {
......
......@@ -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)->flags & PPI_FLAG_SLAVE_ONLY);
def->slaveOnly = (INST(ppg, 0)->role == PPSI_ROLE_SLAVE);
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->flags & PPI_FLAG_SLAVE_ONLY))
if (def->slaveOnly && ppi->role != PPSI_ROLE_SLAVE)
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->flags & PPI_FLAG_MASTER_ONLY))
if (ppi->role != PPSI_ROLE_MASTER)
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->flags & PPI_FLAG_SLAVE_ONLY))
|| (ppi->role == PPSI_ROLE_SLAVE))
ppi->next_state = PPS_LISTENING;
} else {
ppi->next_state = PPS_FAULTY;
......
......@@ -63,7 +63,7 @@ static int bare_open_ch(struct pp_instance *ppi, char *ifname)
struct bare_packet_mreq pmr;
char *context;
if (ppi->flags & PPI_FLAG_RAW_PROTO) {
if (ppi->proto == PPSI_PROTO_RAW) {
/* 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->flags & PPI_FLAG_RAW_PROTO) {
if (ppi->proto == PPSI_PROTO_RAW) {
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->flags & PPI_FLAG_RAW_PROTO) {
if (ppi->proto == PPSI_PROTO_RAW) {
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->flags & PPI_FLAG_RAW_PROTO) {
if (ppi->proto == PPSI_PROTO_RAW) {
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->flags & PPI_FLAG_RAW_PROTO) {
if (ppi->proto == PPSI_PROTO_RAW) {
/* 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->flags & PPI_FLAG_RAW_PROTO) {
if (ppi->proto == PPSI_PROTO_RAW) {
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->flags & PPI_FLAG_RAW_PROTO) {
if (ppi->proto == PPSI_PROTO_RAW) {
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->flags & PPI_FLAG_RAW_PROTO) {
if (ppi->proto == PPSI_PROTO_RAW) {
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->flags & PPI_FLAG_RAW_PROTO))
if (!(ppi->proto == PPSI_PROTO_RAW))
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->flags & PPI_FLAG_RAW_PROTO) {
if (ppi->proto == PPSI_PROTO_RAW) {
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