blob: 134bb6c3eadb4a69f3aac2203c95082096667560 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef IEEE1394_HIGHLEVEL_H
2#define IEEE1394_HIGHLEVEL_H
3
Stefan Richtere1d118f2006-07-03 12:02:28 -04004/* internal to ieee1394 core */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005struct hpsb_address_serve {
Stefan Richtere1d118f2006-07-03 12:02:28 -04006 struct list_head host_list; /* per host list */
7 struct list_head hl_list; /* hpsb_highlevel list */
8 struct hpsb_address_ops *op;
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 struct hpsb_host *host;
Stefan Richtere1d118f2006-07-03 12:02:28 -040010 u64 start; /* first address handled, quadlet aligned */
11 u64 end; /* first address behind, quadlet aligned */
Linus Torvalds1da177e2005-04-16 15:20:36 -070012};
13
Stefan Richtere1d118f2006-07-03 12:02:28 -040014/* Only the following structures are of interest to actual highlevel drivers. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
16struct hpsb_highlevel {
17 struct module *owner;
18 const char *name;
19
Stefan Richtere1d118f2006-07-03 12:02:28 -040020 /* Any of the following pointers can legally be NULL, except for
21 * iso_receive which can only be NULL when you don't request
22 * channels. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Stefan Richtere1d118f2006-07-03 12:02:28 -040024 /* New host initialized. Will also be called during
25 * hpsb_register_highlevel for all hosts already installed. */
26 void (*add_host)(struct hpsb_host *host);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027
Stefan Richtere1d118f2006-07-03 12:02:28 -040028 /* Host about to be removed. Will also be called during
29 * hpsb_unregister_highlevel once for each host. */
30 void (*remove_host)(struct hpsb_host *host);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Stefan Richtere1d118f2006-07-03 12:02:28 -040032 /* Host experienced bus reset with possible configuration changes.
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 * Note that this one may occur during interrupt/bottom half handling.
34 * You can not expect to be able to do stock hpsb_reads. */
Stefan Richtere1d118f2006-07-03 12:02:28 -040035 void (*host_reset)(struct hpsb_host *host);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Stefan Richtere1d118f2006-07-03 12:02:28 -040037 /* An isochronous packet was received. Channel contains the channel
38 * number for your convenience, it is also contained in the included
39 * packet header (first quadlet, CRCs are missing). You may get called
40 * for channel/host combinations you did not request. */
41 void (*iso_receive)(struct hpsb_host *host, int channel,
42 quadlet_t *data, size_t length);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
Stefan Richtere1d118f2006-07-03 12:02:28 -040044 /* A write request was received on either the FCP_COMMAND (direction =
45 * 0) or the FCP_RESPONSE (direction = 1) register. The cts arg
46 * contains the cts field (first byte of data). */
47 void (*fcp_request)(struct hpsb_host *host, int nodeid, int direction,
48 int cts, u8 *data, size_t length);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50 /* These are initialized by the subsystem when the
51 * hpsb_higlevel is registered. */
52 struct list_head hl_list;
53 struct list_head irq_list;
54 struct list_head addr_list;
55
56 struct list_head host_info_list;
57 rwlock_t host_info_lock;
58};
59
60struct hpsb_address_ops {
Stefan Richtere1d118f2006-07-03 12:02:28 -040061 /*
62 * Null function pointers will make the respective operation complete
63 * with RCODE_TYPE_ERROR. Makes for easy to implement read-only
64 * registers (just leave everything but read NULL).
65 *
66 * All functions shall return appropriate IEEE 1394 rcodes.
67 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Stefan Richtere1d118f2006-07-03 12:02:28 -040069 /* These functions have to implement block reads for themselves.
70 *
71 * These functions either return a response code or a negative number.
72 * In the first case a response will be generated. In the latter case,
73 * no response will be sent and the driver which handled the request
74 * will send the response itself. */
75 int (*read)(struct hpsb_host *host, int nodeid, quadlet_t *buffer,
76 u64 addr, size_t length, u16 flags);
77 int (*write)(struct hpsb_host *host, int nodeid, int destid,
78 quadlet_t *data, u64 addr, size_t length, u16 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Stefan Richtere1d118f2006-07-03 12:02:28 -040080 /* Lock transactions: write results of ext_tcode operation into
81 * *store. */
82 int (*lock)(struct hpsb_host *host, int nodeid, quadlet_t *store,
83 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
84 u16 flags);
85 int (*lock64)(struct hpsb_host *host, int nodeid, octlet_t *store,
86 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
87 u16 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088};
89
Linus Torvalds1da177e2005-04-16 15:20:36 -070090void highlevel_add_host(struct hpsb_host *host);
91void highlevel_remove_host(struct hpsb_host *host);
92void highlevel_host_reset(struct hpsb_host *host);
93
Stefan Richtere1d118f2006-07-03 12:02:28 -040094/*
95 * These functions are called to handle transactions. They are called when a
96 * packet arrives. The flags argument contains the second word of the first
97 * header quadlet of the incoming packet (containing transaction label, retry
98 * code, transaction code and priority). These functions either return a
99 * response code or a negative number. In the first case a response will be
100 * generated. In the latter case, no response will be sent and the driver which
101 * handled the request will send the response itself.
102 */
103int highlevel_read(struct hpsb_host *host, int nodeid, void *data, u64 addr,
104 unsigned int length, u16 flags);
105int highlevel_write(struct hpsb_host *host, int nodeid, int destid, void *data,
106 u64 addr, unsigned int length, u16 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107int highlevel_lock(struct hpsb_host *host, int nodeid, quadlet_t *store,
Stefan Richtere1d118f2006-07-03 12:02:28 -0400108 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
109 u16 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110int highlevel_lock64(struct hpsb_host *host, int nodeid, octlet_t *store,
Stefan Richtere1d118f2006-07-03 12:02:28 -0400111 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
112 u16 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
Stefan Richtere1d118f2006-07-03 12:02:28 -0400114void highlevel_iso_receive(struct hpsb_host *host, void *data, size_t length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115void highlevel_fcp_request(struct hpsb_host *host, int nodeid, int direction,
Stefan Richtere1d118f2006-07-03 12:02:28 -0400116 void *data, size_t length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118/*
119 * Register highlevel driver. The name pointer has to stay valid at all times
120 * because the string is not copied.
121 */
122void hpsb_register_highlevel(struct hpsb_highlevel *hl);
123void hpsb_unregister_highlevel(struct hpsb_highlevel *hl);
124
125/*
126 * Register handlers for host address spaces. Start and end are 48 bit pointers
Stefan Richtere1d118f2006-07-03 12:02:28 -0400127 * and have to be quadlet aligned. Argument "end" points to the first address
128 * behind the handled addresses. This function can be called multiple times for
129 * a single hpsb_highlevel to implement sparse register sets. The requested
130 * region must not overlap any previously allocated region, otherwise
131 * registering will fail.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 *
Stefan Richtere1d118f2006-07-03 12:02:28 -0400133 * It returns true for successful allocation. Address spaces can be
134 * unregistered with hpsb_unregister_addrspace. All remaining address spaces
135 * are automatically deallocated together with the hpsb_highlevel.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 */
137u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
138 struct hpsb_host *host,
139 struct hpsb_address_ops *ops,
140 u64 size, u64 alignment,
141 u64 start, u64 end);
142int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
Stefan Richtere1d118f2006-07-03 12:02:28 -0400143 struct hpsb_address_ops *ops, u64 start, u64 end);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144int hpsb_unregister_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
Stefan Richtere1d118f2006-07-03 12:02:28 -0400145 u64 start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
147/*
148 * Enable or disable receving a certain isochronous channel through the
149 * iso_receive op.
150 */
151int hpsb_listen_channel(struct hpsb_highlevel *hl, struct hpsb_host *host,
Stefan Richtere1d118f2006-07-03 12:02:28 -0400152 unsigned int channel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153void hpsb_unlisten_channel(struct hpsb_highlevel *hl, struct hpsb_host *host,
Stefan Richtere1d118f2006-07-03 12:02:28 -0400154 unsigned int channel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
156/* Retrieve a hostinfo pointer bound to this driver/host */
157void *hpsb_get_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host);
158
159/* Allocate a hostinfo pointer of data_size bound to this driver/host */
160void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
161 size_t data_size);
162
163/* Free and remove the hostinfo pointer bound to this driver/host */
164void hpsb_destroy_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host);
165
166/* Set an alternate lookup key for the hostinfo bound to this driver/host */
Stefan Richtere1d118f2006-07-03 12:02:28 -0400167void hpsb_set_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host,
168 unsigned long key);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Stefan Richtere1d118f2006-07-03 12:02:28 -0400170/* Retrieve the alternate lookup key for the hostinfo bound to this
171 * driver/host */
172unsigned long hpsb_get_hostinfo_key(struct hpsb_highlevel *hl,
173 struct hpsb_host *host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175/* Retrieve a hostinfo pointer bound to this driver using its alternate key */
176void *hpsb_get_hostinfo_bykey(struct hpsb_highlevel *hl, unsigned long key);
177
178/* Set the hostinfo pointer to something useful. Usually follows a call to
179 * hpsb_create_hostinfo, where the size is 0. */
Stefan Richtere1d118f2006-07-03 12:02:28 -0400180int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
181 void *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183/* Retrieve hpsb_host using a highlevel handle and a key */
Stefan Richtere1d118f2006-07-03 12:02:28 -0400184struct hpsb_host *hpsb_get_host_bykey(struct hpsb_highlevel *hl,
185 unsigned long key);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
187#endif /* IEEE1394_HIGHLEVEL_H */