Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Stefan Richter | de4394f | 2006-07-03 12:02:29 -0400 | [diff] [blame] | 15 | #include <linux/spinlock_types.h> |
Stefan Richter | 612262a | 2008-08-26 00:17:30 +0200 | [diff] [blame^] | 16 | #include <linux/wait.h> |
Stefan Richter | de4394f | 2006-07-03 12:02:29 -0400 | [diff] [blame] | 17 | #include <asm/atomic.h> |
| 18 | #include <asm/types.h> |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include "dma.h" |
| 21 | |
Stefan Richter | de4394f | 2006-07-03 12:02:29 -0400 | [diff] [blame] | 22 | struct hpsb_host; |
| 23 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | /* high-level ISO interface */ |
| 25 | |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 26 | /* |
| 27 | * This API sends and receives isochronous packets on a large, |
| 28 | * virtually-contiguous kernel memory buffer. The buffer may be mapped |
| 29 | * into a user-space process for zero-copy transmission and reception. |
| 30 | * |
| 31 | * There are no explicit boundaries between packets in the buffer. A |
| 32 | * packet may be transmitted or received at any location. However, |
| 33 | * low-level drivers may impose certain restrictions on alignment or |
| 34 | * size of packets. (e.g. in OHCI no packet may cross a page boundary, |
| 35 | * and packets should be quadlet-aligned) |
| 36 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | /* Packet descriptor - the API maintains a ring buffer of these packet |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 39 | * descriptors in kernel memory (hpsb_iso.infos[]). */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | struct hpsb_iso_packet_info { |
| 41 | /* offset of data payload relative to the first byte of the buffer */ |
| 42 | __u32 offset; |
| 43 | |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 44 | /* length of the data payload, in bytes (not including the isochronous |
| 45 | * header) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | __u16 len; |
| 47 | |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 48 | /* (recv only) the cycle number (mod 8000) on which the packet was |
| 49 | * received */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | __u16 cycle; |
| 51 | |
| 52 | /* (recv only) channel on which the packet was received */ |
| 53 | __u8 channel; |
| 54 | |
| 55 | /* 2-bit 'tag' and 4-bit 'sy' fields of the isochronous header */ |
| 56 | __u8 tag; |
| 57 | __u8 sy; |
Ben Collins | 1934b8b | 2005-07-09 20:01:23 -0400 | [diff] [blame] | 58 | |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 59 | /* length in bytes of the packet including header/trailer. |
| 60 | * MUST be at structure end, since the first part of this structure is |
| 61 | * also defined in raw1394.h (i.e. struct raw1394_iso_packet_info), is |
| 62 | * copied to userspace and is accessed there through libraw1394. */ |
Ben Collins | 1934b8b | 2005-07-09 20:01:23 -0400 | [diff] [blame] | 63 | __u16 total_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | }; |
| 65 | |
| 66 | enum hpsb_iso_type { HPSB_ISO_RECV = 0, HPSB_ISO_XMIT = 1 }; |
| 67 | |
| 68 | /* The mode of the dma when receiving iso data. Must be supported by chip */ |
| 69 | enum raw1394_iso_dma_recv_mode { |
| 70 | HPSB_ISO_DMA_DEFAULT = -1, |
| 71 | HPSB_ISO_DMA_OLD_ABI = 0, |
| 72 | HPSB_ISO_DMA_BUFFERFILL = 1, |
| 73 | HPSB_ISO_DMA_PACKET_PER_BUFFER = 2 |
| 74 | }; |
| 75 | |
| 76 | struct hpsb_iso { |
| 77 | enum hpsb_iso_type type; |
| 78 | |
| 79 | /* pointer to low-level driver and its private data */ |
| 80 | struct hpsb_host *host; |
| 81 | void *hostdata; |
| 82 | |
| 83 | /* a function to be called (from interrupt context) after |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 84 | * outgoing packets have been sent, or incoming packets have |
| 85 | * arrived */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | void (*callback)(struct hpsb_iso*); |
| 87 | |
| 88 | /* wait for buffer space */ |
| 89 | wait_queue_head_t waitq; |
| 90 | |
| 91 | int speed; /* IEEE1394_SPEED_100, 200, or 400 */ |
| 92 | int channel; /* -1 if multichannel */ |
| 93 | int dma_mode; /* dma receive mode */ |
| 94 | |
| 95 | |
| 96 | /* greatest # of packets between interrupts - controls |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 97 | * the maximum latency of the buffer */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | int irq_interval; |
| 99 | |
| 100 | /* the buffer for packet data payloads */ |
| 101 | struct dma_region data_buf; |
| 102 | |
| 103 | /* size of data_buf, in bytes (always a multiple of PAGE_SIZE) */ |
| 104 | unsigned int buf_size; |
| 105 | |
| 106 | /* # of packets in the ringbuffer */ |
| 107 | unsigned int buf_packets; |
| 108 | |
| 109 | /* protects packet cursors */ |
| 110 | spinlock_t lock; |
| 111 | |
| 112 | /* the index of the next packet that will be produced |
| 113 | or consumed by the user */ |
| 114 | int first_packet; |
| 115 | |
| 116 | /* the index of the next packet that will be transmitted |
| 117 | or received by the 1394 hardware */ |
| 118 | int pkt_dma; |
| 119 | |
| 120 | /* how many packets, starting at first_packet: |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 121 | * (transmit) are ready to be filled with data |
| 122 | * (receive) contain received data */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | int n_ready_packets; |
| 124 | |
| 125 | /* how many times the buffer has overflowed or underflowed */ |
| 126 | atomic_t overflows; |
Pieter Palmers | cc9429b | 2008-03-19 22:10:59 +0100 | [diff] [blame] | 127 | /* how many cycles were skipped for a given context */ |
| 128 | atomic_t skips; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Ben Collins | 1934b8b | 2005-07-09 20:01:23 -0400 | [diff] [blame] | 130 | /* Current number of bytes lost in discarded packets */ |
| 131 | int bytes_discarded; |
| 132 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | /* private flags to track initialization progress */ |
| 134 | #define HPSB_ISO_DRIVER_INIT (1<<0) |
| 135 | #define HPSB_ISO_DRIVER_STARTED (1<<1) |
| 136 | unsigned int flags; |
| 137 | |
| 138 | /* # of packets left to prebuffer (xmit only) */ |
| 139 | int prebuffer; |
| 140 | |
| 141 | /* starting cycle for DMA (xmit only) */ |
| 142 | int start_cycle; |
| 143 | |
| 144 | /* cycle at which next packet will be transmitted, |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 145 | * -1 if not known */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | int xmit_cycle; |
| 147 | |
| 148 | /* ringbuffer of packet descriptors in regular kernel memory |
| 149 | * XXX Keep this last, since we use over-allocated memory from |
| 150 | * this entry to fill this field. */ |
| 151 | struct hpsb_iso_packet_info *infos; |
| 152 | }; |
| 153 | |
| 154 | /* functions available to high-level drivers (e.g. raw1394) */ |
| 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | struct hpsb_iso* hpsb_iso_xmit_init(struct hpsb_host *host, |
| 157 | unsigned int data_buf_size, |
| 158 | unsigned int buf_packets, |
| 159 | int channel, |
| 160 | int speed, |
| 161 | int irq_interval, |
| 162 | void (*callback)(struct hpsb_iso*)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | struct hpsb_iso* hpsb_iso_recv_init(struct hpsb_host *host, |
| 164 | unsigned int data_buf_size, |
| 165 | unsigned int buf_packets, |
| 166 | int channel, |
| 167 | int dma_mode, |
| 168 | int irq_interval, |
| 169 | void (*callback)(struct hpsb_iso*)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | int hpsb_iso_recv_listen_channel(struct hpsb_iso *iso, unsigned char channel); |
| 171 | int hpsb_iso_recv_unlisten_channel(struct hpsb_iso *iso, unsigned char channel); |
| 172 | int hpsb_iso_recv_set_channel_mask(struct hpsb_iso *iso, u64 mask); |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 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); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | void hpsb_iso_stop(struct hpsb_iso *iso); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | void hpsb_iso_shutdown(struct hpsb_iso *iso); |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 179 | int hpsb_iso_xmit_queue_packet(struct hpsb_iso *iso, u32 offset, u16 len, |
| 180 | u8 tag, u8 sy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | int hpsb_iso_xmit_sync(struct hpsb_iso *iso); |
Stefan Richter | afd6546 | 2007-03-05 03:06:23 +0100 | [diff] [blame] | 182 | int hpsb_iso_recv_release_packets(struct hpsb_iso *recv, |
| 183 | unsigned int n_packets); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | int hpsb_iso_recv_flush(struct hpsb_iso *iso); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 185 | int hpsb_iso_n_ready(struct hpsb_iso *iso); |
| 186 | |
| 187 | /* the following are callbacks available to low-level drivers */ |
| 188 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 189 | void hpsb_iso_packet_sent(struct hpsb_iso *iso, int cycle, int error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | void hpsb_iso_packet_received(struct hpsb_iso *iso, u32 offset, u16 len, |
Stefan Richter | e1d118f | 2006-07-03 12:02:28 -0400 | [diff] [blame] | 191 | u16 total_len, u16 cycle, u8 channel, u8 tag, |
| 192 | u8 sy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | void hpsb_iso_wake(struct hpsb_iso *iso); |
| 194 | |
| 195 | #endif /* IEEE1394_ISO_H */ |