blob: 31d9efccdc0da73e957e61f0ec1d90c65949f26a [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -07006#include <asm/atomic.h>
7#include <asm/semaphore.h>
8#include "hosts.h"
9
10
11struct hpsb_packet {
Stefan Richter741854e2005-12-01 18:52:03 -050012 /* This struct is basically read-only for hosts with the exception of
13 * the data buffer contents and xnext - see below. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
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
Stefan Richter741854e2005-12-01 18:52:03 -050023 nodeid_t node_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Stefan Richter741854e2005-12-01 18:52:03 -050025 /* 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Stefan Richter741854e2005-12-01 18:52:03 -050029 /* 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Stefan Richter741854e2005-12-01 18:52:03 -050038 /* These are core internal. */
39 signed char tlabel;
Linus Torvalds07bbeaf2005-07-06 13:05:50 -070040 signed char ack_code;
41 unsigned char tcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070042
Stefan Richter741854e2005-12-01 18:52:03 -050043 unsigned expect_response:1;
44 unsigned no_waiter:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Stefan Richter741854e2005-12-01 18:52:03 -050046 /* Speed to transmit with: 0 = 100Mbps, 1 = 200Mbps, 2 = 400Mbps */
47 unsigned speed_code:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Stefan Richter741854e2005-12-01 18:52:03 -050049 /*
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
Stefan Richter741854e2005-12-01 18:52:03 -050061 struct hpsb_host *host;
62 unsigned int generation;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64 atomic_t refcnt;
65
66 /* Function (and possible data to pass to it) to call when this
67 * packet is completed. */
68 void (*complete_routine)(void *);
69 void *complete_data;
70
71 /* XXX This is just a hack at the moment */
72 struct sk_buff *skb;
73
Stefan Richter741854e2005-12-01 18:52:03 -050074 /* Store jiffies for implementing bus timeouts. */
75 unsigned long sendtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Stefan Richter741854e2005-12-01 18:52:03 -050077 quadlet_t embedded_header[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -070078};
79
80/* Set a task for when a packet completes */
81void hpsb_set_packet_complete_task(struct hpsb_packet *packet,
Stefan Richtere1d118f2006-07-03 12:02:28 -040082 void (*routine)(void *), void *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
84static inline struct hpsb_packet *driver_packet(struct list_head *l)
85{
86 return list_entry(l, struct hpsb_packet, driver_list);
87}
88
89void abort_timedouts(unsigned long __opaque);
90
91struct hpsb_packet *hpsb_alloc_packet(size_t data_size);
92void hpsb_free_packet(struct hpsb_packet *packet);
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094/*
95 * Generation counter for the complete 1394 subsystem. Generation gets
96 * incremented on every change in the subsystem (e.g. bus reset).
97 *
98 * Use the functions, not the variable.
99 */
100static inline unsigned int get_hpsb_generation(struct hpsb_host *host)
101{
Stefan Richter741854e2005-12-01 18:52:03 -0500102 return atomic_read(&host->generation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
104
105/*
106 * Send a PHY configuration packet, return 0 on success, negative
107 * errno on failure.
108 */
109int hpsb_send_phy_config(struct hpsb_host *host, int rootid, int gapcnt);
110
111/*
112 * Queue packet for transmitting, return 0 on success, negative errno
113 * on failure.
114 */
115int hpsb_send_packet(struct hpsb_packet *packet);
116
117/*
118 * Queue packet for transmitting, and block until the transaction
119 * completes. Return 0 on success, negative errno on failure.
120 */
121int hpsb_send_packet_and_wait(struct hpsb_packet *packet);
122
123/* Initiate bus reset on the given host. Returns 1 if bus reset already in
124 * progress, 0 otherwise. */
125int hpsb_reset_bus(struct hpsb_host *host, int type);
126
127/*
128 * The following functions are exported for host driver module usage. All of
129 * them are safe to use in interrupt contexts, although some are quite
130 * complicated so you may want to run them in bottom halves instead of calling
131 * them directly.
132 */
133
134/* Notify a bus reset to the core. Returns 1 if bus reset already in progress,
135 * 0 otherwise. */
136int hpsb_bus_reset(struct hpsb_host *host);
137
138/*
139 * Hand over received selfid packet to the core. Complement check (second
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200140 * quadlet is complement of first) is expected to be done and successful.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 */
142void hpsb_selfid_received(struct hpsb_host *host, quadlet_t sid);
143
144/*
145 * Notify completion of SelfID stage to the core and report new physical ID
146 * and whether host is root now.
147 */
148void hpsb_selfid_complete(struct hpsb_host *host, int phyid, int isroot);
149
150/*
151 * Notify core of sending a packet. Ackcode is the ack code returned for async
152 * transmits or ACKX_SEND_ERROR if the transmission failed completely; ACKX_NONE
153 * for other cases (internal errors that don't justify a panic). Safe to call
154 * from within a transmit packet routine.
155 */
156void hpsb_packet_sent(struct hpsb_host *host, struct hpsb_packet *packet,
Stefan Richter741854e2005-12-01 18:52:03 -0500157 int ackcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
159/*
160 * Hand over received packet to the core. The contents of data are expected to
161 * be the full packet but with the CRCs left out (data block follows header
162 * immediately), with the header (i.e. the first four quadlets) in machine byte
163 * order and the data block in big endian. *data can be safely overwritten
164 * after this call.
165 *
166 * If the packet is a write request, write_acked is to be set to true if it was
167 * ack_complete'd already, false otherwise. This arg is ignored for any other
168 * packet type.
169 */
170void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
Stefan Richter741854e2005-12-01 18:52:03 -0500171 int write_acked);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173
174/*
175 * CHARACTER DEVICE DISPATCHING
176 *
177 * All ieee1394 character device drivers share the same major number
178 * (major 171). The 256 minor numbers are allocated to the various
179 * task-specific interfaces (raw1394, video1394, dv1394, etc) in
180 * blocks of 16.
181 *
182 * The core ieee1394.o module allocates the device number region
183 * 171:0-255, the various drivers must then cdev_add() their cdev
184 * objects to handle their respective sub-regions.
185 *
186 * Minor device number block allocations:
187 *
188 * Block 0 ( 0- 15) raw1394
189 * Block 1 ( 16- 31) video1394
190 * Block 2 ( 32- 47) dv1394
191 *
192 * Blocks 3-14 free for future allocation
193 *
194 * Block 15 (240-255) reserved for drivers under development, etc.
195 */
196
Stefan Richter741854e2005-12-01 18:52:03 -0500197#define IEEE1394_MAJOR 171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Stefan Richter741854e2005-12-01 18:52:03 -0500199#define IEEE1394_MINOR_BLOCK_RAW1394 0
200#define IEEE1394_MINOR_BLOCK_VIDEO1394 1
201#define IEEE1394_MINOR_BLOCK_DV1394 2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202#define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15
203
Stefan Richter741854e2005-12-01 18:52:03 -0500204#define IEEE1394_CORE_DEV MKDEV(IEEE1394_MAJOR, 0)
Stefan Richtere1d118f2006-07-03 12:02:28 -0400205#define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, \
206 IEEE1394_MINOR_BLOCK_RAW1394 * 16)
207#define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, \
208 IEEE1394_MINOR_BLOCK_VIDEO1394 * 16)
209#define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, \
210 IEEE1394_MINOR_BLOCK_DV1394 * 16)
211#define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, \
212 IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214/* return the index (within a minor number block) of a file */
215static inline unsigned char ieee1394_file_to_instance(struct file *file)
216{
217 return file->f_dentry->d_inode->i_cindex;
218}
219
220extern int hpsb_disable_irm;
221
222/* Our sysfs bus entry */
223extern struct bus_type ieee1394_bus_type;
224extern struct class hpsb_host_class;
gregkh@suse.de7e25ab92005-03-23 09:53:36 -0800225extern struct class *hpsb_protocol_class;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226
227#endif /* _IEEE1394_CORE_H */