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