Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tail-tagging support (for rt-kernel) #462

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/common/pf_lldp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,8 @@ static void pf_lldp_send (pnet_t * net, int loc_port_num)
p_buffer->len =
pf_lldp_construct_frame (net, loc_port_num, p_buffer->payload);

pnal_set_port_num(p_buffer, loc_port_num);

(void)pf_eth_send (net, p_port_data->netif.handle, p_buffer);
}

Expand Down Expand Up @@ -1926,6 +1928,8 @@ int pf_lldp_recv (
int loc_port_num = pf_port_get_port_number (net, eth_handle);
int err = 0;

pnal_get_port_num(p_frame_buf, &loc_port_num);

err = pf_lldp_parse_packet (buf, buf_len, &peer_data);

if (!err)
Expand Down
2 changes: 1 addition & 1 deletion src/device/pf_cmina.c
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ void pf_cmina_port_statistics_show (pnet_t * net)
}
else
{
printf ("Did not find port %s\n", p_port_data->netif.name);
printf ("Did not find statistics for port %s\n", p_port_data->netif.name);
}

port = pf_port_get_next (&port_iterator);
Expand Down
4 changes: 4 additions & 0 deletions src/pnal.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ pnal_buf_t * pnal_buf_alloc (uint16_t length);
void pnal_buf_free (pnal_buf_t * p);
uint8_t pnal_buf_header (pnal_buf_t * p, int16_t header_size_increment);

/* Functions to use when tail-tagging is enabled */
void pnal_get_port_num (pnal_buf_t * p, int * loc_port_num);
void pnal_set_port_num (pnal_buf_t * p, int loc_port_num);

/**
* Network interface handle, forward declaration.
*/
Expand Down
10 changes: 10 additions & 0 deletions src/ports/STM32Cube/pnal_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,13 @@ int pnal_eth_send (pnal_eth_handle_t * handle, pnal_buf_t * buf)
}
return ret;
}

void pnal_get_port_num (pnal_buf_t * p, int * loc_port_num)
{
/* Not yet applicable for STM32Cube */
}

void pnal_set_port_num (pnal_buf_t * p, int loc_port_num)
{
/* Not yet applicable for STM32Cube */
}
10 changes: 10 additions & 0 deletions src/ports/linux/pnal_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,3 +164,13 @@ int pnal_eth_send (pnal_eth_handle_t * handle, pnal_buf_t * buf)
int ret = send (handle->socket, buf->payload, buf->len, 0);
return ret;
}

void pnal_get_port_num (pnal_buf_t * p, int * loc_port_num)
{
/* Not applicable for Linux */
}

