ieee1394_core.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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/types.h>
  7. #include <linux/cdev.h>
  8. #include <asm/atomic.h>
  9. #include "hosts.h"
  10. #include "ieee1394_types.h"
  11. struct hpsb_packet {
  12. /* This struct is basically read-only for hosts with the exception of
  13. * the data buffer contents and driver_list. */
  14. /* This can be used for host driver internal linking.
  15. *
  16. * NOTE: This must be left in init state when the driver is done
  17. * with it (e.g. by using list_del_init()), since the core does
  18. * some sanity checks to make sure the packet is not on a
  19. * driver_list when free'ing it. */
  20. struct list_head driver_list;
  21. nodeid_t node_id;
  22. /* hpsb_raw = send as-is, do not CRC (but still byte-swap it) */
  23. enum { hpsb_async, hpsb_raw } __attribute__((packed)) type;
  24. /* Okay, this is core internal and a no care for hosts.
  25. * queued = queued for sending
  26. * pending = sent, waiting for response
  27. * complete = processing completed, successful or not
  28. */
  29. enum {
  30. hpsb_unused, hpsb_queued, hpsb_pending, hpsb_complete
  31. } __attribute__((packed)) state;
  32. /* These are core-internal. */
  33. signed char tlabel;
  34. signed char ack_code;
  35. unsigned char tcode;
  36. unsigned expect_response:1;
  37. unsigned no_waiter:1;
  38. /* Speed to transmit with: 0 = 100Mbps, 1 = 200Mbps, 2 = 400Mbps */
  39. unsigned speed_code:2;
  40. struct hpsb_host *host;
  41. unsigned int generation;
  42. atomic_t refcnt;
  43. struct list_head queue;
  44. /* Function (and possible data to pass to it) to call when this
  45. * packet is completed. */
  46. void (*complete_routine)(void *);
  47. void *complete_data;
  48. /* Store jiffies for implementing bus timeouts. */
  49. unsigned long sendtime;
  50. /* Core-internal. */
  51. size_t allocated_data_size; /* as allocated */
  52. /* Sizes are in bytes. To be set by caller of hpsb_alloc_packet. */
  53. size_t data_size; /* as filled in */
  54. size_t header_size; /* as filled in, not counting the CRC */
  55. /* Buffers */
  56. quadlet_t *data; /* can be DMA-mapped */
  57. quadlet_t header[5];
  58. quadlet_t embedded_data[0]; /* keep as last member */
  59. };
  60. void hpsb_set_packet_complete_task(struct hpsb_packet *packet,
  61. void (*routine)(void *), void *data);
  62. static inline struct hpsb_packet *driver_packet(struct list_head *l)
  63. {
  64. return list_entry(l, struct hpsb_packet, driver_list);
  65. }
  66. void abort_timedouts(unsigned long __opaque);
  67. struct hpsb_packet *hpsb_alloc_packet(size_t data_size);
  68. void hpsb_free_packet(struct hpsb_packet *packet);
  69. /**
  70. * get_hpsb_generation - generation counter for the complete 1394 subsystem
  71. *
  72. * Generation gets incremented on every change in the subsystem (notably on bus
  73. * resets). Use the functions, not the variable.
  74. */
  75. static inline unsigned int get_hpsb_generation(struct hpsb_host *host)
  76. {
  77. return atomic_read(&host->generation);
  78. }
  79. int hpsb_send_phy_config(struct hpsb_host *host, int rootid, int gapcnt);
  80. int hpsb_send_packet(struct hpsb_packet *packet);
  81. int hpsb_send_packet_and_wait(struct hpsb_packet *packet);
  82. int hpsb_reset_bus(struct hpsb_host *host, int type);
  83. int hpsb_read_cycle_timer(struct hpsb_host *host, u32 *cycle_timer,
  84. u64 *local_time);
  85. int hpsb_bus_reset(struct hpsb_host *host);
  86. void hpsb_selfid_received(struct hpsb_host *host, quadlet_t sid);
  87. void hpsb_selfid_complete(struct hpsb_host *host, int phyid, int isroot);
  88. void hpsb_packet_sent(struct hpsb_host *host, struct hpsb_packet *packet,
  89. int ackcode);
  90. void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
  91. int write_acked);
  92. /*
  93. * CHARACTER DEVICE DISPATCHING
  94. *
  95. * All ieee1394 character device drivers share the same major number
  96. * (major 171). The 256 minor numbers are allocated to the various
  97. * task-specific interfaces (raw1394, video1394, dv1394, etc) in
  98. * blocks of 16.
  99. *
  100. * The core ieee1394.o module allocates the device number region
  101. * 171:0-255, the various drivers must then cdev_add() their cdev
  102. * objects to handle their respective sub-regions.
  103. *
  104. * Minor device number block allocations:
  105. *
  106. * Block 0 ( 0- 15) raw1394
  107. * Block 1 ( 16- 31) video1394
  108. * Block 2 ( 32- 47) dv1394
  109. *
  110. * Blocks 3-14 free for future allocation
  111. *
  112. * Block 15 (240-255) reserved for drivers under development, etc.
  113. */
  114. #define IEEE1394_MAJOR 171
  115. #define IEEE1394_MINOR_BLOCK_RAW1394 0
  116. #define IEEE1394_MINOR_BLOCK_VIDEO1394 1
  117. #define IEEE1394_MINOR_BLOCK_DV1394 2
  118. #define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15
  119. #define IEEE1394_CORE_DEV MKDEV(IEEE1394_MAJOR, 0)
  120. #define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, \
  121. IEEE1394_MINOR_BLOCK_RAW1394 * 16)
  122. #define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, \
  123. IEEE1394_MINOR_BLOCK_VIDEO1394 * 16)
  124. #define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, \
  125. IEEE1394_MINOR_BLOCK_DV1394 * 16)
  126. #define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, \
  127. IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16)
  128. /**
  129. * ieee1394_file_to_instance - get the index within a minor number block
  130. */
  131. static inline unsigned char ieee1394_file_to_instance(struct file *file)
  132. {
  133. int idx = cdev_index(file->f_path.dentry->d_inode);
  134. if (idx < 0)
  135. idx = 0;
  136. return idx;
  137. }
  138. extern int hpsb_disable_irm;
  139. /* Our sysfs bus entry */
  140. extern struct bus_type ieee1394_bus_type;
  141. extern struct class hpsb_host_class;
  142. extern struct class *hpsb_protocol_class;
  143. #endif /* _IEEE1394_CORE_H */