FreeBSD/Linux Kernel Cross Reference
sys/dev/mii/pnaphy.c
1 /*-
2 * Copyright (c) 2000 Berkeley Software Design, Inc.
3 * Copyright (c) 1997, 1998, 1999, 2000
4 * Bill Paul <wpaul@osd.bsdi.com>. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Bill Paul.
17 * 4. Neither the name of the author nor the names of any co-contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
36
37 /*
38 * driver for homePNA PHYs
39 * This is really just a stub that allows us to identify homePNA-based
40 * transceicers and display the link status. MII-based homePNA PHYs
41 * only support one media type and no autonegotiation. If we were
42 * really clever, we could tweak some of the vendor-specific registers
43 * to optimize the link.
44 */
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/socket.h>
50 #include <sys/errno.h>
51 #include <sys/module.h>
52 #include <sys/bus.h>
53
54 #include <net/if.h>
55 #include <net/if_media.h>
56
57 #include <dev/mii/mii.h>
58 #include <dev/mii/miivar.h>
59 #include "miidevs.h"
60
61 #include "miibus_if.h"
62
63 static int pnaphy_probe(device_t);
64 static int pnaphy_attach(device_t);
65
66 static device_method_t pnaphy_methods[] = {
67 /* device interface */
68 DEVMETHOD(device_probe, pnaphy_probe),
69 DEVMETHOD(device_attach, pnaphy_attach),
70 DEVMETHOD(device_detach, mii_phy_detach),
71 DEVMETHOD(device_shutdown, bus_generic_shutdown),
72 DEVMETHOD_END
73 };
74
75 static devclass_t pnaphy_devclass;
76
77 static driver_t pnaphy_driver = {
78 "pnaphy",
79 pnaphy_methods,
80 sizeof(struct mii_softc)
81 };
82
83 DRIVER_MODULE(pnaphy, miibus, pnaphy_driver, pnaphy_devclass, 0, 0);
84
85 static int pnaphy_service(struct mii_softc *, struct mii_data *,int);
86
87 static const struct mii_phydesc pnaphys[] = {
88 MII_PHY_DESC(AMD, 79c978),
89 MII_PHY_END
90 };
91
92 static int
93 pnaphy_probe(device_t dev)
94 {
95
96 return (mii_phy_dev_probe(dev, pnaphys, BUS_PROBE_DEFAULT));
97 }
98
99 static int
100 pnaphy_attach(device_t dev)
101 {
102 struct mii_softc *sc;
103 struct mii_attach_args *ma;
104 struct mii_data *mii;
105
106 sc = device_get_softc(dev);
107 ma = device_get_ivars(dev);
108 sc->mii_dev = device_get_parent(dev);
109 mii = ma->mii_data;
110 LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
111
112 sc->mii_flags = miibus_get_flags(dev);
113 sc->mii_inst = mii->mii_instance++;
114 sc->mii_phy = ma->mii_phyno;
115 sc->mii_service = pnaphy_service;
116 sc->mii_pdata = mii;
117
118 sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOLOOP | MIIF_IS_HPNA |
119 MIIF_NOMANPAUSE;
120
121 mii_phy_reset(sc);
122
123 sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
124 device_printf(dev, " ");
125 mii_phy_add_media(sc);
126 printf("\n");
127
128 MIIBUS_MEDIAINIT(sc->mii_dev);
129 return (0);
130 }
131
132 static int
133 pnaphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
134 {
135 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
136
137 switch (cmd) {
138 case MII_POLLSTAT:
139 break;
140
141 case MII_MEDIACHG:
142 /*
143 * If the interface is not up, don't do anything.
144 */
145 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
146 break;
147
148 switch (IFM_SUBTYPE(ife->ifm_media)) {
149 case IFM_HPNA_1:
150 mii_phy_setmedia(sc);
151 break;
152 default:
153 return (EINVAL);
154 }
155 break;
156
157 case MII_TICK:
158 if (mii_phy_tick(sc) == EJUSTRETURN)
159 return (0);
160 break;
161 }
162
163 /* Update the media status. */
164 ukphy_status(sc);
165 if (IFM_SUBTYPE(mii->mii_media_active) == IFM_10_T)
166 mii->mii_media_active = IFM_ETHER | IFM_HPNA_1;
167
168 /* Callback if something changed. */
169 mii_phy_update(sc, cmd);
170 return (0);
171 }
Cache object: 7812f6a18cd35187b61ad3a1f93a021a
|