blob: 8d17bd6bd5dbaa964233bd0c0dfb7df467e520f2 [file] [log] [blame]
David S. Millere53e97c2007-07-09 22:22:44 -07001#ifndef _SPARC64_LDC_H
2#define _SPARC64_LDC_H
3
4#include <asm/hypervisor.h>
5
6extern int ldom_domaining_enabled;
David S. Millerb3e13fb2007-07-12 15:55:55 -07007extern void ldom_set_var(const char *var, const char *value);
8extern void ldom_reboot(const char *boot_command);
David S. Miller4f0234f2007-07-13 16:03:42 -07009extern void ldom_power_off(void);
10extern void ldom_startcpu_cpuid(unsigned int cpu, unsigned long thread_reg);
David S. Millere53e97c2007-07-09 22:22:44 -070011
12/* The event handler will be evoked when link state changes
13 * or data becomes available on the receive side.
14 *
15 * For non-RAW links, if the LDC_EVENT_RESET event arrives the
16 * driver should reset all of it's internal state and reinvoke
17 * ldc_connect() to try and bring the link up again.
18 *
19 * For RAW links, ldc_connect() is not used. Instead the driver
20 * just waits for the LDC_EVENT_UP event.
21 */
22struct ldc_channel_config {
23 void (*event)(void *arg, int event);
24
25 u32 mtu;
26 unsigned int rx_irq;
27 unsigned int tx_irq;
28 u8 mode;
29#define LDC_MODE_RAW 0x00
30#define LDC_MODE_UNRELIABLE 0x01
31#define LDC_MODE_RESERVED 0x02
David S. Millercb481232007-07-11 18:14:41 -070032#define LDC_MODE_STREAM 0x03
David S. Millere53e97c2007-07-09 22:22:44 -070033
34 u8 debug;
35#define LDC_DEBUG_HS 0x01
36#define LDC_DEBUG_STATE 0x02
37#define LDC_DEBUG_RX 0x04
38#define LDC_DEBUG_TX 0x08
39#define LDC_DEBUG_DATA 0x10
40};
41
42#define LDC_EVENT_RESET 0x01
43#define LDC_EVENT_UP 0x02
44#define LDC_EVENT_DATA_READY 0x04
45
46#define LDC_STATE_INVALID 0x00
47#define LDC_STATE_INIT 0x01
48#define LDC_STATE_BOUND 0x02
49#define LDC_STATE_READY 0x03
50#define LDC_STATE_CONNECTED 0x04
51
52struct ldc_channel;
53
54/* Allocate state for a channel. */
55extern struct ldc_channel *ldc_alloc(unsigned long id,
56 const struct ldc_channel_config *cfgp,
57 void *event_arg);
58
59/* Shut down and free state for a channel. */
60extern void ldc_free(struct ldc_channel *lp);
61
62/* Register TX and RX queues of the link with the hypervisor. */
David S. Miller133f09a2007-07-11 23:22:55 -070063extern int ldc_bind(struct ldc_channel *lp, const char *name);
David S. Millere53e97c2007-07-09 22:22:44 -070064
65/* For non-RAW protocols we need to complete a handshake before
66 * communication can proceed. ldc_connect() does that, if the
67 * handshake completes successfully, an LDC_EVENT_UP event will
68 * be sent up to the driver.
69 */
70extern int ldc_connect(struct ldc_channel *lp);
71extern int ldc_disconnect(struct ldc_channel *lp);
72
73extern int ldc_state(struct ldc_channel *lp);
74
75/* Read and write operations. Only valid when the link is up. */
76extern int ldc_write(struct ldc_channel *lp, const void *buf,
77 unsigned int size);
78extern int ldc_read(struct ldc_channel *lp, void *buf, unsigned int size);
79
80#define LDC_MAP_SHADOW 0x01
81#define LDC_MAP_DIRECT 0x02
82#define LDC_MAP_IO 0x04
83#define LDC_MAP_R 0x08
84#define LDC_MAP_W 0x10
85#define LDC_MAP_X 0x20
86#define LDC_MAP_RW (LDC_MAP_R | LDC_MAP_W)
87#define LDC_MAP_RWX (LDC_MAP_R | LDC_MAP_W | LDC_MAP_X)
88#define LDC_MAP_ALL 0x03f
89
90struct ldc_trans_cookie {
91 u64 cookie_addr;
92 u64 cookie_size;
93};
94
95struct scatterlist;
96extern int ldc_map_sg(struct ldc_channel *lp,
97 struct scatterlist *sg, int num_sg,
98 struct ldc_trans_cookie *cookies, int ncookies,
99 unsigned int map_perm);
100
101extern int ldc_map_single(struct ldc_channel *lp,
102 void *buf, unsigned int len,
103 struct ldc_trans_cookie *cookies, int ncookies,
104 unsigned int map_perm);
105
106extern void ldc_unmap(struct ldc_channel *lp, struct ldc_trans_cookie *cookies,
107 int ncookies);
108
109extern int ldc_copy(struct ldc_channel *lp, int copy_dir,
110 void *buf, unsigned int len, unsigned long offset,
111 struct ldc_trans_cookie *cookies, int ncookies);
112
113static inline int ldc_get_dring_entry(struct ldc_channel *lp,
114 void *buf, unsigned int len,
115 unsigned long offset,
116 struct ldc_trans_cookie *cookies,
117 int ncookies)
118{
119 return ldc_copy(lp, LDC_COPY_IN, buf, len, offset, cookies, ncookies);
120}
121
122static inline int ldc_put_dring_entry(struct ldc_channel *lp,
123 void *buf, unsigned int len,
124 unsigned long offset,
125 struct ldc_trans_cookie *cookies,
126 int ncookies)
127{
128 return ldc_copy(lp, LDC_COPY_OUT, buf, len, offset, cookies, ncookies);
129}
130
131extern void *ldc_alloc_exp_dring(struct ldc_channel *lp, unsigned int len,
132 struct ldc_trans_cookie *cookies,
133 int *ncookies, unsigned int map_perm);
134
135extern void ldc_free_exp_dring(struct ldc_channel *lp, void *buf,
136 unsigned int len,
137 struct ldc_trans_cookie *cookies, int ncookies);
138
139#endif /* _SPARC64_LDC_H */