Merge branch 'thermal-2.6.33' into release
[linux-2.6-block.git] / drivers / ieee1394 / ieee1394_core.h
CommitLineData
1da177e4
LT
1#ifndef _IEEE1394_CORE_H
2#define _IEEE1394_CORE_H
3
de4394f1
SR
4#include <linux/device.h>
5#include <linux/fs.h>
6#include <linux/list.h>
de4394f1 7#include <linux/types.h>
9fd5746f 8#include <linux/cdev.h>
1da177e4 9#include <asm/atomic.h>
1da177e4 10
de4394f1
SR
11#include "hosts.h"
12#include "ieee1394_types.h"
1da177e4
LT
13
14struct hpsb_packet {
741854e4 15 /* This struct is basically read-only for hosts with the exception of
7542e0e6 16 * the data buffer contents and driver_list. */
1da177e4
LT
17
18 /* This can be used for host driver internal linking.
19 *
20 * NOTE: This must be left in init state when the driver is done
21 * with it (e.g. by using list_del_init()), since the core does
22 * some sanity checks to make sure the packet is not on a
23 * driver_list when free'ing it. */
24 struct list_head driver_list;
25
741854e4 26 nodeid_t node_id;
1da177e4 27
53c96b41
SR
28 /* hpsb_raw = send as-is, do not CRC (but still byte-swap it) */
29 enum { hpsb_async, hpsb_raw } __attribute__((packed)) type;
1da177e4 30
741854e4
SR
31 /* Okay, this is core internal and a no care for hosts.
32 * queued = queued for sending
33 * pending = sent, waiting for response
34 * complete = processing completed, successful or not
35 */
36 enum {
37 hpsb_unused, hpsb_queued, hpsb_pending, hpsb_complete
38 } __attribute__((packed)) state;
1da177e4 39
6552731a 40 /* These are core-internal. */
741854e4 41 signed char tlabel;
07bbeaf1
LT
42 signed char ack_code;
43 unsigned char tcode;
1da177e4 44
741854e4
SR
45 unsigned expect_response:1;
46 unsigned no_waiter:1;
1da177e4 47
741854e4
SR
48 /* Speed to transmit with: 0 = 100Mbps, 1 = 200Mbps, 2 = 400Mbps */
49 unsigned speed_code:2;
1da177e4 50
741854e4
SR
51 struct hpsb_host *host;
52 unsigned int generation;
1da177e4
LT
53
54 atomic_t refcnt;
7542e0e6 55 struct list_head queue;
1da177e4
LT
56
57 /* Function (and possible data to pass to it) to call when this
58 * packet is completed. */
59 void (*complete_routine)(void *);
60 void *complete_data;
61
741854e4
SR
62 /* Store jiffies for implementing bus timeouts. */
63 unsigned long sendtime;
1da177e4 64
6552731a 65 /* Core-internal. */
7542e0e6 66 size_t allocated_data_size; /* as allocated */
6552731a
SR
67
68 /* Sizes are in bytes. To be set by caller of hpsb_alloc_packet. */
7542e0e6
SR
69 size_t data_size; /* as filled in */
70 size_t header_size; /* as filled in, not counting the CRC */
6552731a
SR
71
72 /* Buffers */
73 quadlet_t *data; /* can be DMA-mapped */
7542e0e6
SR
74 quadlet_t header[5];
75 quadlet_t embedded_data[0]; /* keep as last member */
1da177e4
LT
76};
77
1da177e4 78void hpsb_set_packet_complete_task(struct hpsb_packet *packet,
e1d118f1 79 void (*routine)(void *), void *data);
1da177e4
LT
80static inline struct hpsb_packet *driver_packet(struct list_head *l)
81{
82 return list_entry(l, struct hpsb_packet, driver_list);
83}
1da177e4 84void abort_timedouts(unsigned long __opaque);
1da177e4
LT
85struct hpsb_packet *hpsb_alloc_packet(size_t data_size);
86void hpsb_free_packet(struct hpsb_packet *packet);
87
afd6546d
SR
88/**
89 * get_hpsb_generation - generation counter for the complete 1394 subsystem
1da177e4 90 *
afd6546d
SR
91 * Generation gets incremented on every change in the subsystem (notably on bus
92 * resets). Use the functions, not the variable.
1da177e4
LT
93 */
94static inline unsigned int get_hpsb_generation(struct hpsb_host *host)
95{
741854e4 96 return atomic_read(&host->generation);
1da177e4
LT
97}
98
1da177e4 99int hpsb_send_phy_config(struct hpsb_host *host, int rootid, int gapcnt);
1da177e4 100int hpsb_send_packet(struct hpsb_packet *packet);
1da177e4 101int hpsb_send_packet_and_wait(struct hpsb_packet *packet);
1da177e4 102int hpsb_reset_bus(struct hpsb_host *host, int type);
3dc5ea9b
PP
103int hpsb_read_cycle_timer(struct hpsb_host *host, u32 *cycle_timer,
104 u64 *local_time);
105
1da177e4 106int hpsb_bus_reset(struct hpsb_host *host);
1da177e4 107void hpsb_selfid_received(struct hpsb_host *host, quadlet_t sid);
1da177e4 108void hpsb_selfid_complete(struct hpsb_host *host, int phyid, int isroot);
1da177e4 109void hpsb_packet_sent(struct hpsb_host *host, struct hpsb_packet *packet,
741854e4 110 int ackcode);
1da177e4 111void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
741854e4 112 int write_acked);
1da177e4 113
1da177e4
LT
114/*
115 * CHARACTER DEVICE DISPATCHING
116 *
117 * All ieee1394 character device drivers share the same major number
118 * (major 171). The 256 minor numbers are allocated to the various
119 * task-specific interfaces (raw1394, video1394, dv1394, etc) in
120 * blocks of 16.
121 *
122 * The core ieee1394.o module allocates the device number region
123 * 171:0-255, the various drivers must then cdev_add() their cdev
124 * objects to handle their respective sub-regions.
125 *
126 * Minor device number block allocations:
127 *
128 * Block 0 ( 0- 15) raw1394
129 * Block 1 ( 16- 31) video1394
130 * Block 2 ( 32- 47) dv1394
131 *
132 * Blocks 3-14 free for future allocation
133 *
134 * Block 15 (240-255) reserved for drivers under development, etc.
135 */
136
741854e4 137#define IEEE1394_MAJOR 171
1da177e4 138
741854e4
SR
139#define IEEE1394_MINOR_BLOCK_RAW1394 0
140#define IEEE1394_MINOR_BLOCK_VIDEO1394 1
141#define IEEE1394_MINOR_BLOCK_DV1394 2
1da177e4
LT
142#define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15
143
741854e4 144#define IEEE1394_CORE_DEV MKDEV(IEEE1394_MAJOR, 0)
e1d118f1
SR
145#define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, \
146 IEEE1394_MINOR_BLOCK_RAW1394 * 16)
147#define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, \
148 IEEE1394_MINOR_BLOCK_VIDEO1394 * 16)
149#define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, \
150 IEEE1394_MINOR_BLOCK_DV1394 * 16)
151#define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, \
152 IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16)
1da177e4 153
afd6546d
SR
154/**
155 * ieee1394_file_to_instance - get the index within a minor number block
156 */
1da177e4
LT
157static inline unsigned char ieee1394_file_to_instance(struct file *file)
158{
9fd5746f
TT
159 int idx = cdev_index(file->f_path.dentry->d_inode);
160 if (idx < 0)
161 idx = 0;
162 return idx;
1da177e4
LT
163}
164
165extern int hpsb_disable_irm;
166
167/* Our sysfs bus entry */
168extern struct bus_type ieee1394_bus_type;
169extern struct class hpsb_host_class;
7e25ab91 170extern struct class *hpsb_protocol_class;
1da177e4
LT
171
172#endif /* _IEEE1394_CORE_H */