rawdev: add private data size to queue config inputs
The queue setup and queue defaults query functions take a void * parameter as configuration data, preventing any compile-time checking of the parameters and limiting runtime checks. Adding in the length of the expected structure provides a measure of typechecking, and can also be used for ABI compatibility in future, since ABI changes involving structs almost always involve a change in size. Signed-off-by: Bruce Richardson <bruce.richardson@intel.com> Acked-by: Nipun Gupta <nipun.gupta@nxp.com>
This commit is contained in:
parent
8db9dce72d
commit
f574ed8116
@ -85,6 +85,7 @@ API Changes
|
||||
=======================================================
|
||||
|
||||
* rawdev: Added a structure size parameter to the functions
|
||||
``rte_rawdev_queue_setup()``, ``rte_rawdev_queue_conf_get()``,
|
||||
``rte_rawdev_info_get()`` and ``rte_rawdev_configure()``,
|
||||
allowing limited driver type-checking and ABI compatibility.
|
||||
|
||||
|
@ -249,11 +249,15 @@ ntb_dev_intr_handler(void *param)
|
||||
static void
|
||||
ntb_queue_conf_get(struct rte_rawdev *dev,
|
||||
uint16_t queue_id,
|
||||
rte_rawdev_obj_t queue_conf)
|
||||
rte_rawdev_obj_t queue_conf,
|
||||
size_t conf_size)
|
||||
{
|
||||
struct ntb_queue_conf *q_conf = queue_conf;
|
||||
struct ntb_hw *hw = dev->dev_private;
|
||||
|
||||
if (conf_size != sizeof(*q_conf))
|
||||
return;
|
||||
|
||||
q_conf->tx_free_thresh = hw->tx_queues[queue_id]->tx_free_thresh;
|
||||
q_conf->nb_desc = hw->rx_queues[queue_id]->nb_rx_desc;
|
||||
q_conf->rx_mp = hw->rx_queues[queue_id]->mpool;
|
||||
@ -294,12 +298,16 @@ ntb_rxq_release(struct ntb_rx_queue *rxq)
|
||||
static int
|
||||
ntb_rxq_setup(struct rte_rawdev *dev,
|
||||
uint16_t qp_id,
|
||||
rte_rawdev_obj_t queue_conf)
|
||||
rte_rawdev_obj_t queue_conf,
|
||||
size_t conf_size)
|
||||
{
|
||||
struct ntb_queue_conf *rxq_conf = queue_conf;
|
||||
struct ntb_hw *hw = dev->dev_private;
|
||||
struct ntb_rx_queue *rxq;
|
||||
|
||||
if (conf_size != sizeof(*rxq_conf))
|
||||
return -EINVAL;
|
||||
|
||||
/* Allocate the rx queue data structure */
|
||||
rxq = rte_zmalloc_socket("ntb rx queue",
|
||||
sizeof(struct ntb_rx_queue),
|
||||
@ -375,13 +383,17 @@ ntb_txq_release(struct ntb_tx_queue *txq)
|
||||
static int
|
||||
ntb_txq_setup(struct rte_rawdev *dev,
|
||||
uint16_t qp_id,
|
||||
rte_rawdev_obj_t queue_conf)
|
||||
rte_rawdev_obj_t queue_conf,
|
||||
size_t conf_size)
|
||||
{
|
||||
struct ntb_queue_conf *txq_conf = queue_conf;
|
||||
struct ntb_hw *hw = dev->dev_private;
|
||||
struct ntb_tx_queue *txq;
|
||||
uint16_t i, prev;
|
||||
|
||||
if (conf_size != sizeof(*txq_conf))
|
||||
return -EINVAL;
|
||||
|
||||
/* Allocate the TX queue data structure. */
|
||||
txq = rte_zmalloc_socket("ntb tx queue",
|
||||
sizeof(struct ntb_tx_queue),
|
||||
@ -439,7 +451,8 @@ ntb_txq_setup(struct rte_rawdev *dev,
|
||||
static int
|
||||
ntb_queue_setup(struct rte_rawdev *dev,
|
||||
uint16_t queue_id,
|
||||
rte_rawdev_obj_t queue_conf)
|
||||
rte_rawdev_obj_t queue_conf,
|
||||
size_t conf_size)
|
||||
{
|
||||
struct ntb_hw *hw = dev->dev_private;
|
||||
int ret;
|
||||
@ -447,11 +460,11 @@ ntb_queue_setup(struct rte_rawdev *dev,
|
||||
if (queue_id >= hw->queue_pairs)
|
||||
return -EINVAL;
|
||||
|
||||
ret = ntb_txq_setup(dev, queue_id, queue_conf);
|
||||
ret = ntb_txq_setup(dev, queue_id, queue_conf, conf_size);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
ret = ntb_rxq_setup(dev, queue_id, queue_conf);
|
||||
ret = ntb_rxq_setup(dev, queue_id, queue_conf, conf_size);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -222,14 +222,16 @@ static int skeleton_rawdev_reset(struct rte_rawdev *dev)
|
||||
|
||||
static void skeleton_rawdev_queue_def_conf(struct rte_rawdev *dev,
|
||||
uint16_t queue_id,
|
||||
rte_rawdev_obj_t queue_conf)
|
||||
rte_rawdev_obj_t queue_conf,
|
||||
size_t conf_size)
|
||||
{
|
||||
struct skeleton_rawdev *skeldev;
|
||||
struct skeleton_rawdev_queue *skelq;
|
||||
|
||||
SKELETON_PMD_FUNC_TRACE();
|
||||
|
||||
if (!dev || !queue_conf)
|
||||
if (!dev || !queue_conf ||
|
||||
conf_size != sizeof(struct skeleton_rawdev_queue))
|
||||
return;
|
||||
|
||||
skeldev = skeleton_rawdev_get_priv(dev);
|
||||
@ -252,7 +254,8 @@ clear_queue_bufs(int queue_id)
|
||||
|
||||
static int skeleton_rawdev_queue_setup(struct rte_rawdev *dev,
|
||||
uint16_t queue_id,
|
||||
rte_rawdev_obj_t queue_conf)
|
||||
rte_rawdev_obj_t queue_conf,
|
||||
size_t conf_size)
|
||||
{
|
||||
int ret = 0;
|
||||
struct skeleton_rawdev *skeldev;
|
||||
@ -260,7 +263,8 @@ static int skeleton_rawdev_queue_setup(struct rte_rawdev *dev,
|
||||
|
||||
SKELETON_PMD_FUNC_TRACE();
|
||||
|
||||
if (!dev || !queue_conf)
|
||||
if (!dev || !queue_conf ||
|
||||
conf_size != sizeof(struct skeleton_rawdev_queue))
|
||||
return -EINVAL;
|
||||
|
||||
skeldev = skeleton_rawdev_get_priv(dev);
|
||||
|
@ -185,7 +185,7 @@ test_rawdev_queue_default_conf_get(void)
|
||||
* depth = DEF_DEPTH
|
||||
*/
|
||||
for (i = 0; i < rdev_conf_get.num_queues; i++) {
|
||||
rte_rawdev_queue_conf_get(test_dev_id, i, &q);
|
||||
rte_rawdev_queue_conf_get(test_dev_id, i, &q, sizeof(q));
|
||||
RTE_TEST_ASSERT_EQUAL(q.depth, SKELETON_QUEUE_DEF_DEPTH,
|
||||
"Invalid default depth of queue (%d)",
|
||||
q.depth);
|
||||
@ -235,11 +235,11 @@ test_rawdev_queue_setup(void)
|
||||
/* Modify the queue depth for Queue 0 and attach it */
|
||||
qset.depth = 15;
|
||||
qset.state = SKELETON_QUEUE_ATTACH;
|
||||
ret = rte_rawdev_queue_setup(test_dev_id, 0, &qset);
|
||||
ret = rte_rawdev_queue_setup(test_dev_id, 0, &qset, sizeof(qset));
|
||||
RTE_TEST_ASSERT_SUCCESS(ret, "Failed to setup queue (%d)", ret);
|
||||
|
||||
/* Now, fetching the queue 0 should show depth as 15 */
|
||||
ret = rte_rawdev_queue_conf_get(test_dev_id, 0, &qget);
|
||||
ret = rte_rawdev_queue_conf_get(test_dev_id, 0, &qget, sizeof(qget));
|
||||
RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get queue config (%d)", ret);
|
||||
|
||||
RTE_TEST_ASSERT_EQUAL(qset.depth, qget.depth,
|
||||
@ -263,7 +263,7 @@ test_rawdev_queue_release(void)
|
||||
RTE_TEST_ASSERT_SUCCESS(ret, "Failed to release queue 0; (%d)", ret);
|
||||
|
||||
/* Now, fetching the queue 0 should show depth as default */
|
||||
ret = rte_rawdev_queue_conf_get(test_dev_id, 0, &qget);
|
||||
ret = rte_rawdev_queue_conf_get(test_dev_id, 0, &qget, sizeof(qget));
|
||||
RTE_TEST_ASSERT_SUCCESS(ret, "Failed to get queue config (%d)", ret);
|
||||
|
||||
RTE_TEST_ASSERT_EQUAL(qget.depth, SKELETON_QUEUE_DEF_DEPTH,
|
||||
|
@ -1411,7 +1411,8 @@ main(int argc, char **argv)
|
||||
ntb_q_conf.rx_mp = mbuf_pool;
|
||||
for (i = 0; i < num_queues; i++) {
|
||||
/* Setup rawdev queue */
|
||||
ret = rte_rawdev_queue_setup(dev_id, i, &ntb_q_conf);
|
||||
ret = rte_rawdev_queue_setup(dev_id, i, &ntb_q_conf,
|
||||
sizeof(ntb_q_conf));
|
||||
if (ret < 0)
|
||||
rte_exit(EXIT_FAILURE,
|
||||
"Failed to setup ntb queue %u.\n", i);
|
||||
|
@ -137,7 +137,8 @@ rte_rawdev_configure(uint16_t dev_id, struct rte_rawdev_info *dev_conf,
|
||||
int
|
||||
rte_rawdev_queue_conf_get(uint16_t dev_id,
|
||||
uint16_t queue_id,
|
||||
rte_rawdev_obj_t queue_conf)
|
||||
rte_rawdev_obj_t queue_conf,
|
||||
size_t queue_conf_size)
|
||||
{
|
||||
struct rte_rawdev *dev;
|
||||
|
||||
@ -145,14 +146,16 @@ rte_rawdev_queue_conf_get(uint16_t dev_id,
|
||||
dev = &rte_rawdevs[dev_id];
|
||||
|
||||
RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_def_conf, -ENOTSUP);
|
||||
(*dev->dev_ops->queue_def_conf)(dev, queue_id, queue_conf);
|
||||
(*dev->dev_ops->queue_def_conf)(dev, queue_id, queue_conf,
|
||||
queue_conf_size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
rte_rawdev_queue_setup(uint16_t dev_id,
|
||||
uint16_t queue_id,
|
||||
rte_rawdev_obj_t queue_conf)
|
||||
rte_rawdev_obj_t queue_conf,
|
||||
size_t queue_conf_size)
|
||||
{
|
||||
struct rte_rawdev *dev;
|
||||
|
||||
@ -160,7 +163,8 @@ rte_rawdev_queue_setup(uint16_t dev_id,
|
||||
dev = &rte_rawdevs[dev_id];
|
||||
|
||||
RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_setup, -ENOTSUP);
|
||||
return (*dev->dev_ops->queue_setup)(dev, queue_id, queue_conf);
|
||||
return (*dev->dev_ops->queue_setup)(dev, queue_id, queue_conf,
|
||||
queue_conf_size);
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -146,6 +146,8 @@ rte_rawdev_configure(uint16_t dev_id, struct rte_rawdev_info *dev_conf,
|
||||
* previously supplied to rte_rawdev_configure().
|
||||
* @param[out] queue_conf
|
||||
* The pointer to the default raw queue configuration data.
|
||||
* @param queue_conf_size
|
||||
* The size of the structure pointed to by queue_conf
|
||||
* @return
|
||||
* - 0: Success, driver updates the default raw queue configuration data.
|
||||
* - <0: Error code returned by the driver info get function.
|
||||
@ -156,7 +158,8 @@ rte_rawdev_configure(uint16_t dev_id, struct rte_rawdev_info *dev_conf,
|
||||
int
|
||||
rte_rawdev_queue_conf_get(uint16_t dev_id,
|
||||
uint16_t queue_id,
|
||||
rte_rawdev_obj_t queue_conf);
|
||||
rte_rawdev_obj_t queue_conf,
|
||||
size_t queue_conf_size);
|
||||
|
||||
/**
|
||||
* Allocate and set up a raw queue for a raw device.
|
||||
@ -169,6 +172,8 @@ rte_rawdev_queue_conf_get(uint16_t dev_id,
|
||||
* @param queue_conf
|
||||
* The pointer to the configuration data to be used for the raw queue.
|
||||
* NULL value is allowed, in which case default configuration used.
|
||||
* @param queue_conf_size
|
||||
* The size of the structure pointed to by queue_conf
|
||||
*
|
||||
* @see rte_rawdev_queue_conf_get()
|
||||
*
|
||||
@ -179,7 +184,8 @@ rte_rawdev_queue_conf_get(uint16_t dev_id,
|
||||
int
|
||||
rte_rawdev_queue_setup(uint16_t dev_id,
|
||||
uint16_t queue_id,
|
||||
rte_rawdev_obj_t queue_conf);
|
||||
rte_rawdev_obj_t queue_conf,
|
||||
size_t queue_conf_size);
|
||||
|
||||
/**
|
||||
* Release and deallocate a raw queue from a raw device.
|
||||
|
@ -218,7 +218,8 @@ typedef int (*rawdev_reset_t)(struct rte_rawdev *dev);
|
||||
*/
|
||||
typedef void (*rawdev_queue_conf_get_t)(struct rte_rawdev *dev,
|
||||
uint16_t queue_id,
|
||||
rte_rawdev_obj_t queue_conf);
|
||||
rte_rawdev_obj_t queue_conf,
|
||||
size_t queue_conf_size);
|
||||
|
||||
/**
|
||||
* Setup an raw queue.
|
||||
@ -235,7 +236,8 @@ typedef void (*rawdev_queue_conf_get_t)(struct rte_rawdev *dev,
|
||||
*/
|
||||
typedef int (*rawdev_queue_setup_t)(struct rte_rawdev *dev,
|
||||
uint16_t queue_id,
|
||||
rte_rawdev_obj_t queue_conf);
|
||||
rte_rawdev_obj_t queue_conf,
|
||||
size_t queue_conf_size);
|
||||
|
||||
/**
|
||||
* Release resources allocated by given raw queue.
|
||||
|
Loading…
Reference in New Issue
Block a user