fw-transaction.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. /* -*- c-basic-offset: 8 -*-
  2. *
  3. * fw-transaction.h - Header for IEEE1394 transaction logic
  4. *
  5. * Copyright (C) 2003-2006 Kristian Hoegsberg <krh@bitplanet.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software Foundation,
  19. * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  20. */
  21. #ifndef __fw_core_h
  22. #define __fw_core_h
  23. #include <linux/device.h>
  24. #include <linux/timer.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/list.h>
  27. #include <linux/fs.h>
  28. #define TCODE_WRITE_QUADLET_REQUEST 0
  29. #define TCODE_WRITE_BLOCK_REQUEST 1
  30. #define TCODE_WRITE_RESPONSE 2
  31. #define TCODE_READ_QUADLET_REQUEST 4
  32. #define TCODE_READ_BLOCK_REQUEST 5
  33. #define TCODE_READ_QUADLET_RESPONSE 6
  34. #define TCODE_READ_BLOCK_RESPONSE 7
  35. #define TCODE_CYCLE_START 8
  36. #define TCODE_LOCK_REQUEST 9
  37. #define TCODE_STREAM_DATA 10
  38. #define TCODE_LOCK_RESPONSE 11
  39. #define TCODE_IS_BLOCK_PACKET(tcode) (((tcode) & 1) != 0)
  40. #define TCODE_IS_REQUEST(tcode) (((tcode) & 2) == 0)
  41. #define TCODE_IS_RESPONSE(tcode) (((tcode) & 2) != 0)
  42. #define TCODE_HAS_REQUEST_DATA(tcode) (((tcode) & 12) != 4)
  43. #define TCODE_HAS_RESPONSE_DATA(tcode) (((tcode) & 12) != 0)
  44. /* Juju specific tcodes */
  45. #define TCODE_DEALLOCATE 0x10
  46. #define TCODE_LOCK_MASK_SWAP 0x11
  47. #define TCODE_LOCK_COMPARE_SWAP 0x12
  48. #define TCODE_LOCK_FETCH_ADD 0x13
  49. #define TCODE_LOCK_LITTLE_ADD 0x14
  50. #define TCODE_LOCK_BOUNDED_ADD 0x15
  51. #define TCODE_LOCK_WRAP_ADD 0x16
  52. #define TCODE_LOCK_VENDOR_SPECIFIC 0x17
  53. #define SCODE_100 0x0
  54. #define SCODE_200 0x1
  55. #define SCODE_400 0x2
  56. #define SCODE_BETA 0x3
  57. #define EXTCODE_MASK_SWAP 0x1
  58. #define EXTCODE_COMPARE_SWAP 0x2
  59. #define EXTCODE_FETCH_ADD 0x3
  60. #define EXTCODE_LITTLE_ADD 0x4
  61. #define EXTCODE_BOUNDED_ADD 0x5
  62. #define EXTCODE_WRAP_ADD 0x6
  63. #define ACK_COMPLETE 0x1
  64. #define ACK_PENDING 0x2
  65. #define ACK_BUSY_X 0x4
  66. #define ACK_BUSY_A 0x5
  67. #define ACK_BUSY_B 0x6
  68. #define ACK_DATA_ERROR 0xd
  69. #define ACK_TYPE_ERROR 0xe
  70. #define RCODE_COMPLETE 0x0
  71. #define RCODE_CONFLICT_ERROR 0x4
  72. #define RCODE_DATA_ERROR 0x5
  73. #define RCODE_TYPE_ERROR 0x6
  74. #define RCODE_ADDRESS_ERROR 0x7
  75. /* Juju specific rcodes */
  76. #define RCODE_SEND_ERROR 0x10
  77. #define RCODE_CANCELLED 0x11
  78. #define RCODE_BUSY 0x12
  79. #define RETRY_1 0x00
  80. #define RETRY_X 0x01
  81. #define RETRY_A 0x02
  82. #define RETRY_B 0x03
  83. #define LOCAL_BUS 0xffc0
  84. #define SELFID_PORT_CHILD 0x3
  85. #define SELFID_PORT_PARENT 0x2
  86. #define SELFID_PORT_NCONN 0x1
  87. #define SELFID_PORT_NONE 0x0
  88. #define PHY_PACKET_CONFIG 0x0
  89. #define PHY_PACKET_LINK_ON 0x1
  90. #define PHY_PACKET_SELF_ID 0x2
  91. #define fw_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, ## args)
  92. #define fw_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args)
  93. #define fw_debug(s, args...) printk(KERN_DEBUG KBUILD_MODNAME ": " s, ## args)
  94. static inline void
  95. fw_memcpy_from_be32(void *_dst, void *_src, size_t size)
  96. {
  97. u32 *dst = _dst;
  98. u32 *src = _src;
  99. int i;
  100. for (i = 0; i < size / 4; i++)
  101. dst[i] = cpu_to_be32(src[i]);
  102. }
  103. static inline void
  104. fw_memcpy_to_be32(void *_dst, void *_src, size_t size)
  105. {
  106. fw_memcpy_from_be32(_dst, _src, size);
  107. }
  108. struct fw_card;
  109. struct fw_packet;
  110. struct fw_node;
  111. struct fw_request;
  112. struct fw_descriptor {
  113. struct list_head link;
  114. size_t length;
  115. u32 key;
  116. u32 *data;
  117. };
  118. int fw_core_add_descriptor (struct fw_descriptor *desc);
  119. void fw_core_remove_descriptor (struct fw_descriptor *desc);
  120. typedef void (*fw_packet_callback_t) (struct fw_packet *packet,
  121. struct fw_card *card, int status);
  122. typedef void (*fw_transaction_callback_t)(struct fw_card *card, int rcode,
  123. void *data,
  124. size_t length,
  125. void *callback_data);
  126. typedef void (*fw_address_callback_t)(struct fw_card *card,
  127. struct fw_request *request,
  128. int tcode, int destination, int source,
  129. int generation, int speed,
  130. unsigned long long offset,
  131. void *data, size_t length,
  132. void *callback_data);
  133. typedef void (*fw_bus_reset_callback_t)(struct fw_card *handle,
  134. int node_id, int generation,
  135. u32 *self_ids,
  136. int self_id_count,
  137. void *callback_data);
  138. struct fw_packet {
  139. int speed;
  140. int generation;
  141. u32 header[4];
  142. size_t header_length;
  143. void *payload;
  144. size_t payload_length;
  145. u32 timestamp;
  146. dma_addr_t payload_bus;
  147. /* This callback is called when the packet transmission has
  148. * completed; for successful transmission, the status code is
  149. * the ack received from the destination, otherwise it's a
  150. * negative errno: ENOMEM, ESTALE, ETIMEDOUT, ENODEV, EIO.
  151. * The callback can be called from tasklet context and thus
  152. * must never block.
  153. */
  154. fw_packet_callback_t callback;
  155. int status;
  156. struct list_head link;
  157. };
  158. struct fw_transaction {
  159. int node_id; /* The generation is implied; it is always the current. */
  160. int tlabel;
  161. int timestamp;
  162. struct list_head link;
  163. struct fw_packet packet;
  164. /* The data passed to the callback is valid only during the
  165. * callback. */
  166. fw_transaction_callback_t callback;
  167. void *callback_data;
  168. };
  169. extern inline struct fw_packet *
  170. fw_packet(struct list_head *l)
  171. {
  172. return list_entry (l, struct fw_packet, link);
  173. }
  174. struct fw_address_handler {
  175. u64 offset;
  176. size_t length;
  177. fw_address_callback_t address_callback;
  178. void *callback_data;
  179. struct list_head link;
  180. };
  181. struct fw_address_region {
  182. u64 start;
  183. u64 end;
  184. };
  185. extern struct fw_address_region fw_low_memory_region;
  186. extern struct fw_address_region fw_high_memory_region;
  187. extern struct fw_address_region fw_private_region;
  188. extern struct fw_address_region fw_csr_region;
  189. extern struct fw_address_region fw_unit_space_region;
  190. int fw_core_add_address_handler(struct fw_address_handler *handler,
  191. struct fw_address_region *region);
  192. void fw_core_remove_address_handler(struct fw_address_handler *handler);
  193. void fw_send_response(struct fw_card *card,
  194. struct fw_request *request, int rcode);
  195. extern struct bus_type fw_bus_type;
  196. struct fw_card {
  197. struct fw_card_driver *driver;
  198. struct device *device;
  199. int node_id;
  200. int generation;
  201. /* This is the generation used for timestamping incoming requests. */
  202. int request_generation;
  203. int current_tlabel, tlabel_mask;
  204. struct list_head transaction_list;
  205. struct timer_list flush_timer;
  206. unsigned long long guid;
  207. int max_receive;
  208. int link_speed;
  209. int config_rom_generation;
  210. /* We need to store up to 4 self ID for a maximum of 63 devices. */
  211. int self_id_count;
  212. u32 self_ids[252];
  213. spinlock_t lock; /* Take this lock when handling the lists in
  214. * this struct. */
  215. struct fw_node *local_node;
  216. struct fw_node *root_node;
  217. struct fw_node *irm_node;
  218. int color;
  219. int index;
  220. struct device card_device;
  221. struct list_head link;
  222. /* Work struct for IRM duties. */
  223. struct delayed_work work;
  224. int irm_retries;
  225. };
  226. struct fw_card *fw_card_get(struct fw_card *card);
  227. void fw_card_put(struct fw_card *card);
  228. /* The iso packet format allows for an immediate header/payload part
  229. * stored in 'header' immediately after the packet info plus an
  230. * indirect payload part that is pointer to by the 'payload' field.
  231. * Applications can use one or the other or both to implement simple
  232. * low-bandwidth streaming (e.g. audio) or more advanced
  233. * scatter-gather streaming (e.g. assembling video frame automatically). */
  234. struct fw_iso_packet {
  235. u16 payload_length; /* Length of indirect payload. */
  236. u32 interrupt : 1; /* Generate interrupt on this packet */
  237. u32 skip : 1; /* Set to not send packet at all. */
  238. u32 tag : 2;
  239. u32 sy : 4;
  240. u32 header_length : 8; /* Length of immediate header. */
  241. u32 header[0];
  242. };
  243. #define FW_ISO_CONTEXT_TRANSMIT 0
  244. #define FW_ISO_CONTEXT_RECEIVE 1
  245. struct fw_iso_context;
  246. typedef void (*fw_iso_callback_t) (struct fw_iso_context *context,
  247. int status, u32 cycle, void *data);
  248. struct fw_iso_context {
  249. struct fw_card *card;
  250. int type;
  251. int channel;
  252. int speed;
  253. fw_iso_callback_t callback;
  254. void *callback_data;
  255. void *buffer;
  256. size_t buffer_size;
  257. dma_addr_t *pages;
  258. int page_count;
  259. };
  260. struct fw_iso_context *
  261. fw_iso_context_create(struct fw_card *card, int type,
  262. size_t buffer_size,
  263. fw_iso_callback_t callback,
  264. void *callback_data);
  265. void
  266. fw_iso_context_destroy(struct fw_iso_context *ctx);
  267. void
  268. fw_iso_context_start(struct fw_iso_context *ctx,
  269. int channel, int speed, int cycle);
  270. int
  271. fw_iso_context_queue(struct fw_iso_context *ctx,
  272. struct fw_iso_packet *packet, void *payload);
  273. int
  274. fw_iso_context_send(struct fw_iso_context *ctx,
  275. int channel, int speed, int cycle);
  276. struct fw_card_driver {
  277. const char *name;
  278. /* Enable the given card with the given initial config rom.
  279. * This function is expected to activate the card, and either
  280. * enable the PHY or set the link_on bit and initiate a bus
  281. * reset. */
  282. int (*enable) (struct fw_card *card, u32 *config_rom, size_t length);
  283. int (*update_phy_reg) (struct fw_card *card, int address,
  284. int clear_bits, int set_bits);
  285. /* Update the config rom for an enabled card. This function
  286. * should change the config rom that is presented on the bus
  287. * an initiate a bus reset. */
  288. int (*set_config_rom) (struct fw_card *card,
  289. u32 *config_rom, size_t length);
  290. void (*send_request) (struct fw_card *card, struct fw_packet *packet);
  291. void (*send_response) (struct fw_card *card, struct fw_packet *packet);
  292. /* Allow the specified node ID to do direct DMA out and in of
  293. * host memory. The card will disable this for all node when
  294. * a bus reset happens, so driver need to reenable this after
  295. * bus reset. Returns 0 on success, -ENODEV if the card
  296. * doesn't support this, -ESTALE if the generation doesn't
  297. * match. */
  298. int (*enable_phys_dma) (struct fw_card *card,
  299. int node_id, int generation);
  300. struct fw_iso_context *
  301. (*allocate_iso_context)(struct fw_card *card, int type);
  302. void (*free_iso_context)(struct fw_iso_context *ctx);
  303. int (*send_iso)(struct fw_iso_context *ctx, s32 cycle);
  304. int (*queue_iso)(struct fw_iso_context *ctx,
  305. struct fw_iso_packet *packet, void *payload);
  306. };
  307. int
  308. fw_core_initiate_bus_reset(struct fw_card *card, int short_reset);
  309. void
  310. fw_send_request(struct fw_card *card, struct fw_transaction *t,
  311. int tcode, int node_id, int generation, int speed,
  312. unsigned long long offset,
  313. void *data, size_t length,
  314. fw_transaction_callback_t callback, void *callback_data);
  315. void fw_flush_transactions(struct fw_card *card);
  316. void
  317. fw_send_force_root(struct fw_card *card, int node_id, int generation);
  318. /* Called by the topology code to inform the device code of node
  319. * activity; found, lost, or updated nodes */
  320. void
  321. fw_node_event(struct fw_card *card, struct fw_node *node, int event);
  322. /* API used by card level drivers */
  323. /* Do we need phy speed here also? If we add more args, maybe we
  324. should go back to struct fw_card_info. */
  325. void
  326. fw_card_initialize(struct fw_card *card, struct fw_card_driver *driver,
  327. struct device *device);
  328. int
  329. fw_card_add(struct fw_card *card,
  330. u32 max_receive, u32 link_speed, u64 guid);
  331. void
  332. fw_core_remove_card(struct fw_card *card);
  333. void
  334. fw_core_handle_bus_reset(struct fw_card *card,
  335. int node_id, int generation,
  336. int self_id_count, u32 *self_ids);
  337. void
  338. fw_core_handle_request(struct fw_card *card,
  339. int speed, int ack, int timestamp,
  340. int generation,
  341. u32 length, u32 *payload);
  342. void
  343. fw_core_handle_response(struct fw_card *card,
  344. int speed, int ack, int timestamp,
  345. u32 length, u32 *payload);
  346. #endif /* __fw_core_h */