blob: 35d0538a59748305bce975dac94d1a178aa2508f [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 */
28#define MEI_WATCHDOG_DATA_SIZE 16
29#define MEI_START_WD_DATA_SIZE 20
30#define MEI_WD_PARAMS_SIZE 4
31#define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0)
32
Tomas Winkleredf1eed2012-02-09 19:25:54 +020033#define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32))
34
Oren Weilab841162011-05-15 13:43:41 +030035/*
Oren Weil4a3cafd2011-09-07 09:03:10 +030036 * MEI PCI Device object
37 */
38extern struct pci_dev *mei_device;
39
Oren Weil9ce178e2011-09-07 09:03:09 +030040
41/*
Oren Weilab841162011-05-15 13:43:41 +030042 * AMTHI Client UUID
43 */
44extern const uuid_le mei_amthi_guid;
45
46/*
47 * Watchdog Client UUID
48 */
49extern const uuid_le mei_wd_guid;
50
51/*
52 * Watchdog independence state message
53 */
54extern const u8 mei_wd_state_independence_msg[3][4];
55
56/*
57 * Number of File descriptors/handles
58 * that can be opened to the driver.
59 *
60 * Limit to 253: 255 Total Clients
61 * minus internal client for AMTHI
62 * minus internal client for Watchdog
63 */
64#define MEI_MAX_OPEN_HANDLE_COUNT 253
65
66/*
Oren Weilab841162011-05-15 13:43:41 +030067 * Number of Maximum MEI Clients
68 */
69#define MEI_CLIENTS_MAX 255
70
71/* File state */
72enum file_state {
73 MEI_FILE_INITIALIZING = 0,
74 MEI_FILE_CONNECTING,
75 MEI_FILE_CONNECTED,
76 MEI_FILE_DISCONNECTING,
77 MEI_FILE_DISCONNECTED
78};
79
80/* MEI device states */
Tomas Winklerb210d752012-08-07 00:03:56 +030081enum mei_dev_state {
82 MEI_DEV_INITIALIZING = 0,
83 MEI_DEV_INIT_CLIENTS,
84 MEI_DEV_ENABLED,
85 MEI_DEV_RESETING,
86 MEI_DEV_DISABLED,
87 MEI_DEV_RECOVERING_FROM_RESET,
88 MEI_DEV_POWER_DOWN,
89 MEI_DEV_POWER_UP
Oren Weilab841162011-05-15 13:43:41 +030090};
91
Tomas Winklerb210d752012-08-07 00:03:56 +030092const char *mei_dev_state_str(int state);
93
Justin P. Mattock5f9092f32012-03-12 07:18:09 -070094/* init clients states*/
Oren Weilab841162011-05-15 13:43:41 +030095enum mei_init_clients_states {
96 MEI_START_MESSAGE = 0,
97 MEI_ENUM_CLIENTS_MESSAGE,
98 MEI_CLIENT_PROPERTIES_MESSAGE
99};
100
101enum iamthif_states {
102 MEI_IAMTHIF_IDLE,
103 MEI_IAMTHIF_WRITING,
104 MEI_IAMTHIF_FLOW_CONTROL,
105 MEI_IAMTHIF_READING,
106 MEI_IAMTHIF_READ_COMPLETE
107};
108
109enum mei_file_transaction_states {
110 MEI_IDLE,
111 MEI_WRITING,
112 MEI_WRITE_COMPLETE,
113 MEI_FLOW_CONTROL,
114 MEI_READING,
115 MEI_READ_COMPLETE
116};
117
118/* MEI CB */
119enum mei_cb_major_types {
120 MEI_READ = 0,
121 MEI_WRITE,
122 MEI_IOCTL,
123 MEI_OPEN,
124 MEI_CLOSE
125};
126
127/*
128 * Intel MEI message data struct
129 */
130struct mei_message_data {
131 u32 size;
Tomas Winkleredf1eed2012-02-09 19:25:54 +0200132 unsigned char *data;
Oren Weilab841162011-05-15 13:43:41 +0300133} __packed;
134
135
136struct mei_cl_cb {
137 struct list_head cb_list;
138 enum mei_cb_major_types major_file_operations;
139 void *file_private;
140 struct mei_message_data request_buffer;
141 struct mei_message_data response_buffer;
142 unsigned long information;
143 unsigned long read_time;
144 struct file *file_object;
145};
146
147/* MEI client instance carried as file->pirvate_data*/
148struct mei_cl {
149 struct list_head link;
150 struct mei_device *dev;
151 enum file_state state;
152 wait_queue_head_t tx_wait;
153 wait_queue_head_t rx_wait;
154 wait_queue_head_t wait;
155 int read_pending;
156 int status;
157 /* ID of client connected */
158 u8 host_client_id;
159 u8 me_client_id;
160 u8 mei_flow_ctrl_creds;
161 u8 timer_count;
162 enum mei_file_transaction_states reading_state;
163 enum mei_file_transaction_states writing_state;
164 int sm_state;
165 struct mei_cl_cb *read_cb;
166};
167
168struct mei_io_list {
169 struct mei_cl_cb mei_cb;
Oren Weilab841162011-05-15 13:43:41 +0300170};
171
Tomas Winkler24aadc82012-06-25 23:46:27 +0300172/**
173 * struct mei_deive - MEI private device struct
174 * @hbuf_depth - depth of host(write) buffer
175 */
Oren Weilab841162011-05-15 13:43:41 +0300176struct mei_device {
177 struct pci_dev *pdev; /* pointer to pci device struct */
178 /*
179 * lists of queues
180 */
181 /* array of pointers to aio lists */
Oren Weilab841162011-05-15 13:43:41 +0300182 struct mei_io_list read_list; /* driver read queue */
183 struct mei_io_list write_list; /* driver write queue */
184 struct mei_io_list write_waiting_list; /* write waiting queue */
185 struct mei_io_list ctrl_wr_list; /* managed write IOCTL list */
186 struct mei_io_list ctrl_rd_list; /* managed read IOCTL list */
187 struct mei_io_list amthi_cmd_list; /* amthi list for cmd waiting */
188
189 /* driver managed amthi list for reading completed amthi cmd data */
190 struct mei_io_list amthi_read_complete_list;
191 /*
192 * list of files
193 */
194 struct list_head file_list;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300195 long open_handle_count;
Oren Weilab841162011-05-15 13:43:41 +0300196 /*
197 * memory of device
198 */
199 unsigned int mem_base;
200 unsigned int mem_length;
201 void __iomem *mem_addr;
202 /*
203 * lock for the device
204 */
205 struct mutex device_lock; /* device lock */
Oren Weila61c6532011-09-07 09:03:13 +0300206 struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300207 bool recvd_msg;
Oren Weilab841162011-05-15 13:43:41 +0300208 /*
209 * hw states of host and fw(ME)
210 */
211 u32 host_hw_state;
212 u32 me_hw_state;
Tomas Winkler24aadc82012-06-25 23:46:27 +0300213 u8 hbuf_depth;
Oren Weilab841162011-05-15 13:43:41 +0300214 /*
215 * waiting queue for receive message from FW
216 */
217 wait_queue_head_t wait_recvd_msg;
218 wait_queue_head_t wait_stop_wd;
219
220 /*
221 * mei device states
222 */
Tomas Winklerb210d752012-08-07 00:03:56 +0300223 enum mei_dev_state dev_state;
Oren Weilab841162011-05-15 13:43:41 +0300224 enum mei_init_clients_states init_clients_state;
225 u16 init_clients_timer;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300226 bool stop;
227 bool need_reset;
Oren Weilab841162011-05-15 13:43:41 +0300228
229 u32 extra_write_index;
Tomas Winkleredf1eed2012-02-09 19:25:54 +0200230 unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */
Oren Weilab841162011-05-15 13:43:41 +0300231 u32 wr_msg_buf[128]; /* used for control messages */
232 u32 ext_msg_buf[8]; /* for control responses */
233 u32 rd_msg_hdr;
234
235 struct hbm_version version;
236
Oren Weilab841162011-05-15 13:43:41 +0300237 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);
Tomas Winklercf9673d2011-06-06 10:44:33 +0300240 u8 me_clients_num;
Oren Weilab841162011-05-15 13:43:41 +0300241 u8 me_client_presentation_num;
242 u8 me_client_index;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300243 bool mei_host_buffer_is_empty;
Oren Weilab841162011-05-15 13:43:41 +0300244
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300245 struct mei_cl wd_cl;
Tomas Winkler21c66d12012-06-19 09:13:37 +0300246 bool wd_interface_reg;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300247 bool wd_pending;
248 bool wd_stopped;
249 bool wd_bypass; /* if false, don't refresh watchdog ME client */
Oren Weilab841162011-05-15 13:43:41 +0300250 u16 wd_timeout; /* seconds ((wd_data[1] << 8) + wd_data[0]) */
251 unsigned char wd_data[MEI_START_WD_DATA_SIZE];
252
253
Oren Weilab841162011-05-15 13:43:41 +0300254 struct file *iamthif_file_object;
255 struct mei_cl iamthif_cl;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300256 struct mei_cl_cb *iamthif_current_cb;
Oren Weilab841162011-05-15 13:43:41 +0300257 int iamthif_mtu;
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;
Oren Weilab841162011-05-15 13:43:41 +0300263 enum iamthif_states iamthif_state;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300264 bool iamthif_flow_control_pending;
265 bool iamthif_ioctl;
266 bool iamthif_canceled;
Oren Weilab841162011-05-15 13:43:41 +0300267};
268
269
270/*
271 * mei init function prototypes
272 */
Tomas Winklerc95efb72011-05-25 17:28:21 +0300273struct mei_device *mei_device_init(struct pci_dev *pdev);
Oren Weilab841162011-05-15 13:43:41 +0300274void mei_reset(struct mei_device *dev, int interrupts);
275int mei_hw_init(struct mei_device *dev);
276int mei_task_initialize_clients(void *data);
277int mei_initialize_clients(struct mei_device *dev);
Oren Weilab841162011-05-15 13:43:41 +0300278int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
Tomas Winkler106fb492011-05-25 17:28:20 +0300279void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id);
Tomas Winklerc95efb72011-05-25 17:28:21 +0300280void mei_host_init_iamthif(struct mei_device *dev);
281void mei_allocate_me_clients_storage(struct mei_device *dev);
Oren Weilab841162011-05-15 13:43:41 +0300282
Oren Weilab841162011-05-15 13:43:41 +0300283
Tomas Winkler07b509b2012-07-23 14:05:39 +0300284int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl,
285 const uuid_le *cguid, u8 host_client_id);
286int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid);
287int mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
Oren Weilab841162011-05-15 13:43:41 +0300288
289/*
Tomas Winkler0288c7c2011-06-06 10:44:34 +0300290 * MEI IO List Functions
291 */
292void mei_io_list_init(struct mei_io_list *list);
293void mei_io_list_flush(struct mei_io_list *list, struct mei_cl *cl);
294
295/*
Tomas Winklerc95efb72011-05-25 17:28:21 +0300296 * MEI ME Client Functions
297 */
298
299struct mei_cl *mei_cl_allocate(struct mei_device *dev);
Tomas Winkler0288c7c2011-06-06 10:44:34 +0300300void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);
301int mei_cl_flush_queues(struct mei_cl *cl);
302/**
303 * mei_cl_cmp_id - tells if file private data have same id
304 *
305 * @fe1: private data of 1. file object
306 * @fe2: private data of 2. file object
307 *
308 * returns true - if ids are the same and not NULL
309 */
310static inline bool mei_cl_cmp_id(const struct mei_cl *cl1,
311 const struct mei_cl *cl2)
312{
313 return cl1 && cl2 &&
314 (cl1->host_client_id == cl2->host_client_id) &&
315 (cl1->me_client_id == cl2->me_client_id);
316}
317
Tomas Winklerc95efb72011-05-25 17:28:21 +0300318
319
320/*
321 * MEI Host Client Functions
322 */
323void mei_host_start_message(struct mei_device *dev);
324void mei_host_enum_clients_message(struct mei_device *dev);
Oren Weilabc51b62011-09-21 16:45:30 +0300325int mei_host_client_properties(struct mei_device *dev);
Tomas Winklerc95efb72011-05-25 17:28:21 +0300326
327/*
328 * MEI interrupt functions prototype
Oren Weilab841162011-05-15 13:43:41 +0300329 */
330irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id);
Tomas Winklerc95efb72011-05-25 17:28:21 +0300331irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id);
Oren Weila61c6532011-09-07 09:03:13 +0300332void mei_timer(struct work_struct *work);
Oren Weilab841162011-05-15 13:43:41 +0300333
334/*
Tomas Winklerc95efb72011-05-25 17:28:21 +0300335 * MEI input output function prototype
Oren Weilab841162011-05-15 13:43:41 +0300336 */
337int mei_ioctl_connect_client(struct file *file,
338 struct mei_connect_client_data *data);
339
340int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
341
342int amthi_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
343
344int amthi_read(struct mei_device *dev, struct file *file,
345 char __user *ubuf, size_t length, loff_t *offset);
346
347struct mei_cl_cb *find_amthi_read_list_entry(struct mei_device *dev,
348 struct file *file);
349
Tomas Winklerc95efb72011-05-25 17:28:21 +0300350void mei_run_next_iamthif_cmd(struct mei_device *dev);
Oren Weilab841162011-05-15 13:43:41 +0300351
352void mei_free_cb_private(struct mei_cl_cb *priv_cb);
353
Oren Weilab841162011-05-15 13:43:41 +0300354
355/*
356 * Register Access Function
357 */
358
359/**
360 * mei_reg_read - Reads 32bit data from the mei device
361 *
362 * @dev: the device structure
363 * @offset: offset from which to read the data
364 *
Oren Weil92eb4012011-09-07 09:03:08 +0300365 * returns register value (u32)
Oren Weilab841162011-05-15 13:43:41 +0300366 */
Tomas Winkler4a0d6a72012-07-04 19:24:49 +0300367static inline u32 mei_reg_read(const struct mei_device *dev,
368 unsigned long offset)
Oren Weilab841162011-05-15 13:43:41 +0300369{
370 return ioread32(dev->mem_addr + offset);
371}
372
373/**
374 * mei_reg_write - Writes 32bit data to the mei device
375 *
376 * @dev: the device structure
377 * @offset: offset from which to write the data
Oren Weil92eb4012011-09-07 09:03:08 +0300378 * @value: register value to write (u32)
Oren Weilab841162011-05-15 13:43:41 +0300379 */
Tomas Winkler4a0d6a72012-07-04 19:24:49 +0300380static inline void mei_reg_write(const struct mei_device *dev,
381 unsigned long offset, u32 value)
Oren Weilab841162011-05-15 13:43:41 +0300382{
383 iowrite32(value, dev->mem_addr + offset);
384}
385
386/**
387 * mei_hcsr_read - Reads 32bit data from the host CSR
388 *
389 * @dev: the device structure
390 *
391 * returns the byte read.
392 */
Tomas Winkler4a0d6a72012-07-04 19:24:49 +0300393static inline u32 mei_hcsr_read(const struct mei_device *dev)
Oren Weilab841162011-05-15 13:43:41 +0300394{
395 return mei_reg_read(dev, H_CSR);
396}
397
398/**
399 * mei_mecsr_read - Reads 32bit data from the ME CSR
400 *
401 * @dev: the device structure
402 *
403 * returns ME_CSR_HA register value (u32)
404 */
Tomas Winkler4a0d6a72012-07-04 19:24:49 +0300405static inline u32 mei_mecsr_read(const struct mei_device *dev)
Oren Weilab841162011-05-15 13:43:41 +0300406{
407 return mei_reg_read(dev, ME_CSR_HA);
408}
409
410/**
411 * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register
412 *
413 * @dev: the device structure
414 *
415 * returns ME_CB_RW register value (u32)
416 */
Tomas Winkler4a0d6a72012-07-04 19:24:49 +0300417static inline u32 mei_mecbrw_read(const struct mei_device *dev)
Oren Weilab841162011-05-15 13:43:41 +0300418{
419 return mei_reg_read(dev, ME_CB_RW);
420}
421
422
423/*
424 * mei interface function prototypes
425 */
426void mei_hcsr_set(struct mei_device *dev);
427void mei_csr_clear_his(struct mei_device *dev);
428
429void mei_enable_interrupts(struct mei_device *dev);
430void mei_disable_interrupts(struct mei_device *dev);
431
Oren Weilab841162011-05-15 13:43:41 +0300432#endif