xref: /titanic_44/usr/src/uts/sun4v/sys/ldc.h (revision cee8668251d5ec44fd1c6d6ddeb9c1d1821a57d2)
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 
109 /*
110  * FIXME: Attribute passed in should be an MTU size
111  * Allocate the queue internally to ldc module to accomodate
112  * based on MTU size. For streaming mode, size can be zero.
113  */
114 
115 typedef struct ldc_attr {
116 	ldc_dev_t	devclass;	/* device class */
117 	uint64_t	instance;	/* device class instance */
118 	ldc_mode_t	mode;		/* channel mode */
119 	uint64_t	qlen;		/* channel queue elements */
120 } ldc_attr_t;
121 
122 /* LDC memory cookie */
123 typedef struct ldc_mem_cookie {
124 	uint64_t	addr;		/* cookie address */
125 	uint64_t	size;		/* size @ offset */
126 } ldc_mem_cookie_t;
127 
128 /*
129  * LDC Memory Map Type
130  * Specifies how shared memory being created is shared with its
131  * peer and/or how the peer has mapped in the exported memory.
132  */
133 #define	LDC_SHADOW_MAP		0x1	/* share mem via shadow copy only */
134 #define	LDC_DIRECT_MAP		0x2	/* share mem direct access */
135 #define	LDC_IO_MAP		0x4	/* share mem for IOMMU/DMA access */
136 
137 /* LDC Memory Access Permissions  */
138 #define	LDC_MEM_R		0x1	/* Memory region is read only */
139 #define	LDC_MEM_W		0x2	/* Memory region is write only */
140 #define	LDC_MEM_X		0x4	/* Memory region is execute only */
141 #define	LDC_MEM_RW		(LDC_MEM_R|LDC_MEM_W)
142 #define	LDC_MEM_RWX		(LDC_MEM_R|LDC_MEM_W|LDC_MEM_X)
143 
144 /* LDC Memory Copy Direction */
145 #define	LDC_COPY_IN		0x0	/* Copy data to VA from cookie mem */
146 #define	LDC_COPY_OUT		0x1	/* Copy data from VA to cookie mem */
147 
148 /* LDC memory/dring (handle) status */
149 typedef enum {
150 	LDC_UNBOUND,			/* Memory handle is unbound */
151 	LDC_BOUND,			/* Memory handle is bound */
152 	LDC_MAPPED			/* Memory handle is mapped */
153 } ldc_mstatus_t;
154 
155 /* LDC [dring] memory info */
156 typedef struct ldc_mem_info {
157 	uint8_t		mtype;		/* map type */
158 	uint8_t		perm;		/* RWX permissions */
159 	caddr_t		vaddr;		/* base VA */
160 	uintptr_t	raddr;		/* base RA */
161 	ldc_mstatus_t	status;		/* dring/mem handle status */
162 } ldc_mem_info_t;
163 
164 /* API functions */
165 int ldc_register(ldc_cnex_t *cinfo);
166 int ldc_unregister(ldc_cnex_t *cinfo);
167 
168 int ldc_init(uint64_t id, ldc_attr_t *attr, ldc_handle_t *handle);
169 int ldc_fini(ldc_handle_t handle);
170 int ldc_open(ldc_handle_t handle);
171 int ldc_close(ldc_handle_t handle);
172 int ldc_up(ldc_handle_t handle);
173 int ldc_reset(ldc_handle_t handle);
174 int ldc_reg_callback(ldc_handle_t handle,
175     uint_t(*callback)(uint64_t event, caddr_t arg), caddr_t arg);
176 int ldc_unreg_callback(ldc_handle_t handle);
177 int ldc_set_cb_mode(ldc_handle_t handle, ldc_cb_mode_t imode);
178 int ldc_chkq(ldc_handle_t handle, boolean_t *isempty);
179 int ldc_read(ldc_handle_t handle, caddr_t buf, size_t *size);
180 int ldc_write(ldc_handle_t handle, caddr_t buf, size_t *size);
181 int ldc_status(ldc_handle_t handle, ldc_status_t *status);
182 
183 int ldc_mem_alloc_handle(ldc_handle_t handle, ldc_mem_handle_t *mhandle);
184 int ldc_mem_free_handle(ldc_mem_handle_t mhandle);
185 int ldc_mem_bind_handle(ldc_mem_handle_t mhandle, caddr_t vaddr, size_t len,
186     uint8_t mtype, uint8_t perm, ldc_mem_cookie_t *cookie, uint32_t *ccount);
187 int ldc_mem_unbind_handle(ldc_mem_handle_t mhandle);
188 int ldc_mem_info(ldc_mem_handle_t mhandle, ldc_mem_info_t *minfo);
189 int ldc_mem_nextcookie(ldc_mem_handle_t mhandle, ldc_mem_cookie_t *cookie);
190 int ldc_mem_copy(ldc_handle_t handle, caddr_t vaddr, uint64_t off, size_t *len,
191     ldc_mem_cookie_t *cookies, uint32_t ccount, uint8_t direction);
192 int ldc_mem_rdwr_pa(ldc_handle_t handle, caddr_t vaddr, size_t *size,
193     caddr_t paddr, uint8_t  direction);
194 int ldc_mem_map(ldc_mem_handle_t mhandle, ldc_mem_cookie_t *cookie,
195     uint32_t ccount, uint8_t mtype, caddr_t *vaddr, caddr_t *raddr);
196 int ldc_mem_acquire(ldc_mem_handle_t mhandle, uint64_t offset, uint64_t size);
197 int ldc_mem_release(ldc_mem_handle_t mhandle, uint64_t offset, uint64_t size);
198 
199 int ldc_mem_dring_create(uint32_t len, uint32_t dsize,
200     ldc_dring_handle_t *dhandle);
201 int ldc_mem_dring_destroy(ldc_dring_handle_t dhandle);
202 int ldc_mem_dring_bind(ldc_handle_t handle, ldc_dring_handle_t dhandle,
203     uint8_t mtype, uint8_t perm, ldc_mem_cookie_t *dcookie, uint32_t *ccount);
204 int ldc_mem_dring_nextcookie(ldc_dring_handle_t mhandle,
205     ldc_mem_cookie_t *cookie);
206 int ldc_mem_dring_unbind(ldc_dring_handle_t dhandle);
207 int ldc_mem_dring_info(ldc_dring_handle_t dhandle, ldc_mem_info_t *minfo);
208 int ldc_mem_dring_map(ldc_handle_t handle, ldc_mem_cookie_t *cookie,
209     uint32_t ccount, uint32_t len, uint32_t dsize, uint8_t mtype,
210     ldc_dring_handle_t *dhandle);
211 int ldc_mem_dring_unmap(ldc_dring_handle_t dhandle);
212 int ldc_mem_dring_acquire(ldc_dring_handle_t dhandle, uint64_t start,
213     uint64_t end);
214 int ldc_mem_dring_release(ldc_dring_handle_t dhandle, uint64_t start,
215     uint64_t end);
216 
217 #ifdef __cplusplus
218 }
219 #endif
220 
221 #endif /* _LDC_H */
222