blob: c8660c0eb1c7045d51e6552a88e5769cc4301216 [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 Weilab841162011-05-15 13:43:41 +030042/*
Oren Weil4a3cafd2011-09-07 09:03:10 +030043 * MEI PCI Device object
44 */
45extern struct pci_dev *mei_device;
46
Oren Weil9ce178e2011-09-07 09:03:09 +030047
48/*
Oren Weilab841162011-05-15 13:43:41 +030049 * AMTHI Client UUID
50 */
51extern const uuid_le mei_amthi_guid;
52
53/*
54 * Watchdog Client UUID
55 */
56extern const uuid_le mei_wd_guid;
57
58/*
59 * Watchdog independence state message
60 */
61extern const u8 mei_wd_state_independence_msg[3][4];
62
63/*
64 * Number of File descriptors/handles
65 * that can be opened to the driver.
66 *
67 * Limit to 253: 255 Total Clients
68 * minus internal client for AMTHI
69 * minus internal client for Watchdog
70 */
71#define MEI_MAX_OPEN_HANDLE_COUNT 253
72
73/*
Oren Weilab841162011-05-15 13:43:41 +030074 * Number of Maximum MEI Clients
75 */
76#define MEI_CLIENTS_MAX 255
77
78/* File state */
79enum file_state {
80 MEI_FILE_INITIALIZING = 0,
81 MEI_FILE_CONNECTING,
82 MEI_FILE_CONNECTED,
83 MEI_FILE_DISCONNECTING,
84 MEI_FILE_DISCONNECTED
85};
86
87/* MEI device states */
Tomas Winklerb210d752012-08-07 00:03:56 +030088enum mei_dev_state {
89 MEI_DEV_INITIALIZING = 0,
90 MEI_DEV_INIT_CLIENTS,
91 MEI_DEV_ENABLED,
92 MEI_DEV_RESETING,
93 MEI_DEV_DISABLED,
94 MEI_DEV_RECOVERING_FROM_RESET,
95 MEI_DEV_POWER_DOWN,
96 MEI_DEV_POWER_UP
Oren Weilab841162011-05-15 13:43:41 +030097};
98
Tomas Winklerb210d752012-08-07 00:03:56 +030099const char *mei_dev_state_str(int state);
100
Justin P. Mattock5f9092f32012-03-12 07:18:09 -0700101/* init clients states*/
Oren Weilab841162011-05-15 13:43:41 +0300102enum mei_init_clients_states {
103 MEI_START_MESSAGE = 0,
104 MEI_ENUM_CLIENTS_MESSAGE,
105 MEI_CLIENT_PROPERTIES_MESSAGE
106};
107
108enum iamthif_states {
109 MEI_IAMTHIF_IDLE,
110 MEI_IAMTHIF_WRITING,
111 MEI_IAMTHIF_FLOW_CONTROL,
112 MEI_IAMTHIF_READING,
113 MEI_IAMTHIF_READ_COMPLETE
114};
115
116enum mei_file_transaction_states {
117 MEI_IDLE,
118 MEI_WRITING,
119 MEI_WRITE_COMPLETE,
120 MEI_FLOW_CONTROL,
121 MEI_READING,
122 MEI_READ_COMPLETE
123};
124
Tomas Winklerc216fde2012-08-16 19:39:43 +0300125enum mei_wd_states {
126 MEI_WD_IDLE,
127 MEI_WD_RUNNING,
128 MEI_WD_STOPPING,
129};
130
Oren Weilab841162011-05-15 13:43:41 +0300131/* MEI CB */
132enum mei_cb_major_types {
133 MEI_READ = 0,
134 MEI_WRITE,
135 MEI_IOCTL,
136 MEI_OPEN,
137 MEI_CLOSE
138};
139
140/*
141 * Intel MEI message data struct
142 */
143struct mei_message_data {
144 u32 size;
Tomas Winkleredf1eed2012-02-09 19:25:54 +0200145 unsigned char *data;
Oren Weilab841162011-05-15 13:43:41 +0300146} __packed;
147
148
149struct mei_cl_cb {
150 struct list_head cb_list;
151 enum mei_cb_major_types major_file_operations;
152 void *file_private;
153 struct mei_message_data request_buffer;
154 struct mei_message_data response_buffer;
155 unsigned long information;
156 unsigned long read_time;
157 struct file *file_object;
158};
159
160/* MEI client instance carried as file->pirvate_data*/
161struct mei_cl {
162 struct list_head link;
163 struct mei_device *dev;
164 enum file_state state;
165 wait_queue_head_t tx_wait;
166 wait_queue_head_t rx_wait;
167 wait_queue_head_t wait;
168 int read_pending;
169 int status;
170 /* ID of client connected */
171 u8 host_client_id;
172 u8 me_client_id;
173 u8 mei_flow_ctrl_creds;
174 u8 timer_count;
175 enum mei_file_transaction_states reading_state;
176 enum mei_file_transaction_states writing_state;
177 int sm_state;
178 struct mei_cl_cb *read_cb;
179};
180
181struct mei_io_list {
182 struct mei_cl_cb mei_cb;
Oren Weilab841162011-05-15 13:43:41 +0300183};
184
Tomas Winkler24aadc82012-06-25 23:46:27 +0300185/**
186 * struct mei_deive - MEI private device struct
187 * @hbuf_depth - depth of host(write) buffer
188 */
Oren Weilab841162011-05-15 13:43:41 +0300189struct mei_device {
190 struct pci_dev *pdev; /* pointer to pci device struct */
191 /*
192 * lists of queues
193 */
194 /* array of pointers to aio lists */
Oren Weilab841162011-05-15 13:43:41 +0300195 struct mei_io_list read_list; /* driver read queue */
196 struct mei_io_list write_list; /* driver write queue */
197 struct mei_io_list write_waiting_list; /* write waiting queue */
198 struct mei_io_list ctrl_wr_list; /* managed write IOCTL list */
199 struct mei_io_list ctrl_rd_list; /* managed read IOCTL list */
200 struct mei_io_list amthi_cmd_list; /* amthi list for cmd waiting */
201
202 /* driver managed amthi list for reading completed amthi cmd data */
203 struct mei_io_list amthi_read_complete_list;
204 /*
205 * list of files
206 */
207 struct list_head file_list;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300208 long open_handle_count;
Oren Weilab841162011-05-15 13:43:41 +0300209 /*
210 * memory of device
211 */
212 unsigned int mem_base;
213 unsigned int mem_length;
214 void __iomem *mem_addr;
215 /*
216 * lock for the device
217 */
218 struct mutex device_lock; /* device lock */
Oren Weila61c6532011-09-07 09:03:13 +0300219 struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300220 bool recvd_msg;
Oren Weilab841162011-05-15 13:43:41 +0300221 /*
222 * hw states of host and fw(ME)
223 */
224 u32 host_hw_state;
225 u32 me_hw_state;
Tomas Winkler24aadc82012-06-25 23:46:27 +0300226 u8 hbuf_depth;
Oren Weilab841162011-05-15 13:43:41 +0300227 /*
228 * waiting queue for receive message from FW
229 */
230 wait_queue_head_t wait_recvd_msg;
231 wait_queue_head_t wait_stop_wd;
232
233 /*
234 * mei device states
235 */
Tomas Winklerb210d752012-08-07 00:03:56 +0300236 enum mei_dev_state dev_state;
Oren Weilab841162011-05-15 13:43:41 +0300237 enum mei_init_clients_states init_clients_state;
238 u16 init_clients_timer;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300239 bool need_reset;
Oren Weilab841162011-05-15 13:43:41 +0300240
241 u32 extra_write_index;
Tomas Winkleredf1eed2012-02-09 19:25:54 +0200242 unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */
Oren Weilab841162011-05-15 13:43:41 +0300243 u32 wr_msg_buf[128]; /* used for control messages */
244 u32 ext_msg_buf[8]; /* for control responses */
245 u32 rd_msg_hdr;
246
247 struct hbm_version version;
248
Oren Weilab841162011-05-15 13:43:41 +0300249 struct mei_me_client *me_clients; /* Note: memory has to be allocated */
250 DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
251 DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
Tomas Winklercf9673d2011-06-06 10:44:33 +0300252 u8 me_clients_num;
Oren Weilab841162011-05-15 13:43:41 +0300253 u8 me_client_presentation_num;
254 u8 me_client_index;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300255 bool mei_host_buffer_is_empty;
Oren Weilab841162011-05-15 13:43:41 +0300256
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300257 struct mei_cl wd_cl;
Tomas Winklerc216fde2012-08-16 19:39:43 +0300258 enum mei_wd_states wd_state;
Tomas Winkler21c66d12012-06-19 09:13:37 +0300259 bool wd_interface_reg;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300260 bool wd_pending;
Tomas Winklerc216fde2012-08-16 19:39:43 +0300261 u16 wd_timeout;
Tomas Winkler248ffdf2012-08-16 19:39:42 +0300262 unsigned char wd_data[MEI_WD_START_MSG_SIZE];
Oren Weilab841162011-05-15 13:43:41 +0300263
264
Oren Weilab841162011-05-15 13:43:41 +0300265 struct file *iamthif_file_object;
266 struct mei_cl iamthif_cl;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300267 struct mei_cl_cb *iamthif_current_cb;
Oren Weilab841162011-05-15 13:43:41 +0300268 int iamthif_mtu;
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;
Oren Weilab841162011-05-15 13:43:41 +0300274 enum iamthif_states iamthif_state;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300275 bool iamthif_flow_control_pending;
276 bool iamthif_ioctl;
277 bool iamthif_canceled;
Oren Weilab841162011-05-15 13:43:41 +0300278};
279
280
281/*
282 * mei init function prototypes
283 */
Tomas Winklerc95efb72011-05-25 17:28:21 +0300284struct mei_device *mei_device_init(struct pci_dev *pdev);
Oren Weilab841162011-05-15 13:43:41 +0300285void mei_reset(struct mei_device *dev, int interrupts);
286int mei_hw_init(struct mei_device *dev);
287int mei_task_initialize_clients(void *data);
288int mei_initialize_clients(struct mei_device *dev);
Oren Weilab841162011-05-15 13:43:41 +0300289int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
Tomas Winkler106fb492011-05-25 17:28:20 +0300290void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id);
Tomas Winklerc95efb72011-05-25 17:28:21 +0300291void mei_host_init_iamthif(struct mei_device *dev);
292void mei_allocate_me_clients_storage(struct mei_device *dev);
Oren Weilab841162011-05-15 13:43:41 +0300293
Oren Weilab841162011-05-15 13:43:41 +0300294
Tomas Winkler07b509b2012-07-23 14:05:39 +0300295int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl,
296 const uuid_le *cguid, u8 host_client_id);
297int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid);
298int mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
Oren Weilab841162011-05-15 13:43:41 +0300299
300/*
Tomas Winkler0288c7c2011-06-06 10:44:34 +0300301 * MEI IO List Functions
302 */
303void mei_io_list_init(struct mei_io_list *list);
304void mei_io_list_flush(struct mei_io_list *list, struct mei_cl *cl);
305
306/*
Tomas Winklerc95efb72011-05-25 17:28:21 +0300307 * MEI ME Client Functions
308 */
309
310struct mei_cl *mei_cl_allocate(struct mei_device *dev);
Tomas Winkler0288c7c2011-06-06 10:44:34 +0300311void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);
312int mei_cl_flush_queues(struct mei_cl *cl);
313/**
314 * mei_cl_cmp_id - tells if file private data have same id
315 *
316 * @fe1: private data of 1. file object
317 * @fe2: private data of 2. file object
318 *
319 * returns true - if ids are the same and not NULL
320 */
321static inline bool mei_cl_cmp_id(const struct mei_cl *cl1,
322 const struct mei_cl *cl2)
323{
324 return cl1 && cl2 &&
325 (cl1->host_client_id == cl2->host_client_id) &&
326 (cl1->me_client_id == cl2->me_client_id);
327}
328
Tomas Winklerc95efb72011-05-25 17:28:21 +0300329
330
331/*
332 * MEI Host Client Functions
333 */
334void mei_host_start_message(struct mei_device *dev);
335void mei_host_enum_clients_message(struct mei_device *dev);
Oren Weilabc51b62011-09-21 16:45:30 +0300336int mei_host_client_properties(struct mei_device *dev);
Tomas Winklerc95efb72011-05-25 17:28:21 +0300337
338/*
339 * MEI interrupt functions prototype
Oren Weilab841162011-05-15 13:43:41 +0300340 */
341irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id);
Tomas Winklerc95efb72011-05-25 17:28:21 +0300342irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id);
Oren Weila61c6532011-09-07 09:03:13 +0300343void mei_timer(struct work_struct *work);
Oren Weilab841162011-05-15 13:43:41 +0300344
345/*
Tomas Winklerc95efb72011-05-25 17:28:21 +0300346 * MEI input output function prototype
Oren Weilab841162011-05-15 13:43:41 +0300347 */
348int mei_ioctl_connect_client(struct file *file,
349 struct mei_connect_client_data *data);
350
351int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
352
353int amthi_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
354
355int amthi_read(struct mei_device *dev, struct file *file,
356 char __user *ubuf, size_t length, loff_t *offset);
357
358struct mei_cl_cb *find_amthi_read_list_entry(struct mei_device *dev,
359 struct file *file);
360
Tomas Winklerc95efb72011-05-25 17:28:21 +0300361void mei_run_next_iamthif_cmd(struct mei_device *dev);
Oren Weilab841162011-05-15 13:43:41 +0300362
363void mei_free_cb_private(struct mei_cl_cb *priv_cb);
364
Oren Weilab841162011-05-15 13:43:41 +0300365
366/*
367 * Register Access Function
368 */
369
370/**
371 * mei_reg_read - Reads 32bit data from the mei device
372 *
373 * @dev: the device structure
374 * @offset: offset from which to read the data
375 *
Oren Weil92eb4012011-09-07 09:03:08 +0300376 * returns register value (u32)
Oren Weilab841162011-05-15 13:43:41 +0300377 */
Tomas Winkler4a0d6a72012-07-04 19:24:49 +0300378static inline u32 mei_reg_read(const struct mei_device *dev,
379 unsigned long offset)
Oren Weilab841162011-05-15 13:43:41 +0300380{
381 return ioread32(dev->mem_addr + offset);
382}
383
384/**
385 * mei_reg_write - Writes 32bit data to the mei device
386 *
387 * @dev: the device structure
388 * @offset: offset from which to write the data
Oren Weil92eb4012011-09-07 09:03:08 +0300389 * @value: register value to write (u32)
Oren Weilab841162011-05-15 13:43:41 +0300390 */
Tomas Winkler4a0d6a72012-07-04 19:24:49 +0300391static inline void mei_reg_write(const struct mei_device *dev,
392 unsigned long offset, u32 value)
Oren Weilab841162011-05-15 13:43:41 +0300393{
394 iowrite32(value, dev->mem_addr + offset);
395}
396
397/**
398 * mei_hcsr_read - Reads 32bit data from the host CSR
399 *
400 * @dev: the device structure
401 *
402 * returns the byte read.
403 */
Tomas Winkler4a0d6a72012-07-04 19:24:49 +0300404static inline u32 mei_hcsr_read(const struct mei_device *dev)
Oren Weilab841162011-05-15 13:43:41 +0300405{
406 return mei_reg_read(dev, H_CSR);
407}
408
409/**
410 * mei_mecsr_read - Reads 32bit data from the ME CSR
411 *
412 * @dev: the device structure
413 *
414 * returns ME_CSR_HA register value (u32)
415 */
Tomas Winkler4a0d6a72012-07-04 19:24:49 +0300416static inline u32 mei_mecsr_read(const struct mei_device *dev)
Oren Weilab841162011-05-15 13:43:41 +0300417{
418 return mei_reg_read(dev, ME_CSR_HA);
419}
420
421/**
422 * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register
423 *
424 * @dev: the device structure
425 *
426 * returns ME_CB_RW register value (u32)
427 */
Tomas Winkler4a0d6a72012-07-04 19:24:49 +0300428static inline u32 mei_mecbrw_read(const struct mei_device *dev)
Oren Weilab841162011-05-15 13:43:41 +0300429{
430 return mei_reg_read(dev, ME_CB_RW);
431}
432
433
434/*
435 * mei interface function prototypes
436 */
437void mei_hcsr_set(struct mei_device *dev);
438void mei_csr_clear_his(struct mei_device *dev);
439
440void mei_enable_interrupts(struct mei_device *dev);
441void mei_disable_interrupts(struct mei_device *dev);
442
Oren Weilab841162011-05-15 13:43:41 +0300443#endif