firewire.h 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. #ifndef _LINUX_FIREWIRE_H
  2. #define _LINUX_FIREWIRE_H
  3. #include <linux/completion.h>
  4. #include <linux/device.h>
  5. #include <linux/kernel.h>
  6. #include <linux/kref.h>
  7. #include <linux/list.h>
  8. #include <linux/mutex.h>
  9. #include <linux/spinlock.h>
  10. #include <linux/sysfs.h>
  11. #include <linux/timer.h>
  12. #include <linux/types.h>
  13. #include <linux/workqueue.h>
  14. #include <asm/atomic.h>
  15. #include <asm/byteorder.h>
  16. #define fw_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, ## args)
  17. #define fw_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args)
  18. static inline void fw_memcpy_from_be32(void *_dst, void *_src, size_t size)
  19. {
  20. u32 *dst = _dst;
  21. __be32 *src = _src;
  22. int i;
  23. for (i = 0; i < size / 4; i++)
  24. dst[i] = be32_to_cpu(src[i]);
  25. }
  26. static inline void fw_memcpy_to_be32(void *_dst, void *_src, size_t size)
  27. {
  28. fw_memcpy_from_be32(_dst, _src, size);
  29. }
  30. #define CSR_REGISTER_BASE 0xfffff0000000ULL
  31. /* register offsets are relative to CSR_REGISTER_BASE */
  32. #define CSR_STATE_CLEAR 0x0
  33. #define CSR_STATE_SET 0x4
  34. #define CSR_NODE_IDS 0x8
  35. #define CSR_RESET_START 0xc
  36. #define CSR_SPLIT_TIMEOUT_HI 0x18
  37. #define CSR_SPLIT_TIMEOUT_LO 0x1c
  38. #define CSR_CYCLE_TIME 0x200
  39. #define CSR_BUS_TIME 0x204
  40. #define CSR_BUSY_TIMEOUT 0x210
  41. #define CSR_BUS_MANAGER_ID 0x21c
  42. #define CSR_BANDWIDTH_AVAILABLE 0x220
  43. #define CSR_CHANNELS_AVAILABLE 0x224
  44. #define CSR_CHANNELS_AVAILABLE_HI 0x224
  45. #define CSR_CHANNELS_AVAILABLE_LO 0x228
  46. #define CSR_BROADCAST_CHANNEL 0x234
  47. #define CSR_CONFIG_ROM 0x400
  48. #define CSR_CONFIG_ROM_END 0x800
  49. #define CSR_FCP_COMMAND 0xB00
  50. #define CSR_FCP_RESPONSE 0xD00
  51. #define CSR_FCP_END 0xF00
  52. #define CSR_TOPOLOGY_MAP 0x1000
  53. #define CSR_TOPOLOGY_MAP_END 0x1400
  54. #define CSR_SPEED_MAP 0x2000
  55. #define CSR_SPEED_MAP_END 0x3000
  56. #define CSR_OFFSET 0x40
  57. #define CSR_LEAF 0x80
  58. #define CSR_DIRECTORY 0xc0
  59. #define CSR_DESCRIPTOR 0x01
  60. #define CSR_VENDOR 0x03
  61. #define CSR_HARDWARE_VERSION 0x04
  62. #define CSR_NODE_CAPABILITIES 0x0c
  63. #define CSR_UNIT 0x11
  64. #define CSR_SPECIFIER_ID 0x12
  65. #define CSR_VERSION 0x13
  66. #define CSR_DEPENDENT_INFO 0x14
  67. #define CSR_MODEL 0x17
  68. #define CSR_INSTANCE 0x18
  69. #define CSR_DIRECTORY_ID 0x20
  70. struct fw_csr_iterator {
  71. u32 *p;
  72. u32 *end;
  73. };
  74. void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p);
  75. int fw_csr_iterator_next(struct fw_csr_iterator *ci, int *key, int *value);
  76. extern struct bus_type fw_bus_type;
  77. struct fw_card_driver;
  78. struct fw_node;
  79. struct fw_card {
  80. const struct fw_card_driver *driver;
  81. struct device *device;
  82. struct kref kref;
  83. struct completion done;
  84. int node_id;
  85. int generation;
  86. int current_tlabel;
  87. u64 tlabel_mask;
  88. struct list_head transaction_list;
  89. struct timer_list flush_timer;
  90. unsigned long reset_jiffies;
  91. unsigned long long guid;
  92. unsigned max_receive;
  93. int link_speed;
  94. int config_rom_generation;
  95. spinlock_t lock; /* Take this lock when handling the lists in
  96. * this struct. */
  97. struct fw_node *local_node;
  98. struct fw_node *root_node;
  99. struct fw_node *irm_node;
  100. u8 color; /* must be u8 to match the definition in struct fw_node */
  101. int gap_count;
  102. bool beta_repeaters_present;
  103. int index;
  104. struct list_head link;
  105. /* Work struct for BM duties. */
  106. struct delayed_work work;
  107. int bm_retries;
  108. int bm_generation;
  109. bool broadcast_channel_allocated;
  110. u32 broadcast_channel;
  111. u32 topology_map[(CSR_TOPOLOGY_MAP_END - CSR_TOPOLOGY_MAP) / 4];
  112. };
  113. static inline struct fw_card *fw_card_get(struct fw_card *card)
  114. {
  115. kref_get(&card->kref);
  116. return card;
  117. }
  118. void fw_card_release(struct kref *kref);
  119. static inline void fw_card_put(struct fw_card *card)
  120. {
  121. kref_put(&card->kref, fw_card_release);
  122. }
  123. struct fw_attribute_group {
  124. struct attribute_group *groups[2];
  125. struct attribute_group group;
  126. struct attribute *attrs[12];
  127. };
  128. enum fw_device_state {
  129. FW_DEVICE_INITIALIZING,
  130. FW_DEVICE_RUNNING,
  131. FW_DEVICE_GONE,
  132. FW_DEVICE_SHUTDOWN,
  133. };
  134. /*
  135. * Note, fw_device.generation always has to be read before fw_device.node_id.
  136. * Use SMP memory barriers to ensure this. Otherwise requests will be sent
  137. * to an outdated node_id if the generation was updated in the meantime due
  138. * to a bus reset.
  139. *
  140. * Likewise, fw-core will take care to update .node_id before .generation so
  141. * that whenever fw_device.generation is current WRT the actual bus generation,
  142. * fw_device.node_id is guaranteed to be current too.
  143. *
  144. * The same applies to fw_device.card->node_id vs. fw_device.generation.
  145. *
  146. * fw_device.config_rom and fw_device.config_rom_length may be accessed during
  147. * the lifetime of any fw_unit belonging to the fw_device, before device_del()
  148. * was called on the last fw_unit. Alternatively, they may be accessed while
  149. * holding fw_device_rwsem.
  150. */
  151. struct fw_device {
  152. atomic_t state;
  153. struct fw_node *node;
  154. int node_id;
  155. int generation;
  156. unsigned max_speed;
  157. struct fw_card *card;
  158. struct device device;
  159. struct mutex client_list_mutex;
  160. struct list_head client_list;
  161. u32 *config_rom;
  162. size_t config_rom_length;
  163. int config_rom_retries;
  164. unsigned is_local:1;
  165. unsigned max_rec:4;
  166. unsigned cmc:1;
  167. unsigned irmc:1;
  168. unsigned bc_implemented:2;
  169. struct delayed_work work;
  170. struct fw_attribute_group attribute_group;
  171. };
  172. static inline struct fw_device *fw_device(struct device *dev)
  173. {
  174. return container_of(dev, struct fw_device, device);
  175. }
  176. static inline int fw_device_is_shutdown(struct fw_device *device)
  177. {
  178. return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN;
  179. }
  180. static inline struct fw_device *fw_device_get(struct fw_device *device)
  181. {
  182. get_device(&device->device);
  183. return device;
  184. }
  185. static inline void fw_device_put(struct fw_device *device)
  186. {
  187. put_device(&device->device);
  188. }
  189. int fw_device_enable_phys_dma(struct fw_device *device);
  190. /*
  191. * fw_unit.directory must not be accessed after device_del(&fw_unit.device).
  192. */
  193. struct fw_unit {
  194. struct device device;
  195. u32 *directory;
  196. struct fw_attribute_group attribute_group;
  197. };
  198. static inline struct fw_unit *fw_unit(struct device *dev)
  199. {
  200. return container_of(dev, struct fw_unit, device);
  201. }
  202. static inline struct fw_unit *fw_unit_get(struct fw_unit *unit)
  203. {
  204. get_device(&unit->device);
  205. return unit;
  206. }
  207. static inline void fw_unit_put(struct fw_unit *unit)
  208. {
  209. put_device(&unit->device);
  210. }
  211. static inline struct fw_device *fw_parent_device(struct fw_unit *unit)
  212. {
  213. return fw_device(unit->device.parent);
  214. }
  215. struct ieee1394_device_id;
  216. struct fw_driver {
  217. struct device_driver driver;
  218. /* Called when the parent device sits through a bus reset. */
  219. void (*update)(struct fw_unit *unit);
  220. const struct ieee1394_device_id *id_table;
  221. };
  222. struct fw_packet;
  223. struct fw_request;
  224. typedef void (*fw_packet_callback_t)(struct fw_packet *packet,
  225. struct fw_card *card, int status);
  226. typedef void (*fw_transaction_callback_t)(struct fw_card *card, int rcode,
  227. void *data, size_t length,
  228. void *callback_data);
  229. /*
  230. * Important note: The callback must guarantee that either fw_send_response()
  231. * or kfree() is called on the @request.
  232. */
  233. typedef void (*fw_address_callback_t)(struct fw_card *card,
  234. struct fw_request *request,
  235. int tcode, int destination, int source,
  236. int generation, int speed,
  237. unsigned long long offset,
  238. void *data, size_t length,
  239. void *callback_data);
  240. struct fw_packet {
  241. int speed;
  242. int generation;
  243. u32 header[4];
  244. size_t header_length;
  245. void *payload;
  246. size_t payload_length;
  247. dma_addr_t payload_bus;
  248. u32 timestamp;
  249. /*
  250. * This callback is called when the packet transmission has
  251. * completed; for successful transmission, the status code is
  252. * the ack received from the destination, otherwise it's a
  253. * negative errno: ENOMEM, ESTALE, ETIMEDOUT, ENODEV, EIO.
  254. * The callback can be called from tasklet context and thus
  255. * must never block.
  256. */
  257. fw_packet_callback_t callback;
  258. int ack;
  259. struct list_head link;
  260. void *driver_data;
  261. };
  262. struct fw_transaction {
  263. int node_id; /* The generation is implied; it is always the current. */
  264. int tlabel;
  265. int timestamp;
  266. struct list_head link;
  267. struct fw_packet packet;
  268. /*
  269. * The data passed to the callback is valid only during the
  270. * callback.
  271. */
  272. fw_transaction_callback_t callback;
  273. void *callback_data;
  274. };
  275. struct fw_address_handler {
  276. u64 offset;
  277. size_t length;
  278. fw_address_callback_t address_callback;
  279. void *callback_data;
  280. struct list_head link;
  281. };
  282. struct fw_address_region {
  283. u64 start;
  284. u64 end;
  285. };
  286. extern const struct fw_address_region fw_high_memory_region;
  287. int fw_core_add_address_handler(struct fw_address_handler *handler,
  288. const struct fw_address_region *region);
  289. void fw_core_remove_address_handler(struct fw_address_handler *handler);
  290. void fw_send_response(struct fw_card *card,
  291. struct fw_request *request, int rcode);
  292. void fw_send_request(struct fw_card *card, struct fw_transaction *t,
  293. int tcode, int destination_id, int generation, int speed,
  294. unsigned long long offset, void *payload, size_t length,
  295. fw_transaction_callback_t callback, void *callback_data);
  296. int fw_cancel_transaction(struct fw_card *card,
  297. struct fw_transaction *transaction);
  298. int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
  299. int generation, int speed, unsigned long long offset,
  300. void *payload, size_t length);
  301. #endif /* _LINUX_FIREWIRE_H */