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