1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
|
/*
################################################################################
#
# Copyright(c) Realtek Semiconductor Corp. All rights reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation; either version 2 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 59
# Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# The full GNU General Public License is included in this distribution in the
# file called LICENSE.
#
################################################################################
*/
/*
* This product is covered by one or more of the following patents:
* US5,307,459, US5,434,872, US5,732,094, US6,570,884, US6,115,776, and US6,327,625.
*/
#include <linux/module.h>
#include <linux/version.h>
#include <linux/pci.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/delay.h>
#include <linux/ethtool.h>
#include <linux/mii.h>
#include <linux/if_vlan.h>
#include <linux/crc32.h>
#include <linux/in.h>
#include <linux/ip.h>
#include <linux/tcp.h>
#include <linux/init.h>
#include <linux/rtnetlink.h>
#include "r8198.h"
#include "r8198_asf.h"
extern int rtl8198_eri_read(void __iomem *ioaddr, int addr, int len, int type);
extern int rtl8198_eri_write(void __iomem *ioaddr, int addr, int len, int value, int type);
int rtl8198_asf_ioctl(struct net_device *dev,
struct ifreq *ifr)
{
struct rtl8198_private *tp = netdev_priv(dev);
void __iomem *ioaddr = tp->mmio_addr;
void *user_data = ifr->ifr_data;
struct asf_ioctl_struct asf_usrdata;
if (tp->mcfg != CFG_METHOD_7 && tp->mcfg != CFG_METHOD_8)
return -EOPNOTSUPP;
if (copy_from_user(&asf_usrdata, user_data, sizeof(struct asf_ioctl_struct)))
return -EFAULT;
switch (asf_usrdata.offset) {
case HBPeriod:
rtl8198_asf_hbperiod(ioaddr, asf_usrdata.arg, asf_usrdata.u.data);
break;
case WD8Timer:
break;
case WD16Rst:
rtl8198_asf_wd16rst(ioaddr, asf_usrdata.arg, asf_usrdata.u.data);
break;
case WD8Rst:
rtl8198_asf_time_period(ioaddr, asf_usrdata.arg, WD8Rst, asf_usrdata.u.data);
break;
case LSnsrPollCycle:
rtl8198_asf_time_period(ioaddr, asf_usrdata.arg, LSnsrPollCycle, asf_usrdata.u.data);
break;
case ASFSnsrPollPrd:
rtl8198_asf_time_period(ioaddr, asf_usrdata.arg, ASFSnsrPollPrd, asf_usrdata.u.data);
break;
case AlertReSendItvl:
rtl8198_asf_time_period(ioaddr, asf_usrdata.arg, AlertReSendItvl, asf_usrdata.u.data);
break;
case SMBAddr:
rtl8198_asf_rw_hexadecimal(ioaddr, asf_usrdata.arg, SMBAddr, RW_ONE_BYTE, asf_usrdata.u.data);
break;
case ASFConfigR0:
rtl8198_asf_config_regs(ioaddr, asf_usrdata.arg, ASFConfigR0, asf_usrdata.u.data);
break;
case ASFConfigR1:
rtl8198_asf_config_regs(ioaddr, asf_usrdata.arg, ASFConfigR1, asf_usrdata.u.data);
break;
case ConsoleMA:
rtl8198_asf_console_mac(ioaddr, asf_usrdata.arg, asf_usrdata.u.data);
break;
case ConsoleIP:
rtl8198_asf_ip_address(ioaddr, asf_usrdata.arg, ConsoleIP, asf_usrdata.u.data);
break;
case IPAddr:
rtl8198_asf_ip_address(ioaddr, asf_usrdata.arg, IPAddr, asf_usrdata.u.data);
break;
case UUID:
rtl8198_asf_rw_uuid(ioaddr, asf_usrdata.arg, asf_usrdata.u.data);
break;
case IANA:
rtl8198_asf_rw_iana(ioaddr, asf_usrdata.arg, asf_usrdata.u.data);
break;
case SysID:
rtl8198_asf_rw_systemid(ioaddr, asf_usrdata.arg, asf_usrdata.u.data);
break;
case Community:
rtl8198_asf_community_string(ioaddr, asf_usrdata.arg, asf_usrdata.u.string);
break;
case StringLength:
rtl8198_asf_community_string_len(ioaddr, asf_usrdata.arg, asf_usrdata.u.data);
break;
case FmCapMsk:
rtl8198_asf_capability_masks(ioaddr, asf_usrdata.arg, FmCapMsk, asf_usrdata.u.data);
break;
case SpCMDMsk:
rtl8198_asf_capability_masks(ioaddr, asf_usrdata.arg, SpCMDMsk, asf_usrdata.u.data);
break;
case SysCapMsk:
rtl8198_asf_capability_masks(ioaddr, asf_usrdata.arg, SysCapMsk, asf_usrdata.u.data);
break;
case RmtRstAddr:
rtl8198_asf_rw_hexadecimal(ioaddr, asf_usrdata.arg, RmtRstAddr, RW_ONE_BYTE, asf_usrdata.u.data);
break;
case RmtRstCmd:
rtl8198_asf_rw_hexadecimal(ioaddr, asf_usrdata.arg, RmtRstCmd, RW_ONE_BYTE, asf_usrdata.u.data);
break;
case RmtRstData:
rtl8198_asf_rw_hexadecimal(ioaddr, asf_usrdata.arg, RmtRstData, RW_ONE_BYTE, asf_usrdata.u.data);
break;
case RmtPwrOffAddr:
rtl8198_asf_rw_hexadecimal(ioaddr, asf_usrdata.arg, RmtPwrOffAddr, RW_ONE_BYTE, asf_usrdata.u.data);
break;
case RmtPwrOffCmd:
rtl8198_asf_rw_hexadecimal(ioaddr, asf_usrdata.arg, RmtPwrOffCmd, RW_ONE_BYTE, asf_usrdata.u.data);
break;
case RmtPwrOffData:
rtl8198_asf_rw_hexadecimal(ioaddr, asf_usrdata.arg, RmtPwrOffData, RW_ONE_BYTE, asf_usrdata.u.data);
break;
case RmtPwrOnAddr:
rtl8198_asf_rw_hexadecimal(ioaddr, asf_usrdata.arg, RmtPwrOnAddr, RW_ONE_BYTE, asf_usrdata.u.data);
break;
case RmtPwrOnCmd:
rtl8198_asf_rw_hexadecimal(ioaddr, asf_usrdata.arg, RmtPwrOnCmd, RW_ONE_BYTE, asf_usrdata.u.data);
break;
case RmtPwrOnData:
rtl8198_asf_rw_hexadecimal(ioaddr, asf_usrdata.arg, RmtPwrOnData, RW_ONE_BYTE, asf_usrdata.u.data);
break;
case RmtPCRAddr:
rtl8198_asf_rw_hexadecimal(ioaddr, asf_usrdata.arg, RmtPCRAddr, RW_ONE_BYTE, asf_usrdata.u.data);
break;
case RmtPCRCmd:
rtl8198_asf_rw_hexadecimal(ioaddr, asf_usrdata.arg, RmtPCRCmd, RW_ONE_BYTE, asf_usrdata.u.data);
break;
case RmtPCRData:
rtl8198_asf_rw_hexadecimal(ioaddr, asf_usrdata.arg, RmtPCRData, RW_ONE_BYTE, asf_usrdata.u.data);
break;
case ASFSnsr0Addr:
rtl8198_asf_rw_hexadecimal(ioaddr, asf_usrdata.arg, ASFSnsr0Addr, RW_ONE_BYTE, asf_usrdata.u.data);
break;
case LSnsrAddr0:
rtl8198_asf_rw_hexadecimal(ioaddr, asf_usrdata.arg, LSnsrAddr0, RW_ONE_BYTE, asf_usrdata.u.data);
break;
case KO:
/* Get/Set Key Operation */
rtl8198_asf_key_access(ioaddr, asf_usrdata.arg, KO, asf_usrdata.u.data);
break;
case KA:
/* Get/Set Key Administrator */
rtl8198_asf_key_access(ioaddr, asf_usrdata.arg, KA, asf_usrdata.u.data);
break;
case KG:
/* Get/Set Key Generation */
rtl8198_asf_key_access(ioaddr, asf_usrdata.arg, KG, asf_usrdata.u.data);
break;
case KR:
/* Get/Set Key Random */
rtl8198_asf_key_access(ioaddr, asf_usrdata.arg, KR, asf_usrdata.u.data);
break;
default:
return -EOPNOTSUPP;
}
if (copy_to_user(user_data, &asf_usrdata, sizeof(struct asf_ioctl_struct)))
return -EFAULT;
return 0;
}
void rtl8198_asf_hbperiod(void __iomem *ioaddr, int arg, unsigned int *data)
{
if (arg == ASF_GET)
data[ASFHBPERIOD] = rtl8198_eri_read(ioaddr, HBPeriod, RW_TWO_BYTES, ERIAR_ASF);
else if (arg == ASF_SET) {
rtl8198_eri_write(ioaddr, HBPeriod, RW_TWO_BYTES, data[ASFHBPERIOD], ERIAR_ASF);
rtl8198_eri_write(ioaddr, 0x1EC, RW_ONE_BYTE, 0x07, ERIAR_ASF);
}
}
void rtl8198_asf_wd16rst(void __iomem *ioaddr, int arg, unsigned int *data)
{
data[ASFWD16RST] = rtl8198_eri_read(ioaddr, WD16Rst, RW_TWO_BYTES, ERIAR_ASF);
}
void rtl8198_asf_console_mac(void __iomem *ioaddr, int arg, unsigned int *data)
{
int i;
if (arg == ASF_GET) {
for (i = 0; i < 6; i++)
data[i] = rtl8198_eri_read(ioaddr, ConsoleMA + i, RW_ONE_BYTE, ERIAR_ASF);
} else if (arg == ASF_SET) {
for (i = 0; i < 6; i++)
rtl8198_eri_write(ioaddr, ConsoleMA + i, RW_ONE_BYTE, data[i], ERIAR_ASF);
}
}
void rtl8198_asf_ip_address(void __iomem *ioaddr, int arg, int offset, unsigned int *data)
{
int i;
if (arg == ASF_GET) {
for (i = 0; i < 4; i++)
data[i] = rtl8198_eri_read(ioaddr, offset + i, RW_ONE_BYTE, ERIAR_ASF);
} else if (arg == ASF_SET) {
for (i = 0; i < 4; i++)
rtl8198_eri_write(ioaddr, offset + i, RW_ONE_BYTE, data[i], ERIAR_ASF);
}
}
void rtl8198_asf_config_regs(void __iomem *ioaddr, int arg, int offset, unsigned int *data)
{
unsigned int value;
if (arg == ASF_GET) {
data[ASFCAPABILITY] = (rtl8198_eri_read(ioaddr, offset, RW_ONE_BYTE, ERIAR_ASF) & data[ASFCONFIG]) ? FUNCTION_ENABLE : FUNCTION_DISABLE;
} else if (arg == ASF_SET) {
value = rtl8198_eri_read(ioaddr, offset, RW_ONE_BYTE, ERIAR_ASF);
if (data[ASFCAPABILITY] == FUNCTION_ENABLE)
value |= data[ASFCONFIG];
else if (data[ASFCAPABILITY] == FUNCTION_DISABLE)
value &= ~data[ASFCONFIG];
rtl8198_eri_write(ioaddr, offset, RW_ONE_BYTE, value, ERIAR_ASF);
}
}
void rtl8198_asf_capability_masks(void __iomem *ioaddr, int arg, int offset, unsigned int *data)
{
unsigned int len, bit_mask;
bit_mask = DISABLE_MASK;
if (offset == FmCapMsk) {
/* System firmware capabilities */
len = RW_FOUR_BYTES;
if (data[ASFCAPMASK] == FUNCTION_ENABLE)
bit_mask = FMW_CAP_MASK;
} else if (offset == SpCMDMsk) {
/* Special commands */
len = RW_TWO_BYTES;
if (data[ASFCAPMASK] == FUNCTION_ENABLE)
bit_mask = SPC_CMD_MASK;
} else {
/* System capability (offset == SysCapMsk)*/
len = RW_ONE_BYTE;
if (data[ASFCAPMASK] == FUNCTION_ENABLE)
bit_mask = SYS_CAP_MASK;
}
if (arg == ASF_GET)
data[ASFCAPMASK] = rtl8198_eri_read(ioaddr, offset, len, ERIAR_ASF) ? FUNCTION_ENABLE : FUNCTION_DISABLE;
else /* arg == ASF_SET */
rtl8198_eri_write(ioaddr, offset, len, bit_mask, ERIAR_ASF);
}
void rtl8198_asf_community_string(void __iomem *ioaddr, int arg, char *string)
{
int i;
if (arg == ASF_GET) {
for (i = 0; i < COMMU_STR_MAX_LEN; i++)
string[i] = rtl8198_eri_read(ioaddr, Community + i, RW_ONE_BYTE, ERIAR_ASF);
} else { /* arg == ASF_SET */
for (i = 0; i < COMMU_STR_MAX_LEN; i++)
rtl8198_eri_write(ioaddr, Community + i, RW_ONE_BYTE, string[i], ERIAR_ASF);
}
}
void rtl8198_asf_community_string_len(void __iomem *ioaddr, int arg, unsigned int *data)
{
if (arg == ASF_GET)
data[ASFCOMMULEN] = rtl8198_eri_read(ioaddr, StringLength, RW_ONE_BYTE, ERIAR_ASF);
else /* arg == ASF_SET */
rtl8198_eri_write(ioaddr, StringLength, RW_ONE_BYTE, data[ASFCOMMULEN], ERIAR_ASF);
}
void rtl8198_asf_time_period(void __iomem *ioaddr, int arg, int offset, unsigned int *data)
{
int pos;
if (offset == WD8Rst)
pos = ASFWD8RESET;
else if (offset == LSnsrPollCycle)
pos = ASFLSNRPOLLCYC;
else if (offset == ASFSnsrPollPrd)
pos = ASFSNRPOLLCYC;
else if (offset == AlertReSendItvl)
pos = ASFALERTRESND;
if (arg == ASF_GET)
data[pos] = rtl8198_eri_read(ioaddr, offset, RW_ONE_BYTE, ERIAR_ASF);
else /* arg == ASF_SET */
rtl8198_eri_write(ioaddr, offset, RW_ONE_BYTE, data[pos], ERIAR_ASF);
}
void rtl8198_asf_key_access(void __iomem *ioaddr, int arg, int offset, unsigned int *data)
{
int i;
if (arg == ASF_GET)
for (i = 0; i < KEY_LEN; i++)
data[i] = rtl8198_eri_read(ioaddr, offset + KEY_LEN - (i + 1), RW_ONE_BYTE, ERIAR_ASF);
else /* arg == ASF_SET */
for (i = 0; i < KEY_LEN; i++)
rtl8198_eri_write(ioaddr, offset + KEY_LEN - (i + 1), RW_ONE_BYTE, data[i], ERIAR_ASF);
}
void rtl8198_asf_rw_hexadecimal(void __iomem *ioaddr, int arg, int offset, int len, unsigned int *data)
{
if (arg == ASF_GET)
data[ASFRWHEXNUM] = rtl8198_eri_read(ioaddr, offset, len, ERIAR_ASF);
else /* arg == ASF_SET */
rtl8198_eri_write(ioaddr, offset, len, data[ASFRWHEXNUM], ERIAR_ASF);
}
void rtl8198_asf_rw_systemid(void __iomem *ioaddr, int arg, unsigned int *data)
{
int i;
if (arg == ASF_GET)
for (i = 0; i < SYSID_LEN ; i++)
data[i] = rtl8198_eri_read(ioaddr, SysID + i, RW_ONE_BYTE, ERIAR_ASF);
else /* arg == ASF_SET */
for (i = 0; i < SYSID_LEN ; i++)
rtl8198_eri_write(ioaddr, SysID + i, RW_ONE_BYTE, data[i], ERIAR_ASF);
}
void rtl8198_asf_rw_iana(void __iomem *ioaddr, int arg, unsigned int *data)
{
int i;
if (arg == ASF_GET)
for (i = 0; i < RW_FOUR_BYTES; i++)
data[i] = rtl8198_eri_read(ioaddr, IANA + i, RW_ONE_BYTE, ERIAR_ASF);
else /* arg == ASF_SET */
for (i = 0; i < RW_FOUR_BYTES; i++)
rtl8198_eri_write(ioaddr, IANA + i, RW_ONE_BYTE, data[i], ERIAR_ASF);
}
void rtl8198_asf_rw_uuid(void __iomem *ioaddr, int arg, unsigned int *data)
{
int i, j;
if (arg == ASF_GET)
for (i = UUID_LEN - 1, j = 0; i >= 0 ; i--, j++)
data[j] = rtl8198_eri_read(ioaddr, UUID + i, RW_ONE_BYTE, ERIAR_ASF);
else /* arg == ASF_SET */
for (i = UUID_LEN - 1, j = 0; i >= 0 ; i--, j++)
rtl8198_eri_write(ioaddr, UUID + i, RW_ONE_BYTE, data[j], ERIAR_ASF);
}
|