iso.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. #ifndef IEEE1394_ISO_H
  12. #define IEEE1394_ISO_H
  13. #include <linux/spinlock_types.h>
  14. #include <linux/wait.h>
  15. #include <asm/atomic.h>
  16. #include <asm/types.h>
  17. #include "dma.h"
  18. struct hpsb_host;
  19. /* high-level ISO interface */
  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. /* Packet descriptor - the API maintains a ring buffer of these packet
  32. * descriptors in kernel memory (hpsb_iso.infos[]). */
  33. struct hpsb_iso_packet_info {
  34. /* offset of data payload relative to the first byte of the buffer */
  35. __u32 offset;
  36. /* length of the data payload, in bytes (not including the isochronous
  37. * header) */
  38. __u16 len;
  39. /* (recv only) the cycle number (mod 8000) on which the packet was
  40. * received */
  41. __u16 cycle;
  42. /* (recv only) channel on which the packet was received */
  43. __u8 channel;
  44. /* 2-bit 'tag' and 4-bit 'sy' fields of the isochronous header */
  45. __u8 tag;
  46. __u8 sy;
  47. /* length in bytes of the packet including header/trailer.
  48. * MUST be at structure end, since the first part of this structure is
  49. * also defined in raw1394.h (i.e. struct raw1394_iso_packet_info), is
  50. * copied to userspace and is accessed there through libraw1394. */
  51. __u16 total_len;
  52. };
  53. enum hpsb_iso_type { HPSB_ISO_RECV = 0, HPSB_ISO_XMIT = 1 };
  54. /* The mode of the dma when receiving iso data. Must be supported by chip */
  55. enum raw1394_iso_dma_recv_mode {
  56. HPSB_ISO_DMA_DEFAULT = -1,
  57. HPSB_ISO_DMA_OLD_ABI = 0,
  58. HPSB_ISO_DMA_BUFFERFILL = 1,
  59. HPSB_ISO_DMA_PACKET_PER_BUFFER = 2
  60. };
  61. struct hpsb_iso {
  62. enum hpsb_iso_type type;
  63. /* pointer to low-level driver and its private data */
  64. struct hpsb_host *host;
  65. void *hostdata;
  66. /* a function to be called (from interrupt context) after
  67. * outgoing packets have been sent, or incoming packets have
  68. * arrived */
  69. void (*callback)(struct hpsb_iso*);
  70. /* wait for buffer space */
  71. wait_queue_head_t waitq;
  72. int speed; /* IEEE1394_SPEED_100, 200, or 400 */
  73. int channel; /* -1 if multichannel */
  74. int dma_mode; /* dma receive mode */
  75. /* greatest # of packets between interrupts - controls
  76. * the maximum latency of the buffer */
  77. int irq_interval;
  78. /* the buffer for packet data payloads */
  79. struct dma_region data_buf;
  80. /* size of data_buf, in bytes (always a multiple of PAGE_SIZE) */
  81. unsigned int buf_size;
  82. /* # of packets in the ringbuffer */
  83. unsigned int buf_packets;
  84. /* protects packet cursors */
  85. spinlock_t lock;
  86. /* the index of the next packet that will be produced
  87. or consumed by the user */
  88. int first_packet;
  89. /* the index of the next packet that will be transmitted
  90. or received by the 1394 hardware */
  91. int pkt_dma;
  92. /* how many packets, starting at first_packet:
  93. * (transmit) are ready to be filled with data
  94. * (receive) contain received data */
  95. int n_ready_packets;
  96. /* how many times the buffer has overflowed or underflowed */
  97. atomic_t overflows;
  98. /* how many cycles were skipped for a given context */
  99. atomic_t skips;
  100. /* Current number of bytes lost in discarded packets */
  101. int bytes_discarded;
  102. /* private flags to track initialization progress */
  103. #define HPSB_ISO_DRIVER_INIT (1<<0)
  104. #define HPSB_ISO_DRIVER_STARTED (1<<1)
  105. unsigned int flags;
  106. /* # of packets left to prebuffer (xmit only) */
  107. int prebuffer;
  108. /* starting cycle for DMA (xmit only) */
  109. int start_cycle;
  110. /* cycle at which next packet will be transmitted,
  111. * -1 if not known */
  112. int xmit_cycle;
  113. /* ringbuffer of packet descriptors in regular kernel memory
  114. * XXX Keep this last, since we use over-allocated memory from
  115. * this entry to fill this field. */
  116. struct hpsb_iso_packet_info *infos;
  117. };
  118. /* functions available to high-level drivers (e.g. raw1394) */
  119. struct hpsb_iso* hpsb_iso_xmit_init(struct hpsb_host *host,
  120. unsigned int data_buf_size,
  121. unsigned int buf_packets,
  122. int channel,
  123. int speed,
  124. int irq_interval,
  125. void (*callback)(struct hpsb_iso*));
  126. struct hpsb_iso* hpsb_iso_recv_init(struct hpsb_host *host,
  127. unsigned int data_buf_size,
  128. unsigned int buf_packets,
  129. int channel,
  130. int dma_mode,
  131. int irq_interval,
  132. void (*callback)(struct hpsb_iso*));
  133. int hpsb_iso_recv_listen_channel(struct hpsb_iso *iso, unsigned char channel);
  134. int hpsb_iso_recv_unlisten_channel(struct hpsb_iso *iso, unsigned char channel);
  135. int hpsb_iso_recv_set_channel_mask(struct hpsb_iso *iso, u64 mask);
  136. int hpsb_iso_xmit_start(struct hpsb_iso *iso, int start_on_cycle,
  137. int prebuffer);
  138. int hpsb_iso_recv_start(struct hpsb_iso *iso, int start_on_cycle,
  139. int tag_mask, int sync);
  140. void hpsb_iso_stop(struct hpsb_iso *iso);
  141. void hpsb_iso_shutdown(struct hpsb_iso *iso);
  142. int hpsb_iso_xmit_queue_packet(struct hpsb_iso *iso, u32 offset, u16 len,
  143. u8 tag, u8 sy);
  144. int hpsb_iso_xmit_sync(struct hpsb_iso *iso);
  145. int hpsb_iso_recv_release_packets(struct hpsb_iso *recv,
  146. unsigned int n_packets);
  147. int hpsb_iso_recv_flush(struct hpsb_iso *iso);
  148. int hpsb_iso_n_ready(struct hpsb_iso *iso);
  149. /* the following are callbacks available to low-level drivers */
  150. void hpsb_iso_packet_sent(struct hpsb_iso *iso, int cycle, int error);
  151. void hpsb_iso_packet_received(struct hpsb_iso *iso, u32 offset, u16 len,
  152. u16 total_len, u16 cycle, u8 channel, u8 tag,
  153. u8 sy);
  154. void hpsb_iso_wake(struct hpsb_iso *iso);
  155. #endif /* IEEE1394_ISO_H */