View | Details | Raw Unified | Return to bug 83807 | Differences between
and this patch

Collapse All | Expand All

(-)sbin/ifconfig/Makefile (+2 lines)
Lines 28-33 Link Here
28
28
29
SRCS+=	ifbridge.c		# bridge support
29
SRCS+=	ifbridge.c		# bridge support
30
30
31
SRCS+=	ifwol.c			# wake on lan support
32
31
.if !defined(RELEASE_CRUNCH)
33
.if !defined(RELEASE_CRUNCH)
32
SRCS+=	af_ipx.c		# IPX support
34
SRCS+=	af_ipx.c		# IPX support
33
DPADD=	${LIBIPX}
35
DPADD=	${LIBIPX}
(-)sbin/ifconfig/ifconfig.8 (-1 / +21 lines)
Lines 896-901 Link Here
896
If that is the case, then the first four keys
896
If that is the case, then the first four keys
897
(1-4) will be the standard temporary keys and any others will be adaptor
897
(1-4) will be the standard temporary keys and any others will be adaptor
898
specific keys such as permanent keys stored in NVRAM.
898
specific keys such as permanent keys stored in NVRAM.
899
.It Cm wakeon Ar events
900
Enable Wake On Lan support, if available. The 
901
.Ar events
902
argument is a comma seperated list of package types that shall
903
trigger wake events. The set of valid package types is
904
.Dq Li unicast ,
905
.Dq Li multicast ,
906
.Dq Li broadcast ,
907
and
908
.Dq Li magic .
909
These enable wake on unicast, multicast, broadcast and Magic Packet(tm),
910
respectively.
911
A SecureOn password, if supported, can be be enabled using the
912
.Dq Li sopasswd:<password> 
913
event.
914
SecureOn passwords only work in combination with
915
.Dq Li magic .
916
The password must consist of 12 hexadecimal digits.
917
.It Fl wakeon
918
Disable Wake On Lan.
919
.Pp
899
.It Cm wme
920
.It Cm wme
900
Enable Wireless Multimedia Extensions (WME) support, if available,
921
Enable Wireless Multimedia Extensions (WME) support, if available,
901
for the specified interface.
922
for the specified interface.
Lines 903-909 Link Here
903
efficient communication of realtime and multimedia data.
924
efficient communication of realtime and multimedia data.
904
To disable WME support, use
925
To disable WME support, use
905
.Fl wme .
926
.Fl wme .
906
.Pp
907
The following parameters are meaningful only when WME support is in use.
927
The following parameters are meaningful only when WME support is in use.
908
Parameters are specified per-AC (Access Category) and
928
Parameters are specified per-AC (Access Category) and
909
split into those that are used by a station when acting
929
split into those that are used by a station when acting
(-)sbin/ifconfig/ifwol.c (+232 lines)
Added Link Here
1
/* $Id$ */
2
3
/*
4
 * Copyright (c) 2005 Stefan Sperling.
5
 * All rights reserved.
6
 *
7
 * Redistribution and use in source and binary forms, with or without
8
 * modification, are permitted provided that the following conditions
9
 * are met:
10
 * 1. Redistributions of source code must retain the above copyright
11
 *    notice, this list of conditions and the following disclaimer.
12
 * 2. Redistributions in binary form must reproduce the above copyright
13
 *    notice, this list of conditions and the following disclaimer in the
14
 *    documentation and/or other materials provided with the distribution.
15
 * 3. The name of the author may not be used to endorse or promote products
16
 *    derived from this software without specific prior written permission.
17
 *
18
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25
 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28
 * SUCH DAMAGE.
29
 */
30
31
#include <sys/param.h>
32
#include <sys/ioctl.h>
33
#include <sys/socket.h>
34
#include <sys/sysctl.h>
35
#include <sys/time.h>
36
37
#include <net/if.h>
38
#include <net/if_dl.h>
39
#include <net/if_types.h>
40
#include <net/if_media.h>
41
#include <net/route.h>
42
43
#include <ctype.h>
44
#include <err.h>
45
#include <errno.h>
46
#include <fcntl.h>
47
#include <stdio.h>
48
#include <stdlib.h>
49
#include <string.h>
50
#include <unistd.h>
51
#include <sysexits.h>
52
53
#include "ifconfig.h"
54
55
static void wol_status(int s);
56
static void setwol(const char *, int, int, const struct afswtch *);
57
static void parse_args(const char *, struct if_wolopts *);
58
static void parse_sopasswd(char *, u_char *);
59
static void unsetwol(const char *, int, int, const struct afswtch *);
60
static void print_wol_events(uint32_t events);
61
62
/*
63
 * Print wake on lan capabilities and events the device currently heeds.
64
 */
65
static void
66
wol_status(int s)
67
{
68
	struct ifreq ifr;
69
70
	memset(&ifr, 0, sizeof(ifr));
71
	strncpy(ifr.ifr_name, name, IFNAMSIZ);
72
73
	if (ioctl(s, SIOCGIFWOLSUPP, &ifr) < 0)
74
		/* Device does not support wake on lan */
75
		return;
76
77
	printf("\tsupported wake events:");
78
	print_wol_events(ifr.ifr_wolopts.ifwol_supported);
79
	printf("\n");
80
81
	if (ioctl(s, SIOCGIFWOLOPTS, &ifr) < 0)
82
		err(EX_USAGE, "SIOCGIFWOLOPTS");
83
84
	if (ifr.ifr_wolopts.ifwol_events == 0)
85
		return;
86
87
	printf("\twill wake on:");
88
	print_wol_events(ifr.ifr_wolopts.ifwol_events);
89
	printf("\n");
90
}
91
92
static void
93
print_wol_events(uint32_t events)
94
{
95
	if (events & IFWOL_WAKE_ON_UNICAST)
96
		printf(" unicast");
97
	if (events & IFWOL_WAKE_ON_MULTICAST)
98
		printf(" multicast");
99
	if (events & IFWOL_WAKE_ON_BROADCAST)
100
		printf(" broadcast");
101
	if (events & IFWOL_WAKE_ON_MAGIC) {
102
		printf(" magic");
103
		if (events & IFWOL_ENABLE_SOPASSWD)
104
			printf("[SecureOn password]");
105
	}
106
}
107
108
/*
109
 * Set wake on lan events.
110
 */
111
static void
112
setwol(const char *val, int d, int s, const struct afswtch *afp)
113
{
114
	char *args;
115
	struct ifreq ifr;
116
117
	memset(&ifr, 0, sizeof(ifr));
118
	strncpy(ifr.ifr_name, name, IFNAMSIZ);
119
120
	if (ioctl(s, SIOCGIFWOLSUPP, &ifr) < 0)
121
		err(EX_USAGE, "device does not support wake on lan");
122
123
	args = strdup(val);
124
	parse_args(args, &ifr.ifr_wolopts);
125
	free(args);
126
	if (ioctl(s, SIOCSIFWOLOPTS, &ifr) < 0)
127
		err(EX_USAGE, "SIOCSIFWOLOPTS");
128
}
129
130
/* 
131
 * Parse the argument string, which may contain one or more of the
132
 * following:
133
 *    
134
 *     unicast,multicast,broadcast,magic,sopasswd:xxxxxxxxxxxx,
135
 *
136
 * and fill the wolopts structure accordingly.
137
 * 
138
 */
