1139749Simp/*-
2116258Sharti * Copyright (c) 2003
3116258Sharti *	Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4116258Sharti * 	All rights reserved.
5116258Sharti *
6116258Sharti * Redistribution and use in source and binary forms, with or without
7116258Sharti * modification, are permitted provided that the following conditions
8116258Sharti * are met:
9116258Sharti * 1. Redistributions of source code must retain the above copyright
10116258Sharti *    notice, this list of conditions and the following disclaimer.
11116258Sharti * 2. Redistributions in binary form must reproduce the above copyright
12116258Sharti *    notice, this list of conditions and the following disclaimer in the
13116258Sharti *    documentation and/or other materials provided with the distribution.
14116258Sharti *
15116258Sharti * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16116258Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17116258Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18116258Sharti * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19116258Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20116258Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21116258Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22116258Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23116258Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24116258Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25116258Sharti * SUCH DAMAGE.
26116258Sharti *
27116258Sharti * Author: Hartmut Brandt <harti@freebsd.org>
28116258Sharti *
29116258Sharti * $FreeBSD$
30116258Sharti */
31116258Sharti#ifndef _DEV_UTOPIA_UTOPIA_H
32116258Sharti#define	_DEV_UTOPIA_UTOPIA_H
33116258Sharti
34116258Sharti/* Structure for user-level register formatting */
35116258Shartistruct utopia_print {
36116258Sharti	uint8_t		type;	/* register type */
37116258Sharti	uint8_t		reg;	/* register number */
38116258Sharti	const char	*name;	/* register name */
39116258Sharti	const char	*fmt;	/* format for printing */
40116258Sharti};
41116258Sharti
42116258Sharti/*
43116258Sharti * Types of registers
44116258Sharti */
45116258Sharti#define	UTP_REGT_BITS		0x0	/* use printb to print */
46116258Sharti#define	UTP_REGT_INT8		0x1	/* 8 bit hex number */
47116258Sharti#define	UTP_REGT_INT10BITS	0x2	/* 10 bit hex number + 6 bit printb */
48116258Sharti#define	UTP_REGT_INT12		0x3	/* 12 bit LE hex */
49116258Sharti#define	UTP_REGT_INT16		0x4	/* 16 bit LE hex */
50116258Sharti#define	UTP_REGT_INT19		0x5	/* 19 bit LE hex */
51116258Sharti#define	UTP_REGT_INT20		0x6	/* 20 bit LE hex */
52116258Sharti#define	UTP_REGT_INT21		0x7	/* 21 bit LE hex */
53142384Sharti#define	UTP_REGT_INT18		0x8	/* 18 bit LE hex */
54116258Sharti
55116258Sharti/* number of additional registers per type */
56142384Sharti#define	UTP_REG_ADD	0, 0, 1, 1, 1, 2, 2, 2, 2
57116258Sharti
58116258Sharti/* flags field */
59116258Sharti#define	UTP_FL_NORESET		0x0001	/* cannot write MRESET register */
60116258Sharti#define	UTP_FL_POLL_CARRIER	0x0002	/* need to poll for carrier */
61116258Sharti
62116258Sharti/* state field */
63116258Sharti#define	UTP_ST_ACTIVE		0x0001	/* registers accessible */
64116258Sharti#define	UTP_ST_SDH		0x0002	/* SDH or SONET */
65116258Sharti#define	UTP_ST_UNASS		0x0004	/* produce unassigned cells */
66116258Sharti#define	UTP_ST_NOSCRAMB		0x0008	/* no scrambling */
67116258Sharti#define	UTP_ST_DETACH		0x0010	/* detaching */
68116258Sharti#define	UTP_ST_ATTACHED		0x0020	/* successful attached */
69116258Sharti
70116258Sharti/* carrier field */
71116258Sharti#define	UTP_CARR_UNKNOWN	0
72116258Sharti#define	UTP_CARR_OK		1
73116258Sharti#define	UTP_CARR_LOST		2
74116258Sharti
75116258Sharti/* loopback field */
76116258Sharti#define	UTP_LOOP_NONE		0x0000
77116258Sharti#define	UTP_LOOP_TIME		0x0001	/* timing source loopback */
78116258Sharti#define	UTP_LOOP_DIAG		0x0002	/* diagnostic loopback */
79116258Sharti#define	UTP_LOOP_LINE		0x0004	/* serial line loopback */
80116258Sharti#define	UTP_LOOP_PARAL		0x0008	/* parallel diagnostic loopback */
81116258Sharti#define	UTP_LOOP_TWIST		0x0010	/* twisted pair diagnostic loopback */
82116258Sharti#define	UTP_LOOP_PATH		0x0020	/* diagnostic path loopback */
83116258Sharti
84116258Sharti/* type */
85116258Sharti#define	UTP_TYPE_UNKNOWN	0
86116258Sharti#define	UTP_TYPE_SUNI_LITE	1
87116258Sharti#define	UTP_TYPE_SUNI_ULTRA	2
88116258Sharti#define	UTP_TYPE_SUNI_622	3
89116258Sharti#define	UTP_TYPE_IDT77105	4
90117546Sharti#define	UTP_TYPE_IDT77155	5
91142384Sharti#define	UTP_TYPE_CX28250	6
92116258Sharti
93117552Sharti/*
94117552Sharti * Statistics. These structures are versioned.
95117552Sharti */
96117552Shartistruct utopia_stats1 {
97117552Sharti	uint32_t	version;	/* version of this statistics struct */
98117552Sharti	uint32_t	fill;
99117552Sharti
100117552Sharti	uint64_t	rx_sbip;	/* rx section BIP errors */
101117552Sharti	uint64_t	rx_lbip;	/* rx line BIP errors */
102117552Sharti	uint64_t	rx_lfebe;	/* rx line far end block errors */
103117552Sharti	uint64_t	rx_pbip;	/* rx path BIP errors */
104117552Sharti	uint64_t	rx_pfebe;	/* rx path far end block errors */
105117552Sharti	uint64_t	rx_cells;	/* received cells */
106117552Sharti	uint64_t	rx_corr;	/* correctable cell errors */
107117552Sharti	uint64_t	rx_uncorr;	/* uncorrectable cell errors */
108117552Sharti	uint64_t	rx_symerr;	/* symbol errors */
109117552Sharti
110117552Sharti	uint64_t	tx_cells;	/* transmitted cells */
111117552Sharti};
112117552Sharti
113116258Sharti#ifdef _KERNEL
114116258Sharti
115116258Sharti#include <sys/queue.h>
116116258Sharti
117116258Sharti/*
118116258Sharti * These must be implemented by the card driver
119116258Sharti */
120116258Shartistruct utopia_methods {
121116258Sharti	/* read at most n PHY registers starting at reg into val */
122116258Sharti	int	(*readregs)(struct ifatm *, u_int reg, uint8_t *val, u_int *n);
123116258Sharti
124116258Sharti	/* change the bits given by mask to them in val in register reg */
125116258Sharti	int	(*writereg)(struct ifatm *, u_int reg, u_int mask, u_int val);
126116258Sharti};
127116258Sharti
128116258Sharti/*
129116258Sharti * Public state
130116258Sharti */
131116258Shartistruct utopia {
132116258Sharti	struct ifatm	*ifatm;		/* driver data */
133116258Sharti	struct ifmedia	*media;		/* driver supplied */
134116258Sharti	struct mtx	*lock;		/* driver supplied */
135116258Sharti	const struct utopia_methods *methods;
136116258Sharti	LIST_ENTRY(utopia) link;	/* list of these structures */
137116258Sharti	u_int		flags;		/* flags set by the driver */
138116258Sharti	u_int		state;		/* current state */
139116258Sharti	u_int		carrier;	/* carrier state */
140116258Sharti	u_int		loopback;	/* loopback mode */
141116258Sharti	const struct utopia_chip *chip;	/* chip operations */
142117552Sharti	struct utopia_stats1 stats;	/* statistics */
143116258Sharti};
144116258Sharti
145116258Shartistruct utopia_chip {
146116258Sharti	/* type and name of the chip */
147116258Sharti	u_int	type;
148116258Sharti	const char *const name;
149116258Sharti
150116258Sharti	/* number of registers */
151116258Sharti	u_int	nregs;
152116258Sharti
153116258Sharti	/* reset chip to known state */
154116258Sharti	int	(*reset)(struct utopia *);
155116258Sharti
156116258Sharti	/* set SONET/SDH mode */
157116258Sharti	int	(*set_sdh)(struct utopia *, int sdh);
158116258Sharti
159116258Sharti	/* set idle/unassigned cells */
160116258Sharti	int	(*set_unass)(struct utopia *, int unass);
161116258Sharti
162116258Sharti	/* enable/disable scrambling */
163116258Sharti	int	(*set_noscramb)(struct utopia *, int noscramb);
164116258Sharti
165116258Sharti	/* update carrier status */
166116258Sharti	int	(*update_carrier)(struct utopia *);
167116258Sharti
168116258Sharti	/* set loopback mode */
169116258Sharti	int	(*set_loopback)(struct utopia *, u_int mode);
170116258Sharti
171116258Sharti	/* handle interrupt */
172116258Sharti	void	(*intr)(struct utopia *);
173117552Sharti
174117552Sharti	/* update statistics */
175117552Sharti	void	(*update_stats)(struct utopia *);
176116258Sharti};
177116258Sharti
178116258Sharti/*
179116258Sharti * These are implemented in the common utopia code
180116258Sharti */
181116258Shartiint utopia_attach(struct utopia *, struct ifatm *, struct ifmedia *,
182116258Sharti    struct mtx *, struct sysctl_ctx_list *, struct sysctl_oid_list *,
183116258Sharti    const struct utopia_methods *);
184116258Shartivoid utopia_detach(struct utopia *);
185116258Sharti
186116258Shartiint utopia_start(struct utopia *);
187116258Shartivoid utopia_stop(struct utopia *);
188116258Sharti
189116258Shartivoid utopia_init_media(struct utopia *);
190116258Shartivoid utopia_reset_media(struct utopia *);
191116258Sharti
192116258Sharti#define	utopia_reset(S)			((S)->chip->reset((S)))
193116258Sharti#define	utopia_set_sdh(S, SDH)		((S)->chip->set_sdh((S), (SDH)))
194116258Sharti#define	utopia_set_unass(S, U)		((S)->chip->set_unass((S), (U)))
195116258Sharti#define	utopia_set_noscramb(S, N)	((S)->chip->set_noscramb((S), (N)))
196116258Sharti#define	utopia_update_carrier(S)	((S)->chip->update_carrier((S)))
197117552Sharti#define	utopia_update_stats(S)		((S)->chip->update_stats((S)))
198116258Sharti#define	utopia_set_loopback(S, L)	((S)->chip->set_loopback((S), (L)))
199116258Sharti#define	utopia_intr(S)			((S)->chip->intr((S)))
200116258Sharti
201116258Sharti#endif /* _KERNEL */
202116258Sharti
203116258Sharti#endif	/* _DEV_UTOPIA_UTOPIA_H */
204