blob: bd29d8ef5bbd9c58c7a698901c86558421367e2f [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>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010
Stefan Richterde4394f2006-07-03 12:02:29 -040011#include "hosts.h"
12#include "ieee1394_types.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14struct hpsb_packet {
Stefan Richter741854e2005-12-01 18:52:03 -050015 /* This struct is basically read-only for hosts with the exception of
16 * the data buffer contents and xnext - see below. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070017
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
Stefan Richter741854e2005-12-01 18:52:03 -050026 nodeid_t node_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Stefan Richter741854e2005-12-01 18:52:03 -050028 /* Async and Iso types should be clear, raw means send-as-is, do not
29 * CRC! Byte swapping shall still be done in this case. */
30 enum { hpsb_async, hpsb_iso, hpsb_raw } __attribute__((packed)) type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Stefan Richter741854e2005-12-01 18:52:03 -050032 /* Okay, this is core internal and a no care for hosts.
33 * queued = queued for sending
34 * pending = sent, waiting for response
35 * complete = processing completed, successful or not
36 */
37 enum {
38 hpsb_unused, hpsb_queued, hpsb_pending, hpsb_complete
39 } __attribute__((packed)) state;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
Stefan Richter741854e2005-12-01 18:52:03 -050041 /* These are core internal. */
42 signed char tlabel;
Linus Torvalds07bbeaf2005-07-06 13:05:50 -070043 signed char ack_code;
44 unsigned char tcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Stefan Richter741854e2005-12-01 18:52:03 -050046 unsigned expect_response:1;
47 unsigned no_waiter:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Stefan Richter741854e2005-12-01 18:52:03 -050049 /* Speed to transmit with: 0 = 100Mbps, 1 = 200Mbps, 2 = 400Mbps */
50 unsigned speed_code:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Stefan Richter741854e2005-12-01 18:52:03 -050052 /*
53 * *header and *data are guaranteed to be 32-bit DMAable and may be
54 * overwritten to allow in-place byte swapping. Neither of these is
55 * CRCed (the sizes also don't include CRC), but contain space for at
56 * least one additional quadlet to allow in-place CRCing. The memory is
57 * also guaranteed to be DMA mappable.
58 */
59 quadlet_t *header;
60 quadlet_t *data;
61 size_t header_size;
62 size_t data_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Stefan Richter741854e2005-12-01 18:52:03 -050064 struct hpsb_host *host;
65 unsigned int generation;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67 atomic_t refcnt;
68
69 /* Function (and possible data to pass to it) to call when this
70 * packet is completed. */
71 void (*complete_routine)(void *);
72 void *complete_data;
73
74 /* XXX This is just a hack at the moment */
75 struct sk_buff *skb;
76
Stefan Richter741854e2005-12-01 18:52:03 -050077 /* Store jiffies for implementing bus timeouts. */
78 unsigned long sendtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Stefan Richter741854e2005-12-01 18:52:03 -050080 quadlet_t embedded_header[5];
Linus Torvalds1da177e2005-04-16 15:20:36 -070081};
82
83/* Set a task for when a packet completes */
84void hpsb_set_packet_complete_task(struct hpsb_packet *packet,
Stefan Richtere1d118f2006-07-03 12:02:28 -040085 void (*routine)(void *), void *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070086
87static inline struct hpsb_packet *driver_packet(struct list_head *l)
88{
89 return list_entry(l, struct hpsb_packet, driver_list);
90}
91
92void abort_timedouts(unsigned long __opaque);
93
94struct hpsb_packet *hpsb_alloc_packet(size_t data_size);
95void hpsb_free_packet(struct hpsb_packet *packet);
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097/*
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{
Stefan Richter741854e2005-12-01 18:52:03 -0500105 return atomic_read(&host->generation);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106}
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
Pieter Palmers3dc5ea92007-02-03 17:44:39 +0100130int hpsb_read_cycle_timer(struct hpsb_host *host, u32 *cycle_timer,
131 u64 *local_time);
132
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133/*
134 * The following functions are exported for host driver module usage. All of
135 * them are safe to use in interrupt contexts, although some are quite
136 * complicated so you may want to run them in bottom halves instead of calling
137 * them directly.
138 */
139
140/* Notify a bus reset to the core. Returns 1 if bus reset already in progress,
141 * 0 otherwise. */
142int hpsb_bus_reset(struct hpsb_host *host);
143
144/*
145 * Hand over received selfid packet to the core. Complement check (second
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200146 * quadlet is complement of first) is expected to be done and successful.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 */
148void hpsb_selfid_received(struct hpsb_host *host, quadlet_t sid);
149
150/*
151 * Notify completion of SelfID stage to the core and report new physical ID
152 * and whether host is root now.
153 */
154void hpsb_selfid_complete(struct hpsb_host *host, int phyid, int isroot);
155
156/*
157 * Notify core of sending a packet. Ackcode is the ack code returned for async
158 * transmits or ACKX_SEND_ERROR if the transmission failed completely; ACKX_NONE
159 * for other cases (internal errors that don't justify a panic). Safe to call
160 * from within a transmit packet routine.
161 */
162void hpsb_packet_sent(struct hpsb_host *host, struct hpsb_packet *packet,
Stefan Richter741854e2005-12-01 18:52:03 -0500163 int ackcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
165/*
166 * Hand over received packet to the core. The contents of data are expected to
167 * be the full packet but with the CRCs left out (data block follows header
168 * immediately), with the header (i.e. the first four quadlets) in machine byte
169 * order and the data block in big endian. *data can be safely overwritten
170 * after this call.
171 *
172 * If the packet is a write request, write_acked is to be set to true if it was
173 * ack_complete'd already, false otherwise. This arg is ignored for any other
174 * packet type.
175 */
176void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
Stefan Richter741854e2005-12-01 18:52:03 -0500177 int write_acked);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
179
180/*
181 * CHARACTER DEVICE DISPATCHING
182 *
183 * All ieee1394 character device drivers share the same major number
184 * (major 171). The 256 minor numbers are allocated to the various
185 * task-specific interfaces (raw1394, video1394, dv1394, etc) in
186 * blocks of 16.
187 *
188 * The core ieee1394.o module allocates the device number region
189 * 171:0-255, the various drivers must then cdev_add() their cdev
190 * objects to handle their respective sub-regions.
191 *
192 * Minor device number block allocations:
193 *
194 * Block 0 ( 0- 15) raw1394
195 * Block 1 ( 16- 31) video1394
196 * Block 2 ( 32- 47) dv1394
197 *
198 * Blocks 3-14 free for future allocation
199 *
200 * Block 15 (240-255) reserved for drivers under development, etc.
201 */
202
Stefan Richter741854e2005-12-01 18:52:03 -0500203#define IEEE1394_MAJOR 171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Stefan Richter741854e2005-12-01 18:52:03 -0500205#define IEEE1394_MINOR_BLOCK_RAW1394 0
206#define IEEE1394_MINOR_BLOCK_VIDEO1394 1
207#define IEEE1394_MINOR_BLOCK_DV1394 2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208#define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15
209
Stefan Richter741854e2005-12-01 18:52:03 -0500210#define IEEE1394_CORE_DEV MKDEV(IEEE1394_MAJOR, 0)
Stefan Richtere1d118f2006-07-03 12:02:28 -0400211#define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, \
212 IEEE1394_MINOR_BLOCK_RAW1394 * 16)
213#define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, \
214 IEEE1394_MINOR_BLOCK_VIDEO1394 * 16)
215#define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, \
216 IEEE1394_MINOR_BLOCK_DV1394 * 16)
217#define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, \
218 IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220/* return the index (within a minor number block) of a file */
221static inline unsigned char ieee1394_file_to_instance(struct file *file)
222{
Josef Sipek4db61082006-12-08 02:37:10 -0800223 return file->f_path.dentry->d_inode->i_cindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224}
225
226extern int hpsb_disable_irm;
227
228/* Our sysfs bus entry */
229extern struct bus_type ieee1394_bus_type;
230extern struct class hpsb_host_class;
gregkh@suse.de7e25ab92005-03-23 09:53:36 -0800231extern struct class *hpsb_protocol_class;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233#endif /* _IEEE1394_CORE_H */