setup enviroment for compilation
[linux-2.4.21-pre4.git] / drivers / ieee1394 / hosts.h
1 #ifndef _IEEE1394_HOSTS_H
2 #define _IEEE1394_HOSTS_H
3
4 #include <linux/wait.h>
5 #include <linux/list.h>
6 #include <asm/semaphore.h>
7
8 #include "ieee1394_types.h"
9 #include "csr.h"
10
11 /* size of the array used to store config rom (in quadlets)
12    maximum is 0x100. About 0x40 is needed for the default
13    entries. So 0x80 should provide enough space for additional
14    directories etc. 
15    Note: All lowlevel drivers are required to allocate at least
16          this amount of memory for the configuration rom!
17 */
18 #define CSR_CONFIG_ROM_SIZE       0x100
19
20 struct hpsb_packet;
21
22 struct hpsb_host {
23         struct list_head host_list;
24
25         void *hostdata;
26
27         atomic_t generation;
28
29         int refcount;
30
31         struct list_head pending_packets;
32         spinlock_t pending_pkt_lock;
33         struct hpsb_queue_struct timeout_tq;
34
35         /* A bitmask where a set bit means that this tlabel is in use.
36          * FIXME - should be handled per node instead of per bus. */
37         u32 tlabel_pool[2];
38         struct semaphore tlabel_count;
39         spinlock_t tlabel_lock;
40         u32 tlabel_current;
41
42         unsigned char iso_listen_count[64];
43
44         int node_count; /* number of identified nodes on this bus */
45         int selfid_count; /* total number of SelfIDs received */
46         int nodes_active; /* number of nodes that are actually active */
47
48         nodeid_t node_id; /* node ID of this host */
49         nodeid_t irm_id; /* ID of this bus' isochronous resource manager */
50         nodeid_t busmgr_id; /* ID of this bus' bus manager */
51
52         /* this nodes state */
53         unsigned in_bus_reset:1;
54         unsigned is_shutdown:1;
55
56         /* this nodes' duties on the bus */
57         unsigned is_root:1;
58         unsigned is_cycmst:1;
59         unsigned is_irm:1;
60         unsigned is_busmgr:1;
61
62         int reset_retries;
63         quadlet_t *topology_map;
64         u8 *speed_map;
65         struct csr_control csr;
66
67         struct hpsb_host_driver *driver;
68
69         struct pci_dev *pdev;
70 };
71
72
73
74 enum devctl_cmd {
75         /* Host is requested to reset its bus and cancel all outstanding async
76          * requests.  If arg == 1, it shall also attempt to become root on the
77          * bus.  Return void. */
78         RESET_BUS,
79
80         /* Arg is void, return value is the hardware cycle counter value. */
81         GET_CYCLE_COUNTER,
82
83         /* Set the hardware cycle counter to the value in arg, return void.
84          * FIXME - setting is probably not required. */
85         SET_CYCLE_COUNTER,
86
87         /* Configure hardware for new bus ID in arg, return void. */
88         SET_BUS_ID,
89
90         /* If arg true, start sending cycle start packets, stop if arg == 0.
91          * Return void. */
92         ACT_CYCLE_MASTER,
93
94         /* Cancel all outstanding async requests without resetting the bus.
95          * Return void. */
96         CANCEL_REQUESTS,
97
98         /* Decrease host usage count if arg == 0, increase otherwise.  Return
99          * 1 for success, 0 for failure.  Increase usage may fail if the driver
100          * is in the process of shutting itself down.  Decrease usage can not
101          * fail. */
102         MODIFY_USAGE,
103
104         /* Start or stop receiving isochronous channel in arg.  Return void.
105          * This acts as an optimization hint, hosts are not required not to
106          * listen on unrequested channels. */
107         ISO_LISTEN_CHANNEL,
108         ISO_UNLISTEN_CHANNEL
109 };
110
111 enum reset_types {
112         /* 166 microsecond reset -- only type of reset available on
113            non-1394a capable IEEE 1394 controllers */
114         LONG_RESET,
115
116         /* Short (arbitrated) reset -- only available on 1394a capable
117            IEEE 1394 capable controllers */
118         SHORT_RESET
119 };
120
121 struct hpsb_host_driver {
122         const char *name;
123
124         /* This function must store a pointer to the configuration ROM into the
125          * location referenced to by pointer and return the size of the ROM. It
126          * may not fail.  If any allocation is required, it must be done
127          * earlier.
128          */
129         size_t (*get_rom) (struct hpsb_host *host, quadlet_t **pointer);
130
131         /* This function shall implement packet transmission based on
132          * packet->type.  It shall CRC both parts of the packet (unless
133          * packet->type == raw) and do byte-swapping as necessary or instruct
134          * the hardware to do so.  It can return immediately after the packet
135          * was queued for sending.  After sending, hpsb_sent_packet() has to be
136          * called.  Return 0 for failure.
137          * NOTE: The function must be callable in interrupt context.
138          */
139         int (*transmit_packet) (struct hpsb_host *host, 
140                                 struct hpsb_packet *packet);
141
142         /* This function requests miscellanous services from the driver, see
143          * above for command codes and expected actions.  Return -1 for unknown
144          * command, though that should never happen.
145          */
146         int (*devctl) (struct hpsb_host *host, enum devctl_cmd command, int arg);
147
148         /* This function is mainly to redirect local CSR reads/locks to the iso
149          * management registers (bus manager id, bandwidth available, channels
150          * available) to the hardware registers in OHCI.  reg is 0,1,2,3 for bus
151          * mgr, bwdth avail, ch avail hi, ch avail lo respectively (the same ids
152          * as OHCI uses).  data and compare are the new data and expected data
153          * respectively, return value is the old value.
154          */
155         quadlet_t (*hw_csr_reg) (struct hpsb_host *host, int reg,
156                                  quadlet_t data, quadlet_t compare);
157 };
158
159 /* core internal use */
160 void register_builtin_lowlevels(void);
161
162 /* high level internal use */
163 struct hpsb_highlevel;
164 void hl_all_hosts(void (*function)(struct hpsb_host*));
165
166
167 /*
168  * In order to prevent hosts from unloading, use hpsb_ref_host().  This prevents
169  * the host from going away (e.g. makes module unloading of the driver
170  * impossible), but still can not guarantee it (e.g. PC-Card being pulled by the
171  * user).  hpsb_ref_host() returns false if host could not be locked.  If it is
172  * successful, host is valid as a pointer until hpsb_unref_host() (not just
173  * until after remove_host).
174  */
175 int hpsb_ref_host(struct hpsb_host *host);
176 void hpsb_unref_host(struct hpsb_host *host);
177
178 struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra);
179 void hpsb_add_host(struct hpsb_host *host);
180 void hpsb_remove_host(struct hpsb_host *h);
181
182 /* updates the configuration rom of a host.
183  * rom_version must be the current version,
184  * otherwise it will fail with return value -1.
185  * Return value -2 indicates that the new
186  * rom version is too big.
187  * Return value 0 indicates success
188  */
189 int hpsb_update_config_rom(struct hpsb_host *host,
190       const quadlet_t *new_rom, size_t size, unsigned char rom_version);
191
192 /* reads the current version of the configuration rom of a host.
193  * buffersize is the size of the buffer, rom_size
194  * returns the size of the current rom image.
195  * rom_version is the version number of the fetched rom.
196  * return value -1 indicates, that the buffer was
197  * too small, 0 indicates success.
198  */
199 int hpsb_get_config_rom(struct hpsb_host *host, quadlet_t *buffer,
200       size_t buffersize, size_t *rom_size, unsigned char *rom_version);
201
202 #endif /* _IEEE1394_HOSTS_H */