17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*1ae08745Sheppo * Common Development and Distribution License (the "License"). 6*1ae08745Sheppo * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21*1ae08745Sheppo 227c478bd9Sstevel@tonic-gate /* 23*1ae08745Sheppo * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * sun4v console driver 317c478bd9Sstevel@tonic-gate */ 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <sys/errno.h> 347c478bd9Sstevel@tonic-gate #include <sys/stat.h> 357c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 367c478bd9Sstevel@tonic-gate #include <sys/conf.h> 377c478bd9Sstevel@tonic-gate #include <sys/termios.h> 387c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 397c478bd9Sstevel@tonic-gate #include <sys/kbio.h> 407c478bd9Sstevel@tonic-gate #include <sys/stropts.h> 417c478bd9Sstevel@tonic-gate #include <sys/stream.h> 427c478bd9Sstevel@tonic-gate #include <sys/strsun.h> 437c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 447c478bd9Sstevel@tonic-gate #include <sys/promif.h> 457c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 467c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 477c478bd9Sstevel@tonic-gate #include <sys/cyclic.h> 487c478bd9Sstevel@tonic-gate #include <sys/intr.h> 497c478bd9Sstevel@tonic-gate #include <sys/spl.h> 507c478bd9Sstevel@tonic-gate #include <sys/qcn.h> 517c478bd9Sstevel@tonic-gate #include <sys/hypervisor_api.h> 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate /* dev_ops and cb_ops for device driver */ 547c478bd9Sstevel@tonic-gate static int qcn_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **); 557c478bd9Sstevel@tonic-gate static int qcn_attach(dev_info_t *, ddi_attach_cmd_t); 567c478bd9Sstevel@tonic-gate static int qcn_detach(dev_info_t *, ddi_detach_cmd_t); 577c478bd9Sstevel@tonic-gate static int qcn_open(queue_t *, dev_t *, int, int, cred_t *); 587c478bd9Sstevel@tonic-gate static int qcn_close(queue_t *, int, cred_t *); 597c478bd9Sstevel@tonic-gate static int qcn_wput(queue_t *, mblk_t *); 607c478bd9Sstevel@tonic-gate static int qcn_wsrv(queue_t *); 617c478bd9Sstevel@tonic-gate static int qcn_rsrv(queue_t *); 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* other internal qcn routines */ 647c478bd9Sstevel@tonic-gate static void qcn_ioctl(queue_t *, mblk_t *); 657c478bd9Sstevel@tonic-gate static void qcn_reioctl(void *); 667c478bd9Sstevel@tonic-gate static void qcn_ack(mblk_t *, mblk_t *, uint_t); 677c478bd9Sstevel@tonic-gate static void qcn_start(void); 687c478bd9Sstevel@tonic-gate static int qcn_transmit(queue_t *, mblk_t *); 697c478bd9Sstevel@tonic-gate static void qcn_flush(void); 707c478bd9Sstevel@tonic-gate static uint_t qcn_hi_intr(caddr_t arg); 717c478bd9Sstevel@tonic-gate static uint_t qcn_soft_intr(caddr_t arg1, caddr_t arg2); 727c478bd9Sstevel@tonic-gate 737c478bd9Sstevel@tonic-gate static boolean_t abort_charseq_recognize(uchar_t); 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate static qcn_t *qcn_state; 767c478bd9Sstevel@tonic-gate static uchar_t qcn_stopped = B_FALSE; 777c478bd9Sstevel@tonic-gate static int qcn_timeout_period = 20; /* time out in seconds */ 787c478bd9Sstevel@tonic-gate size_t qcn_input_dropped; /* dropped input character counter */ 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate #ifdef QCN_POLLING 817c478bd9Sstevel@tonic-gate static void qcn_poll_handler(void *unused); 827c478bd9Sstevel@tonic-gate static cyc_time_t qcn_poll_time; 837c478bd9Sstevel@tonic-gate static cyc_handler_t qcn_poll_cychandler = { 847c478bd9Sstevel@tonic-gate qcn_poll_handler, 857c478bd9Sstevel@tonic-gate NULL, 867c478bd9Sstevel@tonic-gate CY_LOW_LEVEL /* XXX need softint to make this high */ 877c478bd9Sstevel@tonic-gate }; 887c478bd9Sstevel@tonic-gate static cyclic_id_t qcn_poll_cycid = CYCLIC_NONE; 897c478bd9Sstevel@tonic-gate static uint64_t qcn_poll_interval = 5; /* milli sec */ 907c478bd9Sstevel@tonic-gate static uint64_t sb_interval = 0; 91*1ae08745Sheppo uint_t qcn_force_polling = 0; 927c478bd9Sstevel@tonic-gate #endif 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate #define QCN_MI_IDNUM 0xABCE 957c478bd9Sstevel@tonic-gate #define QCN_MI_HIWAT 8192 967c478bd9Sstevel@tonic-gate #define QCN_MI_LOWAT 128 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate /* streams structures */ 997c478bd9Sstevel@tonic-gate static struct module_info minfo = { 1007c478bd9Sstevel@tonic-gate QCN_MI_IDNUM, /* mi_idnum */ 1017c478bd9Sstevel@tonic-gate "qcn", /* mi_idname */ 1027c478bd9Sstevel@tonic-gate 0, /* mi_minpsz */ 1037c478bd9Sstevel@tonic-gate INFPSZ, /* mi_maxpsz */ 1047c478bd9Sstevel@tonic-gate QCN_MI_HIWAT, /* mi_hiwat */ 1057c478bd9Sstevel@tonic-gate QCN_MI_LOWAT /* mi_lowat */ 1067c478bd9Sstevel@tonic-gate }; 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate static struct qinit rinit = { 1097c478bd9Sstevel@tonic-gate putq, /* qi_putp */ 1107c478bd9Sstevel@tonic-gate qcn_rsrv, /* qi_srvp */ 1117c478bd9Sstevel@tonic-gate qcn_open, /* qi_qopen */ 1127c478bd9Sstevel@tonic-gate qcn_close, /* qi_qclose */ 1137c478bd9Sstevel@tonic-gate NULL, /* qi_qadmin */ 1147c478bd9Sstevel@tonic-gate &minfo, /* qi_minfo */ 1157c478bd9Sstevel@tonic-gate NULL /* qi_mstat */ 1167c478bd9Sstevel@tonic-gate }; 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate static struct qinit winit = { 1197c478bd9Sstevel@tonic-gate qcn_wput, /* qi_putp */ 1207c478bd9Sstevel@tonic-gate qcn_wsrv, /* qi_srvp */ 1217c478bd9Sstevel@tonic-gate qcn_open, /* qi_qopen */ 1227c478bd9Sstevel@tonic-gate qcn_close, /* qi_qclose */ 1237c478bd9Sstevel@tonic-gate NULL, /* qi_qadmin */ 1247c478bd9Sstevel@tonic-gate &minfo, /* qi_minfo */ 1257c478bd9Sstevel@tonic-gate NULL /* qi_mstat */ 1267c478bd9Sstevel@tonic-gate }; 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate static struct streamtab qcnstrinfo = { 1297c478bd9Sstevel@tonic-gate &rinit, 1307c478bd9Sstevel@tonic-gate &winit, 1317c478bd9Sstevel@tonic-gate NULL, 1327c478bd9Sstevel@tonic-gate NULL 1337c478bd9Sstevel@tonic-gate }; 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate /* standard device driver structures */ 1367c478bd9Sstevel@tonic-gate static struct cb_ops qcn_cb_ops = { 1377c478bd9Sstevel@tonic-gate nulldev, /* open() */ 1387c478bd9Sstevel@tonic-gate nulldev, /* close() */ 1397c478bd9Sstevel@tonic-gate nodev, /* strategy() */ 1407c478bd9Sstevel@tonic-gate nodev, /* print() */ 1417c478bd9Sstevel@tonic-gate nodev, /* dump() */ 1427c478bd9Sstevel@tonic-gate nodev, /* read() */ 1437c478bd9Sstevel@tonic-gate nodev, /* write() */ 1447c478bd9Sstevel@tonic-gate nodev, /* ioctl() */ 1457c478bd9Sstevel@tonic-gate nodev, /* devmap() */ 1467c478bd9Sstevel@tonic-gate nodev, /* mmap() */ 1477c478bd9Sstevel@tonic-gate nodev, /* segmap() */ 1487c478bd9Sstevel@tonic-gate nochpoll, /* poll() */ 1497c478bd9Sstevel@tonic-gate ddi_prop_op, /* prop_op() */ 1507c478bd9Sstevel@tonic-gate &qcnstrinfo, /* cb_str */ 1517c478bd9Sstevel@tonic-gate D_NEW | D_MP /* cb_flag */ 1527c478bd9Sstevel@tonic-gate }; 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate static struct dev_ops qcn_ops = { 1557c478bd9Sstevel@tonic-gate DEVO_REV, 1567c478bd9Sstevel@tonic-gate 0, /* refcnt */ 1577c478bd9Sstevel@tonic-gate qcn_getinfo, /* getinfo() */ 1587c478bd9Sstevel@tonic-gate nulldev, /* identify() */ 1597c478bd9Sstevel@tonic-gate nulldev, /* probe() */ 1607c478bd9Sstevel@tonic-gate qcn_attach, /* attach() */ 1617c478bd9Sstevel@tonic-gate qcn_detach, /* detach() */ 1627c478bd9Sstevel@tonic-gate nodev, /* reset() */ 1637c478bd9Sstevel@tonic-gate &qcn_cb_ops, /* cb_ops */ 1647c478bd9Sstevel@tonic-gate (struct bus_ops *)NULL, /* bus_ops */ 1657c478bd9Sstevel@tonic-gate NULL /* power() */ 1667c478bd9Sstevel@tonic-gate }; 1677c478bd9Sstevel@tonic-gate 1687c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 1697c478bd9Sstevel@tonic-gate &mod_driverops, 1707c478bd9Sstevel@tonic-gate "sun4v console driver v%I%", 1717c478bd9Sstevel@tonic-gate &qcn_ops 1727c478bd9Sstevel@tonic-gate }; 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 1757c478bd9Sstevel@tonic-gate MODREV_1, 1767c478bd9Sstevel@tonic-gate (void*)&modldrv, 1777c478bd9Sstevel@tonic-gate NULL 1787c478bd9Sstevel@tonic-gate }; 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate /* driver configuration routines */ 1827c478bd9Sstevel@tonic-gate int 1837c478bd9Sstevel@tonic-gate _init(void) 1847c478bd9Sstevel@tonic-gate { 1857c478bd9Sstevel@tonic-gate int error; 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate qcn_state = kmem_zalloc(sizeof (qcn_t), KM_SLEEP); 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate error = mod_install(&modlinkage); 1907c478bd9Sstevel@tonic-gate if (error != 0) 1917c478bd9Sstevel@tonic-gate kmem_free(qcn_state, sizeof (qcn_t)); 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate return (error); 1947c478bd9Sstevel@tonic-gate } 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate int 1977c478bd9Sstevel@tonic-gate _fini(void) 1987c478bd9Sstevel@tonic-gate { 1997c478bd9Sstevel@tonic-gate /* can't remove console driver */ 2007c478bd9Sstevel@tonic-gate return (EBUSY); 2017c478bd9Sstevel@tonic-gate } 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate int 2047c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 2057c478bd9Sstevel@tonic-gate { 2067c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 2077c478bd9Sstevel@tonic-gate } 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate static int 2107c478bd9Sstevel@tonic-gate qcn_add_intrs(void) 2117c478bd9Sstevel@tonic-gate { 2127c478bd9Sstevel@tonic-gate dev_info_t *devinfo = qcn_state->qcn_dip; 2137c478bd9Sstevel@tonic-gate int actual, count = 0; 2147c478bd9Sstevel@tonic-gate int x, y, rc, inum = 0; 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate /* get number of interrupts */ 2187c478bd9Sstevel@tonic-gate rc = ddi_intr_get_nintrs(devinfo, DDI_INTR_TYPE_FIXED, &count); 2197c478bd9Sstevel@tonic-gate if ((rc != DDI_SUCCESS) || (count == 0)) { 2207c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2217c478bd9Sstevel@tonic-gate } 2227c478bd9Sstevel@tonic-gate 2237c478bd9Sstevel@tonic-gate /* Allocate an array of interrupt handles */ 2247c478bd9Sstevel@tonic-gate qcn_state->qcn_intr_size = count * sizeof (ddi_intr_handle_t); 2257c478bd9Sstevel@tonic-gate qcn_state->qcn_htable = kmem_zalloc(qcn_state->qcn_intr_size, KM_SLEEP); 2267c478bd9Sstevel@tonic-gate 2277c478bd9Sstevel@tonic-gate /* call ddi_intr_alloc() */ 2287c478bd9Sstevel@tonic-gate rc = ddi_intr_alloc(devinfo, qcn_state->qcn_htable, 2297c478bd9Sstevel@tonic-gate DDI_INTR_TYPE_FIXED, inum, count, &actual, 2307c478bd9Sstevel@tonic-gate DDI_INTR_ALLOC_STRICT); 2317c478bd9Sstevel@tonic-gate 2327c478bd9Sstevel@tonic-gate if ((rc != DDI_SUCCESS) || (actual == 0)) { 2337c478bd9Sstevel@tonic-gate kmem_free(qcn_state->qcn_htable, qcn_state->qcn_intr_size); 2347c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate if (actual < count) { 2387c478bd9Sstevel@tonic-gate for (x = 0; x < actual; x++) { 2397c478bd9Sstevel@tonic-gate (void) ddi_intr_free(qcn_state->qcn_htable[x]); 2407c478bd9Sstevel@tonic-gate } 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate kmem_free(qcn_state->qcn_htable, qcn_state->qcn_intr_size); 2437c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2447c478bd9Sstevel@tonic-gate } 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate qcn_state->qcn_intr_cnt = actual; 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate /* Get intr priority */ 2497c478bd9Sstevel@tonic-gate if (ddi_intr_get_pri(qcn_state->qcn_htable[0], 2507c478bd9Sstevel@tonic-gate &qcn_state->qcn_intr_pri) != DDI_SUCCESS) { 2517c478bd9Sstevel@tonic-gate for (x = 0; x < actual; x++) { 2527c478bd9Sstevel@tonic-gate (void) ddi_intr_free(qcn_state->qcn_htable[x]); 2537c478bd9Sstevel@tonic-gate } 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate kmem_free(qcn_state->qcn_htable, qcn_state->qcn_intr_size); 2567c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2577c478bd9Sstevel@tonic-gate } 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate /* Call ddi_intr_add_handler() */ 2607c478bd9Sstevel@tonic-gate for (x = 0; x < actual; x++) { 2617c478bd9Sstevel@tonic-gate if (ddi_intr_add_handler(qcn_state->qcn_htable[x], 2627c478bd9Sstevel@tonic-gate (ddi_intr_handler_t *)qcn_hi_intr, 2637c478bd9Sstevel@tonic-gate (caddr_t)qcn_state, NULL) != DDI_SUCCESS) { 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate for (y = 0; y < x; y++) { 2667c478bd9Sstevel@tonic-gate (void) ddi_intr_remove_handler( 2677c478bd9Sstevel@tonic-gate qcn_state->qcn_htable[y]); 2687c478bd9Sstevel@tonic-gate } 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate for (y = 0; y < actual; y++) { 2717c478bd9Sstevel@tonic-gate (void) ddi_intr_free(qcn_state->qcn_htable[y]); 2727c478bd9Sstevel@tonic-gate } 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate kmem_free(qcn_state->qcn_htable, 2757c478bd9Sstevel@tonic-gate qcn_state->qcn_intr_size); 2767c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2777c478bd9Sstevel@tonic-gate } 2787c478bd9Sstevel@tonic-gate } 2797c478bd9Sstevel@tonic-gate 2807c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2817c478bd9Sstevel@tonic-gate } 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate static void 2847c478bd9Sstevel@tonic-gate qcn_remove_intrs(void) 2857c478bd9Sstevel@tonic-gate { 2867c478bd9Sstevel@tonic-gate int x; 2877c478bd9Sstevel@tonic-gate for (x = 0; x < qcn_state->qcn_intr_cnt; x++) { 2887c478bd9Sstevel@tonic-gate (void) ddi_intr_disable(qcn_state->qcn_htable[x]); 2897c478bd9Sstevel@tonic-gate (void) ddi_intr_remove_handler(qcn_state->qcn_htable[x]); 2907c478bd9Sstevel@tonic-gate (void) ddi_intr_free(qcn_state->qcn_htable[x]); 2917c478bd9Sstevel@tonic-gate } 292ea841a36Sarao kmem_free(qcn_state->qcn_htable, qcn_state->qcn_intr_size); 2937c478bd9Sstevel@tonic-gate } 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate static void 2967c478bd9Sstevel@tonic-gate qcn_intr_enable(void) 2977c478bd9Sstevel@tonic-gate { 2987c478bd9Sstevel@tonic-gate int x; 2997c478bd9Sstevel@tonic-gate 3007c478bd9Sstevel@tonic-gate for (x = 0; x < qcn_state->qcn_intr_cnt; x++) { 3017c478bd9Sstevel@tonic-gate (void) ddi_intr_enable(qcn_state->qcn_htable[x]); 3027c478bd9Sstevel@tonic-gate } 3037c478bd9Sstevel@tonic-gate } 3047c478bd9Sstevel@tonic-gate 3057c478bd9Sstevel@tonic-gate /* 3067c478bd9Sstevel@tonic-gate * qcn_attach is called at startup time. 3077c478bd9Sstevel@tonic-gate * There is only once instance of this driver. 3087c478bd9Sstevel@tonic-gate */ 3097c478bd9Sstevel@tonic-gate static int 3107c478bd9Sstevel@tonic-gate qcn_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 3117c478bd9Sstevel@tonic-gate { 3127c478bd9Sstevel@tonic-gate extern int ddi_create_internal_pathname(dev_info_t *, char *, 3137c478bd9Sstevel@tonic-gate int, minor_t); 3147c478bd9Sstevel@tonic-gate uint_t soft_prip; 3157c478bd9Sstevel@tonic-gate 3167c478bd9Sstevel@tonic-gate #ifdef QCN_POLLING 3177c478bd9Sstevel@tonic-gate char *binding_name; 3187c478bd9Sstevel@tonic-gate #endif 3197c478bd9Sstevel@tonic-gate if (cmd != DDI_ATTACH) 3207c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate if (ddi_create_internal_pathname(dip, "qcn", 3237c478bd9Sstevel@tonic-gate S_IFCHR, 0) != DDI_SUCCESS) 3247c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 3257c478bd9Sstevel@tonic-gate 3267c478bd9Sstevel@tonic-gate qcn_state->qcn_soft_pend = 0; 3277c478bd9Sstevel@tonic-gate qcn_state->qcn_hangup = 0; 3287c478bd9Sstevel@tonic-gate qcn_state->qcn_rbuf_overflow = 0; 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate /* prepare some data structures in soft state */ 3317c478bd9Sstevel@tonic-gate 3327c478bd9Sstevel@tonic-gate qcn_state->qcn_dip = dip; 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate qcn_state->qcn_polling = 0; 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate #ifdef QCN_POLLING 3377c478bd9Sstevel@tonic-gate /* 3387c478bd9Sstevel@tonic-gate * This test is for the sole purposes of allowing 3397c478bd9Sstevel@tonic-gate * the console to work on older firmware releases. 3407c478bd9Sstevel@tonic-gate */ 3417c478bd9Sstevel@tonic-gate binding_name = ddi_binding_name(qcn_state->qcn_dip); 342*1ae08745Sheppo if ((strcmp(binding_name, "qcn") == 0) || 343*1ae08745Sheppo (qcn_force_polling)) 3447c478bd9Sstevel@tonic-gate qcn_state->qcn_polling = 1; 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate if (qcn_state->qcn_polling) { 3477c478bd9Sstevel@tonic-gate qcn_poll_time.cyt_when = 0ull; 3487c478bd9Sstevel@tonic-gate qcn_poll_time.cyt_interval = 3497c478bd9Sstevel@tonic-gate qcn_poll_interval * 1000ull * 1000ull; 3507c478bd9Sstevel@tonic-gate mutex_enter(&cpu_lock); 3517c478bd9Sstevel@tonic-gate qcn_poll_cycid = cyclic_add(&qcn_poll_cychandler, 3527c478bd9Sstevel@tonic-gate &qcn_poll_time); 3537c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock); 3547c478bd9Sstevel@tonic-gate } 3557c478bd9Sstevel@tonic-gate #endif 3567c478bd9Sstevel@tonic-gate 3577c478bd9Sstevel@tonic-gate if (!qcn_state->qcn_polling) { 3587c478bd9Sstevel@tonic-gate if (qcn_add_intrs() != DDI_SUCCESS) { 3597c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "qcn_attach: add_intr failed\n"); 3607c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 3617c478bd9Sstevel@tonic-gate } 3627c478bd9Sstevel@tonic-gate if (ddi_intr_add_softint(dip, &qcn_state->qcn_softint_hdl, 3637c478bd9Sstevel@tonic-gate DDI_INTR_SOFTPRI_MAX, qcn_soft_intr, 3647c478bd9Sstevel@tonic-gate (caddr_t)qcn_state) != DDI_SUCCESS) { 3657c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "qcn_attach: add_soft_intr failed\n"); 3667c478bd9Sstevel@tonic-gate qcn_remove_intrs(); 3677c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate if (ddi_intr_get_softint_pri(qcn_state->qcn_softint_hdl, 3707c478bd9Sstevel@tonic-gate &soft_prip) != DDI_SUCCESS) { 3717c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "qcn_attach: softint_pri failed\n"); 372ea841a36Sarao (void) ddi_intr_remove_softint( 373ea841a36Sarao qcn_state->qcn_softint_hdl); 3747c478bd9Sstevel@tonic-gate qcn_remove_intrs(); 3757c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 3767c478bd9Sstevel@tonic-gate } 3777c478bd9Sstevel@tonic-gate qcn_state->qcn_soft_pri = 3787c478bd9Sstevel@tonic-gate (ddi_iblock_cookie_t)(uint64_t)soft_prip; 3797c478bd9Sstevel@tonic-gate 3807c478bd9Sstevel@tonic-gate mutex_init(&qcn_state->qcn_hi_lock, NULL, MUTEX_DRIVER, 3810bd5614cSiskreen (void *)(uintptr_t)(qcn_state->qcn_intr_pri)); 3827c478bd9Sstevel@tonic-gate mutex_init(&qcn_state->qcn_softlock, NULL, MUTEX_DRIVER, 3837c478bd9Sstevel@tonic-gate (void *)(qcn_state->qcn_soft_pri)); 3847c478bd9Sstevel@tonic-gate } 3857c478bd9Sstevel@tonic-gate 3867c478bd9Sstevel@tonic-gate mutex_init(&qcn_state->qcn_lock, NULL, MUTEX_DRIVER, NULL); 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate /* 3897c478bd9Sstevel@tonic-gate * Enable interrupts 3907c478bd9Sstevel@tonic-gate */ 3917c478bd9Sstevel@tonic-gate if (!qcn_state->qcn_polling) { 3927c478bd9Sstevel@tonic-gate qcn_intr_enable(); 3937c478bd9Sstevel@tonic-gate } 3947c478bd9Sstevel@tonic-gate #ifdef QCN_DEBUG 3957c478bd9Sstevel@tonic-gate prom_printf("qcn_attach(): qcn driver attached\n"); 3967c478bd9Sstevel@tonic-gate #endif 3977c478bd9Sstevel@tonic-gate 3987c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 3997c478bd9Sstevel@tonic-gate 4007c478bd9Sstevel@tonic-gate } 4017c478bd9Sstevel@tonic-gate 4027c478bd9Sstevel@tonic-gate /* ARGSUSED */ 4037c478bd9Sstevel@tonic-gate static int 4047c478bd9Sstevel@tonic-gate qcn_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 4057c478bd9Sstevel@tonic-gate { 4067c478bd9Sstevel@tonic-gate 4077c478bd9Sstevel@tonic-gate if (cmd != DDI_DETACH) 4087c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4097c478bd9Sstevel@tonic-gate 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate #ifdef QCN_DEBUG 4127c478bd9Sstevel@tonic-gate prom_printf("qcn_detach(): QCN driver detached\n"); 4137c478bd9Sstevel@tonic-gate #endif 4147c478bd9Sstevel@tonic-gate 4157c478bd9Sstevel@tonic-gate #ifdef QCN_POLLING 4167c478bd9Sstevel@tonic-gate if (qcn_state->qcn_polling) { 4177c478bd9Sstevel@tonic-gate mutex_enter(&cpu_lock); 4187c478bd9Sstevel@tonic-gate if (qcn_poll_cycid != CYCLIC_NONE) 4197c478bd9Sstevel@tonic-gate cyclic_remove(qcn_poll_cycid); 4207c478bd9Sstevel@tonic-gate qcn_poll_cycid = CYCLIC_NONE; 4217c478bd9Sstevel@tonic-gate mutex_exit(&cpu_lock); 4227c478bd9Sstevel@tonic-gate } 4237c478bd9Sstevel@tonic-gate #endif 4247c478bd9Sstevel@tonic-gate 4257c478bd9Sstevel@tonic-gate if (!qcn_state->qcn_polling) 4267c478bd9Sstevel@tonic-gate qcn_remove_intrs(); 4277c478bd9Sstevel@tonic-gate 4287c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 4297c478bd9Sstevel@tonic-gate } 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate /* ARGSUSED */ 4327c478bd9Sstevel@tonic-gate static int 4337c478bd9Sstevel@tonic-gate qcn_getinfo(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) 4347c478bd9Sstevel@tonic-gate { 4357c478bd9Sstevel@tonic-gate int error = DDI_FAILURE; 4367c478bd9Sstevel@tonic-gate int instance = 0; 4377c478bd9Sstevel@tonic-gate switch (infocmd) { 4387c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 4397c478bd9Sstevel@tonic-gate if (qcn_state) { 4407c478bd9Sstevel@tonic-gate #ifdef QCN_DEBUG 4417c478bd9Sstevel@tonic-gate prom_printf("qcn_getinfo(): devt2dip %lx\n", arg); 4427c478bd9Sstevel@tonic-gate #endif 4437c478bd9Sstevel@tonic-gate *result = (void *)qcn_state->qcn_dip; 4447c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 4457c478bd9Sstevel@tonic-gate } 4467c478bd9Sstevel@tonic-gate break; 4477c478bd9Sstevel@tonic-gate 4487c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 4497c478bd9Sstevel@tonic-gate #ifdef QCN_DEBUG 4507c478bd9Sstevel@tonic-gate prom_printf("qcn_getinfo(): devt2instance %lx\n", arg); 4517c478bd9Sstevel@tonic-gate #endif 4527c478bd9Sstevel@tonic-gate if (getminor((dev_t)arg) == 0) { 4530bd5614cSiskreen *result = (void *)(uintptr_t)instance; 4547c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 4557c478bd9Sstevel@tonic-gate } 4567c478bd9Sstevel@tonic-gate break; 4577c478bd9Sstevel@tonic-gate } 4587c478bd9Sstevel@tonic-gate 4597c478bd9Sstevel@tonic-gate return (error); 4607c478bd9Sstevel@tonic-gate } 4617c478bd9Sstevel@tonic-gate 4627c478bd9Sstevel@tonic-gate /* streams open & close */ 4637c478bd9Sstevel@tonic-gate /* ARGSUSED */ 4647c478bd9Sstevel@tonic-gate static int 4657c478bd9Sstevel@tonic-gate qcn_open(queue_t *q, dev_t *devp, int oflag, int sflag, cred_t *credp) 4667c478bd9Sstevel@tonic-gate { 4677c478bd9Sstevel@tonic-gate tty_common_t *tty; 4687c478bd9Sstevel@tonic-gate int unit = getminor(*devp); 4697c478bd9Sstevel@tonic-gate 4707c478bd9Sstevel@tonic-gate #ifdef QCN_DEBUG 4717c478bd9Sstevel@tonic-gate prom_printf("qcn_open(): minor %x\n", unit); 4727c478bd9Sstevel@tonic-gate #endif 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate if (unit != 0) 4757c478bd9Sstevel@tonic-gate return (ENXIO); 4767c478bd9Sstevel@tonic-gate 4777c478bd9Sstevel@tonic-gate /* stream already open */ 4787c478bd9Sstevel@tonic-gate if (q->q_ptr != NULL) 4797c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 4807c478bd9Sstevel@tonic-gate 4817c478bd9Sstevel@tonic-gate if (!qcn_state) { 4827c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "qcn_open: console was not configured by " 4837c478bd9Sstevel@tonic-gate "autoconfig\n"); 4847c478bd9Sstevel@tonic-gate return (ENXIO); 4857c478bd9Sstevel@tonic-gate } 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate mutex_enter(&qcn_state->qcn_lock); 4887c478bd9Sstevel@tonic-gate tty = &(qcn_state->qcn_tty); 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate tty->t_readq = q; 4917c478bd9Sstevel@tonic-gate tty->t_writeq = WR(q); 4927c478bd9Sstevel@tonic-gate 4937c478bd9Sstevel@tonic-gate /* Link the RD and WR Q's */ 4947c478bd9Sstevel@tonic-gate q->q_ptr = WR(q)->q_ptr = (caddr_t)qcn_state; 4957c478bd9Sstevel@tonic-gate qcn_state->qcn_readq = RD(q); 4967c478bd9Sstevel@tonic-gate qcn_state->qcn_writeq = WR(q); 4977c478bd9Sstevel@tonic-gate qprocson(q); 4987c478bd9Sstevel@tonic-gate 4997c478bd9Sstevel@tonic-gate mutex_exit(&qcn_state->qcn_lock); 5007c478bd9Sstevel@tonic-gate 5017c478bd9Sstevel@tonic-gate #ifdef QCN_DEBUG 5027c478bd9Sstevel@tonic-gate prom_printf("qcn_open: opened as dev %lx\n", *devp); 5037c478bd9Sstevel@tonic-gate #endif 5047c478bd9Sstevel@tonic-gate 5057c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 5067c478bd9Sstevel@tonic-gate } 5077c478bd9Sstevel@tonic-gate 5087c478bd9Sstevel@tonic-gate /* ARGSUSED */ 5097c478bd9Sstevel@tonic-gate static int 5107c478bd9Sstevel@tonic-gate qcn_close(queue_t *q, int flag, cred_t *credp) 5117c478bd9Sstevel@tonic-gate { 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate ASSERT(qcn_state == q->q_ptr); 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate if (qcn_state->qcn_wbufcid != 0) { 5167c478bd9Sstevel@tonic-gate unbufcall(qcn_state->qcn_wbufcid); 5177c478bd9Sstevel@tonic-gate } 5187c478bd9Sstevel@tonic-gate ttycommon_close(&qcn_state->qcn_tty); 5197c478bd9Sstevel@tonic-gate 5207c478bd9Sstevel@tonic-gate qprocsoff(q); 5217c478bd9Sstevel@tonic-gate q->q_ptr = WR(q)->q_ptr = NULL; 5227c478bd9Sstevel@tonic-gate qcn_state->qcn_readq = NULL; 5237c478bd9Sstevel@tonic-gate qcn_state->qcn_writeq = NULL; 5247c478bd9Sstevel@tonic-gate 5257c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 5267c478bd9Sstevel@tonic-gate } 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate /* 5297c478bd9Sstevel@tonic-gate * Put procedure for write queue. 5307c478bd9Sstevel@tonic-gate * Respond to M_IOCTL, M_DATA and M_FLUSH messages here; 5317c478bd9Sstevel@tonic-gate * It put's the data onto internal qcn_output_q. 5327c478bd9Sstevel@tonic-gate */ 5337c478bd9Sstevel@tonic-gate static int 5347c478bd9Sstevel@tonic-gate qcn_wput(queue_t *q, mblk_t *mp) 5357c478bd9Sstevel@tonic-gate { 5367c478bd9Sstevel@tonic-gate 5377c478bd9Sstevel@tonic-gate #ifdef QCN_DEBUG 5387c478bd9Sstevel@tonic-gate struct iocblk *iocp; 5397c478bd9Sstevel@tonic-gate int i; 5407c478bd9Sstevel@tonic-gate #endif 5417c478bd9Sstevel@tonic-gate 5427c478bd9Sstevel@tonic-gate ASSERT(qcn_state == q->q_ptr); 5437c478bd9Sstevel@tonic-gate 5447c478bd9Sstevel@tonic-gate if (!mp->b_datap) { 5457c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "qcn_wput: null datap"); 5467c478bd9Sstevel@tonic-gate } 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate #ifdef QCN_DEBUG 5497c478bd9Sstevel@tonic-gate prom_printf("qcn_wput(): QCN wput q=%X mp=%X rd=%X wr=%X type=%X\n", 5507c478bd9Sstevel@tonic-gate q, mp, mp->b_rptr, mp->b_wptr, mp->b_datap->db_type); 5517c478bd9Sstevel@tonic-gate #endif 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate mutex_enter(&qcn_state->qcn_lock); 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate switch (mp->b_datap->db_type) { 5567c478bd9Sstevel@tonic-gate case M_IOCTL: 5577c478bd9Sstevel@tonic-gate case M_CTL: 5587c478bd9Sstevel@tonic-gate #ifdef QCN_DEBUG 5597c478bd9Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr; 5607c478bd9Sstevel@tonic-gate prom_printf("qcn_wput(): M_IOCTL cmd=%X TIOC=%X\n", 5617c478bd9Sstevel@tonic-gate iocp->ioc_cmd, TIOC); 5627c478bd9Sstevel@tonic-gate #endif 5637c478bd9Sstevel@tonic-gate switch (((struct iocblk *)mp->b_rptr)->ioc_cmd) { 5647c478bd9Sstevel@tonic-gate case TCSETSW: 5657c478bd9Sstevel@tonic-gate case TCSETSF: 5667c478bd9Sstevel@tonic-gate case TCSETAW: 5677c478bd9Sstevel@tonic-gate case TCSETAF: 5687c478bd9Sstevel@tonic-gate case TCSBRK: 5697c478bd9Sstevel@tonic-gate /* 5707c478bd9Sstevel@tonic-gate * The change do not take effect until all 5717c478bd9Sstevel@tonic-gate * output queued before them is drained. 5727c478bd9Sstevel@tonic-gate * Put this message on the queue, so that 5737c478bd9Sstevel@tonic-gate * "qcn_start" will see it when it's done 5747c478bd9Sstevel@tonic-gate * with the output before it. Poke the start 5757c478bd9Sstevel@tonic-gate * routine, just in case. 5767c478bd9Sstevel@tonic-gate */ 5777c478bd9Sstevel@tonic-gate (void) putq(q, mp); 5787c478bd9Sstevel@tonic-gate qcn_start(); 5797c478bd9Sstevel@tonic-gate break; 5807c478bd9Sstevel@tonic-gate default: 5817c478bd9Sstevel@tonic-gate qcn_ioctl(q, mp); 5827c478bd9Sstevel@tonic-gate } 5837c478bd9Sstevel@tonic-gate break; 5847c478bd9Sstevel@tonic-gate 5857c478bd9Sstevel@tonic-gate case M_FLUSH: 5867c478bd9Sstevel@tonic-gate if (*mp->b_rptr & FLUSHW) { 5877c478bd9Sstevel@tonic-gate flushq(q, FLUSHDATA); 5887c478bd9Sstevel@tonic-gate *mp->b_rptr &= ~FLUSHW; 5897c478bd9Sstevel@tonic-gate } 5907c478bd9Sstevel@tonic-gate if (*mp->b_rptr & FLUSHR) { 5917c478bd9Sstevel@tonic-gate flushq(RD(q), FLUSHDATA); 5927c478bd9Sstevel@tonic-gate qreply(q, mp); 5937c478bd9Sstevel@tonic-gate } else { 5947c478bd9Sstevel@tonic-gate freemsg(mp); 5957c478bd9Sstevel@tonic-gate } 5967c478bd9Sstevel@tonic-gate break; 5977c478bd9Sstevel@tonic-gate 5987c478bd9Sstevel@tonic-gate case M_STOP: 5997c478bd9Sstevel@tonic-gate qcn_stopped = B_TRUE; 6007c478bd9Sstevel@tonic-gate freemsg(mp); 6017c478bd9Sstevel@tonic-gate break; 6027c478bd9Sstevel@tonic-gate 6037c478bd9Sstevel@tonic-gate case M_START: 6047c478bd9Sstevel@tonic-gate qcn_stopped = B_FALSE; 6057c478bd9Sstevel@tonic-gate freemsg(mp); 6067c478bd9Sstevel@tonic-gate qenable(q); /* Start up delayed messages */ 6077c478bd9Sstevel@tonic-gate break; 6087c478bd9Sstevel@tonic-gate 6097c478bd9Sstevel@tonic-gate case M_DATA: 6107c478bd9Sstevel@tonic-gate /* 6117c478bd9Sstevel@tonic-gate * Queue the message up to be transmitted, 6127c478bd9Sstevel@tonic-gate * and poke the start routine. 6137c478bd9Sstevel@tonic-gate */ 6147c478bd9Sstevel@tonic-gate #ifdef QCN_DEBUG 6157c478bd9Sstevel@tonic-gate if (mp->b_rptr < mp->b_wptr) { 6167c478bd9Sstevel@tonic-gate prom_printf("qcn_wput(): DATA q=%X mp=%X rd=%X wr=%X\n", 6177c478bd9Sstevel@tonic-gate q, mp, mp->b_rptr, mp->b_wptr); 6187c478bd9Sstevel@tonic-gate prom_printf("qcn_wput(): ["); 6197c478bd9Sstevel@tonic-gate for (i = 0; i < mp->b_wptr-mp->b_rptr; i++) { 6207c478bd9Sstevel@tonic-gate prom_printf("%c", *(mp->b_rptr+i)); 6217c478bd9Sstevel@tonic-gate } 6227c478bd9Sstevel@tonic-gate prom_printf("]\n"); 6237c478bd9Sstevel@tonic-gate } 6247c478bd9Sstevel@tonic-gate #endif /* QCN_DEBUG */ 6257c478bd9Sstevel@tonic-gate (void) putq(q, mp); 6267c478bd9Sstevel@tonic-gate qcn_start(); 6277c478bd9Sstevel@tonic-gate break; 6287c478bd9Sstevel@tonic-gate 6297c478bd9Sstevel@tonic-gate default: 6307c478bd9Sstevel@tonic-gate freemsg(mp); 6317c478bd9Sstevel@tonic-gate } 6327c478bd9Sstevel@tonic-gate 6337c478bd9Sstevel@tonic-gate mutex_exit(&qcn_state->qcn_lock); 6347c478bd9Sstevel@tonic-gate return (0); 6357c478bd9Sstevel@tonic-gate } 6367c478bd9Sstevel@tonic-gate 6377c478bd9Sstevel@tonic-gate /* 6387c478bd9Sstevel@tonic-gate * Process an "ioctl" message sent down to us. 6397c478bd9Sstevel@tonic-gate */ 6407c478bd9Sstevel@tonic-gate static void 6417c478bd9Sstevel@tonic-gate qcn_ioctl(queue_t *q, mblk_t *mp) 6427c478bd9Sstevel@tonic-gate { 6437c478bd9Sstevel@tonic-gate struct iocblk *iocp; 6447c478bd9Sstevel@tonic-gate tty_common_t *tty; 6457c478bd9Sstevel@tonic-gate mblk_t *datamp; 6467c478bd9Sstevel@tonic-gate int data_size; 6477c478bd9Sstevel@tonic-gate int error = 0; 6487c478bd9Sstevel@tonic-gate 6497c478bd9Sstevel@tonic-gate #ifdef QCN_DEBUG 6507c478bd9Sstevel@tonic-gate prom_printf("qcn_ioctl(): q=%X mp=%X\n", q, mp); 6517c478bd9Sstevel@tonic-gate #endif 6527c478bd9Sstevel@tonic-gate 6537c478bd9Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr; 6547c478bd9Sstevel@tonic-gate tty = &(qcn_state->qcn_tty); 6557c478bd9Sstevel@tonic-gate 6567c478bd9Sstevel@tonic-gate if (tty->t_iocpending != NULL) { 6577c478bd9Sstevel@tonic-gate freemsg(tty->t_iocpending); 6587c478bd9Sstevel@tonic-gate tty->t_iocpending = NULL; 6597c478bd9Sstevel@tonic-gate } 6607c478bd9Sstevel@tonic-gate data_size = ttycommon_ioctl(tty, q, mp, &error); 6617c478bd9Sstevel@tonic-gate if (data_size != 0) { 6627c478bd9Sstevel@tonic-gate if (qcn_state->qcn_wbufcid) 6637c478bd9Sstevel@tonic-gate unbufcall(qcn_state->qcn_wbufcid); 6647c478bd9Sstevel@tonic-gate /* call qcn_reioctl() */ 6657c478bd9Sstevel@tonic-gate qcn_state->qcn_wbufcid = 6667c478bd9Sstevel@tonic-gate bufcall(data_size, BPRI_HI, qcn_reioctl, qcn_state); 6677c478bd9Sstevel@tonic-gate return; 6687c478bd9Sstevel@tonic-gate } 6697c478bd9Sstevel@tonic-gate 6707c478bd9Sstevel@tonic-gate if (error < 0) { 6717c478bd9Sstevel@tonic-gate iocp = (struct iocblk *)mp->b_rptr; 6727c478bd9Sstevel@tonic-gate /* 6737c478bd9Sstevel@tonic-gate * "ttycommon_ioctl" didn't do anything; we process it here. 6747c478bd9Sstevel@tonic-gate */ 6757c478bd9Sstevel@tonic-gate error = 0; 6767c478bd9Sstevel@tonic-gate switch (iocp->ioc_cmd) { 6777c478bd9Sstevel@tonic-gate case TCSBRK: 6787c478bd9Sstevel@tonic-gate case TIOCSBRK: 6797c478bd9Sstevel@tonic-gate case TIOCCBRK: 6807c478bd9Sstevel@tonic-gate case TIOCMSET: 6817c478bd9Sstevel@tonic-gate case TIOCMBIS: 6827c478bd9Sstevel@tonic-gate case TIOCMBIC: 6837c478bd9Sstevel@tonic-gate if (iocp->ioc_count != TRANSPARENT) 6847c478bd9Sstevel@tonic-gate qcn_ack(mp, NULL, 0); 6857c478bd9Sstevel@tonic-gate else 6867c478bd9Sstevel@tonic-gate mcopyin(mp, NULL, sizeof (int), NULL); 6877c478bd9Sstevel@tonic-gate break; 6887c478bd9Sstevel@tonic-gate 6897c478bd9Sstevel@tonic-gate case TIOCMGET: 6907c478bd9Sstevel@tonic-gate datamp = allocb(sizeof (int), BPRI_MED); 6917c478bd9Sstevel@tonic-gate if (datamp == NULL) { 6927c478bd9Sstevel@tonic-gate error = EAGAIN; 6937c478bd9Sstevel@tonic-gate break; 6947c478bd9Sstevel@tonic-gate } 6957c478bd9Sstevel@tonic-gate 6967c478bd9Sstevel@tonic-gate *(int *)datamp->b_rptr = 0; 6977c478bd9Sstevel@tonic-gate 6987c478bd9Sstevel@tonic-gate if (iocp->ioc_count != TRANSPARENT) 6997c478bd9Sstevel@tonic-gate qcn_ack(mp, datamp, sizeof (int)); 7007c478bd9Sstevel@tonic-gate else 7017c478bd9Sstevel@tonic-gate mcopyout(mp, NULL, sizeof (int), NULL, datamp); 7027c478bd9Sstevel@tonic-gate break; 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate default: 7057c478bd9Sstevel@tonic-gate error = EINVAL; 7067c478bd9Sstevel@tonic-gate break; 7077c478bd9Sstevel@tonic-gate } 7087c478bd9Sstevel@tonic-gate } 7097c478bd9Sstevel@tonic-gate if (error != 0) { 7107c478bd9Sstevel@tonic-gate iocp->ioc_count = 0; 7117c478bd9Sstevel@tonic-gate iocp->ioc_error = error; 7127c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCNAK; 7137c478bd9Sstevel@tonic-gate } 7147c478bd9Sstevel@tonic-gate qreply(q, mp); 7157c478bd9Sstevel@tonic-gate } 7167c478bd9Sstevel@tonic-gate 7177c478bd9Sstevel@tonic-gate static void 7187c478bd9Sstevel@tonic-gate qcn_reioctl(void *unit) 7197c478bd9Sstevel@tonic-gate { 7207c478bd9Sstevel@tonic-gate queue_t *q; 7217c478bd9Sstevel@tonic-gate mblk_t *mp; 7227c478bd9Sstevel@tonic-gate qcn_t *qcnp = (qcn_t *)unit; 7237c478bd9Sstevel@tonic-gate 7247c478bd9Sstevel@tonic-gate if (!qcnp->qcn_wbufcid) 7257c478bd9Sstevel@tonic-gate return; 7267c478bd9Sstevel@tonic-gate 7277c478bd9Sstevel@tonic-gate qcnp->qcn_wbufcid = 0; 7287c478bd9Sstevel@tonic-gate if ((q = qcnp->qcn_tty.t_writeq) == NULL) 7297c478bd9Sstevel@tonic-gate return; 7307c478bd9Sstevel@tonic-gate 7317c478bd9Sstevel@tonic-gate if ((mp = qcnp->qcn_tty.t_iocpending) == NULL) 7327c478bd9Sstevel@tonic-gate return; 7337c478bd9Sstevel@tonic-gate 7347c478bd9Sstevel@tonic-gate qcnp->qcn_tty.t_iocpending = NULL; 7357c478bd9Sstevel@tonic-gate qcn_ioctl(q, mp); 7367c478bd9Sstevel@tonic-gate } 7377c478bd9Sstevel@tonic-gate 7387c478bd9Sstevel@tonic-gate static void 7397c478bd9Sstevel@tonic-gate qcn_ack(mblk_t *mp, mblk_t *dp, uint_t size) 7407c478bd9Sstevel@tonic-gate { 7417c478bd9Sstevel@tonic-gate struct iocblk *iocp = (struct iocblk *)mp->b_rptr; 7427c478bd9Sstevel@tonic-gate 7437c478bd9Sstevel@tonic-gate mp->b_datap->db_type = M_IOCACK; 7447c478bd9Sstevel@tonic-gate iocp->ioc_count = size; 7457c478bd9Sstevel@tonic-gate iocp->ioc_error = 0; 7467c478bd9Sstevel@tonic-gate iocp->ioc_rval = 0; 7477c478bd9Sstevel@tonic-gate if (mp->b_cont != NULL) 7487c478bd9Sstevel@tonic-gate freeb(mp->b_cont); 7497c478bd9Sstevel@tonic-gate if (dp != NULL) { 7507c478bd9Sstevel@tonic-gate mp->b_cont = dp; 7517c478bd9Sstevel@tonic-gate dp->b_wptr += size; 7527c478bd9Sstevel@tonic-gate } else 7537c478bd9Sstevel@tonic-gate mp->b_cont = NULL; 7547c478bd9Sstevel@tonic-gate } 7557c478bd9Sstevel@tonic-gate 7567c478bd9Sstevel@tonic-gate static void 7577c478bd9Sstevel@tonic-gate qcn_start(void) 7587c478bd9Sstevel@tonic-gate { 7597c478bd9Sstevel@tonic-gate 7607c478bd9Sstevel@tonic-gate queue_t *q; 7617c478bd9Sstevel@tonic-gate mblk_t *mp; 7627c478bd9Sstevel@tonic-gate int rv; 7637c478bd9Sstevel@tonic-gate 7647c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&qcn_state->qcn_lock)); 7657c478bd9Sstevel@tonic-gate 7667c478bd9Sstevel@tonic-gate /* 7677c478bd9Sstevel@tonic-gate * read stream queue and remove data from the queue and 7687c478bd9Sstevel@tonic-gate * transmit them if possible 7697c478bd9Sstevel@tonic-gate */ 7707c478bd9Sstevel@tonic-gate q = qcn_state->qcn_writeq; 7717c478bd9Sstevel@tonic-gate ASSERT(q != NULL); 7727c478bd9Sstevel@tonic-gate while (mp = getq(q)) { 7737c478bd9Sstevel@tonic-gate if (mp->b_datap->db_type == M_IOCTL) { 7747c478bd9Sstevel@tonic-gate /* 7757c478bd9Sstevel@tonic-gate * These are those IOCTLs queued up 7767c478bd9Sstevel@tonic-gate * do it now 7777c478bd9Sstevel@tonic-gate */ 7787c478bd9Sstevel@tonic-gate qcn_ioctl(q, mp); 7797c478bd9Sstevel@tonic-gate continue; 7807c478bd9Sstevel@tonic-gate } 7817c478bd9Sstevel@tonic-gate /* 7827c478bd9Sstevel@tonic-gate * M_DATA 7837c478bd9Sstevel@tonic-gate */ 7847c478bd9Sstevel@tonic-gate rv = qcn_transmit(q, mp); 7857c478bd9Sstevel@tonic-gate if (rv == EBUSY || rv == EAGAIN) 7867c478bd9Sstevel@tonic-gate return; 7877c478bd9Sstevel@tonic-gate } 7887c478bd9Sstevel@tonic-gate } 7897c478bd9Sstevel@tonic-gate 7907c478bd9Sstevel@tonic-gate static int 7917c478bd9Sstevel@tonic-gate qcn_transmit(queue_t *q, mblk_t *mp) 7927c478bd9Sstevel@tonic-gate { 7937c478bd9Sstevel@tonic-gate caddr_t buf; 7947c478bd9Sstevel@tonic-gate mblk_t *bp; 7957c478bd9Sstevel@tonic-gate size_t len; 7967c478bd9Sstevel@tonic-gate long i; 7977c478bd9Sstevel@tonic-gate 7987c478bd9Sstevel@tonic-gate #ifdef QCN_DEBUG 7997c478bd9Sstevel@tonic-gate prom_printf("qcn_transmit(): q=%X mp=%X\n", q, mp); 8007c478bd9Sstevel@tonic-gate #endif 8017c478bd9Sstevel@tonic-gate do { 8027c478bd9Sstevel@tonic-gate bp = mp; 8037c478bd9Sstevel@tonic-gate len = bp->b_wptr - bp->b_rptr; 8047c478bd9Sstevel@tonic-gate buf = (caddr_t)bp->b_rptr; 8057c478bd9Sstevel@tonic-gate 8067c478bd9Sstevel@tonic-gate for (i = 0; i < len; i++) { 807*1ae08745Sheppo if (hv_cnputchar(buf[i]) == H_EWOULDBLOCK) 8087c478bd9Sstevel@tonic-gate break; 8097c478bd9Sstevel@tonic-gate } 8107c478bd9Sstevel@tonic-gate if (i != len) { 8117c478bd9Sstevel@tonic-gate bp->b_rptr += i; 8127c478bd9Sstevel@tonic-gate (void) putbq(q, mp); 8137c478bd9Sstevel@tonic-gate return (EAGAIN); 8147c478bd9Sstevel@tonic-gate } 8157c478bd9Sstevel@tonic-gate mp = bp->b_cont; 8167c478bd9Sstevel@tonic-gate freeb(bp); 8177c478bd9Sstevel@tonic-gate } while (mp != NULL); 8187c478bd9Sstevel@tonic-gate 8197c478bd9Sstevel@tonic-gate return (0); 8207c478bd9Sstevel@tonic-gate } 8217c478bd9Sstevel@tonic-gate 8227c478bd9Sstevel@tonic-gate /* 8237c478bd9Sstevel@tonic-gate * called when SC first establishes console connection 8247c478bd9Sstevel@tonic-gate * drop all the data on the output queue 8257c478bd9Sstevel@tonic-gate */ 8267c478bd9Sstevel@tonic-gate static void 8277c478bd9Sstevel@tonic-gate qcn_flush(void) 8287c478bd9Sstevel@tonic-gate { 8297c478bd9Sstevel@tonic-gate queue_t *q; 8307c478bd9Sstevel@tonic-gate mblk_t *mp; 8317c478bd9Sstevel@tonic-gate 8327c478bd9Sstevel@tonic-gate ASSERT(MUTEX_HELD(&qcn_state->qcn_lock)); 8337c478bd9Sstevel@tonic-gate 8347c478bd9Sstevel@tonic-gate q = qcn_state->qcn_writeq; 8357c478bd9Sstevel@tonic-gate 8360bd5614cSiskreen prom_printf("qcn_flush(): WARNING console output is dropped time=%lx\n", 8377c478bd9Sstevel@tonic-gate gethrestime_sec()); 8387c478bd9Sstevel@tonic-gate while (mp = getq(q)) 8397c478bd9Sstevel@tonic-gate freemsg(mp); 8407c478bd9Sstevel@tonic-gate } 8417c478bd9Sstevel@tonic-gate 8427c478bd9Sstevel@tonic-gate static void 8437c478bd9Sstevel@tonic-gate qcn_trigger_softint(void) 8447c478bd9Sstevel@tonic-gate { 8457c478bd9Sstevel@tonic-gate 8467c478bd9Sstevel@tonic-gate if (mutex_tryenter(&qcn_state->qcn_softlock)) { 8477c478bd9Sstevel@tonic-gate if (!qcn_state->qcn_soft_pend) { 8487c478bd9Sstevel@tonic-gate qcn_state->qcn_soft_pend = 1; 8497c478bd9Sstevel@tonic-gate mutex_exit(&qcn_state->qcn_softlock); 8507c478bd9Sstevel@tonic-gate (void) ddi_intr_trigger_softint( 8517c478bd9Sstevel@tonic-gate qcn_state->qcn_softint_hdl, NULL); 8527c478bd9Sstevel@tonic-gate } else 8537c478bd9Sstevel@tonic-gate mutex_exit(&qcn_state->qcn_softlock); 8547c478bd9Sstevel@tonic-gate } 8557c478bd9Sstevel@tonic-gate } 8567c478bd9Sstevel@tonic-gate 8577c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 8587c478bd9Sstevel@tonic-gate static uint_t 8597c478bd9Sstevel@tonic-gate qcn_soft_intr(caddr_t arg1, caddr_t arg2) 8607c478bd9Sstevel@tonic-gate { 8617c478bd9Sstevel@tonic-gate mblk_t *mp; 8627c478bd9Sstevel@tonic-gate int cc; 8637c478bd9Sstevel@tonic-gate 8647c478bd9Sstevel@tonic-gate mutex_enter(&qcn_state->qcn_softlock); 8657c478bd9Sstevel@tonic-gate mutex_enter(&qcn_state->qcn_hi_lock); 8667c478bd9Sstevel@tonic-gate if ((cc = RING_CNT(qcn_state)) <= 0) { 8677c478bd9Sstevel@tonic-gate mutex_exit(&qcn_state->qcn_hi_lock); 8687c478bd9Sstevel@tonic-gate goto out; 8697c478bd9Sstevel@tonic-gate } 8707c478bd9Sstevel@tonic-gate 8717c478bd9Sstevel@tonic-gate if ((mp = allocb(cc, BPRI_MED)) == NULL) { 8727c478bd9Sstevel@tonic-gate qcn_input_dropped += cc; 8737c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "qcn_intr: allocb" 8747c478bd9Sstevel@tonic-gate "failed (console input dropped)"); 8757c478bd9Sstevel@tonic-gate mutex_exit(&qcn_state->qcn_hi_lock); 8767c478bd9Sstevel@tonic-gate goto out; 8777c478bd9Sstevel@tonic-gate } 8787c478bd9Sstevel@tonic-gate 8797c478bd9Sstevel@tonic-gate do { 8807c478bd9Sstevel@tonic-gate /* put console input onto stream */ 8817c478bd9Sstevel@tonic-gate *(char *)mp->b_wptr++ = RING_GET(qcn_state); 8827c478bd9Sstevel@tonic-gate } while (--cc); 8837c478bd9Sstevel@tonic-gate 8847c478bd9Sstevel@tonic-gate if (qcn_state->qcn_rbuf_overflow) { 8857c478bd9Sstevel@tonic-gate mutex_exit(&qcn_state->qcn_hi_lock); 8867c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "qcn: Ring buffer overflow\n"); 8877c478bd9Sstevel@tonic-gate mutex_enter(&qcn_state->qcn_hi_lock); 8887c478bd9Sstevel@tonic-gate qcn_state->qcn_rbuf_overflow = 0; 8897c478bd9Sstevel@tonic-gate } 8907c478bd9Sstevel@tonic-gate 8917c478bd9Sstevel@tonic-gate mutex_exit(&qcn_state->qcn_hi_lock); 8927c478bd9Sstevel@tonic-gate if (qcn_state->qcn_readq) { 8937c478bd9Sstevel@tonic-gate putnext(qcn_state->qcn_readq, mp); 8947c478bd9Sstevel@tonic-gate } 8957c478bd9Sstevel@tonic-gate out: 8967c478bd9Sstevel@tonic-gate /* 8977c478bd9Sstevel@tonic-gate * If there are pending transmits because hypervisor 8987c478bd9Sstevel@tonic-gate * returned EWOULDBLOCK poke start now. 8997c478bd9Sstevel@tonic-gate */ 9007c478bd9Sstevel@tonic-gate 9017c478bd9Sstevel@tonic-gate if (qcn_state->qcn_writeq != NULL) { 9027c478bd9Sstevel@tonic-gate if (qcn_state->qcn_hangup) { 9037c478bd9Sstevel@tonic-gate (void) putctl(qcn_state->qcn_readq, M_HANGUP); 9047c478bd9Sstevel@tonic-gate flushq(qcn_state->qcn_writeq, FLUSHDATA); 9057c478bd9Sstevel@tonic-gate qcn_state->qcn_hangup = 0; 9067c478bd9Sstevel@tonic-gate } else { 9077c478bd9Sstevel@tonic-gate mutex_enter(&qcn_state->qcn_lock); 9087c478bd9Sstevel@tonic-gate qcn_start(); 9097c478bd9Sstevel@tonic-gate mutex_exit(&qcn_state->qcn_lock); 9107c478bd9Sstevel@tonic-gate } 9117c478bd9Sstevel@tonic-gate } 9127c478bd9Sstevel@tonic-gate qcn_state->qcn_soft_pend = 0; 9137c478bd9Sstevel@tonic-gate mutex_exit(&qcn_state->qcn_softlock); 9147c478bd9Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 9157c478bd9Sstevel@tonic-gate } 9167c478bd9Sstevel@tonic-gate 9177c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 9187c478bd9Sstevel@tonic-gate static uint_t 9197c478bd9Sstevel@tonic-gate qcn_hi_intr(caddr_t arg) 9207c478bd9Sstevel@tonic-gate { 9217c478bd9Sstevel@tonic-gate int64_t rv; 9227c478bd9Sstevel@tonic-gate uint8_t buf; 9237c478bd9Sstevel@tonic-gate 9247c478bd9Sstevel@tonic-gate mutex_enter(&qcn_state->qcn_hi_lock); 9257c478bd9Sstevel@tonic-gate /* LINTED: E_CONSTANT_CONDITION */ 9267c478bd9Sstevel@tonic-gate while (1) { 9277c478bd9Sstevel@tonic-gate rv = hv_cngetchar(&buf); 9287c478bd9Sstevel@tonic-gate if (rv == H_BREAK) { 9297c478bd9Sstevel@tonic-gate if (abort_enable != KIOCABORTALTERNATE) 9307c478bd9Sstevel@tonic-gate abort_sequence_enter((char *)NULL); 9317c478bd9Sstevel@tonic-gate } 9327c478bd9Sstevel@tonic-gate 9337c478bd9Sstevel@tonic-gate if (rv == H_HUP) { 9347c478bd9Sstevel@tonic-gate qcn_state->qcn_hangup = 1; 9357c478bd9Sstevel@tonic-gate } 9367c478bd9Sstevel@tonic-gate 9377c478bd9Sstevel@tonic-gate if (rv != H_EOK) 9387c478bd9Sstevel@tonic-gate goto out; 9397c478bd9Sstevel@tonic-gate 9407c478bd9Sstevel@tonic-gate if (abort_enable == KIOCABORTALTERNATE) { 9417c478bd9Sstevel@tonic-gate if (abort_charseq_recognize(buf)) { 9427c478bd9Sstevel@tonic-gate abort_sequence_enter((char *)NULL); 9437c478bd9Sstevel@tonic-gate } 9447c478bd9Sstevel@tonic-gate } 9457c478bd9Sstevel@tonic-gate 9467c478bd9Sstevel@tonic-gate /* put console input onto stream */ 9477c478bd9Sstevel@tonic-gate if (RING_POK(qcn_state, 1)) { 9487c478bd9Sstevel@tonic-gate RING_PUT(qcn_state, buf); 9497c478bd9Sstevel@tonic-gate } else { 9507c478bd9Sstevel@tonic-gate qcn_state->qcn_rbuf_overflow++; 9517c478bd9Sstevel@tonic-gate } 9527c478bd9Sstevel@tonic-gate } 9537c478bd9Sstevel@tonic-gate out: 9547c478bd9Sstevel@tonic-gate mutex_exit(&qcn_state->qcn_hi_lock); 9557c478bd9Sstevel@tonic-gate qcn_trigger_softint(); 9567c478bd9Sstevel@tonic-gate 9577c478bd9Sstevel@tonic-gate return (DDI_INTR_CLAIMED); 9587c478bd9Sstevel@tonic-gate } 9597c478bd9Sstevel@tonic-gate 9607c478bd9Sstevel@tonic-gate #ifdef QCN_POLLING 9617c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 9627c478bd9Sstevel@tonic-gate static void 9637c478bd9Sstevel@tonic-gate qcn_poll_handler(void *unused) 9647c478bd9Sstevel@tonic-gate { 9657c478bd9Sstevel@tonic-gate mblk_t *mp; 9667c478bd9Sstevel@tonic-gate int64_t rv; 9677c478bd9Sstevel@tonic-gate uint8_t buf; 9687c478bd9Sstevel@tonic-gate int qcn_writeq_flush = 0; 9697c478bd9Sstevel@tonic-gate 9707c478bd9Sstevel@tonic-gate /* LINTED: E_CONSTANT_CONDITION */ 9717c478bd9Sstevel@tonic-gate while (1) { 9727c478bd9Sstevel@tonic-gate rv = hv_cngetchar(&buf); 9737c478bd9Sstevel@tonic-gate if (rv == H_BREAK) { 9747c478bd9Sstevel@tonic-gate if (abort_enable != KIOCABORTALTERNATE) 9757c478bd9Sstevel@tonic-gate abort_sequence_enter((char *)NULL); 9767c478bd9Sstevel@tonic-gate } 9777c478bd9Sstevel@tonic-gate 9787c478bd9Sstevel@tonic-gate if (rv == H_HUP) { 9797c478bd9Sstevel@tonic-gate if (qcn_state->qcn_readq) { 9807c478bd9Sstevel@tonic-gate (void) putctl(qcn_state->qcn_readq, M_HANGUP); 9817c478bd9Sstevel@tonic-gate qcn_writeq_flush = 1; 9827c478bd9Sstevel@tonic-gate } 9837c478bd9Sstevel@tonic-gate goto out; 9847c478bd9Sstevel@tonic-gate } 9857c478bd9Sstevel@tonic-gate 9867c478bd9Sstevel@tonic-gate if (rv != H_EOK) 9877c478bd9Sstevel@tonic-gate goto out; 9887c478bd9Sstevel@tonic-gate 9897c478bd9Sstevel@tonic-gate if (abort_enable == KIOCABORTALTERNATE) { 9907c478bd9Sstevel@tonic-gate if (abort_charseq_recognize(buf)) { 9917c478bd9Sstevel@tonic-gate abort_sequence_enter((char *)NULL); 9927c478bd9Sstevel@tonic-gate } 9937c478bd9Sstevel@tonic-gate } 9947c478bd9Sstevel@tonic-gate 9957c478bd9Sstevel@tonic-gate /* put console input onto stream */ 9967c478bd9Sstevel@tonic-gate if (qcn_state->qcn_readq) { 9977c478bd9Sstevel@tonic-gate if ((mp = allocb(1, BPRI_MED)) == NULL) { 9987c478bd9Sstevel@tonic-gate qcn_input_dropped++; 9997c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "qcn_intr: allocb" 10007c478bd9Sstevel@tonic-gate "failed (console input dropped)"); 10017c478bd9Sstevel@tonic-gate return; 10027c478bd9Sstevel@tonic-gate } 10037c478bd9Sstevel@tonic-gate *(char *)mp->b_wptr++ = buf; 10047c478bd9Sstevel@tonic-gate putnext(qcn_state->qcn_readq, mp); 10057c478bd9Sstevel@tonic-gate } 10067c478bd9Sstevel@tonic-gate } 10077c478bd9Sstevel@tonic-gate out: 10087c478bd9Sstevel@tonic-gate /* 10097c478bd9Sstevel@tonic-gate * If there are pending transmits because hypervisor 10107c478bd9Sstevel@tonic-gate * returned EWOULDBLOCK poke start now. 10117c478bd9Sstevel@tonic-gate */ 10127c478bd9Sstevel@tonic-gate 10137c478bd9Sstevel@tonic-gate mutex_enter(&qcn_state->qcn_lock); 10147c478bd9Sstevel@tonic-gate if (qcn_state->qcn_writeq != NULL) { 10157c478bd9Sstevel@tonic-gate if (qcn_writeq_flush) { 10167c478bd9Sstevel@tonic-gate flushq(qcn_state->qcn_writeq, FLUSHDATA); 10177c478bd9Sstevel@tonic-gate } else { 10187c478bd9Sstevel@tonic-gate qcn_start(); 10197c478bd9Sstevel@tonic-gate } 10207c478bd9Sstevel@tonic-gate } 10217c478bd9Sstevel@tonic-gate mutex_exit(&qcn_state->qcn_lock); 10227c478bd9Sstevel@tonic-gate } 10237c478bd9Sstevel@tonic-gate #endif 10247c478bd9Sstevel@tonic-gate 10257c478bd9Sstevel@tonic-gate /* 10267c478bd9Sstevel@tonic-gate * Check for abort character sequence, copied from zs_async.c 10277c478bd9Sstevel@tonic-gate */ 10287c478bd9Sstevel@tonic-gate #define CNTRL(c) ((c)&037) 10297c478bd9Sstevel@tonic-gate 10307c478bd9Sstevel@tonic-gate static boolean_t 10317c478bd9Sstevel@tonic-gate abort_charseq_recognize(uchar_t ch) 10327c478bd9Sstevel@tonic-gate { 10337c478bd9Sstevel@tonic-gate static int state = 0; 10347c478bd9Sstevel@tonic-gate static char sequence[] = { '\r', '~', CNTRL('b') }; 10357c478bd9Sstevel@tonic-gate 10367c478bd9Sstevel@tonic-gate if (ch == sequence[state]) { 10377c478bd9Sstevel@tonic-gate if (++state >= sizeof (sequence)) { 10387c478bd9Sstevel@tonic-gate state = 0; 10397c478bd9Sstevel@tonic-gate return (B_TRUE); 10407c478bd9Sstevel@tonic-gate } 10417c478bd9Sstevel@tonic-gate } else { 10427c478bd9Sstevel@tonic-gate state = (ch == sequence[0]) ? 1 : 0; 10437c478bd9Sstevel@tonic-gate } 10447c478bd9Sstevel@tonic-gate return (B_FALSE); 10457c478bd9Sstevel@tonic-gate } 10467c478bd9Sstevel@tonic-gate 10477c478bd9Sstevel@tonic-gate 10487c478bd9Sstevel@tonic-gate static int 10497c478bd9Sstevel@tonic-gate qcn_rsrv(queue_t *q) 10507c478bd9Sstevel@tonic-gate { 10517c478bd9Sstevel@tonic-gate mblk_t *mp; 10527c478bd9Sstevel@tonic-gate 10537c478bd9Sstevel@tonic-gate if (qcn_stopped == B_TRUE) 10547c478bd9Sstevel@tonic-gate return (0); 10557c478bd9Sstevel@tonic-gate 10567c478bd9Sstevel@tonic-gate mutex_enter(&qcn_state->qcn_lock); 10577c478bd9Sstevel@tonic-gate 10587c478bd9Sstevel@tonic-gate while ((mp = getq(q)) != NULL) { 10597c478bd9Sstevel@tonic-gate if (canputnext(q)) 10607c478bd9Sstevel@tonic-gate putnext(q, mp); 10617c478bd9Sstevel@tonic-gate else if (mp->b_datap->db_type >= QPCTL) 10627c478bd9Sstevel@tonic-gate (void) putbq(q, mp); 10637c478bd9Sstevel@tonic-gate } 10647c478bd9Sstevel@tonic-gate 10657c478bd9Sstevel@tonic-gate mutex_exit(&qcn_state->qcn_lock); 10667c478bd9Sstevel@tonic-gate 10677c478bd9Sstevel@tonic-gate return (0); 10687c478bd9Sstevel@tonic-gate } 10697c478bd9Sstevel@tonic-gate 10707c478bd9Sstevel@tonic-gate /* ARGSUSED */ 10717c478bd9Sstevel@tonic-gate static int 10727c478bd9Sstevel@tonic-gate qcn_wsrv(queue_t *q) 10737c478bd9Sstevel@tonic-gate { 10747c478bd9Sstevel@tonic-gate if (qcn_stopped == B_TRUE) 10757c478bd9Sstevel@tonic-gate return (0); 10767c478bd9Sstevel@tonic-gate 10777c478bd9Sstevel@tonic-gate mutex_enter(&qcn_state->qcn_lock); 10787c478bd9Sstevel@tonic-gate 10797c478bd9Sstevel@tonic-gate if (qcn_state->qcn_writeq != NULL) 10807c478bd9Sstevel@tonic-gate qcn_start(); 10817c478bd9Sstevel@tonic-gate 10827c478bd9Sstevel@tonic-gate mutex_exit(&qcn_state->qcn_lock); 10837c478bd9Sstevel@tonic-gate 10847c478bd9Sstevel@tonic-gate return (0); 10857c478bd9Sstevel@tonic-gate } 1086