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