1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef IBMVMC_H
14#define IBMVMC_H
15
16#include <linux/types.h>
17#include <linux/cdev.h>
18
19#include <asm/vio.h>
20
21#define IBMVMC_PROTOCOL_VERSION 0x0101
22
23#define MIN_BUF_POOL_SIZE 16
24#define MIN_HMCS 1
25#define MIN_MTU 4096
26#define MAX_BUF_POOL_SIZE 64
27#define MAX_HMCS 2
28#define MAX_MTU (4 * 4096)
29#define DEFAULT_BUF_POOL_SIZE 32
30#define DEFAULT_HMCS 1
31#define DEFAULT_MTU 4096
32#define HMC_ID_LEN 32
33
34#define VMC_INVALID_BUFFER_ID 0xFFFF
35
36
37#define VMC_BASE 0xCC
38#define VMC_IOCTL_SETHMCID _IOW(VMC_BASE, 0x00, unsigned char *)
39#define VMC_IOCTL_QUERY _IOR(VMC_BASE, 0x01, struct ibmvmc_query_struct)
40#define VMC_IOCTL_REQUESTVMC _IOR(VMC_BASE, 0x02, u32)
41
42#define VMC_MSG_CAP 0x01
43#define VMC_MSG_CAP_RESP 0x81
44#define VMC_MSG_OPEN 0x02
45#define VMC_MSG_OPEN_RESP 0x82
46#define VMC_MSG_CLOSE 0x03
47#define VMC_MSG_CLOSE_RESP 0x83
48#define VMC_MSG_ADD_BUF 0x04
49#define VMC_MSG_ADD_BUF_RESP 0x84
50#define VMC_MSG_REM_BUF 0x05
51#define VMC_MSG_REM_BUF_RESP 0x85
52#define VMC_MSG_SIGNAL 0x06
53
54#define VMC_MSG_SUCCESS 0
55#define VMC_MSG_INVALID_HMC_INDEX 1
56#define VMC_MSG_INVALID_BUFFER_ID 2
57#define VMC_MSG_CLOSED_HMC 3
58#define VMC_MSG_INTERFACE_FAILURE 4
59#define VMC_MSG_NO_BUFFER 5
60
61#define VMC_BUF_OWNER_ALPHA 0
62#define VMC_BUF_OWNER_HV 1
63
64enum ibmvmc_states {
65 ibmvmc_state_sched_reset = -1,
66 ibmvmc_state_initial = 0,
67 ibmvmc_state_crqinit = 1,
68 ibmvmc_state_capabilities = 2,
69 ibmvmc_state_ready = 3,
70 ibmvmc_state_failed = 4,
71};
72
73enum ibmhmc_states {
74
75 ibmhmc_state_free = 0,
76
77
78 ibmhmc_state_initial = 1,
79
80
81 ibmhmc_state_opening = 2,
82
83
84 ibmhmc_state_ready = 3,
85
86
87 ibmhmc_state_failed = 4,
88};
89
90struct ibmvmc_buffer {
91 u8 valid;
92 u8 free;
93 u8 owner;
94 u16 id;
95 u32 size;
96 u32 msg_len;
97 dma_addr_t dma_addr_local;
98 dma_addr_t dma_addr_remote;
99 void *real_addr_local;
100};
101
102struct ibmvmc_admin_crq_msg {
103 u8 valid;
104 u8 type;
105 u8 status;
106
107
108
109 u8 rsvd[2];
110 u8 max_hmc;
111 __be16 pool_size;
112
113
114 __be32 max_mtu;
115 __be16 crq_size;
116
117
118
119
120 __be16 version;
121
122
123
124
125};
126
127struct ibmvmc_crq_msg {
128 u8 valid;
129 u8 type;
130 u8 status;
131 union {
132 u8 rsvd;
133 u8 owner;
134 } var1;
135 u8 hmc_session;
136 u8 hmc_index;
137
138
139 union {
140 __be16 rsvd;
141 __be16 buffer_id;
142 } var2;
143 __be32 rsvd;
144 union {
145 __be32 rsvd;
146 __be32 lioba;
147 __be32 msg_len;
148 } var3;
149};
150
151
152struct crq_queue {
153 struct ibmvmc_crq_msg *msgs;
154 int size, cur;
155 dma_addr_t msg_token;
156 spinlock_t lock;
157};
158
159
160struct crq_server_adapter {
161 struct device *dev;
162 struct crq_queue queue;
163 u32 liobn;
164 u32 riobn;
165 struct tasklet_struct work_task;
166 wait_queue_head_t reset_wait_queue;
167 struct task_struct *reset_task;
168};
169
170
171struct ibmvmc_struct {
172 u32 state;
173 u32 max_mtu;
174 u32 max_buffer_pool_size;
175 u32 max_hmc_index;
176 struct crq_server_adapter *adapter;
177 struct cdev cdev;
178 u32 vmc_drc_index;
179};
180
181struct ibmvmc_file_session;
182
183
184struct ibmvmc_hmc {
185 u8 session;
186 u8 index;
187 u32 state;
188 struct crq_server_adapter *adapter;
189 spinlock_t lock;
190 unsigned char hmc_id[HMC_ID_LEN];
191 struct ibmvmc_buffer buffer[MAX_BUF_POOL_SIZE];
192 unsigned short queue_outbound_msgs[MAX_BUF_POOL_SIZE];
193 int queue_head, queue_tail;
194 struct ibmvmc_file_session *file_session;
195};
196
197struct ibmvmc_file_session {
198 struct file *file;
199 struct ibmvmc_hmc *hmc;
200 bool valid;
201};
202
203struct ibmvmc_query_struct {
204 int have_vmc;
205 int state;
206 int vmc_drc_index;
207};
208
209#endif
210