Staging: add cowloop driver
[safe/jmp/linux-2.6] / drivers / staging / heci / heci_data_structures.h
1 /*
2  * Part of Intel(R) Manageability Engine Interface Linux driver
3  *
4  * Copyright (c) 2003 - 2008 Intel Corp.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions, and the following disclaimer,
12  *    without modification.
13  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
14  *    substantially similar to the "NO WARRANTY" disclaimer below
15  *    ("Disclaimer") and any redistribution must be conditioned upon
16  *    including a substantially similar Disclaimer requirement for further
17  *    binary redistribution.
18  * 3. Neither the names of the above-listed copyright holders nor the names
19  *    of any contributors may be used to endorse or promote products derived
20  *    from this software without specific prior written permission.
21  *
22  * Alternatively, this software may be distributed under the terms of the
23  * GNU General Public License ("GPL") version 2 as published by the Free
24  * Software Foundation.
25  *
26  * NO WARRANTY
27  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
30  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGES.
38  *
39  */
40
41 #ifndef _HECI_DATA_STRUCTURES_H_
42 #define _HECI_DATA_STRUCTURES_H_
43
44 #include <linux/spinlock.h>
45 #include <linux/list.h>
46 #include <linux/pci.h>
47 #include <linux/timer.h>
48 #include <linux/interrupt.h>
49 #include <linux/workqueue.h>
50 #include <linux/module.h>
51 #include <linux/aio.h>
52 #include <linux/types.h>
53
54 /*
55  * error code definition
56  */
57 #define     ESLOTS_OVERFLOW              1
58 #define     ECORRUPTED_MESSAGE_HEADER    1000
59 #define     ECOMPLETE_MESSAGE            1001
60
61 #define     HECI_FC_MESSAGE_RESERVED_LENGTH           5
62
63 /*
64  * Number of queue lists used by this driver
65  */
66 #define HECI_IO_LISTS_NUMBER        7
67
68 /*
69  * Maximum transmission unit (MTU) of heci messages
70  */
71 #define IAMTHIF_MTU 4160
72
73
74 /*
75  * HECI HW Section
76  */
77
78 /* HECI registers */
79 /* H_CB_WW - Host Circular Buffer (CB) Write Window register */
80 #define H_CB_WW    0
81 /* H_CSR - Host Control Status register */
82 #define H_CSR      4
83 /* ME_CB_RW - ME Circular Buffer Read Window register (read only) */
84 #define ME_CB_RW   8
85 /* ME_CSR_HA - ME Control Status Host Access register (read only) */
86 #define ME_CSR_HA  0xC
87
88
89 /* register bits of H_CSR (Host Control Status register) */
90 /* Host Circular Buffer Depth - maximum number of 32-bit entries in CB */
91 #define H_CBD             0xFF000000
92 /* Host Circular Buffer Write Pointer */
93 #define H_CBWP            0x00FF0000
94 /* Host Circular Buffer Read Pointer */
95 #define H_CBRP            0x0000FF00
96 /* Host Reset */
97 #define H_RST             0x00000010
98 /* Host Ready */
99 #define H_RDY             0x00000008
100 /* Host Interrupt Generate */
101 #define H_IG              0x00000004
102 /* Host Interrupt Status */
103 #define H_IS              0x00000002
104 /* Host Interrupt Enable */
105 #define H_IE              0x00000001
106
107
108 /* register bits of ME_CSR_HA (ME Control Status Host Access register) */
109 /* ME CB (Circular Buffer) Depth HRA (Host Read Access)
110  *  - host read only access to ME_CBD */
111 #define ME_CBD_HRA        0xFF000000
112 /* ME CB Write Pointer HRA - host read only access to ME_CBWP */
113 #define ME_CBWP_HRA       0x00FF0000
114 /* ME CB Read Pointer HRA - host read only access to ME_CBRP */
115 #define ME_CBRP_HRA       0x0000FF00
116 /* ME Reset HRA - host read only access to ME_RST */
117 #define ME_RST_HRA        0x00000010
118 /* ME Ready HRA - host read only access to ME_RDY */
119 #define ME_RDY_HRA        0x00000008
120 /* ME Interrupt Generate HRA - host read only access to ME_IG */
121 #define ME_IG_HRA         0x00000004
122 /* ME Interrupt Status HRA - host read only access to ME_IS */
123 #define ME_IS_HRA         0x00000002
124 /* ME Interrupt Enable HRA - host read only access to ME_IE */
125 #define ME_IE_HRA         0x00000001
126
127 #define HECI_MINORS_BASE        1
128 #define HECI_MINORS_COUNT       1
129
130 #define  HECI_MINOR_NUMBER      1
131 #define  HECI_MAX_OPEN_HANDLE_COUNT     253
132
133 /*
134  * debug kernel print macro define
135  */
136 extern int heci_debug;
137
138 #define DBG(format, arg...) do { \
139         if (heci_debug) \
140                 printk(KERN_INFO "heci: %s: " format, __func__, ## arg); \
141 } while (0)
142
143
144 /*
145  * time to wait HECI become ready after init
146  */
147 #define HECI_INTEROP_TIMEOUT    (HZ * 7)
148
149 /*
150  * watch dog definition
151  */
152 #define HECI_WATCHDOG_DATA_SIZE         16
153 #define HECI_START_WD_DATA_SIZE         20
154 #define HECI_WD_PARAMS_SIZE             4
155 #define HECI_WD_STATE_INDEPENDENCE_MSG_SENT       (1 << 0)
156
157 #define HECI_WD_HOST_CLIENT_ID          1
158 #define HECI_IAMTHIF_HOST_CLIENT_ID     2
159
160 struct guid {
161         __u32 data1;
162         __u16 data2;
163         __u16 data3;
164         __u8 data4[8];
165 };
166
167 /* File state */
168 enum file_state {
169         HECI_FILE_INITIALIZING = 0,
170         HECI_FILE_CONNECTING,
171         HECI_FILE_CONNECTED,
172         HECI_FILE_DISCONNECTING,
173         HECI_FILE_DISCONNECTED
174 };
175
176 /* HECI device states */
177 enum heci_states {
178         HECI_INITIALIZING = 0,
179         HECI_ENABLED,
180         HECI_RESETING,
181         HECI_DISABLED,
182         HECI_RECOVERING_FROM_RESET,
183         HECI_POWER_DOWN,
184         HECI_POWER_UP
185 };
186
187 enum iamthif_states {
188         HECI_IAMTHIF_IDLE,
189         HECI_IAMTHIF_WRITING,
190         HECI_IAMTHIF_FLOW_CONTROL,
191         HECI_IAMTHIF_READING,
192         HECI_IAMTHIF_READ_COMPLETE
193 };
194
195 enum heci_file_transaction_states {
196         HECI_IDLE,
197         HECI_WRITING,
198         HECI_WRITE_COMPLETE,
199         HECI_FLOW_CONTROL,
200         HECI_READING,
201         HECI_READ_COMPLETE
202 };
203
204 /* HECI CB */
205 enum heci_cb_major_types {
206         HECI_READ = 0,
207         HECI_WRITE,
208         HECI_IOCTL,
209         HECI_OPEN,
210         HECI_CLOSE
211 };
212
213 /* HECI user data struct */
214 struct heci_message_data {
215         __u32 size;
216         char *data;
217 } __attribute__((packed));
218
219 #define HECI_CONNECT_TIMEOUT             3      /* at least 2 seconds */
220
221 #define IAMTHIF_STALL_TIMER              12     /* seconds */
222 #define IAMTHIF_READ_TIMER               15     /* seconds */
223
224 struct heci_cb_private {
225         struct list_head cb_list;
226         enum heci_cb_major_types major_file_operations;
227         void *file_private;
228         struct heci_message_data request_buffer;
229         struct heci_message_data response_buffer;
230         unsigned long information;
231         unsigned long read_time;
232         struct file *file_object;
233 };
234
235 /* Private file struct */
236 struct heci_file_private {
237         struct list_head link;
238         struct file *file;
239         enum file_state state;
240         wait_queue_head_t tx_wait;
241         wait_queue_head_t rx_wait;
242         wait_queue_head_t wait;
243         spinlock_t file_lock; /* file lock */
244         spinlock_t read_io_lock; /* read lock */
245         spinlock_t write_io_lock; /* write lock */
246         int read_pending;
247         int status;
248         /* ID of client connected */
249         __u8 host_client_id;
250         __u8 me_client_id;
251         __u8 flow_ctrl_creds;
252         __u8 timer_count;
253         enum heci_file_transaction_states reading_state;
254         enum heci_file_transaction_states writing_state;
255         int sm_state;
256         struct heci_cb_private *read_cb;
257 };
258
259 struct io_heci_list {
260         struct heci_cb_private heci_cb;
261         int status;
262         struct iamt_heci_device *device_extension;
263 };
264
265 struct heci_driver_version {
266         __u8 major;
267         __u8 minor;
268         __u8 hotfix;
269         __u16 build;
270 } __attribute__((packed));
271
272
273 struct heci_client {
274         __u32 max_msg_length;
275         __u8 protocol_version;
276 } __attribute__((packed));
277
278 /*
279  *  HECI BUS Interface Section
280  */
281 struct heci_msg_hdr {
282         __u32 me_addr:8;
283         __u32 host_addr:8;
284         __u32 length:9;
285         __u32 reserved:6;
286         __u32 msg_complete:1;
287 } __attribute__((packed));
288
289
290 struct hbm_cmd {
291         __u8 cmd:7;
292         __u8 is_response:1;
293 } __attribute__((packed));
294
295
296 struct heci_bus_message {
297         struct hbm_cmd cmd;
298         __u8 command_specific_data[];
299 } __attribute__((packed));
300
301 struct hbm_version {
302         __u8 minor_version;
303         __u8 major_version;
304 } __attribute__((packed));
305
306 struct hbm_host_version_request {
307         struct hbm_cmd cmd;
308         __u8 reserved;
309         struct hbm_version host_version;
310 } __attribute__((packed));
311
312 struct hbm_host_version_response {
313         struct hbm_cmd cmd;
314         int host_version_supported;
315         struct hbm_version me_max_version;
316 } __attribute__((packed));
317
318 struct hbm_host_stop_request {
319         struct hbm_cmd cmd;
320         __u8 reason;
321         __u8 reserved[2];
322 } __attribute__((packed));
323
324 struct hbm_host_stop_response {
325         struct hbm_cmd cmd;
326         __u8 reserved[3];
327 } __attribute__((packed));
328
329 struct hbm_me_stop_request {
330         struct hbm_cmd cmd;
331         __u8 reason;
332         __u8 reserved[2];
333 } __attribute__((packed));
334
335 struct hbm_host_enum_request {
336         struct hbm_cmd cmd;
337         __u8 reserved[3];
338 } __attribute__((packed));
339
340 struct hbm_host_enum_response {
341         struct hbm_cmd cmd;
342         __u8 reserved[3];
343         __u8 valid_addresses[32];
344 } __attribute__((packed));
345
346 struct heci_client_properties {
347         struct guid protocol_name;
348         __u8 protocol_version;
349         __u8 max_number_of_connections;
350         __u8 fixed_address;
351         __u8 single_recv_buf;
352         __u32 max_msg_length;
353 } __attribute__((packed));
354
355 struct hbm_props_request {
356         struct hbm_cmd cmd;
357         __u8 address;
358         __u8 reserved[2];
359 } __attribute__((packed));
360
361
362 struct hbm_props_response {
363         struct hbm_cmd cmd;
364         __u8 address;
365         __u8 status;
366         __u8 reserved[1];
367         struct heci_client_properties client_properties;
368 } __attribute__((packed));
369
370 struct hbm_client_connect_request {
371         struct hbm_cmd cmd;
372         __u8 me_addr;
373         __u8 host_addr;
374         __u8 reserved;
375 } __attribute__((packed));
376
377 struct hbm_client_connect_response {
378         struct hbm_cmd cmd;
379         __u8 me_addr;
380         __u8 host_addr;
381         __u8 status;
382 } __attribute__((packed));
383
384 struct hbm_client_disconnect_request {
385         struct hbm_cmd cmd;
386         __u8 me_addr;
387         __u8 host_addr;
388         __u8 reserved[1];
389 } __attribute__((packed));
390
391 struct hbm_flow_control {
392         struct hbm_cmd cmd;
393         __u8 me_addr;
394         __u8 host_addr;
395         __u8 reserved[HECI_FC_MESSAGE_RESERVED_LENGTH];
396 } __attribute__((packed));
397
398 struct heci_me_client {
399         struct heci_client_properties props;
400         __u8 client_id;
401         __u8 flow_ctrl_creds;
402 } __attribute__((packed));
403
404 /* private device struct */
405 struct iamt_heci_device {
406         struct pci_dev *pdev;   /* pointer to pci device struct */
407         /*
408          * lists of queues
409          */
410          /* array of pointers to  aio lists */
411         struct io_heci_list *io_list_array[HECI_IO_LISTS_NUMBER];
412         struct io_heci_list read_list;  /* driver read queue */
413         struct io_heci_list write_list; /* driver write queue */
414         struct io_heci_list write_waiting_list; /* write waiting queue */
415         struct io_heci_list ctrl_wr_list;       /* managed write IOCTL list */
416         struct io_heci_list ctrl_rd_list;       /* managed read IOCTL list */
417         struct io_heci_list pthi_cmd_list;      /* PTHI list for cmd waiting */
418
419         /* driver managed PTHI list for reading completed pthi cmd data */
420         struct io_heci_list pthi_read_complete_list;
421         /*
422          * list of files
423          */
424         struct list_head file_list;
425         /*
426          * memory of device
427          */
428         unsigned int mem_base;
429         unsigned int mem_length;
430         void __iomem *mem_addr;
431         /*
432          * lock for the device
433          */
434         spinlock_t device_lock; /* device lock*/
435         struct work_struct work;
436         int recvd_msg;
437
438         struct task_struct *reinit_tsk;
439
440         struct timer_list wd_timer;
441         /*
442          * hw states of host and fw(ME)
443          */
444         __u32 host_hw_state;
445         __u32 me_hw_state;
446         /*
447          * waiting queue for receive message from FW
448          */
449         wait_queue_head_t wait_recvd_msg;
450         wait_queue_head_t wait_stop_wd;
451         /*
452          * heci device  states
453          */
454         enum heci_states heci_state;
455         int stop;
456
457         __u32 extra_write_index;
458         __u32 rd_msg_buf[128];  /* used for control messages */
459         __u32 wr_msg_buf[128];  /* used for control messages */
460         __u32 ext_msg_buf[8];   /* for control responses    */
461         __u32 rd_msg_hdr;
462
463         struct hbm_version version;
464
465         int host_buffer_is_empty;
466         struct heci_file_private wd_file_ext;
467         struct heci_me_client *me_clients; /* Note: memory has to be allocated*/
468         __u8 heci_me_clients[32];       /* list of existing clients */
469         __u8 num_heci_me_clients;
470         __u8 heci_host_clients[32];     /* list of existing clients */
471         __u8 current_host_client_id;
472
473         int wd_pending;
474         int wd_stoped;
475         __u16 wd_timeout;       /* seconds ((wd_data[1] << 8) + wd_data[0]) */
476         unsigned char wd_data[HECI_START_WD_DATA_SIZE];
477
478
479         __u16 wd_due_counter;
480         int asf_mode;
481         int wd_bypass;  /* if 1, don't refresh watchdog ME client */
482
483         struct file *iamthif_file_object;
484         struct heci_file_private iamthif_file_ext;
485         int iamthif_ioctl;
486         int iamthif_canceled;
487         __u32 iamthif_timer;
488         __u32 iamthif_stall_timer;
489         unsigned char iamthif_msg_buf[IAMTHIF_MTU];
490         __u32 iamthif_msg_buf_size;
491         __u32 iamthif_msg_buf_index;
492         int iamthif_flow_control_pending;
493         enum iamthif_states iamthif_state;
494
495         struct heci_cb_private *iamthif_current_cb;
496         __u8 write_hang;
497         int need_reset;
498         long open_handle_count;
499
500 };
501
502 /**
503  * read_heci_register - Read a byte from the heci device
504  *
505  * @dev: the device structure
506  * @offset: offset from which to read the data
507  *
508  * returns  the byte read.
509  */
510 static inline __u32 read_heci_register(struct iamt_heci_device *dev,
511                                         unsigned long offset)
512 {
513         return readl(dev->mem_addr + offset);
514 }
515
516 /**
517  * write_heci_register - Write  4 bytes to the heci device
518  *
519  * @dev: the device structure
520  * @offset: offset from which to write the data
521  * @value: the byte to write
522  */
523 static inline void write_heci_register(struct iamt_heci_device *dev,
524                                         unsigned long offset,  __u32 value)
525 {
526         writel(value, dev->mem_addr + offset);
527 }
528
529 #endif /* _HECI_DATA_STRUCTURES_H_ */