]> Pileus Git - ~andy/linux/blob - include/linux/firewire-cdev.h
firewire: cdev: fix ABI for FCP and address range mapping, add fw_cdev_event_request2
[~andy/linux] / include / linux / firewire-cdev.h
1 /*
2  * Char device interface.
3  *
4  * Copyright (C) 2005-2006  Kristian Hoegsberg <krh@bitplanet.net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software Foundation,
18  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19  */
20
21 #ifndef _LINUX_FIREWIRE_CDEV_H
22 #define _LINUX_FIREWIRE_CDEV_H
23
24 #include <linux/ioctl.h>
25 #include <linux/types.h>
26 #include <linux/firewire-constants.h>
27
28 #define FW_CDEV_EVENT_BUS_RESET                 0x00
29 #define FW_CDEV_EVENT_RESPONSE                  0x01
30 #define FW_CDEV_EVENT_REQUEST                   0x02
31 #define FW_CDEV_EVENT_ISO_INTERRUPT             0x03
32 #define FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED    0x04
33 #define FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED  0x05
34
35 /* available since kernel version 2.6.36 */
36 #define FW_CDEV_EVENT_REQUEST2                  0x06
37
38 /**
39  * struct fw_cdev_event_common - Common part of all fw_cdev_event_ types
40  * @closure:    For arbitrary use by userspace
41  * @type:       Discriminates the fw_cdev_event_ types
42  *
43  * This struct may be used to access generic members of all fw_cdev_event_
44  * types regardless of the specific type.
45  *
46  * Data passed in the @closure field for a request will be returned in the
47  * corresponding event.  It is big enough to hold a pointer on all platforms.
48  * The ioctl used to set @closure depends on the @type of event.
49  */
50 struct fw_cdev_event_common {
51         __u64 closure;
52         __u32 type;
53 };
54
55 /**
56  * struct fw_cdev_event_bus_reset - Sent when a bus reset occurred
57  * @closure:    See &fw_cdev_event_common; set by %FW_CDEV_IOC_GET_INFO ioctl
58  * @type:       See &fw_cdev_event_common; always %FW_CDEV_EVENT_BUS_RESET
59  * @node_id:       New node ID of this node
60  * @local_node_id: Node ID of the local node, i.e. of the controller
61  * @bm_node_id:    Node ID of the bus manager
62  * @irm_node_id:   Node ID of the iso resource manager
63  * @root_node_id:  Node ID of the root node
64  * @generation:    New bus generation
65  *
66  * This event is sent when the bus the device belongs to goes through a bus
67  * reset.  It provides information about the new bus configuration, such as
68  * new node ID for this device, new root ID, and others.
69  */
70 struct fw_cdev_event_bus_reset {
71         __u64 closure;
72         __u32 type;
73         __u32 node_id;
74         __u32 local_node_id;
75         __u32 bm_node_id;
76         __u32 irm_node_id;
77         __u32 root_node_id;
78         __u32 generation;
79 };
80
81 /**
82  * struct fw_cdev_event_response - Sent when a response packet was received
83  * @closure:    See &fw_cdev_event_common;
84  *              set by %FW_CDEV_IOC_SEND_REQUEST ioctl
85  * @type:       See &fw_cdev_event_common; always %FW_CDEV_EVENT_RESPONSE
86  * @rcode:      Response code returned by the remote node
87  * @length:     Data length, i.e. the response's payload size in bytes
88  * @data:       Payload data, if any
89  *
90  * This event is sent when the stack receives a response to an outgoing request
91  * sent by %FW_CDEV_IOC_SEND_REQUEST ioctl.  The payload data for responses
92  * carrying data (read and lock responses) follows immediately and can be
93  * accessed through the @data field.
94  */
95 struct fw_cdev_event_response {
96         __u64 closure;
97         __u32 type;
98         __u32 rcode;
99         __u32 length;
100         __u32 data[0];
101 };
102
103 /**
104  * struct fw_cdev_event_request - Old version of &fw_cdev_event_request2
105  * @closure:    See &fw_cdev_event_common; set by %FW_CDEV_IOC_ALLOCATE ioctl
106  * @type:       See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST
107  * @tcode:      See &fw_cdev_event_request2
108  * @offset:     See &fw_cdev_event_request2
109  * @handle:     See &fw_cdev_event_request2
110  * @length:     See &fw_cdev_event_request2
111  * @data:       See &fw_cdev_event_request2
112  *
113  * This event is sent instead of &fw_cdev_event_request2 if the kernel or
114  * the client implements ABI version <= 3.
115  *
116  * Unlike &fw_cdev_event_request2, the sender identity cannot be established,
117  * broadcast write requests cannot be distinguished from unicast writes, and
118  * @tcode of lock requests is %TCODE_LOCK_REQUEST.
119  *
120  * Requests to the FCP_REQUEST or FCP_RESPONSE register are responded to as
121  * with &fw_cdev_event_request2, except in kernel 2.6.32 and older which send
122  * the response packet of the client's %FW_CDEV_IOC_SEND_RESPONSE ioctl.
123  */
124 struct fw_cdev_event_request {
125         __u64 closure;
126         __u32 type;
127         __u32 tcode;
128         __u64 offset;
129         __u32 handle;
130         __u32 length;
131         __u32 data[0];
132 };
133
134 /**
135  * struct fw_cdev_event_request2 - Sent on incoming request to an address region
136  * @closure:    See &fw_cdev_event_common; set by %FW_CDEV_IOC_ALLOCATE ioctl
137  * @type:       See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST2
138  * @tcode:      Transaction code of the incoming request
139  * @offset:     The offset into the 48-bit per-node address space
140  * @source_node_id: Sender node ID
141  * @destination_node_id: Destination node ID
142  * @card:       The index of the card from which the request came
143  * @generation: Bus generation in which the request is valid
144  * @handle:     Reference to the kernel-side pending request
145  * @length:     Data length, i.e. the request's payload size in bytes
146  * @data:       Incoming data, if any
147  *
148  * This event is sent when the stack receives an incoming request to an address
149  * region registered using the %FW_CDEV_IOC_ALLOCATE ioctl.  The request is
150  * guaranteed to be completely contained in the specified region.  Userspace is
151  * responsible for sending the response by %FW_CDEV_IOC_SEND_RESPONSE ioctl,
152  * using the same @handle.
153  *
154  * The payload data for requests carrying data (write and lock requests)
155  * follows immediately and can be accessed through the @data field.
156  *
157  * Unlike &fw_cdev_event_request, @tcode of lock requests is one of the
158  * firewire-core specific %TCODE_LOCK_MASK_SWAP...%TCODE_LOCK_VENDOR_DEPENDENT,
159  * i.e. encodes the extended transaction code.
160  *
161  * @card may differ from &fw_cdev_get_info.card because requests are received
162  * from all cards of the Linux host.  @source_node_id, @destination_node_id, and
163  * @generation pertain to that card.  Destination node ID and bus generation may
164  * therefore differ from the corresponding fields of the last
165  * &fw_cdev_event_bus_reset.
166  *
167  * @destination_node_id may also differ from the current node ID because of a
168  * non-local bus ID part or in case of a broadcast write request.  Note, a
169  * client must call an %FW_CDEV_IOC_SEND_RESPONSE ioctl even in case of a
170  * broadcast write request; the kernel will then release the kernel-side pending
171  * request but will not actually send a response packet.
172  *
173  * In case of a write request to FCP_REQUEST or FCP_RESPONSE, the kernel already
174  * sent a write response immediately after the request was received; in this
175  * case the client must still call an %FW_CDEV_IOC_SEND_RESPONSE ioctl to
176  * release the kernel-side pending request, though another response won't be
177  * sent.
178  *
179  * If the client subsequently needs to initiate requests to the sender node of
180  * an &fw_cdev_event_request2, it needs to use a device file with matching
181  * card index, node ID, and generation for outbound requests.
182  */
183 struct fw_cdev_event_request2 {
184         __u64 closure;
185         __u32 type;
186         __u32 tcode;
187         __u64 offset;
188         __u32 source_node_id;
189         __u32 destination_node_id;
190         __u32 card;
191         __u32 generation;
192         __u32 handle;
193         __u32 length;
194         __u32 data[0];
195 };
196
197 /**
198  * struct fw_cdev_event_iso_interrupt - Sent when an iso packet was completed
199  * @closure:    See &fw_cdev_event_common;
200  *              set by %FW_CDEV_CREATE_ISO_CONTEXT ioctl
201  * @type:       See &fw_cdev_event_common; always %FW_CDEV_EVENT_ISO_INTERRUPT
202  * @cycle:      Cycle counter of the interrupt packet
203  * @header_length: Total length of following headers, in bytes
204  * @header:     Stripped headers, if any
205  *
206  * This event is sent when the controller has completed an &fw_cdev_iso_packet
207  * with the %FW_CDEV_ISO_INTERRUPT bit set.  In the receive case, the headers
208  * stripped of all packets up until and including the interrupt packet are
209  * returned in the @header field.  The amount of header data per packet is as
210  * specified at iso context creation by &fw_cdev_create_iso_context.header_size.
211  *
212  * In version 1 of this ABI, header data consisted of the 1394 isochronous
213  * packet header, followed by quadlets from the packet payload if
214  * &fw_cdev_create_iso_context.header_size > 4.
215  *
216  * In version 2 of this ABI, header data consist of the 1394 isochronous
217  * packet header, followed by a timestamp quadlet if
218  * &fw_cdev_create_iso_context.header_size > 4, followed by quadlets from the
219  * packet payload if &fw_cdev_create_iso_context.header_size > 8.
220  *
221  * Behaviour of ver. 1 of this ABI is no longer available since ABI ver. 2.
222  *
223  * Format of 1394 iso packet header: 16 bits len, 2 bits tag, 6 bits channel,
224  * 4 bits tcode, 4 bits sy, in big endian byte order.  Format of timestamp:
225  * 16 bits invalid, 3 bits cycleSeconds, 13 bits cycleCount, in big endian byte
226  * order.
227  */
228 struct fw_cdev_event_iso_interrupt {
229         __u64 closure;
230         __u32 type;
231         __u32 cycle;
232         __u32 header_length;
233         __u32 header[0];
234 };
235
236 /**
237  * struct fw_cdev_event_iso_resource - Iso resources were allocated or freed
238  * @closure:    See &fw_cdev_event_common;
239  *              set by %FW_CDEV_IOC_(DE)ALLOCATE_ISO_RESOURCE(_ONCE) ioctl
240  * @type:       %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or
241  *              %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED
242  * @handle:     Reference by which an allocated resource can be deallocated
243  * @channel:    Isochronous channel which was (de)allocated, if any
244  * @bandwidth:  Bandwidth allocation units which were (de)allocated, if any
245  *
246  * An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event is sent after an isochronous
247  * resource was allocated at the IRM.  The client has to check @channel and
248  * @bandwidth for whether the allocation actually succeeded.
249  *
250  * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event is sent after an isochronous
251  * resource was deallocated at the IRM.  It is also sent when automatic
252  * reallocation after a bus reset failed.
253  *
254  * @channel is <0 if no channel was (de)allocated or if reallocation failed.
255  * @bandwidth is 0 if no bandwidth was (de)allocated or if reallocation failed.
256  */
257 struct fw_cdev_event_iso_resource {
258         __u64 closure;
259         __u32 type;
260         __u32 handle;
261         __s32 channel;
262         __s32 bandwidth;
263 };
264
265 /**
266  * union fw_cdev_event - Convenience union of fw_cdev_event_ types
267  * @common:        Valid for all types
268  * @bus_reset:     Valid if @common.type == %FW_CDEV_EVENT_BUS_RESET
269  * @response:      Valid if @common.type == %FW_CDEV_EVENT_RESPONSE
270  * @request:       Valid if @common.type == %FW_CDEV_EVENT_REQUEST
271  * @request2:      Valid if @common.type == %FW_CDEV_EVENT_REQUEST2
272  * @iso_interrupt: Valid if @common.type == %FW_CDEV_EVENT_ISO_INTERRUPT
273  * @iso_resource:  Valid if @common.type ==
274  *                              %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or
275  *                              %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED
276  *
277  * Convenience union for userspace use.  Events could be read(2) into an
278  * appropriately aligned char buffer and then cast to this union for further
279  * processing.  Note that for a request, response or iso_interrupt event,
280  * the data[] or header[] may make the size of the full event larger than
281  * sizeof(union fw_cdev_event).  Also note that if you attempt to read(2)
282  * an event into a buffer that is not large enough for it, the data that does
283  * not fit will be discarded so that the next read(2) will return a new event.
284  */
285 union fw_cdev_event {
286         struct fw_cdev_event_common             common;
287         struct fw_cdev_event_bus_reset          bus_reset;
288         struct fw_cdev_event_response           response;
289         struct fw_cdev_event_request            request;
290         struct fw_cdev_event_request2           request2;     /* added in 2.6.36 */
291         struct fw_cdev_event_iso_interrupt      iso_interrupt;
292         struct fw_cdev_event_iso_resource       iso_resource; /* added in 2.6.30 */
293 };
294
295 /* available since kernel version 2.6.22 */
296 #define FW_CDEV_IOC_GET_INFO           _IOWR('#', 0x00, struct fw_cdev_get_info)
297 #define FW_CDEV_IOC_SEND_REQUEST        _IOW('#', 0x01, struct fw_cdev_send_request)
298 #define FW_CDEV_IOC_ALLOCATE           _IOWR('#', 0x02, struct fw_cdev_allocate)
299 #define FW_CDEV_IOC_DEALLOCATE          _IOW('#', 0x03, struct fw_cdev_deallocate)
300 #define FW_CDEV_IOC_SEND_RESPONSE       _IOW('#', 0x04, struct fw_cdev_send_response)
301 #define FW_CDEV_IOC_INITIATE_BUS_RESET  _IOW('#', 0x05, struct fw_cdev_initiate_bus_reset)
302 #define FW_CDEV_IOC_ADD_DESCRIPTOR     _IOWR('#', 0x06, struct fw_cdev_add_descriptor)
303 #define FW_CDEV_IOC_REMOVE_DESCRIPTOR   _IOW('#', 0x07, struct fw_cdev_remove_descriptor)
304 #define FW_CDEV_IOC_CREATE_ISO_CONTEXT _IOWR('#', 0x08, struct fw_cdev_create_iso_context)
305 #define FW_CDEV_IOC_QUEUE_ISO          _IOWR('#', 0x09, struct fw_cdev_queue_iso)
306 #define FW_CDEV_IOC_START_ISO           _IOW('#', 0x0a, struct fw_cdev_start_iso)
307 #define FW_CDEV_IOC_STOP_ISO            _IOW('#', 0x0b, struct fw_cdev_stop_iso)
308
309 /* available since kernel version 2.6.24 */
310 #define FW_CDEV_IOC_GET_CYCLE_TIMER     _IOR('#', 0x0c, struct fw_cdev_get_cycle_timer)
311
312 /* available since kernel version 2.6.30 */
313 #define FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE       _IOWR('#', 0x0d, struct fw_cdev_allocate_iso_resource)
314 #define FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE      _IOW('#', 0x0e, struct fw_cdev_deallocate)
315 #define FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE   _IOW('#', 0x0f, struct fw_cdev_allocate_iso_resource)
316 #define FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE _IOW('#', 0x10, struct fw_cdev_allocate_iso_resource)
317 #define FW_CDEV_IOC_GET_SPEED                     _IO('#', 0x11) /* returns speed code */
318 #define FW_CDEV_IOC_SEND_BROADCAST_REQUEST       _IOW('#', 0x12, struct fw_cdev_send_request)
319 #define FW_CDEV_IOC_SEND_STREAM_PACKET           _IOW('#', 0x13, struct fw_cdev_send_stream_packet)
320
321 /* available since kernel version 2.6.34 */
322 #define FW_CDEV_IOC_GET_CYCLE_TIMER2   _IOWR('#', 0x14, struct fw_cdev_get_cycle_timer2)
323
324 /*
325  * ABI version history
326  *  1  (2.6.22)  - initial version
327  *     (2.6.24)  - added %FW_CDEV_IOC_GET_CYCLE_TIMER
328  *  2  (2.6.30)  - changed &fw_cdev_event_iso_interrupt.header if
329  *                 &fw_cdev_create_iso_context.header_size is 8 or more
330  *               - added %FW_CDEV_IOC_*_ISO_RESOURCE*,
331  *                 %FW_CDEV_IOC_GET_SPEED, %FW_CDEV_IOC_SEND_BROADCAST_REQUEST,
332  *                 %FW_CDEV_IOC_SEND_STREAM_PACKET
333  *     (2.6.32)  - added time stamp to xmit &fw_cdev_event_iso_interrupt
334  *     (2.6.33)  - IR has always packet-per-buffer semantics now, not one of
335  *                 dual-buffer or packet-per-buffer depending on hardware
336  *               - shared use and auto-response for FCP registers
337  *  3  (2.6.34)  - made &fw_cdev_get_cycle_timer reliable
338  *               - added %FW_CDEV_IOC_GET_CYCLE_TIMER2
339  *  4  (2.6.36)  - added %FW_CDEV_EVENT_REQUEST2
340  */
341 #define FW_CDEV_VERSION 3 /* Meaningless; don't use this macro. */
342
343 /**
344  * struct fw_cdev_get_info - General purpose information ioctl
345  * @version:    The version field is just a running serial number.  Both an
346  *              input parameter (ABI version implemented by the client) and
347  *              output parameter (ABI version implemented by the kernel).
348  *              A client must not fill in an %FW_CDEV_VERSION defined from an
349  *              included kernel header file but the actual version for which
350  *              the client was implemented.  This is necessary for forward
351  *              compatibility.  We never break backwards compatibility, but
352  *              may add more structs, events, and ioctls in later revisions.
353  * @rom_length: If @rom is non-zero, at most rom_length bytes of configuration
354  *              ROM will be copied into that user space address.  In either
355  *              case, @rom_length is updated with the actual length of the
356  *              configuration ROM.
357  * @rom:        If non-zero, address of a buffer to be filled by a copy of the
358  *              device's configuration ROM
359  * @bus_reset:  If non-zero, address of a buffer to be filled by a
360  *              &struct fw_cdev_event_bus_reset with the current state
361  *              of the bus.  This does not cause a bus reset to happen.
362  * @bus_reset_closure: Value of &closure in this and subsequent bus reset events
363  * @card:       The index of the card this device belongs to
364  */
365 struct fw_cdev_get_info {
366         __u32 version;
367         __u32 rom_length;
368         __u64 rom;
369         __u64 bus_reset;
370         __u64 bus_reset_closure;
371         __u32 card;
372 };
373
374 /**
375  * struct fw_cdev_send_request - Send an asynchronous request packet
376  * @tcode:      Transaction code of the request
377  * @length:     Length of outgoing payload, in bytes
378  * @offset:     48-bit offset at destination node
379  * @closure:    Passed back to userspace in the response event
380  * @data:       Userspace pointer to payload
381  * @generation: The bus generation where packet is valid
382  *
383  * Send a request to the device.  This ioctl implements all outgoing requests.
384  * Both quadlet and block request specify the payload as a pointer to the data
385  * in the @data field.  Once the transaction completes, the kernel writes an
386  * &fw_cdev_event_response event back.  The @closure field is passed back to
387  * user space in the response event.
388  */
389 struct fw_cdev_send_request {
390         __u32 tcode;
391         __u32 length;
392         __u64 offset;
393         __u64 closure;
394         __u64 data;
395         __u32 generation;
396 };
397
398 /**
399  * struct fw_cdev_send_response - Send an asynchronous response packet
400  * @rcode:      Response code as determined by the userspace handler
401  * @length:     Length of outgoing payload, in bytes
402  * @data:       Userspace pointer to payload
403  * @handle:     The handle from the &fw_cdev_event_request
404  *
405  * Send a response to an incoming request.  By setting up an address range using
406  * the %FW_CDEV_IOC_ALLOCATE ioctl, userspace can listen for incoming requests.  An
407  * incoming request will generate an %FW_CDEV_EVENT_REQUEST, and userspace must
408  * send a reply using this ioctl.  The event has a handle to the kernel-side
409  * pending transaction, which should be used with this ioctl.
410  */
411 struct fw_cdev_send_response {
412         __u32 rcode;
413         __u32 length;
414         __u64 data;
415         __u32 handle;
416 };
417
418 /**
419  * struct fw_cdev_allocate - Allocate a CSR address range
420  * @offset:     Start offset of the address range
421  * @closure:    To be passed back to userspace in request events
422  * @length:     Length of the address range, in bytes
423  * @handle:     Handle to the allocation, written by the kernel
424  *
425  * Allocate an address range in the 48-bit address space on the local node
426  * (the controller).  This allows userspace to listen for requests with an
427  * offset within that address range.  When the kernel receives a request
428  * within the range, an &fw_cdev_event_request event will be written back.
429  * The @closure field is passed back to userspace in the response event.
430  * The @handle field is an out parameter, returning a handle to the allocated
431  * range to be used for later deallocation of the range.
432  *
433  * The address range is allocated on all local nodes.  The address allocation
434  * is exclusive except for the FCP command and response registers.
435  */
436 struct fw_cdev_allocate {
437         __u64 offset;
438         __u64 closure;
439         __u32 length;
440         __u32 handle;
441 };
442
443 /**
444  * struct fw_cdev_deallocate - Free a CSR address range or isochronous resource
445  * @handle:     Handle to the address range or iso resource, as returned by the
446  *              kernel when the range or resource was allocated
447  */
448 struct fw_cdev_deallocate {
449         __u32 handle;
450 };
451
452 #define FW_CDEV_LONG_RESET      0
453 #define FW_CDEV_SHORT_RESET     1
454
455 /**
456  * struct fw_cdev_initiate_bus_reset - Initiate a bus reset
457  * @type:       %FW_CDEV_SHORT_RESET or %FW_CDEV_LONG_RESET
458  *
459  * Initiate a bus reset for the bus this device is on.  The bus reset can be
460  * either the original (long) bus reset or the arbitrated (short) bus reset
461  * introduced in 1394a-2000.
462  */
463 struct fw_cdev_initiate_bus_reset {
464         __u32 type;     /* FW_CDEV_SHORT_RESET or FW_CDEV_LONG_RESET */
465 };
466
467 /**
468  * struct fw_cdev_add_descriptor - Add contents to the local node's config ROM
469  * @immediate:  If non-zero, immediate key to insert before pointer
470  * @key:        Upper 8 bits of root directory pointer
471  * @data:       Userspace pointer to contents of descriptor block
472  * @length:     Length of descriptor block data, in quadlets
473  * @handle:     Handle to the descriptor, written by the kernel
474  *
475  * Add a descriptor block and optionally a preceding immediate key to the local
476  * node's configuration ROM.
477  *
478  * The @key field specifies the upper 8 bits of the descriptor root directory
479  * pointer and the @data and @length fields specify the contents. The @key
480  * should be of the form 0xXX000000. The offset part of the root directory entry
481  * will be filled in by the kernel.
482  *
483  * If not 0, the @immediate field specifies an immediate key which will be
484  * inserted before the root directory pointer.
485  *
486  * @immediate, @key, and @data array elements are CPU-endian quadlets.
487  *
488  * If successful, the kernel adds the descriptor and writes back a handle to the
489  * kernel-side object to be used for later removal of the descriptor block and
490  * immediate key.
491  *
492  * This ioctl affects the configuration ROMs of all local nodes.
493  * The ioctl only succeeds on device files which represent a local node.
494  */
495 struct fw_cdev_add_descriptor {
496         __u32 immediate;
497         __u32 key;
498         __u64 data;
499         __u32 length;
500         __u32 handle;
501 };
502
503 /**
504  * struct fw_cdev_remove_descriptor - Remove contents from the configuration ROM
505  * @handle:     Handle to the descriptor, as returned by the kernel when the
506  *              descriptor was added
507  *
508  * Remove a descriptor block and accompanying immediate key from the local
509  * nodes' configuration ROMs.
510  */
511 struct fw_cdev_remove_descriptor {
512         __u32 handle;
513 };
514
515 #define FW_CDEV_ISO_CONTEXT_TRANSMIT    0
516 #define FW_CDEV_ISO_CONTEXT_RECEIVE     1
517
518 /**
519  * struct fw_cdev_create_iso_context - Create a context for isochronous IO
520  * @type:       %FW_CDEV_ISO_CONTEXT_TRANSMIT or %FW_CDEV_ISO_CONTEXT_RECEIVE
521  * @header_size: Header size to strip for receive contexts
522  * @channel:    Channel to bind to
523  * @speed:      Speed for transmit contexts
524  * @closure:    To be returned in &fw_cdev_event_iso_interrupt
525  * @handle:     Handle to context, written back by kernel
526  *
527  * Prior to sending or receiving isochronous I/O, a context must be created.
528  * The context records information about the transmit or receive configuration
529  * and typically maps to an underlying hardware resource.  A context is set up
530  * for either sending or receiving.  It is bound to a specific isochronous
531  * channel.
532  *
533  * If a context was successfully created, the kernel writes back a handle to the
534  * context, which must be passed in for subsequent operations on that context.
535  *
536  * For receive contexts, @header_size must be at least 4 and must be a multiple
537  * of 4.
538  *
539  * Note that the effect of a @header_size > 4 depends on
540  * &fw_cdev_get_info.version, as documented at &fw_cdev_event_iso_interrupt.
541  */
542 struct fw_cdev_create_iso_context {
543         __u32 type;
544         __u32 header_size;
545         __u32 channel;
546         __u32 speed;
547         __u64 closure;
548         __u32 handle;
549 };
550
551 #define FW_CDEV_ISO_PAYLOAD_LENGTH(v)   (v)
552 #define FW_CDEV_ISO_INTERRUPT           (1 << 16)
553 #define FW_CDEV_ISO_SKIP                (1 << 17)
554 #define FW_CDEV_ISO_SYNC                (1 << 17)
555 #define FW_CDEV_ISO_TAG(v)              ((v) << 18)
556 #define FW_CDEV_ISO_SY(v)               ((v) << 20)
557 #define FW_CDEV_ISO_HEADER_LENGTH(v)    ((v) << 24)
558
559 /**
560  * struct fw_cdev_iso_packet - Isochronous packet
561  * @control:    Contains the header length (8 uppermost bits), the sy field
562  *              (4 bits), the tag field (2 bits), a sync flag (1 bit),
563  *              a skip flag (1 bit), an interrupt flag (1 bit), and the
564  *              payload length (16 lowermost bits)
565  * @header:     Header and payload
566  *
567  * &struct fw_cdev_iso_packet is used to describe isochronous packet queues.
568  *
569  * Use the FW_CDEV_ISO_ macros to fill in @control.
570  *
571  * For transmit packets, the header length must be a multiple of 4 and specifies
572  * the numbers of bytes in @header that will be prepended to the packet's
573  * payload; these bytes are copied into the kernel and will not be accessed
574  * after the ioctl has returned.  The sy and tag fields are copied to the iso
575  * packet header (these fields are specified by IEEE 1394a and IEC 61883-1).
576  * The skip flag specifies that no packet is to be sent in a frame; when using
577  * this, all other fields except the interrupt flag must be zero.
578  *
579  * For receive packets, the header length must be a multiple of the context's
580  * header size; if the header length is larger than the context's header size,
581  * multiple packets are queued for this entry.  The sy and tag fields are
582  * ignored.  If the sync flag is set, the context drops all packets until
583  * a packet with a matching sy field is received (the sync value to wait for is
584  * specified in the &fw_cdev_start_iso structure).  The payload length defines
585  * how many payload bytes can be received for one packet (in addition to payload
586  * quadlets that have been defined as headers and are stripped and returned in
587  * the &fw_cdev_event_iso_interrupt structure).  If more bytes are received, the
588  * additional bytes are dropped.  If less bytes are received, the remaining
589  * bytes in this part of the payload buffer will not be written to, not even by
590  * the next packet, i.e., packets received in consecutive frames will not
591  * necessarily be consecutive in memory.  If an entry has queued multiple
592  * packets, the payload length is divided equally among them.
593  *
594  * When a packet with the interrupt flag set has been completed, the
595  * &fw_cdev_event_iso_interrupt event will be sent.  An entry that has queued
596  * multiple receive packets is completed when its last packet is completed.
597  */
598 struct fw_cdev_iso_packet {
599         __u32 control;
600         __u32 header[0];
601 };
602
603 /**
604  * struct fw_cdev_queue_iso - Queue isochronous packets for I/O
605  * @packets:    Userspace pointer to packet data
606  * @data:       Pointer into mmap()'ed payload buffer
607  * @size:       Size of packet data in bytes
608  * @handle:     Isochronous context handle
609  *
610  * Queue a number of isochronous packets for reception or transmission.
611  * This ioctl takes a pointer to an array of &fw_cdev_iso_packet structs,
612  * which describe how to transmit from or receive into a contiguous region
613  * of a mmap()'ed payload buffer.  As part of transmit packet descriptors,
614  * a series of headers can be supplied, which will be prepended to the
615  * payload during DMA.
616  *
617  * The kernel may or may not queue all packets, but will write back updated
618  * values of the @packets, @data and @size fields, so the ioctl can be
619  * resubmitted easily.
620  */
621 struct fw_cdev_queue_iso {
622         __u64 packets;
623         __u64 data;
624         __u32 size;
625         __u32 handle;
626 };
627
628 #define FW_CDEV_ISO_CONTEXT_MATCH_TAG0           1
629 #define FW_CDEV_ISO_CONTEXT_MATCH_TAG1           2
630 #define FW_CDEV_ISO_CONTEXT_MATCH_TAG2           4
631 #define FW_CDEV_ISO_CONTEXT_MATCH_TAG3           8
632 #define FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS      15
633
634 /**
635  * struct fw_cdev_start_iso - Start an isochronous transmission or reception
636  * @cycle:      Cycle in which to start I/O.  If @cycle is greater than or
637  *              equal to 0, the I/O will start on that cycle.
638  * @sync:       Determines the value to wait for for receive packets that have
639  *              the %FW_CDEV_ISO_SYNC bit set
640  * @tags:       Tag filter bit mask.  Only valid for isochronous reception.
641  *              Determines the tag values for which packets will be accepted.
642  *              Use FW_CDEV_ISO_CONTEXT_MATCH_ macros to set @tags.
643  * @handle:     Isochronous context handle within which to transmit or receive
644  */
645 struct fw_cdev_start_iso {
646         __s32 cycle;
647         __u32 sync;
648         __u32 tags;
649         __u32 handle;
650 };
651
652 /**
653  * struct fw_cdev_stop_iso - Stop an isochronous transmission or reception
654  * @handle:     Handle of isochronous context to stop
655  */
656 struct fw_cdev_stop_iso {
657         __u32 handle;
658 };
659
660 /**
661  * struct fw_cdev_get_cycle_timer - read cycle timer register
662  * @local_time:   system time, in microseconds since the Epoch
663  * @cycle_timer:  Cycle Time register contents
664  *
665  * The %FW_CDEV_IOC_GET_CYCLE_TIMER ioctl reads the isochronous cycle timer
666  * and also the system clock (%CLOCK_REALTIME).  This allows to express the
667  * receive time of an isochronous packet as a system time.
668  *
669  * @cycle_timer consists of 7 bits cycleSeconds, 13 bits cycleCount, and
670  * 12 bits cycleOffset, in host byte order.  Cf. the Cycle Time register
671  * per IEEE 1394 or Isochronous Cycle Timer register per OHCI-1394.
672  *
673  * In version 1 and 2 of the ABI, this ioctl returned unreliable (non-
674  * monotonic) @cycle_timer values on certain controllers.
675  */
676 struct fw_cdev_get_cycle_timer {
677         __u64 local_time;
678         __u32 cycle_timer;
679 };
680
681 /**
682  * struct fw_cdev_get_cycle_timer2 - read cycle timer register
683  * @tv_sec:       system time, seconds
684  * @tv_nsec:      system time, sub-seconds part in nanoseconds
685  * @clk_id:       input parameter, clock from which to get the system time
686  * @cycle_timer:  Cycle Time register contents
687  *
688  * The %FW_CDEV_IOC_GET_CYCLE_TIMER2 works like
689  * %FW_CDEV_IOC_GET_CYCLE_TIMER but lets you choose a clock like with POSIX'
690  * clock_gettime function.  Supported @clk_id values are POSIX' %CLOCK_REALTIME
691  * and %CLOCK_MONOTONIC and Linux' %CLOCK_MONOTONIC_RAW.
692  */
693 struct fw_cdev_get_cycle_timer2 {
694         __s64 tv_sec;
695         __s32 tv_nsec;
696         __s32 clk_id;
697         __u32 cycle_timer;
698 };
699
700 /**
701  * struct fw_cdev_allocate_iso_resource - (De)allocate a channel or bandwidth
702  * @closure:    Passed back to userspace in correponding iso resource events
703  * @channels:   Isochronous channels of which one is to be (de)allocated
704  * @bandwidth:  Isochronous bandwidth units to be (de)allocated
705  * @handle:     Handle to the allocation, written by the kernel (only valid in
706  *              case of %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ioctls)
707  *
708  * The %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ioctl initiates allocation of an
709  * isochronous channel and/or of isochronous bandwidth at the isochronous
710  * resource manager (IRM).  Only one of the channels specified in @channels is
711  * allocated.  An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED is sent after
712  * communication with the IRM, indicating success or failure in the event data.
713  * The kernel will automatically reallocate the resources after bus resets.
714  * Should a reallocation fail, an %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event
715  * will be sent.  The kernel will also automatically deallocate the resources
716  * when the file descriptor is closed.
717  *
718  * The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE ioctl can be used to initiate
719  * deallocation of resources which were allocated as described above.
720  * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation.
721  *
722  * The %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE ioctl is a variant of allocation
723  * without automatic re- or deallocation.
724  * An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event concludes this operation,
725  * indicating success or failure in its data.
726  *
727  * The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE ioctl works like
728  * %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE except that resources are freed
729  * instead of allocated.
730  * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation.
731  *
732  * To summarize, %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE allocates iso resources
733  * for the lifetime of the fd or @handle.
734  * In contrast, %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE allocates iso resources
735  * for the duration of a bus generation.
736  *
737  * @channels is a host-endian bitfield with the least significant bit
738  * representing channel 0 and the most significant bit representing channel 63:
739  * 1ULL << c for each channel c that is a candidate for (de)allocation.
740  *
741  * @bandwidth is expressed in bandwidth allocation units, i.e. the time to send
742  * one quadlet of data (payload or header data) at speed S1600.
743  */
744 struct fw_cdev_allocate_iso_resource {
745         __u64 closure;
746         __u64 channels;
747         __u32 bandwidth;
748         __u32 handle;
749 };
750
751 /**
752  * struct fw_cdev_send_stream_packet - send an asynchronous stream packet
753  * @length:     Length of outgoing payload, in bytes
754  * @tag:        Data format tag
755  * @channel:    Isochronous channel to transmit to
756  * @sy:         Synchronization code
757  * @closure:    Passed back to userspace in the response event
758  * @data:       Userspace pointer to payload
759  * @generation: The bus generation where packet is valid
760  * @speed:      Speed to transmit at
761  *
762  * The %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl sends an asynchronous stream packet
763  * to every device which is listening to the specified channel.  The kernel
764  * writes an &fw_cdev_event_response event which indicates success or failure of
765  * the transmission.
766  */
767 struct fw_cdev_send_stream_packet {
768         __u32 length;
769         __u32 tag;
770         __u32 channel;
771         __u32 sy;
772         __u64 closure;
773         __u64 data;
774         __u32 generation;
775         __u32 speed;
776 };
777
778 #endif /* _LINUX_FIREWIRE_CDEV_H */