xref: /titanic_51/usr/src/uts/sun4v/sys/ldc.h (revision 24da5b34f49324ed742a340010ed5bd3d4e06625)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _LDC_H
28 #define	_LDC_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 #include <sys/types.h>
37 #include <sys/ddi.h>
38 #include <sys/sunddi.h>
39 #include <sys/ioctl.h>
40 #include <sys/processor.h>
41 
42 /* Types */
43 typedef uint64_t ldc_handle_t;		/* Channel handle */
44 typedef uint64_t ldc_mem_handle_t;	/* Channel memory handle */
45 typedef uint64_t ldc_dring_handle_t;	/* Descriptor ring handle */
46 
47 /* LDC transport mode */
48 typedef enum {
49 	LDC_MODE_RAW,			/* Raw mode */
50 	LDC_MODE_UNRELIABLE,		/* Unreliable packet mode */
51 	LDC_MODE_RELIABLE,		/* Reliable packet mode */
52 	LDC_MODE_STREAM			/* Reliable byte stream */
53 } ldc_mode_t;
54 
55 /* LDC message payload sizes */
56 #define	LDC_ELEM_SIZE			8		/* size in bytes */
57 #define	LDC_PACKET_SIZE			(LDC_ELEM_SIZE * 8)
58 #define	LDC_PAYLOAD_SIZE_RAW		(LDC_PACKET_SIZE)
59 #define	LDC_PAYLOAD_SIZE_UNRELIABLE	(LDC_PACKET_SIZE - LDC_ELEM_SIZE)
60 #define	LDC_PAYLOAD_SIZE_RELIABLE	(LDC_PACKET_SIZE - (LDC_ELEM_SIZE * 2))
61 
62 /* LDC Channel Status */
63 typedef enum {
64 	LDC_INIT = 1,			/* Channel initialized */
65 	LDC_OPEN,			/* Channel open */
66 	LDC_READY,			/* Channel peer opened (hw-link-up) */
67 	LDC_UP				/* Channel UP - ready for data xfer */
68 } ldc_status_t;
69 
70 /* Callback return values */
71 #define	LDC_SUCCESS	0
72 #define	LDC_FAILURE	1
73 
74 /* LDC callback mode */
75 typedef enum {
76 	LDC_CB_ENABLE,			/* Enable callbacks */
77 	LDC_CB_DISABLE			/* Disable callbacks */
78 } ldc_cb_mode_t;
79 
80 /* Callback events */
81 #define	LDC_EVT_DOWN		0x1	/* Channel DOWN, status = OPEN */
82 #define	LDC_EVT_RESET		0x2	/* Channel RESET, status = READY */
83 #define	LDC_EVT_UP		0x4	/* Channel UP, status = UP */
84 #define	LDC_EVT_READ		0x8	/* Channel has data for read */
85 #define	LDC_EVT_WRITE		0x10	/* Channel has space for write */
86 
87 /* LDC device classes */
88 typedef enum {
89 	LDC_DEV_GENERIC = 1,		/* generic device */
90 	LDC_DEV_BLK,			/* block device, eg. vdc */
91 	LDC_DEV_BLK_SVC,		/* block device service, eg. vds */
92 	LDC_DEV_NT,			/* network device, eg. vnet */
93 	LDC_DEV_NT_SVC,			/* network service eg. vsw */
94 	LDC_DEV_SERIAL			/* serial device eg. vldc, vcc */
95 } ldc_dev_t;
96 
97 /* Channel nexus registration */
98 typedef struct ldc_cnex {
99 	dev_info_t	*dip;		/* dip of channel nexus */
100 	int		(*reg_chan)();	/* interface for channel register */
101 	int		(*unreg_chan)(); /* interface for channel unregister */
102 	int		(*add_intr)();	/* interface for adding interrupts */
103 	int		(*rem_intr)();	/* interface for removing interrupts */
104 	int		(*clr_intr)();	/* interface for clearing interrupts */
105 } ldc_cnex_t;
106 
107 /* LDC attribute structure */
108 typedef struct ldc_attr {
109 	ldc_dev_t	devclass;	/* device class */
110 	uint64_t	instance;	/* device class instance */
111 	ldc_mode_t	mode;		/* channel mode */
112 	uint64_t	mtu;		/* channel mtu */
113 } ldc_attr_t;
114 
115 /* LDC memory cookie */
116 typedef struct ldc_mem_cookie {
117 	uint64_t	addr;		/* cookie address */
118 	uint64_t	size;		/* size @ offset */
119 } ldc_mem_cookie_t;
120 
121 /*
122  * LDC Memory Map Type
123  * Specifies how shared memory being created is shared with its
124  * peer and/or how the peer has mapped in the exported memory.
125  */
126 #define	LDC_SHADOW_MAP		0x1	/* share mem via shadow copy only */
127 #define	LDC_DIRECT_MAP		0x2	/* share mem direct access */
128 #define	LDC_IO_MAP		0x4	/* share mem for IOMMU/DMA access */
129 
130 /* LDC Memory Access Permissions  */
131 #define	LDC_MEM_R		0x1	/* Memory region is read only */
132 #define	LDC_MEM_W		0x2	/* Memory region is write only */
133 #define	LDC_MEM_X		0x4	/* Memory region is execute only */
134 #define	LDC_MEM_RW		(LDC_MEM_R|LDC_MEM_W)
135 #define	LDC_MEM_RWX		(LDC_MEM_R|LDC_MEM_W|LDC_MEM_X)
136 
137 /* LDC Memory Copy Direction */
138 #define	LDC_COPY_IN		0x0	/* Copy data to VA from cookie mem */
139 #define	LDC_COPY_OUT		0x1	/* Copy data from VA to cookie mem */
140 
141 /* LDC memory/dring (handle) status */
142 typedef enum {
143 	LDC_UNBOUND,			/* Memory handle is unbound */
144 	LDC_BOUND,			/* Memory handle is bound */
145 	LDC_MAPPED			/* Memory handle is mapped */
146 } ldc_mstatus_t;
147 
148 /* LDC [dring] memory info */
149 typedef struct ldc_mem_info {
150 	uint8_t		mtype;		/* map type */
151 	uint8_t		perm;		/* RWX permissions */
152 	caddr_t		vaddr;		/* base VA */
153 	uintptr_t	raddr;		/* base RA */
154 	ldc_mstatus_t	status;		/* dring/mem handle status */
155 } ldc_mem_info_t;
156 
157 /* API functions */
158 int ldc_register(ldc_cnex_t *cinfo);
159 int ldc_unregister(ldc_cnex_t *cinfo);
160 
161 int ldc_init(uint64_t id, ldc_attr_t *attr, ldc_handle_t *handle);
162 int ldc_fini(ldc_handle_t handle);
163 int ldc_open(ldc_handle_t handle);
164 int ldc_close(ldc_handle_t handle);
165 int ldc_up(ldc_handle_t handle);
166 int ldc_down(ldc_handle_t handle);
167 int ldc_reg_callback(ldc_handle_t handle,
168     uint_t(*callback)(uint64_t event, caddr_t arg), caddr_t arg);
169 int ldc_unreg_callback(ldc_handle_t handle);
170 int ldc_set_cb_mode(ldc_handle_t handle, ldc_cb_mode_t imode);
171 int ldc_chkq(ldc_handle_t handle, boolean_t *hasdata);
172 int ldc_read(ldc_handle_t handle, caddr_t buf, size_t *size);
173 int ldc_write(ldc_handle_t handle, caddr_t buf, size_t *size);
174 int ldc_status(ldc_handle_t handle, ldc_status_t *status);
175 
176 int ldc_mem_alloc_handle(ldc_handle_t handle, ldc_mem_handle_t *mhandle);
177 int ldc_mem_free_handle(ldc_mem_handle_t mhandle);
178 int ldc_mem_bind_handle(ldc_mem_handle_t mhandle, caddr_t vaddr, size_t len,
179     uint8_t mtype, uint8_t perm, ldc_mem_cookie_t *cookie, uint32_t *ccount);
180 int ldc_mem_unbind_handle(ldc_mem_handle_t mhandle);
181 int ldc_mem_info(ldc_mem_handle_t mhandle, ldc_mem_info_t *minfo);
182 int ldc_mem_nextcookie(ldc_mem_handle_t mhandle, ldc_mem_cookie_t *cookie);
183 int ldc_mem_copy(ldc_handle_t handle, caddr_t vaddr, uint64_t off, size_t *len,
184     ldc_mem_cookie_t *cookies, uint32_t ccount, uint8_t direction);
185 int ldc_mem_rdwr_cookie(ldc_handle_t handle, caddr_t vaddr, size_t *size,
186     caddr_t paddr, uint8_t  direction);
187 int ldc_mem_map(ldc_mem_handle_t mhandle, ldc_mem_cookie_t *cookie,
188     uint32_t ccount, uint8_t mtype, uint8_t perm, caddr_t *vaddr,
189     caddr_t *raddr);
190 int ldc_mem_unmap(ldc_mem_handle_t mhandle);
191 int ldc_mem_acquire(ldc_mem_handle_t mhandle, uint64_t offset, uint64_t size);
192 int ldc_mem_release(ldc_mem_handle_t mhandle, uint64_t offset, uint64_t size);
193 
194 int ldc_mem_dring_create(uint32_t len, uint32_t dsize,
195     ldc_dring_handle_t *dhandle);
196 int ldc_mem_dring_destroy(ldc_dring_handle_t dhandle);
197 int ldc_mem_dring_bind(ldc_handle_t handle, ldc_dring_handle_t dhandle,
198     uint8_t mtype, uint8_t perm, ldc_mem_cookie_t *dcookie, uint32_t *ccount);
199 int ldc_mem_dring_nextcookie(ldc_dring_handle_t mhandle,
200     ldc_mem_cookie_t *cookie);
201 int ldc_mem_dring_unbind(ldc_dring_handle_t dhandle);
202 int ldc_mem_dring_info(ldc_dring_handle_t dhandle, ldc_mem_info_t *minfo);
203 int ldc_mem_dring_map(ldc_handle_t handle, ldc_mem_cookie_t *cookie,
204     uint32_t ccount, uint32_t len, uint32_t dsize, uint8_t mtype,
205     ldc_dring_handle_t *dhandle);
206 int ldc_mem_dring_unmap(ldc_dring_handle_t dhandle);
207 int ldc_mem_dring_acquire(ldc_dring_handle_t dhandle, uint64_t start,
208     uint64_t end);
209 int ldc_mem_dring_release(ldc_dring_handle_t dhandle, uint64_t start,
210     uint64_t end);
211 
212 #ifdef __cplusplus
213 }
214 #endif
215 
216 #endif /* _LDC_H */
217