Home | History | Annotate | Line # | Download | only in mii
mii_ethersubr.c revision 1.1.106.2
      1  1.1.106.2    martin /* $NetBSD: mii_ethersubr.c,v 1.1.106.2 2020/04/08 14:08:08 martin Exp $ */
      2  1.1.106.1  christos 
      3  1.1.106.1  christos /*
      4  1.1.106.1  christos  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
      5  1.1.106.1  christos  * All rights reserved.
      6  1.1.106.1  christos  *
      7  1.1.106.1  christos  * Redistribution and use in source and binary forms, with or without
      8  1.1.106.1  christos  * modification, are permitted provided that the following conditions
      9  1.1.106.1  christos  * are met:
     10  1.1.106.1  christos  * 1. Redistributions of source code must retain the above copyright
     11  1.1.106.1  christos  *    notice, this list of conditions and the following disclaimer.
     12  1.1.106.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1.106.1  christos  *    notice, this list of conditions and the following disclaimer in the
     14  1.1.106.1  christos  *    documentation and/or other materials provided with the distribution.
     15  1.1.106.1  christos  * 3. Neither the name of the project nor the names of its contributors
     16  1.1.106.1  christos  *    may be used to endorse or promote products derived from this software
     17  1.1.106.1  christos  *    without specific prior written permission.
     18  1.1.106.1  christos  *
     19  1.1.106.1  christos  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
     20  1.1.106.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     21  1.1.106.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     22  1.1.106.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
     23  1.1.106.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  1.1.106.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     25  1.1.106.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  1.1.106.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  1.1.106.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  1.1.106.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  1.1.106.1  christos  * SUCH DAMAGE.
     30  1.1.106.1  christos  */
     31  1.1.106.1  christos 
     32  1.1.106.1  christos /*
     33  1.1.106.1  christos  * Copyright (c) 1982, 1989, 1993
     34  1.1.106.1  christos  *	The Regents of the University of California.  All rights reserved.
     35  1.1.106.1  christos  *
     36  1.1.106.1  christos  * Redistribution and use in source and binary forms, with or without
     37  1.1.106.1  christos  * modification, are permitted provided that the following conditions
     38  1.1.106.1  christos  * are met:
     39  1.1.106.1  christos  * 1. Redistributions of source code must retain the above copyright
     40  1.1.106.1  christos  *    notice, this list of conditions and the following disclaimer.
     41  1.1.106.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     42  1.1.106.1  christos  *    notice, this list of conditions and the following disclaimer in the
     43  1.1.106.1  christos  *    documentation and/or other materials provided with the distribution.
     44  1.1.106.1  christos  * 3. Neither the name of the University nor the names of its contributors
     45  1.1.106.1  christos  *    may be used to endorse or promote products derived from this software
     46  1.1.106.1  christos  *    without specific prior written permission.
     47  1.1.106.1  christos  *
     48  1.1.106.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     49  1.1.106.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     50  1.1.106.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     51  1.1.106.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     52  1.1.106.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     53  1.1.106.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     54  1.1.106.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     55  1.1.106.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     56  1.1.106.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     57  1.1.106.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     58  1.1.106.1  christos  * SUCH DAMAGE.
     59  1.1.106.1  christos  *
     60  1.1.106.1  christos  *	@(#)if_ethersubr.c	8.2 (Berkeley) 4/4/96
     61  1.1.106.1  christos  */
     62  1.1.106.1  christos 
     63  1.1.106.1  christos #include <sys/cdefs.h>
     64  1.1.106.2    martin __KERNEL_RCSID(0, "$NetBSD: mii_ethersubr.c,v 1.1.106.2 2020/04/08 14:08:08 martin Exp $");
     65  1.1.106.2    martin 
     66  1.1.106.2    martin #define	__IFMEDIA_PRIVATE
     67  1.1.106.1  christos 
     68        1.1    dyoung #include <sys/param.h>
     69        1.1    dyoung #include <sys/systm.h>
     70        1.1    dyoung #include <sys/kernel.h>
     71        1.1    dyoung #include <sys/errno.h>
     72        1.1    dyoung #include <sys/device.h>
     73        1.1    dyoung 
     74        1.1    dyoung #include <net/if.h>
     75        1.1    dyoung #include <net/if_types.h>
     76        1.1    dyoung 
     77        1.1    dyoung #include <net/if_ether.h>
     78        1.1    dyoung #include <net/if_media.h>
     79        1.1    dyoung #include <dev/mii/mii.h>
     80        1.1    dyoung #include <dev/mii/miivar.h>
     81        1.1    dyoung 
     82        1.1    dyoung int
     83        1.1    dyoung ether_mediachange(struct ifnet *ifp)
     84        1.1    dyoung {
     85        1.1    dyoung 	struct ethercom *ec = (struct ethercom *)ifp;
     86        1.1    dyoung 	int rc;
     87        1.1    dyoung 
     88        1.1    dyoung 	KASSERT(ec->ec_mii != NULL);
     89  1.1.106.2    martin 	KASSERT(mii_locked(ec->ec_mii) ||
     90  1.1.106.2    martin 		ifmedia_islegacy(&ec->ec_mii->mii_media));
     91        1.1    dyoung 
     92        1.1    dyoung 	if ((ifp->if_flags & IFF_UP) == 0)
     93        1.1    dyoung 		return 0;
     94        1.1    dyoung 	if ((rc = mii_mediachg(ec->ec_mii)) == ENXIO)
     95        1.1    dyoung 		return 0;
     96        1.1    dyoung 	return rc;
     97        1.1    dyoung }
     98        1.1    dyoung 
     99        1.1    dyoung void
    100        1.1    dyoung ether_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
    101        1.1    dyoung {
    102        1.1    dyoung 	struct ethercom	*ec = (struct ethercom	*)ifp;
    103        1.1    dyoung 	struct mii_data		*mii;
    104        1.1    dyoung 
    105        1.1    dyoung 	KASSERT(ec->ec_mii != NULL);
    106  1.1.106.2    martin 	KASSERT(mii_locked(ec->ec_mii) ||
    107  1.1.106.2    martin 		ifmedia_islegacy(&ec->ec_mii->mii_media));
    108        1.1    dyoung 
    109        1.1    dyoung #ifdef notyet
    110        1.1    dyoung 	if ((ifp->if_flags & IFF_RUNNING) == 0) {
    111        1.1    dyoung 		ifmr->ifm_active = IFM_ETHER | IFM_NONE;
    112        1.1    dyoung 		ifmr->ifm_status = 0;
    113        1.1    dyoung 		return;
    114        1.1    dyoung 	}
    115        1.1    dyoung #endif
    116        1.1    dyoung 
    117        1.1    dyoung 	mii = ec->ec_mii;
    118        1.1    dyoung 
    119        1.1    dyoung 	mii_pollstat(mii);
    120        1.1    dyoung 	ifmr->ifm_active = mii->mii_media_active;
    121        1.1    dyoung 	ifmr->ifm_status = mii->mii_media_status;
    122        1.1    dyoung }
    123