blob: 50f2dd2c7e20afecc2dde1b95c78eeac070730da [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef IEEE1394_HIGHLEVEL_H
2#define IEEE1394_HIGHLEVEL_H
3
Stefan Richterde4394f2006-07-03 12:02:29 -04004#include <linux/list.h>
5#include <linux/spinlock_types.h>
6#include <linux/types.h>
7
8struct module;
9
10#include "ieee1394_types.h"
11
12struct hpsb_host;
13
Stefan Richtere1d118f2006-07-03 12:02:28 -040014/* internal to ieee1394 core */
Linus Torvalds1da177e2005-04-16 15:20:36 -070015struct hpsb_address_serve {
Stefan Richtere1d118f2006-07-03 12:02:28 -040016 struct list_head host_list; /* per host list */
17 struct list_head hl_list; /* hpsb_highlevel list */
18 struct hpsb_address_ops *op;
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 struct hpsb_host *host;
Stefan Richtere1d118f2006-07-03 12:02:28 -040020 u64 start; /* first address handled, quadlet aligned */
21 u64 end; /* first address behind, quadlet aligned */
Linus Torvalds1da177e2005-04-16 15:20:36 -070022};
23
Stefan Richtere1d118f2006-07-03 12:02:28 -040024/* Only the following structures are of interest to actual highlevel drivers. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26struct hpsb_highlevel {
27 struct module *owner;
28 const char *name;
29
Stefan Richtere1d118f2006-07-03 12:02:28 -040030 /* Any of the following pointers can legally be NULL, except for
31 * iso_receive which can only be NULL when you don't request
32 * channels. */
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
Stefan Richtere1d118f2006-07-03 12:02:28 -040034 /* New host initialized. Will also be called during
35 * hpsb_register_highlevel for all hosts already installed. */
36 void (*add_host)(struct hpsb_host *host);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Stefan Richtere1d118f2006-07-03 12:02:28 -040038 /* Host about to be removed. Will also be called during
39 * hpsb_unregister_highlevel once for each host. */
40 void (*remove_host)(struct hpsb_host *host);
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
Stefan Richtere1d118f2006-07-03 12:02:28 -040042 /* Host experienced bus reset with possible configuration changes.
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 * Note that this one may occur during interrupt/bottom half handling.
44 * You can not expect to be able to do stock hpsb_reads. */
Stefan Richtere1d118f2006-07-03 12:02:28 -040045 void (*host_reset)(struct hpsb_host *host);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Stefan Richtere1d118f2006-07-03 12:02:28 -040047 /* An isochronous packet was received. Channel contains the channel
48 * number for your convenience, it is also contained in the included
49 * packet header (first quadlet, CRCs are missing). You may get called
50 * for channel/host combinations you did not request. */
51 void (*iso_receive)(struct hpsb_host *host, int channel,
52 quadlet_t *data, size_t length);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
Stefan Richtere1d118f2006-07-03 12:02:28 -040054 /* A write request was received on either the FCP_COMMAND (direction =
55 * 0) or the FCP_RESPONSE (direction = 1) register. The cts arg
56 * contains the cts field (first byte of data). */
57 void (*fcp_request)(struct hpsb_host *host, int nodeid, int direction,
58 int cts, u8 *data, size_t length);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60 /* These are initialized by the subsystem when the
61 * hpsb_higlevel is registered. */
62 struct list_head hl_list;
63 struct list_head irq_list;
64 struct list_head addr_list;
65
66 struct list_head host_info_list;
67 rwlock_t host_info_lock;
68};
69
70struct hpsb_address_ops {
Stefan Richtere1d118f2006-07-03 12:02:28 -040071 /*
72 * Null function pointers will make the respective operation complete
73 * with RCODE_TYPE_ERROR. Makes for easy to implement read-only
74 * registers (just leave everything but read NULL).
75 *
76 * All functions shall return appropriate IEEE 1394 rcodes.
77 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
Stefan Richtere1d118f2006-07-03 12:02:28 -040079 /* These functions have to implement block reads for themselves.
80 *
81 * These functions either return a response code or a negative number.
82 * In the first case a response will be generated. In the latter case,
83 * no response will be sent and the driver which handled the request
84 * will send the response itself. */
85 int (*read)(struct hpsb_host *host, int nodeid, quadlet_t *buffer,
86 u64 addr, size_t length, u16 flags);
87 int (*write)(struct hpsb_host *host, int nodeid, int destid,
88 quadlet_t *data, u64 addr, size_t length, u16 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Stefan Richtere1d118f2006-07-03 12:02:28 -040090 /* Lock transactions: write results of ext_tcode operation into
91 * *store. */
92 int (*lock)(struct hpsb_host *host, int nodeid, quadlet_t *store,
93 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
94 u16 flags);
95 int (*lock64)(struct hpsb_host *host, int nodeid, octlet_t *store,
96 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
97 u16 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098};
99
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100void highlevel_add_host(struct hpsb_host *host);
101void highlevel_remove_host(struct hpsb_host *host);
102void highlevel_host_reset(struct hpsb_host *host);
103
Stefan Richtere1d118f2006-07-03 12:02:28 -0400104/*
105 * These functions are called to handle transactions. They are called when a
106 * packet arrives. The flags argument contains the second word of the first
107 * header quadlet of the incoming packet (containing transaction label, retry
108 * code, transaction code and priority). These functions either return a
109 * response code or a negative number. In the first case a response will be
110 * generated. In the latter case, no response will be sent and the driver which
111 * handled the request will send the response itself.
112 */
113int highlevel_read(struct hpsb_host *host, int nodeid, void *data, u64 addr,
114 unsigned int length, u16 flags);
115int highlevel_write(struct hpsb_host *host, int nodeid, int destid, void *data,
116 u64 addr, unsigned int length, u16 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117int highlevel_lock(struct hpsb_host *host, int nodeid, quadlet_t *store,
Stefan Richtere1d118f2006-07-03 12:02:28 -0400118 u64 addr, quadlet_t data, quadlet_t arg, int ext_tcode,
119 u16 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120int highlevel_lock64(struct hpsb_host *host, int nodeid, octlet_t *store,
Stefan Richtere1d118f2006-07-03 12:02:28 -0400121 u64 addr, octlet_t data, octlet_t arg, int ext_tcode,
122 u16 flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
Stefan Richtere1d118f2006-07-03 12:02:28 -0400124void highlevel_iso_receive(struct hpsb_host *host, void *data, size_t length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125void highlevel_fcp_request(struct hpsb_host *host, int nodeid, int direction,
Stefan Richtere1d118f2006-07-03 12:02:28 -0400126 void *data, size_t length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128/*
129 * Register highlevel driver. The name pointer has to stay valid at all times
130 * because the string is not copied.
131 */
132void hpsb_register_highlevel(struct hpsb_highlevel *hl);
133void hpsb_unregister_highlevel(struct hpsb_highlevel *hl);
134
135/*
136 * Register handlers for host address spaces. Start and end are 48 bit pointers
Stefan Richtere1d118f2006-07-03 12:02:28 -0400137 * and have to be quadlet aligned. Argument "end" points to the first address
138 * behind the handled addresses. This function can be called multiple times for
139 * a single hpsb_highlevel to implement sparse register sets. The requested
140 * region must not overlap any previously allocated region, otherwise
141 * registering will fail.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 *
Stefan Richtere1d118f2006-07-03 12:02:28 -0400143 * It returns true for successful allocation. Address spaces can be
144 * unregistered with hpsb_unregister_addrspace. All remaining address spaces
145 * are automatically deallocated together with the hpsb_highlevel.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 */
147u64 hpsb_allocate_and_register_addrspace(struct hpsb_highlevel *hl,
148 struct hpsb_host *host,
149 struct hpsb_address_ops *ops,
150 u64 size, u64 alignment,
151 u64 start, u64 end);
152int hpsb_register_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
Stefan Richtere1d118f2006-07-03 12:02:28 -0400153 struct hpsb_address_ops *ops, u64 start, u64 end);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154int hpsb_unregister_addrspace(struct hpsb_highlevel *hl, struct hpsb_host *host,
Stefan Richtere1d118f2006-07-03 12:02:28 -0400155 u64 start);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
157/*
158 * Enable or disable receving a certain isochronous channel through the
159 * iso_receive op.
160 */
161int hpsb_listen_channel(struct hpsb_highlevel *hl, struct hpsb_host *host,
Stefan Richtere1d118f2006-07-03 12:02:28 -0400162 unsigned int channel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163void hpsb_unlisten_channel(struct hpsb_highlevel *hl, struct hpsb_host *host,
Stefan Richtere1d118f2006-07-03 12:02:28 -0400164 unsigned int channel);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
166/* Retrieve a hostinfo pointer bound to this driver/host */
167void *hpsb_get_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host);
168
169/* Allocate a hostinfo pointer of data_size bound to this driver/host */
170void *hpsb_create_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
171 size_t data_size);
172
173/* Free and remove the hostinfo pointer bound to this driver/host */
174void hpsb_destroy_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host);
175
176/* Set an alternate lookup key for the hostinfo bound to this driver/host */
Stefan Richtere1d118f2006-07-03 12:02:28 -0400177void hpsb_set_hostinfo_key(struct hpsb_highlevel *hl, struct hpsb_host *host,
178 unsigned long key);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
Stefan Richtere1d118f2006-07-03 12:02:28 -0400180/* Retrieve the alternate lookup key for the hostinfo bound to this
181 * driver/host */
182unsigned long hpsb_get_hostinfo_key(struct hpsb_highlevel *hl,
183 struct hpsb_host *host);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184
185/* Retrieve a hostinfo pointer bound to this driver using its alternate key */
186void *hpsb_get_hostinfo_bykey(struct hpsb_highlevel *hl, unsigned long key);
187
188/* Set the hostinfo pointer to something useful. Usually follows a call to
189 * hpsb_create_hostinfo, where the size is 0. */
Stefan Richtere1d118f2006-07-03 12:02:28 -0400190int hpsb_set_hostinfo(struct hpsb_highlevel *hl, struct hpsb_host *host,
191 void *data);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
193/* Retrieve hpsb_host using a highlevel handle and a key */
Stefan Richtere1d118f2006-07-03 12:02:28 -0400194struct hpsb_host *hpsb_get_host_bykey(struct hpsb_highlevel *hl,
195 unsigned long key);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197#endif /* IEEE1394_HIGHLEVEL_H */