blob: 81f3b14d5d765512230e8bc95132803d06a3b3da [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
20 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * 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
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +010033#define FW_CDEV_EVENT_BUS_RESET 0x00
34#define FW_CDEV_EVENT_RESPONSE 0x01
35#define FW_CDEV_EVENT_REQUEST 0x02
36#define FW_CDEV_EVENT_ISO_INTERRUPT 0x03
37#define FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED 0x04
38#define FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED 0x05
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050039
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +020040/**
41 * struct fw_cdev_event_common - Common part of all fw_cdev_event_ types
42 * @closure: For arbitrary use by userspace
43 * @type: Discriminates the fw_cdev_event_ types
44 *
45 * This struct may be used to access generic members of all fw_cdev_event_
46 * types regardless of the specific type.
47 *
48 * Data passed in the @closure field for a request will be returned in the
49 * corresponding event. It is big enough to hold a pointer on all platforms.
50 * The ioctl used to set @closure depends on the @type of event.
51 */
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -040052struct fw_cdev_event_common {
53 __u64 closure;
54 __u32 type;
55};
56
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +020057/**
58 * struct fw_cdev_event_bus_reset - Sent when a bus reset occurred
59 * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_GET_INFO ioctl
60 * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_BUS_RESET
61 * @node_id: New node ID of this node
62 * @local_node_id: Node ID of the local node, i.e. of the controller
63 * @bm_node_id: Node ID of the bus manager
64 * @irm_node_id: Node ID of the iso resource manager
65 * @root_node_id: Node ID of the root node
66 * @generation: New bus generation
67 *
68 * This event is sent when the bus the device belongs to goes through a bus
69 * reset. It provides information about the new bus configuration, such as
70 * new node ID for this device, new root ID, and others.
71 */
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -050072struct fw_cdev_event_bus_reset {
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -040073 __u64 closure;
Kristian Høgsberg97bd9ef2007-03-07 12:12:41 -050074 __u32 type;
75 __u32 node_id;
76 __u32 local_node_id;
77 __u32 bm_node_id;
78 __u32 irm_node_id;
79 __u32 root_node_id;
80 __u32 generation;
81};
82
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +020083/**
84 * struct fw_cdev_event_response - Sent when a response packet was received
85 * @closure: See &fw_cdev_event_common;
86 * set by %FW_CDEV_IOC_SEND_REQUEST ioctl
87 * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_RESPONSE
88 * @rcode: Response code returned by the remote node
89 * @length: Data length, i.e. the response's payload size in bytes
90 * @data: Payload data, if any
91 *
92 * This event is sent when the stack receives a response to an outgoing request
93 * sent by %FW_CDEV_IOC_SEND_REQUEST ioctl. The payload data for responses
94 * carrying data (read and lock responses) follows immediately and can be
95 * accessed through the @data field.
96 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050097struct fw_cdev_event_response {
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -040098 __u64 closure;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -050099 __u32 type;
100 __u32 rcode;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500101 __u32 length;
102 __u32 data[0];
103};
104
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200105/**
106 * struct fw_cdev_event_request - Sent on incoming request to an address region
107 * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_ALLOCATE ioctl
108 * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST
109 * @tcode: Transaction code of the incoming request
110 * @offset: The offset into the 48-bit per-node address space
111 * @handle: Reference to the kernel-side pending request
112 * @length: Data length, i.e. the request's payload size in bytes
113 * @data: Incoming data, if any
114 *
115 * This event is sent when the stack receives an incoming request to an address
116 * region registered using the %FW_CDEV_IOC_ALLOCATE ioctl. The request is
117 * guaranteed to be completely contained in the specified region. Userspace is
118 * responsible for sending the response by %FW_CDEV_IOC_SEND_RESPONSE ioctl,
119 * using the same @handle.
120 *
121 * The payload data for requests carrying data (write and lock requests)
122 * follows immediately and can be accessed through the @data field.
123 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500124struct fw_cdev_event_request {
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400125 __u64 closure;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500126 __u32 type;
127 __u32 tcode;
128 __u64 offset;
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400129 __u32 handle;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500130 __u32 length;
131 __u32 data[0];
132};
133
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200134/**
135 * struct fw_cdev_event_iso_interrupt - Sent when an iso packet was completed
136 * @closure: See &fw_cdev_event_common;
137 * set by %FW_CDEV_CREATE_ISO_CONTEXT ioctl
138 * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_ISO_INTERRUPT
139 * @cycle: Cycle counter of the interrupt packet
140 * @header_length: Total length of following headers, in bytes
141 * @header: Stripped headers, if any
142 *
143 * This event is sent when the controller has completed an &fw_cdev_iso_packet
144 * with the %FW_CDEV_ISO_INTERRUPT bit set. In the receive case, the headers
145 * stripped of all packets up until and including the interrupt packet are
Stefan Richter77258da2009-01-07 20:14:53 +0100146 * returned in the @header field. The amount of header data per packet is as
147 * specified at iso context creation by &fw_cdev_create_iso_context.header_size.
148 *
149 * In version 1 of this ABI, header data consisted of the 1394 isochronous
150 * packet header, followed by quadlets from the packet payload if
151 * &fw_cdev_create_iso_context.header_size > 4.
152 *
153 * In version 2 of this ABI, header data consist of the 1394 isochronous
154 * packet header, followed by a timestamp quadlet if
155 * &fw_cdev_create_iso_context.header_size > 4, followed by quadlets from the
156 * packet payload if &fw_cdev_create_iso_context.header_size > 8.
157 *
158 * Behaviour of ver. 1 of this ABI is no longer available since ABI ver. 2.
159 *
160 * Format of 1394 iso packet header: 16 bits len, 2 bits tag, 6 bits channel,
161 * 4 bits tcode, 4 bits sy, in big endian byte order. Format of timestamp:
162 * 16 bits invalid, 3 bits cycleSeconds, 13 bits cycleCount, in big endian byte
163 * order.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200164 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500165struct fw_cdev_event_iso_interrupt {
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400166 __u64 closure;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500167 __u32 type;
168 __u32 cycle;
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200169 __u32 header_length;
Kristian Høgsberg9b32d5f2007-02-16 17:34:44 -0500170 __u32 header[0];
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500171};
172
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200173/**
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100174 * struct fw_cdev_event_iso_resource - Iso resources were allocated or freed
175 * @closure: See &fw_cdev_event_common;
Stefan Richter1ec3c022009-01-04 16:23:29 +0100176 * set by %FW_CDEV_IOC_(DE)ALLOCATE_ISO_RESOURCE(_ONCE) ioctl
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100177 * @type: %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or
178 * %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED
179 * @handle: Reference by which an allocated resource can be deallocated
180 * @channel: Isochronous channel which was (de)allocated, if any
181 * @bandwidth: Bandwidth allocation units which were (de)allocated, if any
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100182 *
183 * An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event is sent after an isochronous
184 * resource was allocated at the IRM. The client has to check @channel and
185 * @bandwidth for whether the allocation actually succeeded.
186 *
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100187 * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event is sent after an isochronous
188 * resource was deallocated at the IRM. It is also sent when automatic
189 * reallocation after a bus reset failed.
Stefan Richter1ec3c022009-01-04 16:23:29 +0100190 *
191 * @channel is <0 if no channel was (de)allocated or if reallocation failed.
192 * @bandwidth is 0 if no bandwidth was (de)allocated or if reallocation failed.
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100193 */
194struct fw_cdev_event_iso_resource {
195 __u64 closure;
196 __u32 type;
197 __u32 handle;
198 __s32 channel;
199 __s32 bandwidth;
200};
201
202/**
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200203 * union fw_cdev_event - Convenience union of fw_cdev_event_ types
204 * @common: Valid for all types
205 * @bus_reset: Valid if @common.type == %FW_CDEV_EVENT_BUS_RESET
206 * @response: Valid if @common.type == %FW_CDEV_EVENT_RESPONSE
207 * @request: Valid if @common.type == %FW_CDEV_EVENT_REQUEST
208 * @iso_interrupt: Valid if @common.type == %FW_CDEV_EVENT_ISO_INTERRUPT
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100209 * @iso_resource: Valid if @common.type ==
210 * %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or
211 * %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200212 *
Jay Fenlasonbe585c02008-10-01 18:13:20 -0400213 * Convenience union for userspace use. Events could be read(2) into an
214 * appropriately aligned char buffer and then cast to this union for further
215 * processing. Note that for a request, response or iso_interrupt event,
216 * the data[] or header[] may make the size of the full event larger than
217 * sizeof(union fw_cdev_event). Also note that if you attempt to read(2)
218 * an event into a buffer that is not large enough for it, the data that does
219 * not fit will be discarded so that the next read(2) will return a new event.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200220 */
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400221union fw_cdev_event {
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100222 struct fw_cdev_event_common common;
223 struct fw_cdev_event_bus_reset bus_reset;
224 struct fw_cdev_event_response response;
225 struct fw_cdev_event_request request;
226 struct fw_cdev_event_iso_interrupt iso_interrupt;
227 struct fw_cdev_event_iso_resource iso_resource;
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400228};
229
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100230/* available since kernel version 2.6.22 */
Stefan Richterc8a25902009-03-10 20:59:16 +0100231#define FW_CDEV_IOC_GET_INFO _IOWR('#', 0x00, struct fw_cdev_get_info)
232#define FW_CDEV_IOC_SEND_REQUEST _IOW('#', 0x01, struct fw_cdev_send_request)
233#define FW_CDEV_IOC_ALLOCATE _IOWR('#', 0x02, struct fw_cdev_allocate)
234#define FW_CDEV_IOC_DEALLOCATE _IOW('#', 0x03, struct fw_cdev_deallocate)
235#define FW_CDEV_IOC_SEND_RESPONSE _IOW('#', 0x04, struct fw_cdev_send_response)
236#define FW_CDEV_IOC_INITIATE_BUS_RESET _IOW('#', 0x05, struct fw_cdev_initiate_bus_reset)
237#define FW_CDEV_IOC_ADD_DESCRIPTOR _IOWR('#', 0x06, struct fw_cdev_add_descriptor)
238#define FW_CDEV_IOC_REMOVE_DESCRIPTOR _IOW('#', 0x07, struct fw_cdev_remove_descriptor)
239#define FW_CDEV_IOC_CREATE_ISO_CONTEXT _IOWR('#', 0x08, struct fw_cdev_create_iso_context)
240#define FW_CDEV_IOC_QUEUE_ISO _IOWR('#', 0x09, struct fw_cdev_queue_iso)
241#define FW_CDEV_IOC_START_ISO _IOW('#', 0x0a, struct fw_cdev_start_iso)
242#define FW_CDEV_IOC_STOP_ISO _IOW('#', 0x0b, struct fw_cdev_stop_iso)
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100243
244/* available since kernel version 2.6.24 */
Stefan Richterc8a25902009-03-10 20:59:16 +0100245#define FW_CDEV_IOC_GET_CYCLE_TIMER _IOR('#', 0x0c, struct fw_cdev_get_cycle_timer)
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500246
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100247/* available since kernel version 2.6.30 */
Stefan Richter1ec3c022009-01-04 16:23:29 +0100248#define FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE _IOWR('#', 0x0d, struct fw_cdev_allocate_iso_resource)
249#define FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE _IOW('#', 0x0e, struct fw_cdev_deallocate)
250#define FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE _IOW('#', 0x0f, struct fw_cdev_allocate_iso_resource)
251#define FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE _IOW('#', 0x10, struct fw_cdev_allocate_iso_resource)
Stefan Richterc8a25902009-03-10 20:59:16 +0100252#define FW_CDEV_IOC_GET_SPEED _IO('#', 0x11) /* returns speed code */
Jay Fenlason, Stefan Richteracfe8332009-01-04 16:23:29 +0100253#define FW_CDEV_IOC_SEND_BROADCAST_REQUEST _IOW('#', 0x12, struct fw_cdev_send_request)
Jay Fenlasonf8c22872009-03-05 19:08:40 +0100254#define FW_CDEV_IOC_SEND_STREAM_PACKET _IOW('#', 0x13, struct fw_cdev_send_stream_packet)
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100255
Stefan Richterabfe5a02010-02-20 12:13:49 +0100256/* available since kernel version 2.6.34 */
257#define FW_CDEV_IOC_GET_CYCLE_TIMER2 _IOWR('#', 0x14, struct fw_cdev_get_cycle_timer2)
258
Stefan Richter77258da2009-01-07 20:14:53 +0100259/*
260 * FW_CDEV_VERSION History
261 * 1 (2.6.22) - initial version
262 * 2 (2.6.30) - changed &fw_cdev_event_iso_interrupt.header if
263 * &fw_cdev_create_iso_context.header_size is 8 or more
Stefan Richtere94b6d72010-02-21 12:48:57 +0100264 * (2.6.32) - added time stamp to xmit &fw_cdev_event_iso_interrupt
265 * (2.6.33) - IR has always packet-per-buffer semantics now, not one of
266 * dual-buffer or packet-per-buffer depending on hardware
267 * 3 (2.6.34) - made &fw_cdev_get_cycle_timer reliable
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500268 */
Stefan Richtere94b6d72010-02-21 12:48:57 +0100269#define FW_CDEV_VERSION 3
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500270
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200271/**
272 * struct fw_cdev_get_info - General purpose information ioctl
273 * @version: The version field is just a running serial number.
274 * We never break backwards compatibility, but may add more
275 * structs and ioctls in later revisions.
276 * @rom_length: If @rom is non-zero, at most rom_length bytes of configuration
277 * ROM will be copied into that user space address. In either
278 * case, @rom_length is updated with the actual length of the
279 * configuration ROM.
280 * @rom: If non-zero, address of a buffer to be filled by a copy of the
Stefan Richter632321e2009-01-02 12:47:13 +0100281 * device's configuration ROM
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200282 * @bus_reset: If non-zero, address of a buffer to be filled by a
283 * &struct fw_cdev_event_bus_reset with the current state
284 * of the bus. This does not cause a bus reset to happen.
285 * @bus_reset_closure: Value of &closure in this and subsequent bus reset events
286 * @card: The index of the card this device belongs to
287 */
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500288struct fw_cdev_get_info {
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500289 __u32 version;
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500290 __u32 rom_length;
291 __u64 rom;
Kristian Høgsberg344bbc42007-03-07 12:12:43 -0500292 __u64 bus_reset;
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400293 __u64 bus_reset_closure;
Kristian Høgsberge7533502007-03-07 12:12:52 -0500294 __u32 card;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500295};
296
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200297/**
298 * struct fw_cdev_send_request - Send an asynchronous request packet
299 * @tcode: Transaction code of the request
300 * @length: Length of outgoing payload, in bytes
301 * @offset: 48-bit offset at destination node
302 * @closure: Passed back to userspace in the response event
303 * @data: Userspace pointer to payload
304 * @generation: The bus generation where packet is valid
305 *
306 * Send a request to the device. This ioctl implements all outgoing requests.
307 * Both quadlet and block request specify the payload as a pointer to the data
308 * in the @data field. Once the transaction completes, the kernel writes an
Stefan Richterbf8e3352008-12-05 22:43:41 +0100309 * &fw_cdev_event_response event back. The @closure field is passed back to
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200310 * user space in the response event.
311 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500312struct fw_cdev_send_request {
313 __u32 tcode;
314 __u32 length;
315 __u64 offset;
316 __u64 closure;
317 __u64 data;
Kristian Høgsberg97e35272007-03-07 12:12:53 -0500318 __u32 generation;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500319};
320
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200321/**
322 * struct fw_cdev_send_response - Send an asynchronous response packet
323 * @rcode: Response code as determined by the userspace handler
324 * @length: Length of outgoing payload, in bytes
325 * @data: Userspace pointer to payload
326 * @handle: The handle from the &fw_cdev_event_request
327 *
328 * Send a response to an incoming request. By setting up an address range using
329 * the %FW_CDEV_IOC_ALLOCATE ioctl, userspace can listen for incoming requests. An
330 * incoming request will generate an %FW_CDEV_EVENT_REQUEST, and userspace must
331 * send a reply using this ioctl. The event has a handle to the kernel-side
332 * pending transaction, which should be used with this ioctl.
333 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500334struct fw_cdev_send_response {
335 __u32 rcode;
336 __u32 length;
337 __u64 data;
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400338 __u32 handle;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500339};
340
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200341/**
342 * struct fw_cdev_allocate - Allocate a CSR address range
343 * @offset: Start offset of the address range
344 * @closure: To be passed back to userspace in request events
345 * @length: Length of the address range, in bytes
346 * @handle: Handle to the allocation, written by the kernel
347 *
348 * Allocate an address range in the 48-bit address space on the local node
349 * (the controller). This allows userspace to listen for requests with an
350 * offset within that address range. When the kernel receives a request
351 * within the range, an &fw_cdev_event_request event will be written back.
352 * The @closure field is passed back to userspace in the response event.
353 * The @handle field is an out parameter, returning a handle to the allocated
354 * range to be used for later deallocation of the range.
Clemens Ladischdb5d2472009-12-24 12:05:58 +0100355 *
356 * The address range is allocated on all local nodes. The address allocation
357 * is exclusive except for the FCP command and response registers.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200358 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500359struct fw_cdev_allocate {
360 __u64 offset;
361 __u64 closure;
362 __u32 length;
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400363 __u32 handle;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500364};
365
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200366/**
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100367 * struct fw_cdev_deallocate - Free a CSR address range or isochronous resource
368 * @handle: Handle to the address range or iso resource, as returned by the
369 * kernel when the range or resource was allocated
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200370 */
Kristian Høgsberg94723162007-03-14 17:34:55 -0400371struct fw_cdev_deallocate {
Kristian Høgsberg3964a442007-03-27 01:43:41 -0400372 __u32 handle;
Kristian Høgsberg94723162007-03-14 17:34:55 -0400373};
374
Kristian Høgsberg53718422007-03-07 12:12:42 -0500375#define FW_CDEV_LONG_RESET 0
376#define FW_CDEV_SHORT_RESET 1
377
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200378/**
379 * struct fw_cdev_initiate_bus_reset - Initiate a bus reset
380 * @type: %FW_CDEV_SHORT_RESET or %FW_CDEV_LONG_RESET
381 *
382 * Initiate a bus reset for the bus this device is on. The bus reset can be
383 * either the original (long) bus reset or the arbitrated (short) bus reset
384 * introduced in 1394a-2000.
385 */
Kristian Høgsberg53718422007-03-07 12:12:42 -0500386struct fw_cdev_initiate_bus_reset {
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200387 __u32 type; /* FW_CDEV_SHORT_RESET or FW_CDEV_LONG_RESET */
Kristian Høgsberg53718422007-03-07 12:12:42 -0500388};
389
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200390/**
391 * struct fw_cdev_add_descriptor - Add contents to the local node's config ROM
392 * @immediate: If non-zero, immediate key to insert before pointer
393 * @key: Upper 8 bits of root directory pointer
394 * @data: Userspace pointer to contents of descriptor block
Stefan Richter6d3faf62010-01-24 14:48:00 +0100395 * @length: Length of descriptor block data, in quadlets
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200396 * @handle: Handle to the descriptor, written by the kernel
397 *
398 * Add a descriptor block and optionally a preceding immediate key to the local
399 * node's configuration ROM.
400 *
401 * The @key field specifies the upper 8 bits of the descriptor root directory
402 * pointer and the @data and @length fields specify the contents. The @key
403 * should be of the form 0xXX000000. The offset part of the root directory entry
404 * will be filled in by the kernel.
405 *
406 * If not 0, the @immediate field specifies an immediate key which will be
407 * inserted before the root directory pointer.
408 *
Stefan Richter6d3faf62010-01-24 14:48:00 +0100409 * @immediate, @key, and @data array elements are CPU-endian quadlets.
410 *
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200411 * If successful, the kernel adds the descriptor and writes back a handle to the
412 * kernel-side object to be used for later removal of the descriptor block and
413 * immediate key.
Stefan Richterde487da2009-03-10 21:00:23 +0100414 *
415 * This ioctl affects the configuration ROMs of all local nodes.
416 * The ioctl only succeeds on device files which represent a local node.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200417 */
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200418struct fw_cdev_add_descriptor {
419 __u32 immediate;
420 __u32 key;
421 __u64 data;
422 __u32 length;
423 __u32 handle;
424};
425
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200426/**
427 * struct fw_cdev_remove_descriptor - Remove contents from the configuration ROM
428 * @handle: Handle to the descriptor, as returned by the kernel when the
429 * descriptor was added
430 *
431 * Remove a descriptor block and accompanying immediate key from the local
Stefan Richterde487da2009-03-10 21:00:23 +0100432 * nodes' configuration ROMs.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200433 */
Kristian Høgsberg66dea3e2007-03-28 21:26:42 +0200434struct fw_cdev_remove_descriptor {
435 __u32 handle;
436};
437
Kristian Høgsberg295e3fe2007-02-16 17:34:40 -0500438#define FW_CDEV_ISO_CONTEXT_TRANSMIT 0
439#define FW_CDEV_ISO_CONTEXT_RECEIVE 1
440
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200441/**
442 * struct fw_cdev_create_iso_context - Create a context for isochronous IO
443 * @type: %FW_CDEV_ISO_CONTEXT_TRANSMIT or %FW_CDEV_ISO_CONTEXT_RECEIVE
444 * @header_size: Header size to strip for receive contexts
445 * @channel: Channel to bind to
Clemens Ladischaa6fec32010-03-31 16:26:52 +0200446 * @speed: Speed for transmit contexts
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200447 * @closure: To be returned in &fw_cdev_event_iso_interrupt
448 * @handle: Handle to context, written back by kernel
449 *
450 * Prior to sending or receiving isochronous I/O, a context must be created.
451 * The context records information about the transmit or receive configuration
452 * and typically maps to an underlying hardware resource. A context is set up
453 * for either sending or receiving. It is bound to a specific isochronous
454 * channel.
455 *
456 * If a context was successfully created, the kernel writes back a handle to the
457 * context, which must be passed in for subsequent operations on that context.
Stefan Richter77258da2009-01-07 20:14:53 +0100458 *
Clemens Ladischaa6fec32010-03-31 16:26:52 +0200459 * For receive contexts, @header_size must be at least 4 and must be a multiple
460 * of 4.
461 *
Stefan Richter77258da2009-01-07 20:14:53 +0100462 * Note that the effect of a @header_size > 4 depends on
463 * &fw_cdev_get_info.version, as documented at &fw_cdev_event_iso_interrupt.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200464 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500465struct fw_cdev_create_iso_context {
Kristian Høgsberg295e3fe2007-02-16 17:34:40 -0500466 __u32 type;
467 __u32 header_size;
Kristian Høgsberg21efb3c2007-02-16 17:34:50 -0500468 __u32 channel;
469 __u32 speed;
Kristian Høgsbergabaa5742007-04-30 15:03:14 -0400470 __u64 closure;
471 __u32 handle;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500472};
473
Kristian Høgsberg1ca31ae2007-05-31 11:16:43 -0400474#define FW_CDEV_ISO_PAYLOAD_LENGTH(v) (v)
475#define FW_CDEV_ISO_INTERRUPT (1 << 16)
476#define FW_CDEV_ISO_SKIP (1 << 17)
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200477#define FW_CDEV_ISO_SYNC (1 << 17)
Kristian Høgsberg1ca31ae2007-05-31 11:16:43 -0400478#define FW_CDEV_ISO_TAG(v) ((v) << 18)
479#define FW_CDEV_ISO_SY(v) ((v) << 20)
480#define FW_CDEV_ISO_HEADER_LENGTH(v) ((v) << 24)
481
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200482/**
483 * struct fw_cdev_iso_packet - Isochronous packet
484 * @control: Contains the header length (8 uppermost bits), the sy field
485 * (4 bits), the tag field (2 bits), a sync flag (1 bit),
486 * a skip flag (1 bit), an interrupt flag (1 bit), and the
487 * payload length (16 lowermost bits)
488 * @header: Header and payload
489 *
490 * &struct fw_cdev_iso_packet is used to describe isochronous packet queues.
491 *
Clemens Ladischaa6fec32010-03-31 16:26:52 +0200492 * Use the FW_CDEV_ISO_ macros to fill in @control.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200493 *
Clemens Ladischaa6fec32010-03-31 16:26:52 +0200494 * For transmit packets, the header length must be a multiple of 4 and specifies
495 * the numbers of bytes in @header that will be prepended to the packet's
496 * payload; these bytes are copied into the kernel and will not be accessed
497 * after the ioctl has returned. The sy and tag fields are copied to the iso
498 * packet header (these fields are specified by IEEE 1394a and IEC 61883-1).
499 * The skip flag specifies that no packet is to be sent in a frame; when using
500 * this, all other fields except the interrupt flag must be zero.
501 *
502 * For receive packets, the header length must be a multiple of the context's
503 * header size; if the header length is larger than the context's header size,
504 * multiple packets are queued for this entry. The sy and tag fields are
505 * ignored. If the sync flag is set, the context drops all packets until
506 * a packet with a matching sy field is received (the sync value to wait for is
507 * specified in the &fw_cdev_start_iso structure). The payload length defines
508 * how many payload bytes can be received for one packet (in addition to payload
509 * quadlets that have been defined as headers and are stripped and returned in
510 * the &fw_cdev_event_iso_interrupt structure). If more bytes are received, the
511 * additional bytes are dropped. If less bytes are received, the remaining
512 * bytes in this part of the payload buffer will not be written to, not even by
513 * the next packet, i.e., packets received in consecutive frames will not
514 * necessarily be consecutive in memory. If an entry has queued multiple
515 * packets, the payload length is divided equally among them.
516 *
517 * When a packet with the interrupt flag set has been completed, the
518 * &fw_cdev_event_iso_interrupt event will be sent. An entry that has queued
519 * multiple receive packets is completed when its last packet is completed.
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200520 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500521struct fw_cdev_iso_packet {
Kristian Høgsberg1ca31ae2007-05-31 11:16:43 -0400522 __u32 control;
Stefan Richter5e20c282007-01-21 20:44:09 +0100523 __u32 header[0];
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500524};
525
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200526/**
527 * struct fw_cdev_queue_iso - Queue isochronous packets for I/O
528 * @packets: Userspace pointer to packet data
529 * @data: Pointer into mmap()'ed payload buffer
530 * @size: Size of packet data in bytes
531 * @handle: Isochronous context handle
532 *
533 * Queue a number of isochronous packets for reception or transmission.
534 * This ioctl takes a pointer to an array of &fw_cdev_iso_packet structs,
535 * which describe how to transmit from or receive into a contiguous region
Clemens Ladischaa6fec32010-03-31 16:26:52 +0200536 * of a mmap()'ed payload buffer. As part of transmit packet descriptors,
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200537 * a series of headers can be supplied, which will be prepended to the
538 * payload during DMA.
539 *
540 * The kernel may or may not queue all packets, but will write back updated
541 * values of the @packets, @data and @size fields, so the ioctl can be
542 * resubmitted easily.
543 */
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500544struct fw_cdev_queue_iso {
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500545 __u64 packets;
546 __u64 data;
Kristian Høgsbergda8ecff2007-03-27 01:43:39 -0400547 __u32 size;
Kristian Høgsbergabaa5742007-04-30 15:03:14 -0400548 __u32 handle;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500549};
550
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200551#define FW_CDEV_ISO_CONTEXT_MATCH_TAG0 1
552#define FW_CDEV_ISO_CONTEXT_MATCH_TAG1 2
553#define FW_CDEV_ISO_CONTEXT_MATCH_TAG2 4
554#define FW_CDEV_ISO_CONTEXT_MATCH_TAG3 8
555#define FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS 15
556
557/**
558 * struct fw_cdev_start_iso - Start an isochronous transmission or reception
559 * @cycle: Cycle in which to start I/O. If @cycle is greater than or
560 * equal to 0, the I/O will start on that cycle.
561 * @sync: Determines the value to wait for for receive packets that have
562 * the %FW_CDEV_ISO_SYNC bit set
563 * @tags: Tag filter bit mask. Only valid for isochronous reception.
564 * Determines the tag values for which packets will be accepted.
565 * Use FW_CDEV_ISO_CONTEXT_MATCH_ macros to set @tags.
566 * @handle: Isochronous context handle within which to transmit or receive
567 */
Kristian Høgsberg69cdb722007-02-16 17:34:41 -0500568struct fw_cdev_start_iso {
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500569 __s32 cycle;
Kristian Høgsbergeb0306e2007-03-14 17:34:54 -0400570 __u32 sync;
571 __u32 tags;
Kristian Høgsbergabaa5742007-04-30 15:03:14 -0400572 __u32 handle;
573};
574
Kristian Høgsberg7ada60e2007-06-22 00:20:34 +0200575/**
576 * struct fw_cdev_stop_iso - Stop an isochronous transmission or reception
577 * @handle: Handle of isochronous context to stop
578 */
Kristian Høgsbergabaa5742007-04-30 15:03:14 -0400579struct fw_cdev_stop_iso {
580 __u32 handle;
Kristian Høgsberg19a15b92006-12-19 19:58:31 -0500581};
582
Stefan Richtera64408b2007-09-29 10:41:58 +0200583/**
584 * struct fw_cdev_get_cycle_timer - read cycle timer register
585 * @local_time: system time, in microseconds since the Epoch
Stefan Richterabfe5a02010-02-20 12:13:49 +0100586 * @cycle_timer: Cycle Time register contents
Stefan Richtera64408b2007-09-29 10:41:58 +0200587 *
588 * The %FW_CDEV_IOC_GET_CYCLE_TIMER ioctl reads the isochronous cycle timer
Stefan Richterabfe5a02010-02-20 12:13:49 +0100589 * and also the system clock (%CLOCK_REALTIME). This allows to express the
590 * receive time of an isochronous packet as a system time.
Stefan Richter77258da2009-01-07 20:14:53 +0100591 *
592 * @cycle_timer consists of 7 bits cycleSeconds, 13 bits cycleCount, and
Stefan Richterabfe5a02010-02-20 12:13:49 +0100593 * 12 bits cycleOffset, in host byte order. Cf. the Cycle Time register
594 * per IEEE 1394 or Isochronous Cycle Timer register per OHCI-1394.
Stefan Richtere94b6d72010-02-21 12:48:57 +0100595 *
596 * In version 1 and 2 of the ABI, this ioctl returned unreliable (non-
597 * monotonic) @cycle_timer values on certain controllers.
Stefan Richtera64408b2007-09-29 10:41:58 +0200598 */
599struct fw_cdev_get_cycle_timer {
600 __u64 local_time;
601 __u32 cycle_timer;
602};
603
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100604/**
Stefan Richterabfe5a02010-02-20 12:13:49 +0100605 * struct fw_cdev_get_cycle_timer2 - read cycle timer register
606 * @tv_sec: system time, seconds
607 * @tv_nsec: system time, sub-seconds part in nanoseconds
608 * @clk_id: input parameter, clock from which to get the system time
609 * @cycle_timer: Cycle Time register contents
610 *
611 * The %FW_CDEV_IOC_GET_CYCLE_TIMER2 works like
612 * %FW_CDEV_IOC_GET_CYCLE_TIMER but lets you choose a clock like with POSIX'
613 * clock_gettime function. Supported @clk_id values are POSIX' %CLOCK_REALTIME
614 * and %CLOCK_MONOTONIC and Linux' %CLOCK_MONOTONIC_RAW.
615 */
616struct fw_cdev_get_cycle_timer2 {
617 __s64 tv_sec;
618 __s32 tv_nsec;
619 __s32 clk_id;
620 __u32 cycle_timer;
621};
622
623/**
Stefan Richter1ec3c022009-01-04 16:23:29 +0100624 * struct fw_cdev_allocate_iso_resource - (De)allocate a channel or bandwidth
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100625 * @closure: Passed back to userspace in correponding iso resource events
Stefan Richter1ec3c022009-01-04 16:23:29 +0100626 * @channels: Isochronous channels of which one is to be (de)allocated
627 * @bandwidth: Isochronous bandwidth units to be (de)allocated
628 * @handle: Handle to the allocation, written by the kernel (only valid in
629 * case of %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ioctls)
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100630 *
631 * The %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ioctl initiates allocation of an
632 * isochronous channel and/or of isochronous bandwidth at the isochronous
633 * resource manager (IRM). Only one of the channels specified in @channels is
634 * allocated. An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED is sent after
635 * communication with the IRM, indicating success or failure in the event data.
636 * The kernel will automatically reallocate the resources after bus resets.
637 * Should a reallocation fail, an %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event
638 * will be sent. The kernel will also automatically deallocate the resources
639 * when the file descriptor is closed.
640 *
Stefan Richter1ec3c022009-01-04 16:23:29 +0100641 * The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE ioctl can be used to initiate
642 * deallocation of resources which were allocated as described above.
643 * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation.
644 *
645 * The %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE ioctl is a variant of allocation
646 * without automatic re- or deallocation.
647 * An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event concludes this operation,
648 * indicating success or failure in its data.
649 *
650 * The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE ioctl works like
651 * %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE except that resources are freed
Stefan Richter5d9cb7d272009-01-08 23:07:40 +0100652 * instead of allocated.
Stefan Richter1ec3c022009-01-04 16:23:29 +0100653 * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation.
654 *
Stefan Richterca658b12010-04-10 12:23:09 +0200655 * To summarize, %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE allocates iso resources
656 * for the lifetime of the fd or @handle.
Stefan Richter1ec3c022009-01-04 16:23:29 +0100657 * In contrast, %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE allocates iso resources
658 * for the duration of a bus generation.
659 *
Stefan Richter5d9cb7d272009-01-08 23:07:40 +0100660 * @channels is a host-endian bitfield with the least significant bit
661 * representing channel 0 and the most significant bit representing channel 63:
662 * 1ULL << c for each channel c that is a candidate for (de)allocation.
Jay Fenlason, Stefan Richterb1bda4c2009-01-04 16:23:29 +0100663 *
664 * @bandwidth is expressed in bandwidth allocation units, i.e. the time to send
665 * one quadlet of data (payload or header data) at speed S1600.
666 */
667struct fw_cdev_allocate_iso_resource {
668 __u64 closure;
669 __u64 channels;
670 __u32 bandwidth;
671 __u32 handle;
672};
673
Stefan Richter33580a32009-01-04 16:23:29 +0100674/**
Jay Fenlasonf8c22872009-03-05 19:08:40 +0100675 * struct fw_cdev_send_stream_packet - send an asynchronous stream packet
Stefan Richter18e9b102009-03-10 21:02:21 +0100676 * @length: Length of outgoing payload, in bytes
677 * @tag: Data format tag
678 * @channel: Isochronous channel to transmit to
679 * @sy: Synchronization code
680 * @closure: Passed back to userspace in the response event
681 * @data: Userspace pointer to payload
682 * @generation: The bus generation where packet is valid
683 * @speed: Speed to transmit at
Jay Fenlasonf8c22872009-03-05 19:08:40 +0100684 *
685 * The %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl sends an asynchronous stream packet
Stefan Richter18e9b102009-03-10 21:02:21 +0100686 * to every device which is listening to the specified channel. The kernel
687 * writes an &fw_cdev_event_response event which indicates success or failure of
688 * the transmission.
Jay Fenlasonf8c22872009-03-05 19:08:40 +0100689 */
690struct fw_cdev_send_stream_packet {
Stefan Richter18e9b102009-03-10 21:02:21 +0100691 __u32 length;
692 __u32 tag;
Jay Fenlasonf8c22872009-03-05 19:08:40 +0100693 __u32 channel;
694 __u32 sy;
Stefan Richter18e9b102009-03-10 21:02:21 +0100695 __u64 closure;
Jay Fenlasonf8c22872009-03-05 19:08:40 +0100696 __u64 data;
Stefan Richter18e9b102009-03-10 21:02:21 +0100697 __u32 generation;
698 __u32 speed;
Jay Fenlasonf8c22872009-03-05 19:08:40 +0100699};
700
Kristian Høgsberg4c5a4432007-05-07 20:33:37 -0400701#endif /* _LINUX_FIREWIRE_CDEV_H */