Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
mei_dev.h
Go to the documentation of this file.
1 /*
2  *
3  * Intel Management Engine Interface (Intel MEI) Linux driver
4  * Copyright (c) 2003-2012, 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 <linux/mei.h>
23 #include "hw.h"
24 
25 /*
26  * watch dog definition
27  */
28 #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 
36 #define MEI_WD_STOP_TIMEOUT 10 /* msecs */
37 
38 #define MEI_WD_STATE_INDEPENDENCE_MSG_SENT (1 << 0)
39 
40 #define MEI_RD_MSG_BUF_SIZE (128 * sizeof(u32))
41 
42 
43 /*
44  * AMTHI Client UUID
45  */
46 extern const uuid_le mei_amthi_guid;
47 
48 /*
49  * Watchdog Client UUID
50  */
51 extern const uuid_le mei_wd_guid;
52 
53 /*
54  * Watchdog independence state message
55  */
56 extern const u8 mei_wd_state_independence_msg[3][4];
57 
58 /*
59  * Number of Maximum MEI Clients
60  */
61 #define MEI_CLIENTS_MAX 256
62 
63 /*
64  * Number of File descriptors/handles
65  * that can be opened to the driver.
66  *
67  * Limit to 253: 256 Total Clients
68  * minus internal client for MEI Bus Messags
69  * minus internal client for AMTHI
70  * minus internal client for Watchdog
71  */
72 #define MEI_MAX_OPEN_HANDLE_COUNT (MEI_CLIENTS_MAX - 3)
73 
74 
75 /* File state */
76 enum file_state {
82 };
83 
84 /* MEI device states */
94 };
95 
96 const char *mei_dev_state_str(int state);
97 
98 /* init clients states*/
103 };
104 
111 };
112 
120 };
121 
126 };
127 
128 /* MEI CB */
130  MEI_READ = 0,
135 };
136 
137 /*
138  * Intel MEI message data struct
139  */
142  unsigned char *data;
143 };
144 
145 
146 struct mei_cl_cb {
152  unsigned long information;
153  unsigned long read_time;
154  struct file *file_object;
155 };
156 
157 /* MEI client instance carried as file->pirvate_data*/
158 struct mei_cl {
159  struct list_head link;
160  struct mei_device *dev;
166  int status;
167  /* ID of client connected */
174  int sm_state;
176 };
177 
178 struct mei_io_list {
180 };
181 
186 struct mei_device {
187  struct pci_dev *pdev; /* pointer to pci device struct */
188  /*
189  * lists of queues
190  */
191  /* array of pointers to aio lists */
192  struct mei_io_list read_list; /* driver read queue */
193  struct mei_io_list write_list; /* driver write queue */
194  struct mei_io_list write_waiting_list; /* write waiting queue */
195  struct mei_io_list ctrl_wr_list; /* managed write IOCTL list */
196  struct mei_io_list ctrl_rd_list; /* managed read IOCTL list */
197  struct mei_io_list amthi_cmd_list; /* amthi list for cmd waiting */
198 
199  /* driver managed amthi list for reading completed amthi cmd data */
201  /*
202  * list of files
203  */
206  /*
207  * memory of device
208  */
209  unsigned int mem_base;
210  unsigned int mem_length;
212  /*
213  * lock for the device
214  */
215  struct mutex device_lock; /* device lock */
216  struct delayed_work timer_work; /* MEI timer delayed work (timeouts) */
217  bool recvd_msg;
218  /*
219  * hw states of host and fw(ME)
220  */
224  /*
225  * waiting queue for receive message from FW
226  */
229 
230  /*
231  * mei device states
232  */
237 
239  unsigned char rd_msg_buf[MEI_RD_MSG_BUF_SIZE]; /* control messages */
240  u32 wr_msg_buf[128]; /* used for control messages */
241  u32 ext_msg_buf[8]; /* for control responses */
243 
245 
246  struct mei_me_client *me_clients; /* Note: memory has to be allocated */
247  DECLARE_BITMAP(me_clients_map, MEI_CLIENTS_MAX);
248  DECLARE_BITMAP(host_clients_map, MEI_CLIENTS_MAX);
253 
254  struct mei_cl wd_cl;
260 
261 
266  unsigned long iamthif_timer;
268  unsigned char *iamthif_msg_buf; /* Note: memory has to be allocated */
275 };
276 
277 
278 /*
279  * mei init function prototypes
280  */
281 struct mei_device *mei_device_init(struct pci_dev *pdev);
282 void mei_reset(struct mei_device *dev, int interrupts);
283 int mei_hw_init(struct mei_device *dev);
286 int mei_disconnect_host_client(struct mei_device *dev, struct mei_cl *cl);
287 void mei_remove_client_from_file_list(struct mei_device *dev, u8 host_client_id);
288 void mei_host_init_iamthif(struct mei_device *dev);
290 
291 
292 int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl,
293  const uuid_le *cguid, u8 host_client_id);
294 int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid);
296 
297 /*
298  * MEI IO List Functions
299  */
300 void mei_io_list_init(struct mei_io_list *list);
301 void mei_io_list_flush(struct mei_io_list *list, struct mei_cl *cl);
302 
303 /*
304  * MEI ME Client Functions
305  */
306 
307 struct mei_cl *mei_cl_allocate(struct mei_device *dev);
308 void mei_cl_init(struct mei_cl *cl, struct mei_device *dev);
309 int mei_cl_flush_queues(struct mei_cl *cl);
318 static inline bool mei_cl_cmp_id(const struct mei_cl *cl1,
319  const struct mei_cl *cl2)
320 {
321  return cl1 && cl2 &&
322  (cl1->host_client_id == cl2->host_client_id) &&
323  (cl1->me_client_id == cl2->me_client_id);
324 }
325 
326 
327 
328 /*
329  * MEI Host Client Functions
330  */
334 
335 /*
336  * MEI interrupt functions prototype
337  */
340 void mei_timer(struct work_struct *work);
341 
342 /*
343  * MEI input output function prototype
344  */
346  struct mei_connect_client_data *data);
347 
348 int mei_start_read(struct mei_device *dev, struct mei_cl *cl);
349 
350 int amthi_write(struct mei_device *dev, struct mei_cl_cb *priv_cb);
351 
352 int amthi_read(struct mei_device *dev, struct file *file,
353  char __user *ubuf, size_t length, loff_t *offset);
354 
356  struct file *file);
357 
359 
360 void mei_free_cb_private(struct mei_cl_cb *priv_cb);
361 
362 
363 /*
364  * Register Access Function
365  */
366 
375 static inline u32 mei_reg_read(const struct mei_device *dev,
376  unsigned long offset)
377 {
378  return ioread32(dev->mem_addr + offset);
379 }
380 
388 static inline void mei_reg_write(const struct mei_device *dev,
389  unsigned long offset, u32 value)
390 {
391  iowrite32(value, dev->mem_addr + offset);
392 }
393 
401 static inline u32 mei_hcsr_read(const struct mei_device *dev)
402 {
403  return mei_reg_read(dev, H_CSR);
404 }
405 
413 static inline u32 mei_mecsr_read(const struct mei_device *dev)
414 {
415  return mei_reg_read(dev, ME_CSR_HA);
416 }
417 
425 static inline u32 mei_mecbrw_read(const struct mei_device *dev)
426 {
427  return mei_reg_read(dev, ME_CB_RW);
428 }
429 
430 
431 /*
432  * mei interface function prototypes
433  */
434 void mei_hcsr_set(struct mei_device *dev);
435 void mei_csr_clear_his(struct mei_device *dev);
436 
437 void mei_enable_interrupts(struct mei_device *dev);
439 
440 #endif