Home | History | Annotate | Line # | Download | only in ic
      1 /*	$NetBSD: z8530tty.c,v 1.136 2026/11/10 03:05:01 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998, 1999
      5  *	Charles M. Hannum.  All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  * 3. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed by Charles M. Hannum.
     18  * 4. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  */
     32 
     33 /*
     34  * Copyright (c) 1992, 1993
     35  *	The Regents of the University of California.  All rights reserved.
     36  *
     37  * This software was developed by the Computer Systems Engineering group
     38  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     39  * contributed to Berkeley.
     40  *
     41  * All advertising materials mentioning features or use of this software
     42  * must display the following acknowledgement:
     43  *	This product includes software developed by the University of
     44  *	California, Lawrence Berkeley Laboratory.
     45  *
     46  * Redistribution and use in source and binary forms, with or without
     47  * modification, are permitted provided that the following conditions
     48  * are met:
     49  * 1. Redistributions of source code must retain the above copyright
     50  *    notice, this list of conditions and the following disclaimer.
     51  * 2. Redistributions in binary form must reproduce the above copyright
     52  *    notice, this list of conditions and the following disclaimer in the
     53  *    documentation and/or other materials provided with the distribution.
     54  * 3. Neither the name of the University nor the names of its contributors
     55  *    may be used to endorse or promote products derived from this software
     56  *    without specific prior written permission.
     57  *
     58  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68  * SUCH DAMAGE.
     69  *
     70  *	@(#)zs.c	8.1 (Berkeley) 7/19/93
     71  */
     72 
     73 /*
     74  * Copyright (c) 1994 Gordon W. Ross
     75  *
     76  * This software was developed by the Computer Systems Engineering group
     77  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
     78  * contributed to Berkeley.
     79  *
     80  * All advertising materials mentioning features or use of this software
     81  * must display the following acknowledgement:
     82  *	This product includes software developed by the University of
     83  *	California, Lawrence Berkeley Laboratory.
     84  *
     85  * Redistribution and use in source and binary forms, with or without
     86  * modification, are permitted provided that the following conditions
     87  * are met:
     88  * 1. Redistributions of source code must retain the above copyright
     89  *    notice, this list of conditions and the following disclaimer.
     90  * 2. Redistributions in binary form must reproduce the above copyright
     91  *    notice, this list of conditions and the following disclaimer in the
     92  *    documentation and/or other materials provided with the distribution.
     93  * 3. All advertising materials mentioning features or use of this software
     94  *    must display the following acknowledgement:
     95  *	This product includes software developed by the University of
     96  *	California, Berkeley and its contributors.
     97  * 4. Neither the name of the University nor the names of its contributors
     98  *    may be used to endorse or promote products derived from this software
     99  *    without specific prior written permission.
    100  *
    101  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
    102  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
    103  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
    104  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    105  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    106  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    107  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    108  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    109  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    110  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    111  * SUCH DAMAGE.
    112  *
    113  *	@(#)zs.c	8.1 (Berkeley) 7/19/93
    114  */
    115 
    116 /*
    117  * Zilog Z8530 Dual UART driver (tty interface)
    118  *
    119  * This is the "slave" driver that will be attached to
    120  * the "zsc" driver for plain "tty" async. serial lines.
    121  *
    122  * Credits, history:
    123  *
    124  * The original version of this code was the sparc/dev/zs.c driver
    125  * as distributed with the Berkeley 4.4 Lite release.  Since then,
    126  * Gordon Ross reorganized the code into the current parent/child
    127  * driver scheme, separating the Sun keyboard and mouse support
    128  * into independent child drivers.
    129  *
    130  * RTS/CTS flow-control support was a collaboration of:
    131  *	Gordon Ross <gwr (at) NetBSD.org>,
    132  *	Bill Studenmund <wrstuden (at) loki.stanford.edu>
    133  *	Ian Dall <Ian.Dall (at) dsto.defence.gov.au>
    134  *
    135  * The driver was massively overhauled in November 1997 by Charles Hannum,
    136  * fixing *many* bugs, and substantially improving performance.
    137  */
    138 
    139 #include <sys/cdefs.h>
    140 __KERNEL_RCSID(0, "$NetBSD: z8530tty.c,v 1.136 2026/11/10 03:05:01 thorpej Exp $");
    141 
    142 #include "opt_kgdb.h"
    143 #include "opt_ntp.h"
    144 
    145 #include <sys/param.h>
    146 #include <sys/systm.h>
    147 #include <sys/proc.h>
    148 #include <sys/device.h>
    149 #include <sys/conf.h>
    150 #include <sys/file.h>
    151 #include <sys/ioctl.h>
    152 #include <sys/malloc.h>
    153 #include <sys/timepps.h>
    154 #include <sys/tty.h>
    155 #include <sys/time.h>
    156 #include <sys/kernel.h>
    157 #include <sys/syslog.h>
    158 #include <sys/kauth.h>
    159 
    160 #include <dev/ic/z8530reg.h>
    161 #include <machine/z8530var.h>
    162 
    163 #include <dev/cons.h>
    164 
    165 #include "ioconf.h"
    166 #include "locators.h"
    167 
    168 /*
    169  * How many input characters we can buffer.
    170  * The port-specific var.h may override this.
    171  * Note: must be a power of two!
    172  */
    173 #ifndef	ZSTTY_RING_SIZE
    174 #define	ZSTTY_RING_SIZE	2048
    175 #endif
    176 
    177 static struct cnm_state zstty_cnm_state;
    178 /*
    179  * Make this an option variable one can patch.
    180  * But be warned:  this must be a power of 2!
    181  */
    182 u_int zstty_rbuf_size = ZSTTY_RING_SIZE;
    183 
    184 /* Stop input when 3/4 of the ring is full; restart when only 1/4 is full. */
    185 u_int zstty_rbuf_hiwat = (ZSTTY_RING_SIZE * 1) / 4;
    186 u_int zstty_rbuf_lowat = (ZSTTY_RING_SIZE * 3) / 4;
    187 
    188 struct zstty_softc {
    189 	device_t zst_dev;		/* required first: base device */
    190 	struct  tty *zst_tty;
    191 	struct	zs_chanstate *zst_cs;
    192 
    193 	struct callout zst_diag_ch;
    194 
    195 	u_int zst_overflows,
    196 	      zst_floods,
    197 	      zst_errors;
    198 
    199 	int zst_hwflags,	/* see z8530var.h */
    200 	    zst_swflags;	/* TIOCFLAG_SOFTCAR, ... <ttycom.h> */
    201 
    202 	u_int zst_r_hiwat,
    203 	      zst_r_lowat;
    204 	uint8_t *volatile zst_rbget,
    205 	        *volatile zst_rbput;
    206 	volatile u_int zst_rbavail;
    207 	uint8_t *zst_rbuf,
    208 	        *zst_ebuf;
    209 
    210 	/*
    211 	 * The transmit byte count and address are used for pseudo-DMA
    212 	 * output in the hardware interrupt code.  PDMA can be suspended
    213 	 * to get pending changes done; heldtbc is used for this.  It can
    214 	 * also be stopped for ^S; this sets TS_TTSTOP in tp->t_state.
    215 	 */
    216 	uint8_t *zst_tba;		/* transmit buffer address */
    217 	u_int zst_tbc,			/* transmit byte count */
    218 	      zst_heldtbc;		/* held tbc while xmission stopped */
    219 
    220 	/* Flags to communicate with zstty_softint() */
    221 	volatile uint8_t zst_rx_flags,	/* receiver blocked */
    222 #define	RX_TTY_BLOCKED		0x01
    223 #define	RX_TTY_OVERFLOWED	0x02
    224 #define	RX_IBUF_BLOCKED		0x04
    225 #define	RX_IBUF_OVERFLOWED	0x08
    226 #define	RX_ANY_BLOCK		0x0f
    227 			zst_tx_busy,	/* working on an output chunk */
    228 			zst_tx_done,	/* done with one output chunk */
    229 			zst_tx_stopped,	/* H/W level stop (lost CTS) */
    230 			zst_st_check,	/* got a status interrupt */
    231 			zst_rx_ready;
    232 
    233 	/* PPS signal on DCD, with or without inkernel clock disciplining */
    234 	uint8_t  zst_ppsmask;			/* pps signal mask */
    235 	struct pps_state zst_pps_state;
    236 };
    237 
    238 /* Definition of the driver for autoconfig. */
    239 static int	zstty_match(device_t, cfdata_t, void *);
    240 static void	zstty_attach(device_t, device_t, void *);
    241 
    242 CFATTACH_DECL_NEW(zstty, sizeof(struct zstty_softc),
    243     zstty_match, zstty_attach, NULL, NULL);
    244 
    245 dev_type_open(zsopen);
    246 dev_type_close(zsclose);
    247 dev_type_read(zsread);
    248 dev_type_write(zswrite);
    249 dev_type_ioctl(zsioctl);
    250 dev_type_stop(zsstop);
    251 dev_type_tty(zstty);
    252 dev_type_poll(zspoll);
    253 
    254 const struct cdevsw zstty_cdevsw = {
    255 	.d_open = zsopen,
    256 	.d_close = zsclose,
    257 	.d_read = zsread,
    258 	.d_write = zswrite,
    259 	.d_ioctl = zsioctl,
    260 	.d_stop = zsstop,
    261 	.d_tty = zstty,
    262 	.d_poll = zspoll,
    263 	.d_mmap = nommap,
    264 	.d_kqfilter = ttykqfilter,
    265 	.d_discard = nodiscard,
    266 	.d_flag = D_TTY
    267 };
    268 
    269 struct zsops zsops_tty;
    270 
    271 static void zs_shutdown(struct zstty_softc *);
    272 static void	zsstart(struct tty *);
    273 static int	zsparam(struct tty *, struct termios *);
    274 static void zs_modem(struct zstty_softc *, int);
    275 static void tiocm_to_zs(struct zstty_softc *, u_long, int);
    276 static int  zs_to_tiocm(struct zstty_softc *);
    277 static int    zshwiflow(struct tty *, int);
    278 static void  zs_hwiflow(struct zstty_softc *);
    279 static void zs_maskintr(struct zstty_softc *);
    280 
    281 /* Low-level routines. */
    282 static void zstty_rxint  (struct zs_chanstate *);
    283 static void zstty_stint  (struct zs_chanstate *, int);
    284 static void zstty_txint  (struct zs_chanstate *);
    285 static void zstty_softint(struct zs_chanstate *);
    286 static void zstty_softint1(struct zs_chanstate *);
    287 
    288 #define	ZSUNIT(x)	TTUNIT(x)
    289 #define	ZSDIALOUT(x)	TTDIALOUT(x)
    290 
    291 struct tty *zstty_get_tty_from_dev(device_t);
    292 
    293 /*
    294  * XXX get the (struct tty *) out of a (device_t) we trust to be a
    295  * (struct zstty_softc *) - needed by sparc/dev/zs.c, sparc64/dev/zs.c,
    296  * sun3/dev/zs.c and sun2/dev/zs.c will probably need it at some point
    297  */
    298 
    299 struct tty *
    300 zstty_get_tty_from_dev(device_t dev)
    301 {
    302 	struct zstty_softc *sc = device_private(dev);
    303 
    304 	return sc->zst_tty;
    305 }
    306 
    307 /*
    308  * zstty_match: how is this zs channel configured?
    309  */
    310 int
    311 zstty_match(device_t parent, cfdata_t cf, void *aux)
    312 {
    313 	struct zsc_attach_args *args = aux;
    314 
    315 	/* Exact match is better than wildcard. */
    316 	if (cf->zsccf_channel == args->channel)
    317 		return 2;
    318 
    319 	/* This driver accepts wildcard. */
    320 	if (cf->zsccf_channel == ZSCCF_CHANNEL_DEFAULT)
    321 		return 1;
    322 
    323 	return 0;
    324 }
    325 
    326 void
    327 zstty_attach(device_t parent, device_t self, void *aux)
    328 {
    329 	struct zstty_softc *zst = device_private(self);
    330 	struct zsc_softc *zsc = device_private(parent);
    331 	cfdata_t cf = device_cfdata(self);
    332 	struct zsc_attach_args *args = aux;
    333 	struct zs_chanstate *cs;
    334 	struct tty *tp;
    335 	int channel, tty_unit;
    336 	dev_t dev;
    337 	const char *i, *o;
    338 	int dtr_on;
    339 	int resetbit;
    340 
    341 	zst->zst_dev = self;
    342 
    343 	callout_init(&zst->zst_diag_ch, 0);
    344 	cn_init_magic(&zstty_cnm_state);
    345 #ifdef ZSTTY_CNMAGIC_ACTION
    346 	cn_set_magic_action(&zstty_cnm_state, ZSTTY_CNMAGIC_ACTION);
    347 #endif
    348 
    349 	tty_unit = device_unit(self);
    350 	channel = args->channel;
    351 	cs = zsc->zsc_cs[channel];
    352 	cs->cs_private = zst;
    353 	cs->cs_ops = &zsops_tty;
    354 
    355 	zst->zst_cs = cs;
    356 	zst->zst_swflags = cf->cf_flags;	/* softcar, etc. */
    357 	zst->zst_hwflags = args->hwflags;
    358 	dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), tty_unit);
    359 
    360 	if (zst->zst_swflags)
    361 		aprint_normal(" flags 0x%x", zst->zst_swflags);
    362 
    363 	/*
    364 	 * Check whether we serve as a console device.
    365 	 * XXX - split console input/output channels aren't
    366 	 *	 supported yet on /dev/console
    367 	 */
    368 	i = o = NULL;
    369 	if ((zst->zst_hwflags & ZS_HWFLAG_CONSOLE_INPUT) != 0) {
    370 		i = "input";
    371 		if ((args->hwflags & ZS_HWFLAG_USE_CONSDEV) != 0) {
    372 			args->consdev->cn_dev = dev;
    373 			cn_tab->cn_pollc = args->consdev->cn_pollc;
    374 			cn_tab->cn_getc = args->consdev->cn_getc;
    375 		}
    376 		cn_tab->cn_dev = dev;
    377 		/* Set console magic to BREAK */
    378 		cn_set_magic("\047\001");
    379 	}
    380 	if ((zst->zst_hwflags & ZS_HWFLAG_CONSOLE_OUTPUT) != 0) {
    381 		o = "output";
    382 		if ((args->hwflags & ZS_HWFLAG_USE_CONSDEV) != 0) {
    383 			cn_tab->cn_putc = args->consdev->cn_putc;
    384 		}
    385 		cn_tab->cn_dev = dev;
    386 	}
    387 	if (i != NULL || o != NULL)
    388 		aprint_normal(" (console %s)", i ? (o ? "i/o" : i) : o);
    389 
    390 #ifdef KGDB
    391 	if (zs_check_kgdb(cs, dev)) {
    392 		/*
    393 		 * Allow kgdb to "take over" this port.  Returns true
    394 		 * if this serial port is in-use by kgdb.
    395 		 */
    396 		aprint_normal(" (kgdb)\n");
    397 		/*
    398 		 * This is the kgdb port (exclusive use)
    399 		 * so skip the normal attach code.
    400 		 */
    401 		return;
    402 	}
    403 #endif
    404 	aprint_normal("\n");
    405 
    406 	tp = tty_alloc();
    407 	tp->t_dev = dev;
    408 	tp->t_oproc = zsstart;
    409 	tp->t_param = zsparam;
    410 	tp->t_hwiflow = zshwiflow;
    411 	tty_attach(tp);
    412 
    413 	zst->zst_tty = tp;
    414 	zst->zst_rbuf = malloc(zstty_rbuf_size << 1, M_DEVBUF, M_WAITOK);
    415 	zst->zst_ebuf = zst->zst_rbuf + (zstty_rbuf_size << 1);
    416 	/* Disable the high water mark. */
    417 	zst->zst_r_hiwat = 0;
    418 	zst->zst_r_lowat = 0;
    419 	zst->zst_rbget = zst->zst_rbput = zst->zst_rbuf;
    420 	zst->zst_rbavail = zstty_rbuf_size;
    421 
    422 	/* if there are no enable/disable functions, assume the device
    423 	   is always enabled */
    424 	if (!cs->enable)
    425 		cs->enabled = 1;
    426 
    427 	/*
    428 	 * Hardware init
    429 	 */
    430 	dtr_on = 0;
    431 	resetbit = 0;
    432 	if (ISSET(zst->zst_hwflags, ZS_HWFLAG_CONSOLE)) {
    433 		/* Call zsparam similar to open. */
    434 		struct termios t;
    435 
    436 		/* Wait a while for previous console output to complete */
    437 		DELAY(10000);
    438 
    439 		/* Setup the "new" parameters in t. */
    440 		t.c_ispeed = 0;
    441 		t.c_ospeed = cs->cs_defspeed;
    442 		t.c_cflag = cs->cs_defcflag;
    443 
    444 		/*
    445 		 * Turn on receiver and status interrupts.
    446 		 * We defer the actual write of the register to zsparam(),
    447 		 * but we must make sure status interrupts are turned on by
    448 		 * the time zsparam() reads the initial rr0 state.
    449 		 */
    450 		SET(cs->cs_preg[1], ZSWR1_RIE | ZSWR1_TIE | ZSWR1_SIE);
    451 
    452 		/* Make sure zsparam will see changes. */
    453 		tp->t_ospeed = 0;
    454 		(void) zsparam(tp, &t);
    455 
    456 		/* Make sure DTR is on now. */
    457 		dtr_on = 1;
    458 
    459 	} else if (!ISSET(zst->zst_hwflags, ZS_HWFLAG_NORESET)) {
    460 		/* Not the console; may need reset. */
    461 		resetbit = (channel == 0) ? ZSWR9_A_RESET : ZSWR9_B_RESET;
    462 	}
    463 
    464 	mutex_spin_enter(&cs->cs_lock);
    465 	if (resetbit)
    466 		zs_write_reg(cs, 9, resetbit);
    467 	zs_modem(zst, dtr_on);
    468 	mutex_spin_exit(&cs->cs_lock);
    469 }
    470 
    471 
    472 /*
    473  * Return pointer to our tty.
    474  */
    475 struct tty *
    476 zstty(dev_t dev)
    477 {
    478 	struct zstty_softc *zst;
    479 
    480 	zst = device_lookup_private(&zstty_cd, ZSUNIT(dev));
    481 
    482 	return (zst->zst_tty);
    483 }
    484 
    485 
    486 void
    487 zs_shutdown(struct zstty_softc *zst)
    488 {
    489 	struct zs_chanstate *cs = zst->zst_cs;
    490 	struct tty *tp = zst->zst_tty;
    491 
    492 	mutex_spin_enter(&cs->cs_lock);
    493 
    494 	/* If we were asserting flow control, then deassert it. */
    495 	SET(zst->zst_rx_flags, RX_IBUF_BLOCKED);
    496 	zs_hwiflow(zst);
    497 
    498 	/* Clear any break condition set with TIOCSBRK. */
    499 	zs_break(cs, 0);
    500 
    501 	/*
    502 	 * Hang up if necessary.  Wait a bit, so the other side has time to
    503 	 * notice even if we immediately open the port again.
    504 	 */
    505 	if (ISSET(tp->t_cflag, HUPCL)) {
    506 		zs_modem(zst, 0);
    507 		mutex_spin_exit(&cs->cs_lock);
    508 		/*
    509 		 * XXX -    another process is not prevented from opening
    510 		 *	    the device during our sleep.
    511 		 */
    512 		(void) tsleep(cs, TTIPRI, ttclos, hz);
    513 		/* Re-check state in case we were opened during our sleep */
    514 		if (ISSET(tp->t_state, TS_ISOPEN) || tp->t_wopen != 0)
    515 			return;
    516 
    517 		mutex_spin_enter(&cs->cs_lock);
    518 	}
    519 
    520 	/* Turn off interrupts if not the console. */
    521 	if (!ISSET(zst->zst_hwflags, ZS_HWFLAG_CONSOLE)) {
    522 		CLR(cs->cs_preg[1], ZSWR1_RIE | ZSWR1_TIE | ZSWR1_SIE);
    523 		cs->cs_creg[1] = cs->cs_preg[1];
    524 		zs_write_reg(cs, 1, cs->cs_creg[1]);
    525 	}
    526 
    527 	/* Call the power management hook. */
    528 	if (cs->disable) {
    529 #ifdef DIAGNOSTIC
    530 		if (!cs->enabled)
    531 			panic("%s: not enabled?", __func__);
    532 #endif
    533 		(*cs->disable)(zst->zst_cs);
    534 	}
    535 
    536 	mutex_spin_exit(&cs->cs_lock);
    537 }
    538 
    539 /*
    540  * Open a zs serial (tty) port.
    541  */
    542 int
    543 zsopen(dev_t dev, int flags, int mode, struct lwp *l)
    544 {
    545 	struct zstty_softc *zst;
    546 	struct zs_chanstate *cs;
    547 	struct tty *tp;
    548 	int error;
    549 
    550 	zst = device_lookup_private(&zstty_cd, ZSUNIT(dev));
    551 	if (zst == NULL)
    552 		return (ENXIO);
    553 
    554 	tp = zst->zst_tty;
    555 	cs = zst->zst_cs;
    556 
    557 	/* If KGDB took the line, then tp==NULL */
    558 	if (tp == NULL)
    559 		return (EBUSY);
    560 
    561 	/*
    562 	 * If the device is exclusively for kernel use, deny userland
    563 	 * open.
    564 	 */
    565 	if (ISSET(tp->t_state, TS_KERN_ONLY))
    566 		return (EBUSY);
    567 
    568 	if (kauth_authorize_device_tty(l->l_cred, KAUTH_DEVICE_TTY_OPEN, tp))
    569 		return (EBUSY);
    570 
    571 	ttylock(tp);
    572 
    573 	/*
    574 	 * Do the following iff this is a first open.
    575 	 */
    576 	if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
    577 		struct termios t;
    578 
    579 		tp->t_dev = dev;
    580 
    581 		/* Call the power management hook. */
    582 		if (cs->enable) {
    583 			if ((*cs->enable)(cs)) {
    584 				ttyunlock(tp);
    585 				printf("%s: device enable failed\n",
    586 				    device_xname(zst->zst_dev));
    587 				return (EIO);
    588 			}
    589 		}
    590 
    591 		/*
    592 		 * Initialize the termios status to the defaults.  Add in the
    593 		 * sticky bits from TIOCSFLAGS.
    594 		 */
    595 		t.c_ispeed = 0;
    596 		t.c_ospeed = cs->cs_defspeed;
    597 		t.c_cflag = cs->cs_defcflag;
    598 		if (ISSET(zst->zst_swflags, TIOCFLAG_CLOCAL))
    599 			SET(t.c_cflag, CLOCAL);
    600 		if (ISSET(zst->zst_swflags, TIOCFLAG_CRTSCTS))
    601 			SET(t.c_cflag, CRTSCTS);
    602 		if (ISSET(zst->zst_swflags, TIOCFLAG_CDTRCTS))
    603 			SET(t.c_cflag, CDTRCTS);
    604 		if (ISSET(zst->zst_swflags, TIOCFLAG_MDMBUF))
    605 			SET(t.c_cflag, MDMBUF);
    606 
    607 		mutex_spin_enter(&cs->cs_lock);
    608 
    609 		/*
    610 		 * Turn on receiver and status interrupts.
    611 		 * We defer the actual write of the register to zsparam(),
    612 		 * but we must make sure status interrupts are turned on by
    613 		 * the time zsparam() reads the initial rr0 state.
    614 		 */
    615 		SET(cs->cs_preg[1], ZSWR1_RIE | ZSWR1_TIE | ZSWR1_SIE);
    616 
    617 		/* Clear PPS capture state on first open. */
    618 		mutex_spin_enter(&timecounter_lock);
    619 		zst->zst_ppsmask = 0;
    620 		memset(&zst->zst_pps_state, 0, sizeof(zst->zst_pps_state));
    621 		zst->zst_pps_state.ppscap =
    622 		    PPS_CAPTUREASSERT | PPS_CAPTURECLEAR;
    623 		pps_init(&zst->zst_pps_state);
    624 		mutex_spin_exit(&timecounter_lock);
    625 
    626 		mutex_spin_exit(&cs->cs_lock);
    627 
    628 		/* Make sure zsparam will see changes. */
    629 		tp->t_ospeed = 0;
    630 		ttyunlock(tp);
    631 		(void) zsparam(tp, &t);
    632 		ttylock(tp);
    633 
    634 		/*
    635 		 * Note: zsparam has done: cflag, ispeed, ospeed
    636 		 * so we just need to do: iflag, oflag, lflag, cc
    637 		 * For "raw" mode, just leave all zeros.
    638 		 */
    639 		if (!ISSET(zst->zst_hwflags, ZS_HWFLAG_RAW)) {
    640 			tp->t_iflag = TTYDEF_IFLAG;
    641 			tp->t_oflag = TTYDEF_OFLAG;
    642 			tp->t_lflag = TTYDEF_LFLAG;
    643 		} else {
    644 			tp->t_iflag = 0;
    645 			tp->t_oflag = 0;
    646 			tp->t_lflag = 0;
    647 		}
    648 		ttychars(tp);
    649 		ttsetwater(tp);
    650 
    651 		mutex_spin_enter(&cs->cs_lock);
    652 
    653 		/*
    654 		 * Turn on DTR.  We must always do this, even if carrier is not
    655 		 * present, because otherwise we'd have to use TIOCSDTR
    656 		 * immediately after setting CLOCAL, which applications do not
    657 		 * expect.  We always assert DTR while the device is open
    658 		 * unless explicitly requested to deassert it.
    659 		 */
    660 		zs_modem(zst, 1);
    661 
    662 		/* Clear the input ring, and unblock. */
    663 		zst->zst_rbget = zst->zst_rbput = zst->zst_rbuf;
    664 		zst->zst_rbavail = zstty_rbuf_size;
    665 		zs_iflush(cs);
    666 		CLR(zst->zst_rx_flags, RX_ANY_BLOCK);
    667 		zs_hwiflow(zst);
    668 
    669 		mutex_spin_exit(&cs->cs_lock);
    670 	}
    671 
    672 	ttyunlock(tp);
    673 
    674 	error = ttyopen(tp, ZSDIALOUT(dev), ISSET(flags, O_NONBLOCK));
    675 	if (error)
    676 		goto bad;
    677 
    678 	error = (*tp->t_linesw->l_open)(dev, tp);
    679 	if (error)
    680 		goto bad;
    681 
    682 	return (0);
    683 
    684 bad:
    685 	if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
    686 		/*
    687 		 * We failed to open the device, and nobody else had it opened.
    688 		 * Clean up the state as appropriate.
    689 		 */
    690 		zs_shutdown(zst);
    691 	}
    692 
    693 	return (error);
    694 }
    695 
    696 /*
    697  * Close a zs serial port.
    698  */
    699 int
    700 zsclose(dev_t dev, int flags, int mode, struct lwp *l)
    701 {
    702 	struct zstty_softc *zst;
    703 	struct tty *tp;
    704 
    705 	zst = device_lookup_private(&zstty_cd, ZSUNIT(dev));
    706 	tp = zst->zst_tty;
    707 
    708 	/* XXX This is for cons.c. */
    709 	if (!ISSET(tp->t_state, TS_ISOPEN))
    710 		return 0;
    711 
    712 	(*tp->t_linesw->l_close)(tp, flags);
    713 	ttyclose(tp);
    714 
    715 	if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
    716 		/*
    717 		 * Although we got a last close, the device may still be in
    718 		 * use; e.g. if this was the dialout node, and there are still
    719 		 * processes waiting for carrier on the non-dialout node.
    720 		 */
    721 		zs_shutdown(zst);
    722 	}
    723 
    724 	return (0);
    725 }
    726 
    727 /*
    728  * Read/write zs serial port.
    729  */
    730 int
    731 zsread(dev_t dev, struct uio *uio, int flags)
    732 {
    733 	struct zstty_softc *zst;
    734 	struct tty *tp;
    735 
    736 	zst = device_lookup_private(&zstty_cd, ZSUNIT(dev));
    737 	tp = zst->zst_tty;
    738 
    739 	return ((*tp->t_linesw->l_read)(tp, uio, flags));
    740 }
    741 
    742 int
    743 zswrite(dev_t dev, struct uio *uio, int flags)
    744 {
    745 	struct zstty_softc *zst;
    746 	struct tty *tp;
    747 
    748 	zst = device_lookup_private(&zstty_cd, ZSUNIT(dev));
    749 	tp = zst->zst_tty;
    750 
    751 	return ((*tp->t_linesw->l_write)(tp, uio, flags));
    752 }
    753 
    754 int
    755 zspoll(dev_t dev, int events, struct lwp *l)
    756 {
    757 	struct zstty_softc *zst;
    758 	struct tty *tp;
    759 
    760 	zst = device_lookup_private(&zstty_cd, ZSUNIT(dev));
    761 	tp = zst->zst_tty;
    762 
    763 	return ((*tp->t_linesw->l_poll)(tp, events, l));
    764 }
    765 
    766 int
    767 zsioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
    768 {
    769 	struct zstty_softc *zst;
    770 	struct zs_chanstate *cs;
    771 	struct tty *tp;
    772 	int error;
    773 
    774 	zst = device_lookup_private(&zstty_cd, ZSUNIT(dev));
    775 	cs = zst->zst_cs;
    776 	tp = zst->zst_tty;
    777 	error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, l);
    778 	if (error != EPASSTHROUGH)
    779 		return (error);
    780 
    781 	error = ttioctl(tp, cmd, data, flag, l);
    782 	if (error != EPASSTHROUGH)
    783 		return (error);
    784 
    785 #ifdef	ZS_MD_IOCTL
    786 	error = ZS_MD_IOCTL(cs, cmd, data);
    787 	if (error != EPASSTHROUGH)
    788 		return (error);
    789 #endif	/* ZS_MD_IOCTL */
    790 
    791 	error = 0;
    792 
    793 	mutex_spin_enter(&cs->cs_lock);
    794 
    795 	switch (cmd) {
    796 	case TIOCSBRK:
    797 		zs_break(cs, 1);
    798 		break;
    799 
    800 	case TIOCCBRK:
    801 		zs_break(cs, 0);
    802 		break;
    803 
    804 	case TIOCGFLAGS:
    805 		*(int *)data = zst->zst_swflags;
    806 		break;
    807 
    808 	case TIOCSFLAGS:
    809 		error = kauth_authorize_device_tty(l->l_cred,
    810 			KAUTH_DEVICE_TTY_PRIVSET, tp);
    811 		if (error)
    812 			break;
    813 		zst->zst_swflags = *(int *)data;
    814 		break;
    815 
    816 	case TIOCSDTR:
    817 		zs_modem(zst, 1);
    818 		break;
    819 
    820 	case TIOCCDTR:
    821 		zs_modem(zst, 0);
    822 		break;
    823 
    824 	case TIOCMSET:
    825 	case TIOCMBIS:
    826 	case TIOCMBIC:
    827 		tiocm_to_zs(zst, cmd, *(int *)data);
    828 		break;
    829 
    830 	case TIOCMGET:
    831 		*(int *)data = zs_to_tiocm(zst);
    832 		break;
    833 
    834 	case PPS_IOC_CREATE:
    835 	case PPS_IOC_DESTROY:
    836 	case PPS_IOC_GETPARAMS:
    837 	case PPS_IOC_SETPARAMS:
    838 	case PPS_IOC_GETCAP:
    839 	case PPS_IOC_FETCH:
    840 #ifdef PPS_SYNC
    841 	case PPS_IOC_KCBIND:
    842 #endif
    843 		mutex_spin_enter(&timecounter_lock);
    844 		error = pps_ioctl(cmd, data, &zst->zst_pps_state);
    845 		if (zst->zst_pps_state.ppsparam.mode & PPS_CAPTUREBOTH)
    846 			zst->zst_ppsmask = ZSRR0_DCD;
    847 		else
    848 			zst->zst_ppsmask = 0;
    849 		mutex_spin_exit(&timecounter_lock);
    850 		break;
    851 
    852 	case TIOCDCDTIMESTAMP:	/* XXX old, overloaded  API used by xntpd v3 */
    853 		if (cs->cs_rr0_pps == 0) {
    854 			error = EINVAL;
    855 			break;
    856 		}
    857 		mutex_spin_enter(&timecounter_lock);
    858 #ifndef PPS_TRAILING_EDGE
    859 		TIMESPEC_TO_TIMEVAL((struct timeval *)data,
    860 		    &zst->zst_pps_state.ppsinfo.assert_timestamp);
    861 #else
    862 		TIMESPEC_TO_TIMEVAL((struct timeval *)data,
    863 		    &zst->zst_pps_state.ppsinfo.clear_timestamp);
    864 #endif
    865 		mutex_spin_exit(&timecounter_lock);
    866 		/*
    867 		 * Now update interrupts.
    868 		 */
    869 		zs_maskintr(zst);
    870 		/*
    871 		 * If nothing is being transmitted, set up new current values,
    872 		 * else mark them as pending.
    873 		 */
    874 		if (!cs->cs_heldchange) {
    875 			if (zst->zst_tx_busy) {
    876 				zst->zst_heldtbc = zst->zst_tbc;
    877 				zst->zst_tbc = 0;
    878 				cs->cs_heldchange = 1;
    879 			} else
    880 				zs_loadchannelregs(cs);
    881 		}
    882 
    883 		break;
    884 
    885 	default:
    886 		error = EPASSTHROUGH;
    887 		break;
    888 	}
    889 
    890 	mutex_spin_exit(&cs->cs_lock);
    891 
    892 	return (error);
    893 }
    894 
    895 /*
    896  * Start or restart transmission.
    897  */
    898 static void
    899 zsstart(struct tty *tp)
    900 {
    901 	struct zstty_softc *zst;
    902 	struct zs_chanstate *cs;
    903 	u_char *tba;
    904 	int tbc;
    905 
    906 	zst = device_lookup_private(&zstty_cd, ZSUNIT(tp->t_dev));
    907 	cs = zst->zst_cs;
    908 
    909 	if (ISSET(tp->t_state, TS_BUSY | TS_TIMEOUT | TS_TTSTOP))
    910 		return;
    911 	if (zst->zst_tx_stopped)
    912 		return;
    913 	if (!ttypull(tp))
    914 		return;
    915 
    916 	/* Grab the first contiguous region of buffer space. */
    917 	tba = tp->t_outq.c_cf;
    918 	tbc = ndqb(&tp->t_outq, 0);
    919 
    920 	mutex_spin_enter(&cs->cs_lock);
    921 
    922 	zst->zst_tba = tba;
    923 	zst->zst_tbc = tbc;
    924 	SET(tp->t_state, TS_BUSY);
    925 	zst->zst_tx_busy = 1;
    926 
    927 #ifdef ZS_TXDMA
    928 	if (zst->zst_tbc > 1) {
    929 		zs_dma_setup(cs, zst->zst_tba, zst->zst_tbc);
    930 		mutex_spin_exit(&cs->cs_lock);
    931 		return;
    932 	}
    933 #endif
    934 
    935 	/* Output the first character of the contiguous buffer. */
    936 	zs_write_data(cs, *zst->zst_tba);
    937 	zst->zst_tbc--;
    938 	zst->zst_tba++;
    939 
    940 	mutex_spin_exit(&cs->cs_lock);
    941 }
    942 
    943 /*
    944  * Stop output, e.g., for ^S or output flush.
    945  */
    946 void
    947 zsstop(struct tty *tp, int flag)
    948 {
    949 	struct zstty_softc *zst;
    950 
    951 	zst = device_lookup_private(&zstty_cd, ZSUNIT(tp->t_dev));
    952 
    953 	mutex_spin_enter(&zst->zst_cs->cs_lock);
    954 	if (ISSET(tp->t_state, TS_BUSY)) {
    955 		/* Stop transmitting at the next chunk. */
    956 		zst->zst_tbc = 0;
    957 		zst->zst_heldtbc = 0;
    958 		if (!ISSET(tp->t_state, TS_TTSTOP))
    959 			SET(tp->t_state, TS_FLUSH);
    960 	}
    961 	mutex_spin_exit(&zst->zst_cs->cs_lock);
    962 }
    963 
    964 /*
    965  * Set ZS tty parameters from termios.
    966  * XXX - Should just copy the whole termios after
    967  * making sure all the changes could be done.
    968  */
    969 static int
    970 zsparam(struct tty *tp, struct termios *t)
    971 {
    972 	struct zstty_softc *zst;
    973 	struct zs_chanstate *cs;
    974 	int ospeed;
    975 	tcflag_t cflag;
    976 	uint8_t tmp3, tmp4, tmp5;
    977 	int error;
    978 
    979 	zst = device_lookup_private(&zstty_cd, ZSUNIT(tp->t_dev));
    980 	cs = zst->zst_cs;
    981 	ospeed = t->c_ospeed;
    982 	cflag = t->c_cflag;
    983 
    984 	/* Check requested parameters. */
    985 	if (ospeed < 0)
    986 		return (EINVAL);
    987 	if (t->c_ispeed && t->c_ispeed != ospeed)
    988 		return (EINVAL);
    989 
    990 	/*
    991 	 * For the console, always force CLOCAL and !HUPCL, so that the port
    992 	 * is always active.
    993 	 */
    994 	if (ISSET(zst->zst_swflags, TIOCFLAG_SOFTCAR) ||
    995 	    ISSET(zst->zst_hwflags, ZS_HWFLAG_CONSOLE)) {
    996 		SET(cflag, CLOCAL);
    997 		CLR(cflag, HUPCL);
    998 	}
    999 
   1000 	/*
   1001 	 * Only whack the UART when params change.
   1002 	 * Some callers need to clear tp->t_ospeed
   1003 	 * to make sure initialization gets done.
   1004 	 */
   1005 	if (tp->t_ospeed == ospeed &&
   1006 	    tp->t_cflag == cflag)
   1007 		return (0);
   1008 
   1009 	/*
   1010 	 * Call MD functions to deal with changed
   1011 	 * clock modes or H/W flow control modes.
   1012 	 * The BRG divisor is set now. (reg 12,13)
   1013 	 */
   1014 	error = zs_set_speed(cs, ospeed);
   1015 	if (error)
   1016 		return (error);
   1017 	error = zs_set_modes(cs, cflag);
   1018 	if (error)
   1019 		return (error);
   1020 
   1021 	/*
   1022 	 * Block interrupts so that state will not
   1023 	 * be altered until we are done setting it up.
   1024 	 *
   1025 	 * Initial values in cs_preg are set before
   1026 	 * our attach routine is called.  The master
   1027 	 * interrupt enable is handled by zsc.c
   1028 	 *
   1029 	 */
   1030 	mutex_spin_enter(&cs->cs_lock);
   1031 
   1032 	/*
   1033 	 * Recalculate which status ints to enable.
   1034 	 */
   1035 	zs_maskintr(zst);
   1036 
   1037 	/* Recompute character size bits. */
   1038 	tmp3 = cs->cs_preg[3];
   1039 	tmp5 = cs->cs_preg[5];
   1040 	CLR(tmp3, ZSWR3_RXSIZE);
   1041 	CLR(tmp5, ZSWR5_TXSIZE);
   1042 	switch (ISSET(cflag, CSIZE)) {
   1043 	case CS5:
   1044 		SET(tmp3, ZSWR3_RX_5);
   1045 		SET(tmp5, ZSWR5_TX_5);
   1046 		break;
   1047 	case CS6:
   1048 		SET(tmp3, ZSWR3_RX_6);
   1049 		SET(tmp5, ZSWR5_TX_6);
   1050 		break;
   1051 	case CS7:
   1052 		SET(tmp3, ZSWR3_RX_7);
   1053 		SET(tmp5, ZSWR5_TX_7);
   1054 		break;
   1055 	case CS8:
   1056 		SET(tmp3, ZSWR3_RX_8);
   1057 		SET(tmp5, ZSWR5_TX_8);
   1058 		break;
   1059 	}
   1060 	cs->cs_preg[3] = tmp3;
   1061 	cs->cs_preg[5] = tmp5;
   1062 
   1063 	/*
   1064 	 * Recompute the stop bits and parity bits.  Note that
   1065 	 * zs_set_speed() may have set clock selection bits etc.
   1066 	 * in wr4, so those must preserved.
   1067 	 */
   1068 	tmp4 = cs->cs_preg[4];
   1069 	CLR(tmp4, ZSWR4_SBMASK | ZSWR4_PARMASK);
   1070 	if (ISSET(cflag, CSTOPB))
   1071 		SET(tmp4, ZSWR4_TWOSB);
   1072 	else
   1073 		SET(tmp4, ZSWR4_ONESB);
   1074 	if (!ISSET(cflag, PARODD))
   1075 		SET(tmp4, ZSWR4_EVENP);
   1076 	if (ISSET(cflag, PARENB))
   1077 		SET(tmp4, ZSWR4_PARENB);
   1078 	cs->cs_preg[4] = tmp4;
   1079 
   1080 	/* And copy to tty. */
   1081 	tp->t_ispeed = 0;
   1082 	tp->t_ospeed = ospeed;
   1083 	tp->t_cflag = cflag;
   1084 
   1085 	/*
   1086 	 * If nothing is being transmitted, set up new current values,
   1087 	 * else mark them as pending.
   1088 	 */
   1089 	if (!cs->cs_heldchange) {
   1090 		if (zst->zst_tx_busy) {
   1091 			zst->zst_heldtbc = zst->zst_tbc;
   1092 			zst->zst_tbc = 0;
   1093 			cs->cs_heldchange = 1;
   1094 		} else
   1095 			zs_loadchannelregs(cs);
   1096 	}
   1097 
   1098 	/*
   1099 	 * If hardware flow control is disabled, turn off the buffer water
   1100 	 * marks and unblock any soft flow control state.  Otherwise, enable
   1101 	 * the water marks.
   1102 	 */
   1103 	if (!ISSET(cflag, CHWFLOW)) {
   1104 		zst->zst_r_hiwat = 0;
   1105 		zst->zst_r_lowat = 0;
   1106 		if (ISSET(zst->zst_rx_flags, RX_TTY_OVERFLOWED)) {
   1107 			CLR(zst->zst_rx_flags, RX_TTY_OVERFLOWED);
   1108 			zst->zst_rx_ready = 1;
   1109 			cs->cs_softreq = 1;
   1110 		}
   1111 		if (ISSET(zst->zst_rx_flags, RX_TTY_BLOCKED|RX_IBUF_BLOCKED)) {
   1112 			CLR(zst->zst_rx_flags, RX_TTY_BLOCKED|RX_IBUF_BLOCKED);
   1113 			zs_hwiflow(zst);
   1114 		}
   1115 	} else {
   1116 		zst->zst_r_hiwat = zstty_rbuf_hiwat;
   1117 		zst->zst_r_lowat = zstty_rbuf_lowat;
   1118 	}
   1119 
   1120 	/*
   1121 	 * Force a recheck of the hardware carrier and flow control status,
   1122 	 * since we may have changed which bits we're looking at.
   1123 	 */
   1124 	zstty_stint(cs, 1);
   1125 
   1126 	mutex_spin_exit(&cs->cs_lock);
   1127 
   1128 	/*
   1129 	 * If hardware flow control is disabled, unblock any hard flow control
   1130 	 * state.
   1131 	 */
   1132 	if (!ISSET(cflag, CHWFLOW)) {
   1133 		if (zst->zst_tx_stopped) {
   1134 			zst->zst_tx_stopped = 0;
   1135 			zsstart(tp);
   1136 		}
   1137 	}
   1138 
   1139 	zstty_softint1(cs);
   1140 
   1141 	return (0);
   1142 }
   1143 
   1144 /*
   1145  * Compute interrupt enable bits and set in the pending bits. Called both
   1146  * in zsparam() and when PPS (pulse per second timing) state changes.
   1147  * Must be called at splzs().
   1148  */
   1149 static void
   1150 zs_maskintr(struct zstty_softc *zst)
   1151 {
   1152 	struct zs_chanstate *cs = zst->zst_cs;
   1153 	uint8_t tmp15;
   1154 
   1155 	cs->cs_rr0_mask = cs->cs_rr0_cts | cs->cs_rr0_dcd;
   1156 	if (zst->zst_ppsmask != 0)
   1157 		cs->cs_rr0_mask |= cs->cs_rr0_pps;
   1158 	tmp15 = cs->cs_preg[15];
   1159 	if (ISSET(cs->cs_rr0_mask, ZSRR0_DCD))
   1160 		SET(tmp15, ZSWR15_DCD_IE);
   1161 	else
   1162 		CLR(tmp15, ZSWR15_DCD_IE);
   1163 	if (ISSET(cs->cs_rr0_mask, ZSRR0_CTS))
   1164 		SET(tmp15, ZSWR15_CTS_IE);
   1165 	else
   1166 		CLR(tmp15, ZSWR15_CTS_IE);
   1167 	cs->cs_preg[15] = tmp15;
   1168 }
   1169 
   1170 
   1171 /*
   1172  * Raise or lower modem control (DTR/RTS) signals.  If a character is
   1173  * in transmission, the change is deferred.
   1174  * Called at splzs() and with the channel lock held.
   1175  */
   1176 static void
   1177 zs_modem(struct zstty_softc *zst, int onoff)
   1178 {
   1179 	struct zs_chanstate *cs = zst->zst_cs, *ccs;
   1180 
   1181 	if (cs->cs_wr5_dtr == 0)
   1182 		return;
   1183 
   1184 	ccs = (cs->cs_ctl_chan != NULL ? cs->cs_ctl_chan : cs);
   1185 
   1186 	if (onoff)
   1187 		SET(ccs->cs_preg[5], cs->cs_wr5_dtr);
   1188 	else
   1189 		CLR(ccs->cs_preg[5], cs->cs_wr5_dtr);
   1190 
   1191 	if (!cs->cs_heldchange) {
   1192 		if (zst->zst_tx_busy) {
   1193 			zst->zst_heldtbc = zst->zst_tbc;
   1194 			zst->zst_tbc = 0;
   1195 			cs->cs_heldchange = 1;
   1196 		} else
   1197 			zs_loadchannelregs(cs);
   1198 	}
   1199 }
   1200 
   1201 /*
   1202  * Set modem bits.
   1203  * Called at splzs() and with the channel lock held.
   1204  */
   1205 static void
   1206 tiocm_to_zs(struct zstty_softc *zst, u_long how, int ttybits)
   1207 {
   1208 	struct zs_chanstate *cs = zst->zst_cs, *ccs;
   1209 	uint8_t zsbits;
   1210 
   1211 	ccs = (cs->cs_ctl_chan != NULL ? cs->cs_ctl_chan : cs);
   1212 
   1213 	zsbits = 0;
   1214 	if (ISSET(ttybits, TIOCM_DTR))
   1215 		SET(zsbits, ZSWR5_DTR);
   1216 	if (ISSET(ttybits, TIOCM_RTS))
   1217 		SET(zsbits, ZSWR5_RTS);
   1218 
   1219 	switch (how) {
   1220 	case TIOCMBIC:
   1221 		CLR(ccs->cs_preg[5], zsbits);
   1222 		break;
   1223 
   1224 	case TIOCMBIS:
   1225 		SET(ccs->cs_preg[5], zsbits);
   1226 		break;
   1227 
   1228 	case TIOCMSET:
   1229 		CLR(ccs->cs_preg[5], ZSWR5_RTS | ZSWR5_DTR);
   1230 		SET(ccs->cs_preg[5], zsbits);
   1231 		break;
   1232 	}
   1233 
   1234 	if (!cs->cs_heldchange) {
   1235 		if (zst->zst_tx_busy) {
   1236 			zst->zst_heldtbc = zst->zst_tbc;
   1237 			zst->zst_tbc = 0;
   1238 			cs->cs_heldchange = 1;
   1239 		} else
   1240 			zs_loadchannelregs(cs);
   1241 	}
   1242 }
   1243 
   1244 /*
   1245  * Get modem bits.
   1246  * Called at splzs() and with the channel lock held.
   1247  */
   1248 static int
   1249 zs_to_tiocm(struct zstty_softc *zst)
   1250 {
   1251 	struct zs_chanstate *cs = zst->zst_cs, *ccs;
   1252 	uint8_t zsbits;
   1253 	int ttybits = 0;
   1254 
   1255 	ccs = (cs->cs_ctl_chan != NULL ? cs->cs_ctl_chan : cs);
   1256 
   1257 	zsbits = ccs->cs_preg[5];
   1258 	if (ISSET(zsbits, ZSWR5_DTR))
   1259 		SET(ttybits, TIOCM_DTR);
   1260 	if (ISSET(zsbits, ZSWR5_RTS))
   1261 		SET(ttybits, TIOCM_RTS);
   1262 
   1263 	zsbits = cs->cs_rr0;
   1264 	if (ISSET(zsbits, ZSRR0_DCD))
   1265 		SET(ttybits, TIOCM_CD);
   1266 	if (ISSET(zsbits, ZSRR0_CTS))
   1267 		SET(ttybits, TIOCM_CTS);
   1268 
   1269 	return (ttybits);
   1270 }
   1271 
   1272 /*
   1273  * Try to block or unblock input using hardware flow-control.
   1274  * This is called by kern/tty.c if MDMBUF|CRTSCTS is set, and
   1275  * if this function returns non-zero, the TS_TBLOCK flag will
   1276  * be set or cleared according to the "block" arg passed.
   1277  */
   1278 int
   1279 zshwiflow(struct tty *tp, int block)
   1280 {
   1281 	struct zstty_softc *zst;
   1282 	struct zs_chanstate *cs;
   1283 
   1284 	zst = device_lookup_private(&zstty_cd, ZSUNIT(tp->t_dev));
   1285 	cs = zst->zst_cs;
   1286 
   1287 	if (cs->cs_wr5_rts == 0)
   1288 		return (0);
   1289 
   1290 	mutex_spin_enter(&cs->cs_lock);
   1291 	if (block) {
   1292 		if (!ISSET(zst->zst_rx_flags, RX_TTY_BLOCKED)) {
   1293 			SET(zst->zst_rx_flags, RX_TTY_BLOCKED);
   1294 			zs_hwiflow(zst);
   1295 		}
   1296 	} else {
   1297 		if (ISSET(zst->zst_rx_flags, RX_TTY_OVERFLOWED)) {
   1298 			CLR(zst->zst_rx_flags, RX_TTY_OVERFLOWED);
   1299 			zst->zst_rx_ready = 1;
   1300 			cs->cs_softreq = 1;
   1301 		}
   1302 		if (ISSET(zst->zst_rx_flags, RX_TTY_BLOCKED)) {
   1303 			CLR(zst->zst_rx_flags, RX_TTY_BLOCKED);
   1304 			zs_hwiflow(zst);
   1305 		}
   1306 	}
   1307 	mutex_spin_exit(&cs->cs_lock);
   1308 	return (1);
   1309 }
   1310 
   1311 /*
   1312  * Internal version of zshwiflow
   1313  * Called at splzs() and with the channel lock held.
   1314  */
   1315 static void
   1316 zs_hwiflow(struct zstty_softc *zst)
   1317 {
   1318 	struct zs_chanstate *cs = zst->zst_cs, *ccs;
   1319 
   1320 	if (cs->cs_wr5_rts == 0)
   1321 		return;
   1322 
   1323 	ccs = (cs->cs_ctl_chan != NULL ? cs->cs_ctl_chan : cs);
   1324 
   1325 	if (ISSET(zst->zst_rx_flags, RX_ANY_BLOCK)) {
   1326 		CLR(ccs->cs_preg[5], cs->cs_wr5_rts);
   1327 		CLR(ccs->cs_creg[5], cs->cs_wr5_rts);
   1328 	} else {
   1329 		SET(ccs->cs_preg[5], cs->cs_wr5_rts);
   1330 		SET(ccs->cs_creg[5], cs->cs_wr5_rts);
   1331 	}
   1332 	zs_write_reg(ccs, 5, ccs->cs_creg[5]);
   1333 }
   1334 
   1335 
   1336 /****************************************************************
   1337  * Interface to the lower layer (zscc)
   1338  ****************************************************************/
   1339 
   1340 #define	integrate	static inline
   1341 integrate void zstty_rxsoft(struct zstty_softc *, struct tty *);
   1342 integrate void zstty_txsoft(struct zstty_softc *, struct tty *);
   1343 integrate void zstty_stsoft(struct zstty_softc *, struct tty *);
   1344 static void zstty_diag(void *);
   1345 
   1346 /*
   1347  * Receiver Ready interrupt.
   1348  * Called at splzs() and with the channel lock held.
   1349  */
   1350 static void
   1351 zstty_rxint(struct zs_chanstate *cs)
   1352 {
   1353 	struct zstty_softc *zst = cs->cs_private;
   1354 	uint8_t *put, *end;
   1355 	u_int cc;
   1356 	uint8_t rr0, rr1, c;
   1357 
   1358 	end = zst->zst_ebuf;
   1359 	put = zst->zst_rbput;
   1360 	cc = zst->zst_rbavail;
   1361 
   1362 	while (cc > 0) {
   1363 		/*
   1364 		 * First read the status, because reading the received char
   1365 		 * destroys the status of this char.
   1366 		 */
   1367 		rr1 = zs_read_reg(cs, 1);
   1368 		c = zs_read_data(cs);
   1369 
   1370 		if (ISSET(rr1, ZSRR1_FE | ZSRR1_DO | ZSRR1_PE)) {
   1371 			/* Clear the receive error. */
   1372 			zs_write_csr(cs, ZSWR0_RESET_ERRORS);
   1373 		}
   1374 
   1375 		cn_check_magic(zst->zst_tty->t_dev, c, &zstty_cnm_state);
   1376 		put[0] = c;
   1377 		put[1] = rr1;
   1378 		put += 2;
   1379 		if (put >= end)
   1380 			put = zst->zst_rbuf;
   1381 		cc--;
   1382 
   1383 		rr0 = zs_read_csr(cs);
   1384 		if (!ISSET(rr0, ZSRR0_RX_READY))
   1385 			break;
   1386 	}
   1387 
   1388 	/*
   1389 	 * Current string of incoming characters ended because
   1390 	 * no more data was available or we ran out of space.
   1391 	 * Schedule a receive event if any data was received.
   1392 	 * If we're out of space, turn off receive interrupts.
   1393 	 */
   1394 	zst->zst_rbput = put;
   1395 	zst->zst_rbavail = cc;
   1396 	if (!ISSET(zst->zst_rx_flags, RX_TTY_OVERFLOWED)) {
   1397 		zst->zst_rx_ready = 1;
   1398 		cs->cs_softreq = 1;
   1399 	}
   1400 
   1401 	/*
   1402 	 * See if we are in danger of overflowing a buffer. If
   1403 	 * so, use hardware flow control to ease the pressure.
   1404 	 */
   1405 	if (!ISSET(zst->zst_rx_flags, RX_IBUF_BLOCKED) &&
   1406 	    cc < zst->zst_r_hiwat) {
   1407 		SET(zst->zst_rx_flags, RX_IBUF_BLOCKED);
   1408 		zs_hwiflow(zst);
   1409 	}
   1410 
   1411 	/*
   1412 	 * If we're out of space, disable receive interrupts
   1413 	 * until the queue has drained a bit.
   1414 	 */
   1415 	if (!cc) {
   1416 		SET(zst->zst_rx_flags, RX_IBUF_OVERFLOWED);
   1417 		CLR(cs->cs_preg[1], ZSWR1_RIE);
   1418 		cs->cs_creg[1] = cs->cs_preg[1];
   1419 		zs_write_reg(cs, 1, cs->cs_creg[1]);
   1420 	}
   1421 
   1422 #if 0
   1423 	printf("%xH%04d\n", zst->zst_rx_flags, zst->zst_rbavail);
   1424 #endif
   1425 }
   1426 
   1427 /*
   1428  * Transmitter Ready interrupt.
   1429  * Called at splzs() and with the channel lock held.
   1430  */
   1431 static void
   1432 zstty_txint(struct zs_chanstate *cs)
   1433 {
   1434 	struct zstty_softc *zst = cs->cs_private;
   1435 
   1436 	zs_write_csr(cs, ZSWR0_RESET_TXINT);
   1437 
   1438 	/*
   1439 	 * If we've delayed a parameter change, do it now, and restart
   1440 	 * output.
   1441 	 */
   1442 	if (cs->cs_heldchange) {
   1443 		zs_loadchannelregs(cs);
   1444 		cs->cs_heldchange = 0;
   1445 		zst->zst_tbc = zst->zst_heldtbc;
   1446 		zst->zst_heldtbc = 0;
   1447 	}
   1448 
   1449 	/* Output the next character in the buffer, if any. */
   1450 	if (zst->zst_tbc > 0) {
   1451 		zs_write_data(cs, *zst->zst_tba);
   1452 		zst->zst_tbc--;
   1453 		zst->zst_tba++;
   1454 	} else {
   1455 		if (zst->zst_tx_busy) {
   1456 			zst->zst_tx_busy = 0;
   1457 			zst->zst_tx_done = 1;
   1458 			cs->cs_softreq = 1;
   1459 		}
   1460 	}
   1461 }
   1462 
   1463 /*
   1464  * Status Change interrupt.
   1465  * Called at splzs() and with the channel lock held.
   1466  */
   1467 static void
   1468 zstty_stint(struct zs_chanstate *cs, int force)
   1469 {
   1470 	struct zstty_softc *zst = cs->cs_private;
   1471 	uint8_t rr0, delta;
   1472 
   1473 	rr0 = zs_read_csr(cs);
   1474 	zs_write_csr(cs, ZSWR0_RESET_STATUS);
   1475 
   1476 	/*
   1477 	 * Check here for console break, so that we can abort
   1478 	 * even when interrupts are locking up the machine.
   1479 	 */
   1480 	if (ISSET(rr0, ZSRR0_BREAK)) {
   1481 		cn_check_magic(zst->zst_tty->t_dev, CNC_BREAK,
   1482 			       &zstty_cnm_state);
   1483 	}
   1484 
   1485 	if (!force)
   1486 		delta = rr0 ^ cs->cs_rr0;
   1487 	else
   1488 		delta = cs->cs_rr0_mask;
   1489 	cs->cs_rr0 = rr0;
   1490 
   1491 	if (ISSET(delta, cs->cs_rr0_mask)) {
   1492 		SET(cs->cs_rr0_delta, delta);
   1493 
   1494 		/*
   1495 		 * Pulse-per-second clock signal on edge of DCD?
   1496 		 */
   1497 		if (ISSET(delta, zst->zst_ppsmask)) {
   1498 			if (zst->zst_pps_state.ppsparam.mode &
   1499 			    PPS_CAPTUREBOTH) {
   1500 				mutex_spin_enter(&timecounter_lock);
   1501 				pps_capture(&zst->zst_pps_state);
   1502 				pps_event(&zst->zst_pps_state,
   1503 				    (ISSET(cs->cs_rr0, zst->zst_ppsmask))
   1504 				    ? PPS_CAPTUREASSERT
   1505 				    : PPS_CAPTURECLEAR);
   1506 				mutex_spin_exit(&timecounter_lock);
   1507 			}
   1508 		}
   1509 
   1510 		/*
   1511 		 * Stop output immediately if we lose the output
   1512 		 * flow control signal or carrier detect.
   1513 		 */
   1514 		if (ISSET(~rr0, cs->cs_rr0_mask)) {
   1515 			zst->zst_tbc = 0;
   1516 			zst->zst_heldtbc = 0;
   1517 		}
   1518 
   1519 		zst->zst_st_check = 1;
   1520 		cs->cs_softreq = 1;
   1521 	}
   1522 }
   1523 
   1524 void
   1525 zstty_diag(void *arg)
   1526 {
   1527 	struct zstty_softc *zst = arg;
   1528 	int overflows, floods;
   1529 
   1530 	mutex_spin_enter(&zst->zst_cs->cs_lock);
   1531 	overflows = zst->zst_overflows;
   1532 	zst->zst_overflows = 0;
   1533 	floods = zst->zst_floods;
   1534 	zst->zst_floods = 0;
   1535 	zst->zst_errors = 0;
   1536 	mutex_spin_exit(&zst->zst_cs->cs_lock);
   1537 
   1538 	log(LOG_WARNING, "%s: %d silo overflow%s, %d ibuf flood%s\n",
   1539 	    device_xname(zst->zst_dev),
   1540 	    overflows, overflows == 1 ? "" : "s",
   1541 	    floods, floods == 1 ? "" : "s");
   1542 }
   1543 
   1544 integrate void
   1545 zstty_rxsoft(struct zstty_softc *zst, struct tty *tp)
   1546 {
   1547 	struct zs_chanstate *cs = zst->zst_cs;
   1548 	int (*rint)(int, struct tty *) = tp->t_linesw->l_rint;
   1549 	uint8_t *get, *end;
   1550 	u_int cc, scc;
   1551 	uint8_t rr1;
   1552 	int code;
   1553 
   1554 	end = zst->zst_ebuf;
   1555 	get = zst->zst_rbget;
   1556 	scc = cc = zstty_rbuf_size - zst->zst_rbavail;
   1557 
   1558 	if (cc == zstty_rbuf_size) {
   1559 		zst->zst_floods++;
   1560 		if (zst->zst_errors++ == 0)
   1561 			callout_reset(&zst->zst_diag_ch, 60 * hz,
   1562 			    zstty_diag, zst);
   1563 	}
   1564 
   1565 	/* If not yet open, drop the entire buffer content here */
   1566 	if (!ISSET(tp->t_state, TS_ISOPEN)) {
   1567 		get += cc << 1;
   1568 		if (get >= end)
   1569 			get -= zstty_rbuf_size << 1;
   1570 		cc = 0;
   1571 	}
   1572 	while (cc) {
   1573 		code = get[0];
   1574 		rr1 = get[1];
   1575 		if (ISSET(rr1, ZSRR1_DO | ZSRR1_FE | ZSRR1_PE)) {
   1576 			if (ISSET(rr1, ZSRR1_DO)) {
   1577 				zst->zst_overflows++;
   1578 				if (zst->zst_errors++ == 0)
   1579 					callout_reset(&zst->zst_diag_ch,
   1580 					    60 * hz, zstty_diag, zst);
   1581 			}
   1582 			if (ISSET(rr1, ZSRR1_FE))
   1583 				SET(code, TTY_FE);
   1584 			if (ISSET(rr1, ZSRR1_PE))
   1585 				SET(code, TTY_PE);
   1586 		}
   1587 		if ((*rint)(code, tp) == -1) {
   1588 			/*
   1589 			 * The line discipline's buffer is out of space.
   1590 			 */
   1591 			if (!ISSET(zst->zst_rx_flags, RX_TTY_BLOCKED)) {
   1592 				/*
   1593 				 * We're either not using flow control, or the
   1594 				 * line discipline didn't tell us to block for
   1595 				 * some reason.  Either way, we have no way to
   1596 				 * know when there's more space available, so
   1597 				 * just drop the rest of the data.
   1598 				 */
   1599 				get += cc << 1;
   1600 				if (get >= end)
   1601 					get -= zstty_rbuf_size << 1;
   1602 				cc = 0;
   1603 			} else {
   1604 				/*
   1605 				 * Don't schedule any more receive processing
   1606 				 * until the line discipline tells us there's
   1607 				 * space available (through comhwiflow()).
   1608 				 * Leave the rest of the data in the input
   1609 				 * buffer.
   1610 				 */
   1611 				SET(zst->zst_rx_flags, RX_TTY_OVERFLOWED);
   1612 			}
   1613 			break;
   1614 		}
   1615 		get += 2;
   1616 		if (get >= end)
   1617 			get = zst->zst_rbuf;
   1618 		cc--;
   1619 	}
   1620 
   1621 	if (cc != scc) {
   1622 		zst->zst_rbget = get;
   1623 		mutex_spin_enter(&cs->cs_lock);
   1624 		cc = zst->zst_rbavail += scc - cc;
   1625 		/* Buffers should be ok again, release possible block. */
   1626 		if (cc >= zst->zst_r_lowat) {
   1627 			if (ISSET(zst->zst_rx_flags, RX_IBUF_OVERFLOWED)) {
   1628 				CLR(zst->zst_rx_flags, RX_IBUF_OVERFLOWED);
   1629 				SET(cs->cs_preg[1], ZSWR1_RIE);
   1630 				cs->cs_creg[1] = cs->cs_preg[1];
   1631 				zs_write_reg(cs, 1, cs->cs_creg[1]);
   1632 			}
   1633 			if (ISSET(zst->zst_rx_flags, RX_IBUF_BLOCKED)) {
   1634 				CLR(zst->zst_rx_flags, RX_IBUF_BLOCKED);
   1635 				zs_hwiflow(zst);
   1636 			}
   1637 		}
   1638 		mutex_spin_exit(&cs->cs_lock);
   1639 	}
   1640 
   1641 #if 0
   1642 	printf("%xS%04d\n", zst->zst_rx_flags, zst->zst_rbavail);
   1643 #endif
   1644 }
   1645 
   1646 integrate void
   1647 zstty_txsoft(struct zstty_softc *zst, struct tty *tp)
   1648 {
   1649 	struct zs_chanstate *cs = zst->zst_cs;
   1650 
   1651 	mutex_spin_enter(&cs->cs_lock);
   1652 	CLR(tp->t_state, TS_BUSY);
   1653 	if (ISSET(tp->t_state, TS_FLUSH))
   1654 		CLR(tp->t_state, TS_FLUSH);
   1655 	else
   1656 		ndflush(&tp->t_outq, (int)(zst->zst_tba - tp->t_outq.c_cf));
   1657 	mutex_spin_exit(&cs->cs_lock);
   1658 	(*tp->t_linesw->l_start)(tp);
   1659 }
   1660 
   1661 integrate void
   1662 zstty_stsoft(struct zstty_softc *zst, struct tty *tp)
   1663 {
   1664 	struct zs_chanstate *cs = zst->zst_cs;
   1665 	uint8_t rr0, delta;
   1666 
   1667 	mutex_spin_enter(&cs->cs_lock);
   1668 	rr0 = cs->cs_rr0;
   1669 	delta = cs->cs_rr0_delta;
   1670 	cs->cs_rr0_delta = 0;
   1671 	mutex_spin_exit(&cs->cs_lock);
   1672 
   1673 	if (ISSET(delta, cs->cs_rr0_dcd)) {
   1674 		/*
   1675 		 * Inform the tty layer that carrier detect changed.
   1676 		 */
   1677 		(void) (*tp->t_linesw->l_modem)(tp, ISSET(rr0, ZSRR0_DCD));
   1678 	}
   1679 
   1680 	if (ISSET(delta, cs->cs_rr0_cts)) {
   1681 		/* Block or unblock output according to flow control. */
   1682 		if (ISSET(rr0, cs->cs_rr0_cts)) {
   1683 			zst->zst_tx_stopped = 0;
   1684 			(*tp->t_linesw->l_start)(tp);
   1685 		} else {
   1686 			zst->zst_tx_stopped = 1;
   1687 		}
   1688 	}
   1689 }
   1690 
   1691 /*
   1692  * Software interrupt.  Called at zssoft
   1693  *
   1694  * The main job to be done here is to empty the input ring
   1695  * by passing its contents up to the tty layer.  The ring is
   1696  * always emptied during this operation, therefore the ring
   1697  * must not be larger than the space after "high water" in
   1698  * the tty layer, or the tty layer might drop our input.
   1699  *
   1700  * Note: an "input blockage" condition is assumed to exist if
   1701  * EITHER the TS_TBLOCK flag or zst_rx_blocked flag is set.
   1702  */
   1703 static void
   1704 zstty_softint(struct zs_chanstate *cs)
   1705 {
   1706 
   1707 	zstty_softint1(cs);
   1708 }
   1709 
   1710 static void
   1711 zstty_softint1(struct zs_chanstate *cs)
   1712 {
   1713 	struct zstty_softc *zst = cs->cs_private;
   1714 	struct tty *tp = zst->zst_tty;
   1715 
   1716 
   1717 	if (zst->zst_rx_ready) {
   1718 		zst->zst_rx_ready = 0;
   1719 		zstty_rxsoft(zst, tp);
   1720 	}
   1721 
   1722 	if (zst->zst_st_check) {
   1723 		zst->zst_st_check = 0;
   1724 		zstty_stsoft(zst, tp);
   1725 	}
   1726 
   1727 	if (zst->zst_tx_done) {
   1728 		zst->zst_tx_done = 0;
   1729 		zstty_txsoft(zst, tp);
   1730 	}
   1731 }
   1732 
   1733 struct zsops zsops_tty = {
   1734 	zstty_rxint,	/* receive char available */
   1735 	zstty_stint,	/* external/status */
   1736 	zstty_txint,	/* xmit buffer empty */
   1737 	zstty_softint,	/* process software interrupt */
   1738 };
   1739 
   1740 #ifdef ZS_TXDMA
   1741 void
   1742 zstty_txdma_int(void *arg)
   1743 {
   1744 	struct zs_chanstate *cs = arg;
   1745 	struct zstty_softc *zst = cs->cs_private;
   1746 
   1747 	zst->zst_tba += zst->zst_tbc;
   1748 	zst->zst_tbc = 0;
   1749 
   1750 	if (zst->zst_tx_busy) {
   1751 		zst->zst_tx_busy = 0;
   1752 		zst->zst_tx_done = 1;
   1753 		cs->cs_softreq = 1;
   1754 	}
   1755 }
   1756 #endif
   1757