blob: adb35fb9281c4ae82ba2a617c062293faa2b2bca [file] [log] [blame]
Oren Weilab841162011-05-15 13:43:41 +03001/*
2 *
3 * Intel Management Engine Interface (Intel MEI) Linux driver
Tomas Winkler733ba912012-02-09 19:25:53 +02004 * Copyright (c) 2003-2012, Intel Corporation.
Oren Weilab841162011-05-15 13:43:41 +03005 *
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>
Oren Weil9ce178e2011-09-07 09:03:09 +030021#include <linux/watchdog.h>
Tomas Winkler4f3afe12012-05-09 16:38:59 +030022#include <linux/mei.h>
Oren Weilab841162011-05-15 13:43:41 +030023#include "hw.h"
24
25/*
Oren Weilab841162011-05-15 13:43:41 +030026 * watch dog definition
27 */
Tomas Winkler248ffdf2012-08-16 19:39:42 +030028#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
Tomas Winklerc216fde2012-08-16 19:39:43 +030036#define MEI_WD_STOP_TIMEOUT 10 /* msecs */
37
Oren Weilab841162011-05-15 13:43:41 +030038#define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0)
39
Tomas Winkleredf1eed2012-02-09 19:25:54 +020040#define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32))
41
Oren Weil9ce178e2011-09-07 09:03:09 +030042
43/*
Oren Weilab841162011-05-15 13:43:41 +030044 * 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
58/*
Tomas Winkler1e2776c2012-08-24 00:35:58 +030059 * Number of Maximum MEI Clients
60 */
61#define MEI_CLIENTS_MAX 256
62
63/*
Oren Weilab841162011-05-15 13:43:41 +030064 * Number of File descriptors/handles
65 * that can be opened to the driver.
66 *
Tomas Winkler1e2776c2012-08-24 00:35:58 +030067 * Limit to 253: 256 Total Clients
68 * minus internal client for MEI Bus Messags
Oren Weilab841162011-05-15 13:43:41 +030069 * minus internal client for AMTHI
70 * minus internal client for Watchdog
71 */
Tomas Winkler1e2776c2012-08-24 00:35:58 +030072#define MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 3)
Oren Weilab841162011-05-15 13:43:41 +030073
Oren Weilab841162011-05-15 13:43:41 +030074
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 */
Tomas Winklerb210d752012-08-07 00:03:56 +030085enum 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
Oren Weilab841162011-05-15 13:43:41 +030094};
95
Tomas Winklerb210d752012-08-07 00:03:56 +030096const char *mei_dev_state_str(int state);
97
Justin P. Mattock5f9092f2012-03-12 07:18:09 -070098/* init clients states*/
Oren Weilab841162011-05-15 13:43:41 +030099enum 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
Tomas Winklerc216fde2012-08-16 19:39:43 +0300122enum mei_wd_states {
123 MEI_WD_IDLE,
124 MEI_WD_RUNNING,
125 MEI_WD_STOPPING,
126};
127
Oren Weilab841162011-05-15 13:43:41 +0300128/* MEI CB */
129enum mei_cb_major_types {
130 MEI_READ = 0,
131 MEI_WRITE,
132 MEI_IOCTL,
133 MEI_OPEN,
134 MEI_CLOSE
135};
136
137/*
138 * Intel MEI message data struct
139 */
140struct mei_message_data {
141 u32 size;
Tomas Winkleredf1eed2012-02-09 19:25:54 +0200142 unsigned char *data;
Tomas Winklerf0609392012-09-11 00:43:21 +0300143};
Oren Weilab841162011-05-15 13:43:41 +0300144
145
146struct mei_cl_cb {
147 struct list_head cb_list;
148 enum mei_cb_major_types major_file_operations;
149 void *file_private;
150 struct mei_message_data request_buffer;
151 struct mei_message_data response_buffer;
152 unsigned long information;
153 unsigned long read_time;
154 struct file *file_object;
155};
156
157/* MEI client instance carried as file->pirvate_data*/
158struct mei_cl {
159 struct list_head link;
160 struct mei_device *dev;
161 enum file_state state;
162 wait_queue_head_t tx_wait;
163 wait_queue_head_t rx_wait;
164 wait_queue_head_t wait;
165 int read_pending;
166 int status;
167 /* ID of client connected */
168 u8 host_client_id;
169 u8 me_client_id;
170 u8 mei_flow_ctrl_creds;
171 u8 timer_count;
172 enum mei_file_transaction_states reading_state;
173 enum mei_file_transaction_states writing_state;
174 int sm_state;
175 struct mei_cl_cb *read_cb;
176};
177
178struct mei_io_list {
179 struct mei_cl_cb mei_cb;
Oren Weilab841162011-05-15 13:43:41 +0300180};
181
Tomas Winkler24aadc82012-06-25 23:46:27 +0300182/**
183 * struct mei_deive - MEI private device struct
184 * @hbuf_depth - depth of host(write) buffer
185 */
Oren Weilab841162011-05-15 13:43:41 +0300186struct mei_device {
187 struct pci_dev *pdev; /* pointer to pci device struct */
188 /*
189 * lists of queues
190 */
191 /* array of pointers to aio lists */
Oren Weilab841162011-05-15 13:43:41 +0300192 struct mei_io_list read_list; /* driver read queue */
193 struct mei_io_list write_list; /* driver write queue */
194 struct mei_io_list write_waiting_list; /* write waiting queue */
195 struct mei_io_list ctrl_wr_list; /* managed write IOCTL list */
196 struct mei_io_list ctrl_rd_list; /* managed read IOCTL list */
197 struct mei_io_list amthi_cmd_list; /* amthi list for cmd waiting */
198
199 /* driver managed amthi list for reading completed amthi cmd data */
200 struct mei_io_list amthi_read_complete_list;
201 /*
202 * list of files
203 */
204 struct list_head file_list;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300205 long open_handle_count;
Oren Weilab841162011-05-15 13:43:41 +0300206 /*
207 * memory of device
208 */
209 unsigned int mem_base;
210 unsigned int mem_length;
211 void __iomem *mem_addr;
212 /*
213 * lock for the device
214 */
215 struct mutex device_lock; /* device lock */
Oren Weila61c6532011-09-07 09:03:13 +0300216 struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300217 bool recvd_msg;
Oren Weilab841162011-05-15 13:43:41 +0300218 /*
219 * hw states of host and fw(ME)
220 */
221 u32 host_hw_state;
222 u32 me_hw_state;
Tomas Winkler24aadc82012-06-25 23:46:27 +0300223 u8 hbuf_depth;
Oren Weilab841162011-05-15 13:43:41 +0300224 /*
225 * waiting queue for receive message from FW
226 */
227 wait_queue_head_t wait_recvd_msg;
228 wait_queue_head_t wait_stop_wd;
229
230 /*
231 * mei device states
232 */
Tomas Winklerb210d752012-08-07 00:03:56 +0300233 enum mei_dev_state dev_state;
Oren Weilab841162011-05-15 13:43:41 +0300234 enum mei_init_clients_states init_clients_state;
235 u16 init_clients_timer;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300236 bool need_reset;
Oren Weilab841162011-05-15 13:43:41 +0300237
238 u32 extra_write_index;
Tomas Winkleredf1eed2012-02-09 19:25:54 +0200239 unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */
Oren Weilab841162011-05-15 13:43:41 +0300240 u32 wr_msg_buf[128]; /* used for control messages */
241 u32 ext_msg_buf[8]; /* for control responses */
242 u32 rd_msg_hdr;
243
244 struct hbm_version version;
245
Oren Weilab841162011-05-15 13:43:41 +0300246 struct mei_me_client *me_clients; /* Note: memory has to be allocated */
247 DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
248 DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
Tomas Winklercf9673d2011-06-06 10:44:33 +0300249 u8 me_clients_num;
Oren Weilab841162011-05-15 13:43:41 +0300250 u8 me_client_presentation_num;
251 u8 me_client_index;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300252 bool mei_host_buffer_is_empty;
Oren Weilab841162011-05-15 13:43:41 +0300253
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300254 struct mei_cl wd_cl;
Tomas Winklerc216fde2012-08-16 19:39:43 +0300255 enum mei_wd_states wd_state;
Tomas Winkler21c66d12012-06-19 09:13:37 +0300256 bool wd_interface_reg;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300257 bool wd_pending;
Tomas Winklerc216fde2012-08-16 19:39:43 +0300258 u16 wd_timeout;
Tomas Winkler248ffdf2012-08-16 19:39:42 +0300259 unsigned char wd_data[MEI_WD_START_MSG_SIZE];
Oren Weilab841162011-05-15 13:43:41 +0300260
261
Oren Weilab841162011-05-15 13:43:41 +0300262 struct file *iamthif_file_object;
263 struct mei_cl iamthif_cl;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300264 struct mei_cl_cb *iamthif_current_cb;
Oren Weilab841162011-05-15 13:43:41 +0300265 int iamthif_mtu;
266 unsigned long iamthif_timer;
267 u32 iamthif_stall_timer;
268 unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */
269 u32 iamthif_msg_buf_size;
270 u32 iamthif_msg_buf_index;
Oren Weilab841162011-05-15 13:43:41 +0300271 enum iamthif_states iamthif_state;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300272 bool iamthif_flow_control_pending;
273 bool iamthif_ioctl;
274 bool iamthif_canceled;
Oren Weilab841162011-05-15 13:43:41 +0300275};
276
277
278/*
279 * mei init function prototypes
280 */
Tomas Winklerc95efb72011-05-25 17:28:21 +0300281struct mei_device *mei_device_init(struct pci_dev *pdev);
Oren Weilab841162011-05-15 13:43:41 +0300282void mei_reset(struct mei_device *dev, int interrupts);
283int mei_hw_init(struct mei_device *dev);
284int mei_task_initialize_clients(void *data);
285int mei_initialize_clients(struct mei_device *dev);
Oren Weilab841162011-05-15 13:43:41 +0300286int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
Tomas Winkler106fb492011-05-25 17:28:20 +0300287void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id);
Tomas Winklerc95efb72011-05-25 17:28:21 +0300288void mei_host_init_iamthif(struct mei_device *dev);
289void mei_allocate_me_clients_storage(struct mei_device *dev);
Oren Weilab841162011-05-15 13:43:41 +0300290
Oren Weilab841162011-05-15 13:43:41 +0300291
Tomas Winkler07b509b2012-07-23 14:05:39 +0300292int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl,
293 const uuid_le *cguid, u8 host_client_id);
294int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid);
295int mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
Oren Weilab841162011-05-15 13:43:41 +0300296
297/*
Tomas Winkler0288c7c2011-06-06 10:44:34 +0300298 * MEI IO List Functions
299 */
300void mei_io_list_init(struct mei_io_list *list);
301void mei_io_list_flush(struct mei_io_list *list, struct mei_cl *cl);
302
303/*
Tomas Winklerc95efb72011-05-25 17:28:21 +0300304 * MEI ME Client Functions
305 */
306
307struct mei_cl *mei_cl_allocate(struct mei_device *dev);
Tomas Winkler0288c7c2011-06-06 10:44:34 +0300308void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);
309int mei_cl_flush_queues(struct mei_cl *cl);
310/**
311 * mei_cl_cmp_id - tells if file private data have same id
312 *
313 * @fe1: private data of 1. file object
314 * @fe2: private data of 2. file object
315 *
316 * returns true - if ids are the same and not NULL
317 */
318static inline bool mei_cl_cmp_id(const struct mei_cl *cl1,
319 const struct mei_cl *cl2)
320{
321 return cl1 && cl2 &&
322 (cl1->host_client_id == cl2->host_client_id) &&
323 (cl1->me_client_id == cl2->me_client_id);
324}
325
Tomas Winklerc95efb72011-05-25 17:28:21 +0300326
327
328/*
329 * MEI Host Client Functions
330 */
331void mei_host_start_message(struct mei_device *dev);
332void mei_host_enum_clients_message(struct mei_device *dev);
Oren Weilabc51b62011-09-21 16:45:30 +0300333int mei_host_client_properties(struct mei_device *dev);
Tomas Winklerc95efb72011-05-25 17:28:21 +0300334
335/*
336 * MEI interrupt functions prototype
Oren Weilab841162011-05-15 13:43:41 +0300337 */
338irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id);
Tomas Winklerc95efb72011-05-25 17:28:21 +0300339irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id);
Oren Weila61c6532011-09-07 09:03:13 +0300340void mei_timer(struct work_struct *work);
Oren Weilab841162011-05-15 13:43:41 +0300341
342/*
Tomas Winklerc95efb72011-05-25 17:28:21 +0300343 * MEI input output function prototype
Oren Weilab841162011-05-15 13:43:41 +0300344 */
345int mei_ioctl_connect_client(struct file *file,
346 struct mei_connect_client_data *data);
347
348int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
349
350int amthi_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
351
352int amthi_read(struct mei_device *dev, struct file *file,
353 char __user *ubuf, size_t length, loff_t *offset);
354
355struct mei_cl_cb *find_amthi_read_list_entry(struct mei_device *dev,
356 struct file *file);
357
Tomas Winklerc95efb72011-05-25 17:28:21 +0300358void mei_run_next_iamthif_cmd(struct mei_device *dev);
Oren Weilab841162011-05-15 13:43:41 +0300359
360void mei_free_cb_private(struct mei_cl_cb *priv_cb);
361
Oren Weilab841162011-05-15 13:43:41 +0300362
363/*
364 * Register Access Function
365 */
366
367/**
368 * mei_reg_read - Reads 32bit data from the mei device
369 *
370 * @dev: the device structure
371 * @offset: offset from which to read the data
372 *
Oren Weil92eb4012011-09-07 09:03:08 +0300373 * returns register value (u32)
Oren Weilab841162011-05-15 13:43:41 +0300374 */
Tomas Winkler4a0d6a72012-07-04 19:24:49 +0300375static inline u32 mei_reg_read(const struct mei_device *dev,
376 unsigned long offset)
Oren Weilab841162011-05-15 13:43:41 +0300377{
378 return ioread32(dev->mem_addr + offset);
379}
380
381/**
382 * mei_reg_write - Writes 32bit data to the mei device
383 *
384 * @dev: the device structure
385 * @offset: offset from which to write the data
Oren Weil92eb4012011-09-07 09:03:08 +0300386 * @value: register value to write (u32)
Oren Weilab841162011-05-15 13:43:41 +0300387 */
Tomas Winkler4a0d6a72012-07-04 19:24:49 +0300388static inline void mei_reg_write(const struct mei_device *dev,
389 unsigned long offset, u32 value)
Oren Weilab841162011-05-15 13:43:41 +0300390{
391 iowrite32(value, dev->mem_addr + offset);
392}
393
394/**
395 * mei_hcsr_read - Reads 32bit data from the host CSR
396 *
397 * @dev: the device structure
398 *
399 * returns the byte read.
400 */
Tomas Winkler4a0d6a72012-07-04 19:24:49 +0300401static inline u32 mei_hcsr_read(const struct mei_device *dev)
Oren Weilab841162011-05-15 13:43:41 +0300402{
403 return mei_reg_read(dev, H_CSR);
404}
405
406/**
407 * mei_mecsr_read - Reads 32bit data from the ME CSR
408 *
409 * @dev: the device structure
410 *
411 * returns ME_CSR_HA register value (u32)
412 */
Tomas Winkler4a0d6a72012-07-04 19:24:49 +0300413static inline u32 mei_mecsr_read(const struct mei_device *dev)
Oren Weilab841162011-05-15 13:43:41 +0300414{
415 return mei_reg_read(dev, ME_CSR_HA);
416}
417
418/**
419 * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register
420 *
421 * @dev: the device structure
422 *
423 * returns ME_CB_RW register value (u32)
424 */
Tomas Winkler4a0d6a72012-07-04 19:24:49 +0300425static inline u32 mei_mecbrw_read(const struct mei_device *dev)
Oren Weilab841162011-05-15 13:43:41 +0300426{
427 return mei_reg_read(dev, ME_CB_RW);
428}
429
430
431/*
432 * mei interface function prototypes
433 */
434void mei_hcsr_set(struct mei_device *dev);
435void mei_csr_clear_his(struct mei_device *dev);
436
437void mei_enable_interrupts(struct mei_device *dev);
438void mei_disable_interrupts(struct mei_device *dev);
439
Oren Weilab841162011-05-15 13:43:41 +0300440#endif