Commit 52ec2a38 authored by Alessandro Rubini's avatar Alessandro Rubini

net: define wr_ethhdr and use it (no change)

We used to have "struct ethhdr" local in net.c, passing "void *hdr" to
minic.  We exports the structure to an header so to use it in
communicating with the minic.  Unfortunaltey, ethhdr is defined elsewhere
too, so we'd better rename to wr_ethhdr.

This is a step towards the introduction of vlans, but has no technical
effect by itself.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent dd612fb9
......@@ -191,7 +191,7 @@ int minic_poll_rx()
return (isr & MINIC_EIC_ISR_RX) ? 1 : 0;
}
int minic_rx_frame(uint8_t * hdr, uint8_t * payload, uint32_t buf_size,
int minic_rx_frame(struct wr_ethhdr *hdr, uint8_t * payload, uint32_t buf_size,
struct hw_timestamp *hwts)
{
uint32_t frame_size, payload_size, num_words;
......@@ -262,7 +262,7 @@ int minic_rx_frame(uint8_t * hdr, uint8_t * payload, uint32_t buf_size,
n_recvd = (buf_size < payload_size ? buf_size : payload_size);
minic.rx_count++;
minic_rx_memcpy(hdr, (void *)minic.rx_head + 4,
minic_rx_memcpy((void *)hdr, (void *)minic.rx_head + 4,
ETH_HEADER_SIZE);
minic_rx_memcpy(payload, (void *)minic.rx_head + 4
+ ETH_HEADER_SIZE, n_recvd);
......@@ -288,7 +288,7 @@ int minic_rx_frame(uint8_t * hdr, uint8_t * payload, uint32_t buf_size,
return n_recvd;
}
int minic_tx_frame(uint8_t * hdr, uint8_t * payload, uint32_t size,
int minic_tx_frame(struct wr_ethhdr *hdr, uint8_t * payload, uint32_t size,
struct hw_timestamp *hwts)
{
uint32_t d_hdr, mcr, nwords;
......
......@@ -19,9 +19,15 @@ void minic_disable(void);
int minic_poll_rx(void);
void minic_get_stats(int *tx_frames, int *rx_frames);
int minic_rx_frame(uint8_t * hdr, uint8_t * payload, uint32_t buf_size,
struct wr_ethhdr {
uint8_t dstmac[6];
uint8_t srcmac[6];
uint16_t ethtype;
};
int minic_rx_frame(struct wr_ethhdr *hdr, uint8_t * payload, uint32_t buf_size,
struct hw_timestamp *hwts);
int minic_tx_frame(uint8_t * hdr, uint8_t * payload, uint32_t size,
int minic_tx_frame(struct wr_ethhdr *hdr, uint8_t * payload, uint32_t size,
struct hw_timestamp *hwts);
#endif
......@@ -80,7 +80,6 @@ PACKED struct wr_timestamp {
int correct;
};
// Creates UDP or Ethernet RAW socket (determined by sock_type) bound
// to bind_addr. If PTPD_FLAG_MULTICAST is set, the socket is
// automatically added to multicast group. User can specify
......
......@@ -26,12 +26,6 @@
#define min(x,y) ((x) < (y) ? (x) : (y))
struct ethhdr {
uint8_t dstmac[6];
uint8_t srcmac[6];
uint16_t ethtype;
};
static struct wrpc_socket *socks[NET_MAX_SOCKETS];
//#define net_verbose pp_printf
......@@ -231,7 +225,7 @@ int ptpd_netif_recvfrom(struct wrpc_socket *s, struct wr_sockaddr *from, void *d
struct sockq *q = &s->queue;
uint16_t size;
struct ethhdr hdr;
struct wr_ethhdr hdr;
struct hw_timestamp hwts;
uint8_t spll_busy;
......@@ -243,7 +237,7 @@ int ptpd_netif_recvfrom(struct wrpc_socket *s, struct wr_sockaddr *from, void *d
q->avail += wrap_copy_in(&size, q, 2, 0);
q->avail += wrap_copy_in(&hwts, q, sizeof(struct hw_timestamp), 0);
q->avail += wrap_copy_in(&hdr, q, sizeof(struct ethhdr), 0);
q->avail += wrap_copy_in(&hdr, q, sizeof(struct wr_ethhdr), 0);
q->avail += wrap_copy_in(data, q, size, data_length);
from->ethertype = ntohs(hdr.ethtype);
......@@ -282,7 +276,7 @@ int ptpd_netif_sendto(struct wrpc_socket * sock, struct wr_sockaddr *to, void *d
{
struct wrpc_socket *s = (struct wrpc_socket *)sock;
struct hw_timestamp hwts;
struct ethhdr hdr;
struct wr_ethhdr hdr;
int rval;
memcpy(hdr.dstmac, to->mac, 6);
......@@ -294,7 +288,7 @@ int ptpd_netif_sendto(struct wrpc_socket * sock, struct wr_sockaddr *to, void *d
data_length);
rval =
minic_tx_frame((uint8_t *) & hdr, (uint8_t *) data,
minic_tx_frame(&hdr, (uint8_t *) data,
data_length, &hwts);
......@@ -313,13 +307,13 @@ int update_rx_queues()
struct wrpc_socket *s = NULL;
struct sockq *q;
struct hw_timestamp hwts;
static struct ethhdr hdr;
static struct wr_ethhdr hdr;
int recvd, i, q_required;
static uint8_t payload[NET_MAX_SKBUF_SIZE - 32];
uint16_t size, port;
recvd =
minic_rx_frame((uint8_t *) & hdr, payload, sizeof(payload),
minic_rx_frame(&hdr, payload, sizeof(payload),
&hwts);
if (recvd <= 0) /* No data received? */
......@@ -357,7 +351,7 @@ int update_rx_queues()
q = &s->queue;
q_required =
sizeof(struct ethhdr) + recvd + sizeof(struct hw_timestamp) + 2;
sizeof(struct wr_ethhdr) + recvd + sizeof(struct hw_timestamp) + 2;
if (q->avail < q_required) {
net_verbose
......@@ -370,7 +364,7 @@ int update_rx_queues()
q->avail -= wrap_copy_out(q, &size, 2);
q->avail -= wrap_copy_out(q, &hwts, sizeof(struct hw_timestamp));
q->avail -= wrap_copy_out(q, &hdr, sizeof(struct ethhdr));
q->avail -= wrap_copy_out(q, &hdr, sizeof(struct wr_ethhdr));
q->avail -= wrap_copy_out(q, payload, size);
q->n++;
......
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