blob: 357dbfc2829e3f5ac3dc729f2b1b28345f91daea [file] [log] [blame]
Kristian Høgsberg4c5a4432007-05-07 20:33:37 -04001/*
2 * Char device interface.
Kristian Høgsberg19a15b92006-12-19 19:58:31 -05003 *
Stefan Richter19b3eec2010-04-11 11:52:12 +02004 * Copyright (C) 2005-2007 Kristian Hoegsberg <krh@bitplanet.net>
Kristian Høgsberg19a15b92006-12-19 19:58:31 -05005 *
Stefan Richter19b3eec2010-04-11 11:52:12 +02006 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050012 *
Stefan Richter19b3eec2010-04-11 11:52:12 +020013 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050016 *
Stefan Richter19b3eec2010-04-11 11:52:12 +020017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
Stefan Richtera2612cb2010-04-15 22:16:04 +020020 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
Stefan Richter19b3eec2010-04-11 11:52:12 +020021 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050024 */
25
Kristian Høgsberg4c5a4432007-05-07 20:33:37 -040026#ifndef _LINUX_FIREWIRE_CDEV_H
27#define _LINUX_FIREWIRE_CDEV_H
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050028
Kristian Høgsberg04dfb8d2007-05-07 20:33:36 -040029#include <linux/ioctl.h>
30#include <linux/types.h>
Kristian Høgsberg4c5a4432007-05-07 20:33:37 -040031#include <linux/firewire-constants.h>
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050032
Stefan Richterf6a7cd02011-07-14 21:08:39 +020033/* available since kernel version 2.6.22 */
Stefan Richter872e3302010-07-29 18:19:22 +020034#define FW_CDEV_EVENT_BUS_RESET 0x00
35#define FW_CDEV_EVENT_RESPONSE 0x01
36#define FW_CDEV_EVENT_REQUEST 0x02
37#define FW_CDEV_EVENT_ISO_INTERRUPT 0x03
Stefan Richterf6a7cd02011-07-14 21:08:39 +020038
39/* available since kernel version 2.6.30 */
Stefan Richter872e3302010-07-29 18:19:22 +020040#define FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED 0x04
41#define FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED 0x05
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050042
Stefan Richtere2055972010-06-20 22:53:55 +020043/* available since kernel version 2.6.36 */
Stefan Richter872e3302010-07-29 18:19:22 +020044#define FW_CDEV_EVENT_REQUEST2 0x06
45#define FW_CDEV_EVENT_PHY_PACKET_SENT 0x07
46#define FW_CDEV_EVENT_PHY_PACKET_RECEIVED 0x08
47#define FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL 0x09
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050048
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +020049/**
50 * struct fw_cdev_event_common - Common part of all fw_cdev_event_ types
51 * @closure: For arbitrary use by userspace
52 * @type: Discriminates the fw_cdev_event_ types
53 *
54 * This struct may be used to access generic members of all fw_cdev_event_
55 * types regardless of the specific type.
56 *
57 * Data passed in the @closure field for a request will be returned in the
58 * corresponding event. It is big enough to hold a pointer on all platforms.
59 * The ioctl used to set @closure depends on the @type of event.
60 */
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -040061struct fw_cdev_event_common {
62 __u64 closure;
63 __u32 type;
64};
65
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +020066/**
67 * struct fw_cdev_event_bus_reset - Sent when a bus reset occurred
68 * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_GET_INFO ioctl
69 * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_BUS_RESET
70 * @node_id: New node ID of this node
71 * @local_node_id: Node ID of the local node, i.e. of the controller
72 * @bm_node_id: Node ID of the bus manager
73 * @irm_node_id: Node ID of the iso resource manager
74 * @root_node_id: Node ID of the root node
75 * @generation: New bus generation
76 *
77 * This event is sent when the bus the device belongs to goes through a bus
78 * reset. It provides information about the new bus configuration, such as
79 * new node ID for this device, new root ID, and others.
Stefan Richter250b2b62010-06-21 23:24:35 +020080 *
81 * If @bm_node_id is 0xffff right after bus reset it can be reread by an
82 * %FW_CDEV_IOC_GET_INFO ioctl after bus manager selection was finished.
83 * Kernels with ABI version < 4 do not set @bm_node_id.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +020084 */
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -050085struct fw_cdev_event_bus_reset {
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -040086 __u64 closure;
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -050087 __u32 type;
88 __u32 node_id;
89 __u32 local_node_id;
90 __u32 bm_node_id;
91 __u32 irm_node_id;
92 __u32 root_node_id;
93 __u32 generation;
94};
95
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +020096/**
97 * struct fw_cdev_event_response - Sent when a response packet was received
Stefan Richterd505e6e2010-07-17 21:36:02 +020098 * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_SEND_REQUEST
99 * or %FW_CDEV_IOC_SEND_BROADCAST_REQUEST
100 * or %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200101 * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_RESPONSE
102 * @rcode: Response code returned by the remote node
103 * @length: Data length, i.e. the response's payload size in bytes
104 * @data: Payload data, if any
105 *
106 * This event is sent when the stack receives a response to an outgoing request
107 * sent by %FW_CDEV_IOC_SEND_REQUEST ioctl. The payload data for responses
108 * carrying data (read and lock responses) follows immediately and can be
109 * accessed through the @data field.
Stefan Richterd505e6e2010-07-17 21:36:02 +0200110 *
111 * The event is also generated after conclusions of transactions that do not
112 * involve response packets. This includes unified write transactions,
113 * broadcast write transactions, and transmission of asynchronous stream
114 * packets. @rcode indicates success or failure of such transmissions.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200115 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500116struct fw_cdev_event_response {
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400117 __u64 closure;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500118 __u32 type;
119 __u32 rcode;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500120 __u32 length;
121 __u32 data[0];
122};
123
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200124/**
Stefan Richtere2055972010-06-20 22:53:55 +0200125 * struct fw_cdev_event_request - Old version of &fw_cdev_event_request2
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200126 * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST
Stefan Richtere2055972010-06-20 22:53:55 +0200127 *
128 * This event is sent instead of &fw_cdev_event_request2 if the kernel or
Stefan Richterf6a7cd02011-07-14 21:08:39 +0200129 * the client implements ABI version <= 3. &fw_cdev_event_request lacks
130 * essential information; use &fw_cdev_event_request2 instead.
Stefan Richtere2055972010-06-20 22:53:55 +0200131 */
132struct fw_cdev_event_request {
133 __u64 closure;
134 __u32 type;
135 __u32 tcode;
136 __u64 offset;
137 __u32 handle;
138 __u32 length;
139 __u32 data[0];
140};
141
142/**
143 * struct fw_cdev_event_request2 - Sent on incoming request to an address region
144 * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_ALLOCATE ioctl
145 * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST2
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200146 * @tcode: Transaction code of the incoming request
147 * @offset: The offset into the 48-bit per-node address space
Stefan Richtere2055972010-06-20 22:53:55 +0200148 * @source_node_id: Sender node ID
149 * @destination_node_id: Destination node ID
150 * @card: The index of the card from which the request came
151 * @generation: Bus generation in which the request is valid
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200152 * @handle: Reference to the kernel-side pending request
153 * @length: Data length, i.e. the request's payload size in bytes
154 * @data: Incoming data, if any
155 *
156 * This event is sent when the stack receives an incoming request to an address
157 * region registered using the %FW_CDEV_IOC_ALLOCATE ioctl. The request is
158 * guaranteed to be completely contained in the specified region. Userspace is
159 * responsible for sending the response by %FW_CDEV_IOC_SEND_RESPONSE ioctl,
160 * using the same @handle.
161 *
162 * The payload data for requests carrying data (write and lock requests)
163 * follows immediately and can be accessed through the @data field.
Stefan Richtere2055972010-06-20 22:53:55 +0200164 *
165 * Unlike &fw_cdev_event_request, @tcode of lock requests is one of the
166 * firewire-core specific %TCODE_LOCK_MASK_SWAP...%TCODE_LOCK_VENDOR_DEPENDENT,
167 * i.e. encodes the extended transaction code.
168 *
169 * @card may differ from &fw_cdev_get_info.card because requests are received
170 * from all cards of the Linux host. @source_node_id, @destination_node_id, and
171 * @generation pertain to that card. Destination node ID and bus generation may
172 * therefore differ from the corresponding fields of the last
173 * &fw_cdev_event_bus_reset.
174 *
175 * @destination_node_id may also differ from the current node ID because of a
176 * non-local bus ID part or in case of a broadcast write request. Note, a
177 * client must call an %FW_CDEV_IOC_SEND_RESPONSE ioctl even in case of a
178 * broadcast write request; the kernel will then release the kernel-side pending
179 * request but will not actually send a response packet.
180 *
181 * In case of a write request to FCP_REQUEST or FCP_RESPONSE, the kernel already
182 * sent a write response immediately after the request was received; in this
183 * case the client must still call an %FW_CDEV_IOC_SEND_RESPONSE ioctl to
184 * release the kernel-side pending request, though another response won't be
185 * sent.
186 *
187 * If the client subsequently needs to initiate requests to the sender node of
188 * an &fw_cdev_event_request2, it needs to use a device file with matching
189 * card index, node ID, and generation for outbound requests.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200190 */
Stefan Richtere2055972010-06-20 22:53:55 +0200191struct fw_cdev_event_request2 {
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400192 __u64 closure;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500193 __u32 type;
194 __u32 tcode;
195 __u64 offset;
Stefan Richtere2055972010-06-20 22:53:55 +0200196 __u32 source_node_id;
197 __u32 destination_node_id;
198 __u32 card;
199 __u32 generation;
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400200 __u32 handle;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500201 __u32 length;
202 __u32 data[0];
203};
204
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200205/**
206 * struct fw_cdev_event_iso_interrupt - Sent when an iso packet was completed
207 * @closure: See &fw_cdev_event_common;
208 * set by %FW_CDEV_CREATE_ISO_CONTEXT ioctl
209 * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_ISO_INTERRUPT
210 * @cycle: Cycle counter of the interrupt packet
211 * @header_length: Total length of following headers, in bytes
212 * @header: Stripped headers, if any
213 *
214 * This event is sent when the controller has completed an &fw_cdev_iso_packet
Stefan Richter3b2b65d2010-06-20 22:54:22 +0200215 * with the %FW_CDEV_ISO_INTERRUPT bit set.
Stefan Richter77258da2009-01-07 20:14:53 +0100216 *
Stefan Richter872e3302010-07-29 18:19:22 +0200217 * Isochronous transmit events (context type %FW_CDEV_ISO_CONTEXT_TRANSMIT):
Stefan Richter77258da2009-01-07 20:14:53 +0100218 *
Stefan Richter872e3302010-07-29 18:19:22 +0200219 * In version 3 and some implementations of version 2 of the ABI, &header_length
220 * is a multiple of 4 and &header contains timestamps of all packets up until
221 * the interrupt packet. The format of the timestamps is as described below for
222 * isochronous reception. In version 1 of the ABI, &header_length was 0.
Stefan Richter77258da2009-01-07 20:14:53 +0100223 *
Stefan Richter872e3302010-07-29 18:19:22 +0200224 * Isochronous receive events (context type %FW_CDEV_ISO_CONTEXT_RECEIVE):
Stefan Richter3b2b65d2010-06-20 22:54:22 +0200225 *
226 * The headers stripped of all packets up until and including the interrupt
227 * packet are returned in the @header field. The amount of header data per
228 * packet is as specified at iso context creation by
229 * &fw_cdev_create_iso_context.header_size.
Stefan Richter77258da2009-01-07 20:14:53 +0100230 *
Stefan Richter872e3302010-07-29 18:19:22 +0200231 * Hence, _interrupt.header_length / _context.header_size is the number of
232 * packets received in this interrupt event. The client can now iterate
233 * through the mmap()'ed DMA buffer according to this number of packets and
234 * to the buffer sizes as the client specified in &fw_cdev_queue_iso.
Stefan Richter77258da2009-01-07 20:14:53 +0100235 *
Stefan Richter872e3302010-07-29 18:19:22 +0200236 * Since version 2 of this ABI, the portion for each packet in _interrupt.header
237 * consists of the 1394 isochronous packet header, followed by a timestamp
238 * quadlet if &fw_cdev_create_iso_context.header_size > 4, followed by quadlets
239 * from the packet payload if &fw_cdev_create_iso_context.header_size > 8.
Stefan Richter77258da2009-01-07 20:14:53 +0100240 *
Stefan Richter872e3302010-07-29 18:19:22 +0200241 * Format of 1394 iso packet header: 16 bits data_length, 2 bits tag, 6 bits
242 * channel, 4 bits tcode, 4 bits sy, in big endian byte order.
243 * data_length is the actual received size of the packet without the four
244 * 1394 iso packet header bytes.
245 *
246 * Format of timestamp: 16 bits invalid, 3 bits cycleSeconds, 13 bits
247 * cycleCount, in big endian byte order.
248 *
249 * In version 1 of the ABI, no timestamp quadlet was inserted; instead, payload
250 * data followed directly after the 1394 is header if header_size > 4.
Stefan Richter77258da2009-01-07 20:14:53 +0100251 * Behaviour of ver. 1 of this ABI is no longer available since ABI ver. 2.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200252 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500253struct fw_cdev_event_iso_interrupt {
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400254 __u64 closure;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500255 __u32 type;
256 __u32 cycle;
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200257 __u32 header_length;
Kristian Høgsberg9b32d5f2007-02-16 17:34:44 -0500258 __u32 header[0];
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500259};
260
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200261/**
Stefan Richter872e3302010-07-29 18:19:22 +0200262 * struct fw_cdev_event_iso_interrupt_mc - An iso buffer chunk was completed
263 * @closure: See &fw_cdev_event_common;
264 * set by %FW_CDEV_CREATE_ISO_CONTEXT ioctl
265 * @type: %FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL
Uwe Kleine-Königb5950762010-11-01 15:38:34 -0400266 * @completed: Offset into the receive buffer; data before this offset is valid
Stefan Richter872e3302010-07-29 18:19:22 +0200267 *
268 * This event is sent in multichannel contexts (context type
269 * %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL) for &fw_cdev_iso_packet buffer
270 * chunks that have the %FW_CDEV_ISO_INTERRUPT bit set. Whether this happens
271 * when a packet is completed and/or when a buffer chunk is completed depends
272 * on the hardware implementation.
273 *
274 * The buffer is continuously filled with the following data, per packet:
275 * - the 1394 iso packet header as described at &fw_cdev_event_iso_interrupt,
276 * but in little endian byte order,
277 * - packet payload (as many bytes as specified in the data_length field of
278 * the 1394 iso packet header) in big endian byte order,
279 * - 0...3 padding bytes as needed to align the following trailer quadlet,
280 * - trailer quadlet, containing the reception timestamp as described at
281 * &fw_cdev_event_iso_interrupt, but in little endian byte order.
282 *
283 * Hence the per-packet size is data_length (rounded up to a multiple of 4) + 8.
284 * When processing the data, stop before a packet that would cross the
285 * @completed offset.
286 *
287 * A packet near the end of a buffer chunk will typically spill over into the
288 * next queued buffer chunk. It is the responsibility of the client to check
289 * for this condition, assemble a broken-up packet from its parts, and not to
290 * re-queue any buffer chunks in which as yet unread packet parts reside.
291 */
292struct fw_cdev_event_iso_interrupt_mc {
293 __u64 closure;
294 __u32 type;
295 __u32 completed;
296};
297
298/**
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100299 * struct fw_cdev_event_iso_resource - Iso resources were allocated or freed
300 * @closure: See &fw_cdev_event_common;
Stefan Richter1ec3c022009-01-04 16:23:29 +0100301 * set by %FW_CDEV_IOC_(DE)ALLOCATE_ISO_RESOURCE(_ONCE) ioctl
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100302 * @type: %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or
303 * %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED
304 * @handle: Reference by which an allocated resource can be deallocated
305 * @channel: Isochronous channel which was (de)allocated, if any
306 * @bandwidth: Bandwidth allocation units which were (de)allocated, if any
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100307 *
308 * An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event is sent after an isochronous
309 * resource was allocated at the IRM. The client has to check @channel and
310 * @bandwidth for whether the allocation actually succeeded.
311 *
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100312 * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event is sent after an isochronous
313 * resource was deallocated at the IRM. It is also sent when automatic
314 * reallocation after a bus reset failed.
Stefan Richter1ec3c022009-01-04 16:23:29 +0100315 *
316 * @channel is <0 if no channel was (de)allocated or if reallocation failed.
317 * @bandwidth is 0 if no bandwidth was (de)allocated or if reallocation failed.
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100318 */
319struct fw_cdev_event_iso_resource {
320 __u64 closure;
321 __u32 type;
322 __u32 handle;
323 __s32 channel;
324 __s32 bandwidth;
325};
326
327/**
Stefan Richterbf54e142010-07-16 22:25:51 +0200328 * struct fw_cdev_event_phy_packet - A PHY packet was transmitted or received
329 * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_SEND_PHY_PACKET
330 * or %FW_CDEV_IOC_RECEIVE_PHY_PACKETS ioctl
331 * @type: %FW_CDEV_EVENT_PHY_PACKET_SENT or %..._RECEIVED
Stefan Richter850bb6f2010-07-16 22:25:14 +0200332 * @rcode: %RCODE_..., indicates success or failure of transmission
Stefan Richterbf54e142010-07-16 22:25:51 +0200333 * @length: Data length in bytes
334 * @data: Incoming data
335 *
Stefan Richtercc550212010-07-18 13:00:50 +0200336 * If @type is %FW_CDEV_EVENT_PHY_PACKET_SENT, @length is 0 and @data empty,
337 * except in case of a ping packet: Then, @length is 4, and @data[0] is the
338 * ping time in 49.152MHz clocks if @rcode is %RCODE_COMPLETE.
339 *
Stefan Richterbf54e142010-07-16 22:25:51 +0200340 * If @type is %FW_CDEV_EVENT_PHY_PACKET_RECEIVED, @length is 8 and @data
341 * consists of the two PHY packet quadlets, in host byte order.
Stefan Richter850bb6f2010-07-16 22:25:14 +0200342 */
343struct fw_cdev_event_phy_packet {
344 __u64 closure;
345 __u32 type;
346 __u32 rcode;
Stefan Richterbf54e142010-07-16 22:25:51 +0200347 __u32 length;
348 __u32 data[0];
Stefan Richter850bb6f2010-07-16 22:25:14 +0200349};
350
351/**
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200352 * union fw_cdev_event - Convenience union of fw_cdev_event_ types
Stefan Richter872e3302010-07-29 18:19:22 +0200353 * @common: Valid for all types
354 * @bus_reset: Valid if @common.type == %FW_CDEV_EVENT_BUS_RESET
355 * @response: Valid if @common.type == %FW_CDEV_EVENT_RESPONSE
356 * @request: Valid if @common.type == %FW_CDEV_EVENT_REQUEST
357 * @request2: Valid if @common.type == %FW_CDEV_EVENT_REQUEST2
358 * @iso_interrupt: Valid if @common.type == %FW_CDEV_EVENT_ISO_INTERRUPT
359 * @iso_interrupt_mc: Valid if @common.type ==
360 * %FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL
361 * @iso_resource: Valid if @common.type ==
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100362 * %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or
363 * %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED
Stefan Richter872e3302010-07-29 18:19:22 +0200364 * @phy_packet: Valid if @common.type ==
Stefan Richterbf54e142010-07-16 22:25:51 +0200365 * %FW_CDEV_EVENT_PHY_PACKET_SENT or
366 * %FW_CDEV_EVENT_PHY_PACKET_RECEIVED
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200367 *
Jay Fenlasonbe585c02008-10-01 18:13:20 -0400368 * Convenience union for userspace use. Events could be read(2) into an
369 * appropriately aligned char buffer and then cast to this union for further
370 * processing. Note that for a request, response or iso_interrupt event,
371 * the data[] or header[] may make the size of the full event larger than
372 * sizeof(union fw_cdev_event). Also note that if you attempt to read(2)
373 * an event into a buffer that is not large enough for it, the data that does
374 * not fit will be discarded so that the next read(2) will return a new event.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200375 */
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400376union fw_cdev_event {
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100377 struct fw_cdev_event_common common;
378 struct fw_cdev_event_bus_reset bus_reset;
379 struct fw_cdev_event_response response;
380 struct fw_cdev_event_request request;
Stefan Richter872e3302010-07-29 18:19:22 +0200381 struct fw_cdev_event_request2 request2; /* added in 2.6.36 */
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100382 struct fw_cdev_event_iso_interrupt iso_interrupt;
Stefan Richter872e3302010-07-29 18:19:22 +0200383 struct fw_cdev_event_iso_interrupt_mc iso_interrupt_mc; /* added in 2.6.36 */
384 struct fw_cdev_event_iso_resource iso_resource; /* added in 2.6.30 */
385 struct fw_cdev_event_phy_packet phy_packet; /* added in 2.6.36 */
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400386};
387
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100388/* available since kernel version 2.6.22 */
Stefan Richterc8a25902009-03-10 20:59:16 +0100389#define FW_CDEV_IOC_GET_INFO _IOWR('#', 0x00, struct fw_cdev_get_info)
390#define FW_CDEV_IOC_SEND_REQUEST _IOW('#', 0x01, struct fw_cdev_send_request)
391#define FW_CDEV_IOC_ALLOCATE _IOWR('#', 0x02, struct fw_cdev_allocate)
392#define FW_CDEV_IOC_DEALLOCATE _IOW('#', 0x03, struct fw_cdev_deallocate)
393#define FW_CDEV_IOC_SEND_RESPONSE _IOW('#', 0x04, struct fw_cdev_send_response)
394#define FW_CDEV_IOC_INITIATE_BUS_RESET _IOW('#', 0x05, struct fw_cdev_initiate_bus_reset)
395#define FW_CDEV_IOC_ADD_DESCRIPTOR _IOWR('#', 0x06, struct fw_cdev_add_descriptor)
396#define FW_CDEV_IOC_REMOVE_DESCRIPTOR _IOW('#', 0x07, struct fw_cdev_remove_descriptor)
397#define FW_CDEV_IOC_CREATE_ISO_CONTEXT _IOWR('#', 0x08, struct fw_cdev_create_iso_context)
398#define FW_CDEV_IOC_QUEUE_ISO _IOWR('#', 0x09, struct fw_cdev_queue_iso)
399#define FW_CDEV_IOC_START_ISO _IOW('#', 0x0a, struct fw_cdev_start_iso)
400#define FW_CDEV_IOC_STOP_ISO _IOW('#', 0x0b, struct fw_cdev_stop_iso)
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100401
402/* available since kernel version 2.6.24 */
Stefan Richterc8a25902009-03-10 20:59:16 +0100403#define FW_CDEV_IOC_GET_CYCLE_TIMER _IOR('#', 0x0c, struct fw_cdev_get_cycle_timer)
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500404
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100405/* available since kernel version 2.6.30 */
Stefan Richter1ec3c022009-01-04 16:23:29 +0100406#define FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE _IOWR('#', 0x0d, struct fw_cdev_allocate_iso_resource)
407#define FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE _IOW('#', 0x0e, struct fw_cdev_deallocate)
408#define FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE _IOW('#', 0x0f, struct fw_cdev_allocate_iso_resource)
409#define FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE _IOW('#', 0x10, struct fw_cdev_allocate_iso_resource)
Stefan Richterc8a25902009-03-10 20:59:16 +0100410#define FW_CDEV_IOC_GET_SPEED _IO('#', 0x11) /* returns speed code */
Jay Fenlason, Stefan Richteracfe8332009-01-04 16:23:29 +0100411#define FW_CDEV_IOC_SEND_BROADCAST_REQUEST _IOW('#', 0x12, struct fw_cdev_send_request)
Jay Fenlasonf8c22872009-03-05 19:08:40 +0100412#define FW_CDEV_IOC_SEND_STREAM_PACKET _IOW('#', 0x13, struct fw_cdev_send_stream_packet)
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100413
Stefan Richterabfe5a02010-02-20 12:13:49 +0100414/* available since kernel version 2.6.34 */
415#define FW_CDEV_IOC_GET_CYCLE_TIMER2 _IOWR('#', 0x14, struct fw_cdev_get_cycle_timer2)
416
Stefan Richter850bb6f2010-07-16 22:25:14 +0200417/* available since kernel version 2.6.36 */
418#define FW_CDEV_IOC_SEND_PHY_PACKET _IOWR('#', 0x15, struct fw_cdev_send_phy_packet)
Stefan Richterbf54e142010-07-16 22:25:51 +0200419#define FW_CDEV_IOC_RECEIVE_PHY_PACKETS _IOW('#', 0x16, struct fw_cdev_receive_phy_packets)
Stefan Richter872e3302010-07-29 18:19:22 +0200420#define FW_CDEV_IOC_SET_ISO_CHANNELS _IOW('#', 0x17, struct fw_cdev_set_iso_channels)
Stefan Richter850bb6f2010-07-16 22:25:14 +0200421
Stefan Richter77258da2009-01-07 20:14:53 +0100422/*
Stefan Richter604f4512010-06-20 22:52:55 +0200423 * ABI version history
Stefan Richter77258da2009-01-07 20:14:53 +0100424 * 1 (2.6.22) - initial version
Stefan Richter604f4512010-06-20 22:52:55 +0200425 * (2.6.24) - added %FW_CDEV_IOC_GET_CYCLE_TIMER
Stefan Richter77258da2009-01-07 20:14:53 +0100426 * 2 (2.6.30) - changed &fw_cdev_event_iso_interrupt.header if
427 * &fw_cdev_create_iso_context.header_size is 8 or more
Stefan Richter604f4512010-06-20 22:52:55 +0200428 * - added %FW_CDEV_IOC_*_ISO_RESOURCE*,
429 * %FW_CDEV_IOC_GET_SPEED, %FW_CDEV_IOC_SEND_BROADCAST_REQUEST,
430 * %FW_CDEV_IOC_SEND_STREAM_PACKET
Stefan Richtere94b6d72010-02-21 12:48:57 +0100431 * (2.6.32) - added time stamp to xmit &fw_cdev_event_iso_interrupt
432 * (2.6.33) - IR has always packet-per-buffer semantics now, not one of
433 * dual-buffer or packet-per-buffer depending on hardware
Stefan Richtere2055972010-06-20 22:53:55 +0200434 * - shared use and auto-response for FCP registers
Stefan Richtere94b6d72010-02-21 12:48:57 +0100435 * 3 (2.6.34) - made &fw_cdev_get_cycle_timer reliable
Stefan Richter604f4512010-06-20 22:52:55 +0200436 * - added %FW_CDEV_IOC_GET_CYCLE_TIMER2
Stefan Richter872e3302010-07-29 18:19:22 +0200437 * 4 (2.6.36) - added %FW_CDEV_EVENT_REQUEST2, %FW_CDEV_EVENT_PHY_PACKET_*,
438 * and &fw_cdev_allocate.region_end
Stefan Richter250b2b62010-06-21 23:24:35 +0200439 * - implemented &fw_cdev_event_bus_reset.bm_node_id
Stefan Richterbf54e142010-07-16 22:25:51 +0200440 * - added %FW_CDEV_IOC_SEND_PHY_PACKET, _RECEIVE_PHY_PACKETS
Stefan Richter872e3302010-07-29 18:19:22 +0200441 * - added %FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL,
442 * %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL, and
443 * %FW_CDEV_IOC_SET_ISO_CHANNELS
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500444 */
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500445
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200446/**
447 * struct fw_cdev_get_info - General purpose information ioctl
Stefan Richter604f4512010-06-20 22:52:55 +0200448 * @version: The version field is just a running serial number. Both an
449 * input parameter (ABI version implemented by the client) and
450 * output parameter (ABI version implemented by the kernel).
Stefan Richterf6a7cd02011-07-14 21:08:39 +0200451 * A client shall fill in the ABI @version for which the client
452 * was implemented. This is necessary for forward compatibility.
453 * @rom_length: If @rom is non-zero, up to @rom_length bytes of Configuration
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200454 * ROM will be copied into that user space address. In either
455 * case, @rom_length is updated with the actual length of the
Stefan Richterf6a7cd02011-07-14 21:08:39 +0200456 * Configuration ROM.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200457 * @rom: If non-zero, address of a buffer to be filled by a copy of the
Stefan Richterf6a7cd02011-07-14 21:08:39 +0200458 * device's Configuration ROM
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200459 * @bus_reset: If non-zero, address of a buffer to be filled by a
460 * &struct fw_cdev_event_bus_reset with the current state
461 * of the bus. This does not cause a bus reset to happen.
462 * @bus_reset_closure: Value of &closure in this and subsequent bus reset events
463 * @card: The index of the card this device belongs to
Stefan Richter93b37902011-07-09 16:43:22 +0200464 *
Stefan Richterf6a7cd02011-07-14 21:08:39 +0200465 * The %FW_CDEV_IOC_GET_INFO ioctl is usually the very first one which a client
466 * performs right after it opened a /dev/fw* file.
467 *
Stefan Richter93b37902011-07-09 16:43:22 +0200468 * As a side effect, reception of %FW_CDEV_EVENT_BUS_RESET events to be read(2)
469 * is started by this ioctl.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200470 */
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500471struct fw_cdev_get_info {
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500472 __u32 version;
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500473 __u32 rom_length;
474 __u64 rom;
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500475 __u64 bus_reset;
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400476 __u64 bus_reset_closure;
Kristian Høgsberge7533502007-03-07 12:12:52 -0500477 __u32 card;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500478};
479
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200480/**
481 * struct fw_cdev_send_request - Send an asynchronous request packet
482 * @tcode: Transaction code of the request
483 * @length: Length of outgoing payload, in bytes
484 * @offset: 48-bit offset at destination node
485 * @closure: Passed back to userspace in the response event
486 * @data: Userspace pointer to payload
487 * @generation: The bus generation where packet is valid
488 *
489 * Send a request to the device. This ioctl implements all outgoing requests.
490 * Both quadlet and block request specify the payload as a pointer to the data
491 * in the @data field. Once the transaction completes, the kernel writes an
Stefan Richterbf8e3352008-12-05 22:43:41 +0100492 * &fw_cdev_event_response event back. The @closure field is passed back to
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200493 * user space in the response event.
494 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500495struct fw_cdev_send_request {
496 __u32 tcode;
497 __u32 length;
498 __u64 offset;
499 __u64 closure;
500 __u64 data;
Kristian Høgsberg97e35272007-03-07 12:12:53 -0500501 __u32 generation;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500502};
503
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200504/**
505 * struct fw_cdev_send_response - Send an asynchronous response packet
506 * @rcode: Response code as determined by the userspace handler
507 * @length: Length of outgoing payload, in bytes
508 * @data: Userspace pointer to payload
509 * @handle: The handle from the &fw_cdev_event_request
510 *
511 * Send a response to an incoming request. By setting up an address range using
512 * the %FW_CDEV_IOC_ALLOCATE ioctl, userspace can listen for incoming requests. An
513 * incoming request will generate an %FW_CDEV_EVENT_REQUEST, and userspace must
514 * send a reply using this ioctl. The event has a handle to the kernel-side
515 * pending transaction, which should be used with this ioctl.
516 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500517struct fw_cdev_send_response {
518 __u32 rcode;
519 __u32 length;
520 __u64 data;
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400521 __u32 handle;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500522};
523
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200524/**
Stefan Richter8e2b2b42010-07-23 13:05:39 +0200525 * struct fw_cdev_allocate - Allocate a CSR in an address range
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200526 * @offset: Start offset of the address range
527 * @closure: To be passed back to userspace in request events
Stefan Richter8e2b2b42010-07-23 13:05:39 +0200528 * @length: Length of the CSR, in bytes
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200529 * @handle: Handle to the allocation, written by the kernel
Stefan Richter8e2b2b42010-07-23 13:05:39 +0200530 * @region_end: First address above the address range (added in ABI v4, 2.6.36)
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200531 *
532 * Allocate an address range in the 48-bit address space on the local node
533 * (the controller). This allows userspace to listen for requests with an
Stefan Richter8e2b2b42010-07-23 13:05:39 +0200534 * offset within that address range. Every time when the kernel receives a
535 * request within the range, an &fw_cdev_event_request2 event will be emitted.
536 * (If the kernel or the client implements ABI version <= 3, an
537 * &fw_cdev_event_request will be generated instead.)
538 *
539 * The @closure field is passed back to userspace in these request events.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200540 * The @handle field is an out parameter, returning a handle to the allocated
541 * range to be used for later deallocation of the range.
Clemens Ladischdb5d2472009-12-24 12:05:58 +0100542 *
543 * The address range is allocated on all local nodes. The address allocation
Stefan Richterd505e6e2010-07-17 21:36:02 +0200544 * is exclusive except for the FCP command and response registers. If an
545 * exclusive address region is already in use, the ioctl fails with errno set
546 * to %EBUSY.
Stefan Richter8e2b2b42010-07-23 13:05:39 +0200547 *
548 * If kernel and client implement ABI version >= 4, the kernel looks up a free
549 * spot of size @length inside [@offset..@region_end) and, if found, writes
550 * the start address of the new CSR back in @offset. I.e. @offset is an
551 * in and out parameter. If this automatic placement of a CSR in a bigger
552 * address range is not desired, the client simply needs to set @region_end
553 * = @offset + @length.
554 *
555 * If the kernel or the client implements ABI version <= 3, @region_end is
556 * ignored and effectively assumed to be @offset + @length.
557 *
558 * @region_end is only present in a kernel header >= 2.6.36. If necessary,
559 * this can for example be tested by #ifdef FW_CDEV_EVENT_REQUEST2.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200560 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500561struct fw_cdev_allocate {
562 __u64 offset;
563 __u64 closure;
564 __u32 length;
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400565 __u32 handle;
Stefan Richter8e2b2b42010-07-23 13:05:39 +0200566 __u64 region_end; /* available since kernel version 2.6.36 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500567};
568
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200569/**
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100570 * struct fw_cdev_deallocate - Free a CSR address range or isochronous resource
571 * @handle: Handle to the address range or iso resource, as returned by the
572 * kernel when the range or resource was allocated
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200573 */
Kristian Høgsberg94723162007-03-14 17:34:55 -0400574struct fw_cdev_deallocate {
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400575 __u32 handle;
Kristian Høgsberg94723162007-03-14 17:34:55 -0400576};
577
Kristian Høgsberg53718422007-03-07 12:12:42 -0500578#define FW_CDEV_LONG_RESET 0
579#define FW_CDEV_SHORT_RESET 1
580
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200581/**
582 * struct fw_cdev_initiate_bus_reset - Initiate a bus reset
583 * @type: %FW_CDEV_SHORT_RESET or %FW_CDEV_LONG_RESET
584 *
585 * Initiate a bus reset for the bus this device is on. The bus reset can be
586 * either the original (long) bus reset or the arbitrated (short) bus reset
587 * introduced in 1394a-2000.
Stefan Richterd505e6e2010-07-17 21:36:02 +0200588 *
589 * The ioctl returns immediately. A subsequent &fw_cdev_event_bus_reset
590 * indicates when the reset actually happened. Since ABI v4, this may be
591 * considerably later than the ioctl because the kernel ensures a grace period
592 * between subsequent bus resets as per IEEE 1394 bus management specification.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200593 */
Kristian Høgsberg53718422007-03-07 12:12:42 -0500594struct fw_cdev_initiate_bus_reset {
Stefan Richterd505e6e2010-07-17 21:36:02 +0200595 __u32 type;
Kristian Høgsberg53718422007-03-07 12:12:42 -0500596};
597
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200598/**
599 * struct fw_cdev_add_descriptor - Add contents to the local node's config ROM
600 * @immediate: If non-zero, immediate key to insert before pointer
601 * @key: Upper 8 bits of root directory pointer
602 * @data: Userspace pointer to contents of descriptor block
Stefan Richter6d3faf62010-01-24 14:48:00 +0100603 * @length: Length of descriptor block data, in quadlets
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200604 * @handle: Handle to the descriptor, written by the kernel
605 *
606 * Add a descriptor block and optionally a preceding immediate key to the local
Stefan Richterf6a7cd02011-07-14 21:08:39 +0200607 * node's Configuration ROM.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200608 *
609 * The @key field specifies the upper 8 bits of the descriptor root directory
610 * pointer and the @data and @length fields specify the contents. The @key
611 * should be of the form 0xXX000000. The offset part of the root directory entry
612 * will be filled in by the kernel.
613 *
614 * If not 0, the @immediate field specifies an immediate key which will be
615 * inserted before the root directory pointer.
616 *
Stefan Richter6d3faf62010-01-24 14:48:00 +0100617 * @immediate, @key, and @data array elements are CPU-endian quadlets.
618 *
Stefan Richterd505e6e2010-07-17 21:36:02 +0200619 * If successful, the kernel adds the descriptor and writes back a @handle to
620 * the kernel-side object to be used for later removal of the descriptor block
621 * and immediate key. The kernel will also generate a bus reset to signal the
Stefan Richterf6a7cd02011-07-14 21:08:39 +0200622 * change of the Configuration ROM to other nodes.
Stefan Richterde487da2009-03-10 21:00:23 +0100623 *
Stefan Richterf6a7cd02011-07-14 21:08:39 +0200624 * This ioctl affects the Configuration ROMs of all local nodes.
Stefan Richterde487da2009-03-10 21:00:23 +0100625 * The ioctl only succeeds on device files which represent a local node.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200626 */
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200627struct fw_cdev_add_descriptor {
628 __u32 immediate;
629 __u32 key;
630 __u64 data;
631 __u32 length;
632 __u32 handle;
633};
634
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200635/**
Stefan Richterf6a7cd02011-07-14 21:08:39 +0200636 * struct fw_cdev_remove_descriptor - Remove contents from the Configuration ROM
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200637 * @handle: Handle to the descriptor, as returned by the kernel when the
638 * descriptor was added
639 *
640 * Remove a descriptor block and accompanying immediate key from the local
Stefan Richterf6a7cd02011-07-14 21:08:39 +0200641 * nodes' Configuration ROMs. The kernel will also generate a bus reset to
642 * signal the change of the Configuration ROM to other nodes.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200643 */
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200644struct fw_cdev_remove_descriptor {
645 __u32 handle;
646};
647
Stefan Richter872e3302010-07-29 18:19:22 +0200648#define FW_CDEV_ISO_CONTEXT_TRANSMIT 0
649#define FW_CDEV_ISO_CONTEXT_RECEIVE 1
650#define FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL 2 /* added in 2.6.36 */
Kristian Høgsberg295e3fe2007-02-16 17:34:40 -0500651
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200652/**
Stefan Richter872e3302010-07-29 18:19:22 +0200653 * struct fw_cdev_create_iso_context - Create a context for isochronous I/O
654 * @type: %FW_CDEV_ISO_CONTEXT_TRANSMIT or %FW_CDEV_ISO_CONTEXT_RECEIVE or
655 * %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL
656 * @header_size: Header size to strip in single-channel reception
657 * @channel: Channel to bind to in single-channel reception or transmission
658 * @speed: Transmission speed
659 * @closure: To be returned in &fw_cdev_event_iso_interrupt or
660 * &fw_cdev_event_iso_interrupt_multichannel
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200661 * @handle: Handle to context, written back by kernel
662 *
663 * Prior to sending or receiving isochronous I/O, a context must be created.
664 * The context records information about the transmit or receive configuration
665 * and typically maps to an underlying hardware resource. A context is set up
666 * for either sending or receiving. It is bound to a specific isochronous
Stefan Richter872e3302010-07-29 18:19:22 +0200667 * @channel.
668 *
669 * In case of multichannel reception, @header_size and @channel are ignored
670 * and the channels are selected by %FW_CDEV_IOC_SET_ISO_CHANNELS.
671 *
672 * For %FW_CDEV_ISO_CONTEXT_RECEIVE contexts, @header_size must be at least 4
673 * and must be a multiple of 4. It is ignored in other context types.
674 *
675 * @speed is ignored in receive context types.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200676 *
677 * If a context was successfully created, the kernel writes back a handle to the
678 * context, which must be passed in for subsequent operations on that context.
Stefan Richter77258da2009-01-07 20:14:53 +0100679 *
Stefan Richter872e3302010-07-29 18:19:22 +0200680 * Limitations:
Stefan Richterd505e6e2010-07-17 21:36:02 +0200681 * No more than one iso context can be created per fd.
Stefan Richter872e3302010-07-29 18:19:22 +0200682 * The total number of contexts that all userspace and kernelspace drivers can
683 * create on a card at a time is a hardware limit, typically 4 or 8 contexts per
684 * direction, and of them at most one multichannel receive context.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200685 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500686struct fw_cdev_create_iso_context {
Kristian Høgsberg295e3fe2007-02-16 17:34:40 -0500687 __u32 type;
688 __u32 header_size;
Kristian Høgsberg21efb3c2007-02-16 17:34:50 -0500689 __u32 channel;
690 __u32 speed;
Kristian Høgsbergabaa5742007-04-30 15:03:14 -0400691 __u64 closure;
692 __u32 handle;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500693};
694
Stefan Richter872e3302010-07-29 18:19:22 +0200695/**
696 * struct fw_cdev_set_iso_channels - Select channels in multichannel reception
697 * @channels: Bitmask of channels to listen to
698 * @handle: Handle of the mutichannel receive context
699 *
700 * @channels is the bitwise or of 1ULL << n for each channel n to listen to.
701 *
702 * The ioctl fails with errno %EBUSY if there is already another receive context
703 * on a channel in @channels. In that case, the bitmask of all unoccupied
704 * channels is returned in @channels.
705 */
706struct fw_cdev_set_iso_channels {
707 __u64 channels;
708 __u32 handle;
709};
710
Kristian Høgsberg1ca31ae2007-05-31 11:16:43 -0400711#define FW_CDEV_ISO_PAYLOAD_LENGTH(v) (v)
712#define FW_CDEV_ISO_INTERRUPT (1 << 16)
713#define FW_CDEV_ISO_SKIP (1 << 17)
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200714#define FW_CDEV_ISO_SYNC (1 << 17)
Kristian Høgsberg1ca31ae2007-05-31 11:16:43 -0400715#define FW_CDEV_ISO_TAG(v) ((v) << 18)
716#define FW_CDEV_ISO_SY(v) ((v) << 20)
717#define FW_CDEV_ISO_HEADER_LENGTH(v) ((v) << 24)
718
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200719/**
720 * struct fw_cdev_iso_packet - Isochronous packet
Stefan Richter872e3302010-07-29 18:19:22 +0200721 * @control: Contains the header length (8 uppermost bits),
722 * the sy field (4 bits), the tag field (2 bits), a sync flag
723 * or a skip flag (1 bit), an interrupt flag (1 bit), and the
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200724 * payload length (16 lowermost bits)
Stefan Richter872e3302010-07-29 18:19:22 +0200725 * @header: Header and payload in case of a transmit context.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200726 *
727 * &struct fw_cdev_iso_packet is used to describe isochronous packet queues.
Clemens Ladischaa6fec32010-03-31 16:26:52 +0200728 * Use the FW_CDEV_ISO_ macros to fill in @control.
Stefan Richter872e3302010-07-29 18:19:22 +0200729 * The @header array is empty in case of receive contexts.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200730 *
Stefan Richter872e3302010-07-29 18:19:22 +0200731 * Context type %FW_CDEV_ISO_CONTEXT_TRANSMIT:
Clemens Ladischaa6fec32010-03-31 16:26:52 +0200732 *
Stefan Richter872e3302010-07-29 18:19:22 +0200733 * @control.HEADER_LENGTH must be a multiple of 4. It specifies the numbers of
734 * bytes in @header that will be prepended to the packet's payload. These bytes
735 * are copied into the kernel and will not be accessed after the ioctl has
736 * returned.
Clemens Ladischaa6fec32010-03-31 16:26:52 +0200737 *
Stefan Richter872e3302010-07-29 18:19:22 +0200738 * The @control.SY and TAG fields are copied to the iso packet header. These
739 * fields are specified by IEEE 1394a and IEC 61883-1.
740 *
741 * The @control.SKIP flag specifies that no packet is to be sent in a frame.
742 * When using this, all other fields except @control.INTERRUPT must be zero.
743 *
744 * When a packet with the @control.INTERRUPT flag set has been completed, an
745 * &fw_cdev_event_iso_interrupt event will be sent.
746 *
747 * Context type %FW_CDEV_ISO_CONTEXT_RECEIVE:
748 *
749 * @control.HEADER_LENGTH must be a multiple of the context's header_size.
750 * If the HEADER_LENGTH is larger than the context's header_size, multiple
751 * packets are queued for this entry.
752 *
753 * The @control.SY and TAG fields are ignored.
754 *
755 * If the @control.SYNC flag is set, the context drops all packets until a
756 * packet with a sy field is received which matches &fw_cdev_start_iso.sync.
757 *
758 * @control.PAYLOAD_LENGTH defines how many payload bytes can be received for
759 * one packet (in addition to payload quadlets that have been defined as headers
760 * and are stripped and returned in the &fw_cdev_event_iso_interrupt structure).
761 * If more bytes are received, the additional bytes are dropped. If less bytes
762 * are received, the remaining bytes in this part of the payload buffer will not
763 * be written to, not even by the next packet. I.e., packets received in
764 * consecutive frames will not necessarily be consecutive in memory. If an
765 * entry has queued multiple packets, the PAYLOAD_LENGTH is divided equally
766 * among them.
767 *
768 * When a packet with the @control.INTERRUPT flag set has been completed, an
Clemens Ladischaa6fec32010-03-31 16:26:52 +0200769 * &fw_cdev_event_iso_interrupt event will be sent. An entry that has queued
770 * multiple receive packets is completed when its last packet is completed.
Stefan Richter872e3302010-07-29 18:19:22 +0200771 *
772 * Context type %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL:
773 *
774 * Here, &fw_cdev_iso_packet would be more aptly named _iso_buffer_chunk since
775 * it specifies a chunk of the mmap()'ed buffer, while the number and alignment
776 * of packets to be placed into the buffer chunk is not known beforehand.
777 *
778 * @control.PAYLOAD_LENGTH is the size of the buffer chunk and specifies room
779 * for header, payload, padding, and trailer bytes of one or more packets.
780 * It must be a multiple of 4.
781 *
782 * @control.HEADER_LENGTH, TAG and SY are ignored. SYNC is treated as described
783 * for single-channel reception.
784 *
785 * When a buffer chunk with the @control.INTERRUPT flag set has been filled
786 * entirely, an &fw_cdev_event_iso_interrupt_mc event will be sent.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200787 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500788struct fw_cdev_iso_packet {
Kristian Høgsberg1ca31ae2007-05-31 11:16:43 -0400789 __u32 control;
Stefan Richter5e20c282007-01-21 20:44:09 +0100790 __u32 header[0];
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500791};
792
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200793/**
794 * struct fw_cdev_queue_iso - Queue isochronous packets for I/O
Stefan Richter872e3302010-07-29 18:19:22 +0200795 * @packets: Userspace pointer to an array of &fw_cdev_iso_packet
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200796 * @data: Pointer into mmap()'ed payload buffer
Stefan Richter872e3302010-07-29 18:19:22 +0200797 * @size: Size of the @packets array, in bytes
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200798 * @handle: Isochronous context handle
799 *
800 * Queue a number of isochronous packets for reception or transmission.
801 * This ioctl takes a pointer to an array of &fw_cdev_iso_packet structs,
802 * which describe how to transmit from or receive into a contiguous region
Clemens Ladischaa6fec32010-03-31 16:26:52 +0200803 * of a mmap()'ed payload buffer. As part of transmit packet descriptors,
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200804 * a series of headers can be supplied, which will be prepended to the
805 * payload during DMA.
806 *
807 * The kernel may or may not queue all packets, but will write back updated
808 * values of the @packets, @data and @size fields, so the ioctl can be
809 * resubmitted easily.
Stefan Richter872e3302010-07-29 18:19:22 +0200810 *
811 * In case of a multichannel receive context, @data must be quadlet-aligned
812 * relative to the buffer start.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200813 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500814struct fw_cdev_queue_iso {
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500815 __u64 packets;
816 __u64 data;
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400817 __u32 size;
Kristian Høgsbergabaa5742007-04-30 15:03:14 -0400818 __u32 handle;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500819};
820
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200821#define FW_CDEV_ISO_CONTEXT_MATCH_TAG0 1
822#define FW_CDEV_ISO_CONTEXT_MATCH_TAG1 2
823#define FW_CDEV_ISO_CONTEXT_MATCH_TAG2 4
824#define FW_CDEV_ISO_CONTEXT_MATCH_TAG3 8
825#define FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS 15
826
827/**
828 * struct fw_cdev_start_iso - Start an isochronous transmission or reception
829 * @cycle: Cycle in which to start I/O. If @cycle is greater than or
830 * equal to 0, the I/O will start on that cycle.
831 * @sync: Determines the value to wait for for receive packets that have
832 * the %FW_CDEV_ISO_SYNC bit set
833 * @tags: Tag filter bit mask. Only valid for isochronous reception.
834 * Determines the tag values for which packets will be accepted.
835 * Use FW_CDEV_ISO_CONTEXT_MATCH_ macros to set @tags.
836 * @handle: Isochronous context handle within which to transmit or receive
837 */
Kristian Høgsberg69cdb722007-02-16 17:34:41 -0500838struct fw_cdev_start_iso {
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500839 __s32 cycle;
Kristian Høgsbergeb0306e2007-03-14 17:34:54 -0400840 __u32 sync;
841 __u32 tags;
Kristian Høgsbergabaa5742007-04-30 15:03:14 -0400842 __u32 handle;
843};
844
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200845/**
846 * struct fw_cdev_stop_iso - Stop an isochronous transmission or reception
847 * @handle: Handle of isochronous context to stop
848 */
Kristian Høgsbergabaa5742007-04-30 15:03:14 -0400849struct fw_cdev_stop_iso {
850 __u32 handle;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500851};
852
Stefan Richtera64408b2007-09-29 10:41:58 +0200853/**
854 * struct fw_cdev_get_cycle_timer - read cycle timer register
855 * @local_time: system time, in microseconds since the Epoch
Stefan Richterabfe5a02010-02-20 12:13:49 +0100856 * @cycle_timer: Cycle Time register contents
Stefan Richtera64408b2007-09-29 10:41:58 +0200857 *
Stefan Richterf6a7cd02011-07-14 21:08:39 +0200858 * Same as %FW_CDEV_IOC_GET_CYCLE_TIMER2, but fixed to use %CLOCK_REALTIME
859 * and only with microseconds resolution.
Stefan Richtere94b6d72010-02-21 12:48:57 +0100860 *
861 * In version 1 and 2 of the ABI, this ioctl returned unreliable (non-
862 * monotonic) @cycle_timer values on certain controllers.
Stefan Richtera64408b2007-09-29 10:41:58 +0200863 */
864struct fw_cdev_get_cycle_timer {
865 __u64 local_time;
866 __u32 cycle_timer;
867};
868
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100869/**
Stefan Richterabfe5a02010-02-20 12:13:49 +0100870 * struct fw_cdev_get_cycle_timer2 - read cycle timer register
871 * @tv_sec: system time, seconds
872 * @tv_nsec: system time, sub-seconds part in nanoseconds
873 * @clk_id: input parameter, clock from which to get the system time
874 * @cycle_timer: Cycle Time register contents
875 *
Stefan Richterf6a7cd02011-07-14 21:08:39 +0200876 * The %FW_CDEV_IOC_GET_CYCLE_TIMER2 ioctl reads the isochronous cycle timer
877 * and also the system clock. This allows to correlate reception time of
878 * isochronous packets with system time.
879 *
880 * @clk_id lets you choose a clock like with POSIX' clock_gettime function.
881 * Supported @clk_id values are POSIX' %CLOCK_REALTIME and %CLOCK_MONOTONIC
882 * and Linux' %CLOCK_MONOTONIC_RAW.
883 *
884 * @cycle_timer consists of 7 bits cycleSeconds, 13 bits cycleCount, and
885 * 12 bits cycleOffset, in host byte order. Cf. the Cycle Time register
886 * per IEEE 1394 or Isochronous Cycle Timer register per OHCI-1394.
Stefan Richterabfe5a02010-02-20 12:13:49 +0100887 */
888struct fw_cdev_get_cycle_timer2 {
889 __s64 tv_sec;
890 __s32 tv_nsec;
891 __s32 clk_id;
892 __u32 cycle_timer;
893};
894
895/**
Stefan Richter1ec3c022009-01-04 16:23:29 +0100896 * struct fw_cdev_allocate_iso_resource - (De)allocate a channel or bandwidth
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300897 * @closure: Passed back to userspace in corresponding iso resource events
Stefan Richter1ec3c022009-01-04 16:23:29 +0100898 * @channels: Isochronous channels of which one is to be (de)allocated
899 * @bandwidth: Isochronous bandwidth units to be (de)allocated
900 * @handle: Handle to the allocation, written by the kernel (only valid in
901 * case of %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ioctls)
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100902 *
903 * The %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ioctl initiates allocation of an
904 * isochronous channel and/or of isochronous bandwidth at the isochronous
905 * resource manager (IRM). Only one of the channels specified in @channels is
906 * allocated. An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED is sent after
907 * communication with the IRM, indicating success or failure in the event data.
908 * The kernel will automatically reallocate the resources after bus resets.
909 * Should a reallocation fail, an %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event
910 * will be sent. The kernel will also automatically deallocate the resources
911 * when the file descriptor is closed.
912 *
Stefan Richter1ec3c022009-01-04 16:23:29 +0100913 * The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE ioctl can be used to initiate
914 * deallocation of resources which were allocated as described above.
915 * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation.
916 *
917 * The %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE ioctl is a variant of allocation
918 * without automatic re- or deallocation.
919 * An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event concludes this operation,
920 * indicating success or failure in its data.
921 *
922 * The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE ioctl works like
923 * %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE except that resources are freed
Stefan Richter5d9cb7d272009-01-08 23:07:40 +0100924 * instead of allocated.
Stefan Richter1ec3c022009-01-04 16:23:29 +0100925 * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation.
926 *
Stefan Richterca658b12010-04-10 12:23:09 +0200927 * To summarize, %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE allocates iso resources
928 * for the lifetime of the fd or @handle.
Stefan Richter1ec3c022009-01-04 16:23:29 +0100929 * In contrast, %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE allocates iso resources
930 * for the duration of a bus generation.
931 *
Stefan Richter5d9cb7d272009-01-08 23:07:40 +0100932 * @channels is a host-endian bitfield with the least significant bit
933 * representing channel 0 and the most significant bit representing channel 63:
934 * 1ULL << c for each channel c that is a candidate for (de)allocation.
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100935 *
936 * @bandwidth is expressed in bandwidth allocation units, i.e. the time to send
937 * one quadlet of data (payload or header data) at speed S1600.
938 */
939struct fw_cdev_allocate_iso_resource {
940 __u64 closure;
941 __u64 channels;
942 __u32 bandwidth;
943 __u32 handle;
944};
945
Stefan Richter33580a32009-01-04 16:23:29 +0100946/**
Jay Fenlasonf8c22872009-03-05 19:08:40 +0100947 * struct fw_cdev_send_stream_packet - send an asynchronous stream packet
Stefan Richter18e9b102009-03-10 21:02:21 +0100948 * @length: Length of outgoing payload, in bytes
949 * @tag: Data format tag
950 * @channel: Isochronous channel to transmit to
951 * @sy: Synchronization code
952 * @closure: Passed back to userspace in the response event
953 * @data: Userspace pointer to payload
954 * @generation: The bus generation where packet is valid
955 * @speed: Speed to transmit at
Jay Fenlasonf8c22872009-03-05 19:08:40 +0100956 *
957 * The %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl sends an asynchronous stream packet
Stefan Richter18e9b102009-03-10 21:02:21 +0100958 * to every device which is listening to the specified channel. The kernel
959 * writes an &fw_cdev_event_response event which indicates success or failure of
960 * the transmission.
Jay Fenlasonf8c22872009-03-05 19:08:40 +0100961 */
962struct fw_cdev_send_stream_packet {
Stefan Richter18e9b102009-03-10 21:02:21 +0100963 __u32 length;
964 __u32 tag;
Jay Fenlasonf8c22872009-03-05 19:08:40 +0100965 __u32 channel;
966 __u32 sy;
Stefan Richter18e9b102009-03-10 21:02:21 +0100967 __u64 closure;
Jay Fenlasonf8c22872009-03-05 19:08:40 +0100968 __u64 data;
Stefan Richter18e9b102009-03-10 21:02:21 +0100969 __u32 generation;
970 __u32 speed;
Jay Fenlasonf8c22872009-03-05 19:08:40 +0100971};
972
Stefan Richter850bb6f2010-07-16 22:25:14 +0200973/**
974 * struct fw_cdev_send_phy_packet - send a PHY packet
975 * @closure: Passed back to userspace in the PHY-packet-sent event
976 * @data: First and second quadlet of the PHY packet
977 * @generation: The bus generation where packet is valid
978 *
979 * The %FW_CDEV_IOC_SEND_PHY_PACKET ioctl sends a PHY packet to all nodes
980 * on the same card as this device. After transmission, an
981 * %FW_CDEV_EVENT_PHY_PACKET_SENT event is generated.
982 *
983 * The payload @data[] shall be specified in host byte order. Usually,
984 * @data[1] needs to be the bitwise inverse of @data[0]. VersaPHY packets
985 * are an exception to this rule.
986 *
987 * The ioctl is only permitted on device files which represent a local node.
988 */
989struct fw_cdev_send_phy_packet {
990 __u64 closure;
991 __u32 data[2];
992 __u32 generation;
993};
994
Stefan Richterbf54e142010-07-16 22:25:51 +0200995/**
996 * struct fw_cdev_receive_phy_packets - start reception of PHY packets
997 * @closure: Passed back to userspace in phy packet events
998 *
999 * This ioctl activates issuing of %FW_CDEV_EVENT_PHY_PACKET_RECEIVED due to
1000 * incoming PHY packets from any node on the same bus as the device.
1001 *
1002 * The ioctl is only permitted on device files which represent a local node.
1003 */
1004struct fw_cdev_receive_phy_packets {
1005 __u64 closure;
1006};
1007
Stefan Richterf6a7cd02011-07-14 21:08:39 +02001008#define FW_CDEV_VERSION 3 /* Meaningless legacy macro; don't use it. */
1009
Kristian Høgsberg4c5a4432007-05-07 20:33:37 -04001010#endif /* _LINUX_FIREWIRE_CDEV_H */