cosim_eth_proto.h 4.77 KB
Newer Older
Antoine Kaufmann's avatar
Antoine Kaufmann committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
/*
 * Copyright 2021 Max Planck Institute for Software Systems, and
 * National University of Singapore
 *
 * Permission is hereby granted, free of charge, to any person obtaining
 * a copy of this software and associated documentation files (the
 * "Software"), to deal in the Software without restriction, including
 * without limitation the rights to use, copy, modify, merge, publish,
 * distribute, sublicense, and/or sell copies of the Software, and to
 * permit persons to whom the Software is furnished to do so, subject to
 * the following conditions:
 *
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 */

Antoine Kaufmann's avatar
Antoine Kaufmann committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef COSIM_ETH_PROTO_H_
#define COSIM_ETH_PROTO_H_

#include <stdint.h>

/******************************************************************************/
/* Initialization messages on Unix socket */

/** in dev_intro.flags to indicate that sender supports issuing syncs. */
#define COSIM_ETH_PROTO_FLAGS_DI_SYNC (1 << 0)

/**
 * welcome message sent by device to network. This message comes with the shared
 * memory file descriptor attached.
 */
struct cosim_eth_proto_dev_intro {
    /** flags: see COSIM_ETH_PROTO_FLAGS_DI_* */
    uint64_t flags;

    /** offset of the device-to-network queue in shared memory region */
    uint64_t d2n_offset;
    /** size of an entry in the device-to-network queue in bytes */
    uint64_t d2n_elen;
    /** total device-to-network queue length in #entries */
    uint64_t d2n_nentries;

    /** offset of the net-to-device queue in shared memory region */
    uint64_t n2d_offset;
    /** size of an entry in the net-to-device queue in bytes */
    uint64_t n2d_elen;
    /** total net-to-device queue length in #entries */
    uint64_t n2d_nentries;
} __attribute__((packed));


60
#define COSIM_ETH_PROTO_FLAGS_NI_SYNC (1 << 0)
Antoine Kaufmann's avatar
Antoine Kaufmann committed
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

/** welcome message sent by network to device */
struct cosim_eth_proto_net_intro {
    /** flags: see COSIM_ETH_PROTO_FLAGS_IN_* */
  uint64_t flags;
} __attribute__((packed));


/******************************************************************************/
/* Messages on in-memory device to network channel */

/** Mask for ownership bit in own_type field */
#define COSIM_ETH_PROTO_D2N_OWN_MASK 0x80
/** Message is owned by device */
#define COSIM_ETH_PROTO_D2N_OWN_DEV 0x00
/** Message is owned by network */
#define COSIM_ETH_PROTO_D2N_OWN_NET 0x80

/** Mask for type value in own_type field */
#define COSIM_ETH_PROTO_D2N_MSG_MASK 0x7f
#define COSIM_ETH_PROTO_D2N_MSG_SYNC 0x1
#define COSIM_ETH_PROTO_D2N_MSG_SEND 0x2

struct cosim_eth_proto_d2n_dummy {
85
86
87
    uint8_t pad[48];
    uint64_t timestamp;
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
88
89
90
91
    uint8_t own_type;
} __attribute__((packed));

struct cosim_eth_proto_d2n_sync {
92
    uint8_t pad[48];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
93
    uint64_t timestamp;
94
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
95
96
97
98
99
100
    uint8_t own_type;
} __attribute__((packed));

struct cosim_eth_proto_d2n_send {
    uint16_t len;
    uint8_t port;
101
102
103
    uint8_t pad[45];
    uint64_t timestamp;
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    uint8_t own_type;
    uint8_t data[];
} __attribute__((packed));

union cosim_eth_proto_d2n {
    struct cosim_eth_proto_d2n_dummy dummy;
    struct cosim_eth_proto_d2n_sync sync;
    struct cosim_eth_proto_d2n_send send;
};


/******************************************************************************/
/* Messages on in-memory network to device channel */

#define COSIM_ETH_PROTO_N2D_OWN_MASK 0x80
/** Message is owned by host */
#define COSIM_ETH_PROTO_N2D_OWN_NET 0x00
/** Message is owned by device */
#define COSIM_ETH_PROTO_N2D_OWN_DEV 0x80

#define COSIM_ETH_PROTO_N2D_MSG_MASK 0x7f
#define COSIM_ETH_PROTO_N2D_MSG_SYNC 0x1
#define COSIM_ETH_PROTO_N2D_MSG_RECV 0x2

struct cosim_eth_proto_n2d_dummy {
129
130
131
    uint8_t pad[48];
    uint64_t timestamp;
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
132
133
134
135
    uint8_t own_type;
} __attribute__((packed));

struct cosim_eth_proto_n2d_sync {
136
    uint8_t pad[48];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
137
    uint64_t timestamp;
138
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
139
140
141
142
143
144
    uint8_t own_type;
} __attribute__((packed));

struct cosim_eth_proto_n2d_recv {
    uint16_t len;
    uint8_t port;
145
146
147
    uint8_t pad[45];
    uint64_t timestamp;
    uint8_t pad_[7];
Antoine Kaufmann's avatar
Antoine Kaufmann committed
148
149
150
151
152
153
154
155
156
157
158
    uint8_t own_type;
    uint8_t data[];
};

union cosim_eth_proto_n2d {
    struct cosim_eth_proto_n2d_dummy dummy;
    struct cosim_eth_proto_n2d_sync sync;
    struct cosim_eth_proto_n2d_recv recv;
};

#endif /* ndef COSIM_ETH_PROTO_H_ */