Deleted Added
full compact
pnphy.c (217417) pnphy.c (221407)
1/*
2 * Copyright (c) 1997, 1998, 1999
3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <sys/cdefs.h>
1/*
2 * Copyright (c) 1997, 1998, 1999
3 * Bill Paul <wpaul@ee.columbia.edu>. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Bill Paul.
16 * 4. Neither the name of the author nor the names of any co-contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
30 * THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#include <sys/cdefs.h>
34__FBSDID("$FreeBSD: head/sys/dev/dc/pnphy.c 217417 2011-01-14 20:26:59Z marius $");
34__FBSDID("$FreeBSD: head/sys/dev/dc/pnphy.c 221407 2011-05-03 19:51:29Z marius $");
35
36/*
37 * Pseudo-driver for media selection on the Lite-On PNIC 82c168
38 * chip. The NWAY support on this chip is horribly broken, so we
39 * only support manual mode selection. This is lame, but getting
40 * NWAY to work right is amazingly difficult.
41 */
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/kernel.h>
46#include <sys/socket.h>
47#include <sys/errno.h>
48#include <sys/lock.h>
49#include <sys/module.h>
50#include <sys/mutex.h>
51#include <sys/bus.h>
52
53#include <net/if.h>
54#include <net/if_arp.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 <machine/bus.h>
62#include <machine/resource.h>
63#include <sys/bus.h>
64
65#include <dev/dc/if_dcreg.h>
66
67#include "miibus_if.h"
68
69static int pnphy_probe(device_t);
70static int pnphy_attach(device_t);
71
72static device_method_t pnphy_methods[] = {
73 /* device interface */
74 DEVMETHOD(device_probe, pnphy_probe),
75 DEVMETHOD(device_attach, pnphy_attach),
76 DEVMETHOD(device_detach, mii_phy_detach),
77 DEVMETHOD(device_shutdown, bus_generic_shutdown),
78 { 0, 0 }
79};
80
81static devclass_t pnphy_devclass;
82
83static driver_t pnphy_driver = {
84 "pnphy",
85 pnphy_methods,
86 sizeof(struct mii_softc)
87};
88
89DRIVER_MODULE(pnphy, miibus, pnphy_driver, pnphy_devclass, 0, 0);
90
91static int pnphy_service(struct mii_softc *, struct mii_data *, int);
92static void pnphy_status(struct mii_softc *);
35
36/*
37 * Pseudo-driver for media selection on the Lite-On PNIC 82c168
38 * chip. The NWAY support on this chip is horribly broken, so we
39 * only support manual mode selection. This is lame, but getting
40 * NWAY to work right is amazingly difficult.
41 */
42
43#include <sys/param.h>
44#include <sys/systm.h>
45#include <sys/kernel.h>
46#include <sys/socket.h>
47#include <sys/errno.h>
48#include <sys/lock.h>
49#include <sys/module.h>
50#include <sys/mutex.h>
51#include <sys/bus.h>
52
53#include <net/if.h>
54#include <net/if_arp.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 <machine/bus.h>
62#include <machine/resource.h>
63#include <sys/bus.h>
64
65#include <dev/dc/if_dcreg.h>
66
67#include "miibus_if.h"
68
69static int pnphy_probe(device_t);
70static int pnphy_attach(device_t);
71
72static device_method_t pnphy_methods[] = {
73 /* device interface */
74 DEVMETHOD(device_probe, pnphy_probe),
75 DEVMETHOD(device_attach, pnphy_attach),
76 DEVMETHOD(device_detach, mii_phy_detach),
77 DEVMETHOD(device_shutdown, bus_generic_shutdown),
78 { 0, 0 }
79};
80
81static devclass_t pnphy_devclass;
82
83static driver_t pnphy_driver = {
84 "pnphy",
85 pnphy_methods,
86 sizeof(struct mii_softc)
87};
88
89DRIVER_MODULE(pnphy, miibus, pnphy_driver, pnphy_devclass, 0, 0);
90
91static int pnphy_service(struct mii_softc *, struct mii_data *, int);
92static void pnphy_status(struct mii_softc *);
93static void pnphy_reset(struct mii_softc *);
93
94
95static const struct mii_phy_funcs pnphy_funcs = {
96 pnphy_service,
97 pnphy_status,
98 pnphy_reset
99};
100
94static int
95pnphy_probe(device_t dev)
96{
97 struct mii_attach_args *ma;
98
99 ma = device_get_ivars(dev);
100
101 /*
102 * The dc driver will report the 82c168 vendor and device
103 * ID to let us know that it wants us to attach.
104 */
105 if (ma->mii_id1 != DC_VENDORID_LO ||
106 ma->mii_id2 != DC_DEVICEID_82C168)
107 return (ENXIO);
108
109 device_set_desc(dev, "PNIC 82c168 media interface");
110
111 return (BUS_PROBE_DEFAULT);
112}
113
114static int
115pnphy_attach(device_t dev)
116{
117 struct mii_softc *sc;
101static int
102pnphy_probe(device_t dev)
103{
104 struct mii_attach_args *ma;
105
106 ma = device_get_ivars(dev);
107
108 /*
109 * The dc driver will report the 82c168 vendor and device
110 * ID to let us know that it wants us to attach.
111 */
112 if (ma->mii_id1 != DC_VENDORID_LO ||
113 ma->mii_id2 != DC_DEVICEID_82C168)
114 return (ENXIO);
115
116 device_set_desc(dev, "PNIC 82c168 media interface");
117
118 return (BUS_PROBE_DEFAULT);
119}
120
121static int
122pnphy_attach(device_t dev)
123{
124 struct mii_softc *sc;
118 struct mii_attach_args *ma;
119 struct mii_data *mii;
120
121 sc = device_get_softc(dev);
125
126 sc = device_get_softc(dev);
122 ma = device_get_ivars(dev);
123 sc->mii_dev = device_get_parent(dev);
124 mii = ma->mii_data;
125 LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
126
127
127 sc->mii_flags = miibus_get_flags(dev);
128 sc->mii_inst = mii->mii_instance++;
129 sc->mii_phy = ma->mii_phyno;
130 sc->mii_service = pnphy_service;
131 sc->mii_pdata = mii;
128 mii_phy_dev_attach(dev, MIIF_NOISOLATE | MIIF_NOMANPAUSE,
129 &pnphy_funcs, 0);
132
130
133 /*
134 * Apparently, we can neither isolate nor do loopback.
135 */
136 sc->mii_flags |= MIIF_NOISOLATE | MIIF_NOLOOP;
137
138 sc->mii_capabilities =
139 BMSR_100TXFDX | BMSR_100TXHDX | BMSR_10TFDX | BMSR_10THDX;
131 sc->mii_capabilities =
132 BMSR_100TXFDX | BMSR_100TXHDX | BMSR_10TFDX | BMSR_10THDX;
140 sc->mii_capabilities &= ma->mii_capmask;
133 sc->mii_capabilities &= sc->mii_capmask;
141 device_printf(dev, " ");
142 mii_phy_add_media(sc);
143 printf("\n");
144
145 MIIBUS_MEDIAINIT(sc->mii_dev);
146 return (0);
147}
148
149static int
150pnphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
151{
152 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
153
154 switch (cmd) {
155 case MII_POLLSTAT:
156 break;
157
158 case MII_MEDIACHG:
159 /*
160 * If the interface is not up, don't do anything.
161 */
162 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
163 break;
164
165 /*
166 * Note that auto-negotiation is broken on this chip.
167 */
168 switch (IFM_SUBTYPE(ife->ifm_media)) {
169 case IFM_100_TX:
170 mii->mii_media_active = IFM_ETHER | IFM_100_TX;
171 if ((ife->ifm_media & IFM_FDX) != 0)
172 mii->mii_media_active |= IFM_FDX;
173 MIIBUS_STATCHG(sc->mii_dev);
174 return (0);
175 case IFM_10_T:
176 mii->mii_media_active = IFM_ETHER | IFM_10_T;
177 if ((ife->ifm_media & IFM_FDX) != 0)
178 mii->mii_media_active |= IFM_FDX;
179 MIIBUS_STATCHG(sc->mii_dev);
180 return (0);
181 default:
182 return (EINVAL);
183 }
184 break;
185
186 case MII_TICK:
187 /*
188 * Is the interface even up?
189 */
190 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
191 return (0);
192
193 break;
194 }
195
196 /* Update the media status. */
134 device_printf(dev, " ");
135 mii_phy_add_media(sc);
136 printf("\n");
137
138 MIIBUS_MEDIAINIT(sc->mii_dev);
139 return (0);
140}
141
142static int
143pnphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
144{
145 struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
146
147 switch (cmd) {
148 case MII_POLLSTAT:
149 break;
150
151 case MII_MEDIACHG:
152 /*
153 * If the interface is not up, don't do anything.
154 */
155 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
156 break;
157
158 /*
159 * Note that auto-negotiation is broken on this chip.
160 */
161 switch (IFM_SUBTYPE(ife->ifm_media)) {
162 case IFM_100_TX:
163 mii->mii_media_active = IFM_ETHER | IFM_100_TX;
164 if ((ife->ifm_media & IFM_FDX) != 0)
165 mii->mii_media_active |= IFM_FDX;
166 MIIBUS_STATCHG(sc->mii_dev);
167 return (0);
168 case IFM_10_T:
169 mii->mii_media_active = IFM_ETHER | IFM_10_T;
170 if ((ife->ifm_media & IFM_FDX) != 0)
171 mii->mii_media_active |= IFM_FDX;
172 MIIBUS_STATCHG(sc->mii_dev);
173 return (0);
174 default:
175 return (EINVAL);
176 }
177 break;
178
179 case MII_TICK:
180 /*
181 * Is the interface even up?
182 */
183 if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
184 return (0);
185
186 break;
187 }
188
189 /* Update the media status. */
197 pnphy_status(sc);
190 PHY_STATUS(sc);
198
199 /* Callback if something changed. */
200 mii_phy_update(sc, cmd);
201 return (0);
202}
203
204static void
205pnphy_status(struct mii_softc *sc)
206{
207 struct mii_data *mii = sc->mii_pdata;
208 int reg;
209 struct dc_softc *dc_sc;
210
211 dc_sc = mii->mii_ifp->if_softc;
212
213 mii->mii_media_status = IFM_AVALID;
214 mii->mii_media_active = IFM_ETHER;
215
216 reg = CSR_READ_4(dc_sc, DC_ISR);
217 if (!(reg & DC_ISR_LINKFAIL))
218 mii->mii_media_status |= IFM_ACTIVE;
219 reg = CSR_READ_4(dc_sc, DC_NETCFG);
220 if (reg & DC_NETCFG_SPEEDSEL)
221 mii->mii_media_active |= IFM_10_T;
222 else
223 mii->mii_media_active |= IFM_100_TX;
224 if (reg & DC_NETCFG_FULLDUPLEX)
225 mii->mii_media_active |= IFM_FDX;
226 else
227 mii->mii_media_active |= IFM_HDX;
228}
191
192 /* Callback if something changed. */
193 mii_phy_update(sc, cmd);
194 return (0);
195}
196
197static void
198pnphy_status(struct mii_softc *sc)
199{
200 struct mii_data *mii = sc->mii_pdata;
201 int reg;
202 struct dc_softc *dc_sc;
203
204 dc_sc = mii->mii_ifp->if_softc;
205
206 mii->mii_media_status = IFM_AVALID;
207 mii->mii_media_active = IFM_ETHER;
208
209 reg = CSR_READ_4(dc_sc, DC_ISR);
210 if (!(reg & DC_ISR_LINKFAIL))
211 mii->mii_media_status |= IFM_ACTIVE;
212 reg = CSR_READ_4(dc_sc, DC_NETCFG);
213 if (reg & DC_NETCFG_SPEEDSEL)
214 mii->mii_media_active |= IFM_10_T;
215 else
216 mii->mii_media_active |= IFM_100_TX;
217 if (reg & DC_NETCFG_FULLDUPLEX)
218 mii->mii_media_active |= IFM_FDX;
219 else
220 mii->mii_media_active |= IFM_HDX;
221}
222
223static void
224pnphy_reset(struct mii_softc *sc __unused)
225{
226
227}