2 #ifndef _IEEE1394_CORE_H
3 #define _IEEE1394_CORE_H
5 #include <linux/slab.h>
6 #include <linux/devfs_fs_kernel.h>
7 #include <linux/proc_fs.h>
8 #include <asm/semaphore.h>
13 /* This struct is basically read-only for hosts with the exception of
14 * the data buffer contents and xnext - see below. */
15 struct list_head list;
17 /* This can be used for host driver internal linking. */
18 struct list_head driver_list;
22 /* Async and Iso types should be clear, raw means send-as-is, do not
23 * CRC! Byte swapping shall still be done in this case. */
24 enum { hpsb_async, hpsb_iso, hpsb_raw } __attribute__((packed)) type;
26 /* Okay, this is core internal and a no care for hosts.
27 * queued = queued for sending
28 * pending = sent, waiting for response
29 * complete = processing completed, successful or not
30 * incoming = incoming packet
33 hpsb_unused, hpsb_queued, hpsb_pending, hpsb_complete, hpsb_incoming
34 } __attribute__((packed)) state;
36 /* These are core internal. */
41 unsigned expect_response:1;
44 /* Data big endianness flag - may vary from request to request. The
45 * header is always in machine byte order.
46 * Not really used currently. */
49 /* Speed to transmit with: 0 = 100Mbps, 1 = 200Mbps, 2 = 400Mbps */
50 unsigned speed_code:2;
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.
65 struct hpsb_host *host;
66 unsigned int generation;
68 /* Very core internal, don't care. */
69 struct semaphore state_change;
71 struct list_head complete_tq;
73 /* Store jiffies for implementing bus timeouts. */
74 unsigned long sendtime;
76 quadlet_t embedded_header[5];
79 /* add a new task for when a packet completes */
80 void hpsb_add_packet_complete_task(struct hpsb_packet *packet, struct hpsb_queue_struct *tq);
82 static inline struct hpsb_packet *driver_packet(struct list_head *l)
84 return list_entry(l, struct hpsb_packet, driver_list);
87 void abort_timedouts(struct hpsb_host *host);
88 void abort_requests(struct hpsb_host *host);
90 struct hpsb_packet *alloc_hpsb_packet(size_t data_size);
91 void free_hpsb_packet(struct hpsb_packet *packet);
95 * Generation counter for the complete 1394 subsystem. Generation gets
96 * incremented on every change in the subsystem (e.g. bus reset).
98 * Use the functions, not the variable.
100 #include <asm/atomic.h>
102 static inline unsigned int get_hpsb_generation(struct hpsb_host *host)
104 return atomic_read(&host->generation);
108 * Queue packet for transmitting, return 0 for failure.
110 int hpsb_send_packet(struct hpsb_packet *packet);
112 /* Initiate bus reset on the given host. Returns 1 if bus reset already in
113 * progress, 0 otherwise. */
114 int hpsb_reset_bus(struct hpsb_host *host, int type);
117 * The following functions are exported for host driver module usage. All of
118 * them are safe to use in interrupt contexts, although some are quite
119 * complicated so you may want to run them in bottom halves instead of calling
123 /* Notify a bus reset to the core. Returns 1 if bus reset already in progress,
125 int hpsb_bus_reset(struct hpsb_host *host);
128 * Hand over received selfid packet to the core. Complement check (second
129 * quadlet is complement of first) is expected to be done and succesful.
131 void hpsb_selfid_received(struct hpsb_host *host, quadlet_t sid);
134 * Notify completion of SelfID stage to the core and report new physical ID
135 * and whether host is root now.
137 void hpsb_selfid_complete(struct hpsb_host *host, int phyid, int isroot);
140 * Notify core of sending a packet. Ackcode is the ack code returned for async
141 * transmits or ACKX_SEND_ERROR if the transmission failed completely; ACKX_NONE
142 * for other cases (internal errors that don't justify a panic). Safe to call
143 * from within a transmit packet routine.
145 void hpsb_packet_sent(struct hpsb_host *host, struct hpsb_packet *packet,
149 * Hand over received packet to the core. The contents of data are expected to
150 * be the full packet but with the CRCs left out (data block follows header
151 * immediately), with the header (i.e. the first four quadlets) in machine byte
152 * order and the data block in big endian. *data can be safely overwritten
155 * If the packet is a write request, write_acked is to be set to true if it was
156 * ack_complete'd already, false otherwise. This arg is ignored for any other
159 void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
164 * CHARACTER DEVICE DISPATCHING
166 * All ieee1394 character device drivers share the same major number
167 * (major 171). The 256 minor numbers are allocated to the various
168 * task-specific interfaces (raw1394, video1394, dv1394, etc) in
171 * The core ieee1394.o modules handles the initial open() for all
172 * character devices on major 171; it then dispatches to the
173 * appropriate task-specific driver.
175 * Minor device number block allocations:
177 * Block 0 ( 0- 15) raw1394
178 * Block 1 ( 16- 31) video1394
179 * Block 2 ( 32- 47) dv1394
181 * Blocks 3-14 free for future allocation
183 * Block 15 (240-255) reserved for drivers under development, etc.
186 #define IEEE1394_MAJOR 171
188 #define IEEE1394_MINOR_BLOCK_RAW1394 0
189 #define IEEE1394_MINOR_BLOCK_VIDEO1394 1
190 #define IEEE1394_MINOR_BLOCK_DV1394 2
191 #define IEEE1394_MINOR_BLOCK_AMDTP 3
192 #define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15
194 /* return the index (within a minor number block) of a file */
195 static inline unsigned char ieee1394_file_to_instance(struct file *file)
197 unsigned char minor = minor(file->f_dentry->d_inode->i_rdev);
199 /* return lower 4 bits */
204 * Task-specific drivers should call ieee1394_register_chardev() to
205 * request a block of 16 minor numbers.
207 * Returns 0 if the request was successful, -EBUSY if the block was
211 int ieee1394_register_chardev(int blocknum, /* 0-15 */
212 struct module *module, /* THIS_MODULE */
213 struct file_operations *file_ops);
215 /* release a block of minor numbers */
216 void ieee1394_unregister_chardev(int blocknum);
218 /* the devfs handle for /dev/ieee1394; NULL if devfs is not in use */
219 extern devfs_handle_t ieee1394_devfs_handle;
221 /* the proc_fs entry for /proc/ieee1394 */
222 extern struct proc_dir_entry *ieee1394_procfs_entry;
224 #endif /* _IEEE1394_CORE_H */