ieee1394_core.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. #ifndef _IEEE1394_CORE_H
  2. #define _IEEE1394_CORE_H
  3. #include <linux/device.h>
  4. #include <linux/fs.h>
  5. #include <linux/list.h>
  6. #include <linux/skbuff.h>
  7. #include <linux/types.h>
  8. #include <asm/atomic.h>
  9. #include <asm/semaphore.h>
  10. #include "hosts.h"
  11. #include "ieee1394_types.h"
  12. struct hpsb_packet {
  13. /* This struct is basically read-only for hosts with the exception of
  14. * the data buffer contents and xnext - see below. */
  15. /* This can be used for host driver internal linking.
  16. *
  17. * NOTE: This must be left in init state when the driver is done
  18. * with it (e.g. by using list_del_init()), since the core does
  19. * some sanity checks to make sure the packet is not on a
  20. * driver_list when free'ing it. */
  21. struct list_head driver_list;
  22. nodeid_t node_id;
  23. /* Async and Iso types should be clear, raw means send-as-is, do not
  24. * CRC! Byte swapping shall still be done in this case. */
  25. enum { hpsb_async, hpsb_iso, hpsb_raw } __attribute__((packed)) type;
  26. /* Okay, this is core internal and a no care for hosts.
  27. * queued = queued for sending
  28. * pending = sent, waiting for response
  29. * complete = processing completed, successful or not
  30. */
  31. enum {
  32. hpsb_unused, hpsb_queued, hpsb_pending, hpsb_complete
  33. } __attribute__((packed)) state;
  34. /* These are core internal. */
  35. signed char tlabel;
  36. signed char ack_code;
  37. unsigned char tcode;
  38. unsigned expect_response:1;
  39. unsigned no_waiter:1;
  40. /* Speed to transmit with: 0 = 100Mbps, 1 = 200Mbps, 2 = 400Mbps */
  41. unsigned speed_code:2;
  42. /*
  43. * *header and *data are guaranteed to be 32-bit DMAable and may be
  44. * overwritten to allow in-place byte swapping. Neither of these is
  45. * CRCed (the sizes also don't include CRC), but contain space for at
  46. * least one additional quadlet to allow in-place CRCing. The memory is
  47. * also guaranteed to be DMA mappable.
  48. */
  49. quadlet_t *header;
  50. quadlet_t *data;
  51. size_t header_size;
  52. size_t data_size;
  53. struct hpsb_host *host;
  54. unsigned int generation;
  55. atomic_t refcnt;
  56. /* Function (and possible data to pass to it) to call when this
  57. * packet is completed. */
  58. void (*complete_routine)(void *);
  59. void *complete_data;
  60. /* XXX This is just a hack at the moment */
  61. struct sk_buff *skb;
  62. /* Store jiffies for implementing bus timeouts. */
  63. unsigned long sendtime;
  64. quadlet_t embedded_header[5];
  65. };
  66. /* Set a task for when a packet completes */
  67. void hpsb_set_packet_complete_task(struct hpsb_packet *packet,
  68. void (*routine)(void *), void *data);
  69. static inline struct hpsb_packet *driver_packet(struct list_head *l)
  70. {
  71. return list_entry(l, struct hpsb_packet, driver_list);
  72. }
  73. void abort_timedouts(unsigned long __opaque);
  74. struct hpsb_packet *hpsb_alloc_packet(size_t data_size);
  75. void hpsb_free_packet(struct hpsb_packet *packet);
  76. /*
  77. * Generation counter for the complete 1394 subsystem. Generation gets
  78. * incremented on every change in the subsystem (e.g. bus reset).
  79. *
  80. * Use the functions, not the variable.
  81. */
  82. static inline unsigned int get_hpsb_generation(struct hpsb_host *host)
  83. {
  84. return atomic_read(&host->generation);
  85. }
  86. /*
  87. * Send a PHY configuration packet, return 0 on success, negative
  88. * errno on failure.
  89. */
  90. int hpsb_send_phy_config(struct hpsb_host *host, int rootid, int gapcnt);
  91. /*
  92. * Queue packet for transmitting, return 0 on success, negative errno
  93. * on failure.
  94. */
  95. int hpsb_send_packet(struct hpsb_packet *packet);
  96. /*
  97. * Queue packet for transmitting, and block until the transaction
  98. * completes. Return 0 on success, negative errno on failure.
  99. */
  100. int hpsb_send_packet_and_wait(struct hpsb_packet *packet);
  101. /* Initiate bus reset on the given host. Returns 1 if bus reset already in
  102. * progress, 0 otherwise. */
  103. int hpsb_reset_bus(struct hpsb_host *host, int type);
  104. /*
  105. * The following functions are exported for host driver module usage. All of
  106. * them are safe to use in interrupt contexts, although some are quite
  107. * complicated so you may want to run them in bottom halves instead of calling
  108. * them directly.
  109. */
  110. /* Notify a bus reset to the core. Returns 1 if bus reset already in progress,
  111. * 0 otherwise. */
  112. int hpsb_bus_reset(struct hpsb_host *host);
  113. /*
  114. * Hand over received selfid packet to the core. Complement check (second
  115. * quadlet is complement of first) is expected to be done and successful.
  116. */
  117. void hpsb_selfid_received(struct hpsb_host *host, quadlet_t sid);
  118. /*
  119. * Notify completion of SelfID stage to the core and report new physical ID
  120. * and whether host is root now.
  121. */
  122. void hpsb_selfid_complete(struct hpsb_host *host, int phyid, int isroot);
  123. /*
  124. * Notify core of sending a packet. Ackcode is the ack code returned for async
  125. * transmits or ACKX_SEND_ERROR if the transmission failed completely; ACKX_NONE
  126. * for other cases (internal errors that don't justify a panic). Safe to call
  127. * from within a transmit packet routine.
  128. */
  129. void hpsb_packet_sent(struct hpsb_host *host, struct hpsb_packet *packet,
  130. int ackcode);
  131. /*
  132. * Hand over received packet to the core. The contents of data are expected to
  133. * be the full packet but with the CRCs left out (data block follows header
  134. * immediately), with the header (i.e. the first four quadlets) in machine byte
  135. * order and the data block in big endian. *data can be safely overwritten
  136. * after this call.
  137. *
  138. * If the packet is a write request, write_acked is to be set to true if it was
  139. * ack_complete'd already, false otherwise. This arg is ignored for any other
  140. * packet type.
  141. */
  142. void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
  143. int write_acked);
  144. /*
  145. * CHARACTER DEVICE DISPATCHING
  146. *
  147. * All ieee1394 character device drivers share the same major number
  148. * (major 171). The 256 minor numbers are allocated to the various
  149. * task-specific interfaces (raw1394, video1394, dv1394, etc) in
  150. * blocks of 16.
  151. *
  152. * The core ieee1394.o module allocates the device number region
  153. * 171:0-255, the various drivers must then cdev_add() their cdev
  154. * objects to handle their respective sub-regions.
  155. *
  156. * Minor device number block allocations:
  157. *
  158. * Block 0 ( 0- 15) raw1394
  159. * Block 1 ( 16- 31) video1394
  160. * Block 2 ( 32- 47) dv1394
  161. *
  162. * Blocks 3-14 free for future allocation
  163. *
  164. * Block 15 (240-255) reserved for drivers under development, etc.
  165. */
  166. #define IEEE1394_MAJOR 171
  167. #define IEEE1394_MINOR_BLOCK_RAW1394 0
  168. #define IEEE1394_MINOR_BLOCK_VIDEO1394 1
  169. #define IEEE1394_MINOR_BLOCK_DV1394 2
  170. #define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15
  171. #define IEEE1394_CORE_DEV MKDEV(IEEE1394_MAJOR, 0)
  172. #define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, \
  173. IEEE1394_MINOR_BLOCK_RAW1394 * 16)
  174. #define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, \
  175. IEEE1394_MINOR_BLOCK_VIDEO1394 * 16)
  176. #define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, \
  177. IEEE1394_MINOR_BLOCK_DV1394 * 16)
  178. #define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, \
  179. IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16)
  180. /* return the index (within a minor number block) of a file */
  181. static inline unsigned char ieee1394_file_to_instance(struct file *file)
  182. {
  183. return file->f_dentry->d_inode->i_cindex;
  184. }
  185. extern int hpsb_disable_irm;
  186. /* Our sysfs bus entry */
  187. extern struct bus_type ieee1394_bus_type;
  188. extern struct class hpsb_host_class;
  189. extern struct class *hpsb_protocol_class;
  190. #endif /* _IEEE1394_CORE_H */