1 #ifndef _LINUX_FIREWIRE_H
2 #define _LINUX_FIREWIRE_H
4 #include <linux/completion.h>
5 #include <linux/device.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>
16 #include <asm/atomic.h>
17 #include <asm/byteorder.h>
19 #define fw_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, ## args)
20 #define fw_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args)
22 static inline void fw_memcpy_from_be32(void *_dst, void *_src, size_t size)
28 for (i = 0; i < size / 4; i++)
29 dst[i] = be32_to_cpu(src[i]);
32 static inline void fw_memcpy_to_be32(void *_dst, void *_src, size_t size)
34 fw_memcpy_from_be32(_dst, _src, size);
36 #define CSR_REGISTER_BASE 0xfffff0000000ULL
38 /* register offsets are relative to CSR_REGISTER_BASE */
39 #define CSR_STATE_CLEAR 0x0
40 #define CSR_STATE_SET 0x4
41 #define CSR_NODE_IDS 0x8
42 #define CSR_RESET_START 0xc
43 #define CSR_SPLIT_TIMEOUT_HI 0x18
44 #define CSR_SPLIT_TIMEOUT_LO 0x1c
45 #define CSR_CYCLE_TIME 0x200
46 #define CSR_BUS_TIME 0x204
47 #define CSR_BUSY_TIMEOUT 0x210
48 #define CSR_BUS_MANAGER_ID 0x21c
49 #define CSR_BANDWIDTH_AVAILABLE 0x220
50 #define CSR_CHANNELS_AVAILABLE 0x224
51 #define CSR_CHANNELS_AVAILABLE_HI 0x224
52 #define CSR_CHANNELS_AVAILABLE_LO 0x228
53 #define CSR_BROADCAST_CHANNEL 0x234
54 #define CSR_CONFIG_ROM 0x400
55 #define CSR_CONFIG_ROM_END 0x800
56 #define CSR_FCP_COMMAND 0xB00
57 #define CSR_FCP_RESPONSE 0xD00
58 #define CSR_FCP_END 0xF00
59 #define CSR_TOPOLOGY_MAP 0x1000
60 #define CSR_TOPOLOGY_MAP_END 0x1400
61 #define CSR_SPEED_MAP 0x2000
62 #define CSR_SPEED_MAP_END 0x3000
64 #define CSR_OFFSET 0x40
66 #define CSR_DIRECTORY 0xc0
68 #define CSR_DESCRIPTOR 0x01
69 #define CSR_VENDOR 0x03
70 #define CSR_HARDWARE_VERSION 0x04
71 #define CSR_NODE_CAPABILITIES 0x0c
73 #define CSR_SPECIFIER_ID 0x12
74 #define CSR_VERSION 0x13
75 #define CSR_DEPENDENT_INFO 0x14
76 #define CSR_MODEL 0x17
77 #define CSR_INSTANCE 0x18
78 #define CSR_DIRECTORY_ID 0x20
80 struct fw_csr_iterator {
85 void fw_csr_iterator_init(struct fw_csr_iterator *ci, u32 *p);
86 int fw_csr_iterator_next(struct fw_csr_iterator *ci, int *key, int *value);
88 extern struct bus_type fw_bus_type;
90 struct fw_card_driver;
94 const struct fw_card_driver *driver;
95 struct device *device;
97 struct completion done;
103 struct list_head transaction_list;
104 struct timer_list flush_timer;
105 unsigned long reset_jiffies;
107 unsigned long long guid;
108 unsigned max_receive;
110 int config_rom_generation;
112 spinlock_t lock; /* Take this lock when handling the lists in
114 struct fw_node *local_node;
115 struct fw_node *root_node;
116 struct fw_node *irm_node;
117 u8 color; /* must be u8 to match the definition in struct fw_node */
119 bool beta_repeaters_present;
123 struct list_head link;
125 /* Work struct for BM duties. */
126 struct delayed_work work;
130 bool broadcast_channel_allocated;
131 u32 broadcast_channel;
132 u32 topology_map[(CSR_TOPOLOGY_MAP_END - CSR_TOPOLOGY_MAP) / 4];
135 static inline struct fw_card *fw_card_get(struct fw_card *card)
137 kref_get(&card->kref);
142 void fw_card_release(struct kref *kref);
144 static inline void fw_card_put(struct fw_card *card)
146 kref_put(&card->kref, fw_card_release);
149 struct fw_attribute_group {
150 struct attribute_group *groups[2];
151 struct attribute_group group;
152 struct attribute *attrs[12];
155 enum fw_device_state {
156 FW_DEVICE_INITIALIZING,
163 * Note, fw_device.generation always has to be read before fw_device.node_id.
164 * Use SMP memory barriers to ensure this. Otherwise requests will be sent
165 * to an outdated node_id if the generation was updated in the meantime due
168 * Likewise, fw-core will take care to update .node_id before .generation so
169 * that whenever fw_device.generation is current WRT the actual bus generation,
170 * fw_device.node_id is guaranteed to be current too.
172 * The same applies to fw_device.card->node_id vs. fw_device.generation.
174 * fw_device.config_rom and fw_device.config_rom_length may be accessed during
175 * the lifetime of any fw_unit belonging to the fw_device, before device_del()
176 * was called on the last fw_unit. Alternatively, they may be accessed while
177 * holding fw_device_rwsem.
181 struct fw_node *node;
185 struct fw_card *card;
186 struct device device;
188 struct mutex client_list_mutex;
189 struct list_head client_list;
192 size_t config_rom_length;
193 int config_rom_retries;
198 unsigned bc_implemented:2;
200 struct delayed_work work;
201 struct fw_attribute_group attribute_group;
204 static inline struct fw_device *fw_device(struct device *dev)
206 return container_of(dev, struct fw_device, device);
209 static inline int fw_device_is_shutdown(struct fw_device *device)
211 return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN;
214 static inline struct fw_device *fw_device_get(struct fw_device *device)
216 get_device(&device->device);
221 static inline void fw_device_put(struct fw_device *device)
223 put_device(&device->device);
226 int fw_device_enable_phys_dma(struct fw_device *device);
229 * fw_unit.directory must not be accessed after device_del(&fw_unit.device).
232 struct device device;
234 struct fw_attribute_group attribute_group;
237 static inline struct fw_unit *fw_unit(struct device *dev)
239 return container_of(dev, struct fw_unit, device);
242 static inline struct fw_unit *fw_unit_get(struct fw_unit *unit)
244 get_device(&unit->device);
249 static inline void fw_unit_put(struct fw_unit *unit)
251 put_device(&unit->device);
254 static inline struct fw_device *fw_parent_device(struct fw_unit *unit)
256 return fw_device(unit->device.parent);
259 struct ieee1394_device_id;
262 struct device_driver driver;
263 /* Called when the parent device sits through a bus reset. */
264 void (*update)(struct fw_unit *unit);
265 const struct ieee1394_device_id *id_table;
271 typedef void (*fw_packet_callback_t)(struct fw_packet *packet,
272 struct fw_card *card, int status);
273 typedef void (*fw_transaction_callback_t)(struct fw_card *card, int rcode,
274 void *data, size_t length,
275 void *callback_data);
277 * Important note: The callback must guarantee that either fw_send_response()
278 * or kfree() is called on the @request.
280 typedef void (*fw_address_callback_t)(struct fw_card *card,
281 struct fw_request *request,
282 int tcode, int destination, int source,
283 int generation, int speed,
284 unsigned long long offset,
285 void *data, size_t length,
286 void *callback_data);
292 size_t header_length;
294 size_t payload_length;
295 dma_addr_t payload_bus;
299 * This callback is called when the packet transmission has
300 * completed; for successful transmission, the status code is
301 * the ack received from the destination, otherwise it's a
302 * negative errno: ENOMEM, ESTALE, ETIMEDOUT, ENODEV, EIO.
303 * The callback can be called from tasklet context and thus
306 fw_packet_callback_t callback;
308 struct list_head link;
312 struct fw_transaction {
313 int node_id; /* The generation is implied; it is always the current. */
316 struct list_head link;
318 struct fw_packet packet;
321 * The data passed to the callback is valid only during the
324 fw_transaction_callback_t callback;
328 struct fw_address_handler {
331 fw_address_callback_t address_callback;
333 struct list_head link;
336 struct fw_address_region {
341 extern const struct fw_address_region fw_high_memory_region;
343 int fw_core_add_address_handler(struct fw_address_handler *handler,
344 const struct fw_address_region *region);
345 void fw_core_remove_address_handler(struct fw_address_handler *handler);
346 void fw_send_response(struct fw_card *card,
347 struct fw_request *request, int rcode);
348 void fw_send_request(struct fw_card *card, struct fw_transaction *t,
349 int tcode, int destination_id, int generation, int speed,
350 unsigned long long offset, void *payload, size_t length,
351 fw_transaction_callback_t callback, void *callback_data);
352 int fw_cancel_transaction(struct fw_card *card,
353 struct fw_transaction *transaction);
354 int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
355 int generation, int speed, unsigned long long offset,
356 void *payload, size_t length);
358 #endif /* _LINUX_FIREWIRE_H */