Commit 82de2e3a authored by Alessandro Rubini's avatar Alessandro Rubini

general: network operations are now per-instance

This commit moves the network operations inside the instance.  It
allows to have different operations for each instance, which will be
useful in the future. For example, one ethernet card may have hardware
timestamping and another may not.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 4220b51a
...@@ -50,7 +50,7 @@ void posix_main_loop(struct pp_instance *ppi) ...@@ -50,7 +50,7 @@ void posix_main_loop(struct pp_instance *ppi)
* We got a packet. If it's not ours, continue consuming * We got a packet. If it's not ours, continue consuming
* the pending timeout * the pending timeout
*/ */
i = pp_net_ops.recv(ppi, payload, sizeof(packet) - 16, i = ppi->n_ops->recv(ppi, payload, sizeof(packet) - 16,
&ppi->last_rcv_time); &ppi->last_rcv_time);
ppi->last_rcv_time.seconds += DSPRO(ppi)->currentUtcOffset; ppi->last_rcv_time.seconds += DSPRO(ppi)->currentUtcOffset;
......
...@@ -475,7 +475,7 @@ int posix_net_check_pkt(struct pp_instance *ppi, int delay_ms) ...@@ -475,7 +475,7 @@ int posix_net_check_pkt(struct pp_instance *ppi, int delay_ms)
return ret; return ret;
} }
struct pp_network_operations pp_net_ops = { struct pp_network_operations posix_net_ops = {
.init = posix_net_init, .init = posix_net_init,
.exit = posix_net_exit, .exit = posix_net_exit,
.recv = posix_net_recv, .recv = posix_net_recv,
......
...@@ -46,6 +46,8 @@ int main(int argc, char **argv) ...@@ -46,6 +46,8 @@ int main(int argc, char **argv)
ppi->frgn_master = calloc(1, sizeof(*ppi->frgn_master)); ppi->frgn_master = calloc(1, sizeof(*ppi->frgn_master));
ppi->arch_data = calloc(1, sizeof(struct posix_arch_data)); ppi->arch_data = calloc(1, sizeof(struct posix_arch_data));
ppi->n_ops = &posix_net_ops;
if ((!ppi->defaultDS) || (!ppi->currentDS) || (!ppi->parentDS) if ((!ppi->defaultDS) || (!ppi->currentDS) || (!ppi->parentDS)
|| (!ppi->portDS) || (!ppi->timePropertiesDS) || (!ppi->portDS) || (!ppi->timePropertiesDS)
|| (!ppi->net_path) || (!ppi->frgn_master) || (!ppi->arch_data) || (!ppi->net_path) || (!ppi->frgn_master) || (!ppi->arch_data)
......
...@@ -15,3 +15,5 @@ struct posix_arch_data { ...@@ -15,3 +15,5 @@ struct posix_arch_data {
extern int posix_net_check_pkt(struct pp_instance *ppi, int delay_ms); extern int posix_net_check_pkt(struct pp_instance *ppi, int delay_ms);
extern void posix_main_loop(struct pp_instance *ppi); extern void posix_main_loop(struct pp_instance *ppi);
extern struct pp_network_operations posix_net_ops;
...@@ -122,7 +122,7 @@ static int wrpc_net_exit(struct pp_instance *ppi) ...@@ -122,7 +122,7 @@ static int wrpc_net_exit(struct pp_instance *ppi)
return 0; return 0;
} }
struct pp_network_operations pp_net_ops = { struct pp_network_operations wrpc_net_ops = {
.init = wrpc_net_init, .init = wrpc_net_init,
.exit = wrpc_net_exit, .exit = wrpc_net_exit,
.recv = wrpc_net_recv, .recv = wrpc_net_recv,
......
...@@ -149,6 +149,9 @@ struct pp_instance { ...@@ -149,6 +149,9 @@ struct pp_instance {
struct pp_servo *servo; struct pp_servo *servo;
unsigned long flags; /* ppi-specific flags (diag mainly) */ unsigned long flags; /* ppi-specific flags (diag mainly) */
/* Operations that may be different in each instance */
struct pp_network_operations *n_ops;
/* Data sets */ /* Data sets */
DSDefault *defaultDS; /* page 65 */ DSDefault *defaultDS; /* page 65 */
DSCurrent *currentDS; /* page 67 */ DSCurrent *currentDS; /* page 67 */
...@@ -277,8 +280,6 @@ struct pp_network_operations { ...@@ -277,8 +280,6 @@ struct pp_network_operations {
TimeInternal *t, int chtype, int use_pdelay_addr); TimeInternal *t, int chtype, int use_pdelay_addr);
}; };
extern struct pp_network_operations pp_net_ops;
/* /*
* Time operations, like network operations above, are encapsulated. * Time operations, like network operations above, are encapsulated.
......
...@@ -8,6 +8,8 @@ ...@@ -8,6 +8,8 @@
extern void bare_main_loop(struct pp_instance *ppi); extern void bare_main_loop(struct pp_instance *ppi);
extern struct pp_network_operations bare_net_ops;
/* syscalls */ /* syscalls */
struct bare_sockaddr; struct bare_sockaddr;
......
...@@ -146,7 +146,7 @@ static int bare_net_exit(struct pp_instance *ppi) ...@@ -146,7 +146,7 @@ static int bare_net_exit(struct pp_instance *ppi)
return sys_shutdown(NP(ppi)->ch[PP_NP_GEN].fd, SHUT_RDWR); return sys_shutdown(NP(ppi)->ch[PP_NP_GEN].fd, SHUT_RDWR);
} }
struct pp_network_operations pp_net_ops = { struct pp_network_operations bare_net_ops = {
.init = bare_net_init, .init = bare_net_init,
.exit = bare_net_exit, .exit = bare_net_exit,
.recv = bare_net_recv, .recv = bare_net_recv,
......
...@@ -48,6 +48,7 @@ int ppsi_main(int argc, char **argv) ...@@ -48,6 +48,7 @@ int ppsi_main(int argc, char **argv)
ppi->servo = &servo; ppi->servo = &servo;
ppi->frgn_master = &frgn_master; ppi->frgn_master = &frgn_master;
ppi->arch_data = NULL; ppi->arch_data = NULL;
ppi->n_ops = &bare_net_ops;
/* This just llocates the stuff */ /* This just llocates the stuff */
pp_open_instance(ppi, NULL); pp_open_instance(ppi, NULL);
......
...@@ -66,7 +66,7 @@ void bare_main_loop(struct pp_instance *ppi) ...@@ -66,7 +66,7 @@ void bare_main_loop(struct pp_instance *ppi)
* *
* FIXME: we don't know which socket to receive from * FIXME: we don't know which socket to receive from
*/ */
i = pp_net_ops.recv(ppi, payload, sizeof(packet) - 16, i = ppi->n_ops->recv(ppi, payload, sizeof(packet) - 16,
&ppi->last_rcv_time); &ppi->last_rcv_time);
ppi->last_rcv_time.seconds += DSPRO(ppi)->currentUtcOffset; ppi->last_rcv_time.seconds += DSPRO(ppi)->currentUtcOffset;
......
...@@ -40,7 +40,7 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf, ...@@ -40,7 +40,7 @@ int st_com_slave_handle_followup(struct pp_instance *ppi, unsigned char *buf,
static inline int __send_and_log(struct pp_instance *ppi, int msglen, static inline int __send_and_log(struct pp_instance *ppi, int msglen,
int msgtype, int chtype) int msgtype, int chtype)
{ {
if (pp_net_ops.send(ppi, ppi->buf_out, msglen, if (ppi->n_ops->send(ppi, ppi->buf_out, msglen,
&ppi->last_snt_time, chtype, 0) < msglen) { &ppi->last_snt_time, chtype, 0) < msglen) {
if (pp_verbose_frames) if (pp_verbose_frames)
PP_PRINTF("%s(%d) Message can't be sent\n", PP_PRINTF("%s(%d) Message can't be sent\n",
......
...@@ -19,9 +19,9 @@ int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen) ...@@ -19,9 +19,9 @@ int pp_initializing(struct pp_instance *ppi, unsigned char *pkt, int plen)
int ret = 0; int ret = 0;
if (NP(ppi)->inited) if (NP(ppi)->inited)
pp_net_ops.exit(ppi); ppi->n_ops->exit(ppi);
if (pp_net_ops.init(ppi) < 0) if (ppi->n_ops->init(ppi) < 0)
goto failure; goto failure;
NP(ppi)->inited = 1; NP(ppi)->inited = 1;
......
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