@@ -660,3 +660,130 @@ rte_hcdev_comm_get_flag_value(struct rte_hcdev_comm_flag *hcflag, uint32_t *val)
return 0;
}
+
+struct rte_hcdev_comm_list *
+rte_hcdev_comm_create_list(uint16_t dev_id,
+ uint32_t num_comm_items)
+{
+ struct rte_hcdev_comm_list *comm_list;
+ uint32_t idx_l;
+
+ if (num_comm_items == 0) {
+ rte_errno = EINVAL;
+ return NULL;
+ }
+
+ comm_list = rte_hcdev_malloc(dev_id,
+ sizeof(struct rte_hcdev_comm_list) * num_comm_items,
+ RTE_HCDEV_MALLOC_REGISTER_FROM_CPU);
+ if (comm_list == NULL) {
+ rte_errno = ENOMEM;
+ return NULL;
+ }
+
+ for (idx_l = 0; idx_l < num_comm_items; idx_l++) {
+ comm_list[idx_l].pkt_list =
+ rte_hcdev_malloc(dev_id,
+ sizeof(struct rte_hcdev_comm_pkt) *
+ RTE_HCDEV_COMM_LIST_PKTS_MAX,
+ RTE_HCDEV_MALLOC_REGISTER_FROM_CPU);
+ if (comm_list[idx_l].pkt_list == NULL) {
+ rte_errno = ENOMEM;
+ return NULL;
+ }
+
+ RTE_HCDEV_VOLATILE(comm_list[idx_l].status) =
+ RTE_HCDEV_COMM_LIST_FREE;
+ comm_list[idx_l].num_pkts = 0;
+ }
+
+ return comm_list;
+}
+
+int
+rte_hcdev_comm_destroy_list(uint16_t dev_id,
+ struct rte_hcdev_comm_list *comm_list,
+ uint32_t num_comm_items)
+{
+ uint32_t idx_l;
+
+ if (comm_list == NULL) {
+ rte_errno = EINVAL;
+ return -rte_errno;
+ }
+
+ for (idx_l = 0; idx_l < num_comm_items; idx_l++)
+ rte_hcdev_free(dev_id, comm_list[idx_l].pkt_list);
+ rte_hcdev_free(dev_id, comm_list);
+
+ return 0;
+}
+
+int
+rte_hcdev_comm_populate_list_pkts(struct rte_hcdev_comm_list *comm_list_item,
+ struct rte_mbuf **mbufs, uint32_t num_mbufs)
+{
+ uint32_t idx;
+
+ if (comm_list_item == NULL || comm_list_item->pkt_list == NULL ||
+ mbufs == NULL || num_mbufs > RTE_HCDEV_COMM_LIST_PKTS_MAX) {
+ rte_errno = EINVAL;
+ return -rte_errno;
+ }
+
+ for (idx = 0; idx < num_mbufs; idx++) {
+ /* support only unchained mbufs */
+ if (unlikely((mbufs[idx]->nb_segs > 1) ||
+ (mbufs[idx]->next != NULL) ||
+ (mbufs[idx]->data_len != mbufs[idx]->pkt_len))) {
+ rte_errno = ENOTSUP;
+ return -rte_errno;
+ }
+ comm_list_item->pkt_list[idx].addr =
+ rte_pktmbuf_mtod_offset(mbufs[idx], uintptr_t, 0);
+ comm_list_item->pkt_list[idx].size = mbufs[idx]->pkt_len;
+ comm_list_item->pkt_list[idx].opaque = mbufs[idx];
+ }
+
+ RTE_HCDEV_VOLATILE(comm_list_item->num_pkts) = num_mbufs;
+ rte_mb();
+ RTE_HCDEV_VOLATILE(comm_list_item->status) = RTE_HCDEV_COMM_LIST_READY;
+
+ return 0;
+}
+
+int
+rte_hcdev_comm_cleanup_list(struct rte_hcdev_comm_list *comm_list_item)
+{
+ struct rte_mbuf *mbufs[RTE_HCDEV_COMM_LIST_PKTS_MAX];
+ uint32_t idx = 0;
+
+ if (comm_list_item == NULL) {
+ rte_errno = EINVAL;
+ return -rte_errno;
+ }
+
+ if (RTE_HCDEV_VOLATILE(comm_list_item->status) ==
+ RTE_HCDEV_COMM_LIST_READY) {
+ HCDEV_LOG(ERR, "packet list is still in progress");
+ rte_errno = EINVAL;
+ return -rte_errno;
+ }
+
+ for (idx = 0; idx < RTE_HCDEV_COMM_LIST_PKTS_MAX; idx++) {
+ if (comm_list_item->pkt_list[idx].addr == 0)
+ break;
+
+ comm_list_item->pkt_list[idx].addr = 0;
+ comm_list_item->pkt_list[idx].size = 0;
+ mbufs[idx] = (struct rte_mbuf *) comm_list_item->pkt_list[idx].opaque;
+ }
+
+ rte_pktmbuf_free_bulk(mbufs, idx);
+
+ RTE_HCDEV_VOLATILE(comm_list_item->status) = RTE_HCDEV_COMM_LIST_FREE;
+ RTE_HCDEV_VOLATILE(comm_list_item->num_pkts) = 0;
+ rte_mb();
+
+ return 0;
+}
@@ -8,3 +8,5 @@ headers = files(
sources = files(
'hcdev.c',
)
+
+deps += ['mbuf']
@@ -9,6 +9,7 @@
#include <stdint.h>
#include <stdbool.h>
+#include <rte_mbuf.h>
#include <rte_bitops.h>
#include <rte_compat.h>
@@ -41,6 +42,9 @@ extern "C" {
/** Access variable as volatile. */
#define RTE_HCDEV_VOLATILE(x) (*(volatile typeof(x)*)&(x))
+/** Max number of packets per communication list. */
+#define RTE_HCDEV_COMM_LIST_PKTS_MAX 1024
+
/** Store device info. */
struct rte_hcdev_info {
/** Unique identifier name. */
@@ -79,10 +83,47 @@ enum rte_hcdev_comm_flag_type {
/** Communication flag to coordinate CPU with the device. */
struct rte_hcdev_comm_flag {
+ /** Pointer to flag memory area. */
uint32_t *ptr;
+ /** Type of memory used to allocate the flag. */
enum rte_hcdev_comm_flag_type mtype;
};
+/** List of packets shared among CPU and device. */
+struct rte_hcdev_comm_pkt {
+ /** Address of the packet in memory (e.g. mbuf->buf_addr). */
+ uintptr_t addr;
+ /** Size in byte of the packet. */
+ size_t size;
+ /** Mbuf reference to release it in the rte_hcdev_comm_cleanup_list(). */
+ void *opaque;
+};
+
+/** Possible status for the list of packets shared among CPU and device. */
+enum rte_hcdev_comm_list_status {
+ /** Packet list can be filled with new mbufs, no one is using it. */
+ RTE_HCDEV_COMM_LIST_FREE = 0,
+ /** Packet list has been filled with new mbufs and it's ready to be used .*/
+ RTE_HCDEV_COMM_LIST_READY,
+ /** Packet list has been processed, it's ready to be freed. */
+ RTE_HCDEV_COMM_LIST_DONE,
+ /** Some error occurred during packet list processing. */
+ RTE_HCDEV_COMM_LIST_ERROR,
+};
+
+/**
+ * Communication list holding a number of lists of packets
+ * each having a status flag.
+ */
+struct rte_hcdev_comm_list {
+ /** List of packets populated by the CPU with a set of mbufs info. */
+ struct rte_hcdev_comm_pkt *pkt_list;
+ /** Number of packets in the list. */
+ uint32_t num_pkts;
+ /** Status of the list. */
+ enum rte_hcdev_comm_list_status status;
+};
+
/**
* @warning
* @b EXPERIMENTAL: this API may change without prior notice.
@@ -453,6 +494,97 @@ __rte_experimental
int rte_hcdev_comm_get_flag_value(struct rte_hcdev_comm_flag *hcflag,
uint32_t *val);
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Create a communication list that can be used to share packets
+ * between CPU and device.
+ * Each element of the list contains:
+ * - a packet list of RTE_HCDEV_COMM_LIST_PKTS_MAX elements
+ * - number of packets in the list
+ * - a status flag to communicate if the packet list is FREE,
+ * READY to be processed, DONE with processing.
+ *
+ * The list is allocated in CPU-visible memory.
+ * At creation time, every list is in FREE state.
+ *
+ * @param dev_id
+ * Reference device ID.
+ * @param num_comm_items
+ * Number of items in the communication list.
+ *
+ * @return
+ * A pointer to the allocated list, otherwise NULL and rte_errno is set:
+ * - EINVAL if invalid input params
+ */
+__rte_experimental
+struct rte_hcdev_comm_list *rte_hcdev_comm_create_list(uint16_t dev_id,
+ uint32_t num_comm_items);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Destroy a communication list.
+ *
+ * @param dev_id
+ * Reference device ID.
+ * @param comm_list
+ * Communication list to be destroyed.
+ * @param num_comm_items
+ * Number of items in the communication list.
+ *
+ * @return
+ * 0 on success, -rte_errno otherwise:
+ * - EINVAL if invalid input params
+ */
+__rte_experimental
+int rte_hcdev_comm_destroy_list(uint16_t dev_id,
+ struct rte_hcdev_comm_list *comm_list,
+ uint32_t num_comm_items);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Populate the packets list of the communication item
+ * with info from a list of mbufs.
+ * Status flag of that packet list is set to READY.
+ *
+ * @param comm_list_item
+ * Communication list item to fill.
+ * @param mbufs
+ * List of mbufs.
+ * @param num_mbufs
+ * Number of mbufs.
+ *
+ * @return
+ * 0 on success, -rte_errno otherwise:
+ * - EINVAL if invalid input params
+ * - ENOTSUP if mbufs are chained (multiple segments)
+ */
+__rte_experimental
+int rte_hcdev_comm_populate_list_pkts(struct rte_hcdev_comm_list *comm_list_item,
+ struct rte_mbuf **mbufs, uint32_t num_mbufs);
+
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Reset a communication list item to the original state.
+ * The status flag set to FREE and mbufs are returned to the pool.
+ *
+ * @param comm_list_item
+ * Communication list item to reset.
+ *
+ * @return
+ * 0 on success, -rte_errno otherwise:
+ * - EINVAL if invalid input params
+ */
+__rte_experimental
+int rte_hcdev_comm_cleanup_list(struct rte_hcdev_comm_list *comm_list_item);
+
#ifdef __cplusplus
}
#endif
@@ -6,9 +6,13 @@ EXPERIMENTAL {
rte_hcdev_callback_register;
rte_hcdev_callback_unregister;
rte_hcdev_close;
+ rte_hcdev_comm_cleanup_list;
rte_hcdev_comm_create_flag;
+ rte_hcdev_comm_create_list;
rte_hcdev_comm_destroy_flag;
+ rte_hcdev_comm_destroy_list;
rte_hcdev_comm_get_flag_value;
+ rte_hcdev_comm_populate_list_pkts;
rte_hcdev_comm_set_flag;
rte_hcdev_count_avail;
rte_hcdev_find_next;