iso.h 6.3 KB

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