139
static void
140
parse_args(const char* args, struct if_wolopts *wolopts)
141
{
142
	uint32_t wol_events = 0;
143
	char* opt;
144
145
	for (opt = strdup(args); (opt = strtok(opt, ",")) != NULL; opt = NULL) {
146
		if (strcmp(opt, "unicast") == 0)
147
			wol_events |= IFWOL_WAKE_ON_UNICAST;
148
		else if (strcmp(opt, "multicast") == 0)
149
			wol_events |= IFWOL_WAKE_ON_MULTICAST;
150
		else if (strcmp(opt, "broadcast") == 0)
151
			wol_events |= IFWOL_WAKE_ON_BROADCAST;
152
		else if (strcmp(opt, "magic") == 0)
153
			wol_events |= IFWOL_WAKE_ON_MAGIC;
154
		else if (strcmp(opt, "sopasswd") == 0)
155
			errx(EX_USAGE, "no SecureOn password specfied.");
156
		else if (strncmp(opt, "sopasswd:", strlen("sopasswd:")) == 0) {
157
			wol_events |= IFWOL_ENABLE_SOPASSWD;
158
			parse_sopasswd(opt + strlen("sopasswd:"), wolopts->ifwol_sopasswd);
159
		} else {
160
			errx(EX_USAGE, "unknown wake event %s", opt);
161
		}
162
	}
163
	free(opt);
164
	wolopts->ifwol_events = wol_events;
165
}
166
167
/* SecureOn passwords are not like plain text passwords. Instead, they consist
168
 * of 6 bytes (ie unsigned char). Try to prevent users from giving anything other
169
 * than a string of six concatenated unsigned chars in hex as password.
170
 */
171
static void
172
parse_sopasswd(char *pw, u_char *dest) {
173
	char substr[3];
174
	int len, i, n;
175
176
	len = strlen(pw) / 2;
177
	if (len != 6)
178
		errx(EX_USAGE, "Invalid SecureOn password.");
179
180
	for (i = 0; i < len; i++) {
181
		(void)strncpy(substr, pw, 2);
182
		substr[2] = '\0';
183
		if (sscanf(substr, "%x", &n) != 1)
184
			errx(EX_USAGE, "Invalid SecureOn password.");
185
		if (n < 0x0 || n > 0xff)
186
			/* Should never happen, but just in case... */
187
			errx(EX_USAGE, "Invalid SecureOn password.");
188
		*dest++ = (u_char)n;
189
		pw += 2;
190
	}
191
}
192
193
/*
194
 * Unset all wake on lan events.
195
 */
196
static void
197
unsetwol(const char *val, int d, int s, const struct afswtch *afp)
198
{
199
	struct ifreq ifr;
200
201
	memset(&ifr, 0, sizeof(ifr));
202
	strncpy(ifr.ifr_name, name, IFNAMSIZ);
203
204
	if (ioctl(s, SIOCGIFWOLSUPP, &ifr) < 0)
205
		err(EX_USAGE, "device does not support wake on lan");
206
207
	ifr.ifr_wolopts.ifwol_events = IFWOL_DISABLE;
208
	if (ioctl(s, SIOCSIFWOLOPTS, &ifr) < 0)
209
		err(EX_USAGE, "SIOCSIFWOLOPTS");
210
}
211
212
static struct cmd wol_cmds[] = {
213
	DEF_CMD_ARG("wakeon",	setwol),
214
	DEF_CMD("-wakeon", 0, unsetwol)
215
};
216
static struct afswtch af_wol = {
217
	.af_name	= "af_wol",
218
	.af_af		= AF_UNSPEC,
219
	.af_other_status = wol_status,
220
};
221
222
static __constructor void
223
ifwol_ctor(void)
224
{
225
#define	N(a)	(sizeof(a) / sizeof(a[0]))
226
	int i;
227
228
	for (i = 0; i < N(wol_cmds);  i++)
229
		cmd_register(&wol_cmds[i]);
230
	af_register(&af_wol);
231
#undef N
232
}
(-)sys/dev/nve/if_nve.c (+69 lines)
Lines 179-184 Link Here
179
static NV_SINT32 nve_oslockrelease(PNV_VOID, NV_SINT32, PNV_VOID);
179
static NV_SINT32 nve_oslockrelease(PNV_VOID, NV_SINT32, PNV_VOID);
180
static PNV_VOID  nve_osreturnbufvirt(PNV_VOID, PNV_VOID);
180
static PNV_VOID  nve_osreturnbufvirt(PNV_VOID, PNV_VOID);
181
181
182
static void	nve_enable_wol(struct nve_softc *);
183
static void	nve_get_wolopts(struct nve_softc *, struct if_wolopts *);
184
static int	nve_set_wolopts(struct nve_softc *, struct if_wolopts *);
185
182
static device_method_t nve_methods[] = {
186
static device_method_t nve_methods[] = {
183
	/* Device interface */
187
	/* Device interface */
184
	DEVMETHOD(device_probe, nve_probe),
188
	DEVMETHOD(device_probe, nve_probe),
Lines 718-723 Link Here
718
722
719
	sc = device_get_softc(dev);
723
	sc = device_get_softc(dev);
720
724
725
	NVE_LOCK(sc);
726
	nve_enable_wol(sc);
727
	NVE_UNLOCK(sc);
728
721
	/* Stop hardware activity */
729
	/* Stop hardware activity */
722
	NVE_LOCK(sc);
730
	NVE_LOCK(sc);
723
	nve_stop(sc);
731
	nve_stop(sc);
Lines 1018-1023 Link Here
1018
		mii = device_get_softc(sc->miibus);
1026
		mii = device_get_softc(sc->miibus);
1019
		error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
1027
		error = ifmedia_ioctl(ifp, ifr, &mii->mii_media, command);
1020
		break;
1028
		break;
1029
 	case SIOCGIFWOLSUPP:
1030
 		ifr->ifr_wolopts.ifwol_supported = NVE_SUPPORTED_WOL_EVENTS;
1031
 		error = 0;
1032
 		break;
1033
 	case SIOCGIFWOLOPTS:
1034
 		NVE_LOCK(sc);
1035
 		nve_get_wolopts(sc, &ifr->ifr_wolopts);
1036
 		NVE_UNLOCK(sc);
1037
 		error = 0;
1038
 		break;
1039
 	case SIOCSIFWOLOPTS:
1040
 		NVE_LOCK(sc);
1041
 		error = nve_set_wolopts(sc, &ifr->ifr_wolopts);
1042
 		NVE_UNLOCK(sc);
1043
  		break;
1021
1044
1022
	default:
1045
	default:
1023
		/* Everything else we forward to generic ether ioctl */
1046
		/* Everything else we forward to generic ether ioctl */
Lines 1736-1738 Link Here
1736
}
1759
}
1737
1760
1738
/* --- End on NVOSAPI interface --- */
1761
/* --- End on NVOSAPI interface --- */
1762
1763
/*
1764
 * Enable Wake On Lan.
1765
 */
