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