]> Pileus Git - ~andy/linux/blob - drivers/ieee1394/iso.h
[PATCH] ieee1394: coding style and comment fixes in midlayer header files
[~andy/linux] / drivers / ieee1394 / iso.h
1 /*
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
15 #include "hosts.h"
16 #include "dma.h"
17
18 /* high-level ISO interface */
19
20 /*
21  * This API sends and receives isochronous packets on a large,
22  * virtually-contiguous kernel memory buffer. The buffer may be mapped
23  * into a user-space process for zero-copy transmission and reception.
24  *
25  * There are no explicit boundaries between packets in the buffer. A
26  * packet may be transmitted or received at any location. However,
27  * low-level drivers may impose certain restrictions on alignment or
28  * size of packets. (e.g. in OHCI no packet may cross a page boundary,
29  * and packets should be quadlet-aligned)
30  */
31
32 /* Packet descriptor - the API maintains a ring buffer of these packet
33  * descriptors in kernel memory (hpsb_iso.infos[]).  */
34 struct hpsb_iso_packet_info {
35         /* offset of data payload relative to the first byte of the buffer */
36         __u32 offset;
37
38         /* length of the data payload, in bytes (not including the isochronous
39          * header) */
40         __u16 len;
41
42         /* (recv only) the cycle number (mod 8000) on which the packet was
43          * received */
44         __u16 cycle;
45
46         /* (recv only) channel on which the packet was received */
47         __u8 channel;
48
49         /* 2-bit 'tag' and 4-bit 'sy' fields of the isochronous header */
50         __u8 tag;
51         __u8 sy;
52
53         /* length in bytes of the packet including header/trailer.
54          * MUST be at structure end, since the first part of this structure is
55          * also defined in raw1394.h (i.e. struct raw1394_iso_packet_info), is
56          * copied to userspace and is accessed there through libraw1394. */
57         __u16 total_len;
58 };
59
60 enum hpsb_iso_type { HPSB_ISO_RECV = 0, HPSB_ISO_XMIT = 1 };
61
62 /* The mode of the dma when receiving iso data. Must be supported by chip */
63 enum raw1394_iso_dma_recv_mode {
64         HPSB_ISO_DMA_DEFAULT = -1,
65         HPSB_ISO_DMA_OLD_ABI = 0,
66         HPSB_ISO_DMA_BUFFERFILL = 1,
67         HPSB_ISO_DMA_PACKET_PER_BUFFER = 2
68 };
69
70 struct hpsb_iso {
71         enum hpsb_iso_type type;
72
73         /* pointer to low-level driver and its private data */
74         struct hpsb_host *host;
75         void *hostdata;
76
77         /* a function to be called (from interrupt context) after
78          * outgoing packets have been sent, or incoming packets have
79          * arrived */
80         void (*callback)(struct hpsb_iso*);
81
82         /* wait for buffer space */
83         wait_queue_head_t waitq;
84
85         int speed; /* IEEE1394_SPEED_100, 200, or 400 */
86         int channel; /* -1 if multichannel */
87         int dma_mode; /* dma receive mode */
88
89
90         /* greatest # of packets between interrupts - controls
91          * the maximum latency of the buffer */
92         int irq_interval;
93
94         /* the buffer for packet data payloads */
95         struct dma_region data_buf;
96
97         /* size of data_buf, in bytes (always a multiple of PAGE_SIZE) */
98         unsigned int buf_size;
99
100         /* # of packets in the ringbuffer */
101         unsigned int buf_packets;
102
103         /* protects packet cursors */
104         spinlock_t lock;
105
106         /* the index of the next packet that will be produced
107            or consumed by the user */
108         int first_packet;
109
110         /* the index of the next packet that will be transmitted
111            or received by the 1394 hardware */
112         int pkt_dma;
113
114         /* how many packets, starting at first_packet:
115          * (transmit) are ready to be filled with data
116          * (receive)  contain received data */
117         int n_ready_packets;
118
119         /* how many times the buffer has overflowed or underflowed */
120         atomic_t overflows;
121
122         /* Current number of bytes lost in discarded packets */
123         int bytes_discarded;
124
125         /* private flags to track initialization progress */
126 #define HPSB_ISO_DRIVER_INIT     (1<<0)
127 #define HPSB_ISO_DRIVER_STARTED  (1<<1)
128         unsigned int flags;
129
130         /* # of packets left to prebuffer (xmit only) */
131         int prebuffer;
132
133         /* starting cycle for DMA (xmit only) */
134         int start_cycle;
135
136         /* cycle at which next packet will be transmitted,
137          * -1 if not known */
138         int xmit_cycle;
139
140         /* ringbuffer of packet descriptors in regular kernel memory
141          * XXX Keep this last, since we use over-allocated memory from
142          * this entry to fill this field. */
143         struct hpsb_iso_packet_info *infos;
144 };
145
146 /* functions available to high-level drivers (e.g. raw1394) */
147
148 /* allocate the buffer and DMA context */
149
150 struct hpsb_iso* hpsb_iso_xmit_init(struct hpsb_host *host,
151                                     unsigned int data_buf_size,
152                                     unsigned int buf_packets,
153                                     int channel,
154                                     int speed,
155                                     int irq_interval,
156                                     void (*callback)(struct hpsb_iso*));
157
158 /* note: if channel = -1, multi-channel receive is enabled */
159 struct hpsb_iso* hpsb_iso_recv_init(struct hpsb_host *host,
160                                     unsigned int data_buf_size,
161                                     unsigned int buf_packets,
162                                     int channel,
163                                     int dma_mode,
164                                     int irq_interval,
165                                     void (*callback)(struct hpsb_iso*));
166
167 /* multi-channel only */
168 int hpsb_iso_recv_listen_channel(struct hpsb_iso *iso, unsigned char channel);
169 int hpsb_iso_recv_unlisten_channel(struct hpsb_iso *iso, unsigned char channel);
170 int hpsb_iso_recv_set_channel_mask(struct hpsb_iso *iso, u64 mask);
171
172 /* start/stop DMA */
173 int hpsb_iso_xmit_start(struct hpsb_iso *iso, int start_on_cycle,
174                         int prebuffer);
175 int hpsb_iso_recv_start(struct hpsb_iso *iso, int start_on_cycle,
176                         int tag_mask, int sync);
177 void hpsb_iso_stop(struct hpsb_iso *iso);
178
179 /* deallocate buffer and DMA context */
180 void hpsb_iso_shutdown(struct hpsb_iso *iso);
181
182 /* queue a packet for transmission.
183  * 'offset' is relative to the beginning of the DMA buffer, where the packet's
184  * data payload should already have been placed. */
185 int hpsb_iso_xmit_queue_packet(struct hpsb_iso *iso, u32 offset, u16 len,
186                                u8 tag, u8 sy);
187
188 /* wait until all queued packets have been transmitted to the bus */
189 int hpsb_iso_xmit_sync(struct hpsb_iso *iso);
190
191 /* N packets have been read out of the buffer, re-use the buffer space */
192 int  hpsb_iso_recv_release_packets(struct hpsb_iso *recv,
193                                    unsigned int n_packets);
194
195 /* check for arrival of new packets immediately (even if irq_interval
196  * has not yet been reached) */
197 int hpsb_iso_recv_flush(struct hpsb_iso *iso);
198
199 /* returns # of packets ready to send or receive */
200 int hpsb_iso_n_ready(struct hpsb_iso *iso);
201
202 /* the following are callbacks available to low-level drivers */
203
204 /* call after a packet has been transmitted to the bus (interrupt context is OK)
205  * 'cycle' is the _exact_ cycle the packet was sent on
206  * 'error' should be non-zero if some sort of error occurred when sending the
207  *  packet */
208 void hpsb_iso_packet_sent(struct hpsb_iso *iso, int cycle, int error);
209
210 /* call after a packet has been received (interrupt context OK) */
211 void hpsb_iso_packet_received(struct hpsb_iso *iso, u32 offset, u16 len,
212                               u16 total_len, u16 cycle, u8 channel, u8 tag,
213                               u8 sy);
214
215 /* call to wake waiting processes after buffer space has opened up. */
216 void hpsb_iso_wake(struct hpsb_iso *iso);
217
218 #endif /* IEEE1394_ISO_H */