ieee1394_core.h 5.2 KB

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