]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | |
2 | #ifndef _IEEE1394_CORE_H | |
3 | #define _IEEE1394_CORE_H | |
4 | ||
5 | #include <linux/slab.h> | |
1da177e4 LT |
6 | #include <asm/atomic.h> |
7 | #include <asm/semaphore.h> | |
8 | #include "hosts.h" | |
9 | ||
10 | ||
11 | struct hpsb_packet { | |
741854e4 SR |
12 | /* This struct is basically read-only for hosts with the exception of |
13 | * the data buffer contents and xnext - see below. */ | |
1da177e4 LT |
14 | |
15 | /* This can be used for host driver internal linking. | |
16 | * | |
17 | * NOTE: This must be left in init state when the driver is done | |
18 | * with it (e.g. by using list_del_init()), since the core does | |
19 | * some sanity checks to make sure the packet is not on a | |
20 | * driver_list when free'ing it. */ | |
21 | struct list_head driver_list; | |
22 | ||
741854e4 | 23 | nodeid_t node_id; |
1da177e4 | 24 | |
741854e4 SR |
25 | /* Async and Iso types should be clear, raw means send-as-is, do not |
26 | * CRC! Byte swapping shall still be done in this case. */ | |
27 | enum { hpsb_async, hpsb_iso, hpsb_raw } __attribute__((packed)) type; | |
1da177e4 | 28 | |
741854e4 SR |
29 | /* Okay, this is core internal and a no care for hosts. |
30 | * queued = queued for sending | |
31 | * pending = sent, waiting for response | |
32 | * complete = processing completed, successful or not | |
33 | */ | |
34 | enum { | |
35 | hpsb_unused, hpsb_queued, hpsb_pending, hpsb_complete | |
36 | } __attribute__((packed)) state; | |
1da177e4 | 37 | |
741854e4 SR |
38 | /* These are core internal. */ |
39 | signed char tlabel; | |
07bbeaf1 LT |
40 | signed char ack_code; |
41 | unsigned char tcode; | |
1da177e4 | 42 | |
741854e4 SR |
43 | unsigned expect_response:1; |
44 | unsigned no_waiter:1; | |
1da177e4 | 45 | |
741854e4 SR |
46 | /* Speed to transmit with: 0 = 100Mbps, 1 = 200Mbps, 2 = 400Mbps */ |
47 | unsigned speed_code:2; | |
1da177e4 | 48 | |
741854e4 SR |
49 | /* |
50 | * *header and *data are guaranteed to be 32-bit DMAable and may be | |
51 | * overwritten to allow in-place byte swapping. Neither of these is | |
52 | * CRCed (the sizes also don't include CRC), but contain space for at | |
53 | * least one additional quadlet to allow in-place CRCing. The memory is | |
54 | * also guaranteed to be DMA mappable. | |
55 | */ | |
56 | quadlet_t *header; | |
57 | quadlet_t *data; | |
58 | size_t header_size; | |
59 | size_t data_size; | |
1da177e4 LT |
60 | |
61 | ||
741854e4 SR |
62 | struct hpsb_host *host; |
63 | unsigned int generation; | |
1da177e4 LT |
64 | |
65 | atomic_t refcnt; | |
66 | ||
67 | /* Function (and possible data to pass to it) to call when this | |
68 | * packet is completed. */ | |
69 | void (*complete_routine)(void *); | |
70 | void *complete_data; | |
71 | ||
72 | /* XXX This is just a hack at the moment */ | |
73 | struct sk_buff *skb; | |
74 | ||
741854e4 SR |
75 | /* Store jiffies for implementing bus timeouts. */ |
76 | unsigned long sendtime; | |
1da177e4 | 77 | |
741854e4 | 78 | quadlet_t embedded_header[5]; |
1da177e4 LT |
79 | }; |
80 | ||
81 | /* Set a task for when a packet completes */ | |
82 | void hpsb_set_packet_complete_task(struct hpsb_packet *packet, | |
83 | void (*routine)(void *), void *data); | |
84 | ||
85 | static inline struct hpsb_packet *driver_packet(struct list_head *l) | |
86 | { | |
87 | return list_entry(l, struct hpsb_packet, driver_list); | |
88 | } | |
89 | ||
90 | void abort_timedouts(unsigned long __opaque); | |
91 | ||
92 | struct hpsb_packet *hpsb_alloc_packet(size_t data_size); | |
93 | void hpsb_free_packet(struct hpsb_packet *packet); | |
94 | ||
95 | ||
96 | /* | |
97 | * Generation counter for the complete 1394 subsystem. Generation gets | |
98 | * incremented on every change in the subsystem (e.g. bus reset). | |
99 | * | |
100 | * Use the functions, not the variable. | |
101 | */ | |
102 | static inline unsigned int get_hpsb_generation(struct hpsb_host *host) | |
103 | { | |
741854e4 | 104 | return atomic_read(&host->generation); |
1da177e4 LT |
105 | } |
106 | ||
107 | /* | |
108 | * Send a PHY configuration packet, return 0 on success, negative | |
109 | * errno on failure. | |
110 | */ | |
111 | int hpsb_send_phy_config(struct hpsb_host *host, int rootid, int gapcnt); | |
112 | ||
113 | /* | |
114 | * Queue packet for transmitting, return 0 on success, negative errno | |
115 | * on failure. | |
116 | */ | |
117 | int hpsb_send_packet(struct hpsb_packet *packet); | |
118 | ||
119 | /* | |
120 | * Queue packet for transmitting, and block until the transaction | |
121 | * completes. Return 0 on success, negative errno on failure. | |
122 | */ | |
123 | int hpsb_send_packet_and_wait(struct hpsb_packet *packet); | |
124 | ||
125 | /* Initiate bus reset on the given host. Returns 1 if bus reset already in | |
126 | * progress, 0 otherwise. */ | |
127 | int hpsb_reset_bus(struct hpsb_host *host, int type); | |
128 | ||
129 | /* | |
130 | * The following functions are exported for host driver module usage. All of | |
131 | * them are safe to use in interrupt contexts, although some are quite | |
132 | * complicated so you may want to run them in bottom halves instead of calling | |
133 | * them directly. | |
134 | */ | |
135 | ||
136 | /* Notify a bus reset to the core. Returns 1 if bus reset already in progress, | |
137 | * 0 otherwise. */ | |
138 | int hpsb_bus_reset(struct hpsb_host *host); | |
139 | ||
140 | /* | |
141 | * Hand over received selfid packet to the core. Complement check (second | |
d6e05edc | 142 | * quadlet is complement of first) is expected to be done and successful. |
1da177e4 LT |
143 | */ |
144 | void hpsb_selfid_received(struct hpsb_host *host, quadlet_t sid); | |
145 | ||
146 | /* | |
147 | * Notify completion of SelfID stage to the core and report new physical ID | |
148 | * and whether host is root now. | |
149 | */ | |
150 | void hpsb_selfid_complete(struct hpsb_host *host, int phyid, int isroot); | |
151 | ||
152 | /* | |
153 | * Notify core of sending a packet. Ackcode is the ack code returned for async | |
154 | * transmits or ACKX_SEND_ERROR if the transmission failed completely; ACKX_NONE | |
155 | * for other cases (internal errors that don't justify a panic). Safe to call | |
156 | * from within a transmit packet routine. | |
157 | */ | |
158 | void hpsb_packet_sent(struct hpsb_host *host, struct hpsb_packet *packet, | |
741854e4 | 159 | int ackcode); |
1da177e4 LT |
160 | |
161 | /* | |
162 | * Hand over received packet to the core. The contents of data are expected to | |
163 | * be the full packet but with the CRCs left out (data block follows header | |
164 | * immediately), with the header (i.e. the first four quadlets) in machine byte | |
165 | * order and the data block in big endian. *data can be safely overwritten | |
166 | * after this call. | |
167 | * | |
168 | * If the packet is a write request, write_acked is to be set to true if it was | |
169 | * ack_complete'd already, false otherwise. This arg is ignored for any other | |
170 | * packet type. | |
171 | */ | |
172 | void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size, | |
741854e4 | 173 | int write_acked); |
1da177e4 LT |
174 | |
175 | ||
176 | /* | |
177 | * CHARACTER DEVICE DISPATCHING | |
178 | * | |
179 | * All ieee1394 character device drivers share the same major number | |
180 | * (major 171). The 256 minor numbers are allocated to the various | |
181 | * task-specific interfaces (raw1394, video1394, dv1394, etc) in | |
182 | * blocks of 16. | |
183 | * | |
184 | * The core ieee1394.o module allocates the device number region | |
185 | * 171:0-255, the various drivers must then cdev_add() their cdev | |
186 | * objects to handle their respective sub-regions. | |
187 | * | |
188 | * Minor device number block allocations: | |
189 | * | |
190 | * Block 0 ( 0- 15) raw1394 | |
191 | * Block 1 ( 16- 31) video1394 | |
192 | * Block 2 ( 32- 47) dv1394 | |
193 | * | |
194 | * Blocks 3-14 free for future allocation | |
195 | * | |
196 | * Block 15 (240-255) reserved for drivers under development, etc. | |
197 | */ | |
198 | ||
741854e4 | 199 | #define IEEE1394_MAJOR 171 |
1da177e4 | 200 | |
741854e4 SR |
201 | #define IEEE1394_MINOR_BLOCK_RAW1394 0 |
202 | #define IEEE1394_MINOR_BLOCK_VIDEO1394 1 | |
203 | #define IEEE1394_MINOR_BLOCK_DV1394 2 | |
1da177e4 LT |
204 | #define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15 |
205 | ||
741854e4 SR |
206 | #define IEEE1394_CORE_DEV MKDEV(IEEE1394_MAJOR, 0) |
207 | #define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_RAW1394 * 16) | |
208 | #define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_VIDEO1394 * 16) | |
209 | #define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_DV1394 * 16) | |
741854e4 | 210 | #define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16) |
1da177e4 LT |
211 | |
212 | /* return the index (within a minor number block) of a file */ | |
213 | static inline unsigned char ieee1394_file_to_instance(struct file *file) | |
214 | { | |
215 | return file->f_dentry->d_inode->i_cindex; | |
216 | } | |
217 | ||
218 | extern int hpsb_disable_irm; | |
219 | ||
220 | /* Our sysfs bus entry */ | |
221 | extern struct bus_type ieee1394_bus_type; | |
222 | extern struct class hpsb_host_class; | |
7e25ab91 | 223 | extern struct class *hpsb_protocol_class; |
1da177e4 LT |
224 | |
225 | #endif /* _IEEE1394_CORE_H */ | |
7e25ab91 | 226 |