Commit | Line | Data |
---|---|---|
ab841160 OW |
1 | /* |
2 | * | |
3 | * Intel Management Engine Interface (Intel MEI) Linux driver | |
4 | * Copyright (c) 2003-2011, Intel Corporation. | |
5 | * | |
6 | * This program is free software; you can redistribute it and/or modify it | |
7 | * under the terms and conditions of the GNU General Public License, | |
8 | * version 2, as published by the Free Software Foundation. | |
9 | * | |
10 | * This program is distributed in the hope it will be useful, but WITHOUT | |
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
13 | * more details. | |
14 | * | |
15 | */ | |
16 | ||
17 | #ifndef _MEI_DEV_H_ | |
18 | #define _MEI_DEV_H_ | |
19 | ||
20 | #include <linux/types.h> | |
21 | #include "mei.h" | |
22 | #include "hw.h" | |
23 | ||
24 | /* | |
25 | * MEI Char Driver Minors | |
26 | */ | |
27 | #define MEI_MINORS_BASE 1 | |
28 | #define MEI_MINORS_COUNT 1 | |
29 | #define MEI_MINOR_NUMBER 1 | |
30 | ||
31 | /* | |
32 | * watch dog definition | |
33 | */ | |
34 | #define MEI_WATCHDOG_DATA_SIZE 16 | |
35 | #define MEI_START_WD_DATA_SIZE 20 | |
36 | #define MEI_WD_PARAMS_SIZE 4 | |
37 | #define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0) | |
38 | ||
39 | /* | |
40 | * AMTHI Client UUID | |
41 | */ | |
42 | extern const uuid_le mei_amthi_guid; | |
43 | ||
44 | /* | |
45 | * Watchdog Client UUID | |
46 | */ | |
47 | extern const uuid_le mei_wd_guid; | |
48 | ||
49 | /* | |
50 | * Watchdog independence state message | |
51 | */ | |
52 | extern const u8 mei_wd_state_independence_msg[3][4]; | |
53 | ||
54 | /* | |
55 | * Number of File descriptors/handles | |
56 | * that can be opened to the driver. | |
57 | * | |
58 | * Limit to 253: 255 Total Clients | |
59 | * minus internal client for AMTHI | |
60 | * minus internal client for Watchdog | |
61 | */ | |
62 | #define MEI_MAX_OPEN_HANDLE_COUNT 253 | |
63 | ||
64 | /* | |
65 | * Number of queue lists used by this driver | |
66 | */ | |
67 | #define MEI_IO_LISTS_NUMBER 7 | |
68 | ||
69 | /* | |
70 | * Number of Maximum MEI Clients | |
71 | */ | |
72 | #define MEI_CLIENTS_MAX 255 | |
73 | ||
74 | /* File state */ | |
75 | enum file_state { | |
76 | MEI_FILE_INITIALIZING = 0, | |
77 | MEI_FILE_CONNECTING, | |
78 | MEI_FILE_CONNECTED, | |
79 | MEI_FILE_DISCONNECTING, | |
80 | MEI_FILE_DISCONNECTED | |
81 | }; | |
82 | ||
83 | /* MEI device states */ | |
84 | enum mei_states { | |
85 | MEI_INITIALIZING = 0, | |
86 | MEI_INIT_CLIENTS, | |
87 | MEI_ENABLED, | |
88 | MEI_RESETING, | |
89 | MEI_DISABLED, | |
90 | MEI_RECOVERING_FROM_RESET, | |
91 | MEI_POWER_DOWN, | |
92 | MEI_POWER_UP | |
93 | }; | |
94 | ||
95 | /* init clients states*/ | |
96 | enum mei_init_clients_states { | |
97 | MEI_START_MESSAGE = 0, | |
98 | MEI_ENUM_CLIENTS_MESSAGE, | |
99 | MEI_CLIENT_PROPERTIES_MESSAGE | |
100 | }; | |
101 | ||
102 | enum iamthif_states { | |
103 | MEI_IAMTHIF_IDLE, | |
104 | MEI_IAMTHIF_WRITING, | |
105 | MEI_IAMTHIF_FLOW_CONTROL, | |
106 | MEI_IAMTHIF_READING, | |
107 | MEI_IAMTHIF_READ_COMPLETE | |
108 | }; | |
109 | ||
110 | enum mei_file_transaction_states { | |
111 | MEI_IDLE, | |
112 | MEI_WRITING, | |
113 | MEI_WRITE_COMPLETE, | |
114 | MEI_FLOW_CONTROL, | |
115 | MEI_READING, | |
116 | MEI_READ_COMPLETE | |
117 | }; | |
118 | ||
119 | /* MEI CB */ | |
120 | enum mei_cb_major_types { | |
121 | MEI_READ = 0, | |
122 | MEI_WRITE, | |
123 | MEI_IOCTL, | |
124 | MEI_OPEN, | |
125 | MEI_CLOSE | |
126 | }; | |
127 | ||
128 | /* | |
129 | * Intel MEI message data struct | |
130 | */ | |
131 | struct mei_message_data { | |
132 | u32 size; | |
133 | char *data; | |
134 | } __packed; | |
135 | ||
136 | ||
137 | struct mei_cl_cb { | |
138 | struct list_head cb_list; | |
139 | enum mei_cb_major_types major_file_operations; | |
140 | void *file_private; | |
141 | struct mei_message_data request_buffer; | |
142 | struct mei_message_data response_buffer; | |
143 | unsigned long information; | |
144 | unsigned long read_time; | |
145 | struct file *file_object; | |
146 | }; | |
147 | ||
148 | /* MEI client instance carried as file->pirvate_data*/ | |
149 | struct mei_cl { | |
150 | struct list_head link; | |
151 | struct mei_device *dev; | |
152 | enum file_state state; | |
153 | wait_queue_head_t tx_wait; | |
154 | wait_queue_head_t rx_wait; | |
155 | wait_queue_head_t wait; | |
156 | int read_pending; | |
157 | int status; | |
158 | /* ID of client connected */ | |
159 | u8 host_client_id; | |
160 | u8 me_client_id; | |
161 | u8 mei_flow_ctrl_creds; | |
162 | u8 timer_count; | |
163 | enum mei_file_transaction_states reading_state; | |
164 | enum mei_file_transaction_states writing_state; | |
165 | int sm_state; | |
166 | struct mei_cl_cb *read_cb; | |
167 | }; | |
168 | ||
169 | struct mei_io_list { | |
170 | struct mei_cl_cb mei_cb; | |
171 | int status; | |
ab841160 OW |
172 | }; |
173 | ||
174 | /* MEI private device struct */ | |
175 | struct mei_device { | |
176 | struct pci_dev *pdev; /* pointer to pci device struct */ | |
177 | /* | |
178 | * lists of queues | |
179 | */ | |
180 | /* array of pointers to aio lists */ | |
181 | struct mei_io_list *io_list_array[MEI_IO_LISTS_NUMBER]; | |
182 | struct mei_io_list read_list; /* driver read queue */ | |
183 | struct mei_io_list write_list; /* driver write queue */ | |
184 | struct mei_io_list write_waiting_list; /* write waiting queue */ | |
185 | struct mei_io_list ctrl_wr_list; /* managed write IOCTL list */ | |
186 | struct mei_io_list ctrl_rd_list; /* managed read IOCTL list */ | |
187 | struct mei_io_list amthi_cmd_list; /* amthi list for cmd waiting */ | |
188 | ||
189 | /* driver managed amthi list for reading completed amthi cmd data */ | |
190 | struct mei_io_list amthi_read_complete_list; | |
191 | /* | |
192 | * list of files | |
193 | */ | |
194 | struct list_head file_list; | |
eb9af0ac | 195 | long open_handle_count; |
ab841160 OW |
196 | /* |
197 | * memory of device | |
198 | */ | |
199 | unsigned int mem_base; | |
200 | unsigned int mem_length; | |
201 | void __iomem *mem_addr; | |
202 | /* | |
203 | * lock for the device | |
204 | */ | |
205 | struct mutex device_lock; /* device lock */ | |
ab841160 | 206 | struct delayed_work wd_work; /* watch dog deleye work */ |
eb9af0ac | 207 | bool recvd_msg; |
ab841160 OW |
208 | /* |
209 | * hw states of host and fw(ME) | |
210 | */ | |
211 | u32 host_hw_state; | |
212 | u32 me_hw_state; | |
213 | /* | |
214 | * waiting queue for receive message from FW | |
215 | */ | |
216 | wait_queue_head_t wait_recvd_msg; | |
217 | wait_queue_head_t wait_stop_wd; | |
218 | ||
219 | /* | |
220 | * mei device states | |
221 | */ | |
222 | enum mei_states mei_state; | |
223 | enum mei_init_clients_states init_clients_state; | |
224 | u16 init_clients_timer; | |
eb9af0ac TW |
225 | bool stop; |
226 | bool need_reset; | |
ab841160 OW |
227 | |
228 | u32 extra_write_index; | |
229 | u32 rd_msg_buf[128]; /* used for control messages */ | |
230 | u32 wr_msg_buf[128]; /* used for control messages */ | |
231 | u32 ext_msg_buf[8]; /* for control responses */ | |
232 | u32 rd_msg_hdr; | |
233 | ||
234 | struct hbm_version version; | |
235 | ||
ab841160 OW |
236 | struct mei_me_client *me_clients; /* Note: memory has to be allocated */ |
237 | DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX); | |
238 | DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX); | |
cf9673da | 239 | u8 me_clients_num; |
ab841160 OW |
240 | u8 me_client_presentation_num; |
241 | u8 me_client_index; | |
eb9af0ac | 242 | bool mei_host_buffer_is_empty; |
ab841160 | 243 | |
eb9af0ac TW |
244 | struct mei_cl wd_cl; |
245 | bool wd_pending; | |
246 | bool wd_stopped; | |
247 | bool wd_bypass; /* if false, don't refresh watchdog ME client */ | |
ab841160 | 248 | u16 wd_timeout; /* seconds ((wd_data[1] << 8) + wd_data[0]) */ |
eb9af0ac | 249 | u16 wd_due_counter; |
ab841160 OW |
250 | unsigned char wd_data[MEI_START_WD_DATA_SIZE]; |
251 | ||
252 | ||
ab841160 OW |
253 | |
254 | struct file *iamthif_file_object; | |
255 | struct mei_cl iamthif_cl; | |
eb9af0ac | 256 | struct mei_cl_cb *iamthif_current_cb; |
ab841160 OW |
257 | int iamthif_mtu; |
258 | unsigned long iamthif_timer; | |
259 | u32 iamthif_stall_timer; | |
260 | unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */ | |
261 | u32 iamthif_msg_buf_size; | |
262 | u32 iamthif_msg_buf_index; | |
ab841160 | 263 | enum iamthif_states iamthif_state; |
eb9af0ac TW |
264 | bool iamthif_flow_control_pending; |
265 | bool iamthif_ioctl; | |
266 | bool iamthif_canceled; | |
ab841160 OW |
267 | }; |
268 | ||
269 | ||
270 | /* | |
271 | * mei init function prototypes | |
272 | */ | |
c95efb74 | 273 | struct mei_device *mei_device_init(struct pci_dev *pdev); |
ab841160 OW |
274 | void mei_reset(struct mei_device *dev, int interrupts); |
275 | int mei_hw_init(struct mei_device *dev); | |
276 | int mei_task_initialize_clients(void *data); | |
277 | int mei_initialize_clients(struct mei_device *dev); | |
ab841160 | 278 | int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl); |
106fb49f | 279 | void mei_initialize_list(struct mei_io_list *list, struct mei_device *dev); |
ab841160 OW |
280 | void mei_flush_list(struct mei_io_list *list, struct mei_cl *cl); |
281 | void mei_flush_queues(struct mei_device *dev, struct mei_cl *cl); | |
106fb49f | 282 | void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id); |
c95efb74 TW |
283 | void mei_host_init_iamthif(struct mei_device *dev); |
284 | void mei_allocate_me_clients_storage(struct mei_device *dev); | |
ab841160 | 285 | |
ab841160 OW |
286 | |
287 | u8 mei_find_me_client_update_filext(struct mei_device *dev, | |
288 | struct mei_cl *priv, | |
289 | const uuid_le *cguid, u8 client_id); | |
290 | ||
291 | /* | |
c95efb74 TW |
292 | * MEI ME Client Functions |
293 | */ | |
294 | ||
295 | struct mei_cl *mei_cl_allocate(struct mei_device *dev); | |
296 | void mei_cl_init(struct mei_cl *priv, struct mei_device *dev); | |
297 | ||
298 | ||
299 | /* | |
300 | * MEI Host Client Functions | |
301 | */ | |
302 | void mei_host_start_message(struct mei_device *dev); | |
303 | void mei_host_enum_clients_message(struct mei_device *dev); | |
304 | void mei_host_client_properties(struct mei_device *dev); | |
305 | ||
306 | /* | |
307 | * MEI interrupt functions prototype | |
ab841160 OW |
308 | */ |
309 | irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id); | |
c95efb74 | 310 | irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id); |
ab841160 OW |
311 | void mei_wd_timer(struct work_struct *work); |
312 | ||
313 | /* | |
c95efb74 | 314 | * MEI input output function prototype |
ab841160 OW |
315 | */ |
316 | int mei_ioctl_connect_client(struct file *file, | |
317 | struct mei_connect_client_data *data); | |
318 | ||
319 | int mei_start_read(struct mei_device *dev, struct mei_cl *cl); | |
320 | ||
321 | int amthi_write(struct mei_device *dev, struct mei_cl_cb *priv_cb); | |
322 | ||
323 | int amthi_read(struct mei_device *dev, struct file *file, | |
324 | char __user *ubuf, size_t length, loff_t *offset); | |
325 | ||
326 | struct mei_cl_cb *find_amthi_read_list_entry(struct mei_device *dev, | |
327 | struct file *file); | |
328 | ||
c95efb74 | 329 | void mei_run_next_iamthif_cmd(struct mei_device *dev); |
ab841160 OW |
330 | |
331 | void mei_free_cb_private(struct mei_cl_cb *priv_cb); | |
332 | ||
333 | int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid); | |
334 | ||
335 | /* | |
336 | * Register Access Function | |
337 | */ | |
338 | ||
339 | /** | |
340 | * mei_reg_read - Reads 32bit data from the mei device | |
341 | * | |
342 | * @dev: the device structure | |
343 | * @offset: offset from which to read the data | |
344 | * | |
345 | * returns the byte read. | |
346 | */ | |
106fb49f | 347 | static inline u32 mei_reg_read(struct mei_device *dev, unsigned long offset) |
ab841160 OW |
348 | { |
349 | return ioread32(dev->mem_addr + offset); | |
350 | } | |
351 | ||
352 | /** | |
353 | * mei_reg_write - Writes 32bit data to the mei device | |
354 | * | |
355 | * @dev: the device structure | |
356 | * @offset: offset from which to write the data | |
357 | * @value: the byte to write | |
358 | */ | |
359 | static inline void mei_reg_write(struct mei_device *dev, | |
360 | unsigned long offset, u32 value) | |
361 | { | |
362 | iowrite32(value, dev->mem_addr + offset); | |
363 | } | |
364 | ||
365 | /** | |
366 | * mei_hcsr_read - Reads 32bit data from the host CSR | |
367 | * | |
368 | * @dev: the device structure | |
369 | * | |
370 | * returns the byte read. | |
371 | */ | |
372 | static inline u32 mei_hcsr_read(struct mei_device *dev) | |
373 | { | |
374 | return mei_reg_read(dev, H_CSR); | |
375 | } | |
376 | ||
377 | /** | |
378 | * mei_mecsr_read - Reads 32bit data from the ME CSR | |
379 | * | |
380 | * @dev: the device structure | |
381 | * | |
382 | * returns ME_CSR_HA register value (u32) | |
383 | */ | |
384 | static inline u32 mei_mecsr_read(struct mei_device *dev) | |
385 | { | |
386 | return mei_reg_read(dev, ME_CSR_HA); | |
387 | } | |
388 | ||
389 | /** | |
390 | * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register | |
391 | * | |
392 | * @dev: the device structure | |
393 | * | |
394 | * returns ME_CB_RW register value (u32) | |
395 | */ | |
396 | static inline u32 mei_mecbrw_read(struct mei_device *dev) | |
397 | { | |
398 | return mei_reg_read(dev, ME_CB_RW); | |
399 | } | |
400 | ||
401 | ||
402 | /* | |
403 | * mei interface function prototypes | |
404 | */ | |
405 | void mei_hcsr_set(struct mei_device *dev); | |
406 | void mei_csr_clear_his(struct mei_device *dev); | |
407 | ||
408 | void mei_enable_interrupts(struct mei_device *dev); | |
409 | void mei_disable_interrupts(struct mei_device *dev); | |
410 | ||
411 | /** | |
412 | * mei_fe_same_id - tells if file private data have same id | |
413 | * | |
414 | * @fe1: private data of 1. file object | |
415 | * @fe2: private data of 2. file object | |
416 | * | |
417 | * returns !=0 - if ids are the same, 0 - if differ. | |
418 | */ | |
419 | static inline int mei_fe_same_id(const struct mei_cl *fe1, | |
420 | const struct mei_cl *fe2) | |
421 | { | |
422 | return ((fe1->host_client_id == fe2->host_client_id) && | |
423 | (fe1->me_client_id == fe2->me_client_id)); | |
424 | } | |
425 | ||
426 | #endif |