firewire.h 12 KB

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