ldc_impl.h revision e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * CDDL HEADER START
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * The contents of this file are subject to the terms of the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Common Development and Distribution License (the "License").
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * You may not use this file except in compliance with the License.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * See the License for the specific language governing permissions
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * and limitations under the License.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * When distributing Covered Code, include this CDDL HEADER in each
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * If applicable, add the following below this CDDL HEADER, with the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * fields enclosed by brackets "[]" replaced with your own identifying
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * information: Portions Copyright [yyyy] [name of copyright owner]
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * CDDL HEADER END
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Use is subject to license terms.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#pragma ident "%Z%%M% %I% %E% SMI"
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppoextern "C" {
e1ebb9ec908bc2d0a8810f137ebd6566cc8a8061lm/* Memory map table entries */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* Define LDC Queue info */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define LDC_QUEUE_SIZE (LDC_QUEUE_ENTRIES << LDC_PACKET_SHIFT)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * LDC Reliable mode - initial packet seqid
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * - If peer initiated handshake, RDX should contain init_seqid + 1
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * - If this endpoint initiated handshake first data packet should
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * contain the message init_seqid + 1
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* LDC Message types */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* LDC Message Subtypes */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define LDC_INFO 0x01 /* Control/Data/Error info pkt */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* LDC Control Messages */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define LDC_CTRL_MASK 0x0f /* Mask to read control bits */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* LDC Channel Transport State (tstate) */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define TS_QCONF_RDY 0x04 /* registered queues with HV */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define TS_CNEX_RDY 0x08 /* registered channel with cnex */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define TS_LINK_READY 0x10 /* both endpts registered Rx queues */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define TS_UP (TS_READY | TS_VER_DONE | TS_HSHAKE_DONE)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* LDC Channel Transport Handshake states */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* LDC MSG Envelope */
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * LDC will retry LDC_MAX_RETRIES times when sending or
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * receiving data or if the HV returns back EWOULDBLOCK.
0a55fbb79ee31ed09f84a9ae28e9747bc23f4a08lm * Between each retry it will wait LDC_DELAY usecs.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * LDC Version information
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define LDC_PAYLOAD_VER_OFF 8 /* offset of version in payload */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef struct ldc_ver {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Each guest consists of one or more LDC endpoints represented by a ldc_chan
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * structure. Each ldc_chan structure points to a ldc_mtbl structure that
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * contains information about the map table associated with this LDC endpoint.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * The map table contains the list of pages being shared by this guest over
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * this endpoint with the guest at the other end of this endpoint. Each LDC
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * endpoint also points to a list of memory handles used to bind and export
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * memory segments from this guest. If a memory segment is bound, it points to
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * a memory segment structure, which inturn consists of an array of ldc_page
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * structure for all the pages within that segment. Each ldc_page structure
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * contains information about the shared page and also points to the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * corresponding entry in the map table.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Each LDC endpoint also points to a list of ldc_dring structures that refer
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * to both imported and exported descriptor rings. If it is a exported
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * descriptor ring, it then points to memory handle/memseg corresponding to
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * the region of memory associated with the descriptor ring.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +----------+ +----------+ +----------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | ldc_chan |-->| ldc_chan |-->| ldc_chan |-->....
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +----------+ +----------+ +----------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | | | +-----------+ +-----------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | | +----->| ldc_dring |---->| ldc_dring |---->......
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | | +-----------+ +-----------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | | +----------------------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | | +----------+ +----------+ +----------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | +----->| ldc_mhdl |---->| ldc_mhdl |---->| ldc_mhdl |---> ....
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | +----------+ +----------+ +----------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +----------+ | +------------+ | +------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | ldc_mtbl |--+ +--->| ldc_memseg |-----+ +--->| ldc_memseg |
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +----------+ | +------------+ | +------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | | | | |
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * v v v | v
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +--------------+ +----------+ +--------+ | +--------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | ldc_mte_slot |<--------| ldc_page | | cookie | | | cookie |
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +--------------+ +----------+ +--------+ | +--------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | ldc_mte_slot |<--------| ldc_page | | cookie | v
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +--------------+ +----------+ +--------+ +----------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | ldc_mte_slot |<-----------------------------------| ldc_page |
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +--------------+ +----------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | ldc_mte_slot |
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +--------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | ...... |/ +------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +--------------+ | entry |
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | ldc_mte_slot | +------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +--------------+ | inv_cookie |
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * \ +------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Message format of each packet sent over the LDC channel.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Each packet is 64-bytes long.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Each packet that is sent over LDC can contain either data or acks.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * The type will reflect the contents. The len will contain in bytes
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * the amount of data being sent. In the case of ACKs, the seqid and
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * data fields will contain the SEQIDs of messages for which ACKs are
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * being sent.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Raw pkt format:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +------------------------------------------------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * 0 - 7 | data payload |
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +------------------------------------------------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Unreliable pkt format:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +------------------------------------------------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * 0 | seqid | env | ctrl | stype | type |
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +------------------------------------------------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * 1 - 7 | data payload |
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +------------------------------------------------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Reliable pkt format:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +------------------------------------------------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * 0 | seqid | env | ctrl | stype | type |
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +------------------------------------------------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * 1 | ackid | unused |
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +------------------------------------------------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * 2 - 7 | data payload |
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +------------------------------------------------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef struct ldc_msg {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Unreliable data payload */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* Reliable data payload */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * LDC Map Table Entry (MTE)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * 6 6 1 1 1
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * |3 0| psz| 3| 1| 0| 9| 8| 7|6|5|4| 0|
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +------+--------------------------+----+----+--+--+--+--+-+-+-+-------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | rsvd | PFN | 0 | 0 |CW|CR|IW|IR|X|W|R| pgszc |
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +------+--------------------------+----+----+--+--+--+--+-+-+-+-------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * | hv invalidation cookie |
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +---------------------------------------------------------------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef union {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define MTEBYTES(sz) (MMU_PAGESIZE << MTE_BSZS_SHIFT(sz))
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define MTE_PAGE_SHIFT(sz) (MMU_PAGESHIFT + MTE_BSZS_SHIFT(sz))
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define MTE_PFNMASK(sz) (~(MTE_PAGE_OFFSET(sz) >> MMU_PAGESHIFT))
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * LDC Map Table Slot
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef struct ldc_mte_slot {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * LDC Memory Map Table
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Each LDC has a memory map table it uses to list all the pages
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * it exporting to its peer over the channel. This structure
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * contains information about the map table and is pointed to
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * by the ldc_chan structure.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef struct ldc_mtbl {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * LDC page and memory segment information
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef struct ldc_page {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef struct ldc_memseg {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * LDC Cookie address format
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * |3| 0| | m| 0|
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +-+-------+----------+-------------------+-------------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * |X| pgszc | rsvd | table_idx | page_offset |
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * +-+-------+----------+-------------------+-------------------+
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * LDC Memory handle
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef struct ldc_mhdl {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * LDC Descriptor rings
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef struct ldc_dring {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo struct ldc_dring *ch_next; /* Next dring in channel */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Channel specific information is kept in a separate
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * structure. These are then stored on a array indexed
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * by the channel number.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint32_t hstate; /* Channel transport handshake state */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo boolean_t cb_inprogress; /* Channel callback in progress */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo boolean_t cb_enabled; /* Channel callbacks are enabled */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo boolean_t intr_pending; /* TRUE if interrupts are pending */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint64_t tx_q_entries; /* Num entries in transmit queue */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint64_t tx_q_va; /* Virtual addr of transmit queue */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint64_t tx_ackd_head; /* Tx queue ACKd head (Reliable) */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint64_t rx_q_entries; /* Num entries in receive queue */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint64_t link_state; /* Underlying HV channel state */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo ldc_dring_t *exp_dring_list; /* Exported desc ring list */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo kmutex_t exp_dlist_lock; /* Lock for exported desc ring list */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo ldc_dring_t *imp_dring_list; /* Imported desc ring list */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo kmutex_t imp_dlist_lock; /* Lock for imported desc ring list */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint32_t last_msg_snt; /* Seqid of last packet sent */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint32_t last_msg_rcd; /* Seqid of last packet received */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint32_t stream_remains; /* Number of bytes in stream */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* packet buffer */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint32_t stream_offset; /* Offset into packet buffer for */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* next read */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * LDC module soft state structure
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef struct ldc_soft_state {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo ldc_dring_t *dring_list; /* Descriptor rings (for export) */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#endif /* _LDC_IMPL_H */