Commit 01ae0747 authored by Alessandro Rubini's avatar Alessandro Rubini

net: let the caller allocate queue size

I also change the prototype of the socket creation so the compile can
warn me where the locally-allocated socket must be changed.

The size saving is not huge, but this allows later creation of further
sockets with a smaller overhead (e.g.: the syslog socket that sends only
has no queue, and the snmp socket needs a very small buffer).
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent b0c2a74c
......@@ -34,7 +34,7 @@
#define NET_MAX_SOCKETS 4
/* Socket buffer size, determines the max. RX packet size */
#define NET_SKBUF_SIZE 512
#define NET_MAX_SKBUF_SIZE 512
/* Number of auxillary clock channels - usually equal to the number of FMCs */
#define NUM_AUX_CLOCKS 1
......
......@@ -38,9 +38,9 @@ struct wr_sockaddr {
};
struct sockq {
uint8_t buf[NET_SKBUF_SIZE];
uint16_t head, tail, avail;
uint16_t head, tail, avail, size;
uint16_t n;
uint8_t *buff;
};
struct wrpc_socket {
......@@ -78,8 +78,8 @@ PACKED struct wr_timestamp {
// automatically added to multicast group. User can specify
// physical_port field to bind the socket to specific switch port only.
struct wrpc_socket *ptpd_netif_create_socket(struct wrpc_socket *s,
int unused, int unused2,
struct wr_sockaddr * bind_addr);
struct wr_sockaddr * bind_addr,
int unused, int unused2);
// 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.
......
......@@ -16,7 +16,11 @@
#define htons(x) x
#endif
static struct wrpc_socket __static_arp_socket;
static uint8_t __arp_queue[128];
static struct wrpc_socket __static_arp_socket = {
.queue.buff = __arp_queue,
.queue.size = sizeof(__arp_queue),
};
static struct wrpc_socket *arp_socket;
#define ARP_HTYPE 0
......@@ -39,8 +43,8 @@ void arp_init(void)
memset(&saddr.mac, 0xFF, 6); /* Broadcast */
saddr.ethertype = htons(0x0806); /* ARP */
arp_socket = ptpd_netif_create_socket(&__static_arp_socket,
0, 0 /* both unused */, &saddr);
arp_socket = ptpd_netif_create_socket(&__static_arp_socket, &saddr,
0, 0 /* both unused */);
}
static int process_arp(uint8_t * buf, int len)
......
......@@ -20,7 +20,11 @@
int needIP = 1;
static uint8_t myIP[4];
static struct wrpc_socket __static_ipv4_socket;
static uint8_t __ipv4_queue[512];
static struct wrpc_socket __static_ipv4_socket = {
.queue.buff = __ipv4_queue,
.queue.size = sizeof(__ipv4_queue),
};
static struct wrpc_socket *ipv4_socket;
unsigned int ipv4_checksum(unsigned short *buf, int shorts)
......@@ -50,8 +54,8 @@ void ipv4_init(void)
get_mac_addr(&saddr.mac[0]); /* Unicast */
saddr.ethertype = htons(0x0800); /* IPv4 */
ipv4_socket = ptpd_netif_create_socket(&__static_ipv4_socket,
0, 0 /* both unused */, &saddr);
ipv4_socket = ptpd_netif_create_socket(&__static_ipv4_socket, &saddr,
0, 0 /* both unused */);
}
static int bootp_retry = 0;
......
......@@ -52,8 +52,8 @@ void ptpd_netif_set_phase_transition(uint32_t phase)
struct wrpc_socket *ptpd_netif_create_socket(struct wrpc_socket *sock,
int unused, int unusd2,
struct wr_sockaddr * bind_addr)
struct wr_sockaddr * bind_addr,
int unused, int unusd2)
{
int i;
struct hal_port_state pstate;
......@@ -82,7 +82,7 @@ struct wrpc_socket *ptpd_netif_create_socket(struct wrpc_socket *sock,
/*packet queue */
sock->queue.head = sock->queue.tail = 0;
sock->queue.avail = NET_SKBUF_SIZE;
sock->queue.avail = sock->queue.size;
sock->queue.n = 0;
return sock;
......@@ -184,14 +184,15 @@ static int wrap_copy_in(void *dst, struct sockq *q, size_t len, size_t buflen)
q->tail, q->avail, len, buflen);
i = min(len, buflen);
while (i--) {
*dptr++ = q->buf[q->tail];
*dptr++ = q->buff[q->tail];
q->tail++;
if (q->tail == NET_SKBUF_SIZE)
if (q->tail == q->size)
q->tail = 0;
}
if (len > buflen) {
q->tail += len - buflen;
q->tail %= NET_SKBUF_SIZE;
while (q->tail > q->size)
q->tail -= q->size;
}
return len;
}
......@@ -205,8 +206,8 @@ static int wrap_copy_out(struct sockq *q, void *src, size_t len)
len);
while (i--) {
q->buf[q->head++] = *sptr++;
if (q->head == NET_SKBUF_SIZE)
q->buff[q->head++] = *sptr++;
if (q->head == q->size)
q->head = 0;
}
return len;
......@@ -296,11 +297,11 @@ void update_rx_queues()
struct hw_timestamp hwts;
static struct ethhdr hdr;
int recvd, i, q_required;
static uint8_t payload[NET_SKBUF_SIZE - 32];
static uint8_t payload[NET_MAX_SKBUF_SIZE - 32];
uint16_t size;
recvd =
minic_rx_frame((uint8_t *) & hdr, payload, NET_SKBUF_SIZE - 32,
minic_rx_frame((uint8_t *) & hdr, payload, sizeof(payload),
&hwts);
if (recvd <= 0) /* No data received? */
......
ppsi @ 43635331
Subproject commit f68c1ad458fe4bbef0d41dd32b43bab1f406538c
Subproject commit 43635331c54fa906bf54ad75e3087e336bdc7799
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