FreeBSD/sys/dev/utopia/utopia.c
/*
 * Initialize the state. This is called from the drivers attach
 * function. The mutex must be already initialized.
 */
Initialize the state. This is called from the drivers attach
function. The mutex must be already initialized.
Initialize the state . This is called from the drivers attach function . The mutex must be already initialized .
int
utopia_attach(struct utopia *utp, struct ifatm *ifatm, struct ifmedia *media,
    struct mtx *lock, struct sysctl_ctx_list *ctx,
    struct sysctl_oid_list *children, const struct utopia_methods *m)
{
	bzero(utp, sizeof(*utp));
	utp->ifatm = ifatm;
	utp->methods = m;
	utp->media = media;
	utp->lock = lock;
	utp->chip = &utopia_chip_unknown;
	utp->stats.version = 1;
	ifmedia_init(media,
	    IFM_ATM_SDH | IFM_ATM_UNASSIGNED | IFM_ATM_NOSCRAMB,
	    utopia_media_change, utopia_media_status);
	if (SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "phy_regs",
	    CTLFLAG_RW | CTLTYPE_OPAQUE, utp, 0, utopia_sysctl_regs, "S",
	    "phy registers") == NULL)
		return (-1);
	if (SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "phy_loopback",
	    CTLFLAG_RW | CTLTYPE_UINT, utp, 0, utopia_sysctl_loopback, "IU",
	    "phy loopback mode") == NULL)
		return (-1);
	if (SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "phy_type",
	    CTLFLAG_RD | CTLTYPE_UINT, utp, 0, utopia_sysctl_type, "IU",
	    "phy type") == NULL)
		return (-1);
	if (SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "phy_name",
	    CTLFLAG_RD | CTLTYPE_STRING, utp, 0, utopia_sysctl_name, "A",
	    "phy name") == NULL)
		return (-1);
	if (SYSCTL_ADD_PROC(ctx, children, OID_AUTO, "phy_stats",
	    CTLFLAG_RW | CTLTYPE_OPAQUE, utp, 0, utopia_sysctl_stats, "S",
	    "phy statistics") == NULL)
		return (-1);
	if (SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "phy_state",
	    CTLFLAG_RD, &utp->state, 0, "phy state") == NULL)
		return (-1);
	if (SYSCTL_ADD_UINT(ctx, children, OID_AUTO, "phy_carrier",
	    CTLFLAG_RD, &utp->carrier, 0, "phy carrier") == NULL)
		return (-1);
	UTP_WLOCK_LIST();
	LIST_INSERT_HEAD(&utopia_list, utp, link);
	UTP_WUNLOCK_LIST();
	utp->state |= UTP_ST_ATTACHED;
	return (0);
}
int utopia_attach ( struct utopia * utp , struct ifatm * ifatm , struct ifmedia * media , struct mtx * lock , struct sysctl_ctx_list * ctx , struct sysctl_oid_list * children , const struct utopia_methods * m ) { bzero ( utp , sizeof ( * utp ) ) ; utp -> ifatm = ifatm ; utp -> methods = m ; utp -> media = media ; utp -> lock = lock ; utp -> chip = & utopia_chip_unknown ; utp -> stats . version = 1 ; ifmedia_init ( media , IFM_ATM_SDH | IFM_ATM_UNASSIGNED | IFM_ATM_NOSCRAMB , utopia_media_change , utopia_media_status ) ; if ( SYSCTL_ADD_PROC ( ctx , children , OID_AUTO , " " , CTLFLAG_RW | CTLTYPE_OPAQUE , utp , 0 , utopia_sysctl_regs , " " , " " ) == NULL ) return ( -1 ) ; if ( SYSCTL_ADD_PROC ( ctx , children , OID_AUTO , " " , CTLFLAG_RW | CTLTYPE_UINT , utp , 0 , utopia_sysctl_loopback , " " , " " ) == NULL ) return ( -1 ) ; if ( SYSCTL_ADD_PROC ( ctx , children , OID_AUTO , " " , CTLFLAG_RD | CTLTYPE_UINT , utp , 0 , utopia_sysctl_type , " " , " " ) == NULL ) return ( -1 ) ; if ( SYSCTL_ADD_PROC ( ctx , children , OID_AUTO , " " , CTLFLAG_RD | CTLTYPE_STRING , utp , 0 , utopia_sysctl_name , " " , " " ) == NULL ) return ( -1 ) ; if ( SYSCTL_ADD_PROC ( ctx , children , OID_AUTO , " " , CTLFLAG_RW | CTLTYPE_OPAQUE , utp , 0 , utopia_sysctl_stats , " " , " " ) == NULL ) return ( -1 ) ; if ( SYSCTL_ADD_UINT ( ctx , children , OID_AUTO , " " , CTLFLAG_RD , & utp -> state , 0 , " " ) == NULL ) return ( -1 ) ; if ( SYSCTL_ADD_UINT ( ctx , children , OID_AUTO , " " , CTLFLAG_RD , & utp -> carrier , 0 , " " ) == NULL ) return ( -1 ) ; UTP_WLOCK_LIST ( ) ; LIST_INSERT_HEAD ( & utopia_list , utp , link ) ; UTP_WUNLOCK_LIST ( ) ; utp -> state |= UTP_ST_ATTACHED ; return ( 0 ) ; }
Initialize the state.
Initialize the state .