1 | #include <machine/rtems-bsd-kernel-space.h> |
---|
2 | |
---|
3 | /* $NetBSD: ukphy.c,v 1.2 1999/04/23 04:24:32 thorpej Exp $ */ |
---|
4 | |
---|
5 | /*- |
---|
6 | * SPDX-License-Identifier: BSD-2-Clause-NetBSD |
---|
7 | * |
---|
8 | * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc. |
---|
9 | * All rights reserved. |
---|
10 | * |
---|
11 | * This code is derived from software contributed to The NetBSD Foundation |
---|
12 | * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, |
---|
13 | * NASA Ames Research Center, and by Frank van der Linden. |
---|
14 | * |
---|
15 | * Redistribution and use in source and binary forms, with or without |
---|
16 | * modification, are permitted provided that the following conditions |
---|
17 | * are met: |
---|
18 | * 1. Redistributions of source code must retain the above copyright |
---|
19 | * notice, this list of conditions and the following disclaimer. |
---|
20 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
21 | * notice, this list of conditions and the following disclaimer in the |
---|
22 | * documentation and/or other materials provided with the distribution. |
---|
23 | * |
---|
24 | * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
---|
25 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
---|
26 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
---|
27 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
---|
28 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
---|
29 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
---|
30 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
---|
31 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
---|
32 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
---|
33 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
---|
34 | * POSSIBILITY OF SUCH DAMAGE. |
---|
35 | */ |
---|
36 | |
---|
37 | /*- |
---|
38 | * Copyright (c) 1997 Manuel Bouyer. All rights reserved. |
---|
39 | * |
---|
40 | * Redistribution and use in source and binary forms, with or without |
---|
41 | * modification, are permitted provided that the following conditions |
---|
42 | * are met: |
---|
43 | * 1. Redistributions of source code must retain the above copyright |
---|
44 | * notice, this list of conditions and the following disclaimer. |
---|
45 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
46 | * notice, this list of conditions and the following disclaimer in the |
---|
47 | * documentation and/or other materials provided with the distribution. |
---|
48 | * |
---|
49 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
---|
50 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
---|
51 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
---|
52 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
---|
53 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
---|
54 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
---|
55 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
---|
56 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
---|
57 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
---|
58 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
59 | */ |
---|
60 | |
---|
61 | #include <sys/cdefs.h> |
---|
62 | __FBSDID("$FreeBSD$"); |
---|
63 | |
---|
64 | /* |
---|
65 | * driver for generic unknown PHYs |
---|
66 | */ |
---|
67 | |
---|
68 | #include <sys/param.h> |
---|
69 | #include <sys/systm.h> |
---|
70 | #include <sys/kernel.h> |
---|
71 | #include <sys/socket.h> |
---|
72 | #include <sys/errno.h> |
---|
73 | #include <sys/module.h> |
---|
74 | #include <sys/bus.h> |
---|
75 | |
---|
76 | #include <net/if.h> |
---|
77 | #include <net/if_media.h> |
---|
78 | |
---|
79 | #include <dev/mii/mii.h> |
---|
80 | #include <dev/mii/miivar.h> |
---|
81 | |
---|
82 | #include <rtems/bsd/local/miibus_if.h> |
---|
83 | |
---|
84 | static int ukphy_probe(device_t); |
---|
85 | static int ukphy_attach(device_t); |
---|
86 | |
---|
87 | static device_method_t ukphy_methods[] = { |
---|
88 | /* device interface */ |
---|
89 | DEVMETHOD(device_probe, ukphy_probe), |
---|
90 | DEVMETHOD(device_attach, ukphy_attach), |
---|
91 | DEVMETHOD(device_detach, mii_phy_detach), |
---|
92 | DEVMETHOD(device_shutdown, bus_generic_shutdown), |
---|
93 | DEVMETHOD_END |
---|
94 | }; |
---|
95 | |
---|
96 | static devclass_t ukphy_devclass; |
---|
97 | |
---|
98 | static driver_t ukphy_driver = { |
---|
99 | "ukphy", |
---|
100 | ukphy_methods, |
---|
101 | sizeof(struct mii_softc) |
---|
102 | }; |
---|
103 | |
---|
104 | DRIVER_MODULE(ukphy, miibus, ukphy_driver, ukphy_devclass, 0, 0); |
---|
105 | |
---|
106 | static int ukphy_service(struct mii_softc *, struct mii_data *, int); |
---|
107 | |
---|
108 | static const struct mii_phy_funcs ukphy_funcs = { |
---|
109 | ukphy_service, |
---|
110 | ukphy_status, |
---|
111 | mii_phy_reset |
---|
112 | }; |
---|
113 | |
---|
114 | static int |
---|
115 | ukphy_probe(device_t dev) |
---|
116 | { |
---|
117 | |
---|
118 | /* |
---|
119 | * We know something is here, so always match at a low priority. |
---|
120 | */ |
---|
121 | device_set_desc(dev, "Generic IEEE 802.3u media interface"); |
---|
122 | return (BUS_PROBE_GENERIC); |
---|
123 | } |
---|
124 | |
---|
125 | static int |
---|
126 | ukphy_attach(device_t dev) |
---|
127 | { |
---|
128 | struct mii_softc *sc; |
---|
129 | |
---|
130 | sc = device_get_softc(dev); |
---|
131 | |
---|
132 | mii_phy_dev_attach(dev, MIIF_NOMANPAUSE, &ukphy_funcs, 1); |
---|
133 | mii_phy_setmedia(sc); |
---|
134 | |
---|
135 | return (0); |
---|
136 | } |
---|
137 | |
---|
138 | static int |
---|
139 | ukphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) |
---|
140 | { |
---|
141 | |
---|
142 | switch (cmd) { |
---|
143 | case MII_POLLSTAT: |
---|
144 | break; |
---|
145 | |
---|
146 | case MII_MEDIACHG: |
---|
147 | mii_phy_setmedia(sc); |
---|
148 | break; |
---|
149 | |
---|
150 | case MII_TICK: |
---|
151 | if (mii_phy_tick(sc) == EJUSTRETURN) |
---|
152 | return (0); |
---|
153 | break; |
---|
154 | } |
---|
155 | |
---|
156 | /* Update the media status. */ |
---|
157 | PHY_STATUS(sc); |
---|
158 | |
---|
159 | /* Callback if something changed. */ |
---|
160 | mii_phy_update(sc, cmd); |
---|
161 | return (0); |
---|
162 | } |
---|