[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20180131135356.19134-17-bjorn.topel@gmail.com>
Date: Wed, 31 Jan 2018 14:53:48 +0100
From: Björn Töpel <bjorn.topel@...il.com>
To: bjorn.topel@...il.com, magnus.karlsson@...el.com,
alexander.h.duyck@...el.com, alexander.duyck@...il.com,
john.fastabend@...il.com, ast@...com, brouer@...hat.com,
willemdebruijn.kernel@...il.com, daniel@...earbox.net,
netdev@...r.kernel.org
Cc: Björn Töpel <bjorn.topel@...el.com>,
michael.lundkvist@...csson.com, jesse.brandeburg@...el.com,
anjali.singhai@...el.com, jeffrey.b.shaw@...el.com,
ferruh.yigit@...el.com, qi.z.zhang@...el.com
Subject: [RFC PATCH 16/24] i40e: separated buff_pool interface from i40e implementaion
From: Björn Töpel <bjorn.topel@...el.com>
Moved buff_pool to include, so that buff_pool implementations can be
done outside of the i40e module.
Signed-off-by: Björn Töpel <bjorn.topel@...el.com>
---
drivers/net/ethernet/intel/i40e/Makefile | 2 +-
drivers/net/ethernet/intel/i40e/buff_pool.h | 76 -----------
.../intel/i40e/{buff_pool.c => i40e_buff_pool.c} | 148 ++++-----------------
drivers/net/ethernet/intel/i40e/i40e_buff_pool.h | 15 +++
drivers/net/ethernet/intel/i40e/i40e_main.c | 3 +-
drivers/net/ethernet/intel/i40e/i40e_txrx.c | 5 +-
include/linux/buff_pool.h | 136 +++++++++++++++++++
7 files changed, 186 insertions(+), 199 deletions(-)
delete mode 100644 drivers/net/ethernet/intel/i40e/buff_pool.h
rename drivers/net/ethernet/intel/i40e/{buff_pool.c => i40e_buff_pool.c} (82%)
create mode 100644 drivers/net/ethernet/intel/i40e/i40e_buff_pool.h
create mode 100644 include/linux/buff_pool.h
diff --git a/drivers/net/ethernet/intel/i40e/Makefile b/drivers/net/ethernet/intel/i40e/Makefile
index bfdf9ce3e7f0..bbd7e2babd97 100644
--- a/drivers/net/ethernet/intel/i40e/Makefile
+++ b/drivers/net/ethernet/intel/i40e/Makefile
@@ -46,6 +46,6 @@ i40e-objs := i40e_main.o \
i40e_ptp.o \
i40e_client.o \
i40e_virtchnl_pf.o \
- buff_pool.o
+ i40e_buff_pool.o
i40e-$(CONFIG_I40E_DCB) += i40e_dcb.o i40e_dcb_nl.o
diff --git a/drivers/net/ethernet/intel/i40e/buff_pool.h b/drivers/net/ethernet/intel/i40e/buff_pool.h
deleted file mode 100644
index 03897f5ebbff..000000000000
--- a/drivers/net/ethernet/intel/i40e/buff_pool.h
+++ /dev/null
@@ -1,76 +0,0 @@
-#ifndef BUFF_POOL_H_
-#define BUFF_POOL_H_
-
-#include <linux/types.h>
-
-struct page;
-struct device;
-
-struct buff_pool_ops;
-
-struct buff_pool {
- void *pool;
- struct buff_pool_ops *ops;
-};
-
-/* Allocates a new buffer from the pool */
-int bpool_alloc(struct buff_pool *pool, unsigned long *handle);
-
-/* Returns a buffer originating from the pool, back to the pool */
-void bpool_free(struct buff_pool *pool, unsigned long handle);
-
-/* Returns the size of the buffer, w/o headroom. This is what the pool
- * creator passed to the constructor.
- */
-unsigned int bpool_buff_size(struct buff_pool *pool);
-
-/* Returns the size of the buffer, plus additional headroom (if
- * any).
- */
-unsigned int bpool_total_buff_size(struct buff_pool *pool);
-
-/* Returns additional headroom (if any) */
-unsigned int bpool_buff_headroom(struct buff_pool *pool);
-
-/* Returns the truesize (as for skbuff) */
-unsigned int bpool_buff_truesize(struct buff_pool *pool);
-
-/* Returns the kernel virtual address to the handle. */
-void *bpool_buff_ptr(struct buff_pool *pool, unsigned long handle);
-
-/* Converts a handle to a page. After a successful call, the handle is
- * stale and should not be used and should be considered
- * freed. Callers need to manually clean up the returned page (using
- * page_free).
- */
-int bpool_buff_convert_to_page(struct buff_pool *pool, unsigned long handle,
- struct page **pg, unsigned int *pg_off);
-
-/* Returns the dma address of a buffer */
-dma_addr_t bpool_buff_dma(struct buff_pool *pool,
- unsigned long handle);
-
-/* DMA sync for CPU */
-void bpool_buff_dma_sync_cpu(struct buff_pool *pool,
- unsigned long handle,
- unsigned int off,
- unsigned int size);
-
-/* DMA sync for device */
-void bpool_buff_dma_sync_dev(struct buff_pool *pool,
- unsigned long handle,
- unsigned int off,
- unsigned int size);
-/* ---- */
-
-struct buff_pool *i40e_buff_pool_create(struct device *dev);
-void i40e_buff_pool_destroy(struct buff_pool *pool);
-
-struct buff_pool *i40e_buff_pool_recycle_create(unsigned int mtu,
- bool reserve_headroom,
- struct device *dev,
- unsigned int pool_size);
-void i40e_buff_pool_recycle_destroy(struct buff_pool *pool);
-
-#endif /* BUFF_POOL_H_ */
-
diff --git a/drivers/net/ethernet/intel/i40e/buff_pool.c b/drivers/net/ethernet/intel/i40e/i40e_buff_pool.c
similarity index 82%
rename from drivers/net/ethernet/intel/i40e/buff_pool.c
rename to drivers/net/ethernet/intel/i40e/i40e_buff_pool.c
index 42b6cf5042e9..d1e13632b6e4 100644
--- a/drivers/net/ethernet/intel/i40e/buff_pool.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_buff_pool.c
@@ -1,94 +1,10 @@
-#include "buff_pool.h"
+#include "i40e_buff_pool.h"
+
+#include <linux/buff_pool.h>
#include "i40e.h"
#include "i40e_txrx.h"
-struct buff_pool_ops {
- int (*alloc)(void *pool, unsigned long *handle);
- void (*free)(void *pool, unsigned long handle);
- unsigned int (*buff_size)(void *pool);
- unsigned int (*total_buff_size)(void *pool);
- unsigned int (*buff_headroom)(void *pool);
- unsigned int (*buff_truesize)(void *pool);
- void *(*buff_ptr)(void *pool, unsigned long handle);
- int (*buff_convert_to_page)(void *pool,
- unsigned long handle,
- struct page **pg, unsigned int *pg_off);
- dma_addr_t (*buff_dma)(void *pool,
- unsigned long handle);
- void (*buff_dma_sync_cpu)(void *pool,
- unsigned long handle,
- unsigned int off,
- unsigned int size);
- void (*buff_dma_sync_dev)(void *pool,
- unsigned long handle,
- unsigned int off,
- unsigned int size);
-};
-
-int bpool_alloc(struct buff_pool *pool, unsigned long *handle)
-{
- return pool->ops->alloc(pool->pool, handle);
-}
-
-void bpool_free(struct buff_pool *pool, unsigned long handle)
-{
- pool->ops->free(pool->pool, handle);
-}
-
-unsigned int bpool_buff_size(struct buff_pool *pool)
-{
- return pool->ops->buff_size(pool->pool);
-}
-
-unsigned int bpool_total_buff_size(struct buff_pool *pool)
-{
- return pool->ops->total_buff_size(pool->pool);
-}
-
-unsigned int bpool_buff_headroom(struct buff_pool *pool)
-{
- return pool->ops->buff_headroom(pool->pool);
-}
-
-unsigned int bpool_buff_truesize(struct buff_pool *pool)
-{
- return pool->ops->buff_truesize(pool->pool);
-}
-
-void *bpool_buff_ptr(struct buff_pool *pool, unsigned long handle)
-{
- return pool->ops->buff_ptr(pool->pool, handle);
-}
-
-int bpool_buff_convert_to_page(struct buff_pool *pool, unsigned long handle,
- struct page **pg, unsigned int *pg_off)
-{
- return pool->ops->buff_convert_to_page(pool->pool, handle, pg, pg_off);
-}
-
-dma_addr_t bpool_buff_dma(struct buff_pool *pool,
- unsigned long handle)
-{
- return pool->ops->buff_dma(pool->pool, handle);
-}
-
-void bpool_buff_dma_sync_cpu(struct buff_pool *pool,
- unsigned long handle,
- unsigned int off,
- unsigned int size)
-{
- pool->ops->buff_dma_sync_cpu(pool->pool, handle, off, size);
-}
-
-void bpool_buff_dma_sync_dev(struct buff_pool *pool,
- unsigned long handle,
- unsigned int off,
- unsigned int size)
-{
- pool->ops->buff_dma_sync_dev(pool->pool, handle, off, size);
-}
-
/* Naive, non-recycling allocator. */
struct i40e_bp_pool {
@@ -233,6 +149,11 @@ static void i40e_bp_buff_dma_sync_dev(void *pool,
DMA_FROM_DEVICE);
}
+static void i40e_bp_destroy(void *pool)
+{
+ kfree(pool);
+}
+
struct buff_pool *i40e_buff_pool_create(struct device *dev)
{
struct i40e_bp_pool *pool_impl;
@@ -267,6 +188,7 @@ struct buff_pool *i40e_buff_pool_create(struct device *dev)
pool_ops->buff_dma = i40e_bp_buff_dma;
pool_ops->buff_dma_sync_cpu = i40e_bp_buff_dma_sync_cpu;
pool_ops->buff_dma_sync_dev = i40e_bp_buff_dma_sync_dev;
+ pool_ops->destroy = i40e_bp_destroy;
pool_impl->dev = dev;
@@ -276,13 +198,6 @@ struct buff_pool *i40e_buff_pool_create(struct device *dev)
return pool;
}
-void i40e_buff_pool_destroy(struct buff_pool *pool)
-{
- kfree(pool->ops);
- kfree(pool->pool);
- kfree(pool);
-}
-
/* Recycling allocator */
struct i40e_bpr_header {
@@ -470,8 +385,8 @@ static int i40e_bpr_buff_convert_to_page(void *pool, unsigned long handle,
return 0;
}
-static dma_addr_t i40e_bpr_buff_dma(void *pool,
- unsigned long handle)
+static inline dma_addr_t i40e_bpr_buff_dma(void *pool,
+ unsigned long handle)
{
struct i40e_bpr_header *hdr;
@@ -582,6 +497,23 @@ static void calc_buffer_size(unsigned int mtu, bool reserve_headroom,
buff_len, headroom, pg_order);
}
+static void i40e_bpr_destroy(void *pool)
+{
+ struct i40e_bpr_pool *impl = (struct i40e_bpr_pool *)pool;
+ struct i40e_bpr_header *hdr;
+
+ while (impl->head != impl->tail) {
+ hdr = impl->buffs[impl->head];
+ dma_unmap_page_attrs(impl->dev, hdr->dma, impl->pg_size,
+ DMA_FROM_DEVICE, I40E_RX_DMA_ATTR);
+ __page_frag_cache_drain(virt_to_head_page(hdr),
+ hdr->pagecnt_bias);
+ impl->head = (impl->head + 1) & impl->buffs_size_mask;
+ }
+
+ kfree(impl);
+}
+
struct buff_pool *i40e_buff_pool_recycle_create(unsigned int mtu,
bool reserve_headroom,
struct device *dev,
@@ -637,11 +569,7 @@ struct buff_pool *i40e_buff_pool_recycle_create(unsigned int mtu,
pool_ops->buff_dma = i40e_bpr_buff_dma;
pool_ops->buff_dma_sync_cpu = i40e_bpr_buff_dma_sync_cpu;
pool_ops->buff_dma_sync_dev = i40e_bpr_buff_dma_sync_dev;
-
- pr_err("%s mtu=%u reserve=%d pool_size=%u buff_tot_len=%u buff_len=%u headroom=%u pg_order=%u pf_size=%u\n",
- __func__,
- mtu, (int)reserve_headroom, pool_size, impl->buff_tot_len,
- impl->buff_len, impl->headroom, impl->pg_order, impl->pg_size);
+ pool_ops->destroy = i40e_bpr_destroy;
pool->pool = impl;
pool->ops = pool_ops;
@@ -649,22 +577,4 @@ struct buff_pool *i40e_buff_pool_recycle_create(unsigned int mtu,
return pool;
}
-void i40e_buff_pool_recycle_destroy(struct buff_pool *pool)
-{
- struct i40e_bpr_pool *impl = (struct i40e_bpr_pool *)pool->pool;
- struct i40e_bpr_header *hdr;
-
- while (impl->head != impl->tail) {
- hdr = impl->buffs[impl->head];
- dma_unmap_page_attrs(impl->dev, hdr->dma, impl->pg_size,
- DMA_FROM_DEVICE, I40E_RX_DMA_ATTR);
- __page_frag_cache_drain(virt_to_head_page(hdr),
- hdr->pagecnt_bias);
- impl->head = (impl->head + 1) & impl->buffs_size_mask;
- }
-
- kfree(pool->ops);
- kfree(pool->pool);
- kfree(pool);
-}
diff --git a/drivers/net/ethernet/intel/i40e/i40e_buff_pool.h b/drivers/net/ethernet/intel/i40e/i40e_buff_pool.h
new file mode 100644
index 000000000000..dddd04680c1a
--- /dev/null
+++ b/drivers/net/ethernet/intel/i40e/i40e_buff_pool.h
@@ -0,0 +1,15 @@
+#ifndef I40E_BUFF_POOL_H_
+#define I40E_BUFF_POOL_H_
+
+#include <linux/types.h>
+
+struct buff_pool;
+struct device;
+
+struct buff_pool *i40e_buff_pool_create(struct device *dev);
+
+struct buff_pool *i40e_buff_pool_recycle_create(unsigned int mtu,
+ bool reserve_headroom,
+ struct device *dev,
+ unsigned int pool_size);
+#endif /* I40E_BUFF_POOL_H_ */
diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c
index 79e48840a6bd..0e1445af6b01 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_main.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_main.c
@@ -28,6 +28,7 @@
#include <linux/of_net.h>
#include <linux/pci.h>
#include <linux/bpf.h>
+#include <linux/buff_pool.h>
/* Local includes */
#include "i40e.h"
@@ -39,7 +40,7 @@
*/
#define CREATE_TRACE_POINTS
#include "i40e_trace.h"
-#include "buff_pool.h"
+#include "i40e_buff_pool.h"
const char i40e_driver_name[] = "i40e";
static const char i40e_driver_string[] =
diff --git a/drivers/net/ethernet/intel/i40e/i40e_txrx.c b/drivers/net/ethernet/intel/i40e/i40e_txrx.c
index 757cda5ac889..fffc254abd8c 100644
--- a/drivers/net/ethernet/intel/i40e/i40e_txrx.c
+++ b/drivers/net/ethernet/intel/i40e/i40e_txrx.c
@@ -27,11 +27,12 @@
#include <linux/prefetch.h>
#include <net/busy_poll.h>
#include <linux/bpf_trace.h>
+#include <linux/buff_pool.h>
#include <net/xdp.h>
#include "i40e.h"
#include "i40e_trace.h"
#include "i40e_prototype.h"
-#include "buff_pool.h"
+#include "i40e_buff_pool.h"
static inline __le64 build_ctob(u32 td_cmd, u32 td_offset, unsigned int size,
u32 td_tag)
@@ -1255,7 +1256,7 @@ void i40e_free_rx_resources(struct i40e_ring *rx_ring)
kfree(rx_ring->rx_bi);
rx_ring->rx_bi = NULL;
- i40e_buff_pool_recycle_destroy(rx_ring->bpool);
+ bpool_destroy(rx_ring->bpool);
rx_ring->bpool = NULL;
if (rx_ring->desc) {
diff --git a/include/linux/buff_pool.h b/include/linux/buff_pool.h
new file mode 100644
index 000000000000..660ca827f4a6
--- /dev/null
+++ b/include/linux/buff_pool.h
@@ -0,0 +1,136 @@
+#ifndef BUFF_POOL_H_
+#define BUFF_POOL_H_
+
+#include <linux/types.h>
+#include <linux/slab.h>
+
+struct page;
+struct device;
+
+struct buff_pool_ops {
+ int (*alloc)(void *pool, unsigned long *handle);
+ void (*free)(void *pool, unsigned long handle);
+ unsigned int (*buff_size)(void *pool);
+ unsigned int (*total_buff_size)(void *pool);
+ unsigned int (*buff_headroom)(void *pool);
+ unsigned int (*buff_truesize)(void *pool);
+ void *(*buff_ptr)(void *pool, unsigned long handle);
+ int (*buff_convert_to_page)(void *pool,
+ unsigned long handle,
+ struct page **pg, unsigned int *pg_off);
+ dma_addr_t (*buff_dma)(void *pool,
+ unsigned long handle);
+ void (*buff_dma_sync_cpu)(void *pool,
+ unsigned long handle,
+ unsigned int off,
+ unsigned int size);
+ void (*buff_dma_sync_dev)(void *pool,
+ unsigned long handle,
+ unsigned int off,
+ unsigned int size);
+ void (*destroy)(void *pool);
+};
+
+struct buff_pool {
+ void *pool;
+ struct buff_pool_ops *ops;
+};
+
+/* Allocates a new buffer from the pool */
+static inline int bpool_alloc(struct buff_pool *pool, unsigned long *handle)
+{
+ return pool->ops->alloc(pool->pool, handle);
+}
+
+/* Returns a buffer originating from the pool, back to the pool */
+static inline void bpool_free(struct buff_pool *pool, unsigned long handle)
+{
+ pool->ops->free(pool->pool, handle);
+}
+
+/* Returns the size of the buffer, w/o headroom. This is what the pool
+ * creator passed to the constructor.
+ */
+static inline unsigned int bpool_buff_size(struct buff_pool *pool)
+{
+ return pool->ops->buff_size(pool->pool);
+}
+
+/* Returns the size of the buffer, plus additional headroom (if
+ * any).
+ */
+static inline unsigned int bpool_total_buff_size(struct buff_pool *pool)
+{
+ return pool->ops->total_buff_size(pool->pool);
+}
+
+/* Returns additional available headroom (if any) */
+static inline unsigned int bpool_buff_headroom(struct buff_pool *pool)
+{
+ return pool->ops->buff_headroom(pool->pool);
+}
+
+/* Returns the truesize (as for skbuff) */
+static inline unsigned int bpool_buff_truesize(struct buff_pool *pool)
+{
+ return pool->ops->buff_truesize(pool->pool);
+}
+
+/* Returns the kernel virtual address to the handle. */
+static inline void *bpool_buff_ptr(struct buff_pool *pool, unsigned long handle)
+{
+ return pool->ops->buff_ptr(pool->pool, handle);
+}
+
+/* Converts a handle to a page. After a successful call, the handle is
+ * stale and should not be used and should be considered
+ * freed. Callers need to manually clean up the returned page (using
+ * page_free).
+ */
+static inline int bpool_buff_convert_to_page(struct buff_pool *pool,
+ unsigned long handle,
+ struct page **pg,
+ unsigned int *pg_off)
+{
+ return pool->ops->buff_convert_to_page(pool->pool, handle, pg, pg_off);
+}
+
+/* Returns the dma address of a buffer */
+static inline dma_addr_t bpool_buff_dma(struct buff_pool *pool,
+ unsigned long handle)
+{
+ return pool->ops->buff_dma(pool->pool, handle);
+}
+
+/* DMA sync for CPU */
+static inline void bpool_buff_dma_sync_cpu(struct buff_pool *pool,
+ unsigned long handle,
+ unsigned int off,
+ unsigned int size)
+{
+ pool->ops->buff_dma_sync_cpu(pool->pool, handle, off, size);
+}
+
+/* DMA sync for device */
+static inline void bpool_buff_dma_sync_dev(struct buff_pool *pool,
+ unsigned long handle,
+ unsigned int off,
+ unsigned int size)
+{
+ pool->ops->buff_dma_sync_dev(pool->pool, handle, off, size);
+}
+
+/* Destroy pool */
+static inline void bpool_destroy(struct buff_pool *pool)
+{
+ if (!pool)
+ return;
+
+ pool->ops->destroy(pool->pool);
+
+ kfree(pool->ops);
+ kfree(pool);
+}
+
+#endif /* BUFF_POOL_H_ */
+
--
2.14.1
Powered by blists - more mailing lists