1 1.3 thorpej /* $NetBSD: mii_ethersubr.c,v 1.3 2020/03/15 23:04:50 thorpej Exp $ */ 2 1.2 msaitoh 3 1.2 msaitoh /* 4 1.2 msaitoh * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 5 1.2 msaitoh * All rights reserved. 6 1.2 msaitoh * 7 1.2 msaitoh * Redistribution and use in source and binary forms, with or without 8 1.2 msaitoh * modification, are permitted provided that the following conditions 9 1.2 msaitoh * are met: 10 1.2 msaitoh * 1. Redistributions of source code must retain the above copyright 11 1.2 msaitoh * notice, this list of conditions and the following disclaimer. 12 1.2 msaitoh * 2. Redistributions in binary form must reproduce the above copyright 13 1.2 msaitoh * notice, this list of conditions and the following disclaimer in the 14 1.2 msaitoh * documentation and/or other materials provided with the distribution. 15 1.2 msaitoh * 3. Neither the name of the project nor the names of its contributors 16 1.2 msaitoh * may be used to endorse or promote products derived from this software 17 1.2 msaitoh * without specific prior written permission. 18 1.2 msaitoh * 19 1.2 msaitoh * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 20 1.2 msaitoh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 1.2 msaitoh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 1.2 msaitoh * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 23 1.2 msaitoh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 1.2 msaitoh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 1.2 msaitoh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 1.2 msaitoh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 1.2 msaitoh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 1.2 msaitoh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 1.2 msaitoh * SUCH DAMAGE. 30 1.2 msaitoh */ 31 1.2 msaitoh 32 1.2 msaitoh /* 33 1.2 msaitoh * Copyright (c) 1982, 1989, 1993 34 1.2 msaitoh * The Regents of the University of California. All rights reserved. 35 1.2 msaitoh * 36 1.2 msaitoh * Redistribution and use in source and binary forms, with or without 37 1.2 msaitoh * modification, are permitted provided that the following conditions 38 1.2 msaitoh * are met: 39 1.2 msaitoh * 1. Redistributions of source code must retain the above copyright 40 1.2 msaitoh * notice, this list of conditions and the following disclaimer. 41 1.2 msaitoh * 2. Redistributions in binary form must reproduce the above copyright 42 1.2 msaitoh * notice, this list of conditions and the following disclaimer in the 43 1.2 msaitoh * documentation and/or other materials provided with the distribution. 44 1.2 msaitoh * 3. Neither the name of the University nor the names of its contributors 45 1.2 msaitoh * may be used to endorse or promote products derived from this software 46 1.2 msaitoh * without specific prior written permission. 47 1.2 msaitoh * 48 1.2 msaitoh * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 49 1.2 msaitoh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 50 1.2 msaitoh * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 51 1.2 msaitoh * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 52 1.2 msaitoh * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 53 1.2 msaitoh * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 54 1.2 msaitoh * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 55 1.2 msaitoh * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 56 1.2 msaitoh * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 57 1.2 msaitoh * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 58 1.2 msaitoh * SUCH DAMAGE. 59 1.2 msaitoh * 60 1.2 msaitoh * @(#)if_ethersubr.c 8.2 (Berkeley) 4/4/96 61 1.2 msaitoh */ 62 1.2 msaitoh 63 1.2 msaitoh #include <sys/cdefs.h> 64 1.3 thorpej __KERNEL_RCSID(0, "$NetBSD: mii_ethersubr.c,v 1.3 2020/03/15 23:04:50 thorpej Exp $"); 65 1.3 thorpej 66 1.3 thorpej #define __IFMEDIA_PRIVATE 67 1.2 msaitoh 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.3 thorpej KASSERT(mii_locked(ec->ec_mii) || 90 1.3 thorpej 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.3 thorpej KASSERT(mii_locked(ec->ec_mii) || 107 1.3 thorpej 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