3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * Author: Hartmut Brandt <harti@freebsd.org>
31 #ifndef _DEV_UTOPIA_UTOPIA_H
32 #define _DEV_UTOPIA_UTOPIA_H
34 /* Structure for user-level register formatting */
36 uint8_t type; /* register type */
37 uint8_t reg; /* register number */
38 const char *name; /* register name */
39 const char *fmt; /* format for printing */
45 #define UTP_REGT_BITS 0x0 /* use printb to print */
46 #define UTP_REGT_INT8 0x1 /* 8 bit hex number */
47 #define UTP_REGT_INT10BITS 0x2 /* 10 bit hex number + 6 bit printb */
48 #define UTP_REGT_INT12 0x3 /* 12 bit LE hex */
49 #define UTP_REGT_INT16 0x4 /* 16 bit LE hex */
50 #define UTP_REGT_INT19 0x5 /* 19 bit LE hex */
51 #define UTP_REGT_INT20 0x6 /* 20 bit LE hex */
52 #define UTP_REGT_INT21 0x7 /* 21 bit LE hex */
54 /* number of additional registers per type */
55 #define UTP_REG_ADD 0, 0, 1, 1, 1, 2, 2, 2
58 #define UTP_FL_NORESET 0x0001 /* cannot write MRESET register */
59 #define UTP_FL_POLL_CARRIER 0x0002 /* need to poll for carrier */
62 #define UTP_ST_ACTIVE 0x0001 /* registers accessible */
63 #define UTP_ST_SDH 0x0002 /* SDH or SONET */
64 #define UTP_ST_UNASS 0x0004 /* produce unassigned cells */
65 #define UTP_ST_NOSCRAMB 0x0008 /* no scrambling */
66 #define UTP_ST_DETACH 0x0010 /* detaching */
67 #define UTP_ST_ATTACHED 0x0020 /* successful attached */
70 #define UTP_CARR_UNKNOWN 0
72 #define UTP_CARR_LOST 2
75 #define UTP_LOOP_NONE 0x0000
76 #define UTP_LOOP_TIME 0x0001 /* timing source loopback */
77 #define UTP_LOOP_DIAG 0x0002 /* diagnostic loopback */
78 #define UTP_LOOP_LINE 0x0004 /* serial line loopback */
79 #define UTP_LOOP_PARAL 0x0008 /* parallel diagnostic loopback */
80 #define UTP_LOOP_TWIST 0x0010 /* twisted pair diagnostic loopback */
81 #define UTP_LOOP_PATH 0x0020 /* diagnostic path loopback */
84 #define UTP_TYPE_UNKNOWN 0
85 #define UTP_TYPE_SUNI_LITE 1
86 #define UTP_TYPE_SUNI_ULTRA 2
87 #define UTP_TYPE_SUNI_622 3
88 #define UTP_TYPE_IDT77105 4
89 #define UTP_TYPE_IDT77155 5
92 * Statistics. These structures are versioned.
94 struct utopia_stats1 {
95 uint32_t version; /* version of this statistics struct */
98 uint64_t rx_sbip; /* rx section BIP errors */
99 uint64_t rx_lbip; /* rx line BIP errors */
100 uint64_t rx_lfebe; /* rx line far end block errors */
101 uint64_t rx_pbip; /* rx path BIP errors */
102 uint64_t rx_pfebe; /* rx path far end block errors */
103 uint64_t rx_cells; /* received cells */
104 uint64_t rx_corr; /* correctable cell errors */
105 uint64_t rx_uncorr; /* uncorrectable cell errors */
106 uint64_t rx_symerr; /* symbol errors */
108 uint64_t tx_cells; /* transmitted cells */
113 #include <sys/queue.h>
116 * These must be implemented by the card driver
118 struct utopia_methods {
119 /* read at most n PHY registers starting at reg into val */
120 int (*readregs)(struct ifatm *, u_int reg, uint8_t *val, u_int *n);
122 /* change the bits given by mask to them in val in register reg */
123 int (*writereg)(struct ifatm *, u_int reg, u_int mask, u_int val);
130 struct ifatm *ifatm; /* driver data */
131 struct ifmedia *media; /* driver supplied */
132 struct mtx *lock; /* driver supplied */
133 const struct utopia_methods *methods;
134 LIST_ENTRY(utopia) link; /* list of these structures */
135 u_int flags; /* flags set by the driver */
136 u_int state; /* current state */
137 u_int carrier; /* carrier state */
138 u_int loopback; /* loopback mode */
139 const struct utopia_chip *chip; /* chip operations */
140 struct utopia_stats1 stats; /* statistics */
144 /* type and name of the chip */
146 const char *const name;
148 /* number of registers */
151 /* reset chip to known state */
152 int (*reset)(struct utopia *);
154 /* set SONET/SDH mode */
155 int (*set_sdh)(struct utopia *, int sdh);
157 /* set idle/unassigned cells */
158 int (*set_unass)(struct utopia *, int unass);
160 /* enable/disable scrambling */
161 int (*set_noscramb)(struct utopia *, int noscramb);
163 /* update carrier status */
164 int (*update_carrier)(struct utopia *);
166 /* set loopback mode */
167 int (*set_loopback)(struct utopia *, u_int mode);
169 /* handle interrupt */
170 void (*intr)(struct utopia *);
172 /* update statistics */
173 void (*update_stats)(struct utopia *);
177 * These are implemented in the common utopia code
179 int utopia_attach(struct utopia *, struct ifatm *, struct ifmedia *,
180 struct mtx *, struct sysctl_ctx_list *, struct sysctl_oid_list *,
181 const struct utopia_methods *);
182 void utopia_detach(struct utopia *);
184 int utopia_start(struct utopia *);
185 void utopia_stop(struct utopia *);
187 void utopia_init_media(struct utopia *);
188 void utopia_reset_media(struct utopia *);
190 #define utopia_reset(S) ((S)->chip->reset((S)))
191 #define utopia_set_sdh(S, SDH) ((S)->chip->set_sdh((S), (SDH)))
192 #define utopia_set_unass(S, U) ((S)->chip->set_unass((S), (U)))
193 #define utopia_set_noscramb(S, N) ((S)->chip->set_noscramb((S), (N)))
194 #define utopia_update_carrier(S) ((S)->chip->update_carrier((S)))
195 #define utopia_update_stats(S) ((S)->chip->update_stats((S)))
196 #define utopia_set_loopback(S, L) ((S)->chip->set_loopback((S), (L)))
197 #define utopia_intr(S) ((S)->chip->intr((S)))
201 #endif /* _DEV_UTOPIA_UTOPIA_H */