staging: mei: mei_dev - use type bool instead of int
[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 "mei.h"
22 #include "hw.h"
23
24 /*
25  * MEI Char Driver Minors
26  */
27 #define MEI_MINORS_BASE 1
28 #define MEI_MINORS_COUNT        1
29 #define MEI_MINOR_NUMBER        1
30
31 /*
32  * watch dog definition
33  */
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)
38
39 /*
40  * AMTHI Client UUID
41  */
42 extern const uuid_le mei_amthi_guid;
43
44 /*
45  * Watchdog Client UUID
46  */
47 extern const uuid_le mei_wd_guid;
48
49 /*
50  * Watchdog independence state message
51  */
52 extern const u8 mei_wd_state_independence_msg[3][4];
53
54 /*
55  * Number of File descriptors/handles
56  * that can be opened to the driver.
57  *
58  * Limit to 253: 255 Total Clients
59  * minus internal client for AMTHI
60  * minus internal client for Watchdog
61  */
62 #define  MEI_MAX_OPEN_HANDLE_COUNT      253
63
64 /*
65  * Number of queue lists used by this driver
66  */
67 #define MEI_IO_LISTS_NUMBER        7
68
69 /*
70  * Number of Maximum MEI Clients
71  */
72 #define MEI_CLIENTS_MAX 255
73
74 /* File state */
75 enum file_state {
76         MEI_FILE_INITIALIZING = 0,
77         MEI_FILE_CONNECTING,
78         MEI_FILE_CONNECTED,
79         MEI_FILE_DISCONNECTING,
80         MEI_FILE_DISCONNECTED
81 };
82
83 /* MEI device states */
84 enum mei_states {
85         MEI_INITIALIZING = 0,
86         MEI_INIT_CLIENTS,
87         MEI_ENABLED,
88         MEI_RESETING,
89         MEI_DISABLED,
90         MEI_RECOVERING_FROM_RESET,
91         MEI_POWER_DOWN,
92         MEI_POWER_UP
93 };
94
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
100 };
101
102 enum iamthif_states {
103         MEI_IAMTHIF_IDLE,
104         MEI_IAMTHIF_WRITING,
105         MEI_IAMTHIF_FLOW_CONTROL,
106         MEI_IAMTHIF_READING,
107         MEI_IAMTHIF_READ_COMPLETE
108 };
109
110 enum mei_file_transaction_states {
111         MEI_IDLE,
112         MEI_WRITING,
113         MEI_WRITE_COMPLETE,
114         MEI_FLOW_CONTROL,
115         MEI_READING,
116         MEI_READ_COMPLETE
117 };
118
119 /* MEI CB */
120 enum mei_cb_major_types {
121         MEI_READ = 0,
122         MEI_WRITE,
123         MEI_IOCTL,
124         MEI_OPEN,
125         MEI_CLOSE
126 };
127
128 /*
129  * Intel MEI message data struct
130  */
131 struct mei_message_data {
132         u32 size;
133         char *data;
134 } __packed;
135
136
137 struct mei_cl_cb {
138         struct list_head cb_list;
139         enum mei_cb_major_types major_file_operations;
140         void *file_private;
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;
146 };
147
148 /* MEI client instance carried as file->pirvate_data*/
149 struct mei_cl {
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;
156         int read_pending;
157         int status;
158         /* ID of client connected */
159         u8 host_client_id;
160         u8 me_client_id;
161         u8 mei_flow_ctrl_creds;
162         u8 timer_count;
163         enum mei_file_transaction_states reading_state;
164         enum mei_file_transaction_states writing_state;
165         int sm_state;
166         struct mei_cl_cb *read_cb;
167 };
168
169 struct mei_io_list {
170         struct mei_cl_cb mei_cb;
171         int status;
172         struct mei_device *device_extension;
173 };
174
175 /* MEI private device struct */
176 struct 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 */
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 */
189
190         /* driver managed amthi list for reading completed amthi cmd data */
191         struct mei_io_list amthi_read_complete_list;
192         /*
193          * list of files
194          */
195         struct list_head file_list;
196         long open_handle_count;
197         /*
198          * memory of device
199          */
200         unsigned int mem_base;
201         unsigned int mem_length;
202         void __iomem *mem_addr;
203         /*
204          * lock for the device
205          */
206         struct mutex device_lock; /* device lock */
207         struct delayed_work wd_work;    /* watch dog deleye work */
208         bool recvd_msg;
209         /*
210          * hw states of host and fw(ME)
211          */
212         u32 host_hw_state;
213         u32 me_hw_state;
214         /*
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          */
223         enum mei_states mei_state;
224         enum mei_init_clients_states init_clients_state;
225         u16 init_clients_timer;
226         bool stop;
227         bool need_reset;
228
229         u32 extra_write_index;
230         u32 rd_msg_buf[128];    /* used for control messages */
231         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
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;
242         u8 me_client_index;
243         bool mei_host_buffer_is_empty;
244
245         struct mei_cl wd_cl;
246         bool wd_pending;
247         bool wd_stopped;
248         bool wd_bypass; /* if false, don't refresh watchdog ME client */
249         u16 wd_timeout; /* seconds ((wd_data[1] << 8) + wd_data[0]) */
250         u16 wd_due_counter;
251         unsigned char wd_data[MEI_START_WD_DATA_SIZE];
252
253
254
255         struct file *iamthif_file_object;
256         struct mei_cl iamthif_cl;
257         struct mei_cl_cb *iamthif_current_cb;
258         int iamthif_mtu;
259         unsigned long iamthif_timer;
260         u32 iamthif_stall_timer;
261         unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */
262         u32 iamthif_msg_buf_size;
263         u32 iamthif_msg_buf_index;
264         enum iamthif_states iamthif_state;
265         bool iamthif_flow_control_pending;
266         bool iamthif_ioctl;
267         bool iamthif_canceled;
268         u8 write_hang;
269 };
270
271
272 /*
273  * mei init function prototypes
274  */
275 struct mei_device *mei_device_init(struct pci_dev *pdev);
276 void mei_reset(struct mei_device *dev, int interrupts);
277 int mei_hw_init(struct mei_device *dev);
278 int mei_task_initialize_clients(void *data);
279 int mei_initialize_clients(struct mei_device *dev);
280 int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
281 void mei_initialize_list(struct mei_io_list *list, struct mei_device *dev);
282 void mei_flush_list(struct mei_io_list *list, struct mei_cl *cl);
283 void mei_flush_queues(struct mei_device *dev, struct mei_cl *cl);
284 void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id);
285 void mei_host_init_iamthif(struct mei_device *dev);
286 void mei_allocate_me_clients_storage(struct mei_device *dev);
287
288
289 u8 mei_find_me_client_update_filext(struct mei_device *dev,
290                                 struct mei_cl *priv,
291                                 const uuid_le *cguid, u8 client_id);
292
293 /*
294  * MEI ME Client Functions
295  */
296
297 struct mei_cl *mei_cl_allocate(struct mei_device *dev);
298 void mei_cl_init(struct mei_cl *priv, struct mei_device *dev);
299
300
301 /*
302  * MEI Host Client Functions
303  */
304 void mei_host_start_message(struct mei_device *dev);
305 void mei_host_enum_clients_message(struct mei_device *dev);
306 void mei_host_client_properties(struct mei_device *dev);
307
308 /*
309  *  MEI interrupt functions prototype
310  */
311 irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id);
312 irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id);
313 void mei_wd_timer(struct work_struct *work);
314
315 /*
316  *  MEI input output function prototype
317  */
318 int mei_ioctl_connect_client(struct file *file,
319                         struct mei_connect_client_data *data);
320
321 int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
322
323 int amthi_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
324
325 int amthi_read(struct mei_device *dev, struct file *file,
326               char __user *ubuf, size_t length, loff_t *offset);
327
328 struct mei_cl_cb *find_amthi_read_list_entry(struct mei_device *dev,
329                                                 struct file *file);
330
331 void mei_run_next_iamthif_cmd(struct mei_device *dev);
332
333 void mei_free_cb_private(struct mei_cl_cb *priv_cb);
334
335 int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid);
336
337 /*
338  * Register Access Function
339  */
340
341 /**
342  * mei_reg_read - Reads 32bit data from the mei device
343  *
344  * @dev: the device structure
345  * @offset: offset from which to read the data
346  *
347  * returns the byte read.
348  */
349 static inline u32 mei_reg_read(struct mei_device *dev, unsigned long offset)
350 {
351         return ioread32(dev->mem_addr + offset);
352 }
353
354 /**
355  * mei_reg_write - Writes 32bit data to the mei device
356  *
357  * @dev: the device structure
358  * @offset: offset from which to write the data
359  * @value: the byte to write
360  */
361 static inline void mei_reg_write(struct mei_device *dev,
362                                 unsigned long offset, u32 value)
363 {
364         iowrite32(value, dev->mem_addr + offset);
365 }
366
367 /**
368  * mei_hcsr_read - Reads 32bit data from the host CSR
369  *
370  * @dev: the device structure
371  *
372  * returns the byte read.
373  */
374 static inline u32 mei_hcsr_read(struct mei_device *dev)
375 {
376         return mei_reg_read(dev, H_CSR);
377 }
378
379 /**
380  * mei_mecsr_read - Reads 32bit data from the ME CSR
381  *
382  * @dev: the device structure
383  *
384  * returns ME_CSR_HA register value (u32)
385  */
386 static inline u32 mei_mecsr_read(struct mei_device *dev)
387 {
388         return mei_reg_read(dev, ME_CSR_HA);
389 }
390
391 /**
392  * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register
393  *
394  * @dev: the device structure
395  *
396  * returns ME_CB_RW register value (u32)
397  */
398 static inline u32 mei_mecbrw_read(struct mei_device *dev)
399 {
400         return mei_reg_read(dev, ME_CB_RW);
401 }
402
403
404 /*
405  * mei interface function prototypes
406  */
407 void mei_hcsr_set(struct mei_device *dev);
408 void mei_csr_clear_his(struct mei_device *dev);
409
410 void mei_enable_interrupts(struct mei_device *dev);
411 void mei_disable_interrupts(struct mei_device *dev);
412
413 /**
414  * mei_fe_same_id - tells if file private data have same id
415  *
416  * @fe1: private data of 1. file object
417  * @fe2: private data of 2. file object
418  *
419  * returns !=0 - if ids are the same, 0 - if differ.
420  */
421 static inline int mei_fe_same_id(const struct mei_cl *fe1,
422                                   const struct mei_cl *fe2)
423 {
424         return ((fe1->host_client_id == fe2->host_client_id) &&
425                 (fe1->me_client_id == fe2->me_client_id));
426 }
427
428 #endif