blob: 1210a97e8685624f7a5ccf669e892111d619d462 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * IEEE 1394 for Linux
3 *
4 * kernel ISO transmission/reception
5 *
6 * Copyright (C) 2002 Maas Digital LLC
7 *
8 * This code is licensed under the GPL. See the file COPYING in the root
9 * directory of the kernel sources for details.
10 */
11
12#ifndef IEEE1394_ISO_H
13#define IEEE1394_ISO_H
14
Stefan Richterde4394f2006-07-03 12:02:29 -040015#include <linux/spinlock_types.h>
16#include <asm/atomic.h>
17#include <asm/types.h>
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include "dma.h"
20
Stefan Richterde4394f2006-07-03 12:02:29 -040021struct hpsb_host;
22
Linus Torvalds1da177e2005-04-16 15:20:36 -070023/* high-level ISO interface */
24
Stefan Richtere1d118f2006-07-03 12:02:28 -040025/*
26 * This API sends and receives isochronous packets on a large,
27 * virtually-contiguous kernel memory buffer. The buffer may be mapped
28 * into a user-space process for zero-copy transmission and reception.
29 *
30 * There are no explicit boundaries between packets in the buffer. A
31 * packet may be transmitted or received at any location. However,
32 * low-level drivers may impose certain restrictions on alignment or
33 * size of packets. (e.g. in OHCI no packet may cross a page boundary,
34 * and packets should be quadlet-aligned)
35 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
37/* Packet descriptor - the API maintains a ring buffer of these packet
Stefan Richtere1d118f2006-07-03 12:02:28 -040038 * descriptors in kernel memory (hpsb_iso.infos[]). */
Linus Torvalds1da177e2005-04-16 15:20:36 -070039struct hpsb_iso_packet_info {
40 /* offset of data payload relative to the first byte of the buffer */
41 __u32 offset;
42
Stefan Richtere1d118f2006-07-03 12:02:28 -040043 /* length of the data payload, in bytes (not including the isochronous
44 * header) */
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 __u16 len;
46
Stefan Richtere1d118f2006-07-03 12:02:28 -040047 /* (recv only) the cycle number (mod 8000) on which the packet was
48 * received */
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 __u16 cycle;
50
51 /* (recv only) channel on which the packet was received */
52 __u8 channel;
53
54 /* 2-bit 'tag' and 4-bit 'sy' fields of the isochronous header */
55 __u8 tag;
56 __u8 sy;
Ben Collins1934b8b2005-07-09 20:01:23 -040057
Stefan Richtere1d118f2006-07-03 12:02:28 -040058 /* length in bytes of the packet including header/trailer.
59 * MUST be at structure end, since the first part of this structure is
60 * also defined in raw1394.h (i.e. struct raw1394_iso_packet_info), is
61 * copied to userspace and is accessed there through libraw1394. */
Ben Collins1934b8b2005-07-09 20:01:23 -040062 __u16 total_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063};
64
65enum hpsb_iso_type { HPSB_ISO_RECV = 0, HPSB_ISO_XMIT = 1 };
66
67/* The mode of the dma when receiving iso data. Must be supported by chip */
68enum raw1394_iso_dma_recv_mode {
69 HPSB_ISO_DMA_DEFAULT = -1,
70 HPSB_ISO_DMA_OLD_ABI = 0,
71 HPSB_ISO_DMA_BUFFERFILL = 1,
72 HPSB_ISO_DMA_PACKET_PER_BUFFER = 2
73};
74
75struct hpsb_iso {
76 enum hpsb_iso_type type;
77
78 /* pointer to low-level driver and its private data */
79 struct hpsb_host *host;
80 void *hostdata;
81
82 /* a function to be called (from interrupt context) after
Stefan Richtere1d118f2006-07-03 12:02:28 -040083 * outgoing packets have been sent, or incoming packets have
84 * arrived */
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 void (*callback)(struct hpsb_iso*);
86
87 /* wait for buffer space */
88 wait_queue_head_t waitq;
89
90 int speed; /* IEEE1394_SPEED_100, 200, or 400 */
91 int channel; /* -1 if multichannel */
92 int dma_mode; /* dma receive mode */
93
94
95 /* greatest # of packets between interrupts - controls
Stefan Richtere1d118f2006-07-03 12:02:28 -040096 * the maximum latency of the buffer */
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 int irq_interval;
98
99 /* the buffer for packet data payloads */
100 struct dma_region data_buf;
101
102 /* size of data_buf, in bytes (always a multiple of PAGE_SIZE) */
103 unsigned int buf_size;
104
105 /* # of packets in the ringbuffer */
106 unsigned int buf_packets;
107
108 /* protects packet cursors */
109 spinlock_t lock;
110
111 /* the index of the next packet that will be produced
112 or consumed by the user */
113 int first_packet;
114
115 /* the index of the next packet that will be transmitted
116 or received by the 1394 hardware */
117 int pkt_dma;
118
119 /* how many packets, starting at first_packet:
Stefan Richtere1d118f2006-07-03 12:02:28 -0400120 * (transmit) are ready to be filled with data
121 * (receive) contain received data */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 int n_ready_packets;
123
124 /* how many times the buffer has overflowed or underflowed */
125 atomic_t overflows;
126
Ben Collins1934b8b2005-07-09 20:01:23 -0400127 /* Current number of bytes lost in discarded packets */
128 int bytes_discarded;
129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 /* private flags to track initialization progress */
131#define HPSB_ISO_DRIVER_INIT (1<<0)
132#define HPSB_ISO_DRIVER_STARTED (1<<1)
133 unsigned int flags;
134
135 /* # of packets left to prebuffer (xmit only) */
136 int prebuffer;
137
138 /* starting cycle for DMA (xmit only) */
139 int start_cycle;
140
141 /* cycle at which next packet will be transmitted,
Stefan Richtere1d118f2006-07-03 12:02:28 -0400142 * -1 if not known */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 int xmit_cycle;
144
145 /* ringbuffer of packet descriptors in regular kernel memory
146 * XXX Keep this last, since we use over-allocated memory from
147 * this entry to fill this field. */
148 struct hpsb_iso_packet_info *infos;
149};
150
151/* functions available to high-level drivers (e.g. raw1394) */
152
153/* allocate the buffer and DMA context */
154
155struct hpsb_iso* hpsb_iso_xmit_init(struct hpsb_host *host,
156 unsigned int data_buf_size,
157 unsigned int buf_packets,
158 int channel,
159 int speed,
160 int irq_interval,
161 void (*callback)(struct hpsb_iso*));
162
163/* note: if channel = -1, multi-channel receive is enabled */
164struct hpsb_iso* hpsb_iso_recv_init(struct hpsb_host *host,
165 unsigned int data_buf_size,
166 unsigned int buf_packets,
167 int channel,
168 int dma_mode,
169 int irq_interval,
170 void (*callback)(struct hpsb_iso*));
171
172/* multi-channel only */
173int hpsb_iso_recv_listen_channel(struct hpsb_iso *iso, unsigned char channel);
174int hpsb_iso_recv_unlisten_channel(struct hpsb_iso *iso, unsigned char channel);
175int hpsb_iso_recv_set_channel_mask(struct hpsb_iso *iso, u64 mask);
176
177/* start/stop DMA */
Stefan Richtere1d118f2006-07-03 12:02:28 -0400178int hpsb_iso_xmit_start(struct hpsb_iso *iso, int start_on_cycle,
179 int prebuffer);
180int hpsb_iso_recv_start(struct hpsb_iso *iso, int start_on_cycle,
181 int tag_mask, int sync);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182void hpsb_iso_stop(struct hpsb_iso *iso);
183
184/* deallocate buffer and DMA context */
185void hpsb_iso_shutdown(struct hpsb_iso *iso);
186
Stefan Richtere1d118f2006-07-03 12:02:28 -0400187/* queue a packet for transmission.
188 * 'offset' is relative to the beginning of the DMA buffer, where the packet's
189 * data payload should already have been placed. */
190int hpsb_iso_xmit_queue_packet(struct hpsb_iso *iso, u32 offset, u16 len,
191 u8 tag, u8 sy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193/* wait until all queued packets have been transmitted to the bus */
194int hpsb_iso_xmit_sync(struct hpsb_iso *iso);
195
196/* N packets have been read out of the buffer, re-use the buffer space */
Stefan Richtere1d118f2006-07-03 12:02:28 -0400197int hpsb_iso_recv_release_packets(struct hpsb_iso *recv,
198 unsigned int n_packets);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
200/* check for arrival of new packets immediately (even if irq_interval
Stefan Richtere1d118f2006-07-03 12:02:28 -0400201 * has not yet been reached) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202int hpsb_iso_recv_flush(struct hpsb_iso *iso);
203
204/* returns # of packets ready to send or receive */
205int hpsb_iso_n_ready(struct hpsb_iso *iso);
206
207/* the following are callbacks available to low-level drivers */
208
209/* call after a packet has been transmitted to the bus (interrupt context is OK)
Stefan Richtere1d118f2006-07-03 12:02:28 -0400210 * 'cycle' is the _exact_ cycle the packet was sent on
211 * 'error' should be non-zero if some sort of error occurred when sending the
212 * packet */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213void hpsb_iso_packet_sent(struct hpsb_iso *iso, int cycle, int error);
214
215/* call after a packet has been received (interrupt context OK) */
216void hpsb_iso_packet_received(struct hpsb_iso *iso, u32 offset, u16 len,
Stefan Richtere1d118f2006-07-03 12:02:28 -0400217 u16 total_len, u16 cycle, u8 channel, u8 tag,
218 u8 sy);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220/* call to wake waiting processes after buffer space has opened up. */
221void hpsb_iso_wake(struct hpsb_iso *iso);
222
223#endif /* IEEE1394_ISO_H */