aboutsummaryrefslogtreecommitdiff
path: root/sys/net/iflib.c
diff options
context:
space:
mode:
authorEric Joyner <erj@FreeBSD.org>2019-03-19 17:59:56 +0000
committerEric Joyner <erj@FreeBSD.org>2019-03-19 17:59:56 +0000
commit1b9d93948a37858a81e04a9fca16fef98172063f (patch)
tree8a2daa892585d2cc950981dfc58d2cc47aae83c8 /sys/net/iflib.c
parent3e8d1bae5f49aab7132bd3f4be24867f18d5b103 (diff)
downloadsrc-1b9d93948a37858a81e04a9fca16fef98172063f.tar.gz
src-1b9d93948a37858a81e04a9fca16fef98172063f.zip
iflib: expose the Rx mbuf buffer size to drivers
From Jake: iflib_fl_setup calculates a suitable buffer size for the Rx mbufs based on the isc_max_frame_size value that drivers setup. This calculation is repeated by drivers when programming their hardware with the size of each Rx buffer. This can lead to a mismatch where the iflib mbuf size is different from the expected size of the buffer as programmed by the hardware. This can lead to unexpected results. If iflib ever wants to support mbuf sizes larger than one page, every driver must be updated to account for the new possible buffer sizes. Fix this by calculating the mbuf size prior to calling IFDI_INIT, and adding the iflib_get_rx_mbuf_sz function which will expose this value to drivers, so that they do not repeat the same calculation. Submitted by: Jacob Keller <jacob.e.keller@intel.com> Reviewed by: shurd@, erj@ MFC after: 1 week Sponsored by: Intel Corporation Differential Revision: https://reviews.freebsd.org/D19489
Notes
Notes: svn path=/head/; revision=345305
Diffstat (limited to 'sys/net/iflib.c')
-rw-r--r--sys/net/iflib.c40
1 files changed, 31 insertions, 9 deletions
diff --git a/sys/net/iflib.c b/sys/net/iflib.c
index 694dd9b632fb..c1f1df1a3874 100644
--- a/sys/net/iflib.c
+++ b/sys/net/iflib.c
@@ -171,6 +171,7 @@ struct iflib_ctx {
uint32_t ifc_if_flags;
uint32_t ifc_flags;
uint32_t ifc_max_fl_buf_size;
+ uint32_t ifc_rx_mbuf_sz;
int ifc_link_state;
int ifc_link_irq;
@@ -2172,7 +2173,6 @@ iflib_fl_setup(iflib_fl_t fl)
{
iflib_rxq_t rxq = fl->ifl_rxq;
if_ctx_t ctx = rxq->ifr_ctx;
- if_softc_ctx_t sctx = &ctx->ifc_softc_ctx;
bit_nclear(fl->ifl_rx_bitmap, 0, fl->ifl_size - 1);
/*
@@ -2181,14 +2181,7 @@ iflib_fl_setup(iflib_fl_t fl)
iflib_fl_bufs_free(fl);
/* Now replenish the mbufs */
MPASS(fl->ifl_credits == 0);
- /*
- * XXX don't set the max_frame_size to larger
- * than the hardware can handle
- */
- if (sctx->isc_max_frame_size <= 2048)
- fl->ifl_buf_size = MCLBYTES;
- else
- fl->ifl_buf_size = MJUMPAGESIZE;
+ fl->ifl_buf_size = ctx->ifc_rx_mbuf_sz;
if (fl->ifl_buf_size > ctx->ifc_max_fl_buf_size)
ctx->ifc_max_fl_buf_size = fl->ifl_buf_size;
fl->ifl_cltype = m_gettype(fl->ifl_buf_size);
@@ -2314,6 +2307,27 @@ iflib_timer(void *arg)
}
static void
+iflib_calc_rx_mbuf_sz(if_ctx_t ctx)
+{
+ if_softc_ctx_t sctx = &ctx->ifc_softc_ctx;
+
+ /*
+ * XXX don't set the max_frame_size to larger
+ * than the hardware can handle
+ */
+ if (sctx->isc_max_frame_size <= MCLBYTES)
+ ctx->ifc_rx_mbuf_sz = MCLBYTES;
+ else
+ ctx->ifc_rx_mbuf_sz = MJUMPAGESIZE;
+}
+
+uint32_t
+iflib_get_rx_mbuf_sz(if_ctx_t ctx)
+{
+ return (ctx->ifc_rx_mbuf_sz);
+}
+
+static void
iflib_init_locked(if_ctx_t ctx)
{
if_softc_ctx_t sctx = &ctx->ifc_softc_ctx;
@@ -2347,6 +2361,14 @@ iflib_init_locked(if_ctx_t ctx)
CALLOUT_UNLOCK(txq);
iflib_netmap_txq_init(ctx, txq);
}
+
+ /*
+ * Calculate a suitable Rx mbuf size prior to calling IFDI_INIT, so
+ * that drivers can use the value when setting up the hardware receive
+ * buffers.
+ */
+ iflib_calc_rx_mbuf_sz(ctx);
+
#ifdef INVARIANTS
i = if_getdrvflags(ifp);
#endif