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