1607ca46eSDavid Howells /*
2607ca46eSDavid Howells  * Char device interface.
3607ca46eSDavid Howells  *
4607ca46eSDavid Howells  * Copyright (C) 2005-2007  Kristian Hoegsberg <[email protected]>
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 
49607ca46eSDavid Howells /**
509a400682SRandy Dunlap  * struct fw_cdev_event_common - Common part of all fw_cdev_event_* types
51607ca46eSDavid Howells  * @closure:	For arbitrary use by userspace
529a400682SRandy Dunlap  * @type:	Discriminates the fw_cdev_event_* types
53607ca46eSDavid Howells  *
549a400682SRandy Dunlap  * This struct may be used to access generic members of all fw_cdev_event_*
55607ca46eSDavid Howells  * types regardless of the specific type.
56607ca46eSDavid Howells  *
57607ca46eSDavid Howells  * Data passed in the @closure field for a request will be returned in the
58607ca46eSDavid Howells  * corresponding event.  It is big enough to hold a pointer on all platforms.
59607ca46eSDavid Howells  * The ioctl used to set @closure depends on the @type of event.
60607ca46eSDavid Howells  */
61607ca46eSDavid Howells struct fw_cdev_event_common {
62607ca46eSDavid Howells 	__u64 closure;
63607ca46eSDavid Howells 	__u32 type;
64607ca46eSDavid Howells };
65607ca46eSDavid Howells 
66607ca46eSDavid Howells /**
67607ca46eSDavid Howells  * struct fw_cdev_event_bus_reset - Sent when a bus reset occurred
68607ca46eSDavid Howells  * @closure:	See &fw_cdev_event_common; set by %FW_CDEV_IOC_GET_INFO ioctl
69607ca46eSDavid Howells  * @type:	See &fw_cdev_event_common; always %FW_CDEV_EVENT_BUS_RESET
70607ca46eSDavid Howells  * @node_id:       New node ID of this node
71607ca46eSDavid Howells  * @local_node_id: Node ID of the local node, i.e. of the controller
72607ca46eSDavid Howells  * @bm_node_id:    Node ID of the bus manager
73607ca46eSDavid Howells  * @irm_node_id:   Node ID of the iso resource manager
74607ca46eSDavid Howells  * @root_node_id:  Node ID of the root node
75607ca46eSDavid Howells  * @generation:    New bus generation
76607ca46eSDavid Howells  *
77607ca46eSDavid Howells  * This event is sent when the bus the device belongs to goes through a bus
78607ca46eSDavid Howells  * reset.  It provides information about the new bus configuration, such as
79607ca46eSDavid Howells  * new node ID for this device, new root ID, and others.
80607ca46eSDavid Howells  *
81607ca46eSDavid Howells  * If @bm_node_id is 0xffff right after bus reset it can be reread by an
82607ca46eSDavid Howells  * %FW_CDEV_IOC_GET_INFO ioctl after bus manager selection was finished.
83607ca46eSDavid Howells  * Kernels with ABI version < 4 do not set @bm_node_id.
84607ca46eSDavid Howells  */
85607ca46eSDavid Howells struct fw_cdev_event_bus_reset {
86607ca46eSDavid Howells 	__u64 closure;
87607ca46eSDavid Howells 	__u32 type;
88607ca46eSDavid Howells 	__u32 node_id;
89607ca46eSDavid Howells 	__u32 local_node_id;
90607ca46eSDavid Howells 	__u32 bm_node_id;
91607ca46eSDavid Howells 	__u32 irm_node_id;
92607ca46eSDavid Howells 	__u32 root_node_id;
93607ca46eSDavid Howells 	__u32 generation;
94607ca46eSDavid Howells };
95607ca46eSDavid Howells 
96607ca46eSDavid Howells /**
97607ca46eSDavid Howells  * struct fw_cdev_event_response - Sent when a response packet was received
98607ca46eSDavid Howells  * @closure:	See &fw_cdev_event_common; set by %FW_CDEV_IOC_SEND_REQUEST
99607ca46eSDavid Howells  *		or %FW_CDEV_IOC_SEND_BROADCAST_REQUEST
100607ca46eSDavid Howells  *		or %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl
101607ca46eSDavid Howells  * @type:	See &fw_cdev_event_common; always %FW_CDEV_EVENT_RESPONSE
102607ca46eSDavid Howells  * @rcode:	Response code returned by the remote node
103607ca46eSDavid Howells  * @length:	Data length, i.e. the response's payload size in bytes
104607ca46eSDavid Howells  * @data:	Payload data, if any
105607ca46eSDavid Howells  *
106607ca46eSDavid Howells  * This event is sent when the stack receives a response to an outgoing request
107607ca46eSDavid Howells  * sent by %FW_CDEV_IOC_SEND_REQUEST ioctl.  The payload data for responses
108607ca46eSDavid Howells  * carrying data (read and lock responses) follows immediately and can be
109607ca46eSDavid Howells  * accessed through the @data field.
110607ca46eSDavid Howells  *
111607ca46eSDavid Howells  * The event is also generated after conclusions of transactions that do not
112607ca46eSDavid Howells  * involve response packets.  This includes unified write transactions,
113607ca46eSDavid Howells  * broadcast write transactions, and transmission of asynchronous stream
114607ca46eSDavid Howells  * packets.  @rcode indicates success or failure of such transmissions.
115607ca46eSDavid Howells  */
116607ca46eSDavid Howells struct fw_cdev_event_response {
117607ca46eSDavid Howells 	__u64 closure;
118607ca46eSDavid Howells 	__u32 type;
119607ca46eSDavid Howells 	__u32 rcode;
120607ca46eSDavid Howells 	__u32 length;
121607ca46eSDavid Howells 	__u32 data[0];
122607ca46eSDavid Howells };
123607ca46eSDavid Howells 
124607ca46eSDavid Howells /**
125607ca46eSDavid Howells  * struct fw_cdev_event_request - Old version of &fw_cdev_event_request2
1269a400682SRandy Dunlap  * @closure:	See &fw_cdev_event_common; set by %FW_CDEV_IOC_ALLOCATE ioctl
127607ca46eSDavid Howells  * @type:	See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST
1289a400682SRandy Dunlap  * @tcode:	Transaction code of the incoming request
1299a400682SRandy Dunlap  * @offset:	The offset into the 48-bit per-node address space
1309a400682SRandy Dunlap  * @handle:	Reference to the kernel-side pending request
1319a400682SRandy Dunlap  * @length:	Data length, i.e. the request's payload size in bytes
1329a400682SRandy Dunlap  * @data:	Incoming data, if any
133607ca46eSDavid Howells  *
134607ca46eSDavid Howells  * This event is sent instead of &fw_cdev_event_request2 if the kernel or
135607ca46eSDavid Howells  * the client implements ABI version <= 3.  &fw_cdev_event_request lacks
136607ca46eSDavid Howells  * essential information; use &fw_cdev_event_request2 instead.
137607ca46eSDavid Howells  */
138607ca46eSDavid Howells struct fw_cdev_event_request {
139607ca46eSDavid Howells 	__u64 closure;
140607ca46eSDavid Howells 	__u32 type;
141607ca46eSDavid Howells 	__u32 tcode;
142607ca46eSDavid Howells 	__u64 offset;
143607ca46eSDavid Howells 	__u32 handle;
144607ca46eSDavid Howells 	__u32 length;
145607ca46eSDavid Howells 	__u32 data[0];
146607ca46eSDavid Howells };
147607ca46eSDavid Howells 
148607ca46eSDavid Howells /**
149607ca46eSDavid Howells  * struct fw_cdev_event_request2 - Sent on incoming request to an address region
150607ca46eSDavid Howells  * @closure:	See &fw_cdev_event_common; set by %FW_CDEV_IOC_ALLOCATE ioctl
151607ca46eSDavid Howells  * @type:	See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST2
152607ca46eSDavid Howells  * @tcode:	Transaction code of the incoming request
153607ca46eSDavid Howells  * @offset:	The offset into the 48-bit per-node address space
154607ca46eSDavid Howells  * @source_node_id: Sender node ID
155607ca46eSDavid Howells  * @destination_node_id: Destination node ID
156607ca46eSDavid Howells  * @card:	The index of the card from which the request came
157607ca46eSDavid Howells  * @generation:	Bus generation in which the request is valid
158607ca46eSDavid Howells  * @handle:	Reference to the kernel-side pending request
159607ca46eSDavid Howells  * @length:	Data length, i.e. the request's payload size in bytes
160607ca46eSDavid Howells  * @data:	Incoming data, if any
161607ca46eSDavid Howells  *
162607ca46eSDavid Howells  * This event is sent when the stack receives an incoming request to an address
163607ca46eSDavid Howells  * region registered using the %FW_CDEV_IOC_ALLOCATE ioctl.  The request is
164607ca46eSDavid Howells  * guaranteed to be completely contained in the specified region.  Userspace is
165607ca46eSDavid Howells  * responsible for sending the response by %FW_CDEV_IOC_SEND_RESPONSE ioctl,
166607ca46eSDavid Howells  * using the same @handle.
167607ca46eSDavid Howells  *
168607ca46eSDavid Howells  * The payload data for requests carrying data (write and lock requests)
169607ca46eSDavid Howells  * follows immediately and can be accessed through the @data field.
170607ca46eSDavid Howells  *
171607ca46eSDavid Howells  * Unlike &fw_cdev_event_request, @tcode of lock requests is one of the
172607ca46eSDavid Howells  * firewire-core specific %TCODE_LOCK_MASK_SWAP...%TCODE_LOCK_VENDOR_DEPENDENT,
173607ca46eSDavid Howells  * i.e. encodes the extended transaction code.
174607ca46eSDavid Howells  *
175607ca46eSDavid Howells  * @card may differ from &fw_cdev_get_info.card because requests are received
176607ca46eSDavid Howells  * from all cards of the Linux host.  @source_node_id, @destination_node_id, and
177607ca46eSDavid Howells  * @generation pertain to that card.  Destination node ID and bus generation may
178607ca46eSDavid Howells  * therefore differ from the corresponding fields of the last
179607ca46eSDavid Howells  * &fw_cdev_event_bus_reset.
180607ca46eSDavid Howells  *
181607ca46eSDavid Howells  * @destination_node_id may also differ from the current node ID because of a
182607ca46eSDavid Howells  * non-local bus ID part or in case of a broadcast write request.  Note, a
183607ca46eSDavid Howells  * client must call an %FW_CDEV_IOC_SEND_RESPONSE ioctl even in case of a
184607ca46eSDavid Howells  * broadcast write request; the kernel will then release the kernel-side pending
185607ca46eSDavid Howells  * request but will not actually send a response packet.
186607ca46eSDavid Howells  *
187607ca46eSDavid Howells  * In case of a write request to FCP_REQUEST or FCP_RESPONSE, the kernel already
188607ca46eSDavid Howells  * sent a write response immediately after the request was received; in this
189607ca46eSDavid Howells  * case the client must still call an %FW_CDEV_IOC_SEND_RESPONSE ioctl to
190607ca46eSDavid Howells  * release the kernel-side pending request, though another response won't be
191607ca46eSDavid Howells  * sent.
192607ca46eSDavid Howells  *
193607ca46eSDavid Howells  * If the client subsequently needs to initiate requests to the sender node of
194607ca46eSDavid Howells  * an &fw_cdev_event_request2, it needs to use a device file with matching
195607ca46eSDavid Howells  * card index, node ID, and generation for outbound requests.
196607ca46eSDavid Howells  */
197607ca46eSDavid Howells struct fw_cdev_event_request2 {
198607ca46eSDavid Howells 	__u64 closure;
199607ca46eSDavid Howells 	__u32 type;
200607ca46eSDavid Howells 	__u32 tcode;
201607ca46eSDavid Howells 	__u64 offset;
202607ca46eSDavid Howells 	__u32 source_node_id;
203607ca46eSDavid Howells 	__u32 destination_node_id;
204607ca46eSDavid Howells 	__u32 card;
205607ca46eSDavid Howells 	__u32 generation;
206607ca46eSDavid Howells 	__u32 handle;
207607ca46eSDavid Howells 	__u32 length;
208607ca46eSDavid Howells 	__u32 data[0];
209607ca46eSDavid Howells };
210607ca46eSDavid Howells 
211607ca46eSDavid Howells /**
212607ca46eSDavid Howells  * struct fw_cdev_event_iso_interrupt - Sent when an iso packet was completed
213607ca46eSDavid Howells  * @closure:	See &fw_cdev_event_common;
214607ca46eSDavid Howells  *		set by %FW_CDEV_CREATE_ISO_CONTEXT ioctl
215607ca46eSDavid Howells  * @type:	See &fw_cdev_event_common; always %FW_CDEV_EVENT_ISO_INTERRUPT
216607ca46eSDavid Howells  * @cycle:	Cycle counter of the last completed packet
217607ca46eSDavid Howells  * @header_length: Total length of following headers, in bytes
218607ca46eSDavid Howells  * @header:	Stripped headers, if any
219607ca46eSDavid Howells  *
220607ca46eSDavid Howells  * This event is sent when the controller has completed an &fw_cdev_iso_packet
221607ca46eSDavid Howells  * with the %FW_CDEV_ISO_INTERRUPT bit set, when explicitly requested with
222607ca46eSDavid Howells  * %FW_CDEV_IOC_FLUSH_ISO, or when there have been so many completed packets
223607ca46eSDavid Howells  * without the interrupt bit set that the kernel's internal buffer for @header
2240699a73aSClemens Ladisch  * is about to overflow.  (In the last case, ABI versions < 5 drop header data
2250699a73aSClemens Ladisch  * up to the next interrupt packet.)
226607ca46eSDavid Howells  *
227607ca46eSDavid Howells  * Isochronous transmit events (context type %FW_CDEV_ISO_CONTEXT_TRANSMIT):
228607ca46eSDavid Howells  *
229607ca46eSDavid Howells  * In version 3 and some implementations of version 2 of the ABI, &header_length
230607ca46eSDavid Howells  * is a multiple of 4 and &header contains timestamps of all packets up until
231607ca46eSDavid Howells  * the interrupt packet.  The format of the timestamps is as described below for
232607ca46eSDavid Howells  * isochronous reception.  In version 1 of the ABI, &header_length was 0.
233607ca46eSDavid Howells  *
234607ca46eSDavid Howells  * Isochronous receive events (context type %FW_CDEV_ISO_CONTEXT_RECEIVE):
235607ca46eSDavid Howells  *
236607ca46eSDavid Howells  * The headers stripped of all packets up until and including the interrupt
237607ca46eSDavid Howells  * packet are returned in the @header field.  The amount of header data per
238607ca46eSDavid Howells  * packet is as specified at iso context creation by
239607ca46eSDavid Howells  * &fw_cdev_create_iso_context.header_size.
240607ca46eSDavid Howells  *
241607ca46eSDavid Howells  * Hence, _interrupt.header_length / _context.header_size is the number of
242607ca46eSDavid Howells  * packets received in this interrupt event.  The client can now iterate
243607ca46eSDavid Howells  * through the mmap()'ed DMA buffer according to this number of packets and
244607ca46eSDavid Howells  * to the buffer sizes as the client specified in &fw_cdev_queue_iso.
245607ca46eSDavid Howells  *
246607ca46eSDavid Howells  * Since version 2 of this ABI, the portion for each packet in _interrupt.header
247607ca46eSDavid Howells  * consists of the 1394 isochronous packet header, followed by a timestamp
248607ca46eSDavid Howells  * quadlet if &fw_cdev_create_iso_context.header_size > 4, followed by quadlets
249607ca46eSDavid Howells  * from the packet payload if &fw_cdev_create_iso_context.header_size > 8.
250607ca46eSDavid Howells  *
251607ca46eSDavid Howells  * Format of 1394 iso packet header:  16 bits data_length, 2 bits tag, 6 bits
252607ca46eSDavid Howells  * channel, 4 bits tcode, 4 bits sy, in big endian byte order.
253607ca46eSDavid Howells  * data_length is the actual received size of the packet without the four
254607ca46eSDavid Howells  * 1394 iso packet header bytes.
255607ca46eSDavid Howells  *
256607ca46eSDavid Howells  * Format of timestamp:  16 bits invalid, 3 bits cycleSeconds, 13 bits
257607ca46eSDavid Howells  * cycleCount, in big endian byte order.
258607ca46eSDavid Howells  *
259607ca46eSDavid Howells  * In version 1 of the ABI, no timestamp quadlet was inserted; instead, payload
260607ca46eSDavid Howells  * data followed directly after the 1394 is header if header_size > 4.
261607ca46eSDavid Howells  * Behaviour of ver. 1 of this ABI is no longer available since ABI ver. 2.
262607ca46eSDavid Howells  */
263607ca46eSDavid Howells struct fw_cdev_event_iso_interrupt {
264607ca46eSDavid Howells 	__u64 closure;
265607ca46eSDavid Howells 	__u32 type;
266607ca46eSDavid Howells 	__u32 cycle;
267607ca46eSDavid Howells 	__u32 header_length;
268607ca46eSDavid Howells 	__u32 header[0];
269607ca46eSDavid Howells };
270607ca46eSDavid Howells 
271607ca46eSDavid Howells /**
272607ca46eSDavid Howells  * struct fw_cdev_event_iso_interrupt_mc - An iso buffer chunk was completed
273607ca46eSDavid Howells  * @closure:	See &fw_cdev_event_common;
274607ca46eSDavid Howells  *		set by %FW_CDEV_CREATE_ISO_CONTEXT ioctl
275607ca46eSDavid Howells  * @type:	%FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL
276607ca46eSDavid Howells  * @completed:	Offset into the receive buffer; data before this offset is valid
277607ca46eSDavid Howells  *
278607ca46eSDavid Howells  * This event is sent in multichannel contexts (context type
279607ca46eSDavid Howells  * %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL) for &fw_cdev_iso_packet buffer
280607ca46eSDavid Howells  * chunks that have been completely filled and that have the
281607ca46eSDavid Howells  * %FW_CDEV_ISO_INTERRUPT bit set, or when explicitly requested with
282607ca46eSDavid Howells  * %FW_CDEV_IOC_FLUSH_ISO.
283607ca46eSDavid Howells  *
284607ca46eSDavid Howells  * The buffer is continuously filled with the following data, per packet:
285607ca46eSDavid Howells  *  - the 1394 iso packet header as described at &fw_cdev_event_iso_interrupt,
286607ca46eSDavid Howells  *    but in little endian byte order,
287607ca46eSDavid Howells  *  - packet payload (as many bytes as specified in the data_length field of
288607ca46eSDavid Howells  *    the 1394 iso packet header) in big endian byte order,
289607ca46eSDavid Howells  *  - 0...3 padding bytes as needed to align the following trailer quadlet,
290607ca46eSDavid Howells  *  - trailer quadlet, containing the reception timestamp as described at
291607ca46eSDavid Howells  *    &fw_cdev_event_iso_interrupt, but in little endian byte order.
292607ca46eSDavid Howells  *
293607ca46eSDavid Howells  * Hence the per-packet size is data_length (rounded up to a multiple of 4) + 8.
294607ca46eSDavid Howells  * When processing the data, stop before a packet that would cross the
295607ca46eSDavid Howells  * @completed offset.
296607ca46eSDavid Howells  *
297607ca46eSDavid Howells  * A packet near the end of a buffer chunk will typically spill over into the
298607ca46eSDavid Howells  * next queued buffer chunk.  It is the responsibility of the client to check
299607ca46eSDavid Howells  * for this condition, assemble a broken-up packet from its parts, and not to
300607ca46eSDavid Howells  * re-queue any buffer chunks in which as yet unread packet parts reside.
301607ca46eSDavid Howells  */
302607ca46eSDavid Howells struct fw_cdev_event_iso_interrupt_mc {
303607ca46eSDavid Howells 	__u64 closure;
304607ca46eSDavid Howells 	__u32 type;
305607ca46eSDavid Howells 	__u32 completed;
306607ca46eSDavid Howells };
307607ca46eSDavid Howells 
308607ca46eSDavid Howells /**
309607ca46eSDavid Howells  * struct fw_cdev_event_iso_resource - Iso resources were allocated or freed
310607ca46eSDavid Howells  * @closure:	See &fw_cdev_event_common;
311*af690f45SMauro Carvalho Chehab  *		set by``FW_CDEV_IOC_(DE)ALLOCATE_ISO_RESOURCE(_ONCE)`` ioctl
312607ca46eSDavid Howells  * @type:	%FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or
313607ca46eSDavid Howells  *		%FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED
314607ca46eSDavid Howells  * @handle:	Reference by which an allocated resource can be deallocated
315607ca46eSDavid Howells  * @channel:	Isochronous channel which was (de)allocated, if any
316607ca46eSDavid Howells  * @bandwidth:	Bandwidth allocation units which were (de)allocated, if any
317607ca46eSDavid Howells  *
318607ca46eSDavid Howells  * An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event is sent after an isochronous
319607ca46eSDavid Howells  * resource was allocated at the IRM.  The client has to check @channel and
320607ca46eSDavid Howells  * @bandwidth for whether the allocation actually succeeded.
321607ca46eSDavid Howells  *
322607ca46eSDavid Howells  * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event is sent after an isochronous
323607ca46eSDavid Howells  * resource was deallocated at the IRM.  It is also sent when automatic
324607ca46eSDavid Howells  * reallocation after a bus reset failed.
325607ca46eSDavid Howells  *
326607ca46eSDavid Howells  * @channel is <0 if no channel was (de)allocated or if reallocation failed.
327607ca46eSDavid Howells  * @bandwidth is 0 if no bandwidth was (de)allocated or if reallocation failed.
328607ca46eSDavid Howells  */
329607ca46eSDavid Howells struct fw_cdev_event_iso_resource {
330607ca46eSDavid Howells 	__u64 closure;
331607ca46eSDavid Howells 	__u32 type;
332607ca46eSDavid Howells 	__u32 handle;
333607ca46eSDavid Howells 	__s32 channel;
334607ca46eSDavid Howells 	__s32 bandwidth;
335607ca46eSDavid Howells };
336607ca46eSDavid Howells 
337607ca46eSDavid Howells /**
338607ca46eSDavid Howells  * struct fw_cdev_event_phy_packet - A PHY packet was transmitted or received
339607ca46eSDavid Howells  * @closure:	See &fw_cdev_event_common; set by %FW_CDEV_IOC_SEND_PHY_PACKET
340607ca46eSDavid Howells  *		or %FW_CDEV_IOC_RECEIVE_PHY_PACKETS ioctl
341607ca46eSDavid Howells  * @type:	%FW_CDEV_EVENT_PHY_PACKET_SENT or %..._RECEIVED
342607ca46eSDavid Howells  * @rcode:	%RCODE_..., indicates success or failure of transmission
343607ca46eSDavid Howells  * @length:	Data length in bytes
344607ca46eSDavid Howells  * @data:	Incoming data
345607ca46eSDavid Howells  *
346607ca46eSDavid Howells  * If @type is %FW_CDEV_EVENT_PHY_PACKET_SENT, @length is 0 and @data empty,
347607ca46eSDavid Howells  * except in case of a ping packet:  Then, @length is 4, and @data[0] is the
348607ca46eSDavid Howells  * ping time in 49.152MHz clocks if @rcode is %RCODE_COMPLETE.
349607ca46eSDavid Howells  *
350607ca46eSDavid Howells  * If @type is %FW_CDEV_EVENT_PHY_PACKET_RECEIVED, @length is 8 and @data
351607ca46eSDavid Howells  * consists of the two PHY packet quadlets, in host byte order.
352607ca46eSDavid Howells  */
353607ca46eSDavid Howells struct fw_cdev_event_phy_packet {
354607ca46eSDavid Howells 	__u64 closure;
355607ca46eSDavid Howells 	__u32 type;
356607ca46eSDavid Howells 	__u32 rcode;
357607ca46eSDavid Howells 	__u32 length;
358607ca46eSDavid Howells 	__u32 data[0];
359607ca46eSDavid Howells };
360607ca46eSDavid Howells 
361607ca46eSDavid Howells /**
3629a400682SRandy Dunlap  * union fw_cdev_event - Convenience union of fw_cdev_event_* types
363607ca46eSDavid Howells  * @common:		Valid for all types
364607ca46eSDavid Howells  * @bus_reset:		Valid if @common.type == %FW_CDEV_EVENT_BUS_RESET
365607ca46eSDavid Howells  * @response:		Valid if @common.type == %FW_CDEV_EVENT_RESPONSE
366607ca46eSDavid Howells  * @request:		Valid if @common.type == %FW_CDEV_EVENT_REQUEST
367607ca46eSDavid Howells  * @request2:		Valid if @common.type == %FW_CDEV_EVENT_REQUEST2
368607ca46eSDavid Howells  * @iso_interrupt:	Valid if @common.type == %FW_CDEV_EVENT_ISO_INTERRUPT
369607ca46eSDavid Howells  * @iso_interrupt_mc:	Valid if @common.type ==
370607ca46eSDavid Howells  *				%FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL
371607ca46eSDavid Howells  * @iso_resource:	Valid if @common.type ==
372607ca46eSDavid Howells  *				%FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or
373607ca46eSDavid Howells  *				%FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED
374607ca46eSDavid Howells  * @phy_packet:		Valid if @common.type ==
375607ca46eSDavid Howells  *				%FW_CDEV_EVENT_PHY_PACKET_SENT or
376607ca46eSDavid Howells  *				%FW_CDEV_EVENT_PHY_PACKET_RECEIVED
377607ca46eSDavid Howells  *
378607ca46eSDavid Howells  * Convenience union for userspace use.  Events could be read(2) into an
379607ca46eSDavid Howells  * appropriately aligned char buffer and then cast to this union for further
380607ca46eSDavid Howells  * processing.  Note that for a request, response or iso_interrupt event,
381607ca46eSDavid Howells  * the data[] or header[] may make the size of the full event larger than
382607ca46eSDavid Howells  * sizeof(union fw_cdev_event).  Also note that if you attempt to read(2)
383607ca46eSDavid Howells  * an event into a buffer that is not large enough for it, the data that does
384607ca46eSDavid Howells  * not fit will be discarded so that the next read(2) will return a new event.
385607ca46eSDavid Howells  */
386607ca46eSDavid Howells union fw_cdev_event {
387607ca46eSDavid Howells 	struct fw_cdev_event_common		common;
388607ca46eSDavid Howells 	struct fw_cdev_event_bus_reset		bus_reset;
389607ca46eSDavid Howells 	struct fw_cdev_event_response		response;
390607ca46eSDavid Howells 	struct fw_cdev_event_request		request;
391607ca46eSDavid Howells 	struct fw_cdev_event_request2		request2;		/* added in 2.6.36 */
392607ca46eSDavid Howells 	struct fw_cdev_event_iso_interrupt	iso_interrupt;
393607ca46eSDavid Howells 	struct fw_cdev_event_iso_interrupt_mc	iso_interrupt_mc;	/* added in 2.6.36 */
394607ca46eSDavid Howells 	struct fw_cdev_event_iso_resource	iso_resource;		/* added in 2.6.30 */
395607ca46eSDavid Howells 	struct fw_cdev_event_phy_packet		phy_packet;		/* added in 2.6.36 */
396607ca46eSDavid Howells };
397607ca46eSDavid Howells 
398607ca46eSDavid Howells /* available since kernel version 2.6.22 */
399607ca46eSDavid Howells #define FW_CDEV_IOC_GET_INFO           _IOWR('#', 0x00, struct fw_cdev_get_info)
400607ca46eSDavid Howells #define FW_CDEV_IOC_SEND_REQUEST        _IOW('#', 0x01, struct fw_cdev_send_request)
401607ca46eSDavid Howells #define FW_CDEV_IOC_ALLOCATE           _IOWR('#', 0x02, struct fw_cdev_allocate)
402607ca46eSDavid Howells #define FW_CDEV_IOC_DEALLOCATE          _IOW('#', 0x03, struct fw_cdev_deallocate)
403607ca46eSDavid Howells #define FW_CDEV_IOC_SEND_RESPONSE       _IOW('#', 0x04, struct fw_cdev_send_response)
404607ca46eSDavid Howells #define FW_CDEV_IOC_INITIATE_BUS_RESET  _IOW('#', 0x05, struct fw_cdev_initiate_bus_reset)
405607ca46eSDavid Howells #define FW_CDEV_IOC_ADD_DESCRIPTOR     _IOWR('#', 0x06, struct fw_cdev_add_descriptor)
406607ca46eSDavid Howells #define FW_CDEV_IOC_REMOVE_DESCRIPTOR   _IOW('#', 0x07, struct fw_cdev_remove_descriptor)
407607ca46eSDavid Howells #define FW_CDEV_IOC_CREATE_ISO_CONTEXT _IOWR('#', 0x08, struct fw_cdev_create_iso_context)
408607ca46eSDavid Howells #define FW_CDEV_IOC_QUEUE_ISO          _IOWR('#', 0x09, struct fw_cdev_queue_iso)
409607ca46eSDavid Howells #define FW_CDEV_IOC_START_ISO           _IOW('#', 0x0a, struct fw_cdev_start_iso)
410607ca46eSDavid Howells #define FW_CDEV_IOC_STOP_ISO            _IOW('#', 0x0b, struct fw_cdev_stop_iso)
411607ca46eSDavid Howells 
412607ca46eSDavid Howells /* available since kernel version 2.6.24 */
413607ca46eSDavid Howells #define FW_CDEV_IOC_GET_CYCLE_TIMER     _IOR('#', 0x0c, struct fw_cdev_get_cycle_timer)
414607ca46eSDavid Howells 
415607ca46eSDavid Howells /* available since kernel version 2.6.30 */
416607ca46eSDavid Howells #define FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE       _IOWR('#', 0x0d, struct fw_cdev_allocate_iso_resource)
417607ca46eSDavid Howells #define FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE      _IOW('#', 0x0e, struct fw_cdev_deallocate)
418607ca46eSDavid Howells #define FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE   _IOW('#', 0x0f, struct fw_cdev_allocate_iso_resource)
419607ca46eSDavid Howells #define FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE _IOW('#', 0x10, struct fw_cdev_allocate_iso_resource)
420607ca46eSDavid Howells #define FW_CDEV_IOC_GET_SPEED                     _IO('#', 0x11) /* returns speed code */
421607ca46eSDavid Howells #define FW_CDEV_IOC_SEND_BROADCAST_REQUEST       _IOW('#', 0x12, struct fw_cdev_send_request)
422607ca46eSDavid Howells #define FW_CDEV_IOC_SEND_STREAM_PACKET           _IOW('#', 0x13, struct fw_cdev_send_stream_packet)
423607ca46eSDavid Howells 
424607ca46eSDavid Howells /* available since kernel version 2.6.34 */
425607ca46eSDavid Howells #define FW_CDEV_IOC_GET_CYCLE_TIMER2   _IOWR('#', 0x14, struct fw_cdev_get_cycle_timer2)
426607ca46eSDavid Howells 
427607ca46eSDavid Howells /* available since kernel version 2.6.36 */
428607ca46eSDavid Howells #define FW_CDEV_IOC_SEND_PHY_PACKET    _IOWR('#', 0x15, struct fw_cdev_send_phy_packet)
429607ca46eSDavid Howells #define FW_CDEV_IOC_RECEIVE_PHY_PACKETS _IOW('#', 0x16, struct fw_cdev_receive_phy_packets)
430607ca46eSDavid Howells #define FW_CDEV_IOC_SET_ISO_CHANNELS    _IOW('#', 0x17, struct fw_cdev_set_iso_channels)
431607ca46eSDavid Howells 
432607ca46eSDavid Howells /* available since kernel version 3.4 */
433607ca46eSDavid Howells #define FW_CDEV_IOC_FLUSH_ISO           _IOW('#', 0x18, struct fw_cdev_flush_iso)
434607ca46eSDavid Howells 
435607ca46eSDavid Howells /*
436607ca46eSDavid Howells  * ABI version history
437607ca46eSDavid Howells  *  1  (2.6.22)  - initial version
438607ca46eSDavid Howells  *     (2.6.24)  - added %FW_CDEV_IOC_GET_CYCLE_TIMER
439607ca46eSDavid Howells  *  2  (2.6.30)  - changed &fw_cdev_event_iso_interrupt.header if
440607ca46eSDavid Howells  *                 &fw_cdev_create_iso_context.header_size is 8 or more
441607ca46eSDavid Howells  *               - added %FW_CDEV_IOC_*_ISO_RESOURCE*,
442607ca46eSDavid Howells  *                 %FW_CDEV_IOC_GET_SPEED, %FW_CDEV_IOC_SEND_BROADCAST_REQUEST,
443607ca46eSDavid Howells  *                 %FW_CDEV_IOC_SEND_STREAM_PACKET
444607ca46eSDavid Howells  *     (2.6.32)  - added time stamp to xmit &fw_cdev_event_iso_interrupt
445607ca46eSDavid Howells  *     (2.6.33)  - IR has always packet-per-buffer semantics now, not one of
446607ca46eSDavid Howells  *                 dual-buffer or packet-per-buffer depending on hardware
447607ca46eSDavid Howells  *               - shared use and auto-response for FCP registers
448607ca46eSDavid Howells  *  3  (2.6.34)  - made &fw_cdev_get_cycle_timer reliable
449607ca46eSDavid Howells  *               - added %FW_CDEV_IOC_GET_CYCLE_TIMER2
450607ca46eSDavid Howells  *  4  (2.6.36)  - added %FW_CDEV_EVENT_REQUEST2, %FW_CDEV_EVENT_PHY_PACKET_*,
451607ca46eSDavid Howells  *                 and &fw_cdev_allocate.region_end
452607ca46eSDavid Howells  *               - implemented &fw_cdev_event_bus_reset.bm_node_id
453607ca46eSDavid Howells  *               - added %FW_CDEV_IOC_SEND_PHY_PACKET, _RECEIVE_PHY_PACKETS
454607ca46eSDavid Howells  *               - added %FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL,
455607ca46eSDavid Howells  *                 %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL, and
456607ca46eSDavid Howells  *                 %FW_CDEV_IOC_SET_ISO_CHANNELS
457607ca46eSDavid Howells  *  5  (3.4)     - send %FW_CDEV_EVENT_ISO_INTERRUPT events when needed to
458607ca46eSDavid Howells  *                 avoid dropping data
459607ca46eSDavid Howells  *               - added %FW_CDEV_IOC_FLUSH_ISO
460607ca46eSDavid Howells  */
461607ca46eSDavid Howells 
462607ca46eSDavid Howells /**
463607ca46eSDavid Howells  * struct fw_cdev_get_info - General purpose information ioctl
464607ca46eSDavid Howells  * @version:	The version field is just a running serial number.  Both an
465607ca46eSDavid Howells  *		input parameter (ABI version implemented by the client) and
466607ca46eSDavid Howells  *		output parameter (ABI version implemented by the kernel).
467607ca46eSDavid Howells  *		A client shall fill in the ABI @version for which the client
468607ca46eSDavid Howells  *		was implemented.  This is necessary for forward compatibility.
469607ca46eSDavid Howells  * @rom_length:	If @rom is non-zero, up to @rom_length bytes of Configuration
470607ca46eSDavid Howells  *		ROM will be copied into that user space address.  In either
471607ca46eSDavid Howells  *		case, @rom_length is updated with the actual length of the
472607ca46eSDavid Howells  *		Configuration ROM.
473607ca46eSDavid Howells  * @rom:	If non-zero, address of a buffer to be filled by a copy of the
474607ca46eSDavid Howells  *		device's Configuration ROM
475607ca46eSDavid Howells  * @bus_reset:	If non-zero, address of a buffer to be filled by a
476607ca46eSDavid Howells  *		&struct fw_cdev_event_bus_reset with the current state
477607ca46eSDavid Howells  *		of the bus.  This does not cause a bus reset to happen.
478607ca46eSDavid Howells  * @bus_reset_closure: Value of &closure in this and subsequent bus reset events
479607ca46eSDavid Howells  * @card:	The index of the card this device belongs to
480607ca46eSDavid Howells  *
481607ca46eSDavid Howells  * The %FW_CDEV_IOC_GET_INFO ioctl is usually the very first one which a client
482607ca46eSDavid Howells  * performs right after it opened a /dev/fw* file.
483607ca46eSDavid Howells  *
484607ca46eSDavid Howells  * As a side effect, reception of %FW_CDEV_EVENT_BUS_RESET events to be read(2)
485607ca46eSDavid Howells  * is started by this ioctl.
486607ca46eSDavid Howells  */
487607ca46eSDavid Howells struct fw_cdev_get_info {
488607ca46eSDavid Howells 	__u32 version;
489607ca46eSDavid Howells 	__u32 rom_length;
490607ca46eSDavid Howells 	__u64 rom;
491607ca46eSDavid Howells 	__u64 bus_reset;
492607ca46eSDavid Howells 	__u64 bus_reset_closure;
493607ca46eSDavid Howells 	__u32 card;
494607ca46eSDavid Howells };
495607ca46eSDavid Howells 
496607ca46eSDavid Howells /**
497607ca46eSDavid Howells  * struct fw_cdev_send_request - Send an asynchronous request packet
498607ca46eSDavid Howells  * @tcode:	Transaction code of the request
499607ca46eSDavid Howells  * @length:	Length of outgoing payload, in bytes
500607ca46eSDavid Howells  * @offset:	48-bit offset at destination node
501607ca46eSDavid Howells  * @closure:	Passed back to userspace in the response event
502607ca46eSDavid Howells  * @data:	Userspace pointer to payload
503607ca46eSDavid Howells  * @generation:	The bus generation where packet is valid
504607ca46eSDavid Howells  *
505607ca46eSDavid Howells  * Send a request to the device.  This ioctl implements all outgoing requests.
506607ca46eSDavid Howells  * Both quadlet and block request specify the payload as a pointer to the data
507607ca46eSDavid Howells  * in the @data field.  Once the transaction completes, the kernel writes an
508607ca46eSDavid Howells  * &fw_cdev_event_response event back.  The @closure field is passed back to
509607ca46eSDavid Howells  * user space in the response event.
510607ca46eSDavid Howells  */
511607ca46eSDavid Howells struct fw_cdev_send_request {
512607ca46eSDavid Howells 	__u32 tcode;
513607ca46eSDavid Howells 	__u32 length;
514607ca46eSDavid Howells 	__u64 offset;
515607ca46eSDavid Howells 	__u64 closure;
516607ca46eSDavid Howells 	__u64 data;
517607ca46eSDavid Howells 	__u32 generation;
518607ca46eSDavid Howells };
519607ca46eSDavid Howells 
520607ca46eSDavid Howells /**
521607ca46eSDavid Howells  * struct fw_cdev_send_response - Send an asynchronous response packet
522607ca46eSDavid Howells  * @rcode:	Response code as determined by the userspace handler
523607ca46eSDavid Howells  * @length:	Length of outgoing payload, in bytes
524607ca46eSDavid Howells  * @data:	Userspace pointer to payload
525607ca46eSDavid Howells  * @handle:	The handle from the &fw_cdev_event_request
526607ca46eSDavid Howells  *
527607ca46eSDavid Howells  * Send a response to an incoming request.  By setting up an address range using
528607ca46eSDavid Howells  * the %FW_CDEV_IOC_ALLOCATE ioctl, userspace can listen for incoming requests.  An
529607ca46eSDavid Howells  * incoming request will generate an %FW_CDEV_EVENT_REQUEST, and userspace must
530607ca46eSDavid Howells  * send a reply using this ioctl.  The event has a handle to the kernel-side
531607ca46eSDavid Howells  * pending transaction, which should be used with this ioctl.
532607ca46eSDavid Howells  */
533607ca46eSDavid Howells struct fw_cdev_send_response {
534607ca46eSDavid Howells 	__u32 rcode;
535607ca46eSDavid Howells 	__u32 length;
536607ca46eSDavid Howells 	__u64 data;
537607ca46eSDavid Howells 	__u32 handle;
538607ca46eSDavid Howells };
539607ca46eSDavid Howells 
540607ca46eSDavid Howells /**
541607ca46eSDavid Howells  * struct fw_cdev_allocate - Allocate a CSR in an address range
542607ca46eSDavid Howells  * @offset:	Start offset of the address range
543607ca46eSDavid Howells  * @closure:	To be passed back to userspace in request events
544607ca46eSDavid Howells  * @length:	Length of the CSR, in bytes
545607ca46eSDavid Howells  * @handle:	Handle to the allocation, written by the kernel
546607ca46eSDavid Howells  * @region_end:	First address above the address range (added in ABI v4, 2.6.36)
547607ca46eSDavid Howells  *
548607ca46eSDavid Howells  * Allocate an address range in the 48-bit address space on the local node
549607ca46eSDavid Howells  * (the controller).  This allows userspace to listen for requests with an
550607ca46eSDavid Howells  * offset within that address range.  Every time when the kernel receives a
551607ca46eSDavid Howells  * request within the range, an &fw_cdev_event_request2 event will be emitted.
552607ca46eSDavid Howells  * (If the kernel or the client implements ABI version <= 3, an
553607ca46eSDavid Howells  * &fw_cdev_event_request will be generated instead.)
554607ca46eSDavid Howells  *
555607ca46eSDavid Howells  * The @closure field is passed back to userspace in these request events.
556607ca46eSDavid Howells  * The @handle field is an out parameter, returning a handle to the allocated
557607ca46eSDavid Howells  * range to be used for later deallocation of the range.
558607ca46eSDavid Howells  *
559607ca46eSDavid Howells  * The address range is allocated on all local nodes.  The address allocation
560607ca46eSDavid Howells  * is exclusive except for the FCP command and response registers.  If an
561607ca46eSDavid Howells  * exclusive address region is already in use, the ioctl fails with errno set
562607ca46eSDavid Howells  * to %EBUSY.
563607ca46eSDavid Howells  *
564607ca46eSDavid Howells  * If kernel and client implement ABI version >= 4, the kernel looks up a free
565607ca46eSDavid Howells  * spot of size @length inside [@offset..@region_end) and, if found, writes
566607ca46eSDavid Howells  * the start address of the new CSR back in @offset.  I.e. @offset is an
567607ca46eSDavid Howells  * in and out parameter.  If this automatic placement of a CSR in a bigger
568607ca46eSDavid Howells  * address range is not desired, the client simply needs to set @region_end
569607ca46eSDavid Howells  * = @offset + @length.
570607ca46eSDavid Howells  *
571607ca46eSDavid Howells  * If the kernel or the client implements ABI version <= 3, @region_end is
572607ca46eSDavid Howells  * ignored and effectively assumed to be @offset + @length.
573607ca46eSDavid Howells  *
574607ca46eSDavid Howells  * @region_end is only present in a kernel header >= 2.6.36.  If necessary,
575607ca46eSDavid Howells  * this can for example be tested by #ifdef FW_CDEV_EVENT_REQUEST2.
576607ca46eSDavid Howells  */
577607ca46eSDavid Howells struct fw_cdev_allocate {
578607ca46eSDavid Howells 	__u64 offset;
579607ca46eSDavid Howells 	__u64 closure;
580607ca46eSDavid Howells 	__u32 length;
581607ca46eSDavid Howells 	__u32 handle;
582607ca46eSDavid Howells 	__u64 region_end;	/* available since kernel version 2.6.36 */
583607ca46eSDavid Howells };
584607ca46eSDavid Howells 
585607ca46eSDavid Howells /**
586607ca46eSDavid Howells  * struct fw_cdev_deallocate - Free a CSR address range or isochronous resource
587607ca46eSDavid Howells  * @handle:	Handle to the address range or iso resource, as returned by the
588607ca46eSDavid Howells  *		kernel when the range or resource was allocated
589607ca46eSDavid Howells  */
590607ca46eSDavid Howells struct fw_cdev_deallocate {
591607ca46eSDavid Howells 	__u32 handle;
592607ca46eSDavid Howells };
593607ca46eSDavid Howells 
594607ca46eSDavid Howells #define FW_CDEV_LONG_RESET	0
595607ca46eSDavid Howells #define FW_CDEV_SHORT_RESET	1
596607ca46eSDavid Howells 
597607ca46eSDavid Howells /**
598607ca46eSDavid Howells  * struct fw_cdev_initiate_bus_reset - Initiate a bus reset
599607ca46eSDavid Howells  * @type:	%FW_CDEV_SHORT_RESET or %FW_CDEV_LONG_RESET
600607ca46eSDavid Howells  *
601607ca46eSDavid Howells  * Initiate a bus reset for the bus this device is on.  The bus reset can be
602607ca46eSDavid Howells  * either the original (long) bus reset or the arbitrated (short) bus reset
603607ca46eSDavid Howells  * introduced in 1394a-2000.
604607ca46eSDavid Howells  *
605607ca46eSDavid Howells  * The ioctl returns immediately.  A subsequent &fw_cdev_event_bus_reset
606607ca46eSDavid Howells  * indicates when the reset actually happened.  Since ABI v4, this may be
607607ca46eSDavid Howells  * considerably later than the ioctl because the kernel ensures a grace period
608607ca46eSDavid Howells  * between subsequent bus resets as per IEEE 1394 bus management specification.
609607ca46eSDavid Howells  */
610607ca46eSDavid Howells struct fw_cdev_initiate_bus_reset {
611607ca46eSDavid Howells 	__u32 type;
612607ca46eSDavid Howells };
613607ca46eSDavid Howells 
614607ca46eSDavid Howells /**
615607ca46eSDavid Howells  * struct fw_cdev_add_descriptor - Add contents to the local node's config ROM
616607ca46eSDavid Howells  * @immediate:	If non-zero, immediate key to insert before pointer
617607ca46eSDavid Howells  * @key:	Upper 8 bits of root directory pointer
618607ca46eSDavid Howells  * @data:	Userspace pointer to contents of descriptor block
619607ca46eSDavid Howells  * @length:	Length of descriptor block data, in quadlets
620607ca46eSDavid Howells  * @handle:	Handle to the descriptor, written by the kernel
621607ca46eSDavid Howells  *
622607ca46eSDavid Howells  * Add a descriptor block and optionally a preceding immediate key to the local
623607ca46eSDavid Howells  * node's Configuration ROM.
624607ca46eSDavid Howells  *
625607ca46eSDavid Howells  * The @key field specifies the upper 8 bits of the descriptor root directory
626607ca46eSDavid Howells  * pointer and the @data and @length fields specify the contents. The @key
627607ca46eSDavid Howells  * should be of the form 0xXX000000. The offset part of the root directory entry
628607ca46eSDavid Howells  * will be filled in by the kernel.
629607ca46eSDavid Howells  *
630607ca46eSDavid Howells  * If not 0, the @immediate field specifies an immediate key which will be
631607ca46eSDavid Howells  * inserted before the root directory pointer.
632607ca46eSDavid Howells  *
633607ca46eSDavid Howells  * @immediate, @key, and @data array elements are CPU-endian quadlets.
634607ca46eSDavid Howells  *
635607ca46eSDavid Howells  * If successful, the kernel adds the descriptor and writes back a @handle to
636607ca46eSDavid Howells  * the kernel-side object to be used for later removal of the descriptor block
637607ca46eSDavid Howells  * and immediate key.  The kernel will also generate a bus reset to signal the
638607ca46eSDavid Howells  * change of the Configuration ROM to other nodes.
639607ca46eSDavid Howells  *
640607ca46eSDavid Howells  * This ioctl affects the Configuration ROMs of all local nodes.
641607ca46eSDavid Howells  * The ioctl only succeeds on device files which represent a local node.
642607ca46eSDavid Howells  */
643607ca46eSDavid Howells struct fw_cdev_add_descriptor {
644607ca46eSDavid Howells 	__u32 immediate;
645607ca46eSDavid Howells 	__u32 key;
646607ca46eSDavid Howells 	__u64 data;
647607ca46eSDavid Howells 	__u32 length;
648607ca46eSDavid Howells 	__u32 handle;
649607ca46eSDavid Howells };
650607ca46eSDavid Howells 
651607ca46eSDavid Howells /**
652607ca46eSDavid Howells  * struct fw_cdev_remove_descriptor - Remove contents from the Configuration ROM
653607ca46eSDavid Howells  * @handle:	Handle to the descriptor, as returned by the kernel when the
654607ca46eSDavid Howells  *		descriptor was added
655607ca46eSDavid Howells  *
656607ca46eSDavid Howells  * Remove a descriptor block and accompanying immediate key from the local
657607ca46eSDavid Howells  * nodes' Configuration ROMs.  The kernel will also generate a bus reset to
658607ca46eSDavid Howells  * signal the change of the Configuration ROM to other nodes.
659607ca46eSDavid Howells  */
660607ca46eSDavid Howells struct fw_cdev_remove_descriptor {
661607ca46eSDavid Howells 	__u32 handle;
662607ca46eSDavid Howells };
663607ca46eSDavid Howells 
664607ca46eSDavid Howells #define FW_CDEV_ISO_CONTEXT_TRANSMIT			0
665607ca46eSDavid Howells #define FW_CDEV_ISO_CONTEXT_RECEIVE			1
666607ca46eSDavid Howells #define FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL	2 /* added in 2.6.36 */
667607ca46eSDavid Howells 
668607ca46eSDavid Howells /**
669607ca46eSDavid Howells  * struct fw_cdev_create_iso_context - Create a context for isochronous I/O
670607ca46eSDavid Howells  * @type:	%FW_CDEV_ISO_CONTEXT_TRANSMIT or %FW_CDEV_ISO_CONTEXT_RECEIVE or
671607ca46eSDavid Howells  *		%FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL
672607ca46eSDavid Howells  * @header_size: Header size to strip in single-channel reception
673607ca46eSDavid Howells  * @channel:	Channel to bind to in single-channel reception or transmission
674607ca46eSDavid Howells  * @speed:	Transmission speed
675607ca46eSDavid Howells  * @closure:	To be returned in &fw_cdev_event_iso_interrupt or
676607ca46eSDavid Howells  *		&fw_cdev_event_iso_interrupt_multichannel
677607ca46eSDavid Howells  * @handle:	Handle to context, written back by kernel
678607ca46eSDavid Howells  *
679607ca46eSDavid Howells  * Prior to sending or receiving isochronous I/O, a context must be created.
680607ca46eSDavid Howells  * The context records information about the transmit or receive configuration
681607ca46eSDavid Howells  * and typically maps to an underlying hardware resource.  A context is set up
682607ca46eSDavid Howells  * for either sending or receiving.  It is bound to a specific isochronous
683607ca46eSDavid Howells  * @channel.
684607ca46eSDavid Howells  *
685607ca46eSDavid Howells  * In case of multichannel reception, @header_size and @channel are ignored
686607ca46eSDavid Howells  * and the channels are selected by %FW_CDEV_IOC_SET_ISO_CHANNELS.
687607ca46eSDavid Howells  *
688607ca46eSDavid Howells  * For %FW_CDEV_ISO_CONTEXT_RECEIVE contexts, @header_size must be at least 4
689607ca46eSDavid Howells  * and must be a multiple of 4.  It is ignored in other context types.
690607ca46eSDavid Howells  *
691607ca46eSDavid Howells  * @speed is ignored in receive context types.
692607ca46eSDavid Howells  *
693607ca46eSDavid Howells  * If a context was successfully created, the kernel writes back a handle to the
694607ca46eSDavid Howells  * context, which must be passed in for subsequent operations on that context.
695607ca46eSDavid Howells  *
696607ca46eSDavid Howells  * Limitations:
697607ca46eSDavid Howells  * No more than one iso context can be created per fd.
698607ca46eSDavid Howells  * The total number of contexts that all userspace and kernelspace drivers can
699607ca46eSDavid Howells  * create on a card at a time is a hardware limit, typically 4 or 8 contexts per
700607ca46eSDavid Howells  * direction, and of them at most one multichannel receive context.
701607ca46eSDavid Howells  */
702607ca46eSDavid Howells struct fw_cdev_create_iso_context {
703607ca46eSDavid Howells 	__u32 type;
704607ca46eSDavid Howells 	__u32 header_size;
705607ca46eSDavid Howells 	__u32 channel;
706607ca46eSDavid Howells 	__u32 speed;
707607ca46eSDavid Howells 	__u64 closure;
708607ca46eSDavid Howells 	__u32 handle;
709607ca46eSDavid Howells };
710607ca46eSDavid Howells 
711607ca46eSDavid Howells /**
712607ca46eSDavid Howells  * struct fw_cdev_set_iso_channels - Select channels in multichannel reception
713607ca46eSDavid Howells  * @channels:	Bitmask of channels to listen to
714607ca46eSDavid Howells  * @handle:	Handle of the mutichannel receive context
715607ca46eSDavid Howells  *
716607ca46eSDavid Howells  * @channels is the bitwise or of 1ULL << n for each channel n to listen to.
717607ca46eSDavid Howells  *
718607ca46eSDavid Howells  * The ioctl fails with errno %EBUSY if there is already another receive context
719607ca46eSDavid Howells  * on a channel in @channels.  In that case, the bitmask of all unoccupied
720607ca46eSDavid Howells  * channels is returned in @channels.
721607ca46eSDavid Howells  */
722607ca46eSDavid Howells struct fw_cdev_set_iso_channels {
723607ca46eSDavid Howells 	__u64 channels;
724607ca46eSDavid Howells 	__u32 handle;
725607ca46eSDavid Howells };
726607ca46eSDavid Howells 
727607ca46eSDavid Howells #define FW_CDEV_ISO_PAYLOAD_LENGTH(v)	(v)
728607ca46eSDavid Howells #define FW_CDEV_ISO_INTERRUPT		(1 << 16)
729607ca46eSDavid Howells #define FW_CDEV_ISO_SKIP		(1 << 17)
730607ca46eSDavid Howells #define FW_CDEV_ISO_SYNC		(1 << 17)
731607ca46eSDavid Howells #define FW_CDEV_ISO_TAG(v)		((v) << 18)
732607ca46eSDavid Howells #define FW_CDEV_ISO_SY(v)		((v) << 20)
733607ca46eSDavid Howells #define FW_CDEV_ISO_HEADER_LENGTH(v)	((v) << 24)
734607ca46eSDavid Howells 
735607ca46eSDavid Howells /**
736607ca46eSDavid Howells  * struct fw_cdev_iso_packet - Isochronous packet
737607ca46eSDavid Howells  * @control:	Contains the header length (8 uppermost bits),
738607ca46eSDavid Howells  *		the sy field (4 bits), the tag field (2 bits), a sync flag
739607ca46eSDavid Howells  *		or a skip flag (1 bit), an interrupt flag (1 bit), and the
740607ca46eSDavid Howells  *		payload length (16 lowermost bits)
741607ca46eSDavid Howells  * @header:	Header and payload in case of a transmit context.
742607ca46eSDavid Howells  *
743607ca46eSDavid Howells  * &struct fw_cdev_iso_packet is used to describe isochronous packet queues.
7449a400682SRandy Dunlap  * Use the FW_CDEV_ISO_* macros to fill in @control.
745607ca46eSDavid Howells  * The @header array is empty in case of receive contexts.
746607ca46eSDavid Howells  *
747607ca46eSDavid Howells  * Context type %FW_CDEV_ISO_CONTEXT_TRANSMIT:
748607ca46eSDavid Howells  *
749607ca46eSDavid Howells  * @control.HEADER_LENGTH must be a multiple of 4.  It specifies the numbers of
750607ca46eSDavid Howells  * bytes in @header that will be prepended to the packet's payload.  These bytes
751607ca46eSDavid Howells  * are copied into the kernel and will not be accessed after the ioctl has
752607ca46eSDavid Howells  * returned.
753607ca46eSDavid Howells  *
754607ca46eSDavid Howells  * The @control.SY and TAG fields are copied to the iso packet header.  These
755607ca46eSDavid Howells  * fields are specified by IEEE 1394a and IEC 61883-1.
756607ca46eSDavid Howells  *
757607ca46eSDavid Howells  * The @control.SKIP flag specifies that no packet is to be sent in a frame.
758607ca46eSDavid Howells  * When using this, all other fields except @control.INTERRUPT must be zero.
759607ca46eSDavid Howells  *
760607ca46eSDavid Howells  * When a packet with the @control.INTERRUPT flag set has been completed, an
761607ca46eSDavid Howells  * &fw_cdev_event_iso_interrupt event will be sent.
762607ca46eSDavid Howells  *
763607ca46eSDavid Howells  * Context type %FW_CDEV_ISO_CONTEXT_RECEIVE:
764607ca46eSDavid Howells  *
765607ca46eSDavid Howells  * @control.HEADER_LENGTH must be a multiple of the context's header_size.
766607ca46eSDavid Howells  * If the HEADER_LENGTH is larger than the context's header_size, multiple
767607ca46eSDavid Howells  * packets are queued for this entry.
768607ca46eSDavid Howells  *
769607ca46eSDavid Howells  * The @control.SY and TAG fields are ignored.
770607ca46eSDavid Howells  *
771607ca46eSDavid Howells  * If the @control.SYNC flag is set, the context drops all packets until a
772607ca46eSDavid Howells  * packet with a sy field is received which matches &fw_cdev_start_iso.sync.
773607ca46eSDavid Howells  *
774607ca46eSDavid Howells  * @control.PAYLOAD_LENGTH defines how many payload bytes can be received for
775607ca46eSDavid Howells  * one packet (in addition to payload quadlets that have been defined as headers
776607ca46eSDavid Howells  * and are stripped and returned in the &fw_cdev_event_iso_interrupt structure).
777607ca46eSDavid Howells  * If more bytes are received, the additional bytes are dropped.  If less bytes
778607ca46eSDavid Howells  * are received, the remaining bytes in this part of the payload buffer will not
779607ca46eSDavid Howells  * be written to, not even by the next packet.  I.e., packets received in
780607ca46eSDavid Howells  * consecutive frames will not necessarily be consecutive in memory.  If an
781607ca46eSDavid Howells  * entry has queued multiple packets, the PAYLOAD_LENGTH is divided equally
782607ca46eSDavid Howells  * among them.
783607ca46eSDavid Howells  *
784607ca46eSDavid Howells  * When a packet with the @control.INTERRUPT flag set has been completed, an
785607ca46eSDavid Howells  * &fw_cdev_event_iso_interrupt event will be sent.  An entry that has queued
786607ca46eSDavid Howells  * multiple receive packets is completed when its last packet is completed.
787607ca46eSDavid Howells  *
788607ca46eSDavid Howells  * Context type %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL:
789607ca46eSDavid Howells  *
790607ca46eSDavid Howells  * Here, &fw_cdev_iso_packet would be more aptly named _iso_buffer_chunk since
791607ca46eSDavid Howells  * it specifies a chunk of the mmap()'ed buffer, while the number and alignment
792607ca46eSDavid Howells  * of packets to be placed into the buffer chunk is not known beforehand.
793607ca46eSDavid Howells  *
794607ca46eSDavid Howells  * @control.PAYLOAD_LENGTH is the size of the buffer chunk and specifies room
795607ca46eSDavid Howells  * for header, payload, padding, and trailer bytes of one or more packets.
796607ca46eSDavid Howells  * It must be a multiple of 4.
797607ca46eSDavid Howells  *
798607ca46eSDavid Howells  * @control.HEADER_LENGTH, TAG and SY are ignored.  SYNC is treated as described
799607ca46eSDavid Howells  * for single-channel reception.
800607ca46eSDavid Howells  *
801607ca46eSDavid Howells  * When a buffer chunk with the @control.INTERRUPT flag set has been filled
802607ca46eSDavid Howells  * entirely, an &fw_cdev_event_iso_interrupt_mc event will be sent.
803607ca46eSDavid Howells  */
804607ca46eSDavid Howells struct fw_cdev_iso_packet {
805607ca46eSDavid Howells 	__u32 control;
806607ca46eSDavid Howells 	__u32 header[0];
807607ca46eSDavid Howells };
808607ca46eSDavid Howells 
809607ca46eSDavid Howells /**
810607ca46eSDavid Howells  * struct fw_cdev_queue_iso - Queue isochronous packets for I/O
811607ca46eSDavid Howells  * @packets:	Userspace pointer to an array of &fw_cdev_iso_packet
812607ca46eSDavid Howells  * @data:	Pointer into mmap()'ed payload buffer
813607ca46eSDavid Howells  * @size:	Size of the @packets array, in bytes
814607ca46eSDavid Howells  * @handle:	Isochronous context handle
815607ca46eSDavid Howells  *
816607ca46eSDavid Howells  * Queue a number of isochronous packets for reception or transmission.
817607ca46eSDavid Howells  * This ioctl takes a pointer to an array of &fw_cdev_iso_packet structs,
818607ca46eSDavid Howells  * which describe how to transmit from or receive into a contiguous region
819607ca46eSDavid Howells  * of a mmap()'ed payload buffer.  As part of transmit packet descriptors,
820607ca46eSDavid Howells  * a series of headers can be supplied, which will be prepended to the
821607ca46eSDavid Howells  * payload during DMA.
822607ca46eSDavid Howells  *
823607ca46eSDavid Howells  * The kernel may or may not queue all packets, but will write back updated
824607ca46eSDavid Howells  * values of the @packets, @data and @size fields, so the ioctl can be
825607ca46eSDavid Howells  * resubmitted easily.
826607ca46eSDavid Howells  *
827607ca46eSDavid Howells  * In case of a multichannel receive context, @data must be quadlet-aligned
828607ca46eSDavid Howells  * relative to the buffer start.
829607ca46eSDavid Howells  */
830607ca46eSDavid Howells struct fw_cdev_queue_iso {
831607ca46eSDavid Howells 	__u64 packets;
832607ca46eSDavid Howells 	__u64 data;
833607ca46eSDavid Howells 	__u32 size;
834607ca46eSDavid Howells 	__u32 handle;
835607ca46eSDavid Howells };
836607ca46eSDavid Howells 
837607ca46eSDavid Howells #define FW_CDEV_ISO_CONTEXT_MATCH_TAG0		 1
838607ca46eSDavid Howells #define FW_CDEV_ISO_CONTEXT_MATCH_TAG1		 2
839607ca46eSDavid Howells #define FW_CDEV_ISO_CONTEXT_MATCH_TAG2		 4
840607ca46eSDavid Howells #define FW_CDEV_ISO_CONTEXT_MATCH_TAG3		 8
841607ca46eSDavid Howells #define FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS	15
842607ca46eSDavid Howells 
843607ca46eSDavid Howells /**
844607ca46eSDavid Howells  * struct fw_cdev_start_iso - Start an isochronous transmission or reception
845607ca46eSDavid Howells  * @cycle:	Cycle in which to start I/O.  If @cycle is greater than or
846607ca46eSDavid Howells  *		equal to 0, the I/O will start on that cycle.
847607ca46eSDavid Howells  * @sync:	Determines the value to wait for for receive packets that have
848607ca46eSDavid Howells  *		the %FW_CDEV_ISO_SYNC bit set
849607ca46eSDavid Howells  * @tags:	Tag filter bit mask.  Only valid for isochronous reception.
850607ca46eSDavid Howells  *		Determines the tag values for which packets will be accepted.
8519a400682SRandy Dunlap  *		Use FW_CDEV_ISO_CONTEXT_MATCH_* macros to set @tags.
852607ca46eSDavid Howells  * @handle:	Isochronous context handle within which to transmit or receive
853607ca46eSDavid Howells  */
854607ca46eSDavid Howells struct fw_cdev_start_iso {
855607ca46eSDavid Howells 	__s32 cycle;
856607ca46eSDavid Howells 	__u32 sync;
857607ca46eSDavid Howells 	__u32 tags;
858607ca46eSDavid Howells 	__u32 handle;
859607ca46eSDavid Howells };
860607ca46eSDavid Howells 
861607ca46eSDavid Howells /**
862607ca46eSDavid Howells  * struct fw_cdev_stop_iso - Stop an isochronous transmission or reception
863607ca46eSDavid Howells  * @handle:	Handle of isochronous context to stop
864607ca46eSDavid Howells  */
865607ca46eSDavid Howells struct fw_cdev_stop_iso {
866607ca46eSDavid Howells 	__u32 handle;
867607ca46eSDavid Howells };
868607ca46eSDavid Howells 
869607ca46eSDavid Howells /**
870607ca46eSDavid Howells  * struct fw_cdev_flush_iso - flush completed iso packets
871607ca46eSDavid Howells  * @handle:	handle of isochronous context to flush
872607ca46eSDavid Howells  *
873607ca46eSDavid Howells  * For %FW_CDEV_ISO_CONTEXT_TRANSMIT or %FW_CDEV_ISO_CONTEXT_RECEIVE contexts,
874607ca46eSDavid Howells  * report any completed packets.
875607ca46eSDavid Howells  *
876607ca46eSDavid Howells  * For %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL contexts, report the current
877607ca46eSDavid Howells  * offset in the receive buffer, if it has changed; this is typically in the
878607ca46eSDavid Howells  * middle of some buffer chunk.
879607ca46eSDavid Howells  *
880607ca46eSDavid Howells  * Any %FW_CDEV_EVENT_ISO_INTERRUPT or %FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL
881607ca46eSDavid Howells  * events generated by this ioctl are sent synchronously, i.e., are available
882607ca46eSDavid Howells  * for reading from the file descriptor when this ioctl returns.
883607ca46eSDavid Howells  */
884607ca46eSDavid Howells struct fw_cdev_flush_iso {
885607ca46eSDavid Howells 	__u32 handle;
886607ca46eSDavid Howells };
887607ca46eSDavid Howells 
888607ca46eSDavid Howells /**
889607ca46eSDavid Howells  * struct fw_cdev_get_cycle_timer - read cycle timer register
890607ca46eSDavid Howells  * @local_time:   system time, in microseconds since the Epoch
891607ca46eSDavid Howells  * @cycle_timer:  Cycle Time register contents
892607ca46eSDavid Howells  *
893607ca46eSDavid Howells  * Same as %FW_CDEV_IOC_GET_CYCLE_TIMER2, but fixed to use %CLOCK_REALTIME
894607ca46eSDavid Howells  * and only with microseconds resolution.
895607ca46eSDavid Howells  *
896607ca46eSDavid Howells  * In version 1 and 2 of the ABI, this ioctl returned unreliable (non-
897607ca46eSDavid Howells  * monotonic) @cycle_timer values on certain controllers.
898607ca46eSDavid Howells  */
899607ca46eSDavid Howells struct fw_cdev_get_cycle_timer {
900607ca46eSDavid Howells 	__u64 local_time;
901607ca46eSDavid Howells 	__u32 cycle_timer;
902607ca46eSDavid Howells };
903607ca46eSDavid Howells 
904607ca46eSDavid Howells /**
905607ca46eSDavid Howells  * struct fw_cdev_get_cycle_timer2 - read cycle timer register
906607ca46eSDavid Howells  * @tv_sec:       system time, seconds
907607ca46eSDavid Howells  * @tv_nsec:      system time, sub-seconds part in nanoseconds
908607ca46eSDavid Howells  * @clk_id:       input parameter, clock from which to get the system time
909607ca46eSDavid Howells  * @cycle_timer:  Cycle Time register contents
910607ca46eSDavid Howells  *
911607ca46eSDavid Howells  * The %FW_CDEV_IOC_GET_CYCLE_TIMER2 ioctl reads the isochronous cycle timer
912607ca46eSDavid Howells  * and also the system clock.  This allows to correlate reception time of
913607ca46eSDavid Howells  * isochronous packets with system time.
914607ca46eSDavid Howells  *
915607ca46eSDavid Howells  * @clk_id lets you choose a clock like with POSIX' clock_gettime function.
916607ca46eSDavid Howells  * Supported @clk_id values are POSIX' %CLOCK_REALTIME and %CLOCK_MONOTONIC
917607ca46eSDavid Howells  * and Linux' %CLOCK_MONOTONIC_RAW.
918607ca46eSDavid Howells  *
919607ca46eSDavid Howells  * @cycle_timer consists of 7 bits cycleSeconds, 13 bits cycleCount, and
920607ca46eSDavid Howells  * 12 bits cycleOffset, in host byte order.  Cf. the Cycle Time register
921607ca46eSDavid Howells  * per IEEE 1394 or Isochronous Cycle Timer register per OHCI-1394.
922607ca46eSDavid Howells  */
923607ca46eSDavid Howells struct fw_cdev_get_cycle_timer2 {
924607ca46eSDavid Howells 	__s64 tv_sec;
925607ca46eSDavid Howells 	__s32 tv_nsec;
926607ca46eSDavid Howells 	__s32 clk_id;
927607ca46eSDavid Howells 	__u32 cycle_timer;
928607ca46eSDavid Howells };
929607ca46eSDavid Howells 
930607ca46eSDavid Howells /**
931607ca46eSDavid Howells  * struct fw_cdev_allocate_iso_resource - (De)allocate a channel or bandwidth
932607ca46eSDavid Howells  * @closure:	Passed back to userspace in corresponding iso resource events
933607ca46eSDavid Howells  * @channels:	Isochronous channels of which one is to be (de)allocated
934607ca46eSDavid Howells  * @bandwidth:	Isochronous bandwidth units to be (de)allocated
935607ca46eSDavid Howells  * @handle:	Handle to the allocation, written by the kernel (only valid in
936607ca46eSDavid Howells  *		case of %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ioctls)
937607ca46eSDavid Howells  *
938607ca46eSDavid Howells  * The %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ioctl initiates allocation of an
939607ca46eSDavid Howells  * isochronous channel and/or of isochronous bandwidth at the isochronous
940607ca46eSDavid Howells  * resource manager (IRM).  Only one of the channels specified in @channels is
941607ca46eSDavid Howells  * allocated.  An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED is sent after
942607ca46eSDavid Howells  * communication with the IRM, indicating success or failure in the event data.
943607ca46eSDavid Howells  * The kernel will automatically reallocate the resources after bus resets.
944607ca46eSDavid Howells  * Should a reallocation fail, an %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event
945607ca46eSDavid Howells  * will be sent.  The kernel will also automatically deallocate the resources
946607ca46eSDavid Howells  * when the file descriptor is closed.
947607ca46eSDavid Howells  *
948607ca46eSDavid Howells  * The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE ioctl can be used to initiate
949607ca46eSDavid Howells  * deallocation of resources which were allocated as described above.
950607ca46eSDavid Howells  * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation.
951607ca46eSDavid Howells  *
952607ca46eSDavid Howells  * The %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE ioctl is a variant of allocation
953607ca46eSDavid Howells  * without automatic re- or deallocation.
954607ca46eSDavid Howells  * An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event concludes this operation,
955607ca46eSDavid Howells  * indicating success or failure in its data.
956607ca46eSDavid Howells  *
957607ca46eSDavid Howells  * The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE ioctl works like
958607ca46eSDavid Howells  * %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE except that resources are freed
959607ca46eSDavid Howells  * instead of allocated.
960607ca46eSDavid Howells  * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation.
961607ca46eSDavid Howells  *
962607ca46eSDavid Howells  * To summarize, %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE allocates iso resources
963607ca46eSDavid Howells  * for the lifetime of the fd or @handle.
964607ca46eSDavid Howells  * In contrast, %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE allocates iso resources
965607ca46eSDavid Howells  * for the duration of a bus generation.
966607ca46eSDavid Howells  *
967607ca46eSDavid Howells  * @channels is a host-endian bitfield with the least significant bit
968607ca46eSDavid Howells  * representing channel 0 and the most significant bit representing channel 63:
969607ca46eSDavid Howells  * 1ULL << c for each channel c that is a candidate for (de)allocation.
970607ca46eSDavid Howells  *
971607ca46eSDavid Howells  * @bandwidth is expressed in bandwidth allocation units, i.e. the time to send
972607ca46eSDavid Howells  * one quadlet of data (payload or header data) at speed S1600.
973607ca46eSDavid Howells  */
974607ca46eSDavid Howells struct fw_cdev_allocate_iso_resource {
975607ca46eSDavid Howells 	__u64 closure;
976607ca46eSDavid Howells 	__u64 channels;
977607ca46eSDavid Howells 	__u32 bandwidth;
978607ca46eSDavid Howells 	__u32 handle;
979607ca46eSDavid Howells };
980607ca46eSDavid Howells 
981607ca46eSDavid Howells /**
982607ca46eSDavid Howells  * struct fw_cdev_send_stream_packet - send an asynchronous stream packet
983607ca46eSDavid Howells  * @length:	Length of outgoing payload, in bytes
984607ca46eSDavid Howells  * @tag:	Data format tag
985607ca46eSDavid Howells  * @channel:	Isochronous channel to transmit to
986607ca46eSDavid Howells  * @sy:		Synchronization code
987607ca46eSDavid Howells  * @closure:	Passed back to userspace in the response event
988607ca46eSDavid Howells  * @data:	Userspace pointer to payload
989607ca46eSDavid Howells  * @generation:	The bus generation where packet is valid
990607ca46eSDavid Howells  * @speed:	Speed to transmit at
991607ca46eSDavid Howells  *
992607ca46eSDavid Howells  * The %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl sends an asynchronous stream packet
993607ca46eSDavid Howells  * to every device which is listening to the specified channel.  The kernel
994607ca46eSDavid Howells  * writes an &fw_cdev_event_response event which indicates success or failure of
995607ca46eSDavid Howells  * the transmission.
996607ca46eSDavid Howells  */
997607ca46eSDavid Howells struct fw_cdev_send_stream_packet {
998607ca46eSDavid Howells 	__u32 length;
999607ca46eSDavid Howells 	__u32 tag;
1000607ca46eSDavid Howells 	__u32 channel;
1001607ca46eSDavid Howells 	__u32 sy;
1002607ca46eSDavid Howells 	__u64 closure;
1003607ca46eSDavid Howells 	__u64 data;
1004607ca46eSDavid Howells 	__u32 generation;
1005607ca46eSDavid Howells 	__u32 speed;
1006607ca46eSDavid Howells };
1007607ca46eSDavid Howells 
1008607ca46eSDavid Howells /**
1009607ca46eSDavid Howells  * struct fw_cdev_send_phy_packet - send a PHY packet
1010607ca46eSDavid Howells  * @closure:	Passed back to userspace in the PHY-packet-sent event
1011607ca46eSDavid Howells  * @data:	First and second quadlet of the PHY packet
1012607ca46eSDavid Howells  * @generation:	The bus generation where packet is valid
1013607ca46eSDavid Howells  *
1014607ca46eSDavid Howells  * The %FW_CDEV_IOC_SEND_PHY_PACKET ioctl sends a PHY packet to all nodes
1015607ca46eSDavid Howells  * on the same card as this device.  After transmission, an
1016607ca46eSDavid Howells  * %FW_CDEV_EVENT_PHY_PACKET_SENT event is generated.
1017607ca46eSDavid Howells  *
10189a400682SRandy Dunlap  * The payload @data\[\] shall be specified in host byte order.  Usually,
10199a400682SRandy Dunlap  * @data\[1\] needs to be the bitwise inverse of @data\[0\].  VersaPHY packets
1020607ca46eSDavid Howells  * are an exception to this rule.
1021607ca46eSDavid Howells  *
1022607ca46eSDavid Howells  * The ioctl is only permitted on device files which represent a local node.
1023607ca46eSDavid Howells  */
1024607ca46eSDavid Howells struct fw_cdev_send_phy_packet {
1025607ca46eSDavid Howells 	__u64 closure;
1026607ca46eSDavid Howells 	__u32 data[2];
1027607ca46eSDavid Howells 	__u32 generation;
1028607ca46eSDavid Howells };
1029607ca46eSDavid Howells 
1030607ca46eSDavid Howells /**
1031607ca46eSDavid Howells  * struct fw_cdev_receive_phy_packets - start reception of PHY packets
1032607ca46eSDavid Howells  * @closure: Passed back to userspace in phy packet events
1033607ca46eSDavid Howells  *
1034607ca46eSDavid Howells  * This ioctl activates issuing of %FW_CDEV_EVENT_PHY_PACKET_RECEIVED due to
1035607ca46eSDavid Howells  * incoming PHY packets from any node on the same bus as the device.
1036607ca46eSDavid Howells  *
1037607ca46eSDavid Howells  * The ioctl is only permitted on device files which represent a local node.
1038607ca46eSDavid Howells  */
1039607ca46eSDavid Howells struct fw_cdev_receive_phy_packets {
1040607ca46eSDavid Howells 	__u64 closure;
1041607ca46eSDavid Howells };
1042607ca46eSDavid Howells 
1043607ca46eSDavid Howells #define FW_CDEV_VERSION 3 /* Meaningless legacy macro; don't use it. */
1044607ca46eSDavid Howells 
1045607ca46eSDavid Howells #endif /* _LINUX_FIREWIRE_CDEV_H */
1046