xref: /linux/include/uapi/linux/firewire-cdev.h (revision cdd5b5a9761fd66d17586e4f4ba6588c70e640ea)
1607ca46eSDavid Howells /*
2607ca46eSDavid Howells  * Char device interface.
3607ca46eSDavid Howells  *
4607ca46eSDavid Howells  * Copyright (C) 2005-2007  Kristian Hoegsberg <krh@bitplanet.net>
5607ca46eSDavid Howells  *
6607ca46eSDavid Howells  * Permission is hereby granted, free of charge, to any person obtaining a
7607ca46eSDavid Howells  * copy of this software and associated documentation files (the "Software"),
8607ca46eSDavid Howells  * to deal in the Software without restriction, including without limitation
9607ca46eSDavid Howells  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10607ca46eSDavid Howells  * and/or sell copies of the Software, and to permit persons to whom the
11607ca46eSDavid Howells  * Software is furnished to do so, subject to the following conditions:
12607ca46eSDavid Howells  *
13607ca46eSDavid Howells  * The above copyright notice and this permission notice (including the next
14607ca46eSDavid Howells  * paragraph) shall be included in all copies or substantial portions of the
15607ca46eSDavid Howells  * Software.
16607ca46eSDavid Howells  *
17607ca46eSDavid Howells  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18607ca46eSDavid Howells  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19607ca46eSDavid Howells  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20607ca46eSDavid Howells  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21607ca46eSDavid Howells  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22607ca46eSDavid Howells  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23607ca46eSDavid Howells  * DEALINGS IN THE SOFTWARE.
24607ca46eSDavid Howells  */
25607ca46eSDavid Howells 
26607ca46eSDavid Howells #ifndef _LINUX_FIREWIRE_CDEV_H
27607ca46eSDavid Howells #define _LINUX_FIREWIRE_CDEV_H
28607ca46eSDavid Howells 
29607ca46eSDavid Howells #include <linux/ioctl.h>
30607ca46eSDavid Howells #include <linux/types.h>
31607ca46eSDavid Howells #include <linux/firewire-constants.h>
32607ca46eSDavid Howells 
33607ca46eSDavid Howells /* available since kernel version 2.6.22 */
34607ca46eSDavid Howells #define FW_CDEV_EVENT_BUS_RESET				0x00
35607ca46eSDavid Howells #define FW_CDEV_EVENT_RESPONSE				0x01
36607ca46eSDavid Howells #define FW_CDEV_EVENT_REQUEST				0x02
37607ca46eSDavid Howells #define FW_CDEV_EVENT_ISO_INTERRUPT			0x03
38607ca46eSDavid Howells 
39607ca46eSDavid Howells /* available since kernel version 2.6.30 */
40607ca46eSDavid Howells #define FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED		0x04
41607ca46eSDavid Howells #define FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED		0x05
42607ca46eSDavid Howells 
43607ca46eSDavid Howells /* available since kernel version 2.6.36 */
44607ca46eSDavid Howells #define FW_CDEV_EVENT_REQUEST2				0x06
45607ca46eSDavid Howells #define FW_CDEV_EVENT_PHY_PACKET_SENT			0x07
46607ca46eSDavid Howells #define FW_CDEV_EVENT_PHY_PACKET_RECEIVED		0x08
47607ca46eSDavid Howells #define FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL	0x09
48607ca46eSDavid Howells 
497c22d4a9STakashi Sakamoto /* available since kernel version 6.5 */
507c22d4a9STakashi Sakamoto #define FW_CDEV_EVENT_REQUEST3				0x0a
51fc2b52cfSTakashi Sakamoto #define FW_CDEV_EVENT_RESPONSE2				0x0b
52e27b3939STakashi Sakamoto #define FW_CDEV_EVENT_PHY_PACKET_SENT2			0x0c
53e27b3939STakashi Sakamoto #define FW_CDEV_EVENT_PHY_PACKET_RECEIVED2		0x0d
547c22d4a9STakashi Sakamoto 
55607ca46eSDavid Howells /**
569a400682SRandy Dunlap  * struct fw_cdev_event_common - Common part of all fw_cdev_event_* types
57607ca46eSDavid Howells  * @closure:	For arbitrary use by userspace
589a400682SRandy Dunlap  * @type:	Discriminates the fw_cdev_event_* types
59607ca46eSDavid Howells  *
609a400682SRandy Dunlap  * This struct may be used to access generic members of all fw_cdev_event_*
61607ca46eSDavid Howells  * types regardless of the specific type.
62607ca46eSDavid Howells  *
63607ca46eSDavid Howells  * Data passed in the @closure field for a request will be returned in the
64607ca46eSDavid Howells  * corresponding event.  It is big enough to hold a pointer on all platforms.
65607ca46eSDavid Howells  * The ioctl used to set @closure depends on the @type of event.
66607ca46eSDavid Howells  */
67607ca46eSDavid Howells struct fw_cdev_event_common {
68607ca46eSDavid Howells 	__u64 closure;
69607ca46eSDavid Howells 	__u32 type;
70607ca46eSDavid Howells };
71607ca46eSDavid Howells 
72607ca46eSDavid Howells /**
73607ca46eSDavid Howells  * struct fw_cdev_event_bus_reset - Sent when a bus reset occurred
74607ca46eSDavid Howells  * @closure:	See &fw_cdev_event_common; set by %FW_CDEV_IOC_GET_INFO ioctl
75607ca46eSDavid Howells  * @type:	See &fw_cdev_event_common; always %FW_CDEV_EVENT_BUS_RESET
76607ca46eSDavid Howells  * @node_id:       New node ID of this node
77607ca46eSDavid Howells  * @local_node_id: Node ID of the local node, i.e. of the controller
78607ca46eSDavid Howells  * @bm_node_id:    Node ID of the bus manager
79607ca46eSDavid Howells  * @irm_node_id:   Node ID of the iso resource manager
80607ca46eSDavid Howells  * @root_node_id:  Node ID of the root node
81607ca46eSDavid Howells  * @generation:    New bus generation
82607ca46eSDavid Howells  *
83607ca46eSDavid Howells  * This event is sent when the bus the device belongs to goes through a bus
84607ca46eSDavid Howells  * reset.  It provides information about the new bus configuration, such as
85607ca46eSDavid Howells  * new node ID for this device, new root ID, and others.
86607ca46eSDavid Howells  *
87607ca46eSDavid Howells  * If @bm_node_id is 0xffff right after bus reset it can be reread by an
88607ca46eSDavid Howells  * %FW_CDEV_IOC_GET_INFO ioctl after bus manager selection was finished.
89607ca46eSDavid Howells  * Kernels with ABI version < 4 do not set @bm_node_id.
90607ca46eSDavid Howells  */
91607ca46eSDavid Howells struct fw_cdev_event_bus_reset {
92607ca46eSDavid Howells 	__u64 closure;
93607ca46eSDavid Howells 	__u32 type;
94607ca46eSDavid Howells 	__u32 node_id;
95607ca46eSDavid Howells 	__u32 local_node_id;
96607ca46eSDavid Howells 	__u32 bm_node_id;
97607ca46eSDavid Howells 	__u32 irm_node_id;
98607ca46eSDavid Howells 	__u32 root_node_id;
99607ca46eSDavid Howells 	__u32 generation;
100607ca46eSDavid Howells };
101607ca46eSDavid Howells 
102607ca46eSDavid Howells /**
103607ca46eSDavid Howells  * struct fw_cdev_event_response - Sent when a response packet was received
104607ca46eSDavid Howells  * @closure:	See &fw_cdev_event_common; set by %FW_CDEV_IOC_SEND_REQUEST
105607ca46eSDavid Howells  *		or %FW_CDEV_IOC_SEND_BROADCAST_REQUEST
106607ca46eSDavid Howells  *		or %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl
107607ca46eSDavid Howells  * @type:	See &fw_cdev_event_common; always %FW_CDEV_EVENT_RESPONSE
108607ca46eSDavid Howells  * @rcode:	Response code returned by the remote node
109607ca46eSDavid Howells  * @length:	Data length, i.e. the response's payload size in bytes
110607ca46eSDavid Howells  * @data:	Payload data, if any
111607ca46eSDavid Howells  *
112fc2b52cfSTakashi Sakamoto  * This event is sent instead of &fw_cdev_event_response if the kernel or the client implements
113fc2b52cfSTakashi Sakamoto  * ABI version <= 5. It has the lack of time stamp field comparing to &fw_cdev_event_response2.
114fc2b52cfSTakashi Sakamoto  */
115fc2b52cfSTakashi Sakamoto struct fw_cdev_event_response {
116fc2b52cfSTakashi Sakamoto 	__u64 closure;
117fc2b52cfSTakashi Sakamoto 	__u32 type;
118fc2b52cfSTakashi Sakamoto 	__u32 rcode;
119fc2b52cfSTakashi Sakamoto 	__u32 length;
120fc2b52cfSTakashi Sakamoto 	__u32 data[];
121fc2b52cfSTakashi Sakamoto };
122fc2b52cfSTakashi Sakamoto 
123fc2b52cfSTakashi Sakamoto /**
124fc2b52cfSTakashi Sakamoto  * struct fw_cdev_event_response2 - Sent when a response packet was received
125fc2b52cfSTakashi Sakamoto  * @closure:	See &fw_cdev_event_common; set by %FW_CDEV_IOC_SEND_REQUEST
126fc2b52cfSTakashi Sakamoto  *		or %FW_CDEV_IOC_SEND_BROADCAST_REQUEST
127fc2b52cfSTakashi Sakamoto  *		or %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl
128fc2b52cfSTakashi Sakamoto  * @type:	See &fw_cdev_event_common; always %FW_CDEV_EVENT_RESPONSE
129fc2b52cfSTakashi Sakamoto  * @rcode:	Response code returned by the remote node
130fc2b52cfSTakashi Sakamoto  * @length:	Data length, i.e. the response's payload size in bytes
131fc2b52cfSTakashi Sakamoto  * @request_tstamp:	The time stamp of isochronous cycle at which the request was sent.
132fc2b52cfSTakashi Sakamoto  * @response_tstamp:	The time stamp of isochronous cycle at which the response was sent.
133*0258d889STakashi Sakamoto  * @padding:	Padding to keep the size of structure as multiples of 8 in various architectures
134*0258d889STakashi Sakamoto  *		since 4 byte alignment is used for 8 byte of object type in System V ABI for i386
135*0258d889STakashi Sakamoto  *		architecture.
136fc2b52cfSTakashi Sakamoto  * @data:	Payload data, if any
137fc2b52cfSTakashi Sakamoto  *
138607ca46eSDavid Howells  * This event is sent when the stack receives a response to an outgoing request
139607ca46eSDavid Howells  * sent by %FW_CDEV_IOC_SEND_REQUEST ioctl.  The payload data for responses
140607ca46eSDavid Howells  * carrying data (read and lock responses) follows immediately and can be
141607ca46eSDavid Howells  * accessed through the @data field.
142607ca46eSDavid Howells  *
143607ca46eSDavid Howells  * The event is also generated after conclusions of transactions that do not
144607ca46eSDavid Howells  * involve response packets.  This includes unified write transactions,
145607ca46eSDavid Howells  * broadcast write transactions, and transmission of asynchronous stream
146607ca46eSDavid Howells  * packets.  @rcode indicates success or failure of such transmissions.
147fc2b52cfSTakashi Sakamoto  *
148fc2b52cfSTakashi Sakamoto  * The value of @request_tstamp expresses the isochronous cycle at which the request was sent to
149fc2b52cfSTakashi Sakamoto  * initiate the transaction. The value of @response_tstamp expresses the isochronous cycle at which
150fc2b52cfSTakashi Sakamoto  * the response arrived to complete the transaction. Each value is unsigned 16 bit integer
151fc2b52cfSTakashi Sakamoto  * containing three low order bits of second field and all 13 bits of cycle field in format of
152fc2b52cfSTakashi Sakamoto  * CYCLE_TIMER register.
153607ca46eSDavid Howells  */
154fc2b52cfSTakashi Sakamoto struct fw_cdev_event_response2 {
155607ca46eSDavid Howells 	__u64 closure;
156607ca46eSDavid Howells 	__u32 type;
157607ca46eSDavid Howells 	__u32 rcode;
158607ca46eSDavid Howells 	__u32 length;
159fc2b52cfSTakashi Sakamoto 	__u32 request_tstamp;
160fc2b52cfSTakashi Sakamoto 	__u32 response_tstamp;
161fc2b52cfSTakashi Sakamoto 	__u32 padding;
16294dfc73eSGustavo A. R. Silva 	__u32 data[];
163607ca46eSDavid Howells };
164607ca46eSDavid Howells 
165607ca46eSDavid Howells /**
166607ca46eSDavid Howells  * struct fw_cdev_event_request - Old version of &fw_cdev_event_request2
1679a400682SRandy Dunlap  * @closure:	See &fw_cdev_event_common; set by %FW_CDEV_IOC_ALLOCATE ioctl
168607ca46eSDavid Howells  * @type:	See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST
1699a400682SRandy Dunlap  * @tcode:	Transaction code of the incoming request
1709a400682SRandy Dunlap  * @offset:	The offset into the 48-bit per-node address space
1719a400682SRandy Dunlap  * @handle:	Reference to the kernel-side pending request
1729a400682SRandy Dunlap  * @length:	Data length, i.e. the request's payload size in bytes
1739a400682SRandy Dunlap  * @data:	Incoming data, if any
174607ca46eSDavid Howells  *
175607ca46eSDavid Howells  * This event is sent instead of &fw_cdev_event_request2 if the kernel or
176607ca46eSDavid Howells  * the client implements ABI version <= 3.  &fw_cdev_event_request lacks
177607ca46eSDavid Howells  * essential information; use &fw_cdev_event_request2 instead.
178607ca46eSDavid Howells  */
179607ca46eSDavid Howells struct fw_cdev_event_request {
180607ca46eSDavid Howells 	__u64 closure;
181607ca46eSDavid Howells 	__u32 type;
182607ca46eSDavid Howells 	__u32 tcode;
183607ca46eSDavid Howells 	__u64 offset;
184607ca46eSDavid Howells 	__u32 handle;
185607ca46eSDavid Howells 	__u32 length;
18694dfc73eSGustavo A. R. Silva 	__u32 data[];
187607ca46eSDavid Howells };
188607ca46eSDavid Howells 
189607ca46eSDavid Howells /**
190607ca46eSDavid Howells  * struct fw_cdev_event_request2 - Sent on incoming request to an address region
191607ca46eSDavid Howells  * @closure:	See &fw_cdev_event_common; set by %FW_CDEV_IOC_ALLOCATE ioctl
192607ca46eSDavid Howells  * @type:	See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST2
193607ca46eSDavid Howells  * @tcode:	Transaction code of the incoming request
194607ca46eSDavid Howells  * @offset:	The offset into the 48-bit per-node address space
195607ca46eSDavid Howells  * @source_node_id: Sender node ID
196607ca46eSDavid Howells  * @destination_node_id: Destination node ID
197607ca46eSDavid Howells  * @card:	The index of the card from which the request came
198607ca46eSDavid Howells  * @generation:	Bus generation in which the request is valid
199607ca46eSDavid Howells  * @handle:	Reference to the kernel-side pending request
200607ca46eSDavid Howells  * @length:	Data length, i.e. the request's payload size in bytes
201607ca46eSDavid Howells  * @data:	Incoming data, if any
202607ca46eSDavid Howells  *
2037c22d4a9STakashi Sakamoto  * This event is sent instead of &fw_cdev_event_request3 if the kernel or the client implements
2047c22d4a9STakashi Sakamoto  * ABI version <= 5. It has the lack of time stamp field comparing to &fw_cdev_event_request3.
2057c22d4a9STakashi Sakamoto  */
2067c22d4a9STakashi Sakamoto struct fw_cdev_event_request2 {
2077c22d4a9STakashi Sakamoto 	__u64 closure;
2087c22d4a9STakashi Sakamoto 	__u32 type;
2097c22d4a9STakashi Sakamoto 	__u32 tcode;
2107c22d4a9STakashi Sakamoto 	__u64 offset;
2117c22d4a9STakashi Sakamoto 	__u32 source_node_id;
2127c22d4a9STakashi Sakamoto 	__u32 destination_node_id;
2137c22d4a9STakashi Sakamoto 	__u32 card;
2147c22d4a9STakashi Sakamoto 	__u32 generation;
2157c22d4a9STakashi Sakamoto 	__u32 handle;
2167c22d4a9STakashi Sakamoto 	__u32 length;
2177c22d4a9STakashi Sakamoto 	__u32 data[];
2187c22d4a9STakashi Sakamoto };
2197c22d4a9STakashi Sakamoto 
2207c22d4a9STakashi Sakamoto /**
2217c22d4a9STakashi Sakamoto  * struct fw_cdev_event_request3 - Sent on incoming request to an address region
2227c22d4a9STakashi Sakamoto  * @closure:	See &fw_cdev_event_common; set by %FW_CDEV_IOC_ALLOCATE ioctl
2237c22d4a9STakashi Sakamoto  * @type:	See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST2
2247c22d4a9STakashi Sakamoto  * @tcode:	Transaction code of the incoming request
2257c22d4a9STakashi Sakamoto  * @offset:	The offset into the 48-bit per-node address space
2267c22d4a9STakashi Sakamoto  * @source_node_id: Sender node ID
2277c22d4a9STakashi Sakamoto  * @destination_node_id: Destination node ID
2287c22d4a9STakashi Sakamoto  * @card:	The index of the card from which the request came
2297c22d4a9STakashi Sakamoto  * @generation:	Bus generation in which the request is valid
2307c22d4a9STakashi Sakamoto  * @handle:	Reference to the kernel-side pending request
2317c22d4a9STakashi Sakamoto  * @length:	Data length, i.e. the request's payload size in bytes
2327c22d4a9STakashi Sakamoto  * @tstamp:	The time stamp of isochronous cycle at which the request arrived.
233*0258d889STakashi Sakamoto  * @padding:	Padding to keep the size of structure as multiples of 8 in various architectures
234*0258d889STakashi Sakamoto  *		since 4 byte alignment is used for 8 byte of object type in System V ABI for i386
235*0258d889STakashi Sakamoto  *		architecture.
2367c22d4a9STakashi Sakamoto  * @data:	Incoming data, if any
2377c22d4a9STakashi Sakamoto  *
238607ca46eSDavid Howells  * This event is sent when the stack receives an incoming request to an address
239607ca46eSDavid Howells  * region registered using the %FW_CDEV_IOC_ALLOCATE ioctl.  The request is
240607ca46eSDavid Howells  * guaranteed to be completely contained in the specified region.  Userspace is
241607ca46eSDavid Howells  * responsible for sending the response by %FW_CDEV_IOC_SEND_RESPONSE ioctl,
242607ca46eSDavid Howells  * using the same @handle.
243607ca46eSDavid Howells  *
244607ca46eSDavid Howells  * The payload data for requests carrying data (write and lock requests)
245607ca46eSDavid Howells  * follows immediately and can be accessed through the @data field.
246607ca46eSDavid Howells  *
247607ca46eSDavid Howells  * Unlike &fw_cdev_event_request, @tcode of lock requests is one of the
248607ca46eSDavid Howells  * firewire-core specific %TCODE_LOCK_MASK_SWAP...%TCODE_LOCK_VENDOR_DEPENDENT,
249607ca46eSDavid Howells  * i.e. encodes the extended transaction code.
250607ca46eSDavid Howells  *
251607ca46eSDavid Howells  * @card may differ from &fw_cdev_get_info.card because requests are received
252607ca46eSDavid Howells  * from all cards of the Linux host.  @source_node_id, @destination_node_id, and
253607ca46eSDavid Howells  * @generation pertain to that card.  Destination node ID and bus generation may
254607ca46eSDavid Howells  * therefore differ from the corresponding fields of the last
255607ca46eSDavid Howells  * &fw_cdev_event_bus_reset.
256607ca46eSDavid Howells  *
257607ca46eSDavid Howells  * @destination_node_id may also differ from the current node ID because of a
258607ca46eSDavid Howells  * non-local bus ID part or in case of a broadcast write request.  Note, a
259607ca46eSDavid Howells  * client must call an %FW_CDEV_IOC_SEND_RESPONSE ioctl even in case of a
260607ca46eSDavid Howells  * broadcast write request; the kernel will then release the kernel-side pending
261607ca46eSDavid Howells  * request but will not actually send a response packet.
262607ca46eSDavid Howells  *
263607ca46eSDavid Howells  * In case of a write request to FCP_REQUEST or FCP_RESPONSE, the kernel already
264607ca46eSDavid Howells  * sent a write response immediately after the request was received; in this
265607ca46eSDavid Howells  * case the client must still call an %FW_CDEV_IOC_SEND_RESPONSE ioctl to
266607ca46eSDavid Howells  * release the kernel-side pending request, though another response won't be
267607ca46eSDavid Howells  * sent.
268607ca46eSDavid Howells  *
269607ca46eSDavid Howells  * If the client subsequently needs to initiate requests to the sender node of
2707c22d4a9STakashi Sakamoto  * an &fw_cdev_event_request3, it needs to use a device file with matching
271607ca46eSDavid Howells  * card index, node ID, and generation for outbound requests.
2727c22d4a9STakashi Sakamoto  *
2737c22d4a9STakashi Sakamoto  * @tstamp is isochronous cycle at which the request arrived. It is 16 bit integer value and the
2747c22d4a9STakashi Sakamoto  * higher 3 bits expresses three low order bits of second field in the format of CYCLE_TIME
2757c22d4a9STakashi Sakamoto  * register and the rest 13 bits expresses cycle field.
276607ca46eSDavid Howells  */
2777c22d4a9STakashi Sakamoto struct fw_cdev_event_request3 {
278607ca46eSDavid Howells 	__u64 closure;
279607ca46eSDavid Howells 	__u32 type;
280607ca46eSDavid Howells 	__u32 tcode;
281607ca46eSDavid Howells 	__u64 offset;
282607ca46eSDavid Howells 	__u32 source_node_id;
283607ca46eSDavid Howells 	__u32 destination_node_id;
284607ca46eSDavid Howells 	__u32 card;
285607ca46eSDavid Howells 	__u32 generation;
286607ca46eSDavid Howells 	__u32 handle;
287607ca46eSDavid Howells 	__u32 length;
2887c22d4a9STakashi Sakamoto 	__u32 tstamp;
2897c22d4a9STakashi Sakamoto 	__u32 padding;
29094dfc73eSGustavo A. R. Silva 	__u32 data[];
291607ca46eSDavid Howells };
292607ca46eSDavid Howells 
293607ca46eSDavid Howells /**
294607ca46eSDavid Howells  * struct fw_cdev_event_iso_interrupt - Sent when an iso packet was completed
295607ca46eSDavid Howells  * @closure:	See &fw_cdev_event_common;
296607ca46eSDavid Howells  *		set by %FW_CDEV_CREATE_ISO_CONTEXT ioctl
297607ca46eSDavid Howells  * @type:	See &fw_cdev_event_common; always %FW_CDEV_EVENT_ISO_INTERRUPT
298607ca46eSDavid Howells  * @cycle:	Cycle counter of the last completed packet
299607ca46eSDavid Howells  * @header_length: Total length of following headers, in bytes
300607ca46eSDavid Howells  * @header:	Stripped headers, if any
301607ca46eSDavid Howells  *
302607ca46eSDavid Howells  * This event is sent when the controller has completed an &fw_cdev_iso_packet
303607ca46eSDavid Howells  * with the %FW_CDEV_ISO_INTERRUPT bit set, when explicitly requested with
304607ca46eSDavid Howells  * %FW_CDEV_IOC_FLUSH_ISO, or when there have been so many completed packets
305607ca46eSDavid Howells  * without the interrupt bit set that the kernel's internal buffer for @header
3060699a73aSClemens Ladisch  * is about to overflow.  (In the last case, ABI versions < 5 drop header data
3070699a73aSClemens Ladisch  * up to the next interrupt packet.)
308607ca46eSDavid Howells  *
309607ca46eSDavid Howells  * Isochronous transmit events (context type %FW_CDEV_ISO_CONTEXT_TRANSMIT):
310607ca46eSDavid Howells  *
311607ca46eSDavid Howells  * In version 3 and some implementations of version 2 of the ABI, &header_length
312607ca46eSDavid Howells  * is a multiple of 4 and &header contains timestamps of all packets up until
313607ca46eSDavid Howells  * the interrupt packet.  The format of the timestamps is as described below for
314607ca46eSDavid Howells  * isochronous reception.  In version 1 of the ABI, &header_length was 0.
315607ca46eSDavid Howells  *
316607ca46eSDavid Howells  * Isochronous receive events (context type %FW_CDEV_ISO_CONTEXT_RECEIVE):
317607ca46eSDavid Howells  *
318607ca46eSDavid Howells  * The headers stripped of all packets up until and including the interrupt
319607ca46eSDavid Howells  * packet are returned in the @header field.  The amount of header data per
320607ca46eSDavid Howells  * packet is as specified at iso context creation by
321607ca46eSDavid Howells  * &fw_cdev_create_iso_context.header_size.
322607ca46eSDavid Howells  *
323607ca46eSDavid Howells  * Hence, _interrupt.header_length / _context.header_size is the number of
324607ca46eSDavid Howells  * packets received in this interrupt event.  The client can now iterate
325607ca46eSDavid Howells  * through the mmap()'ed DMA buffer according to this number of packets and
326607ca46eSDavid Howells  * to the buffer sizes as the client specified in &fw_cdev_queue_iso.
327607ca46eSDavid Howells  *
328607ca46eSDavid Howells  * Since version 2 of this ABI, the portion for each packet in _interrupt.header
329607ca46eSDavid Howells  * consists of the 1394 isochronous packet header, followed by a timestamp
330607ca46eSDavid Howells  * quadlet if &fw_cdev_create_iso_context.header_size > 4, followed by quadlets
331607ca46eSDavid Howells  * from the packet payload if &fw_cdev_create_iso_context.header_size > 8.
332607ca46eSDavid Howells  *
333607ca46eSDavid Howells  * Format of 1394 iso packet header:  16 bits data_length, 2 bits tag, 6 bits
334607ca46eSDavid Howells  * channel, 4 bits tcode, 4 bits sy, in big endian byte order.
335607ca46eSDavid Howells  * data_length is the actual received size of the packet without the four
336607ca46eSDavid Howells  * 1394 iso packet header bytes.
337607ca46eSDavid Howells  *
338607ca46eSDavid Howells  * Format of timestamp:  16 bits invalid, 3 bits cycleSeconds, 13 bits
339607ca46eSDavid Howells  * cycleCount, in big endian byte order.
340607ca46eSDavid Howells  *
341607ca46eSDavid Howells  * In version 1 of the ABI, no timestamp quadlet was inserted; instead, payload
342607ca46eSDavid Howells  * data followed directly after the 1394 is header if header_size > 4.
343607ca46eSDavid Howells  * Behaviour of ver. 1 of this ABI is no longer available since ABI ver. 2.
344607ca46eSDavid Howells  */
345607ca46eSDavid Howells struct fw_cdev_event_iso_interrupt {
346607ca46eSDavid Howells 	__u64 closure;
347607ca46eSDavid Howells 	__u32 type;
348607ca46eSDavid Howells 	__u32 cycle;
349607ca46eSDavid Howells 	__u32 header_length;
35094dfc73eSGustavo A. R. Silva 	__u32 header[];
351607ca46eSDavid Howells };
352607ca46eSDavid Howells 
353607ca46eSDavid Howells /**
354607ca46eSDavid Howells  * struct fw_cdev_event_iso_interrupt_mc - An iso buffer chunk was completed
355607ca46eSDavid Howells  * @closure:	See &fw_cdev_event_common;
356607ca46eSDavid Howells  *		set by %FW_CDEV_CREATE_ISO_CONTEXT ioctl
357607ca46eSDavid Howells  * @type:	%FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL
358607ca46eSDavid Howells  * @completed:	Offset into the receive buffer; data before this offset is valid
359607ca46eSDavid Howells  *
360607ca46eSDavid Howells  * This event is sent in multichannel contexts (context type
361607ca46eSDavid Howells  * %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL) for &fw_cdev_iso_packet buffer
362607ca46eSDavid Howells  * chunks that have been completely filled and that have the
363607ca46eSDavid Howells  * %FW_CDEV_ISO_INTERRUPT bit set, or when explicitly requested with
364607ca46eSDavid Howells  * %FW_CDEV_IOC_FLUSH_ISO.
365607ca46eSDavid Howells  *
366607ca46eSDavid Howells  * The buffer is continuously filled with the following data, per packet:
367607ca46eSDavid Howells  *  - the 1394 iso packet header as described at &fw_cdev_event_iso_interrupt,
368607ca46eSDavid Howells  *    but in little endian byte order,
369607ca46eSDavid Howells  *  - packet payload (as many bytes as specified in the data_length field of
370607ca46eSDavid Howells  *    the 1394 iso packet header) in big endian byte order,
371607ca46eSDavid Howells  *  - 0...3 padding bytes as needed to align the following trailer quadlet,
372607ca46eSDavid Howells  *  - trailer quadlet, containing the reception timestamp as described at
373607ca46eSDavid Howells  *    &fw_cdev_event_iso_interrupt, but in little endian byte order.
374607ca46eSDavid Howells  *
375607ca46eSDavid Howells  * Hence the per-packet size is data_length (rounded up to a multiple of 4) + 8.
376607ca46eSDavid Howells  * When processing the data, stop before a packet that would cross the
377607ca46eSDavid Howells  * @completed offset.
378607ca46eSDavid Howells  *
379607ca46eSDavid Howells  * A packet near the end of a buffer chunk will typically spill over into the
380607ca46eSDavid Howells  * next queued buffer chunk.  It is the responsibility of the client to check
381607ca46eSDavid Howells  * for this condition, assemble a broken-up packet from its parts, and not to
382607ca46eSDavid Howells  * re-queue any buffer chunks in which as yet unread packet parts reside.
383607ca46eSDavid Howells  */
384607ca46eSDavid Howells struct fw_cdev_event_iso_interrupt_mc {
385607ca46eSDavid Howells 	__u64 closure;
386607ca46eSDavid Howells 	__u32 type;
387607ca46eSDavid Howells 	__u32 completed;
388607ca46eSDavid Howells };
389607ca46eSDavid Howells 
390607ca46eSDavid Howells /**
391607ca46eSDavid Howells  * struct fw_cdev_event_iso_resource - Iso resources were allocated or freed
392607ca46eSDavid Howells  * @closure:	See &fw_cdev_event_common;
393af690f45SMauro Carvalho Chehab  *		set by``FW_CDEV_IOC_(DE)ALLOCATE_ISO_RESOURCE(_ONCE)`` ioctl
394607ca46eSDavid Howells  * @type:	%FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or
395607ca46eSDavid Howells  *		%FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED
396607ca46eSDavid Howells  * @handle:	Reference by which an allocated resource can be deallocated
397607ca46eSDavid Howells  * @channel:	Isochronous channel which was (de)allocated, if any
398607ca46eSDavid Howells  * @bandwidth:	Bandwidth allocation units which were (de)allocated, if any
399607ca46eSDavid Howells  *
400607ca46eSDavid Howells  * An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event is sent after an isochronous
401607ca46eSDavid Howells  * resource was allocated at the IRM.  The client has to check @channel and
402607ca46eSDavid Howells  * @bandwidth for whether the allocation actually succeeded.
403607ca46eSDavid Howells  *
404607ca46eSDavid Howells  * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event is sent after an isochronous
405607ca46eSDavid Howells  * resource was deallocated at the IRM.  It is also sent when automatic
406607ca46eSDavid Howells  * reallocation after a bus reset failed.
407607ca46eSDavid Howells  *
408607ca46eSDavid Howells  * @channel is <0 if no channel was (de)allocated or if reallocation failed.
409607ca46eSDavid Howells  * @bandwidth is 0 if no bandwidth was (de)allocated or if reallocation failed.
410607ca46eSDavid Howells  */
411607ca46eSDavid Howells struct fw_cdev_event_iso_resource {
412607ca46eSDavid Howells 	__u64 closure;
413607ca46eSDavid Howells 	__u32 type;
414607ca46eSDavid Howells 	__u32 handle;
415607ca46eSDavid Howells 	__s32 channel;
416607ca46eSDavid Howells 	__s32 bandwidth;
417607ca46eSDavid Howells };
418607ca46eSDavid Howells 
419607ca46eSDavid Howells /**
420607ca46eSDavid Howells  * struct fw_cdev_event_phy_packet - A PHY packet was transmitted or received
421607ca46eSDavid Howells  * @closure:	See &fw_cdev_event_common; set by %FW_CDEV_IOC_SEND_PHY_PACKET
422607ca46eSDavid Howells  *		or %FW_CDEV_IOC_RECEIVE_PHY_PACKETS ioctl
423607ca46eSDavid Howells  * @type:	%FW_CDEV_EVENT_PHY_PACKET_SENT or %..._RECEIVED
424607ca46eSDavid Howells  * @rcode:	%RCODE_..., indicates success or failure of transmission
425607ca46eSDavid Howells  * @length:	Data length in bytes
426e27b3939STakashi Sakamoto  * @data:	Incoming data for %FW_CDEV_IOC_RECEIVE_PHY_PACKETS. For %FW_CDEV_IOC_SEND_PHY_PACKET
427e27b3939STakashi Sakamoto  *		the field has the same data in the request, thus the length of 8 bytes.
428607ca46eSDavid Howells  *
429e27b3939STakashi Sakamoto  * This event is sent instead of &fw_cdev_event_phy_packet2 if the kernel or
430e27b3939STakashi Sakamoto  * the client implements ABI version <= 5. It has the lack of time stamp field comparing to
431e27b3939STakashi Sakamoto  * &fw_cdev_event_phy_packet2.
432607ca46eSDavid Howells  */
433607ca46eSDavid Howells struct fw_cdev_event_phy_packet {
434607ca46eSDavid Howells 	__u64 closure;
435607ca46eSDavid Howells 	__u32 type;
436607ca46eSDavid Howells 	__u32 rcode;
437607ca46eSDavid Howells 	__u32 length;
43894dfc73eSGustavo A. R. Silva 	__u32 data[];
439607ca46eSDavid Howells };
440607ca46eSDavid Howells 
441607ca46eSDavid Howells /**
442e27b3939STakashi Sakamoto  * struct fw_cdev_event_phy_packet2 - A PHY packet was transmitted or received with time stamp.
443e27b3939STakashi Sakamoto  * @closure:	See &fw_cdev_event_common; set by %FW_CDEV_IOC_SEND_PHY_PACKET
444e27b3939STakashi Sakamoto  *		or %FW_CDEV_IOC_RECEIVE_PHY_PACKETS ioctl
445e27b3939STakashi Sakamoto  * @type:	%FW_CDEV_EVENT_PHY_PACKET_SENT2 or %FW_CDEV_EVENT_PHY_PACKET_RECEIVED2
446e27b3939STakashi Sakamoto  * @rcode:	%RCODE_..., indicates success or failure of transmission
447e27b3939STakashi Sakamoto  * @length:	Data length in bytes
448e27b3939STakashi Sakamoto  * @tstamp:	For %FW_CDEV_EVENT_PHY_PACKET_RECEIVED2, the time stamp of isochronous cycle at
449e27b3939STakashi Sakamoto  *		which the packet arrived. For %FW_CDEV_EVENT_PHY_PACKET_SENT2 and non-ping packet,
450e27b3939STakashi Sakamoto  *		the time stamp of isochronous cycle at which the packet was sent. For ping packet,
451e27b3939STakashi Sakamoto  *		the tick count for round-trip time measured by 1394 OHCI controller.
452e27b3939STakashi Sakamoto  * The time stamp of isochronous cycle at which either the response was sent for
453e27b3939STakashi Sakamoto  *		%FW_CDEV_EVENT_PHY_PACKET_SENT2 or the request arrived for
454e27b3939STakashi Sakamoto  *		%FW_CDEV_EVENT_PHY_PACKET_RECEIVED2.
455e27b3939STakashi Sakamoto  * @data:	Incoming data
456e27b3939STakashi Sakamoto  *
457e27b3939STakashi Sakamoto  * If @type is %FW_CDEV_EVENT_PHY_PACKET_SENT2, @length is 8 and @data consists of the two PHY
458e27b3939STakashi Sakamoto  * packet quadlets to be sent, in host byte order,
459e27b3939STakashi Sakamoto  *
460e27b3939STakashi Sakamoto  * If @type is %FW_CDEV_EVENT_PHY_PACKET_RECEIVED2, @length is 8 and @data consists of the two PHY
461e27b3939STakashi Sakamoto  * packet quadlets, in host byte order.
462e27b3939STakashi Sakamoto  *
463e27b3939STakashi Sakamoto  * For %FW_CDEV_EVENT_PHY_PACKET_RECEIVED2, the @tstamp is the isochronous cycle at which the
464e27b3939STakashi Sakamoto  * packet arrived. It is 16 bit integer value and the higher 3 bits expresses three low order bits
465e27b3939STakashi Sakamoto  * of second field and the rest 13 bits expresses cycle field in the format of CYCLE_TIME register.
466e27b3939STakashi Sakamoto  *
467e27b3939STakashi Sakamoto  * For %FW_CDEV_EVENT_PHY_PACKET_SENT2, the @tstamp has different meanings whether to sent the
468e27b3939STakashi Sakamoto  * packet for ping or not. If it's not for ping, the @tstamp is the isochronous cycle at which the
469e27b3939STakashi Sakamoto  * packet was sent, and use the same format as the case of %FW_CDEV_EVENT_PHY_PACKET_SENT2. If it's
470e27b3939STakashi Sakamoto  * for ping, the @tstamp is for round-trip time measured by 1394 OHCI controller with 42.195 MHz
471e27b3939STakashi Sakamoto  * resolution.
472e27b3939STakashi Sakamoto  */
473e27b3939STakashi Sakamoto struct fw_cdev_event_phy_packet2 {
474e27b3939STakashi Sakamoto 	__u64 closure;
475e27b3939STakashi Sakamoto 	__u32 type;
476e27b3939STakashi Sakamoto 	__u32 rcode;
477e27b3939STakashi Sakamoto 	__u32 length;
478e27b3939STakashi Sakamoto 	__u32 tstamp;
479e27b3939STakashi Sakamoto 	__u32 data[];
480e27b3939STakashi Sakamoto };
481e27b3939STakashi Sakamoto 
482e27b3939STakashi Sakamoto /**
4839a400682SRandy Dunlap  * union fw_cdev_event - Convenience union of fw_cdev_event_* types
484607ca46eSDavid Howells  * @common:		Valid for all types
485607ca46eSDavid Howells  * @bus_reset:		Valid if @common.type == %FW_CDEV_EVENT_BUS_RESET
486607ca46eSDavid Howells  * @response:		Valid if @common.type == %FW_CDEV_EVENT_RESPONSE
487607ca46eSDavid Howells  * @request:		Valid if @common.type == %FW_CDEV_EVENT_REQUEST
488607ca46eSDavid Howells  * @request2:		Valid if @common.type == %FW_CDEV_EVENT_REQUEST2
489607ca46eSDavid Howells  * @iso_interrupt:	Valid if @common.type == %FW_CDEV_EVENT_ISO_INTERRUPT
490607ca46eSDavid Howells  * @iso_interrupt_mc:	Valid if @common.type ==
491607ca46eSDavid Howells  *				%FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL
492607ca46eSDavid Howells  * @iso_resource:	Valid if @common.type ==
493607ca46eSDavid Howells  *				%FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or
494607ca46eSDavid Howells  *				%FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED
495607ca46eSDavid Howells  * @phy_packet:		Valid if @common.type ==
496607ca46eSDavid Howells  *				%FW_CDEV_EVENT_PHY_PACKET_SENT or
497607ca46eSDavid Howells  *				%FW_CDEV_EVENT_PHY_PACKET_RECEIVED
498607ca46eSDavid Howells  *
4997c22d4a9STakashi Sakamoto  * @request3:		Valid if @common.type == %FW_CDEV_EVENT_REQUEST3
500fc2b52cfSTakashi Sakamoto  * @response2:		Valid if @common.type == %FW_CDEV_EVENT_RESPONSE2
501e27b3939STakashi Sakamoto  * @phy_packet2:	Valid if @common.type == %FW_CDEV_EVENT_PHY_PACKET_SENT2 or
502e27b3939STakashi Sakamoto  *				%FW_CDEV_EVENT_PHY_PACKET_RECEIVED2
5037c22d4a9STakashi Sakamoto  *
504607ca46eSDavid Howells  * Convenience union for userspace use.  Events could be read(2) into an
505607ca46eSDavid Howells  * appropriately aligned char buffer and then cast to this union for further
506607ca46eSDavid Howells  * processing.  Note that for a request, response or iso_interrupt event,
507607ca46eSDavid Howells  * the data[] or header[] may make the size of the full event larger than
508607ca46eSDavid Howells  * sizeof(union fw_cdev_event).  Also note that if you attempt to read(2)
509607ca46eSDavid Howells  * an event into a buffer that is not large enough for it, the data that does
510607ca46eSDavid Howells  * not fit will be discarded so that the next read(2) will return a new event.
511607ca46eSDavid Howells  */
512607ca46eSDavid Howells union fw_cdev_event {
513607ca46eSDavid Howells 	struct fw_cdev_event_common		common;
514607ca46eSDavid Howells 	struct fw_cdev_event_bus_reset		bus_reset;
515607ca46eSDavid Howells 	struct fw_cdev_event_response		response;
516607ca46eSDavid Howells 	struct fw_cdev_event_request		request;
517607ca46eSDavid Howells 	struct fw_cdev_event_request2		request2;		/* added in 2.6.36 */
518607ca46eSDavid Howells 	struct fw_cdev_event_iso_interrupt	iso_interrupt;
519607ca46eSDavid Howells 	struct fw_cdev_event_iso_interrupt_mc	iso_interrupt_mc;	/* added in 2.6.36 */
520607ca46eSDavid Howells 	struct fw_cdev_event_iso_resource	iso_resource;		/* added in 2.6.30 */
521607ca46eSDavid Howells 	struct fw_cdev_event_phy_packet		phy_packet;		/* added in 2.6.36 */
5227c22d4a9STakashi Sakamoto 	struct fw_cdev_event_request3		request3;		/* added in 6.5 */
523fc2b52cfSTakashi Sakamoto 	struct fw_cdev_event_response2		response2;		/* added in 6.5 */
524e27b3939STakashi Sakamoto 	struct fw_cdev_event_phy_packet2	phy_packet2;		/* added in 6.5 */
525607ca46eSDavid Howells };
526607ca46eSDavid Howells 
527607ca46eSDavid Howells /* available since kernel version 2.6.22 */
528607ca46eSDavid Howells #define FW_CDEV_IOC_GET_INFO           _IOWR('#', 0x00, struct fw_cdev_get_info)
529607ca46eSDavid Howells #define FW_CDEV_IOC_SEND_REQUEST        _IOW('#', 0x01, struct fw_cdev_send_request)
530607ca46eSDavid Howells #define FW_CDEV_IOC_ALLOCATE           _IOWR('#', 0x02, struct fw_cdev_allocate)
531607ca46eSDavid Howells #define FW_CDEV_IOC_DEALLOCATE          _IOW('#', 0x03, struct fw_cdev_deallocate)
532607ca46eSDavid Howells #define FW_CDEV_IOC_SEND_RESPONSE       _IOW('#', 0x04, struct fw_cdev_send_response)
533607ca46eSDavid Howells #define FW_CDEV_IOC_INITIATE_BUS_RESET  _IOW('#', 0x05, struct fw_cdev_initiate_bus_reset)
534607ca46eSDavid Howells #define FW_CDEV_IOC_ADD_DESCRIPTOR     _IOWR('#', 0x06, struct fw_cdev_add_descriptor)
535607ca46eSDavid Howells #define FW_CDEV_IOC_REMOVE_DESCRIPTOR   _IOW('#', 0x07, struct fw_cdev_remove_descriptor)
536607ca46eSDavid Howells #define FW_CDEV_IOC_CREATE_ISO_CONTEXT _IOWR('#', 0x08, struct fw_cdev_create_iso_context)
537607ca46eSDavid Howells #define FW_CDEV_IOC_QUEUE_ISO          _IOWR('#', 0x09, struct fw_cdev_queue_iso)
538607ca46eSDavid Howells #define FW_CDEV_IOC_START_ISO           _IOW('#', 0x0a, struct fw_cdev_start_iso)
539607ca46eSDavid Howells #define FW_CDEV_IOC_STOP_ISO            _IOW('#', 0x0b, struct fw_cdev_stop_iso)
540607ca46eSDavid Howells 
541607ca46eSDavid Howells /* available since kernel version 2.6.24 */
542607ca46eSDavid Howells #define FW_CDEV_IOC_GET_CYCLE_TIMER     _IOR('#', 0x0c, struct fw_cdev_get_cycle_timer)
543607ca46eSDavid Howells 
544607ca46eSDavid Howells /* available since kernel version 2.6.30 */
545607ca46eSDavid Howells #define FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE       _IOWR('#', 0x0d, struct fw_cdev_allocate_iso_resource)
546607ca46eSDavid Howells #define FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE      _IOW('#', 0x0e, struct fw_cdev_deallocate)
547607ca46eSDavid Howells #define FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE   _IOW('#', 0x0f, struct fw_cdev_allocate_iso_resource)
548607ca46eSDavid Howells #define FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE _IOW('#', 0x10, struct fw_cdev_allocate_iso_resource)
549607ca46eSDavid Howells #define FW_CDEV_IOC_GET_SPEED                     _IO('#', 0x11) /* returns speed code */
550607ca46eSDavid Howells #define FW_CDEV_IOC_SEND_BROADCAST_REQUEST       _IOW('#', 0x12, struct fw_cdev_send_request)
551607ca46eSDavid Howells #define FW_CDEV_IOC_SEND_STREAM_PACKET           _IOW('#', 0x13, struct fw_cdev_send_stream_packet)
552607ca46eSDavid Howells 
553607ca46eSDavid Howells /* available since kernel version 2.6.34 */
554607ca46eSDavid Howells #define FW_CDEV_IOC_GET_CYCLE_TIMER2   _IOWR('#', 0x14, struct fw_cdev_get_cycle_timer2)
555607ca46eSDavid Howells 
556607ca46eSDavid Howells /* available since kernel version 2.6.36 */
557607ca46eSDavid Howells #define FW_CDEV_IOC_SEND_PHY_PACKET    _IOWR('#', 0x15, struct fw_cdev_send_phy_packet)
558607ca46eSDavid Howells #define FW_CDEV_IOC_RECEIVE_PHY_PACKETS _IOW('#', 0x16, struct fw_cdev_receive_phy_packets)
559607ca46eSDavid Howells #define FW_CDEV_IOC_SET_ISO_CHANNELS    _IOW('#', 0x17, struct fw_cdev_set_iso_channels)
560607ca46eSDavid Howells 
561607ca46eSDavid Howells /* available since kernel version 3.4 */
562607ca46eSDavid Howells #define FW_CDEV_IOC_FLUSH_ISO           _IOW('#', 0x18, struct fw_cdev_flush_iso)
563607ca46eSDavid Howells 
564607ca46eSDavid Howells /*
565607ca46eSDavid Howells  * ABI version history
566607ca46eSDavid Howells  *  1  (2.6.22)  - initial version
567607ca46eSDavid Howells  *     (2.6.24)  - added %FW_CDEV_IOC_GET_CYCLE_TIMER
568607ca46eSDavid Howells  *  2  (2.6.30)  - changed &fw_cdev_event_iso_interrupt.header if
569607ca46eSDavid Howells  *                 &fw_cdev_create_iso_context.header_size is 8 or more
570607ca46eSDavid Howells  *               - added %FW_CDEV_IOC_*_ISO_RESOURCE*,
571607ca46eSDavid Howells  *                 %FW_CDEV_IOC_GET_SPEED, %FW_CDEV_IOC_SEND_BROADCAST_REQUEST,
572607ca46eSDavid Howells  *                 %FW_CDEV_IOC_SEND_STREAM_PACKET
573607ca46eSDavid Howells  *     (2.6.32)  - added time stamp to xmit &fw_cdev_event_iso_interrupt
574607ca46eSDavid Howells  *     (2.6.33)  - IR has always packet-per-buffer semantics now, not one of
575607ca46eSDavid Howells  *                 dual-buffer or packet-per-buffer depending on hardware
576607ca46eSDavid Howells  *               - shared use and auto-response for FCP registers
577607ca46eSDavid Howells  *  3  (2.6.34)  - made &fw_cdev_get_cycle_timer reliable
578607ca46eSDavid Howells  *               - added %FW_CDEV_IOC_GET_CYCLE_TIMER2
579607ca46eSDavid Howells  *  4  (2.6.36)  - added %FW_CDEV_EVENT_REQUEST2, %FW_CDEV_EVENT_PHY_PACKET_*,
580607ca46eSDavid Howells  *                 and &fw_cdev_allocate.region_end
581607ca46eSDavid Howells  *               - implemented &fw_cdev_event_bus_reset.bm_node_id
582607ca46eSDavid Howells  *               - added %FW_CDEV_IOC_SEND_PHY_PACKET, _RECEIVE_PHY_PACKETS
583607ca46eSDavid Howells  *               - added %FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL,
584607ca46eSDavid Howells  *                 %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL, and
585607ca46eSDavid Howells  *                 %FW_CDEV_IOC_SET_ISO_CHANNELS
586607ca46eSDavid Howells  *  5  (3.4)     - send %FW_CDEV_EVENT_ISO_INTERRUPT events when needed to
587607ca46eSDavid Howells  *                 avoid dropping data
588607ca46eSDavid Howells  *               - added %FW_CDEV_IOC_FLUSH_ISO
5896add87e9STakashi Sakamoto  *  6  (6.5)     - added some event for subactions of asynchronous transaction with time stamp
5907c22d4a9STakashi Sakamoto  *                   - %FW_CDEV_EVENT_REQUEST3
591fc2b52cfSTakashi Sakamoto  *                   - %FW_CDEV_EVENT_RESPONSE2
592e27b3939STakashi Sakamoto  *                   - %FW_CDEV_EVENT_PHY_PACKET_SENT2
593e27b3939STakashi Sakamoto  *                   - %FW_CDEV_EVENT_PHY_PACKET_RECEIVED2
594607ca46eSDavid Howells  */
595607ca46eSDavid Howells 
596607ca46eSDavid Howells /**
597607ca46eSDavid Howells  * struct fw_cdev_get_info - General purpose information ioctl
598607ca46eSDavid Howells  * @version:	The version field is just a running serial number.  Both an
599607ca46eSDavid Howells  *		input parameter (ABI version implemented by the client) and
600607ca46eSDavid Howells  *		output parameter (ABI version implemented by the kernel).
601607ca46eSDavid Howells  *		A client shall fill in the ABI @version for which the client
602607ca46eSDavid Howells  *		was implemented.  This is necessary for forward compatibility.
603607ca46eSDavid Howells  * @rom_length:	If @rom is non-zero, up to @rom_length bytes of Configuration
604607ca46eSDavid Howells  *		ROM will be copied into that user space address.  In either
605607ca46eSDavid Howells  *		case, @rom_length is updated with the actual length of the
606607ca46eSDavid Howells  *		Configuration ROM.
607607ca46eSDavid Howells  * @rom:	If non-zero, address of a buffer to be filled by a copy of the
608607ca46eSDavid Howells  *		device's Configuration ROM
609607ca46eSDavid Howells  * @bus_reset:	If non-zero, address of a buffer to be filled by a
610607ca46eSDavid Howells  *		&struct fw_cdev_event_bus_reset with the current state
611607ca46eSDavid Howells  *		of the bus.  This does not cause a bus reset to happen.
612607ca46eSDavid Howells  * @bus_reset_closure: Value of &closure in this and subsequent bus reset events
613607ca46eSDavid Howells  * @card:	The index of the card this device belongs to
614607ca46eSDavid Howells  *
615607ca46eSDavid Howells  * The %FW_CDEV_IOC_GET_INFO ioctl is usually the very first one which a client
616607ca46eSDavid Howells  * performs right after it opened a /dev/fw* file.
617607ca46eSDavid Howells  *
618607ca46eSDavid Howells  * As a side effect, reception of %FW_CDEV_EVENT_BUS_RESET events to be read(2)
619607ca46eSDavid Howells  * is started by this ioctl.
620607ca46eSDavid Howells  */
621607ca46eSDavid Howells struct fw_cdev_get_info {
622607ca46eSDavid Howells 	__u32 version;
623607ca46eSDavid Howells 	__u32 rom_length;
624607ca46eSDavid Howells 	__u64 rom;
625607ca46eSDavid Howells 	__u64 bus_reset;
626607ca46eSDavid Howells 	__u64 bus_reset_closure;
627607ca46eSDavid Howells 	__u32 card;
628607ca46eSDavid Howells };
629607ca46eSDavid Howells 
630607ca46eSDavid Howells /**
631607ca46eSDavid Howells  * struct fw_cdev_send_request - Send an asynchronous request packet
632607ca46eSDavid Howells  * @tcode:	Transaction code of the request
633607ca46eSDavid Howells  * @length:	Length of outgoing payload, in bytes
634607ca46eSDavid Howells  * @offset:	48-bit offset at destination node
635607ca46eSDavid Howells  * @closure:	Passed back to userspace in the response event
636607ca46eSDavid Howells  * @data:	Userspace pointer to payload
637607ca46eSDavid Howells  * @generation:	The bus generation where packet is valid
638607ca46eSDavid Howells  *
639fc2b52cfSTakashi Sakamoto  * Send a request to the device.  This ioctl implements all outgoing requests. Both quadlet and
640fc2b52cfSTakashi Sakamoto  * block request specify the payload as a pointer to the data in the @data field. Once the
641fc2b52cfSTakashi Sakamoto  * transaction completes, the kernel writes either &fw_cdev_event_response event or
642fc2b52cfSTakashi Sakamoto  * &fw_cdev_event_response event back. The @closure field is passed back to user space in the
643fc2b52cfSTakashi Sakamoto  * response event.
644607ca46eSDavid Howells  */
645607ca46eSDavid Howells struct fw_cdev_send_request {
646607ca46eSDavid Howells 	__u32 tcode;
647607ca46eSDavid Howells 	__u32 length;
648607ca46eSDavid Howells 	__u64 offset;
649607ca46eSDavid Howells 	__u64 closure;
650607ca46eSDavid Howells 	__u64 data;
651607ca46eSDavid Howells 	__u32 generation;
652607ca46eSDavid Howells };
653607ca46eSDavid Howells 
654607ca46eSDavid Howells /**
655607ca46eSDavid Howells  * struct fw_cdev_send_response - Send an asynchronous response packet
656607ca46eSDavid Howells  * @rcode:	Response code as determined by the userspace handler
657607ca46eSDavid Howells  * @length:	Length of outgoing payload, in bytes
658607ca46eSDavid Howells  * @data:	Userspace pointer to payload
659607ca46eSDavid Howells  * @handle:	The handle from the &fw_cdev_event_request
660607ca46eSDavid Howells  *
661607ca46eSDavid Howells  * Send a response to an incoming request.  By setting up an address range using
662607ca46eSDavid Howells  * the %FW_CDEV_IOC_ALLOCATE ioctl, userspace can listen for incoming requests.  An
663607ca46eSDavid Howells  * incoming request will generate an %FW_CDEV_EVENT_REQUEST, and userspace must
664607ca46eSDavid Howells  * send a reply using this ioctl.  The event has a handle to the kernel-side
665607ca46eSDavid Howells  * pending transaction, which should be used with this ioctl.
666607ca46eSDavid Howells  */
667607ca46eSDavid Howells struct fw_cdev_send_response {
668607ca46eSDavid Howells 	__u32 rcode;
669607ca46eSDavid Howells 	__u32 length;
670607ca46eSDavid Howells 	__u64 data;
671607ca46eSDavid Howells 	__u32 handle;
672607ca46eSDavid Howells };
673607ca46eSDavid Howells 
674607ca46eSDavid Howells /**
675607ca46eSDavid Howells  * struct fw_cdev_allocate - Allocate a CSR in an address range
676607ca46eSDavid Howells  * @offset:	Start offset of the address range
677607ca46eSDavid Howells  * @closure:	To be passed back to userspace in request events
678607ca46eSDavid Howells  * @length:	Length of the CSR, in bytes
679607ca46eSDavid Howells  * @handle:	Handle to the allocation, written by the kernel
680607ca46eSDavid Howells  * @region_end:	First address above the address range (added in ABI v4, 2.6.36)
681607ca46eSDavid Howells  *
682607ca46eSDavid Howells  * Allocate an address range in the 48-bit address space on the local node
683607ca46eSDavid Howells  * (the controller).  This allows userspace to listen for requests with an
684607ca46eSDavid Howells  * offset within that address range.  Every time when the kernel receives a
685607ca46eSDavid Howells  * request within the range, an &fw_cdev_event_request2 event will be emitted.
686607ca46eSDavid Howells  * (If the kernel or the client implements ABI version <= 3, an
687607ca46eSDavid Howells  * &fw_cdev_event_request will be generated instead.)
688607ca46eSDavid Howells  *
689607ca46eSDavid Howells  * The @closure field is passed back to userspace in these request events.
690607ca46eSDavid Howells  * The @handle field is an out parameter, returning a handle to the allocated
691607ca46eSDavid Howells  * range to be used for later deallocation of the range.
692607ca46eSDavid Howells  *
693607ca46eSDavid Howells  * The address range is allocated on all local nodes.  The address allocation
694607ca46eSDavid Howells  * is exclusive except for the FCP command and response registers.  If an
695607ca46eSDavid Howells  * exclusive address region is already in use, the ioctl fails with errno set
696607ca46eSDavid Howells  * to %EBUSY.
697607ca46eSDavid Howells  *
698607ca46eSDavid Howells  * If kernel and client implement ABI version >= 4, the kernel looks up a free
699607ca46eSDavid Howells  * spot of size @length inside [@offset..@region_end) and, if found, writes
700607ca46eSDavid Howells  * the start address of the new CSR back in @offset.  I.e. @offset is an
701607ca46eSDavid Howells  * in and out parameter.  If this automatic placement of a CSR in a bigger
702607ca46eSDavid Howells  * address range is not desired, the client simply needs to set @region_end
703607ca46eSDavid Howells  * = @offset + @length.
704607ca46eSDavid Howells  *
705607ca46eSDavid Howells  * If the kernel or the client implements ABI version <= 3, @region_end is
706607ca46eSDavid Howells  * ignored and effectively assumed to be @offset + @length.
707607ca46eSDavid Howells  *
708607ca46eSDavid Howells  * @region_end is only present in a kernel header >= 2.6.36.  If necessary,
709607ca46eSDavid Howells  * this can for example be tested by #ifdef FW_CDEV_EVENT_REQUEST2.
710607ca46eSDavid Howells  */
711607ca46eSDavid Howells struct fw_cdev_allocate {
712607ca46eSDavid Howells 	__u64 offset;
713607ca46eSDavid Howells 	__u64 closure;
714607ca46eSDavid Howells 	__u32 length;
715607ca46eSDavid Howells 	__u32 handle;
716607ca46eSDavid Howells 	__u64 region_end;	/* available since kernel version 2.6.36 */
717607ca46eSDavid Howells };
718607ca46eSDavid Howells 
719607ca46eSDavid Howells /**
720607ca46eSDavid Howells  * struct fw_cdev_deallocate - Free a CSR address range or isochronous resource
721607ca46eSDavid Howells  * @handle:	Handle to the address range or iso resource, as returned by the
722607ca46eSDavid Howells  *		kernel when the range or resource was allocated
723607ca46eSDavid Howells  */
724607ca46eSDavid Howells struct fw_cdev_deallocate {
725607ca46eSDavid Howells 	__u32 handle;
726607ca46eSDavid Howells };
727607ca46eSDavid Howells 
728607ca46eSDavid Howells #define FW_CDEV_LONG_RESET	0
729607ca46eSDavid Howells #define FW_CDEV_SHORT_RESET	1
730607ca46eSDavid Howells 
731607ca46eSDavid Howells /**
732607ca46eSDavid Howells  * struct fw_cdev_initiate_bus_reset - Initiate a bus reset
733607ca46eSDavid Howells  * @type:	%FW_CDEV_SHORT_RESET or %FW_CDEV_LONG_RESET
734607ca46eSDavid Howells  *
735607ca46eSDavid Howells  * Initiate a bus reset for the bus this device is on.  The bus reset can be
736607ca46eSDavid Howells  * either the original (long) bus reset or the arbitrated (short) bus reset
737607ca46eSDavid Howells  * introduced in 1394a-2000.
738607ca46eSDavid Howells  *
739607ca46eSDavid Howells  * The ioctl returns immediately.  A subsequent &fw_cdev_event_bus_reset
740607ca46eSDavid Howells  * indicates when the reset actually happened.  Since ABI v4, this may be
741607ca46eSDavid Howells  * considerably later than the ioctl because the kernel ensures a grace period
742607ca46eSDavid Howells  * between subsequent bus resets as per IEEE 1394 bus management specification.
743607ca46eSDavid Howells  */
744607ca46eSDavid Howells struct fw_cdev_initiate_bus_reset {
745607ca46eSDavid Howells 	__u32 type;
746607ca46eSDavid Howells };
747607ca46eSDavid Howells 
748607ca46eSDavid Howells /**
749607ca46eSDavid Howells  * struct fw_cdev_add_descriptor - Add contents to the local node's config ROM
750607ca46eSDavid Howells  * @immediate:	If non-zero, immediate key to insert before pointer
751607ca46eSDavid Howells  * @key:	Upper 8 bits of root directory pointer
752607ca46eSDavid Howells  * @data:	Userspace pointer to contents of descriptor block
753607ca46eSDavid Howells  * @length:	Length of descriptor block data, in quadlets
754607ca46eSDavid Howells  * @handle:	Handle to the descriptor, written by the kernel
755607ca46eSDavid Howells  *
756607ca46eSDavid Howells  * Add a descriptor block and optionally a preceding immediate key to the local
757607ca46eSDavid Howells  * node's Configuration ROM.
758607ca46eSDavid Howells  *
759607ca46eSDavid Howells  * The @key field specifies the upper 8 bits of the descriptor root directory
760607ca46eSDavid Howells  * pointer and the @data and @length fields specify the contents. The @key
761607ca46eSDavid Howells  * should be of the form 0xXX000000. The offset part of the root directory entry
762607ca46eSDavid Howells  * will be filled in by the kernel.
763607ca46eSDavid Howells  *
764607ca46eSDavid Howells  * If not 0, the @immediate field specifies an immediate key which will be
765607ca46eSDavid Howells  * inserted before the root directory pointer.
766607ca46eSDavid Howells  *
767607ca46eSDavid Howells  * @immediate, @key, and @data array elements are CPU-endian quadlets.
768607ca46eSDavid Howells  *
769607ca46eSDavid Howells  * If successful, the kernel adds the descriptor and writes back a @handle to
770607ca46eSDavid Howells  * the kernel-side object to be used for later removal of the descriptor block
771607ca46eSDavid Howells  * and immediate key.  The kernel will also generate a bus reset to signal the
772607ca46eSDavid Howells  * change of the Configuration ROM to other nodes.
773607ca46eSDavid Howells  *
774607ca46eSDavid Howells  * This ioctl affects the Configuration ROMs of all local nodes.
775607ca46eSDavid Howells  * The ioctl only succeeds on device files which represent a local node.
776607ca46eSDavid Howells  */
777607ca46eSDavid Howells struct fw_cdev_add_descriptor {
778607ca46eSDavid Howells 	__u32 immediate;
779607ca46eSDavid Howells 	__u32 key;
780607ca46eSDavid Howells 	__u64 data;
781607ca46eSDavid Howells 	__u32 length;
782607ca46eSDavid Howells 	__u32 handle;
783607ca46eSDavid Howells };
784607ca46eSDavid Howells 
785607ca46eSDavid Howells /**
786607ca46eSDavid Howells  * struct fw_cdev_remove_descriptor - Remove contents from the Configuration ROM
787607ca46eSDavid Howells  * @handle:	Handle to the descriptor, as returned by the kernel when the
788607ca46eSDavid Howells  *		descriptor was added
789607ca46eSDavid Howells  *
790607ca46eSDavid Howells  * Remove a descriptor block and accompanying immediate key from the local
791607ca46eSDavid Howells  * nodes' Configuration ROMs.  The kernel will also generate a bus reset to
792607ca46eSDavid Howells  * signal the change of the Configuration ROM to other nodes.
793607ca46eSDavid Howells  */
794607ca46eSDavid Howells struct fw_cdev_remove_descriptor {
795607ca46eSDavid Howells 	__u32 handle;
796607ca46eSDavid Howells };
797607ca46eSDavid Howells 
798607ca46eSDavid Howells #define FW_CDEV_ISO_CONTEXT_TRANSMIT			0
799607ca46eSDavid Howells #define FW_CDEV_ISO_CONTEXT_RECEIVE			1
800607ca46eSDavid Howells #define FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL	2 /* added in 2.6.36 */
801607ca46eSDavid Howells 
802607ca46eSDavid Howells /**
803607ca46eSDavid Howells  * struct fw_cdev_create_iso_context - Create a context for isochronous I/O
804607ca46eSDavid Howells  * @type:	%FW_CDEV_ISO_CONTEXT_TRANSMIT or %FW_CDEV_ISO_CONTEXT_RECEIVE or
805607ca46eSDavid Howells  *		%FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL
806607ca46eSDavid Howells  * @header_size: Header size to strip in single-channel reception
807607ca46eSDavid Howells  * @channel:	Channel to bind to in single-channel reception or transmission
808607ca46eSDavid Howells  * @speed:	Transmission speed
809607ca46eSDavid Howells  * @closure:	To be returned in &fw_cdev_event_iso_interrupt or
810607ca46eSDavid Howells  *		&fw_cdev_event_iso_interrupt_multichannel
811607ca46eSDavid Howells  * @handle:	Handle to context, written back by kernel
812607ca46eSDavid Howells  *
813607ca46eSDavid Howells  * Prior to sending or receiving isochronous I/O, a context must be created.
814607ca46eSDavid Howells  * The context records information about the transmit or receive configuration
815607ca46eSDavid Howells  * and typically maps to an underlying hardware resource.  A context is set up
816607ca46eSDavid Howells  * for either sending or receiving.  It is bound to a specific isochronous
817607ca46eSDavid Howells  * @channel.
818607ca46eSDavid Howells  *
819607ca46eSDavid Howells  * In case of multichannel reception, @header_size and @channel are ignored
820607ca46eSDavid Howells  * and the channels are selected by %FW_CDEV_IOC_SET_ISO_CHANNELS.
821607ca46eSDavid Howells  *
822607ca46eSDavid Howells  * For %FW_CDEV_ISO_CONTEXT_RECEIVE contexts, @header_size must be at least 4
823607ca46eSDavid Howells  * and must be a multiple of 4.  It is ignored in other context types.
824607ca46eSDavid Howells  *
825607ca46eSDavid Howells  * @speed is ignored in receive context types.
826607ca46eSDavid Howells  *
827607ca46eSDavid Howells  * If a context was successfully created, the kernel writes back a handle to the
828607ca46eSDavid Howells  * context, which must be passed in for subsequent operations on that context.
829607ca46eSDavid Howells  *
830607ca46eSDavid Howells  * Limitations:
831607ca46eSDavid Howells  * No more than one iso context can be created per fd.
832607ca46eSDavid Howells  * The total number of contexts that all userspace and kernelspace drivers can
833607ca46eSDavid Howells  * create on a card at a time is a hardware limit, typically 4 or 8 contexts per
834607ca46eSDavid Howells  * direction, and of them at most one multichannel receive context.
835607ca46eSDavid Howells  */
836607ca46eSDavid Howells struct fw_cdev_create_iso_context {
837607ca46eSDavid Howells 	__u32 type;
838607ca46eSDavid Howells 	__u32 header_size;
839607ca46eSDavid Howells 	__u32 channel;
840607ca46eSDavid Howells 	__u32 speed;
841607ca46eSDavid Howells 	__u64 closure;
842607ca46eSDavid Howells 	__u32 handle;
843607ca46eSDavid Howells };
844607ca46eSDavid Howells 
845607ca46eSDavid Howells /**
846607ca46eSDavid Howells  * struct fw_cdev_set_iso_channels - Select channels in multichannel reception
847607ca46eSDavid Howells  * @channels:	Bitmask of channels to listen to
848607ca46eSDavid Howells  * @handle:	Handle of the mutichannel receive context
849607ca46eSDavid Howells  *
850607ca46eSDavid Howells  * @channels is the bitwise or of 1ULL << n for each channel n to listen to.
851607ca46eSDavid Howells  *
852607ca46eSDavid Howells  * The ioctl fails with errno %EBUSY if there is already another receive context
853607ca46eSDavid Howells  * on a channel in @channels.  In that case, the bitmask of all unoccupied
854607ca46eSDavid Howells  * channels is returned in @channels.
855607ca46eSDavid Howells  */
856607ca46eSDavid Howells struct fw_cdev_set_iso_channels {
857607ca46eSDavid Howells 	__u64 channels;
858607ca46eSDavid Howells 	__u32 handle;
859607ca46eSDavid Howells };
860607ca46eSDavid Howells 
861607ca46eSDavid Howells #define FW_CDEV_ISO_PAYLOAD_LENGTH(v)	(v)
862607ca46eSDavid Howells #define FW_CDEV_ISO_INTERRUPT		(1 << 16)
863607ca46eSDavid Howells #define FW_CDEV_ISO_SKIP		(1 << 17)
864607ca46eSDavid Howells #define FW_CDEV_ISO_SYNC		(1 << 17)
865607ca46eSDavid Howells #define FW_CDEV_ISO_TAG(v)		((v) << 18)
866607ca46eSDavid Howells #define FW_CDEV_ISO_SY(v)		((v) << 20)
867607ca46eSDavid Howells #define FW_CDEV_ISO_HEADER_LENGTH(v)	((v) << 24)
868607ca46eSDavid Howells 
869607ca46eSDavid Howells /**
870607ca46eSDavid Howells  * struct fw_cdev_iso_packet - Isochronous packet
871607ca46eSDavid Howells  * @control:	Contains the header length (8 uppermost bits),
872607ca46eSDavid Howells  *		the sy field (4 bits), the tag field (2 bits), a sync flag
873607ca46eSDavid Howells  *		or a skip flag (1 bit), an interrupt flag (1 bit), and the
874607ca46eSDavid Howells  *		payload length (16 lowermost bits)
875607ca46eSDavid Howells  * @header:	Header and payload in case of a transmit context.
876607ca46eSDavid Howells  *
877607ca46eSDavid Howells  * &struct fw_cdev_iso_packet is used to describe isochronous packet queues.
8789a400682SRandy Dunlap  * Use the FW_CDEV_ISO_* macros to fill in @control.
879607ca46eSDavid Howells  * The @header array is empty in case of receive contexts.
880607ca46eSDavid Howells  *
881607ca46eSDavid Howells  * Context type %FW_CDEV_ISO_CONTEXT_TRANSMIT:
882607ca46eSDavid Howells  *
883607ca46eSDavid Howells  * @control.HEADER_LENGTH must be a multiple of 4.  It specifies the numbers of
884607ca46eSDavid Howells  * bytes in @header that will be prepended to the packet's payload.  These bytes
885607ca46eSDavid Howells  * are copied into the kernel and will not be accessed after the ioctl has
886607ca46eSDavid Howells  * returned.
887607ca46eSDavid Howells  *
888607ca46eSDavid Howells  * The @control.SY and TAG fields are copied to the iso packet header.  These
889607ca46eSDavid Howells  * fields are specified by IEEE 1394a and IEC 61883-1.
890607ca46eSDavid Howells  *
891607ca46eSDavid Howells  * The @control.SKIP flag specifies that no packet is to be sent in a frame.
892607ca46eSDavid Howells  * When using this, all other fields except @control.INTERRUPT must be zero.
893607ca46eSDavid Howells  *
894607ca46eSDavid Howells  * When a packet with the @control.INTERRUPT flag set has been completed, an
895607ca46eSDavid Howells  * &fw_cdev_event_iso_interrupt event will be sent.
896607ca46eSDavid Howells  *
897607ca46eSDavid Howells  * Context type %FW_CDEV_ISO_CONTEXT_RECEIVE:
898607ca46eSDavid Howells  *
899607ca46eSDavid Howells  * @control.HEADER_LENGTH must be a multiple of the context's header_size.
900607ca46eSDavid Howells  * If the HEADER_LENGTH is larger than the context's header_size, multiple
901607ca46eSDavid Howells  * packets are queued for this entry.
902607ca46eSDavid Howells  *
903607ca46eSDavid Howells  * The @control.SY and TAG fields are ignored.
904607ca46eSDavid Howells  *
905607ca46eSDavid Howells  * If the @control.SYNC flag is set, the context drops all packets until a
906607ca46eSDavid Howells  * packet with a sy field is received which matches &fw_cdev_start_iso.sync.
907607ca46eSDavid Howells  *
908607ca46eSDavid Howells  * @control.PAYLOAD_LENGTH defines how many payload bytes can be received for
909607ca46eSDavid Howells  * one packet (in addition to payload quadlets that have been defined as headers
910607ca46eSDavid Howells  * and are stripped and returned in the &fw_cdev_event_iso_interrupt structure).
911607ca46eSDavid Howells  * If more bytes are received, the additional bytes are dropped.  If less bytes
912607ca46eSDavid Howells  * are received, the remaining bytes in this part of the payload buffer will not
913607ca46eSDavid Howells  * be written to, not even by the next packet.  I.e., packets received in
914607ca46eSDavid Howells  * consecutive frames will not necessarily be consecutive in memory.  If an
915607ca46eSDavid Howells  * entry has queued multiple packets, the PAYLOAD_LENGTH is divided equally
916607ca46eSDavid Howells  * among them.
917607ca46eSDavid Howells  *
918607ca46eSDavid Howells  * When a packet with the @control.INTERRUPT flag set has been completed, an
919607ca46eSDavid Howells  * &fw_cdev_event_iso_interrupt event will be sent.  An entry that has queued
920607ca46eSDavid Howells  * multiple receive packets is completed when its last packet is completed.
921607ca46eSDavid Howells  *
922607ca46eSDavid Howells  * Context type %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL:
923607ca46eSDavid Howells  *
924607ca46eSDavid Howells  * Here, &fw_cdev_iso_packet would be more aptly named _iso_buffer_chunk since
925607ca46eSDavid Howells  * it specifies a chunk of the mmap()'ed buffer, while the number and alignment
926607ca46eSDavid Howells  * of packets to be placed into the buffer chunk is not known beforehand.
927607ca46eSDavid Howells  *
928607ca46eSDavid Howells  * @control.PAYLOAD_LENGTH is the size of the buffer chunk and specifies room
929607ca46eSDavid Howells  * for header, payload, padding, and trailer bytes of one or more packets.
930607ca46eSDavid Howells  * It must be a multiple of 4.
931607ca46eSDavid Howells  *
932607ca46eSDavid Howells  * @control.HEADER_LENGTH, TAG and SY are ignored.  SYNC is treated as described
933607ca46eSDavid Howells  * for single-channel reception.
934607ca46eSDavid Howells  *
935607ca46eSDavid Howells  * When a buffer chunk with the @control.INTERRUPT flag set has been filled
936607ca46eSDavid Howells  * entirely, an &fw_cdev_event_iso_interrupt_mc event will be sent.
937607ca46eSDavid Howells  */
938607ca46eSDavid Howells struct fw_cdev_iso_packet {
939607ca46eSDavid Howells 	__u32 control;
94094dfc73eSGustavo A. R. Silva 	__u32 header[];
941607ca46eSDavid Howells };
942607ca46eSDavid Howells 
943607ca46eSDavid Howells /**
944607ca46eSDavid Howells  * struct fw_cdev_queue_iso - Queue isochronous packets for I/O
945607ca46eSDavid Howells  * @packets:	Userspace pointer to an array of &fw_cdev_iso_packet
946607ca46eSDavid Howells  * @data:	Pointer into mmap()'ed payload buffer
947607ca46eSDavid Howells  * @size:	Size of the @packets array, in bytes
948607ca46eSDavid Howells  * @handle:	Isochronous context handle
949607ca46eSDavid Howells  *
950607ca46eSDavid Howells  * Queue a number of isochronous packets for reception or transmission.
951607ca46eSDavid Howells  * This ioctl takes a pointer to an array of &fw_cdev_iso_packet structs,
952607ca46eSDavid Howells  * which describe how to transmit from or receive into a contiguous region
953607ca46eSDavid Howells  * of a mmap()'ed payload buffer.  As part of transmit packet descriptors,
954607ca46eSDavid Howells  * a series of headers can be supplied, which will be prepended to the
955607ca46eSDavid Howells  * payload during DMA.
956607ca46eSDavid Howells  *
957607ca46eSDavid Howells  * The kernel may or may not queue all packets, but will write back updated
958607ca46eSDavid Howells  * values of the @packets, @data and @size fields, so the ioctl can be
959607ca46eSDavid Howells  * resubmitted easily.
960607ca46eSDavid Howells  *
961607ca46eSDavid Howells  * In case of a multichannel receive context, @data must be quadlet-aligned
962607ca46eSDavid Howells  * relative to the buffer start.
963607ca46eSDavid Howells  */
964607ca46eSDavid Howells struct fw_cdev_queue_iso {
965607ca46eSDavid Howells 	__u64 packets;
966607ca46eSDavid Howells 	__u64 data;
967607ca46eSDavid Howells 	__u32 size;
968607ca46eSDavid Howells 	__u32 handle;
969607ca46eSDavid Howells };
970607ca46eSDavid Howells 
971607ca46eSDavid Howells #define FW_CDEV_ISO_CONTEXT_MATCH_TAG0		 1
972607ca46eSDavid Howells #define FW_CDEV_ISO_CONTEXT_MATCH_TAG1		 2
973607ca46eSDavid Howells #define FW_CDEV_ISO_CONTEXT_MATCH_TAG2		 4
974607ca46eSDavid Howells #define FW_CDEV_ISO_CONTEXT_MATCH_TAG3		 8
975607ca46eSDavid Howells #define FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS	15
976607ca46eSDavid Howells 
977607ca46eSDavid Howells /**
978607ca46eSDavid Howells  * struct fw_cdev_start_iso - Start an isochronous transmission or reception
979607ca46eSDavid Howells  * @cycle:	Cycle in which to start I/O.  If @cycle is greater than or
980607ca46eSDavid Howells  *		equal to 0, the I/O will start on that cycle.
981df54714fSRandy Dunlap  * @sync:	Determines the value to wait for receive packets that have
982607ca46eSDavid Howells  *		the %FW_CDEV_ISO_SYNC bit set
983607ca46eSDavid Howells  * @tags:	Tag filter bit mask.  Only valid for isochronous reception.
984607ca46eSDavid Howells  *		Determines the tag values for which packets will be accepted.
9859a400682SRandy Dunlap  *		Use FW_CDEV_ISO_CONTEXT_MATCH_* macros to set @tags.
986607ca46eSDavid Howells  * @handle:	Isochronous context handle within which to transmit or receive
987607ca46eSDavid Howells  */
988607ca46eSDavid Howells struct fw_cdev_start_iso {
989607ca46eSDavid Howells 	__s32 cycle;
990607ca46eSDavid Howells 	__u32 sync;
991607ca46eSDavid Howells 	__u32 tags;
992607ca46eSDavid Howells 	__u32 handle;
993607ca46eSDavid Howells };
994607ca46eSDavid Howells 
995607ca46eSDavid Howells /**
996607ca46eSDavid Howells  * struct fw_cdev_stop_iso - Stop an isochronous transmission or reception
997607ca46eSDavid Howells  * @handle:	Handle of isochronous context to stop
998607ca46eSDavid Howells  */
999607ca46eSDavid Howells struct fw_cdev_stop_iso {
1000607ca46eSDavid Howells 	__u32 handle;
1001607ca46eSDavid Howells };
1002607ca46eSDavid Howells 
1003607ca46eSDavid Howells /**
1004607ca46eSDavid Howells  * struct fw_cdev_flush_iso - flush completed iso packets
1005607ca46eSDavid Howells  * @handle:	handle of isochronous context to flush
1006607ca46eSDavid Howells  *
1007607ca46eSDavid Howells  * For %FW_CDEV_ISO_CONTEXT_TRANSMIT or %FW_CDEV_ISO_CONTEXT_RECEIVE contexts,
1008607ca46eSDavid Howells  * report any completed packets.
1009607ca46eSDavid Howells  *
1010607ca46eSDavid Howells  * For %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL contexts, report the current
1011607ca46eSDavid Howells  * offset in the receive buffer, if it has changed; this is typically in the
1012607ca46eSDavid Howells  * middle of some buffer chunk.
1013607ca46eSDavid Howells  *
1014607ca46eSDavid Howells  * Any %FW_CDEV_EVENT_ISO_INTERRUPT or %FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL
1015607ca46eSDavid Howells  * events generated by this ioctl are sent synchronously, i.e., are available
1016607ca46eSDavid Howells  * for reading from the file descriptor when this ioctl returns.
1017607ca46eSDavid Howells  */
1018607ca46eSDavid Howells struct fw_cdev_flush_iso {
1019607ca46eSDavid Howells 	__u32 handle;
1020607ca46eSDavid Howells };
1021607ca46eSDavid Howells 
1022607ca46eSDavid Howells /**
1023607ca46eSDavid Howells  * struct fw_cdev_get_cycle_timer - read cycle timer register
1024607ca46eSDavid Howells  * @local_time:   system time, in microseconds since the Epoch
1025607ca46eSDavid Howells  * @cycle_timer:  Cycle Time register contents
1026607ca46eSDavid Howells  *
1027607ca46eSDavid Howells  * Same as %FW_CDEV_IOC_GET_CYCLE_TIMER2, but fixed to use %CLOCK_REALTIME
1028607ca46eSDavid Howells  * and only with microseconds resolution.
1029607ca46eSDavid Howells  *
1030607ca46eSDavid Howells  * In version 1 and 2 of the ABI, this ioctl returned unreliable (non-
1031607ca46eSDavid Howells  * monotonic) @cycle_timer values on certain controllers.
1032607ca46eSDavid Howells  */
1033607ca46eSDavid Howells struct fw_cdev_get_cycle_timer {
1034607ca46eSDavid Howells 	__u64 local_time;
1035607ca46eSDavid Howells 	__u32 cycle_timer;
1036607ca46eSDavid Howells };
1037607ca46eSDavid Howells 
1038607ca46eSDavid Howells /**
1039607ca46eSDavid Howells  * struct fw_cdev_get_cycle_timer2 - read cycle timer register
1040607ca46eSDavid Howells  * @tv_sec:       system time, seconds
1041607ca46eSDavid Howells  * @tv_nsec:      system time, sub-seconds part in nanoseconds
1042607ca46eSDavid Howells  * @clk_id:       input parameter, clock from which to get the system time
1043607ca46eSDavid Howells  * @cycle_timer:  Cycle Time register contents
1044607ca46eSDavid Howells  *
1045607ca46eSDavid Howells  * The %FW_CDEV_IOC_GET_CYCLE_TIMER2 ioctl reads the isochronous cycle timer
1046607ca46eSDavid Howells  * and also the system clock.  This allows to correlate reception time of
1047607ca46eSDavid Howells  * isochronous packets with system time.
1048607ca46eSDavid Howells  *
1049607ca46eSDavid Howells  * @clk_id lets you choose a clock like with POSIX' clock_gettime function.
1050607ca46eSDavid Howells  * Supported @clk_id values are POSIX' %CLOCK_REALTIME and %CLOCK_MONOTONIC
1051607ca46eSDavid Howells  * and Linux' %CLOCK_MONOTONIC_RAW.
1052607ca46eSDavid Howells  *
1053607ca46eSDavid Howells  * @cycle_timer consists of 7 bits cycleSeconds, 13 bits cycleCount, and
1054607ca46eSDavid Howells  * 12 bits cycleOffset, in host byte order.  Cf. the Cycle Time register
1055607ca46eSDavid Howells  * per IEEE 1394 or Isochronous Cycle Timer register per OHCI-1394.
1056607ca46eSDavid Howells  */
1057607ca46eSDavid Howells struct fw_cdev_get_cycle_timer2 {
1058607ca46eSDavid Howells 	__s64 tv_sec;
1059607ca46eSDavid Howells 	__s32 tv_nsec;
1060607ca46eSDavid Howells 	__s32 clk_id;
1061607ca46eSDavid Howells 	__u32 cycle_timer;
1062607ca46eSDavid Howells };
1063607ca46eSDavid Howells 
1064607ca46eSDavid Howells /**
1065607ca46eSDavid Howells  * struct fw_cdev_allocate_iso_resource - (De)allocate a channel or bandwidth
1066607ca46eSDavid Howells  * @closure:	Passed back to userspace in corresponding iso resource events
1067607ca46eSDavid Howells  * @channels:	Isochronous channels of which one is to be (de)allocated
1068607ca46eSDavid Howells  * @bandwidth:	Isochronous bandwidth units to be (de)allocated
1069607ca46eSDavid Howells  * @handle:	Handle to the allocation, written by the kernel (only valid in
1070607ca46eSDavid Howells  *		case of %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ioctls)
1071607ca46eSDavid Howells  *
1072607ca46eSDavid Howells  * The %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ioctl initiates allocation of an
1073607ca46eSDavid Howells  * isochronous channel and/or of isochronous bandwidth at the isochronous
1074607ca46eSDavid Howells  * resource manager (IRM).  Only one of the channels specified in @channels is
1075607ca46eSDavid Howells  * allocated.  An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED is sent after
1076607ca46eSDavid Howells  * communication with the IRM, indicating success or failure in the event data.
1077607ca46eSDavid Howells  * The kernel will automatically reallocate the resources after bus resets.
1078607ca46eSDavid Howells  * Should a reallocation fail, an %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event
1079607ca46eSDavid Howells  * will be sent.  The kernel will also automatically deallocate the resources
1080607ca46eSDavid Howells  * when the file descriptor is closed.
1081607ca46eSDavid Howells  *
1082607ca46eSDavid Howells  * The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE ioctl can be used to initiate
1083607ca46eSDavid Howells  * deallocation of resources which were allocated as described above.
1084607ca46eSDavid Howells  * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation.
1085607ca46eSDavid Howells  *
1086607ca46eSDavid Howells  * The %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE ioctl is a variant of allocation
1087607ca46eSDavid Howells  * without automatic re- or deallocation.
1088607ca46eSDavid Howells  * An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event concludes this operation,
1089607ca46eSDavid Howells  * indicating success or failure in its data.
1090607ca46eSDavid Howells  *
1091607ca46eSDavid Howells  * The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE ioctl works like
1092607ca46eSDavid Howells  * %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE except that resources are freed
1093607ca46eSDavid Howells  * instead of allocated.
1094607ca46eSDavid Howells  * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation.
1095607ca46eSDavid Howells  *
1096607ca46eSDavid Howells  * To summarize, %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE allocates iso resources
1097607ca46eSDavid Howells  * for the lifetime of the fd or @handle.
1098607ca46eSDavid Howells  * In contrast, %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE allocates iso resources
1099607ca46eSDavid Howells  * for the duration of a bus generation.
1100607ca46eSDavid Howells  *
1101607ca46eSDavid Howells  * @channels is a host-endian bitfield with the least significant bit
1102607ca46eSDavid Howells  * representing channel 0 and the most significant bit representing channel 63:
1103607ca46eSDavid Howells  * 1ULL << c for each channel c that is a candidate for (de)allocation.
1104607ca46eSDavid Howells  *
1105607ca46eSDavid Howells  * @bandwidth is expressed in bandwidth allocation units, i.e. the time to send
1106607ca46eSDavid Howells  * one quadlet of data (payload or header data) at speed S1600.
1107607ca46eSDavid Howells  */
1108607ca46eSDavid Howells struct fw_cdev_allocate_iso_resource {
1109607ca46eSDavid Howells 	__u64 closure;
1110607ca46eSDavid Howells 	__u64 channels;
1111607ca46eSDavid Howells 	__u32 bandwidth;
1112607ca46eSDavid Howells 	__u32 handle;
1113607ca46eSDavid Howells };
1114607ca46eSDavid Howells 
1115607ca46eSDavid Howells /**
1116607ca46eSDavid Howells  * struct fw_cdev_send_stream_packet - send an asynchronous stream packet
1117607ca46eSDavid Howells  * @length:	Length of outgoing payload, in bytes
1118607ca46eSDavid Howells  * @tag:	Data format tag
1119607ca46eSDavid Howells  * @channel:	Isochronous channel to transmit to
1120607ca46eSDavid Howells  * @sy:		Synchronization code
1121607ca46eSDavid Howells  * @closure:	Passed back to userspace in the response event
1122607ca46eSDavid Howells  * @data:	Userspace pointer to payload
1123607ca46eSDavid Howells  * @generation:	The bus generation where packet is valid
1124607ca46eSDavid Howells  * @speed:	Speed to transmit at
1125607ca46eSDavid Howells  *
1126fc2b52cfSTakashi Sakamoto  * The %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl sends an asynchronous stream packet to every device
1127fc2b52cfSTakashi Sakamoto  * which is listening to the specified channel. The kernel writes either &fw_cdev_event_response
1128fc2b52cfSTakashi Sakamoto  * event or &fw_cdev_event_response2 event which indicates success or failure of the transmission.
1129607ca46eSDavid Howells  */
1130607ca46eSDavid Howells struct fw_cdev_send_stream_packet {
1131607ca46eSDavid Howells 	__u32 length;
1132607ca46eSDavid Howells 	__u32 tag;
1133607ca46eSDavid Howells 	__u32 channel;
1134607ca46eSDavid Howells 	__u32 sy;
1135607ca46eSDavid Howells 	__u64 closure;
1136607ca46eSDavid Howells 	__u64 data;
1137607ca46eSDavid Howells 	__u32 generation;
1138607ca46eSDavid Howells 	__u32 speed;
1139607ca46eSDavid Howells };
1140607ca46eSDavid Howells 
1141607ca46eSDavid Howells /**
1142607ca46eSDavid Howells  * struct fw_cdev_send_phy_packet - send a PHY packet
1143607ca46eSDavid Howells  * @closure:	Passed back to userspace in the PHY-packet-sent event
1144607ca46eSDavid Howells  * @data:	First and second quadlet of the PHY packet
1145607ca46eSDavid Howells  * @generation:	The bus generation where packet is valid
1146607ca46eSDavid Howells  *
1147e27b3939STakashi Sakamoto  * The %FW_CDEV_IOC_SEND_PHY_PACKET ioctl sends a PHY packet to all nodes on the same card as this
1148e27b3939STakashi Sakamoto  * device.  After transmission, either %FW_CDEV_EVENT_PHY_PACKET_SENT event or
1149607ca46eSDavid Howells  * %FW_CDEV_EVENT_PHY_PACKET_SENT event is generated.
1150607ca46eSDavid Howells  *
11519a400682SRandy Dunlap  * The payload @data\[\] shall be specified in host byte order.  Usually,
11529a400682SRandy Dunlap  * @data\[1\] needs to be the bitwise inverse of @data\[0\].  VersaPHY packets
1153607ca46eSDavid Howells  * are an exception to this rule.
1154607ca46eSDavid Howells  *
1155607ca46eSDavid Howells  * The ioctl is only permitted on device files which represent a local node.
1156607ca46eSDavid Howells  */
1157607ca46eSDavid Howells struct fw_cdev_send_phy_packet {
1158607ca46eSDavid Howells 	__u64 closure;
1159607ca46eSDavid Howells 	__u32 data[2];
1160607ca46eSDavid Howells 	__u32 generation;
1161607ca46eSDavid Howells };
1162607ca46eSDavid Howells 
1163607ca46eSDavid Howells /**
1164607ca46eSDavid Howells  * struct fw_cdev_receive_phy_packets - start reception of PHY packets
1165607ca46eSDavid Howells  * @closure: Passed back to userspace in phy packet events
1166607ca46eSDavid Howells  *
1167e27b3939STakashi Sakamoto  * This ioctl activates issuing of either %FW_CDEV_EVENT_PHY_PACKET_RECEIVED or
1168e27b3939STakashi Sakamoto  * %FW_CDEV_EVENT_PHY_PACKET_RECEIVED2 due to incoming PHY packets from any node on the same bus
1169e27b3939STakashi Sakamoto  * as the device.
1170607ca46eSDavid Howells  *
1171607ca46eSDavid Howells  * The ioctl is only permitted on device files which represent a local node.
1172607ca46eSDavid Howells  */
1173607ca46eSDavid Howells struct fw_cdev_receive_phy_packets {
1174607ca46eSDavid Howells 	__u64 closure;
1175607ca46eSDavid Howells };
1176607ca46eSDavid Howells 
1177607ca46eSDavid Howells #define FW_CDEV_VERSION 3 /* Meaningless legacy macro; don't use it. */
1178607ca46eSDavid Howells 
1179607ca46eSDavid Howells #endif /* _LINUX_FIREWIRE_CDEV_H */
1180