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