ieee1394_core.h 7.4 KB

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