xref: /onnv-gate/usr/src/uts/sun4v/sys/ldc_impl.h (revision 5944:12a4b3347aac)
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*5944Sha137994  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
241991Sheppo  * Use is subject to license terms.
251991Sheppo  */
261991Sheppo 
271991Sheppo #ifndef _LDC_IMPL_H
281991Sheppo #define	_LDC_IMPL_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 
412410Slm66018 /* Memory map table entries */
422410Slm66018 #define	LDC_MTBL_ENTRIES	8192	/* 8 K */
431991Sheppo 
441991Sheppo /* Define LDC Queue info */
451991Sheppo #define	LDC_PACKET_SHIFT	6
462410Slm66018 #define	LDC_QUEUE_ENTRIES	512
472410Slm66018 #define	LDC_MTU_MSGS		4
481991Sheppo #define	LDC_QUEUE_SIZE		(LDC_QUEUE_ENTRIES << LDC_PACKET_SHIFT)
492410Slm66018 #define	LDC_DEFAULT_MTU		(LDC_QUEUE_SIZE / LDC_MTU_MSGS)
50*5944Sha137994 #define	LDC_RXDQ_MULTIPLIER	2
511991Sheppo 
521991Sheppo /*
531991Sheppo  * LDC Reliable mode - initial packet seqid
541991Sheppo  * - If peer initiated handshake, RDX should contain init_seqid + 1
551991Sheppo  * - If this endpoint initiated handshake first data packet should
561991Sheppo  *   contain the message init_seqid + 1
571991Sheppo  */
581991Sheppo #define	LDC_INIT_SEQID	0x0
591991Sheppo 
601991Sheppo /* LDC Message types */
611991Sheppo #define	LDC_CTRL	0x01	/* Control Pkt */
621991Sheppo #define	LDC_DATA	0x02	/* Data Pkt */
631991Sheppo #define	LDC_ERR		0x10	/* Error Pkt */
641991Sheppo 
651991Sheppo /* LDC Message Subtypes */
661991Sheppo #define	LDC_INFO	0x01	/* Control/Data/Error info pkt */
671991Sheppo #define	LDC_ACK		0x02	/* Control/Data ACK */
681991Sheppo #define	LDC_NACK	0x04	/* Control/Data NACK */
691991Sheppo 
701991Sheppo /* LDC Control Messages */
711991Sheppo #define	LDC_VER		0x01	/* Version message */
721991Sheppo #define	LDC_RTS		0x02	/* Request to Send */
731991Sheppo #define	LDC_RTR		0x03	/* Ready To Receive */
741991Sheppo #define	LDC_RDX		0x04	/* Ready for data exchange */
751991Sheppo 
761991Sheppo #define	LDC_CTRL_MASK	0x0f	/* Mask to read control bits */
771991Sheppo 
781991Sheppo /* LDC Channel Transport State (tstate) */
791991Sheppo #define	TS_TXQ_RDY	0x01	/* allocated TX queue */
801991Sheppo #define	TS_RXQ_RDY	0x02	/* allocated RX queue */
811991Sheppo #define	TS_INIT		(TS_TXQ_RDY | TS_RXQ_RDY)
821991Sheppo #define	TS_QCONF_RDY	0x04	/* registered queues with HV */
831991Sheppo #define	TS_CNEX_RDY	0x08	/* registered channel with cnex */
841991Sheppo #define	TS_OPEN		(TS_INIT | TS_QCONF_RDY | TS_CNEX_RDY)
851991Sheppo #define	TS_LINK_READY	0x10	/* both endpts registered Rx queues */
861991Sheppo #define	TS_READY	(TS_OPEN | TS_LINK_READY)
871991Sheppo #define	TS_VER_DONE	0x20	/* negotiated version */
881991Sheppo #define	TS_VREADY	(TS_READY | TS_VER_DONE)
891991Sheppo #define	TS_HSHAKE_DONE	0x40	/* completed handshake */
901991Sheppo #define	TS_UP		(TS_READY | TS_VER_DONE | TS_HSHAKE_DONE)
911991Sheppo 
922793Slm66018 #define	TS_IN_RESET	0x100	/* channel is in reset state */
932793Slm66018 
941991Sheppo /*  LDC Channel Transport Handshake states */
952032Slm66018 #define	TS_SENT_VER	0x01	/* Sent version */
962032Slm66018 #define	TS_SENT_RTS	0x02	/* Sent RTS */
972032Slm66018 #define	TS_RCVD_RTR	0x04	/* Received RTR */
982032Slm66018 #define	TS_SENT_RDX	0x08	/* Sent RDX */
992032Slm66018 #define	TS_RCVD_VER	0x10	/* Received version */
1002032Slm66018 #define	TS_RCVD_RTS	0x20	/* Received RTS */
1012032Slm66018 #define	TS_SENT_RTR	0x40	/* Sent RTR */
1022032Slm66018 #define	TS_RCVD_RDX	0x80	/* Received RDX */
1031991Sheppo 
1042793Slm66018 /* LDC Interrupt State */
1052793Slm66018 #define	LDC_INTR_NONE	0x00	/* No interrupts */
1062793Slm66018 #define	LDC_INTR_ACTIVE	0x01	/* Interrupt being processed */
1072793Slm66018 #define	LDC_INTR_PEND	0x02	/* Interrupt pending */
1082793Slm66018 
1091991Sheppo /* LDC MSG Envelope */
1101991Sheppo #define	LDC_LEN_MASK	0x3F
1111991Sheppo #define	LDC_FRAG_MASK	0xC0
1121991Sheppo 
1131991Sheppo #define	LDC_FRAG_START	0x40	/* frag_info = 0x01 */
1141991Sheppo #define	LDC_FRAG_STOP	0x80	/* frag_info = 0x02 */
1151991Sheppo #define	LDC_FRAG_CONT	0x00	/* frag_info = 0x00 */
1161991Sheppo 
1171991Sheppo /*
1182032Slm66018  * LDC will retry LDC_MAX_RETRIES times when sending or
1192032Slm66018  * receiving data or if the HV returns back EWOULDBLOCK.
1202032Slm66018  * Between each retry it will wait LDC_DELAY usecs.
1211991Sheppo  */
1222032Slm66018 #define	LDC_MAX_RETRIES	1000
1232032Slm66018 #define	LDC_DELAY	1
1241991Sheppo 
1253151Ssg70180 /* delay(usec) between channel unregister retries in ldc_close() */
1263151Ssg70180 #define	LDC_CLOSE_DELAY	1
1273151Ssg70180 
1281991Sheppo /*
1291991Sheppo  * LDC Version information
1301991Sheppo  */
1311991Sheppo #define	LDC_PAYLOAD_VER_OFF	8	/* offset of version in payload */
1321991Sheppo 
1331991Sheppo typedef struct ldc_ver {
1341991Sheppo 	uint16_t	major;
1351991Sheppo 	uint16_t	minor;
1361991Sheppo } ldc_ver_t;
1371991Sheppo 
1381991Sheppo /*
1391991Sheppo  * Each guest consists of one or more LDC endpoints represented by a ldc_chan
1401991Sheppo  * structure. Each ldc_chan structure points to a ldc_mtbl structure that
1411991Sheppo  * contains information about the map table associated with this LDC endpoint.
1421991Sheppo  * The map table contains the list of pages being shared by this guest over
1431991Sheppo  * this endpoint with the guest at the other end of this endpoint. Each LDC
1441991Sheppo  * endpoint also points to a list of memory handles used to bind and export
1451991Sheppo  * memory segments from this guest. If a memory segment is bound, it points to
1461991Sheppo  * a memory segment structure, which inturn consists of an array of ldc_page
1471991Sheppo  * structure for all the pages within that segment. Each ldc_page structure
1481991Sheppo  * contains information about the shared page and also points to the
1491991Sheppo  * corresponding entry in the map table.
1501991Sheppo  *
1511991Sheppo  * Each LDC endpoint also points to a list of ldc_dring structures that refer
1521991Sheppo  * to both imported and exported descriptor rings. If it is a exported
1531991Sheppo  * descriptor ring, it then points to memory handle/memseg corresponding to
1541991Sheppo  * the region of memory associated with the descriptor ring.
1551991Sheppo  *
1561991Sheppo  *     +----------+   +----------+   +----------+
1571991Sheppo  *     | ldc_chan |-->| ldc_chan |-->| ldc_chan |-->....
1581991Sheppo  *     +----------+   +----------+   +----------+
1591991Sheppo  *       |  |  |
1601991Sheppo  *       |  |  |
1611991Sheppo  *       |  |  |      +-----------+     +-----------+
1621991Sheppo  *       |  |  +----->| ldc_dring |---->| ldc_dring |---->......
1631991Sheppo  *       |  |         +-----------+     +-----------+
1641991Sheppo  *       |  |               |
1651991Sheppo  *       |  |               +----------------------------+
1661991Sheppo  *       |  |                                            |
1671991Sheppo  *       |  |                                            v
1681991Sheppo  *       |  |      +----------+     +----------+     +----------+
1691991Sheppo  *       |  +----->| ldc_mhdl |---->| ldc_mhdl |---->| ldc_mhdl |---> ....
1701991Sheppo  *       |         +----------+     +----------+     +----------+
1711991Sheppo  *       v                 |                             |
1721991Sheppo  *  +----------+           |    +------------+           |    +------------+
1731991Sheppo  *  | ldc_mtbl |--+        +--->| ldc_memseg |-----+     +--->| ldc_memseg |
1741991Sheppo  *  +----------+  |             +------------+     |          +------------+
1751991Sheppo  *                |                   |            |            |       |
1761991Sheppo  *                v                   v            v            |       v
1771991Sheppo  *     +--------------+         +----------+  +--------+        |   +--------+
1781991Sheppo  *     | ldc_mte_slot |<--------| ldc_page |  | cookie |        |   | cookie |
1791991Sheppo  *     +--------------+         +----------+  +--------+        |   +--------+
1801991Sheppo  *     | ldc_mte_slot |<--------| ldc_page |  | cookie |        v
1811991Sheppo  *     +--------------+         +----------+  +--------+   +----------+
1821991Sheppo  *     | ldc_mte_slot |<-----------------------------------| ldc_page |
1831991Sheppo  *     +--------------+                                    +----------+
1841991Sheppo  *     | ldc_mte_slot |
1851991Sheppo  *     +--------------+
1861991Sheppo  *     |    ......    |/ +------------+
1871991Sheppo  *     +--------------+  |   entry    |
1881991Sheppo  *     | ldc_mte_slot |  +------------+
1891991Sheppo  *     +--------------+  | inv_cookie |
1901991Sheppo  *                     \ +------------+
1911991Sheppo  *
1921991Sheppo  */
1931991Sheppo 
1941991Sheppo /*
1951991Sheppo  * Message format of each packet sent over the LDC channel.
1961991Sheppo  * Each packet is 64-bytes long.
1971991Sheppo  *
1981991Sheppo  * Each packet that is sent over LDC can contain either data or acks.
1991991Sheppo  * The type will reflect the contents. The len will contain in bytes
2001991Sheppo  * the amount of data being sent. In the case of ACKs, the seqid and
2011991Sheppo  * data fields will contain the SEQIDs of messages for which ACKs are
2021991Sheppo  * being sent.
2031991Sheppo  *
2041991Sheppo  * Raw pkt format:
2051991Sheppo  *
2061991Sheppo  *          +------------------------------------------------------+
2071991Sheppo  *  0 - 7   |                 data payload                         |
2081991Sheppo  *          +------------------------------------------------------+
2091991Sheppo  *
2101991Sheppo  * Unreliable pkt format:
2111991Sheppo  *
2121991Sheppo  *          +------------------------------------------------------+
2131991Sheppo  *      0   |          seqid          | env  | ctrl | stype | type |
2141991Sheppo  *          +------------------------------------------------------+
2151991Sheppo  *  1 - 7   |                 data payload                         |
2161991Sheppo  *          +------------------------------------------------------+
2171991Sheppo  *
2181991Sheppo  * Reliable pkt format:
2191991Sheppo  *
2201991Sheppo  *          +------------------------------------------------------+
2211991Sheppo  *      0   |            seqid        | env  | ctrl | stype | type |
2221991Sheppo  *          +------------------------------------------------------+
2231991Sheppo  *      1   |          ackid          |         unused             |
2241991Sheppo  *          +------------------------------------------------------+
2251991Sheppo  *  2 - 7   |                 data payload                         |
2261991Sheppo  *          +------------------------------------------------------+
2271991Sheppo  */
2281991Sheppo 
2291991Sheppo typedef struct ldc_msg {
2301991Sheppo 	union {
2311991Sheppo 		struct {
2321991Sheppo 			uint8_t		_type;	/* Message type */
2331991Sheppo 			uint8_t		_stype;	/* Message subtype */
2341991Sheppo 			uint8_t		_ctrl;	/* Control/Error Message */
2351991Sheppo 			uint8_t 	_env;	/* Message Envelope */
2361991Sheppo 			uint32_t	_seqid;	/* Sequence ID */
2371991Sheppo 
2381991Sheppo 			union {
2391991Sheppo 				uint8_t	_ud[LDC_PAYLOAD_SIZE_UNRELIABLE];
2401991Sheppo 						/* Unreliable data payload */
2411991Sheppo 				struct {
2421991Sheppo 					uint32_t _unused;	/* unused */
2431991Sheppo 					uint32_t _ackid;	/* ACK ID */
2441991Sheppo 					uint8_t	_rd[LDC_PAYLOAD_SIZE_RELIABLE];
2451991Sheppo 						/* Reliable data payload */
2461991Sheppo 				} _rl;
2471991Sheppo 			} _data;
2481991Sheppo 		} _tpkt;
2491991Sheppo 
2501991Sheppo 		uint8_t		_raw[LDC_PAYLOAD_SIZE_RAW];
2511991Sheppo 	} _pkt;
2521991Sheppo 
2531991Sheppo } ldc_msg_t;
2541991Sheppo 
2551991Sheppo #define	raw		_pkt._raw
2561991Sheppo #define	type		_pkt._tpkt._type
2571991Sheppo #define	stype		_pkt._tpkt._stype
2581991Sheppo #define	ctrl		_pkt._tpkt._ctrl
2591991Sheppo #define	env		_pkt._tpkt._env
2601991Sheppo #define	seqid		_pkt._tpkt._seqid
2611991Sheppo #define	udata		_pkt._tpkt._data._ud
2621991Sheppo #define	ackid		_pkt._tpkt._data._rl._ackid
2631991Sheppo #define	rdata		_pkt._tpkt._data._rl._rd
2641991Sheppo 
2651991Sheppo /*
2661991Sheppo  * LDC Map Table Entry (MTE)
2671991Sheppo  *
2681991Sheppo  *   6    6                               1    1  1
2691991Sheppo  *  |3    0|                       psz|   3|   1| 0| 9| 8| 7|6|5|4|      0|
2701991Sheppo  *  +------+--------------------------+----+----+--+--+--+--+-+-+-+-------+
2711991Sheppo  *  | rsvd |           PFN            | 0  | 0  |CW|CR|IW|IR|X|W|R| pgszc |
2721991Sheppo  *  +------+--------------------------+----+----+--+--+--+--+-+-+-+-------+
2731991Sheppo  *  |                       hv invalidation cookie                        |
2741991Sheppo  *  +---------------------------------------------------------------------+
2751991Sheppo  */
2761991Sheppo typedef union {
2771991Sheppo 	struct {
2781991Sheppo 		uint64_t	_rsvd2:8,	/* <63:56> reserved */
2791991Sheppo 				rpfn:43,	/* <55:13> real pfn */
2801991Sheppo 				_rsvd1:2,	/* <12:11> reserved */
2811991Sheppo 				cw:1,		/* <10> copy write access */
2821991Sheppo 				cr:1,		/* <9> copy read perm */
2831991Sheppo 				iw:1,		/* <8> iommu write perm */
2841991Sheppo 				ir:1,		/* <7> iommu read perm */
2851991Sheppo 				x:1,		/* <6> execute perm */
2861991Sheppo 				w:1,		/* <5> write perm */
2871991Sheppo 				r:1,		/* <4> read perm */
2881991Sheppo 				pgszc:4;	/* <3:0> pgsz code */
2891991Sheppo 	} mte_bit;
2901991Sheppo 
2911991Sheppo 	uint64_t 		ll;
2921991Sheppo 
2931991Sheppo } ldc_mte_t;
2941991Sheppo 
2951991Sheppo #define	mte_rpfn	mte_bit.rpfn
2961991Sheppo #define	mte_cw		mte_bit.cw
2971991Sheppo #define	mte_cr		mte_bit.cr
2981991Sheppo #define	mte_iw		mte_bit.iw
2991991Sheppo #define	mte_ir		mte_bit.ir
3001991Sheppo #define	mte_x		mte_bit.x
3011991Sheppo #define	mte_w		mte_bit.w
3021991Sheppo #define	mte_r		mte_bit.r
3031991Sheppo #define	mte_pgszc	mte_bit.pgszc
3041991Sheppo 
3051991Sheppo #define	MTE_BSZS_SHIFT(sz)	((sz) * 3)
3061991Sheppo #define	MTEBYTES(sz)    	(MMU_PAGESIZE << MTE_BSZS_SHIFT(sz))
3071991Sheppo #define	MTEPAGES(sz)    	(1 << MTE_BSZS_SHIFT(sz))
3081991Sheppo #define	MTE_PAGE_SHIFT(sz)	(MMU_PAGESHIFT + MTE_BSZS_SHIFT(sz))
3091991Sheppo #define	MTE_PAGE_OFFSET(sz)	(MTEBYTES(sz) - 1)
3101991Sheppo #define	MTE_PAGEMASK(sz)	(~MTE_PAGE_OFFSET(sz))
3111991Sheppo #define	MTE_PFNMASK(sz)		(~(MTE_PAGE_OFFSET(sz) >> MMU_PAGESHIFT))
3121991Sheppo 
3131991Sheppo /*
3141991Sheppo  * LDC Map Table Slot
3151991Sheppo  */
3161991Sheppo typedef struct ldc_mte_slot {
3171991Sheppo 	ldc_mte_t	entry;
3181991Sheppo 	uint64_t	cookie;
3191991Sheppo } ldc_mte_slot_t;
3201991Sheppo 
3211991Sheppo /*
3221991Sheppo  * LDC Memory Map Table
3231991Sheppo  *
3241991Sheppo  * Each LDC has a memory map table it uses to list all the pages
3251991Sheppo  * it exporting to its peer over the channel. This structure
3261991Sheppo  * contains information about the map table and is pointed to
3271991Sheppo  * by the ldc_chan structure.
3281991Sheppo  */
3291991Sheppo typedef struct ldc_mtbl {
3301991Sheppo 	kmutex_t		lock;		/* Table lock */
3311991Sheppo 	size_t			size;		/* Table size (in bytes) */
3321991Sheppo 	uint64_t		next_entry;	/* Next entry to use */
3331991Sheppo 	uint64_t		num_entries;	/* Num entries in table */
3341991Sheppo 	uint64_t		num_avail;	/* Num of available entries */
3352793Slm66018 	boolean_t		contigmem;	/* TRUE=Contig mem alloc'd */
3361991Sheppo 	ldc_mte_slot_t		*table;		/* The table itself */
3371991Sheppo } ldc_mtbl_t;
3381991Sheppo 
3391991Sheppo /*
3401991Sheppo  * LDC page and memory segment information
3411991Sheppo  */
3421991Sheppo typedef struct ldc_page {
3431991Sheppo 	uintptr_t		raddr;		/* Exported page RA */
3441991Sheppo 	uint64_t		offset;		/* Exported page offset */
3451991Sheppo 	size_t			size;		/* Exported page size */
3461991Sheppo 	uint64_t		index;		/* Index in map table */
3471991Sheppo 	ldc_mte_slot_t		*mte;		/* Map table entry */
3481991Sheppo } ldc_page_t;
3491991Sheppo 
3501991Sheppo typedef struct ldc_memseg {
3511991Sheppo 	caddr_t			vaddr;		/* Exported segment VA */
3521991Sheppo 	uintptr_t		raddr;		/* Exported segment VA */
3531991Sheppo 	size_t			size;		/* Exported segment size */
3541991Sheppo 	uint64_t		npages;		/* Number of pages */
3551991Sheppo 	ldc_page_t		*pages;		/* Array of exported pages */
3561991Sheppo 	uint32_t		ncookies;	/* Number of cookies */
3571991Sheppo 	ldc_mem_cookie_t	*cookies;
3581991Sheppo 	uint64_t		next_cookie;	/* Index to next cookie */
3591991Sheppo } ldc_memseg_t;
3601991Sheppo 
3611991Sheppo /*
3621991Sheppo  * LDC Cookie address format
3631991Sheppo  *
3641991Sheppo  *   6       6          m+n
3651991Sheppo  *  |3|      0|          |                  m|                  0|
3661991Sheppo  *  +-+-------+----------+-------------------+-------------------+
3671991Sheppo  *  |X| pgszc |   rsvd   |      table_idx    |     page_offset   |
3681991Sheppo  *  +-+-------+----------+-------------------+-------------------+
3691991Sheppo  */
3701991Sheppo #define	LDC_COOKIE_PGSZC_MASK	0x7
3711991Sheppo #define	LDC_COOKIE_PGSZC_SHIFT	60
3721991Sheppo 
3731991Sheppo /*
3741991Sheppo  * LDC Memory handle
3751991Sheppo  */
3761991Sheppo typedef struct ldc_chan ldc_chan_t;
3771991Sheppo 
3781991Sheppo typedef struct ldc_mhdl {
3791991Sheppo 	kmutex_t		lock;		/* Mutex for memory handle */
3801991Sheppo 	ldc_mstatus_t		status;		/* Memory map status */
3811991Sheppo 
3821991Sheppo 	uint8_t			mtype;		/* Type of sharing */
3831991Sheppo 	uint8_t			perm;		/* Access permissions */
3841991Sheppo 	boolean_t		myshadow;	/* TRUE=alloc'd shadow mem */
3851991Sheppo 
3861991Sheppo 	ldc_chan_t		*ldcp;		/* Pointer to channel struct */
3871991Sheppo 	ldc_memseg_t		*memseg;	/* Bound memory segment */
3881991Sheppo 	struct ldc_mhdl		*next;		/* Next memory handle */
3891991Sheppo } ldc_mhdl_t;
3901991Sheppo 
3911991Sheppo /*
3921991Sheppo  * LDC Descriptor rings
3931991Sheppo  */
3941991Sheppo 
3951991Sheppo typedef struct ldc_dring {
3961991Sheppo 	kmutex_t		lock;		/* Desc ring lock */
3971991Sheppo 	ldc_mstatus_t		status;		/* Desc ring status */
3981991Sheppo 
3991991Sheppo 	uint32_t		dsize;		/* Descriptor size */
4001991Sheppo 	uint32_t		length;		/* Descriptor ring length */
4011991Sheppo 	uint64_t		size;		/* Desc ring size (in bytes) */
4021991Sheppo 	caddr_t			base;		/* Descriptor ring base addr */
4031991Sheppo 
4041991Sheppo 	ldc_chan_t		*ldcp;		/* Pointer to bound channel */
4051991Sheppo 	ldc_mem_handle_t	mhdl;		/* Mem handle to desc ring */
4061991Sheppo 
4071991Sheppo 	struct ldc_dring	*ch_next;	/* Next dring in channel */
4081991Sheppo 	struct ldc_dring 	*next;		/* Next dring overall */
4091991Sheppo 
4101991Sheppo } ldc_dring_t;
4111991Sheppo 
4121991Sheppo 
4131991Sheppo /*
4141991Sheppo  * Channel specific information is kept in a separate
4151991Sheppo  * structure. These are then stored on a array indexed
4161991Sheppo  * by the channel number.
4171991Sheppo  */
4181991Sheppo struct ldc_chan {
4191991Sheppo 	ldc_chan_t	*next;		/* Next channel */
4201991Sheppo 
4211991Sheppo 	kmutex_t	lock;		/* Channel lock */
4221991Sheppo 	uint64_t	id;		/* Channel ID */
4231991Sheppo 	ldc_status_t	status;		/* Channel status */
4241991Sheppo 	uint32_t	tstate;		/* Channel transport state */
4251991Sheppo 	uint32_t	hstate;		/* Channel transport handshake state */
4261991Sheppo 
4271991Sheppo 	ldc_dev_t	devclass;	/* Associated device class */
4281991Sheppo 	uint64_t	devinst;	/* Associated device instance */
4291991Sheppo 	ldc_mode_t	mode;		/* Channel mode */
4301991Sheppo 
4312793Slm66018 	uint64_t	mtu;		/* Max TU size */
4321991Sheppo 
4331991Sheppo 	ldc_ver_t	version;	/* Channel version */
4341991Sheppo 	uint32_t	next_vidx;	/* Next version to match */
4351991Sheppo 
4361991Sheppo 	uint_t		(*cb)(uint64_t event, caddr_t arg);
4371991Sheppo 	caddr_t		cb_arg;		/* Channel callback and arg */
4381991Sheppo 	boolean_t	cb_inprogress;	/* Channel callback in progress */
4391991Sheppo 	boolean_t	cb_enabled;	/* Channel callbacks are enabled */
4401991Sheppo 
4412793Slm66018 	uint8_t		tx_intr_state;	/* Tx interrupt state */
4422793Slm66018 	uint8_t		rx_intr_state;	/* Rx interrupt state */
4431991Sheppo 
4442336Snarayan 	kmutex_t	tx_lock;	/* Transmit lock */
4451991Sheppo 	uint64_t	tx_q_entries;	/* Num entries in transmit queue */
4461991Sheppo 	uint64_t	tx_q_va;	/* Virtual addr of transmit queue */
4471991Sheppo 	uint64_t	tx_q_ra;	/* Real addr of transmit queue */
4481991Sheppo 	uint64_t	tx_head;	/* Tx queue head */
4491991Sheppo 	uint64_t	tx_ackd_head;	/* Tx queue ACKd head (Reliable) */
4501991Sheppo 	uint64_t	tx_tail;	/* Tx queue tail */
4511991Sheppo 
4521991Sheppo 	uint64_t	rx_q_entries;	/* Num entries in receive queue */
4531991Sheppo 	uint64_t	rx_q_va;	/* Virtual addr of receive queue */
4541991Sheppo 	uint64_t	rx_q_ra;	/* Real addr of receive queue */
4551991Sheppo 
456*5944Sha137994 	uint64_t	rx_dq_entries;	/* Num entries in the data queue */
457*5944Sha137994 	uint64_t	rx_dq_va;	/* Virtual addr of the data queue */
458*5944Sha137994 	uint64_t	rx_dq_head;	/* Receive data queue head */
459*5944Sha137994 	uint64_t	rx_dq_tail;	/* Receive data queue tail */
460*5944Sha137994 	uint64_t	rx_ack_head;	/* Receive data ACK peek head ptr */
461*5944Sha137994 
4621991Sheppo 	uint64_t	link_state;	/* Underlying HV channel state */
4631991Sheppo 
4641991Sheppo 	ldc_mtbl_t	*mtbl;		/* Memory table used by channel */
4651991Sheppo 	ldc_mhdl_t	*mhdl_list;	/* List of memory handles */
4661991Sheppo 	kmutex_t	mlist_lock;	/* Mem handle list lock */
4671991Sheppo 
4681991Sheppo 	ldc_dring_t	*exp_dring_list; /* Exported desc ring list */
4691991Sheppo 	kmutex_t	exp_dlist_lock;	/* Lock for exported desc ring list */
4701991Sheppo 	ldc_dring_t	*imp_dring_list; /* Imported desc ring list */
4711991Sheppo 	kmutex_t	imp_dlist_lock;	/* Lock for imported desc ring list */
4721991Sheppo 
4731991Sheppo 	uint8_t		pkt_payload;	/* Size of packet payload */
4741991Sheppo 
4751991Sheppo 	uint32_t	last_msg_snt;	/* Seqid of last packet sent */
4761991Sheppo 	uint32_t	last_ack_rcd;	/* Seqid of last ACK recd */
4771991Sheppo 	uint32_t	last_msg_rcd;	/* Seqid of last packet received */
4781991Sheppo 
4791991Sheppo 	uint32_t	stream_remains;	/* Number of bytes in stream */
4801991Sheppo 					/* packet buffer */
4811991Sheppo 	uint32_t	stream_offset;	/* Offset into packet buffer for */
4821991Sheppo 					/* next read */
4831991Sheppo 	uint8_t		*stream_bufferp; /* Stream packet buffer */
4841991Sheppo 
4851991Sheppo 	int		(*read_p)(ldc_chan_t *ldcp, caddr_t bufferp,
4861991Sheppo 				size_t *sizep);
4871991Sheppo 	int		(*write_p)(ldc_chan_t *ldcp, caddr_t bufferp,
4881991Sheppo 				size_t *sizep);
489*5944Sha137994 
490*5944Sha137994 	uint64_t	(*readq_get_state)(ldc_chan_t *ldcp, uint64_t *head,
491*5944Sha137994 				uint64_t *tail, uint64_t *link_state);
492*5944Sha137994 
493*5944Sha137994 	int		(*readq_set_head)(ldc_chan_t *ldcp, uint64_t head);
4941991Sheppo };
4951991Sheppo 
4961991Sheppo 
4971991Sheppo /*
4981991Sheppo  * LDC module soft state structure
4991991Sheppo  */
5001991Sheppo typedef struct ldc_soft_state {
5011991Sheppo 	kmutex_t 	lock;		/* Protects ldc_soft_state_t  */
5021991Sheppo 	ldc_cnex_t	cinfo;		/* channel nexus info */
5031991Sheppo 	uint64_t	channel_count;	/* Number of channels */
5041991Sheppo 	uint64_t	channels_open;	/* Number of open channels */
5051991Sheppo 	ldc_chan_t 	*chan_list;	/* List of LDC endpoints */
5061991Sheppo 	ldc_dring_t	*dring_list;	/* Descriptor rings (for export) */
5072531Snarayan 
5082531Snarayan 	kmem_cache_t	*memhdl_cache;	/* Memory handle cache */
5092531Snarayan 	kmem_cache_t	*memseg_cache;	/* Memory segment cache */
5101991Sheppo } ldc_soft_state_t;
5111991Sheppo 
5121991Sheppo #ifdef __cplusplus
5131991Sheppo }
5141991Sheppo #endif
5151991Sheppo 
5161991Sheppo #endif /* _LDC_IMPL_H */
517