core.h 5.8 KB

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