summaryrefslogtreecommitdiffstats
path: root/src/plugins/avf/device.c
diff options
context:
space:
mode:
authorSteven Luong <sluong@cisco.com>2020-09-28 12:25:22 -0700
committerDamjan Marion <dmarion@me.com>2020-09-29 09:00:26 +0000
commit8b388e35b2aeca39c277453337751d14aeba0d40 (patch)
tree5f745cdd4e63f915726b23b0fd940fbcd30e1a2d /src/plugins/avf/device.c
parent4537c30925050ffa34c33e6a481f07f1ec0a01ff (diff)
avf: validate queue size config
Check CLI queue size is within the range of 64 and 4096 Enhance show hardware to display queue size and number of queues. Type: improvement Signed-off-by: Steven Luong <sluong@cisco.com> Change-Id: I360e3cdb2e69e4ea7380ed924e71a5ae84ed4b64
Diffstat (limited to 'src/plugins/avf/device.c')
-rw-r--r--src/plugins/avf/device.c50
1 files changed, 39 insertions, 11 deletions
diff --git a/src/plugins/avf/device.c b/src/plugins/avf/device.c
index 0481e61b294..d7115044c05 100644
--- a/src/plugins/avf/device.c
+++ b/src/plugins/avf/device.c
@@ -1418,28 +1418,56 @@ avf_delete_if (vlib_main_t * vm, avf_device_t * ad, int with_barrier)
clib_mem_free (ad);
}
-void
-avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args)
+static u8
+avf_validate_queue_size (avf_create_if_args_t * args)
{
- vnet_main_t *vnm = vnet_get_main ();
- avf_main_t *am = &avf_main;
- avf_device_t *ad, **adp;
- vlib_pci_dev_handle_t h;
clib_error_t *error = 0;
- int i;
- /* check input args */
args->rxq_size = (args->rxq_size == 0) ? AVF_RXQ_SZ : args->rxq_size;
args->txq_size = (args->txq_size == 0) ? AVF_TXQ_SZ : args->txq_size;
- if ((args->rxq_size & (args->rxq_size - 1))
- || (args->txq_size & (args->txq_size - 1)))
+ if ((args->rxq_size > AVF_QUEUE_SZ_MAX)
+ || (args->txq_size > AVF_QUEUE_SZ_MAX))
+ {
+ args->rv = VNET_API_ERROR_INVALID_VALUE;
+ args->error =
+ clib_error_return (error, "queue size must not be greater than %u",
+ AVF_QUEUE_SZ_MAX);
+ return 1;
+ }
+ if ((args->rxq_size < AVF_QUEUE_SZ_MIN)
+ || (args->txq_size < AVF_QUEUE_SZ_MIN))
+ {
+ args->rv = VNET_API_ERROR_INVALID_VALUE;
+ args->error =
+ clib_error_return (error, "queue size must not be smaller than %u",
+ AVF_QUEUE_SZ_MIN);
+ return 1;
+ }
+ if ((args->rxq_size & (args->rxq_size - 1)) ||
+ (args->txq_size & (args->txq_size - 1)))
{
args->rv = VNET_API_ERROR_INVALID_VALUE;
args->error =
clib_error_return (error, "queue size must be a power of two");
- return;
+ return 1;
}
+ return 0;
+}
+
+void
+avf_create_if (vlib_main_t * vm, avf_create_if_args_t * args)
+{
+ vnet_main_t *vnm = vnet_get_main ();
+ avf_main_t *am = &avf_main;
+ avf_device_t *ad, **adp;
+ vlib_pci_dev_handle_t h;
+ clib_error_t *error = 0;
+ int i;
+
+ /* check input args */
+ if (avf_validate_queue_size (args) != 0)
+ return;
pool_get (am->devices, adp);
adp[0] = ad = clib_mem_alloc_aligned (sizeof (avf_device_t),