1766
static void
1767
nve_enable_wol(struct nve_softc *sc)
1768
{
1769
	ADAPTER_POWERSTATE pstate = {0};
1770
1771
	if (sc->wol_events == 0)
1772
		return;
1773
	
1774
	if (sc->wol_events & IFWOL_WAKE_ON_MAGIC) {
1775
		pstate.ulPowerFlags = POWER_STATE_D3;
1776
		pstate.ulMagicPacketWakeUpFlags = POWER_STATE_ALL;
1777
		pstate.ulLinkChangeWakeUpFlags = 0;
1778
		pstate.ulPatternWakeUpFlags = 0;
1779
		sc->hwapi->pfnSetPowerState(sc->hwapi->pADCX, &pstate);
1780
	}
1781
}
1782
1783
/*
1784
 * Write current wake on lan settings into an if_wolopts structure.
1785
 */
1786
static void
1787
nve_get_wolopts(struct nve_softc *sc, struct if_wolopts *wolopts)
1788
{
1789
	wolopts->ifwol_events = sc->wol_events;
1790
}
1791
1792
/*
1793
 * Set wake on lan options.
1794
 */
1795
static int
1796
nve_set_wolopts(struct nve_softc *sc, struct if_wolopts *wolopts)
1797
{
1798
	if (wolopts->ifwol_events == IFWOL_DISABLE)
1799
		sc->wol_events = 0;
1800
	else {
1801
		if ((wolopts->ifwol_events & ~NVE_SUPPORTED_WOL_EVENTS) != 0)
1802
			return EINVAL;
1803
		sc->wol_events = wolopts->ifwol_events;
1804
	}
1805
1806
	return 0;
1807
}
(-)sys/dev/nve/if_nvereg.h (+4 lines)
Lines 67-72 Link Here
67
#define	NVE_DEBUG_MII		0x0100
67
#define	NVE_DEBUG_MII		0x0100
68
#define	NVE_DEBUG_ALL		0xFFFF
68
#define	NVE_DEBUG_ALL		0xFFFF
69
69
70
#define NVE_SUPPORTED_WOL_EVENTS	IFWOL_WAKE_ON_MAGIC
71
70
#if NVE_DEBUG
72
#if NVE_DEBUG
71
#define	DEBUGOUT(level, fmt, args...) if (NVE_DEBUG & level) \
73
#define	DEBUGOUT(level, fmt, args...) if (NVE_DEBUG & level) \
72
    printf(fmt, ## args)
74
    printf(fmt, ## args)
Lines 141-146 Link Here
141
143
142
	struct mtx mtx;
144
	struct mtx mtx;
143
145
146
	uint32_t wol_events;
147
144
	/* Stuff for dealing with the NVIDIA OS API */
148
	/* Stuff for dealing with the NVIDIA OS API */
145
	struct callout ostimer;
149
	struct callout ostimer;
146
	PTIMER_FUNC ostimer_func;
150
	PTIMER_FUNC ostimer_func;
(-)sys/net/if.c (+3 lines)
Lines 1436-1441 Link Here
1436
	case SIOCSLIFPHYADDR:
1436
	case SIOCSLIFPHYADDR:
1437
	case SIOCSIFMEDIA:
1437
	case SIOCSIFMEDIA:
1438
	case SIOCSIFGENERIC:
1438
	case SIOCSIFGENERIC:
1439
	case SIOCSIFWOLOPTS:
1439
		error = suser(td);
1440
		error = suser(td);
1440
		if (error)
1441
		if (error)
1441
			return (error);
1442
			return (error);
Lines 1457-1462 Link Here
1457
	case SIOCGLIFPHYADDR:
1458
	case SIOCGLIFPHYADDR:
1458
	case SIOCGIFMEDIA:
1459
	case SIOCGIFMEDIA:
1459
	case SIOCGIFGENERIC:
1460
	case SIOCGIFGENERIC:
1461
	case SIOCGIFWOLOPTS:
1462
	case SIOCGIFWOLSUPP:
1460
		if (ifp->if_ioctl == NULL)
1463
		if (ifp->if_ioctl == NULL)
1461
			return (EOPNOTSUPP);
1464
			return (EOPNOTSUPP);
1462
		IFF_LOCKGIANT(ifp);
1465
		IFF_LOCKGIANT(ifp);
(-)sys/net/if.h (+24 lines)
Lines 254-259 Link Here
254
#define	IFAN_DEPARTURE	1	/* interface departure */
254
#define	IFAN_DEPARTURE	1	/* interface departure */
255
255
256
/*
256
/*
257
 * Wake on Lan related options.
258
 */
259
struct if_wolopts {
260
	uint32_t	ifwol_supported;/* indicates wol capabilities */
261
	uint32_t 	ifwol_events;	/* indicates desired wake events */
262
263
	/* Supported wake on lan events.
264
	 * A given device may not support all of these,
265
	 * or even support wake events not listed here.
266
	 * If you add wake more events, make to sure to teach
267
	 * ifconfig about them too. */
268
#define	IFWOL_DISABLE		0x01 /* clears all other events */
269
#define	IFWOL_WAKE_ON_UNICAST	0x02
270
#define	IFWOL_WAKE_ON_MULTICAST	0x04
271
#define	IFWOL_WAKE_ON_BROADCAST	0x08
272
#define	IFWOL_WAKE_ON_MAGIC	0x10 /* wake on Magic Packet(tm) */
273
#define	IFWOL_ENABLE_SOPASSWD	0x20 /* whether to set SecureOn password */
274
275
	u_char	ifwol_sopasswd[6]; /* SecureOn password */
276
};
277
278
/*
257
 * Interface request structure used for socket
279
 * Interface request structure used for socket
258
 * ioctl's.  All interface ioctl's must have parameter
280
 * ioctl's.  All interface ioctl's must have parameter
259
 * definitions which begin with ifr_name.  The
281
 * definitions which begin with ifr_name.  The
Lines 265-270 Link Here
265
		struct	sockaddr ifru_addr;
287
		struct	sockaddr ifru_addr;
266
		struct	sockaddr ifru_dstaddr;
288
		struct	sockaddr ifru_dstaddr;
267
		struct	sockaddr ifru_broadaddr;
289
		struct	sockaddr ifru_broadaddr;
290
		struct  if_wolopts ifru_wolopts;
268
		short	ifru_flags[2];
291
		short	ifru_flags[2];
269
		short	ifru_index;
292
		short	ifru_index;
270
		int	ifru_metric;
293
		int	ifru_metric;
Lines 277-282 Link Here
277
#define	ifr_addr	ifr_ifru.ifru_addr	/* address */
300
#define	ifr_addr	ifr_ifru.ifru_addr	/* address */
278
#define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
301
#define	ifr_dstaddr	ifr_ifru.ifru_dstaddr	/* other end of p-to-p link */
279
#define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
302
#define	ifr_broadaddr	ifr_ifru.ifru_broadaddr	/* broadcast address */
303
#define	ifr_wolopts	ifr_ifru.ifru_wolopts	/* wake on lan related options */
280
#define	ifr_flags	ifr_ifru.ifru_flags[0]	/* flags (low 16 bits) */
304
#define	ifr_flags	ifr_ifru.ifru_flags[0]	/* flags (low 16 bits) */
281
#define	ifr_flagshigh	ifr_ifru.ifru_flags[1]	/* flags (high 16 bits) */
305
#define	ifr_flagshigh	ifr_ifru.ifru_flags[1]	/* flags (high 16 bits) */
282
#define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
306
#define	ifr_metric	ifr_ifru.ifru_metric	/* metric */
(-)sys/pci/if_sis.c (-24 / +175 lines)
Lines 126-131 Link Here
126
static void sis_startl(struct ifnet *);
126
static void sis_startl(struct ifnet *);
127
static void sis_stop(struct sis_softc *);
127
static void sis_stop(struct sis_softc *);
128
static void sis_watchdog(struct ifnet *);
128
static void sis_watchdog(struct ifnet *);
129
static void sis_get_wolopts(struct sis_softc *, struct if_wolopts *);
130
static int sis_set_wolopts(struct sis_softc *, struct if_wolopts *);
131
static void sis_enable_wol(struct sis_softc *);
132
static uint32_t sis_translate_wol_events(uint32_t);
129
133
130
#ifdef SIS_USEIOSPACE
134
#ifdef SIS_USEIOSPACE
131
#define SIS_RES			SYS_RES_IOPORT
135
#define SIS_RES			SYS_RES_IOPORT
Lines 170-176 Link Here
170
static void
174
static void
171
sis_dma_map_ring(void *arg, bus_dma_segment_t *segs, int nseg, int error)
175
sis_dma_map_ring(void *arg, bus_dma_segment_t *segs, int nseg, int error)
172
{
176
{
173
	u_int32_t *p;
177
	uint32_t *p;
174
178
175
	p = arg;
179
	p = arg;
176
	*p = segs->ds_addr;
180
	*p = segs->ds_addr;
Lines 258-264 Link Here
258
sis_eeprom_getword(struct sis_softc *sc, int addr, uint16_t *dest)
262
sis_eeprom_getword(struct sis_softc *sc, int addr, uint16_t *dest)
259
{
263
{
260
	int		i;
264
	int		i;
261
	u_int16_t		word = 0;
265
	uint16_t		word = 0;
262
266
263
	/* Force EEPROM to idle state. */
267
	/* Force EEPROM to idle state. */
264
	sis_eeprom_idle(sc);
268
	sis_eeprom_idle(sc);
Lines 301-311 Link Here
301
sis_read_eeprom(struct sis_softc *sc, caddr_t dest, int off, int cnt, int swap)
305
sis_read_eeprom(struct sis_softc *sc, caddr_t dest, int off, int cnt, int swap)
302
{
306
{
303
	int			i;
307
	int			i;
304
	u_int16_t		word = 0, *ptr;
308
	uint16_t		word = 0, *ptr;
305
309
306
	for (i = 0; i < cnt; i++) {
310
	for (i = 0; i < cnt; i++) {
307
		sis_eeprom_getword(sc, off + i, &word);
311
		sis_eeprom_getword(sc, off + i, &word);
308
		ptr = (u_int16_t *)(dest + (i * 2));
312
		ptr = (uint16_t *)(dest + (i * 2));
309
		if (swap)
313
		if (swap)
310
			*ptr = ntohs(word);
314
			*ptr = ntohs(word);
311
		else
315
		else
Lines 354-360 Link Here
354
sis_read_cmos(struct sis_softc *sc, device_t dev, caddr_t dest, int off, int cnt)
358
sis_read_cmos(struct sis_softc *sc, device_t dev, caddr_t dest, int off, int cnt)
355
{
359
{
356
	device_t		bridge;
360
	device_t		bridge;
357
	u_int8_t		reg;
361
	uint8_t			reg;
358
	int			i;
362
	int			i;
359
	bus_space_tag_t		btag;
363
	bus_space_tag_t		btag;
360
364
Lines 383-389 Link Here
383
static void
387
static void
384
sis_read_mac(struct sis_softc *sc, device_t dev, caddr_t dest)
388
sis_read_mac(struct sis_softc *sc, device_t dev, caddr_t dest)
385
{
389
{
386
	u_int32_t		filtsave, csrsave;
390
	uint32_t		filtsave, csrsave;
387
391
388
	filtsave = CSR_READ_4(sc, SIS_RXFILT_CTL);
392
	filtsave = CSR_READ_4(sc, SIS_RXFILT_CTL);
389
	csrsave = CSR_READ_4(sc, SIS_CSR);
393
	csrsave = CSR_READ_4(sc, SIS_CSR);
Lines 394-404 Link Here
394
	CSR_WRITE_4(sc, SIS_RXFILT_CTL, filtsave & ~SIS_RXFILTCTL_ENABLE);
398
	CSR_WRITE_4(sc, SIS_RXFILT_CTL, filtsave & ~SIS_RXFILTCTL_ENABLE);
395
399
396
	CSR_WRITE_4(sc, SIS_RXFILT_CTL, SIS_FILTADDR_PAR0);
400
	CSR_WRITE_4(sc, SIS_RXFILT_CTL, SIS_FILTADDR_PAR0);
397
	((u_int16_t *)dest)[0] = CSR_READ_2(sc, SIS_RXFILT_DATA);
401
	((uint16_t *)dest)[0] = CSR_READ_2(sc, SIS_RXFILT_DATA);
398
	CSR_WRITE_4(sc, SIS_RXFILT_CTL,SIS_FILTADDR_PAR1);
402
	CSR_WRITE_4(sc, SIS_RXFILT_CTL,SIS_FILTADDR_PAR1);
399
	((u_int16_t *)dest)[1] = CSR_READ_2(sc, SIS_RXFILT_DATA);
403
	((uint16_t *)dest)[1] = CSR_READ_2(sc, SIS_RXFILT_DATA);
400
	CSR_WRITE_4(sc, SIS_RXFILT_CTL, SIS_FILTADDR_PAR2);
404
	CSR_WRITE_4(sc, SIS_RXFILT_CTL, SIS_FILTADDR_PAR2);
401
	((u_int16_t *)dest)[2] = CSR_READ_2(sc, SIS_RXFILT_DATA);
405
	((uint16_t *)dest)[2] = CSR_READ_2(sc, SIS_RXFILT_DATA);
402
406
403
	CSR_WRITE_4(sc, SIS_RXFILT_CTL, filtsave);
407
	CSR_WRITE_4(sc, SIS_RXFILT_CTL, filtsave);
404
	CSR_WRITE_4(sc, SIS_CSR, csrsave);
408
	CSR_WRITE_4(sc, SIS_CSR, csrsave);
Lines 731-737 Link Here
731
{
735
{
732
	struct ifnet		*ifp;
736
	struct ifnet		*ifp;
733
	struct ifmultiaddr	*ifma;
737
	struct ifmultiaddr	*ifma;
734
	u_int32_t		h = 0, i, filtsave;
738
	uint32_t		h = 0, i, filtsave;
735
	int			bit, index;
739
	int			bit, index;
736
740
737
	ifp = sc->sis_ifp;
741
	ifp = sc->sis_ifp;
Lines 782-789 Link Here
782
{
786
{
783
	struct ifnet		*ifp;
787
	struct ifnet		*ifp;
784
	struct ifmultiaddr	*ifma;
788
	struct ifmultiaddr	*ifma;
785
	u_int32_t		h, i, n, ctl;
789
	uint32_t		h, i, n, ctl;
786
	u_int16_t		hashes[16];
790
	uint16_t		hashes[16];
787
791
788
	ifp = sc->sis_ifp;
792
	ifp = sc->sis_ifp;
789
793
Lines 984-990 Link Here
984
		 * Why? Who the hell knows.
988
		 * Why? Who the hell knows.
985
		 */
989
		 */
986
		{
990
		{
987
			u_int16_t		tmp[4];
991
			uint16_t		tmp[4];
988
992
989
			sis_read_eeprom(sc, (caddr_t)&tmp,
993
			sis_read_eeprom(sc, (caddr_t)&tmp,
990
			    NS_EE_NODEADDR, 4, 0);
994
			    NS_EE_NODEADDR, 4, 0);
Lines 1406-1412 Link Here
1406
        struct ifnet		*ifp;
1410
        struct ifnet		*ifp;
1407
	struct sis_desc		*cur_rx;
1411
	struct sis_desc		*cur_rx;
1408
	int			total_len = 0;
1412
	int			total_len = 0;
1409
	u_int32_t		rxstat;
1413
	uint32_t		rxstat;
1410
1414
1411
	SIS_LOCK_ASSERT(sc);
1415
	SIS_LOCK_ASSERT(sc);
1412
1416
Lines 1501-1507 Link Here
1501
sis_txeof(struct sis_softc *sc)
1505
sis_txeof(struct sis_softc *sc)
1502
{
1506
{
1503
	struct ifnet		*ifp;
1507
	struct ifnet		*ifp;
1504
	u_int32_t		idx;
1508
	uint32_t		idx;
1505
1509
1506
	SIS_LOCK_ASSERT(sc);
1510
	SIS_LOCK_ASSERT(sc);
1507
	ifp = sc->sis_ifp;
1511
	ifp = sc->sis_ifp;
Lines 1605-1611 Link Here
1605
		sis_startl(ifp);
1609
		sis_startl(ifp);
1606
1610
1607
	if (sc->rxcycles > 0 || cmd == POLL_AND_CHECK_STATUS) {
1611
	if (sc->rxcycles > 0 || cmd == POLL_AND_CHECK_STATUS) {
1608
		u_int32_t	status;
1612
		uint32_t	status;
1609
1613
1610
		/* Reading the ISR register clears all interrupts. */
1614
		/* Reading the ISR register clears all interrupts. */
1611
		status = CSR_READ_4(sc, SIS_ISR);
1615
		status = CSR_READ_4(sc, SIS_ISR);
Lines 1631-1637 Link Here
1631
{
1635
{
1632
	struct sis_softc	*sc;
1636
	struct sis_softc	*sc;
1633
	struct ifnet		*ifp;
1637
	struct ifnet		*ifp;
1634
	u_int32_t		status;
1638
	uint32_t		status;
1635
1639
1636
	sc = arg;
1640
	sc = arg;
1637
	ifp = sc->sis_ifp;
1641
	ifp = sc->sis_ifp;
Lines 1785-1791 Link Here
1785
{
1789
{
1786
	struct sis_softc	*sc;
1790
	struct sis_softc	*sc;
1787
	struct mbuf		*m_head = NULL;
1791
	struct mbuf		*m_head = NULL;
1788
	u_int32_t		idx, queued = 0;
1792
	uint32_t		idx, queued = 0;
1789
1793
1790
	sc = ifp->if_softc;
1794
	sc = ifp->if_softc;
1791
1795
Lines 1872-1894 Link Here
1872
	if (sc->sis_type == SIS_TYPE_83815) {
1876
	if (sc->sis_type == SIS_TYPE_83815) {
1873
		CSR_WRITE_4(sc, SIS_RXFILT_CTL, NS_FILTADDR_PAR0);
1877
		CSR_WRITE_4(sc, SIS_RXFILT_CTL, NS_FILTADDR_PAR0);
1874
		CSR_WRITE_4(sc, SIS_RXFILT_DATA,
1878
		CSR_WRITE_4(sc, SIS_RXFILT_DATA,
1875
		    ((u_int16_t *)IFP2ENADDR(sc->sis_ifp))[0]);
1879
		    ((uint16_t *)IFP2ENADDR(sc->sis_ifp))[0]);
1876
		CSR_WRITE_4(sc, SIS_RXFILT_CTL, NS_FILTADDR_PAR1);
1880
		CSR_WRITE_4(sc, SIS_RXFILT_CTL, NS_FILTADDR_PAR1);
1877
		CSR_WRITE_4(sc, SIS_RXFILT_DATA,
1881
		CSR_WRITE_4(sc, SIS_RXFILT_DATA,
1878
		    ((u_int16_t *)IFP2ENADDR(sc->sis_ifp))[1]);
1882
		    ((uint16_t *)IFP2ENADDR(sc->sis_ifp))[1]);
1879
		CSR_WRITE_4(sc, SIS_RXFILT_CTL, NS_FILTADDR_PAR2);
1883
		CSR_WRITE_4(sc, SIS_RXFILT_CTL, NS_FILTADDR_PAR2);
1880
		CSR_WRITE_4(sc, SIS_RXFILT_DATA,
1884
		CSR_WRITE_4(sc, SIS_RXFILT_DATA,
1881
		    ((u_int16_t *)IFP2ENADDR(sc->sis_ifp))[2]);
1885
		    ((uint16_t *)IFP2ENADDR(sc->sis_ifp))[2]);
1882
	} else {
1886
	} else {
1883
		CSR_WRITE_4(sc, SIS_RXFILT_CTL, SIS_FILTADDR_PAR0);
1887
		CSR_WRITE_4(sc, SIS_RXFILT_CTL, SIS_FILTADDR_PAR0);
1884
		CSR_WRITE_4(sc, SIS_RXFILT_DATA,
1888
		CSR_WRITE_4(sc, SIS_RXFILT_DATA,
1885
		    ((u_int16_t *)IFP2ENADDR(sc->sis_ifp))[0]);
1889
		    ((uint16_t *)IFP2ENADDR(sc->sis_ifp))[0]);
1886
		CSR_WRITE_4(sc, SIS_RXFILT_CTL, SIS_FILTADDR_PAR1);
1890
		CSR_WRITE_4(sc, SIS_RXFILT_CTL, SIS_FILTADDR_PAR1);
1887
		CSR_WRITE_4(sc, SIS_RXFILT_DATA,
1891
		CSR_WRITE_4(sc, SIS_RXFILT_DATA,
1888
		    ((u_int16_t *)IFP2ENADDR(sc->sis_ifp))[1]);
1892
		    ((uint16_t *)IFP2ENADDR(sc->sis_ifp))[1]);
1889
		CSR_WRITE_4(sc, SIS_RXFILT_CTL, SIS_FILTADDR_PAR2);
1893
		CSR_WRITE_4(sc, SIS_RXFILT_CTL, SIS_FILTADDR_PAR2);
1890
		CSR_WRITE_4(sc, SIS_RXFILT_DATA,
1894
		CSR_WRITE_4(sc, SIS_RXFILT_DATA,
1891
		    ((u_int16_t *)IFP2ENADDR(sc->sis_ifp))[2]);
1895
		    ((uint16_t *)IFP2ENADDR(sc->sis_ifp))[2]);
1892
	}
1896
	}
1893
1897
1894
	/* Init circular TX/RX lists. */
1898
	/* Init circular TX/RX lists. */
Lines 2162-2167 Link Here
2162
		}
2166
		}
2163
#endif /* DEVICE_POLLING */
2167
#endif /* DEVICE_POLLING */
2164
		break;
2168
		break;
2169
 	case SIOCGIFWOLSUPP:
2170
 		ifr->ifr_wolopts.ifwol_supported = NS_SUPPORTED_WOL_EVENTS;
2171
 		error = 0;
2172
 		break;
2173
 	case SIOCGIFWOLOPTS:
2174
 		SIS_LOCK(sc);
2175
 		sis_get_wolopts(sc, &ifr->ifr_wolopts);
2176
 		SIS_UNLOCK(sc);
2177
 		error = 0;
2178
 		break;
2179
 	case SIOCSIFWOLOPTS:
2180
 		SIS_LOCK(sc);
2181
 		error = sis_set_wolopts(sc, &ifr->ifr_wolopts);
2182
 		SIS_UNLOCK(sc);
2183
  		break;
2165
	default:
2184
	default:
2166
		error = ether_ioctl(ifp, command, data);
2185
		error = ether_ioctl(ifp, command, data);
2167
		break;
2186
		break;
Lines 2271-2279 Link Here
2271
	SIS_LOCK(sc);
2290
	SIS_LOCK(sc);
2272
	sis_reset(sc);
2291
	sis_reset(sc);
2273
	sis_stop(sc);
2292
	sis_stop(sc);
2293
	sis_enable_wol(sc);
2274
	SIS_UNLOCK(sc);
2294
	SIS_UNLOCK(sc);
2275
}
2295
}
2276
2296
2297
/*
2298
 * Translate wake on lan events defined in if.h
2299
 * into flags the chip understands.
2300
 */
2301
static uint32_t
2302
sis_translate_wol_events(uint32_t wol_events)
2303
{
2304
	uint32_t sis_wol_events = 0;
2305
	
2306
	if (wol_events & IFWOL_WAKE_ON_UNICAST)
2307
		sis_wol_events |= NS_WCSR_WAKE_UCAST;
2308
	if (wol_events & IFWOL_WAKE_ON_MULTICAST)
2309
		sis_wol_events |= NS_WCSR_WAKE_MCAST;
2310
	if (wol_events & IFWOL_WAKE_ON_BROADCAST)
2311
		sis_wol_events |= NS_WCSR_WAKE_BCAST;
2312
	if (wol_events & IFWOL_WAKE_ON_MAGIC)
2313
		sis_wol_events |= NS_WCSR_WAKE_MAGIC;
2314
2315
	return sis_wol_events;
2316
}
2317
2318
/*
2319
 * Write current wake on lan settings into an if_wolopts structure.
2320
 * Note that the sopasswd field in the structure is cleared, because
2321
 * the password is confidential.
2322
 */
2323
static void
2324
sis_get_wolopts(struct sis_softc *sc, struct if_wolopts *wolopts)
2325
{
2326
	int i;
2327
2328
	SIS_LOCK_ASSERT(sc);
2329
2330
	wolopts->ifwol_events = sc->ns_wol_events;
2331
	
2332
	/* Do not disclose Secure On password. */
2333
#define	N(a)	(sizeof(a) / sizeof(a[0]))
2334
	for (i = 0; i < N(wolopts->ifwol_sopasswd); i++)
2335
		wolopts->ifwol_sopasswd[i] = '\0';
2336
#undef N
2337
}
2338
	
2339
/*
2340
 * Set wake on lan options.
2341
 */
2342
static int
2343
sis_set_wolopts(struct sis_softc *sc, struct if_wolopts *wolopts)
2344
{
2345
	SIS_LOCK_ASSERT(sc);
2346
2347
	/* FIXME: handle sopasswd */
2348
2349
	if (wolopts->ifwol_events == IFWOL_DISABLE)
2350
		sc->ns_wol_events = 0;
2351
	else {
2352
		if ((wolopts->ifwol_events & ~NS_SUPPORTED_WOL_EVENTS) != 0)
2353
			return EINVAL;
2354
		sc->ns_wol_events = wolopts->ifwol_events;
2355
	}
2356
2357
	return 0;
2358
}
2359
2360
/* 
2361
 * Enable Wake On Lan on the DP83815,
2362
 * if any wake on lan options have been set.
2363
 */
2364
static void
2365
sis_enable_wol(struct sis_softc *sc)
2366
{
2367
	SIS_LOCK_ASSERT(sc);
2368
	
2369
	if (sc->sis_type != SIS_TYPE_83815)
2370
		return;
2371
2372
	/* Check whether any wake on lan events have been set. */
2373
	if (sc->ns_wol_events == 0)
2374
		return;
2375
2376
	/*
2377
	 * Configure the recieve filter to accept potential wake packets,
2378
	 * configure wake events and enter low-power state.
2379
	 */
2380
2381
	/* Stop reciever. */
2382
	SIS_SETBIT(sc, SIS_CSR, SIS_CSR_RX_DISABLE);
2383
	
2384
	/* Reset recieve pointer */
2385
	CSR_WRITE_4(sc, SIS_RX_LISTPTR, 0);
2386
2387
	/* Re-enable reciever (now in "silent recieve mode.") */
2388
	SIS_SETBIT(sc, SIS_CSR, SIS_CSR_RX_ENABLE);
2389
2390
	/* Clear recieve filter register, so that the enable bit is unset.
2391
	 * Other bits in this register can only be configured while the enable
2392
	 * bit is zero. */
2393
	CSR_WRITE_4(sc, SIS_RXFILT_CTL, 0);
2394
2395
	/* 
2396
	 * Accept unicast packets. The datasheet seems to be inaccurate.
2397
	 * It suggests simply setting the unicast bit in NS_RXFILTCTL,
2398
	 * but this does not seem to work. Instead, we "perfect match"
2399
	 * our own mac address, which makes the rx filter accept unicast
2400
	 * packets. (section below copy pasted from sis_initl routine)
2401
	 */
2402
	CSR_WRITE_4(sc, SIS_RXFILT_CTL, NS_FILTADDR_PAR0);
2403
	CSR_WRITE_4(sc, SIS_RXFILT_DATA,
2404
	    ((uint16_t *)IFP2ENADDR(sc->sis_ifp))[0]);
2405
	CSR_WRITE_4(sc, SIS_RXFILT_CTL, NS_FILTADDR_PAR1);
2406
	CSR_WRITE_4(sc, SIS_RXFILT_DATA,
2407
	    ((uint16_t *)IFP2ENADDR(sc->sis_ifp))[1]);
2408
	CSR_WRITE_4(sc, SIS_RXFILT_CTL, NS_FILTADDR_PAR2);
2409
	CSR_WRITE_4(sc, SIS_RXFILT_DATA,
2410
	    ((uint16_t *)IFP2ENADDR(sc->sis_ifp))[2]);
2411
	SIS_SETBIT(sc, SIS_RXFILT_CTL, NS_RXFILTCTL_PERFECT);
2412
2413
	/* Allow broadcast and multicast packets, too. */
2414
	SIS_SETBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_BROAD);
2415
	SIS_SETBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_ALLMULTI);
2416
2417
	/* Re-enable RX filter. */
2418
	SIS_SETBIT(sc, SIS_RXFILT_CTL, SIS_RXFILTCTL_ENABLE);
2419
2420
	/* Configure wake on lan events */
2421
	CSR_WRITE_4(sc, NS_WCSR, sis_translate_wol_events(sc->ns_wol_events));
2422
2423
	/* Set appropriate power state, so the card stays active
2424
	 * after system shutdown. */
2425
	CSR_WRITE_4(sc, NS_CLKRUN, NS_CLKRUN_PMESTS | NS_CLKRUN_PMEENB);
2426
}
2427
2277
static device_method_t sis_methods[] = {
2428
static device_method_t sis_methods[] = {
2278
	/* Device interface */
2429
	/* Device interface */
2279
	DEVMETHOD(device_probe,		sis_probe),
2430
	DEVMETHOD(device_probe,		sis_probe),
(-)sys/pci/if_sisreg.h (+16 lines)
Lines 77-82 Link Here
77
/* NS DP83815/6 registers */
77
/* NS DP83815/6 registers */
78
#define NS_IHR			0x1C
78
#define NS_IHR			0x1C
79
#define NS_CLKRUN		0x3C
79
#define NS_CLKRUN		0x3C
80
#define NS_WCSR			0x40
80
#define NS_SRR			0x58
81
#define NS_SRR			0x58
81
#define NS_BMCR			0x80
82
#define NS_BMCR			0x80
82
#define NS_BMSR			0x84
83
#define NS_BMSR			0x84
Lines 463-468 Link Here
463
#endif
464
#endif
464
	int			in_tick;
465
	int			in_tick;
465
	struct mtx		sis_mtx;
466
	struct mtx		sis_mtx;
467
	uint32_t		ns_wol_events;
466
};
468
};
467
469
468
#define	SIS_LOCK(_sc)		mtx_lock(&(_sc)->sis_mtx)
470
#define	SIS_LOCK(_sc)		mtx_lock(&(_sc)->sis_mtx)
Lines 523-525 Link Here
523
#define SIS_PSTATE_D3		0x0003
525
#define SIS_PSTATE_D3		0x0003
524
#define SIS_PME_EN		0x0010
526
#define SIS_PME_EN		0x0010
525
#define SIS_PME_STATUS		0x8000
527
#define SIS_PME_STATUS		0x8000
528
529
/* DP83815 pci config space power management register */
530
#define NS_PMCSR		0x44
531
532
/* DP83815 Wake On Lan Command/Status register */
533
#define NS_WCSR_WAKE_UCAST	0x00000002
534
#define NS_WCSR_WAKE_MCAST	0x00000004
535
#define NS_WCSR_WAKE_BCAST	0x00000008
536
#define NS_WCSR_WAKE_MAGIC	0x00000200
537
538
/* FIXME: handle sopasswd */
539
#define NS_SUPPORTED_WOL_EVENTS	(IFWOL_WAKE_ON_UNICAST | IFWOL_WAKE_ON_MULTICAST \
540
				    | IFWOL_WAKE_ON_BROADCAST | IFWOL_WAKE_ON_MAGIC)
541
(-)sys/pci/if_vr.c (-1 / +113 lines)
Lines 169-174 Link Here
169
static int vr_list_rx_init(struct vr_softc *);
169
static int vr_list_rx_init(struct vr_softc *);
170
static int vr_list_tx_init(struct vr_softc *);
170
static int vr_list_tx_init(struct vr_softc *);
171
171
172
static int vr_set_wolopts(struct vr_softc *, struct if_wolopts *);
173
static void vr_get_wolopts(struct vr_softc *, struct if_wolopts *);
174
static void vr_enable_wol(struct vr_softc *);
175
172
#ifdef VR_USEIOSPACE
176
#ifdef VR_USEIOSPACE
173
#define VR_RES			SYS_RES_IOPORT
177
#define VR_RES			SYS_RES_IOPORT
174
#define VR_RID			VR_PCI_LOIO
178
#define VR_RID			VR_PCI_LOIO
Lines 710-716 Link Here
710
#endif
714
#endif
711
715
712
	/*
716
	/*
713
	 * Windows may put the chip in suspend mode when it
717
	 * Windows or WOL may put the chip in suspend mode when it
714
	 * shuts down. Be sure to kick it in the head to wake it
718
	 * shuts down. Be sure to kick it in the head to wake it
715
	 * up again.
719
	 * up again.
716
	 */
720
	 */
Lines 761-766 Link Here
761
765
762
	sc->suspended = 0;
766
	sc->suspended = 0;
763
767
768
	/* Check Wake on Lan support. */
769
	if (sc->vr_revid >= REV_ID_VT6102 ) {
770
		sc->wol_support = 1;
771
		if (sc->vr_revid >= REV_ID_VT6105_B0)
772
			sc->wol_6patterns = 1;
773
	}
774
764
	/* Hook interrupt last to avoid having to lock softc */
775
	/* Hook interrupt last to avoid having to lock softc */
765
	error = bus_setup_intr(dev, sc->vr_irq, INTR_TYPE_NET | INTR_MPSAFE,
776
	error = bus_setup_intr(dev, sc->vr_irq, INTR_TYPE_NET | INTR_MPSAFE,
766
	    vr_intr, sc, &sc->vr_intrhand);
777
	    vr_intr, sc, &sc->vr_intrhand);
Lines 1618-1623 Link Here
1618
		}
1629
		}
1619
#endif /* DEVICE_POLLING */
1630
#endif /* DEVICE_POLLING */
1620
		break;
1631
		break;
1632
 	case SIOCGIFWOLSUPP:
1633
 		ifr->ifr_wolopts.ifwol_supported = VR_SUPPORTED_WOL_EVENTS;
1634
 		error = 0;
1635
 		break;
1636
 	case SIOCGIFWOLOPTS:
1637
 		VR_LOCK(sc);
1638
 		vr_get_wolopts(sc, &ifr->ifr_wolopts);
1639
 		VR_UNLOCK(sc);
1640
 		error = 0;
1641
 		break;
1642
 	case SIOCSIFWOLOPTS:
1643
 		VR_LOCK(sc);
1644
 		error = vr_set_wolopts(sc, &ifr->ifr_wolopts);
1645
 		VR_UNLOCK(sc);
1646
  		break;
1621
	default:
1647
	default:
1622
		error = ether_ioctl(ifp, command, data);
1648
		error = ether_ioctl(ifp, command, data);
1623
		break;
1649
		break;
Lines 1702-1707 Link Here
1702
static void
1728
static void
1703
vr_shutdown(device_t dev)
1729
vr_shutdown(device_t dev)
1704
{
1730
{
1731
	struct vr_softc *sc;
1705
1732
1733
	sc = device_get_softc(dev);
1734
	VR_LOCK(sc);
1735
	vr_enable_wol(sc);
1736
	VR_UNLOCK(sc);
1706
	vr_detach(dev);
1737
	vr_detach(dev);
1707
}
1738
}
1739
1740
static void
1741
vr_enable_wol(struct vr_softc *sc)
1742
{
1743
	VR_LOCK_ASSERT(sc);
1744
	
1745
	/* Check whether wake on lan is available
1746
	 * and whether events have been set. */
1747
	if (!sc->wol_support || sc->wol_events == 0)
1748
		return;
1749
1750
	/* Set the chip to power state D0 */
1751
	VR_CLRBIT(sc, VR_STICKHW, (VR_STICKHW_DS0|VR_STICKHW_DS1));
1752
1753
	/* Clear WOL configuration */
1754
	CSR_WRITE_1(sc, VR_WOLCRCLR, 0xFF);
1755
	if (sc->wol_6patterns)
1756
		CSR_WRITE_1(sc, VR_WOLCRCLR1, 0x03);
1757
1758
	/* Clear power-event status. */
1759
	CSR_WRITE_1(sc, VR_PWRCSRCLR, 0xFF);
1760
1761
	/* Don't use extra patterns. */
1762
	if (sc->wol_6patterns)
1763
		CSR_WRITE_1(sc, VR_WOLCGCLR, 0x04);
1764
	
1765
	/* Set unicast wake event if applicable. */
1766
	if (sc->wol_events & IFWOL_WAKE_ON_UNICAST)
1767
		VR_SETBIT(sc, VR_WOLCRSET, VR_WAKE_UCAST);
1768
	
1769
	/* Set magic wake event if applicable. */
1770
	if (sc->wol_events & IFWOL_WAKE_ON_MAGIC) {
1771
		VR_SETBIT(sc, VR_WOLCRSET, VR_WAKE_MAGIC);
1772
		/* enable EEPROM-controlled wake-up */
1773
		VR_SETBIT(sc, VR_CONFIG, 0x03);
1774
	}
1775
#if 0
1776
	/* Set broadcast/multicast wake event if applicable. */
1777
	/* Does not work for some reason :( */
1778
	if (sc->wol_events & IFWOL_WAKE_ON_BROADCAST ||
1779
	    sc->wol_events & IFWOL_WAKE_ON_MULTICAST)
1780
		CSR_WRITE_1(sc, VR_WOLCGSET, VR_WAKE_BMCAST);
1781
#endif
1782
	/* Enable Wake On Lan. */
1783
	CSR_WRITE_1(sc, VR_PWCFGSET, 0x01);
1784
	VR_SETBIT(sc, VR_STICKHW, VR_STICKHW_WOL_ENB);
1785
1786
	/* Set power state to D3 */
1787
	VR_SETBIT(sc, VR_STICKHW, (VR_STICKHW_DS0|VR_STICKHW_DS1));
1788
}
1789
1790
1791
/*
1792
 * Write current wake on lan settings into an if_wolopts structure.
1793
 */
1794
static void
1795
vr_get_wolopts(struct vr_softc *sc, struct if_wolopts *wolopts)
1796
{
1797
	VR_LOCK_ASSERT(sc);
1798
	wolopts->ifwol_events = sc->wol_events;
1799
}
1800
	
1801
/*
1802
 * Set wake on lan options.
1803
 */
1804
static int
1805
vr_set_wolopts(struct vr_softc *sc, struct if_wolopts *wolopts)
1806
{
1807
	VR_LOCK_ASSERT(sc);
1808
1809
	if (wolopts->ifwol_events == IFWOL_DISABLE)
1810
		sc->wol_events = 0;
1811
	else {
1812
		if ((wolopts->ifwol_events & ~VR_SUPPORTED_WOL_EVENTS) != 0)
1813
			return EINVAL;
1814
		sc->wol_events = wolopts->ifwol_events;
1815
	}
1816
1817
	return 0;
1818
}
1819
(-)sys/pci/if_vrreg.h (+23 lines)
Lines 283-288 Link Here
283
#define VR_STICKHW_WOL_STS	0x08
283
#define VR_STICKHW_WOL_STS	0x08
284
#define VR_STICKHW_LEGWOL_ENB	0x80
284
#define VR_STICKHW_LEGWOL_ENB	0x80
285
285
286
/* Wake on Lan definitions (snooped from Linux driver) */
287
#define	VR_WOLCRSET		0xA0
288
#define VR_PWCFGSET		0xA1
289
#define	VR_WOLCGSET		0xA3
290
#define	VR_WOLCRCLR		0xA4
291
#define	VR_WOLCRCLR1		0xA6
292
#define	VR_WOLCGCLR		0xA7
293
#define	VR_PWRCSRCLR		0xAC
294
#define	VR_WAKE_UCAST		0x10
295
#define	VR_WAKE_MAGIC		0x20
296
#define	VR_WAKE_BMCAST		0x30
297
#define	VR_WAKE_LINKON		0x40
298
#define	VR_WAKE_LINKOFF		0x80
299
#define VR_SUPPORTED_WOL_EVENTS	(IFWOL_WAKE_ON_UNICAST | IFWOL_WAKE_ON_MAGIC)
300
286
/*
301
/*
287
 * BCR0 register bits. (At least for the VT6102 chip.)
302
 * BCR0 register bits. (At least for the VT6102 chip.)
288
 */
303
 */
Lines 471-476 Link Here
471
#ifdef DEVICE_POLLING
486
#ifdef DEVICE_POLLING
472
	int			rxcycles;
487
	int			rxcycles;
473
#endif
488
#endif
489
	int			wol_support;	/* Chip supports WOL. */
490
	uint32_t		wol_events;	/* Wake on Lan satus */
491
	int			wol_6patterns;	/* some chips have 6 patterns
492
						   for WOL instead of 4 */
474
};
493
};
475
494
476
#define VR_F_RESTART		0x01		/* Restart unit on next tick */
495
#define VR_F_RESTART		0x01		/* Restart unit on next tick */
Lines 545-554 Link Here
545
#define REV_ID_VT3065_A			0x40
564
#define REV_ID_VT3065_A			0x40
546
#define REV_ID_VT3065_B			0x41
565
#define REV_ID_VT3065_B			0x41
547
#define REV_ID_VT3065_C			0x42
566
#define REV_ID_VT3065_C			0x42
567
#define REV_ID_VT6102			0x40
548
#define REV_ID_VT6102_APOLLO		0x74
568
#define REV_ID_VT6102_APOLLO		0x74
549
#define REV_ID_VT3106			0x80
569
#define REV_ID_VT3106			0x80
550
#define REV_ID_VT3106_J			0x80    /* 0x80-0x8F */
570
#define REV_ID_VT3106_J			0x80    /* 0x80-0x8F */
551
#define REV_ID_VT3106_S			0x90    /* 0x90-0xA0 */
571
#define REV_ID_VT3106_S			0x90    /* 0x90-0xA0 */
572
#define	REV_ID_VT6105			0x80
573
#define	REV_ID_VT6105_B0		0x83
574
552
575
553
/*
576
/*
554
 * PCI low memory base and low I/O base register, and
577
 * PCI low memory base and low I/O base register, and
(-)sys/sys/sockio.h (+7 lines)
Lines 117-120 Link Here
117
#define	SIOCIFDESTROY	 _IOW('i', 121, struct ifreq)	/* destroy clone if */
117
#define	SIOCIFDESTROY	 _IOW('i', 121, struct ifreq)	/* destroy clone if */
118
#define	SIOCIFGCLONERS	_IOWR('i', 120, struct if_clonereq) /* get cloners */
118
#define	SIOCIFGCLONERS	_IOWR('i', 120, struct if_clonereq) /* get cloners */
119
119
120
#define	SIOCGIFWOLOPTS	_IOWR('i', 124, struct ifreq)	/* get wake on lan
121
							   	options */
122
#define	SIOCSIFWOLOPTS	 _IOW('i', 125, struct ifreq)	/* set wake on lan
123
							   	options */
124
#define	SIOCGIFWOLSUPP	_IOWR('i', 126, struct ifreq)	/* get wake on lan
125
							   modes supported by
126
							   device */
120
#endif /* !_SYS_SOCKIO_H_ */
127
#endif /* !_SYS_SOCKIO_H_ */

Return to bug 83807