]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - drivers/misc/mei/mei_dev.h
mei: simplify write complete loop in irq handler
[mirror_ubuntu-eoan-kernel.git] / drivers / misc / mei / mei_dev.h
CommitLineData
ab841160
OW
1/*
2 *
3 * Intel Management Engine Interface (Intel MEI) Linux driver
733ba91c 4 * Copyright (c) 2003-2012, Intel Corporation.
ab841160
OW
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>
9ce178e5 21#include <linux/watchdog.h>
744f0f2f 22#include <linux/poll.h>
4f3afe1d 23#include <linux/mei.h>
ab841160
OW
24#include "hw.h"
25
ab841160
OW
26/*
27 * watch dog definition
28 */
248ffdf7
TW
29#define MEI_WD_HDR_SIZE 4
30#define MEI_WD_STOP_MSG_SIZE MEI_WD_HDR_SIZE
31#define MEI_WD_START_MSG_SIZE (MEI_WD_HDR_SIZE + 16)
32
33#define MEI_WD_DEFAULT_TIMEOUT 120 /* seconds */
34#define MEI_WD_MIN_TIMEOUT 120 /* seconds */
35#define MEI_WD_MAX_TIMEOUT 65535 /* seconds */
36
c216fdeb
TW
37#define MEI_WD_STOP_TIMEOUT 10 /* msecs */
38
ab841160
OW
39#define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0)
40
edf1eed4
TW
41#define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32))
42
9ce178e5 43
ab841160
OW
44/*
45 * AMTHI Client UUID
46 */
47extern const uuid_le mei_amthi_guid;
48
49/*
50 * Watchdog Client UUID
51 */
52extern const uuid_le mei_wd_guid;
53
54/*
55 * Watchdog independence state message
56 */
57extern const u8 mei_wd_state_independence_msg[3][4];
58
1e2776c3
TW
59/*
60 * Number of Maximum MEI Clients
61 */
62#define MEI_CLIENTS_MAX 256
63
ab841160
OW
64/*
65 * Number of File descriptors/handles
66 * that can be opened to the driver.
67 *
1e2776c3
TW
68 * Limit to 253: 256 Total Clients
69 * minus internal client for MEI Bus Messags
ab841160
OW
70 * minus internal client for AMTHI
71 * minus internal client for Watchdog
72 */
1e2776c3 73#define MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 3)
ab841160 74
ab841160
OW
75
76/* File state */
77enum file_state {
78 MEI_FILE_INITIALIZING = 0,
79 MEI_FILE_CONNECTING,
80 MEI_FILE_CONNECTED,
81 MEI_FILE_DISCONNECTING,
82 MEI_FILE_DISCONNECTED
83};
84
85/* MEI device states */
b210d750
TW
86enum mei_dev_state {
87 MEI_DEV_INITIALIZING = 0,
88 MEI_DEV_INIT_CLIENTS,
89 MEI_DEV_ENABLED,
90 MEI_DEV_RESETING,
91 MEI_DEV_DISABLED,
92 MEI_DEV_RECOVERING_FROM_RESET,
93 MEI_DEV_POWER_DOWN,
94 MEI_DEV_POWER_UP
ab841160
OW
95};
96
b210d750
TW
97const char *mei_dev_state_str(int state);
98
5f9092f3 99/* init clients states*/
ab841160
OW
100enum mei_init_clients_states {
101 MEI_START_MESSAGE = 0,
102 MEI_ENUM_CLIENTS_MESSAGE,
103 MEI_CLIENT_PROPERTIES_MESSAGE
104};
105
106enum iamthif_states {
107 MEI_IAMTHIF_IDLE,
108 MEI_IAMTHIF_WRITING,
109 MEI_IAMTHIF_FLOW_CONTROL,
110 MEI_IAMTHIF_READING,
111 MEI_IAMTHIF_READ_COMPLETE
112};
113
114enum mei_file_transaction_states {
115 MEI_IDLE,
116 MEI_WRITING,
117 MEI_WRITE_COMPLETE,
118 MEI_FLOW_CONTROL,
119 MEI_READING,
120 MEI_READ_COMPLETE
121};
122
c216fdeb
TW
123enum mei_wd_states {
124 MEI_WD_IDLE,
125 MEI_WD_RUNNING,
126 MEI_WD_STOPPING,
127};
128
4b8960b4
TW
129/**
130 * enum mei_cb_file_ops - file operation associated with the callback
131 * @MEI_FOP_READ - read
132 * @MEI_FOP_WRITE - write
133 * @MEI_FOP_IOCTL - ioctl
134 * @MEI_FOP_OPEN - open
135 * @MEI_FOP_CLOSE - close
136 */
137enum mei_cb_file_ops {
138 MEI_FOP_READ = 0,
139 MEI_FOP_WRITE,
140 MEI_FOP_IOCTL,
141 MEI_FOP_OPEN,
142 MEI_FOP_CLOSE
ab841160
OW
143};
144
145/*
146 * Intel MEI message data struct
147 */
148struct mei_message_data {
149 u32 size;
edf1eed4 150 unsigned char *data;
f060939d 151};
ab841160
OW
152
153
db3ed431
TW
154struct mei_cl;
155
4b8960b4 156/**
db3ed431
TW
157 * struct mei_cl_cb - file operation callback structure
158 *
159 * @cl - file client who is running this operation
4b8960b4 160 * @fop_type - file operation type
db3ed431 161 */
ab841160 162struct mei_cl_cb {
fb601adb 163 struct list_head list;
db3ed431 164 struct mei_cl *cl;
4b8960b4 165 enum mei_cb_file_ops fop_type;
ab841160
OW
166 struct mei_message_data request_buffer;
167 struct mei_message_data response_buffer;
ebb108ef 168 unsigned long buf_idx;
ab841160
OW
169 unsigned long read_time;
170 struct file *file_object;
171};
172
173/* MEI client instance carried as file->pirvate_data*/
174struct mei_cl {
175 struct list_head link;
176 struct mei_device *dev;
177 enum file_state state;
178 wait_queue_head_t tx_wait;
179 wait_queue_head_t rx_wait;
180 wait_queue_head_t wait;
181 int read_pending;
182 int status;
183 /* ID of client connected */
184 u8 host_client_id;
185 u8 me_client_id;
186 u8 mei_flow_ctrl_creds;
187 u8 timer_count;
188 enum mei_file_transaction_states reading_state;
189 enum mei_file_transaction_states writing_state;
190 int sm_state;
191 struct mei_cl_cb *read_cb;
192};
193
24aadc80 194/**
5fb54fb4 195 * struct mei_device - MEI private device struct
24aadc80 196 * @hbuf_depth - depth of host(write) buffer
5fb54fb4 197 * @wr_ext_msg - buffer for hbm control responses (set in read cycle)
24aadc80 198 */
ab841160
OW
199struct mei_device {
200 struct pci_dev *pdev; /* pointer to pci device struct */
201 /*
202 * lists of queues
203 */
e773efc4 204 /* array of pointers to aio lists */
fb601adb
TW
205 struct mei_cl_cb read_list; /* driver read queue */
206 struct mei_cl_cb write_list; /* driver write queue */
207 struct mei_cl_cb write_waiting_list; /* write waiting queue */
208 struct mei_cl_cb ctrl_wr_list; /* managed write IOCTL list */
209 struct mei_cl_cb ctrl_rd_list; /* managed read IOCTL list */
ab841160 210
ab841160
OW
211 /*
212 * list of files
213 */
214 struct list_head file_list;
eb9af0ac 215 long open_handle_count;
ab841160
OW
216 /*
217 * memory of device
218 */
219 unsigned int mem_base;
220 unsigned int mem_length;
221 void __iomem *mem_addr;
222 /*
223 * lock for the device
224 */
225 struct mutex device_lock; /* device lock */
a61c6530 226 struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */
eb9af0ac 227 bool recvd_msg;
ab841160
OW
228 /*
229 * hw states of host and fw(ME)
230 */
231 u32 host_hw_state;
232 u32 me_hw_state;
24aadc80 233 u8 hbuf_depth;
ab841160
OW
234 /*
235 * waiting queue for receive message from FW
236 */
237 wait_queue_head_t wait_recvd_msg;
238 wait_queue_head_t wait_stop_wd;
239
240 /*
241 * mei device states
242 */
b210d750 243 enum mei_dev_state dev_state;
ab841160
OW
244 enum mei_init_clients_states init_clients_state;
245 u16 init_clients_timer;
eb9af0ac 246 bool need_reset;
ab841160 247
edf1eed4 248 unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */
ab841160 249 u32 rd_msg_hdr;
5fb54fb4
TW
250 u32 wr_msg_buf[128]; /* used for control messages */
251 struct {
252 struct mei_msg_hdr hdr;
253 unsigned char data[4]; /* All HBM messages are 4 bytes */
254 } wr_ext_msg; /* for control responses */
ab841160
OW
255
256 struct hbm_version version;
257
ab841160
OW
258 struct mei_me_client *me_clients; /* Note: memory has to be allocated */
259 DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
260 DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
cf9673da 261 u8 me_clients_num;
ab841160
OW
262 u8 me_client_presentation_num;
263 u8 me_client_index;
eb9af0ac 264 bool mei_host_buffer_is_empty;
ab841160 265
eb9af0ac 266 struct mei_cl wd_cl;
c216fdeb 267 enum mei_wd_states wd_state;
eb9af0ac 268 bool wd_pending;
c216fdeb 269 u16 wd_timeout;
248ffdf7 270 unsigned char wd_data[MEI_WD_START_MSG_SIZE];
ab841160
OW
271
272
e773efc4
TW
273 /* amthif list for cmd waiting */
274 struct mei_cl_cb amthif_cmd_list;
275 /* driver managed amthif list for reading completed amthif cmd data */
276 struct mei_cl_cb amthif_rd_complete_list;
ab841160
OW
277 struct file *iamthif_file_object;
278 struct mei_cl iamthif_cl;
eb9af0ac 279 struct mei_cl_cb *iamthif_current_cb;
ab841160
OW
280 int iamthif_mtu;
281 unsigned long iamthif_timer;
282 u32 iamthif_stall_timer;
283 unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */
284 u32 iamthif_msg_buf_size;
285 u32 iamthif_msg_buf_index;
ab841160 286 enum iamthif_states iamthif_state;
eb9af0ac
TW
287 bool iamthif_flow_control_pending;
288 bool iamthif_ioctl;
289 bool iamthif_canceled;
ab841160
OW
290};
291
3870c320
TW
292static inline unsigned long mei_secs_to_jiffies(unsigned long sec)
293{
294 return msecs_to_jiffies(sec * MSEC_PER_SEC);
295}
296
ab841160
OW
297
298/*
299 * mei init function prototypes
300 */
c95efb74 301struct mei_device *mei_device_init(struct pci_dev *pdev);
ab841160
OW
302void mei_reset(struct mei_device *dev, int interrupts);
303int mei_hw_init(struct mei_device *dev);
304int mei_task_initialize_clients(void *data);
305int mei_initialize_clients(struct mei_device *dev);
ab841160 306int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
c95efb74 307void mei_allocate_me_clients_storage(struct mei_device *dev);
ab841160 308
ab841160 309
ff8b2f4e 310int mei_me_cl_link(struct mei_device *dev, struct mei_cl *cl,
07b509b7 311 const uuid_le *cguid, u8 host_client_id);
ff8b2f4e 312void mei_me_cl_unlink(struct mei_device *dev, struct mei_cl *cl);
07b509b7
TW
313int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid);
314int mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
ab841160 315
0288c7c9 316/*
601a1efa 317 * MEI IO Functions
0288c7c9 318 */
664df38b 319struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp);
601a1efa 320void mei_io_cb_free(struct mei_cl_cb *priv_cb);
664df38b
TW
321int mei_io_cb_alloc_req_buf(struct mei_cl_cb *cb, size_t length);
322int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length);
323
601a1efa 324
fb601adb
TW
325/**
326 * mei_io_list_init - Sets up a queue list.
327 *
328 * @list: An instance cl callback structure
329 */
330static inline void mei_io_list_init(struct mei_cl_cb *list)
331{
332 INIT_LIST_HEAD(&list->list);
333}
334void mei_io_list_flush(struct mei_cl_cb *list, struct mei_cl *cl);
0288c7c9 335
ab841160 336/*
c95efb74
TW
337 * MEI ME Client Functions
338 */
339
340struct mei_cl *mei_cl_allocate(struct mei_device *dev);
0288c7c9
TW
341void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);
342int mei_cl_flush_queues(struct mei_cl *cl);
343/**
344 * mei_cl_cmp_id - tells if file private data have same id
345 *
346 * @fe1: private data of 1. file object
347 * @fe2: private data of 2. file object
348 *
349 * returns true - if ids are the same and not NULL
350 */
351static inline bool mei_cl_cmp_id(const struct mei_cl *cl1,
352 const struct mei_cl *cl2)
353{
354 return cl1 && cl2 &&
355 (cl1->host_client_id == cl2->host_client_id) &&
356 (cl1->me_client_id == cl2->me_client_id);
357}
358
c95efb74
TW
359
360
361/*
362 * MEI Host Client Functions
363 */
364void mei_host_start_message(struct mei_device *dev);
365void mei_host_enum_clients_message(struct mei_device *dev);
abc51b6d 366int mei_host_client_properties(struct mei_device *dev);
c95efb74
TW
367
368/*
369 * MEI interrupt functions prototype
ab841160
OW
370 */
371irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id);
c95efb74 372irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id);
a61c6530 373void mei_timer(struct work_struct *work);
ab841160
OW
374
375/*
c95efb74 376 * MEI input output function prototype
ab841160
OW
377 */
378int mei_ioctl_connect_client(struct file *file,
379 struct mei_connect_client_data *data);
380
381int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
382
ab841160 383
19838fb8
TW
384/*
385 * AMTHIF - AMT Host Interface Functions
386 */
387void mei_amthif_reset_params(struct mei_device *dev);
388
389void mei_amthif_host_init(struct mei_device *dev);
390
391int mei_amthif_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
392
393int mei_amthif_read(struct mei_device *dev, struct file *file,
744f0f2f
TW
394 char __user *ubuf, size_t length, loff_t *offset);
395
396unsigned int mei_amthif_poll(struct mei_device *dev,
397 struct file *file, poll_table *wait);
ab841160 398
a562d5c2
TW
399int mei_amthif_release(struct mei_device *dev, struct file *file);
400
19838fb8 401struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev,
ab841160
OW
402 struct file *file);
403
19838fb8
TW
404void mei_amthif_run_next_cmd(struct mei_device *dev);
405
406
407int mei_amthif_read_message(struct mei_cl_cb *complete_list,
408 struct mei_device *dev, struct mei_msg_hdr *mei_hdr);
ab841160 409
24c656e5
TW
410int mei_amthif_irq_write_complete(struct mei_device *dev, s32 *slots,
411 struct mei_cl_cb *cb, struct mei_cl_cb *cmpl_list);
ab841160 412
19838fb8
TW
413void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb);
414int mei_amthif_irq_read_message(struct mei_cl_cb *complete_list,
415 struct mei_device *dev, struct mei_msg_hdr *mei_hdr);
416int mei_amthif_irq_read(struct mei_device *dev, s32 *slots);
ab841160
OW
417
418/*
419 * Register Access Function
420 */
421
422/**
423 * mei_reg_read - Reads 32bit data from the mei device
424 *
425 * @dev: the device structure
426 * @offset: offset from which to read the data
427 *
92eb4013 428 * returns register value (u32)
ab841160 429 */
4a0d6a74
TW
430static inline u32 mei_reg_read(const struct mei_device *dev,
431 unsigned long offset)
ab841160
OW
432{
433 return ioread32(dev->mem_addr + offset);
434}
435
436/**
437 * mei_reg_write - Writes 32bit data to the mei device
438 *
439 * @dev: the device structure
440 * @offset: offset from which to write the data
92eb4013 441 * @value: register value to write (u32)
ab841160 442 */
4a0d6a74
TW
443static inline void mei_reg_write(const struct mei_device *dev,
444 unsigned long offset, u32 value)
ab841160
OW
445{
446 iowrite32(value, dev->mem_addr + offset);
447}
448
449/**
450 * mei_hcsr_read - Reads 32bit data from the host CSR
451 *
452 * @dev: the device structure
453 *
454 * returns the byte read.
455 */
4a0d6a74 456static inline u32 mei_hcsr_read(const struct mei_device *dev)
ab841160
OW
457{
458 return mei_reg_read(dev, H_CSR);
459}
460
461/**
462 * mei_mecsr_read - Reads 32bit data from the ME CSR
463 *
464 * @dev: the device structure
465 *
466 * returns ME_CSR_HA register value (u32)
467 */
4a0d6a74 468static inline u32 mei_mecsr_read(const struct mei_device *dev)
ab841160
OW
469{
470 return mei_reg_read(dev, ME_CSR_HA);
471}
472
473/**
474 * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register
475 *
476 * @dev: the device structure
477 *
478 * returns ME_CB_RW register value (u32)
479 */
4a0d6a74 480static inline u32 mei_mecbrw_read(const struct mei_device *dev)
ab841160
OW
481{
482 return mei_reg_read(dev, ME_CB_RW);
483}
484
485
486/*
487 * mei interface function prototypes
488 */
489void mei_hcsr_set(struct mei_device *dev);
490void mei_csr_clear_his(struct mei_device *dev);
491
492void mei_enable_interrupts(struct mei_device *dev);
493void mei_disable_interrupts(struct mei_device *dev);
494
5bd64714
TW
495static inline struct mei_msg_hdr *mei_hbm_hdr(u32 *buf, size_t length)
496{
497 struct mei_msg_hdr *hdr = (struct mei_msg_hdr *)buf;
498 hdr->host_addr = 0;
499 hdr->me_addr = 0;
500 hdr->length = length;
501 hdr->msg_complete = 1;
502 hdr->reserved = 0;
503 return hdr;
504}
505
ab841160 506#endif