firewire.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. #ifndef _LINUX_FIREWIRE_H
  2. #define _LINUX_FIREWIRE_H
  3. #include <linux/completion.h>
  4. #include <linux/device.h>
  5. #include <linux/dma-mapping.h>
  6. #include <linux/kernel.h>
  7. #include <linux/kref.h>
  8. #include <linux/list.h>
  9. #include <linux/mutex.h>
  10. #include <linux/spinlock.h>
  11. #include <linux/sysfs.h>
  12. #include <linux/timer.h>
  13. #include <linux/types.h>
  14. #include <linux/workqueue.h>
  15. #include <asm/atomic.h>
  16. #include <asm/byteorder.h>
  17. #define fw_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, ## args)
  18. #define fw_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args)
  19. #define CSR_REGISTER_BASE 0xfffff0000000ULL
  20. /* register offsets are relative to CSR_REGISTER_BASE */
  21. #define CSR_STATE_CLEAR 0x0
  22. #define CSR_STATE_SET 0x4
  23. #define CSR_NODE_IDS 0x8
  24. #define CSR_RESET_START 0xc
  25. #define CSR_SPLIT_TIMEOUT_HI 0x18
  26. #define CSR_SPLIT_TIMEOUT_LO 0x1c
  27. #define CSR_CYCLE_TIME 0x200
  28. #define CSR_BUS_TIME 0x204
  29. #define CSR_BUSY_TIMEOUT 0x210
  30. #define CSR_BUS_MANAGER_ID 0x21c
  31. #define CSR_BANDWIDTH_AVAILABLE 0x220
  32. #define CSR_CHANNELS_AVAILABLE 0x224
  33. #define CSR_CHANNELS_AVAILABLE_HI 0x224
  34. #define CSR_CHANNELS_AVAILABLE_LO 0x228
  35. #define CSR_BROADCAST_CHANNEL 0x234
  36. #define CSR_CONFIG_ROM 0x400
  37. #define CSR_CONFIG_ROM_END 0x800
  38. #define CSR_FCP_COMMAND 0xB00
  39. #define CSR_FCP_RESPONSE 0xD00
  40. #define CSR_FCP_END 0xF00
  41. #define CSR_TOPOLOGY_MAP 0x1000
  42. #define CSR_TOPOLOGY_MAP_END 0x1400
  43. #define CSR_SPEED_MAP 0x2000
  44. #define CSR_SPEED_MAP_END 0x3000
  45. #define CSR_OFFSET 0x40
  46. #define CSR_LEAF 0x80
  47. #define CSR_DIRECTORY 0xc0
  48. #define CSR_DESCRIPTOR 0x01
  49. #define CSR_VENDOR 0x03
  50. #define CSR_HARDWARE_VERSION 0x04
  51. #define CSR_NODE_CAPABILITIES 0x0c
  52. #define CSR_UNIT 0x11
  53. #define CSR_SPECIFIER_ID 0x12
  54. #define CSR_VERSION 0x13
  55. #define CSR_DEPENDENT_INFO 0x14
  56. #define CSR_MODEL 0x17
  57. #define CSR_INSTANCE 0x18
  58. #define CSR_DIRECTORY_ID 0x20
  59. struct fw_csr_iterator {
  60. u32 *p;
  61. u32 *end;
  62. };
  63. void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p);
  64. int fw_csr_iterator_next(struct fw_csr_iterator *ci, int *key, int *value);
  65. extern struct bus_type fw_bus_type;
  66. struct fw_card_driver;
  67. struct fw_node;
  68. struct fw_card {
  69. const struct fw_card_driver *driver;
  70. struct device *device;
  71. struct kref kref;
  72. struct completion done;
  73. int node_id;
  74. int generation;
  75. int current_tlabel;
  76. u64 tlabel_mask;
  77. struct list_head transaction_list;
  78. struct timer_list flush_timer;
  79. unsigned long reset_jiffies;
  80. unsigned long long guid;
  81. unsigned max_receive;
  82. int link_speed;
  83. int config_rom_generation;
  84. spinlock_t lock; /* Take this lock when handling the lists in
  85. * this struct. */
  86. struct fw_node *local_node;
  87. struct fw_node *root_node;
  88. struct fw_node *irm_node;
  89. u8 color; /* must be u8 to match the definition in struct fw_node */
  90. int gap_count;
  91. bool beta_repeaters_present;
  92. int index;
  93. struct list_head link;
  94. /* Work struct for BM duties. */
  95. struct delayed_work work;
  96. int bm_retries;
  97. int bm_generation;
  98. __be32 bm_transaction_data[2];
  99. bool broadcast_channel_allocated;
  100. u32 broadcast_channel;
  101. __be32 topology_map[(CSR_TOPOLOGY_MAP_END - CSR_TOPOLOGY_MAP) / 4];
  102. };
  103. struct fw_attribute_group {
  104. struct attribute_group *groups[2];
  105. struct attribute_group group;
  106. struct attribute *attrs[12];
  107. };
  108. enum fw_device_state {
  109. FW_DEVICE_INITIALIZING,
  110. FW_DEVICE_RUNNING,
  111. FW_DEVICE_GONE,
  112. FW_DEVICE_SHUTDOWN,
  113. };
  114. /*
  115. * Note, fw_device.generation always has to be read before fw_device.node_id.
  116. * Use SMP memory barriers to ensure this. Otherwise requests will be sent
  117. * to an outdated node_id if the generation was updated in the meantime due
  118. * to a bus reset.
  119. *
  120. * Likewise, fw-core will take care to update .node_id before .generation so
  121. * that whenever fw_device.generation is current WRT the actual bus generation,
  122. * fw_device.node_id is guaranteed to be current too.
  123. *
  124. * The same applies to fw_device.card->node_id vs. fw_device.generation.
  125. *
  126. * fw_device.config_rom and fw_device.config_rom_length may be accessed during
  127. * the lifetime of any fw_unit belonging to the fw_device, before device_del()
  128. * was called on the last fw_unit. Alternatively, they may be accessed while
  129. * holding fw_device_rwsem.
  130. */
  131. struct fw_device {
  132. atomic_t state;
  133. struct fw_node *node;
  134. int node_id;
  135. int generation;
  136. unsigned max_speed;
  137. struct fw_card *card;
  138. struct device device;
  139. struct mutex client_list_mutex;
  140. struct list_head client_list;
  141. u32 *config_rom;
  142. size_t config_rom_length;
  143. int config_rom_retries;
  144. unsigned is_local:1;
  145. unsigned max_rec:4;
  146. unsigned cmc:1;
  147. unsigned irmc:1;
  148. unsigned bc_implemented:2;
  149. struct delayed_work work;
  150. struct fw_attribute_group attribute_group;
  151. };
  152. static inline struct fw_device *fw_device(struct device *dev)
  153. {
  154. return container_of(dev, struct fw_device, device);
  155. }
  156. static inline int fw_device_is_shutdown(struct fw_device *device)
  157. {
  158. return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN;
  159. }
  160. static inline struct fw_device *fw_device_get(struct fw_device *device)
  161. {
  162. get_device(&device->device);
  163. return device;
  164. }
  165. static inline void fw_device_put(struct fw_device *device)
  166. {
  167. put_device(&device->device);
  168. }
  169. int fw_device_enable_phys_dma(struct fw_device *device);
  170. /*
  171. * fw_unit.directory must not be accessed after device_del(&fw_unit.device).
  172. */
  173. struct fw_unit {
  174. struct device device;
  175. u32 *directory;
  176. struct fw_attribute_group attribute_group;
  177. };
  178. static inline struct fw_unit *fw_unit(struct device *dev)
  179. {
  180. return container_of(dev, struct fw_unit, device);
  181. }
  182. static inline struct fw_unit *fw_unit_get(struct fw_unit *unit)
  183. {
  184. get_device(&unit->device);
  185. return unit;
  186. }
  187. static inline void fw_unit_put(struct fw_unit *unit)
  188. {
  189. put_device(&unit->device);
  190. }
  191. static inline struct fw_device *fw_parent_device(struct fw_unit *unit)
  192. {
  193. return fw_device(unit->device.parent);
  194. }
  195. struct ieee1394_device_id;
  196. struct fw_driver {
  197. struct device_driver driver;
  198. /* Called when the parent device sits through a bus reset. */
  199. void (*update)(struct fw_unit *unit);
  200. const struct ieee1394_device_id *id_table;
  201. };
  202. struct fw_packet;
  203. struct fw_request;
  204. typedef void (*fw_packet_callback_t)(struct fw_packet *packet,
  205. struct fw_card *card, int status);
  206. typedef void (*fw_transaction_callback_t)(struct fw_card *card, int rcode,
  207. void *data, size_t length,
  208. void *callback_data);
  209. /*
  210. * Important note: Except for the FCP registers, the callback must guarantee
  211. * that either fw_send_response() or kfree() is called on the @request.
  212. */
  213. typedef void (*fw_address_callback_t)(struct fw_card *card,
  214. struct fw_request *request,
  215. int tcode, int destination, int source,
  216. int generation, int speed,
  217. unsigned long long offset,
  218. void *data, size_t length,
  219. void *callback_data);
  220. struct fw_packet {
  221. int speed;
  222. int generation;
  223. u32 header[4];
  224. size_t header_length;
  225. void *payload;
  226. size_t payload_length;
  227. dma_addr_t payload_bus;
  228. bool payload_mapped;
  229. u32 timestamp;
  230. /*
  231. * This callback is called when the packet transmission has
  232. * completed; for successful transmission, the status code is
  233. * the ack received from the destination, otherwise it's a
  234. * negative errno: ENOMEM, ESTALE, ETIMEDOUT, ENODEV, EIO.
  235. * The callback can be called from tasklet context and thus
  236. * must never block.
  237. */
  238. fw_packet_callback_t callback;
  239. int ack;
  240. struct list_head link;
  241. void *driver_data;
  242. };
  243. struct fw_transaction {
  244. int node_id; /* The generation is implied; it is always the current. */
  245. int tlabel;
  246. int timestamp;
  247. struct list_head link;
  248. struct fw_packet packet;
  249. /*
  250. * The data passed to the callback is valid only during the
  251. * callback.
  252. */
  253. fw_transaction_callback_t callback;
  254. void *callback_data;
  255. };
  256. struct fw_address_handler {
  257. u64 offset;
  258. size_t length;
  259. fw_address_callback_t address_callback;
  260. void *callback_data;
  261. struct list_head link;
  262. };
  263. struct fw_address_region {
  264. u64 start;
  265. u64 end;
  266. };
  267. extern const struct fw_address_region fw_high_memory_region;
  268. int fw_core_add_address_handler(struct fw_address_handler *handler,
  269. const struct fw_address_region *region);
  270. void fw_core_remove_address_handler(struct fw_address_handler *handler);
  271. void fw_send_response(struct fw_card *card,
  272. struct fw_request *request, int rcode);
  273. void fw_send_request(struct fw_card *card, struct fw_transaction *t,
  274. int tcode, int destination_id, int generation, int speed,
  275. unsigned long long offset, void *payload, size_t length,
  276. fw_transaction_callback_t callback, void *callback_data);
  277. int fw_cancel_transaction(struct fw_card *card,
  278. struct fw_transaction *transaction);
  279. int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
  280. int generation, int speed, unsigned long long offset,
  281. void *payload, size_t length);
  282. static inline int fw_stream_packet_destination_id(int tag, int channel, int sy)
  283. {
  284. return tag << 14 | channel << 8 | sy;
  285. }
  286. struct fw_descriptor {
  287. struct list_head link;
  288. size_t length;
  289. u32 immediate;
  290. u32 key;
  291. const u32 *data;
  292. };
  293. int fw_core_add_descriptor(struct fw_descriptor *desc);
  294. void fw_core_remove_descriptor(struct fw_descriptor *desc);
  295. /*
  296. * The iso packet format allows for an immediate header/payload part
  297. * stored in 'header' immediately after the packet info plus an
  298. * indirect payload part that is pointer to by the 'payload' field.
  299. * Applications can use one or the other or both to implement simple
  300. * low-bandwidth streaming (e.g. audio) or more advanced
  301. * scatter-gather streaming (e.g. assembling video frame automatically).
  302. */
  303. struct fw_iso_packet {
  304. u16 payload_length; /* Length of indirect payload. */
  305. u32 interrupt:1; /* Generate interrupt on this packet */
  306. u32 skip:1; /* Set to not send packet at all. */
  307. u32 tag:2;
  308. u32 sy:4;
  309. u32 header_length:8; /* Length of immediate header. */
  310. u32 header[0];
  311. };
  312. #define FW_ISO_CONTEXT_TRANSMIT 0
  313. #define FW_ISO_CONTEXT_RECEIVE 1
  314. #define FW_ISO_CONTEXT_MATCH_TAG0 1
  315. #define FW_ISO_CONTEXT_MATCH_TAG1 2
  316. #define FW_ISO_CONTEXT_MATCH_TAG2 4
  317. #define FW_ISO_CONTEXT_MATCH_TAG3 8
  318. #define FW_ISO_CONTEXT_MATCH_ALL_TAGS 15
  319. /*
  320. * An iso buffer is just a set of pages mapped for DMA in the
  321. * specified direction. Since the pages are to be used for DMA, they
  322. * are not mapped into the kernel virtual address space. We store the
  323. * DMA address in the page private. The helper function
  324. * fw_iso_buffer_map() will map the pages into a given vma.
  325. */
  326. struct fw_iso_buffer {
  327. enum dma_data_direction direction;
  328. struct page **pages;
  329. int page_count;
  330. };
  331. int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card,
  332. int page_count, enum dma_data_direction direction);
  333. void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer, struct fw_card *card);
  334. struct fw_iso_context;
  335. typedef void (*fw_iso_callback_t)(struct fw_iso_context *context,
  336. u32 cycle, size_t header_length,
  337. void *header, void *data);
  338. struct fw_iso_context {
  339. struct fw_card *card;
  340. int type;
  341. int channel;
  342. int speed;
  343. size_t header_size;
  344. fw_iso_callback_t callback;
  345. void *callback_data;
  346. };
  347. struct fw_iso_context *fw_iso_context_create(struct fw_card *card,
  348. int type, int channel, int speed, size_t header_size,
  349. fw_iso_callback_t callback, void *callback_data);
  350. int fw_iso_context_queue(struct fw_iso_context *ctx,
  351. struct fw_iso_packet *packet,
  352. struct fw_iso_buffer *buffer,
  353. unsigned long payload);
  354. int fw_iso_context_start(struct fw_iso_context *ctx,
  355. int cycle, int sync, int tags);
  356. int fw_iso_context_stop(struct fw_iso_context *ctx);
  357. void fw_iso_context_destroy(struct fw_iso_context *ctx);
  358. #endif /* _LINUX_FIREWIRE_H */