3 * Intel Management Engine Interface (Intel MEI) Linux driver
4 * Copyright (c) 2003-2012, Intel Corporation.
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.
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
20 #include <linux/types.h>
21 #include <linux/watchdog.h>
22 #include <linux/mei.h>
26 * watch dog definition
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)
32 #define MEI_WD_DEFAULT_TIMEOUT 120 /* seconds */
33 #define MEI_WD_MIN_TIMEOUT 120 /* seconds */
34 #define MEI_WD_MAX_TIMEOUT 65535 /* seconds */
36 #define MEI_WD_STOP_TIMEOUT 10 /* msecs */
38 #define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0)
40 #define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32))
46 extern const uuid_le mei_amthi_guid;
49 * Watchdog Client UUID
51 extern const uuid_le mei_wd_guid;
54 * Watchdog independence state message
56 extern const u8 mei_wd_state_independence_msg[3][4];
59 * Number of Maximum MEI Clients
61 #define MEI_CLIENTS_MAX 256
64 * Number of File descriptors/handles
65 * that can be opened to the driver.
67 * Limit to 253: 256 Total Clients
68 * minus internal client for MEI Bus Messags
69 * minus internal client for AMTHI
70 * minus internal client for Watchdog
72 #define MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 3)
77 MEI_FILE_INITIALIZING = 0,
80 MEI_FILE_DISCONNECTING,
84 /* MEI device states */
86 MEI_DEV_INITIALIZING = 0,
91 MEI_DEV_RECOVERING_FROM_RESET,
96 const char *mei_dev_state_str(int state);
98 /* init clients states*/
99 enum mei_init_clients_states {
100 MEI_START_MESSAGE = 0,
101 MEI_ENUM_CLIENTS_MESSAGE,
102 MEI_CLIENT_PROPERTIES_MESSAGE
105 enum iamthif_states {
108 MEI_IAMTHIF_FLOW_CONTROL,
110 MEI_IAMTHIF_READ_COMPLETE
113 enum mei_file_transaction_states {
129 enum mei_cb_major_types {
138 * Intel MEI message data struct
140 struct mei_message_data {
149 * struct mei_cl_cb - file operation callback structure
151 * @cl - file client who is running this operation
154 struct list_head list;
156 enum mei_cb_major_types major_file_operations;
157 struct mei_message_data request_buffer;
158 struct mei_message_data response_buffer;
159 unsigned long buf_idx;
160 unsigned long read_time;
161 struct file *file_object;
164 /* MEI client instance carried as file->pirvate_data*/
166 struct list_head link;
167 struct mei_device *dev;
168 enum file_state state;
169 wait_queue_head_t tx_wait;
170 wait_queue_head_t rx_wait;
171 wait_queue_head_t wait;
174 /* ID of client connected */
177 u8 mei_flow_ctrl_creds;
179 enum mei_file_transaction_states reading_state;
180 enum mei_file_transaction_states writing_state;
182 struct mei_cl_cb *read_cb;
186 * struct mei_deive - MEI private device struct
187 * @hbuf_depth - depth of host(write) buffer
190 struct pci_dev *pdev; /* pointer to pci device struct */
194 /* array of pointers to aio lists */
195 struct mei_cl_cb read_list; /* driver read queue */
196 struct mei_cl_cb write_list; /* driver write queue */
197 struct mei_cl_cb write_waiting_list; /* write waiting queue */
198 struct mei_cl_cb ctrl_wr_list; /* managed write IOCTL list */
199 struct mei_cl_cb ctrl_rd_list; /* managed read IOCTL list */
204 struct list_head file_list;
205 long open_handle_count;
209 unsigned int mem_base;
210 unsigned int mem_length;
211 void __iomem *mem_addr;
213 * lock for the device
215 struct mutex device_lock; /* device lock */
216 struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */
219 * hw states of host and fw(ME)
225 * waiting queue for receive message from FW
227 wait_queue_head_t wait_recvd_msg;
228 wait_queue_head_t wait_stop_wd;
233 enum mei_dev_state dev_state;
234 enum mei_init_clients_states init_clients_state;
235 u16 init_clients_timer;
238 u32 extra_write_index;
239 unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */
240 u32 wr_msg_buf[128]; /* used for control messages */
241 u32 ext_msg_buf[8]; /* for control responses */
244 struct hbm_version version;
246 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);
250 u8 me_client_presentation_num;
252 bool mei_host_buffer_is_empty;
255 enum mei_wd_states wd_state;
258 unsigned char wd_data[MEI_WD_START_MSG_SIZE];
261 /* amthif list for cmd waiting */
262 struct mei_cl_cb amthif_cmd_list;
263 /* driver managed amthif list for reading completed amthif cmd data */
264 struct mei_cl_cb amthif_rd_complete_list;
265 struct file *iamthif_file_object;
266 struct mei_cl iamthif_cl;
267 struct mei_cl_cb *iamthif_current_cb;
269 unsigned long iamthif_timer;
270 u32 iamthif_stall_timer;
271 unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */
272 u32 iamthif_msg_buf_size;
273 u32 iamthif_msg_buf_index;
274 enum iamthif_states iamthif_state;
275 bool iamthif_flow_control_pending;
277 bool iamthif_canceled;
280 static inline unsigned long mei_secs_to_jiffies(unsigned long sec)
282 return msecs_to_jiffies(sec * MSEC_PER_SEC);
287 * mei init function prototypes
289 struct mei_device *mei_device_init(struct pci_dev *pdev);
290 void mei_reset(struct mei_device *dev, int interrupts);
291 int mei_hw_init(struct mei_device *dev);
292 int mei_task_initialize_clients(void *data);
293 int mei_initialize_clients(struct mei_device *dev);
294 int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
295 void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id);
296 void mei_allocate_me_clients_storage(struct mei_device *dev);
299 int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl,
300 const uuid_le *cguid, u8 host_client_id);
301 int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid);
302 int mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
307 struct mei_cl_cb *mei_io_cb_init(struct mei_cl *cl, struct file *fp);
308 void mei_io_cb_free(struct mei_cl_cb *priv_cb);
309 int mei_io_cb_alloc_req_buf(struct mei_cl_cb *cb, size_t length);
310 int mei_io_cb_alloc_resp_buf(struct mei_cl_cb *cb, size_t length);
314 * mei_io_list_init - Sets up a queue list.
316 * @list: An instance cl callback structure
318 static inline void mei_io_list_init(struct mei_cl_cb *list)
320 INIT_LIST_HEAD(&list->list);
322 void mei_io_list_flush(struct mei_cl_cb *list, struct mei_cl *cl);
325 * MEI ME Client Functions
328 struct mei_cl *mei_cl_allocate(struct mei_device *dev);
329 void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);
330 int mei_cl_flush_queues(struct mei_cl *cl);
332 * mei_cl_cmp_id - tells if file private data have same id
334 * @fe1: private data of 1. file object
335 * @fe2: private data of 2. file object
337 * returns true - if ids are the same and not NULL
339 static inline bool mei_cl_cmp_id(const struct mei_cl *cl1,
340 const struct mei_cl *cl2)
343 (cl1->host_client_id == cl2->host_client_id) &&
344 (cl1->me_client_id == cl2->me_client_id);
350 * MEI Host Client Functions
352 void mei_host_start_message(struct mei_device *dev);
353 void mei_host_enum_clients_message(struct mei_device *dev);
354 int mei_host_client_properties(struct mei_device *dev);
357 * MEI interrupt functions prototype
359 irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id);
360 irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id);
361 void mei_timer(struct work_struct *work);
364 * MEI input output function prototype
366 int mei_ioctl_connect_client(struct file *file,
367 struct mei_connect_client_data *data);
369 int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
373 * AMTHIF - AMT Host Interface Functions
375 void mei_amthif_reset_params(struct mei_device *dev);
377 void mei_amthif_host_init(struct mei_device *dev);
379 int mei_amthif_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
381 int mei_amthif_read(struct mei_device *dev, struct file *file,
382 char __user *ubuf, size_t length, loff_t *offset);
384 struct mei_cl_cb *mei_amthif_find_read_list_entry(struct mei_device *dev,
387 void mei_amthif_run_next_cmd(struct mei_device *dev);
390 int mei_amthif_read_message(struct mei_cl_cb *complete_list,
391 struct mei_device *dev, struct mei_msg_hdr *mei_hdr);
393 int mei_amthif_irq_process_completed(struct mei_device *dev, s32 *slots,
394 struct mei_cl_cb *cb_pos,
396 struct mei_cl_cb *cmpl_list);
398 void mei_amthif_complete(struct mei_device *dev, struct mei_cl_cb *cb);
399 int mei_amthif_irq_read_message(struct mei_cl_cb *complete_list,
400 struct mei_device *dev, struct mei_msg_hdr *mei_hdr);
401 int mei_amthif_irq_read(struct mei_device *dev, s32 *slots);
404 * Register Access Function
408 * mei_reg_read - Reads 32bit data from the mei device
410 * @dev: the device structure
411 * @offset: offset from which to read the data
413 * returns register value (u32)
415 static inline u32 mei_reg_read(const struct mei_device *dev,
416 unsigned long offset)
418 return ioread32(dev->mem_addr + offset);
422 * mei_reg_write - Writes 32bit data to the mei device
424 * @dev: the device structure
425 * @offset: offset from which to write the data
426 * @value: register value to write (u32)
428 static inline void mei_reg_write(const struct mei_device *dev,
429 unsigned long offset, u32 value)
431 iowrite32(value, dev->mem_addr + offset);
435 * mei_hcsr_read - Reads 32bit data from the host CSR
437 * @dev: the device structure
439 * returns the byte read.
441 static inline u32 mei_hcsr_read(const struct mei_device *dev)
443 return mei_reg_read(dev, H_CSR);
447 * mei_mecsr_read - Reads 32bit data from the ME CSR
449 * @dev: the device structure
451 * returns ME_CSR_HA register value (u32)
453 static inline u32 mei_mecsr_read(const struct mei_device *dev)
455 return mei_reg_read(dev, ME_CSR_HA);
459 * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register
461 * @dev: the device structure
463 * returns ME_CB_RW register value (u32)
465 static inline u32 mei_mecbrw_read(const struct mei_device *dev)
467 return mei_reg_read(dev, ME_CB_RW);
472 * mei interface function prototypes
474 void mei_hcsr_set(struct mei_device *dev);
475 void mei_csr_clear_his(struct mei_device *dev);
477 void mei_enable_interrupts(struct mei_device *dev);
478 void mei_disable_interrupts(struct mei_device *dev);