Commit 95fbc8d4 authored by Alessandro Rubini's avatar Alessandro Rubini

config: fold pp_link into pp_instance

This saves a few dozen bytes in wrpc-sw builds.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 095c3ef7
...@@ -38,7 +38,6 @@ int main(int argc, char **argv) ...@@ -38,7 +38,6 @@ int main(int argc, char **argv)
exit(__LINE__); exit(__LINE__);
ppg->max_links = PP_MAX_LINKS; ppg->max_links = PP_MAX_LINKS;
ppg->links = calloc(ppg->max_links, sizeof(struct pp_link));
ppg->defaultDS = calloc(1, sizeof(*ppg->defaultDS)); ppg->defaultDS = calloc(1, sizeof(*ppg->defaultDS));
ppg->currentDS = calloc(1, sizeof(*ppg->currentDS)); ppg->currentDS = calloc(1, sizeof(*ppg->currentDS));
ppg->parentDS = calloc(1, sizeof(*ppg->parentDS)); ppg->parentDS = calloc(1, sizeof(*ppg->parentDS));
...@@ -58,20 +57,18 @@ int main(int argc, char **argv) ...@@ -58,20 +57,18 @@ int main(int argc, char **argv)
for (i = 0; i < ppg->nlinks; i++) { for (i = 0; i < ppg->nlinks; i++) {
struct pp_link *lnk = &ppg->links[i];
ppi = &ppg->pp_instances[i]; ppi = &ppg->pp_instances[i];
NP(ppi)->ch[PP_NP_EVT].fd = -1; NP(ppi)->ch[PP_NP_EVT].fd = -1;
NP(ppi)->ch[PP_NP_GEN].fd = -1; NP(ppi)->ch[PP_NP_GEN].fd = -1;
ppi->glbs = ppg; ppi->glbs = ppg;
ppi->iface_name = lnk->iface_name; ppi->iface_name = ppi->cfg.iface_name;
ppi->ethernet_mode = (lnk->proto == 0) ? 1 : 0; ppi->ethernet_mode = (ppi->cfg.proto == 0) ? 1 : 0;
if (lnk->role == 1) { if (ppi->cfg.role == 1) {
ppi->master_only = 1; ppi->master_only = 1;
ppi->slave_only = 0; ppi->slave_only = 0;
} }
else if (lnk->role == 2) { else if (ppi->cfg.role == 2) {
ppi->master_only = 0; ppi->master_only = 0;
ppi->slave_only = 1; ppi->slave_only = 1;
} }
......
...@@ -58,7 +58,6 @@ int main(int argc, char **argv) ...@@ -58,7 +58,6 @@ int main(int argc, char **argv)
exit(__LINE__); exit(__LINE__);
ppg->max_links = PP_MAX_LINKS; ppg->max_links = PP_MAX_LINKS;
ppg->links = calloc(ppg->max_links, sizeof(struct pp_link));
ppg->defaultDS = calloc(1, sizeof(*ppg->defaultDS)); ppg->defaultDS = calloc(1, sizeof(*ppg->defaultDS));
ppg->currentDS = calloc(1, sizeof(*ppg->currentDS)); ppg->currentDS = calloc(1, sizeof(*ppg->currentDS));
ppg->parentDS = calloc(1, sizeof(*ppg->parentDS)); ppg->parentDS = calloc(1, sizeof(*ppg->parentDS));
...@@ -78,20 +77,18 @@ int main(int argc, char **argv) ...@@ -78,20 +77,18 @@ int main(int argc, char **argv)
for (i = 0; i < ppg->nlinks; i++) { for (i = 0; i < ppg->nlinks; i++) {
struct pp_link *lnk = &ppg->links[i];
ppi = &ppg->pp_instances[i]; ppi = &ppg->pp_instances[i];
NP(ppi)->ch[PP_NP_EVT].fd = -1; NP(ppi)->ch[PP_NP_EVT].fd = -1;
NP(ppi)->ch[PP_NP_GEN].fd = -1; NP(ppi)->ch[PP_NP_GEN].fd = -1;
ppi->glbs = ppg; ppi->glbs = ppg;
ppi->iface_name = lnk->iface_name; ppi->iface_name = ppi->cfg.iface_name;
ppi->ethernet_mode = (lnk->proto == 0) ? 1 : 0; ppi->ethernet_mode = (ppi->cfg.proto == 0) ? 1 : 0;
if (lnk->role == 1) { if (ppi->cfg.role == 1) {
ppi->master_only = 1; ppi->master_only = 1;
ppi->slave_only = 0; ppi->slave_only = 0;
} }
else if (lnk->role == 2) { else if (ppi->cfg.role == 2) {
ppi->master_only = 0; ppi->master_only = 0;
ppi->slave_only = 1; ppi->slave_only = 1;
} }
......
...@@ -108,6 +108,18 @@ struct pp_net_path { ...@@ -108,6 +108,18 @@ struct pp_net_path {
int ptp_offset; int ptp_offset;
}; };
/*
* Struct containg the result of ppsi.conf parsing: one for each link
* (see lib/conf.c)
*/
struct pp_instance_cfg {
char link_name[16];
char iface_name[16];
int proto; /* 0: raw, 1: udp */
int role; /* 0: auto, 1: master, 2: slave */
int ext; /* 0: none, 1: whiterabbit */ /* FIXME extension enumeration */
};
/* /*
* Structure for the individual ppsi link * Structure for the individual ppsi link
*/ */
...@@ -167,20 +179,11 @@ struct pp_instance { ...@@ -167,20 +179,11 @@ struct pp_instance {
ethernet_mode:1; ethernet_mode:1;
char *iface_name; char *iface_name;
int port_idx; int port_idx;
};
/* struct pp_instance_cfg cfg;
* Struct containg the result of ppsi.conf parsing: one for each link
* (see lib/conf.c)
*/
struct pp_link {
char link_name[16];
char iface_name[16];
int proto; /* 0: raw, 1: udp */
int role; /* 0: auto, 1: master, 2: slave */
int ext; /* 0: none, 1: whiterabbit */ /* FIXME extension enumeration */
}; };
/* /*
* Structure for the multi-port ppsi instance. * Structure for the multi-port ppsi instance.
*/ */
...@@ -204,7 +207,6 @@ struct pp_globals { ...@@ -204,7 +207,6 @@ struct pp_globals {
int nlinks; int nlinks;
int max_links; int max_links;
struct pp_link *links;
void *arch_data; /* if arch needs it */ void *arch_data; /* if arch needs it */
/* FIXME Here include all is common to many interfaces */ /* FIXME Here include all is common to many interfaces */
......
...@@ -68,13 +68,15 @@ static int handle_link(struct pp_globals *ppg, char *val) ...@@ -68,13 +68,15 @@ static int handle_link(struct pp_globals *ppg, char *val)
pp_printf("ppsi: Too many links in config file\n"); pp_printf("ppsi: Too many links in config file\n");
exit(1); exit(1);
} }
strcpy(ppg->links[ppg->nlinks].link_name, val); /* FIXME check val len */ /* FIXME: strncpy (it is missing in bare archs by now) */
strcpy(ppg->pp_instances[ppg->nlinks].cfg.link_name, val);
return 1; return 1;
} }
static int handle_iface(struct pp_globals *ppg, char *val) static int handle_iface(struct pp_globals *ppg, char *val)
{ {
strcpy(ppg->links[ppg->nlinks].iface_name, val); /* FIXME check iface len */ /* FIXME: strncpy (it is missing in bare archs by now) */
strcpy(ppg->pp_instances[ppg->nlinks].iface_name, val);
return 1; return 1;
} }
...@@ -98,7 +100,8 @@ static int handle_proto(struct pp_globals *ppg, char *val) ...@@ -98,7 +100,8 @@ static int handle_proto(struct pp_globals *ppg, char *val)
switch(v_id) { switch(v_id) {
case KW_RAW: case KW_RAW:
case KW_UDP: case KW_UDP:
ppg->links[ppg->nlinks].proto = v_id - KW_RAW; ppg->pp_instances[ppg->nlinks].cfg.proto
= v_id - KW_RAW;
break; break;
default: default:
return 0; return 0;
...@@ -115,7 +118,8 @@ static int handle_role(struct pp_globals *ppg, char *val) ...@@ -115,7 +118,8 @@ static int handle_role(struct pp_globals *ppg, char *val)
case KW_AUTO: case KW_AUTO:
case KW_MASTER: case KW_MASTER:
case KW_SLAVE: case KW_SLAVE:
ppg->links[ppg->nlinks].role = v_id - KW_AUTO; ppg->pp_instances[ppg->nlinks].cfg.role
= v_id - KW_AUTO;
break; break;
default: default:
return 0; return 0;
...@@ -131,7 +135,8 @@ static int handle_ext(struct pp_globals *ppg, char *val) ...@@ -131,7 +135,8 @@ static int handle_ext(struct pp_globals *ppg, char *val)
switch(v_id) { switch(v_id) {
case KW_NONE: case KW_NONE:
case KW_WHITERAB: case KW_WHITERAB:
ppg->links[ppg->nlinks].ext = v_id - KW_NONE; ppg->pp_instances[ppg->nlinks].cfg.ext
= v_id - KW_NONE;
break; break;
default: default:
return 0; return 0;
...@@ -174,7 +179,6 @@ static int pp_parse_conf(struct pp_globals *ppg, char *conf, int len) ...@@ -174,7 +179,6 @@ static int pp_parse_conf(struct pp_globals *ppg, char *conf, int len)
/* ppg->nlinks is initialized to -1 and increased at first link found, /* ppg->nlinks is initialized to -1 and increased at first link found,
* so that we can use it as array index */ * so that we can use it as array index */
ppg->nlinks = -1; ppg->nlinks = -1;
memset(ppg->links, 0, ppg->max_links * sizeof(struct pp_link));
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
c = conf[i]; c = conf[i];
......
...@@ -31,15 +31,14 @@ static int wr_open(struct pp_globals *ppg, struct pp_runtime_opts *rt_opts) ...@@ -31,15 +31,14 @@ static int wr_open(struct pp_globals *ppg, struct pp_runtime_opts *rt_opts)
} }
for (i = 0; i < ppg->nlinks; i++) { for (i = 0; i < ppg->nlinks; i++) {
struct pp_link *lnk = &ppg->links[i];
struct pp_instance *ppi = &ppg->pp_instances[i]; struct pp_instance *ppi = &ppg->pp_instances[i];
/* FIXME check if correct: assign to each instance the same /* FIXME check if correct: assign to each instance the same
* wr_data. May I move it to pp_globals? */ * wr_data. May I move it to pp_globals? */
ppg->pp_instances[i].ext_data = &wr_data; ppg->pp_instances[i].ext_data = &wr_data;
if (lnk->ext) { if (ppi->cfg.ext) {
switch (lnk->role) { switch (ppi->cfg.role) {
case 1: case 1:
WR_DSPOR(ppi)->wrConfig = WR_M_ONLY; WR_DSPOR(ppi)->wrConfig = WR_M_ONLY;
break; break;
......
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