glvc.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/machsystm.h>
#include <sys/hypervisor_api.h>
/*
* Global Variables - can be patched from Solaris
* ==============================================
*/
/* bit defination in virtual device register */
#define GLVC_REG_RECV 0x0001
#define GLVC_REG_RECV_ENA 0x0002
#define GLVC_REG_SEND 0x0004
#define GLVC_REG_SEND_ENA 0x0008
#define GLVC_REG_ERR 0x8000
/*
* For interrupt mode
*/
#define GLVC_MODE_NONE 0
#define GLVC_POLLING_MODE 1
#define GLVC_INTR_MODE 2
/*
* For open
*/
#define GLVC_NO_OPEN 0
#define GLVC_OPEN 1
#define GLVC_EXCL_OPEN 2
/*
* For timeout polling, in microsecond.
*/
/*
* For debug printing
*/
/*
* Driver entry points
*/
static struct cb_ops glvc_cb_ops = {
glvc_open, /* open */
glvc_close, /* close */
nodev, /* strategy() */
nodev, /* print() */
nodev, /* dump() */
glvc_read, /* read() */
glvc_write, /* write() */
glvc_ioctl, /* ioctl() */
nodev, /* devmap() */
nodev, /* mmap() */
ddi_segmap, /* segmap() */
nochpoll, /* poll() */
ddi_prop_op, /* prop_op() */
NULL, /* cb_str */
};
0, /* ref count */
ddi_getinfo_1to1, /* getinfo() */
nulldev, /* identify() */
nulldev, /* probe() */
glvc_attach, /* attach() */
glvc_detach, /* detach */
nodev, /* reset */
&glvc_cb_ops, /* pointer to cb_ops structure */
nulldev /* power() */
};
/*
* Loadable module support.
*/
extern struct mod_ops mod_driverops;
&mod_driverops, /* Type of module. This is a driver */
"Sun4v virtual channel driver", /* Name of the module */
&glvc_ops /* pointer to the dev_ops structure */
};
static struct modlinkage modlinkage = {
&modldrv,
};
typedef struct glvc_soft_state {
char *mb_recv_buf;
char *mb_send_buf;
/*
* Module Variables
* ================
*/
/*
* functions local to this driver.
*/
/*
* Driver globals
*/
static void *glvc_ssp; /* pointer to driver soft state */
static uint_t glvc_debug = 0;
int
_init(void)
{
int error = 0;
sizeof (glvc_soft_state_t), 1)) != 0)
return (error);
return (error);
}
int
{
}
int
_fini(void)
{
int error = 0;
if (error)
return (error);
return (0);
}
static int
{
int instance;
int err;
switch (cmd) {
case DDI_ATTACH:
!= DDI_SUCCESS)
return (DDI_FAILURE);
/* Set the dip in the soft state */
== -1) {
goto bad;
}
<= 0) {
goto bad;
}
goto bad;
}
goto bad;
}
if (err != DDI_SUCCESS) {
goto bad;
}
MUTEX_DRIVER, NULL);
MUTEX_DRIVER, NULL);
/*
* Add the handlers which watch for unsolicited messages
* and post event to Sysevent Framework.
*/
if (err != DDI_SUCCESS) {
goto bad1;
}
/*
* Trigger soft interrupt to start polling device if
* we are in the polling mode
*/
DPRINTF(("glvc instance %d, s_id %lu,"
return (DDI_SUCCESS);
case DDI_RESUME:
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
bad1:
bad:
return (DDI_FAILURE);
}
static int
{
int instance;
int err;
switch (cmd) {
case DDI_DETACH:
if (err != DDI_SUCCESS) {
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
case DDI_SUSPEND:
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
}
static int
{
int instance;
int err = DDI_SUCCESS;
if (err == DDI_SUCCESS) {
DPRINTF(("glvc instance %d polling_interval = %lu",
} else {
DPRINTF(("glvc, instance %d intr support not found, "
DPRINTF(("glvc instance %d polling_interval = %lu",
}
return (err);
}
static int
{
int instance;
softsp->polling_interval = 0;
return (DDI_SUCCESS);
}
static uint_t
{
/*
* Call the interrupt handle routine to check the register
* status.
*/
return (DDI_INTR_CLAIMED);
}
/*ARGSUSED*/
static int
{
int error = 0;
int instance;
switch (softsp->open_state) {
case GLVC_NO_OPEN:
else
break;
case GLVC_OPEN:
break;
case GLVC_EXCL_OPEN:
break;
default:
/* Should not happen */
softsp->open_state);
break;
}
return (error);
}
/*ARGSUSED*/
static int
{
int instance;
int error = 0;
"glvc_close: device already closed");
} else {
}
return (error);
}
/*ARGSUSED*/
static int
{
int instance;
/*
* If no data available, we wait till we get some.
* Notice we still holding the recv_mutex lock at this
* point.
*/
if (rv == 0) {
/*
* We got interrupted.
*/
return (EINTR);
}
if (rv == -1) {
/*
* Timeout wait, trigger a soft intr in case
* we miss an interrupt or in polling mode.
*/
}
}
/* Read data into kernel buffer */
DPRINTF(("Instance %d glvc_read returns error = %ld, recv_count = %lu",
DPRINTF(("Instance %d, glvc_read user buffer "
"size(%lu) smaller than number of bytes "
recv_count));
return (EINVAL);
}
/* move data from kernel to user space */
} else {
}
/* Clear the RECV data interrupt bit on device register */
}
return (error);
}
/*ARGSUSED*/
static int
{
int instance;
return (EINVAL);
} else {
DPRINTF(("instance %d glvc_write: request to send %lu bytes",
instance, send_count));
}
while (softsp->send_complete_flag == 0) {
if (rv == 0) {
/*
* We got interrupted.
*/
return (EINTR);
}
if (rv == -1) {
/*
* Timeout wait, trigger a soft intr in case
* we miss an interrupt or in polling mode.
*/
}
}
/* Clear the SEND_COMPLETE interrupt bit on device register */
!= H_EOK) {
"error = %ld", hverr);
}
/* move data from to user to kernel space */
if (error == 0) {
}
DPRINTF(("instance %d glvc_write write check error = %d,"
softsp->send_complete_flag = 0;
return (error);
}
/*
* Interrupt handler
*/
static uint_t
{
int error = DDI_INTR_UNCLAIMED;
DPRINTF(("glvc_intr: err = %ld, getstatus = 0x%lx",
hverr, status_reg));
return (DDI_INTR_UNCLAIMED);
if (status_reg & GLVC_REG_RECV) {
/*
* If recv_flag has already been set to 1, it means
* this is not a recv data interrupt, it is a
* send complete interrupt. If recv_flag is 0, then
* it is recv data interrupt. We claim the interrupt.
*/
}
}
if (error == DDI_INTR_CLAIMED)
return (error);
if (status_reg & GLVC_REG_SEND) {
if (softsp->send_complete_flag == 0) {
}
}
return (DDI_INTR_CLAIMED);
}
/*
* Peek to see if there is data received. If no data available,
* we sleep wait. If there is data, read from hypervisor and copy
* to ioctl buffer. We don't clear the receive data interrupt bit.
*/
static int
{
uint64_t recv_count = 0;
/*
* If no data available, we wait till we get some.
* Notice we still holding the recv_mutex lock at
* this point.
*/
if (rv == 0) {
/*
* We got interrupted.
*/
return (EINTR);
}
if (rv == -1) {
/*
* Timeout wait, trigger a soft intr in case
* we miss an interrupt or in polling mode.
*/
}
}
/* Read data into kernel buffer */
DPRINTF(("glvc_peek recv data, error = %ld, recv_count = %lu",
hverr, recv_count));
} else {
}
return (error);
}
static int
{
int retval = 0;
sizeof (glvc_xport_opt_op_t), mode) != 0) {
return (EFAULT);
}
switch (glvc_xport_cmd.opt_sel) {
case GLVC_XPORT_OPT_MTU_SZ:
mode);
} else
break;
mode);
} else {
}
} else {
}
break;
default:
break;
}
return (retval);
}
/*ARGSUSED*/
static int
int *rval_p)
{
int retval = 0;
switch (cmd) {
case GLVC_XPORT_IOCTL_OPT_OP:
break;
return (EBUSY);
if (retval == 0) {
switch (ddi_model_convert_from(mode)) {
case DDI_MODEL_ILP32:
sizeof (glvc_xport_msg_peek32_t),
mode) == -1) {
break;
}
if (msg_peek_cmd32.buflen32 == 0) {
break;
}
if (msg_peek_cmd32.buflen32 >
break;
}
sizeof (glvc_xport_msg_peek32_t), mode)
== -1)
break;
case DDI_MODEL_NONE:
if (msg_peek_cmd.buflen == 0) {
break;
}
break;
}
break;
default:
break;
}
}
break;
default:
break;
}
return (retval);
}
/*
* Map hypervisor error code to solaris. Only
* H_EOK, H_EINVA, H_EWOULDBLOCK and H_EIO are meaningful
* to this device. All other error codes are mapped to EIO.
*/
static int
{
int s_errcode;
switch (hv_errcode) {
case H_EOK:
s_errcode = 0;
break;
case H_EINVAL:
break;
case H_EWOULDBLOCK:
break;
case H_EIO:
break;
default:
/* should not happen */
DPRINTF(("Unexpected device error code %ld received, "
"mapped to EIO", hv_errcode));
break;
}
return (s_errcode);
}