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