Commit e8c6d64c authored by Aurelio Colosimo's avatar Aurelio Colosimo

slave_only, master_only, iface_name and ethernet_mode defined as per-port cfg

Due to multilink needs, those variables are no more global but can be defined
as a different setting for each port. They will be set in a /etc/ppsi.conf file,
which is not yet handled, but will be soon.
struct pp_runtime_opts will contain only multiport settings.
If the /etc/ppsi.conf file is not found or not handled (like it is at present),
ppsi accepts and properly handles the same cmd line options as in the past.
Signed-off-by: Aurelio Colosimo's avatarAurelio Colosimo <aurelio@aureliocolosimo.it>
parent 7bdf7669
......@@ -24,7 +24,7 @@ void posix_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 (OPTS(ppi)->ethernet_mode)
if (ppi->ethernet_mode)
NP(ppi)->ptp_offset = ETH_HLEN;
/*
......
......@@ -96,7 +96,7 @@ static int posix_net_recv(struct pp_instance *ppi, void *pkt, int len,
struct pp_channel *ch1, *ch2;
int ret;
if (OPTS(ppi)->ethernet_mode) {
if (ppi->ethernet_mode) {
int fd = NP(ppi)->ch[PP_NP_GEN].fd;
ret = posix_recv_msg(ppi, fd, pkt, len, t);
......@@ -128,7 +128,7 @@ static int posix_net_send(struct pp_instance *ppi, void *pkt, int len,
struct ethhdr *hdr = pkt;
int ret;
if (OPTS(ppi)->ethernet_mode) {
if (ppi->ethernet_mode) {
hdr->h_proto = htons(ETH_P_1588);
memcpy(hdr->h_dest, PP_MCAST_MACADDRESS, ETH_ALEN);
......@@ -175,7 +175,7 @@ static int posix_open_ch(struct pp_instance *ppi, char *ifname, int chtype)
char addr_str[INET_ADDRSTRLEN];
char *context;
if (OPTS(ppi)->ethernet_mode) {
if (ppi->ethernet_mode) {
/* open socket */
context = "socket()";
sock = socket(PF_PACKET, SOCK_RAW, ETH_P_1588);
......@@ -340,17 +340,17 @@ int posix_net_init(struct pp_instance *ppi)
/* The buffer is inside ppi, but we need to set pointers and align */
pp_prepare_pointers(ppi);
if (OPTS(ppi)->ethernet_mode) {
if (ppi->ethernet_mode) {
PP_PRINTF("posix_net_init IEEE 802.3\n");
/* raw sockets implementation always use gen socket */
return posix_open_ch(ppi, OPTS(ppi)->iface_name, PP_NP_GEN);
return posix_open_ch(ppi, ppi->iface_name, PP_NP_GEN);
}
/* else: UDP */
PP_PRINTF("posix_net_init UDP\n");
for (i = PP_NP_GEN; i <= PP_NP_EVT; i++) {
if (posix_open_ch(ppi, OPTS(ppi)->iface_name, i))
if (posix_open_ch(ppi, ppi->iface_name, i))
return -1;
}
return 0;
......@@ -365,7 +365,7 @@ static int posix_net_exit(struct pp_instance *ppi)
int fd;
int i;
if (OPTS(ppi)->ethernet_mode) {
if (ppi->ethernet_mode) {
close(NP(ppi)->ch[PP_NP_GEN].fd);
return 0;
}
......@@ -412,7 +412,7 @@ int posix_net_check_pkt(struct pp_instance *ppi, int delay_ms)
NP(ppi)->ch[PP_NP_GEN].pkt_present = 0;
NP(ppi)->ch[PP_NP_EVT].pkt_present = 0;
if (OPTS(ppi)->ethernet_mode) {
if (ppi->ethernet_mode) {
maxfd = NP(ppi)->ch[PP_NP_GEN].fd;
FD_ZERO(&set);
FD_SET(NP(ppi)->ch[PP_NP_GEN].fd, &set);
......
......@@ -74,19 +74,18 @@ int main(int argc, char **argv)
|| (!GLBS(ppi)->frgn_master) || (!ppi->arch_data)
)
exit(__LINE__);
}
/* FIXME temporary workaround to make the first interface work as in the past */
if (ppg->nports == 1) {
struct pp_instance *ppi = &ppg->pp_instances[0];
ppi->iface_name = strdup(ifname);
ppi->ethernet_mode = PP_DEFAULT_ETHERNET_MODE;
pp_open_instance(ppi, NULL);
/* FIXME temporary workaround to make the first interface work as in the past */
if (i == 0)
OPTS(ppi)->iface_name = strdup(ifname);
if (pp_parse_cmdline(ppi, argc, argv) != 0)
return -1;
}
/* FIXME temporary workaround: pp_parse_cmdline will receive ppg */
if (pp_parse_cmdline(&ppg->pp_instances[0], argc, argv) != 0)
return -1;
posix_main_loop(ppg);
return 0; /* never reached */
}
......@@ -88,8 +88,8 @@ int wrc_ptp_set_mode(int mode)
case WRC_MODE_GM:
/* FIXME multiport rtOpts.primarySource = TRUE; */
WR_DSPOR(ppi)->wrConfig = WR_M_ONLY;
OPTS(ppi)->master_only = TRUE;
OPTS(ppi)->slave_only = FALSE;
ppi->master_only = TRUE;
ppi->slave_only = FALSE;
spll_init(SPLL_MODE_GRAND_MASTER, 0, 1);
lock_timeout = LOCK_TIMEOUT_GM;
break;
......@@ -97,8 +97,8 @@ int wrc_ptp_set_mode(int mode)
case WRC_MODE_MASTER:
/* FIXME multiport rtOpts.primarySource = FALSE; */
WR_DSPOR(ppi)->wrConfig = WR_M_ONLY;
OPTS(ppi)->master_only = TRUE;
OPTS(ppi)->slave_only = FALSE;
ppi->master_only = TRUE;
ppi->slave_only = FALSE;
spll_init(SPLL_MODE_FREE_RUNNING_MASTER, 0, 1);
lock_timeout = LOCK_TIMEOUT_FM;
break;
......@@ -106,8 +106,8 @@ int wrc_ptp_set_mode(int mode)
case WRC_MODE_SLAVE:
/* FIXME multiport rtOpts.primarySource = FALSE; */
WR_DSPOR(ppi)->wrConfig = WR_S_ONLY;
OPTS(ppi)->master_only = FALSE;
OPTS(ppi)->slave_only = TRUE;
ppi->master_only = FALSE;
ppi->slave_only = TRUE;
spll_init(SPLL_MODE_SLAVE, 0, 1);
break;
}
......
......@@ -15,7 +15,7 @@ static int wrpc_read_calibration_data(struct pp_instance *ppi,
{
hexp_port_state_t state;
halexp_get_port_state(&state, OPTS(ppi)->iface_name);
halexp_get_port_state(&state, ppi->iface_name);
// check if the data is available
if(state.valid)
......
......@@ -22,7 +22,7 @@ void __pp_diag(struct pp_instance *ppi, enum pp_diag_things th,
if (!__PP_DIAG_ALLOW(ppi, th, level))
return;
pp_printf("%s-%i-%s: ", thing_name[th], level, OPTS(ppi)->iface_name);
pp_printf("%s-%i-%s: ", thing_name[th], level, ppi->iface_name);
va_start(args, fmt);
pp_vprintf(fmt, args);
va_end(args);
......
......@@ -24,7 +24,7 @@ static void pp_fsm_printf(struct pp_instance *ppi, char *fmt, ...)
ppi->t_ops->get(ppi, &t);
pp_global_flags = oflags;
pp_printf("diag-fsm-1-%s: %09d.%03d: ", OPTS(ppi)->iface_name,
pp_printf("diag-fsm-1-%s: %09d.%03d: ", ppi->iface_name,
(int)t.seconds, (int)t.nanoseconds / 1000000);
va_start(args, fmt);
pp_vprintf(fmt, args);
......@@ -110,7 +110,7 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
err = ip->f1(ppi, packet, plen);
if (err)
pp_printf("fsm for %s: Error %i in %s\n",
OPTS(ppi)->iface_name, err, ip->name);
ppi->iface_name, err, ip->name);
/* done: if new state mark it, and enter it now (0 ms) */
if (ppi->state != ppi->next_state) {
......@@ -126,6 +126,6 @@ int pp_state_machine(struct pp_instance *ppi, uint8_t *packet, int plen)
return ppi->next_delay;
}
/* Unknwon state, can't happen */
pp_printf("fsm: Unknown state for iface %s\n", OPTS(ppi)->iface_name);
pp_printf("fsm: Unknown state for iface %s\n", ppi->iface_name);
return 10000; /* No way out. Repeat message every 10s */
}
......@@ -20,10 +20,10 @@ struct pp_runtime_opts {
Integer32 max_rst; /* Maximum number of nanoseconds to reset */
Integer32 max_dly; /* Maximum number of nanoseconds of delay */
Integer32 ttl;
UInteger32 slave_only:1,
master_only:1,
UInteger32 /* slave_only:1, -- moved to ppsi, is no more global */
/* master_only:1, -- moved to ppsi, is no more global */
no_adjust:1,
ethernet_mode:1,
/* ethernet_mode:1, -- moved to ppsi, is no more global */
/* e2e_mode:1, -- no more: we only support e2e */
/* gptp_mode:1, -- no more: peer-to-peer unsupported */
ofst_first_updated:1,
......@@ -35,7 +35,6 @@ struct pp_runtime_opts {
UInteger8 prio1;
UInteger8 prio2;
UInteger8 domain_number;
char *iface_name;
void *arch_opts;
};
extern struct pp_runtime_opts default_rt_opts; /* preinited with defaults */
......@@ -171,7 +170,11 @@ struct pp_instance {
MsgHeader delay_req_hdr;
UInteger32
is_from_cur_par:1,
waiting_for_follow:1;
waiting_for_follow:1,
slave_only:1,
master_only:1,
ethernet_mode:1;
char *iface_name;
};
/*
......
......@@ -60,7 +60,7 @@ static int bare_open_ch(struct pp_instance *ppi, char *ifname)
struct bare_packet_mreq pmr;
char *context;
if (OPTS(ppi)->ethernet_mode) {
if (ppi->ethernet_mode) {
/* open socket */
context = "socket()";
sock = sys_socket(PF_PACKET, SOCK_RAW, ETH_P_1588);
......@@ -138,11 +138,11 @@ 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 (OPTS(ppi)->ethernet_mode) {
if (ppi->ethernet_mode) {
PP_PRINTF("bare_net_init IEEE 802.3\n");
/* raw sockets implementation always use gen socket */
return bare_open_ch(ppi, OPTS(ppi)->iface_name);
return bare_open_ch(ppi, ppi->iface_name);
}
/* else: UDP -- not supported */
......
......@@ -49,11 +49,12 @@ int ppsi_main(int argc, char **argv)
ppi->n_ops = &bare_net_ops;
ppi->t_ops = &bare_time_ops;
ppi->ethernet_mode = PP_DEFAULT_ETHERNET_MODE;
ppi->iface_name = "eth0";
/* This just llocates the stuff */
pp_open_instance(ppi, NULL);
OPTS(ppi)->iface_name = "eth0";
if (pp_parse_cmdline(ppi, argc, argv) != 0)
return -1;
......
......@@ -149,7 +149,7 @@ int pp_parse_cmdline(struct pp_instance *ppi, int argc, char **argv)
break;
case 'b':
a = argv[++i];
OPTS(ppi)->iface_name = a;
ppi->iface_name = a;
break;
case 'l':
a = argv[++i];
......@@ -175,7 +175,7 @@ int pp_parse_cmdline(struct pp_instance *ppi, int argc, char **argv)
OPTS(ppi)->announce_intvl = 4;
break;
case 'g':
OPTS(ppi)->slave_only = 1;
ppi->slave_only = 1;
break;
case 'v':
a = argv[++i];
......@@ -204,7 +204,7 @@ int pp_parse_cmdline(struct pp_instance *ppi, int argc, char **argv)
/* ignored: was "OPTS(ppi)->e2e_mode = 1;" */
break;
case 'e':
OPTS(ppi)->ethernet_mode = 1;
ppi->ethernet_mode = 1;
break;
case 'G':
/* gptp_mode not supported: fall through */
......
......@@ -22,7 +22,7 @@ static int wr_open(struct pp_instance *ppi, struct pp_runtime_opts *rt_opts)
{
static struct wr_data_t wr_data; /* WR-specific global data */
rt_opts->iface_name = "wr1";
ppi->iface_name = "wr1";
ppi->ext_data = &wr_data;
return 0;
}
......
......@@ -177,10 +177,10 @@ static int bmc_state_decision(struct pp_instance *ppi, struct pp_frgn_master *m)
int cmpres;
struct pp_frgn_master myself;
if (OPTS(ppi)->master_only)
if (ppi->master_only)
goto master;
if (OPTS(ppi)->slave_only)
if (ppi->slave_only)
goto slave;
if ((!GLBS(ppi)->frgn_rec_num) && (ppi->state == PPS_LISTENING))
......
......@@ -25,7 +25,6 @@ struct pp_runtime_opts default_rt_opts = {
.ap = PP_DEFAULT_AP,
.ai = PP_DEFAULT_AI,
.s = PP_DEFAULT_DELAY_S,
.ethernet_mode = PP_DEFAULT_ETHERNET_MODE,
.ofst_first_updated = 0, /* FIXME: is it a option or a state var? */
.announce_intvl = PP_DEFAULT_ANNOUNCE_INTERVAL,
.sync_intvl = PP_DEFAULT_SYNC_INTERVAL,
......
......@@ -41,8 +41,8 @@ int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
def->priority1 = opt->prio1;
def->priority2 = opt->prio2;
def->domainNumber = opt->domain_number;
def->slaveOnly = opt->slave_only;
if (opt->slave_only)
def->slaveOnly = ppi->slave_only;
if (def->slaveOnly)
def->clockQuality.clockClass = 255;
/*
......@@ -74,7 +74,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 (!opt->master_only)
if (!ppi->master_only)
ppi->next_state = PPS_LISTENING;
else
ppi->next_state = PPS_MASTER;
......
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