core.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #ifndef _FIREWIRE_CORE_H
  2. #define _FIREWIRE_CORE_H
  3. #include <linux/fs.h>
  4. #include <linux/list.h>
  5. #include <linux/idr.h>
  6. #include <linux/mm_types.h>
  7. #include <linux/rwsem.h>
  8. #include <linux/slab.h>
  9. #include <linux/types.h>
  10. #include <asm/atomic.h>
  11. struct device;
  12. struct fw_card;
  13. struct fw_device;
  14. struct fw_iso_buffer;
  15. struct fw_iso_context;
  16. struct fw_iso_packet;
  17. struct fw_node;
  18. struct fw_packet;
  19. /* -card */
  20. /* bitfields within the PHY registers */
  21. #define PHY_LINK_ACTIVE 0x80
  22. #define PHY_CONTENDER 0x40
  23. #define PHY_BUS_RESET 0x40
  24. #define PHY_EXTENDED_REGISTERS 0xe0
  25. #define PHY_BUS_SHORT_RESET 0x40
  26. #define PHY_INT_STATUS_BITS 0x3c
  27. #define PHY_ENABLE_ACCEL 0x02
  28. #define PHY_ENABLE_MULTI 0x01
  29. #define PHY_PAGE_SELECT 0xe0
  30. #define BANDWIDTH_AVAILABLE_INITIAL 4915
  31. #define BROADCAST_CHANNEL_INITIAL (1 << 31 | 31)
  32. #define BROADCAST_CHANNEL_VALID (1 << 30)
  33. struct fw_card_driver {
  34. /*
  35. * Enable the given card with the given initial config rom.
  36. * This function is expected to activate the card, and either
  37. * enable the PHY or set the link_on bit and initiate a bus
  38. * reset.
  39. */
  40. int (*enable)(struct fw_card *card,
  41. const __be32 *config_rom, size_t length);
  42. int (*update_phy_reg)(struct fw_card *card, int address,
  43. int clear_bits, int set_bits);
  44. /*
  45. * Update the config rom for an enabled card. This function
  46. * should change the config rom that is presented on the bus
  47. * and initiate a bus reset.
  48. */
  49. int (*set_config_rom)(struct fw_card *card,
  50. const __be32 *config_rom, size_t length);
  51. void (*send_request)(struct fw_card *card, struct fw_packet *packet);
  52. void (*send_response)(struct fw_card *card, struct fw_packet *packet);
  53. /* Calling cancel is valid once a packet has been submitted. */
  54. int (*cancel_packet)(struct fw_card *card, struct fw_packet *packet);
  55. /*
  56. * Allow the specified node ID to do direct DMA out and in of
  57. * host memory. The card will disable this for all node when
  58. * a bus reset happens, so driver need to reenable this after
  59. * bus reset. Returns 0 on success, -ENODEV if the card
  60. * doesn't support this, -ESTALE if the generation doesn't
  61. * match.
  62. */
  63. int (*enable_phys_dma)(struct fw_card *card,
  64. int node_id, int generation);
  65. u32 (*get_cycle_time)(struct fw_card *card);
  66. struct fw_iso_context *
  67. (*allocate_iso_context)(struct fw_card *card,
  68. int type, int channel, size_t header_size);
  69. void (*free_iso_context)(struct fw_iso_context *ctx);
  70. int (*start_iso)(struct fw_iso_context *ctx,
  71. s32 cycle, u32 sync, u32 tags);
  72. int (*queue_iso)(struct fw_iso_context *ctx,
  73. struct fw_iso_packet *packet,
  74. struct fw_iso_buffer *buffer,
  75. unsigned long payload);
  76. int (*stop_iso)(struct fw_iso_context *ctx);
  77. };
  78. void fw_card_initialize(struct fw_card *card,
  79. const struct fw_card_driver *driver, struct device *device);
  80. int fw_card_add(struct fw_card *card,
  81. u32 max_receive, u32 link_speed, u64 guid);
  82. void fw_core_remove_card(struct fw_card *card);
  83. int fw_core_initiate_bus_reset(struct fw_card *card, int short_reset);
  84. int fw_compute_block_crc(__be32 *block);
  85. void fw_schedule_bm_work(struct fw_card *card, unsigned long delay);
  86. static inline struct fw_card *fw_card_get(struct fw_card *card)
  87. {
  88. kref_get(&card->kref);
  89. return card;
  90. }
  91. void fw_card_release(struct kref *kref);
  92. static inline void fw_card_put(struct fw_card *card)
  93. {
  94. kref_put(&card->kref, fw_card_release);
  95. }
  96. /* -cdev */
  97. extern const struct file_operations fw_device_ops;
  98. void fw_device_cdev_update(struct fw_device *device);
  99. void fw_device_cdev_remove(struct fw_device *device);
  100. /* -device */
  101. extern struct rw_semaphore fw_device_rwsem;
  102. extern struct idr fw_device_idr;
  103. extern int fw_cdev_major;
  104. struct fw_device *fw_device_get_by_devt(dev_t devt);
  105. int fw_device_set_broadcast_channel(struct device *dev, void *gen);
  106. void fw_node_event(struct fw_card *card, struct fw_node *node, int event);
  107. /* -iso */
  108. int fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma);
  109. void fw_iso_resource_manage(struct fw_card *card, int generation,
  110. u64 channels_mask, int *channel, int *bandwidth,
  111. bool allocate, __be32 buffer[2]);
  112. /* -topology */
  113. enum {
  114. FW_NODE_CREATED,
  115. FW_NODE_UPDATED,
  116. FW_NODE_DESTROYED,
  117. FW_NODE_LINK_ON,
  118. FW_NODE_LINK_OFF,
  119. FW_NODE_INITIATED_RESET,
  120. };
  121. struct fw_node {
  122. u16 node_id;
  123. u8 color;
  124. u8 port_count;
  125. u8 link_on:1;
  126. u8 initiated_reset:1;
  127. u8 b_path:1;
  128. u8 phy_speed:2; /* As in the self ID packet. */
  129. u8 max_speed:2; /* Minimum of all phy-speeds on the path from the
  130. * local node to this node. */
  131. u8 max_depth:4; /* Maximum depth to any leaf node */
  132. u8 max_hops:4; /* Max hops in this sub tree */
  133. atomic_t ref_count;
  134. /* For serializing node topology into a list. */
  135. struct list_head link;
  136. /* Upper layer specific data. */
  137. void *data;
  138. struct fw_node *ports[0];
  139. };
  140. static inline struct fw_node *fw_node_get(struct fw_node *node)
  141. {
  142. atomic_inc(&node->ref_count);
  143. return node;
  144. }
  145. static inline void fw_node_put(struct fw_node *node)
  146. {
  147. if (atomic_dec_and_test(&node->ref_count))
  148. kfree(node);
  149. }
  150. void fw_core_handle_bus_reset(struct fw_card *card, int node_id,
  151. int generation, int self_id_count, u32 *self_ids);
  152. void fw_destroy_nodes(struct fw_card *card);
  153. /*
  154. * Check whether new_generation is the immediate successor of old_generation.
  155. * Take counter roll-over at 255 (as per OHCI) into account.
  156. */
  157. static inline bool is_next_generation(int new_generation, int old_generation)
  158. {
  159. return (new_generation & 0xff) == ((old_generation + 1) & 0xff);
  160. }
  161. /* -transaction */
  162. #define TCODE_IS_READ_REQUEST(tcode) (((tcode) & ~1) == 4)
  163. #define TCODE_IS_BLOCK_PACKET(tcode) (((tcode) & 1) != 0)
  164. #define TCODE_IS_REQUEST(tcode) (((tcode) & 2) == 0)
  165. #define TCODE_IS_RESPONSE(tcode) (((tcode) & 2) != 0)
  166. #define TCODE_HAS_REQUEST_DATA(tcode) (((tcode) & 12) != 4)
  167. #define TCODE_HAS_RESPONSE_DATA(tcode) (((tcode) & 12) != 0)
  168. #define LOCAL_BUS 0xffc0
  169. void fw_core_handle_request(struct fw_card *card, struct fw_packet *request);
  170. void fw_core_handle_response(struct fw_card *card, struct fw_packet *packet);
  171. void fw_fill_response(struct fw_packet *response, u32 *request_header,
  172. int rcode, void *payload, size_t length);
  173. void fw_send_phy_config(struct fw_card *card,
  174. int node_id, int generation, int gap_count);
  175. #endif /* _FIREWIRE_CORE_H */