blob: d60250d663c69579540ad68dd62c7d83c6b2f594 [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 */
81enum mei_states {
82 MEI_INITIALIZING = 0,
83 MEI_INIT_CLIENTS,
84 MEI_ENABLED,
85 MEI_RESETING,
86 MEI_DISABLED,
87 MEI_RECOVERING_FROM_RESET,
88 MEI_POWER_DOWN,
89 MEI_POWER_UP
90};
91
Justin P. Mattock5f9092f2012-03-12 07:18:09 -070092/* init clients states*/
Oren Weilab841162011-05-15 13:43:41 +030093enum mei_init_clients_states {
94 MEI_START_MESSAGE = 0,
95 MEI_ENUM_CLIENTS_MESSAGE,
96 MEI_CLIENT_PROPERTIES_MESSAGE
97};
98
99enum iamthif_states {
100 MEI_IAMTHIF_IDLE,
101 MEI_IAMTHIF_WRITING,
102 MEI_IAMTHIF_FLOW_CONTROL,
103 MEI_IAMTHIF_READING,
104 MEI_IAMTHIF_READ_COMPLETE
105};
106
107enum mei_file_transaction_states {
108 MEI_IDLE,
109 MEI_WRITING,
110 MEI_WRITE_COMPLETE,
111 MEI_FLOW_CONTROL,
112 MEI_READING,
113 MEI_READ_COMPLETE
114};
115
116/* MEI CB */
117enum mei_cb_major_types {
118 MEI_READ = 0,
119 MEI_WRITE,
120 MEI_IOCTL,
121 MEI_OPEN,
122 MEI_CLOSE
123};
124
125/*
126 * Intel MEI message data struct
127 */
128struct mei_message_data {
129 u32 size;
Tomas Winkleredf1eed2012-02-09 19:25:54 +0200130 unsigned char *data;
Oren Weilab841162011-05-15 13:43:41 +0300131} __packed;
132
133
134struct mei_cl_cb {
135 struct list_head cb_list;
136 enum mei_cb_major_types major_file_operations;
137 void *file_private;
138 struct mei_message_data request_buffer;
139 struct mei_message_data response_buffer;
140 unsigned long information;
141 unsigned long read_time;
142 struct file *file_object;
143};
144
145/* MEI client instance carried as file->pirvate_data*/
146struct mei_cl {
147 struct list_head link;
148 struct mei_device *dev;
149 enum file_state state;
150 wait_queue_head_t tx_wait;
151 wait_queue_head_t rx_wait;
152 wait_queue_head_t wait;
153 int read_pending;
154 int status;
155 /* ID of client connected */
156 u8 host_client_id;
157 u8 me_client_id;
158 u8 mei_flow_ctrl_creds;
159 u8 timer_count;
160 enum mei_file_transaction_states reading_state;
161 enum mei_file_transaction_states writing_state;
162 int sm_state;
163 struct mei_cl_cb *read_cb;
164};
165
166struct mei_io_list {
167 struct mei_cl_cb mei_cb;
Oren Weilab841162011-05-15 13:43:41 +0300168};
169
Tomas Winkler24aadc82012-06-25 23:46:27 +0300170/**
171 * struct mei_deive - MEI private device struct
172 * @hbuf_depth - depth of host(write) buffer
173 */
Oren Weilab841162011-05-15 13:43:41 +0300174struct mei_device {
175 struct pci_dev *pdev; /* pointer to pci device struct */
176 /*
177 * lists of queues
178 */
179 /* array of pointers to aio lists */
Oren Weilab841162011-05-15 13:43:41 +0300180 struct mei_io_list read_list; /* driver read queue */
181 struct mei_io_list write_list; /* driver write queue */
182 struct mei_io_list write_waiting_list; /* write waiting queue */
183 struct mei_io_list ctrl_wr_list; /* managed write IOCTL list */
184 struct mei_io_list ctrl_rd_list; /* managed read IOCTL list */
185 struct mei_io_list amthi_cmd_list; /* amthi list for cmd waiting */
186
187 /* driver managed amthi list for reading completed amthi cmd data */
188 struct mei_io_list amthi_read_complete_list;
189 /*
190 * list of files
191 */
192 struct list_head file_list;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300193 long open_handle_count;
Oren Weilab841162011-05-15 13:43:41 +0300194 /*
195 * memory of device
196 */
197 unsigned int mem_base;
198 unsigned int mem_length;
199 void __iomem *mem_addr;
200 /*
201 * lock for the device
202 */
203 struct mutex device_lock; /* device lock */
Oren Weila61c6532011-09-07 09:03:13 +0300204 struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300205 bool recvd_msg;
Oren Weilab841162011-05-15 13:43:41 +0300206 /*
207 * hw states of host and fw(ME)
208 */
209 u32 host_hw_state;
210 u32 me_hw_state;
Tomas Winkler24aadc82012-06-25 23:46:27 +0300211 u8 hbuf_depth;
Oren Weilab841162011-05-15 13:43:41 +0300212 /*
213 * waiting queue for receive message from FW
214 */
215 wait_queue_head_t wait_recvd_msg;
216 wait_queue_head_t wait_stop_wd;
217
218 /*
219 * mei device states
220 */
221 enum mei_states mei_state;
222 enum mei_init_clients_states init_clients_state;
223 u16 init_clients_timer;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300224 bool stop;
225 bool need_reset;
Oren Weilab841162011-05-15 13:43:41 +0300226
227 u32 extra_write_index;
Tomas Winkleredf1eed2012-02-09 19:25:54 +0200228 unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */
Oren Weilab841162011-05-15 13:43:41 +0300229 u32 wr_msg_buf[128]; /* used for control messages */
230 u32 ext_msg_buf[8]; /* for control responses */
231 u32 rd_msg_hdr;
232
233 struct hbm_version version;
234
Oren Weilab841162011-05-15 13:43:41 +0300235 struct mei_me_client *me_clients; /* Note: memory has to be allocated */
236 DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
237 DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
Tomas Winklercf9673d2011-06-06 10:44:33 +0300238 u8 me_clients_num;
Oren Weilab841162011-05-15 13:43:41 +0300239 u8 me_client_presentation_num;
240 u8 me_client_index;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300241 bool mei_host_buffer_is_empty;
Oren Weilab841162011-05-15 13:43:41 +0300242
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300243 struct mei_cl wd_cl;
Tomas Winkler21c66d12012-06-19 09:13:37 +0300244 bool wd_interface_reg;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300245 bool wd_pending;
246 bool wd_stopped;
247 bool wd_bypass; /* if false, don't refresh watchdog ME client */
Oren Weilab841162011-05-15 13:43:41 +0300248 u16 wd_timeout; /* seconds ((wd_data[1] << 8) + wd_data[0]) */
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300249 u16 wd_due_counter;
Oren Weilab841162011-05-15 13:43:41 +0300250 unsigned char wd_data[MEI_START_WD_DATA_SIZE];
251
252
Oren Weilab841162011-05-15 13:43:41 +0300253 struct file *iamthif_file_object;
254 struct mei_cl iamthif_cl;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300255 struct mei_cl_cb *iamthif_current_cb;
Oren Weilab841162011-05-15 13:43:41 +0300256 int iamthif_mtu;
257 unsigned long iamthif_timer;
258 u32 iamthif_stall_timer;
259 unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */
260 u32 iamthif_msg_buf_size;
261 u32 iamthif_msg_buf_index;
Oren Weilab841162011-05-15 13:43:41 +0300262 enum iamthif_states iamthif_state;
Tomas Winklereb9af0a2011-05-25 17:28:22 +0300263 bool iamthif_flow_control_pending;
264 bool iamthif_ioctl;
265 bool iamthif_canceled;
Oren Weilab841162011-05-15 13:43:41 +0300266};
267
268
269/*
270 * mei init function prototypes
271 */
Tomas Winklerc95efb72011-05-25 17:28:21 +0300272struct mei_device *mei_device_init(struct pci_dev *pdev);
Oren Weilab841162011-05-15 13:43:41 +0300273void mei_reset(struct mei_device *dev, int interrupts);
274int mei_hw_init(struct mei_device *dev);
275int mei_task_initialize_clients(void *data);
276int mei_initialize_clients(struct mei_device *dev);
Oren Weilab841162011-05-15 13:43:41 +0300277int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
Tomas Winkler106fb492011-05-25 17:28:20 +0300278void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id);
Tomas Winklerc95efb72011-05-25 17:28:21 +0300279void mei_host_init_iamthif(struct mei_device *dev);
280void mei_allocate_me_clients_storage(struct mei_device *dev);
Oren Weilab841162011-05-15 13:43:41 +0300281
Oren Weilab841162011-05-15 13:43:41 +0300282
283u8 mei_find_me_client_update_filext(struct mei_device *dev,
284 struct mei_cl *priv,
285 const uuid_le *cguid, u8 client_id);
286
287/*
Tomas Winkler0288c7c2011-06-06 10:44:34 +0300288 * MEI IO List Functions
289 */
290void mei_io_list_init(struct mei_io_list *list);
291void mei_io_list_flush(struct mei_io_list *list, struct mei_cl *cl);
292
293/*
Tomas Winklerc95efb72011-05-25 17:28:21 +0300294 * MEI ME Client Functions
295 */
296
297struct mei_cl *mei_cl_allocate(struct mei_device *dev);
Tomas Winkler0288c7c2011-06-06 10:44:34 +0300298void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);
299int mei_cl_flush_queues(struct mei_cl *cl);
300/**
301 * mei_cl_cmp_id - tells if file private data have same id
302 *
303 * @fe1: private data of 1. file object
304 * @fe2: private data of 2. file object
305 *
306 * returns true - if ids are the same and not NULL
307 */
308static inline bool mei_cl_cmp_id(const struct mei_cl *cl1,
309 const struct mei_cl *cl2)
310{
311 return cl1 && cl2 &&
312 (cl1->host_client_id == cl2->host_client_id) &&
313 (cl1->me_client_id == cl2->me_client_id);
314}
315
Tomas Winklerc95efb72011-05-25 17:28:21 +0300316
317
318/*
319 * MEI Host Client Functions
320 */
321void mei_host_start_message(struct mei_device *dev);
322void mei_host_enum_clients_message(struct mei_device *dev);
Oren Weilabc51b62011-09-21 16:45:30 +0300323int mei_host_client_properties(struct mei_device *dev);
Tomas Winklerc95efb72011-05-25 17:28:21 +0300324
325/*
326 * MEI interrupt functions prototype
Oren Weilab841162011-05-15 13:43:41 +0300327 */
328irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id);
Tomas Winklerc95efb72011-05-25 17:28:21 +0300329irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id);
Oren Weila61c6532011-09-07 09:03:13 +0300330void mei_timer(struct work_struct *work);
Oren Weilab841162011-05-15 13:43:41 +0300331
332/*
Tomas Winklerc95efb72011-05-25 17:28:21 +0300333 * MEI input output function prototype
Oren Weilab841162011-05-15 13:43:41 +0300334 */
335int mei_ioctl_connect_client(struct file *file,
336 struct mei_connect_client_data *data);
337
338int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
339
340int amthi_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
341
342int amthi_read(struct mei_device *dev, struct file *file,
343 char __user *ubuf, size_t length, loff_t *offset);
344
345struct mei_cl_cb *find_amthi_read_list_entry(struct mei_device *dev,
346 struct file *file);
347
Tomas Winklerc95efb72011-05-25 17:28:21 +0300348void mei_run_next_iamthif_cmd(struct mei_device *dev);
Oren Weilab841162011-05-15 13:43:41 +0300349
350void mei_free_cb_private(struct mei_cl_cb *priv_cb);
351
352int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid);
353
354/*
355 * Register Access Function
356 */
357
358/**
359 * mei_reg_read - Reads 32bit data from the mei device
360 *
361 * @dev: the device structure
362 * @offset: offset from which to read the data
363 *
Oren Weil92eb4012011-09-07 09:03:08 +0300364 * returns register value (u32)
Oren Weilab841162011-05-15 13:43:41 +0300365 */
Tomas Winkler106fb492011-05-25 17:28:20 +0300366static inline u32 mei_reg_read(struct mei_device *dev, unsigned long offset)
Oren Weilab841162011-05-15 13:43:41 +0300367{
368 return ioread32(dev->mem_addr + offset);
369}
370
371/**
372 * mei_reg_write - Writes 32bit data to the mei device
373 *
374 * @dev: the device structure
375 * @offset: offset from which to write the data
Oren Weil92eb4012011-09-07 09:03:08 +0300376 * @value: register value to write (u32)
Oren Weilab841162011-05-15 13:43:41 +0300377 */
378static inline void mei_reg_write(struct mei_device *dev,
379 unsigned long offset, u32 value)
380{
381 iowrite32(value, dev->mem_addr + offset);
382}
383
384/**
385 * mei_hcsr_read - Reads 32bit data from the host CSR
386 *
387 * @dev: the device structure
388 *
389 * returns the byte read.
390 */
391static inline u32 mei_hcsr_read(struct mei_device *dev)
392{
393 return mei_reg_read(dev, H_CSR);
394}
395
396/**
397 * mei_mecsr_read - Reads 32bit data from the ME CSR
398 *
399 * @dev: the device structure
400 *
401 * returns ME_CSR_HA register value (u32)
402 */
403static inline u32 mei_mecsr_read(struct mei_device *dev)
404{
405 return mei_reg_read(dev, ME_CSR_HA);
406}
407
408/**
409 * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register
410 *
411 * @dev: the device structure
412 *
413 * returns ME_CB_RW register value (u32)
414 */
415static inline u32 mei_mecbrw_read(struct mei_device *dev)
416{
417 return mei_reg_read(dev, ME_CB_RW);
418}
419
420
421/*
422 * mei interface function prototypes
423 */
424void mei_hcsr_set(struct mei_device *dev);
425void mei_csr_clear_his(struct mei_device *dev);
426
427void mei_enable_interrupts(struct mei_device *dev);
428void mei_disable_interrupts(struct mei_device *dev);
429
Oren Weilab841162011-05-15 13:43:41 +0300430#endif