void pnal_set_port_num (pnal_buf_t * p, int loc_port_num)
{
/* Not applicable for Linux */
}
18 changes: 16 additions & 2 deletions src/ports/rt-kernel/pnal.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ int pnal_set_ip_suite (

int pnal_get_macaddress (const char * interface_name, pnal_ethaddr_t * mac_addr)
{
memcpy (mac_addr, netif_default->hwaddr, sizeof (pnal_ethaddr_t));
phy_t * phy = phy_get_default_driver ();
uint8_t port = atoi (&interface_name[2]) - 1;
phy_mac_address_t phy_mac_addr = phy_get_port_mac_address (phy, port);
memcpy (mac_addr, phy_mac_addr.address, sizeof (pnal_ethaddr_t));

return 0;
}

Expand Down Expand Up @@ -107,6 +111,12 @@ int pnal_get_port_statistics (
const char * interface_name,
pnal_port_stats_t * port_stats)
{
if (memcmp(interface_name, "en1", 3) != 0)
{
/* TODO: statistics for the external ports are not yet supported */
return -1;
}

port_stats->if_in_octets = netif_default->mib2_counters.ifinoctets;
port_stats->if_in_errors = netif_default->mib2_counters.ifinerrors;
port_stats->if_in_discards = netif_default->mib2_counters.ifindiscards;
Expand Down Expand Up @@ -202,11 +212,15 @@ int pnal_eth_get_status (const char * interface_name, pnal_eth_status_t * status
ioctl_eth_status_t link;
int error;

netif = netif_find (interface_name);
netif = netif_find ("en1"); /* There is only one initialized interface */
ASSERT (netif != NULL);

drv = netif->state;
ASSERT (drv != NULL);

uint8_t port = atoi (&interface_name[2]) - 1;
link.state = port;

error = drv->ops->ioctl (drv, netif, IOCTL_ETH_GET_STATUS, &link);
if (error)
{
Expand Down
45 changes: 35 additions & 10 deletions src/ports/rt-kernel/pnal_eth.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@
#include <lwip/apps/snmp_core.h>
#include <lwip/lwip_hooks.h>
#include <drivers/dev.h>
#include <config.h>

#define MAX_NUMBER_OF_IF 1
#define MAX_NUMBER_OF_IF 3

struct pnal_eth_handle
{
Expand Down Expand Up @@ -125,31 +126,41 @@ pnal_eth_handle_t * pnal_eth_init (
pnal_eth_callback_t * callback,
void * arg)
{
static struct netif * first_netif = NULL;
pnal_eth_handle_t * handle;
struct netif * netif;

(void)receive_type; /* Ignore, for now all frames will be received. */

netif = netif_find (if_name);
if (netif == NULL)
{
os_log (LOG_LEVEL_ERROR, "Network interface \"%s\" not found!\n", if_name);
return NULL;
}

handle = pnal_eth_allocate_handle();
if (handle == NULL)
{
os_log (LOG_LEVEL_ERROR, "Too many network interfaces\n");
return NULL;
}

if (first_netif == NULL)
{
first_netif = netif_find (if_name);
if (first_netif == NULL)
{
os_log (LOG_LEVEL_ERROR, "Network interface \"%s\" not found!\n", if_name);
return NULL;
}
netif = first_netif;

lwip_set_hook_for_unknown_eth_protocol (netif, pnal_eth_sys_recv);
}
else
{
netif = malloc (sizeof (struct netif));
memcpy (netif, first_netif, sizeof (struct netif));
}

handle->arg = arg;
handle->eth_rx_callback = callback;
handle->netif = netif;

lwip_set_hook_for_unknown_eth_protocol (netif, pnal_eth_sys_recv);

return handle;
}

Expand All @@ -170,3 +181,17 @@ int pnal_eth_send (pnal_eth_handle_t * handle, pnal_buf_t * buf)
}
return ret;
}

void pnal_get_port_num (pnal_buf_t * p, int * loc_port_num)
{
#ifdef CFG_TAIL_TAGGING
*loc_port_num = p->port_num;
#endif
}

void pnal_set_port_num (pnal_buf_t * p, int loc_port_num)
{
#ifdef CFG_TAIL_TAGGING
p->port_num = loc_port_num;
#endif
}
7 changes: 5 additions & 2 deletions src/ports/rt-kernel/sampleapp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@

#include <string.h>

#define APP_DEFAULT_ETHERNET_INTERFACE "en1"
/* Make it look like there are three interfaces,
* even if only one interface is initialized.
*/
#define APP_DEFAULT_ETHERNET_INTERFACE "en1,en2,en3"
#define APP_DEFAULT_FILE_DIRECTORY "/disk1"
#define APP_LOG_LEVEL APP_LOG_LEVEL_INFO

Expand Down Expand Up @@ -140,7 +143,7 @@ int main (void)

APP_LOG_INFO ("\n** Starting P-Net sample application " PNET_VERSION
" **\n");
APP_LOG_INFO ("\nType help to a list ofsupported shell commands.\n"
APP_LOG_INFO ("\nType help to get a list of supported shell commands.\n"
"Type help <cmd> to get a command description.\n"
"For example: help pnio_show\n\n");
APP_LOG_INFO (
Expand Down