This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
stellar-stellar-2022/src/packet_io/marsio_mode/pio_marsio.h
2022-08-31 22:04:05 +08:00

176 lines
6.0 KiB
C

/*
**********************************************************************************************
* File: marsio.h
* Description: marsio runmode api
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-07-15
* Copyright: (c) 2018-2022 Geedge Networks, Inc. All rights reserved.
***********************************************************************************************
*/
#ifndef _PIO_MARSIO_H_
#define _PIO_MARSIO_H_
#ifdef __cpluscplus
extern "C"
{
#endif
#include <stdint.h>
#include <marsio.h>
/**
* @brief dll is short for dynamic link lib
* the following entries is supported by marsio system
*/
struct marsio_dll_function_entries {
struct mr_instance *(*marsio_create)(void);
int (*marsio_init)(struct mr_instance *instance, const char *appsym);
int (*marsio_destroy)(struct mr_instance *instance);
struct mr_vdev *(*marsio_open_device)(struct mr_instance *instance, const char *devsym,
unsigned int nr_rxstream, unsigned int nr_txstream);
void (*marsio_close_device)(struct mr_vdev *pdev);
int (*marsio_option_set)(struct mr_instance *instance, marsio_opt_type_t opt_type, void *opt, size_t sz_opt);
struct mr_sendpath *(*marsio_sendpath_create_by_vdev)(struct mr_vdev *pdev);
void (*marsio_sendpath_destroy)(struct mr_sendpath *sendpath);
int (*marsio_thread_init)(struct mr_instance *instance);
int (*marsio_recv_burst)(struct mr_vdev *pdev, queue_id_t qid, marsio_buff_t *mbufs[], int nr_mbufs);
int (*marsio_send_burst)(struct mr_sendpath *sendpath, queue_id_t qid, marsio_buff_t *mbufs[], int nr_mbufs);
int (*marsio_send_burst_with_options)(struct mr_sendpath *sendpath, queue_id_t sid,
marsio_buff_t *mbufs[], int nr_mbufs, uint16_t options);
int (*marsio_buff_malloc_global)(struct mr_instance *instance, marsio_buff_t *marsio_buff[], unsigned int nr_mbufs,
int socket_id, int thread_id);
void (*marsio_buff_free)(struct mr_instance *instance, marsio_buff_t *marsio_buff[], unsigned int nr_mbufs,
int socket_id, int thread_id);
char *(*marsio_buff_append)(marsio_buff_t *m, uint16_t len);
void *(*marsio_buff_ctrlzone)(marsio_buff_t *m, uint8_t id);
void (*marsio_buff_ctrlzone_set)(marsio_buff_t *m, uint8_t id, void* ptr_data, uint8_t size);
void (*marsio_buff_set_rehash_index)(marsio_buff_t *m, uint32_t hash);
char *(*marsio_buff_mtod)(marsio_buff_t *m);
uint32_t (*marsio_buff_datalen)(marsio_buff_t *m);
uint32_t (*marsio_buff_buflen)(marsio_buff_t *m);
marsio_buff_t *(*marsio_buff_clone_with_options)(struct mr_instance *instance, marsio_buff_t *md, int socket_id,
int thread_id, uint16_t options);
void (*marsio_send_burst_flush)(struct mr_sendpath *sendpath, queue_id_t sid);
int (*marsio_buff_get_metadata)(marsio_buff_t *m, enum mr_buff_metadata_type type, void *data, unsigned int sz_data);
int (*marsio_buff_set_metadata)(marsio_buff_t *m, enum mr_buff_metadata_type type, void *data, unsigned int sz_data);
int (*marsio_buff_unset_metadata)(marsio_buff_t *m, enum mr_buff_metadata_type type);
};
struct pio_marsio_instance_context {
struct mr_instance *mr_inst_handle;
};
/**
* @brief struct pio_marsio_device_context - marsio device context
* @mr_dev_handle: marsio device handle
* if marsio device receive packets, use mr_dev_handle
* @mr_sendpath_handle: marsio sendpath handle
* if marsio device send packets, both mr_dev_handle and sendpath are required
*/
struct pio_marsio_device_context {
struct mr_vdev *mr_dev_handle;
struct mr_sendpath * mr_sendpath_handle;
struct packet_io_device *pdev;
};
/**
* @brief
*
* @param pinst
* @return int
*/
ssize_t pio_marsio_instance_create(struct packet_io_instance *pinst);
/**
* @brief
*
* @param pinst
*/
void pio_marsio_instance_destroy(struct packet_io_instance *pinst);
/**
* @brief open marsio device
*
* @param pdev: the marsio device's pointer
* pdev->dev_name: the name of marsio device, such as eth1, eth2, ...
* pdev->rxq_num: number of the packet receiving queues for the device
* pdev->txq_num: number of the packet sending queues for the device
*/
ssize_t pio_marsio_device_open(struct packet_io_device *pdev);
/**
* @brief close pcap_live device
*/
ssize_t pio_marsio_device_close(struct packet_io_device *pdev);
/**
* @brief receive packets from device's single rx queue which specified by rxq_id
*
* @param pdev: the marsio device's pointer
* @param rxq_id: the marsio device's rx queue id
* @param pkts: store received packets' pointer array
* @param nr_pkts: number of packets expected to receive
*
* @retval number of packets actually received
*/
ssize_t pio_marsio_device_receive(struct packet_io_device *pdev, uint32_t rxq_id, struct stellar_packet **pkts, size_t nr_pkts);
/**
* @brief send packets by device's single tx queue which specified by txq_id
*
* @param pdev: the marsio device's pointer
* @param txq_id: the marsio device's tx queue id
* @param pkts: store prepare to send packets' pointer array
* @param nr_pkts: number of packets expected to send
*
* @retval if ret<0, means the sending fails; if ret==0 means the sending succeeds
*/
ssize_t pio_marsio_device_send(struct packet_io_device *pdev, uint32_t txq_id, struct stellar_packet **pkts, size_t nr_pkts);
/**
* @brief manually free packet's memory
*
* @param pdev: the marsio device's pointer
* @param qid:
* @param pkts:
* @param nr_pkts:
*/
void pio_marsio_device_pkt_free(struct packet_io_device *pdev, uint32_t qid, struct stellar_packet **pkts, size_t nr_pkts);
char *pio_marsio_device_buff_ctrlzone(struct stellar_packet *p, size_t *ctrlzone_len);
char *pio_marsio_device_buff_mtod(struct stellar_packet *p, size_t *data_len);
#ifdef __cpluscplus
}
#endif
#endif /* _PIO_MARSIO_H_ */