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