setup enviroment for compilation
[linux-2.4.21-pre4.git] / drivers / ieee1394 / ieee1394_core.h
1
2 #ifndef _IEEE1394_CORE_H
3 #define _IEEE1394_CORE_H
4
5 #include <linux/slab.h>
6 #include <linux/devfs_fs_kernel.h>
7 #include <linux/proc_fs.h>
8 #include <asm/semaphore.h>
9 #include "hosts.h"
10
11
12 struct hpsb_packet {
13         /* This struct is basically read-only for hosts with the exception of
14          * the data buffer contents and xnext - see below. */
15         struct list_head list;
16
17         /* This can be used for host driver internal linking. */
18         struct list_head driver_list;
19
20         nodeid_t node_id;
21
22         /* Async and Iso types should be clear, raw means send-as-is, do not
23          * CRC!  Byte swapping shall still be done in this case. */
24         enum { hpsb_async, hpsb_iso, hpsb_raw } __attribute__((packed)) type;
25
26         /* Okay, this is core internal and a no care for hosts.
27          * queued   = queued for sending
28          * pending  = sent, waiting for response
29          * complete = processing completed, successful or not
30          * incoming = incoming packet
31          */
32         enum { 
33                 hpsb_unused, hpsb_queued, hpsb_pending, hpsb_complete, hpsb_incoming 
34         } __attribute__((packed)) state;
35
36         /* These are core internal. */
37         char tlabel;
38         char ack_code;
39         char tcode;
40
41         unsigned expect_response:1;
42         unsigned no_waiter:1;
43
44         /* Data big endianness flag - may vary from request to request.  The
45          * header is always in machine byte order.
46          * Not really used currently.  */
47         unsigned data_be:1;
48
49         /* Speed to transmit with: 0 = 100Mbps, 1 = 200Mbps, 2 = 400Mbps */
50         unsigned speed_code:2;
51
52         /*
53          * *header and *data are guaranteed to be 32-bit DMAable and may be
54          * overwritten to allow in-place byte swapping.  Neither of these is
55          * CRCed (the sizes also don't include CRC), but contain space for at
56          * least one additional quadlet to allow in-place CRCing.  The memory is
57          * also guaranteed to be DMA mappable.
58          */
59         quadlet_t *header;
60         quadlet_t *data;
61         size_t header_size;
62         size_t data_size;
63
64
65         struct hpsb_host *host;
66         unsigned int generation;
67
68         /* Very core internal, don't care. */
69         struct semaphore state_change;
70
71         struct list_head complete_tq;
72
73         /* Store jiffies for implementing bus timeouts. */
74         unsigned long sendtime;
75
76         quadlet_t embedded_header[5];
77 };
78
79 /* add a new task for when a packet completes */
80 void hpsb_add_packet_complete_task(struct hpsb_packet *packet, struct hpsb_queue_struct *tq);
81
82 static inline struct hpsb_packet *driver_packet(struct list_head *l)
83 {
84         return list_entry(l, struct hpsb_packet, driver_list);
85 }
86
87 void abort_timedouts(struct hpsb_host *host);
88 void abort_requests(struct hpsb_host *host);
89
90 struct hpsb_packet *alloc_hpsb_packet(size_t data_size);
91 void free_hpsb_packet(struct hpsb_packet *packet);
92
93
94 /*
95  * Generation counter for the complete 1394 subsystem.  Generation gets
96  * incremented on every change in the subsystem (e.g. bus reset).
97  *
98  * Use the functions, not the variable.
99  */
100 #include <asm/atomic.h>
101
102 static inline unsigned int get_hpsb_generation(struct hpsb_host *host)
103 {
104         return atomic_read(&host->generation);
105 }
106
107 /*
108  * Queue packet for transmitting, return 0 for failure.
109  */
110 int hpsb_send_packet(struct hpsb_packet *packet);
111
112 /* Initiate bus reset on the given host.  Returns 1 if bus reset already in
113  * progress, 0 otherwise. */
114 int hpsb_reset_bus(struct hpsb_host *host, int type);
115
116 /*
117  * The following functions are exported for host driver module usage.  All of
118  * them are safe to use in interrupt contexts, although some are quite
119  * complicated so you may want to run them in bottom halves instead of calling
120  * them directly.
121  */
122
123 /* Notify a bus reset to the core.  Returns 1 if bus reset already in progress,
124  * 0 otherwise. */
125 int hpsb_bus_reset(struct hpsb_host *host);
126
127 /*
128  * Hand over received selfid packet to the core.  Complement check (second
129  * quadlet is complement of first) is expected to be done and succesful.
130  */
131 void hpsb_selfid_received(struct hpsb_host *host, quadlet_t sid);
132
133 /* 
134  * Notify completion of SelfID stage to the core and report new physical ID
135  * and whether host is root now.
136  */
137 void hpsb_selfid_complete(struct hpsb_host *host, int phyid, int isroot);
138
139 /*
140  * Notify core of sending a packet.  Ackcode is the ack code returned for async
141  * transmits or ACKX_SEND_ERROR if the transmission failed completely; ACKX_NONE
142  * for other cases (internal errors that don't justify a panic).  Safe to call
143  * from within a transmit packet routine.
144  */
145 void hpsb_packet_sent(struct hpsb_host *host, struct hpsb_packet *packet,
146                       int ackcode);
147
148 /*
149  * Hand over received packet to the core.  The contents of data are expected to
150  * be the full packet but with the CRCs left out (data block follows header
151  * immediately), with the header (i.e. the first four quadlets) in machine byte
152  * order and the data block in big endian.  *data can be safely overwritten
153  * after this call.
154  *
155  * If the packet is a write request, write_acked is to be set to true if it was
156  * ack_complete'd already, false otherwise.  This arg is ignored for any other
157  * packet type.
158  */
159 void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
160                           int write_acked);
161
162
163 /*
164  * CHARACTER DEVICE DISPATCHING
165  *
166  * All ieee1394 character device drivers share the same major number
167  * (major 171).  The 256 minor numbers are allocated to the various
168  * task-specific interfaces (raw1394, video1394, dv1394, etc) in
169  * blocks of 16.
170  *
171  * The core ieee1394.o modules handles the initial open() for all
172  * character devices on major 171; it then dispatches to the
173  * appropriate task-specific driver.
174  *
175  * Minor device number block allocations:
176  *
177  * Block 0  (  0- 15)  raw1394
178  * Block 1  ( 16- 31)  video1394
179  * Block 2  ( 32- 47)  dv1394
180  *
181  * Blocks 3-14 free for future allocation
182  *
183  * Block 15 (240-255)  reserved for drivers under development, etc.
184  */
185
186 #define IEEE1394_MAJOR               171
187
188 #define IEEE1394_MINOR_BLOCK_RAW1394       0
189 #define IEEE1394_MINOR_BLOCK_VIDEO1394     1
190 #define IEEE1394_MINOR_BLOCK_DV1394        2
191 #define IEEE1394_MINOR_BLOCK_AMDTP         3
192 #define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15
193
194 /* return the index (within a minor number block) of a file */
195 static inline unsigned char ieee1394_file_to_instance(struct file *file)
196 {
197         unsigned char minor = minor(file->f_dentry->d_inode->i_rdev);
198         
199         /* return lower 4 bits */
200         return minor & 0xF;
201 }
202
203 /* 
204  * Task-specific drivers should call ieee1394_register_chardev() to
205  * request a block of 16 minor numbers.
206  *
207  * Returns 0 if the request was successful, -EBUSY if the block was
208  * already taken.
209  */
210
211 int  ieee1394_register_chardev(int blocknum,           /* 0-15 */
212                                struct module *module,  /* THIS_MODULE */
213                                struct file_operations *file_ops);
214
215 /* release a block of minor numbers */
216 void ieee1394_unregister_chardev(int blocknum);
217
218 /* the devfs handle for /dev/ieee1394; NULL if devfs is not in use */
219 extern devfs_handle_t ieee1394_devfs_handle;
220
221 /* the proc_fs entry for /proc/ieee1394 */
222 extern struct proc_dir_entry *ieee1394_procfs_entry;
223
224 #endif /* _IEEE1394_CORE_H */