xref: /freebsd-13-stable/sys/i386/include/cserial.h (revision 4b40a16f0d188422227478889b38cc341d50f88f)
1 /*-
2  * Ioctl interface to Cronyx serial drivers.
3  *
4  * Copyright (C) 1997-2002 Cronyx Engineering.
5  * Author: Serge Vakulenko, <vak@cronyx.ru>
6  *
7  * Copyright (C) 2001-2005 Cronyx Engineering.
8  * Author: Roman Kurakin, <rik@FreeBSD.org>
9  *
10  * Copyright (C) 2004-2005 Cronyx Engineering.
11  * Author: Leo Yuriev, <ly@cronyx.ru>
12  *
13  * This software is distributed with NO WARRANTIES, not even the implied
14  * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *
16  * Authors grant any other persons or organisations permission to use
17  * or modify this software as long as this message is kept with the software,
18  * all derivative works or modified versions.
19  *
20  * Cronyx Id: cserial.h,v 1.4.2.2 2005/11/09 13:01:35 rik Exp $
21  */
22 
23 /*
24  * General channel statistics.
25  */
26 struct serial_statistics {
27 	unsigned long rintr;		/* receive interrupts */
28 	unsigned long tintr;		/* transmit interrupts */
29 	unsigned long mintr;		/* modem interrupts */
30 	unsigned long ibytes;		/* input bytes */
31 	unsigned long ipkts;		/* input packets */
32 	unsigned long ierrs;		/* input errors */
33 	unsigned long obytes;		/* output bytes */
34 	unsigned long opkts;		/* output packets */
35 	unsigned long oerrs;		/* output errors */
36 };
37 
38 /*
39  * Statistics for E1/G703 channels.
40  */
41 struct e1_counters {
42 	unsigned long bpv;		/* bipolar violations */
43 	unsigned long fse;		/* frame sync errors */
44 	unsigned long crce;		/* CRC errors */
45 	unsigned long rcrce;		/* remote CRC errors (E-bit) */
46 	unsigned long uas;		/* unavailable seconds */
47 	unsigned long les;		/* line errored seconds */
48 	unsigned long es;		/* errored seconds */
49 	unsigned long bes;		/* bursty errored seconds */
50 	unsigned long ses;		/* severely errored seconds */
51 	unsigned long oofs;		/* out of frame seconds */
52 	unsigned long css;		/* controlled slip seconds */
53 	unsigned long dm;		/* degraded minutes */
54 };
55 
56 struct e1_statistics {
57 	unsigned long status;		/* line status bit mask */
58 	unsigned long cursec;		/* seconds in current interval */
59 	unsigned long totsec;		/* total seconds elapsed */
60 	struct e1_counters currnt;	/* current 15-min interval data */
61 	struct e1_counters total;	/* total statistics data */
62 	struct e1_counters interval [48]; /* 12 hour period data */
63 };
64 
65 struct e3_statistics {
66 	unsigned long status;
67 	unsigned long cursec;
68 	unsigned long totsec;
69 	unsigned long ccv;
70 	unsigned long tcv;
71 	unsigned long icv[48];
72 };
73 
74 #define M_ASYNC         0		/* asynchronous mode */
75 #define M_HDLC          1		/* bit-sync mode (HDLC) */
76 #define M_G703          2
77 #define M_E1            3
78 
79 /*
80  * Receive error codes.
81  */
82 #define ER_FRAMING	1		/* framing error */
83 #define ER_CHECKSUM	2		/* parity/CRC error */
84 #define ER_BREAK	3		/* break state */
85 #define ER_OVERFLOW	4		/* receive buffer overflow */
86 #define ER_OVERRUN	5		/* receive fifo overrun */
87 #define ER_UNDERRUN	6		/* transmit fifo underrun */
88 #define ER_SCC_FRAMING	7		/* subchannel framing error */
89 #define ER_SCC_OVERFLOW	8		/* subchannel receive buffer overflow */
90 #define ER_SCC_OVERRUN	9		/* subchannel receiver overrun */
91 #define ER_SCC_UNDERRUN	10		/* subchannel transmitter underrun */
92 #define ER_BUS		11		/* system bus is too busy (e.g PCI) */
93 
94 /*
95  * E1 channel status.
96  */
97 #define E1_NOALARM	0x0001          /* no alarm present */
98 #define E1_FARLOF	0x0002          /* receiving far loss of framing */
99 #define E1_CRC4E	0x0004		/* crc4 errors */
100 #define E1_AIS		0x0008          /* receiving all ones */
101 #define E1_LOF		0x0020          /* loss of framing */
102 #define E1_LOS		0x0040          /* loss of signal */
103 #define E1_AIS16	0x0100          /* receiving all ones in timeslot 16 */
104 #define E1_FARLOMF	0x0200          /* receiving alarm in timeslot 16 */
105 #define E1_LOMF		0x0400          /* loss of multiframe sync */
106 #define E1_TSTREQ	0x0800          /* test code detected */
107 #define E1_TSTERR	0x1000          /* test error */
108 
109 #define E3_LOS		0x00000002	/* Lost of synchronization */
110 #define E3_TXE		0x00000004	/* Transmit error */
111 
112 /*
113  * Query the mask of all registered channels, max 128.
114  */
115 #define SERIAL_GETREGISTERED	_IOR ('x', 0, char[16])
116 
117 /*
118  * Attach/detach the protocol to the channel.
119  * The protocol is given by its name, char[8].
120  * For example "async", "hdlc", "cisco", "fr", "ppp".
121  */
122 #define SERIAL_GETPROTO		_IOR ('x', 1, char [8])
123 #define SERIAL_SETPROTO		_IOW ('x', 1, char [8])
124 
125 /*
126  * Query/set the hardware mode for the channel.
127  */
128 #define SERIAL_GETMODE		_IOR ('x', 2, int)
129 #define SERIAL_SETMODE		_IOW ('x', 2, int)
130 
131 #define SERIAL_ASYNC		1
132 #define SERIAL_HDLC		2
133 #define SERIAL_RAW		3
134 
135 /*
136  * Get/clear the channel statistics.
137  */
138 #define SERIAL_GETSTAT		_IOR ('x', 3, struct serial_statistics)
139 #define SERIAL_GETESTAT		_IOR ('x', 3, struct e1_statistics)
140 #define SERIAL_GETE3STAT	_IOR ('x', 3, struct e3_statistics)
141 #define SERIAL_CLRSTAT		_IO  ('x', 3)
142 
143 /*
144  * Query/set the synchronization mode and baud rate.
145  * If baud==0 then the external clock is used.
146  */
147 #define SERIAL_GETBAUD		_IOR ('x', 4, long)
148 #define SERIAL_SETBAUD		_IOW ('x', 4, long)
149 
150 /*
151  * Query/set the internal loopback mode,
152  * useful for debugging purposes.
153  */
154 #define SERIAL_GETLOOP		_IOR ('x', 5, int)
155 #define SERIAL_SETLOOP		_IOW ('x', 5, int)
156 
157 /*
158  * Query/set the DPLL mode, commonly used with NRZI
159  * for channels lacking synchro signals.
160  */
161 #define SERIAL_GETDPLL		_IOR ('x', 6, int)
162 #define SERIAL_SETDPLL		_IOW ('x', 6, int)
163 
164 /*
165  * Query/set the NRZI encoding (default is NRZ).
166  */
167 #define SERIAL_GETNRZI		_IOR ('x', 7, int)
168 #define SERIAL_SETNRZI		_IOW ('x', 7, int)
169 
170 /*
171  * Invert receive and transmit clock.
172  */
173 #define SERIAL_GETINVCLK	_IOR ('x', 8, int)
174 #define SERIAL_SETINVCLK	_IOW ('x', 8, int)
175 
176 /*
177  * Query/set the E1/G703 synchronization mode.
178  */
179 #define SERIAL_GETCLK		_IOR ('x', 9, int)
180 #define SERIAL_SETCLK		_IOW ('x', 9, int)
181 
182 #define E1CLK_RECOVERY		-1
183 #define E1CLK_INTERNAL		0
184 #define E1CLK_RECEIVE		1
185 #define E1CLK_RECEIVE_CHAN0	2
186 #define E1CLK_RECEIVE_CHAN1	3
187 #define E1CLK_RECEIVE_CHAN2	4
188 #define E1CLK_RECEIVE_CHAN3	5
189 
190 /*
191  * Query/set the E1 timeslot mask.
192  */
193 #define SERIAL_GETTIMESLOTS	_IOR ('x', 10, long)
194 #define SERIAL_SETTIMESLOTS	_IOW ('x', 10, long)
195 
196 /*
197  * Query/set the E1 subchannel timeslot mask.
198  */
199 #define SERIAL_GETSUBCHAN	_IOR ('x', 11, long)
200 #define SERIAL_SETSUBCHAN	_IOW ('x', 11, long)
201 
202 /*
203  * Query/set the high input sensitivity mode (E1).
204  */
205 #define SERIAL_GETHIGAIN	_IOR ('x', 12, int)
206 #define SERIAL_SETHIGAIN	_IOW ('x', 12, int)
207 
208 /*
209  * Query the input signal level in santibells.
210  */
211 #define SERIAL_GETLEVEL		_IOR ('x', 13, int)
212 
213 /*
214  * Get the channel name.
215  */
216 #define SERIAL_GETNAME		_IOR ('x', 14, char [32])
217 
218 /*
219  * Get version string.
220  */
221 #define SERIAL_GETVERSIONSTRING _IOR ('x', 15, char [256])
222 
223 /*
224  * Query/set master channel.
225  */
226 #define SERIAL_GETMASTER	_IOR ('x', 16, char [16])
227 #define SERIAL_SETMASTER 	_IOW ('x', 16, char [16])
228 
229 /*
230  * Query/set keepalive.
231  */
232 #define SERIAL_GETKEEPALIVE 	_IOR ('x', 17, int)
233 #define SERIAL_SETKEEPALIVE 	_IOW ('x', 17, int)
234 
235 /*
236  * Query/set E1 configuration.
237  */
238 #define SERIAL_GETCFG		_IOR ('x', 18, char)
239 #define SERIAL_SETCFG		_IOW ('x', 18, char)
240 
241 /*
242  * Query/set debug.
243  */
244 #define SERIAL_GETDEBUG		_IOR ('x', 19, int)
245 #define SERIAL_SETDEBUG		_IOW ('x', 19, int)
246 
247 /*
248  * Query/set phony mode (E1).
249  */
250 #define SERIAL_GETPHONY		_IOR ('x', 20, int)
251 #define SERIAL_SETPHONY		_IOW ('x', 20, int)
252 
253 /*
254  * Query/set timeslot 16 usage mode (E1).
255  */
256 #define SERIAL_GETUSE16		_IOR ('x', 21, int)
257 #define SERIAL_SETUSE16		_IOW ('x', 21, int)
258 
259 /*
260  * Query/set crc4 mode (E1).
261  */
262 #define SERIAL_GETCRC4		_IOR ('x', 22, int)
263 #define SERIAL_SETCRC4		_IOW ('x', 22, int)
264 
265 /*
266  * Query/set the timeout to recover after transmit interrupt loss.
267  * If timo==0 recover will be disabled.
268  */
269 #define SERIAL_GETTIMO		_IOR ('x', 23, long)
270 #define SERIAL_SETTIMO		_IOW ('x', 23, long)
271 
272 /*
273  * Query/set port type for old models of Sigma
274  * -1 Fixed or cable select
275  * 0  RS-232
276  * 1  V35
277  * 2  RS-449
278  * 3  E1	(only for Windows 2000)
279  * 4  G.703	(only for Windows 2000)
280  * 5  DATA	(only for Windows 2000)
281  * 6  E3	(only for Windows 2000)
282  * 7  T3	(only for Windows 2000)
283  * 8  STS1	(only for Windows 2000)
284  */
285 #define SERIAL_GETPORT		_IOR ('x', 25, int)
286 #define SERIAL_SETPORT		_IOW ('x', 25, int)
287 
288 /*
289  * Add the virtual channel DLCI (Frame Relay).
290  */
291 #define SERIAL_ADDDLCI		_IOW ('x', 26, int)
292 
293 /*
294  * Invert receive clock.
295  */
296 #define SERIAL_GETINVRCLK	_IOR ('x', 27, int)
297 #define SERIAL_SETINVRCLK	_IOW ('x', 27, int)
298 
299 /*
300  * Invert transmit clock.
301  */
302 #define SERIAL_GETINVTCLK	_IOR ('x', 28, int)
303 #define SERIAL_SETINVTCLK	_IOW ('x', 28, int)
304 
305 /*
306  * Unframed E1 mode.
307  */
308 #define SERIAL_GETUNFRAM	_IOR ('x', 29, int)
309 #define SERIAL_SETUNFRAM	_IOW ('x', 29, int)
310 
311 /*
312  * E1 monitoring mode.
313  */
314 #define SERIAL_GETMONITOR	_IOR ('x', 30, int)
315 #define SERIAL_SETMONITOR	_IOW ('x', 30, int)
316 
317 /*
318  * Interrupt number.
319  */
320 #define SERIAL_GETIRQ		_IOR ('x', 31, int)
321 
322 /*
323  * Reset.
324  */
325 #define SERIAL_RESET		_IO ('x', 32)
326 
327 /*
328  * Hard reset.
329  */
330 #define SERIAL_HARDRESET	_IO ('x', 33)
331 
332 /*
333  * Query cable type.
334  */
335 #define SERIAL_GETCABLE		_IOR ('x', 34, int)
336 
337 /*
338  * Assignment of HDLC ports to E1 channels.
339  */
340 #define SERIAL_GETDIR		_IOR ('x', 35, int)
341 #define SERIAL_SETDIR		_IOW ('x', 35, int)
342 
343 struct dxc_table {			/* cross-connector parameters */
344 	unsigned char ts [32];		/* timeslot number */
345 	unsigned char link [32];	/* E1 link number */
346 };
347 
348 /*
349  * DXC cross-connector settings for E1 channels.
350  */
351 #define SERIAL_GETDXC		_IOR ('x', 36, struct dxc_table)
352 #define SERIAL_SETDXC		_IOW ('x', 36, struct dxc_table)
353 
354 /*
355  * Scrambler for G.703.
356  */
357 #define SERIAL_GETSCRAMBLER	_IOR ('x', 37, int)
358 #define SERIAL_SETSCRAMBLER	_IOW ('x', 37, int)
359 
360 /*
361  * Length of cable for T3 and STS-1.
362  */
363 #define SERIAL_GETCABLEN	_IOR ('x', 38, int)
364 #define SERIAL_SETCABLEN	_IOW ('x', 38, int)
365 
366 /*
367  * Remote loopback for E3, T3 and STS-1.
368  */
369 #define SERIAL_GETRLOOP		_IOR ('x', 39, int)
370 #define SERIAL_SETRLOOP		_IOW ('x', 39, int)
371 
372 /*
373  * G.703 line code
374  */
375 #define SERIAL_GETLCODE		_IOR ('x', 40, int)
376 #define SERIAL_SETLCODE		_IOW ('x', 40, int)
377 
378 /*
379  * MTU
380  */
381 #define SERIAL_GETMTU		_IOR ('x', 41, int)
382 #define SERIAL_SETMTU		_IOW ('x', 41, int)
383 
384 /*
385  * Receive Queue Length
386  */
387 #define SERIAL_GETRQLEN		_IOR ('x', 42, int)
388 #define SERIAL_SETRQLEN		_IOW ('x', 42, int)
389 
390 #ifdef __KERNEL__
391 #ifdef CRONYX_LYSAP
392 #	define LYSAP_PEER_ADD		_IOWR('x', 101, lysap_peer_config_t)
393 #	define LYSAP_PEER_REMOVE	_IOW('x', 102, unsigned)
394 #	define LYSAP_PEER_INFO		_IOWR('x', 103, lysap_peer_info_t)
395 #	define LYSAP_PEER_COUNT		_IOR('x', 104, unsigned)
396 #	define LYSAP_PEER_ENUM		_IOWR('x', 105, unsigned)
397 #	define LYSAP_PEER_CLEAR		_IOW('x', 106, unsigned)
398 
399 #	define LYSAP_CHAN_ADD		_IOWR('x', 111, lysap_channel_config_t)
400 #	define LYSAP_CHAN_REMOVE	_IO('x', 112)
401 #	define LYSAP_CHAN_INFO		_IOR('x', 113, lysap_channel_info_t)
402 #	define LYSAP_CHAN_COUNT		_IOR('x', 114, unsigned)
403 #	define LYSAP_CHAN_ENUM		_IOWR('x', 115, unsigned)
404 #	define LYSAP_CHAN_CLEAR		_IO('x', 116)
405 #	include "lysap-linux.h"
406 #else /* CRONYX_LYSAP */
407 	typedef struct _lysap_channel_t lysap_channel_t;
408 	typedef struct _lysap_channel_config_t lysap_channel_config_t;
409 	typedef struct _LYSAP_DeviceInterfaceConfig LYSAP_DeviceInterfaceConfig;
410 	typedef struct _LYSAP_ChannelConfig LYSAP_ChannelConfig;
411 	typedef struct _lysap_buf_t lysap_buf_t;
412 #endif /* !CRONYX_LYSAP */
413 
414 /*
415  * Dynamic binder interface.
416  */
417 typedef struct _chan_t chan_t;
418 typedef struct _proto_t proto_t;
419 
420 void binder_register_protocol (proto_t *p);
421 void binder_unregister_protocol (proto_t *p);
422 
423 int binder_register_channel (chan_t *h, char *prefix, int minor);
424 void binder_unregister_channel (chan_t *h);
425 
426 /*
427  * Hardware channel driver structure.
428  */
429 struct sk_buff;
430 
431 struct _chan_t {
432 	char name [16];
433 	int mtu;			/* max packet size */
434 	int fifosz;			/* total hardware i/o buffer size */
435 	int port;			/* hardware base i/o port */
436 	int irq;			/* hardware interrupt line */
437 	int minor;			/* minor number 0..127, assigned by binder */
438 	int debug;			/* debug level, 0..2 */
439 	int running;			/* running, 0..1 */
440 	struct _proto_t *proto;		/* protocol interface data */
441 	void *sw;			/* protocol private data */
442 	void *hw;			/* hardware layer private data */
443 
444 	/* Interface to protocol */
445 	int (*up) (chan_t *h);
446 	void (*down) (chan_t *h);
447 	int (*transmit) (chan_t *h, struct sk_buff *skb);
448 	void (*set_dtr) (chan_t *h, int val);
449 	void (*set_rts) (chan_t *h, int val);
450 	int (*query_dtr) (chan_t *h);
451 	int (*query_rts) (chan_t *h);
452 	int (*query_dsr) (chan_t *h);
453 	int (*query_cts) (chan_t *h);
454 	int (*query_dcd) (chan_t *h);
455 
456 	/* Interface to async protocol */
457 	void (*set_async_param) (chan_t *h, int baud, int bits, int parity,
458 		int stop2, int ignpar, int rtscts,
459 		int ixon, int ixany, int symstart, int symstop);
460 	void (*send_break) (chan_t *h, int msec);
461 	void (*send_xon) (chan_t *h);
462 	void (*send_xoff) (chan_t *h);
463 	void (*start_transmitter) (chan_t *h);
464 	void (*stop_transmitter) (chan_t *h);
465 	void (*flush_transmit_buffer) (chan_t *h);
466 
467 	/* Control interface */
468 	int (*control) (chan_t *h, unsigned int cmd, unsigned long arg);
469 
470 	/* LYSAP interface */
471 	struct lysap_t
472 	{
473 		lysap_channel_t *link;
474 		int (*inspect_config)(chan_t *h, lysap_channel_config_t *,
475 			LYSAP_DeviceInterfaceConfig *, LYSAP_ChannelConfig *);
476 		unsigned long (*probe_freq)(chan_t *h, unsigned long freq);
477 		unsigned long (*set_freq)(chan_t *h, unsigned long freq);
478 		unsigned (*get_status)(chan_t *h);
479 		int (*transmit) (chan_t *h, lysap_buf_t *b);
480 		lysap_buf_t* (*alloc_buf) (chan_t *h, unsigned len);
481 		int (*set_clock_master)(chan_t *h, int enable);
482 		unsigned long (*get_master_freq)(chan_t *h);
483 	} lysap;
484 };
485 
486 /*
487  * Protocol driver structure.
488  */
489 struct _proto_t {
490 	char *name;
491 	struct _proto_t *next;
492 
493 	/* Interface to channel */
494 	void (*receive) (chan_t *h, struct sk_buff *skb);
495 	void (*receive_error) (chan_t *h, int errcode);
496 	void (*transmit) (chan_t *h);
497 	void (*modem_event) (chan_t *h);
498 
499 	/* Interface to binder */
500 	int (*open) (chan_t *h);
501 	void (*close) (chan_t *h);
502 	int (*read) (chan_t *h, unsigned short flg, char *buf, int len);
503 	int (*write) (chan_t *h, unsigned short flg, const char *buf, int len);
504 	int (*select) (chan_t *h, int type, void *st, struct file *filp);
505 	struct fasync_struct *fasync;
506 
507 	/* Control interface */
508 	int (*attach) (chan_t *h);
509 	int (*detach) (chan_t *h);
510 	int (*control) (chan_t *h, unsigned int cmd, unsigned long arg);
511 
512 	/* LYSAP interface */
513 	void (*transmit_error) (chan_t *h, int errcode);
514 	void (*lysap_notify_receive) (chan_t *h, lysap_buf_t *b);
515 	void (*lysap_notify_transmit) (chan_t *h);
516 	lysap_buf_t* (*lysap_get_data)(chan_t *h);
517 };
518 #endif /* KERNEL */
519