staging: mei: fix mei driver namespace
[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         /*
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 */
206         int recvd_msg;
207         struct delayed_work wd_work;    /* watch dog deleye work */
208         /*
209          * hw states of host and fw(ME)
210          */
211         u32 host_hw_state;
212         u32 me_hw_state;
213         /*
214          * waiting queue for receive message from FW
215          */
216         wait_queue_head_t wait_recvd_msg;
217         wait_queue_head_t wait_stop_wd;
218
219         /*
220          * mei device  states
221          */
222         enum mei_states mei_state;
223         enum mei_init_clients_states init_clients_state;
224         u16 init_clients_timer;
225         int stop;
226
227         u32 extra_write_index;
228         u32 rd_msg_buf[128];    /* used for control messages */
229         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
235         int mei_host_buffer_is_empty;
236         struct mei_cl wd_cl;
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
244         int wd_pending;
245         int wd_stopped;
246         u16 wd_timeout; /* seconds ((wd_data[1] << 8) + wd_data[0]) */
247         unsigned char wd_data[MEI_START_WD_DATA_SIZE];
248
249
250         u16 wd_due_counter;
251         bool wd_bypass; /* if false, don't refresh watchdog ME client */
252
253         struct file *iamthif_file_object;
254         struct mei_cl iamthif_cl;
255         int iamthif_ioctl;
256         int iamthif_canceled;
257         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;
263         int iamthif_flow_control_pending;
264         enum iamthif_states iamthif_state;
265         struct mei_cl_cb *iamthif_current_cb;
266         u8 write_hang;
267         int need_reset;
268         long open_handle_count;
269
270 };
271
272
273 /*
274  * mei init function prototypes
275  */
276 struct mei_device *mei_device_init(struct pci_dev *pdev);
277 void mei_reset(struct mei_device *dev, int interrupts);
278 int mei_hw_init(struct mei_device *dev);
279 int mei_task_initialize_clients(void *data);
280 int mei_initialize_clients(struct mei_device *dev);
281 int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
282 void mei_initialize_list(struct mei_io_list *list, struct mei_device *dev);
283 void mei_flush_list(struct mei_io_list *list, struct mei_cl *cl);
284 void mei_flush_queues(struct mei_device *dev, struct mei_cl *cl);
285 void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id);
286 void mei_host_init_iamthif(struct mei_device *dev);
287 void mei_allocate_me_clients_storage(struct mei_device *dev);
288
289
290 u8 mei_find_me_client_update_filext(struct mei_device *dev,
291                                 struct mei_cl *priv,
292                                 const uuid_le *cguid, u8 client_id);
293
294 /*
295  * MEI ME Client Functions
296  */
297
298 struct mei_cl *mei_cl_allocate(struct mei_device *dev);
299 void mei_cl_init(struct mei_cl *priv, struct mei_device *dev);
300
301
302 /*
303  * MEI Host Client Functions
304  */
305 void mei_host_start_message(struct mei_device *dev);
306 void mei_host_enum_clients_message(struct mei_device *dev);
307 void mei_host_client_properties(struct mei_device *dev);
308
309 /*
310  *  MEI interrupt functions prototype
311  */
312 irqreturn_t mei_interrupt_quick_handler(int irq, void *dev_id);
313 irqreturn_t mei_interrupt_thread_handler(int irq, void *dev_id);
314 void mei_wd_timer(struct work_struct *work);
315
316 /*
317  *  MEI input output function prototype
318  */
319 int mei_ioctl_connect_client(struct file *file,
320                         struct mei_connect_client_data *data);
321
322 int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
323
324 int amthi_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
325
326 int amthi_read(struct mei_device *dev, struct file *file,
327               char __user *ubuf, size_t length, loff_t *offset);
328
329 struct mei_cl_cb *find_amthi_read_list_entry(struct mei_device *dev,
330                                                 struct file *file);
331
332 void mei_run_next_iamthif_cmd(struct mei_device *dev);
333
334 void mei_free_cb_private(struct mei_cl_cb *priv_cb);
335
336 int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid);
337
338 /*
339  * Register Access Function
340  */
341
342 /**
343  * mei_reg_read - Reads 32bit data from the mei device
344  *
345  * @dev: the device structure
346  * @offset: offset from which to read the data
347  *
348  * returns the byte read.
349  */
350 static inline u32 mei_reg_read(struct mei_device *dev, unsigned long offset)
351 {
352         return ioread32(dev->mem_addr + offset);
353 }
354
355 /**
356  * mei_reg_write - Writes 32bit data to the mei device
357  *
358  * @dev: the device structure
359  * @offset: offset from which to write the data
360  * @value: the byte to write
361  */
362 static inline void mei_reg_write(struct mei_device *dev,
363                                 unsigned long offset, u32 value)
364 {
365         iowrite32(value, dev->mem_addr + offset);
366 }
367
368 /**
369  * mei_hcsr_read - Reads 32bit data from the host CSR
370  *
371  * @dev: the device structure
372  *
373  * returns the byte read.
374  */
375 static inline u32 mei_hcsr_read(struct mei_device *dev)
376 {
377         return mei_reg_read(dev, H_CSR);
378 }
379
380 /**
381  * mei_mecsr_read - Reads 32bit data from the ME CSR
382  *
383  * @dev: the device structure
384  *
385  * returns ME_CSR_HA register value (u32)
386  */
387 static inline u32 mei_mecsr_read(struct mei_device *dev)
388 {
389         return mei_reg_read(dev, ME_CSR_HA);
390 }
391
392 /**
393  * get_me_cb_rw - Reads 32bit data from the mei ME_CB_RW register
394  *
395  * @dev: the device structure
396  *
397  * returns ME_CB_RW register value (u32)
398  */
399 static inline u32 mei_mecbrw_read(struct mei_device *dev)
400 {
401         return mei_reg_read(dev, ME_CB_RW);
402 }
403
404
405 /*
406  * mei interface function prototypes
407  */
408 void mei_hcsr_set(struct mei_device *dev);
409 void mei_csr_clear_his(struct mei_device *dev);
410
411 void mei_enable_interrupts(struct mei_device *dev);
412 void mei_disable_interrupts(struct mei_device *dev);
413
414 /**
415  * mei_fe_same_id - tells if file private data have same id
416  *
417  * @fe1: private data of 1. file object
418  * @fe2: private data of 2. file object
419  *
420  * returns !=0 - if ids are the same, 0 - if differ.
421  */
422 static inline int mei_fe_same_id(const struct mei_cl *fe1,
423                                   const struct mei_cl *fe2)
424 {
425         return ((fe1->host_client_id == fe2->host_client_id) &&
426                 (fe1->me_client_id == fe2->me_client_id));
427 }
428
429 #endif