1/*
2 * Middle-level code for Cronyx Tau32-PCI adapters.
3 *
4 * Copyright (C) 2004 Cronyx Engineering
5 * Copyright (C) 2004 Roman Kurakin <rik@FreeBSD.org>
6 *
7 * This software is distributed with NO WARRANTIES, not even the implied
8 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9 *
10 * Authors grant any other persons or organisations a permission to use,
11 * modify and redistribute this software in source and binary forms,
12 * as long as this message is kept with the software, all derivative
13 * works or modified versions.
14 *
15 * $Cronyx: ceddk.h,v 1.2.6.1 2005/11/09 13:01:39 rik Exp $
16 * $FreeBSD$
17 */
18
19#define TAU32_UserContext_Add	void	*sys;
20#define TAU32_UserRequest_Add	void	*sys; TAU32_UserRequest *next;
21
22#include <dev/ce/tau32-ddk.h>
23
24#define NCHAN	TAU32_CHANNELS
25#ifndef NBRD
26#   define NBRD 6
27#endif
28#if NBRD != 6
29#   error "NBRD != 6"
30#endif
31
32#define BUFSZ	1664
33
34typedef struct _ce_buf_item_t {
35	TAU32_UserRequest req;
36	unsigned char buf [BUFSZ+4];
37	unsigned long phys;
38} ce_buf_item_t;
39
40typedef struct _ce_buf_t {
41	ce_buf_item_t tx_item[TAU32_IO_QUEUE];
42	ce_buf_item_t rx_item[TAU32_IO_QUEUE];
43} ce_buf_t;
44
45typedef struct {
46	unsigned long bpv;		/* bipolar violations */
47	unsigned long fse;		/* frame sync errors */
48	unsigned long crce;		/* CRC errors */
49	unsigned long rcrce;		/* remote CRC errors (E-bit) */
50	unsigned long uas;		/* unavailable seconds */
51	unsigned long les;		/* line errored seconds */
52	unsigned long es;		/* errored seconds */
53	unsigned long bes;		/* bursty errored seconds */
54	unsigned long ses;		/* severely errored seconds */
55	unsigned long oofs;		/* out of frame seconds */
56	unsigned long css;		/* controlled slip seconds */
57	unsigned long dm;		/* degraded minutes */
58} ce_gstat_t;
59
60typedef struct _ce_chan_t {
61	unsigned char num;
62	unsigned char type;
63#define T_NONE		0		/* no channel */
64#define T_E1		3		/* E1 */
65#define T_DATA		6		/* no physical interface */
66
67	struct _ce_board_t *board;
68	unsigned char dtr;
69	unsigned char rts;
70	ce_buf_item_t *tx_item;
71	ce_buf_item_t *rx_item;
72	TAU32_UserRequest *rx_queue;
73	TAU32_UserRequest *tx_queue;
74	unsigned char debug;
75	unsigned char debug_shadow;
76	void (*transmit) (struct _ce_chan_t*, void*, int);
77	void (*receive) (struct _ce_chan_t*, unsigned char*, int);
78	void (*error) (struct _ce_chan_t*, int);
79#define CE_FRAME	 1
80#define CE_CRC		 2
81#define CE_UNDERRUN	 3
82#define CE_OVERRUN	 4
83#define CE_OVERFLOW	 5
84	int tx_pending;
85	int rx_pending;
86	unsigned long rintr;
87	unsigned long tintr;
88	ulong64	ibytes;
89	ulong64	obytes;
90	unsigned long ipkts;
91	unsigned long opkts;
92	unsigned long underrun;
93	unsigned long overrun;
94	unsigned long frame;
95	unsigned long crc;
96
97	unsigned short status;		/* E1/G.703 line status bit mask */
98#define ESTS_NOALARM	0x0001		/* no alarm present */
99#define ESTS_FARLOF	0x0002		/* receiving far loss of framing */
100#define ESTS_AIS	0x0008		/* receiving all ones */
101#define ESTS_LOF	0x0020		/* loss of framing */
102#define ESTS_LOS	0x0040		/* loss of signal */
103#define ESTS_AIS16	0x0100		/* receiving all ones in timeslot 16 */
104#define ESTS_FARLOMF	0x0200		/* receiving alarm in timeslot 16 */
105#define ESTS_LOMF	0x0400		/* loss of multiframe sync */
106#define ESTS_TSTREQ	0x0800		/* test code detected */
107#define ESTS_TSTERR	0x1000		/* test error */
108
109	unsigned long totsec;		/* total seconds elapsed */
110	unsigned long cursec;		/* current seconds elapsed */
111	unsigned long degsec;		/* degraded seconds */
112	unsigned long degerr;		/* errors during degraded seconds */
113	ce_gstat_t currnt;		/* current 15-min interval data */
114	ce_gstat_t total;		/* total statistics data */
115	ce_gstat_t interval [48];	/* 12 hour period data */
116
117	unsigned int acc_status;
118	unsigned long config;
119	unsigned long baud;
120	unsigned long ts;
121	unsigned long ts_mask;
122	unsigned char dir;
123	unsigned char lloop;
124	unsigned char rloop;
125	unsigned char higain;
126	unsigned char phony;
127	unsigned char scrambler;
128	unsigned char unfram;
129	unsigned char monitor;
130	unsigned char crc4;
131	unsigned char use16;
132	unsigned char gsyn;		/* G.703 clock mode */
133#define GSYN_INT	0		/* internal transmit clock source */
134#define GSYN_RCV	1		/* transmit clock source = receive */
135#define GSYN_RCV0	2		/* tclk = rclk from channel 0 */
136#define GSYN_RCV1	3		/* ...from channel 1 */
137	unsigned long mtu;
138	void *sys;
139} ce_chan_t;
140
141#define CONFREQSZ	128
142typedef struct _ce_conf_req {
143	TAU32_UserRequest req[CONFREQSZ+10];
144	TAU32_UserRequest *queue;
145	int	pending;
146} ce_conf_req;
147
148typedef struct _ce_board_t {
149	TAU32_UserContext	ddk;
150	ce_chan_t		chan[NCHAN];
151	int			num;
152	int			mux;
153#define TAU32_BASE_NAME		"Tau-PCI-32"
154#define TAU32_LITE_NAME		"Tau-PCI-32/Lite"
155#define TAU32_ADPCM_NAME	"Tau-PCI-32/ADPCM"
156#define TAU32_UNKNOWN_NAME	"Unknown Tau-PCI-32"
157	char			name [32];
158	ce_conf_req		cr;
159	TAU32_CrossMatrix	dxc;
160	unsigned long		pmask;
161	void *sys;
162} ce_board_t;
163
164void ce_set_dtr (ce_chan_t *c, int on);
165void ce_set_rts (ce_chan_t *c, int on);
166int ce_get_cd (ce_chan_t *c);
167int ce_get_cts (ce_chan_t *c);
168int ce_get_dsr (ce_chan_t *c);
169
170int ce_transmit_space (ce_chan_t *c);
171int ce_send_packet (ce_chan_t *c, unsigned char *buf, int len, void *tag);
172void ce_start_chan (ce_chan_t *c, int tx, int rx, ce_buf_t *cb, unsigned long phys);
173void ce_stop_chan (ce_chan_t *c);
174void ce_register_transmit (ce_chan_t *c, void (*func) (ce_chan_t*, void*, int));
175void ce_register_receive (ce_chan_t *c, void (*func) (ce_chan_t*,
176							unsigned char*, int));
177void ce_register_error (ce_chan_t *c, void (*func) (ce_chan_t*, int));
178
179void TAU32_CALLBACK_TYPE
180	ce_error_callback(TAU32_UserContext *pContext, int Item,
181			  unsigned NotifyBits);
182void TAU32_CALLBACK_TYPE
183	ce_status_callback(TAU32_UserContext *pContext, int Item,
184			  unsigned NotifyBits);
185
186void ce_set_baud (ce_chan_t *c, unsigned long baud);
187void ce_set_lloop (ce_chan_t *c, unsigned char on);
188void ce_set_rloop (ce_chan_t *c, unsigned char on);
189void ce_set_higain (ce_chan_t *c, unsigned char on);
190void ce_set_unfram (ce_chan_t *c, unsigned char on);
191void ce_set_ts (ce_chan_t *c, unsigned long ts);
192void ce_set_phony (ce_chan_t *c, unsigned char on);
193void ce_set_scrambler (ce_chan_t *c, unsigned char on);
194void ce_set_monitor (ce_chan_t *c, unsigned char on);
195void ce_set_use16 (ce_chan_t *c, unsigned char on);
196void ce_set_crc4 (ce_chan_t *c, unsigned char on);
197void ce_set_gsyn (ce_chan_t *c, int syn);
198#define CABLE_TP		11
199int ce_get_cable (ce_chan_t *c);
200void ce_set_dir (ce_chan_t *c, int dir);
201void ce_e1_timer (ce_chan_t *c);
202void ce_init_board (ce_board_t *b);
203