xref: /onnv-gate/usr/src/uts/sun4v/sys/ldc.h (revision 6408:2dba2c05f7fb)
11991Sheppo /*
21991Sheppo  * CDDL HEADER START
31991Sheppo  *
41991Sheppo  * The contents of this file are subject to the terms of the
51991Sheppo  * Common Development and Distribution License (the "License").
61991Sheppo  * You may not use this file except in compliance with the License.
71991Sheppo  *
81991Sheppo  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
91991Sheppo  * or http://www.opensolaris.org/os/licensing.
101991Sheppo  * See the License for the specific language governing permissions
111991Sheppo  * and limitations under the License.
121991Sheppo  *
131991Sheppo  * When distributing Covered Code, include this CDDL HEADER in each
141991Sheppo  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
151991Sheppo  * If applicable, add the following below this CDDL HEADER, with the
161991Sheppo  * fields enclosed by brackets "[]" replaced with your own identifying
171991Sheppo  * information: Portions Copyright [yyyy] [name of copyright owner]
181991Sheppo  *
191991Sheppo  * CDDL HEADER END
201991Sheppo  */
211991Sheppo 
221991Sheppo /*
23*6408Sha137994  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
241991Sheppo  * Use is subject to license terms.
251991Sheppo  */
261991Sheppo 
271991Sheppo #ifndef _LDC_H
281991Sheppo #define	_LDC_H
291991Sheppo 
301991Sheppo #pragma ident	"%Z%%M%	%I%	%E% SMI"
311991Sheppo 
321991Sheppo #ifdef __cplusplus
331991Sheppo extern "C" {
341991Sheppo #endif
351991Sheppo 
361991Sheppo #include <sys/types.h>
371991Sheppo #include <sys/ddi.h>
381991Sheppo #include <sys/sunddi.h>
391991Sheppo #include <sys/ioctl.h>
401991Sheppo #include <sys/processor.h>
411991Sheppo 
421991Sheppo /* Types */
431991Sheppo typedef uint64_t ldc_handle_t;		/* Channel handle */
441991Sheppo typedef uint64_t ldc_mem_handle_t;	/* Channel memory handle */
451991Sheppo typedef uint64_t ldc_dring_handle_t;	/* Descriptor ring handle */
461991Sheppo 
471991Sheppo /* LDC transport mode */
481991Sheppo typedef enum {
491991Sheppo 	LDC_MODE_RAW,			/* Raw mode */
501991Sheppo 	LDC_MODE_UNRELIABLE,		/* Unreliable packet mode */
51*6408Sha137994 	_LDC_MODE_RESERVED_,		/* reserved */
52*6408Sha137994 	LDC_MODE_RELIABLE		/* Reliable packet mode */
531991Sheppo } ldc_mode_t;
541991Sheppo 
551991Sheppo /* LDC message payload sizes */
561991Sheppo #define	LDC_ELEM_SIZE			8		/* size in bytes */
571991Sheppo #define	LDC_PACKET_SIZE			(LDC_ELEM_SIZE * 8)
581991Sheppo #define	LDC_PAYLOAD_SIZE_RAW		(LDC_PACKET_SIZE)
591991Sheppo #define	LDC_PAYLOAD_SIZE_UNRELIABLE	(LDC_PACKET_SIZE - LDC_ELEM_SIZE)
601991Sheppo #define	LDC_PAYLOAD_SIZE_RELIABLE	(LDC_PACKET_SIZE - (LDC_ELEM_SIZE * 2))
611991Sheppo 
621991Sheppo /* LDC Channel Status */
631991Sheppo typedef enum {
641991Sheppo 	LDC_INIT = 1,			/* Channel initialized */
651991Sheppo 	LDC_OPEN,			/* Channel open */
661991Sheppo 	LDC_READY,			/* Channel peer opened (hw-link-up) */
671991Sheppo 	LDC_UP				/* Channel UP - ready for data xfer */
681991Sheppo } ldc_status_t;
691991Sheppo 
701991Sheppo /* Callback return values */
711991Sheppo #define	LDC_SUCCESS	0
721991Sheppo #define	LDC_FAILURE	1
731991Sheppo 
741991Sheppo /* LDC callback mode */
751991Sheppo typedef enum {
761991Sheppo 	LDC_CB_ENABLE,			/* Enable callbacks */
771991Sheppo 	LDC_CB_DISABLE			/* Disable callbacks */
781991Sheppo } ldc_cb_mode_t;
791991Sheppo 
801991Sheppo /* Callback events */
811991Sheppo #define	LDC_EVT_DOWN		0x1	/* Channel DOWN, status = OPEN */
821991Sheppo #define	LDC_EVT_RESET		0x2	/* Channel RESET, status = READY */
831991Sheppo #define	LDC_EVT_UP		0x4	/* Channel UP, status = UP */
841991Sheppo #define	LDC_EVT_READ		0x8	/* Channel has data for read */
851991Sheppo #define	LDC_EVT_WRITE		0x10	/* Channel has space for write */
861991Sheppo 
871991Sheppo /* LDC device classes */
881991Sheppo typedef enum {
891991Sheppo 	LDC_DEV_GENERIC = 1,		/* generic device */
901991Sheppo 	LDC_DEV_BLK,			/* block device, eg. vdc */
911991Sheppo 	LDC_DEV_BLK_SVC,		/* block device service, eg. vds */
921991Sheppo 	LDC_DEV_NT,			/* network device, eg. vnet */
931991Sheppo 	LDC_DEV_NT_SVC,			/* network service eg. vsw */
941991Sheppo 	LDC_DEV_SERIAL			/* serial device eg. vldc, vcc */
951991Sheppo } ldc_dev_t;
961991Sheppo 
971991Sheppo /* Channel nexus registration */
981991Sheppo typedef struct ldc_cnex {
991991Sheppo 	dev_info_t	*dip;		/* dip of channel nexus */
1001991Sheppo 	int		(*reg_chan)();	/* interface for channel register */
1011991Sheppo 	int		(*unreg_chan)(); /* interface for channel unregister */
1021991Sheppo 	int		(*add_intr)();	/* interface for adding interrupts */
1031991Sheppo 	int		(*rem_intr)();	/* interface for removing interrupts */
1041991Sheppo 	int		(*clr_intr)();	/* interface for clearing interrupts */
1051991Sheppo } ldc_cnex_t;
1061991Sheppo 
1071991Sheppo /* LDC attribute structure */
1081991Sheppo typedef struct ldc_attr {
1091991Sheppo 	ldc_dev_t	devclass;	/* device class */
1101991Sheppo 	uint64_t	instance;	/* device class instance */
1111991Sheppo 	ldc_mode_t	mode;		/* channel mode */
1122410Slm66018 	uint64_t	mtu;		/* channel mtu */
1131991Sheppo } ldc_attr_t;
1141991Sheppo 
1151991Sheppo /* LDC memory cookie */
1161991Sheppo typedef struct ldc_mem_cookie {
1171991Sheppo 	uint64_t	addr;		/* cookie address */
1181991Sheppo 	uint64_t	size;		/* size @ offset */
1191991Sheppo } ldc_mem_cookie_t;
1201991Sheppo 
1211991Sheppo /*
1221991Sheppo  * LDC Memory Map Type
1231991Sheppo  * Specifies how shared memory being created is shared with its
1241991Sheppo  * peer and/or how the peer has mapped in the exported memory.
1251991Sheppo  */
1261991Sheppo #define	LDC_SHADOW_MAP		0x1	/* share mem via shadow copy only */
1271991Sheppo #define	LDC_DIRECT_MAP		0x2	/* share mem direct access */
1281991Sheppo #define	LDC_IO_MAP		0x4	/* share mem for IOMMU/DMA access */
1291991Sheppo 
1301991Sheppo /* LDC Memory Access Permissions  */
1311991Sheppo #define	LDC_MEM_R		0x1	/* Memory region is read only */
1321991Sheppo #define	LDC_MEM_W		0x2	/* Memory region is write only */
1331991Sheppo #define	LDC_MEM_X		0x4	/* Memory region is execute only */
1341991Sheppo #define	LDC_MEM_RW		(LDC_MEM_R|LDC_MEM_W)
1351991Sheppo #define	LDC_MEM_RWX		(LDC_MEM_R|LDC_MEM_W|LDC_MEM_X)
1361991Sheppo 
1371991Sheppo /* LDC Memory Copy Direction */
1381991Sheppo #define	LDC_COPY_IN		0x0	/* Copy data to VA from cookie mem */
1391991Sheppo #define	LDC_COPY_OUT		0x1	/* Copy data from VA to cookie mem */
1401991Sheppo 
1411991Sheppo /* LDC memory/dring (handle) status */
1421991Sheppo typedef enum {
1431991Sheppo 	LDC_UNBOUND,			/* Memory handle is unbound */
1441991Sheppo 	LDC_BOUND,			/* Memory handle is bound */
1451991Sheppo 	LDC_MAPPED			/* Memory handle is mapped */
1461991Sheppo } ldc_mstatus_t;
1471991Sheppo 
1481991Sheppo /* LDC [dring] memory info */
1491991Sheppo typedef struct ldc_mem_info {
1501991Sheppo 	uint8_t		mtype;		/* map type */
1511991Sheppo 	uint8_t		perm;		/* RWX permissions */
1521991Sheppo 	caddr_t		vaddr;		/* base VA */
1531991Sheppo 	uintptr_t	raddr;		/* base RA */
1541991Sheppo 	ldc_mstatus_t	status;		/* dring/mem handle status */
1551991Sheppo } ldc_mem_info_t;
1561991Sheppo 
1571991Sheppo /* API functions */
1581991Sheppo int ldc_register(ldc_cnex_t *cinfo);
1591991Sheppo int ldc_unregister(ldc_cnex_t *cinfo);
1601991Sheppo 
1611991Sheppo int ldc_init(uint64_t id, ldc_attr_t *attr, ldc_handle_t *handle);
1621991Sheppo int ldc_fini(ldc_handle_t handle);
1631991Sheppo int ldc_open(ldc_handle_t handle);
1641991Sheppo int ldc_close(ldc_handle_t handle);
1651991Sheppo int ldc_up(ldc_handle_t handle);
1662410Slm66018 int ldc_down(ldc_handle_t handle);
1671991Sheppo int ldc_reg_callback(ldc_handle_t handle,
1681991Sheppo     uint_t(*callback)(uint64_t event, caddr_t arg), caddr_t arg);
1691991Sheppo int ldc_unreg_callback(ldc_handle_t handle);
1701991Sheppo int ldc_set_cb_mode(ldc_handle_t handle, ldc_cb_mode_t imode);
1712410Slm66018 int ldc_chkq(ldc_handle_t handle, boolean_t *hasdata);
1721991Sheppo int ldc_read(ldc_handle_t handle, caddr_t buf, size_t *size);
1731991Sheppo int ldc_write(ldc_handle_t handle, caddr_t buf, size_t *size);
1741991Sheppo int ldc_status(ldc_handle_t handle, ldc_status_t *status);
1751991Sheppo 
1761991Sheppo int ldc_mem_alloc_handle(ldc_handle_t handle, ldc_mem_handle_t *mhandle);
1771991Sheppo int ldc_mem_free_handle(ldc_mem_handle_t mhandle);
1781991Sheppo int ldc_mem_bind_handle(ldc_mem_handle_t mhandle, caddr_t vaddr, size_t len,
1791991Sheppo     uint8_t mtype, uint8_t perm, ldc_mem_cookie_t *cookie, uint32_t *ccount);
1801991Sheppo int ldc_mem_unbind_handle(ldc_mem_handle_t mhandle);
1811991Sheppo int ldc_mem_info(ldc_mem_handle_t mhandle, ldc_mem_info_t *minfo);
1821991Sheppo int ldc_mem_nextcookie(ldc_mem_handle_t mhandle, ldc_mem_cookie_t *cookie);
1831991Sheppo int ldc_mem_copy(ldc_handle_t handle, caddr_t vaddr, uint64_t off, size_t *len,
1841991Sheppo     ldc_mem_cookie_t *cookies, uint32_t ccount, uint8_t direction);
1852793Slm66018 int ldc_mem_rdwr_cookie(ldc_handle_t handle, caddr_t vaddr, size_t *size,
1861991Sheppo     caddr_t paddr, uint8_t  direction);
1871991Sheppo int ldc_mem_map(ldc_mem_handle_t mhandle, ldc_mem_cookie_t *cookie,
1882531Snarayan     uint32_t ccount, uint8_t mtype, uint8_t perm, caddr_t *vaddr,
1892531Snarayan     caddr_t *raddr);
1902531Snarayan int ldc_mem_unmap(ldc_mem_handle_t mhandle);
1911991Sheppo int ldc_mem_acquire(ldc_mem_handle_t mhandle, uint64_t offset, uint64_t size);
1921991Sheppo int ldc_mem_release(ldc_mem_handle_t mhandle, uint64_t offset, uint64_t size);
1931991Sheppo 
1941991Sheppo int ldc_mem_dring_create(uint32_t len, uint32_t dsize,
1951991Sheppo     ldc_dring_handle_t *dhandle);
1961991Sheppo int ldc_mem_dring_destroy(ldc_dring_handle_t dhandle);
1971991Sheppo int ldc_mem_dring_bind(ldc_handle_t handle, ldc_dring_handle_t dhandle,
1981991Sheppo     uint8_t mtype, uint8_t perm, ldc_mem_cookie_t *dcookie, uint32_t *ccount);
1991991Sheppo int ldc_mem_dring_nextcookie(ldc_dring_handle_t mhandle,
2001991Sheppo     ldc_mem_cookie_t *cookie);
2011991Sheppo int ldc_mem_dring_unbind(ldc_dring_handle_t dhandle);
2021991Sheppo int ldc_mem_dring_info(ldc_dring_handle_t dhandle, ldc_mem_info_t *minfo);
2031991Sheppo int ldc_mem_dring_map(ldc_handle_t handle, ldc_mem_cookie_t *cookie,
2041991Sheppo     uint32_t ccount, uint32_t len, uint32_t dsize, uint8_t mtype,
2051991Sheppo     ldc_dring_handle_t *dhandle);
2061991Sheppo int ldc_mem_dring_unmap(ldc_dring_handle_t dhandle);
2071991Sheppo int ldc_mem_dring_acquire(ldc_dring_handle_t dhandle, uint64_t start,
2081991Sheppo     uint64_t end);
2091991Sheppo int ldc_mem_dring_release(ldc_dring_handle_t dhandle, uint64_t start,
2101991Sheppo     uint64_t end);
2111991Sheppo 
2121991Sheppo #ifdef __cplusplus
2131991Sheppo }
2141991Sheppo #endif
2151991Sheppo 
2161991Sheppo #endif /* _LDC_H */
217