pandora: defconfig: update
[pandora-kernel.git] / drivers / staging / mei / mei_dev.h
1 /*
2  *
3  * Intel Management Engine Interface (Intel MEI) Linux driver
4  * Copyright (c) 2003-2011, Intel Corporation.
5  *
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>
21 #include <linux/watchdog.h>
22 #include "mei.h"
23 #include "hw.h"
24
25 /*
26  * MEI Char Driver Minors
27  */
28 #define MEI_MINORS_BASE 1
29 #define MEI_MINORS_COUNT        1
30 #define MEI_MINOR_NUMBER        1
31
32 /*
33  * watch dog definition
34  */
35 #define MEI_WATCHDOG_DATA_SIZE         16
36 #define MEI_START_WD_DATA_SIZE         20
37 #define MEI_WD_PARAMS_SIZE             4
38 #define MEI_WD_STATE_INDEPENDENCE_MSG_SENT       (1 << 0)
39
40 /*
41  * MEI PCI Device object
42  */
43 extern struct pci_dev *mei_device;
44
45 /*
46  * AMT Watchdog Device
47  */
48 #define INTEL_AMT_WATCHDOG_ID "INTCAMT"
49 extern struct watchdog_device amt_wd_dev;
50
51 /*
52  * AMTHI Client UUID
53  */
54 extern const uuid_le mei_amthi_guid;
55
56 /*
57  * Watchdog Client UUID
58  */
59 extern const uuid_le mei_wd_guid;
60
61 /*
62  * Watchdog independence state message
63  */
64 extern const u8 mei_wd_state_independence_msg[3][4];
65
66 /*
67  * maximum number of consecutive resets
68  */
69 #define MEI_MAX_CONSEC_RESET  3
70
71 /*
72  * Number of File descriptors/handles
73  * that can be opened to the driver.
74  *
75  * Limit to 253: 255 Total Clients
76  * minus internal client for AMTHI
77  * minus internal client for Watchdog
78  */
79 #define  MEI_MAX_OPEN_HANDLE_COUNT      253
80
81 /*
82  * Number of Maximum MEI Clients
83  */
84 #define MEI_CLIENTS_MAX 255
85
86 /* File state */
87 enum file_state {
88         MEI_FILE_INITIALIZING = 0,
89         MEI_FILE_CONNECTING,
90         MEI_FILE_CONNECTED,
91         MEI_FILE_DISCONNECTING,
92         MEI_FILE_DISCONNECTED
93 };
94
95 /* MEI device states */
96 enum mei_states {
97         MEI_INITIALIZING = 0,
98         MEI_INIT_CLIENTS,
99         MEI_ENABLED,
100         MEI_RESETING,
101         MEI_DISABLED,
102         MEI_RECOVERING_FROM_RESET,
103         MEI_POWER_DOWN,
104         MEI_POWER_UP
105 };
106
107 /* init clients  states*/
108 enum mei_init_clients_states {
109         MEI_START_MESSAGE = 0,
110         MEI_ENUM_CLIENTS_MESSAGE,
111         MEI_CLIENT_PROPERTIES_MESSAGE
112 };
113
114 enum iamthif_states {
115         MEI_IAMTHIF_IDLE,
116         MEI_IAMTHIF_WRITING,
117         MEI_IAMTHIF_FLOW_CONTROL,
118         MEI_IAMTHIF_READING,
119         MEI_IAMTHIF_READ_COMPLETE
120 };
121
122 enum mei_file_transaction_states {
123         MEI_IDLE,
124         MEI_WRITING,
125         MEI_WRITE_COMPLETE,
126         MEI_FLOW_CONTROL,
127         MEI_READING,
128         MEI_READ_COMPLETE
129 };
130
131 /* MEI CB */
132 enum 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  */
143 struct mei_message_data {
144         u32 size;
145         char *data;
146 } __packed;
147
148
149 struct 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*/
161 struct 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
181 struct mei_io_list {
182         struct mei_cl_cb mei_cb;
183         int status;
184 };
185
186 /**
187  * mei_device - MEI private device struct
188  *
189  * @reset_count - limits the number of consecutive resets
190  */
191 struct mei_device {
192         struct pci_dev *pdev;   /* pointer to pci device struct */
193         /*
194          * lists of queues
195          */
196          /* array of pointers to aio lists */
197         struct mei_io_list read_list;           /* driver read queue */
198         struct mei_io_list write_list;          /* driver write queue */
199         struct mei_io_list write_waiting_list;  /* write waiting queue */
200         struct mei_io_list ctrl_wr_list;        /* managed write IOCTL list */
201         struct mei_io_list ctrl_rd_list;        /* managed read IOCTL list */
202         struct mei_io_list amthi_cmd_list;      /* amthi list for cmd waiting */
203
204         /* driver managed amthi list for reading completed amthi cmd data */
205         struct mei_io_list amthi_read_complete_list;
206         /*
207          * list of files
208          */
209         struct list_head file_list;
210         long open_handle_count;
211         /*
212          * memory of device
213          */
214         unsigned int mem_base;
215         unsigned int mem_length;
216         void __iomem *mem_addr;
217         /*
218          * lock for the device
219          */
220         struct mutex device_lock; /* device lock */
221         struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */
222         bool recvd_msg;
223         /*
224          * hw states of host and fw(ME)
225          */
226         u32 host_hw_state;
227         u32 me_hw_state;
228         /*
229          * waiting queue for receive message from FW
230          */
231         wait_queue_head_t wait_recvd_msg;
232         wait_queue_head_t wait_stop_wd;
233
234         /*
235          * mei device  states
236          */
237         unsigned long reset_count;
238         enum mei_states mei_state;
239         enum mei_init_clients_states init_clients_state;
240         u16 init_clients_timer;
241         bool stop;
242         bool need_reset;
243
244         u32 extra_write_index;
245         u32 rd_msg_buf[128];    /* used for control messages */
246         u32 wr_msg_buf[128];    /* used for control messages */
247         u32 ext_msg_buf[8];     /* for control responses */
248         u32 rd_msg_hdr;
249
250         struct hbm_version version;
251
252         struct mei_me_client *me_clients; /* Note: memory has to be allocated */
253         DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
254         DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
255         u8 me_clients_num;
256         u8 me_client_presentation_num;
257         u8 me_client_index;
258         bool mei_host_buffer_is_empty;
259
260         struct mei_cl wd_cl;
261         bool wd_pending;
262         bool wd_stopped;
263         bool wd_bypass; /* if false, don't refresh watchdog ME client */
264         u16 wd_timeout; /* seconds ((wd_data[1] << 8) + wd_data[0]) */
265         u16 wd_due_counter;
266         unsigned char wd_data[MEI_START_WD_DATA_SIZE];
267
268
269
270         struct file *iamthif_file_object;
271         struct mei_cl iamthif_cl;
272         struct mei_cl_cb *iamthif_current_cb;
273         int iamthif_mtu;
274         unsigned long iamthif_timer;
275         u32 iamthif_stall_timer;
276         unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */
277         u32 iamthif_msg_buf_size;
278         u32 iamthif_msg_buf_index;
279         enum iamthif_states iamthif_state;
280         bool iamthif_flow_control_pending;
281         bool iamthif_ioctl;
282         bool iamthif_canceled;
283
284         bool wd_interface_reg;
285 };
286
287
288 /*
289  * mei init function prototypes
290  */
291 struct mei_device *mei_device_init(struct pci_dev *pdev);
292 void mei_reset(struct mei_device *dev, int interrupts);
293 int mei_hw_init(struct mei_device *dev);
294 int mei_task_initialize_clients(void *data);
295 int mei_initialize_clients(struct mei_device *dev);
296 int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
297 void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id);
298 void mei_host_init_iamthif(struct mei_device *dev);
299 void mei_allocate_me_clients_storage(struct mei_device *dev);
300
301
302 u8 mei_find_me_client_update_filext(struct mei_device *dev,
303                                 struct mei_cl *priv,
304                                 const uuid_le *cguid, u8 client_id);
305
306 /*
307  * MEI IO List Functions
308  */
309 void mei_io_list_init(struct mei_io_list *list);
310 void mei_io_list_flush(struct mei_io_list *list, struct mei_cl *cl);
311
312 /*
313  * MEI ME Client Functions
314  */
315
316 struct mei_cl *mei_cl_allocate(struct mei_device *dev);
317 void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);
318 int mei_cl_flush_queues(struct mei_cl *cl);
319 /**
320  * mei_cl_cmp_id - tells if file private data have same id
321  *
322  * @fe1: private data of 1. file object
323  * @fe2: private data of 2. file object
324  *
325  * returns true  - if ids are the same and not NULL
326  */
327 static inline bool mei_cl_cmp_id(const struct mei_cl *cl1,
328                                 const struct mei_cl *cl2)
329 {
330         return cl1 && cl2 &&
331                 (cl1->host_client_id == cl2->host_client_id) &&
332                 (cl1->me_client_id == cl2->me_client_id);
333 }
334
335
336
337 /*
338  * MEI Host Client Functions
339  */
340 void mei_host_start_message(struct mei_device *dev);
341 void mei_host_enum_clients_message(struct mei_device *dev);
342 int mei_host_client_properties(struct mei_device *dev);
343
344 /*
345  *  MEI interrupt functions prototype
346  */
347 irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id);
348 irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id);
349 void mei_timer(struct work_struct *work);
350
351 /*
352  *  MEI input output function prototype
353  */
354 int mei_ioctl_connect_client(struct file *file,
355                         struct mei_connect_client_data *data);
356
357 int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
358
359 int amthi_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
360
361 int amthi_read(struct mei_device *dev, struct file *file,
362               char __user *ubuf, size_t length, loff_t *offset);
363
364 struct mei_cl_cb *find_amthi_read_list_entry(struct mei_device *dev,
365                                                 struct file *file);
366
367 void mei_run_next_iamthif_cmd(struct mei_device *dev);
368
369 void mei_free_cb_private(struct mei_cl_cb *priv_cb);
370
371 int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid);
372
373 /*
374  * Register Access Function
375  */
376
377 /**
378  * mei_reg_read - Reads 32bit data from the mei device
379  *
380  * @dev: the device structure
381  * @offset: offset from which to read the data
382  *
383  * returns register value (u32)
384  */
385 static inline u32 mei_reg_read(struct mei_device *dev, unsigned long offset)
386 {
387         return ioread32(dev->mem_addr + offset);
388 }
389
390 /**
391  * mei_reg_write - Writes 32bit data to the mei device
392  *
393  * @dev: the device structure
394  * @offset: offset from which to write the data
395  * @value: register value to write (u32)
396  */
397 static inline void mei_reg_write(struct mei_device *dev,
398                                 unsigned long offset, u32 value)
399 {
400         iowrite32(value, dev->mem_addr + offset);
401 }
402
403 /**
404  * mei_hcsr_read - Reads 32bit data from the host CSR
405  *
406  * @dev: the device structure
407  *
408  * returns the byte read.
409  */
410 static inline u32 mei_hcsr_read(struct mei_device *dev)
411 {
412         return mei_reg_read(dev, H_CSR);
413 }
414
415 /**
416  * mei_mecsr_read - Reads 32bit data from the ME CSR
417  *
418  * @dev: the device structure
419  *
420  * returns ME_CSR_HA register value (u32)
421  */
422 static inline u32 mei_mecsr_read(struct mei_device *dev)
423 {
424         return mei_reg_read(dev, ME_CSR_HA);
425 }
426
427 /**
428  * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register
429  *
430  * @dev: the device structure
431  *
432  * returns ME_CB_RW register value (u32)
433  */
434 static inline u32 mei_mecbrw_read(struct mei_device *dev)
435 {
436         return mei_reg_read(dev, ME_CB_RW);
437 }
438
439
440 /*
441  * mei interface function prototypes
442  */
443 void mei_hcsr_set(struct mei_device *dev);
444 void mei_csr_clear_his(struct mei_device *dev);
445
446 void mei_enable_interrupts(struct mei_device *dev);
447 void mei_disable_interrupts(struct mei_device *dev);
448
449 #endif