From 5d1899eedb0534b16866ce4257b3f5b4c6349b24 Mon Sep 17 00:00:00 2001 From: Patrick Kelsey Date: Tue, 17 Mar 2020 03:32:13 +0000 Subject: [PATCH] Restore power-of-2 queue count constraint from r290948 When vmx(4) was converted to an iflib driver in r343291, the power-of-2 queue count constraint was removed as it appeared that current implementations of the VMXNET3 virtual device no longer required that constraint. It turns out that some of the implementations still do, and on such systems, the device will fail to initialize when configured with a non-power-of-2 RX or TX queue count. PR: 237321 Reported by: ncrogers@gmail.com MFC after: 1 week --- sys/dev/vmware/vmxnet3/if_vmx.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/sys/dev/vmware/vmxnet3/if_vmx.c b/sys/dev/vmware/vmxnet3/if_vmx.c index e0474484967d..ee1d76388577 100644 --- a/sys/dev/vmware/vmxnet3/if_vmx.c +++ b/sys/dev/vmware/vmxnet3/if_vmx.c @@ -320,6 +320,13 @@ vmxnet3_register(device_t dev) return (&vmxnet3_sctx_init); } +static int +trunc_powerof2(int val) +{ + + return (1U << (fls(val) - 1)); +} + static int vmxnet3_attach_pre(if_ctx_t ctx) { @@ -349,12 +356,16 @@ vmxnet3_attach_pre(if_ctx_t ctx) /* If 0, the iflib tunable was not set, so set to the default */ if (scctx->isc_nrxqsets == 0) scctx->isc_nrxqsets = VMXNET3_DEF_RX_QUEUES; + scctx->isc_nrxqsets = trunc_powerof2(scctx->isc_nrxqsets); scctx->isc_nrxqsets_max = min(VMXNET3_MAX_RX_QUEUES, mp_ncpus); + scctx->isc_nrxqsets_max = trunc_powerof2(scctx->isc_nrxqsets_max); /* If 0, the iflib tunable was not set, so set to the default */ if (scctx->isc_ntxqsets == 0) scctx->isc_ntxqsets = VMXNET3_DEF_TX_QUEUES; + scctx->isc_ntxqsets = trunc_powerof2(scctx->isc_ntxqsets); scctx->isc_ntxqsets_max = min(VMXNET3_MAX_TX_QUEUES, mp_ncpus); + scctx->isc_ntxqsets_max = trunc_powerof2(scctx->isc_ntxqsets_max); /* * Enforce that the transmit completion queue descriptor count is