summaryrefslogtreecommitdiff
path: root/drivers/bus/ifpga/rte_bus_ifpga.h
blob: 981bc352df5fa36a8501ecf72c888381e8c7f760 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2010-2018 Intel Corporation
 */

#ifndef _RTE_BUS_IFPGA_H_
#define _RTE_BUS_IFPGA_H_

/**
 * @file
 *
 * RTE Intel FPGA Bus Interface
 */

#ifdef __cplusplus
extern "C" {
#endif

#include <rte_bus.h>
#include <rte_pci.h>

/** Name of Intel FPGA Bus */
#define IFPGA_BUS_NAME ifpga

/* Forward declarations */
struct rte_afu_device;
struct rte_afu_driver;

/** Double linked list of Intel FPGA AFU device. */
TAILQ_HEAD(ifpga_afu_dev_list, rte_afu_device);
/** Double linked list of Intel FPGA AFU device drivers. */
TAILQ_HEAD(ifpga_afu_drv_list, rte_afu_driver);

#define IFPGA_BUS_BITSTREAM_PATH_MAX_LEN 256

struct rte_afu_uuid {
	uint64_t uuid_low;
	uint64_t uuid_high;
} __attribute__ ((packed));

#define IFPGA_BUS_DEV_PORT_MAX 4

/**
 * A structure describing an ID for a AFU driver. Each driver provides a
 * table of these IDs for each device that it supports.
 */
struct rte_afu_id {
	struct rte_afu_uuid uuid;
	int      port; /**< port number */
} __attribute__ ((packed));

/**
 * A structure PR (Partial Reconfiguration) configuration AFU driver.
 */

struct rte_afu_pr_conf {
	struct rte_afu_id afu_id;
	int pr_enable;
	char bs_path[IFPGA_BUS_BITSTREAM_PATH_MAX_LEN];
};

#define AFU_PRI_STR_SIZE (PCI_PRI_STR_SIZE + 8)

/**
 * A structure describing a AFU device.
 */
struct rte_afu_device {
	TAILQ_ENTRY(rte_afu_device) next;       /**< Next in device list. */
	struct rte_device device;               /**< Inherit core device */
	struct rte_rawdev *rawdev;    /**< Point Rawdev */
	struct rte_afu_id id;                   /**< AFU id within FPGA. */
	uint32_t num_region;   /**< number of regions found */
	struct rte_mem_resource mem_resource[PCI_MAX_RESOURCE];
						/**< AFU Memory Resource */
	struct rte_intr_handle intr_handle;     /**< Interrupt handle */
	struct rte_afu_driver *driver;          /**< Associated driver */
	char path[IFPGA_BUS_BITSTREAM_PATH_MAX_LEN];
} __attribute__ ((packed));

/**
 * @internal
 * Helper macro for drivers that need to convert to struct rte_afu_device.
 */
#define RTE_DEV_TO_AFU(ptr) \
	container_of(ptr, struct rte_afu_device, device)

#define RTE_DRV_TO_AFU_CONST(ptr) \
	container_of(ptr, const struct rte_afu_driver, driver)

/**
 * Initialization function for the driver called during FPGA BUS probing.
 */
typedef int (afu_probe_t)(struct rte_afu_device *);

/**
 * Uninitialization function for the driver called during hotplugging.
 */
typedef int (afu_remove_t)(struct rte_afu_device *);

/**
 * A structure describing a AFU device.
 */
struct rte_afu_driver {
	TAILQ_ENTRY(rte_afu_driver) next;       /**< Next afu driver. */
	struct rte_driver driver;               /**< Inherit core driver. */
	afu_probe_t *probe;                     /**< Device Probe function. */
	afu_remove_t *remove;                   /**< Device Remove function. */
	const struct rte_afu_uuid *id_table;    /**< AFU uuid within FPGA. */
};

static inline const char *
rte_ifpga_device_name(const struct rte_afu_device *afu)
{
	if (afu && afu->device.name)
		return afu->device.name;
	return NULL;
}

/**
 * Register a ifpga afu device driver.
 *
 * @param driver
 *   A pointer to a rte_afu_driver structure describing the driver
 *   to be registered.
 */
void rte_ifpga_driver_register(struct rte_afu_driver *driver);

/**
 * Unregister a ifpga afu device driver.
 *
 * @param driver
 *   A pointer to a rte_afu_driver structure describing the driver
 *   to be unregistered.
 */
void rte_ifpga_driver_unregister(struct rte_afu_driver *driver);

#define RTE_PMD_REGISTER_AFU(nm, afudrv)\
RTE_INIT(afudrvinitfn_ ##afudrv);\
static const char *afudrvinit_ ## nm ## _alias;\
static void afudrvinitfn_ ##afudrv(void)\
{\
	(afudrv).driver.name = RTE_STR(nm);\
	(afudrv).driver.alias = afudrvinit_ ## nm ## _alias;\
	rte_ifpga_driver_register(&afudrv);\
} \
RTE_PMD_EXPORT_NAME(nm, __COUNTER__)

#define RTE_PMD_REGISTER_AFU_ALIAS(nm, alias)\
static const char *afudrvinit_ ## nm ## _alias = RTE_STR(alias)

#endif /* _RTE_BUS_IFPGA_H_ */