vldc_impl.h revision 592b39e7880f85dc37f53ec4651955413b7c1d23
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/*
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * CDDL HEADER START
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo *
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 *
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * or http://www.opensolaris.org/os/licensing.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * See the License for the specific language governing permissions
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * and limitations under the License.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo *
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 *
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * CDDL HEADER END
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/*
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Use is subject to license terms.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#ifndef _VLDC_IMPL_H
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define _VLDC_IMPL_H
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#pragma ident "%Z%%M% %I% %E% SMI"
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#ifdef __cplusplus
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppoextern "C" {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#endif
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <sys/stream.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <sys/ddi.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <sys/sunddi.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <sys/ldc.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <sys/vldc.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* default values */
592b39e7880f85dc37f53ec4651955413b7c1d23jm#define VLDC_DEFAULT_MTU 0x1000 /* default mtu size 4K */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* VLDC limits */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VLDC_MAX_COOKIE 0x40000 /* max. size of xfer to/from HV */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VLDC_MAX_MTU 0x40000 /* 256K */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VLDC_MAX_PORTS 0x800
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VLDC_MAX_MINORS VLDC_MAX_PORTS
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VLDC_MINOR_MASK (VLDC_MAX_PORTS - 1)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VLDC_INST_SHIFT 11
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan#define VLDC_HVCTL_SVCNAME "hvctl"
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* get port number from minor number */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VLDCPORT(vldcp, minor) \
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo ((vldcp)->minor_tbl[(minor) & VLDC_MINOR_MASK].portno)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* get minor table entry from minor number */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VLDCMINOR(vldcp, minor) \
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo (&((vldcp)->minor_tbl[(minor) & VLDC_MINOR_MASK]))
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* get instance number from minor number */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VLDCINST(minor) ((minor) >> VLDC_INST_SHIFT)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* indicates an invalid port number */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#define VLDC_INVALID_PORTNO ((uint_t)-1)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/*
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Minor node number to port number mapping table.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo *
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * The lock field in the vldc_minor structure is used to serialize operations
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * on the port associated with the minor node. It also protects the minor node
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * in_use field which is used to track the number of active users of the minor
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * node. Driver ops will either hold the lock over the whole operation or
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * will increment (and then decrement) the in use count if they need to
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * release and re-acquire the lock, e.g. when copying data in from or out to
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * userland. When the MDEG framework calls into the driver via the callback to
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * remove a port, the driver must wait until the in use count for the minor
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * node associated with the port drops to zero, before it can remove the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * port.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef struct vldc_minor {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo kmutex_t lock; /* protects port/in_use count */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo kcondvar_t cv; /* for waiting on in use */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint_t in_use; /* in use counter */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint_t portno; /* port number */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo char sname[MAXPATHLEN]; /* service name */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo} vldc_minor_t;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef struct vldc_port {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint_t number; /* port number */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint32_t status; /* port status */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo vldc_minor_t *minorp; /* minor table entry pointer */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint32_t mtu; /* port mtu */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo caddr_t send_buf; /* send buffer */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo caddr_t recv_buf; /* receive buffer */
d10e4ef2fabf16c3237c6d6592496df3eac6a1efnarayan caddr_t cookie_buf; /* rd/wr cookie buffer */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint64_t ldc_id; /* Channel number */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo ldc_handle_t ldc_handle; /* Channel handle */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo ldc_mode_t ldc_mode; /* Channel mode */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo boolean_t is_stream; /* streaming mode */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo boolean_t hanged_up; /* port hanged up */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo struct pollhead poll; /* for poll */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo} vldc_port_t;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/*
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * vldc driver's soft state structure
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef struct vldc {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo kmutex_t lock; /* serializes detach and MDEG */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo boolean_t detaching; /* true iff busy detaching */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo dev_info_t *dip; /* dev_info */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo mdeg_node_spec_t *inst_spec; /* vldc instance specifier */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo mdeg_handle_t mdeg_hdl; /* MD event handle */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint_t num_ports;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo vldc_port_t port[VLDC_MAX_PORTS];
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* table for assigned minors */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo vldc_minor_t minor_tbl[VLDC_MAX_MINORS];
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* number of minors already assigned */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint_t minors_assigned;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo} vldc_t;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#ifdef __cplusplus
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo}
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#endif
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#endif /* _VLDC_IMPL_H */