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