ieee1394_core.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. /* Async and Iso types should be clear, raw means send-as-is, do not
  22. * CRC! Byte swapping shall still be done in this case. */
  23. enum { hpsb_async, hpsb_iso, 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. /* Sizes are in bytes. *data can be DMA-mapped. */
  51. size_t allocated_data_size; /* as allocated */
  52. size_t data_size; /* as filled in */
  53. size_t header_size; /* as filled in, not counting the CRC */
  54. quadlet_t *data;
  55. quadlet_t header[5];
  56. quadlet_t embedded_data[0]; /* keep as last member */
  57. };
  58. void hpsb_set_packet_complete_task(struct hpsb_packet *packet,
  59. void (*routine)(void *), void *data);
  60. static inline struct hpsb_packet *driver_packet(struct list_head *l)
  61. {
  62. return list_entry(l, struct hpsb_packet, driver_list);
  63. }
  64. void abort_timedouts(unsigned long __opaque);
  65. struct hpsb_packet *hpsb_alloc_packet(size_t data_size);
  66. void hpsb_free_packet(struct hpsb_packet *packet);
  67. /**
  68. * get_hpsb_generation - generation counter for the complete 1394 subsystem
  69. *
  70. * Generation gets incremented on every change in the subsystem (notably on bus
  71. * resets). Use the functions, not the variable.
  72. */
  73. static inline unsigned int get_hpsb_generation(struct hpsb_host *host)
  74. {
  75. return atomic_read(&host->generation);
  76. }
  77. int hpsb_send_phy_config(struct hpsb_host *host, int rootid, int gapcnt);
  78. int hpsb_send_packet(struct hpsb_packet *packet);
  79. int hpsb_send_packet_and_wait(struct hpsb_packet *packet);
  80. int hpsb_reset_bus(struct hpsb_host *host, int type);
  81. int hpsb_read_cycle_timer(struct hpsb_host *host, u32 *cycle_timer,
  82. u64 *local_time);
  83. int hpsb_bus_reset(struct hpsb_host *host);
  84. void hpsb_selfid_received(struct hpsb_host *host, quadlet_t sid);
  85. void hpsb_selfid_complete(struct hpsb_host *host, int phyid, int isroot);
  86. void hpsb_packet_sent(struct hpsb_host *host, struct hpsb_packet *packet,
  87. int ackcode);
  88. void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
  89. int write_acked);
  90. /*
  91. * CHARACTER DEVICE DISPATCHING
  92. *
  93. * All ieee1394 character device drivers share the same major number
  94. * (major 171). The 256 minor numbers are allocated to the various
  95. * task-specific interfaces (raw1394, video1394, dv1394, etc) in
  96. * blocks of 16.
  97. *
  98. * The core ieee1394.o module allocates the device number region
  99. * 171:0-255, the various drivers must then cdev_add() their cdev
  100. * objects to handle their respective sub-regions.
  101. *
  102. * Minor device number block allocations:
  103. *
  104. * Block 0 ( 0- 15) raw1394
  105. * Block 1 ( 16- 31) video1394
  106. * Block 2 ( 32- 47) dv1394
  107. *
  108. * Blocks 3-14 free for future allocation
  109. *
  110. * Block 15 (240-255) reserved for drivers under development, etc.
  111. */
  112. #define IEEE1394_MAJOR 171
  113. #define IEEE1394_MINOR_BLOCK_RAW1394 0
  114. #define IEEE1394_MINOR_BLOCK_VIDEO1394 1
  115. #define IEEE1394_MINOR_BLOCK_DV1394 2
  116. #define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15
  117. #define IEEE1394_CORE_DEV MKDEV(IEEE1394_MAJOR, 0)
  118. #define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, \
  119. IEEE1394_MINOR_BLOCK_RAW1394 * 16)
  120. #define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, \
  121. IEEE1394_MINOR_BLOCK_VIDEO1394 * 16)
  122. #define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, \
  123. IEEE1394_MINOR_BLOCK_DV1394 * 16)
  124. #define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, \
  125. IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16)
  126. /**
  127. * ieee1394_file_to_instance - get the index within a minor number block
  128. */
  129. static inline unsigned char ieee1394_file_to_instance(struct file *file)
  130. {
  131. return file->f_path.dentry->d_inode->i_cindex;
  132. }
  133. extern int hpsb_disable_irm;
  134. /* Our sysfs bus entry */
  135. extern struct bus_type ieee1394_bus_type;
  136. extern struct class hpsb_host_class;
  137. extern struct class *hpsb_protocol_class;
  138. #endif /* _IEEE1394_CORE_H */