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