1#ifndef _IEEE1394_HOSTS_H
2#define _IEEE1394_HOSTS_H
3
4#include <linux/device.h>
5#include <linux/list.h>
6#include <linux/timer.h>
7#include <linux/types.h>
8#include <linux/workqueue.h>
9#include <asm/atomic.h>
10
11struct pci_dev;
12struct module;
13
14#include "ieee1394_types.h"
15#include "csr.h"
16
17struct hpsb_packet;
18struct hpsb_iso;
19
20struct hpsb_host {
21	struct list_head host_list;
22
23	void *hostdata;
24
25	atomic_t generation;
26
27	struct list_head pending_packets;
28	struct timer_list timeout;
29	unsigned long timeout_interval;
30
31	unsigned char iso_listen_count[64];
32
33	int node_count;      /* number of identified nodes on this bus */
34	int selfid_count;    /* total number of SelfIDs received */
35	int nodes_active;    /* number of nodes with active link layer */
36
37	nodeid_t node_id;    /* node ID of this host */
38	nodeid_t irm_id;     /* ID of this bus' isochronous resource manager */
39	nodeid_t busmgr_id;  /* ID of this bus' bus manager */
40
41	/* this nodes state */
42	unsigned in_bus_reset:1;
43	unsigned is_shutdown:1;
44	unsigned resume_packet_sent:1;
45
46	/* this nodes' duties on the bus */
47	unsigned is_root:1;
48	unsigned is_cycmst:1;
49	unsigned is_irm:1;
50	unsigned is_busmgr:1;
51
52	int reset_retries;
53	quadlet_t *topology_map;
54	u8 *speed_map;
55
56	int id;
57	struct hpsb_host_driver *driver;
58	struct pci_dev *pdev;
59	struct device device;
60	struct class_device class_dev;
61
62	struct delayed_work delayed_reset;
63	unsigned config_roms:31;
64	unsigned update_config_rom:1;
65
66	struct list_head addr_space;
67	u64 low_addr_space;	/* upper bound of physical DMA area */
68	u64 middle_addr_space;	/* upper bound of posted write area */
69
70	u8 speed[ALL_NODES];	/* speed between each node and local node */
71
72	/* per node tlabel allocation */
73	u8 next_tl[ALL_NODES];
74	struct { DECLARE_BITMAP(map, 64); } tl_pool[ALL_NODES];
75
76	struct csr_control csr;
77};
78
79enum devctl_cmd {
80	/* Host is requested to reset its bus and cancel all outstanding async
81	 * requests.  If arg == 1, it shall also attempt to become root on the
82	 * bus.  Return void. */
83	RESET_BUS,
84
85	/* Arg is void, return value is the hardware cycle counter value. */
86	GET_CYCLE_COUNTER,
87
88	SET_CYCLE_COUNTER,
89
90	/* Configure hardware for new bus ID in arg, return void. */
91	SET_BUS_ID,
92
93	/* If arg true, start sending cycle start packets, stop if arg == 0.
94	 * Return void. */
95	ACT_CYCLE_MASTER,
96
97	/* Cancel all outstanding async requests without resetting the bus.
98	 * Return void. */
99	CANCEL_REQUESTS,
100
101	/* Start or stop receiving isochronous channel in arg.  Return void.
102	 * This acts as an optimization hint, hosts are not required not to
103	 * listen on unrequested channels. */
104	ISO_LISTEN_CHANNEL,
105	ISO_UNLISTEN_CHANNEL
106};
107
108enum isoctl_cmd {
109	/* rawiso API - see iso.h for the meanings of these commands
110	 * (they correspond exactly to the hpsb_iso_* API functions)
111	 * INIT = allocate resources
112	 * START = begin transmission/reception
113	 * STOP = halt transmission/reception
114	 * QUEUE/RELEASE = produce/consume packets
115	 * SHUTDOWN = deallocate resources
116	 */
117
118	XMIT_INIT,
119	XMIT_START,
120	XMIT_STOP,
121	XMIT_QUEUE,
122	XMIT_SHUTDOWN,
123
124	RECV_INIT,
125	RECV_LISTEN_CHANNEL,   /* multi-channel only */
126	RECV_UNLISTEN_CHANNEL, /* multi-channel only */
127	RECV_SET_CHANNEL_MASK, /* multi-channel only; arg is a *u64 */
128	RECV_START,
129	RECV_STOP,
130	RECV_RELEASE,
131	RECV_SHUTDOWN,
132	RECV_FLUSH
133};
134
135enum reset_types {
136	/* 166 microsecond reset -- only type of reset available on
137	   non-1394a capable controllers */
138	LONG_RESET,
139
140	/* Short (arbitrated) reset -- only available on 1394a capable
141	   controllers */
142	SHORT_RESET,
143
144	/* Variants that set force_root before issueing the bus reset */
145	LONG_RESET_FORCE_ROOT, SHORT_RESET_FORCE_ROOT,
146
147	/* Variants that clear force_root before issueing the bus reset */
148	LONG_RESET_NO_FORCE_ROOT, SHORT_RESET_NO_FORCE_ROOT
149};
150
151struct hpsb_host_driver {
152	struct module *owner;
153	const char *name;
154
155	/* The hardware driver may optionally support a function that is used
156	 * to set the hardware ConfigROM if the hardware supports handling
157	 * reads to the ConfigROM on its own. */
158	void (*set_hw_config_rom)(struct hpsb_host *host,
159				  quadlet_t *config_rom);
160
161	/* This function shall implement packet transmission based on
162	 * packet->type.  It shall CRC both parts of the packet (unless
163	 * packet->type == raw) and do byte-swapping as necessary or instruct
164	 * the hardware to do so.  It can return immediately after the packet
165	 * was queued for sending.  After sending, hpsb_sent_packet() has to be
166	 * called.  Return 0 on success, negative errno on failure.
167	 * NOTE: The function must be callable in interrupt context.
168	 */
169	int (*transmit_packet)(struct hpsb_host *host,
170			       struct hpsb_packet *packet);
171
172	/* This function requests miscellanous services from the driver, see
173	 * above for command codes and expected actions.  Return -1 for unknown
174	 * command, though that should never happen.
175	 */
176	int (*devctl)(struct hpsb_host *host, enum devctl_cmd command, int arg);
177
178	 /* ISO transmission/reception functions. Return 0 on success, -1
179	  * (or -EXXX errno code) on failure. If the low-level driver does not
180	  * support the new ISO API, set isoctl to NULL.
181	  */
182	int (*isoctl)(struct hpsb_iso *iso, enum isoctl_cmd command,
183		      unsigned long arg);
184
185	/* This function is mainly to redirect local CSR reads/locks to the iso
186	 * management registers (bus manager id, bandwidth available, channels
187	 * available) to the hardware registers in OHCI.  reg is 0,1,2,3 for bus
188	 * mgr, bwdth avail, ch avail hi, ch avail lo respectively (the same ids
189	 * as OHCI uses).  data and compare are the new data and expected data
190	 * respectively, return value is the old value.
191	 */
192	quadlet_t (*hw_csr_reg) (struct hpsb_host *host, int reg,
193				 quadlet_t data, quadlet_t compare);
194};
195
196struct hpsb_host *hpsb_alloc_host(struct hpsb_host_driver *drv, size_t extra,
197				  struct device *dev);
198int hpsb_add_host(struct hpsb_host *host);
199void hpsb_resume_host(struct hpsb_host *host);
200void hpsb_remove_host(struct hpsb_host *host);
201int hpsb_update_config_rom_image(struct hpsb_host *host);
202
203#endif /* _IEEE1394_HOSTS_H */
204