blob: 21d50f73a210cbadfc6c39e128da8e06d0fa9310 [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>
Stefan Richterde4394f2006-07-03 12:02:29 -04007#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <asm/atomic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Stefan Richterde4394f2006-07-03 12:02:29 -040010#include "hosts.h"
11#include "ieee1394_types.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13struct hpsb_packet {
Stefan Richter741854e2005-12-01 18:52:03 -050014 /* This struct is basically read-only for hosts with the exception of
Stefan Richter7542e0e2007-03-25 22:22:40 +020015 * the data buffer contents and driver_list. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17 /* This can be used for host driver internal linking.
18 *
19 * NOTE: This must be left in init state when the driver is done
20 * with it (e.g. by using list_del_init()), since the core does
21 * some sanity checks to make sure the packet is not on a
22 * driver_list when free'ing it. */
23 struct list_head driver_list;
24
Stefan Richter741854e2005-12-01 18:52:03 -050025 nodeid_t node_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026
Stefan Richter53c96b42007-06-24 15:31:54 +020027 /* hpsb_raw = send as-is, do not CRC (but still byte-swap it) */
28 enum { hpsb_async, hpsb_raw } __attribute__((packed)) type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Stefan Richter741854e2005-12-01 18:52:03 -050030 /* Okay, this is core internal and a no care for hosts.
31 * queued = queued for sending
32 * pending = sent, waiting for response
33 * complete = processing completed, successful or not
34 */
35 enum {
36 hpsb_unused, hpsb_queued, hpsb_pending, hpsb_complete
37 } __attribute__((packed)) state;
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Stefan Richter65527312007-05-19 12:29:37 +020039 /* These are core-internal. */
Stefan Richter741854e2005-12-01 18:52:03 -050040 signed char tlabel;
Linus Torvalds07bbeaf2005-07-06 13:05:50 -070041 signed char ack_code;
42 unsigned char tcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Stefan Richter741854e2005-12-01 18:52:03 -050044 unsigned expect_response:1;
45 unsigned no_waiter:1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Stefan Richter741854e2005-12-01 18:52:03 -050047 /* Speed to transmit with: 0 = 100Mbps, 1 = 200Mbps, 2 = 400Mbps */
48 unsigned speed_code:2;
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Stefan Richter741854e2005-12-01 18:52:03 -050050 struct hpsb_host *host;
51 unsigned int generation;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53 atomic_t refcnt;
Stefan Richter7542e0e2007-03-25 22:22:40 +020054 struct list_head queue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56 /* Function (and possible data to pass to it) to call when this
57 * packet is completed. */
58 void (*complete_routine)(void *);
59 void *complete_data;
60
Stefan Richter741854e2005-12-01 18:52:03 -050061 /* Store jiffies for implementing bus timeouts. */
62 unsigned long sendtime;
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Stefan Richter65527312007-05-19 12:29:37 +020064 /* Core-internal. */
Stefan Richter7542e0e2007-03-25 22:22:40 +020065 size_t allocated_data_size; /* as allocated */
Stefan Richter65527312007-05-19 12:29:37 +020066
67 /* Sizes are in bytes. To be set by caller of hpsb_alloc_packet. */
Stefan Richter7542e0e2007-03-25 22:22:40 +020068 size_t data_size; /* as filled in */
69 size_t header_size; /* as filled in, not counting the CRC */
Stefan Richter65527312007-05-19 12:29:37 +020070
71 /* Buffers */
72 quadlet_t *data; /* can be DMA-mapped */
Stefan Richter7542e0e2007-03-25 22:22:40 +020073 quadlet_t header[5];
74 quadlet_t embedded_data[0]; /* keep as last member */
Linus Torvalds1da177e2005-04-16 15:20:36 -070075};
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077void hpsb_set_packet_complete_task(struct hpsb_packet *packet,
Stefan Richtere1d118f2006-07-03 12:02:28 -040078 void (*routine)(void *), void *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079static inline struct hpsb_packet *driver_packet(struct list_head *l)
80{
81 return list_entry(l, struct hpsb_packet, driver_list);
82}
Linus Torvalds1da177e2005-04-16 15:20:36 -070083void abort_timedouts(unsigned long __opaque);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084struct hpsb_packet *hpsb_alloc_packet(size_t data_size);
85void hpsb_free_packet(struct hpsb_packet *packet);
86
Stefan Richterafd65462007-03-05 03:06:23 +010087/**
88 * get_hpsb_generation - generation counter for the complete 1394 subsystem
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 *
Stefan Richterafd65462007-03-05 03:06:23 +010090 * Generation gets incremented on every change in the subsystem (notably on bus
91 * resets). Use the functions, not the variable.
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 */
93static inline unsigned int get_hpsb_generation(struct hpsb_host *host)
94{
Stefan Richter741854e2005-12-01 18:52:03 -050095 return atomic_read(&host->generation);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096}
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098int hpsb_send_phy_config(struct hpsb_host *host, int rootid, int gapcnt);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099int hpsb_send_packet(struct hpsb_packet *packet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100int hpsb_send_packet_and_wait(struct hpsb_packet *packet);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101int hpsb_reset_bus(struct hpsb_host *host, int type);
Pieter Palmers3dc5ea92007-02-03 17:44:39 +0100102int hpsb_read_cycle_timer(struct hpsb_host *host, u32 *cycle_timer,
103 u64 *local_time);
104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105int hpsb_bus_reset(struct hpsb_host *host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106void hpsb_selfid_received(struct hpsb_host *host, quadlet_t sid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107void hpsb_selfid_complete(struct hpsb_host *host, int phyid, int isroot);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108void hpsb_packet_sent(struct hpsb_host *host, struct hpsb_packet *packet,
Stefan Richter741854e2005-12-01 18:52:03 -0500109 int ackcode);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110void hpsb_packet_received(struct hpsb_host *host, quadlet_t *data, size_t size,
Stefan Richter741854e2005-12-01 18:52:03 -0500111 int write_acked);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113/*
114 * CHARACTER DEVICE DISPATCHING
115 *
116 * All ieee1394 character device drivers share the same major number
117 * (major 171). The 256 minor numbers are allocated to the various
118 * task-specific interfaces (raw1394, video1394, dv1394, etc) in
119 * blocks of 16.
120 *
121 * The core ieee1394.o module allocates the device number region
122 * 171:0-255, the various drivers must then cdev_add() their cdev
123 * objects to handle their respective sub-regions.
124 *
125 * Minor device number block allocations:
126 *
127 * Block 0 ( 0- 15) raw1394
128 * Block 1 ( 16- 31) video1394
129 * Block 2 ( 32- 47) dv1394
130 *
131 * Blocks 3-14 free for future allocation
132 *
133 * Block 15 (240-255) reserved for drivers under development, etc.
134 */
135
Stefan Richter741854e2005-12-01 18:52:03 -0500136#define IEEE1394_MAJOR 171
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
Stefan Richter741854e2005-12-01 18:52:03 -0500138#define IEEE1394_MINOR_BLOCK_RAW1394 0
139#define IEEE1394_MINOR_BLOCK_VIDEO1394 1
140#define IEEE1394_MINOR_BLOCK_DV1394 2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141#define IEEE1394_MINOR_BLOCK_EXPERIMENTAL 15
142
Stefan Richter741854e2005-12-01 18:52:03 -0500143#define IEEE1394_CORE_DEV MKDEV(IEEE1394_MAJOR, 0)
Stefan Richtere1d118f2006-07-03 12:02:28 -0400144#define IEEE1394_RAW1394_DEV MKDEV(IEEE1394_MAJOR, \
145 IEEE1394_MINOR_BLOCK_RAW1394 * 16)
146#define IEEE1394_VIDEO1394_DEV MKDEV(IEEE1394_MAJOR, \
147 IEEE1394_MINOR_BLOCK_VIDEO1394 * 16)
148#define IEEE1394_DV1394_DEV MKDEV(IEEE1394_MAJOR, \
149 IEEE1394_MINOR_BLOCK_DV1394 * 16)
150#define IEEE1394_EXPERIMENTAL_DEV MKDEV(IEEE1394_MAJOR, \
151 IEEE1394_MINOR_BLOCK_EXPERIMENTAL * 16)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Stefan Richterafd65462007-03-05 03:06:23 +0100153/**
154 * ieee1394_file_to_instance - get the index within a minor number block
155 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156static inline unsigned char ieee1394_file_to_instance(struct file *file)
157{
Josef Sipek4db61082006-12-08 02:37:10 -0800158 return file->f_path.dentry->d_inode->i_cindex;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159}
160
161extern int hpsb_disable_irm;
162
163/* Our sysfs bus entry */
164extern struct bus_type ieee1394_bus_type;
165extern struct class hpsb_host_class;
gregkh@suse.de7e25ab92005-03-23 09:53:36 -0800166extern struct class *hpsb_protocol_class;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168#endif /* _IEEE1394_CORE_H */