2 #ifndef _IEEE1394_CORE_H
3 #define _IEEE1394_CORE_H
5 #include <linux/slab.h>
6 #include <linux/devfs_fs_kernel.h>
7 #include <asm/semaphore.h>
12 /* This struct is basically read-only for hosts with the exception of
13 * the data buffer contents and xnext - see below. */
14 struct list_head list;
16 /* This can be used for host driver internal linking. */
17 struct list_head driver_list;
21 /* Async and Iso types should be clear, raw means send-as-is, do not
22 * CRC! Byte swapping shall still be done in this case. */
23 enum { hpsb_async, hpsb_iso, hpsb_raw } __attribute__((packed)) type;
25 /* Okay, this is core internal and a no care for hosts.
26 * queued = queued for sending
27 * pending = sent, waiting for response
28 * complete = processing completed, successful or not
29 * incoming = incoming packet
32 hpsb_unused, hpsb_queued, hpsb_pending, hpsb_complete, hpsb_incoming
33 } __attribute__((packed)) state;
35 /* These are core internal. */
40 unsigned expect_response:1;
43 /* Speed to transmit with: 0 = 100Mbps, 1 = 200Mbps, 2 = 400Mbps */
44 unsigned speed_code:2;
47 * *header and *data are guaranteed to be 32-bit DMAable and may be
48 * overwritten to allow in-place byte swapping. Neither of these is
49 * CRCed (the sizes also don't include CRC), but contain space for at
50 * least one additional quadlet to allow in-place CRCing. The memory is
51 * also guaranteed to be DMA mappable.
59 struct hpsb_host *host;
60 unsigned int generation;
62 /* Function (and possible data to pass to it) to call when this
63 * packet is completed. */
64 void (*complete_routine)(void *);
67 /* Store jiffies for implementing bus timeouts. */
68 unsigned long sendtime;
70 quadlet_t embedded_header[5];
73 /* Set a task for when a packet completes */
74 void hpsb_set_packet_complete_task(struct hpsb_packet *packet,
75 void (*routine)(void *), void *data);
77 static inline struct hpsb_packet *driver_packet(struct list_head *l)
79 return list_entry(l, struct hpsb_packet, driver_list);
82 void abort_timedouts(unsigned long __opaque);
83 void abort_requests(struct hpsb_host *host);
85 struct hpsb_packet *hpsb_alloc_packet(size_t data_size);
86 void hpsb_free_packet(struct hpsb_packet *packet);
90 * Generation counter for the complete 1394 subsystem. Generation gets
91 * incremented on every change in the subsystem (e.g. bus reset).
93 * Use the functions, not the variable.
95 #include <asm/atomic.h>
97 static inline unsigned int get_hpsb_generation(struct hpsb_host *host)
99 return atomic_read(&host->generation);
103 * Send a PHY configuration packet, return 0 on success, negative
106 int hpsb_send_phy_config(struct hpsb_host *host, int rootid, int gapcnt);
109 * Queue packet for transmitting, return 0 on success, negative errno
112 int hpsb_send_packet(struct hpsb_packet *packet);
115 * Queue packet for transmitting, and block until the transaction
116 * completes. Return 0 on success, negative errno on failure.
118 int hpsb_send_packet_and_wait(struct hpsb_packet *packet);
120 /* Initiate bus reset on the given host. Returns 1 if bus reset already in
121 * progress, 0 otherwise. */
122 int hpsb_reset_bus(struct hpsb_host *host, int type);
125 * The following functions are exported for host driver module usage. All of
126 * them are safe to use in interrupt contexts, although some are quite
127 * complicated so you may want to run them in bottom halves instead of calling
131 /* Notify a bus reset to the core. Returns 1 if bus reset already in progress,
133 int hpsb_bus_reset(struct hpsb_host *host);
136 * Hand over received selfid packet to the core. Complement check (second
137 * quadlet is complement of first) is expected to be done and succesful.
139 void hpsb_selfid_received(struct hpsb_host *host, quadlet_t sid);
142 * Notify completion of SelfID stage to the core and report new physical ID
143 * and whether host is root now.
145 void hpsb_selfid_complete(struct hpsb_host *host, int phyid, int isroot);
148 * Notify core of sending a packet. Ackcode is the ack code returned for async
149 * transmits or ACKX_SEND_ERROR if the transmission failed completely; ACKX_NONE
150 * for other cases (internal errors that don't justify a panic). Safe to call
151 * from within a transmit packet routine.
153 void hpsb_packet_sent(struct hpsb_host *host, struct hpsb_packet *packet,
157 * Hand over received packet to the core. The contents of data are expected to
158 * be the full packet but with the CRCs left out (data block follows header
159 * immediately), with the header (i.e. the first four quadlets) in machine byte
160 * order and the data block in big endian. *data can be safely overwritten
163 * If the packet is a write request, write_acked is to be set to true if it was
164 * ack_complete'd already, false otherwise. This arg is ignored for any other
167 void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
172 * CHARACTER DEVICE DISPATCHING
174 * All ieee1394 character device drivers share the same major number
175 * (major 171). The 256 minor numbers are allocated to the various
176 * task-specific interfaces (raw1394, video1394, dv1394, etc) in
179 * The core ieee1394.o modules handles the initial open() for all
180 * character devices on major 171; it then dispatches to the
181 * appropriate task-specific driver.
183 * Minor device number block allocations:
185 * Block 0 ( 0- 15) raw1394
186 * Block 1 ( 16- 31) video1394
187 * Block 2 ( 32- 47) dv1394
189 * Blocks 3-14 free for future allocation
191 * Block 15 (240-255) reserved for drivers under development, etc.
194 #define IEEE1394_MAJOR 171
196 #define IEEE1394_MINOR_BLOCK_RAW1394 0
197 #define IEEE1394_MINOR_BLOCK_VIDEO1394 1
198 #define IEEE1394_MINOR_BLOCK_DV1394 2
199 #define IEEE1394_MINOR_BLOCK_AMDTP 3
200 #define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15
202 /* return the index (within a minor number block) of a file */
203 static inline unsigned char ieee1394_file_to_instance(struct file *file)
205 unsigned char minor = iminor(file->f_dentry->d_inode);
207 /* return lower 4 bits */
212 * Task-specific drivers should call ieee1394_register_chardev() to
213 * request a block of 16 minor numbers.
215 * Returns 0 if the request was successful, -EBUSY if the block was
219 int ieee1394_register_chardev(int blocknum, /* 0-15 */
220 struct module *module, /* THIS_MODULE */
221 struct file_operations *file_ops);
223 /* release a block of minor numbers */
224 void ieee1394_unregister_chardev(int blocknum);
226 /* Our sysfs bus entry */
227 extern struct bus_type ieee1394_bus_type;
229 #endif /* _IEEE1394_CORE_H */