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