digi.h revision 78412
114348Smichaelm/*-
214348Smichaelm * Copyright (c) 2001 Brian Somers <brian@Awfulhak.org>
314348Smichaelm *   based on work by Slawa Olhovchenkov
414348Smichaelm *                    John Prince <johnp@knight-trosoft.com>
514348Smichaelm *                    Eric Hernes
614348Smichaelm * All rights reserved.
714348Smichaelm *
814348Smichaelm * Redistribution and use in source and binary forms, with or without
914348Smichaelm * modification, are permitted provided that the following conditions
1014348Smichaelm * are met:
1114348Smichaelm * 1. Redistributions of source code must retain the above copyright
1214348Smichaelm *    notice, this list of conditions and the following disclaimer.
1314348Smichaelm * 2. Redistributions in binary form must reproduce the above copyright
1414348Smichaelm *    notice, this list of conditions and the following disclaimer in the
1514348Smichaelm *    documentation and/or other materials provided with the distribution.
1614348Smichaelm *
1714348Smichaelm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1814348Smichaelm * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1914348Smichaelm * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2014348Smichaelm * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2114348Smichaelm * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2214348Smichaelm * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2314348Smichaelm * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2414348Smichaelm * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2514348Smichaelm * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2616234Smichaelm * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2714348Smichaelm * SUCH DAMAGE.
2814348Smichaelm *
2914348Smichaelm * $FreeBSD: head/sys/dev/digi/digi.h 78412 2001-06-18 15:02:33Z brian $
3014348Smichaelm */
3114348Smichaelm
3214348Smichaelm#define	W(p)				(*(u_int16_t *)(p))
3314348Smichaelm#define	vW(p)				(*(u_int16_t volatile *)(p))
3414348Smichaelm#define	D(p)				(*(u_int32_t *)(p))
3514348Smichaelm#define	vD(p)				(*(u_int32_t volatile *)(p))
3616234Smichaelm
3716234Smichaelm#define	CE_OVERRUN			0
3814348Smichaelm#define	CE_INTERRUPT_BUF_OVERFLOW	1
3914348Smichaelm#define	CE_TTY_BUF_OVERFLOW		2
4014348Smichaelm#define	CE_NTYPES			3
4114348Smichaelm#define	CE_RECORD(com, errnum)		(++(com)->delta_error_counts[errnum])
4214348Smichaelm
4314348Smichaelm/*#define DIGI_INTERRUPT*/
4414348Smichaelm
4514348Smichaelm#ifndef DEBUG
4614348Smichaelm#define	DEBUG
4714348Smichaelm#endif
4814348Smichaelm
4914348Smichaelm#ifdef DEBUG
5014348Smichaelmextern unsigned digi_debug;
5114348Smichaelm#define	DLOG(level, args)	if (digi_debug & (level)) device_printf args
5214348Smichaelm#else
5314348Smichaelm#define	DLOG(level, args)
5414348Smichaelm#endif
5514348Smichaelm
5614348Smichaelm
5714348Smichaelmstruct digi_softc;
5814348Smichaelm
5914348Smichaelm/* digiboard port structure */
6014348Smichaelmstruct digi_p {
6114348Smichaelm	struct digi_softc *sc;
6214348Smichaelm
6314348Smichaelm	int status;
6414348Smichaelm#define ENABLED 1
6514348Smichaelm#define DIGI_DTR_OFF 2
6614348Smichaelm#define PAUSE_TX 8
6714348Smichaelm#define PAUSE_RX 16
6814348Smichaelm
6914348Smichaelm	int opencnt;
7014348Smichaelm	ushort txbufsize;
7114348Smichaelm	ushort rxbufsize;
7214348Smichaelm	volatile struct board_chan *bc;
7314348Smichaelm	struct tty *tp;
7414348Smichaelm
7514348Smichaelm	dev_t dev[6];
7614348Smichaelm
7714348Smichaelm	u_char *txbuf;
7814348Smichaelm	u_char *rxbuf;
7914348Smichaelm	u_char txwin;
8014348Smichaelm	u_char rxwin;
8114348Smichaelm
8214348Smichaelm	u_char pnum;		/* port number */
8314348Smichaelm
8414348Smichaelm	u_char modemfake;	/* Modem values to be forced */
8514348Smichaelm	u_char mstat;
8614348Smichaelm	u_char modem;		/* Force values */
8714348Smichaelm
88	int active_out;		/* nonzero if the callout device is open */
89	int dtr_wait;		/* time to hold DTR down on close (* 1/hz) */
90	u_int wopeners;		/* # processes waiting for DCD in open() */
91
92	/*
93	 * The high level of the driver never reads status registers directly
94	 * because there would be too many side effects to handle conveniently.
95	 * Instead, it reads copies of the registers stored here by the
96	 * interrupt handler.
97	 */
98	u_char last_modem_status;	/* last MSR read by intr handler */
99	u_char prev_modem_status;	/* last MSR handled by high level */
100
101
102	/* Initial state. */
103	struct termios it_in;		/* should be in struct tty */
104	struct termios it_out;
105
106	/* Lock state. */
107	struct termios lt_in;		/* should be in struct tty */
108	struct termios lt_out;
109
110	u_int do_timestamp;
111	u_int do_dcd_timestamp;
112	struct timeval dcd_timestamp;
113
114	u_long bytes_in, bytes_out;
115	u_int delta_error_counts[CE_NTYPES];
116	u_long error_counts;
117
118	tcflag_t c_iflag;		/* hold true IXON/IXOFF/IXANY */
119	int lcc, lostcc, lbuf;
120	u_char send_ring;
121};
122
123/*
124 * Map TIOCM_* values to digiboard values
125 */
126struct digi_control_signals {
127	int rts;
128	int cd;
129	int dsr;
130	int cts;
131	int ri;
132	int dtr;
133};
134
135enum digi_board_status {
136	DIGI_STATUS_NOTINIT,
137	DIGI_STATUS_ENABLED,
138	DIGI_STATUS_DISABLED
139};
140
141/* Digiboard per-board structure */
142struct digi_softc {
143	/* struct board_info */
144	device_t dev;
145
146	const char *name;
147	enum digi_board_status status;
148	ushort numports;		/* number of ports on card */
149	ushort port;			/* I/O port */
150	ushort wport;			/* window select I/O port */
151
152	struct {
153		struct resource *mem;
154		int mrid;
155		struct resource *irq;
156		int irqrid;
157		struct resource *io;
158		int iorid;
159		void *irqHandler;
160		int unit;
161		dev_t ctldev;
162	} res;
163
164	u_char *vmem;			/* virtual memory address */
165	u_char *memcmd;
166	volatile u_char *memevent;
167	long pmem;			/* physical memory address */
168
169	struct {
170		u_char *data;
171		size_t size;
172	} bios, fep, link;
173
174#ifdef DIGI_INTERRUPT
175	struct timeval intr_timestamp;
176#endif
177
178	struct digi_p *ports;	/* pointer to array of port descriptors */
179	struct tty *ttys;	/* pointer to array of TTY structures */
180	volatile struct global_data *gdata;
181	u_char window;		/* saved window */
182	int win_size;
183	int win_bits;
184	int mem_size;
185	int mem_seg;
186	enum digi_model model;
187	const struct digi_control_signals *csigs;
188	int opencnt;
189	unsigned pcibus : 1;		/* On a PCI bus ? */
190
191	struct callout_handle callout;	/* poll timeout handle */
192	struct callout_handle inttest;	/* int test timeout handle */
193	const char *module;
194
195	u_char *(*setwin)(struct digi_softc *_sc, unsigned _addr);
196	void	(*hidewin)(struct digi_softc *_sc);
197	void	(*towin)(struct digi_softc *_sc, int _win);
198#ifdef DEBUG
199	int	intr_count;
200#endif
201};
202
203extern devclass_t digi_devclass;
204extern const struct digi_control_signals digi_xixe_signals;
205extern const struct digi_control_signals digi_normal_signals;
206
207const char	*digi_errortxt(int _id);
208int		 digi_modhandler(module_t _mod, int _event, void *_arg);
209int		 digi_attach(struct digi_softc *);
210int		 digi_detach(device_t _dev);
211int		 digi_shutdown(device_t _dev);
212