firewire.h 12 KB

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