UTOPIA(9) | MidnightBSD Kernel Developer's Manual | UTOPIA(9) |
utopia
— driver
module for ATM PHY chips
#include
<dev/utopia/utopia.h>
int
utopia_attach
(struct utopia
*utp, struct ifatm *ifatm,
struct ifmedia *media, struct mtx
*lock, struct sysctl_ctx_list *ctx,
struct sysctl_oid_list *tree, const
struct utopia_methods *vtab);
void
utopia_detach
(struct
utopia *utp);
int
utopia_start
(struct
utopia *utp);
void
utopia_stop
(struct
utopia *utp);
void
utopia_init_media
(struct
utopia *utp);
void
utopia_reset_media
(struct
utopia *utp);
int
utopia_reset
(struct
utopia *utp);
int
utopia_set_sdh
(struct
utopia *utp, int
sdh);
int
utopia_set_unass
(struct
utopia *utp, int
unass);
int
utopia_set_noscramb
(struct
utopia *utp, int
noscramb);
int
utopia_update_carrier
(struct
utopia *utp);
int
utopia_set_loopback
(struct
utopia *utp, u_int
mode);
void
utopia_intr
(struct
utopia *utp);
void
utopia_update_stats
(struct
utopia *utp);
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.
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:
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); };
The
readregs
()
function should read PHY registers starting at register
reg. The maximum number of registers to read is given
by the integer pointed to by n. The function should
either return 0 on success, or an error code. In the first case,
*n should be set to the actual number of registers
read. The
writereg
()
function should write one register. It must change all bits for which the
corresponding bit in mask is 1 to the value of the
corresponding bit in val. It returns either 0 on
success, or an error code.
The ATM driver's private state block (softc) must begin with a struct ifatm.
The struct utopia holds the current state of the PHY chip and contains the following fields:
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 */ };
utopia_detach
()
the mutex is locked to sleep and wait for the kernel thread to remove
the struct utopia from the list of all
utopia
devices. Before returning to the caller
the mutex is unlocked.utopia
kernel thread the mutex is locked, and the
utopia_carrier_update
()
function is called with this mutex locked. This will result in the
driver's readregs
() function being called with
the mutex locked.readreg
()
or writereg
() functions.utopia
module. The following flags are defined:
UTP_FL_NORESET
UTP_FL_POLL_CARRIER
UTP_ST_ACTIVE
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).UTP_ST_SDH
UTP_ST_UNASS
UTP_ST_NOSCRAMB
UTP_ST_DETACH
UTP_ST_ATTACHED
UTP_CARR_UNKNOWN
UTP_CARR_OK
UTP_CARR_LOST
UTP_LOOP_NONE
UTP_LOOP_TIME
UTP_LOOP_DIAG
UTP_LOOP_LINE
UTP_LOOP_PARAL
UTP_LOOP_TWIST
UTP_LOOP_PATH
UTP_TYPE_UNKNOWN
(0)UTP_TYPE_SUNI_LITE
(1)UTP_TYPE_SUNI_ULTRA
(2)UTP_TYPE_SUNI_622
(3)UTP_TYPE_IDT77105
(4)The following functions are used by the driver during attach/detach and/or initialisation/stopping the interface:
utopia_attach
()utopia
state and the media field. User settable
flags should be set after the call to
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 UTP_ST_ATTACHED
flag is set.utopia_detach
()utopia
attachment from the system. This
cancels all outstanding polling timeouts.utopia_start
()utopia_stop
()utopia_init_media
()utopia_reset_media
()The following functions can be used to modify the PHY state while the interface is running:
utopia_reset
()utopia_set_sdh
()utopia_set_unass
()utopia_set_noscramb
()utopia_update_carrier
()utopia_set_loopback
()utopia_intr
()utopia_update_stats
()Harti Brandt <harti@FreeBSD.org>
May 8, 2003 | midnightbsd-3.1 |