Commit 6479a356 authored by Tomasz Wlostowski's avatar Tomasz Wlostowski Committed by Grzegorz Daniluk

dev/netif: support for multiple network interfaces

parent b3e2fef0
......@@ -28,7 +28,8 @@ obj-$(CONFIG_EMBEDDED_NODE) += \
dev/ad9520.o \
dev/i2c_eeprom.o \
dev/storage.o \
dev/fine_pulse_generator.o
dev/fine_pulse_generator.o \
dev/netif.o
obj-$(CONFIG_WR_NODE) += \
dev/temperature.o \
......
......@@ -153,9 +153,9 @@ void ep_pfilter_init_default(struct wr_endpoint_device *dev)
uint32_t cr0, cr1;
cmd_word = v[0] | ((uint64_t)v[1] << 32);
mac_dbg("pfilter rule %02i: %x.%08x\n", i,
(uint32_t)(cmd_word >> 32),
(uint32_t)(cmd_word));
//mac_dbg("pfilter rule %02i: %x.%08x\n", i,
// (uint32_t)(cmd_word >> 32),
// (uint32_t)(cmd_word));
cr1 = EP_PFCR1_MM_DATA_LSB_W(cmd_word & 0xfff);
cr0 = EP_PFCR0_MM_ADDR_W(i) | EP_PFCR0_MM_DATA_MSB_W(cmd_word >> 12) |
......
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2011 CERN (www.cern.ch)
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* Released according to the GNU LGPL, version 2.1 or any later version.
*/
#include <stdio.h>
#include <wrc.h>
#include <dev/endpoint.h>
#include <dev/netif.h>
#include "board.h"
#ifndef WRC_NETIF_MAX_DEVICES
#define WRC_NETIF_MAX_DEVICES 2
#endif
static int netif_n_count = 0;
static struct wrc_netif_device netif_devs[WRC_NETIF_MAX_DEVICES];
struct wrc_endpoint_dev* netif_get_default_endpoint()
{
if( netif_n_count == 0 )
return NULL;
return netif_devs[0].ep;
}
int netif_register_device( const char *name, const char* desc, struct wr_endpoint_device* ep )
{
if( netif_n_count >= WRC_NETIF_MAX_DEVICES )
return -1;
struct wrc_netif_device *ndev = &netif_devs[ netif_n_count ];
netif_n_count++;
ndev->name = name;
ndev->ep = ep;
ndev->desc= desc;
ndev->rx_packets = 0;
ndev->tx_packets = 0;
ndev->link_state = NETIF_LINK_DOWN;
dev_dbg("Registered network interface %s @ %p\n", ndev->name, ndev->ep->base );
return 0;
}
int netif_get_device_count()
{
return netif_n_count;
}
static int netif_update_task()
{
int i;
for( i = 0; i < netif_n_count; i++ )
{
struct wrc_netif_device *ndev = &netif_devs[ i ];
int up = ep_link_up( ndev->ep, NULL );
//pp_printf("%s link %d\n", ndev->name, up );
switch(ndev->link_state)
{
case NETIF_LINK_DOWN:
if( up )
ndev->link_state = NETIF_LINK_WENT_UP;
break;
case NETIF_LINK_UP:
if( !up )
ndev->link_state = NETIF_LINK_WENT_DOWN;
break;
case NETIF_LINK_WENT_UP:
if( up )
ndev->link_state = NETIF_LINK_UP;
else
ndev->link_state = NETIF_LINK_WENT_DOWN;
break;
case NETIF_LINK_WENT_DOWN:
if( up )
ndev->link_state = NETIF_LINK_WENT_UP;
else
ndev->link_state = NETIF_LINK_DOWN;
break;
default:
break;
}
}
return 0;
}
struct wrc_netif_device* netif_get_device(int idx)
{
return &netif_devs[idx];
}
int netif_init()
{
wrc_task_create("netif", NULL, netif_update_task);
return 0;
}
\ No newline at end of file
......@@ -19,6 +19,7 @@
#include "dev/syscon.h"
#include "dev/endpoint.h"
#include "dev/netif.h"
#include "dev/rxts_calibrator.h"
/* New calibrator for the transition phase value. A major pain in the ass for
......@@ -238,7 +239,7 @@ static int calib_t24p_slave(uint32_t *value)
int retries = 0;
while (!(rv = rxts_calibration_update(value))) {
if (retries > CALIB_RETRIES || ep_link_up(&wrc_endpoint_dev, NULL) == LINK_DOWN)
if (retries > CALIB_RETRIES || ep_link_up(&wrc_endpoint_dev, NULL) == NETIF_LINK_DOWN)
return -1;
retries++;
}
......
/*
* This work is part of the White Rabbit project
*
* Copyright (C) 2011 CERN (www.cern.ch)
* Author: Tomasz Wlostowski <tomasz.wlostowski@cern.ch>
*
* Released according to the GNU LGPL, version 2.1 or any later version.
*/
#ifndef __WRC_NETIF_H
#define __WRC_NETIF_H
struct wrc_endpoint_dev;
#define NETIF_LINK_DOWN 0
#define NETIF_LINK_WENT_UP 1
#define NETIF_LINK_WENT_DOWN 2
#define NETIF_LINK_UP 3
struct wrc_netif_device
{
const char* name;
const char* desc;
struct wr_endpoint_device* ep;
int link_state;
int rx_packets;
int tx_packets;
};
struct wrc_endpoint_dev* netif_get_default_endpoint();
int netif_register_device( const char *name, const char* desc, struct wr_endpoint_device* ep );
int netif_get_device_count();
struct wrc_netif_device* netif_get_device(int idx);
#endif
......@@ -19,6 +19,7 @@
#include <dev/pps_gen.h>
#include <dev/onewire.h>
#include <dev/endpoint.h>
#include <dev/netif.h>
#include <temperature.h>
#include "wrc_ptp.h"
#include "hal_exports.h"
......@@ -132,15 +133,25 @@ int wrc_mon_gui(void)
wrpc_get_port_state(&state, NULL);
cprintf(C_BLUE, "\n\nLink status:");
cprintf(C_WHITE, "\n%s: ", "wru1");
if (state.state)
cprintf(C_GREEN, "Link up ");
else
cprintf(C_RED, "Link down ");
int ndevs = netif_get_device_count();
minic_get_stats(&tx, &rx);
cprintf(C_GREY, "(RX: %d, TX: %d)", rx, tx);
for( i = 0 ; i < ndevs; i++ )
{
struct wrc_netif_device *ndev = netif_get_device( i );
cprintf(C_WHITE, "\n%-5s: ", ndev->name );
if ( ndev->link_state == NETIF_LINK_UP )
cprintf(C_GREEN, "Link up ");
else
cprintf(C_RED, "Link down ");
if( i == 0 ) // fixme: independent rx/tx stats for each interface
{
minic_get_stats(&tx, &rx);
cprintf(C_GREY, "(RX: %d, TX: %d)", rx, tx);
}
}
if (!state.state) {
return 1;
}
......
......@@ -31,6 +31,14 @@ void decode_mac(const char *str, unsigned char *mac)
}
}
void decode_port(const char *str, int *port)
{
if( !str )
*port = 0;
else
*port = atoi(str);
}
char *format_mac(char *s, const unsigned char *mac)
{
pp_sprintf(s, "%02x:%02x:%02x:%02x:%02x:%02x",
......@@ -43,21 +51,23 @@ static int cmd_mac(const char *args[])
{
unsigned char mac[6];
char buf[32];
int port;
if (!args[0] || !strcasecmp(args[0], "get")) {
/* get current MAC */
ep_get_mac_addr(&wrc_endpoint_dev, mac);
} else if (!strcasecmp(args[0], "getp")) {
/* get persistent MAC */
ep_get_mac_addr(&wrc_endpoint_dev, mac);
storage_get_persistent_mac(mac);
decode_port(args[1], &port);
storage_get_persistent_mac(port, mac);
} else if (!strcasecmp(args[0], "set") && args[1]) {
decode_mac(args[1], mac);
ep_set_mac_addr(&wrc_endpoint_dev, mac);
ep_pfilter_init_default(&wrc_endpoint_dev);
} else if (!strcasecmp(args[0], "setp") && args[1]) {
decode_mac(args[1], mac);
storage_set_persistent_mac(mac);
decode_port(args[2], &port);
storage_set_persistent_mac(port, mac);
} else {
return -EINVAL;
}
......
......@@ -22,6 +22,7 @@
#include <dev/pps_gen.h>
#include <dev/gpio.h>
#include <dev/simple_uart.h>
#include <dev/netif.h>
#include <ptpd_netif.h>
#include <dev/i2c.h>
#include <storage.h>
......@@ -78,22 +79,27 @@ static void wrc_initialize(void)
timer_init(1);
spll_very_init();
usleep_init();
netif_init();
wrc_board_early_init();
pp_printf("WR Core: starting up...\n");
get_hw_name(wrc_hw_name);
#ifndef BOARD_HAS_CUSTOM_NETWORK_INIT
net_rst();
ep_init( &wrc_endpoint_dev, (void *) BASE_EP );
/* 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();
shw_pps_gen_init();
wrc_board_init();
storage_load_calibration();
wrc_ptp_init();
......@@ -102,7 +108,6 @@ static void wrc_initialize(void)
shell_init();
shell_register_commands();
wrc_board_init();
_endram = ENDRAM_MAGIC;
......@@ -117,7 +122,7 @@ int link_status;
static int is_link_up(void)
{
return link_status == LINK_UP;
return link_status == NETIF_LINK_UP;
}
static int wrc_check_link(void)
......@@ -132,14 +137,14 @@ static int wrc_check_link(void)
gen_gpio_out(&pin_sysc_led_link, 1);
sfp_match(0);
wrc_ptp_start();
link_status = LINK_WENT_UP;
link_status = NETIF_LINK_WENT_UP;
rv = 1;
} else if (prev_state && !state) {
wrc_verbose("Link down.\n");
prev_timing_ok = 0;
event_post( WRC_EVENT_LINK_DOWN );
gen_gpio_out(&pin_sysc_led_link, 0);
link_status = LINK_WENT_DOWN;
link_status = NETIF_LINK_WENT_DOWN;
wrc_ptp_stop();
rv = 1;
/* special case */
......@@ -147,7 +152,8 @@ static int wrc_check_link(void)
shw_pps_gen_enable_output(0);
} else
link_status = (state ? LINK_UP : LINK_DOWN);
link_status = (state ? NETIF_LINK_UP : NETIF_LINK_DOWN);
prev_state = state;
return rv;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment