qcn.c revision 54c6b703ab82ab151717d8ee0b810e16c73ef498
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (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 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* sun4v console driver
*/
#include <sys/sysmacros.h>
#include <sys/hypervisor_api.h>
#include <sys/machsystm.h>
/* dev_ops and cb_ops for device driver */
/* other internal qcn routines */
static void qcn_reioctl(void *);
static void qcn_start(void);
static void qcn_receive_read(void);
static void qcn_receive_getchr(void);
static void qcn_flush(void);
#ifdef QCN_POLLING
static void qcn_poll_handler(void *unused);
static cyc_time_t qcn_poll_time;
static cyc_handler_t qcn_poll_cychandler = {
NULL,
CY_LOW_LEVEL /* XXX need softint to make this high */
};
static uint64_t sb_interval = 0;
uint_t qcn_force_polling = 0;
#endif
#define QCN_MI_IDNUM 0xABCE
#define QCN_MI_HIWAT 8192
#define QCN_MI_LOWAT 128
/* streams structures */
static struct module_info minfo = {
QCN_MI_IDNUM, /* mi_idnum */
"qcn", /* mi_idname */
0, /* mi_minpsz */
INFPSZ, /* mi_maxpsz */
QCN_MI_HIWAT, /* mi_hiwat */
QCN_MI_LOWAT /* mi_lowat */
};
putq, /* qi_putp */
qcn_rsrv, /* qi_srvp */
qcn_open, /* qi_qopen */
qcn_close, /* qi_qclose */
NULL, /* qi_qadmin */
&minfo, /* qi_minfo */
NULL /* qi_mstat */
};
qcn_wput, /* qi_putp */
qcn_wsrv, /* qi_srvp */
qcn_open, /* qi_qopen */
qcn_close, /* qi_qclose */
NULL, /* qi_qadmin */
&minfo, /* qi_minfo */
NULL /* qi_mstat */
};
static struct streamtab qcnstrinfo = {
&rinit,
&winit,
NULL,
};
/* standard device driver structures */
static struct cb_ops qcn_cb_ops = {
nulldev, /* open() */
nulldev, /* close() */
nodev, /* strategy() */
nodev, /* print() */
nodev, /* dump() */
nodev, /* read() */
nodev, /* write() */
nodev, /* ioctl() */
nodev, /* devmap() */
nodev, /* mmap() */
nodev, /* segmap() */
nochpoll, /* poll() */
ddi_prop_op, /* prop_op() */
&qcnstrinfo, /* cb_str */
};
0, /* refcnt */
qcn_getinfo, /* getinfo() */
nulldev, /* identify() */
nulldev, /* probe() */
qcn_attach, /* attach() */
qcn_detach, /* detach() */
nodev, /* reset() */
&qcn_cb_ops, /* cb_ops */
NULL /* power() */
};
"sun4v console driver v%I%",
};
static struct modlinkage modlinkage = {
(void*)&modldrv,
};
/* driver configuration routines */
int
_init(void)
{
int error;
if (error != 0) {
return (error);
}
/*
* check minor number to see if CONS_WRITE is supported
* if so, set up real address of the buffers for hv calls.
*/
}
}
}
return (0);
}
int
_fini(void)
{
/* can't remove console driver */
return (EBUSY);
}
int
{
}
static int
qcn_add_intrs(void)
{
/* get number of interrupts */
return (DDI_FAILURE);
}
/* Allocate an array of interrupt handles */
/* call ddi_intr_alloc() */
return (DDI_FAILURE);
}
for (x = 0; x < actual; x++) {
}
return (DDI_FAILURE);
}
/* Get intr priority */
for (x = 0; x < actual; x++) {
}
return (DDI_FAILURE);
}
/* Call ddi_intr_add_handler() */
for (x = 0; x < actual; x++) {
for (y = 0; y < x; y++) {
(void) ddi_intr_remove_handler(
qcn_state->qcn_htable[y]);
}
for (y = 0; y < actual; y++) {
}
return (DDI_FAILURE);
}
}
return (DDI_SUCCESS);
}
static void
qcn_remove_intrs(void)
{
int x;
for (x = 0; x < qcn_state->qcn_intr_cnt; x++) {
}
}
static void
qcn_intr_enable(void)
{
int x;
for (x = 0; x < qcn_state->qcn_intr_cnt; x++) {
}
}
/*
* qcn_attach is called at startup time.
* There is only once instance of this driver.
*/
static int
{
extern int ddi_create_internal_pathname(dev_info_t *, char *,
int, minor_t);
#ifdef QCN_POLLING
char *binding_name;
#endif
if (cmd != DDI_ATTACH)
return (DDI_FAILURE);
S_IFCHR, 0) != DDI_SUCCESS)
return (DDI_FAILURE);
qcn_state->qcn_soft_pend = 0;
qcn_state->qcn_hangup = 0;
qcn_state->qcn_rbuf_overflow = 0;
/* prepare some data structures in soft state */
qcn_state->qcn_polling = 0;
#ifdef QCN_POLLING
/*
* This test is for the sole purposes of allowing
* the console to work on older firmware releases.
*/
if (qcn_state->qcn_polling) {
}
#endif
if (!qcn_state->qcn_polling) {
if (qcn_add_intrs() != DDI_SUCCESS) {
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
&soft_prip) != DDI_SUCCESS) {
(void) ddi_intr_remove_softint(
return (DDI_FAILURE);
}
}
/*
* Enable interrupts
*/
if (!qcn_state->qcn_polling) {
}
#ifdef QCN_DEBUG
prom_printf("qcn_attach(): qcn driver attached\n");
#endif
return (DDI_SUCCESS);
}
/* ARGSUSED */
static int
{
if (cmd != DDI_DETACH)
return (DDI_FAILURE);
#ifdef QCN_DEBUG
prom_printf("qcn_detach(): QCN driver detached\n");
#endif
#ifdef QCN_POLLING
if (qcn_state->qcn_polling) {
if (qcn_poll_cycid != CYCLIC_NONE)
}
#endif
if (!qcn_state->qcn_polling)
return (DDI_SUCCESS);
}
/* ARGSUSED */
static int
{
int error = DDI_FAILURE;
int instance = 0;
switch (infocmd) {
case DDI_INFO_DEVT2DEVINFO:
if (qcn_state) {
#ifdef QCN_DEBUG
#endif
error = DDI_SUCCESS;
}
break;
case DDI_INFO_DEVT2INSTANCE:
#ifdef QCN_DEBUG
#endif
error = DDI_SUCCESS;
}
break;
}
return (error);
}
/* streams open & close */
/* ARGSUSED */
static int
{
#ifdef QCN_DEBUG
#endif
if (unit != 0)
return (ENXIO);
/* stream already open */
return (DDI_SUCCESS);
if (!qcn_state) {
"autoconfig\n");
return (ENXIO);
}
/* Link the RD and WR Q's */
qprocson(q);
#ifdef QCN_DEBUG
#endif
return (DDI_SUCCESS);
}
/* ARGSUSED */
static int
{
if (qcn_state->qcn_wbufcid != 0) {
}
qprocsoff(q);
return (DDI_SUCCESS);
}
/*
* Put procedure for write queue.
* Respond to M_IOCTL, M_DATA and M_FLUSH messages here;
* It put's the data onto internal qcn_output_q.
*/
static int
{
#ifdef QCN_DEBUG
int i;
#endif
}
#ifdef QCN_DEBUG
prom_printf("qcn_wput(): QCN wput q=%X mp=%X rd=%X wr=%X type=%X\n",
#endif
case M_IOCTL:
case M_CTL:
#ifdef QCN_DEBUG
prom_printf("qcn_wput(): M_IOCTL cmd=%X TIOC=%X\n",
#endif
case TCSETSW:
case TCSETSF:
case TCSETAW:
case TCSETAF:
case TCSBRK:
/*
* The change do not take effect until all
* output queued before them is drained.
* Put this message on the queue, so that
* "qcn_start" will see it when it's done
* with the output before it. Poke the start
* routine, just in case.
*/
qcn_start();
break;
default:
}
break;
case M_FLUSH:
}
} else {
}
break;
case M_STOP:
break;
case M_START:
qenable(q); /* Start up delayed messages */
break;
case M_DATA:
/*
* Queue the message up to be transmitted,
* and poke the start routine.
*/
#ifdef QCN_DEBUG
prom_printf("qcn_wput(): DATA q=%X mp=%X rd=%X wr=%X\n",
prom_printf("qcn_wput(): [");
}
prom_printf("]\n");
}
#endif /* QCN_DEBUG */
qcn_start();
break;
default:
}
return (0);
}
/*
* Process an "ioctl" message sent down to us.
*/
static void
{
int data_size;
int error = 0;
#ifdef QCN_DEBUG
#endif
}
if (data_size != 0) {
if (qcn_state->qcn_wbufcid)
/* call qcn_reioctl() */
return;
}
if (error < 0) {
/*
* "ttycommon_ioctl" didn't do anything; we process it here.
*/
error = 0;
case TCSBRK:
case TIOCSBRK:
case TIOCCBRK:
case TIOCMSET:
case TIOCMBIS:
case TIOCMBIC:
else
break;
case TIOCMGET:
break;
}
else
break;
default:
break;
}
}
if (error != 0) {
}
}
static void
qcn_reioctl(void *unit)
{
queue_t *q;
if (!qcnp->qcn_wbufcid)
return;
qcnp->qcn_wbufcid = 0;
return;
return;
}
static void
{
} else
}
static void
qcn_start(void)
{
queue_t *q;
int rv;
/*
* read stream queue and remove data from the queue and
* transmit them if possible
*/
q = qcn_state->qcn_writeq;
/*
* These are those IOCTLs queued up
* do it now
*/
continue;
}
/*
* M_DATA
*/
return;
}
}
static int
{
uint64_t i;
#ifdef QCN_DEBUG
#endif
while (mp) {
/*
* Use the console write call to send a block of characters to
* the console.
*/
len -= i;
/*
* if we have finished with this buf, free
* and get the next buf if present.
*/
if (len == 0) {
}
} else {
switch (retval) {
case H_EWOULDBLOCK :
/*
* hypervisor cannot process the request -
* channel busy. Try again later.
*/
return (EAGAIN);
case H_EIO :
return (EIO);
default :
return (ENXIO);
}
}
}
return (0);
}
static int
{
uint64_t i;
#ifdef QCN_DEBUG
#endif
while (mp) {
for (i = 0; i < len; i++) {
break;
}
if (i != len) {
return (EAGAIN);
}
}
return (0);
}
/*
* called when SC first establishes console connection
* drop all the data on the output queue
*/
static void
qcn_flush(void)
{
queue_t *q;
q = qcn_state->qcn_writeq;
prom_printf("qcn_flush(): WARNING console output is dropped time=%lx\n",
gethrestime_sec());
}
static void
qcn_trigger_softint(void)
{
/*
* if we are not currently servicing a software interrupt
* (qcn_soft_pend == 0), trigger the service routine to run.
*/
QCN_SP_IDL) {
(void) ddi_intr_trigger_softint(
}
}
/*ARGSUSED*/
static uint_t
{
int cc;
int overflow_check;
do {
goto out;
}
qcn_input_dropped += cc;
"failed (console input dropped)");
goto out;
}
do {
/* put console input onto stream */
} while (--cc);
qcn_state->qcn_rbuf_overflow = 0;
}
if (overflow_check) {
}
}
out:
/*
* If there are pending transmits because hypervisor
* returned EWOULDBLOCK poke start now.
*/
if (qcn_state->qcn_hangup) {
qcn_state->qcn_hangup = 0;
} else {
qcn_start();
}
}
/*
* now loop if another interrupt came in (qcn_trigger_softint
* called) while we were processing the loop
*/
return (DDI_INTR_CLAIMED);
}
/*ARGSUSED*/
static uint_t
{
return (DDI_INTR_CLAIMED);
}
static void
qcn_receive_read(void)
{
int i;
do {
/*
* Maximize available buffer size
*/
}
&retcount);
/*
* if the alternate break sequence is enabled, test
* the buffer for the sequence and if it is there,
* enter the debugger.
*/
if (abort_enable == KIOCABORTALTERNATE) {
for (i = 0; i < retcount; i++) {
if (abort_charseq_recognize(*bufp++)) {
(char *)NULL);
}
}
}
/* put console input onto stream */
if (retcount > 0) {
/*
* the characters are already in the ring,
* just update the pointer so the characters
* can be retrieved.
*/
}
} else {
switch (rv) {
case H_EWOULDBLOCK :
/*
* hypervisor cannot handle the request.
* Try again later.
*/
break;
case H_BREAK :
/*
* on break, unless alternate break sequence is
* enabled, enter the debugger
*/
if (abort_enable != KIOCABORTALTERNATE)
abort_sequence_enter((char *)NULL);
break;
case H_HUP :
break;
default :
break;
}
}
}
static void
qcn_receive_getchr(void)
{
do {
if (abort_enable == KIOCABORTALTERNATE) {
if (abort_charseq_recognize(buf)) {
abort_sequence_enter((char *)NULL);
}
}
/* put console input onto stream */
} else {
}
} else {
if (abort_enable != KIOCABORTALTERNATE)
abort_sequence_enter((char *)NULL);
}
}
return;
}
}
#ifdef QCN_POLLING
/*ARGSUSED*/
static void
qcn_poll_handler(void *unused)
{
int qcn_writeq_flush = 0;
/* LINTED: E_CONSTANT_CONDITION */
while (1) {
if (abort_enable != KIOCABORTALTERNATE)
abort_sequence_enter((char *)NULL);
}
qcn_writeq_flush = 1;
}
goto out;
}
goto out;
if (abort_enable == KIOCABORTALTERNATE) {
if (abort_charseq_recognize(buf)) {
abort_sequence_enter((char *)NULL);
}
}
/* put console input onto stream */
"failed (console input dropped)");
return;
}
}
}
out:
/*
* If there are pending transmits because hypervisor
* returned EWOULDBLOCK poke start now.
*/
if (qcn_writeq_flush) {
} else {
qcn_start();
}
}
}
#endif
/*
* Check for abort character sequence, copied from zs_async.c
*/
#define CNTRL(c) ((c)&037)
static boolean_t
{
static int state = 0;
state = 0;
return (B_TRUE);
}
} else {
}
return (B_FALSE);
}
static int
{
if (qcn_stopped == B_TRUE)
return (0);
if (canputnext(q))
}
return (0);
}
/* ARGSUSED */
static int
{
if (qcn_stopped == B_TRUE)
return (0);
qcn_start();
return (0);
}