2 * Char device interface.
4 * Copyright (C) 2005-2007 Kristian Hoegsberg <krh@bitplanet.net>
6 * 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:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * 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 * THE AUTHORS OR COPYRIGHT HOLDERS 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.
26 #ifndef _LINUX_FIREWIRE_CDEV_H
27 #define _LINUX_FIREWIRE_CDEV_H
29 #include <linux/ioctl.h>
30 #include <linux/types.h>
31 #include <linux/firewire-constants.h>
33 /* available since kernel version 2.6.22 */
34 #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
39 /* available since kernel version 2.6.30 */
40 #define FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED 0x04
41 #define FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED 0x05
43 /* available since kernel version 2.6.36 */
44 #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
49 /* available since kernel version 6.5 */
50 #define FW_CDEV_EVENT_REQUEST3 0x0a
53 * struct fw_cdev_event_common - Common part of all fw_cdev_event_* types
54 * @closure: For arbitrary use by userspace
55 * @type: Discriminates the fw_cdev_event_* types
57 * This struct may be used to access generic members of all fw_cdev_event_*
58 * types regardless of the specific type.
60 * Data passed in the @closure field for a request will be returned in the
61 * corresponding event. It is big enough to hold a pointer on all platforms.
62 * The ioctl used to set @closure depends on the @type of event.
64 struct fw_cdev_event_common {
70 * struct fw_cdev_event_bus_reset - Sent when a bus reset occurred
71 * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_GET_INFO ioctl
72 * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_BUS_RESET
73 * @node_id: New node ID of this node
74 * @local_node_id: Node ID of the local node, i.e. of the controller
75 * @bm_node_id: Node ID of the bus manager
76 * @irm_node_id: Node ID of the iso resource manager
77 * @root_node_id: Node ID of the root node
78 * @generation: New bus generation
80 * This event is sent when the bus the device belongs to goes through a bus
81 * reset. It provides information about the new bus configuration, such as
82 * new node ID for this device, new root ID, and others.
84 * If @bm_node_id is 0xffff right after bus reset it can be reread by an
85 * %FW_CDEV_IOC_GET_INFO ioctl after bus manager selection was finished.
86 * Kernels with ABI version < 4 do not set @bm_node_id.
88 struct fw_cdev_event_bus_reset {
100 * struct fw_cdev_event_response - Sent when a response packet was received
101 * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_SEND_REQUEST
102 * or %FW_CDEV_IOC_SEND_BROADCAST_REQUEST
103 * or %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl
104 * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_RESPONSE
105 * @rcode: Response code returned by the remote node
106 * @length: Data length, i.e. the response's payload size in bytes
107 * @data: Payload data, if any
109 * This event is sent when the stack receives a response to an outgoing request
110 * sent by %FW_CDEV_IOC_SEND_REQUEST ioctl. The payload data for responses
111 * carrying data (read and lock responses) follows immediately and can be
112 * accessed through the @data field.
114 * The event is also generated after conclusions of transactions that do not
115 * involve response packets. This includes unified write transactions,
116 * broadcast write transactions, and transmission of asynchronous stream
117 * packets. @rcode indicates success or failure of such transmissions.
119 struct fw_cdev_event_response {
128 * struct fw_cdev_event_request - Old version of &fw_cdev_event_request2
129 * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_ALLOCATE ioctl
130 * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST
131 * @tcode: Transaction code of the incoming request
132 * @offset: The offset into the 48-bit per-node address space
133 * @handle: Reference to the kernel-side pending request
134 * @length: Data length, i.e. the request's payload size in bytes
135 * @data: Incoming data, if any
137 * This event is sent instead of &fw_cdev_event_request2 if the kernel or
138 * the client implements ABI version <= 3. &fw_cdev_event_request lacks
139 * essential information; use &fw_cdev_event_request2 instead.
141 struct fw_cdev_event_request {
152 * struct fw_cdev_event_request2 - Sent on incoming request to an address region
153 * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_ALLOCATE ioctl
154 * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST2
155 * @tcode: Transaction code of the incoming request
156 * @offset: The offset into the 48-bit per-node address space
157 * @source_node_id: Sender node ID
158 * @destination_node_id: Destination node ID
159 * @card: The index of the card from which the request came
160 * @generation: Bus generation in which the request is valid
161 * @handle: Reference to the kernel-side pending request
162 * @length: Data length, i.e. the request's payload size in bytes
163 * @data: Incoming data, if any
165 * This event is sent instead of &fw_cdev_event_request3 if the kernel or the client implements
166 * ABI version <= 5. It has the lack of time stamp field comparing to &fw_cdev_event_request3.
168 struct fw_cdev_event_request2 {
173 __u32 source_node_id;
174 __u32 destination_node_id;
183 * struct fw_cdev_event_request3 - Sent on incoming request to an address region
184 * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_ALLOCATE ioctl
185 * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_REQUEST2
186 * @tcode: Transaction code of the incoming request
187 * @offset: The offset into the 48-bit per-node address space
188 * @source_node_id: Sender node ID
189 * @destination_node_id: Destination node ID
190 * @card: The index of the card from which the request came
191 * @generation: Bus generation in which the request is valid
192 * @handle: Reference to the kernel-side pending request
193 * @length: Data length, i.e. the request's payload size in bytes
194 * @tstamp: The time stamp of isochronous cycle at which the request arrived.
195 * @data: Incoming data, if any
197 * This event is sent when the stack receives an incoming request to an address
198 * region registered using the %FW_CDEV_IOC_ALLOCATE ioctl. The request is
199 * guaranteed to be completely contained in the specified region. Userspace is
200 * responsible for sending the response by %FW_CDEV_IOC_SEND_RESPONSE ioctl,
201 * using the same @handle.
203 * The payload data for requests carrying data (write and lock requests)
204 * follows immediately and can be accessed through the @data field.
206 * Unlike &fw_cdev_event_request, @tcode of lock requests is one of the
207 * firewire-core specific %TCODE_LOCK_MASK_SWAP...%TCODE_LOCK_VENDOR_DEPENDENT,
208 * i.e. encodes the extended transaction code.
210 * @card may differ from &fw_cdev_get_info.card because requests are received
211 * from all cards of the Linux host. @source_node_id, @destination_node_id, and
212 * @generation pertain to that card. Destination node ID and bus generation may
213 * therefore differ from the corresponding fields of the last
214 * &fw_cdev_event_bus_reset.
216 * @destination_node_id may also differ from the current node ID because of a
217 * non-local bus ID part or in case of a broadcast write request. Note, a
218 * client must call an %FW_CDEV_IOC_SEND_RESPONSE ioctl even in case of a
219 * broadcast write request; the kernel will then release the kernel-side pending
220 * request but will not actually send a response packet.
222 * In case of a write request to FCP_REQUEST or FCP_RESPONSE, the kernel already
223 * sent a write response immediately after the request was received; in this
224 * case the client must still call an %FW_CDEV_IOC_SEND_RESPONSE ioctl to
225 * release the kernel-side pending request, though another response won't be
228 * If the client subsequently needs to initiate requests to the sender node of
229 * an &fw_cdev_event_request3, it needs to use a device file with matching
230 * card index, node ID, and generation for outbound requests.
232 * @tstamp is isochronous cycle at which the request arrived. It is 16 bit integer value and the
233 * higher 3 bits expresses three low order bits of second field in the format of CYCLE_TIME
234 * register and the rest 13 bits expresses cycle field.
236 struct fw_cdev_event_request3 {
241 __u32 source_node_id;
242 __u32 destination_node_id;
249 * Padding to keep the size of structure as multiples of 8 in various architectures since
250 * 4 byte alignment is used for 8 byte of object type in System V ABI for i386 architecture.
257 * struct fw_cdev_event_iso_interrupt - Sent when an iso packet was completed
258 * @closure: See &fw_cdev_event_common;
259 * set by %FW_CDEV_CREATE_ISO_CONTEXT ioctl
260 * @type: See &fw_cdev_event_common; always %FW_CDEV_EVENT_ISO_INTERRUPT
261 * @cycle: Cycle counter of the last completed packet
262 * @header_length: Total length of following headers, in bytes
263 * @header: Stripped headers, if any
265 * This event is sent when the controller has completed an &fw_cdev_iso_packet
266 * with the %FW_CDEV_ISO_INTERRUPT bit set, when explicitly requested with
267 * %FW_CDEV_IOC_FLUSH_ISO, or when there have been so many completed packets
268 * without the interrupt bit set that the kernel's internal buffer for @header
269 * is about to overflow. (In the last case, ABI versions < 5 drop header data
270 * up to the next interrupt packet.)
272 * Isochronous transmit events (context type %FW_CDEV_ISO_CONTEXT_TRANSMIT):
274 * In version 3 and some implementations of version 2 of the ABI, &header_length
275 * is a multiple of 4 and &header contains timestamps of all packets up until
276 * the interrupt packet. The format of the timestamps is as described below for
277 * isochronous reception. In version 1 of the ABI, &header_length was 0.
279 * Isochronous receive events (context type %FW_CDEV_ISO_CONTEXT_RECEIVE):
281 * The headers stripped of all packets up until and including the interrupt
282 * packet are returned in the @header field. The amount of header data per
283 * packet is as specified at iso context creation by
284 * &fw_cdev_create_iso_context.header_size.
286 * Hence, _interrupt.header_length / _context.header_size is the number of
287 * packets received in this interrupt event. The client can now iterate
288 * through the mmap()'ed DMA buffer according to this number of packets and
289 * to the buffer sizes as the client specified in &fw_cdev_queue_iso.
291 * Since version 2 of this ABI, the portion for each packet in _interrupt.header
292 * consists of the 1394 isochronous packet header, followed by a timestamp
293 * quadlet if &fw_cdev_create_iso_context.header_size > 4, followed by quadlets
294 * from the packet payload if &fw_cdev_create_iso_context.header_size > 8.
296 * Format of 1394 iso packet header: 16 bits data_length, 2 bits tag, 6 bits
297 * channel, 4 bits tcode, 4 bits sy, in big endian byte order.
298 * data_length is the actual received size of the packet without the four
299 * 1394 iso packet header bytes.
301 * Format of timestamp: 16 bits invalid, 3 bits cycleSeconds, 13 bits
302 * cycleCount, in big endian byte order.
304 * In version 1 of the ABI, no timestamp quadlet was inserted; instead, payload
305 * data followed directly after the 1394 is header if header_size > 4.
306 * Behaviour of ver. 1 of this ABI is no longer available since ABI ver. 2.
308 struct fw_cdev_event_iso_interrupt {
317 * struct fw_cdev_event_iso_interrupt_mc - An iso buffer chunk was completed
318 * @closure: See &fw_cdev_event_common;
319 * set by %FW_CDEV_CREATE_ISO_CONTEXT ioctl
320 * @type: %FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL
321 * @completed: Offset into the receive buffer; data before this offset is valid
323 * This event is sent in multichannel contexts (context type
324 * %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL) for &fw_cdev_iso_packet buffer
325 * chunks that have been completely filled and that have the
326 * %FW_CDEV_ISO_INTERRUPT bit set, or when explicitly requested with
327 * %FW_CDEV_IOC_FLUSH_ISO.
329 * The buffer is continuously filled with the following data, per packet:
330 * - the 1394 iso packet header as described at &fw_cdev_event_iso_interrupt,
331 * but in little endian byte order,
332 * - packet payload (as many bytes as specified in the data_length field of
333 * the 1394 iso packet header) in big endian byte order,
334 * - 0...3 padding bytes as needed to align the following trailer quadlet,
335 * - trailer quadlet, containing the reception timestamp as described at
336 * &fw_cdev_event_iso_interrupt, but in little endian byte order.
338 * Hence the per-packet size is data_length (rounded up to a multiple of 4) + 8.
339 * When processing the data, stop before a packet that would cross the
342 * A packet near the end of a buffer chunk will typically spill over into the
343 * next queued buffer chunk. It is the responsibility of the client to check
344 * for this condition, assemble a broken-up packet from its parts, and not to
345 * re-queue any buffer chunks in which as yet unread packet parts reside.
347 struct fw_cdev_event_iso_interrupt_mc {
354 * struct fw_cdev_event_iso_resource - Iso resources were allocated or freed
355 * @closure: See &fw_cdev_event_common;
356 * set by``FW_CDEV_IOC_(DE)ALLOCATE_ISO_RESOURCE(_ONCE)`` ioctl
357 * @type: %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or
358 * %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED
359 * @handle: Reference by which an allocated resource can be deallocated
360 * @channel: Isochronous channel which was (de)allocated, if any
361 * @bandwidth: Bandwidth allocation units which were (de)allocated, if any
363 * An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event is sent after an isochronous
364 * resource was allocated at the IRM. The client has to check @channel and
365 * @bandwidth for whether the allocation actually succeeded.
367 * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event is sent after an isochronous
368 * resource was deallocated at the IRM. It is also sent when automatic
369 * reallocation after a bus reset failed.
371 * @channel is <0 if no channel was (de)allocated or if reallocation failed.
372 * @bandwidth is 0 if no bandwidth was (de)allocated or if reallocation failed.
374 struct fw_cdev_event_iso_resource {
383 * struct fw_cdev_event_phy_packet - A PHY packet was transmitted or received
384 * @closure: See &fw_cdev_event_common; set by %FW_CDEV_IOC_SEND_PHY_PACKET
385 * or %FW_CDEV_IOC_RECEIVE_PHY_PACKETS ioctl
386 * @type: %FW_CDEV_EVENT_PHY_PACKET_SENT or %..._RECEIVED
387 * @rcode: %RCODE_..., indicates success or failure of transmission
388 * @length: Data length in bytes
389 * @data: Incoming data
391 * If @type is %FW_CDEV_EVENT_PHY_PACKET_SENT, @length is 0 and @data empty,
392 * except in case of a ping packet: Then, @length is 4, and @data[0] is the
393 * ping time in 49.152MHz clocks if @rcode is %RCODE_COMPLETE.
395 * If @type is %FW_CDEV_EVENT_PHY_PACKET_RECEIVED, @length is 8 and @data
396 * consists of the two PHY packet quadlets, in host byte order.
398 struct fw_cdev_event_phy_packet {
407 * union fw_cdev_event - Convenience union of fw_cdev_event_* types
408 * @common: Valid for all types
409 * @bus_reset: Valid if @common.type == %FW_CDEV_EVENT_BUS_RESET
410 * @response: Valid if @common.type == %FW_CDEV_EVENT_RESPONSE
411 * @request: Valid if @common.type == %FW_CDEV_EVENT_REQUEST
412 * @request2: Valid if @common.type == %FW_CDEV_EVENT_REQUEST2
413 * @iso_interrupt: Valid if @common.type == %FW_CDEV_EVENT_ISO_INTERRUPT
414 * @iso_interrupt_mc: Valid if @common.type ==
415 * %FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL
416 * @iso_resource: Valid if @common.type ==
417 * %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or
418 * %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED
419 * @phy_packet: Valid if @common.type ==
420 * %FW_CDEV_EVENT_PHY_PACKET_SENT or
421 * %FW_CDEV_EVENT_PHY_PACKET_RECEIVED
423 * @request3: Valid if @common.type == %FW_CDEV_EVENT_REQUEST3
425 * Convenience union for userspace use. Events could be read(2) into an
426 * appropriately aligned char buffer and then cast to this union for further
427 * processing. Note that for a request, response or iso_interrupt event,
428 * the data[] or header[] may make the size of the full event larger than
429 * sizeof(union fw_cdev_event). Also note that if you attempt to read(2)
430 * an event into a buffer that is not large enough for it, the data that does
431 * not fit will be discarded so that the next read(2) will return a new event.
433 union fw_cdev_event {
434 struct fw_cdev_event_common common;
435 struct fw_cdev_event_bus_reset bus_reset;
436 struct fw_cdev_event_response response;
437 struct fw_cdev_event_request request;
438 struct fw_cdev_event_request2 request2; /* added in 2.6.36 */
439 struct fw_cdev_event_iso_interrupt iso_interrupt;
440 struct fw_cdev_event_iso_interrupt_mc iso_interrupt_mc; /* added in 2.6.36 */
441 struct fw_cdev_event_iso_resource iso_resource; /* added in 2.6.30 */
442 struct fw_cdev_event_phy_packet phy_packet; /* added in 2.6.36 */
443 struct fw_cdev_event_request3 request3; /* added in 6.5 */
446 /* available since kernel version 2.6.22 */
447 #define FW_CDEV_IOC_GET_INFO _IOWR('#', 0x00, struct fw_cdev_get_info)
448 #define FW_CDEV_IOC_SEND_REQUEST _IOW('#', 0x01, struct fw_cdev_send_request)
449 #define FW_CDEV_IOC_ALLOCATE _IOWR('#', 0x02, struct fw_cdev_allocate)
450 #define FW_CDEV_IOC_DEALLOCATE _IOW('#', 0x03, struct fw_cdev_deallocate)
451 #define FW_CDEV_IOC_SEND_RESPONSE _IOW('#', 0x04, struct fw_cdev_send_response)
452 #define FW_CDEV_IOC_INITIATE_BUS_RESET _IOW('#', 0x05, struct fw_cdev_initiate_bus_reset)
453 #define FW_CDEV_IOC_ADD_DESCRIPTOR _IOWR('#', 0x06, struct fw_cdev_add_descriptor)
454 #define FW_CDEV_IOC_REMOVE_DESCRIPTOR _IOW('#', 0x07, struct fw_cdev_remove_descriptor)
455 #define FW_CDEV_IOC_CREATE_ISO_CONTEXT _IOWR('#', 0x08, struct fw_cdev_create_iso_context)
456 #define FW_CDEV_IOC_QUEUE_ISO _IOWR('#', 0x09, struct fw_cdev_queue_iso)
457 #define FW_CDEV_IOC_START_ISO _IOW('#', 0x0a, struct fw_cdev_start_iso)
458 #define FW_CDEV_IOC_STOP_ISO _IOW('#', 0x0b, struct fw_cdev_stop_iso)
460 /* available since kernel version 2.6.24 */
461 #define FW_CDEV_IOC_GET_CYCLE_TIMER _IOR('#', 0x0c, struct fw_cdev_get_cycle_timer)
463 /* available since kernel version 2.6.30 */
464 #define FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE _IOWR('#', 0x0d, struct fw_cdev_allocate_iso_resource)
465 #define FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE _IOW('#', 0x0e, struct fw_cdev_deallocate)
466 #define FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE _IOW('#', 0x0f, struct fw_cdev_allocate_iso_resource)
467 #define FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE _IOW('#', 0x10, struct fw_cdev_allocate_iso_resource)
468 #define FW_CDEV_IOC_GET_SPEED _IO('#', 0x11) /* returns speed code */
469 #define FW_CDEV_IOC_SEND_BROADCAST_REQUEST _IOW('#', 0x12, struct fw_cdev_send_request)
470 #define FW_CDEV_IOC_SEND_STREAM_PACKET _IOW('#', 0x13, struct fw_cdev_send_stream_packet)
472 /* available since kernel version 2.6.34 */
473 #define FW_CDEV_IOC_GET_CYCLE_TIMER2 _IOWR('#', 0x14, struct fw_cdev_get_cycle_timer2)
475 /* available since kernel version 2.6.36 */
476 #define FW_CDEV_IOC_SEND_PHY_PACKET _IOWR('#', 0x15, struct fw_cdev_send_phy_packet)
477 #define FW_CDEV_IOC_RECEIVE_PHY_PACKETS _IOW('#', 0x16, struct fw_cdev_receive_phy_packets)
478 #define FW_CDEV_IOC_SET_ISO_CHANNELS _IOW('#', 0x17, struct fw_cdev_set_iso_channels)
480 /* available since kernel version 3.4 */
481 #define FW_CDEV_IOC_FLUSH_ISO _IOW('#', 0x18, struct fw_cdev_flush_iso)
484 * ABI version history
485 * 1 (2.6.22) - initial version
486 * (2.6.24) - added %FW_CDEV_IOC_GET_CYCLE_TIMER
487 * 2 (2.6.30) - changed &fw_cdev_event_iso_interrupt.header if
488 * &fw_cdev_create_iso_context.header_size is 8 or more
489 * - added %FW_CDEV_IOC_*_ISO_RESOURCE*,
490 * %FW_CDEV_IOC_GET_SPEED, %FW_CDEV_IOC_SEND_BROADCAST_REQUEST,
491 * %FW_CDEV_IOC_SEND_STREAM_PACKET
492 * (2.6.32) - added time stamp to xmit &fw_cdev_event_iso_interrupt
493 * (2.6.33) - IR has always packet-per-buffer semantics now, not one of
494 * dual-buffer or packet-per-buffer depending on hardware
495 * - shared use and auto-response for FCP registers
496 * 3 (2.6.34) - made &fw_cdev_get_cycle_timer reliable
497 * - added %FW_CDEV_IOC_GET_CYCLE_TIMER2
498 * 4 (2.6.36) - added %FW_CDEV_EVENT_REQUEST2, %FW_CDEV_EVENT_PHY_PACKET_*,
499 * and &fw_cdev_allocate.region_end
500 * - implemented &fw_cdev_event_bus_reset.bm_node_id
501 * - added %FW_CDEV_IOC_SEND_PHY_PACKET, _RECEIVE_PHY_PACKETS
502 * - added %FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL,
503 * %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL, and
504 * %FW_CDEV_IOC_SET_ISO_CHANNELS
505 * 5 (3.4) - send %FW_CDEV_EVENT_ISO_INTERRUPT events when needed to
506 * avoid dropping data
507 * - added %FW_CDEV_IOC_FLUSH_ISO
508 * 6 (6.5) - added some event for subactions of asynchronous transaction with time stamp
509 * - %FW_CDEV_EVENT_REQUEST3
513 * struct fw_cdev_get_info - General purpose information ioctl
514 * @version: The version field is just a running serial number. Both an
515 * input parameter (ABI version implemented by the client) and
516 * output parameter (ABI version implemented by the kernel).
517 * A client shall fill in the ABI @version for which the client
518 * was implemented. This is necessary for forward compatibility.
519 * @rom_length: If @rom is non-zero, up to @rom_length bytes of Configuration
520 * ROM will be copied into that user space address. In either
521 * case, @rom_length is updated with the actual length of the
523 * @rom: If non-zero, address of a buffer to be filled by a copy of the
524 * device's Configuration ROM
525 * @bus_reset: If non-zero, address of a buffer to be filled by a
526 * &struct fw_cdev_event_bus_reset with the current state
527 * of the bus. This does not cause a bus reset to happen.
528 * @bus_reset_closure: Value of &closure in this and subsequent bus reset events
529 * @card: The index of the card this device belongs to
531 * The %FW_CDEV_IOC_GET_INFO ioctl is usually the very first one which a client
532 * performs right after it opened a /dev/fw* file.
534 * As a side effect, reception of %FW_CDEV_EVENT_BUS_RESET events to be read(2)
535 * is started by this ioctl.
537 struct fw_cdev_get_info {
542 __u64 bus_reset_closure;
547 * struct fw_cdev_send_request - Send an asynchronous request packet
548 * @tcode: Transaction code of the request
549 * @length: Length of outgoing payload, in bytes
550 * @offset: 48-bit offset at destination node
551 * @closure: Passed back to userspace in the response event
552 * @data: Userspace pointer to payload
553 * @generation: The bus generation where packet is valid
555 * Send a request to the device. This ioctl implements all outgoing requests.
556 * Both quadlet and block request specify the payload as a pointer to the data
557 * in the @data field. Once the transaction completes, the kernel writes an
558 * &fw_cdev_event_response event back. The @closure field is passed back to
559 * user space in the response event.
561 struct fw_cdev_send_request {
571 * struct fw_cdev_send_response - Send an asynchronous response packet
572 * @rcode: Response code as determined by the userspace handler
573 * @length: Length of outgoing payload, in bytes
574 * @data: Userspace pointer to payload
575 * @handle: The handle from the &fw_cdev_event_request
577 * Send a response to an incoming request. By setting up an address range using
578 * the %FW_CDEV_IOC_ALLOCATE ioctl, userspace can listen for incoming requests. An
579 * incoming request will generate an %FW_CDEV_EVENT_REQUEST, and userspace must
580 * send a reply using this ioctl. The event has a handle to the kernel-side
581 * pending transaction, which should be used with this ioctl.
583 struct fw_cdev_send_response {
591 * struct fw_cdev_allocate - Allocate a CSR in an address range
592 * @offset: Start offset of the address range
593 * @closure: To be passed back to userspace in request events
594 * @length: Length of the CSR, in bytes
595 * @handle: Handle to the allocation, written by the kernel
596 * @region_end: First address above the address range (added in ABI v4, 2.6.36)
598 * Allocate an address range in the 48-bit address space on the local node
599 * (the controller). This allows userspace to listen for requests with an
600 * offset within that address range. Every time when the kernel receives a
601 * request within the range, an &fw_cdev_event_request2 event will be emitted.
602 * (If the kernel or the client implements ABI version <= 3, an
603 * &fw_cdev_event_request will be generated instead.)
605 * The @closure field is passed back to userspace in these request events.
606 * The @handle field is an out parameter, returning a handle to the allocated
607 * range to be used for later deallocation of the range.
609 * The address range is allocated on all local nodes. The address allocation
610 * is exclusive except for the FCP command and response registers. If an
611 * exclusive address region is already in use, the ioctl fails with errno set
614 * If kernel and client implement ABI version >= 4, the kernel looks up a free
615 * spot of size @length inside [@offset..@region_end) and, if found, writes
616 * the start address of the new CSR back in @offset. I.e. @offset is an
617 * in and out parameter. If this automatic placement of a CSR in a bigger
618 * address range is not desired, the client simply needs to set @region_end
619 * = @offset + @length.
621 * If the kernel or the client implements ABI version <= 3, @region_end is
622 * ignored and effectively assumed to be @offset + @length.
624 * @region_end is only present in a kernel header >= 2.6.36. If necessary,
625 * this can for example be tested by #ifdef FW_CDEV_EVENT_REQUEST2.
627 struct fw_cdev_allocate {
632 __u64 region_end; /* available since kernel version 2.6.36 */
636 * struct fw_cdev_deallocate - Free a CSR address range or isochronous resource
637 * @handle: Handle to the address range or iso resource, as returned by the
638 * kernel when the range or resource was allocated
640 struct fw_cdev_deallocate {
644 #define FW_CDEV_LONG_RESET 0
645 #define FW_CDEV_SHORT_RESET 1
648 * struct fw_cdev_initiate_bus_reset - Initiate a bus reset
649 * @type: %FW_CDEV_SHORT_RESET or %FW_CDEV_LONG_RESET
651 * Initiate a bus reset for the bus this device is on. The bus reset can be
652 * either the original (long) bus reset or the arbitrated (short) bus reset
653 * introduced in 1394a-2000.
655 * The ioctl returns immediately. A subsequent &fw_cdev_event_bus_reset
656 * indicates when the reset actually happened. Since ABI v4, this may be
657 * considerably later than the ioctl because the kernel ensures a grace period
658 * between subsequent bus resets as per IEEE 1394 bus management specification.
660 struct fw_cdev_initiate_bus_reset {
665 * struct fw_cdev_add_descriptor - Add contents to the local node's config ROM
666 * @immediate: If non-zero, immediate key to insert before pointer
667 * @key: Upper 8 bits of root directory pointer
668 * @data: Userspace pointer to contents of descriptor block
669 * @length: Length of descriptor block data, in quadlets
670 * @handle: Handle to the descriptor, written by the kernel
672 * Add a descriptor block and optionally a preceding immediate key to the local
673 * node's Configuration ROM.
675 * The @key field specifies the upper 8 bits of the descriptor root directory
676 * pointer and the @data and @length fields specify the contents. The @key
677 * should be of the form 0xXX000000. The offset part of the root directory entry
678 * will be filled in by the kernel.
680 * If not 0, the @immediate field specifies an immediate key which will be
681 * inserted before the root directory pointer.
683 * @immediate, @key, and @data array elements are CPU-endian quadlets.
685 * If successful, the kernel adds the descriptor and writes back a @handle to
686 * the kernel-side object to be used for later removal of the descriptor block
687 * and immediate key. The kernel will also generate a bus reset to signal the
688 * change of the Configuration ROM to other nodes.
690 * This ioctl affects the Configuration ROMs of all local nodes.
691 * The ioctl only succeeds on device files which represent a local node.
693 struct fw_cdev_add_descriptor {
702 * struct fw_cdev_remove_descriptor - Remove contents from the Configuration ROM
703 * @handle: Handle to the descriptor, as returned by the kernel when the
704 * descriptor was added
706 * Remove a descriptor block and accompanying immediate key from the local
707 * nodes' Configuration ROMs. The kernel will also generate a bus reset to
708 * signal the change of the Configuration ROM to other nodes.
710 struct fw_cdev_remove_descriptor {
714 #define FW_CDEV_ISO_CONTEXT_TRANSMIT 0
715 #define FW_CDEV_ISO_CONTEXT_RECEIVE 1
716 #define FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL 2 /* added in 2.6.36 */
719 * struct fw_cdev_create_iso_context - Create a context for isochronous I/O
720 * @type: %FW_CDEV_ISO_CONTEXT_TRANSMIT or %FW_CDEV_ISO_CONTEXT_RECEIVE or
721 * %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL
722 * @header_size: Header size to strip in single-channel reception
723 * @channel: Channel to bind to in single-channel reception or transmission
724 * @speed: Transmission speed
725 * @closure: To be returned in &fw_cdev_event_iso_interrupt or
726 * &fw_cdev_event_iso_interrupt_multichannel
727 * @handle: Handle to context, written back by kernel
729 * Prior to sending or receiving isochronous I/O, a context must be created.
730 * The context records information about the transmit or receive configuration
731 * and typically maps to an underlying hardware resource. A context is set up
732 * for either sending or receiving. It is bound to a specific isochronous
735 * In case of multichannel reception, @header_size and @channel are ignored
736 * and the channels are selected by %FW_CDEV_IOC_SET_ISO_CHANNELS.
738 * For %FW_CDEV_ISO_CONTEXT_RECEIVE contexts, @header_size must be at least 4
739 * and must be a multiple of 4. It is ignored in other context types.
741 * @speed is ignored in receive context types.
743 * If a context was successfully created, the kernel writes back a handle to the
744 * context, which must be passed in for subsequent operations on that context.
747 * No more than one iso context can be created per fd.
748 * The total number of contexts that all userspace and kernelspace drivers can
749 * create on a card at a time is a hardware limit, typically 4 or 8 contexts per
750 * direction, and of them at most one multichannel receive context.
752 struct fw_cdev_create_iso_context {
762 * struct fw_cdev_set_iso_channels - Select channels in multichannel reception
763 * @channels: Bitmask of channels to listen to
764 * @handle: Handle of the mutichannel receive context
766 * @channels is the bitwise or of 1ULL << n for each channel n to listen to.
768 * The ioctl fails with errno %EBUSY if there is already another receive context
769 * on a channel in @channels. In that case, the bitmask of all unoccupied
770 * channels is returned in @channels.
772 struct fw_cdev_set_iso_channels {
777 #define FW_CDEV_ISO_PAYLOAD_LENGTH(v) (v)
778 #define FW_CDEV_ISO_INTERRUPT (1 << 16)
779 #define FW_CDEV_ISO_SKIP (1 << 17)
780 #define FW_CDEV_ISO_SYNC (1 << 17)
781 #define FW_CDEV_ISO_TAG(v) ((v) << 18)
782 #define FW_CDEV_ISO_SY(v) ((v) << 20)
783 #define FW_CDEV_ISO_HEADER_LENGTH(v) ((v) << 24)
786 * struct fw_cdev_iso_packet - Isochronous packet
787 * @control: Contains the header length (8 uppermost bits),
788 * the sy field (4 bits), the tag field (2 bits), a sync flag
789 * or a skip flag (1 bit), an interrupt flag (1 bit), and the
790 * payload length (16 lowermost bits)
791 * @header: Header and payload in case of a transmit context.
793 * &struct fw_cdev_iso_packet is used to describe isochronous packet queues.
794 * Use the FW_CDEV_ISO_* macros to fill in @control.
795 * The @header array is empty in case of receive contexts.
797 * Context type %FW_CDEV_ISO_CONTEXT_TRANSMIT:
799 * @control.HEADER_LENGTH must be a multiple of 4. It specifies the numbers of
800 * bytes in @header that will be prepended to the packet's payload. These bytes
801 * are copied into the kernel and will not be accessed after the ioctl has
804 * The @control.SY and TAG fields are copied to the iso packet header. These
805 * fields are specified by IEEE 1394a and IEC 61883-1.
807 * The @control.SKIP flag specifies that no packet is to be sent in a frame.
808 * When using this, all other fields except @control.INTERRUPT must be zero.
810 * When a packet with the @control.INTERRUPT flag set has been completed, an
811 * &fw_cdev_event_iso_interrupt event will be sent.
813 * Context type %FW_CDEV_ISO_CONTEXT_RECEIVE:
815 * @control.HEADER_LENGTH must be a multiple of the context's header_size.
816 * If the HEADER_LENGTH is larger than the context's header_size, multiple
817 * packets are queued for this entry.
819 * The @control.SY and TAG fields are ignored.
821 * If the @control.SYNC flag is set, the context drops all packets until a
822 * packet with a sy field is received which matches &fw_cdev_start_iso.sync.
824 * @control.PAYLOAD_LENGTH defines how many payload bytes can be received for
825 * one packet (in addition to payload quadlets that have been defined as headers
826 * and are stripped and returned in the &fw_cdev_event_iso_interrupt structure).
827 * If more bytes are received, the additional bytes are dropped. If less bytes
828 * are received, the remaining bytes in this part of the payload buffer will not
829 * be written to, not even by the next packet. I.e., packets received in
830 * consecutive frames will not necessarily be consecutive in memory. If an
831 * entry has queued multiple packets, the PAYLOAD_LENGTH is divided equally
834 * When a packet with the @control.INTERRUPT flag set has been completed, an
835 * &fw_cdev_event_iso_interrupt event will be sent. An entry that has queued
836 * multiple receive packets is completed when its last packet is completed.
838 * Context type %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL:
840 * Here, &fw_cdev_iso_packet would be more aptly named _iso_buffer_chunk since
841 * it specifies a chunk of the mmap()'ed buffer, while the number and alignment
842 * of packets to be placed into the buffer chunk is not known beforehand.
844 * @control.PAYLOAD_LENGTH is the size of the buffer chunk and specifies room
845 * for header, payload, padding, and trailer bytes of one or more packets.
846 * It must be a multiple of 4.
848 * @control.HEADER_LENGTH, TAG and SY are ignored. SYNC is treated as described
849 * for single-channel reception.
851 * When a buffer chunk with the @control.INTERRUPT flag set has been filled
852 * entirely, an &fw_cdev_event_iso_interrupt_mc event will be sent.
854 struct fw_cdev_iso_packet {
860 * struct fw_cdev_queue_iso - Queue isochronous packets for I/O
861 * @packets: Userspace pointer to an array of &fw_cdev_iso_packet
862 * @data: Pointer into mmap()'ed payload buffer
863 * @size: Size of the @packets array, in bytes
864 * @handle: Isochronous context handle
866 * Queue a number of isochronous packets for reception or transmission.
867 * This ioctl takes a pointer to an array of &fw_cdev_iso_packet structs,
868 * which describe how to transmit from or receive into a contiguous region
869 * of a mmap()'ed payload buffer. As part of transmit packet descriptors,
870 * a series of headers can be supplied, which will be prepended to the
871 * payload during DMA.
873 * The kernel may or may not queue all packets, but will write back updated
874 * values of the @packets, @data and @size fields, so the ioctl can be
875 * resubmitted easily.
877 * In case of a multichannel receive context, @data must be quadlet-aligned
878 * relative to the buffer start.
880 struct fw_cdev_queue_iso {
887 #define FW_CDEV_ISO_CONTEXT_MATCH_TAG0 1
888 #define FW_CDEV_ISO_CONTEXT_MATCH_TAG1 2
889 #define FW_CDEV_ISO_CONTEXT_MATCH_TAG2 4
890 #define FW_CDEV_ISO_CONTEXT_MATCH_TAG3 8
891 #define FW_CDEV_ISO_CONTEXT_MATCH_ALL_TAGS 15
894 * struct fw_cdev_start_iso - Start an isochronous transmission or reception
895 * @cycle: Cycle in which to start I/O. If @cycle is greater than or
896 * equal to 0, the I/O will start on that cycle.
897 * @sync: Determines the value to wait for receive packets that have
898 * the %FW_CDEV_ISO_SYNC bit set
899 * @tags: Tag filter bit mask. Only valid for isochronous reception.
900 * Determines the tag values for which packets will be accepted.
901 * Use FW_CDEV_ISO_CONTEXT_MATCH_* macros to set @tags.
902 * @handle: Isochronous context handle within which to transmit or receive
904 struct fw_cdev_start_iso {
912 * struct fw_cdev_stop_iso - Stop an isochronous transmission or reception
913 * @handle: Handle of isochronous context to stop
915 struct fw_cdev_stop_iso {
920 * struct fw_cdev_flush_iso - flush completed iso packets
921 * @handle: handle of isochronous context to flush
923 * For %FW_CDEV_ISO_CONTEXT_TRANSMIT or %FW_CDEV_ISO_CONTEXT_RECEIVE contexts,
924 * report any completed packets.
926 * For %FW_CDEV_ISO_CONTEXT_RECEIVE_MULTICHANNEL contexts, report the current
927 * offset in the receive buffer, if it has changed; this is typically in the
928 * middle of some buffer chunk.
930 * Any %FW_CDEV_EVENT_ISO_INTERRUPT or %FW_CDEV_EVENT_ISO_INTERRUPT_MULTICHANNEL
931 * events generated by this ioctl are sent synchronously, i.e., are available
932 * for reading from the file descriptor when this ioctl returns.
934 struct fw_cdev_flush_iso {
939 * struct fw_cdev_get_cycle_timer - read cycle timer register
940 * @local_time: system time, in microseconds since the Epoch
941 * @cycle_timer: Cycle Time register contents
943 * Same as %FW_CDEV_IOC_GET_CYCLE_TIMER2, but fixed to use %CLOCK_REALTIME
944 * and only with microseconds resolution.
946 * In version 1 and 2 of the ABI, this ioctl returned unreliable (non-
947 * monotonic) @cycle_timer values on certain controllers.
949 struct fw_cdev_get_cycle_timer {
955 * struct fw_cdev_get_cycle_timer2 - read cycle timer register
956 * @tv_sec: system time, seconds
957 * @tv_nsec: system time, sub-seconds part in nanoseconds
958 * @clk_id: input parameter, clock from which to get the system time
959 * @cycle_timer: Cycle Time register contents
961 * The %FW_CDEV_IOC_GET_CYCLE_TIMER2 ioctl reads the isochronous cycle timer
962 * and also the system clock. This allows to correlate reception time of
963 * isochronous packets with system time.
965 * @clk_id lets you choose a clock like with POSIX' clock_gettime function.
966 * Supported @clk_id values are POSIX' %CLOCK_REALTIME and %CLOCK_MONOTONIC
967 * and Linux' %CLOCK_MONOTONIC_RAW.
969 * @cycle_timer consists of 7 bits cycleSeconds, 13 bits cycleCount, and
970 * 12 bits cycleOffset, in host byte order. Cf. the Cycle Time register
971 * per IEEE 1394 or Isochronous Cycle Timer register per OHCI-1394.
973 struct fw_cdev_get_cycle_timer2 {
981 * struct fw_cdev_allocate_iso_resource - (De)allocate a channel or bandwidth
982 * @closure: Passed back to userspace in corresponding iso resource events
983 * @channels: Isochronous channels of which one is to be (de)allocated
984 * @bandwidth: Isochronous bandwidth units to be (de)allocated
985 * @handle: Handle to the allocation, written by the kernel (only valid in
986 * case of %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ioctls)
988 * The %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ioctl initiates allocation of an
989 * isochronous channel and/or of isochronous bandwidth at the isochronous
990 * resource manager (IRM). Only one of the channels specified in @channels is
991 * allocated. An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED is sent after
992 * communication with the IRM, indicating success or failure in the event data.
993 * The kernel will automatically reallocate the resources after bus resets.
994 * Should a reallocation fail, an %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event
995 * will be sent. The kernel will also automatically deallocate the resources
996 * when the file descriptor is closed.
998 * The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE ioctl can be used to initiate
999 * deallocation of resources which were allocated as described above.
1000 * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation.
1002 * The %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE ioctl is a variant of allocation
1003 * without automatic re- or deallocation.
1004 * An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event concludes this operation,
1005 * indicating success or failure in its data.
1007 * The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE ioctl works like
1008 * %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE except that resources are freed
1009 * instead of allocated.
1010 * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation.
1012 * To summarize, %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE allocates iso resources
1013 * for the lifetime of the fd or @handle.
1014 * In contrast, %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE allocates iso resources
1015 * for the duration of a bus generation.
1017 * @channels is a host-endian bitfield with the least significant bit
1018 * representing channel 0 and the most significant bit representing channel 63:
1019 * 1ULL << c for each channel c that is a candidate for (de)allocation.
1021 * @bandwidth is expressed in bandwidth allocation units, i.e. the time to send
1022 * one quadlet of data (payload or header data) at speed S1600.
1024 struct fw_cdev_allocate_iso_resource {
1032 * struct fw_cdev_send_stream_packet - send an asynchronous stream packet
1033 * @length: Length of outgoing payload, in bytes
1034 * @tag: Data format tag
1035 * @channel: Isochronous channel to transmit to
1036 * @sy: Synchronization code
1037 * @closure: Passed back to userspace in the response event
1038 * @data: Userspace pointer to payload
1039 * @generation: The bus generation where packet is valid
1040 * @speed: Speed to transmit at
1042 * The %FW_CDEV_IOC_SEND_STREAM_PACKET ioctl sends an asynchronous stream packet
1043 * to every device which is listening to the specified channel. The kernel
1044 * writes an &fw_cdev_event_response event which indicates success or failure of
1047 struct fw_cdev_send_stream_packet {
1059 * struct fw_cdev_send_phy_packet - send a PHY packet
1060 * @closure: Passed back to userspace in the PHY-packet-sent event
1061 * @data: First and second quadlet of the PHY packet
1062 * @generation: The bus generation where packet is valid
1064 * The %FW_CDEV_IOC_SEND_PHY_PACKET ioctl sends a PHY packet to all nodes
1065 * on the same card as this device. After transmission, an
1066 * %FW_CDEV_EVENT_PHY_PACKET_SENT event is generated.
1068 * The payload @data\[\] shall be specified in host byte order. Usually,
1069 * @data\[1\] needs to be the bitwise inverse of @data\[0\]. VersaPHY packets
1070 * are an exception to this rule.
1072 * The ioctl is only permitted on device files which represent a local node.
1074 struct fw_cdev_send_phy_packet {
1081 * struct fw_cdev_receive_phy_packets - start reception of PHY packets
1082 * @closure: Passed back to userspace in phy packet events
1084 * This ioctl activates issuing of %FW_CDEV_EVENT_PHY_PACKET_RECEIVED due to
1085 * incoming PHY packets from any node on the same bus as the device.
1087 * The ioctl is only permitted on device files which represent a local node.
1089 struct fw_cdev_receive_phy_packets {
1093 #define FW_CDEV_VERSION 3 /* Meaningless legacy macro; don't use it. */
1095 #endif /* _LINUX_FIREWIRE_CDEV_H */