iso.h 5.9 KB

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