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