199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson * Copyright 2017 NXP
399a2dd95SBruce Richardson */
499a2dd95SBruce Richardson
599a2dd95SBruce Richardson #ifndef _RTE_RAWDEV_PMD_H_
699a2dd95SBruce Richardson #define _RTE_RAWDEV_PMD_H_
799a2dd95SBruce Richardson
899a2dd95SBruce Richardson /** @file
999a2dd95SBruce Richardson * RTE RAW PMD APIs
1099a2dd95SBruce Richardson *
1199a2dd95SBruce Richardson * @note
1299a2dd95SBruce Richardson * Driver facing APIs for a raw device. These are not to be called directly by
1399a2dd95SBruce Richardson * any application.
1499a2dd95SBruce Richardson */
1599a2dd95SBruce Richardson
1699a2dd95SBruce Richardson #ifdef __cplusplus
1799a2dd95SBruce Richardson extern "C" {
1899a2dd95SBruce Richardson #endif
1999a2dd95SBruce Richardson
2099a2dd95SBruce Richardson #include <string.h>
2199a2dd95SBruce Richardson
2299a2dd95SBruce Richardson #include <rte_dev.h>
2399a2dd95SBruce Richardson #include <rte_malloc.h>
2499a2dd95SBruce Richardson #include <rte_log.h>
2599a2dd95SBruce Richardson #include <rte_common.h>
2699a2dd95SBruce Richardson
2799a2dd95SBruce Richardson #include "rte_rawdev.h"
2899a2dd95SBruce Richardson
2999a2dd95SBruce Richardson extern int librawdev_logtype;
3099a2dd95SBruce Richardson
3199a2dd95SBruce Richardson /* Logging Macros */
3299a2dd95SBruce Richardson #define RTE_RDEV_LOG(level, fmt, args...) \
3399a2dd95SBruce Richardson rte_log(RTE_LOG_ ## level, librawdev_logtype, "%s(): " fmt "\n", \
3499a2dd95SBruce Richardson __func__, ##args)
3599a2dd95SBruce Richardson
3699a2dd95SBruce Richardson #define RTE_RDEV_ERR(fmt, args...) \
3799a2dd95SBruce Richardson RTE_RDEV_LOG(ERR, fmt, ## args)
3899a2dd95SBruce Richardson #define RTE_RDEV_DEBUG(fmt, args...) \
3999a2dd95SBruce Richardson RTE_RDEV_LOG(DEBUG, fmt, ## args)
4099a2dd95SBruce Richardson #define RTE_RDEV_INFO(fmt, args...) \
4199a2dd95SBruce Richardson RTE_RDEV_LOG(INFO, fmt, ## args)
4299a2dd95SBruce Richardson
4399a2dd95SBruce Richardson
4499a2dd95SBruce Richardson /* Macros to check for valid device */
4599a2dd95SBruce Richardson #define RTE_RAWDEV_VALID_DEVID_OR_ERR_RET(dev_id, retval) do { \
4699a2dd95SBruce Richardson if (!rte_rawdev_pmd_is_valid_dev((dev_id))) { \
4799a2dd95SBruce Richardson RTE_RDEV_ERR("Invalid dev_id=%d", dev_id); \
4899a2dd95SBruce Richardson return retval; \
4999a2dd95SBruce Richardson } \
5099a2dd95SBruce Richardson } while (0)
5199a2dd95SBruce Richardson
5299a2dd95SBruce Richardson #define RTE_RAWDEV_VALID_DEVID_OR_RET(dev_id) do { \
5399a2dd95SBruce Richardson if (!rte_rawdev_pmd_is_valid_dev((dev_id))) { \
5499a2dd95SBruce Richardson RTE_RDEV_ERR("Invalid dev_id=%d", dev_id); \
5599a2dd95SBruce Richardson return; \
5699a2dd95SBruce Richardson } \
5799a2dd95SBruce Richardson } while (0)
5899a2dd95SBruce Richardson
5999a2dd95SBruce Richardson #define RTE_RAWDEV_DETACHED (0)
6099a2dd95SBruce Richardson #define RTE_RAWDEV_ATTACHED (1)
6199a2dd95SBruce Richardson
6299a2dd95SBruce Richardson /* Global structure used for maintaining state of allocated raw devices.
6399a2dd95SBruce Richardson *
6499a2dd95SBruce Richardson * TODO: Can be expanded to <type of raw device>:<count> in future.
6599a2dd95SBruce Richardson * Applications should be able to select from a number of type of raw
6699a2dd95SBruce Richardson * devices which were detected or attached to this DPDK instance.
6799a2dd95SBruce Richardson */
6899a2dd95SBruce Richardson struct rte_rawdev_global {
6999a2dd95SBruce Richardson /**< Number of devices found */
7099a2dd95SBruce Richardson uint16_t nb_devs;
7199a2dd95SBruce Richardson };
7299a2dd95SBruce Richardson
7399a2dd95SBruce Richardson extern struct rte_rawdev *rte_rawdevs;
7499a2dd95SBruce Richardson /** The pool of rte_rawdev structures. */
7599a2dd95SBruce Richardson
7699a2dd95SBruce Richardson /**
7799a2dd95SBruce Richardson * Get the rte_rawdev structure device pointer for the named device.
7899a2dd95SBruce Richardson *
7999a2dd95SBruce Richardson * @param name
8099a2dd95SBruce Richardson * device name to select the device structure.
8199a2dd95SBruce Richardson *
8299a2dd95SBruce Richardson * @return
8399a2dd95SBruce Richardson * - The rte_rawdev structure pointer for the given device ID.
8499a2dd95SBruce Richardson */
8599a2dd95SBruce Richardson static inline struct rte_rawdev *
rte_rawdev_pmd_get_named_dev(const char * name)8699a2dd95SBruce Richardson rte_rawdev_pmd_get_named_dev(const char *name)
8799a2dd95SBruce Richardson {
8899a2dd95SBruce Richardson struct rte_rawdev *dev;
8999a2dd95SBruce Richardson unsigned int i;
9099a2dd95SBruce Richardson
9199a2dd95SBruce Richardson if (name == NULL)
9299a2dd95SBruce Richardson return NULL;
9399a2dd95SBruce Richardson
9499a2dd95SBruce Richardson for (i = 0; i < RTE_RAWDEV_MAX_DEVS; i++) {
9599a2dd95SBruce Richardson dev = &rte_rawdevs[i];
9699a2dd95SBruce Richardson if ((dev->attached == RTE_RAWDEV_ATTACHED) &&
9799a2dd95SBruce Richardson (strcmp(dev->name, name) == 0))
9899a2dd95SBruce Richardson return dev;
9999a2dd95SBruce Richardson }
10099a2dd95SBruce Richardson
10199a2dd95SBruce Richardson return NULL;
10299a2dd95SBruce Richardson }
10399a2dd95SBruce Richardson
10499a2dd95SBruce Richardson /**
10599a2dd95SBruce Richardson * Validate if the raw device index is a valid attached raw device.
10699a2dd95SBruce Richardson *
10799a2dd95SBruce Richardson * @param dev_id
10899a2dd95SBruce Richardson * raw device index.
10999a2dd95SBruce Richardson *
11099a2dd95SBruce Richardson * @return
11199a2dd95SBruce Richardson * - If the device index is valid (1) or not (0).
11299a2dd95SBruce Richardson */
11399a2dd95SBruce Richardson static inline unsigned
rte_rawdev_pmd_is_valid_dev(uint8_t dev_id)11499a2dd95SBruce Richardson rte_rawdev_pmd_is_valid_dev(uint8_t dev_id)
11599a2dd95SBruce Richardson {
11699a2dd95SBruce Richardson struct rte_rawdev *dev;
11799a2dd95SBruce Richardson
11899a2dd95SBruce Richardson if (dev_id >= RTE_RAWDEV_MAX_DEVS)
11999a2dd95SBruce Richardson return 0;
12099a2dd95SBruce Richardson
12199a2dd95SBruce Richardson dev = &rte_rawdevs[dev_id];
12299a2dd95SBruce Richardson if (dev->attached != RTE_RAWDEV_ATTACHED)
12399a2dd95SBruce Richardson return 0;
12499a2dd95SBruce Richardson else
12599a2dd95SBruce Richardson return 1;
12699a2dd95SBruce Richardson }
12799a2dd95SBruce Richardson
12899a2dd95SBruce Richardson /**
129*b53d106dSSean Morrissey * Definitions of all functions exported by a driver through
13099a2dd95SBruce Richardson * the generic structure of type *rawdev_ops* supplied in the
13199a2dd95SBruce Richardson * *rte_rawdev* structure associated with a device.
13299a2dd95SBruce Richardson */
13399a2dd95SBruce Richardson
13499a2dd95SBruce Richardson /**
13599a2dd95SBruce Richardson * Get device information of a device.
13699a2dd95SBruce Richardson *
13799a2dd95SBruce Richardson * @param dev
13899a2dd95SBruce Richardson * Raw device pointer
13999a2dd95SBruce Richardson * @param dev_info
14099a2dd95SBruce Richardson * Raw device information structure
14199a2dd95SBruce Richardson * @param dev_private_size
14299a2dd95SBruce Richardson * The size of the structure pointed to by dev_info->dev_private
14399a2dd95SBruce Richardson *
14499a2dd95SBruce Richardson * @return
14599a2dd95SBruce Richardson * Returns 0 on success, negative error code on failure
14699a2dd95SBruce Richardson */
14799a2dd95SBruce Richardson typedef int (*rawdev_info_get_t)(struct rte_rawdev *dev,
14899a2dd95SBruce Richardson rte_rawdev_obj_t dev_info,
14999a2dd95SBruce Richardson size_t dev_private_size);
15099a2dd95SBruce Richardson
15199a2dd95SBruce Richardson /**
15299a2dd95SBruce Richardson * Configure a device.
15399a2dd95SBruce Richardson *
15499a2dd95SBruce Richardson * @param dev
15599a2dd95SBruce Richardson * Raw device pointer
15699a2dd95SBruce Richardson * @param config
15799a2dd95SBruce Richardson * Void object containing device specific configuration
15899a2dd95SBruce Richardson * @param config_size
15999a2dd95SBruce Richardson * Size of the memory allocated for the configuration
16099a2dd95SBruce Richardson *
16199a2dd95SBruce Richardson * @return
16299a2dd95SBruce Richardson * Returns 0 on success
16399a2dd95SBruce Richardson */
16499a2dd95SBruce Richardson typedef int (*rawdev_configure_t)(const struct rte_rawdev *dev,
16599a2dd95SBruce Richardson rte_rawdev_obj_t config,
16699a2dd95SBruce Richardson size_t config_size);
16799a2dd95SBruce Richardson
16899a2dd95SBruce Richardson /**
16999a2dd95SBruce Richardson * Start a configured device.
17099a2dd95SBruce Richardson *
17199a2dd95SBruce Richardson * @param dev
17299a2dd95SBruce Richardson * Raw device pointer
17399a2dd95SBruce Richardson *
17499a2dd95SBruce Richardson * @return
17599a2dd95SBruce Richardson * Returns 0 on success
17699a2dd95SBruce Richardson */
17799a2dd95SBruce Richardson typedef int (*rawdev_start_t)(struct rte_rawdev *dev);
17899a2dd95SBruce Richardson
17999a2dd95SBruce Richardson /**
18099a2dd95SBruce Richardson * Stop a configured device.
18199a2dd95SBruce Richardson *
18299a2dd95SBruce Richardson * @param dev
18399a2dd95SBruce Richardson * Raw device pointer
18499a2dd95SBruce Richardson */
18599a2dd95SBruce Richardson typedef void (*rawdev_stop_t)(struct rte_rawdev *dev);
18699a2dd95SBruce Richardson
18799a2dd95SBruce Richardson /**
18899a2dd95SBruce Richardson * Close a configured device.
18999a2dd95SBruce Richardson *
19099a2dd95SBruce Richardson * @param dev
19199a2dd95SBruce Richardson * Raw device pointer
19299a2dd95SBruce Richardson *
19399a2dd95SBruce Richardson * @return
19499a2dd95SBruce Richardson * - 0 on success
19599a2dd95SBruce Richardson * - (-EAGAIN) if can't close as device is busy
19699a2dd95SBruce Richardson */
19799a2dd95SBruce Richardson typedef int (*rawdev_close_t)(struct rte_rawdev *dev);
19899a2dd95SBruce Richardson
19999a2dd95SBruce Richardson /**
20099a2dd95SBruce Richardson * Reset a configured device.
20199a2dd95SBruce Richardson *
20299a2dd95SBruce Richardson * @param dev
20399a2dd95SBruce Richardson * Raw device pointer
20499a2dd95SBruce Richardson * @return
20599a2dd95SBruce Richardson * 0 for success
20699a2dd95SBruce Richardson * !0 for failure
20799a2dd95SBruce Richardson */
20899a2dd95SBruce Richardson typedef int (*rawdev_reset_t)(struct rte_rawdev *dev);
20999a2dd95SBruce Richardson
21099a2dd95SBruce Richardson /**
21199a2dd95SBruce Richardson * Retrieve the current raw queue configuration.
21299a2dd95SBruce Richardson *
21399a2dd95SBruce Richardson * @param dev
21499a2dd95SBruce Richardson * Raw device pointer
21599a2dd95SBruce Richardson * @param queue_id
21699a2dd95SBruce Richardson * Raw device queue index
21799a2dd95SBruce Richardson * @param[out] queue_conf
21899a2dd95SBruce Richardson * Raw device queue configuration structure
21999a2dd95SBruce Richardson * @param queue_conf_size
22099a2dd95SBruce Richardson * Size of the memory allocated for the configuration
22199a2dd95SBruce Richardson *
22299a2dd95SBruce Richardson * @return
22399a2dd95SBruce Richardson * Returns 0 on success, negative errno on failure
22499a2dd95SBruce Richardson */
22599a2dd95SBruce Richardson typedef int (*rawdev_queue_conf_get_t)(struct rte_rawdev *dev,
22699a2dd95SBruce Richardson uint16_t queue_id,
22799a2dd95SBruce Richardson rte_rawdev_obj_t queue_conf,
22899a2dd95SBruce Richardson size_t queue_conf_size);
22999a2dd95SBruce Richardson
23099a2dd95SBruce Richardson /**
23199a2dd95SBruce Richardson * Setup an raw queue.
23299a2dd95SBruce Richardson *
23399a2dd95SBruce Richardson * @param dev
23499a2dd95SBruce Richardson * Raw device pointer
23599a2dd95SBruce Richardson * @param queue_id
23699a2dd95SBruce Richardson * Rawqueue index
23799a2dd95SBruce Richardson * @param queue_conf
23899a2dd95SBruce Richardson * Rawqueue configuration structure
23999a2dd95SBruce Richardson * @param queue_conf_size
24099a2dd95SBruce Richardson * Size of the memory allocated for the configuration
24199a2dd95SBruce Richardson *
24299a2dd95SBruce Richardson * @return
24399a2dd95SBruce Richardson * Returns 0 on success.
24499a2dd95SBruce Richardson */
24599a2dd95SBruce Richardson typedef int (*rawdev_queue_setup_t)(struct rte_rawdev *dev,
24699a2dd95SBruce Richardson uint16_t queue_id,
24799a2dd95SBruce Richardson rte_rawdev_obj_t queue_conf,
24899a2dd95SBruce Richardson size_t queue_conf_size);
24999a2dd95SBruce Richardson
25099a2dd95SBruce Richardson /**
25199a2dd95SBruce Richardson * Release resources allocated by given raw queue.
25299a2dd95SBruce Richardson *
25399a2dd95SBruce Richardson * @param dev
25499a2dd95SBruce Richardson * Raw device pointer
25599a2dd95SBruce Richardson * @param queue_id
25699a2dd95SBruce Richardson * Raw queue index
25799a2dd95SBruce Richardson *
25899a2dd95SBruce Richardson */
25999a2dd95SBruce Richardson typedef int (*rawdev_queue_release_t)(struct rte_rawdev *dev,
26099a2dd95SBruce Richardson uint16_t queue_id);
26199a2dd95SBruce Richardson
26299a2dd95SBruce Richardson /**
26399a2dd95SBruce Richardson * Get the count of number of queues configured on this device.
26499a2dd95SBruce Richardson *
26599a2dd95SBruce Richardson * Another way to fetch this information is to fetch the device configuration.
26699a2dd95SBruce Richardson * But, that assumes that the device configuration managed by the driver has
26799a2dd95SBruce Richardson * that kind of information.
26899a2dd95SBruce Richardson *
26999a2dd95SBruce Richardson * This function helps in getting queue count supported, independently. It
27099a2dd95SBruce Richardson * can help in cases where iterator needs to be implemented.
27199a2dd95SBruce Richardson *
27299a2dd95SBruce Richardson * @param dev
27399a2dd95SBruce Richardson * Raw device pointer
27499a2dd95SBruce Richardson * @return
27599a2dd95SBruce Richardson * Number of queues; 0 is assumed to be a valid response.
27699a2dd95SBruce Richardson *
27799a2dd95SBruce Richardson */
27899a2dd95SBruce Richardson typedef uint16_t (*rawdev_queue_count_t)(struct rte_rawdev *dev);
27999a2dd95SBruce Richardson
28099a2dd95SBruce Richardson /**
28199a2dd95SBruce Richardson * Enqueue an array of raw buffers to the device.
28299a2dd95SBruce Richardson *
28399a2dd95SBruce Richardson * Buffer being used is opaque - it can be obtained from mempool or from
28499a2dd95SBruce Richardson * any other source. Interpretation of buffer is responsibility of driver.
28599a2dd95SBruce Richardson *
28699a2dd95SBruce Richardson * @param dev
28799a2dd95SBruce Richardson * Raw device pointer
28899a2dd95SBruce Richardson * @param buffers
28999a2dd95SBruce Richardson * array of buffers
29099a2dd95SBruce Richardson * @param count
29199a2dd95SBruce Richardson * number of buffers passed
29299a2dd95SBruce Richardson * @param context
29399a2dd95SBruce Richardson * an opaque object representing context of the call; for example, an
29499a2dd95SBruce Richardson * application can pass information about the queues on which enqueue needs
29599a2dd95SBruce Richardson * to be done. Or, the enqueue operation might be passed reference to an
29699a2dd95SBruce Richardson * object containing a callback (agreed upon between application and driver).
29799a2dd95SBruce Richardson *
29899a2dd95SBruce Richardson * @return
29999a2dd95SBruce Richardson * >=0 Count of buffers successfully enqueued (0: no buffers enqueued)
30099a2dd95SBruce Richardson * <0 Error count in case of error
30199a2dd95SBruce Richardson */
30299a2dd95SBruce Richardson typedef int (*rawdev_enqueue_bufs_t)(struct rte_rawdev *dev,
30399a2dd95SBruce Richardson struct rte_rawdev_buf **buffers,
30499a2dd95SBruce Richardson unsigned int count,
30599a2dd95SBruce Richardson rte_rawdev_obj_t context);
30699a2dd95SBruce Richardson
30799a2dd95SBruce Richardson /**
30899a2dd95SBruce Richardson * Dequeue an array of raw buffers from the device.
30999a2dd95SBruce Richardson *
31099a2dd95SBruce Richardson * @param dev
31199a2dd95SBruce Richardson * Raw device pointer
31299a2dd95SBruce Richardson * @param buffers
31399a2dd95SBruce Richardson * array of buffers
31499a2dd95SBruce Richardson * @param count
31599a2dd95SBruce Richardson * Max buffers expected to be dequeued
31699a2dd95SBruce Richardson * @param context
31799a2dd95SBruce Richardson * an opaque object representing context of the call. Based on this object,
31899a2dd95SBruce Richardson * the application and driver can coordinate for dequeue operation involving
31999a2dd95SBruce Richardson * agreed upon semantics. For example, queue information/id on which Dequeue
32099a2dd95SBruce Richardson * needs to be performed.
32199a2dd95SBruce Richardson * @return
32299a2dd95SBruce Richardson * >0, ~0: Count of buffers returned
32399a2dd95SBruce Richardson * <0: Error
32499a2dd95SBruce Richardson * Whether short dequeue is success or failure is decided between app and
32599a2dd95SBruce Richardson * driver.
32699a2dd95SBruce Richardson */
32799a2dd95SBruce Richardson typedef int (*rawdev_dequeue_bufs_t)(struct rte_rawdev *dev,
32899a2dd95SBruce Richardson struct rte_rawdev_buf **buffers,
32999a2dd95SBruce Richardson unsigned int count,
33099a2dd95SBruce Richardson rte_rawdev_obj_t context);
33199a2dd95SBruce Richardson
33299a2dd95SBruce Richardson /**
33399a2dd95SBruce Richardson * Dump internal information
33499a2dd95SBruce Richardson *
33599a2dd95SBruce Richardson * @param dev
33699a2dd95SBruce Richardson * Raw device pointer
33799a2dd95SBruce Richardson * @param f
33899a2dd95SBruce Richardson * A pointer to a file for output
33999a2dd95SBruce Richardson * @return
34099a2dd95SBruce Richardson * 0 for success,
34199a2dd95SBruce Richardson * !0 Error
34299a2dd95SBruce Richardson *
34399a2dd95SBruce Richardson */
34499a2dd95SBruce Richardson typedef int (*rawdev_dump_t)(struct rte_rawdev *dev, FILE *f);
34599a2dd95SBruce Richardson
34699a2dd95SBruce Richardson /**
34799a2dd95SBruce Richardson * Get an attribute value from implementation.
34899a2dd95SBruce Richardson * Attribute is an opaque handle agreed upon between application and PMD.
34999a2dd95SBruce Richardson *
35099a2dd95SBruce Richardson * @param dev
35199a2dd95SBruce Richardson * Raw device pointer
35299a2dd95SBruce Richardson * @param attr_name
35399a2dd95SBruce Richardson * Opaque object representing an attribute in implementation.
35499a2dd95SBruce Richardson * @param attr_value [out]
35599a2dd95SBruce Richardson * Opaque response to the attribute value. In case of error, this remains
35699a2dd95SBruce Richardson * untouched. This is double pointer of void type.
35799a2dd95SBruce Richardson * @return
35899a2dd95SBruce Richardson * 0 for success
35999a2dd95SBruce Richardson * !0 Error; attr_value remains untouched in case of error.
36099a2dd95SBruce Richardson */
36199a2dd95SBruce Richardson typedef int (*rawdev_get_attr_t)(struct rte_rawdev *dev,
36299a2dd95SBruce Richardson const char *attr_name,
36399a2dd95SBruce Richardson uint64_t *attr_value);
36499a2dd95SBruce Richardson
36599a2dd95SBruce Richardson /**
36699a2dd95SBruce Richardson * Set an attribute value.
36799a2dd95SBruce Richardson * Attribute is an opaque handle agreed upon between application and PMD.
36899a2dd95SBruce Richardson *
36999a2dd95SBruce Richardson * @param dev
37099a2dd95SBruce Richardson * Raw device pointer
37199a2dd95SBruce Richardson * @param attr_name
37299a2dd95SBruce Richardson * Opaque object representing an attribute in implementation.
37399a2dd95SBruce Richardson * @param attr_value
37499a2dd95SBruce Richardson * Value of the attribute represented by attr_name
37599a2dd95SBruce Richardson * @return
37699a2dd95SBruce Richardson * 0 for success
37799a2dd95SBruce Richardson * !0 Error
37899a2dd95SBruce Richardson */
37999a2dd95SBruce Richardson typedef int (*rawdev_set_attr_t)(struct rte_rawdev *dev,
38099a2dd95SBruce Richardson const char *attr_name,
38199a2dd95SBruce Richardson const uint64_t attr_value);
38299a2dd95SBruce Richardson
38399a2dd95SBruce Richardson /**
38499a2dd95SBruce Richardson * Retrieve a set of statistics from device.
38599a2dd95SBruce Richardson * Note: Being a raw device, the stats are specific to the device being
38699a2dd95SBruce Richardson * implemented thus represented as xstats.
38799a2dd95SBruce Richardson *
38899a2dd95SBruce Richardson * @param dev
38999a2dd95SBruce Richardson * Raw device pointer
39099a2dd95SBruce Richardson * @param ids
39199a2dd95SBruce Richardson * The stat ids to retrieve
39299a2dd95SBruce Richardson * @param values
39399a2dd95SBruce Richardson * The returned stat values
39499a2dd95SBruce Richardson * @param n
39599a2dd95SBruce Richardson * The number of id values and entries in the values array
39699a2dd95SBruce Richardson * @return
39799a2dd95SBruce Richardson * The number of stat values successfully filled into the values array
39899a2dd95SBruce Richardson */
39999a2dd95SBruce Richardson typedef int (*rawdev_xstats_get_t)(const struct rte_rawdev *dev,
40099a2dd95SBruce Richardson const unsigned int ids[], uint64_t values[], unsigned int n);
40199a2dd95SBruce Richardson
40299a2dd95SBruce Richardson /**
40399a2dd95SBruce Richardson * Resets the statistic values in xstats for the device.
40499a2dd95SBruce Richardson */
40599a2dd95SBruce Richardson typedef int (*rawdev_xstats_reset_t)(struct rte_rawdev *dev,
40699a2dd95SBruce Richardson const uint32_t ids[],
40799a2dd95SBruce Richardson uint32_t nb_ids);
40899a2dd95SBruce Richardson
40999a2dd95SBruce Richardson /**
41099a2dd95SBruce Richardson * Get names of extended stats of an raw device
41199a2dd95SBruce Richardson *
41299a2dd95SBruce Richardson * @param dev
41399a2dd95SBruce Richardson * Raw device pointer
41499a2dd95SBruce Richardson * @param xstats_names
41599a2dd95SBruce Richardson * Array of name values to be filled in
41699a2dd95SBruce Richardson * @param size
41799a2dd95SBruce Richardson * Number of values in the xstats_names array
41899a2dd95SBruce Richardson * @return
41999a2dd95SBruce Richardson * When size >= the number of stats, return the number of stat values filled
42099a2dd95SBruce Richardson * into the array.
42199a2dd95SBruce Richardson * When size < the number of available stats, return the number of stats
42299a2dd95SBruce Richardson * values, and do not fill in any data into xstats_names.
42399a2dd95SBruce Richardson */
42499a2dd95SBruce Richardson typedef int (*rawdev_xstats_get_names_t)(const struct rte_rawdev *dev,
42599a2dd95SBruce Richardson struct rte_rawdev_xstats_name *xstats_names,
42699a2dd95SBruce Richardson unsigned int size);
42799a2dd95SBruce Richardson
42899a2dd95SBruce Richardson /**
42999a2dd95SBruce Richardson * Get value of one stats and optionally return its id
43099a2dd95SBruce Richardson *
43199a2dd95SBruce Richardson * @param dev
43299a2dd95SBruce Richardson * Raw device pointer
43399a2dd95SBruce Richardson * @param name
43499a2dd95SBruce Richardson * The name of the stat to retrieve
43599a2dd95SBruce Richardson * @param id
43699a2dd95SBruce Richardson * Pointer to an unsigned int where we store the stat-id.
43799a2dd95SBruce Richardson * This pointer may be null if the id is not required.
43899a2dd95SBruce Richardson * @return
43999a2dd95SBruce Richardson * The value of the stat, or (uint64_t)-1 if the stat is not found.
44099a2dd95SBruce Richardson * If the stat is not found, the id value will be returned as (unsigned)-1,
44199a2dd95SBruce Richardson * if id pointer is non-NULL
44299a2dd95SBruce Richardson */
44399a2dd95SBruce Richardson typedef uint64_t (*rawdev_xstats_get_by_name_t)(const struct rte_rawdev *dev,
44499a2dd95SBruce Richardson const char *name,
44599a2dd95SBruce Richardson unsigned int *id);
44699a2dd95SBruce Richardson
44799a2dd95SBruce Richardson /**
44899a2dd95SBruce Richardson * Get firmware/device-stack status.
44999a2dd95SBruce Richardson * Implementation to allocate buffer for returning information.
45099a2dd95SBruce Richardson *
45199a2dd95SBruce Richardson * @param dev
45299a2dd95SBruce Richardson * Raw device pointer
45399a2dd95SBruce Richardson * @param status_info
45499a2dd95SBruce Richardson * void block containing device specific status information
45599a2dd95SBruce Richardson * @return
45699a2dd95SBruce Richardson * 0 for success,
45799a2dd95SBruce Richardson * !0 for failure, with undefined value in `status_info`
45899a2dd95SBruce Richardson */
45999a2dd95SBruce Richardson typedef int (*rawdev_firmware_status_get_t)(struct rte_rawdev *dev,
46099a2dd95SBruce Richardson rte_rawdev_obj_t status_info);
46199a2dd95SBruce Richardson
46299a2dd95SBruce Richardson /**
46399a2dd95SBruce Richardson * Get firmware version information
46499a2dd95SBruce Richardson *
46599a2dd95SBruce Richardson * @param dev
46699a2dd95SBruce Richardson * Raw device pointer
46799a2dd95SBruce Richardson * @param version_info
46899a2dd95SBruce Richardson * void pointer to version information returned by device
46999a2dd95SBruce Richardson * @return
47099a2dd95SBruce Richardson * 0 for success,
47199a2dd95SBruce Richardson * !0 for failure, with undefined value in `version_info`
47299a2dd95SBruce Richardson */
47399a2dd95SBruce Richardson typedef int (*rawdev_firmware_version_get_t)(struct rte_rawdev *dev,
47499a2dd95SBruce Richardson rte_rawdev_obj_t version_info);
47599a2dd95SBruce Richardson
47699a2dd95SBruce Richardson /**
47799a2dd95SBruce Richardson * Load firmware from a buffer (DMA'able)
47899a2dd95SBruce Richardson *
47999a2dd95SBruce Richardson * @param dev
48099a2dd95SBruce Richardson * Raw device pointer
48199a2dd95SBruce Richardson * @param firmware_buf
48299a2dd95SBruce Richardson * Pointer to firmware image
48399a2dd95SBruce Richardson * @return
48499a2dd95SBruce Richardson * >0, ~0: for successful load
48599a2dd95SBruce Richardson * <0: for failure
48699a2dd95SBruce Richardson *
48799a2dd95SBruce Richardson * @see Application may use 'firmware_version_get` for ascertaining successful
48899a2dd95SBruce Richardson * load
48999a2dd95SBruce Richardson */
49099a2dd95SBruce Richardson typedef int (*rawdev_firmware_load_t)(struct rte_rawdev *dev,
49199a2dd95SBruce Richardson rte_rawdev_obj_t firmware_buf);
49299a2dd95SBruce Richardson
49399a2dd95SBruce Richardson /**
49499a2dd95SBruce Richardson * Unload firmware
49599a2dd95SBruce Richardson *
49699a2dd95SBruce Richardson * @param dev
49799a2dd95SBruce Richardson * Raw device pointer
49899a2dd95SBruce Richardson * @return
49999a2dd95SBruce Richardson * >0, ~0 for successful unloading
50099a2dd95SBruce Richardson * <0 for failure in unloading
50199a2dd95SBruce Richardson *
50299a2dd95SBruce Richardson * Note: Application can use the `firmware_status_get` or
50399a2dd95SBruce Richardson * `firmware_version_get` to get result of unload.
50499a2dd95SBruce Richardson */
50599a2dd95SBruce Richardson typedef int (*rawdev_firmware_unload_t)(struct rte_rawdev *dev);
50699a2dd95SBruce Richardson
50799a2dd95SBruce Richardson /**
50899a2dd95SBruce Richardson * Start rawdev selftest
50999a2dd95SBruce Richardson *
51099a2dd95SBruce Richardson * @return
51199a2dd95SBruce Richardson * Return 0 on success
51299a2dd95SBruce Richardson */
51399a2dd95SBruce Richardson typedef int (*rawdev_selftest_t)(uint16_t dev_id);
51499a2dd95SBruce Richardson
51599a2dd95SBruce Richardson /** Rawdevice operations function pointer table */
51699a2dd95SBruce Richardson struct rte_rawdev_ops {
51799a2dd95SBruce Richardson /**< Get device info. */
51899a2dd95SBruce Richardson rawdev_info_get_t dev_info_get;
51999a2dd95SBruce Richardson /**< Configure device. */
52099a2dd95SBruce Richardson rawdev_configure_t dev_configure;
52199a2dd95SBruce Richardson /**< Start device. */
52299a2dd95SBruce Richardson rawdev_start_t dev_start;
52399a2dd95SBruce Richardson /**< Stop device. */
52499a2dd95SBruce Richardson rawdev_stop_t dev_stop;
52599a2dd95SBruce Richardson /**< Close device. */
52699a2dd95SBruce Richardson rawdev_close_t dev_close;
52799a2dd95SBruce Richardson /**< Reset device. */
52899a2dd95SBruce Richardson rawdev_reset_t dev_reset;
52999a2dd95SBruce Richardson
53099a2dd95SBruce Richardson /**< Get raw queue configuration. */
53199a2dd95SBruce Richardson rawdev_queue_conf_get_t queue_def_conf;
53299a2dd95SBruce Richardson /**< Set up an raw queue. */
53399a2dd95SBruce Richardson rawdev_queue_setup_t queue_setup;
53499a2dd95SBruce Richardson /**< Release an raw queue. */
53599a2dd95SBruce Richardson rawdev_queue_release_t queue_release;
53699a2dd95SBruce Richardson /**< Get the number of queues attached to the device */
53799a2dd95SBruce Richardson rawdev_queue_count_t queue_count;
53899a2dd95SBruce Richardson
53999a2dd95SBruce Richardson /**< Enqueue an array of raw buffers to device. */
54099a2dd95SBruce Richardson rawdev_enqueue_bufs_t enqueue_bufs;
54199a2dd95SBruce Richardson /**< Dequeue an array of raw buffers from device. */
54299a2dd95SBruce Richardson /** TODO: Callback based enqueue and dequeue support */
54399a2dd95SBruce Richardson rawdev_dequeue_bufs_t dequeue_bufs;
54499a2dd95SBruce Richardson
54599a2dd95SBruce Richardson /* Dump internal information */
54699a2dd95SBruce Richardson rawdev_dump_t dump;
54799a2dd95SBruce Richardson
54899a2dd95SBruce Richardson /**< Get an attribute managed by the implementation */
54999a2dd95SBruce Richardson rawdev_get_attr_t attr_get;
55099a2dd95SBruce Richardson /**< Set an attribute managed by the implementation */
55199a2dd95SBruce Richardson rawdev_set_attr_t attr_set;
55299a2dd95SBruce Richardson
55399a2dd95SBruce Richardson /**< Get extended device statistics. */
55499a2dd95SBruce Richardson rawdev_xstats_get_t xstats_get;
55599a2dd95SBruce Richardson /**< Get names of extended stats. */
55699a2dd95SBruce Richardson rawdev_xstats_get_names_t xstats_get_names;
55799a2dd95SBruce Richardson /**< Get one value by name. */
55899a2dd95SBruce Richardson rawdev_xstats_get_by_name_t xstats_get_by_name;
55999a2dd95SBruce Richardson /**< Reset the statistics values in xstats. */
56099a2dd95SBruce Richardson rawdev_xstats_reset_t xstats_reset;
56199a2dd95SBruce Richardson
56299a2dd95SBruce Richardson /**< Obtain firmware status */
56399a2dd95SBruce Richardson rawdev_firmware_status_get_t firmware_status_get;
56499a2dd95SBruce Richardson /**< Obtain firmware version information */
56599a2dd95SBruce Richardson rawdev_firmware_version_get_t firmware_version_get;
56699a2dd95SBruce Richardson /**< Load firmware */
56799a2dd95SBruce Richardson rawdev_firmware_load_t firmware_load;
56899a2dd95SBruce Richardson /**< Unload firmware */
56999a2dd95SBruce Richardson rawdev_firmware_unload_t firmware_unload;
57099a2dd95SBruce Richardson
57199a2dd95SBruce Richardson /**< Device selftest function */
57299a2dd95SBruce Richardson rawdev_selftest_t dev_selftest;
57399a2dd95SBruce Richardson };
57499a2dd95SBruce Richardson
57599a2dd95SBruce Richardson /**
57699a2dd95SBruce Richardson * Allocates a new rawdev slot for an raw device and returns the pointer
57799a2dd95SBruce Richardson * to that slot for the driver to use.
57899a2dd95SBruce Richardson *
57999a2dd95SBruce Richardson * @param name
58099a2dd95SBruce Richardson * Unique identifier name for each device
58199a2dd95SBruce Richardson * @param dev_private_size
58299a2dd95SBruce Richardson * Size of private data memory allocated within rte_rawdev object.
58399a2dd95SBruce Richardson * Set to 0 to disable internal memory allocation and allow for
58499a2dd95SBruce Richardson * self-allocation.
58599a2dd95SBruce Richardson * @param socket_id
58699a2dd95SBruce Richardson * Socket to allocate resources on.
58799a2dd95SBruce Richardson * @return
58899a2dd95SBruce Richardson * - Slot in the rte_dev_devices array for a new device;
58999a2dd95SBruce Richardson */
59099a2dd95SBruce Richardson struct rte_rawdev *
59199a2dd95SBruce Richardson rte_rawdev_pmd_allocate(const char *name, size_t dev_private_size,
59299a2dd95SBruce Richardson int socket_id);
59399a2dd95SBruce Richardson
59499a2dd95SBruce Richardson /**
59599a2dd95SBruce Richardson * Release the specified rawdev device.
59699a2dd95SBruce Richardson *
59799a2dd95SBruce Richardson * @param rawdev
59899a2dd95SBruce Richardson * The *rawdev* pointer is the address of the *rte_rawdev* structure.
59999a2dd95SBruce Richardson * @return
60099a2dd95SBruce Richardson * - 0 on success, negative on error
60199a2dd95SBruce Richardson */
60299a2dd95SBruce Richardson int
60399a2dd95SBruce Richardson rte_rawdev_pmd_release(struct rte_rawdev *rawdev);
60499a2dd95SBruce Richardson
60599a2dd95SBruce Richardson /**
60699a2dd95SBruce Richardson * Creates a new raw device and returns the pointer to that device.
60799a2dd95SBruce Richardson *
60899a2dd95SBruce Richardson * @param name
60999a2dd95SBruce Richardson * Pointer to a character array containing name of the device
61099a2dd95SBruce Richardson * @param dev_private_size
61199a2dd95SBruce Richardson * Size of raw PMDs private data
61299a2dd95SBruce Richardson * @param socket_id
61399a2dd95SBruce Richardson * Socket to allocate resources on.
61499a2dd95SBruce Richardson *
61599a2dd95SBruce Richardson * @return
61699a2dd95SBruce Richardson * - Raw device pointer if device is successfully created.
61799a2dd95SBruce Richardson * - NULL if device cannot be created.
61899a2dd95SBruce Richardson */
61999a2dd95SBruce Richardson struct rte_rawdev *
62099a2dd95SBruce Richardson rte_rawdev_pmd_init(const char *name, size_t dev_private_size,
62199a2dd95SBruce Richardson int socket_id);
62299a2dd95SBruce Richardson
62399a2dd95SBruce Richardson /**
62499a2dd95SBruce Richardson * Destroy a raw device
62599a2dd95SBruce Richardson *
62699a2dd95SBruce Richardson * @param name
62799a2dd95SBruce Richardson * Name of the device
62899a2dd95SBruce Richardson * @return
62999a2dd95SBruce Richardson * - 0 on success, negative on error
63099a2dd95SBruce Richardson */
63199a2dd95SBruce Richardson int
63299a2dd95SBruce Richardson rte_rawdev_pmd_uninit(const char *name);
63399a2dd95SBruce Richardson
63499a2dd95SBruce Richardson #ifdef __cplusplus
63599a2dd95SBruce Richardson }
63699a2dd95SBruce Richardson #endif
63799a2dd95SBruce Richardson
63899a2dd95SBruce Richardson #endif /* _RTE_RAWDEV_PMD_H_ */
639