mii_ethersubr.c revision 1.2 1 1.2 msaitoh /* $NetBSD: mii_ethersubr.c,v 1.2 2019/03/25 07:09:54 msaitoh 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.2 msaitoh __KERNEL_RCSID(0, "$NetBSD: mii_ethersubr.c,v 1.2 2019/03/25 07:09:54 msaitoh Exp $");
65 1.2 msaitoh
66 1.1 dyoung #include <sys/param.h>
67 1.1 dyoung #include <sys/systm.h>
68 1.1 dyoung #include <sys/kernel.h>
69 1.1 dyoung #include <sys/errno.h>
70 1.1 dyoung #include <sys/device.h>
71 1.1 dyoung
72 1.1 dyoung #include <net/if.h>
73 1.1 dyoung #include <net/if_types.h>
74 1.1 dyoung
75 1.1 dyoung #include <net/if_ether.h>
76 1.1 dyoung #include <net/if_media.h>
77 1.1 dyoung #include <dev/mii/mii.h>
78 1.1 dyoung #include <dev/mii/miivar.h>
79 1.1 dyoung
80 1.1 dyoung int
81 1.1 dyoung ether_mediachange(struct ifnet *ifp)
82 1.1 dyoung {
83 1.1 dyoung struct ethercom *ec = (struct ethercom *)ifp;
84 1.1 dyoung int rc;
85 1.1 dyoung
86 1.1 dyoung KASSERT(ec->ec_mii != NULL);
87 1.1 dyoung
88 1.1 dyoung if ((ifp->if_flags & IFF_UP) == 0)
89 1.1 dyoung return 0;
90 1.1 dyoung if ((rc = mii_mediachg(ec->ec_mii)) == ENXIO)
91 1.1 dyoung return 0;
92 1.1 dyoung return rc;
93 1.1 dyoung }
94 1.1 dyoung
95 1.1 dyoung void
96 1.1 dyoung ether_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
97 1.1 dyoung {
98 1.1 dyoung struct ethercom *ec = (struct ethercom *)ifp;
99 1.1 dyoung struct mii_data *mii;
100 1.1 dyoung
101 1.1 dyoung KASSERT(ec->ec_mii != NULL);
102 1.1 dyoung
103 1.1 dyoung #ifdef notyet
104 1.1 dyoung if ((ifp->if_flags & IFF_RUNNING) == 0) {
105 1.1 dyoung ifmr->ifm_active = IFM_ETHER | IFM_NONE;
106 1.1 dyoung ifmr->ifm_status = 0;
107 1.1 dyoung return;
108 1.1 dyoung }
109 1.1 dyoung #endif
110 1.1 dyoung
111 1.1 dyoung mii = ec->ec_mii;
112 1.1 dyoung
113 1.1 dyoung mii_pollstat(mii);
114 1.1 dyoung ifmr->ifm_active = mii->mii_media_active;
115 1.1 dyoung ifmr->ifm_status = mii->mii_media_status;
116 1.1 dyoung }
117