z8530tty.c revision 1.110
1/*	$NetBSD: z8530tty.c,v 1.110 2006/07/22 15:09:09 martin 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@NetBSD.org>,
132 *	Bill Studenmund <wrstuden@loki.stanford.edu>
133 *	Ian Dall <Ian.Dall@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.110 2006/07/22 15:09:09 martin 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 "locators.h"
166
167/*
168 * How many input characters we can buffer.
169 * The port-specific var.h may override this.
170 * Note: must be a power of two!
171 */
172#ifndef	ZSTTY_RING_SIZE
173#define	ZSTTY_RING_SIZE	2048
174#endif
175
176static struct cnm_state zstty_cnm_state;
177/*
178 * Make this an option variable one can patch.
179 * But be warned:  this must be a power of 2!
180 */
181u_int zstty_rbuf_size = ZSTTY_RING_SIZE;
182
183/* Stop input when 3/4 of the ring is full; restart when only 1/4 is full. */
184u_int zstty_rbuf_hiwat = (ZSTTY_RING_SIZE * 1) / 4;
185u_int zstty_rbuf_lowat = (ZSTTY_RING_SIZE * 3) / 4;
186
187#ifndef __HAVE_TIMECOUNTER
188static int zsppscap =
189	PPS_TSFMT_TSPEC |
190	PPS_CAPTUREASSERT |
191	PPS_CAPTURECLEAR |
192	PPS_OFFSETASSERT | PPS_OFFSETCLEAR;
193#endif /* __HAVE_TIMECOUNTER */
194
195struct zstty_softc {
196	struct	device zst_dev;		/* required first: base device */
197	struct  tty *zst_tty;
198	struct	zs_chanstate *zst_cs;
199
200	struct callout zst_diag_ch;
201
202	u_int zst_overflows,
203	      zst_floods,
204	      zst_errors;
205
206	int zst_hwflags,	/* see z8530var.h */
207	    zst_swflags;	/* TIOCFLAG_SOFTCAR, ... <ttycom.h> */
208
209	u_int zst_r_hiwat,
210	      zst_r_lowat;
211	u_char *volatile zst_rbget,
212	       *volatile zst_rbput;
213	volatile u_int zst_rbavail;
214	u_char *zst_rbuf,
215	       *zst_ebuf;
216
217	/*
218	 * The transmit byte count and address are used for pseudo-DMA
219	 * output in the hardware interrupt code.  PDMA can be suspended
220	 * to get pending changes done; heldtbc is used for this.  It can
221	 * also be stopped for ^S; this sets TS_TTSTOP in tp->t_state.
222	 */
223	u_char *zst_tba;		/* transmit buffer address */
224	u_int zst_tbc,			/* transmit byte count */
225	      zst_heldtbc;		/* held tbc while xmission stopped */
226
227	/* Flags to communicate with zstty_softint() */
228	volatile u_char zst_rx_flags,	/* receiver blocked */
229#define	RX_TTY_BLOCKED		0x01
230#define	RX_TTY_OVERFLOWED	0x02
231#define	RX_IBUF_BLOCKED		0x04
232#define	RX_IBUF_OVERFLOWED	0x08
233#define	RX_ANY_BLOCK		0x0f
234			zst_tx_busy,	/* working on an output chunk */
235			zst_tx_done,	/* done with one output chunk */
236			zst_tx_stopped,	/* H/W level stop (lost CTS) */
237			zst_st_check,	/* got a status interrupt */
238			zst_rx_ready;
239
240	/* PPS signal on DCD, with or without inkernel clock disciplining */
241	u_char  zst_ppsmask;			/* pps signal mask */
242#ifdef __HAVE_TIMECOUNTER
243	struct pps_state zst_pps_state;
244#else /* !__HAVE_TIMECOUNTER */
245	u_char  zst_ppsassert;			/* pps leading edge */
246	u_char  zst_ppsclear;			/* pps trailing edge */
247	pps_info_t ppsinfo;
248	pps_params_t ppsparam;
249#endif /* !__HAVE_TIMECOUNTER */
250};
251
252/* Definition of the driver for autoconfig. */
253static int	zstty_match(struct device *, struct cfdata *, void *);
254static void	zstty_attach(struct device *, struct device *, void *);
255
256CFATTACH_DECL(zstty, sizeof(struct zstty_softc),
257    zstty_match, zstty_attach, NULL, NULL);
258
259extern struct cfdriver zstty_cd;
260
261dev_type_open(zsopen);
262dev_type_close(zsclose);
263dev_type_read(zsread);
264dev_type_write(zswrite);
265dev_type_ioctl(zsioctl);
266dev_type_stop(zsstop);
267dev_type_tty(zstty);
268dev_type_poll(zspoll);
269
270const struct cdevsw zstty_cdevsw = {
271	zsopen, zsclose, zsread, zswrite, zsioctl,
272	zsstop, zstty, zspoll, nommap, ttykqfilter, D_TTY
273};
274
275struct zsops zsops_tty;
276
277static void zs_shutdown(struct zstty_softc *);
278static void	zsstart(struct tty *);
279static int	zsparam(struct tty *, struct termios *);
280static void zs_modem(struct zstty_softc *, int);
281static void tiocm_to_zs(struct zstty_softc *, u_long, int);
282static int  zs_to_tiocm(struct zstty_softc *);
283static int    zshwiflow(struct tty *, int);
284static void  zs_hwiflow(struct zstty_softc *);
285static void zs_maskintr(struct zstty_softc *);
286
287/* Low-level routines. */
288static void zstty_rxint  (struct zs_chanstate *);
289static void zstty_stint  (struct zs_chanstate *, int);
290static void zstty_txint  (struct zs_chanstate *);
291static void zstty_softint(struct zs_chanstate *);
292
293#define	ZSUNIT(x)	(minor(x) & 0x7ffff)
294#define	ZSDIALOUT(x)	(minor(x) & 0x80000)
295
296struct tty *zstty_get_tty_from_dev(struct device *);
297
298/*
299 * XXX get the (struct tty *) out of a (struct device *) we trust to be a
300 * (struct zstty_softc *) - needed by sparc/dev/zs.c, sparc64/dev/zs.c,
301 * sun3/dev/zs.c and sun2/dev/zs.c will probably need it at some point
302 */
303
304struct tty *
305zstty_get_tty_from_dev(struct device *dev)
306{
307	struct zstty_softc *sc = (struct zstty_softc *)dev;
308
309	return sc->zst_tty;
310}
311
312/*
313 * zstty_match: how is this zs channel configured?
314 */
315int
316zstty_match(parent, cf, aux)
317	struct device *parent;
318	struct cfdata *cf;
319	void   *aux;
320{
321	struct zsc_attach_args *args = aux;
322
323	/* Exact match is better than wildcard. */
324	if (cf->zsccf_channel == args->channel)
325		return 2;
326
327	/* This driver accepts wildcard. */
328	if (cf->zsccf_channel == ZSCCF_CHANNEL_DEFAULT)
329		return 1;
330
331	return 0;
332}
333
334void
335zstty_attach(parent, self, aux)
336	struct device *parent, *self;
337	void   *aux;
338
339{
340	struct zsc_softc *zsc = (void *) parent;
341	struct zstty_softc *zst = (void *) self;
342	struct cfdata *cf = device_cfdata(self);
343	struct zsc_attach_args *args = aux;
344	struct zs_chanstate *cs;
345	struct tty *tp;
346	int channel, s, tty_unit;
347	dev_t dev;
348	const char *i, *o;
349	int dtr_on;
350	int resetbit;
351
352	callout_init(&zst->zst_diag_ch);
353	cn_init_magic(&zstty_cnm_state);
354
355	tty_unit = device_unit(&zst->zst_dev);
356	channel = args->channel;
357	cs = zsc->zsc_cs[channel];
358	cs->cs_private = zst;
359	cs->cs_ops = &zsops_tty;
360
361	zst->zst_cs = cs;
362	zst->zst_swflags = cf->cf_flags;	/* softcar, etc. */
363	zst->zst_hwflags = args->hwflags;
364	dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), tty_unit);
365
366	if (zst->zst_swflags)
367		printf(" flags 0x%x", zst->zst_swflags);
368
369	/*
370	 * Check whether we serve as a console device.
371	 * XXX - split console input/output channels aren't
372	 *	 supported yet on /dev/console
373	 */
374	i = o = NULL;
375	if ((zst->zst_hwflags & ZS_HWFLAG_CONSOLE_INPUT) != 0) {
376		i = "input";
377		if ((args->hwflags & ZS_HWFLAG_USE_CONSDEV) != 0) {
378			args->consdev->cn_dev = dev;
379			cn_tab->cn_pollc = args->consdev->cn_pollc;
380			cn_tab->cn_getc = args->consdev->cn_getc;
381		}
382		cn_tab->cn_dev = dev;
383		/* Set console magic to BREAK */
384		cn_set_magic("\047\001");
385	}
386	if ((zst->zst_hwflags & ZS_HWFLAG_CONSOLE_OUTPUT) != 0) {
387		o = "output";
388		if ((args->hwflags & ZS_HWFLAG_USE_CONSDEV) != 0) {
389			cn_tab->cn_putc = args->consdev->cn_putc;
390		}
391		cn_tab->cn_dev = dev;
392	}
393	if (i != NULL || o != NULL)
394		printf(" (console %s)", i ? (o ? "i/o" : i) : o);
395
396#ifdef KGDB
397	if (zs_check_kgdb(cs, dev)) {
398		/*
399		 * Allow kgdb to "take over" this port.  Returns true
400		 * if this serial port is in-use by kgdb.
401		 */
402		printf(" (kgdb)\n");
403		/*
404		 * This is the kgdb port (exclusive use)
405		 * so skip the normal attach code.
406		 */
407		return;
408	}
409#endif
410	printf("\n");
411
412	tp = ttymalloc();
413	tp->t_dev = dev;
414	tp->t_oproc = zsstart;
415	tp->t_param = zsparam;
416	tp->t_hwiflow = zshwiflow;
417	tty_attach(tp);
418
419	zst->zst_tty = tp;
420	zst->zst_rbuf = malloc(zstty_rbuf_size << 1, M_DEVBUF, M_NOWAIT);
421	if (zst->zst_rbuf == NULL) {
422		aprint_error("%s: unable to allocate ring buffer\n",
423		    zst->zst_dev.dv_xname);
424		return;
425	}
426	zst->zst_ebuf = zst->zst_rbuf + (zstty_rbuf_size << 1);
427	/* Disable the high water mark. */
428	zst->zst_r_hiwat = 0;
429	zst->zst_r_lowat = 0;
430	zst->zst_rbget = zst->zst_rbput = zst->zst_rbuf;
431	zst->zst_rbavail = zstty_rbuf_size;
432
433	/* if there are no enable/disable functions, assume the device
434	   is always enabled */
435	if (!cs->enable)
436		cs->enabled = 1;
437
438	/*
439	 * Hardware init
440	 */
441	dtr_on = 0;
442	resetbit = 0;
443	if (ISSET(zst->zst_hwflags, ZS_HWFLAG_CONSOLE)) {
444		/* Call zsparam similar to open. */
445		struct termios t;
446
447		/* Wait a while for previous console output to complete */
448		DELAY(10000);
449
450		/* Setup the "new" parameters in t. */
451		t.c_ispeed = 0;
452		t.c_ospeed = cs->cs_defspeed;
453		t.c_cflag = cs->cs_defcflag;
454
455		/*
456		 * Turn on receiver and status interrupts.
457		 * We defer the actual write of the register to zsparam(),
458		 * but we must make sure status interrupts are turned on by
459		 * the time zsparam() reads the initial rr0 state.
460		 */
461		SET(cs->cs_preg[1], ZSWR1_RIE | ZSWR1_SIE);
462
463		/* Make sure zsparam will see changes. */
464		tp->t_ospeed = 0;
465		(void) zsparam(tp, &t);
466
467		/* Make sure DTR is on now. */
468		dtr_on = 1;
469
470	} else if (!ISSET(zst->zst_hwflags, ZS_HWFLAG_NORESET)) {
471		/* Not the console; may need reset. */
472		resetbit = (channel == 0) ? ZSWR9_A_RESET : ZSWR9_B_RESET;
473	}
474
475	s = splzs();
476	simple_lock(&cs->cs_lock);
477	if (resetbit)
478		zs_write_reg(cs, 9, resetbit);
479	zs_modem(zst, dtr_on);
480	simple_unlock(&cs->cs_lock);
481	splx(s);
482}
483
484
485/*
486 * Return pointer to our tty.
487 */
488struct tty *
489zstty(dev)
490	dev_t dev;
491{
492	struct zstty_softc *zst = device_lookup(&zstty_cd, ZSUNIT(dev));
493
494	return (zst->zst_tty);
495}
496
497
498void
499zs_shutdown(zst)
500	struct zstty_softc *zst;
501{
502	struct zs_chanstate *cs = zst->zst_cs;
503	struct tty *tp = zst->zst_tty;
504	int s;
505
506	s = splzs();
507	simple_lock(&cs->cs_lock);
508
509	/* If we were asserting flow control, then deassert it. */
510	SET(zst->zst_rx_flags, RX_IBUF_BLOCKED);
511	zs_hwiflow(zst);
512
513	/* Clear any break condition set with TIOCSBRK. */
514	zs_break(cs, 0);
515
516#ifndef __HAVE_TIMECOUNTER
517	/* Turn off PPS capture on last close. */
518	zst->zst_ppsmask = 0;
519	zst->ppsparam.mode = 0;
520#endif /* __HAVE_TIMECOUNTER */
521
522	/*
523	 * Hang up if necessary.  Wait a bit, so the other side has time to
524	 * notice even if we immediately open the port again.
525	 */
526	if (ISSET(tp->t_cflag, HUPCL)) {
527		zs_modem(zst, 0);
528		simple_unlock(&cs->cs_lock);
529		splx(s);
530		/*
531		 * XXX -    another process is not prevented from opening
532		 *	    the device during our sleep.
533		 */
534		(void) tsleep(cs, TTIPRI, ttclos, hz);
535		/* Re-check state in case we were opened during our sleep */
536		if (ISSET(tp->t_state, TS_ISOPEN) || tp->t_wopen != 0)
537			return;
538
539		s = splzs();
540		simple_lock(&cs->cs_lock);
541	}
542
543	/* Turn off interrupts if not the console. */
544	if (!ISSET(zst->zst_hwflags, ZS_HWFLAG_CONSOLE)) {
545		CLR(cs->cs_preg[1], ZSWR1_RIE | ZSWR1_SIE);
546		cs->cs_creg[1] = cs->cs_preg[1];
547		zs_write_reg(cs, 1, cs->cs_creg[1]);
548	}
549
550	/* Call the power management hook. */
551	if (cs->disable) {
552#ifdef DIAGNOSTIC
553		if (!cs->enabled)
554			panic("zs_shutdown: not enabled?");
555#endif
556		(*cs->disable)(zst->zst_cs);
557	}
558
559	simple_unlock(&cs->cs_lock);
560	splx(s);
561}
562
563/*
564 * Open a zs serial (tty) port.
565 */
566int
567zsopen(dev, flags, mode, l)
568	dev_t dev;
569	int flags;
570	int mode;
571	struct lwp *l;
572{
573	struct zstty_softc *zst;
574	struct zs_chanstate *cs;
575	struct tty *tp;
576	int s, s2;
577	int error;
578
579	zst = device_lookup(&zstty_cd, ZSUNIT(dev));
580	if (zst == NULL)
581		return (ENXIO);
582
583	tp = zst->zst_tty;
584	cs = zst->zst_cs;
585
586	/* If KGDB took the line, then tp==NULL */
587	if (tp == NULL)
588		return (EBUSY);
589
590	if (ISSET(tp->t_state, TS_ISOPEN) &&
591	    ISSET(tp->t_state, TS_XCLUDE) &&
592	    kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER,
593	    &l->l_acflag) != 0)
594		return (EBUSY);
595
596	s = spltty();
597
598	/*
599	 * Do the following iff this is a first open.
600	 */
601	if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
602		struct termios t;
603
604		tp->t_dev = dev;
605
606		/* Call the power management hook. */
607		if (cs->enable) {
608			if ((*cs->enable)(cs)) {
609				splx(s);
610				printf("%s: device enable failed\n",
611			       	zst->zst_dev.dv_xname);
612				return (EIO);
613			}
614		}
615
616		/*
617		 * Initialize the termios status to the defaults.  Add in the
618		 * sticky bits from TIOCSFLAGS.
619		 */
620		t.c_ispeed = 0;
621		t.c_ospeed = cs->cs_defspeed;
622		t.c_cflag = cs->cs_defcflag;
623		if (ISSET(zst->zst_swflags, TIOCFLAG_CLOCAL))
624			SET(t.c_cflag, CLOCAL);
625		if (ISSET(zst->zst_swflags, TIOCFLAG_CRTSCTS))
626			SET(t.c_cflag, CRTSCTS);
627		if (ISSET(zst->zst_swflags, TIOCFLAG_CDTRCTS))
628			SET(t.c_cflag, CDTRCTS);
629		if (ISSET(zst->zst_swflags, TIOCFLAG_MDMBUF))
630			SET(t.c_cflag, MDMBUF);
631
632		s2 = splzs();
633		simple_lock(&cs->cs_lock);
634
635		/*
636		 * Turn on receiver and status interrupts.
637		 * We defer the actual write of the register to zsparam(),
638		 * but we must make sure status interrupts are turned on by
639		 * the time zsparam() reads the initial rr0 state.
640		 */
641		SET(cs->cs_preg[1], ZSWR1_RIE | ZSWR1_SIE);
642
643		/* Clear PPS capture state on first open. */
644		zst->zst_ppsmask = 0;
645#ifdef __HAVE_TIMECOUNTER
646		memset(&zst->zst_pps_state, 0, sizeof(zst->zst_pps_state));
647		zst->zst_pps_state.ppscap = PPS_CAPTUREASSERT | PPS_CAPTURECLEAR;
648		pps_init(&zst->zst_pps_state);
649#else /* !__HAVE_TIMECOUNTER */
650		zst->ppsparam.mode = 0;
651#endif /* !__HAVE_TIMECOUNTER */
652
653		simple_unlock(&cs->cs_lock);
654		splx(s2);
655
656		/* Make sure zsparam will see changes. */
657		tp->t_ospeed = 0;
658		(void) zsparam(tp, &t);
659
660		/*
661		 * Note: zsparam has done: cflag, ispeed, ospeed
662		 * so we just need to do: iflag, oflag, lflag, cc
663		 * For "raw" mode, just leave all zeros.
664		 */
665		if (!ISSET(zst->zst_hwflags, ZS_HWFLAG_RAW)) {
666			tp->t_iflag = TTYDEF_IFLAG;
667			tp->t_oflag = TTYDEF_OFLAG;
668			tp->t_lflag = TTYDEF_LFLAG;
669		} else {
670			tp->t_iflag = 0;
671			tp->t_oflag = 0;
672			tp->t_lflag = 0;
673		}
674		ttychars(tp);
675		ttsetwater(tp);
676
677		s2 = splzs();
678		simple_lock(&cs->cs_lock);
679
680		/*
681		 * Turn on DTR.  We must always do this, even if carrier is not
682		 * present, because otherwise we'd have to use TIOCSDTR
683		 * immediately after setting CLOCAL, which applications do not
684		 * expect.  We always assert DTR while the device is open
685		 * unless explicitly requested to deassert it.
686		 */
687		zs_modem(zst, 1);
688
689		/* Clear the input ring, and unblock. */
690		zst->zst_rbget = zst->zst_rbput = zst->zst_rbuf;
691		zst->zst_rbavail = zstty_rbuf_size;
692		zs_iflush(cs);
693		CLR(zst->zst_rx_flags, RX_ANY_BLOCK);
694		zs_hwiflow(zst);
695
696		simple_unlock(&cs->cs_lock);
697		splx(s2);
698	}
699
700	splx(s);
701
702	error = ttyopen(tp, ZSDIALOUT(dev), ISSET(flags, O_NONBLOCK));
703	if (error)
704		goto bad;
705
706	error = (*tp->t_linesw->l_open)(dev, tp);
707	if (error)
708		goto bad;
709
710	return (0);
711
712bad:
713	if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
714		/*
715		 * We failed to open the device, and nobody else had it opened.
716		 * Clean up the state as appropriate.
717		 */
718		zs_shutdown(zst);
719	}
720
721	return (error);
722}
723
724/*
725 * Close a zs serial port.
726 */
727int
728zsclose(dev, flags, mode, l)
729	dev_t dev;
730	int flags;
731	int mode;
732	struct lwp *l;
733{
734	struct zstty_softc *zst = device_lookup(&zstty_cd, ZSUNIT(dev));
735	struct tty *tp = zst->zst_tty;
736
737	/* XXX This is for cons.c. */
738	if (!ISSET(tp->t_state, TS_ISOPEN))
739		return 0;
740
741	(*tp->t_linesw->l_close)(tp, flags);
742	ttyclose(tp);
743
744	if (!ISSET(tp->t_state, TS_ISOPEN) && tp->t_wopen == 0) {
745		/*
746		 * Although we got a last close, the device may still be in
747		 * use; e.g. if this was the dialout node, and there are still
748		 * processes waiting for carrier on the non-dialout node.
749		 */
750		zs_shutdown(zst);
751	}
752
753	return (0);
754}
755
756/*
757 * Read/write zs serial port.
758 */
759int
760zsread(dev, uio, flags)
761	dev_t dev;
762	struct uio *uio;
763	int flags;
764{
765	struct zstty_softc *zst = device_lookup(&zstty_cd, ZSUNIT(dev));
766	struct tty *tp = zst->zst_tty;
767
768	return ((*tp->t_linesw->l_read)(tp, uio, flags));
769}
770
771int
772zswrite(dev, uio, flags)
773	dev_t dev;
774	struct uio *uio;
775	int flags;
776{
777	struct zstty_softc *zst = device_lookup(&zstty_cd, ZSUNIT(dev));
778	struct tty *tp = zst->zst_tty;
779
780	return ((*tp->t_linesw->l_write)(tp, uio, flags));
781}
782
783int
784zspoll(dev, events, l)
785	dev_t dev;
786	int events;
787	struct lwp *l;
788{
789	struct zstty_softc *zst = device_lookup(&zstty_cd, ZSUNIT(dev));
790	struct tty *tp = zst->zst_tty;
791
792	return ((*tp->t_linesw->l_poll)(tp, events, l));
793}
794
795int
796zsioctl(dev, cmd, data, flag, l)
797	dev_t dev;
798	u_long cmd;
799	caddr_t data;
800	int flag;
801	struct lwp *l;
802{
803	struct zstty_softc *zst = device_lookup(&zstty_cd, ZSUNIT(dev));
804	struct zs_chanstate *cs = zst->zst_cs;
805	struct tty *tp = zst->zst_tty;
806	int error;
807	int s;
808
809	error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, l);
810	if (error != EPASSTHROUGH)
811		return (error);
812
813	error = ttioctl(tp, cmd, data, flag, l);
814	if (error != EPASSTHROUGH)
815		return (error);
816
817#ifdef	ZS_MD_IOCTL
818	error = ZS_MD_IOCTL(cs, cmd, data);
819	if (error != EPASSTHROUGH)
820		return (error);
821#endif	/* ZS_MD_IOCTL */
822
823	error = 0;
824
825	s = splzs();
826	simple_lock(&cs->cs_lock);
827
828	switch (cmd) {
829	case TIOCSBRK:
830		zs_break(cs, 1);
831		break;
832
833	case TIOCCBRK:
834		zs_break(cs, 0);
835		break;
836
837	case TIOCGFLAGS:
838		*(int *)data = zst->zst_swflags;
839		break;
840
841	case TIOCSFLAGS:
842		error = kauth_authorize_generic(l->l_cred, KAUTH_GENERIC_ISSUSER,
843		    &l->l_acflag);
844		if (error)
845			break;
846		zst->zst_swflags = *(int *)data;
847		break;
848
849	case TIOCSDTR:
850		zs_modem(zst, 1);
851		break;
852
853	case TIOCCDTR:
854		zs_modem(zst, 0);
855		break;
856
857	case TIOCMSET:
858	case TIOCMBIS:
859	case TIOCMBIC:
860		tiocm_to_zs(zst, cmd, *(int *)data);
861		break;
862
863	case TIOCMGET:
864		*(int *)data = zs_to_tiocm(zst);
865		break;
866
867#ifdef __HAVE_TIMECOUNTER
868	case PPS_IOC_CREATE:
869	case PPS_IOC_DESTROY:
870	case PPS_IOC_GETPARAMS:
871	case PPS_IOC_SETPARAMS:
872	case PPS_IOC_GETCAP:
873	case PPS_IOC_FETCH:
874#ifdef PPS_SYNC
875	case PPS_IOC_KCBIND:
876#endif
877		error = pps_ioctl(cmd, data, &zst->zst_pps_state);
878		if (zst->zst_pps_state.ppsparam.mode & PPS_CAPTUREBOTH)
879			zst->zst_ppsmask = ZSRR0_DCD;
880		else
881			zst->zst_ppsmask = 0;
882		break;
883#else /* !__HAVE_TIMECOUNTER */
884	case PPS_IOC_CREATE:
885		break;
886
887	case PPS_IOC_DESTROY:
888		break;
889
890	case PPS_IOC_GETPARAMS: {
891		pps_params_t *pp;
892		pp = (pps_params_t *)data;
893		*pp = zst->ppsparam;
894		break;
895	}
896
897	case PPS_IOC_SETPARAMS: {
898		pps_params_t *pp;
899		int mode;
900		if (cs->cs_rr0_pps == 0) {
901			error = EINVAL;
902			break;
903		}
904		pp = (pps_params_t *)data;
905		if (pp->mode & ~zsppscap) {
906			error = EINVAL;
907			break;
908		}
909		zst->ppsparam = *pp;
910		/*
911		 * compute masks from user-specified timestamp state.
912		 */
913		mode = zst->ppsparam.mode;
914		switch (mode & PPS_CAPTUREBOTH) {
915		case 0:
916			zst->zst_ppsmask = 0;
917			break;
918
919		case PPS_CAPTUREASSERT:
920			zst->zst_ppsmask = ZSRR0_DCD;
921			zst->zst_ppsassert = ZSRR0_DCD;
922			zst->zst_ppsclear = -1;
923			break;
924
925		case PPS_CAPTURECLEAR:
926			zst->zst_ppsmask = ZSRR0_DCD;
927			zst->zst_ppsassert = -1;
928			zst->zst_ppsclear = 0;
929			break;
930
931		case PPS_CAPTUREBOTH:
932			zst->zst_ppsmask = ZSRR0_DCD;
933			zst->zst_ppsassert = ZSRR0_DCD;
934			zst->zst_ppsclear = 0;
935			break;
936
937		default:
938			error = EINVAL;
939			break;
940		}
941
942		/*
943		 * Now update interrupts.
944		 */
945		zs_maskintr(zst);
946		/*
947		 * If nothing is being transmitted, set up new current values,
948		 * else mark them as pending.
949		 */
950		if (!cs->cs_heldchange) {
951			if (zst->zst_tx_busy) {
952				zst->zst_heldtbc = zst->zst_tbc;
953				zst->zst_tbc = 0;
954				cs->cs_heldchange = 1;
955			} else
956				zs_loadchannelregs(cs);
957		}
958
959		break;
960	}
961
962	case PPS_IOC_GETCAP:
963		*(int *)data = zsppscap;
964		break;
965
966	case PPS_IOC_FETCH: {
967		pps_info_t *pi;
968		pi = (pps_info_t *)data;
969		*pi = zst->ppsinfo;
970		break;
971	}
972
973#ifdef PPS_SYNC
974	case PPS_IOC_KCBIND: {
975		int edge = (*(int *)data) & PPS_CAPTUREBOTH;
976
977		if (edge == 0) {
978			/*
979			 * remove binding for this source; ignore
980			 * the request if this is not the current
981			 * hardpps source
982			 */
983			if (pps_kc_hardpps_source == zst) {
984				pps_kc_hardpps_source = NULL;
985				pps_kc_hardpps_mode = 0;
986			}
987		} else {
988			/*
989			 * bind hardpps to this source, replacing any
990			 * previously specified source or edges
991			 */
992			pps_kc_hardpps_source = zst;
993			pps_kc_hardpps_mode = edge;
994		}
995		break;
996	}
997#endif /* PPS_SYNC */
998#endif /* !__HAVE_TIMECOUNTER */
999
1000	case TIOCDCDTIMESTAMP:	/* XXX old, overloaded  API used by xntpd v3 */
1001		if (cs->cs_rr0_pps == 0) {
1002			error = EINVAL;
1003			break;
1004		}
1005#ifdef __HAVE_TIMECOUNTER
1006#ifndef PPS_TRAILING_EDGE
1007		TIMESPEC_TO_TIMEVAL((struct timeval *)data,
1008		    &zst->zst_pps_state.ppsinfo.assert_timestamp);
1009#else
1010		TIMESPEC_TO_TIMEVAL((struct timeval *)data,
1011		    &zst->zst_pps_state.ppsinfo.clear_timestamp);
1012#endif
1013#else /* !__HAVE_TIMECOUNTER */
1014		zst->zst_ppsmask = ZSRR0_DCD;
1015#ifndef	PPS_TRAILING_EDGE
1016		zst->zst_ppsassert = ZSRR0_DCD;
1017		zst->zst_ppsclear = -1;
1018		TIMESPEC_TO_TIMEVAL((struct timeval *)data,
1019			&zst->ppsinfo.assert_timestamp);
1020#else
1021		zst->zst_ppsassert = -1;
1022		zst->zst_ppsclear = 01;
1023		TIMESPEC_TO_TIMEVAL((struct timeval *)data,
1024			&zst->ppsinfo.clear_timestamp);
1025#endif
1026#endif /* !__HAVE_TIMECOUNTER */
1027		/*
1028		 * Now update interrupts.
1029		 */
1030		zs_maskintr(zst);
1031		/*
1032		 * If nothing is being transmitted, set up new current values,
1033		 * else mark them as pending.
1034		 */
1035		if (!cs->cs_heldchange) {
1036			if (zst->zst_tx_busy) {
1037				zst->zst_heldtbc = zst->zst_tbc;
1038				zst->zst_tbc = 0;
1039				cs->cs_heldchange = 1;
1040			} else
1041				zs_loadchannelregs(cs);
1042		}
1043
1044		break;
1045
1046	default:
1047		error = EPASSTHROUGH;
1048		break;
1049	}
1050
1051	simple_unlock(&cs->cs_lock);
1052	splx(s);
1053
1054	return (error);
1055}
1056
1057/*
1058 * Start or restart transmission.
1059 */
1060static void
1061zsstart(tp)
1062	struct tty *tp;
1063{
1064	struct zstty_softc *zst = device_lookup(&zstty_cd, ZSUNIT(tp->t_dev));
1065	struct zs_chanstate *cs = zst->zst_cs;
1066	u_char *tba;
1067	int s, tbc;
1068
1069	s = spltty();
1070	if (ISSET(tp->t_state, TS_BUSY | TS_TIMEOUT | TS_TTSTOP))
1071		goto out;
1072	if (zst->zst_tx_stopped)
1073		goto out;
1074
1075	if (tp->t_outq.c_cc <= tp->t_lowat) {
1076		if (ISSET(tp->t_state, TS_ASLEEP)) {
1077			CLR(tp->t_state, TS_ASLEEP);
1078			wakeup((caddr_t)&tp->t_outq);
1079		}
1080		selwakeup(&tp->t_wsel);
1081		if (tp->t_outq.c_cc == 0)
1082			goto out;
1083	}
1084
1085	/* Grab the first contiguous region of buffer space. */
1086	tba = tp->t_outq.c_cf;
1087	tbc = ndqb(&tp->t_outq, 0);
1088
1089	(void) splzs();
1090	simple_lock(&cs->cs_lock);
1091
1092	zst->zst_tba = tba;
1093	zst->zst_tbc = tbc;
1094	SET(tp->t_state, TS_BUSY);
1095	zst->zst_tx_busy = 1;
1096
1097#ifdef ZS_TXDMA
1098	if (zst->zst_tbc > 1) {
1099		zs_dma_setup(cs, zst->zst_tba, zst->zst_tbc);
1100		goto out;
1101	}
1102#endif
1103
1104	/* Enable transmit completion interrupts if necessary. */
1105	if (!ISSET(cs->cs_preg[1], ZSWR1_TIE)) {
1106		SET(cs->cs_preg[1], ZSWR1_TIE);
1107		cs->cs_creg[1] = cs->cs_preg[1];
1108		zs_write_reg(cs, 1, cs->cs_creg[1]);
1109	}
1110
1111	/* Output the first character of the contiguous buffer. */
1112	zs_write_data(cs, *zst->zst_tba);
1113	zst->zst_tbc--;
1114	zst->zst_tba++;
1115
1116	simple_unlock(&cs->cs_lock);
1117out:
1118	splx(s);
1119	return;
1120}
1121
1122/*
1123 * Stop output, e.g., for ^S or output flush.
1124 */
1125void
1126zsstop(tp, flag)
1127	struct tty *tp;
1128	int flag;
1129{
1130	struct zstty_softc *zst = device_lookup(&zstty_cd, ZSUNIT(tp->t_dev));
1131	int s;
1132
1133	s = splzs();
1134	if (ISSET(tp->t_state, TS_BUSY)) {
1135		/* Stop transmitting at the next chunk. */
1136		zst->zst_tbc = 0;
1137		zst->zst_heldtbc = 0;
1138		if (!ISSET(tp->t_state, TS_TTSTOP))
1139			SET(tp->t_state, TS_FLUSH);
1140	}
1141	splx(s);
1142}
1143
1144/*
1145 * Set ZS tty parameters from termios.
1146 * XXX - Should just copy the whole termios after
1147 * making sure all the changes could be done.
1148 */
1149static int
1150zsparam(tp, t)
1151	struct tty *tp;
1152	struct termios *t;
1153{
1154	struct zstty_softc *zst = device_lookup(&zstty_cd, ZSUNIT(tp->t_dev));
1155	struct zs_chanstate *cs = zst->zst_cs;
1156	int ospeed;
1157	tcflag_t cflag;
1158	u_char tmp3, tmp4, tmp5;
1159	int s, error;
1160
1161	ospeed = t->c_ospeed;
1162	cflag = t->c_cflag;
1163
1164	/* Check requested parameters. */
1165	if (ospeed < 0)
1166		return (EINVAL);
1167	if (t->c_ispeed && t->c_ispeed != ospeed)
1168		return (EINVAL);
1169
1170	/*
1171	 * For the console, always force CLOCAL and !HUPCL, so that the port
1172	 * is always active.
1173	 */
1174	if (ISSET(zst->zst_swflags, TIOCFLAG_SOFTCAR) ||
1175	    ISSET(zst->zst_hwflags, ZS_HWFLAG_CONSOLE)) {
1176		SET(cflag, CLOCAL);
1177		CLR(cflag, HUPCL);
1178	}
1179
1180	/*
1181	 * Only whack the UART when params change.
1182	 * Some callers need to clear tp->t_ospeed
1183	 * to make sure initialization gets done.
1184	 */
1185	if (tp->t_ospeed == ospeed &&
1186	    tp->t_cflag == cflag)
1187		return (0);
1188
1189	/*
1190	 * Call MD functions to deal with changed
1191	 * clock modes or H/W flow control modes.
1192	 * The BRG divisor is set now. (reg 12,13)
1193	 */
1194	error = zs_set_speed(cs, ospeed);
1195	if (error)
1196		return (error);
1197	error = zs_set_modes(cs, cflag);
1198	if (error)
1199		return (error);
1200
1201	/*
1202	 * Block interrupts so that state will not
1203	 * be altered until we are done setting it up.
1204	 *
1205	 * Initial values in cs_preg are set before
1206	 * our attach routine is called.  The master
1207	 * interrupt enable is handled by zsc.c
1208	 *
1209	 */
1210	s = splzs();
1211	simple_lock(&cs->cs_lock);
1212
1213	/*
1214	 * Recalculate which status ints to enable.
1215	 */
1216	zs_maskintr(zst);
1217
1218	/* Recompute character size bits. */
1219	tmp3 = cs->cs_preg[3];
1220	tmp5 = cs->cs_preg[5];
1221	CLR(tmp3, ZSWR3_RXSIZE);
1222	CLR(tmp5, ZSWR5_TXSIZE);
1223	switch (ISSET(cflag, CSIZE)) {
1224	case CS5:
1225		SET(tmp3, ZSWR3_RX_5);
1226		SET(tmp5, ZSWR5_TX_5);
1227		break;
1228	case CS6:
1229		SET(tmp3, ZSWR3_RX_6);
1230		SET(tmp5, ZSWR5_TX_6);
1231		break;
1232	case CS7:
1233		SET(tmp3, ZSWR3_RX_7);
1234		SET(tmp5, ZSWR5_TX_7);
1235		break;
1236	case CS8:
1237		SET(tmp3, ZSWR3_RX_8);
1238		SET(tmp5, ZSWR5_TX_8);
1239		break;
1240	}
1241	cs->cs_preg[3] = tmp3;
1242	cs->cs_preg[5] = tmp5;
1243
1244	/*
1245	 * Recompute the stop bits and parity bits.  Note that
1246	 * zs_set_speed() may have set clock selection bits etc.
1247	 * in wr4, so those must preserved.
1248	 */
1249	tmp4 = cs->cs_preg[4];
1250	CLR(tmp4, ZSWR4_SBMASK | ZSWR4_PARMASK);
1251	if (ISSET(cflag, CSTOPB))
1252		SET(tmp4, ZSWR4_TWOSB);
1253	else
1254		SET(tmp4, ZSWR4_ONESB);
1255	if (!ISSET(cflag, PARODD))
1256		SET(tmp4, ZSWR4_EVENP);
1257	if (ISSET(cflag, PARENB))
1258		SET(tmp4, ZSWR4_PARENB);
1259	cs->cs_preg[4] = tmp4;
1260
1261	/* And copy to tty. */
1262	tp->t_ispeed = 0;
1263	tp->t_ospeed = ospeed;
1264	tp->t_cflag = cflag;
1265
1266	/*
1267	 * If nothing is being transmitted, set up new current values,
1268	 * else mark them as pending.
1269	 */
1270	if (!cs->cs_heldchange) {
1271		if (zst->zst_tx_busy) {
1272			zst->zst_heldtbc = zst->zst_tbc;
1273			zst->zst_tbc = 0;
1274			cs->cs_heldchange = 1;
1275		} else
1276			zs_loadchannelregs(cs);
1277	}
1278
1279	/*
1280	 * If hardware flow control is disabled, turn off the buffer water
1281	 * marks and unblock any soft flow control state.  Otherwise, enable
1282	 * the water marks.
1283	 */
1284	if (!ISSET(cflag, CHWFLOW)) {
1285		zst->zst_r_hiwat = 0;
1286		zst->zst_r_lowat = 0;
1287		if (ISSET(zst->zst_rx_flags, RX_TTY_OVERFLOWED)) {
1288			CLR(zst->zst_rx_flags, RX_TTY_OVERFLOWED);
1289			zst->zst_rx_ready = 1;
1290			cs->cs_softreq = 1;
1291		}
1292		if (ISSET(zst->zst_rx_flags, RX_TTY_BLOCKED|RX_IBUF_BLOCKED)) {
1293			CLR(zst->zst_rx_flags, RX_TTY_BLOCKED|RX_IBUF_BLOCKED);
1294			zs_hwiflow(zst);
1295		}
1296	} else {
1297		zst->zst_r_hiwat = zstty_rbuf_hiwat;
1298		zst->zst_r_lowat = zstty_rbuf_lowat;
1299	}
1300
1301	/*
1302	 * Force a recheck of the hardware carrier and flow control status,
1303	 * since we may have changed which bits we're looking at.
1304	 */
1305	zstty_stint(cs, 1);
1306
1307	simple_unlock(&cs->cs_lock);
1308	splx(s);
1309
1310	/*
1311	 * If hardware flow control is disabled, unblock any hard flow control
1312	 * state.
1313	 */
1314	if (!ISSET(cflag, CHWFLOW)) {
1315		if (zst->zst_tx_stopped) {
1316			zst->zst_tx_stopped = 0;
1317			zsstart(tp);
1318		}
1319	}
1320
1321	zstty_softint(cs);
1322
1323	return (0);
1324}
1325
1326/*
1327 * Compute interrupt enable bits and set in the pending bits. Called both
1328 * in zsparam() and when PPS (pulse per second timing) state changes.
1329 * Must be called at splzs().
1330 */
1331static void
1332zs_maskintr(zst)
1333	struct zstty_softc *zst;
1334{
1335	struct zs_chanstate *cs = zst->zst_cs;
1336	int tmp15;
1337
1338	cs->cs_rr0_mask = cs->cs_rr0_cts | cs->cs_rr0_dcd;
1339	if (zst->zst_ppsmask != 0)
1340		cs->cs_rr0_mask |= cs->cs_rr0_pps;
1341	tmp15 = cs->cs_preg[15];
1342	if (ISSET(cs->cs_rr0_mask, ZSRR0_DCD))
1343		SET(tmp15, ZSWR15_DCD_IE);
1344	else
1345		CLR(tmp15, ZSWR15_DCD_IE);
1346	if (ISSET(cs->cs_rr0_mask, ZSRR0_CTS))
1347		SET(tmp15, ZSWR15_CTS_IE);
1348	else
1349		CLR(tmp15, ZSWR15_CTS_IE);
1350	cs->cs_preg[15] = tmp15;
1351}
1352
1353
1354/*
1355 * Raise or lower modem control (DTR/RTS) signals.  If a character is
1356 * in transmission, the change is deferred.
1357 * Called at splzs() and with the channel lock held.
1358 */
1359static void
1360zs_modem(zst, onoff)
1361	struct zstty_softc *zst;
1362	int onoff;
1363{
1364	struct zs_chanstate *cs = zst->zst_cs, *ccs;
1365
1366	if (cs->cs_wr5_dtr == 0)
1367		return;
1368
1369	ccs = (cs->cs_ctl_chan != NULL ? cs->cs_ctl_chan : cs);
1370
1371	if (onoff)
1372		SET(ccs->cs_preg[5], cs->cs_wr5_dtr);
1373	else
1374		CLR(ccs->cs_preg[5], cs->cs_wr5_dtr);
1375
1376	if (!cs->cs_heldchange) {
1377		if (zst->zst_tx_busy) {
1378			zst->zst_heldtbc = zst->zst_tbc;
1379			zst->zst_tbc = 0;
1380			cs->cs_heldchange = 1;
1381		} else
1382			zs_loadchannelregs(cs);
1383	}
1384}
1385
1386/*
1387 * Set modem bits.
1388 * Called at splzs() and with the channel lock held.
1389 */
1390static void
1391tiocm_to_zs(zst, how, ttybits)
1392	struct zstty_softc *zst;
1393	u_long how;
1394	int ttybits;
1395{
1396	struct zs_chanstate *cs = zst->zst_cs, *ccs;
1397	u_char zsbits;
1398
1399	ccs = (cs->cs_ctl_chan != NULL ? cs->cs_ctl_chan : cs);
1400
1401	zsbits = 0;
1402	if (ISSET(ttybits, TIOCM_DTR))
1403		SET(zsbits, ZSWR5_DTR);
1404	if (ISSET(ttybits, TIOCM_RTS))
1405		SET(zsbits, ZSWR5_RTS);
1406
1407	switch (how) {
1408	case TIOCMBIC:
1409		CLR(ccs->cs_preg[5], zsbits);
1410		break;
1411
1412	case TIOCMBIS:
1413		SET(ccs->cs_preg[5], zsbits);
1414		break;
1415
1416	case TIOCMSET:
1417		CLR(ccs->cs_preg[5], ZSWR5_RTS | ZSWR5_DTR);
1418		SET(ccs->cs_preg[5], zsbits);
1419		break;
1420	}
1421
1422	if (!cs->cs_heldchange) {
1423		if (zst->zst_tx_busy) {
1424			zst->zst_heldtbc = zst->zst_tbc;
1425			zst->zst_tbc = 0;
1426			cs->cs_heldchange = 1;
1427		} else
1428			zs_loadchannelregs(cs);
1429	}
1430}
1431
1432/*
1433 * Get modem bits.
1434 * Called at splzs() and with the channel lock held.
1435 */
1436static int
1437zs_to_tiocm(zst)
1438	struct zstty_softc *zst;
1439{
1440	struct zs_chanstate *cs = zst->zst_cs, *ccs;
1441	u_char zsbits;
1442	int ttybits = 0;
1443
1444	ccs = (cs->cs_ctl_chan != NULL ? cs->cs_ctl_chan : cs);
1445
1446	zsbits = ccs->cs_preg[5];
1447	if (ISSET(zsbits, ZSWR5_DTR))
1448		SET(ttybits, TIOCM_DTR);
1449	if (ISSET(zsbits, ZSWR5_RTS))
1450		SET(ttybits, TIOCM_RTS);
1451
1452	zsbits = cs->cs_rr0;
1453	if (ISSET(zsbits, ZSRR0_DCD))
1454		SET(ttybits, TIOCM_CD);
1455	if (ISSET(zsbits, ZSRR0_CTS))
1456		SET(ttybits, TIOCM_CTS);
1457
1458	return (ttybits);
1459}
1460
1461/*
1462 * Try to block or unblock input using hardware flow-control.
1463 * This is called by kern/tty.c if MDMBUF|CRTSCTS is set, and
1464 * if this function returns non-zero, the TS_TBLOCK flag will
1465 * be set or cleared according to the "block" arg passed.
1466 */
1467int
1468zshwiflow(tp, block)
1469	struct tty *tp;
1470	int block;
1471{
1472	struct zstty_softc *zst = device_lookup(&zstty_cd, ZSUNIT(tp->t_dev));
1473	struct zs_chanstate *cs = zst->zst_cs;
1474	int s;
1475
1476	if (cs->cs_wr5_rts == 0)
1477		return (0);
1478
1479	s = splzs();
1480	simple_lock(&cs->cs_lock);
1481	if (block) {
1482		if (!ISSET(zst->zst_rx_flags, RX_TTY_BLOCKED)) {
1483			SET(zst->zst_rx_flags, RX_TTY_BLOCKED);
1484			zs_hwiflow(zst);
1485		}
1486	} else {
1487		if (ISSET(zst->zst_rx_flags, RX_TTY_OVERFLOWED)) {
1488			CLR(zst->zst_rx_flags, RX_TTY_OVERFLOWED);
1489			zst->zst_rx_ready = 1;
1490			cs->cs_softreq = 1;
1491		}
1492		if (ISSET(zst->zst_rx_flags, RX_TTY_BLOCKED)) {
1493			CLR(zst->zst_rx_flags, RX_TTY_BLOCKED);
1494			zs_hwiflow(zst);
1495		}
1496	}
1497	simple_unlock(&cs->cs_lock);
1498	splx(s);
1499	return (1);
1500}
1501
1502/*
1503 * Internal version of zshwiflow
1504 * Called at splzs() and with the channel lock held.
1505 */
1506static void
1507zs_hwiflow(zst)
1508	struct zstty_softc *zst;
1509{
1510	struct zs_chanstate *cs = zst->zst_cs, *ccs;
1511
1512	if (cs->cs_wr5_rts == 0)
1513		return;
1514
1515	ccs = (cs->cs_ctl_chan != NULL ? cs->cs_ctl_chan : cs);
1516
1517	if (ISSET(zst->zst_rx_flags, RX_ANY_BLOCK)) {
1518		CLR(ccs->cs_preg[5], cs->cs_wr5_rts);
1519		CLR(ccs->cs_creg[5], cs->cs_wr5_rts);
1520	} else {
1521		SET(ccs->cs_preg[5], cs->cs_wr5_rts);
1522		SET(ccs->cs_creg[5], cs->cs_wr5_rts);
1523	}
1524	zs_write_reg(ccs, 5, ccs->cs_creg[5]);
1525}
1526
1527
1528/****************************************************************
1529 * Interface to the lower layer (zscc)
1530 ****************************************************************/
1531
1532#define	integrate	static inline
1533integrate void zstty_rxsoft(struct zstty_softc *, struct tty *);
1534integrate void zstty_txsoft(struct zstty_softc *, struct tty *);
1535integrate void zstty_stsoft(struct zstty_softc *, struct tty *);
1536static void zstty_diag(void *);
1537
1538/*
1539 * Receiver Ready interrupt.
1540 * Called at splzs() and with the channel lock held.
1541 */
1542static void
1543zstty_rxint(cs)
1544	struct zs_chanstate *cs;
1545{
1546	struct zstty_softc *zst = cs->cs_private;
1547	u_char *put, *end;
1548	u_int cc;
1549	u_char rr0, rr1, c;
1550
1551	end = zst->zst_ebuf;
1552	put = zst->zst_rbput;
1553	cc = zst->zst_rbavail;
1554
1555	while (cc > 0) {
1556		/*
1557		 * First read the status, because reading the received char
1558		 * destroys the status of this char.
1559		 */
1560		rr1 = zs_read_reg(cs, 1);
1561		c = zs_read_data(cs);
1562
1563		if (ISSET(rr1, ZSRR1_FE | ZSRR1_DO | ZSRR1_PE)) {
1564			/* Clear the receive error. */
1565			zs_write_csr(cs, ZSWR0_RESET_ERRORS);
1566		}
1567
1568		cn_check_magic(zst->zst_tty->t_dev, c, zstty_cnm_state);
1569		put[0] = c;
1570		put[1] = rr1;
1571		put += 2;
1572		if (put >= end)
1573			put = zst->zst_rbuf;
1574		cc--;
1575
1576		rr0 = zs_read_csr(cs);
1577		if (!ISSET(rr0, ZSRR0_RX_READY))
1578			break;
1579	}
1580
1581	/*
1582	 * Current string of incoming characters ended because
1583	 * no more data was available or we ran out of space.
1584	 * Schedule a receive event if any data was received.
1585	 * If we're out of space, turn off receive interrupts.
1586	 */
1587	zst->zst_rbput = put;
1588	zst->zst_rbavail = cc;
1589	if (!ISSET(zst->zst_rx_flags, RX_TTY_OVERFLOWED)) {
1590		zst->zst_rx_ready = 1;
1591		cs->cs_softreq = 1;
1592	}
1593
1594	/*
1595	 * See if we are in danger of overflowing a buffer. If
1596	 * so, use hardware flow control to ease the pressure.
1597	 */
1598	if (!ISSET(zst->zst_rx_flags, RX_IBUF_BLOCKED) &&
1599	    cc < zst->zst_r_hiwat) {
1600		SET(zst->zst_rx_flags, RX_IBUF_BLOCKED);
1601		zs_hwiflow(zst);
1602	}
1603
1604	/*
1605	 * If we're out of space, disable receive interrupts
1606	 * until the queue has drained a bit.
1607	 */
1608	if (!cc) {
1609		SET(zst->zst_rx_flags, RX_IBUF_OVERFLOWED);
1610		CLR(cs->cs_preg[1], ZSWR1_RIE);
1611		cs->cs_creg[1] = cs->cs_preg[1];
1612		zs_write_reg(cs, 1, cs->cs_creg[1]);
1613	}
1614
1615#if 0
1616	printf("%xH%04d\n", zst->zst_rx_flags, zst->zst_rbavail);
1617#endif
1618}
1619
1620/*
1621 * Transmitter Ready interrupt.
1622 * Called at splzs() and with the channel lock held.
1623 */
1624static void
1625zstty_txint(cs)
1626	struct zs_chanstate *cs;
1627{
1628	struct zstty_softc *zst = cs->cs_private;
1629
1630	/*
1631	 * If we've delayed a parameter change, do it now, and restart
1632	 * output.
1633	 */
1634	if (cs->cs_heldchange) {
1635		zs_loadchannelregs(cs);
1636		cs->cs_heldchange = 0;
1637		zst->zst_tbc = zst->zst_heldtbc;
1638		zst->zst_heldtbc = 0;
1639	}
1640
1641	/* Output the next character in the buffer, if any. */
1642	if (zst->zst_tbc > 0) {
1643		zs_write_data(cs, *zst->zst_tba);
1644		zst->zst_tbc--;
1645		zst->zst_tba++;
1646	} else {
1647		/* Disable transmit completion interrupts if necessary. */
1648		if (ISSET(cs->cs_preg[1], ZSWR1_TIE)) {
1649			CLR(cs->cs_preg[1], ZSWR1_TIE);
1650			cs->cs_creg[1] = cs->cs_preg[1];
1651			zs_write_reg(cs, 1, cs->cs_creg[1]);
1652		}
1653		if (zst->zst_tx_busy) {
1654			zst->zst_tx_busy = 0;
1655			zst->zst_tx_done = 1;
1656			cs->cs_softreq = 1;
1657		}
1658	}
1659}
1660
1661/*
1662 * Status Change interrupt.
1663 * Called at splzs() and with the channel lock held.
1664 */
1665static void
1666zstty_stint(cs, force)
1667	struct zs_chanstate *cs;
1668	int force;
1669{
1670	struct zstty_softc *zst = cs->cs_private;
1671	u_char rr0, delta;
1672
1673	rr0 = zs_read_csr(cs);
1674	zs_write_csr(cs, ZSWR0_RESET_STATUS);
1675
1676	/*
1677	 * Check here for console break, so that we can abort
1678	 * even when interrupts are locking up the machine.
1679	 */
1680	if (ISSET(rr0, ZSRR0_BREAK))
1681		cn_check_magic(zst->zst_tty->t_dev, CNC_BREAK, zstty_cnm_state);
1682
1683	if (!force)
1684		delta = rr0 ^ cs->cs_rr0;
1685	else
1686		delta = cs->cs_rr0_mask;
1687	cs->cs_rr0 = rr0;
1688
1689	if (ISSET(delta, cs->cs_rr0_mask)) {
1690		SET(cs->cs_rr0_delta, delta);
1691
1692		/*
1693		 * Pulse-per-second clock signal on edge of DCD?
1694		 */
1695		if (ISSET(delta, zst->zst_ppsmask)) {
1696#ifdef __HAVE_TIMECOUNTER
1697			if (zst->zst_pps_state.ppsparam.mode & PPS_CAPTUREBOTH) {
1698				pps_capture(&zst->zst_pps_state);
1699				pps_event(&zst->zst_pps_state,
1700				    (ISSET(cs->cs_rr0, zst->zst_ppsmask))
1701				    ? PPS_CAPTUREASSERT
1702				    : PPS_CAPTURECLEAR);
1703			}
1704#else /* !__HAVE_TIMECOUNTER */
1705			struct timeval tv;
1706			if (ISSET(rr0, zst->zst_ppsmask) == zst->zst_ppsassert) {
1707				/* XXX nanotime() */
1708				microtime(&tv);
1709				TIMEVAL_TO_TIMESPEC(&tv,
1710					&zst->ppsinfo.assert_timestamp);
1711				if (zst->ppsparam.mode & PPS_OFFSETASSERT) {
1712					timespecadd(&zst->ppsinfo.assert_timestamp,
1713					    &zst->ppsparam.assert_offset,
1714					    &zst->ppsinfo.assert_timestamp);
1715				}
1716
1717#ifdef PPS_SYNC
1718				if (pps_kc_hardpps_source == zst &&
1719				    pps_kc_hardpps_mode & PPS_CAPTUREASSERT) {
1720					hardpps(&tv, tv.tv_usec);
1721				}
1722#endif
1723				zst->ppsinfo.assert_sequence++;
1724				zst->ppsinfo.current_mode = zst->ppsparam.mode;
1725			} else if (ISSET(rr0, zst->zst_ppsmask) ==
1726						zst->zst_ppsclear) {
1727				/* XXX nanotime() */
1728				microtime(&tv);
1729				TIMEVAL_TO_TIMESPEC(&tv,
1730					&zst->ppsinfo.clear_timestamp);
1731				if (zst->ppsparam.mode & PPS_OFFSETCLEAR) {
1732					timespecadd(&zst->ppsinfo.clear_timestamp,
1733						&zst->ppsparam.clear_offset,
1734						&zst->ppsinfo.clear_timestamp);
1735				}
1736
1737#ifdef PPS_SYNC
1738				if (pps_kc_hardpps_source == zst &&
1739				    pps_kc_hardpps_mode & PPS_CAPTURECLEAR) {
1740					hardpps(&tv, tv.tv_usec);
1741				}
1742#endif
1743				zst->ppsinfo.clear_sequence++;
1744				zst->ppsinfo.current_mode = zst->ppsparam.mode;
1745			}
1746#endif /* !__HAVE_TIMECOUNTER */
1747		}
1748
1749		/*
1750		 * Stop output immediately if we lose the output
1751		 * flow control signal or carrier detect.
1752		 */
1753		if (ISSET(~rr0, cs->cs_rr0_mask)) {
1754			zst->zst_tbc = 0;
1755			zst->zst_heldtbc = 0;
1756		}
1757
1758		zst->zst_st_check = 1;
1759		cs->cs_softreq = 1;
1760	}
1761}
1762
1763void
1764zstty_diag(arg)
1765	void *arg;
1766{
1767	struct zstty_softc *zst = arg;
1768	int overflows, floods;
1769	int s;
1770
1771	s = splzs();
1772	overflows = zst->zst_overflows;
1773	zst->zst_overflows = 0;
1774	floods = zst->zst_floods;
1775	zst->zst_floods = 0;
1776	zst->zst_errors = 0;
1777	splx(s);
1778
1779	log(LOG_WARNING, "%s: %d silo overflow%s, %d ibuf flood%s\n",
1780	    zst->zst_dev.dv_xname,
1781	    overflows, overflows == 1 ? "" : "s",
1782	    floods, floods == 1 ? "" : "s");
1783}
1784
1785integrate void
1786zstty_rxsoft(zst, tp)
1787	struct zstty_softc *zst;
1788	struct tty *tp;
1789{
1790	struct zs_chanstate *cs = zst->zst_cs;
1791	int (*rint)(int, struct tty *) = tp->t_linesw->l_rint;
1792	u_char *get, *end;
1793	u_int cc, scc;
1794	u_char rr1;
1795	int code;
1796	int s;
1797
1798	end = zst->zst_ebuf;
1799	get = zst->zst_rbget;
1800	scc = cc = zstty_rbuf_size - zst->zst_rbavail;
1801
1802	if (cc == zstty_rbuf_size) {
1803		zst->zst_floods++;
1804		if (zst->zst_errors++ == 0)
1805			callout_reset(&zst->zst_diag_ch, 60 * hz,
1806			    zstty_diag, zst);
1807	}
1808
1809	/* If not yet open, drop the entire buffer content here */
1810	if (!ISSET(tp->t_state, TS_ISOPEN)) {
1811		get += cc << 1;
1812		if (get >= end)
1813			get -= zstty_rbuf_size << 1;
1814		cc = 0;
1815	}
1816	while (cc) {
1817		code = get[0];
1818		rr1 = get[1];
1819		if (ISSET(rr1, ZSRR1_DO | ZSRR1_FE | ZSRR1_PE)) {
1820			if (ISSET(rr1, ZSRR1_DO)) {
1821				zst->zst_overflows++;
1822				if (zst->zst_errors++ == 0)
1823					callout_reset(&zst->zst_diag_ch,
1824					    60 * hz, zstty_diag, zst);
1825			}
1826			if (ISSET(rr1, ZSRR1_FE))
1827				SET(code, TTY_FE);
1828			if (ISSET(rr1, ZSRR1_PE))
1829				SET(code, TTY_PE);
1830		}
1831		if ((*rint)(code, tp) == -1) {
1832			/*
1833			 * The line discipline's buffer is out of space.
1834			 */
1835			if (!ISSET(zst->zst_rx_flags, RX_TTY_BLOCKED)) {
1836				/*
1837				 * We're either not using flow control, or the
1838				 * line discipline didn't tell us to block for
1839				 * some reason.  Either way, we have no way to
1840				 * know when there's more space available, so
1841				 * just drop the rest of the data.
1842				 */
1843				get += cc << 1;
1844				if (get >= end)
1845					get -= zstty_rbuf_size << 1;
1846				cc = 0;
1847			} else {
1848				/*
1849				 * Don't schedule any more receive processing
1850				 * until the line discipline tells us there's
1851				 * space available (through comhwiflow()).
1852				 * Leave the rest of the data in the input
1853				 * buffer.
1854				 */
1855				SET(zst->zst_rx_flags, RX_TTY_OVERFLOWED);
1856			}
1857			break;
1858		}
1859		get += 2;
1860		if (get >= end)
1861			get = zst->zst_rbuf;
1862		cc--;
1863	}
1864
1865	if (cc != scc) {
1866		zst->zst_rbget = get;
1867		s = splzs();
1868		simple_lock(&cs->cs_lock);
1869		cc = zst->zst_rbavail += scc - cc;
1870		/* Buffers should be ok again, release possible block. */
1871		if (cc >= zst->zst_r_lowat) {
1872			if (ISSET(zst->zst_rx_flags, RX_IBUF_OVERFLOWED)) {
1873				CLR(zst->zst_rx_flags, RX_IBUF_OVERFLOWED);
1874				SET(cs->cs_preg[1], ZSWR1_RIE);
1875				cs->cs_creg[1] = cs->cs_preg[1];
1876				zs_write_reg(cs, 1, cs->cs_creg[1]);
1877			}
1878			if (ISSET(zst->zst_rx_flags, RX_IBUF_BLOCKED)) {
1879				CLR(zst->zst_rx_flags, RX_IBUF_BLOCKED);
1880				zs_hwiflow(zst);
1881			}
1882		}
1883		simple_unlock(&cs->cs_lock);
1884		splx(s);
1885	}
1886
1887#if 0
1888	printf("%xS%04d\n", zst->zst_rx_flags, zst->zst_rbavail);
1889#endif
1890}
1891
1892integrate void
1893zstty_txsoft(zst, tp)
1894	struct zstty_softc *zst;
1895	struct tty *tp;
1896{
1897	struct zs_chanstate *cs = zst->zst_cs;
1898	int s;
1899
1900	s = splzs();
1901	simple_lock(&cs->cs_lock);
1902	CLR(tp->t_state, TS_BUSY);
1903	if (ISSET(tp->t_state, TS_FLUSH))
1904		CLR(tp->t_state, TS_FLUSH);
1905	else
1906		ndflush(&tp->t_outq, (int)(zst->zst_tba - tp->t_outq.c_cf));
1907	simple_unlock(&cs->cs_lock);
1908	splx(s);
1909	(*tp->t_linesw->l_start)(tp);
1910}
1911
1912integrate void
1913zstty_stsoft(zst, tp)
1914	struct zstty_softc *zst;
1915	struct tty *tp;
1916{
1917	struct zs_chanstate *cs = zst->zst_cs;
1918	u_char rr0, delta;
1919	int s;
1920
1921	s = splzs();
1922	simple_lock(&cs->cs_lock);
1923	rr0 = cs->cs_rr0;
1924	delta = cs->cs_rr0_delta;
1925	cs->cs_rr0_delta = 0;
1926	simple_unlock(&cs->cs_lock);
1927	splx(s);
1928
1929	if (ISSET(delta, cs->cs_rr0_dcd)) {
1930		/*
1931		 * Inform the tty layer that carrier detect changed.
1932		 */
1933		(void) (*tp->t_linesw->l_modem)(tp, ISSET(rr0, ZSRR0_DCD));
1934	}
1935
1936	if (ISSET(delta, cs->cs_rr0_cts)) {
1937		/* Block or unblock output according to flow control. */
1938		if (ISSET(rr0, cs->cs_rr0_cts)) {
1939			zst->zst_tx_stopped = 0;
1940			(*tp->t_linesw->l_start)(tp);
1941		} else {
1942			zst->zst_tx_stopped = 1;
1943		}
1944	}
1945}
1946
1947/*
1948 * Software interrupt.  Called at zssoft
1949 *
1950 * The main job to be done here is to empty the input ring
1951 * by passing its contents up to the tty layer.  The ring is
1952 * always emptied during this operation, therefore the ring
1953 * must not be larger than the space after "high water" in
1954 * the tty layer, or the tty layer might drop our input.
1955 *
1956 * Note: an "input blockage" condition is assumed to exist if
1957 * EITHER the TS_TBLOCK flag or zst_rx_blocked flag is set.
1958 */
1959static void
1960zstty_softint(cs)
1961	struct zs_chanstate *cs;
1962{
1963	struct zstty_softc *zst = cs->cs_private;
1964	struct tty *tp = zst->zst_tty;
1965	int s;
1966
1967	s = spltty();
1968
1969	if (zst->zst_rx_ready) {
1970		zst->zst_rx_ready = 0;
1971		zstty_rxsoft(zst, tp);
1972	}
1973
1974	if (zst->zst_st_check) {
1975		zst->zst_st_check = 0;
1976		zstty_stsoft(zst, tp);
1977	}
1978
1979	if (zst->zst_tx_done) {
1980		zst->zst_tx_done = 0;
1981		zstty_txsoft(zst, tp);
1982	}
1983
1984	splx(s);
1985}
1986
1987struct zsops zsops_tty = {
1988	zstty_rxint,	/* receive char available */
1989	zstty_stint,	/* external/status */
1990	zstty_txint,	/* xmit buffer empty */
1991	zstty_softint,	/* process software interrupt */
1992};
1993
1994#ifdef ZS_TXDMA
1995void
1996zstty_txdma_int(arg)
1997	void *arg;
1998{
1999	struct zs_chanstate *cs = arg;
2000	struct zstty_softc *zst = cs->cs_private;
2001
2002	zst->zst_tba += zst->zst_tbc;
2003	zst->zst_tbc = 0;
2004
2005	if (zst->zst_tx_busy) {
2006		zst->zst_tx_busy = 0;
2007		zst->zst_tx_done = 1;
2008		cs->cs_softreq = 1;
2009	}
2010}
2011#endif
2012