firewire: add CSR BUSY_TIMEOUT support
[linux-2.6-block.git] / include / linux / firewire.h
CommitLineData
77c9a5da
SR
1#ifndef _LINUX_FIREWIRE_H
2#define _LINUX_FIREWIRE_H
3
4#include <linux/completion.h>
5#include <linux/device.h>
c76acec6 6#include <linux/dma-mapping.h>
77c9a5da
SR
7#include <linux/kernel.h>
8#include <linux/kref.h>
9#include <linux/list.h>
10#include <linux/mutex.h>
11#include <linux/spinlock.h>
12#include <linux/sysfs.h>
13#include <linux/timer.h>
14#include <linux/types.h>
15#include <linux/workqueue.h>
16
17#include <asm/atomic.h>
18#include <asm/byteorder.h>
19
20#define fw_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, ## args)
21#define fw_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args)
22
77c9a5da
SR
23#define CSR_REGISTER_BASE 0xfffff0000000ULL
24
25/* register offsets are relative to CSR_REGISTER_BASE */
26#define CSR_STATE_CLEAR 0x0
27#define CSR_STATE_SET 0x4
28#define CSR_NODE_IDS 0x8
29#define CSR_RESET_START 0xc
30#define CSR_SPLIT_TIMEOUT_HI 0x18
31#define CSR_SPLIT_TIMEOUT_LO 0x1c
32#define CSR_CYCLE_TIME 0x200
33#define CSR_BUS_TIME 0x204
34#define CSR_BUSY_TIMEOUT 0x210
35#define CSR_BUS_MANAGER_ID 0x21c
36#define CSR_BANDWIDTH_AVAILABLE 0x220
37#define CSR_CHANNELS_AVAILABLE 0x224
38#define CSR_CHANNELS_AVAILABLE_HI 0x224
39#define CSR_CHANNELS_AVAILABLE_LO 0x228
40#define CSR_BROADCAST_CHANNEL 0x234
41#define CSR_CONFIG_ROM 0x400
42#define CSR_CONFIG_ROM_END 0x800
43#define CSR_FCP_COMMAND 0xB00
44#define CSR_FCP_RESPONSE 0xD00
45#define CSR_FCP_END 0xF00
46#define CSR_TOPOLOGY_MAP 0x1000
47#define CSR_TOPOLOGY_MAP_END 0x1400
48#define CSR_SPEED_MAP 0x2000
49#define CSR_SPEED_MAP_END 0x3000
50
51#define CSR_OFFSET 0x40
52#define CSR_LEAF 0x80
53#define CSR_DIRECTORY 0xc0
54
55#define CSR_DESCRIPTOR 0x01
56#define CSR_VENDOR 0x03
57#define CSR_HARDWARE_VERSION 0x04
77c9a5da
SR
58#define CSR_UNIT 0x11
59#define CSR_SPECIFIER_ID 0x12
60#define CSR_VERSION 0x13
61#define CSR_DEPENDENT_INFO 0x14
62#define CSR_MODEL 0x17
77c9a5da
SR
63#define CSR_DIRECTORY_ID 0x20
64
65struct fw_csr_iterator {
13b302d0
SR
66 const u32 *p;
67 const u32 *end;
77c9a5da
SR
68};
69
13b302d0 70void fw_csr_iterator_init(struct fw_csr_iterator *ci, const u32 *p);
77c9a5da 71int fw_csr_iterator_next(struct fw_csr_iterator *ci, int *key, int *value);
13b302d0 72int fw_csr_string(const u32 *directory, int key, char *buf, size_t size);
1f8fef7b 73
77c9a5da
SR
74extern struct bus_type fw_bus_type;
75
76struct fw_card_driver;
77struct fw_node;
78
79struct fw_card {
80 const struct fw_card_driver *driver;
81 struct device *device;
82 struct kref kref;
83 struct completion done;
84
85 int node_id;
86 int generation;
1e626fdc
SR
87 int current_tlabel;
88 u64 tlabel_mask;
77c9a5da 89 struct list_head transaction_list;
77c9a5da
SR
90 unsigned long reset_jiffies;
91
8e4b50f9
CL
92 u32 split_timeout_hi;
93 u32 split_timeout_lo;
94 unsigned int split_timeout_cycles;
95 unsigned int split_timeout_jiffies;
96
77c9a5da
SR
97 unsigned long long guid;
98 unsigned max_receive;
99 int link_speed;
100 int config_rom_generation;
101
102 spinlock_t lock; /* Take this lock when handling the lists in
103 * this struct. */
104 struct fw_node *local_node;
105 struct fw_node *root_node;
106 struct fw_node *irm_node;
107 u8 color; /* must be u8 to match the definition in struct fw_node */
108 int gap_count;
109 bool beta_repeaters_present;
110
111 int index;
112
113 struct list_head link;
114
115 /* Work struct for BM duties. */
116 struct delayed_work work;
117 int bm_retries;
118 int bm_generation;
6fdc0370 119 __be32 bm_transaction_data[2];
77c9a5da
SR
120
121 bool broadcast_channel_allocated;
122 u32 broadcast_channel;
cb7c96da 123 __be32 topology_map[(CSR_TOPOLOGY_MAP_END - CSR_TOPOLOGY_MAP) / 4];
77c9a5da
SR
124};
125
77c9a5da
SR
126struct fw_attribute_group {
127 struct attribute_group *groups[2];
128 struct attribute_group group;
129 struct attribute *attrs[12];
130};
131
132enum fw_device_state {
133 FW_DEVICE_INITIALIZING,
134 FW_DEVICE_RUNNING,
135 FW_DEVICE_GONE,
136 FW_DEVICE_SHUTDOWN,
137};
138
139/*
140 * Note, fw_device.generation always has to be read before fw_device.node_id.
141 * Use SMP memory barriers to ensure this. Otherwise requests will be sent
142 * to an outdated node_id if the generation was updated in the meantime due
143 * to a bus reset.
144 *
145 * Likewise, fw-core will take care to update .node_id before .generation so
146 * that whenever fw_device.generation is current WRT the actual bus generation,
147 * fw_device.node_id is guaranteed to be current too.
148 *
149 * The same applies to fw_device.card->node_id vs. fw_device.generation.
150 *
151 * fw_device.config_rom and fw_device.config_rom_length may be accessed during
152 * the lifetime of any fw_unit belonging to the fw_device, before device_del()
153 * was called on the last fw_unit. Alternatively, they may be accessed while
154 * holding fw_device_rwsem.
155 */
156struct fw_device {
157 atomic_t state;
158 struct fw_node *node;
159 int node_id;
160 int generation;
161 unsigned max_speed;
162 struct fw_card *card;
163 struct device device;
164
165 struct mutex client_list_mutex;
166 struct list_head client_list;
167
13b302d0 168 const u32 *config_rom;
77c9a5da
SR
169 size_t config_rom_length;
170 int config_rom_retries;
171 unsigned is_local:1;
837ec787 172 unsigned max_rec:4;
77c9a5da 173 unsigned cmc:1;
837ec787 174 unsigned irmc:1;
77c9a5da
SR
175 unsigned bc_implemented:2;
176
177 struct delayed_work work;
178 struct fw_attribute_group attribute_group;
179};
180
181static inline struct fw_device *fw_device(struct device *dev)
182{
183 return container_of(dev, struct fw_device, device);
184}
185
186static inline int fw_device_is_shutdown(struct fw_device *device)
187{
188 return atomic_read(&device->state) == FW_DEVICE_SHUTDOWN;
189}
190
191static inline struct fw_device *fw_device_get(struct fw_device *device)
192{
193 get_device(&device->device);
194
195 return device;
196}
197
198static inline void fw_device_put(struct fw_device *device)
199{
200 put_device(&device->device);
201}
202
203int fw_device_enable_phys_dma(struct fw_device *device);
204
205/*
206 * fw_unit.directory must not be accessed after device_del(&fw_unit.device).
207 */
208struct fw_unit {
209 struct device device;
13b302d0 210 const u32 *directory;
77c9a5da
SR
211 struct fw_attribute_group attribute_group;
212};
213
214static inline struct fw_unit *fw_unit(struct device *dev)
215{
216 return container_of(dev, struct fw_unit, device);
217}
218
219static inline struct fw_unit *fw_unit_get(struct fw_unit *unit)
220{
221 get_device(&unit->device);
222
223 return unit;
224}
225
226static inline void fw_unit_put(struct fw_unit *unit)
227{
228 put_device(&unit->device);
229}
230
e5110d01
SR
231static inline struct fw_device *fw_parent_device(struct fw_unit *unit)
232{
233 return fw_device(unit->device.parent);
234}
235
77c9a5da
SR
236struct ieee1394_device_id;
237
238struct fw_driver {
239 struct device_driver driver;
240 /* Called when the parent device sits through a bus reset. */
241 void (*update)(struct fw_unit *unit);
242 const struct ieee1394_device_id *id_table;
243};
244
245struct fw_packet;
246struct fw_request;
247
248typedef void (*fw_packet_callback_t)(struct fw_packet *packet,
249 struct fw_card *card, int status);
250typedef void (*fw_transaction_callback_t)(struct fw_card *card, int rcode,
251 void *data, size_t length,
252 void *callback_data);
253/*
db5d247a
CL
254 * Important note: Except for the FCP registers, the callback must guarantee
255 * that either fw_send_response() or kfree() is called on the @request.
77c9a5da
SR
256 */
257typedef void (*fw_address_callback_t)(struct fw_card *card,
258 struct fw_request *request,
259 int tcode, int destination, int source,
260 int generation, int speed,
261 unsigned long long offset,
262 void *data, size_t length,
263 void *callback_data);
264
265struct fw_packet {
266 int speed;
267 int generation;
268 u32 header[4];
269 size_t header_length;
270 void *payload;
271 size_t payload_length;
272 dma_addr_t payload_bus;
19593ffd 273 bool payload_mapped;
77c9a5da
SR
274 u32 timestamp;
275
276 /*
277 * This callback is called when the packet transmission has
278 * completed; for successful transmission, the status code is
279 * the ack received from the destination, otherwise it's a
280 * negative errno: ENOMEM, ESTALE, ETIMEDOUT, ENODEV, EIO.
281 * The callback can be called from tasklet context and thus
282 * must never block.
283 */
284 fw_packet_callback_t callback;
285 int ack;
286 struct list_head link;
287 void *driver_data;
288};
289
290struct fw_transaction {
291 int node_id; /* The generation is implied; it is always the current. */
292 int tlabel;
293 int timestamp;
294 struct list_head link;
5c40cbfe
CL
295 struct fw_card *card;
296 struct timer_list split_timeout_timer;
77c9a5da
SR
297
298 struct fw_packet packet;
299
300 /*
301 * The data passed to the callback is valid only during the
302 * callback.
303 */
304 fw_transaction_callback_t callback;
305 void *callback_data;
306};
307
308struct fw_address_handler {
309 u64 offset;
310 size_t length;
311 fw_address_callback_t address_callback;
312 void *callback_data;
313 struct list_head link;
314};
315
316struct fw_address_region {
317 u64 start;
318 u64 end;
319};
320
321extern const struct fw_address_region fw_high_memory_region;
322
323int fw_core_add_address_handler(struct fw_address_handler *handler,
324 const struct fw_address_region *region);
325void fw_core_remove_address_handler(struct fw_address_handler *handler);
326void fw_send_response(struct fw_card *card,
327 struct fw_request *request, int rcode);
328void fw_send_request(struct fw_card *card, struct fw_transaction *t,
329 int tcode, int destination_id, int generation, int speed,
330 unsigned long long offset, void *payload, size_t length,
331 fw_transaction_callback_t callback, void *callback_data);
332int fw_cancel_transaction(struct fw_card *card,
333 struct fw_transaction *transaction);
334int fw_run_transaction(struct fw_card *card, int tcode, int destination_id,
335 int generation, int speed, unsigned long long offset,
336 void *payload, size_t length);
337
c76acec6
JF
338static inline int fw_stream_packet_destination_id(int tag, int channel, int sy)
339{
340 return tag << 14 | channel << 8 | sy;
341}
342
343struct fw_descriptor {
344 struct list_head link;
345 size_t length;
346 u32 immediate;
347 u32 key;
348 const u32 *data;
349};
350
351int fw_core_add_descriptor(struct fw_descriptor *desc);
352void fw_core_remove_descriptor(struct fw_descriptor *desc);
353
354/*
355 * The iso packet format allows for an immediate header/payload part
356 * stored in 'header' immediately after the packet info plus an
357 * indirect payload part that is pointer to by the 'payload' field.
358 * Applications can use one or the other or both to implement simple
359 * low-bandwidth streaming (e.g. audio) or more advanced
360 * scatter-gather streaming (e.g. assembling video frame automatically).
361 */
362struct fw_iso_packet {
363 u16 payload_length; /* Length of indirect payload. */
364 u32 interrupt:1; /* Generate interrupt on this packet */
365 u32 skip:1; /* Set to not send packet at all. */
366 u32 tag:2;
367 u32 sy:4;
368 u32 header_length:8; /* Length of immediate header. */
369 u32 header[0];
370};
371
372#define FW_ISO_CONTEXT_TRANSMIT 0
373#define FW_ISO_CONTEXT_RECEIVE 1
374
375#define FW_ISO_CONTEXT_MATCH_TAG0 1
376#define FW_ISO_CONTEXT_MATCH_TAG1 2
377#define FW_ISO_CONTEXT_MATCH_TAG2 4
378#define FW_ISO_CONTEXT_MATCH_TAG3 8
379#define FW_ISO_CONTEXT_MATCH_ALL_TAGS 15
380
381/*
382 * An iso buffer is just a set of pages mapped for DMA in the
383 * specified direction. Since the pages are to be used for DMA, they
384 * are not mapped into the kernel virtual address space. We store the
385 * DMA address in the page private. The helper function
386 * fw_iso_buffer_map() will map the pages into a given vma.
387 */
388struct fw_iso_buffer {
389 enum dma_data_direction direction;
390 struct page **pages;
391 int page_count;
392};
393
394int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card,
395 int page_count, enum dma_data_direction direction);
396void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer, struct fw_card *card);
397
398struct fw_iso_context;
399typedef void (*fw_iso_callback_t)(struct fw_iso_context *context,
400 u32 cycle, size_t header_length,
401 void *header, void *data);
402struct fw_iso_context {
403 struct fw_card *card;
404 int type;
405 int channel;
406 int speed;
407 size_t header_size;
408 fw_iso_callback_t callback;
409 void *callback_data;
410};
411
412struct fw_iso_context *fw_iso_context_create(struct fw_card *card,
413 int type, int channel, int speed, size_t header_size,
414 fw_iso_callback_t callback, void *callback_data);
415int fw_iso_context_queue(struct fw_iso_context *ctx,
416 struct fw_iso_packet *packet,
417 struct fw_iso_buffer *buffer,
418 unsigned long payload);
419int fw_iso_context_start(struct fw_iso_context *ctx,
420 int cycle, int sync, int tags);
421int fw_iso_context_stop(struct fw_iso_context *ctx);
422void fw_iso_context_destroy(struct fw_iso_context *ctx);
423
77c9a5da 424#endif /* _LINUX_FIREWIRE_H */