Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
S
Software for White Rabbit PTP Core
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
32
Issues
32
List
Board
Labels
Milestones
Merge Requests
4
Merge Requests
4
CI / CD
CI / CD
Pipelines
Schedules
Wiki
Wiki
image/svg+xml
Discourse
Discourse
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Projects
Software for White Rabbit PTP Core
Commits
95ff18a6
Commit
95ff18a6
authored
May 31, 2023
by
Tristan Gingold
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for multiple nic
parent
0deda175
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
173 additions
and
112 deletions
+173
-112
board.c
boards/afcz/board.c
+3
-2
board.c
boards/ertm14/board.c
+2
-1
board.c
boards/sis8300ku/board.c
+2
-1
board.c
boards/wr2rf-vme/board.c
+2
-1
dac_log.c
dev/dac_log.c
+8
-5
minic.c
dev/minic.c
+58
-49
netif.c
dev/netif.c
+2
-1
minic.h
include/dev/minic.h
+13
-8
netif.h
include/dev/netif.h
+2
-1
net.h
include/net.h
+6
-2
arp.c
lib/arp.c
+3
-1
ipv4.c
lib/ipv4.c
+4
-3
latency.c
lib/latency.c
+11
-8
lldp.c
lib/lldp.c
+3
-1
net.c
lib/net.c
+31
-12
netconsole.c
lib/netconsole.c
+6
-3
snmp.c
lib/snmp.c
+3
-3
syslog.c
lib/syslog.c
+3
-1
task-diags.c
lib/task-diags.c
+2
-1
task-stats.c
lib/task-stats.c
+2
-1
monitor_ppsi.c
monitor/monitor_ppsi.c
+1
-1
wrc_main.c
wrc_main.c
+2
-2
wrc_main_sim.c
wrc_main_sim.c
+4
-4
No files found.
boards/afcz/board.c
View file @
95ff18a6
...
...
@@ -13,6 +13,7 @@
#include "dev/spi_flash.h"
#include "dev/endpoint.h"
#include "dev/netif.h"
#include "dev/minic.h"
#include "softpll_ng.h"
#include "hw/si570_if_wb.h"
...
...
@@ -765,8 +766,8 @@ int wrc_board_early_init()
net_rst
();
ep_init
(
&
wrc_endpoint_dev
,
(
void
*
)
BASE_WR_ENDPOINT_MAIN
);
ep_init
(
&
board
.
ep_btrain
,
(
void
*
)
BASE_WR_ENDPOINT_BTRAIN
);
netif_register_device
(
&
wrc_endpoint_dev
);
netif_register_device
(
&
board
.
ep_btrain
);
netif_register_device
(
&
wrc_endpoint_dev
,
&
minic
);
netif_register_device
(
&
board
.
ep_btrain
,
NULL
);
#if defined (CONFIG_TARGET_AFCZ_V1)
afczv1_read_persistent_mac
();
...
...
boards/ertm14/board.c
View file @
95ff18a6
...
...
@@ -42,6 +42,7 @@
#include "dev/console-uart.h"
#include "dev/endpoint.h"
#include "dev/74x595.h"
#include "dev/minic.h"
#include "dev/netif.h"
#include "dev/leds.h"
#include "dev/wdiags.h"
...
...
@@ -2506,7 +2507,7 @@ int wrc_board_early_init()
/* reset the networking part of the WRCore and start the WR Endpoint */
ep_init
(
&
wrc_endpoint_dev
,
(
void
*
)
BASE_EP
);
ep_set_mac_addr
(
&
wrc_endpoint_dev
,
ertm14_mac
);
netif_register_device
(
&
wrc_endpoint_dev
);
netif_register_device
(
&
wrc_endpoint_dev
,
&
minic
);
/* Sleep for 1s to make sure WRS v4.2 always realizes that
* the link is down */
...
...
boards/sis8300ku/board.c
View file @
95ff18a6
...
...
@@ -5,6 +5,7 @@
#include "dev/syscon.h"
#include "dev/endpoint.h"
#include "dev/netif.h"
#include "dev/minic.h"
#include "softpll_ng.h"
#include "storage.h"
#include <wrc-event.h>
...
...
@@ -95,7 +96,7 @@ int wrc_board_early_init()
ep_init
(
&
wrc_endpoint_dev
,
(
void
*
)
BASE_EP
);
ep_set_mac_addr
(
&
wrc_endpoint_dev
,
board_mac_addr
);
netif_register_device
(
&
wrc_endpoint_dev
);
netif_register_device
(
&
wrc_endpoint_dev
,
&
minic
);
/* Sleep for 1s to make sure WRS v4.2 always realizes that
* the link is down */
...
...
boards/wr2rf-vme/board.c
View file @
95ff18a6
...
...
@@ -42,6 +42,7 @@
#include "dev/24aa025.h"
#include "softpll_ng.h"
#include "dev/minic.h"
#include "storage.h"
#include "wrc_ptp.h"
...
...
@@ -118,7 +119,7 @@ int wrc_board_early_init(void)
ep_init
(
&
wrc_endpoint_dev
,
(
void
*
)
BASE_EP
);
ep_set_mac_addr
(
&
wrc_endpoint_dev
,
board_mac_addr
);
netif_register_device
(
&
wrc_endpoint_dev
);
netif_register_device
(
&
wrc_endpoint_dev
,
&
minic
);
/* Sleep for 1s to make sure WRS v4.2 always realizes that
* the link is down */
...
...
dev/dac_log.c
View file @
95ff18a6
#include
<wrc.h>
#include
<wrpc.h>
#include
"wrc.h"
#include
"wrpc.h"
#include <string.h>
#include <shell.h>
#include <lib/ipv4.h>
#include "shell.h"
#include "lib/ipv4.h"
#include "dev/netif.h"
/* a tx-only socket: no queue is there */
static
DECLARE_WRPC_SOCKET
(
daclog_socket
,
0
);
...
...
@@ -35,9 +36,11 @@ void spll_log_dac(int y)
void
daclog_init
(
void
)
{
struct
wrc_netif_device
*
nif
=
netif_get_device
(
0
);
daclog_socket
=
ptpd_netif_create_socket
(
GET_WRPC_SOCKET
(
daclog_socket
),
LEN_WRPC_SOCKET
(
daclog_socket
),
NULL
,
PTPD_SOCK_UDP
,
1050
);
NULL
,
PTPD_SOCK_UDP
,
1050
,
nif
);
daclog_addr
.
sport
=
daclog_addr
.
dport
=
htons
(
1050
);
}
...
...
dev/minic.c
View file @
95ff18a6
...
...
@@ -36,34 +36,38 @@
rc = (raw) & 0xfffffff; \
fc = (raw >> 28) & 0xf;
//#define RX_DUMP
/* Exported for snmp. */
struct
wr_minic
minic
;
static
unsigned
char
ver_supported
;
static
inline
void
minic_writel
(
uint32_t
reg
,
uint32_t
data
)
static
inline
void
minic_writel
(
struct
wr_minic
*
nic
,
uint32_t
reg
,
uint32_t
data
)
{
*
(
volatile
uint32_t
*
)(
BASE_MINIC
+
reg
)
=
data
;
*
(
volatile
uint32_t
*
)(
nic
->
base
+
reg
)
=
data
;
}
static
inline
uint32_t
minic_readl
(
uint32_t
reg
)
static
inline
uint32_t
minic_readl
(
struct
wr_minic
*
nic
,
uint32_t
reg
)
{
return
*
(
volatile
uint32_t
*
)(
BASE_MINIC
+
reg
);
return
*
(
volatile
uint32_t
*
)(
nic
->
base
+
reg
);
}
static
inline
void
minic_txword
(
int
type
,
uint16_t
word
)
static
inline
void
minic_txword
(
struct
wr_minic
*
nic
,
int
type
,
uint16_t
word
)
{
minic_writel
(
MINIC_REG_TX_FIFO
,
MINIC_TX_FIFO_TYPE_W
(
type
)
|
MINIC_TX_FIFO_DAT_W
(
word
));
minic_writel
(
nic
,
MINIC_REG_TX_FIFO
,
MINIC_TX_FIFO_TYPE_W
(
type
)
|
MINIC_TX_FIFO_DAT_W
(
word
));
}
void
minic_init
(
void
)
void
minic_init
(
struct
wr_minic
*
nic
,
void
*
base
)
{
uint32_t
mcr
;
nic
->
base
=
base
;
/* before doing anything, check the HDL interface version */
mcr
=
minic_readl
(
MINIC_REG_MCR
);
mcr
=
minic_readl
(
nic
,
MINIC_REG_MCR
);
if
(
MINIC_MCR_VER_R
(
mcr
)
!=
MINIC_HDL_VERSION
)
{
pp_printf
(
"Error: Minic HDL version %d not supported by sw
\n
"
,
(
int
)
MINIC_MCR_VER_R
(
mcr
));
...
...
@@ -73,31 +77,32 @@ void minic_init(void)
ver_supported
=
1
;
/* disable interrupts, driver does polling */
minic_writel
(
MINIC_REG_EIC_IDR
,
MINIC_EIC_IDR_TX
|
minic_writel
(
nic
,
MINIC_REG_EIC_IDR
,
MINIC_EIC_IDR_TX
|
MINIC_EIC_IDR_RX
|
MINIC_EIC_IDR_TXTS
);
/* enable RX path */
minic_writel
(
MINIC_REG_MCR
,
mcr
|
MINIC_MCR_RX_EN
);
minic_writel
(
nic
,
MINIC_REG_MCR
,
mcr
|
MINIC_MCR_RX_EN
);
}
void
minic_disable
()
void
minic_disable
(
struct
wr_minic
*
nic
)
{
minic_writel
(
MINIC_REG_MCR
,
0
);
minic_writel
(
nic
,
MINIC_REG_MCR
,
0
);
}
int
minic_poll_rx
()
int
minic_poll_rx
(
struct
wr_minic
*
nic
)
{
uint32_t
mcr
;
if
(
!
ver_supported
)
return
0
;
mcr
=
minic_readl
(
MINIC_REG_MCR
);
mcr
=
minic_readl
(
nic
,
MINIC_REG_MCR
);
return
(
mcr
&
MINIC_MCR_RX_EMPTY
)
?
0
:
1
;
}
int
minic_rx_frame
(
struct
wr_ethhdr
*
hdr
,
uint8_t
*
payload
,
uint32_t
buf_size
,
int
minic_rx_frame
(
struct
wr_minic
*
nic
,
struct
wr_ethhdr
*
hdr
,
uint8_t
*
payload
,
uint32_t
buf_size
,
struct
hw_timestamp
*
hwts
)
{
uint32_t
hdr_size
,
payload_size
;
...
...
@@ -112,8 +117,11 @@ int minic_rx_frame(struct wr_ethhdr *hdr, uint8_t * payload, uint32_t buf_size,
int
cntr_diff
;
int
got_rx_error
=
0
;
if
(
!
ver_supported
)
return
0
;
/* check if there is something in the Rx FIFO to be retrieved */
if
((
minic_readl
(
MINIC_REG_MCR
)
&
MINIC_MCR_RX_EMPTY
)
||
!
ver_supported
)
if
((
minic_readl
(
nic
,
MINIC_REG_MCR
)
&
MINIC_MCR_RX_EMPTY
)
)
return
0
;
hdr_size
=
0
;
...
...
@@ -127,22 +135,22 @@ int minic_rx_frame(struct wr_ethhdr *hdr, uint8_t * payload, uint32_t buf_size,
oob_hdr
=
RXOOB_TS_INCORRECT
;
#ifdef RX_DUMP
pp_printf
(
"RX
:"
);
pp_printf
(
"RX
@%x:"
,
(
unsigned
)
nic
->
base
);
#endif
do
{
u
int32_t
rx
;
u
nsigned
rx
;
rx
=
minic_readl
(
MINIC_REG_RX_FIFO
);
rx
=
minic_readl
(
nic
,
MINIC_REG_RX_FIFO
);
#ifdef RX_DUMP
if
((
rx
>>
16
)
==
0
)
pp_printf
(
" %04x"
,
(
unsigned
)
rx
);
pp_printf
(
" %04x"
,
rx
);
else
pp_printf
(
" %08x"
,
(
unsigned
)
rx
);
pp_printf
(
" %08x"
,
rx
);
#endif
rx_type
=
MINIC_RX_FIFO_TYPE_R
(
rx
);
rx_data
=
(
uint16_t
)
MINIC_RX_FIFO_DAT_R
(
rx
);
rx_empty
=
(
rx
&
MINIC_RX_FIFO_EMPTY
)
?
1
:
0
;
rx_data
=
MINIC_RX_FIFO_DAT_R
(
rx
);
rx_empty
=
(
rx
&
MINIC_RX_FIFO_EMPTY
);
if
(
rx_type
==
WRF_DATA
&&
hdr_size
<
ETH_HEADER_SIZE
)
{
/* reading header */
...
...
@@ -168,8 +176,8 @@ int minic_rx_frame(struct wr_ethhdr *hdr, uint8_t * payload, uint32_t buf_size,
//pp_printf("Rxstat %x\n", rx_data);
if
(
RX_STATUS_ERROR
(
rx_data
))
{
pp_printf
(
"Warning: Minic received erroneous "
"frame, %x
\n
"
,
rx_data
);
pp_printf
(
"Warning: Minic
@%x
received erroneous "
"frame, %x
\n
"
,
(
unsigned
)
nic
->
base
,
rx
);
got_rx_error
=
1
;
}
...
...
@@ -225,20 +233,21 @@ int minic_rx_frame(struct wr_ethhdr *hdr, uint8_t * payload, uint32_t buf_size,
/* Increment Rx counter for statistics */
if
(
got_rx_error
)
{
minic
.
rx_errors
++
;
nic
->
rx_errors
++
;
return
-
1
;
}
else
{
minic
.
rx_count
++
;
nic
->
rx_count
++
;
}
if
(
minic_readl
(
MINIC_REG_MCR
)
&
MINIC_MCR_RX_FULL
)
if
(
minic_readl
(
nic
,
MINIC_REG_MCR
)
&
MINIC_MCR_RX_FULL
)
pp_printf
(
"Warning: Minic Rx fifo full, expect wrong frames
\n
"
);
/* return number of bytes written to the *payload buffer */
return
(
buf_size
<
payload_size
?
buf_size
:
payload_size
);
}
int
minic_tx_frame
(
struct
wr_ethhdr_vlan
*
hdr
,
uint8_t
*
payload
,
uint32_t
size
,
int
minic_tx_frame
(
struct
wr_minic
*
nic
,
struct
wr_ethhdr_vlan
*
hdr
,
uint8_t
*
payload
,
uint32_t
size
,
struct
hw_timestamp
*
hwts
)
{
uint32_t
mcr
,
pwords
,
hwords
;
...
...
@@ -260,10 +269,10 @@ int minic_tx_frame(struct wr_ethhdr_vlan *hdr, uint8_t *payload, uint32_t size,
pwords
=
size
>>
1
;
/* First we write status word (empty status for Tx) */
minic_txword
(
WRF_STATUS
,
0
);
minic_txword
(
nic
,
WRF_STATUS
,
0
);
#ifdef TX_DUMP
pp_printf
(
"TX
:"
);
pp_printf
(
"TX
@%x:"
,
(
unsigned
)
nic
->
base
);
#endif
/* Write the header of the frame */
ptr
=
(
uint16_t
*
)
hdr
;
...
...
@@ -271,7 +280,7 @@ int minic_tx_frame(struct wr_ethhdr_vlan *hdr, uint8_t *payload, uint32_t size,
#ifdef TX_DUMP
pp_printf
(
" %04x"
,
htons
(
ptr
[
i
]));
#endif
minic_txword
(
WRF_DATA
,
htons
(
ptr
[
i
]));
minic_txword
(
nic
,
WRF_DATA
,
htons
(
ptr
[
i
]));
}
/* Write the payload without the last word (which can be one byte) */
...
...
@@ -280,12 +289,12 @@ int minic_tx_frame(struct wr_ethhdr_vlan *hdr, uint8_t *payload, uint32_t size,
#ifdef TX_DUMP
pp_printf
(
" %04x"
,
htons
(
ptr
[
i
]));
#endif
minic_txword
(
WRF_DATA
,
htons
(
ptr
[
i
]));
minic_txword
(
nic
,
WRF_DATA
,
htons
(
ptr
[
i
]));
}
/* Write last word of the payload (which can be one byte) */
if
(
size
&
1
)
minic_txword
(
WRF_BYTESEL
,
htons
(
ptr
[
i
]));
minic_txword
(
nic
,
WRF_BYTESEL
,
htons
(
ptr
[
i
]));
#ifdef TX_DUMP
pp_printf
(
"
\n
"
);
...
...
@@ -293,18 +302,18 @@ int minic_tx_frame(struct wr_ethhdr_vlan *hdr, uint8_t *payload, uint32_t size,
/* Write also OOB if needed */
if
(
hwts
)
{
minic_txword
(
WRF_OOB
,
TX_OOB
);
minic_txword
(
WRF_OOB
,
WRPC_FID
);
minic_txword
(
nic
,
WRF_OOB
,
TX_OOB
);
minic_txword
(
nic
,
WRF_OOB
,
WRPC_FID
);
}
/* Start sending the frame, and while we read mcr check for fifo full */
mcr
=
minic_readl
(
MINIC_REG_MCR
);
mcr
=
minic_readl
(
nic
,
MINIC_REG_MCR
);
assert_warn
((
mcr
&
MINIC_MCR_TX_FULL
)
==
0
,
"Minic tx fifo full
\n
"
);
minic_writel
(
MINIC_REG_MCR
,
mcr
|
MINIC_MCR_TX_START
);
minic_writel
(
nic
,
MINIC_REG_MCR
,
mcr
|
MINIC_MCR_TX_START
);
/* wait for the DMA to finish */
for
(
i
=
0
;
i
<
1000
;
++
i
)
{
mcr
=
minic_readl
(
MINIC_REG_MCR
);
mcr
=
minic_readl
(
nic
,
MINIC_REG_MCR
);
if
((
mcr
&
MINIC_MCR_TX_IDLE
)
!=
0
)
break
;
timer_delay_ms
(
1
);
}
...
...
@@ -322,7 +331,7 @@ int minic_tx_frame(struct wr_ethhdr_vlan *hdr, uint8_t *payload, uint32_t size,
/* wait for the timestamp */
for
(
i
=
0
;
i
<
100
;
++
i
)
{
mcr
=
minic_readl
(
MINIC_REG_MCR
);
mcr
=
minic_readl
(
nic
,
MINIC_REG_MCR
);
if
((
mcr
&
MINIC_MCR_TX_TS_READY
)
!=
0
)
break
;
timer_delay_ms
(
1
);
}
...
...
@@ -337,11 +346,11 @@ int minic_tx_frame(struct wr_ethhdr_vlan *hdr, uint8_t *payload, uint32_t size,
if
(
ts_valid
)
ts_valid
=
minic_readl
(
MINIC_REG_TSR0
)
ts_valid
=
minic_readl
(
nic
,
MINIC_REG_TSR0
)
&
MINIC_TSR0_VALID
;
raw_ts
=
minic_readl
(
MINIC_REG_TSR1
);
fid
=
MINIC_TSR0_FID_R
(
minic_readl
(
MINIC_REG_TSR0
));
raw_ts
=
minic_readl
(
nic
,
MINIC_REG_TSR1
);
fid
=
MINIC_TSR0_FID_R
(
minic_readl
(
nic
,
MINIC_REG_TSR0
));
if
(
fid
!=
WRPC_FID
)
{
wrc_verbose
(
"minic_tx_frame: unmatched fid %d vs %d
\n
"
,
...
...
@@ -360,16 +369,16 @@ int minic_tx_frame(struct wr_ethhdr_vlan *hdr, uint8_t *payload, uint32_t size,
hwts
->
ahead
=
0
;
hwts
->
nsec
=
counter_r
*
(
REF_CLOCK_PERIOD_PS
/
1000
);
minic
.
tx_count
++
;
nic
->
tx_count
++
;
}
return
size
;
}
void
minic_get_stats
(
int
*
tx_frames
,
int
*
rx_frames
,
int
*
rx_errors
)
void
minic_get_stats
(
struct
wr_minic
*
nic
,
int
*
tx_frames
,
int
*
rx_frames
,
int
*
rx_errors
)
{
*
tx_frames
=
minic
.
tx_count
;
*
rx_frames
=
minic
.
rx_count
;
*
tx_frames
=
nic
->
tx_count
;
*
rx_frames
=
nic
->
rx_count
;
if
(
rx_errors
)
*
rx_errors
=
minic
.
rx_errors
;
*
rx_errors
=
nic
->
rx_errors
;
}
dev/netif.c
View file @
95ff18a6
...
...
@@ -22,7 +22,7 @@
static
unsigned
char
netif_n_count
=
0
;
static
struct
wrc_netif_device
netif_devs
[
WRC_NETIF_MAX_DEVICES
];
int
netif_register_device
(
struct
wr_endpoint_device
*
ep
)
int
netif_register_device
(
struct
wr_endpoint_device
*
ep
,
struct
wr_minic
*
nic
)
{
if
(
netif_n_count
>=
WRC_NETIF_MAX_DEVICES
)
return
-
1
;
...
...
@@ -30,6 +30,7 @@ int netif_register_device(struct wr_endpoint_device* ep)
struct
wrc_netif_device
*
ndev
=
&
netif_devs
[
netif_n_count
];
ndev
->
ep
=
ep
;
ndev
->
nic
=
nic
;
dev_dbg
(
"Registered network interface %u @ %p
\n
"
,
netif_n_count
,
ndev
->
ep
->
base
);
...
...
include/dev/minic.h
View file @
95ff18a6
...
...
@@ -19,17 +19,14 @@
#define TX_OOB 0x1000
void
minic_init
(
void
);
void
minic_disable
(
void
);
int
minic_poll_rx
(
void
);
void
minic_get_stats
(
int
*
tx_frames
,
int
*
rx_frames
,
int
*
rx_errors
);
/* Standard ethernet mac packet header. */
struct
wr_ethhdr
{
uint8_t
dstmac
[
6
];
uint8_t
srcmac
[
6
];
uint16_t
ethtype
;
};
/* Ethernet mac packet header with VLAN. */
struct
wr_ethhdr_vlan
{
uint8_t
dstmac
[
6
];
uint8_t
srcmac
[
6
];
...
...
@@ -39,7 +36,8 @@ struct wr_ethhdr_vlan {
};
struct
wr_minic
{
int
tx_count
,
rx_count
,
rx_errors
;
void
*
base
;
unsigned
tx_count
,
rx_count
,
rx_errors
;
};
struct
hw_timestamp
{
...
...
@@ -52,9 +50,16 @@ struct hw_timestamp {
extern
struct
wr_minic
minic
;
int
minic_rx_frame
(
struct
wr_ethhdr
*
hdr
,
uint8_t
*
payload
,
uint32_t
buf_size
,
void
minic_init
(
struct
wr_minic
*
nic
,
void
*
base
);
void
minic_disable
(
struct
wr_minic
*
nic
);
int
minic_poll_rx
(
struct
wr_minic
*
nic
);
void
minic_get_stats
(
struct
wr_minic
*
nic
,
int
*
tx_frames
,
int
*
rx_frames
,
int
*
rx_errors
);
int
minic_rx_frame
(
struct
wr_minic
*
nic
,
struct
wr_ethhdr
*
hdr
,
uint8_t
*
payload
,
uint32_t
buf_size
,
struct
hw_timestamp
*
hwts
);
int
minic_tx_frame
(
struct
wr_ethhdr_vlan
*
hdr
,
uint8_t
*
payload
,
uint32_t
size
,
int
minic_tx_frame
(
struct
wr_minic
*
nic
,
struct
wr_ethhdr_vlan
*
hdr
,
uint8_t
*
payload
,
uint32_t
size
,
struct
hw_timestamp
*
hwts
);
#endif
include/dev/netif.h
View file @
95ff18a6
...
...
@@ -18,9 +18,10 @@
struct
wrc_netif_device
{
struct
wr_endpoint_device
*
ep
;
struct
wr_minic
*
nic
;
};
int
netif_register_device
(
struct
wr_endpoint_device
*
ep
);
int
netif_register_device
(
struct
wr_endpoint_device
*
ep
,
struct
wr_minic
*
nic
);
int
netif_get_device_count
(
void
);
struct
wrc_netif_device
*
netif_get_device
(
int
idx
);
...
...
include/net.h
View file @
95ff18a6
...
...
@@ -42,6 +42,7 @@ struct sockq {
struct
wrpc_socket
{
struct
wr_sockaddr
bind_addr
;
struct
wrc_netif_device
*
nif
;
uint16_t
prio
;
uint32_t
phase_transition
;
...
...
@@ -78,6 +79,8 @@ struct wr_timestamp {
int
correct
;
};
struct
wr_minic
;
/* Copy a mac address (wrapper around memcpy). */
void
copy_eth_addr
(
mac_addr_t
dest
,
const
mac_addr_t
src
);
...
...
@@ -85,8 +88,9 @@ void copy_eth_addr(mac_addr_t dest, const mac_addr_t src);
// to bind_addr.
struct
wrpc_socket
*
ptpd_netif_create_socket
(
struct
wrpc_socket
*
s
,
unsigned
len
,
struct
wr_sockaddr
*
bind_addr
,
int
udp_or_raw
,
int
udpport
);
struct
wr_sockaddr
*
bind_addr
,
int
udp_or_raw
,
int
udpport
,
struct
wrc_netif_device
*
nif
);
// Sends a UDP/RAW packet (data, data_length) to addr in wr_sockaddr.
// For raw frames, mac/ethertype needs to be provided, for UDP - ip/port.
...
...
lib/arp.c
View file @
95ff18a6
...
...
@@ -13,6 +13,7 @@
#include "dev/endpoint.h"
#include "ipv4.h"
#include "net.h"
#include "dev/netif.h"
#include "wrc_global.h"
static
DECLARE_WRPC_SOCKET
(
arp_socket
,
128
);
...
...
@@ -32,6 +33,7 @@ static struct wrpc_socket *arp_socket;
void
arp_init
(
void
)
{
struct
wr_sockaddr
saddr
;
struct
wrc_netif_device
*
nif
=
netif_get_device
(
0
);
/* Configure socket filter */
memset
(
&
saddr
,
0
,
sizeof
(
saddr
));
...
...
@@ -40,7 +42,7 @@ void arp_init(void)
arp_socket
=
ptpd_netif_create_socket
(
GET_WRPC_SOCKET
(
arp_socket
),
LEN_WRPC_SOCKET
(
arp_socket
),
&
saddr
,
PTPD_SOCK_RAW_ETHERNET
,
0
);
&
saddr
,
PTPD_SOCK_RAW_ETHERNET
,
0
,
nif
);
}
static
int
process_arp
(
uint8_t
*
buf
,
int
len
)
...
...
lib/ipv4.c
View file @
95ff18a6
...
...
@@ -58,23 +58,24 @@ unsigned int ipv4_checksum(unsigned short *buf, int shorts)
void
ipv4_init
(
void
)
{
struct
wr_sockaddr
saddr
;
struct
wrc_netif_device
*
nif
=
netif_get_device
(
0
);
/* Bootp: use UDP engine activated by function arguments */
bootp_socket
=
ptpd_netif_create_socket
(
GET_WRPC_SOCKET
(
bootp_socket
),
LEN_WRPC_SOCKET
(
bootp_socket
),
NULL
,
PTPD_SOCK_UDP
,
68
/* bootpc */
);
NULL
,
PTPD_SOCK_UDP
,
68
/* bootpc */
,
nif
);
/* time (rdate): UDP */
rdate_socket
=
ptpd_netif_create_socket
(
GET_WRPC_SOCKET
(
rdate_socket
),
LEN_WRPC_SOCKET
(
rdate_socket
),
NULL
,
PTPD_SOCK_UDP
,
37
/* time */
);
NULL
,
PTPD_SOCK_UDP
,
37
/* time */
,
nif
);
/* ICMP: specify raw (not UDP), with IPV4 ethtype */
memset
(
&
saddr
,
0
,
sizeof
(
saddr
));
saddr
.
ethertype
=
htons
(
0x0800
);
icmp_socket
=
ptpd_netif_create_socket
(
GET_WRPC_SOCKET
(
icmp_socket
),
LEN_WRPC_SOCKET
(
icmp_socket
),
&
saddr
,
PTPD_SOCK_RAW_ETHERNET
,
0
);
&
saddr
,
PTPD_SOCK_RAW_ETHERNET
,
0
,
nif
);
syslog_init
();
}
...
...
lib/latency.c
View file @
95ff18a6
...
...
@@ -6,14 +6,15 @@
*
* Released according to the GNU GPL, version 2 or any later version.
*/
#include
<wrc.h>
#include
<wrpc.h>
#include
<net.h>
#include
<shell.h>
#include
"wrc.h"
#include
"wrpc.h"
#include
"net.h"
#include
"shell.h"
#include "ipv4.h"
#include <dev/endpoint.h>
/* get_mac_addr() */
#include <ppsi/jiffies.h>
/* time_before() */
#include <lib/syslog.h>
#include "dev/endpoint.h"
/* get_mac_addr() */
#include "ppsi/jiffies.h"
/* time_before() */
#include "dev/netif.h"
#include "lib/syslog.h"
#define jiffies timer_get_tics()
#ifdef CONFIG_LATENCY_SYSLOG
...
...
@@ -39,10 +40,12 @@ static struct wr_sockaddr latency_addr = {
void
latency_init
(
void
)
{
struct
wrc_netif_device
*
nif
=
netif_get_device
(
0
);
latency_addr
.
ethertype
=
htons
(
CONFIG_LATENCY_ETHTYPE
);
latency_socket
=
ptpd_netif_create_socket
(
GET_WRPC_SOCKET
(
latency_socket
),
LEN_WRPC_SOCKET
(
latency_socket
),
&
latency_addr
,
PTPD_SOCK_RAW_ETHERNET
,
0
);
&
latency_addr
,
PTPD_SOCK_RAW_ETHERNET
,
0
,
nif
);
}
static
struct
latency_frame
{
...
...
lib/lldp.c
View file @
95ff18a6
...
...
@@ -25,6 +25,7 @@
#include "shell.h"
#include "wrc_ptp.h"
#include "wrc_global.h"
#include "dev/netif.h"
#include "dev/syscon.h"
#include "softpll_ng.h"
...
...
@@ -242,6 +243,7 @@ static void lldp_update(void)
void
lldp_init
(
void
)
{
struct
wrc_netif_device
*
nif
=
netif_get_device
(
0
);
struct
wr_sockaddr
saddr
;
/* LLDP: raw ethernet*/
...
...
@@ -250,7 +252,7 @@ void lldp_init(void)
lldp_socket
=
ptpd_netif_create_socket
(
GET_WRPC_SOCKET
(
lldp_socket
),
LEN_WRPC_SOCKET
(
lldp_socket
),
&
saddr
,
PTPD_SOCK_RAW_ETHERNET
,
0
);
&
saddr
,
PTPD_SOCK_RAW_ETHERNET
,
0
,
nif
);
memset
(
&
addr
,
0x0
,
sizeof
(
struct
wr_sockaddr
));
memcpy
(
addr
.
mac
,
LLDP_MCAST_MAC
,
6
);
...
...
lib/net.c
View file @
95ff18a6
...
...
@@ -22,6 +22,7 @@
#include "dev/pps_gen.h"
#include "dev/minic.h"
#include "dev/endpoint.h"
#include "dev/netif.h"
#include "softpll_ng.h"
#include "ipv4.h"
#include "dev/rxts_calibrator.h"
...
...
@@ -43,11 +44,11 @@ void ptpd_netif_set_phase_transition(uint32_t phase)
}
}
struct
wrpc_socket
*
ptpd_netif_create_socket
(
struct
wrpc_socket
*
sock
,
unsigned
len
,
struct
wr_sockaddr
*
bind_addr
,
int
udp_or_raw
,
int
udpport
)
int
udp_or_raw
,
int
udpport
,
struct
wrc_netif_device
*
nif
)
{
int
i
;
...
...
@@ -72,6 +73,8 @@ struct wrpc_socket *ptpd_netif_create_socket(struct wrpc_socket *sock,
sock
->
bind_addr
.
udpport
=
udpport
;
}
sock
->
nif
=
nif
;
net_verbose
(
"%s: socket %p for %04x:%04x, slot %i
\n
"
,
__func__
,
sock
,
ntohs
(
sock
->
bind_addr
.
ethertype
),
udpport
,
i
);
...
...
@@ -264,16 +267,16 @@ int ptpd_netif_recvfrom(struct wrpc_socket *s, struct wr_sockaddr *from, void *d
return
min
(
size
,
data_length
);
}
int
ptpd_netif_sendto
(
struct
wrpc_socket
*
sock
,
struct
wr_sockaddr
*
to
,
void
*
data
,
size_t
data_length
,
struct
wr_timestamp
*
tx_timestamp
)
int
ptpd_netif_sendto
(
struct
wrpc_socket
*
sock
,
struct
wr_sockaddr
*
to
,
void
*
data
,
size_t
data_length
,
struct
wr_timestamp
*
tx_timestamp
)
{
struct
wrpc_socket
*
s
=
(
struct
wrpc_socket
*
)
sock
;
struct
hw_timestamp
hwts
;
struct
wr_ethhdr_vlan
hdr
;
int
rval
;
copy_eth_addr
(
hdr
.
dstmac
,
to
->
mac
);
copy_eth_addr
(
hdr
.
srcmac
,
wrc_endpoint_dev
.
mac_addr
);
copy_eth_addr
(
hdr
.
srcmac
,
sock
->
nif
->
ep
->
mac_addr
);
if
(
wrc_vlan_number
)
{
hdr
.
ethtype
=
htons
(
0x8100
);
hdr
.
tag
=
htons
(
wrc_vlan_number
|
(
sock
->
prio
<<
13
));
...
...
@@ -282,11 +285,11 @@ int ptpd_netif_sendto(struct wrpc_socket * sock, struct wr_sockaddr *to, void *d
hdr
.
ethtype
=
sock
->
bind_addr
.
ethertype
;
}
net_verbose
(
"TX: socket %04x:%04x, len %i
\n
"
,
ntohs
(
s
->
bind_addr
.
ethertype
),
s
->
bind_addr
.
udpport
,
ntohs
(
s
ock
->
bind_addr
.
ethertype
),
s
ock
->
bind_addr
.
udpport
,
data_length
);
rval
=
minic_tx_frame
(
&
hdr
,
(
uint8_t
*
)
data
,
data_length
,
&
hwts
);
rval
=
minic_tx_frame
(
sock
->
nif
->
nic
,
&
hdr
,
(
uint8_t
*
)
data
,
data_length
,
&
hwts
);
if
(
tx_timestamp
)
{
tx_timestamp
->
sec
=
hwts
.
sec
;
...
...
@@ -297,7 +300,7 @@ int ptpd_netif_sendto(struct wrpc_socket * sock, struct wr_sockaddr *to, void *d
return
rval
;
}
int
net_bh_poll
(
void
)
static
int
netif_poll
(
struct
wrc_netif_device
*
nif
)
{
struct
wrpc_socket
*
s
=
NULL
,
*
raws
=
NULL
,
*
udps
=
NULL
;
struct
sockq
*
q
;
...
...
@@ -309,7 +312,7 @@ int net_bh_poll(void)
uint16_t
size
,
port
;
uint16_t
ethtype
,
tag
;
recvd
=
minic_rx_frame
(
&
hdr
,
buffer
,
sizeof
(
buffer
),
&
hwts
);
recvd
=
minic_rx_frame
(
nif
->
nic
,
&
hdr
,
buffer
,
sizeof
(
buffer
),
&
hwts
);
if
(
recvd
<=
0
)
/* No data received? */
return
0
;
...
...
@@ -327,7 +330,7 @@ int net_bh_poll(void)
net_verbose
(
"%s: want vlan %i, got %i: discard
\n
"
,
__func__
,
wrc_vlan_number
,
ntohs
(
tag
)
&
0xfff
);
return
0
;
return
0
;
}
/* Prepare for IP/UDP checks */
...
...
@@ -340,6 +343,8 @@ int net_bh_poll(void)
s
=
socks
[
i
];
if
(
!
s
)
continue
;
if
(
s
->
nif
!=
nif
)
continue
;
if
(
hdr
.
ethtype
!=
s
->
bind_addr
.
ethertype
)
continue
;
if
(
!
port
&&
!
s
->
bind_addr
.
udpport
)
...
...
@@ -395,3 +400,17 @@ int net_bh_poll(void)
q
->
avail
,
q
->
n
,
q_required
);
return
1
;
}
int
net_bh_poll
(
void
)
{
unsigned
i
;
int
res
=
0
;
for
(
i
=
0
;
i
<
netif_get_device_count
();
i
++
)
{
struct
wrc_netif_device
*
nif
=
netif_get_device
(
i
);
res
|=
netif_poll
(
nif
);
}
return
res
;
}
lib/netconsole.c
View file @
95ff18a6
...
...
@@ -7,14 +7,15 @@
* Released according to the GNU GPL, version 2 or any later version.
*/
#include <string.h>
#include
<wrc.h>
#include
<wrpc.h>
#include
"wrc.h"
#include
"wrpc.h"
#include "wrc_global.h"
#include "ipv4.h"
#include "net.h"
#include "shell.h"
#include "netconsole.h"
#include "dev/netif.h"
#ifdef CONFIG_NETCONSOLE_DEF_WAIT
#define NETCONSOLE_DEF_VAL NETCONSOLE_WAIT
...
...
@@ -35,9 +36,11 @@ struct wr_udp_addr netconsole_udp_addr;
/* init for netconsole task */
void
netconsole_init
(
void
)
{
struct
wrc_netif_device
*
nif
=
netif_get_device
(
0
);
netconsole_socket
=
ptpd_netif_create_socket
(
GET_WRPC_SOCKET
(
netconsole_socket
),
LEN_WRPC_SOCKET
(
netconsole_socket
),
NULL
,
PTPD_SOCK_UDP
,
NETCONSOLE_PORT
);
NULL
,
PTPD_SOCK_UDP
,
NETCONSOLE_PORT
,
nif
);
}
int
netconsole_read_byte
(
void
)
...
...
lib/snmp.c
View file @
95ff18a6
...
...
@@ -22,6 +22,7 @@
#include "dev/minic.h"
#include "ipv4.h"
#include "net.h"
#include "dev/netif.h"
#include "dev/pps_gen.h"
#include "hw/etherbone-config.h"
#include "revision.h"
...
...
@@ -269,8 +270,6 @@ static uint32_t aux_diag_reg_ro_num;
static
uint32_t
aux_diag_reg_rw_num
;
extern
struct
pp_instance
ppi_static
;
/* __DATE__ and __TIME__ is already stored in struct spll_stats stats, but
* redefining it here makes code smaller than concatenate existing one */
static
const
char
snmp_build_date
[]
=
__DATE__
" "
__TIME__
;
...
...
@@ -611,11 +610,12 @@ void snmp_init(void)
{
uint32_t
aux_diag_id
;
uint32_t
aux_diag_ver
;
struct
wrc_netif_device
*
nif
=
netif_get_device
(
0
);
/* Use UDP engine activated by function arguments */
snmp_socket
=
ptpd_netif_create_socket
(
GET_WRPC_SOCKET
(
snmp_socket
),
LEN_WRPC_SOCKET
(
snmp_socket
),
NULL
,
PTPD_SOCK_UDP
,
161
/* snmp */
);
NULL
,
PTPD_SOCK_UDP
,
161
/* snmp */
,
nif
);
if
(
SNMP_AUX_DIAG_ENABLED
)
{
/* Fix ID and version of aux diag registers by values read from FPGA */
diag_read_info
(
&
aux_diag_id
,
&
aux_diag_ver
,
&
aux_diag_reg_rw_num
,
...
...
lib/syslog.c
View file @
95ff18a6
...
...
@@ -23,9 +23,11 @@ static uint32_t tics, tics_zero;
void
syslog_init
(
void
)
{
struct
wrc_netif_device
*
nif
=
netif_get_device
(
0
);
syslog_socket
=
ptpd_netif_create_socket
(
GET_WRPC_SOCKET
(
syslog_socket
),
LEN_WRPC_SOCKET
(
syslog_socket
),
NULL
,
PTPD_SOCK_UDP
,
514
/* syslog */
);
NULL
,
PTPD_SOCK_UDP
,
514
/* syslog */
,
nif
);
syslog_addr
.
sport
=
syslog_addr
.
dport
=
htons
(
514
);
tics_zero
=
timer_get_tics
();
}
...
...
lib/task-diags.c
View file @
95ff18a6
...
...
@@ -26,6 +26,7 @@
int
wrc_wr_diags
(
void
)
{
static
uint32_t
last_update_tick
;
struct
wrc_netif_device
*
ndev
=
netif_get_device
(
0
);
int
tx
,
rx
,
rx_err
;
uint64_t
sec
;
uint32_t
nsec
;
...
...
@@ -51,7 +52,7 @@ int wrc_wr_diags(void)
wdiag_set_valid
(
0
);
/* frame statistics */
minic_get_stats
(
&
tx
,
&
rx
,
&
rx_err
);
minic_get_stats
(
ndev
->
nic
,
&
tx
,
&
rx
,
&
rx_err
);
wdiags_write_cnts
(
tx
,
rx
,
rx_err
);
/* local time */
...
...
lib/task-stats.c
View file @
95ff18a6
...
...
@@ -26,6 +26,7 @@ uint32_t wrc_stats_last;
int
wrc_log_stats
(
void
)
{
struct
wrc_netif_device
*
ndev
=
netif_get_device
(
0
);
int
tx
,
rx
,
rx_err
;
struct
spll_aux_clock_status
aux_stat
;
uint64_t
sec
;
...
...
@@ -61,7 +62,7 @@ int wrc_log_stats(void)
wrc_stats_last
=
s
->
update_count
;
shw_pps_gen_get_time
(
&
sec
,
&
nsec
);
minic_get_stats
(
&
tx
,
&
rx
,
&
rx_err
);
minic_get_stats
(
ndev
->
nic
,
&
tx
,
&
rx
,
&
rx_err
);
pp_printf
(
"lnk:%d rx:%d tx:%d "
,
(
wrc_global_link
.
link_up
==
NETIF_LINK_UP
),
rx
,
tx
);
pp_printf
(
"lock:%d "
,
spll_check_lock
(
0
)
?
1
:
0
);
...
...
monitor/monitor_ppsi.c
View file @
95ff18a6
...
...
@@ -311,7 +311,7 @@ static void print_port(unsigned i)
}
else
pcprintf
(
7
,
26
,
C_GREEN
,
" "
);
minic_get_stats
(
&
tx
,
&
rx
,
&
rx_err
);
minic_get_stats
(
ndev
->
nic
,
&
tx
,
&
rx
,
&
rx_err
);
pcprintf
(
7
,
52
,
C_MAGENTA
,
"%7d"
,
rx
);
pprintf
(
7
,
62
,
"%7d"
,
tx
);
pprintf
(
7
,
72
,
"%4d"
,
wrc_vlan_number
);
...
...
wrc_main.c
View file @
95ff18a6
...
...
@@ -114,14 +114,14 @@ static void wrc_initialize(void)
#ifndef BOARD_HAS_CUSTOM_NETWORK_INIT
net_rst
();
ep_init
(
&
wrc_endpoint_dev
,
(
void
*
)
BASE_EP
);
netif_register_device
(
&
wrc_endpoint_dev
);
netif_register_device
(
&
wrc_endpoint_dev
,
&
minic
);
/* Sleep for 1s to make sure WRS v4.2 always realizes that
* the link is down */
timer_delay_ms
(
200
);
ep_enable
(
&
wrc_endpoint_dev
,
1
,
1
);
#endif
minic_init
();
minic_init
(
&
minic
,
(
void
*
)
BASE_MINIC
);
shw_pps_gen_init
();
/* initialize w1 temp sensor. Note that w1 must have been initialized
...
...
wrc_main_sim.c
View file @
95ff18a6
...
...
@@ -90,7 +90,7 @@ static void wrc_sim_initialize(void)
ep_init
(
&
wrc_endpoint_dev
,
(
void
*
)
BASE_EP
);
ep_enable
(
&
wrc_endpoint_dev
,
1
,
1
);
minic_init
();
minic_init
(
&
minic
,
&
wrc_endpoint_dev
);
shw_pps_gen_init
();
spll_very_init
();
/* wait for link up before enabling tm_time_valid_o */
...
...
@@ -161,10 +161,10 @@ int wrpc_test_1(void)
/* A frame is sent out with sequenceID (firt octet) and awaited
* reception. */
minic_tx_frame
(
&
tx_hdr
,
tx_payload
,
62
,
&
hwts
);
minic_tx_frame
(
&
minic
,
&
tx_hdr
,
tx_payload
,
62
,
&
hwts
);
tx_cnt
++
;
ret
=
minic_rx_frame
(
&
rx_hdr
,
rx_payload
,
NET_MAX_SKBUF_SIZE
,
&
hwts
);
ret
=
minic_rx_frame
(
&
minic
,
&
rx_hdr
,
rx_payload
,
NET_MAX_SKBUF_SIZE
,
&
hwts
);
/** check whether the received value is OK */
if
(
ret
==
0
)
{
...
...
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