3 * Intel Management Engine Interface (Intel MEI) Linux driver
4 * Copyright (c) 2003-2011, 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>
25 * MEI Char Driver Minors
27 #define MEI_MINORS_BASE 1
28 #define MEI_MINORS_COUNT 1
29 #define MEI_MINOR_NUMBER 1
32 * watch dog definition
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)
42 extern const uuid_le mei_amthi_guid;
45 * Watchdog Client UUID
47 extern const uuid_le mei_wd_guid;
50 * Watchdog independence state message
52 extern const u8 mei_wd_state_independence_msg[3][4];
55 * Number of File descriptors/handles
56 * that can be opened to the driver.
58 * Limit to 253: 255 Total Clients
59 * minus internal client for AMTHI
60 * minus internal client for Watchdog
62 #define MEI_MAX_OPEN_HANDLE_COUNT 253
65 * Number of queue lists used by this driver
67 #define MEI_IO_LISTS_NUMBER 7
70 * Number of Maximum MEI Clients
72 #define MEI_CLIENTS_MAX 255
76 MEI_FILE_INITIALIZING = 0,
79 MEI_FILE_DISCONNECTING,
83 /* MEI device states */
90 MEI_RECOVERING_FROM_RESET,
95 /* init clients states*/
96 enum mei_init_clients_states {
97 MEI_START_MESSAGE = 0,
98 MEI_ENUM_CLIENTS_MESSAGE,
99 MEI_CLIENT_PROPERTIES_MESSAGE
102 enum iamthif_states {
105 MEI_IAMTHIF_FLOW_CONTROL,
107 MEI_IAMTHIF_READ_COMPLETE
110 enum mei_file_transaction_states {
120 enum mei_cb_major_types {
129 * Intel MEI message data struct
131 struct mei_message_data {
138 struct list_head cb_list;
139 enum mei_cb_major_types major_file_operations;
141 struct mei_message_data request_buffer;
142 struct mei_message_data response_buffer;
143 unsigned long information;
144 unsigned long read_time;
145 struct file *file_object;
148 /* MEI client instance carried as file->pirvate_data*/
150 struct list_head link;
151 struct mei_device *dev;
152 enum file_state state;
153 wait_queue_head_t tx_wait;
154 wait_queue_head_t rx_wait;
155 wait_queue_head_t wait;
158 /* ID of client connected */
161 u8 mei_flow_ctrl_creds;
163 enum mei_file_transaction_states reading_state;
164 enum mei_file_transaction_states writing_state;
166 struct mei_cl_cb *read_cb;
170 struct mei_cl_cb mei_cb;
172 struct mei_device *device_extension;
175 /* MEI private device struct */
177 struct pci_dev *pdev; /* pointer to pci device struct */
181 /* array of pointers to aio lists */
182 struct mei_io_list *io_list_array[MEI_IO_LISTS_NUMBER];
183 struct mei_io_list read_list; /* driver read queue */
184 struct mei_io_list write_list; /* driver write queue */
185 struct mei_io_list write_waiting_list; /* write waiting queue */
186 struct mei_io_list ctrl_wr_list; /* managed write IOCTL list */
187 struct mei_io_list ctrl_rd_list; /* managed read IOCTL list */
188 struct mei_io_list amthi_cmd_list; /* amthi list for cmd waiting */
190 /* driver managed amthi list for reading completed amthi cmd data */
191 struct mei_io_list amthi_read_complete_list;
195 struct list_head file_list;
199 unsigned int mem_base;
200 unsigned int mem_length;
201 void __iomem *mem_addr;
203 * lock for the device
205 struct mutex device_lock; /* device lock */
207 struct delayed_work wd_work; /* watch dog deleye work */
209 * hw states of host and fw(ME)
214 * waiting queue for receive message from FW
216 wait_queue_head_t wait_recvd_msg;
217 wait_queue_head_t wait_stop_wd;
222 enum mei_states mei_state;
223 enum mei_init_clients_states init_clients_state;
224 u16 init_clients_timer;
227 u32 extra_write_index;
228 u32 rd_msg_buf[128]; /* used for control messages */
229 u32 wr_msg_buf[128]; /* used for control messages */
230 u32 ext_msg_buf[8]; /* for control responses */
233 struct hbm_version version;
235 int mei_host_buffer_is_empty;
237 struct mei_me_client *me_clients; /* Note: memory has to be allocated */
238 DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
239 DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
240 u8 num_mei_me_clients;
241 u8 me_client_presentation_num;
246 u16 wd_timeout; /* seconds ((wd_data[1] << 8) + wd_data[0]) */
247 unsigned char wd_data[MEI_START_WD_DATA_SIZE];
251 bool wd_bypass; /* if false, don't refresh watchdog ME client */
253 struct file *iamthif_file_object;
254 struct mei_cl iamthif_cl;
256 int iamthif_canceled;
258 unsigned long iamthif_timer;
259 u32 iamthif_stall_timer;
260 unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */
261 u32 iamthif_msg_buf_size;
262 u32 iamthif_msg_buf_index;
263 int iamthif_flow_control_pending;
264 enum iamthif_states iamthif_state;
265 struct mei_cl_cb *iamthif_current_cb;
268 long open_handle_count;
274 * mei init function prototypes
276 struct mei_device *init_mei_device(struct pci_dev *pdev);
277 void mei_reset(struct mei_device *dev, int interrupts);
278 int mei_hw_init(struct mei_device *dev);
279 int mei_task_initialize_clients(void *data);
280 int mei_initialize_clients(struct mei_device *dev);
281 struct mei_cl *mei_alloc_file_private(struct mei_device *dev);
282 int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
283 void mei_initialize_list(struct mei_io_list *list, struct mei_device *dev);
284 void mei_flush_list(struct mei_io_list *list, struct mei_cl *cl);
285 void mei_flush_queues(struct mei_device *dev, struct mei_cl *cl);
286 void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id);
287 void host_init_iamthif(struct mei_device *dev);
288 void mei_init_file_private(struct mei_cl *priv, struct mei_device *dev);
289 void allocate_me_clients_storage(struct mei_device *dev);
291 void host_start_message(struct mei_device *dev);
292 void host_enum_clients_message(struct mei_device *dev);
293 void host_client_properties(struct mei_device *dev);
295 u8 mei_find_me_client_update_filext(struct mei_device *dev,
297 const uuid_le *cguid, u8 client_id);
300 * interrupt functions prototype
302 irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id);
303 irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id);
304 void mei_wd_timer(struct work_struct *work);
307 * input output function prototype
309 int mei_ioctl_connect_client(struct file *file,
310 struct mei_connect_client_data *data);
312 int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
314 int amthi_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
316 int amthi_read(struct mei_device *dev, struct file *file,
317 char __user *ubuf, size_t length, loff_t *offset);
319 struct mei_cl_cb *find_amthi_read_list_entry(struct mei_device *dev,
322 void run_next_iamthif_cmd(struct mei_device *dev);
324 void mei_free_cb_private(struct mei_cl_cb *priv_cb);
326 int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid);
329 * Register Access Function
333 * mei_reg_read - Reads 32bit data from the mei device
335 * @dev: the device structure
336 * @offset: offset from which to read the data
338 * returns the byte read.
340 static inline u32 mei_reg_read(struct mei_device *dev, unsigned long offset)
342 return ioread32(dev->mem_addr + offset);
346 * mei_reg_write - Writes 32bit data to the mei device
348 * @dev: the device structure
349 * @offset: offset from which to write the data
350 * @value: the byte to write
352 static inline void mei_reg_write(struct mei_device *dev,
353 unsigned long offset, u32 value)
355 iowrite32(value, dev->mem_addr + offset);
359 * mei_hcsr_read - Reads 32bit data from the host CSR
361 * @dev: the device structure
363 * returns the byte read.
365 static inline u32 mei_hcsr_read(struct mei_device *dev)
367 return mei_reg_read(dev, H_CSR);
371 * mei_mecsr_read - Reads 32bit data from the ME CSR
373 * @dev: the device structure
375 * returns ME_CSR_HA register value (u32)
377 static inline u32 mei_mecsr_read(struct mei_device *dev)
379 return mei_reg_read(dev, ME_CSR_HA);
383 * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register
385 * @dev: the device structure
387 * returns ME_CB_RW register value (u32)
389 static inline u32 mei_mecbrw_read(struct mei_device *dev)
391 return mei_reg_read(dev, ME_CB_RW);
396 * mei interface function prototypes
398 void mei_hcsr_set(struct mei_device *dev);
399 void mei_csr_clear_his(struct mei_device *dev);
401 void mei_enable_interrupts(struct mei_device *dev);
402 void mei_disable_interrupts(struct mei_device *dev);
405 * mei_fe_same_id - tells if file private data have same id
407 * @fe1: private data of 1. file object
408 * @fe2: private data of 2. file object
410 * returns !=0 - if ids are the same, 0 - if differ.
412 static inline int mei_fe_same_id(const struct mei_cl *fe1,
413 const struct mei_cl *fe2)
415 return ((fe1->host_client_id == fe2->host_client_id) &&
416 (fe1->me_client_id == fe2->me_client_id));