1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
.\" Copyright (c) 2003
.\" Fraunhofer Institute for Open Communication Systems (FhG Fokus).
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" Author: Hartmut Brandt <harti@FreeBSD.org>
.\"
.\" $FreeBSD$
.\"
.Dd May 8, 2003
.Dt UTOPIA 9
.Os
.Sh NAME
.Nm utopia
.Nd "driver module for ATM PHY chips"
.Sh SYNOPSIS
.In dev/utopia/utopia.h
.Ft int
.Fo utopia_attach
.Fa "struct utopia *utp" "struct ifatm *ifatm" "struct ifmedia *media"
.Fa "struct mtx *lock" "struct sysctl_ctx_list *ctx"
.Fa "struct sysctl_oid_list *tree" "const struct utopia_methods *vtab"
.Fc
.Ft void
.Fn utopia_detach "struct utopia *utp"
.Ft int
.Fn utopia_start "struct utopia *utp"
.Ft void
.Fn utopia_stop "struct utopia *utp"
.Ft void
.Fn utopia_init_media "struct utopia *utp"
.Ft void
.Fn utopia_reset_media "struct utopia *utp"
.Ft int
.Fn utopia_reset "struct utopia *utp"
.Ft int
.Fn utopia_set_sdh "struct utopia *utp" "int sdh"
.Ft int
.Fn utopia_set_unass "struct utopia *utp" "int unass"
.Ft int
.Fn utopia_set_noscramb "struct utopia *utp" "int noscramb"
.Ft int
.Fn utopia_update_carrier "struct utopia *utp"
.Ft int
.Fn utopia_set_loopback "struct utopia *utp" "u_int mode"
.Ft void
.Fn utopia_intr "struct utopia *utp"
.Ft void
.Fn utopia_update_stats "struct utopia *utp"
.Sh DESCRIPTION
This module is used by all ATM drivers for cards that use a number of known
PHY chips to provide uniform functionality.
The module implements status monitoring in either interrupt or polling mode,
media option handling and application access to PHY registers.
.Pp
To use this interface, a driver must implement two functions for reading and
writing PHY registers, and initialize the following structure with pointers
to these functions:
.Bd -literal -offset indent
struct utopia_methods {
int (*readregs)(struct ifatm *, u_int reg,
uint8_t *val, u_int *n);
int (*writereg)(struct ifatm *, u_int reg,
u_int mask, u_int val);
};
.Ed
.Pp
The
.Fn readregs
function should read PHY registers starting at register
.Fa reg .
The maximum number of registers to read is given by the integer pointed
to by
.Fa n .
The function should either return 0 on success, or an error code.
In the first case,
.Fa *n
should be set to the actual number of registers read.
The
.Fn writereg
function should write one register.
It must change all bits for which the corresponding bit in
.Fa mask
is 1 to the value of the corresponding bit in
.Fa val .
It returns either 0 on success, or an error code.
.Pp
The ATM driver's private state block
.Pq Va softc
must begin with a
.Vt "struct ifatm" .
.Pp
The
.Vt "struct utopia"
holds the current state of the PHY chip and contains the following fields:
.Bd -literal -offset indent
struct utopia {
struct ifatm *ifatm; /* driver data */
struct ifmedia *media; /* driver supplied */
struct mtx *lock; /* driver supplied */
const struct utopia_methods *methods;
LIST_ENTRY(utopia) link; /* list of these structures */
u_int flags; /* flags set by the driver */
u_int state; /* current state */
u_int carrier; /* carrier state */
u_int loopback; /* loopback mode */
const struct utopia_chip *chip; /* chip operations */
struct utopia_stats1 stats; /* statistics */
};
.Ed
The public accessible fields have the following functions:
.Bl -tag -width indent
.It Va ifatm
Pointer to the driver's private data
.Pq Va softc .
.It Va media
Pointer to the driver's media structure.
.It Va lock
Pointer to a mutex provided by the driver.
This mutex is used to synchronize
with the kernel thread that handles device polling.
It is locked in several
places:
.Bl -enum -offset indent
.It
In
.Fn utopia_detach
the mutex is locked to sleep and wait for the kernel thread to remove the
.Vt "struct utopia"
from the list of all
.Nm
devices.
Before returning to the caller the mutex is unlocked.
.It
In the
.Nm
kernel thread the mutex is locked, and the
.Fn utopia_carrier_update
function is called with this mutex locked.
This will result in the driver's
.Fn readregs
function being called with the mutex locked.
.It
In the sysctl handlers the mutex will be locked before calling into the driver's
.Fn readreg
or
.Fn writereg
functions.
.El
.It Va flags
Flags set by either the driver or the
.Nm
module.
The following flags are
defined:
.Bl -tag -width indent
.It Dv UTP_FL_NORESET
If this flag is set, the module will not try to write the
SUNI master reset register.
(Set by the driver.)
.It Dv UTP_FL_POLL_CARRIER
If this flag is set, the module will periodically poll the carrier state
(as opposed to interrupt driven carrier state changes).
(Set by the driver.)
.El
.It Va state
Flags describing the current state of the PHY chip.
These are managed
by the module:
.Bl -tag -width indent
.It Dv UTP_ST_ACTIVE
The driver is active and the PHY registers can be accessed.
This is set by calling
.Fn utopia_start ,
which should be called either in the attach routine of the driver or
in the network interface initialisation routine (depending on whether the
registers are accessible all the time or only when the interface is up).
.It Dv UTP_ST_SDH
Interface is in SDH mode as opposed to SONET mode.
.It Dv UTP_ST_UNASS
Interface is producing unassigned cells instead of idle cells.
.It Dv UTP_ST_NOSCRAMB
Cell scrambling is switched off.
.It Dv UTP_ST_DETACH
(Internal use.)
Interface is currently detaching.
.It Dv UTP_ST_ATTACHED
The attach routine has been run successfully.
.El
.It Va carrier
The carrier state of the interface.
This field can have one of three values:
.Bl -tag -width indent
.It Dv UTP_CARR_UNKNOWN
Carrier state is still unknown.
.It Dv UTP_CARR_OK
Carrier has been detected.
.It Dv UTP_CARR_LOST
Carrier has been lost.
.El
.It Va loopback
This is the current loopback mode of the interface.
Note that not all
chips support all loopback modes.
Refer to the chip documentation.
The
following modes may be supported:
.Bl -tag -width indent
.It Dv UTP_LOOP_NONE
No loopback, normal operation.
.It Dv UTP_LOOP_TIME
Timing source loopback.
The transmitter clock is driven by the receive clock.
.It Dv UTP_LOOP_DIAG
Diagnostic loopback.
.It Dv UTP_LOOP_LINE
Serial line loopback.
.It Dv UTP_LOOP_PARAL
Parallel diagnostic loopback.
.It Dv UTP_LOOP_TWIST
Twisted pair diagnostic loopback.
.It Dv UTP_LOOP_PATH
Diagnostic path loopback.
.El
.It Va chip
This points to a function vector for chip specific functions.
Two fields
in this vector are publically available:
.Bl -tag -width indent
.It Va type
This is the type of the detected PHY chip.
One of:
.Pp
.Bl -tag -width indent -compact
.It Dv UTP_TYPE_UNKNOWN Pq No 0
.It Dv UTP_TYPE_SUNI_LITE Pq No 1
.It Dv UTP_TYPE_SUNI_ULTRA Pq No 2
.It Dv UTP_TYPE_SUNI_622 Pq No 3
.It Dv UTP_TYPE_IDT77105 Pq No 4
.El
.It Va name
This is a string with the name of the PHY chip.
.El
.El
.Pp
The following functions are used by the driver during attach/detach and/or
initialisation/stopping the interface:
.Bl -tag -width indent
.It Fn utopia_attach
Attach the PHY chip.
This is called with a preallocated
.Vt "struct utopia"
(which may be part of the driver's
.Va softc ) .
The module initializes all fields of the
.Nm
state and the media field.
User settable flags should be set after the call to
.Fn utopia_attach .
This function may fail due to the inability to install the sysctl handlers.
In this case it will return \-1.
On success, 0 is returned and the
.Dv UTP_ST_ATTACHED
flag is set.
.It Fn utopia_detach
Remove the
.Nm
attachment from the system.
This cancels all outstanding polling
timeouts.
.It Fn utopia_start
Start operation of that PHY.
This should be called at a time
when the PHY registers are known to be accessible.
This may be either in
the driver's attach function or when the interface is set running.
.It Fn utopia_stop
Stop operation of the PHY attachment.
This may be called either in the detach
function of the driver or when the interface is brought down.
.It Fn utopia_init_media
This must be called if the media field in the ATM MIB was changed.
The function
makes sure, that the ifmedia fields contain the same information as the
ATM MIB.
.It Fn utopia_reset_media
This may be called to remove all media information from the ifmedia field.
.El
.Pp
The following functions can be used to modify the PHY state while the interface
is running:
.Bl -tag -width indent
.It Fn utopia_reset
Reset the operational parameters to the default state (SONET, idle cells,
scrambling enabled).
Returns 0 on success, an error code otherwise, leaving
the state undefined.
.It Fn utopia_set_sdh
If the argument is zero the chip is switched to Sonet mode, if it is non-zero
the chip is switched to SDH mode.
Returns 0 on success, an error code otherwise,
leaving the previous state.
.It Fn utopia_set_unass
If the argument is zero the chip is switched to produce idle cells, if it is
non-zero the chip is switched to produce unassigned cells.
Returns 0 on success,
an error code otherwise, leaving the previous state.
.It Fn utopia_set_noscramb
If the argument is zero enables scrambling, if it is
non-zero disables scrambling.
Returns 0 on success,
an error code otherwise, leaving the previous state.
.It Fn utopia_update_carrier
Check the carrier state and update the carrier field in the state structure.
This will generate a message to the Netgraph stack if the carrier state changes.
For chips that are polled this is called automatically, for interrupt
driven attachments this must be called on interrupts from the PHY chip.
.It Fn utopia_set_loopback
Set the loopback mode of the chip.
Returns 0 on success, an error code
otherwise, leaving the previous state.
.It Fn utopia_intr
Called when an interrupt from the PHY chip is detected.
This resets the
interrupt state by reading all registers and, if the interrupt was from the
RSOP, checks the carrier state.
.It Fn utopia_update_stats
Update the statistics with counters read from the chip.
.El
.Sh SEE ALSO
.Xr utopia 4
.Sh AUTHORS
.An Harti Brandt Aq harti@FreeBSD.org
|