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