Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ycai
simbricks
Commits
d4666c97
Commit
d4666c97
authored
Feb 13, 2021
by
Antoine Kaufmann
Browse files
Reformat closer to google style
parent
eb125a88
Changes
41
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
3402 additions
and
3685 deletions
+3402
-3685
lib/simbricks/netif/netsim.c
lib/simbricks/netif/netsim.c
+124
-133
lib/simbricks/netif/netsim.h
lib/simbricks/netif/netsim.h
+22
-23
lib/simbricks/netif/utils.c
lib/simbricks/netif/utils.c
+65
-68
lib/simbricks/nicbm/nicbm.cc
lib/simbricks/nicbm/nicbm.cc
+320
-345
lib/simbricks/nicbm/nicbm.h
lib/simbricks/nicbm/nicbm.h
+132
-137
lib/simbricks/nicif/nicsim.c
lib/simbricks/nicif/nicsim.c
+303
-333
lib/simbricks/nicif/nicsim.h
lib/simbricks/nicif/nicsim.h
+16
-17
lib/simbricks/nicif/utils.c
lib/simbricks/nicif/utils.c
+84
-88
lib/simbricks/proto/network.h
lib/simbricks/proto/network.h
+53
-56
lib/simbricks/proto/pcie.h
lib/simbricks/proto/pcie.h
+146
-149
sims/net/switch/net_switch.cc
sims/net/switch/net_switch.cc
+146
-150
sims/net/tap/net_tap.c
sims/net/tap/net_tap.c
+89
-95
sims/net/wire/net_wire.c
sims/net/wire/net_wire.c
+129
-135
sims/nic/corundum/coord.h
sims/nic/corundum/coord.h
+81
-90
sims/nic/corundum/corundum_verilator.cc
sims/nic/corundum/corundum_verilator.cc
+791
-845
sims/nic/corundum/dma.cc
sims/nic/corundum/dma.cc
+78
-87
sims/nic/corundum/dma.h
sims/nic/corundum/dma.h
+77
-80
sims/nic/corundum/mem.cc
sims/nic/corundum/mem.cc
+131
-140
sims/nic/corundum/mem.h
sims/nic/corundum/mem.h
+65
-63
sims/nic/corundum_bm/corundum_bm.cc
sims/nic/corundum_bm/corundum_bm.cc
+550
-651
No files found.
lib/simbricks/netif/netsim.c
View file @
d4666c97
...
@@ -22,21 +22,21 @@
...
@@ -22,21 +22,21 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
*/
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <unistd.h>
#include <unistd.h>
#include <simbricks/netif/netsim.h>
#include <simbricks/netif/netsim.h>
#include "lib/simbricks/netif/internal.h"
#include "lib/simbricks/netif/internal.h"
static
uint64_t
current_epoch
=
0
;
static
uint64_t
current_epoch
=
0
;
int
netsim_init
(
struct
netsim_interface
*
nsif
,
int
netsim_init
(
struct
netsim_interface
*
nsif
,
const
char
*
eth_socket_path
,
const
char
*
eth_socket_path
,
int
*
sync_eth
)
int
*
sync_eth
)
{
{
struct
cosim_eth_proto_dev_intro
di
;
struct
cosim_eth_proto_dev_intro
di
;
struct
cosim_eth_proto_net_intro
ni
;
struct
cosim_eth_proto_net_intro
ni
;
int
cfd
,
shm_fd
;
int
cfd
,
shm_fd
;
...
@@ -72,8 +72,8 @@ int netsim_init(struct netsim_interface *nsif,
...
@@ -72,8 +72,8 @@ int netsim_init(struct netsim_interface *nsif,
nsif
->
sync
=
*
sync_eth
;
nsif
->
sync
=
*
sync_eth
;
}
}
nsif
->
d2n_queue
=
(
uint8_t
*
)
p
+
di
.
d2n_offset
;
nsif
->
d2n_queue
=
(
uint8_t
*
)
p
+
di
.
d2n_offset
;
nsif
->
n2d_queue
=
(
uint8_t
*
)
p
+
di
.
n2d_offset
;
nsif
->
n2d_queue
=
(
uint8_t
*
)
p
+
di
.
n2d_offset
;
nsif
->
d2n_elen
=
di
.
d2n_elen
;
nsif
->
d2n_elen
=
di
.
d2n_elen
;
nsif
->
n2d_elen
=
di
.
n2d_elen
;
nsif
->
n2d_elen
=
di
.
n2d_elen
;
nsif
->
d2n_enum
=
di
.
d2n_nentries
;
nsif
->
d2n_enum
=
di
.
d2n_nentries
;
...
@@ -84,18 +84,16 @@ int netsim_init(struct netsim_interface *nsif,
...
@@ -84,18 +84,16 @@ int netsim_init(struct netsim_interface *nsif,
return
0
;
return
0
;
}
}
void
netsim_cleanup
(
struct
netsim_interface
*
nsif
)
void
netsim_cleanup
(
struct
netsim_interface
*
nsif
)
{
{
fprintf
(
stderr
,
"netsim_cleanup: TODO
\n
"
);
fprintf
(
stderr
,
"netsim_cleanup: TODO
\n
"
);
abort
();
abort
();
}
}
volatile
union
cosim_eth_proto_d2n
*
netsim_d2n_poll
(
volatile
union
cosim_eth_proto_d2n
*
netsim_d2n_poll
(
struct
netsim_interface
*
nsif
,
uint64_t
timestamp
)
struct
netsim_interface
*
nsif
,
uint64_t
timestamp
)
{
{
volatile
union
cosim_eth_proto_d2n
*
msg
=
volatile
union
cosim_eth_proto_d2n
*
msg
=
(
volatile
union
cosim_eth_proto_d2n
*
)
(
volatile
union
cosim_eth_proto_d2n
*
)
(
nsif
->
d2n_queue
+
(
nsif
->
d2n_queue
+
nsif
->
d2n_pos
*
nsif
->
d2n_elen
);
nsif
->
d2n_pos
*
nsif
->
d2n_elen
);
/* message not ready */
/* message not ready */
if
((
msg
->
dummy
.
own_type
&
COSIM_ETH_PROTO_D2N_OWN_MASK
)
!=
if
((
msg
->
dummy
.
own_type
&
COSIM_ETH_PROTO_D2N_OWN_MASK
)
!=
...
@@ -112,23 +110,19 @@ volatile union cosim_eth_proto_d2n *netsim_d2n_poll(
...
@@ -112,23 +110,19 @@ volatile union cosim_eth_proto_d2n *netsim_d2n_poll(
}
}
void
netsim_d2n_done
(
struct
netsim_interface
*
nsif
,
void
netsim_d2n_done
(
struct
netsim_interface
*
nsif
,
volatile
union
cosim_eth_proto_d2n
*
msg
)
volatile
union
cosim_eth_proto_d2n
*
msg
)
{
{
msg
->
dummy
.
own_type
=
(
msg
->
dummy
.
own_type
&
COSIM_ETH_PROTO_D2N_MSG_MASK
)
|
msg
->
dummy
.
own_type
=
(
msg
->
dummy
.
own_type
&
COSIM_ETH_PROTO_D2N_MSG_MASK
)
COSIM_ETH_PROTO_D2N_OWN_DEV
;
|
COSIM_ETH_PROTO_D2N_OWN_DEV
;
}
}
volatile
union
cosim_eth_proto_n2d
*
netsim_n2d_alloc
(
volatile
union
cosim_eth_proto_n2d
*
netsim_n2d_alloc
(
struct
netsim_interface
*
nsif
,
uint64_t
timestamp
,
struct
netsim_interface
*
nsif
,
uint64_t
timestamp
,
uint64_t
latency
)
{
uint64_t
latency
)
{
volatile
union
cosim_eth_proto_n2d
*
msg
=
volatile
union
cosim_eth_proto_n2d
*
msg
=
(
volatile
union
cosim_eth_proto_n2d
*
)
(
volatile
union
cosim_eth_proto_n2d
*
)
(
nsif
->
n2d_queue
+
(
nsif
->
n2d_queue
+
nsif
->
n2d_pos
*
nsif
->
n2d_elen
);
nsif
->
n2d_pos
*
nsif
->
n2d_elen
);
if
((
msg
->
dummy
.
own_type
&
COSIM_ETH_PROTO_N2D_OWN_MASK
)
!=
if
((
msg
->
dummy
.
own_type
&
COSIM_ETH_PROTO_N2D_OWN_MASK
)
!=
COSIM_ETH_PROTO_N2D_OWN_NET
)
COSIM_ETH_PROTO_N2D_OWN_NET
)
{
{
return
NULL
;
return
NULL
;
}
}
...
@@ -140,8 +134,7 @@ volatile union cosim_eth_proto_n2d *netsim_n2d_alloc(
...
@@ -140,8 +134,7 @@ volatile union cosim_eth_proto_n2d *netsim_n2d_alloc(
}
}
int
netsim_n2d_sync
(
struct
netsim_interface
*
nsif
,
uint64_t
timestamp
,
int
netsim_n2d_sync
(
struct
netsim_interface
*
nsif
,
uint64_t
timestamp
,
uint64_t
latency
,
uint64_t
sync_delay
,
int
sync_mode
)
uint64_t
latency
,
uint64_t
sync_delay
,
int
sync_mode
)
{
{
volatile
union
cosim_eth_proto_n2d
*
msg
;
volatile
union
cosim_eth_proto_n2d
*
msg
;
volatile
struct
cosim_eth_proto_n2d_sync
*
sync
;
volatile
struct
cosim_eth_proto_n2d_sync
*
sync
;
int
do_sync
;
int
do_sync
;
...
@@ -155,8 +148,7 @@ int netsim_n2d_sync(struct netsim_interface *nsif, uint64_t timestamp,
...
@@ -155,8 +148,7 @@ int netsim_n2d_sync(struct netsim_interface *nsif, uint64_t timestamp,
timestamp
-
nsif
->
n2d_timestamp
>=
sync_delay
;
timestamp
-
nsif
->
n2d_timestamp
>=
sync_delay
;
break
;
break
;
case
SYNC_BARRIER
:
case
SYNC_BARRIER
:
do_sync
=
current_epoch
==
0
||
do_sync
=
current_epoch
==
0
||
timestamp
-
current_epoch
>=
sync_delay
;
timestamp
-
current_epoch
>=
sync_delay
;
break
;
break
;
default:
default:
fprintf
(
stderr
,
"unsupported sync mode=%u
\n
"
,
sync_mode
);
fprintf
(
stderr
,
"unsupported sync mode=%u
\n
"
,
sync_mode
);
...
@@ -179,8 +171,7 @@ int netsim_n2d_sync(struct netsim_interface *nsif, uint64_t timestamp,
...
@@ -179,8 +171,7 @@ int netsim_n2d_sync(struct netsim_interface *nsif, uint64_t timestamp,
}
}
void
netsim_advance_epoch
(
uint64_t
timestamp
,
uint64_t
sync_delay
,
void
netsim_advance_epoch
(
uint64_t
timestamp
,
uint64_t
sync_delay
,
int
sync_mode
)
int
sync_mode
)
{
{
if
(
sync_mode
==
SYNC_BARRIER
)
{
if
(
sync_mode
==
SYNC_BARRIER
)
{
if
(
timestamp
-
current_epoch
>=
sync_delay
)
{
if
(
timestamp
-
current_epoch
>=
sync_delay
)
{
current_epoch
=
timestamp
;
current_epoch
=
timestamp
;
...
@@ -189,14 +180,14 @@ void netsim_advance_epoch(uint64_t timestamp, uint64_t sync_delay,
...
@@ -189,14 +180,14 @@ void netsim_advance_epoch(uint64_t timestamp, uint64_t sync_delay,
}
}
uint64_t
netsim_advance_time
(
uint64_t
timestamp
,
uint64_t
sync_delay
,
uint64_t
netsim_advance_time
(
uint64_t
timestamp
,
uint64_t
sync_delay
,
int
sync_mode
)
int
sync_mode
)
{
{
switch
(
sync_mode
)
{
switch
(
sync_mode
)
{
case
SYNC_MODES
:
case
SYNC_MODES
:
return
timestamp
;
return
timestamp
;
case
SYNC_BARRIER
:
case
SYNC_BARRIER
:
return
timestamp
<
current_epoch
+
sync_delay
?
return
timestamp
<
current_epoch
+
sync_delay
timestamp
:
current_epoch
+
sync_delay
;
?
timestamp
:
current_epoch
+
sync_delay
;
default:
default:
fprintf
(
stderr
,
"unsupported sync mode=%u
\n
"
,
sync_mode
);
fprintf
(
stderr
,
"unsupported sync mode=%u
\n
"
,
sync_mode
);
return
timestamp
;
return
timestamp
;
...
...
lib/simbricks/netif/netsim.h
View file @
d4666c97
...
@@ -27,6 +27,7 @@
...
@@ -27,6 +27,7 @@
#include <stddef.h>
#include <stddef.h>
#include <stdint.h>
#include <stdint.h>
#include <simbricks/proto/network.h>
#include <simbricks/proto/network.h>
#define SYNC_MODES 0
#define SYNC_MODES 0
...
@@ -48,22 +49,20 @@ struct netsim_interface {
...
@@ -48,22 +49,20 @@ struct netsim_interface {
int
sync
;
int
sync
;
};
};
int
netsim_init
(
struct
netsim_interface
*
nsif
,
int
netsim_init
(
struct
netsim_interface
*
nsif
,
const
char
*
eth_socket_path
,
const
char
*
eth_socket_path
,
int
*
sync_eth
);
int
*
sync_eth
);
void
netsim_cleanup
(
struct
netsim_interface
*
nsif
);
void
netsim_cleanup
(
struct
netsim_interface
*
nsif
);
volatile
union
cosim_eth_proto_d2n
*
netsim_d2n_poll
(
volatile
union
cosim_eth_proto_d2n
*
netsim_d2n_poll
(
struct
netsim_interface
*
nsif
,
uint64_t
timestamp
);
struct
netsim_interface
*
nsif
,
uint64_t
timestamp
);
void
netsim_d2n_done
(
struct
netsim_interface
*
nsif
,
void
netsim_d2n_done
(
struct
netsim_interface
*
nsif
,
volatile
union
cosim_eth_proto_d2n
*
msg
);
volatile
union
cosim_eth_proto_d2n
*
msg
);
static
inline
uint64_t
netsim_d2n_timestamp
(
struct
netsim_interface
*
nsif
)
static
inline
uint64_t
netsim_d2n_timestamp
(
struct
netsim_interface
*
nsif
)
{
{
return
nsif
->
d2n_timestamp
;
return
nsif
->
d2n_timestamp
;
}
}
volatile
union
cosim_eth_proto_n2d
*
netsim_n2d_alloc
(
volatile
union
cosim_eth_proto_n2d
*
netsim_n2d_alloc
(
struct
netsim_interface
*
nsif
,
uint64_t
timestamp
,
struct
netsim_interface
*
nsif
,
uint64_t
timestamp
,
uint64_t
latency
);
uint64_t
latency
);
int
netsim_n2d_sync
(
struct
netsim_interface
*
nsif
,
uint64_t
timestamp
,
int
netsim_n2d_sync
(
struct
netsim_interface
*
nsif
,
uint64_t
timestamp
,
uint64_t
latency
,
uint64_t
sync_delay
,
int
sync_mode
);
uint64_t
latency
,
uint64_t
sync_delay
,
int
sync_mode
);
void
netsim_advance_epoch
(
uint64_t
timestamp
,
uint64_t
sync_delay
,
void
netsim_advance_epoch
(
uint64_t
timestamp
,
uint64_t
sync_delay
,
...
...
lib/simbricks/netif/utils.c
View file @
d4666c97
...
@@ -24,20 +24,19 @@
...
@@ -24,20 +24,19 @@
#include <fcntl.h>
#include <fcntl.h>
#include <pthread.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mman.h>
#include <sys/un.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/stat.h>
#include <sys/un.h>
#include <unistd.h>
#include <unistd.h>
#include "lib/simbricks/netif/internal.h"
#include "lib/simbricks/netif/internal.h"
int
uxsocket_connect
(
const
char
*
path
)
int
uxsocket_connect
(
const
char
*
path
)
{
{
int
fd
;
int
fd
;
struct
sockaddr_un
saun
;
struct
sockaddr_un
saun
;
...
@@ -51,7 +50,7 @@ int uxsocket_connect(const char *path)
...
@@ -51,7 +50,7 @@ int uxsocket_connect(const char *path)
return
-
1
;
return
-
1
;
}
}
if
(
connect
(
fd
,
(
struct
sockaddr
*
)
&
saun
,
sizeof
(
saun
))
!=
0
)
{
if
(
connect
(
fd
,
(
struct
sockaddr
*
)
&
saun
,
sizeof
(
saun
))
!=
0
)
{
perror
(
"connect failed"
);
perror
(
"connect failed"
);
return
-
1
;
return
-
1
;
}
}
...
@@ -59,8 +58,7 @@ int uxsocket_connect(const char *path)
...
@@ -59,8 +58,7 @@ int uxsocket_connect(const char *path)
return
fd
;
return
fd
;
}
}
int
uxsocket_recv
(
int
fd
,
void
*
data
,
size_t
len
,
int
*
pfd
)
int
uxsocket_recv
(
int
fd
,
void
*
data
,
size_t
len
,
int
*
pfd
)
{
{
int
*
ppfd
;
int
*
ppfd
;
ssize_t
ret
;
ssize_t
ret
;
struct
cmsghdr
*
cmsg
;
struct
cmsghdr
*
cmsg
;
...
@@ -82,13 +80,13 @@ int uxsocket_recv(int fd, void *data, size_t len, int *pfd)
...
@@ -82,13 +80,13 @@ int uxsocket_recv(int fd, void *data, size_t len, int *pfd)
.
msg_flags
=
0
,
.
msg_flags
=
0
,
};
};
if
((
ret
=
recvmsg
(
fd
,
&
msg
,
0
))
!=
(
ssize_t
)
len
)
{
if
((
ret
=
recvmsg
(
fd
,
&
msg
,
0
))
!=
(
ssize_t
)
len
)
{
perror
(
"recvmsg failed"
);
perror
(
"recvmsg failed"
);
return
-
1
;
return
-
1
;
}
}
cmsg
=
CMSG_FIRSTHDR
(
&
msg
);
cmsg
=
CMSG_FIRSTHDR
(
&
msg
);
ppfd
=
(
int
*
)
CMSG_DATA
(
cmsg
);
ppfd
=
(
int
*
)
CMSG_DATA
(
cmsg
);
if
(
msg
.
msg_controllen
<=
0
||
cmsg
->
cmsg_len
!=
CMSG_LEN
(
sizeof
(
int
)))
{
if
(
msg
.
msg_controllen
<=
0
||
cmsg
->
cmsg_len
!=
CMSG_LEN
(
sizeof
(
int
)))
{
fprintf
(
stderr
,
"accessing ancillary data failed
\n
"
);
fprintf
(
stderr
,
"accessing ancillary data failed
\n
"
);
return
-
1
;
return
-
1
;
...
@@ -98,8 +96,7 @@ int uxsocket_recv(int fd, void *data, size_t len, int *pfd)
...
@@ -98,8 +96,7 @@ int uxsocket_recv(int fd, void *data, size_t len, int *pfd)
return
0
;
return
0
;
}
}
void
*
shm_map
(
int
shm_fd
)
void
*
shm_map
(
int
shm_fd
)
{
{
void
*
p
;
void
*
p
;
struct
stat
statbuf
;
struct
stat
statbuf
;
...
...
lib/simbricks/nicbm/nicbm.cc
View file @
d4666c97
...
@@ -22,42 +22,38 @@
...
@@ -22,42 +22,38 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
*/
#include <stdlib.h>
#include <simbricks/nicbm/nicbm.h>
#include <signal.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <unistd.h>
#include <unistd.h>
#include <signal.h>
#include <cassert>
#include <cassert>
#include <ctime>
#include <ctime>
#include <iostream>
#include <iostream>
#include <simbricks/nicbm/nicbm.h>
// #define DEBUG_NICBM 1
// #define DEBUG_NICBM 1
#define DMA_MAX_PENDING 64
#define DMA_MAX_PENDING 64
namespace
nicbm
{
using
namespace
nicbm
;
static
volatile
int
exiting
=
0
;
static
volatile
int
exiting
=
0
;
static
uint64_t
main_time
=
0
;
static
uint64_t
main_time
=
0
;
static
void
sigint_handler
(
int
dummy
)
{
static
void
sigint_handler
(
int
dummy
)
{
exiting
=
1
;
exiting
=
1
;
}
}
static
void
sigusr1_handler
(
int
dummy
)
static
void
sigusr1_handler
(
int
dummy
)
{
{
fprintf
(
stderr
,
"main_time = %lu
\n
"
,
main_time
);
fprintf
(
stderr
,
"main_time = %lu
\n
"
,
main_time
);
}
}
volatile
union
cosim_pcie_proto_d2h
*
Runner
::
d2h_alloc
(
void
)
volatile
union
cosim_pcie_proto_d2h
*
Runner
::
d2h_alloc
(
void
)
{
{
volatile
union
cosim_pcie_proto_d2h
*
msg
;
volatile
union
cosim_pcie_proto_d2h
*
msg
;
while
((
msg
=
nicsim_d2h_alloc
(
&
nsparams
,
main_time
))
==
NULL
)
{
while
((
msg
=
nicsim_d2h_alloc
(
&
nsparams
,
main_time
))
==
NULL
)
{
fprintf
(
stderr
,
"d2h_alloc: no entry available
\n
"
);
fprintf
(
stderr
,
"d2h_alloc: no entry available
\n
"
);
...
@@ -65,8 +61,7 @@ volatile union cosim_pcie_proto_d2h *Runner::d2h_alloc(void)
...
@@ -65,8 +61,7 @@ volatile union cosim_pcie_proto_d2h *Runner::d2h_alloc(void)
return
msg
;
return
msg
;
}
}
volatile
union
cosim_eth_proto_d2n
*
Runner
::
d2n_alloc
(
void
)
volatile
union
cosim_eth_proto_d2n
*
Runner
::
d2n_alloc
(
void
)
{
{
volatile
union
cosim_eth_proto_d2n
*
msg
;
volatile
union
cosim_eth_proto_d2n
*
msg
;
while
((
msg
=
nicsim_d2n_alloc
(
&
nsparams
,
main_time
))
==
NULL
)
{
while
((
msg
=
nicsim_d2n_alloc
(
&
nsparams
,
main_time
))
==
NULL
)
{
fprintf
(
stderr
,
"d2n_alloc: no entry available
\n
"
);
fprintf
(
stderr
,
"d2n_alloc: no entry available
\n
"
);
...
@@ -74,8 +69,7 @@ volatile union cosim_eth_proto_d2n *Runner::d2n_alloc(void)
...
@@ -74,8 +69,7 @@ volatile union cosim_eth_proto_d2n *Runner::d2n_alloc(void)
return
msg
;
return
msg
;
}
}
void
Runner
::
issue_dma
(
DMAOp
&
op
)
void
Runner
::
issue_dma
(
DMAOp
&
op
)
{
{
if
(
dma_pending
<
DMA_MAX_PENDING
)
{
if
(
dma_pending
<
DMA_MAX_PENDING
)
{
// can directly issue
// can directly issue
#ifdef DEBUG_NICBM
#ifdef DEBUG_NICBM
...
@@ -92,8 +86,7 @@ void Runner::issue_dma(DMAOp &op)
...
@@ -92,8 +86,7 @@ void Runner::issue_dma(DMAOp &op)
}
}
}
}
void
Runner
::
dma_trigger
()
void
Runner
::
dma_trigger
()
{
{
if
(
dma_queue
.
empty
()
||
dma_pending
==
DMA_MAX_PENDING
)
if
(
dma_queue
.
empty
()
||
dma_pending
==
DMA_MAX_PENDING
)
return
;
return
;
...
@@ -103,8 +96,7 @@ void Runner::dma_trigger()
...
@@ -103,8 +96,7 @@ void Runner::dma_trigger()
dma_do
(
*
op
);
dma_do
(
*
op
);
}
}
void
Runner
::
dma_do
(
DMAOp
&
op
)
void
Runner
::
dma_do
(
DMAOp
&
op
)
{
{
volatile
union
cosim_pcie_proto_d2h
*
msg
=
d2h_alloc
();
volatile
union
cosim_pcie_proto_d2h
*
msg
=
d2h_alloc
();
dma_pending
++
;
dma_pending
++
;
#ifdef DEBUG_NICBM
#ifdef DEBUG_NICBM
...
@@ -115,39 +107,42 @@ void Runner::dma_do(DMAOp &op)
...
@@ -115,39 +107,42 @@ void Runner::dma_do(DMAOp &op)
if
(
op
.
write
)
{
if
(
op
.
write
)
{
volatile
struct
cosim_pcie_proto_d2h_write
*
write
=
&
msg
->
write
;
volatile
struct
cosim_pcie_proto_d2h_write
*
write
=
&
msg
->
write
;
if
(
dintro
.
d2h_elen
<
sizeof
(
*
write
)
+
op
.
len
)
{
if
(
dintro
.
d2h_elen
<
sizeof
(
*
write
)
+
op
.
len
)
{
fprintf
(
stderr
,
"issue_dma: write too big (%zu), can only fit up "
fprintf
(
stderr
,
"to (%zu)
\n
"
,
op
.
len
,
dintro
.
d2h_elen
-
sizeof
(
*
write
));
"issue_dma: write too big (%zu), can only fit up "
"to (%zu)
\n
"
,
op
.
len
,
dintro
.
d2h_elen
-
sizeof
(
*
write
));
abort
();
abort
();
}
}
write
->
req_id
=
(
uintptr_t
)
&
op
;
write
->
req_id
=
(
uintptr_t
)
&
op
;
write
->
offset
=
op
.
dma_addr
;
write
->
offset
=
op
.
dma_addr
;
write
->
len
=
op
.
len
;
write
->
len
=
op
.
len
;
memcpy
((
void
*
)
write
->
data
,
(
void
*
)
op
.
data
,
op
.
len
);
memcpy
((
void
*
)
write
->
data
,
(
void
*
)
op
.
data
,
op
.
len
);
// WMB();
// WMB();
write
->
own_type
=
COSIM_PCIE_PROTO_D2H_MSG_WRITE
|
write
->
own_type
=
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
COSIM_PCIE_PROTO_D2H_MSG_WRITE
|
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
}
else
{
}
else
{
volatile
struct
cosim_pcie_proto_d2h_read
*
read
=
&
msg
->
read
;
volatile
struct
cosim_pcie_proto_d2h_read
*
read
=
&
msg
->
read
;
if
(
dintro
.
h2d_elen
<
sizeof
(
struct
cosim_pcie_proto_h2d_readcomp
)
+
if
(
dintro
.
h2d_elen
<
op
.
len
)
{
sizeof
(
struct
cosim_pcie_proto_h2d_readcomp
)
+
op
.
len
)
{
fprintf
(
stderr
,
"issue_dma: write too big (%zu), can only fit up "
fprintf
(
stderr
,
"to (%zu)
\n
"
,
op
.
len
,
dintro
.
h2d_elen
-
"issue_dma: write too big (%zu), can only fit up "
sizeof
(
struct
cosim_pcie_proto_h2d_readcomp
));
"to (%zu)
\n
"
,
op
.
len
,
dintro
.
h2d_elen
-
sizeof
(
struct
cosim_pcie_proto_h2d_readcomp
));
abort
();
abort
();
}
}
read
->
req_id
=
(
uintptr_t
)
&
op
;
read
->
req_id
=
(
uintptr_t
)
&
op
;
read
->
offset
=
op
.
dma_addr
;
read
->
offset
=
op
.
dma_addr
;
read
->
len
=
op
.
len
;
read
->
len
=
op
.
len
;
// WMB();
// WMB();
read
->
own_type
=
COSIM_PCIE_PROTO_D2H_MSG_READ
|
read
->
own_type
=
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
COSIM_PCIE_PROTO_D2H_MSG_READ
|
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
}
}
}
}
void
Runner
::
msi_issue
(
uint8_t
vec
)
void
Runner
::
msi_issue
(
uint8_t
vec
)
{
{
volatile
union
cosim_pcie_proto_d2h
*
msg
=
d2h_alloc
();
volatile
union
cosim_pcie_proto_d2h
*
msg
=
d2h_alloc
();
#ifdef DEBUG_NICBM
#ifdef DEBUG_NICBM
printf
(
"nicbm: issue MSI interrupt vec %u
\n
"
,
vec
);
printf
(
"nicbm: issue MSI interrupt vec %u
\n
"
,
vec
);
...
@@ -157,12 +152,11 @@ void Runner::msi_issue(uint8_t vec)
...
@@ -157,12 +152,11 @@ void Runner::msi_issue(uint8_t vec)
intr
->
inttype
=
COSIM_PCIE_PROTO_INT_MSI
;
intr
->
inttype
=
COSIM_PCIE_PROTO_INT_MSI
;
// WMB();
// WMB();
intr
->
own_type
=
COSIM_PCIE_PROTO_D2H_MSG_INTERRUPT
|
intr
->
own_type
=
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
COSIM_PCIE_PROTO_D2H_MSG_INTERRUPT
|
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
}
}
void
Runner
::
msix_issue
(
uint8_t
vec
)
void
Runner
::
msix_issue
(
uint8_t
vec
)
{
{
volatile
union
cosim_pcie_proto_d2h
*
msg
=
d2h_alloc
();
volatile
union
cosim_pcie_proto_d2h
*
msg
=
d2h_alloc
();
#ifdef DEBUG_NICBM
#ifdef DEBUG_NICBM
printf
(
"nicbm: issue MSI-X interrupt vec %u
\n
"
,
vec
);
printf
(
"nicbm: issue MSI-X interrupt vec %u
\n
"
,
vec
);
...
@@ -172,45 +166,41 @@ void Runner::msix_issue(uint8_t vec)
...
@@ -172,45 +166,41 @@ void Runner::msix_issue(uint8_t vec)
intr
->
inttype
=
COSIM_PCIE_PROTO_INT_MSIX
;
intr
->
inttype
=
COSIM_PCIE_PROTO_INT_MSIX
;
// WMB();
// WMB();
intr
->
own_type
=
COSIM_PCIE_PROTO_D2H_MSG_INTERRUPT
|
intr
->
own_type
=
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
COSIM_PCIE_PROTO_D2H_MSG_INTERRUPT
|
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
}
}
void
Runner
::
event_schedule
(
TimedEvent
&
evt
)
void
Runner
::
event_schedule
(
TimedEvent
&
evt
)
{
{
events
.
insert
(
&
evt
);
events
.
insert
(
&
evt
);
}
}
void
Runner
::
event_cancel
(
TimedEvent
&
evt
)
void
Runner
::
event_cancel
(
TimedEvent
&
evt
)
{
{
events
.
erase
(
&
evt
);
events
.
erase
(
&
evt
);
}
}
void
Runner
::
h2d_read
(
volatile
struct
cosim_pcie_proto_h2d_read
*
read
)
void
Runner
::
h2d_read
(
volatile
struct
cosim_pcie_proto_h2d_read
*
read
)
{
{
volatile
union
cosim_pcie_proto_d2h
*
msg
;
volatile
union
cosim_pcie_proto_d2h
*
msg
;
volatile
struct
cosim_pcie_proto_d2h_readcomp
*
rc
;
volatile
struct
cosim_pcie_proto_d2h_readcomp
*
rc
;
msg
=
d2h_alloc
();
msg
=
d2h_alloc
();
rc
=
&
msg
->
readcomp
;
rc
=
&
msg
->
readcomp
;
dev
.
reg_read
(
read
->
bar
,
read
->
offset
,
(
void
*
)
rc
->
data
,
read
->
len
);
dev
.
reg_read
(
read
->
bar
,
read
->
offset
,
(
void
*
)
rc
->
data
,
read
->
len
);
rc
->
req_id
=
read
->
req_id
;
rc
->
req_id
=
read
->
req_id
;
#ifdef DEBUG_NICBM
#ifdef DEBUG_NICBM
uint64_t
dbg_val
=
0
;
uint64_t
dbg_val
=
0
;
memcpy
(
&
dbg_val
,
(
const
void
*
)
rc
->
data
,
read
->
len
<=
8
?
read
->
len
:
8
);
memcpy
(
&
dbg_val
,
(
const
void
*
)
rc
->
data
,
read
->
len
<=
8
?
read
->
len
:
8
);
printf
(
"nicbm: read(off=0x%lx, len=%u, val=0x%lx)
\n
"
,
read
->
offset
,
printf
(
"nicbm: read(off=0x%lx, len=%u, val=0x%lx)
\n
"
,
read
->
offset
,
read
->
len
,
read
->
len
,
dbg_val
);
dbg_val
);
#endif
#endif
// WMB();
// WMB();
rc
->
own_type
=
COSIM_PCIE_PROTO_D2H_MSG_READCOMP
|
rc
->
own_type
=
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
COSIM_PCIE_PROTO_D2H_MSG_READCOMP
|
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
}
}
void
Runner
::
h2d_write
(
volatile
struct
cosim_pcie_proto_h2d_write
*
write
)
void
Runner
::
h2d_write
(
volatile
struct
cosim_pcie_proto_h2d_write
*
write
)
{
{
volatile
union
cosim_pcie_proto_d2h
*
msg
;
volatile
union
cosim_pcie_proto_d2h
*
msg
;
volatile
struct
cosim_pcie_proto_d2h_writecomp
*
wc
;
volatile
struct
cosim_pcie_proto_d2h_writecomp
*
wc
;
...
@@ -219,26 +209,24 @@ void Runner::h2d_write(volatile struct cosim_pcie_proto_h2d_write *write)
...
@@ -219,26 +209,24 @@ void Runner::h2d_write(volatile struct cosim_pcie_proto_h2d_write *write)
#ifdef DEBUG_NICBM
#ifdef DEBUG_NICBM
uint64_t
dbg_val
=
0
;
uint64_t
dbg_val
=
0
;
memcpy
(
&
dbg_val
,
(
const
void
*
)
write
->
data
,
write
->
len
<=
8
?
write
->
len
:
memcpy
(
&
dbg_val
,
(
const
void
*
)
write
->
data
,
write
->
len
<=
8
?
write
->
len
:
8
);
8
);
printf
(
"nicbm: write(off=0x%lx, len=%u, val=0x%lx)
\n
"
,
write
->
offset
,
printf
(
"nicbm: write(off=0x%lx, len=%u, val=0x%lx)
\n
"
,
write
->
offset
,
write
->
len
,
dbg_val
);
write
->
len
,
dbg_val
);
#endif
#endif
dev
.
reg_write
(
write
->
bar
,
write
->
offset
,
(
void
*
)
write
->
data
,
write
->
len
);
dev
.
reg_write
(
write
->
bar
,
write
->
offset
,
(
void
*
)
write
->
data
,
write
->
len
);
wc
->
req_id
=
write
->
req_id
;
wc
->
req_id
=
write
->
req_id
;
// WMB();
// WMB();
wc
->
own_type
=
COSIM_PCIE_PROTO_D2H_MSG_WRITECOMP
|
wc
->
own_type
=
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
COSIM_PCIE_PROTO_D2H_MSG_WRITECOMP
|
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
}
}
void
Runner
::
h2d_readcomp
(
volatile
struct
cosim_pcie_proto_h2d_readcomp
*
rc
)
void
Runner
::
h2d_readcomp
(
volatile
struct
cosim_pcie_proto_h2d_readcomp
*
rc
)
{
{
DMAOp
*
op
=
(
DMAOp
*
)(
uintptr_t
)
rc
->
req_id
;
DMAOp
*
op
=
(
DMAOp
*
)(
uintptr_t
)
rc
->
req_id
;
#ifdef DEBUG_NICBM
#ifdef DEBUG_NICBM
printf
(
"nicbm: completed dma read op %p addr %lx len %zu
\n
"
,
op
,
printf
(
"nicbm: completed dma read op %p addr %lx len %zu
\n
"
,
op
,
op
->
dma_addr
,
op
->
dma_addr
,
op
->
len
);
op
->
len
);
#endif
#endif
memcpy
(
op
->
data
,
(
void
*
)
rc
->
data
,
op
->
len
);
memcpy
(
op
->
data
,
(
void
*
)
rc
->
data
,
op
->
len
);
...
@@ -248,8 +236,7 @@ void Runner::h2d_readcomp(volatile struct cosim_pcie_proto_h2d_readcomp *rc)
...
@@ -248,8 +236,7 @@ void Runner::h2d_readcomp(volatile struct cosim_pcie_proto_h2d_readcomp *rc)
dma_trigger
();
dma_trigger
();
}
}
void
Runner
::
h2d_writecomp
(
volatile
struct
cosim_pcie_proto_h2d_writecomp
*
wc
)
void
Runner
::
h2d_writecomp
(
volatile
struct
cosim_pcie_proto_h2d_writecomp
*
wc
)
{
{
DMAOp
*
op
=
(
DMAOp
*
)(
uintptr_t
)
wc
->
req_id
;
DMAOp
*
op
=
(
DMAOp
*
)(
uintptr_t
)
wc
->
req_id
;
#ifdef DEBUG_NICBM
#ifdef DEBUG_NICBM
...
@@ -263,22 +250,19 @@ void Runner::h2d_writecomp(volatile struct cosim_pcie_proto_h2d_writecomp *wc)
...
@@ -263,22 +250,19 @@ void Runner::h2d_writecomp(volatile struct cosim_pcie_proto_h2d_writecomp *wc)
dma_trigger
();
dma_trigger
();
}
}
void
Runner
::
h2d_devctrl
(
volatile
struct
cosim_pcie_proto_h2d_devctrl
*
dc
)
void
Runner
::
h2d_devctrl
(
volatile
struct
cosim_pcie_proto_h2d_devctrl
*
dc
)
{
{
dev
.
devctrl_update
(
*
(
struct
cosim_pcie_proto_h2d_devctrl
*
)
dc
);
dev
.
devctrl_update
(
*
(
struct
cosim_pcie_proto_h2d_devctrl
*
)
dc
);
}
}
void
Runner
::
eth_recv
(
volatile
struct
cosim_eth_proto_n2d_recv
*
recv
)
void
Runner
::
eth_recv
(
volatile
struct
cosim_eth_proto_n2d_recv
*
recv
)
{
{
#ifdef DEBUG_NICBM
#ifdef DEBUG_NICBM
printf
(
"nicbm: eth rx: port %u len %u
\n
"
,
recv
->
port
,
recv
->
len
);
printf
(
"nicbm: eth rx: port %u len %u
\n
"
,
recv
->
port
,
recv
->
len
);
#endif
#endif
dev
.
eth_rx
(
recv
->
port
,
(
void
*
)
recv
->
data
,
recv
->
len
);
dev
.
eth_rx
(
recv
->
port
,
(
void
*
)
recv
->
data
,
recv
->
len
);
}
}
void
Runner
::
eth_send
(
const
void
*
data
,
size_t
len
)
void
Runner
::
eth_send
(
const
void
*
data
,
size_t
len
)
{
{
#ifdef DEBUG_NICBM
#ifdef DEBUG_NICBM
printf
(
"nicbm: eth tx: len %zu
\n
"
,
len
);
printf
(
"nicbm: eth tx: len %zu
\n
"
,
len
);
#endif
#endif
...
@@ -288,12 +272,10 @@ void Runner::eth_send(const void *data, size_t len)
...
@@ -288,12 +272,10 @@ void Runner::eth_send(const void *data, size_t len)
send
->
port
=
0
;
// single port
send
->
port
=
0
;
// single port
send
->
len
=
len
;
send
->
len
=
len
;
memcpy
((
void
*
)
send
->
data
,
data
,
len
);
memcpy
((
void
*
)
send
->
data
,
data
,
len
);
send
->
own_type
=
COSIM_ETH_PROTO_D2N_MSG_SEND
|
send
->
own_type
=
COSIM_ETH_PROTO_D2N_MSG_SEND
|
COSIM_ETH_PROTO_D2N_OWN_NET
;
COSIM_ETH_PROTO_D2N_OWN_NET
;
}
}
void
Runner
::
poll_h2d
()
void
Runner
::
poll_h2d
()
{
{
volatile
union
cosim_pcie_proto_h2d
*
msg
=
volatile
union
cosim_pcie_proto_h2d
*
msg
=
nicif_h2d_poll
(
&
nsparams
,
main_time
);
nicif_h2d_poll
(
&
nsparams
,
main_time
);
uint8_t
type
;
uint8_t
type
;
...
@@ -334,8 +316,7 @@ void Runner::poll_h2d()
...
@@ -334,8 +316,7 @@ void Runner::poll_h2d()
nicif_h2d_next
();
nicif_h2d_next
();
}
}
void
Runner
::
poll_n2d
()
void
Runner
::
poll_n2d
()
{
{
volatile
union
cosim_eth_proto_n2d
*
msg
=
volatile
union
cosim_eth_proto_n2d
*
msg
=
nicif_n2d_poll
(
&
nsparams
,
main_time
);
nicif_n2d_poll
(
&
nsparams
,
main_time
);
uint8_t
t
;
uint8_t
t
;
...
@@ -360,18 +341,15 @@ void Runner::poll_n2d()
...
@@ -360,18 +341,15 @@ void Runner::poll_n2d()
nicif_n2d_next
();
nicif_n2d_next
();
}
}
uint64_t
Runner
::
time_ps
()
const
uint64_t
Runner
::
time_ps
()
const
{
{
return
main_time
;
return
main_time
;
}
}
uint64_t
Runner
::
get_mac_addr
()
const
uint64_t
Runner
::
get_mac_addr
()
const
{
{
return
mac_addr
;
return
mac_addr
;
}
}
bool
Runner
::
event_next
(
uint64_t
&
retval
)
bool
Runner
::
event_next
(
uint64_t
&
retval
)
{
{
if
(
events
.
empty
())
if
(
events
.
empty
())
return
false
;
return
false
;
...
@@ -379,8 +357,7 @@ bool Runner::event_next(uint64_t &retval)
...
@@ -379,8 +357,7 @@ bool Runner::event_next(uint64_t &retval)
return
true
;
return
true
;
}
}
void
Runner
::
event_trigger
()
void
Runner
::
event_trigger
()
{
{
auto
it
=
events
.
begin
();
auto
it
=
events
.
begin
();
if
(
it
==
events
.
end
())
if
(
it
==
events
.
end
())
return
;
return
;
...
@@ -395,9 +372,7 @@ void Runner::event_trigger()
...
@@ -395,9 +372,7 @@ void Runner::event_trigger()
dev
.
timed_event
(
*
ev
);
dev
.
timed_event
(
*
ev
);
}
}
Runner
::
Runner
(
Device
&
dev_
)
Runner
::
Runner
(
Device
&
dev_
)
:
dev
(
dev_
),
events
(
event_cmp
())
{
:
dev
(
dev_
),
events
(
event_cmp
())
{
// mac_addr = lrand48() & ~(3ULL << 46);
// mac_addr = lrand48() & ~(3ULL << 46);
dma_pending
=
0
;
dma_pending
=
0
;
srand48
(
time
(
NULL
)
^
getpid
());
srand48
(
time
(
NULL
)
^
getpid
());
...
@@ -409,8 +384,7 @@ Runner::Runner(Device &dev_)
...
@@ -409,8 +384,7 @@ Runner::Runner(Device &dev_)
std
::
cerr
<<
std
::
hex
<<
mac_addr
<<
std
::
endl
;
std
::
cerr
<<
std
::
hex
<<
mac_addr
<<
std
::
endl
;
}
}
int
Runner
::
runMain
(
int
argc
,
char
*
argv
[])
int
Runner
::
runMain
(
int
argc
,
char
*
argv
[])
{
{
uint64_t
next_ts
;
uint64_t
next_ts
;
uint64_t
max_step
=
10000
;
uint64_t
max_step
=
10000
;
uint64_t
sync_period
=
100
*
1000ULL
;
uint64_t
sync_period
=
100
*
1000ULL
;
...
@@ -419,7 +393,8 @@ int Runner::runMain(int argc, char *argv[])
...
@@ -419,7 +393,8 @@ int Runner::runMain(int argc, char *argv[])
int
sync_mode
=
SYNC_MODES
;
int
sync_mode
=
SYNC_MODES
;
if
(
argc
<
4
&&
argc
>
9
)
{
if
(
argc
<
4
&&
argc
>
9
)
{
fprintf
(
stderr
,
"Usage: corundum_bm PCI-SOCKET ETH-SOCKET "
fprintf
(
stderr
,
"Usage: corundum_bm PCI-SOCKET ETH-SOCKET "
"SHM [SYNC-MODE] [START-TICK] [SYNC-PERIOD] [PCI-LATENCY] "
"SHM [SYNC-MODE] [START-TICK] [SYNC-PERIOD] [PCI-LATENCY] "
"[ETH-LATENCY]
\n
"
);
"[ETH-LATENCY]
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
...
@@ -491,14 +466,14 @@ int Runner::runMain(int argc, char *argv[])
...
@@ -491,14 +466,14 @@ int Runner::runMain(int argc, char *argv[])
return
0
;
return
0
;
}
}
void
Runner
::
Device
::
timed_event
(
TimedEvent
&
te
)
void
Runner
::
Device
::
timed_event
(
TimedEvent
&
te
)
{
{
}
}
void
Runner
::
Device
::
devctrl_update
(
void
Runner
::
Device
::
devctrl_update
(
struct
cosim_pcie_proto_h2d_devctrl
&
devctrl
)
struct
cosim_pcie_proto_h2d_devctrl
&
devctrl
)
{
{
int_intx_en
=
devctrl
.
flags
&
COSIM_PCIE_PROTO_CTRL_INTX_EN
;
int_intx_en
=
devctrl
.
flags
&
COSIM_PCIE_PROTO_CTRL_INTX_EN
;
int_msi_en
=
devctrl
.
flags
&
COSIM_PCIE_PROTO_CTRL_MSI_EN
;
int_msi_en
=
devctrl
.
flags
&
COSIM_PCIE_PROTO_CTRL_MSI_EN
;
int_msix_en
=
devctrl
.
flags
&
COSIM_PCIE_PROTO_CTRL_MSIX_EN
;
int_msix_en
=
devctrl
.
flags
&
COSIM_PCIE_PROTO_CTRL_MSIX_EN
;
}
}
}
// namespace nicbm
lib/simbricks/nicbm/nicbm.h
View file @
d4666c97
...
@@ -27,10 +27,11 @@
...
@@ -27,10 +27,11 @@
#include <cassert>
#include <cassert>
#include <cstring>
#include <cstring>
#include <set>
#include <deque>
#include <deque>
#include <set>
extern
"C"
{
extern
"C"
{
#include <simbricks/nicif/nicsim.h>
#include <simbricks/nicif/nicsim.h>
}
}
namespace
nicbm
{
namespace
nicbm
{
...
@@ -39,7 +40,8 @@ static const size_t MAX_DMA_LEN = 2048;
...
@@ -39,7 +40,8 @@ static const size_t MAX_DMA_LEN = 2048;
class
DMAOp
{
class
DMAOp
{
public:
public:
virtual
~
DMAOp
()
{
}
virtual
~
DMAOp
()
{
}
bool
write
;
bool
write
;
uint64_t
dma_addr
;
uint64_t
dma_addr
;
size_t
len
;
size_t
len
;
...
@@ -48,11 +50,11 @@ class DMAOp {
...
@@ -48,11 +50,11 @@ class DMAOp {
class
TimedEvent
{
class
TimedEvent
{
public:
public:
virtual
~
TimedEvent
()
{
}
virtual
~
TimedEvent
()
{
}
uint64_t
time
;
uint64_t
time
;
};
};
/**
/**
* The Runner drives the main simulation loop. It's initialized with a reference
* The Runner drives the main simulation loop. It's initialized with a reference
* to a device it should manage, and then once `runMain` is called, it will
* to a device it should manage, and then once `runMain` is called, it will
...
@@ -72,8 +74,7 @@ class Runner {
...
@@ -72,8 +74,7 @@ class Runner {
* Initialize device specific parameters (pci dev/vendor id,
* Initialize device specific parameters (pci dev/vendor id,
* BARs etc. in intro struct.
* BARs etc. in intro struct.
*/
*/
virtual
void
setup_intro
(
struct
cosim_pcie_proto_dev_intro
&
di
)
virtual
void
setup_intro
(
struct
cosim_pcie_proto_dev_intro
&
di
)
=
0
;
=
0
;
/**
/**
* execute a register read from `bar`:`addr` of length `len`.
* execute a register read from `bar`:`addr` of length `len`.
...
@@ -86,8 +87,8 @@ class Runner {
...
@@ -86,8 +87,8 @@ class Runner {
* execute a register write to `bar`:`addr` of length `len`,
* execute a register write to `bar`:`addr` of length `len`,
* with the data in `src`.
* with the data in `src`.
*/
*/
virtual
void
reg_write
(
uint8_t
bar
,
uint64_t
addr
,
virtual
void
reg_write
(
uint8_t
bar
,
uint64_t
addr
,
const
void
*
src
,
const
void
*
src
,
size_t
len
)
=
0
;
size_t
len
)
=
0
;
/**
/**
* the previously issued DMA operation `op` completed.
* the previously issued DMA operation `op` completed.
...
@@ -98,8 +99,7 @@ class Runner {
...
@@ -98,8 +99,7 @@ class Runner {
* A packet has arrived on the wire, of length `len` with
* A packet has arrived on the wire, of length `len` with
* payload `data`.
* payload `data`.
*/
*/
virtual
void
eth_rx
(
uint8_t
port
,
const
void
*
data
,
size_t
len
)
virtual
void
eth_rx
(
uint8_t
port
,
const
void
*
data
,
size_t
len
)
=
0
;
=
0
;
/**
/**
* A timed event is due.
* A timed event is due.
...
@@ -109,14 +109,12 @@ class Runner {
...
@@ -109,14 +109,12 @@ class Runner {
/**
/**
* Device control update
* Device control update
*/
*/
virtual
void
devctrl_update
(
virtual
void
devctrl_update
(
struct
cosim_pcie_proto_h2d_devctrl
&
devctrl
);
struct
cosim_pcie_proto_h2d_devctrl
&
devctrl
);
};
};
protected:
protected:
struct
event_cmp
{
struct
event_cmp
{
bool
operator
()
(
TimedEvent
*
a
,
TimedEvent
*
b
)
bool
operator
()(
TimedEvent
*
a
,
TimedEvent
*
b
)
{
{
return
a
->
time
<
b
->
time
;
return
a
->
time
<
b
->
time
;
}
}
};
};
...
@@ -176,17 +174,14 @@ class SimpleDevice : public Runner::Device {
...
@@ -176,17 +174,14 @@ class SimpleDevice : public Runner::Device {
virtual
TReg
reg_read
(
uint8_t
bar
,
uint64_t
addr
)
=
0
;
virtual
TReg
reg_read
(
uint8_t
bar
,
uint64_t
addr
)
=
0
;
virtual
void
reg_write
(
uint8_t
bar
,
uint64_t
addr
,
TReg
val
)
=
0
;
virtual
void
reg_write
(
uint8_t
bar
,
uint64_t
addr
,
TReg
val
)
=
0
;
virtual
void
reg_read
(
uint8_t
bar
,
uint64_t
addr
,
void
*
dest
,
virtual
void
reg_read
(
uint8_t
bar
,
uint64_t
addr
,
void
*
dest
,
size_t
len
)
{
size_t
len
)
{
assert
(
len
==
sizeof
(
TReg
));
assert
(
len
==
sizeof
(
TReg
));
TReg
r
=
reg_read
(
bar
,
addr
);
TReg
r
=
reg_read
(
bar
,
addr
);
memcpy
(
dest
,
&
r
,
sizeof
(
r
));
memcpy
(
dest
,
&
r
,
sizeof
(
r
));
}
}
virtual
void
reg_write
(
uint8_t
bar
,
uint64_t
addr
,
virtual
void
reg_write
(
uint8_t
bar
,
uint64_t
addr
,
const
void
*
src
,
const
void
*
src
,
size_t
len
)
size_t
len
)
{
{
assert
(
len
==
sizeof
(
TReg
));
assert
(
len
==
sizeof
(
TReg
));
TReg
r
;
TReg
r
;
memcpy
(
&
r
,
src
,
sizeof
(
r
));
memcpy
(
&
r
,
src
,
sizeof
(
r
));
...
...
lib/simbricks/nicif/nicsim.c
View file @
d4666c97
...
@@ -22,11 +22,11 @@
...
@@ -22,11 +22,11 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
*/
#include <
stdlib
.h>
#include <
poll
.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <poll.h>
#include <unistd.h>
#include <unistd.h>
#include <simbricks/nicif/nicsim.h>
#include <simbricks/nicif/nicsim.h>
...
@@ -45,7 +45,6 @@
...
@@ -45,7 +45,6 @@
#define N2D_ELEN (9024 + 64)
#define N2D_ELEN (9024 + 64)
#define N2D_ENUM 8192
#define N2D_ENUM 8192
static
uint8_t
*
d2h_queue
;
static
uint8_t
*
d2h_queue
;
static
size_t
d2h_pos
;
static
size_t
d2h_pos
;
static
size_t
d2h_off
;
/* offset in shm region */
static
size_t
d2h_off
;
/* offset in shm region */
...
@@ -74,8 +73,7 @@ static int pci_cfd = -1;
...
@@ -74,8 +73,7 @@ static int pci_cfd = -1;
static
int
eth_cfd
=
-
1
;
static
int
eth_cfd
=
-
1
;
static
int
accept_pci
(
struct
cosim_pcie_proto_dev_intro
*
di
,
int
pci_lfd
,
static
int
accept_pci
(
struct
cosim_pcie_proto_dev_intro
*
di
,
int
pci_lfd
,
int
*
sync_pci
)
int
*
sync_pci
)
{
{
if
((
pci_cfd
=
accept
(
pci_lfd
,
NULL
,
NULL
))
<
0
)
{
if
((
pci_cfd
=
accept
(
pci_lfd
,
NULL
,
NULL
))
<
0
)
{
return
-
1
;
return
-
1
;
}
}
...
@@ -93,7 +91,7 @@ static int accept_pci(struct cosim_pcie_proto_dev_intro *di, int pci_lfd,
...
@@ -93,7 +91,7 @@ static int accept_pci(struct cosim_pcie_proto_dev_intro *di, int pci_lfd,
if
(
*
sync_pci
)
if
(
*
sync_pci
)
di
->
flags
|=
COSIM_PCIE_PROTO_FLAGS_DI_SYNC
;
di
->
flags
|=
COSIM_PCIE_PROTO_FLAGS_DI_SYNC
;
else
else
di
->
flags
&=
~
((
uint64_t
)
COSIM_PCIE_PROTO_FLAGS_DI_SYNC
);
di
->
flags
&=
~
((
uint64_t
)
COSIM_PCIE_PROTO_FLAGS_DI_SYNC
);
if
(
uxsocket_send
(
pci_cfd
,
di
,
sizeof
(
*
di
),
shm_fd
))
{
if
(
uxsocket_send
(
pci_cfd
,
di
,
sizeof
(
*
di
),
shm_fd
))
{
return
-
1
;
return
-
1
;
...
@@ -102,8 +100,7 @@ static int accept_pci(struct cosim_pcie_proto_dev_intro *di, int pci_lfd,
...
@@ -102,8 +100,7 @@ static int accept_pci(struct cosim_pcie_proto_dev_intro *di, int pci_lfd,
return
0
;
return
0
;
}
}
static
int
accept_eth
(
int
eth_lfd
,
int
*
sync_eth
)
static
int
accept_eth
(
int
eth_lfd
,
int
*
sync_eth
)
{
{
struct
cosim_eth_proto_dev_intro
di
;
struct
cosim_eth_proto_dev_intro
di
;
if
((
eth_cfd
=
accept
(
eth_lfd
,
NULL
,
NULL
))
<
0
)
{
if
((
eth_cfd
=
accept
(
eth_lfd
,
NULL
,
NULL
))
<
0
)
{
...
@@ -132,9 +129,8 @@ static int accept_eth(int eth_lfd, int *sync_eth)
...
@@ -132,9 +129,8 @@ static int accept_eth(int eth_lfd, int *sync_eth)
return
0
;
return
0
;
}
}
static
int
accept_conns
(
struct
cosim_pcie_proto_dev_intro
*
di
,
static
int
accept_conns
(
struct
cosim_pcie_proto_dev_intro
*
di
,
int
pci_lfd
,
int
pci_lfd
,
int
*
sync_pci
,
int
eth_lfd
,
int
*
sync_eth
)
int
*
sync_pci
,
int
eth_lfd
,
int
*
sync_eth
)
{
{
struct
pollfd
pfds
[
2
];
struct
pollfd
pfds
[
2
];
int
await_pci
=
pci_lfd
!=
-
1
;
int
await_pci
=
pci_lfd
!=
-
1
;
int
await_eth
=
eth_lfd
!=
-
1
;
int
await_eth
=
eth_lfd
!=
-
1
;
...
@@ -181,32 +177,27 @@ static int accept_conns(struct cosim_pcie_proto_dev_intro *di,
...
@@ -181,32 +177,27 @@ static int accept_conns(struct cosim_pcie_proto_dev_intro *di,
}
}
int
nicsim_init
(
struct
nicsim_params
*
params
,
int
nicsim_init
(
struct
nicsim_params
*
params
,
struct
cosim_pcie_proto_dev_intro
*
di
)
struct
cosim_pcie_proto_dev_intro
*
di
)
{
{
int
pci_lfd
=
-
1
,
eth_lfd
=
-
1
;
int
pci_lfd
=
-
1
,
eth_lfd
=
-
1
;
void
*
shmptr
;
void
*
shmptr
;
size_t
shm_size
;
size_t
shm_size
;
/* ready in memory queues */
/* ready in memory queues */
shm_size
=
(
uint64_t
)
D2H_ELEN
*
D2H_ENUM
+
shm_size
=
(
uint64_t
)
D2H_ELEN
*
D2H_ENUM
+
(
uint64_t
)
H2D_ELEN
*
H2D_ENUM
+
(
uint64_t
)
H2D_ELEN
*
H2D_ENUM
+
(
uint64_t
)
D2N_ELEN
*
D2N_ENUM
+
(
uint64_t
)
N2D_ELEN
*
N2D_ENUM
;
(
uint64_t
)
D2N_ELEN
*
D2N_ENUM
+
if
((
shm_fd
=
shm_create
(
params
->
shm_path
,
shm_size
,
&
shmptr
))
<
0
)
{
(
uint64_t
)
N2D_ELEN
*
N2D_ENUM
;
if
((
shm_fd
=
shm_create
(
params
->
shm_path
,
shm_size
,
&
shmptr
))
<
0
)
{
return
-
1
;
return
-
1
;
}
}
d2h_off
=
0
;
d2h_off
=
0
;
h2d_off
=
d2h_off
+
(
uint64_t
)
D2H_ELEN
*
D2H_ENUM
;
h2d_off
=
d2h_off
+
(
uint64_t
)
D2H_ELEN
*
D2H_ENUM
;
d2n_off
=
h2d_off
+
(
uint64_t
)
H2D_ELEN
*
H2D_ENUM
;
d2n_off
=
h2d_off
+
(
uint64_t
)
H2D_ELEN
*
H2D_ENUM
;
n2d_off
=
d2n_off
+
(
uint64_t
)
D2N_ELEN
*
D2N_ENUM
;
n2d_off
=
d2n_off
+
(
uint64_t
)
D2N_ELEN
*
D2N_ENUM
;
d2h_queue
=
(
uint8_t
*
)
shmptr
+
d2h_off
;
d2h_queue
=
(
uint8_t
*
)
shmptr
+
d2h_off
;
h2d_queue
=
(
uint8_t
*
)
shmptr
+
h2d_off
;
h2d_queue
=
(
uint8_t
*
)
shmptr
+
h2d_off
;
d2n_queue
=
(
uint8_t
*
)
shmptr
+
d2n_off
;
d2n_queue
=
(
uint8_t
*
)
shmptr
+
d2n_off
;
n2d_queue
=
(
uint8_t
*
)
shmptr
+
n2d_off
;
n2d_queue
=
(
uint8_t
*
)
shmptr
+
n2d_off
;
d2h_pos
=
h2d_pos
=
d2n_pos
=
n2d_pos
=
0
;
d2h_pos
=
h2d_pos
=
d2n_pos
=
n2d_pos
=
0
;
...
@@ -224,8 +215,7 @@ int nicsim_init(struct nicsim_params *params,
...
@@ -224,8 +215,7 @@ int nicsim_init(struct nicsim_params *params,
/* accept connection fds */
/* accept connection fds */
if
(
accept_conns
(
di
,
pci_lfd
,
&
params
->
sync_pci
,
eth_lfd
,
if
(
accept_conns
(
di
,
pci_lfd
,
&
params
->
sync_pci
,
eth_lfd
,
&
params
->
sync_eth
)
!=
0
)
&
params
->
sync_eth
)
!=
0
)
{
{
return
-
1
;
return
-
1
;
}
}
...
@@ -252,8 +242,7 @@ int nicsim_init(struct nicsim_params *params,
...
@@ -252,8 +242,7 @@ int nicsim_init(struct nicsim_params *params,
return
0
;
return
0
;
}
}
void
nicsim_cleanup
(
void
)
void
nicsim_cleanup
(
void
)
{
{
close
(
pci_cfd
);
close
(
pci_cfd
);
close
(
eth_cfd
);
close
(
eth_cfd
);
}
}
...
@@ -261,8 +250,7 @@ void nicsim_cleanup(void)
...
@@ -261,8 +250,7 @@ void nicsim_cleanup(void)
/******************************************************************************/
/******************************************************************************/
/* Sync */
/* Sync */
int
nicsim_sync
(
struct
nicsim_params
*
params
,
uint64_t
timestamp
)
int
nicsim_sync
(
struct
nicsim_params
*
params
,
uint64_t
timestamp
)
{
{
int
ret
=
0
;
int
ret
=
0
;
volatile
union
cosim_pcie_proto_d2h
*
d2h
;
volatile
union
cosim_pcie_proto_d2h
*
d2h
;
volatile
union
cosim_eth_proto_d2n
*
d2n
;
volatile
union
cosim_eth_proto_d2n
*
d2n
;
...
@@ -284,14 +272,13 @@ int nicsim_sync(struct nicsim_params *params, uint64_t timestamp)
...
@@ -284,14 +272,13 @@ int nicsim_sync(struct nicsim_params *params, uint64_t timestamp)
return
ret
;
return
ret
;
}
}
if
(
sync
)
if
(
sync
)
{
{
d2h
=
nicsim_d2h_alloc
(
params
,
timestamp
);
d2h
=
nicsim_d2h_alloc
(
params
,
timestamp
);
if
(
d2h
==
NULL
)
{
if
(
d2h
==
NULL
)
{
ret
=
-
1
;
ret
=
-
1
;
}
else
{
}
else
{
d2h
->
sync
.
own_type
=
COSIM_PCIE_PROTO_D2H_MSG_SYNC
|
d2h
->
sync
.
own_type
=
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
COSIM_PCIE_PROTO_D2H_MSG_SYNC
|
COSIM_PCIE_PROTO_D2H_OWN_HOST
;
}
}
}
}
}
}
...
@@ -313,14 +300,13 @@ int nicsim_sync(struct nicsim_params *params, uint64_t timestamp)
...
@@ -313,14 +300,13 @@ int nicsim_sync(struct nicsim_params *params, uint64_t timestamp)
return
ret
;
return
ret
;
}
}
if
(
sync
)
if
(
sync
)
{
{
d2n
=
nicsim_d2n_alloc
(
params
,
timestamp
);
d2n
=
nicsim_d2n_alloc
(
params
,
timestamp
);
if
(
d2n
==
NULL
)
{
if
(
d2n
==
NULL
)
{
ret
=
-
1
;
ret
=
-
1
;
}
else
{
}
else
{
d2n
->
sync
.
own_type
=
COSIM_ETH_PROTO_D2N_MSG_SYNC
|
d2n
->
sync
.
own_type
=
COSIM_ETH_PROTO_D2N_OWN_NET
;
COSIM_ETH_PROTO_D2N_MSG_SYNC
|
COSIM_ETH_PROTO_D2N_OWN_NET
;
}
}
}
}
}
}
...
@@ -328,8 +314,7 @@ int nicsim_sync(struct nicsim_params *params, uint64_t timestamp)
...
@@ -328,8 +314,7 @@ int nicsim_sync(struct nicsim_params *params, uint64_t timestamp)
return
ret
;
return
ret
;
}
}
void
nicsim_advance_epoch
(
struct
nicsim_params
*
params
,
uint64_t
timestamp
)
void
nicsim_advance_epoch
(
struct
nicsim_params
*
params
,
uint64_t
timestamp
)
{
{
if
(
params
->
sync_mode
==
SYNC_BARRIER
)
{
if
(
params
->
sync_mode
==
SYNC_BARRIER
)
{
if
((
params
->
sync_pci
||
params
->
sync_eth
)
&&
if
((
params
->
sync_pci
||
params
->
sync_eth
)
&&
timestamp
-
current_epoch
>=
params
->
sync_delay
)
{
timestamp
-
current_epoch
>=
params
->
sync_delay
)
{
...
@@ -338,25 +323,24 @@ void nicsim_advance_epoch(struct nicsim_params *params, uint64_t timestamp)
...
@@ -338,25 +323,24 @@ void nicsim_advance_epoch(struct nicsim_params *params, uint64_t timestamp)
}
}
}
}
uint64_t
nicsim_advance_time
(
struct
nicsim_params
*
params
,
uint64_t
timestamp
)
uint64_t
nicsim_advance_time
(
struct
nicsim_params
*
params
,
uint64_t
timestamp
)
{
{
switch
(
params
->
sync_mode
)
{
switch
(
params
->
sync_mode
)
{
case
SYNC_MODES
:
case
SYNC_MODES
:
return
timestamp
;
return
timestamp
;
case
SYNC_BARRIER
:
case
SYNC_BARRIER
:
return
timestamp
<
current_epoch
+
params
->
sync_delay
?
return
timestamp
<
current_epoch
+
params
->
sync_delay
timestamp
:
current_epoch
+
params
->
sync_delay
;
?
timestamp
:
current_epoch
+
params
->
sync_delay
;
default:
default:
fprintf
(
stderr
,
"unsupported sync mode=%u
\n
"
,
params
->
sync_mode
);
fprintf
(
stderr
,
"unsupported sync mode=%u
\n
"
,
params
->
sync_mode
);
return
timestamp
;
return
timestamp
;
}
}
}
}
uint64_t
nicsim_next_timestamp
(
struct
nicsim_params
*
params
)
uint64_t
nicsim_next_timestamp
(
struct
nicsim_params
*
params
)
{
{
if
(
params
->
sync_pci
&&
params
->
sync_eth
)
{
if
(
params
->
sync_pci
&&
params
->
sync_eth
)
{
return
(
pci_last_rx_time
<=
eth_last_rx_time
?
pci_last_rx_time
:
return
(
pci_last_rx_time
<=
eth_last_rx_time
?
pci_last_rx_time
eth_last_rx_time
);
:
eth_last_rx_time
);
}
else
if
(
params
->
sync_pci
)
{
}
else
if
(
params
->
sync_pci
)
{
return
pci_last_rx_time
;
return
pci_last_rx_time
;
}
else
if
(
params
->
sync_eth
)
{
}
else
if
(
params
->
sync_eth
)
{
...
@@ -370,11 +354,9 @@ uint64_t nicsim_next_timestamp(struct nicsim_params *params)
...
@@ -370,11 +354,9 @@ uint64_t nicsim_next_timestamp(struct nicsim_params *params)
/* PCI */
/* PCI */
volatile
union
cosim_pcie_proto_h2d
*
nicif_h2d_poll
(
volatile
union
cosim_pcie_proto_h2d
*
nicif_h2d_poll
(
struct
nicsim_params
*
params
,
uint64_t
timestamp
)
struct
nicsim_params
*
params
,
uint64_t
timestamp
)
{
{
volatile
union
cosim_pcie_proto_h2d
*
msg
=
volatile
union
cosim_pcie_proto_h2d
*
msg
=
(
volatile
union
cosim_pcie_proto_h2d
*
)
(
volatile
union
cosim_pcie_proto_h2d
*
)(
h2d_queue
+
h2d_pos
*
H2D_ELEN
);
(
h2d_queue
+
h2d_pos
*
H2D_ELEN
);
/* message not ready */
/* message not ready */
if
((
msg
->
dummy
.
own_type
&
COSIM_PCIE_PROTO_H2D_OWN_MASK
)
!=
if
((
msg
->
dummy
.
own_type
&
COSIM_PCIE_PROTO_H2D_OWN_MASK
)
!=
...
@@ -389,27 +371,22 @@ volatile union cosim_pcie_proto_h2d *nicif_h2d_poll(
...
@@ -389,27 +371,22 @@ volatile union cosim_pcie_proto_h2d *nicif_h2d_poll(
return
msg
;
return
msg
;
}
}
void
nicif_h2d_done
(
volatile
union
cosim_pcie_proto_h2d
*
msg
)
void
nicif_h2d_done
(
volatile
union
cosim_pcie_proto_h2d
*
msg
)
{
{
msg
->
dummy
.
own_type
=
(
msg
->
dummy
.
own_type
&
COSIM_PCIE_PROTO_H2D_MSG_MASK
)
|
msg
->
dummy
.
own_type
=
(
msg
->
dummy
.
own_type
&
COSIM_PCIE_PROTO_H2D_MSG_MASK
)
COSIM_PCIE_PROTO_H2D_OWN_HOST
;
|
COSIM_PCIE_PROTO_H2D_OWN_HOST
;
}
}
void
nicif_h2d_next
(
void
)
void
nicif_h2d_next
(
void
)
{
{
h2d_pos
=
(
h2d_pos
+
1
)
%
H2D_ENUM
;
h2d_pos
=
(
h2d_pos
+
1
)
%
H2D_ENUM
;
}
}
volatile
union
cosim_pcie_proto_d2h
*
nicsim_d2h_alloc
(
volatile
union
cosim_pcie_proto_d2h
*
nicsim_d2h_alloc
(
struct
nicsim_params
*
params
,
uint64_t
timestamp
)
struct
nicsim_params
*
params
,
uint64_t
timestamp
)
{
{
volatile
union
cosim_pcie_proto_d2h
*
msg
=
volatile
union
cosim_pcie_proto_d2h
*
msg
=
(
volatile
union
cosim_pcie_proto_d2h
*
)
(
volatile
union
cosim_pcie_proto_d2h
*
)(
d2h_queue
+
d2h_pos
*
D2H_ELEN
);
(
d2h_queue
+
d2h_pos
*
D2H_ELEN
);
if
((
msg
->
dummy
.
own_type
&
COSIM_PCIE_PROTO_D2H_OWN_MASK
)
!=
if
((
msg
->
dummy
.
own_type
&
COSIM_PCIE_PROTO_D2H_OWN_MASK
)
!=
COSIM_PCIE_PROTO_D2H_OWN_DEV
)
COSIM_PCIE_PROTO_D2H_OWN_DEV
)
{
{
return
NULL
;
return
NULL
;
}
}
...
@@ -423,12 +400,10 @@ volatile union cosim_pcie_proto_d2h *nicsim_d2h_alloc(
...
@@ -423,12 +400,10 @@ volatile union cosim_pcie_proto_d2h *nicsim_d2h_alloc(
/******************************************************************************/
/******************************************************************************/
/* Ethernet */
/* Ethernet */
volatile
union
cosim_eth_proto_n2d
*
nicif_n2d_poll
(
volatile
union
cosim_eth_proto_n2d
*
nicif_n2d_poll
(
struct
nicsim_params
*
params
,
struct
nicsim_params
*
params
,
uint64_t
timestamp
)
uint64_t
timestamp
)
{
{
volatile
union
cosim_eth_proto_n2d
*
msg
=
volatile
union
cosim_eth_proto_n2d
*
msg
=
(
volatile
union
cosim_eth_proto_n2d
*
)
(
volatile
union
cosim_eth_proto_n2d
*
)(
n2d_queue
+
n2d_pos
*
N2D_ELEN
);
(
n2d_queue
+
n2d_pos
*
N2D_ELEN
);
/* message not ready */
/* message not ready */
if
((
msg
->
dummy
.
own_type
&
COSIM_ETH_PROTO_N2D_OWN_MASK
)
!=
if
((
msg
->
dummy
.
own_type
&
COSIM_ETH_PROTO_N2D_OWN_MASK
)
!=
...
@@ -443,27 +418,22 @@ volatile union cosim_eth_proto_n2d *nicif_n2d_poll(
...
@@ -443,27 +418,22 @@ volatile union cosim_eth_proto_n2d *nicif_n2d_poll(
return
msg
;
return
msg
;
}
}
void
nicif_n2d_done
(
volatile
union
cosim_eth_proto_n2d
*
msg
)
void
nicif_n2d_done
(
volatile
union
cosim_eth_proto_n2d
*
msg
)
{
{
msg
->
dummy
.
own_type
=
(
msg
->
dummy
.
own_type
&
COSIM_ETH_PROTO_N2D_MSG_MASK
)
|
msg
->
dummy
.
own_type
=
(
msg
->
dummy
.
own_type
&
COSIM_ETH_PROTO_N2D_MSG_MASK
)
COSIM_ETH_PROTO_N2D_OWN_NET
;
|
COSIM_ETH_PROTO_N2D_OWN_NET
;
}
}
void
nicif_n2d_next
(
void
)
void
nicif_n2d_next
(
void
)
{
{
n2d_pos
=
(
n2d_pos
+
1
)
%
N2D_ENUM
;
n2d_pos
=
(
n2d_pos
+
1
)
%
N2D_ENUM
;
}
}
volatile
union
cosim_eth_proto_d2n
*
nicsim_d2n_alloc
(
volatile
union
cosim_eth_proto_d2n
*
nicsim_d2n_alloc
(
struct
nicsim_params
*
params
,
uint64_t
timestamp
)
struct
nicsim_params
*
params
,
uint64_t
timestamp
)
{
{
volatile
union
cosim_eth_proto_d2n
*
msg
=
volatile
union
cosim_eth_proto_d2n
*
msg
=
(
volatile
union
cosim_eth_proto_d2n
*
)
(
volatile
union
cosim_eth_proto_d2n
*
)(
d2n_queue
+
d2n_pos
*
D2N_ELEN
);
(
d2n_queue
+
d2n_pos
*
D2N_ELEN
);
if
((
msg
->
dummy
.
own_type
&
COSIM_ETH_PROTO_D2N_OWN_MASK
)
!=
if
((
msg
->
dummy
.
own_type
&
COSIM_ETH_PROTO_D2N_OWN_MASK
)
!=
COSIM_ETH_PROTO_D2N_OWN_DEV
)
COSIM_ETH_PROTO_D2N_OWN_DEV
)
{
{
return
NULL
;
return
NULL
;
}
}
...
...
lib/simbricks/nicif/nicsim.h
View file @
d4666c97
...
@@ -25,8 +25,8 @@
...
@@ -25,8 +25,8 @@
#ifndef SIMBRICKS_NICIF_NICSIM_H_
#ifndef SIMBRICKS_NICIF_NICSIM_H_
#define SIMBRICKS_NICIF_NICSIM_H_
#define SIMBRICKS_NICIF_NICSIM_H_
#include <simbricks/proto/pcie.h>
#include <simbricks/proto/network.h>
#include <simbricks/proto/network.h>
#include <simbricks/proto/pcie.h>
#define SYNC_MODES 0 // ModES style synchronization
#define SYNC_MODES 0 // ModES style synchronization
#define SYNC_BARRIER 1 // Global barrier style synchronization
#define SYNC_BARRIER 1 // Global barrier style synchronization
...
@@ -62,9 +62,8 @@ void nicif_h2d_next(void);
...
@@ -62,9 +62,8 @@ void nicif_h2d_next(void);
volatile
union
cosim_pcie_proto_d2h
*
nicsim_d2h_alloc
(
volatile
union
cosim_pcie_proto_d2h
*
nicsim_d2h_alloc
(
struct
nicsim_params
*
params
,
uint64_t
timestamp
);
struct
nicsim_params
*
params
,
uint64_t
timestamp
);
volatile
union
cosim_eth_proto_n2d
*
nicif_n2d_poll
(
struct
nicsim_params
*
params
,
volatile
union
cosim_eth_proto_n2d
*
nicif_n2d_poll
(
uint64_t
timestamp
);
struct
nicsim_params
*
params
,
uint64_t
timestamp
);
void
nicif_n2d_done
(
volatile
union
cosim_eth_proto_n2d
*
msg
);
void
nicif_n2d_done
(
volatile
union
cosim_eth_proto_n2d
*
msg
);
void
nicif_n2d_next
(
void
);
void
nicif_n2d_next
(
void
);
...
...
lib/simbricks/nicif/utils.c
View file @
d4666c97
...
@@ -24,18 +24,17 @@
...
@@ -24,18 +24,17 @@
#include <errno.h>
#include <errno.h>
#include <fcntl.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include <stdbool.h>
#include <s
ys/un
.h>
#include <s
tdio
.h>
#include <s
ys/socket
.h>
#include <s
tdlib
.h>
#include <sys/mman.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#include <unistd.h>
#include "lib/simbricks/nicif/internal.h"
#include "lib/simbricks/nicif/internal.h"
int
uxsocket_init
(
const
char
*
path
)
int
uxsocket_init
(
const
char
*
path
)
{
{
int
fd
;
int
fd
;
struct
sockaddr_un
saun
;
struct
sockaddr_un
saun
;
...
@@ -47,7 +46,7 @@ int uxsocket_init(const char *path)
...
@@ -47,7 +46,7 @@ int uxsocket_init(const char *path)
memset
(
&
saun
,
0
,
sizeof
(
saun
));
memset
(
&
saun
,
0
,
sizeof
(
saun
));
saun
.
sun_family
=
AF_UNIX
;
saun
.
sun_family
=
AF_UNIX
;
memcpy
(
saun
.
sun_path
,
path
,
strlen
(
path
));
memcpy
(
saun
.
sun_path
,
path
,
strlen
(
path
));
if
(
bind
(
fd
,
(
struct
sockaddr
*
)
&
saun
,
sizeof
(
saun
)))
{
if
(
bind
(
fd
,
(
struct
sockaddr
*
)
&
saun
,
sizeof
(
saun
)))
{
perror
(
"uxsocket_init: bind failed"
);
perror
(
"uxsocket_init: bind failed"
);
goto
error_close
;
goto
error_close
;
}
}
...
@@ -65,8 +64,7 @@ error_exit:
...
@@ -65,8 +64,7 @@ error_exit:
return
-
1
;
return
-
1
;
}
}
int
uxsocket_send
(
int
connfd
,
void
*
data
,
size_t
len
,
int
fd
)
int
uxsocket_send
(
int
connfd
,
void
*
data
,
size_t
len
,
int
fd
)
{
{
ssize_t
tx
;
ssize_t
tx
;
struct
iovec
iov
=
{
struct
iovec
iov
=
{
.
iov_base
=
data
,
.
iov_base
=
data
,
...
@@ -94,10 +92,10 @@ int uxsocket_send(int connfd, void *data, size_t len, int fd)
...
@@ -94,10 +92,10 @@ int uxsocket_send(int connfd, void *data, size_t len, int fd)
cmsg
->
cmsg_type
=
SCM_RIGHTS
;
cmsg
->
cmsg_type
=
SCM_RIGHTS
;
cmsg
->
cmsg_len
=
CMSG_LEN
(
sizeof
(
int
));
cmsg
->
cmsg_len
=
CMSG_LEN
(
sizeof
(
int
));
*
(
int
*
)
CMSG_DATA
(
cmsg
)
=
fd
;
*
(
int
*
)
CMSG_DATA
(
cmsg
)
=
fd
;
}
}
if
((
tx
=
sendmsg
(
connfd
,
&
msg
,
0
))
!=
(
ssize_t
)
len
)
{
if
((
tx
=
sendmsg
(
connfd
,
&
msg
,
0
))
!=
(
ssize_t
)
len
)
{
fprintf
(
stderr
,
"tx == %zd
\n
"
,
tx
);
fprintf
(
stderr
,
"tx == %zd
\n
"
,
tx
);
return
-
1
;
return
-
1
;
}
}
...
@@ -105,8 +103,7 @@ int uxsocket_send(int connfd, void *data, size_t len, int fd)
...
@@ -105,8 +103,7 @@ int uxsocket_send(int connfd, void *data, size_t len, int fd)
return
0
;
return
0
;
}
}
int
shm_create
(
const
char
*
path
,
size_t
size
,
void
**
addr
)
int
shm_create
(
const
char
*
path
,
size_t
size
,
void
**
addr
)
{
{
int
fd
;
int
fd
;
void
*
p
;
void
*
p
;
...
@@ -119,9 +116,8 @@ int shm_create(const char *path, size_t size, void **addr)
...
@@ -119,9 +116,8 @@ int shm_create(const char *path, size_t size, void **addr)
goto
error_remove
;
goto
error_remove
;
}
}
if
((
p
=
mmap
(
NULL
,
size
,
PROT_READ
|
PROT_WRITE
,
if
((
p
=
mmap
(
NULL
,
size
,
PROT_READ
|
PROT_WRITE
,
MAP_SHARED
|
MAP_POPULATE
,
MAP_SHARED
|
MAP_POPULATE
,
fd
,
0
))
==
(
void
*
)
-
1
)
fd
,
0
))
==
(
void
*
)
-
1
)
{
{
perror
(
"util_create_shmsiszed: mmap failed"
);
perror
(
"util_create_shmsiszed: mmap failed"
);
goto
error_remove
;
goto
error_remove
;
}
}
...
...
lib/simbricks/proto/network.h
View file @
d4666c97
...
@@ -56,7 +56,6 @@ struct cosim_eth_proto_dev_intro {
...
@@ -56,7 +56,6 @@ struct cosim_eth_proto_dev_intro {
uint64_t
n2d_nentries
;
uint64_t
n2d_nentries
;
}
__attribute__
((
packed
));
}
__attribute__
((
packed
));
#define COSIM_ETH_PROTO_FLAGS_NI_SYNC (1 << 0)
#define COSIM_ETH_PROTO_FLAGS_NI_SYNC (1 << 0)
/** welcome message sent by network to device */
/** welcome message sent by network to device */
...
@@ -65,7 +64,6 @@ struct cosim_eth_proto_net_intro {
...
@@ -65,7 +64,6 @@ struct cosim_eth_proto_net_intro {
uint64_t
flags
;
uint64_t
flags
;
}
__attribute__
((
packed
));
}
__attribute__
((
packed
));
/******************************************************************************/
/******************************************************************************/
/* Messages on in-memory device to network channel */
/* Messages on in-memory device to network channel */
...
@@ -111,7 +109,6 @@ union cosim_eth_proto_d2n {
...
@@ -111,7 +109,6 @@ union cosim_eth_proto_d2n {
struct
cosim_eth_proto_d2n_send
send
;
struct
cosim_eth_proto_d2n_send
send
;
};
};
/******************************************************************************/
/******************************************************************************/
/* Messages on in-memory network to device channel */
/* Messages on in-memory network to device channel */
...
...
lib/simbricks/proto/pcie.h
View file @
d4666c97
...
@@ -108,7 +108,6 @@ struct cosim_pcie_proto_dev_intro {
...
@@ -108,7 +108,6 @@ struct cosim_pcie_proto_dev_intro {
uint16_t
psi_msix_cap_offset
;
uint16_t
psi_msix_cap_offset
;
}
__attribute__
((
packed
));
}
__attribute__
((
packed
));
#define COSIM_PCIE_PROTO_FLAGS_HI_SYNC (1 << 0)
#define COSIM_PCIE_PROTO_FLAGS_HI_SYNC (1 << 0)
/** welcome message sent by host to device */
/** welcome message sent by host to device */
...
@@ -117,7 +116,6 @@ struct cosim_pcie_proto_host_intro {
...
@@ -117,7 +116,6 @@ struct cosim_pcie_proto_host_intro {
uint64_t
flags
;
uint64_t
flags
;
}
__attribute__
((
packed
));
}
__attribute__
((
packed
));
/******************************************************************************/
/******************************************************************************/
/* Messages on in-memory device to host channel */
/* Messages on in-memory device to host channel */
...
@@ -221,7 +219,6 @@ union cosim_pcie_proto_d2h {
...
@@ -221,7 +219,6 @@ union cosim_pcie_proto_d2h {
}
__attribute__
((
packed
));
}
__attribute__
((
packed
));
COSIM_PCI_MSG_SZCHECK
(
union
cosim_pcie_proto_d2h
);
COSIM_PCI_MSG_SZCHECK
(
union
cosim_pcie_proto_d2h
);
/******************************************************************************/
/******************************************************************************/
/* Messages on in-memory host to device channel */
/* Messages on in-memory host to device channel */
...
...
sims/net/switch/net_switch.cc
View file @
d4666c97
...
@@ -22,15 +22,16 @@
...
@@ -22,15 +22,16 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
*/
#include <unistd.h>
#include <cassert>
#include <climits>
#include <csignal>
#include <cstdio>
#include <cstdio>
#include <cstdlib>
#include <cstdlib>
#include <csignal>
#include <climits>
#include <cstring>
#include <cstring>
#include <unistd.h>
#include <vector>
#include <unordered_map>
#include <unordered_map>
#include <
cassert
>
#include <
vector
>
extern
"C"
{
extern
"C"
{
#include <simbricks/netif/netsim.h>
#include <simbricks/netif/netsim.h>
...
@@ -43,8 +44,8 @@ static uint64_t eth_latency = (500 * 1000ULL); // 500ns
...
@@ -43,8 +44,8 @@ static uint64_t eth_latency = (500 * 1000ULL); // 500ns
struct
MAC
{
struct
MAC
{
const
volatile
uint8_t
*
data
;
const
volatile
uint8_t
*
data
;
MAC
(
const
volatile
uint8_t
*
data
)
MAC
(
const
volatile
uint8_t
*
data
)
:
data
(
data
)
{
:
data
(
data
)
{
}
}
bool
operator
==
(
const
MAC
&
other
)
const
{
bool
operator
==
(
const
MAC
&
other
)
const
{
for
(
int
i
=
0
;
i
<
6
;
i
++
)
{
for
(
int
i
=
0
;
i
<
6
;
i
++
)
{
...
@@ -57,15 +58,14 @@ struct MAC {
...
@@ -57,15 +58,14 @@ struct MAC {
};
};
namespace
std
{
namespace
std
{
template
<
>
template
<
>
struct
hash
<
MAC
>
struct
hash
<
MAC
>
{
{
size_t
operator
()(
const
MAC
&
m
)
const
{
size_t
operator
()(
const
MAC
&
m
)
const
{
size_t
res
=
0
;
size_t
res
=
0
;
for
(
int
i
=
0
;
i
<
6
;
i
++
)
{
for
(
int
i
=
0
;
i
<
6
;
i
++
)
{
res
=
(
res
<<
4
)
|
(
res
^
m
.
data
[
i
]);
res
=
(
res
<<
4
)
|
(
res
^
m
.
data
[
i
]);
}
}
return
res
;
return
res
;
}
}
};
};
}
// namespace std
}
// namespace std
...
@@ -77,13 +77,12 @@ static const MAC bcast_addr(bcast);
...
@@ -77,13 +77,12 @@ static const MAC bcast_addr(bcast);
static
std
::
vector
<
struct
netsim_interface
>
nsifs
;
static
std
::
vector
<
struct
netsim_interface
>
nsifs
;
static
std
::
unordered_map
<
MAC
,
int
>
mac_table
;
static
std
::
unordered_map
<
MAC
,
int
>
mac_table
;
static
void
sigint_handler
(
int
dummy
)
static
void
sigint_handler
(
int
dummy
)
{
{
exiting
=
1
;
exiting
=
1
;
}
}
static
void
forward_pkt
(
volatile
struct
cosim_eth_proto_d2n_send
*
tx
,
int
port
)
static
void
forward_pkt
(
volatile
struct
cosim_eth_proto_d2n_send
*
tx
,
{
int
port
)
{
volatile
union
cosim_eth_proto_n2d
*
msg_to
;
volatile
union
cosim_eth_proto_n2d
*
msg_to
;
msg_to
=
netsim_n2d_alloc
(
&
nsifs
[
port
],
cur_ts
,
eth_latency
);
msg_to
=
netsim_n2d_alloc
(
&
nsifs
[
port
],
cur_ts
,
eth_latency
);
if
(
msg_to
!=
NULL
)
{
if
(
msg_to
!=
NULL
)
{
...
@@ -94,17 +93,14 @@ static void forward_pkt(volatile struct cosim_eth_proto_d2n_send *tx, int port)
...
@@ -94,17 +93,14 @@ static void forward_pkt(volatile struct cosim_eth_proto_d2n_send *tx, int port)
memcpy
((
void
*
)
rx
->
data
,
(
void
*
)
tx
->
data
,
tx
->
len
);
memcpy
((
void
*
)
rx
->
data
,
(
void
*
)
tx
->
data
,
tx
->
len
);
// WMB();
// WMB();
rx
->
own_type
=
COSIM_ETH_PROTO_N2D_MSG_RECV
|
rx
->
own_type
=
COSIM_ETH_PROTO_N2D_MSG_RECV
|
COSIM_ETH_PROTO_N2D_OWN_DEV
;
COSIM_ETH_PROTO_N2D_OWN_DEV
;
}
else
{
}
else
{
fprintf
(
stderr
,
"forward_pkt: dropping packet
\n
"
);
fprintf
(
stderr
,
"forward_pkt: dropping packet
\n
"
);
}
}
}
}
static
void
switch_pkt
(
struct
netsim_interface
*
nsif
,
int
iport
)
static
void
switch_pkt
(
struct
netsim_interface
*
nsif
,
int
iport
)
{
{
volatile
union
cosim_eth_proto_d2n
*
msg_from
=
netsim_d2n_poll
(
nsif
,
cur_ts
);
volatile
union
cosim_eth_proto_d2n
*
msg_from
=
netsim_d2n_poll
(
nsif
,
cur_ts
);
if
(
msg_from
==
NULL
)
{
if
(
msg_from
==
NULL
)
{
return
;
return
;
}
}
...
@@ -114,7 +110,7 @@ static void switch_pkt(struct netsim_interface *nsif, int iport)
...
@@ -114,7 +110,7 @@ static void switch_pkt(struct netsim_interface *nsif, int iport)
volatile
struct
cosim_eth_proto_d2n_send
*
tx
;
volatile
struct
cosim_eth_proto_d2n_send
*
tx
;
tx
=
&
msg_from
->
send
;
tx
=
&
msg_from
->
send
;
// Get MAC addresses
// Get MAC addresses
MAC
dst
(
tx
->
data
),
src
(
tx
->
data
+
6
);
MAC
dst
(
tx
->
data
),
src
(
tx
->
data
+
6
);
// MAC learning
// MAC learning
if
(
!
(
src
==
bcast_addr
))
{
if
(
!
(
src
==
bcast_addr
))
{
mac_table
[
src
]
=
iport
;
mac_table
[
src
]
=
iport
;
...
@@ -140,8 +136,7 @@ static void switch_pkt(struct netsim_interface *nsif, int iport)
...
@@ -140,8 +136,7 @@ static void switch_pkt(struct netsim_interface *nsif, int iport)
netsim_d2n_done
(
nsif
,
msg_from
);
netsim_d2n_done
(
nsif
,
msg_from
);
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
int
c
;
int
c
;
int
bad_option
=
0
;
int
bad_option
=
0
;
int
sync_mode
=
SYNC_MODES
;
int
sync_mode
=
SYNC_MODES
;
...
@@ -181,7 +176,8 @@ int main(int argc, char *argv[])
...
@@ -181,7 +176,8 @@ int main(int argc, char *argv[])
}
}
if
(
nsifs
.
empty
()
||
bad_option
)
{
if
(
nsifs
.
empty
()
||
bad_option
)
{
fprintf
(
stderr
,
"Usage: net_switch [-S SYNC-PERIOD] [-E ETH-LATENCY] "
fprintf
(
stderr
,
"Usage: net_switch [-S SYNC-PERIOD] [-E ETH-LATENCY] "
"-s SOCKET-A [-s SOCKET-B ...]
\n
"
);
"-s SOCKET-A [-s SOCKET-B ...]
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
...
@@ -193,8 +189,8 @@ int main(int argc, char *argv[])
...
@@ -193,8 +189,8 @@ int main(int argc, char *argv[])
while
(
!
exiting
)
{
while
(
!
exiting
)
{
// Sync all interfaces
// Sync all interfaces
for
(
auto
&
nsif
:
nsifs
)
{
for
(
auto
&
nsif
:
nsifs
)
{
if
(
netsim_n2d_sync
(
&
nsif
,
cur_ts
,
eth_latency
,
if
(
netsim_n2d_sync
(
&
nsif
,
cur_ts
,
eth_latency
,
sync_period
,
sync_mode
)
!=
sync_period
,
sync_mode
)
!=
0
)
{
0
)
{
fprintf
(
stderr
,
"netsim_n2d_sync failed
\n
"
);
fprintf
(
stderr
,
"netsim_n2d_sync failed
\n
"
);
abort
();
abort
();
}
}
...
...
sims/net/tap/net_tap.c
View file @
d4666c97
...
@@ -23,15 +23,15 @@
...
@@ -23,15 +23,15 @@
*/
*/
#include <fcntl.h>
#include <fcntl.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <pthread.h>
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mman.h>
#include <unistd.h>
#include <unistd.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <simbricks/netif/netsim.h>
#include <simbricks/netif/netsim.h>
...
@@ -40,8 +40,7 @@
...
@@ -40,8 +40,7 @@
static
struct
netsim_interface
nsif
;
static
struct
netsim_interface
nsif
;
static
int
tap_fd
;
static
int
tap_fd
;
static
int
tap_open
(
const
char
*
name
)
static
int
tap_open
(
const
char
*
name
)
{
{
struct
ifreq
ifr
;
struct
ifreq
ifr
;
int
fd
;
int
fd
;
...
@@ -63,19 +62,17 @@ static int tap_open(const char *name)
...
@@ -63,19 +62,17 @@ static int tap_open(const char *name)
return
fd
;
return
fd
;
}
}
static
void
d2n_send
(
volatile
struct
cosim_eth_proto_d2n_send
*
s
)
static
void
d2n_send
(
volatile
struct
cosim_eth_proto_d2n_send
*
s
)
{
{
#ifdef DEBUG_PKTMETA
#ifdef DEBUG_PKTMETA
printf
(
"sent packet: len=%u
\n
"
,
s
->
len
);
printf
(
"sent packet: len=%u
\n
"
,
s
->
len
);
#endif
#endif
if
(
write
(
tap_fd
,
(
void
*
)
s
->
data
,
s
->
len
)
!=
(
ssize_t
)
s
->
len
)
{
if
(
write
(
tap_fd
,
(
void
*
)
s
->
data
,
s
->
len
)
!=
(
ssize_t
)
s
->
len
)
{
perror
(
"d2n_send: send failed"
);
perror
(
"d2n_send: send failed"
);
}
}
}
}
static
void
poll_d2n
(
void
)
static
void
poll_d2n
(
void
)
{
{
volatile
union
cosim_eth_proto_d2n
*
msg
=
netsim_d2n_poll
(
&
nsif
,
0
);
volatile
union
cosim_eth_proto_d2n
*
msg
=
netsim_d2n_poll
(
&
nsif
,
0
);
uint8_t
type
;
uint8_t
type
;
...
@@ -96,8 +93,7 @@ static void poll_d2n(void)
...
@@ -96,8 +93,7 @@ static void poll_d2n(void)
netsim_d2n_done
(
&
nsif
,
msg
);
netsim_d2n_done
(
&
nsif
,
msg
);
}
}
static
void
*
rx_handler
(
void
*
arg
)
static
void
*
rx_handler
(
void
*
arg
)
{
{
volatile
union
cosim_eth_proto_n2d
*
msg
;
volatile
union
cosim_eth_proto_n2d
*
msg
;
volatile
struct
cosim_eth_proto_n2d_recv
*
rx
;
volatile
struct
cosim_eth_proto_n2d_recv
*
rx
;
ssize_t
len
;
ssize_t
len
;
...
@@ -110,7 +106,7 @@ static void *rx_handler(void *arg)
...
@@ -110,7 +106,7 @@ static void *rx_handler(void *arg)
}
}
rx
=
&
msg
->
recv
;
rx
=
&
msg
->
recv
;
len
=
read
(
tap_fd
,
(
void
*
)
rx
->
data
,
nsif
.
n2d_elen
-
sizeof
(
*
msg
));
len
=
read
(
tap_fd
,
(
void
*
)
rx
->
data
,
nsif
.
n2d_elen
-
sizeof
(
*
msg
));
if
(
len
<=
0
)
{
if
(
len
<=
0
)
{
perror
(
"rx handler: read failed"
);
perror
(
"rx handler: read failed"
);
}
}
...
@@ -121,13 +117,11 @@ static void *rx_handler(void *arg)
...
@@ -121,13 +117,11 @@ static void *rx_handler(void *arg)
#endif
#endif
// WMB();
// WMB();
rx
->
own_type
=
COSIM_ETH_PROTO_N2D_MSG_RECV
|
rx
->
own_type
=
COSIM_ETH_PROTO_N2D_MSG_RECV
|
COSIM_ETH_PROTO_N2D_OWN_DEV
;
COSIM_ETH_PROTO_N2D_OWN_DEV
;
}
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
int
sync
;
int
sync
;
if
(
argc
!=
3
)
{
if
(
argc
!=
3
)
{
...
...
sims/net/wire/net_wire.c
View file @
d4666c97
...
@@ -22,19 +22,19 @@
...
@@ -22,19 +22,19 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
*/
#include <assert.h>
#include <fcntl.h>
#include <fcntl.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <pcap/pcap.h>
#include <pthread.h>
#include <pthread.h>
#include <s
tdlib
.h>
#include <s
ignal
.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/mman.h>
#include <unistd.h>
#include <unistd.h>
#include <linux/if.h>
#include <linux/if_tun.h>
#include <pcap/pcap.h>
#include <assert.h>
#include <simbricks/netif/netsim.h>
#include <simbricks/netif/netsim.h>
...
@@ -44,20 +44,17 @@ static uint64_t cur_ts;
...
@@ -44,20 +44,17 @@ static uint64_t cur_ts;
static
int
exiting
=
0
;
static
int
exiting
=
0
;
static
pcap_dumper_t
*
dumpfile
=
NULL
;
static
pcap_dumper_t
*
dumpfile
=
NULL
;
static
void
sigint_handler
(
int
dummy
)
static
void
sigint_handler
(
int
dummy
)
{
{
exiting
=
1
;
exiting
=
1
;
}
}
static
void
sigusr1_handler
(
int
dummy
)
static
void
sigusr1_handler
(
int
dummy
)
{
{
fprintf
(
stderr
,
"main_time = %lu
\n
"
,
cur_ts
);
fprintf
(
stderr
,
"main_time = %lu
\n
"
,
cur_ts
);
}
}
static
void
move_pkt
(
struct
netsim_interface
*
from
,
struct
netsim_interface
*
to
)
static
void
move_pkt
(
struct
netsim_interface
*
from
,
{
struct
netsim_interface
*
to
)
{
volatile
union
cosim_eth_proto_d2n
*
msg_from
=
volatile
union
cosim_eth_proto_d2n
*
msg_from
=
netsim_d2n_poll
(
from
,
cur_ts
);
netsim_d2n_poll
(
from
,
cur_ts
);
volatile
union
cosim_eth_proto_n2d
*
msg_to
;
volatile
union
cosim_eth_proto_n2d
*
msg_to
;
volatile
struct
cosim_eth_proto_d2n_send
*
tx
;
volatile
struct
cosim_eth_proto_d2n_send
*
tx
;
volatile
struct
cosim_eth_proto_n2d_recv
*
rx
;
volatile
struct
cosim_eth_proto_n2d_recv
*
rx
;
...
@@ -78,8 +75,7 @@ static void move_pkt(struct netsim_interface *from, struct netsim_interface *to)
...
@@ -78,8 +75,7 @@ static void move_pkt(struct netsim_interface *from, struct netsim_interface *to)
ph
.
ts
.
tv_usec
=
(
cur_ts
%
1000000000000ULL
)
/
1000ULL
;
ph
.
ts
.
tv_usec
=
(
cur_ts
%
1000000000000ULL
)
/
1000ULL
;
ph
.
caplen
=
tx
->
len
;
ph
.
caplen
=
tx
->
len
;
ph
.
len
=
tx
->
len
;
ph
.
len
=
tx
->
len
;
pcap_dump
((
unsigned
char
*
)
dumpfile
,
&
ph
,
pcap_dump
((
unsigned
char
*
)
dumpfile
,
&
ph
,
(
unsigned
char
*
)
tx
->
data
);
(
unsigned
char
*
)
tx
->
data
);
}
}
msg_to
=
netsim_n2d_alloc
(
to
,
cur_ts
,
eth_latency
);
msg_to
=
netsim_n2d_alloc
(
to
,
cur_ts
,
eth_latency
);
...
@@ -87,11 +83,10 @@ static void move_pkt(struct netsim_interface *from, struct netsim_interface *to)
...
@@ -87,11 +83,10 @@ static void move_pkt(struct netsim_interface *from, struct netsim_interface *to)
rx
=
&
msg_to
->
recv
;
rx
=
&
msg_to
->
recv
;
rx
->
len
=
tx
->
len
;
rx
->
len
=
tx
->
len
;
rx
->
port
=
0
;
rx
->
port
=
0
;
memcpy
((
void
*
)
rx
->
data
,
(
void
*
)
tx
->
data
,
tx
->
len
);
memcpy
((
void
*
)
rx
->
data
,
(
void
*
)
tx
->
data
,
tx
->
len
);
// WMB();
// WMB();
rx
->
own_type
=
COSIM_ETH_PROTO_N2D_MSG_RECV
|
rx
->
own_type
=
COSIM_ETH_PROTO_N2D_MSG_RECV
|
COSIM_ETH_PROTO_N2D_OWN_DEV
;
COSIM_ETH_PROTO_N2D_OWN_DEV
;
}
else
{
}
else
{
fprintf
(
stderr
,
"move_pkt: dropping packet
\n
"
);
fprintf
(
stderr
,
"move_pkt: dropping packet
\n
"
);
}
}
...
@@ -104,8 +99,7 @@ static void move_pkt(struct netsim_interface *from, struct netsim_interface *to)
...
@@ -104,8 +99,7 @@ static void move_pkt(struct netsim_interface *from, struct netsim_interface *to)
netsim_d2n_done
(
from
,
msg_from
);
netsim_d2n_done
(
from
,
msg_from
);
}
}
int
main
(
int
argc
,
char
*
argv
[])
int
main
(
int
argc
,
char
*
argv
[])
{
{
struct
netsim_interface
nsif_a
,
nsif_b
;
struct
netsim_interface
nsif_a
,
nsif_b
;
uint64_t
ts_a
,
ts_b
;
uint64_t
ts_a
,
ts_b
;
int
sync_a
,
sync_b
;
int
sync_a
,
sync_b
;
...
@@ -113,7 +107,8 @@ int main(int argc, char *argv[])
...
@@ -113,7 +107,8 @@ int main(int argc, char *argv[])
int
sync_mode
=
SYNC_MODES
;
int
sync_mode
=
SYNC_MODES
;
if
(
argc
<
3
&&
argc
>
7
)
{
if
(
argc
<
3
&&
argc
>
7
)
{
fprintf
(
stderr
,
"Usage: net_wire SOCKET-A SOCKET-B [SYNC-MODE] "
fprintf
(
stderr
,
"Usage: net_wire SOCKET-A SOCKET-B [SYNC-MODE] "
"[SYNC-PERIOD] [ETH-LATENCY] [PCAP-FILE]
\n
"
);
"[SYNC-PERIOD] [ETH-LATENCY] [PCAP-FILE]
\n
"
);
return
EXIT_FAILURE
;
return
EXIT_FAILURE
;
}
}
...
@@ -154,13 +149,13 @@ int main(int argc, char *argv[])
...
@@ -154,13 +149,13 @@ int main(int argc, char *argv[])
printf
(
"start polling
\n
"
);
printf
(
"start polling
\n
"
);
while
(
!
exiting
)
{
while
(
!
exiting
)
{
if
(
netsim_n2d_sync
(
&
nsif_a
,
cur_ts
,
eth_latency
,
sync_period
,
if
(
netsim_n2d_sync
(
&
nsif_a
,
cur_ts
,
eth_latency
,
sync_period
,
sync_mode
)
!=
sync_mode
)
!=
0
)
{
0
)
{
fprintf
(
stderr
,
"netsim_n2d_sync(nsif_a) failed
\n
"
);
fprintf
(
stderr
,
"netsim_n2d_sync(nsif_a) failed
\n
"
);
abort
();
abort
();
}
}
if
(
netsim_n2d_sync
(
&
nsif_b
,
cur_ts
,
eth_latency
,
sync_period
,
if
(
netsim_n2d_sync
(
&
nsif_b
,
cur_ts
,
eth_latency
,
sync_period
,
sync_mode
)
!=
sync_mode
)
!=
0
)
{
0
)
{
fprintf
(
stderr
,
"netsim_n2d_sync(nsif_a) failed
\n
"
);
fprintf
(
stderr
,
"netsim_n2d_sync(nsif_a) failed
\n
"
);
abort
();
abort
();
}
}
...
@@ -172,12 +167,11 @@ int main(int argc, char *argv[])
...
@@ -172,12 +167,11 @@ int main(int argc, char *argv[])
ts_a
=
netsim_d2n_timestamp
(
&
nsif_a
);
ts_a
=
netsim_d2n_timestamp
(
&
nsif_a
);
ts_b
=
netsim_d2n_timestamp
(
&
nsif_b
);
ts_b
=
netsim_d2n_timestamp
(
&
nsif_b
);
}
while
(
!
exiting
&&
}
while
(
!
exiting
&&
((
sync_a
&&
ts_a
<=
cur_ts
)
||
((
sync_a
&&
ts_a
<=
cur_ts
)
||
(
sync_b
&&
ts_b
<=
cur_ts
)));
(
sync_b
&&
ts_b
<=
cur_ts
)));
if
(
sync_a
&&
sync_b
)
if
(
sync_a
&&
sync_b
)
cur_ts
=
netsim_advance_time
(
ts_a
<=
ts_b
?
ts_a
:
ts_b
,
cur_ts
=
netsim_advance_time
(
ts_a
<=
ts_b
?
ts_a
:
ts_b
,
sync_period
,
sync_period
,
sync_mode
);
sync_mode
);
else
if
(
sync_a
)
else
if
(
sync_a
)
cur_ts
=
netsim_advance_time
(
ts_a
,
sync_period
,
sync_mode
);
cur_ts
=
netsim_advance_time
(
ts_a
,
sync_period
,
sync_mode
);
else
if
(
sync_b
)
else
if
(
sync_b
)
...
...
sims/nic/corundum/coord.h
View file @
d4666c97
...
@@ -26,8 +26,8 @@
...
@@ -26,8 +26,8 @@
#define COORD_H_
#define COORD_H_
#include <deque>
#include <deque>
#include <map>
#include <iostream>
#include <iostream>
#include <map>
#include "sims/nic/corundum/debug.h"
#include "sims/nic/corundum/debug.h"
...
@@ -57,8 +57,7 @@ class PCICoordinator {
...
@@ -57,8 +57,7 @@ class PCICoordinator {
std
::
deque
<
PCIOp
*>
queue
;
std
::
deque
<
PCIOp
*>
queue
;
std
::
map
<
DMAOp
*
,
PCIOp
*>
dmamap
;
std
::
map
<
DMAOp
*
,
PCIOp
*>
dmamap
;
void
process
()
void
process
()
{
{
PCIOp
*
op
;
PCIOp
*
op
;
while
(
!
queue
.
empty
())
{
while
(
!
queue
.
empty
())
{
op
=
queue
.
front
();
op
=
queue
.
front
();
...
@@ -68,21 +67,18 @@ class PCICoordinator {
...
@@ -68,21 +67,18 @@ class PCICoordinator {
queue
.
pop_front
();
queue
.
pop_front
();
if
(
op
->
type
==
PCIOp
::
OP_MSI
)
{
if
(
op
->
type
==
PCIOp
::
OP_MSI
)
{
#ifdef COORD_DEBUG
#ifdef COORD_DEBUG
std
::
cout
<<
main_time
<<
" issuing msi "
<<
op
->
msi_vec
<<
std
::
cout
<<
main_time
<<
" issuing msi "
<<
op
->
msi_vec
<<
std
::
endl
;
std
::
endl
;
#endif
#endif
pci_msi_issue
(
op
->
msi_vec
);
pci_msi_issue
(
op
->
msi_vec
);
}
else
if
(
op
->
type
==
PCIOp
::
OP_DMA
)
{
}
else
if
(
op
->
type
==
PCIOp
::
OP_DMA
)
{
#ifdef COORD_DEBUG
#ifdef COORD_DEBUG
std
::
cout
<<
main_time
<<
" issuing dma "
<<
op
->
dma_op
<<
std
::
cout
<<
main_time
<<
" issuing dma "
<<
op
->
dma_op
<<
std
::
endl
;
std
::
endl
;
#endif
#endif
pci_dma_issue
(
op
->
dma_op
);
pci_dma_issue
(
op
->
dma_op
);
dmamap
.
erase
(
op
->
dma_op
);
dmamap
.
erase
(
op
->
dma_op
);
}
else
if
(
op
->
type
==
PCIOp
::
OP_RWCOMP
)
{
}
else
if
(
op
->
type
==
PCIOp
::
OP_RWCOMP
)
{
#ifdef COORD_DEBUG
#ifdef COORD_DEBUG
std
::
cout
<<
main_time
<<
" issuing mmio "
<<
op
->
mmio_op
<<
std
::
cout
<<
main_time
<<
" issuing mmio "
<<
op
->
mmio_op
<<
std
::
endl
;
std
::
endl
;
#endif
#endif
pci_rwcomp_issue
(
op
->
mmio_op
);
pci_rwcomp_issue
(
op
->
mmio_op
);
}
else
{
}
else
{
...
@@ -94,11 +90,10 @@ class PCICoordinator {
...
@@ -94,11 +90,10 @@ class PCICoordinator {
}
}
public:
public:
void
dma_register
(
DMAOp
*
dma_op
,
bool
ready
)
void
dma_register
(
DMAOp
*
dma_op
,
bool
ready
)
{
{
#ifdef COORD_DEBUG
#ifdef COORD_DEBUG
std
::
cout
<<
main_time
<<
" registering dma op "
<<
dma_op
<<
" "
std
::
cout
<<
main_time
<<
" registering dma op "
<<
dma_op
<<
" "
<<
ready
<<
ready
<<
std
::
endl
;
<<
std
::
endl
;
#endif
#endif
PCIOp
*
op
=
new
PCIOp
;
PCIOp
*
op
=
new
PCIOp
;
op
->
dma_op
=
dma_op
;
op
->
dma_op
=
dma_op
;
...
@@ -111,8 +106,7 @@ class PCICoordinator {
...
@@ -111,8 +106,7 @@ class PCICoordinator {
process
();
process
();
}
}
void
dma_mark_ready
(
DMAOp
*
op
)
void
dma_mark_ready
(
DMAOp
*
op
)
{
{
#ifdef COORD_DEBUG
#ifdef COORD_DEBUG
std
::
cout
<<
main_time
<<
" readying dma op "
<<
op
<<
std
::
endl
;
std
::
cout
<<
main_time
<<
" readying dma op "
<<
op
<<
std
::
endl
;
#endif
#endif
...
@@ -121,8 +115,7 @@ class PCICoordinator {
...
@@ -121,8 +115,7 @@ class PCICoordinator {
process
();
process
();
}
}
void
msi_enqueue
(
uint32_t
vec
)
void
msi_enqueue
(
uint32_t
vec
)
{
{
#ifdef COORD_DEBUG
#ifdef COORD_DEBUG
std
::
cout
<<
main_time
<<
" enqueuing MSI "
<<
vec
<<
std
::
endl
;
std
::
cout
<<
main_time
<<
" enqueuing MSI "
<<
vec
<<
std
::
endl
;
#endif
#endif
...
@@ -135,11 +128,9 @@ class PCICoordinator {
...
@@ -135,11 +128,9 @@ class PCICoordinator {
process
();
process
();
}
}
void
mmio_comp_enqueue
(
MMIOOp
*
mmio_op
)
void
mmio_comp_enqueue
(
MMIOOp
*
mmio_op
)
{
{
#ifdef COORD_DEBUG
#ifdef COORD_DEBUG
std
::
cout
<<
main_time
<<
" enqueuing MMIO comp "
<<
mmio_op
<<
std
::
cout
<<
main_time
<<
" enqueuing MMIO comp "
<<
mmio_op
<<
std
::
endl
;
std
::
endl
;
#endif
#endif
PCIOp
*
op
=
new
PCIOp
;
PCIOp
*
op
=
new
PCIOp
;
op
->
mmio_op
=
mmio_op
;
op
->
mmio_op
=
mmio_op
;
...
...
sims/nic/corundum/corundum_verilator.cc
View file @
d4666c97
This diff is collapsed.
Click to expand it.
sims/nic/corundum/dma.cc
View file @
d4666c97
...
@@ -22,16 +22,15 @@
...
@@ -22,16 +22,15 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
*/
#include "sims/nic/corundum/dma.h"
#include <iostream>
#include <iostream>
#include "sims/nic/corundum/debug.h"
#include "sims/nic/corundum/corundum.h"
#include "sims/nic/corundum/corundum.h"
#include "sims/nic/corundum/d
ma
.h"
#include "sims/nic/corundum/d
ebug
.h"
#include "sims/nic/corundum/mem.h"
#include "sims/nic/corundum/mem.h"
void
DMAReader
::
step
()
{
void
DMAReader
::
step
()
{
p
.
dma_ready
=
1
;
p
.
dma_ready
=
1
;
if
(
p
.
dma_valid
)
{
if
(
p
.
dma_valid
)
{
DMAOp
*
op
=
new
DMAOp
;
DMAOp
*
op
=
new
DMAOp
;
...
@@ -45,9 +44,9 @@ void DMAReader::step()
...
@@ -45,9 +44,9 @@ void DMAReader::step()
pending
.
insert
(
op
);
pending
.
insert
(
op
);
#ifdef DMA_DEBUG
#ifdef DMA_DEBUG
std
::
cout
<<
main_time
<<
" dma["
<<
label
<<
"] op "
<<
std
::
hex
<<
std
::
cout
<<
main_time
<<
" dma["
<<
label
<<
"] op "
<<
std
::
hex
op
->
dma_addr
<<
" -> "
<<
op
->
ram_sel
<<
":"
<<
op
->
ram_addr
<<
<<
op
->
dma_addr
<<
" -> "
<<
op
->
ram_sel
<<
":"
<<
op
->
ram_addr
" len="
<<
op
->
len
<<
" tag="
<<
(
int
)
op
->
tag
<<
std
::
endl
;
<<
" len="
<<
op
->
len
<<
" tag="
<<
(
int
)
op
->
tag
<<
std
::
endl
;
#endif
#endif
coord
.
dma_register
(
op
,
true
);
coord
.
dma_register
(
op
,
true
);
...
@@ -68,22 +67,17 @@ void DMAReader::step()
...
@@ -68,22 +67,17 @@ void DMAReader::step()
}
}
}
}
void
DMAReader
::
pci_op_complete
(
DMAOp
*
op
)
void
DMAReader
::
pci_op_complete
(
DMAOp
*
op
)
{
{
mw
.
op_issue
(
op
);
mw
.
op_issue
(
op
);
}
}
void
DMAReader
::
mem_op_complete
(
DMAOp
*
op
)
void
DMAReader
::
mem_op_complete
(
DMAOp
*
op
)
{
{
completed
.
push_back
(
op
);
completed
.
push_back
(
op
);
// std::cout << "dma[" << label << "] mem complete " << op->dma_addr <<
// std::cout << "dma[" << label << "] mem complete " << op->dma_addr <<
// std::endl;
// std::endl;
}
}
void
DMAWriter
::
step
()
{
void
DMAWriter
::
step
()
{
p
.
dma_ready
=
1
;
p
.
dma_ready
=
1
;
if
(
p
.
dma_valid
)
{
if
(
p
.
dma_valid
)
{
DMAOp
*
op
=
new
DMAOp
;
DMAOp
*
op
=
new
DMAOp
;
...
@@ -97,10 +91,9 @@ void DMAWriter::step()
...
@@ -97,10 +91,9 @@ void DMAWriter::step()
pending
.
insert
(
op
);
pending
.
insert
(
op
);
#ifdef DMA_DEBUG
#ifdef DMA_DEBUG
std
::
cout
<<
main_time
<<
" dma write ["
<<
label
<<
"] op "
<<
std
::
cout
<<
main_time
<<
" dma write ["
<<
label
<<
"] op "
<<
std
::
hex
std
::
hex
<<
op
->
dma_addr
<<
" -> "
<<
op
->
ram_sel
<<
":"
<<
<<
op
->
dma_addr
<<
" -> "
<<
op
->
ram_sel
<<
":"
<<
op
->
ram_addr
op
->
ram_addr
<<
" len="
<<
op
->
len
<<
" tag="
<<
(
int
)
op
->
tag
<<
" len="
<<
op
->
len
<<
" tag="
<<
(
int
)
op
->
tag
<<
std
::
endl
;
<<
std
::
endl
;
#endif
#endif
coord
.
dma_register
(
op
,
false
);
coord
.
dma_register
(
op
,
false
);
...
@@ -113,8 +106,8 @@ void DMAWriter::step()
...
@@ -113,8 +106,8 @@ void DMAWriter::step()
completed
.
pop_front
();
completed
.
pop_front
();
#ifdef DMA_DEBUG
#ifdef DMA_DEBUG
std
::
cout
<<
main_time
<<
" dma write ["
<<
label
<<
std
::
cout
<<
main_time
<<
" dma write ["
<<
label
<<
"] status complete "
"] status complete "
<<
op
->
dma_addr
<<
std
::
endl
;
<<
op
->
dma_addr
<<
std
::
endl
;
#endif
#endif
p
.
dma_status_valid
=
1
;
p
.
dma_status_valid
=
1
;
...
@@ -125,22 +118,20 @@ void DMAWriter::step()
...
@@ -125,22 +118,20 @@ void DMAWriter::step()
}
}
}
}
void
DMAWriter
::
pci_op_complete
(
DMAOp
*
op
)
void
DMAWriter
::
pci_op_complete
(
DMAOp
*
op
)
{
{
#ifdef DMA_DEBUG
#ifdef DMA_DEBUG
std
::
cout
<<
main_time
<<
" dma write ["
<<
label
<<
"] pci complete "
<<
std
::
cout
<<
main_time
<<
" dma write ["
<<
label
<<
"] pci complete "
op
->
dma_addr
<<
std
::
endl
;
<<
op
->
dma_addr
<<
std
::
endl
;
#endif
#endif
completed
.
push_back
(
op
);
completed
.
push_back
(
op
);
}
}
void
DMAWriter
::
mem_op_complete
(
DMAOp
*
op
)
void
DMAWriter
::
mem_op_complete
(
DMAOp
*
op
)
{
{
#ifdef DMA_DEBUG
#ifdef DMA_DEBUG
std
::
cout
<<
main_time
<<
" dma write ["
<<
label
<<
"] mem complete "
<<
std
::
cout
<<
main_time
<<
" dma write ["
<<
label
<<
"] mem complete "
op
->
dma_addr
<<
": "
;
<<
op
->
dma_addr
<<
": "
;
for
(
size_t
i
=
0
;
i
<
op
->
len
;
i
++
)
for
(
size_t
i
=
0
;
i
<
op
->
len
;
i
++
)
std
::
cout
<<
(
unsigned
)
op
->
data
[
i
]
<<
" "
;
std
::
cout
<<
(
unsigned
)
op
->
data
[
i
]
<<
" "
;
std
::
cout
<<
std
::
endl
;
std
::
cout
<<
std
::
endl
;
#endif
#endif
coord
.
dma_mark_ready
(
op
);
coord
.
dma_mark_ready
(
op
);
...
...
sims/nic/corundum/dma.h
View file @
d4666c97
...
@@ -25,15 +25,14 @@
...
@@ -25,15 +25,14 @@
#ifndef DMA_H_
#ifndef DMA_H_
#define DMA_H_
#define DMA_H_
#include <set>
#include <deque>
#include <verilated.h>
#include <verilated.h>
#include "sims/nic/corundum/obj_dir/Vinterface.h"
#include <deque>
#include <set>
#include "sims/nic/corundum/debug.h"
#include "sims/nic/corundum/coord.h"
#include "sims/nic/corundum/coord.h"
#include "sims/nic/corundum/debug.h"
#include "sims/nic/corundum/obj_dir/Vinterface.h"
#define MAX_DMA_LEN 2048
#define MAX_DMA_LEN 2048
...
@@ -55,18 +54,19 @@ struct DMAPorts {
...
@@ -55,18 +54,19 @@ struct DMAPorts {
vluint8_t
&
dma_status_tag
;
vluint8_t
&
dma_status_tag
;
vluint8_t
&
dma_status_valid
;
vluint8_t
&
dma_status_valid
;
DMAPorts
(
vluint64_t
&
dma_addr_
,
vluint8_t
&
dma_ram_sel_
,
DMAPorts
(
vluint64_t
&
dma_addr_
,
vluint8_t
&
dma_ram_sel_
,
vluint32_t
&
dma_ram_addr_
,
vluint16_t
&
dma_len_
,
vluint32_t
&
dma_ram_addr_
,
vluint16_t
&
dma_len_
,
vluint8_t
&
dma_tag_
,
vluint8_t
&
dma_tag_
,
vluint8_t
&
dma_valid_
,
vluint8_t
&
dma_valid_
,
vluint8_t
&
dma_ready_
,
vluint8_t
&
dma_ready_
,
vluint8_t
&
dma_status_tag_
,
vluint8_t
&
dma_status_tag_
,
vluint8_t
&
dma_status_valid_
)
vluint8_t
&
dma_status_valid_
)
:
dma_addr
(
dma_addr_
),
:
dma_addr
(
dma_addr_
),
dma_ram_sel
(
dma_ram_sel_
),
dma_ram_sel
(
dma_ram_sel_
),
dma_ram_addr
(
dma_ram_addr_
),
dma_len
(
dma_len_
),
dma_ram_addr
(
dma_ram_addr_
),
dma_tag
(
dma_tag_
),
dma_valid
(
dma_valid_
),
dma_len
(
dma_len_
),
dma_ready
(
dma_ready_
),
dma_status_tag
(
dma_status_tag_
),
dma_tag
(
dma_tag_
),
dma_status_valid
(
dma_status_valid_
)
dma_valid
(
dma_valid_
),
{
dma_ready
(
dma_ready_
),
dma_status_tag
(
dma_status_tag_
),
dma_status_valid
(
dma_status_valid_
)
{
}
}
};
};
...
@@ -86,8 +86,8 @@ class DMAEngine {
...
@@ -86,8 +86,8 @@ class DMAEngine {
DMAPorts
&
p
;
DMAPorts
&
p
;
PCICoordinator
&
coord
;
PCICoordinator
&
coord
;
DMAEngine
(
DMAPorts
&
p_
,
PCICoordinator
&
coord_
)
DMAEngine
(
DMAPorts
&
p_
,
PCICoordinator
&
coord_
)
:
p
(
p_
),
coord
(
coord_
)
{
:
p
(
p_
),
coord
(
coord_
)
{
}
}
public:
public:
virtual
void
pci_op_complete
(
DMAOp
*
op
)
=
0
;
virtual
void
pci_op_complete
(
DMAOp
*
op
)
=
0
;
...
@@ -104,8 +104,7 @@ class DMAReader : public DMAEngine {
...
@@ -104,8 +104,7 @@ class DMAReader : public DMAEngine {
public:
public:
DMAReader
(
const
char
*
label_
,
DMAPorts
&
p_
,
MemWriter
&
mw_
,
DMAReader
(
const
char
*
label_
,
DMAPorts
&
p_
,
MemWriter
&
mw_
,
PCICoordinator
&
coord_
)
PCICoordinator
&
coord_
)
:
DMAEngine
(
p_
,
coord_
),
label
(
label_
),
mw
(
mw_
)
:
DMAEngine
(
p_
,
coord_
),
label
(
label_
),
mw
(
mw_
)
{
{
}
}
virtual
void
pci_op_complete
(
DMAOp
*
op
);
virtual
void
pci_op_complete
(
DMAOp
*
op
);
...
@@ -123,8 +122,7 @@ class DMAWriter : public DMAEngine {
...
@@ -123,8 +122,7 @@ class DMAWriter : public DMAEngine {
public:
public:
DMAWriter
(
const
char
*
label_
,
DMAPorts
&
p_
,
MemReader
&
mr_
,
DMAWriter
(
const
char
*
label_
,
DMAPorts
&
p_
,
MemReader
&
mr_
,
PCICoordinator
&
coord_
)
PCICoordinator
&
coord_
)
:
DMAEngine
(
p_
,
coord_
),
label
(
label_
),
mr
(
mr_
)
:
DMAEngine
(
p_
,
coord_
),
label
(
label_
),
mr
(
mr_
)
{
{
}
}
virtual
void
pci_op_complete
(
DMAOp
*
op
);
virtual
void
pci_op_complete
(
DMAOp
*
op
);
...
@@ -132,5 +130,4 @@ class DMAWriter : public DMAEngine {
...
@@ -132,5 +130,4 @@ class DMAWriter : public DMAEngine {
void
step
();
void
step
();
};
};
#endif // DMA_H_
#endif // DMA_H_
sims/nic/corundum/mem.cc
View file @
d4666c97
...
@@ -22,10 +22,11 @@
...
@@ -22,10 +22,11 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
*/
#include "sims/nic/corundum/mem.h"
#include <iostream>
#include <iostream>
#include "sims/nic/corundum/debug.h"
#include "sims/nic/corundum/debug.h"
#include "sims/nic/corundum/mem.h"
#include "sims/nic/corundum/dma.h"
#include "sims/nic/corundum/dma.h"
/*
/*
...
@@ -40,11 +41,8 @@
...
@@ -40,11 +41,8 @@
#define SEG_COUNT 8
#define SEG_COUNT 8
#define SEG_WIDTH (DATA_WIDTH / SEG_COUNT)
#define SEG_WIDTH (DATA_WIDTH / SEG_COUNT)
void
MemWriter
::
step
()
void
MemWriter
::
step
()
{
{
if
(
cur
&&
p
.
mem_ready
&&
((
p
.
mem_ready
&
p
.
mem_valid
)
==
p
.
mem_valid
))
{
if
(
cur
&&
p
.
mem_ready
&&
((
p
.
mem_ready
&
p
.
mem_valid
)
==
p
.
mem_valid
))
{
#ifdef MEM_DEBUG
#ifdef MEM_DEBUG
std
::
cerr
<<
"completed write to: "
<<
cur
->
ram_addr
<<
std
::
endl
;
std
::
cerr
<<
"completed write to: "
<<
cur
->
ram_addr
<<
std
::
endl
;
#endif
#endif
...
@@ -75,18 +73,17 @@ void MemWriter::step()
...
@@ -75,18 +73,17 @@ void MemWriter::step()
p
.
mem_addr
[
0
]
=
p
.
mem_addr
[
1
]
=
p
.
mem_addr
[
2
]
=
0
;
p
.
mem_addr
[
0
]
=
p
.
mem_addr
[
1
]
=
p
.
mem_addr
[
2
]
=
0
;
p
.
mem_be
[
0
]
=
p
.
mem_be
[
1
]
=
p
.
mem_be
[
2
]
=
p
.
mem_be
[
3
]
=
0
;
p
.
mem_be
[
0
]
=
p
.
mem_be
[
1
]
=
p
.
mem_be
[
2
]
=
p
.
mem_be
[
3
]
=
0
;
p
.
mem_valid
=
0
;
p
.
mem_valid
=
0
;
for
(
size_t
i
=
0
;
i
<
data_byte_width
/
4
;
i
++
)
for
(
size_t
i
=
0
;
i
<
data_byte_width
/
4
;
i
++
)
p
.
mem_data
[
i
]
=
0
;
p
.
mem_data
[
i
]
=
0
;
/* put data bytes in the right places */
/* put data bytes in the right places */
size_t
off
=
data_offset
;
size_t
off
=
data_offset
;
size_t
cur_len
=
(
cur
->
len
-
cur_off
>
data_byte_width
-
data_offset
?
size_t
cur_len
=
(
cur
->
len
-
cur_off
>
data_byte_width
-
data_offset
data_byte_width
-
data_offset
:
cur
->
len
-
cur_off
);
?
data_byte_width
-
data_offset
:
cur
->
len
-
cur_off
);
for
(
size_t
i
=
0
;
i
<
cur_len
;
i
++
,
off
++
)
{
for
(
size_t
i
=
0
;
i
<
cur_len
;
i
++
,
off
++
)
{
size_t
byte_off
=
off
%
4
;
size_t
byte_off
=
off
%
4
;
p
.
mem_data
[
off
/
4
]
|=
(((
uint32_t
)
cur
->
data
[
cur_off
+
i
])
<<
p
.
mem_data
[
off
/
4
]
|=
(
byte_off
*
8
));
(((
uint32_t
)
cur
->
data
[
cur_off
+
i
])
<<
(
byte_off
*
8
));
p
.
mem_be
[
off
/
32
]
|=
(
1
<<
(
off
%
32
));
p
.
mem_be
[
off
/
32
]
|=
(
1
<<
(
off
%
32
));
p
.
mem_valid
|=
(
1
<<
(
off
/
(
SEG_WIDTH
/
8
)));
p
.
mem_valid
|=
(
1
<<
(
off
/
(
SEG_WIDTH
/
8
)));
}
}
...
@@ -108,27 +105,22 @@ void MemWriter::step()
...
@@ -108,27 +105,22 @@ void MemWriter::step()
}
}
}
}
void
MemWriter
::
op_issue
(
DMAOp
*
op
)
void
MemWriter
::
op_issue
(
DMAOp
*
op
)
{
{
#ifdef MEM_DEBUG
#ifdef MEM_DEBUG
std
::
cerr
<<
"enqueued write to "
<<
op
->
ram_addr
<<
std
::
endl
;
std
::
cerr
<<
"enqueued write to "
<<
op
->
ram_addr
<<
std
::
endl
;
#endif
#endif
pending
.
push_back
(
op
);
pending
.
push_back
(
op
);
}
}
void
MemReader
::
step
()
{
void
MemReader
::
step
()
{
size_t
data_byte_width
=
DATA_WIDTH
/
8
;
size_t
data_byte_width
=
DATA_WIDTH
/
8
;
if
(
cur
&&
p
.
mem_resvalid
&&
if
(
cur
&&
p
.
mem_resvalid
&&
((
p
.
mem_resvalid
&
p
.
mem_valid
)
==
p
.
mem_valid
))
{
((
p
.
mem_resvalid
&
p
.
mem_valid
)
==
p
.
mem_valid
))
{
#ifdef MEM_DEBUG
#ifdef MEM_DEBUG
std
::
cerr
<<
"completed read from: "
<<
std
::
hex
<<
cur
->
ram_addr
<<
std
::
cerr
<<
"completed read from: "
<<
std
::
hex
<<
cur
->
ram_addr
std
::
endl
;
<<
std
::
endl
;
std
::
cerr
<<
" reval = "
<<
(
unsigned
)
p
.
mem_resvalid
<<
std
::
endl
;
std
::
cerr
<<
" reval = "
<<
(
unsigned
)
p
.
mem_resvalid
<<
std
::
endl
;
#endif
#endif
p
.
mem_valid
=
0
;
p
.
mem_valid
=
0
;
#ifdef MEM_DEBUG
#ifdef MEM_DEBUG
...
@@ -137,12 +129,12 @@ void MemReader::step()
...
@@ -137,12 +129,12 @@ void MemReader::step()
#endif
#endif
size_t
off
=
(
cur
->
ram_addr
+
cur_off
)
%
data_byte_width
;
size_t
off
=
(
cur
->
ram_addr
+
cur_off
)
%
data_byte_width
;
size_t
cur_len
=
(
cur
->
len
-
cur_off
>
data_byte_width
-
off
?
size_t
cur_len
=
data_byte_width
-
off
:
cur
->
len
-
cur_off
);
(
cur
->
len
-
cur_off
>
data_byte_width
-
off
?
data_byte_width
-
off
:
cur
->
len
-
cur_off
);
for
(
size_t
i
=
0
;
i
<
cur_len
;
i
++
,
off
++
)
{
for
(
size_t
i
=
0
;
i
<
cur_len
;
i
++
,
off
++
)
{
size_t
byte_off
=
(
off
%
4
);
size_t
byte_off
=
(
off
%
4
);
cur
->
data
[
cur_off
+
i
]
=
(
p
.
mem_data
[
off
/
4
]
>>
(
byte_off
*
8
))
&
cur
->
data
[
cur_off
+
i
]
=
(
p
.
mem_data
[
off
/
4
]
>>
(
byte_off
*
8
))
&
0xff
;
0xff
;
}
}
cur_off
+=
cur_len
;
cur_off
+=
cur_len
;
...
@@ -161,8 +153,8 @@ void MemReader::step()
...
@@ -161,8 +153,8 @@ void MemReader::step()
size_t
data_offset
=
(
cur
->
ram_addr
+
cur_off
)
%
data_byte_width
;
size_t
data_offset
=
(
cur
->
ram_addr
+
cur_off
)
%
data_byte_width
;
#ifdef MEM_DEBUG
#ifdef MEM_DEBUG
std
::
cerr
<<
"issuing op="
<<
cur
<<
" read from "
<<
std
::
hex
<<
std
::
cerr
<<
"issuing op="
<<
cur
<<
" read from "
<<
std
::
hex
cur
->
ram_addr
<<
std
::
endl
;
<<
cur
->
ram_addr
<<
std
::
endl
;
std
::
cerr
<<
" off="
<<
data_offset
<<
std
::
endl
;
std
::
cerr
<<
" off="
<<
data_offset
<<
std
::
endl
;
#endif
#endif
...
@@ -171,11 +163,11 @@ void MemReader::step()
...
@@ -171,11 +163,11 @@ void MemReader::step()
p
.
mem_addr
[
0
]
=
p
.
mem_addr
[
1
]
=
p
.
mem_addr
[
2
]
=
0
;
p
.
mem_addr
[
0
]
=
p
.
mem_addr
[
1
]
=
p
.
mem_addr
[
2
]
=
0
;
p
.
mem_valid
=
0x0
;
p
.
mem_valid
=
0x0
;
/* put data bytes in the right places */
/* put data bytes in the right places */
size_t
off
=
data_offset
;
size_t
off
=
data_offset
;
size_t
cur_len
=
(
cur
->
len
-
cur_off
>
data_byte_width
-
data_offset
?
size_t
cur_len
=
(
cur
->
len
-
cur_off
>
data_byte_width
-
data_offset
data_byte_width
-
data_offset
:
cur
->
len
-
cur_off
);
?
data_byte_width
-
data_offset
:
cur
->
len
-
cur_off
);
for
(
size_t
i
=
0
;
i
<
cur_len
;
i
++
,
off
++
)
{
for
(
size_t
i
=
0
;
i
<
cur_len
;
i
++
,
off
++
)
{
p
.
mem_valid
|=
(
1
<<
(
off
/
(
SEG_WIDTH
/
8
)));
p
.
mem_valid
|=
(
1
<<
(
off
/
(
SEG_WIDTH
/
8
)));
}
}
...
@@ -198,13 +190,12 @@ void MemReader::step()
...
@@ -198,13 +190,12 @@ void MemReader::step()
#ifdef MEM_DEBUG
#ifdef MEM_DEBUG
for
(
size_t
i
=
0
;
i
<
3
;
i
++
)
for
(
size_t
i
=
0
;
i
<
3
;
i
++
)
std
::
cerr
<<
" addr = "
<<
p
.
mem_addr
[
i
]
<<
std
::
endl
;
std
::
cerr
<<
" addr = "
<<
p
.
mem_addr
[
i
]
<<
std
::
endl
;
std
::
cerr
<<
" mem_valid = "
<<
(
unsigned
)
p
.
mem_valid
<<
std
::
endl
;
std
::
cerr
<<
" mem_valid = "
<<
(
unsigned
)
p
.
mem_valid
<<
std
::
endl
;
#endif
#endif
}
}
}
}
void
MemReader
::
op_issue
(
DMAOp
*
op
)
void
MemReader
::
op_issue
(
DMAOp
*
op
)
{
{
#ifdef MEM_DEBUG
#ifdef MEM_DEBUG
std
::
cerr
<<
"enqueued read from "
<<
op
->
ram_addr
<<
std
::
endl
;
std
::
cerr
<<
"enqueued read from "
<<
op
->
ram_addr
<<
std
::
endl
;
#endif
#endif
...
...
sims/nic/corundum/mem.h
View file @
d4666c97
...
@@ -25,10 +25,10 @@
...
@@ -25,10 +25,10 @@
#ifndef MEM_H_
#ifndef MEM_H_
#define MEM_H_
#define MEM_H_
#include <deque>
#include <verilated.h>
#include <verilated.h>
#include <deque>
#include "sims/nic/corundum/obj_dir/Vinterface.h"
#include "sims/nic/corundum/obj_dir/Vinterface.h"
class
DMAOp
;
class
DMAOp
;
...
@@ -49,10 +49,13 @@ struct MemReadPort {
...
@@ -49,10 +49,13 @@ struct MemReadPort {
vluint8_t
&
mem_valid_
,
vluint8_t
&
mem_resready_
,
vluint8_t
&
mem_valid_
,
vluint8_t
&
mem_resready_
,
vluint32_t
(
&
mem_data_
)[
32
],
vluint8_t
&
mem_ready_
,
vluint32_t
(
&
mem_data_
)[
32
],
vluint8_t
&
mem_ready_
,
vluint8_t
&
mem_resvalid_
)
vluint8_t
&
mem_resvalid_
)
:
mem_sel
(
mem_sel_
),
mem_addr
(
mem_addr_
),
mem_valid
(
mem_valid_
),
:
mem_sel
(
mem_sel_
),
mem_resready
(
mem_resready_
),
mem_data
(
mem_data_
),
mem_ready
(
mem_ready_
),
mem_addr
(
mem_addr_
),
mem_resvalid
(
mem_resvalid_
)
mem_valid
(
mem_valid_
),
{
mem_resready
(
mem_resready_
),
mem_data
(
mem_data_
),
mem_ready
(
mem_ready_
),
mem_resvalid
(
mem_resvalid_
)
{
}
}
};
};
...
@@ -70,9 +73,12 @@ struct MemWritePort {
...
@@ -70,9 +73,12 @@ struct MemWritePort {
MemWritePort
(
vluint8_t
&
mem_sel_
,
vluint32_t
(
&
mem_be_
)[
4
],
MemWritePort
(
vluint8_t
&
mem_sel_
,
vluint32_t
(
&
mem_be_
)[
4
],
vluint32_t
(
&
mem_addr_
)[
3
],
vluint32_t
(
&
mem_data_
)[
32
],
vluint32_t
(
&
mem_addr_
)[
3
],
vluint32_t
(
&
mem_data_
)[
32
],
vluint8_t
&
mem_valid_
,
vluint8_t
&
mem_ready_
)
vluint8_t
&
mem_valid_
,
vluint8_t
&
mem_ready_
)
:
mem_sel
(
mem_sel_
),
mem_be
(
mem_be_
),
mem_addr
(
mem_addr_
),
:
mem_sel
(
mem_sel_
),
mem_data
(
mem_data_
),
mem_valid
(
mem_valid_
),
mem_ready
(
mem_ready_
)
mem_be
(
mem_be_
),
{
mem_addr
(
mem_addr_
),
mem_data
(
mem_data_
),
mem_valid
(
mem_valid_
),
mem_ready
(
mem_ready_
)
{
}
}
};
};
...
@@ -85,9 +91,7 @@ class MemReader {
...
@@ -85,9 +91,7 @@ class MemReader {
size_t
cur_off
;
size_t
cur_off
;
public:
public:
MemReader
(
MemReadPort
&
p_
)
MemReader
(
MemReadPort
&
p_
)
:
p
(
p_
),
cur
(
0
),
cur_off
(
0
)
{
:
p
(
p_
),
cur
(
0
),
cur_off
(
0
)
{
}
}
void
step
();
void
step
();
...
@@ -103,9 +107,7 @@ class MemWriter {
...
@@ -103,9 +107,7 @@ class MemWriter {
size_t
cur_off
;
size_t
cur_off
;
public:
public:
MemWriter
(
MemWritePort
&
p_
)
MemWriter
(
MemWritePort
&
p_
)
:
p
(
p_
),
cur
(
0
),
cur_off
(
0
)
{
:
p
(
p_
),
cur
(
0
),
cur_off
(
0
)
{
}
}
void
step
();
void
step
();
...
...
sims/nic/corundum_bm/corundum_bm.cc
View file @
d4666c97
...
@@ -22,79 +22,69 @@
...
@@ -22,79 +22,69 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
*/
#include <stdlib.h>
#include "sims/nic/corundum_bm/corundum_bm.h"
#include <signal.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <unistd.h>
#include <unistd.h>
#include <signal.h>
#include <cassert>
#include
"sims/nic/corundum_bm/corundum_bm.h"
#include
<cassert>
static
nicbm
::
Runner
*
runner
;
static
nicbm
::
Runner
*
runner
;
namespace
corundum
{
namespace
corundum
{
DescRing
::
DescRing
()
DescRing
::
DescRing
()
:
_dmaAddr
(
0
),
_sizeLog
(
0
),
_size
(
0
),
_sizeMask
(
0
),
:
_dmaAddr
(
0
),
_index
(
0
),
_headPtr
(
0
),
_tailPtr
(
0
),
_sizeLog
(
0
),
_currHead
(
0
),
_currTail
(
0
),
active
(
false
),
armed
(
false
)
_size
(
0
),
{
_sizeMask
(
0
),
_index
(
0
),
_headPtr
(
0
),
_tailPtr
(
0
),
_currHead
(
0
),
_currTail
(
0
),
active
(
false
),
armed
(
false
)
{
}
}
DescRing
::~
DescRing
()
DescRing
::~
DescRing
()
{
{
}
}
addr_t
DescRing
::
dmaAddr
()
{
addr_t
DescRing
::
dmaAddr
()
{
return
this
->
_dmaAddr
;
return
this
->
_dmaAddr
;
}
}
size_t
size_t
DescRing
::
sizeLog
()
{
DescRing
::
sizeLog
()
{
return
this
->
_sizeLog
;
return
this
->
_sizeLog
;
}
}
unsigned
unsigned
DescRing
::
index
()
{
DescRing
::
index
()
{
return
this
->
_index
;
return
this
->
_index
;
}
}
ptr_t
ptr_t
DescRing
::
headPtr
()
{
DescRing
::
headPtr
()
{
return
this
->
_headPtr
;
return
this
->
_headPtr
;
}
}
ptr_t
ptr_t
DescRing
::
tailPtr
()
{
DescRing
::
tailPtr
()
{
return
this
->
_tailPtr
;
return
this
->
_tailPtr
;
}
}
void
void
DescRing
::
setDMALower
(
uint32_t
addr
)
{
DescRing
::
setDMALower
(
uint32_t
addr
)
{
this
->
_dmaAddr
&=
0xFFFFFFFF00000000
;
this
->
_dmaAddr
&=
0xFFFFFFFF00000000
;
this
->
_dmaAddr
|=
(
addr_t
)
addr
;
this
->
_dmaAddr
|=
(
addr_t
)
addr
;
}
}
void
void
DescRing
::
setDMAUpper
(
uint32_t
addr
)
{
DescRing
::
setDMAUpper
(
uint32_t
addr
)
{
this
->
_dmaAddr
&=
0xFFFFFFFF
;
this
->
_dmaAddr
&=
0xFFFFFFFF
;
this
->
_dmaAddr
|=
((
addr_t
)
addr
<<
32
);
this
->
_dmaAddr
|=
((
addr_t
)
addr
<<
32
);
}
}
void
void
DescRing
::
setSizeLog
(
size_t
size_log
)
{
DescRing
::
setSizeLog
(
size_t
size_log
)
{
if
(
size_log
&
QUEUE_ACTIVE_MASK
)
{
if
(
size_log
&
QUEUE_ACTIVE_MASK
)
{
this
->
active
=
true
;
this
->
active
=
true
;
}
else
{
}
else
{
...
@@ -107,9 +97,7 @@ DescRing::setSizeLog(size_t size_log)
...
@@ -107,9 +97,7 @@ DescRing::setSizeLog(size_t size_log)
this
->
cplDma
.
resize
(
this
->
_size
,
false
);
this
->
cplDma
.
resize
(
this
->
_size
,
false
);
}
}
void
void
DescRing
::
setIndex
(
unsigned
index
)
{
DescRing
::
setIndex
(
unsigned
index
)
{
assert
(
!
(
index
&
QUEUE_CONT_MASK
));
assert
(
!
(
index
&
QUEUE_CONT_MASK
));
if
(
index
&
QUEUE_ARM_MASK
)
{
if
(
index
&
QUEUE_ARM_MASK
)
{
this
->
armed
=
true
;
this
->
armed
=
true
;
...
@@ -117,34 +105,23 @@ DescRing::setIndex(unsigned index)
...
@@ -117,34 +105,23 @@ DescRing::setIndex(unsigned index)
this
->
_index
=
index
&
0xFF
;
this
->
_index
=
index
&
0xFF
;
}
}
void
void
DescRing
::
setHeadPtr
(
ptr_t
ptr
)
{
DescRing
::
setHeadPtr
(
ptr_t
ptr
)
{
this
->
_headPtr
=
ptr
;
this
->
_headPtr
=
ptr
;
}
}
void
void
DescRing
::
setTailPtr
(
ptr_t
ptr
)
{
DescRing
::
setTailPtr
(
ptr_t
ptr
)
{
this
->
_tailPtr
=
ptr
;
this
->
_tailPtr
=
ptr
;
}
}
bool
bool
DescRing
::
empty
()
{
DescRing
::
empty
()
{
return
(
this
->
_headPtr
==
this
->
_currTail
);
return
(
this
->
_headPtr
==
this
->
_currTail
);
}
}
bool
bool
DescRing
::
full
()
{
DescRing
::
full
()
{
return
(
this
->
_currHead
-
this
->
_tailPtr
>=
this
->
_size
);
return
(
this
->
_currHead
-
this
->
_tailPtr
>=
this
->
_size
);
}
}
bool
DescRing
::
updatePtr
(
ptr_t
ptr
,
bool
head
)
{
bool
DescRing
::
updatePtr
(
ptr_t
ptr
,
bool
head
)
{
ptr_t
curr_ptr
=
head
?
this
->
_headPtr
:
this
->
_tailPtr
;
ptr_t
curr_ptr
=
head
?
this
->
_headPtr
:
this
->
_tailPtr
;
if
(
ptr
!=
curr_ptr
)
{
if
(
ptr
!=
curr_ptr
)
{
// out of order completion
// out of order completion
...
@@ -168,17 +145,13 @@ DescRing::updatePtr(ptr_t ptr, bool head)
...
@@ -168,17 +145,13 @@ DescRing::updatePtr(ptr_t ptr, bool head)
return
true
;
return
true
;
}
}
EventRing
::
EventRing
()
EventRing
::
EventRing
()
{
{
}
}
EventRing
::~
EventRing
()
EventRing
::~
EventRing
()
{
{
}
}
void
void
EventRing
::
dmaDone
(
DMAOp
*
op
)
{
EventRing
::
dmaDone
(
DMAOp
*
op
)
{
assert
(
op
->
write
);
assert
(
op
->
write
);
switch
(
op
->
type
)
{
switch
(
op
->
type
)
{
case
DMA_TYPE_EVENT
:
case
DMA_TYPE_EVENT
:
...
@@ -193,17 +166,15 @@ EventRing::dmaDone(DMAOp *op)
...
@@ -193,17 +166,15 @@ EventRing::dmaDone(DMAOp *op)
}
}
}
}
void
void
EventRing
::
issueEvent
(
unsigned
type
,
unsigned
source
)
{
EventRing
::
issueEvent
(
unsigned
type
,
unsigned
source
)
{
assert
(
type
==
EVENT_TYPE_TX_CPL
||
type
==
EVENT_TYPE_RX_CPL
);
assert
(
type
==
EVENT_TYPE_TX_CPL
||
type
==
EVENT_TYPE_RX_CPL
);
if
(
this
->
armed
)
{
if
(
this
->
armed
)
{
if
(
full
())
{
if
(
full
())
{
fprintf
(
stderr
,
"Event ring is rull
\n
"
);
fprintf
(
stderr
,
"Event ring is rull
\n
"
);
return
;
return
;
}
}
addr_t
dma_addr
=
this
->
_dmaAddr
+
(
this
->
_currHead
&
this
->
_sizeMask
)
*
addr_t
dma_addr
=
EVENT_SIZE
;
this
->
_dmaAddr
+
(
this
->
_currHead
&
this
->
_sizeMask
)
*
EVENT_SIZE
;
/* Issue DMA write */
/* Issue DMA write */
DMAOp
*
op
=
new
DMAOp
;
DMAOp
*
op
=
new
DMAOp
;
op
->
type
=
DMA_TYPE_EVENT
;
op
->
type
=
DMA_TYPE_EVENT
;
...
@@ -222,25 +193,20 @@ EventRing::issueEvent(unsigned type, unsigned source)
...
@@ -222,25 +193,20 @@ EventRing::issueEvent(unsigned type, unsigned source)
}
}
}
}
CplRing
::
CplRing
(
EventRing
*
eventRing
)
CplRing
::
CplRing
(
EventRing
*
eventRing
)
:
eventRing
(
eventRing
)
{
:
eventRing
(
eventRing
)
{
}
}
CplRing
::~
CplRing
()
CplRing
::~
CplRing
()
{
{
}
}
void
void
CplRing
::
dmaDone
(
DMAOp
*
op
)
{
CplRing
::
dmaDone
(
DMAOp
*
op
)
{
assert
(
op
->
write
);
assert
(
op
->
write
);
switch
(
op
->
type
)
{
switch
(
op
->
type
)
{
case
DMA_TYPE_TX_CPL
:
case
DMA_TYPE_TX_CPL
:
case
DMA_TYPE_RX_CPL
:
{
case
DMA_TYPE_RX_CPL
:
{
if
(
updatePtr
((
ptr_t
)
op
->
tag
,
true
))
{
if
(
updatePtr
((
ptr_t
)
op
->
tag
,
true
))
{
unsigned
type
=
op
->
type
==
DMA_TYPE_TX_CPL
?
EVENT_TYPE_TX_CPL
:
unsigned
type
=
EVENT_TYPE_RX_CPL
;
op
->
type
==
DMA_TYPE_TX_CPL
?
EVENT_TYPE_TX_CPL
:
EVENT_TYPE_RX_CPL
;
this
->
eventRing
->
issueEvent
(
type
,
0
);
this
->
eventRing
->
issueEvent
(
type
,
0
);
}
}
delete
op
;
delete
op
;
...
@@ -252,9 +218,7 @@ CplRing::dmaDone(DMAOp *op)
...
@@ -252,9 +218,7 @@ CplRing::dmaDone(DMAOp *op)
}
}
}
}
void
void
CplRing
::
complete
(
unsigned
index
,
size_t
len
,
bool
tx
)
{
CplRing
::
complete
(
unsigned
index
,
size_t
len
,
bool
tx
)
{
CplData
data
;
CplData
data
;
data
.
index
=
index
;
data
.
index
=
index
;
data
.
len
=
len
;
data
.
len
=
len
;
...
@@ -262,8 +226,8 @@ CplRing::complete(unsigned index, size_t len, bool tx)
...
@@ -262,8 +226,8 @@ CplRing::complete(unsigned index, size_t len, bool tx)
this
->
pending
.
push_back
(
data
);
this
->
pending
.
push_back
(
data
);
while
(
!
full
()
&&
!
this
->
pending
.
empty
())
{
while
(
!
full
()
&&
!
this
->
pending
.
empty
())
{
CplData
&
data
=
this
->
pending
.
front
();
CplData
&
data
=
this
->
pending
.
front
();
addr_t
dma_addr
=
this
->
_dmaAddr
+
(
this
->
_currHead
&
this
->
_sizeMask
)
*
addr_t
dma_addr
=
CPL_SIZE
;
this
->
_dmaAddr
+
(
this
->
_currHead
&
this
->
_sizeMask
)
*
CPL_SIZE
;
/* Issue DMA write */
/* Issue DMA write */
DMAOp
*
op
=
new
DMAOp
;
DMAOp
*
op
=
new
DMAOp
;
op
->
type
=
data
.
tx
?
DMA_TYPE_TX_CPL
:
DMA_TYPE_RX_CPL
;
op
->
type
=
data
.
tx
?
DMA_TYPE_TX_CPL
:
DMA_TYPE_RX_CPL
;
...
@@ -282,18 +246,13 @@ CplRing::complete(unsigned index, size_t len, bool tx)
...
@@ -282,18 +246,13 @@ CplRing::complete(unsigned index, size_t len, bool tx)
}
}
}
}
TxRing
::
TxRing
(
CplRing
*
cplRing
)
TxRing
::
TxRing
(
CplRing
*
cplRing
)
:
txCplRing
(
cplRing
)
{
:
txCplRing
(
cplRing
)
{
}
}
TxRing
::~
TxRing
()
TxRing
::~
TxRing
()
{
{
}
}
void
void
TxRing
::
setHeadPtr
(
ptr_t
ptr
)
{
TxRing
::
setHeadPtr
(
ptr_t
ptr
)
{
DescRing
::
setHeadPtr
(
ptr
);
DescRing
::
setHeadPtr
(
ptr
);
while
(
this
->
_currTail
!=
this
->
_headPtr
)
{
while
(
this
->
_currTail
!=
this
->
_headPtr
)
{
unsigned
index
=
this
->
_currTail
&
this
->
_sizeMask
;
unsigned
index
=
this
->
_currTail
&
this
->
_sizeMask
;
...
@@ -311,9 +270,7 @@ TxRing::setHeadPtr(ptr_t ptr)
...
@@ -311,9 +270,7 @@ TxRing::setHeadPtr(ptr_t ptr)
}
}
}
}
void
void
TxRing
::
dmaDone
(
DMAOp
*
op
)
{
TxRing
::
dmaDone
(
DMAOp
*
op
)
{
switch
(
op
->
type
)
{
switch
(
op
->
type
)
{
case
DMA_TYPE_DESC
:
{
case
DMA_TYPE_DESC
:
{
assert
(
!
op
->
write
);
assert
(
!
op
->
write
);
...
@@ -338,18 +295,13 @@ TxRing::dmaDone(DMAOp *op)
...
@@ -338,18 +295,13 @@ TxRing::dmaDone(DMAOp *op)
}
}
}
}
RxRing
::
RxRing
(
CplRing
*
cplRing
)
RxRing
::
RxRing
(
CplRing
*
cplRing
)
:
rxCplRing
(
cplRing
)
{
:
rxCplRing
(
cplRing
)
{
}
}
RxRing
::~
RxRing
()
RxRing
::~
RxRing
()
{
{
}
}
void
void
RxRing
::
dmaDone
(
DMAOp
*
op
)
{
RxRing
::
dmaDone
(
DMAOp
*
op
)
{
switch
(
op
->
type
)
{
switch
(
op
->
type
)
{
case
DMA_TYPE_DESC
:
{
case
DMA_TYPE_DESC
:
{
assert
(
!
op
->
write
);
assert
(
!
op
->
write
);
...
@@ -375,15 +327,13 @@ RxRing::dmaDone(DMAOp *op)
...
@@ -375,15 +327,13 @@ RxRing::dmaDone(DMAOp *op)
}
}
}
}
void
void
RxRing
::
rx
(
RxData
*
rx_data
)
{
RxRing
::
rx
(
RxData
*
rx_data
)
{
if
(
empty
())
{
if
(
empty
())
{
delete
rx_data
;
delete
rx_data
;
return
;
return
;
}
}
addr_t
dma_addr
=
this
->
_dmaAddr
+
(
this
->
_currTail
&
this
->
_sizeMask
)
*
addr_t
dma_addr
=
DESC_SIZE
;
this
->
_dmaAddr
+
(
this
->
_currTail
&
this
->
_sizeMask
)
*
DESC_SIZE
;
/* Issue DMA read */
/* Issue DMA read */
DMAOp
*
op
=
new
DMAOp
;
DMAOp
*
op
=
new
DMAOp
;
op
->
type
=
DMA_TYPE_DESC
;
op
->
type
=
DMA_TYPE_DESC
;
...
@@ -398,146 +348,109 @@ RxRing::rx(RxData *rx_data)
...
@@ -398,146 +348,109 @@ RxRing::rx(RxData *rx_data)
}
}
Port
::
Port
()
Port
::
Port
()
:
_id
(
0
),
_features
(
0
),
_mtu
(
0
),
:
_id
(
0
),
_schedCount
(
0
),
_schedOffset
(
0
),
_schedStride
(
0
),
_features
(
0
),
_schedType
(
0
),
_rssMask
(
0
),
_schedEnable
(
false
),
_mtu
(
0
),
_queueEnable
(
false
)
_schedCount
(
0
),
{
_schedOffset
(
0
),
_schedStride
(
0
),
_schedType
(
0
),
_rssMask
(
0
),
_schedEnable
(
false
),
_queueEnable
(
false
)
{
}
}
Port
::~
Port
()
Port
::~
Port
()
{
{
}
}
unsigned
unsigned
Port
::
id
()
{
Port
::
id
()
{
return
this
->
_id
;
return
this
->
_id
;
}
}
unsigned
unsigned
Port
::
features
()
{
Port
::
features
()
{
return
this
->
_features
;
return
this
->
_features
;
}
}
size_t
size_t
Port
::
mtu
()
{
Port
::
mtu
()
{
return
this
->
_mtu
;
return
this
->
_mtu
;
}
}
size_t
size_t
Port
::
schedCount
()
{
Port
::
schedCount
()
{
return
this
->
_schedCount
;
return
this
->
_schedCount
;
}
}
addr_t
addr_t
Port
::
schedOffset
()
{
Port
::
schedOffset
()
{
return
this
->
_schedOffset
;
return
this
->
_schedOffset
;
}
}
addr_t
addr_t
Port
::
schedStride
()
{
Port
::
schedStride
()
{
return
this
->
_schedStride
;
return
this
->
_schedStride
;
}
}
unsigned
unsigned
Port
::
schedType
()
{
Port
::
schedType
()
{
return
this
->
_schedType
;
return
this
->
_schedType
;
}
}
unsigned
Port
::
rssMask
()
{
unsigned
Port
::
rssMask
()
{
return
this
->
_rssMask
;
return
this
->
_rssMask
;
}
}
void
void
Port
::
setId
(
unsigned
id
)
{
Port
::
setId
(
unsigned
id
)
{
this
->
_id
=
id
;
this
->
_id
=
id
;
}
}
void
void
Port
::
setFeatures
(
unsigned
features
)
{
Port
::
setFeatures
(
unsigned
features
)
this
->
_features
=
{
features
&
(
IF_FEATURE_RSS
|
IF_FEATURE_PTP_TS
|
IF_FEATURE_TX_CSUM
|
this
->
_features
=
features
&
(
IF_FEATURE_RSS
|
IF_FEATURE_RX_CSUM
|
IF_FEATURE_RX_HASH
);
IF_FEATURE_PTP_TS
|
IF_FEATURE_TX_CSUM
|
IF_FEATURE_RX_CSUM
|
IF_FEATURE_RX_HASH
);
}
}
void
void
Port
::
setMtu
(
size_t
mtu
)
{
Port
::
setMtu
(
size_t
mtu
)
{
this
->
_mtu
=
mtu
;
this
->
_mtu
=
mtu
;
}
}
void
void
Port
::
setSchedCount
(
size_t
count
)
{
Port
::
setSchedCount
(
size_t
count
)
{
this
->
_schedCount
=
count
;
this
->
_schedCount
=
count
;
}
}
void
void
Port
::
setSchedOffset
(
addr_t
offset
)
{
Port
::
setSchedOffset
(
addr_t
offset
)
{
this
->
_schedOffset
=
offset
;
this
->
_schedOffset
=
offset
;
}
}
void
void
Port
::
setSchedStride
(
addr_t
stride
)
{
Port
::
setSchedStride
(
addr_t
stride
)
{
this
->
_schedStride
=
stride
;
this
->
_schedStride
=
stride
;
}
}
void
void
Port
::
setSchedType
(
unsigned
type
)
{
Port
::
setSchedType
(
unsigned
type
)
{
this
->
_schedType
=
type
;
this
->
_schedType
=
type
;
}
}
void
void
Port
::
setRssMask
(
unsigned
mask
)
{
Port
::
setRssMask
(
unsigned
mask
)
{
this
->
_rssMask
=
mask
;
this
->
_rssMask
=
mask
;
}
}
void
void
Port
::
schedEnable
()
{
Port
::
schedEnable
()
{
this
->
_schedEnable
=
true
;
this
->
_schedEnable
=
true
;
}
}
void
void
Port
::
schedDisable
()
{
Port
::
schedDisable
()
{
this
->
_schedEnable
=
false
;
this
->
_schedEnable
=
false
;
}
}
void
void
Port
::
queueEnable
()
{
Port
::
queueEnable
()
{
this
->
_queueEnable
=
true
;
this
->
_queueEnable
=
true
;
}
}
void
void
Port
::
queueDisable
()
{
Port
::
queueDisable
()
{
this
->
_queueEnable
=
false
;
this
->
_queueEnable
=
false
;
}
}
Corundum
::
Corundum
()
Corundum
::
Corundum
()
:
txCplRing
(
&
this
->
eventRing
),
rxCplRing
(
&
this
->
eventRing
),
:
txCplRing
(
&
this
->
eventRing
),
txRing
(
&
this
->
txCplRing
),
rxRing
(
&
this
->
rxCplRing
),
features
(
0
)
rxCplRing
(
&
this
->
eventRing
),
{
txRing
(
&
this
->
txCplRing
),
rxRing
(
&
this
->
rxCplRing
),
features
(
0
)
{
this
->
port
.
setId
(
0
);
this
->
port
.
setId
(
0
);
this
->
port
.
setFeatures
(
this
->
features
);
this
->
port
.
setFeatures
(
this
->
features
);
this
->
port
.
setMtu
(
2048
);
this
->
port
.
setMtu
(
2048
);
...
@@ -549,13 +462,10 @@ Corundum::Corundum()
...
@@ -549,13 +462,10 @@ Corundum::Corundum()
this
->
port
.
schedDisable
();
this
->
port
.
schedDisable
();
}
}
Corundum
::~
Corundum
()
Corundum
::~
Corundum
()
{
{
}
}
reg_t
reg_t
Corundum
::
reg_read
(
uint8_t
bar
,
addr_t
addr
)
{
Corundum
::
reg_read
(
uint8_t
bar
,
addr_t
addr
)
{
switch
(
addr
)
{
switch
(
addr
)
{
case
REG_FW_ID
:
case
REG_FW_ID
:
return
32
;
return
32
;
...
@@ -645,9 +555,7 @@ Corundum::reg_read(uint8_t bar, addr_t addr)
...
@@ -645,9 +555,7 @@ Corundum::reg_read(uint8_t bar, addr_t addr)
}
}
}
}
void
void
Corundum
::
reg_write
(
uint8_t
bar
,
uint64_t
addr
,
reg_t
val
)
{
Corundum
::
reg_write
(
uint8_t
bar
,
uint64_t
addr
,
reg_t
val
)
{
switch
(
addr
)
{
switch
(
addr
)
{
case
REG_FW_ID
:
case
REG_FW_ID
:
case
REG_FW_VER
:
case
REG_FW_VER
:
...
@@ -778,9 +686,7 @@ Corundum::reg_write(uint8_t bar, uint64_t addr, reg_t val)
...
@@ -778,9 +686,7 @@ Corundum::reg_write(uint8_t bar, uint64_t addr, reg_t val)
}
}
}
}
void
void
Corundum
::
setup_intro
(
struct
cosim_pcie_proto_dev_intro
&
di
)
{
Corundum
::
setup_intro
(
struct
cosim_pcie_proto_dev_intro
&
di
)
{
di
.
bars
[
0
].
len
=
1
<<
24
;
di
.
bars
[
0
].
len
=
1
<<
24
;
di
.
bars
[
0
].
flags
=
COSIM_PCIE_PROTO_BAR_64
;
di
.
bars
[
0
].
flags
=
COSIM_PCIE_PROTO_BAR_64
;
di
.
pci_vendor_id
=
0x5543
;
di
.
pci_vendor_id
=
0x5543
;
...
@@ -791,16 +697,12 @@ Corundum::setup_intro(struct cosim_pcie_proto_dev_intro &di)
...
@@ -791,16 +697,12 @@ Corundum::setup_intro(struct cosim_pcie_proto_dev_intro &di)
di
.
pci_msi_nvecs
=
32
;
di
.
pci_msi_nvecs
=
32
;
}
}
void
void
Corundum
::
dma_complete
(
nicbm
::
DMAOp
&
op
)
{
Corundum
::
dma_complete
(
nicbm
::
DMAOp
&
op
)
{
DMAOp
*
op_
=
reinterpret_cast
<
DMAOp
*>
(
&
op
);
DMAOp
*
op_
=
reinterpret_cast
<
DMAOp
*>
(
&
op
);
op_
->
ring
->
dmaDone
(
op_
);
op_
->
ring
->
dmaDone
(
op_
);
}
}
void
void
Corundum
::
eth_rx
(
uint8_t
port
,
const
void
*
data
,
size_t
len
)
{
Corundum
::
eth_rx
(
uint8_t
port
,
const
void
*
data
,
size_t
len
)
{
RxData
*
rx_data
=
new
RxData
;
RxData
*
rx_data
=
new
RxData
;
memcpy
((
void
*
)
rx_data
->
data
,
data
,
len
);
memcpy
((
void
*
)
rx_data
->
data
,
data
,
len
);
rx_data
->
len
=
len
;
rx_data
->
len
=
len
;
...
@@ -809,11 +711,8 @@ Corundum::eth_rx(uint8_t port, const void *data, size_t len)
...
@@ -809,11 +711,8 @@ Corundum::eth_rx(uint8_t port, const void *data, size_t len)
}
// namespace corundum
}
// namespace corundum
using
namespace
corundum
;
int
main
(
int
argc
,
char
*
argv
[])
{
corundum
::
Corundum
dev
;
int
main
(
int
argc
,
char
*
argv
[])
{
Corundum
dev
;
runner
=
new
nicbm
::
Runner
(
dev
);
runner
=
new
nicbm
::
Runner
(
dev
);
return
runner
->
runMain
(
argc
,
argv
);
return
runner
->
runMain
(
argc
,
argv
);
}
}
Prev
1
2
3
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment