From 9a40de458b3884d9f526172110392501f075bd87 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 9 May 2014 15:46:38 +0200 Subject: ring: Merge common ring_{rx,tx} initialization into own function Instead of having to perform the individual steps to initialize a ring and open coding them in multiple places, provide convenience functions to do all at once. This has the nice side effect of allowing to make most of these *_{rx,tx}_ring() functions static in their respective module. Signed-off-by: Tobias Klauser --- ring_tx.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'ring_tx.c') diff --git a/ring_tx.c b/ring_tx.c index 3d69752..27afe8b 100644 --- a/ring_tx.c +++ b/ring_tx.c @@ -20,7 +20,7 @@ #include "ring_tx.h" #include "built_in.h" -void set_packet_loss_discard(int sock) +static void set_packet_loss_discard(int sock) { int ret, discard = 1; ret = setsockopt(sock, SOL_PACKET, PACKET_LOSS, (void *) &discard, @@ -45,8 +45,8 @@ void destroy_tx_ring(int sock, struct ring *ring) xfree(ring->frames); } -void setup_tx_ring_layout(int sock, struct ring *ring, size_t size, - bool jumbo_support) +static void setup_tx_ring_layout(int sock, struct ring *ring, size_t size, + bool jumbo_support) { fmemset(&ring->layout, 0, sizeof(ring->layout)); @@ -68,7 +68,7 @@ void setup_tx_ring_layout(int sock, struct ring *ring, size_t size, ring_verify_layout(ring); } -void create_tx_ring(int sock, struct ring *ring, bool verbose) +static void create_tx_ring(int sock, struct ring *ring, bool verbose) { int ret; retry: @@ -95,18 +95,20 @@ retry: } } -void mmap_tx_ring(int sock, struct ring *ring) -{ - mmap_ring_generic(sock, ring); -} - -void alloc_tx_ring_frames(int sock __maybe_unused, struct ring *ring) +static void alloc_tx_ring_frames(int sock __maybe_unused, struct ring *ring) { alloc_ring_frames_generic(ring, ring->layout.tp_frame_nr, ring->layout.tp_frame_size); } -void bind_tx_ring(int sock, struct ring *ring, int ifindex) +void ring_tx_setup(struct ring *ring, int sock, size_t size, int ifindex, + bool jumbo_support, bool verbose) { + fmemset(ring, 0, sizeof(*ring)); + set_packet_loss_discard(sock); + setup_tx_ring_layout(sock, ring, size, jumbo_support); + create_tx_ring(sock, ring, verbose); + mmap_ring_generic(sock, ring); + alloc_tx_ring_frames(sock, ring); bind_ring_generic(sock, ring, ifindex, true); } -- cgit v1.2.3-54-g00ecf