raw/ifpga/base: add eth group driver
[dpdk.git] / drivers / raw / ifpga_rawdev / base / ifpga_hw.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2018 Intel Corporation
3  */
4
5 #ifndef _IFPGA_HW_H_
6 #define _IFPGA_HW_H_
7
8 #include "ifpga_defines.h"
9 #include "opae_ifpga_hw_api.h"
10 #include "opae_eth_group.h"
11
12 /** List of private feateues */
13 TAILQ_HEAD(ifpga_feature_list, feature);
14
15 enum ifpga_feature_state {
16         IFPGA_FEATURE_UNUSED = 0,
17         IFPGA_FEATURE_ATTACHED,
18 };
19
20 enum feature_type {
21         FEATURE_FME_TYPE = 0,
22         FEATURE_PORT_TYPE,
23 };
24
25 struct feature_irq_ctx {
26         int eventfd;
27         int idx;
28 };
29
30 struct feature {
31         TAILQ_ENTRY(feature)next;
32         enum ifpga_feature_state state;
33         enum feature_type type;
34         const char *name;
35         u64 id;
36         u8 *addr;
37         uint64_t phys_addr;
38         u32 size;
39         int revision;
40         u64 cap;
41         int vfio_dev_fd;
42         struct feature_irq_ctx *ctx;
43         unsigned int ctx_num;
44
45         void *parent;           /* to parent hw data structure */
46
47         struct feature_ops *ops;/* callback to this private feature */
48         unsigned int vec_start;
49         unsigned int vec_cnt;
50 };
51
52 struct feature_ops {
53         int (*init)(struct feature *feature);
54         void (*uinit)(struct feature *feature);
55         int (*get_prop)(struct feature *feature, struct feature_prop *prop);
56         int (*set_prop)(struct feature *feature, struct feature_prop *prop);
57         int (*set_irq)(struct feature *feature, void *irq_set);
58 };
59
60 enum ifpga_fme_state {
61         IFPGA_FME_UNUSED = 0,
62         IFPGA_FME_IMPLEMENTED,
63 };
64
65 struct ifpga_fme_hw {
66         enum ifpga_fme_state state;
67
68         struct ifpga_feature_list feature_list;
69         spinlock_t lock;        /* protect hardware access */
70
71         void *parent;           /* pointer to ifpga_hw */
72
73         /* provied by HEADER feature */
74         u32 port_num;
75         struct uuid bitstream_id;
76         u64 bitstream_md;
77         size_t pr_bandwidth;
78         u32 socket_id;
79         u32 fabric_version_id;
80         u32 cache_size;
81
82         u32 capability;
83
84         void *max10_dev; /* MAX10 device */
85         void *i2c_master; /* I2C Master device */
86         void *eth_dev[MAX_ETH_GROUP_DEVICES];
87         struct opae_reg_region
88                 eth_group_region[MAX_ETH_GROUP_DEVICES];
89         struct ifpga_fme_board_info board_info;
90         int nums_eth_dev;
91         unsigned int nums_acc_region;
92 };
93
94 enum ifpga_port_state {
95         IFPGA_PORT_UNUSED = 0,
96         IFPGA_PORT_ATTACHED,
97         IFPGA_PORT_DETACHED,
98 };
99
100 struct ifpga_port_hw {
101         enum ifpga_port_state state;
102
103         struct ifpga_feature_list feature_list;
104         spinlock_t lock;        /* protect access to hw */
105
106         void *parent;           /* pointer to ifpga_hw */
107
108         int port_id;            /* provied by HEADER feature */
109         struct uuid afu_id;     /* provied by User AFU feature */
110
111         unsigned int disable_count;
112
113         u32 capability;
114         u32 num_umsgs;  /* The number of allocated umsgs */
115         u32 num_uafu_irqs;      /* The number of uafu interrupts */
116         u8 *stp_addr;
117         u32 stp_size;
118 };
119
120 #define AFU_MAX_REGION 1
121
122 struct ifpga_afu_info {
123         struct opae_reg_region region[AFU_MAX_REGION];
124         unsigned int num_regions;
125         unsigned int num_irqs;
126 };
127
128 struct ifpga_hw {
129         struct opae_adapter *adapter;
130         struct opae_adapter_data_pci *pci_data;
131
132         struct ifpga_fme_hw fme;
133         struct ifpga_port_hw port[MAX_FPGA_PORT_NUM];
134 };
135
136 static inline bool is_ifpga_hw_pf(struct ifpga_hw *hw)
137 {
138         return hw->fme.state != IFPGA_FME_UNUSED;
139 }
140
141 static inline bool is_valid_port_id(struct ifpga_hw *hw, u32 port_id)
142 {
143         if (port_id >= MAX_FPGA_PORT_NUM ||
144             hw->port[port_id].state != IFPGA_PORT_ATTACHED)
145                 return false;
146
147         return true;
148 }
149 #endif /* _IFPGA_HW_H_ */