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