r8152.c 122 KB
Newer Older
hayeswang's avatar
hayeswang committed
1
/*
2
 *  Copyright (c) 2014 Realtek Semiconductor Corp. All rights reserved.
hayeswang's avatar
hayeswang committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * version 2 as published by the Free Software Foundation.
 *
 */

#include <linux/signal.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/mii.h>
#include <linux/ethtool.h>
#include <linux/usb.h>
#include <linux/crc32.h>
#include <linux/if_vlan.h>
#include <linux/uaccess.h>
hayeswang's avatar
hayeswang committed
21
#include <linux/list.h>
hayeswang's avatar
hayeswang committed
22
23
#include <linux/ip.h>
#include <linux/ipv6.h>
hayeswang's avatar
hayeswang committed
24
#include <net/ip6_checksum.h>
hayeswang's avatar
hayeswang committed
25
26
#include <uapi/linux/mdio.h>
#include <linux/mdio.h>
hayeswang's avatar
hayeswang committed
27
#include <linux/usb/cdc.h>
hayeswang's avatar
hayeswang committed
28
#include <linux/suspend.h>
29
#include <linux/acpi.h>
hayeswang's avatar
hayeswang committed
30

hayeswang's avatar
hayeswang committed
31
/* Information for net-next */
hayeswang's avatar
hayeswang committed
32
#define NETNEXT_VERSION		"09"
hayeswang's avatar
hayeswang committed
33
34

/* Information for net */
35
#define NET_VERSION		"9"
hayeswang's avatar
hayeswang committed
36
37

#define DRIVER_VERSION		"v1." NETNEXT_VERSION "." NET_VERSION
hayeswang's avatar
hayeswang committed
38
#define DRIVER_AUTHOR "Realtek linux nic maintainers <nic_swsd@realtek.com>"
hayeswang's avatar
hayeswang committed
39
#define DRIVER_DESC "Realtek RTL8152/RTL8153 Based USB Ethernet Adapters"
hayeswang's avatar
hayeswang committed
40
41
42
43
44
45
46
47
48
49
#define MODULENAME "r8152"

#define R8152_PHY_ID		32

#define PLA_IDR			0xc000
#define PLA_RCR			0xc010
#define PLA_RMS			0xc016
#define PLA_RXFIFO_CTRL0	0xc0a0
#define PLA_RXFIFO_CTRL1	0xc0a4
#define PLA_RXFIFO_CTRL2	0xc0a8
hayeswang's avatar
hayeswang committed
50
#define PLA_DMY_REG0		0xc0b0
hayeswang's avatar
hayeswang committed
51
52
#define PLA_FMC			0xc0b4
#define PLA_CFG_WOL		0xc0b6
hayeswang's avatar
hayeswang committed
53
#define PLA_TEREDO_CFG		0xc0bc
hayeswang's avatar
hayeswang committed
54
#define PLA_TEREDO_WAKE_BASE	0xc0c4
hayeswang's avatar
hayeswang committed
55
#define PLA_MAR			0xcd00
hayeswang's avatar
hayeswang committed
56
#define PLA_BACKUP		0xd000
hayeswang's avatar
hayeswang committed
57
#define PAL_BDC_CR		0xd1a0
hayeswang's avatar
hayeswang committed
58
59
#define PLA_TEREDO_TIMER	0xd2cc
#define PLA_REALWOW_TIMER	0xd2e8
hayeswang's avatar
hayeswang committed
60
61
#define PLA_EFUSE_DATA		0xdd00
#define PLA_EFUSE_CMD		0xdd02
hayeswang's avatar
hayeswang committed
62
63
64
#define PLA_LEDSEL		0xdd90
#define PLA_LED_FEATURE		0xdd92
#define PLA_PHYAR		0xde00
hayeswang's avatar
hayeswang committed
65
#define PLA_BOOT_CTRL		0xe004
hayeswang's avatar
hayeswang committed
66
67
68
69
#define PLA_GPHY_INTR_IMR	0xe022
#define PLA_EEE_CR		0xe040
#define PLA_EEEP_CR		0xe080
#define PLA_MAC_PWR_CTRL	0xe0c0
hayeswang's avatar
hayeswang committed
70
71
72
73
#define PLA_MAC_PWR_CTRL2	0xe0ca
#define PLA_MAC_PWR_CTRL3	0xe0cc
#define PLA_MAC_PWR_CTRL4	0xe0ce
#define PLA_WDT6_CTRL		0xe428
hayeswang's avatar
hayeswang committed
74
75
#define PLA_TCR0		0xe610
#define PLA_TCR1		0xe612
76
#define PLA_MTPS		0xe615
hayeswang's avatar
hayeswang committed
77
#define PLA_TXFIFO_CTRL		0xe618
78
#define PLA_RSTTALLY		0xe800
hayeswang's avatar
hayeswang committed
79
80
#define PLA_CR			0xe813
#define PLA_CRWECR		0xe81c
hayeswang's avatar
hayeswang committed
81
82
#define PLA_CONFIG12		0xe81e	/* CONFIG1, CONFIG2 */
#define PLA_CONFIG34		0xe820	/* CONFIG3, CONFIG4 */
hayeswang's avatar
hayeswang committed
83
84
85
86
87
88
89
#define PLA_CONFIG5		0xe822
#define PLA_PHY_PWR		0xe84c
#define PLA_OOB_CTRL		0xe84f
#define PLA_CPCR		0xe854
#define PLA_MISC_0		0xe858
#define PLA_MISC_1		0xe85a
#define PLA_OCP_GPHY_BASE	0xe86c
90
#define PLA_TALLYCNT		0xe890
hayeswang's avatar
hayeswang committed
91
92
93
94
95
96
97
98
99
100
101
#define PLA_SFF_STS_7		0xe8de
#define PLA_PHYSTATUS		0xe908
#define PLA_BP_BA		0xfc26
#define PLA_BP_0		0xfc28
#define PLA_BP_1		0xfc2a
#define PLA_BP_2		0xfc2c
#define PLA_BP_3		0xfc2e
#define PLA_BP_4		0xfc30
#define PLA_BP_5		0xfc32
#define PLA_BP_6		0xfc34
#define PLA_BP_7		0xfc36
hayeswang's avatar
hayeswang committed
102
#define PLA_BP_EN		0xfc38
hayeswang's avatar
hayeswang committed
103

hayeswang's avatar
hayeswang committed
104
105
#define USB_USB2PHY		0xb41e
#define USB_SSPHYLINK2		0xb428
hayeswang's avatar
hayeswang committed
106
#define USB_U2P3_CTRL		0xb460
hayeswang's avatar
hayeswang committed
107
108
#define USB_CSR_DUMMY1		0xb464
#define USB_CSR_DUMMY2		0xb466
hayeswang's avatar
hayeswang committed
109
#define USB_DEV_STAT		0xb808
hayeswang's avatar
hayeswang committed
110
#define USB_CONNECT_TIMER	0xcbf8
hayeswang's avatar
hayeswang committed
111
#define USB_MSC_TIMER		0xcbfc
hayeswang's avatar
hayeswang committed
112
#define USB_BURST_SIZE		0xcfc0
hayeswang's avatar
hayeswang committed
113
#define USB_LPM_CONFIG		0xcfd8
hayeswang's avatar
hayeswang committed
114
115
116
117
118
#define USB_USB_CTRL		0xd406
#define USB_PHY_CTRL		0xd408
#define USB_TX_AGG		0xd40a
#define USB_RX_BUF_TH		0xd40c
#define USB_USB_TIMER		0xd428
hayeswang's avatar
hayeswang committed
119
120
#define USB_RX_EARLY_TIMEOUT	0xd42c
#define USB_RX_EARLY_SIZE	0xd42e
hayeswang's avatar
hayeswang committed
121
122
#define USB_PM_CTRL_STATUS	0xd432	/* RTL8153A */
#define USB_RX_EXTRA_AGGR_TMR	0xd432	/* RTL8153B */
hayeswang's avatar
hayeswang committed
123
#define USB_TX_DMA		0xd434
hayeswang's avatar
hayeswang committed
124
#define USB_UPT_RXDMA_OWN	0xd437
hayeswang's avatar
hayeswang committed
125
126
#define USB_TOLERANCE		0xd490
#define USB_LPM_CTRL		0xd41a
hayeswang's avatar
hayeswang committed
127
#define USB_BMU_RESET		0xd4b0
hayeswang's avatar
hayeswang committed
128
#define USB_U1U2_TIMER		0xd4da
hayeswang's avatar
hayeswang committed
129
#define USB_UPS_CTRL		0xd800
hayeswang's avatar
hayeswang committed
130
#define USB_POWER_CUT		0xd80a
hayeswang's avatar
hayeswang committed
131
#define USB_MISC_0		0xd81a
hayeswang's avatar
hayeswang committed
132
#define USB_AFE_CTRL2		0xd824
hayeswang's avatar
hayeswang committed
133
134
#define USB_UPS_CFG		0xd842
#define USB_UPS_FLAGS		0xd848
hayeswang's avatar
hayeswang committed
135
#define USB_WDT11_CTRL		0xe43c
hayeswang's avatar
hayeswang committed
136
137
138
139
140
141
142
143
144
#define USB_BP_BA		0xfc26
#define USB_BP_0		0xfc28
#define USB_BP_1		0xfc2a
#define USB_BP_2		0xfc2c
#define USB_BP_3		0xfc2e
#define USB_BP_4		0xfc30
#define USB_BP_5		0xfc32
#define USB_BP_6		0xfc34
#define USB_BP_7		0xfc36
hayeswang's avatar
hayeswang committed
145
#define USB_BP_EN		0xfc38
hayeswang's avatar
hayeswang committed
146
147
148
149
150
151
152
153
154
#define USB_BP_8		0xfc38
#define USB_BP_9		0xfc3a
#define USB_BP_10		0xfc3c
#define USB_BP_11		0xfc3e
#define USB_BP_12		0xfc40
#define USB_BP_13		0xfc42
#define USB_BP_14		0xfc44
#define USB_BP_15		0xfc46
#define USB_BP2_EN		0xfc48
hayeswang's avatar
hayeswang committed
155
156
157
158
159
160

/* OCP Registers */
#define OCP_ALDPS_CONFIG	0x2010
#define OCP_EEE_CONFIG1		0x2080
#define OCP_EEE_CONFIG2		0x2092
#define OCP_EEE_CONFIG3		0x2094
161
#define OCP_BASE_MII		0xa400
hayeswang's avatar
hayeswang committed
162
163
#define OCP_EEE_AR		0xa41a
#define OCP_EEE_DATA		0xa41c
hayeswang's avatar
hayeswang committed
164
#define OCP_PHY_STATUS		0xa420
hayeswang's avatar
hayeswang committed
165
#define OCP_NCTL_CFG		0xa42c
hayeswang's avatar
hayeswang committed
166
167
168
169
170
#define OCP_POWER_CFG		0xa430
#define OCP_EEE_CFG		0xa432
#define OCP_SRAM_ADDR		0xa436
#define OCP_SRAM_DATA		0xa438
#define OCP_DOWN_SPEED		0xa442
hayeswang's avatar
hayeswang committed
171
#define OCP_EEE_ABLE		0xa5c4
hayeswang's avatar
hayeswang committed
172
#define OCP_EEE_ADV		0xa5d0
hayeswang's avatar
hayeswang committed
173
#define OCP_EEE_LPABLE		0xa5d2
174
#define OCP_PHY_STATE		0xa708		/* nway state for 8153 */
hayeswang's avatar
hayeswang committed
175
176
177
#define OCP_PHY_PATCH_STAT	0xb800
#define OCP_PHY_PATCH_CMD	0xb820
#define OCP_ADC_IOFFSET		0xbcfc
hayeswang's avatar
hayeswang committed
178
#define OCP_ADC_CFG		0xbc06
hayeswang's avatar
hayeswang committed
179
#define OCP_SYSCLK_CFG		0xc416
hayeswang's avatar
hayeswang committed
180
181

/* SRAM Register */
hayeswang's avatar
hayeswang committed
182
#define SRAM_GREEN_CFG		0x8011
hayeswang's avatar
hayeswang committed
183
184
185
186
#define SRAM_LPF_CFG		0x8012
#define SRAM_10M_AMP1		0x8080
#define SRAM_10M_AMP2		0x8082
#define SRAM_IMPEDANCE		0x8084
hayeswang's avatar
hayeswang committed
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202

/* PLA_RCR */
#define RCR_AAP			0x00000001
#define RCR_APM			0x00000002
#define RCR_AM			0x00000004
#define RCR_AB			0x00000008
#define RCR_ACPT_ALL		(RCR_AAP | RCR_APM | RCR_AM | RCR_AB)

/* PLA_RXFIFO_CTRL0 */
#define RXFIFO_THR1_NORMAL	0x00080002
#define RXFIFO_THR1_OOB		0x01800003

/* PLA_RXFIFO_CTRL1 */
#define RXFIFO_THR2_FULL	0x00000060
#define RXFIFO_THR2_HIGH	0x00000038
#define RXFIFO_THR2_OOB		0x0000004a
hayeswang's avatar
hayeswang committed
203
#define RXFIFO_THR2_NORMAL	0x00a0
hayeswang's avatar
hayeswang committed
204
205
206
207
208

/* PLA_RXFIFO_CTRL2 */
#define RXFIFO_THR3_FULL	0x00000078
#define RXFIFO_THR3_HIGH	0x00000048
#define RXFIFO_THR3_OOB		0x0000005a
hayeswang's avatar
hayeswang committed
209
#define RXFIFO_THR3_NORMAL	0x0110
hayeswang's avatar
hayeswang committed
210
211
212

/* PLA_TXFIFO_CTRL */
#define TXFIFO_THR_NORMAL	0x00400008
hayeswang's avatar
hayeswang committed
213
#define TXFIFO_THR_NORMAL2	0x01000008
hayeswang's avatar
hayeswang committed
214

hayeswang's avatar
hayeswang committed
215
216
217
/* PLA_DMY_REG0 */
#define ECM_ALDPS		0x0002

hayeswang's avatar
hayeswang committed
218
219
220
221
222
223
/* PLA_FMC */
#define FMC_FCR_MCU_EN		0x0001

/* PLA_EEEP_CR */
#define EEEP_CR_EEEP_TX		0x0002

hayeswang's avatar
hayeswang committed
224
225
226
/* PLA_WDT6_CTRL */
#define WDT6_SET_MODE		0x0010

hayeswang's avatar
hayeswang committed
227
228
229
230
231
232
233
/* PLA_TCR0 */
#define TCR0_TX_EMPTY		0x0800
#define TCR0_AUTO_FIFO		0x0080

/* PLA_TCR1 */
#define VERSION_MASK		0x7cf0

234
235
236
237
/* PLA_MTPS */
#define MTPS_JUMBO		(12 * 1024 / 64)
#define MTPS_DEFAULT		(6 * 1024 / 64)

238
239
240
/* PLA_RSTTALLY */
#define TALLY_RESET		0x0001

hayeswang's avatar
hayeswang committed
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
/* PLA_CR */
#define CR_RST			0x10
#define CR_RE			0x08
#define CR_TE			0x04

/* PLA_CRWECR */
#define CRWECR_NORAML		0x00
#define CRWECR_CONFIG		0xc0

/* PLA_OOB_CTRL */
#define NOW_IS_OOB		0x80
#define TXFIFO_EMPTY		0x20
#define RXFIFO_EMPTY		0x10
#define LINK_LIST_READY		0x02
#define DIS_MCU_CLROOB		0x01
#define FIFO_EMPTY		(TXFIFO_EMPTY | RXFIFO_EMPTY)

/* PLA_MISC_1 */
#define RXDY_GATED_EN		0x0008

/* PLA_SFF_STS_7 */
#define RE_INIT_LL		0x8000
#define MCU_BORW_EN		0x4000

/* PLA_CPCR */
#define CPCR_RX_VLAN		0x0040

/* PLA_CFG_WOL */
#define MAGIC_EN		0x0001

hayeswang's avatar
hayeswang committed
271
272
273
274
275
276
/* PLA_TEREDO_CFG */
#define TEREDO_SEL		0x8000
#define TEREDO_WAKE_MASK	0x7f00
#define TEREDO_RS_EVENT_MASK	0x00fe
#define OOB_TEREDO_EN		0x0001

hayeswang's avatar
hayeswang committed
277
278
279
/* PAL_BDC_CR */
#define ALDPS_PROXY_MODE	0x0001

hayeswang's avatar
hayeswang committed
280
281
282
283
/* PLA_EFUSE_CMD */
#define EFUSE_READ_CMD		BIT(15)
#define EFUSE_DATA_BIT16	BIT(7)

hayeswang's avatar
hayeswang committed
284
285
286
287
/* PLA_CONFIG34 */
#define LINK_ON_WAKE_EN		0x0010
#define LINK_OFF_WAKE_EN	0x0008

hayeswang's avatar
hayeswang committed
288
/* PLA_CONFIG5 */
hayeswang's avatar
hayeswang committed
289
290
291
#define BWF_EN			0x0040
#define MWF_EN			0x0020
#define UWF_EN			0x0010
hayeswang's avatar
hayeswang committed
292
293
294
295
296
297
298
299
300
301
302
303
304
#define LAN_WAKE_EN		0x0002

/* PLA_LED_FEATURE */
#define LED_MODE_MASK		0x0700

/* PLA_PHY_PWR */
#define TX_10M_IDLE_EN		0x0080
#define PFM_PWM_SWITCH		0x0040

/* PLA_MAC_PWR_CTRL */
#define D3_CLK_GATED_EN		0x00004000
#define MCU_CLK_RATIO		0x07010f07
#define MCU_CLK_RATIO_MASK	0x0f0f0f0f
hayeswang's avatar
hayeswang committed
305
306
307
308
#define ALDPS_SPDWN_RATIO	0x0f87

/* PLA_MAC_PWR_CTRL2 */
#define EEE_SPDWN_RATIO		0x8007
hayeswang's avatar
hayeswang committed
309
#define MAC_CLK_SPDWN_EN	BIT(15)
hayeswang's avatar
hayeswang committed
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324

/* PLA_MAC_PWR_CTRL3 */
#define PKT_AVAIL_SPDWN_EN	0x0100
#define SUSPEND_SPDWN_EN	0x0004
#define U1U2_SPDWN_EN		0x0002
#define L1_SPDWN_EN		0x0001

/* PLA_MAC_PWR_CTRL4 */
#define PWRSAVE_SPDWN_EN	0x1000
#define RXDV_SPDWN_EN		0x0800
#define TX10MIDLE_EN		0x0100
#define TP100_SPDWN_EN		0x0020
#define TP500_SPDWN_EN		0x0010
#define TP1000_SPDWN_EN		0x0008
#define EEE_SPDWN_EN		0x0001
hayeswang's avatar
hayeswang committed
325
326
327
328
329
330
331
332
333
334
335
336
337
338

/* PLA_GPHY_INTR_IMR */
#define GPHY_STS_MSK		0x0001
#define SPEED_DOWN_MSK		0x0002
#define SPDWN_RXDV_MSK		0x0004
#define SPDWN_LINKCHG_MSK	0x0008

/* PLA_PHYAR */
#define PHYAR_FLAG		0x80000000

/* PLA_EEE_CR */
#define EEE_RX_EN		0x0001
#define EEE_TX_EN		0x0002

hayeswang's avatar
hayeswang committed
339
340
341
/* PLA_BOOT_CTRL */
#define AUTOLOAD_DONE		0x0002

hayeswang's avatar
hayeswang committed
342
343
344
345
346
347
348
349
350
351
352
353
354
355
/* USB_USB2PHY */
#define USB2PHY_SUSPEND		0x0001
#define USB2PHY_L1		0x0002

/* USB_SSPHYLINK2 */
#define pwd_dn_scale_mask	0x3ffe
#define pwd_dn_scale(x)		((x) << 1)

/* USB_CSR_DUMMY1 */
#define DYNAMIC_BURST		0x0001

/* USB_CSR_DUMMY2 */
#define EP4_FULL_FC		0x0001

hayeswang's avatar
hayeswang committed
356
357
358
/* USB_DEV_STAT */
#define STAT_SPEED_MASK		0x0006
#define STAT_SPEED_HIGH		0x0000
359
#define STAT_SPEED_FULL		0x0002
hayeswang's avatar
hayeswang committed
360

hayeswang's avatar
hayeswang committed
361
362
363
/* USB_LPM_CONFIG */
#define LPM_U1U2_EN		BIT(0)

hayeswang's avatar
hayeswang committed
364
365
366
367
/* USB_TX_AGG */
#define TX_AGG_MAX_THRESHOLD	0x03

/* USB_RX_BUF_TH */
hayeswang's avatar
hayeswang committed
368
#define RX_THR_SUPPER		0x0c350180
hayeswang's avatar
hayeswang committed
369
#define RX_THR_HIGH		0x7a120180
hayeswang's avatar
hayeswang committed
370
#define RX_THR_SLOW		0xffff0180
hayeswang's avatar
hayeswang committed
371
#define RX_THR_B		0x00010001
hayeswang's avatar
hayeswang committed
372
373
374
375
376

/* USB_TX_DMA */
#define TEST_MODE_DISABLE	0x00000001
#define TX_SIZE_ADJUST1		0x00000100

hayeswang's avatar
hayeswang committed
377
378
379
380
/* USB_BMU_RESET */
#define BMU_RESET_EP_IN		0x01
#define BMU_RESET_EP_OUT	0x02

hayeswang's avatar
hayeswang committed
381
382
383
384
/* USB_UPT_RXDMA_OWN */
#define OWN_UPDATE		BIT(0)
#define OWN_CLEAR		BIT(1)

hayeswang's avatar
hayeswang committed
385
386
387
388
/* USB_UPS_CTRL */
#define POWER_CUT		0x0100

/* USB_PM_CTRL_STATUS */
hayeswang's avatar
hayeswang committed
389
#define RESUME_INDICATE		0x0001
hayeswang's avatar
hayeswang committed
390
391
392

/* USB_USB_CTRL */
#define RX_AGG_DISABLE		0x0010
393
#define RX_ZERO_EN		0x0080
hayeswang's avatar
hayeswang committed
394

hayeswang's avatar
hayeswang committed
395
396
397
398
399
400
/* USB_U2P3_CTRL */
#define U2P3_ENABLE		0x0001

/* USB_POWER_CUT */
#define PWR_EN			0x0001
#define PHASE2_EN		0x0008
hayeswang's avatar
hayeswang committed
401
402
#define UPS_EN			BIT(4)
#define USP_PREWAKE		BIT(5)
hayeswang's avatar
hayeswang committed
403
404
405
406

/* USB_MISC_0 */
#define PCUT_STATUS		0x0001

hayeswang's avatar
hayeswang committed
407
408
409
410
/* USB_RX_EARLY_TIMEOUT */
#define COALESCE_SUPER		 85000U
#define COALESCE_HIGH		250000U
#define COALESCE_SLOW		524280U
hayeswang's avatar
hayeswang committed
411
412
413
414
415

/* USB_WDT11_CTRL */
#define TIMER11_EN		0x0001

/* USB_LPM_CTRL */
hayeswang's avatar
hayeswang committed
416
417
418
/* bit 4 ~ 5: fifo empty boundary */
#define FIFO_EMPTY_1FB		0x30	/* 0x1fb * 64 = 32448 bytes */
/* bit 2 ~ 3: LMP timer */
hayeswang's avatar
hayeswang committed
419
420
421
#define LPM_TIMER_MASK		0x0c
#define LPM_TIMER_500MS		0x04	/* 500 ms */
#define LPM_TIMER_500US		0x0c	/* 500 us */
hayeswang's avatar
hayeswang committed
422
#define ROK_EXIT_LPM		0x02
hayeswang's avatar
hayeswang committed
423
424
425
426
427
428

/* USB_AFE_CTRL2 */
#define SEN_VAL_MASK		0xf800
#define SEN_VAL_NORMAL		0xa000
#define SEL_RXIDLE		0x0100

hayeswang's avatar
hayeswang committed
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
/* USB_UPS_CFG */
#define SAW_CNT_1MS_MASK	0x0fff

/* USB_UPS_FLAGS */
#define UPS_FLAGS_R_TUNE		BIT(0)
#define UPS_FLAGS_EN_10M_CKDIV		BIT(1)
#define UPS_FLAGS_250M_CKDIV		BIT(2)
#define UPS_FLAGS_EN_ALDPS		BIT(3)
#define UPS_FLAGS_CTAP_SHORT_DIS	BIT(4)
#define UPS_FLAGS_SPEED_MASK		(0xf << 16)
#define ups_flags_speed(x)		((x) << 16)
#define UPS_FLAGS_EN_EEE		BIT(20)
#define UPS_FLAGS_EN_500M_EEE		BIT(21)
#define UPS_FLAGS_EN_EEE_CKDIV		BIT(22)
#define UPS_FLAGS_EEE_PLLOFF_GIGA	BIT(24)
#define UPS_FLAGS_EEE_CMOD_LV_EN	BIT(25)
#define UPS_FLAGS_EN_GREEN		BIT(26)
#define UPS_FLAGS_EN_FLOW_CTR		BIT(27)

enum spd_duplex {
	NWAY_10M_HALF = 1,
	NWAY_10M_FULL,
	NWAY_100M_HALF,
	NWAY_100M_FULL,
	NWAY_1000M_FULL,
	FORCE_10M_HALF,
	FORCE_10M_FULL,
	FORCE_100M_HALF,
	FORCE_100M_FULL,
};

hayeswang's avatar
hayeswang committed
460
461
462
463
464
465
/* OCP_ALDPS_CONFIG */
#define ENPWRSAVE		0x8000
#define ENPDNPS			0x0200
#define LINKENA			0x0100
#define DIS_SDSAVE		0x0010

hayeswang's avatar
hayeswang committed
466
467
/* OCP_PHY_STATUS */
#define PHY_STAT_MASK		0x0007
468
#define PHY_STAT_EXT_INIT	2
hayeswang's avatar
hayeswang committed
469
470
471
#define PHY_STAT_LAN_ON		3
#define PHY_STAT_PWRDN		5

hayeswang's avatar
hayeswang committed
472
473
474
/* OCP_NCTL_CFG */
#define PGA_RETURN_EN		BIT(1)

hayeswang's avatar
hayeswang committed
475
476
477
478
479
/* OCP_POWER_CFG */
#define EEE_CLKDIV_EN		0x8000
#define EN_ALDPS		0x0004
#define EN_10M_PLLOFF		0x0001

hayeswang's avatar
hayeswang committed
480
481
482
483
484
485
486
/* OCP_EEE_CONFIG1 */
#define RG_TXLPI_MSK_HFDUP	0x8000
#define RG_MATCLR_EN		0x4000
#define EEE_10_CAP		0x2000
#define EEE_NWAY_EN		0x1000
#define TX_QUIET_EN		0x0200
#define RX_QUIET_EN		0x0100
hayeswang's avatar
hayeswang committed
487
#define sd_rise_time_mask	0x0070
hayeswang's avatar
hayeswang committed
488
#define sd_rise_time(x)		(min(x, 7) << 4)	/* bit 4 ~ 6 */
hayeswang's avatar
hayeswang committed
489
490
491
492
493
494
495
496
497
498
499
#define RG_RXLPI_MSK_HFDUP	0x0008
#define SDFALLTIME		0x0007	/* bit 0 ~ 2 */

/* OCP_EEE_CONFIG2 */
#define RG_LPIHYS_NUM		0x7000	/* bit 12 ~ 15 */
#define RG_DACQUIET_EN		0x0400
#define RG_LDVQUIET_EN		0x0200
#define RG_CKRSEL		0x0020
#define RG_EEEPRG_EN		0x0010

/* OCP_EEE_CONFIG3 */
hayeswang's avatar
hayeswang committed
500
#define fast_snr_mask		0xff80
hayeswang's avatar
hayeswang committed
501
#define fast_snr(x)		(min(x, 0x1ff) << 7)	/* bit 7 ~ 15 */
hayeswang's avatar
hayeswang committed
502
503
504
505
506
507
508
509
510
#define RG_LFS_SEL		0x0060	/* bit 6 ~ 5 */
#define MSK_PH			0x0006	/* bit 0 ~ 3 */

/* OCP_EEE_AR */
/* bit[15:14] function */
#define FUN_ADDR		0x0000
#define FUN_DATA		0x4000
/* bit[4:0] device addr */

hayeswang's avatar
hayeswang committed
511
512
513
514
515
/* OCP_EEE_CFG */
#define CTAP_SHORT_EN		0x0040
#define EEE10_EN		0x0010

/* OCP_DOWN_SPEED */
hayeswang's avatar
hayeswang committed
516
517
518
519
#define EN_EEE_CMODE		BIT(14)
#define EN_EEE_1000		BIT(13)
#define EN_EEE_100		BIT(12)
#define EN_10M_CLKDIV		BIT(11)
hayeswang's avatar
hayeswang committed
520
521
#define EN_10M_BGOFF		0x0080

522
523
524
525
/* OCP_PHY_STATE */
#define TXDIS_STATE		0x01
#define ABD_STATE		0x02

hayeswang's avatar
hayeswang committed
526
527
528
529
530
531
/* OCP_PHY_PATCH_STAT */
#define PATCH_READY		BIT(6)

/* OCP_PHY_PATCH_CMD */
#define PATCH_REQUEST		BIT(4)

hayeswang's avatar
hayeswang committed
532
533
534
535
536
/* OCP_ADC_CFG */
#define CKADSEL_L		0x0100
#define ADC_EN			0x0080
#define EN_EMI_L		0x0040

hayeswang's avatar
hayeswang committed
537
538
539
540
541
542
543
/* OCP_SYSCLK_CFG */
#define clk_div_expo(x)		(min(x, 5) << 8)

/* SRAM_GREEN_CFG */
#define GREEN_ETH_EN		BIT(15)
#define R_TUNE_EN		BIT(11)

hayeswang's avatar
hayeswang committed
544
545
546
547
548
549
550
551
552
553
554
555
/* SRAM_LPF_CFG */
#define LPF_AUTO_TUNE		0x8000

/* SRAM_10M_AMP1 */
#define GDAC_IB_UPALL		0x0008

/* SRAM_10M_AMP2 */
#define AMP_DN			0x0200

/* SRAM_IMPEDANCE */
#define RX_DRIVING_MASK		0x6000

556
557
558
559
560
/* MAC PASSTHRU */
#define AD_MASK			0xfee0
#define EFUSE			0xcfdb
#define PASS_THRU_MASK		0x1

hayeswang's avatar
hayeswang committed
561
enum rtl_register_content {
hayeswang's avatar
hayeswang committed
562
	_1000bps	= 0x10,
hayeswang's avatar
hayeswang committed
563
564
565
566
567
568
	_100bps		= 0x08,
	_10bps		= 0x04,
	LINK_STATUS	= 0x02,
	FULL_DUP	= 0x01,
};

hayeswang's avatar
hayeswang committed
569
#define RTL8152_MAX_TX		4
hayeswang's avatar
hayeswang committed
570
#define RTL8152_MAX_RX		10
571
#define INTBUFSIZE		2
hayeswang's avatar
hayeswang committed
572
573
#define TX_ALIGN		4
#define RX_ALIGN		8
574
575

#define INTR_LINK		0x0004
hayeswang's avatar
hayeswang committed
576

hayeswang's avatar
hayeswang committed
577
578
579
580
581
582
583
584
585
586
587
588
#define RTL8152_REQT_READ	0xc0
#define RTL8152_REQT_WRITE	0x40
#define RTL8152_REQ_GET_REGS	0x05
#define RTL8152_REQ_SET_REGS	0x05

#define BYTE_EN_DWORD		0xff
#define BYTE_EN_WORD		0x33
#define BYTE_EN_BYTE		0x11
#define BYTE_EN_SIX_BYTES	0x3f
#define BYTE_EN_START_MASK	0x0f
#define BYTE_EN_END_MASK	0xf0

589
#define RTL8153_MAX_PACKET	9216 /* 9K */
hayeswang's avatar
hayeswang committed
590
591
592
#define RTL8153_MAX_MTU		(RTL8153_MAX_PACKET - VLAN_ETH_HLEN - \
				 ETH_FCS_LEN)
#define RTL8152_RMS		(VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
593
#define RTL8153_RMS		RTL8153_MAX_PACKET
hayeswang's avatar
hayeswang committed
594
#define RTL8152_TX_TIMEOUT	(5 * HZ)
hayeswang's avatar
hayeswang committed
595
#define RTL8152_NAPI_WEIGHT	64
hayeswang's avatar
hayeswang committed
596
#define rx_reserved_size(x)	((x) + VLAN_ETH_HLEN + ETH_FCS_LEN + \
597
				 sizeof(struct rx_desc) + RX_ALIGN)
hayeswang's avatar
hayeswang committed
598
599
600
601
602

/* rtl8152 flags */
enum rtl8152_flags {
	RTL8152_UNPLUG = 0,
	RTL8152_SET_RX_MODE,
603
604
	WORK_ENABLE,
	RTL8152_LINK_CHG,
hayeswang's avatar
hayeswang committed
605
	SELECTIVE_SUSPEND,
606
	PHY_RESET,
hayeswang's avatar
hayeswang committed
607
	SCHEDULE_NAPI,
hayeswang's avatar
hayeswang committed
608
	GREEN_ETHERNET,
609
	DELL_TB_RX_AGG_BUG,
hayeswang's avatar
hayeswang committed
610
611
612
613
};

/* Define these values to match your device */
#define VENDOR_ID_REALTEK		0x0bda
614
#define VENDOR_ID_MICROSOFT		0x045e
hayeswang's avatar
hayeswang committed
615
#define VENDOR_ID_SAMSUNG		0x04e8
616
#define VENDOR_ID_LENOVO		0x17ef
617
#define VENDOR_ID_LINKSYS		0x13b1
618
#define VENDOR_ID_NVIDIA		0x0955
619
#define VENDOR_ID_TPLINK		0x2357
hayeswang's avatar
hayeswang committed
620
621
622
623

#define MCU_TYPE_PLA			0x0100
#define MCU_TYPE_USB			0x0000

624
625
626
627
628
629
630
631
632
633
634
635
636
struct tally_counter {
	__le64	tx_packets;
	__le64	rx_packets;
	__le64	tx_errors;
	__le32	rx_errors;
	__le16	rx_missed;
	__le16	align_errors;
	__le32	tx_one_collision;
	__le32	tx_multi_collision;
	__le64	rx_unicast;
	__le64	rx_broadcast;
	__le32	rx_multicast;
	__le16	tx_aborted;
hayeswang's avatar
hayeswang committed
637
	__le16	tx_underrun;
638
639
};

hayeswang's avatar
hayeswang committed
640
struct rx_desc {
641
	__le32 opts1;
hayeswang's avatar
hayeswang committed
642
#define RX_LEN_MASK			0x7fff
hayeswang's avatar
hayeswang committed
643

644
	__le32 opts2;
hayeswang's avatar
hayeswang committed
645
646
647
648
#define RD_UDP_CS			BIT(23)
#define RD_TCP_CS			BIT(22)
#define RD_IPV6_CS			BIT(20)
#define RD_IPV4_CS			BIT(19)
hayeswang's avatar
hayeswang committed
649

650
	__le32 opts3;
hayeswang's avatar
hayeswang committed
651
652
653
654
#define IPF				BIT(23) /* IP checksum fail */
#define UDPF				BIT(22) /* UDP checksum fail */
#define TCPF				BIT(21) /* TCP checksum fail */
#define RX_VLAN_TAG			BIT(16)
hayeswang's avatar
hayeswang committed
655

656
657
658
	__le32 opts4;
	__le32 opts5;
	__le32 opts6;
hayeswang's avatar
hayeswang committed
659
660
661
};

struct tx_desc {
662
	__le32 opts1;
hayeswang's avatar
hayeswang committed
663
664
665
666
#define TX_FS			BIT(31) /* First segment of a packet */
#define TX_LS			BIT(30) /* Final segment of a packet */
#define GTSENDV4		BIT(28)
#define GTSENDV6		BIT(27)
hayeswang's avatar
hayeswang committed
667
#define GTTCPHO_SHIFT		18
hayeswang's avatar
hayeswang committed
668
#define GTTCPHO_MAX		0x7fU
hayeswang's avatar
hayeswang committed
669
#define TX_LEN_MAX		0x3ffffU
hayeswang's avatar
hayeswang committed
670

671
	__le32 opts2;
hayeswang's avatar
hayeswang committed
672
673
674
675
#define UDP_CS			BIT(31) /* Calculate UDP/IP checksum */
#define TCP_CS			BIT(30) /* Calculate TCP/IP checksum */
#define IPV4_CS			BIT(29) /* Calculate IPv4 checksum */
#define IPV6_CS			BIT(28) /* Calculate IPv6 checksum */
hayeswang's avatar
hayeswang committed
676
677
678
#define MSS_SHIFT		17
#define MSS_MAX			0x7ffU
#define TCPHO_SHIFT		17
hayeswang's avatar
hayeswang committed
679
#define TCPHO_MAX		0x7ffU
hayeswang's avatar
hayeswang committed
680
#define TX_VLAN_TAG		BIT(16)
hayeswang's avatar
hayeswang committed
681
682
};

683
684
struct r8152;

hayeswang's avatar
hayeswang committed
685
686
687
struct rx_agg {
	struct list_head list;
	struct urb *urb;
688
	struct r8152 *context;
hayeswang's avatar
hayeswang committed
689
690
691
692
693
694
695
	void *buffer;
	void *head;
};

struct tx_agg {
	struct list_head list;
	struct urb *urb;
696
	struct r8152 *context;
hayeswang's avatar
hayeswang committed
697
698
699
700
701
702
	void *buffer;
	void *head;
	u32 skb_num;
	u32 skb_len;
};

hayeswang's avatar
hayeswang committed
703
704
705
struct r8152 {
	unsigned long flags;
	struct usb_device *udev;
hayeswang's avatar
hayeswang committed
706
	struct napi_struct napi;
707
	struct usb_interface *intf;
hayeswang's avatar
hayeswang committed
708
	struct net_device *netdev;
709
	struct urb *intr_urb;
hayeswang's avatar
hayeswang committed
710
711
712
	struct tx_agg tx_info[RTL8152_MAX_TX];
	struct rx_agg rx_info[RTL8152_MAX_RX];
	struct list_head rx_done, tx_free;
hayeswang's avatar
hayeswang committed
713
	struct sk_buff_head tx_queue, rx_queue;
hayeswang's avatar
hayeswang committed
714
	spinlock_t rx_lock, tx_lock;
715
	struct delayed_work schedule, hw_phy_work;
hayeswang's avatar
hayeswang committed
716
	struct mii_if_info mii;
hayeswang's avatar
hayeswang committed
717
	struct mutex control;	/* use for hw setting */
hayeswang's avatar
hayeswang committed
718
719
720
#ifdef CONFIG_PM_SLEEP
	struct notifier_block pm_notifier;
#endif
hayeswang's avatar
hayeswang committed
721
722
723
724
725

	struct rtl_ops {
		void (*init)(struct r8152 *);
		int (*enable)(struct r8152 *);
		void (*disable)(struct r8152 *);
726
		void (*up)(struct r8152 *);
hayeswang's avatar
hayeswang committed
727
728
		void (*down)(struct r8152 *);
		void (*unload)(struct r8152 *);
hayeswang's avatar
hayeswang committed
729
730
		int (*eee_get)(struct r8152 *, struct ethtool_eee *);
		int (*eee_set)(struct r8152 *, struct ethtool_eee *);
731
		bool (*in_nway)(struct r8152 *);
732
		void (*hw_phy_cfg)(struct r8152 *);
733
		void (*autosuspend_en)(struct r8152 *tp, bool enable);
hayeswang's avatar
hayeswang committed
734
735
	} rtl_ops;

736
	int intr_interval;
hayeswang's avatar
hayeswang committed
737
	u32 saved_wolopts;
hayeswang's avatar
hayeswang committed
738
	u32 msg_enable;
739
	u32 tx_qlen;
hayeswang's avatar
hayeswang committed
740
	u32 coalesce;
hayeswang's avatar
hayeswang committed
741
	u16 ocp_base;
hayeswang's avatar
hayeswang committed
742
	u16 speed;
743
	u8 *intr_buff;
hayeswang's avatar
hayeswang committed
744
	u8 version;
hayeswang's avatar
hayeswang committed
745
746
	u8 duplex;
	u8 autoneg;
hayeswang's avatar
hayeswang committed
747
748
749
750
751
};

enum rtl_version {
	RTL_VER_UNKNOWN = 0,
	RTL_VER_01,
hayeswang's avatar
hayeswang committed
752
753
754
755
	RTL_VER_02,
	RTL_VER_03,
	RTL_VER_04,
	RTL_VER_05,
756
	RTL_VER_06,
hayeswang's avatar
hayeswang committed
757
	RTL_VER_07,
hayeswang's avatar
hayeswang committed
758
759
	RTL_VER_08,
	RTL_VER_09,
hayeswang's avatar
hayeswang committed
760
	RTL_VER_MAX
hayeswang's avatar
hayeswang committed
761
762
};

hayeswang's avatar
hayeswang committed
763
764
765
766
767
768
enum tx_csum_stat {
	TX_CSUM_SUCCESS = 0,
	TX_CSUM_TSO,
	TX_CSUM_NONE
};

hayeswang's avatar
hayeswang committed
769
770
771
772
/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
 * The RTL chips use a 64 element hash table based on the Ethernet CRC.
 */
static const int multicast_filter_limit = 32;
hayeswang's avatar
hayeswang committed
773
static unsigned int agg_buf_sz = 16384;
hayeswang's avatar
hayeswang committed
774

hayeswang's avatar
hayeswang committed
775
#define RTL_LIMITED_TSO_SIZE	(agg_buf_sz - sizeof(struct tx_desc) - \
hayeswang's avatar
hayeswang committed
776
				 VLAN_ETH_HLEN - ETH_FCS_LEN)
hayeswang's avatar
hayeswang committed
777

hayeswang's avatar
hayeswang committed
778
779
780
static
int get_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
{
781
782
783
784
785
786
787
788
	int ret;
	void *tmp;

	tmp = kmalloc(size, GFP_KERNEL);
	if (!tmp)
		return -ENOMEM;

	ret = usb_control_msg(tp->udev, usb_rcvctrlpipe(tp->udev, 0),
789
790
			      RTL8152_REQ_GET_REGS, RTL8152_REQT_READ,
			      value, index, tmp, size, 500);
791
792
793
794
795

	memcpy(data, tmp, size);
	kfree(tmp);

	return ret;
hayeswang's avatar
hayeswang committed
796
797
798
799
800
}

static
int set_registers(struct r8152 *tp, u16 value, u16 index, u16 size, void *data)
{
801
802
803
	int ret;
	void *tmp;

804
	tmp = kmemdup(data, size, GFP_KERNEL);
805
806
807
808
	if (!tmp)
		return -ENOMEM;

	ret = usb_control_msg(tp->udev, usb_sndctrlpipe(tp->udev, 0),
809
810
			      RTL8152_REQ_SET_REGS, RTL8152_REQT_WRITE,
			      value, index, tmp, size, 500);
811
812

	kfree(tmp);
813

814
	return ret;
hayeswang's avatar
hayeswang committed
815
816
817
}

static int generic_ocp_read(struct r8152 *tp, u16 index, u16 size,
818
			    void *data, u16 type)
hayeswang's avatar
hayeswang committed
819
{
820
821
	u16 limit = 64;
	int ret = 0;
hayeswang's avatar
hayeswang committed
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853

	if (test_bit(RTL8152_UNPLUG, &tp->flags))
		return -ENODEV;

	/* both size and indix must be 4 bytes align */
	if ((size & 3) || !size || (index & 3) || !data)
		return -EPERM;

	if ((u32)index + (u32)size > 0xffff)
		return -EPERM;

	while (size) {
		if (size > limit) {
			ret = get_registers(tp, index, type, limit, data);
			if (ret < 0)
				break;

			index += limit;
			data += limit;
			size -= limit;
		} else {
			ret = get_registers(tp, index, type, size, data);
			if (ret < 0)
				break;

			index += size;
			data += size;
			size = 0;
			break;
		}
	}

854
855
856
	if (ret == -ENODEV)
		set_bit(RTL8152_UNPLUG, &tp->flags);

hayeswang's avatar
hayeswang committed
857
858
859
860
	return ret;
}

static int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen,
861
			     u16 size, void *data, u16 type)
hayeswang's avatar
hayeswang committed
862
{
863
864
865
	int ret;
	u16 byteen_start, byteen_end, byen;
	u16 limit = 512;
hayeswang's avatar
hayeswang committed
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894

	if (test_bit(RTL8152_UNPLUG, &tp->flags))
		return -ENODEV;

	/* both size and indix must be 4 bytes align */
	if ((size & 3) || !size || (index & 3) || !data)
		return -EPERM;

	if ((u32)index + (u32)size > 0xffff)
		return -EPERM;

	byteen_start = byteen & BYTE_EN_START_MASK;
	byteen_end = byteen & BYTE_EN_END_MASK;

	byen = byteen_start | (byteen_start << 4);
	ret = set_registers(tp, index, type | byen, 4, data);
	if (ret < 0)
		goto error1;

	index += 4;
	data += 4;
	size -= 4;

	if (size) {
		size -= 4;

		while (size) {
			if (size > limit) {
				ret = set_registers(tp, index,
895
896
						    type | BYTE_EN_DWORD,
						    limit, data);
hayeswang's avatar
hayeswang committed
897
898
899
900
901
902
903
904
				if (ret < 0)
					goto error1;

				index += limit;
				data += limit;
				size -= limit;
			} else {
				ret = set_registers(tp, index,
905
906
						    type | BYTE_EN_DWORD,
						    size, data);
hayeswang's avatar
hayeswang committed
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
				if (ret < 0)
					goto error1;

				index += size;
				data += size;
				size = 0;
				break;
			}
		}

		byen = byteen_end | (byteen_end >> 4);
		ret = set_registers(tp, index, type | byen, 4, data);
		if (ret < 0)
			goto error1;
	}

error1:
924
925
926
	if (ret == -ENODEV)
		set_bit(RTL8152_UNPLUG, &tp->flags);

hayeswang's avatar
hayeswang committed
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
	return ret;
}

static inline
int pla_ocp_read(struct r8152 *tp, u16 index, u16 size, void *data)
{
	return generic_ocp_read(tp, index, size, data, MCU_TYPE_PLA);
}

static inline
int pla_ocp_write(struct r8152 *tp, u16 index, u16 byteen, u16 size, void *data)
{
	return generic_ocp_write(tp, index, byteen, size, data, MCU_TYPE_PLA);
}

static inline
int usb_ocp_write(struct r8152 *tp, u16 index, u16 byteen, u16 size, void *data)
{
	return generic_ocp_write(tp, index, byteen, size, data, MCU_TYPE_USB);
}

static u32 ocp_read_dword(struct r8152 *tp, u16 type, u16 index)
{
950
	__le32 data;
hayeswang's avatar
hayeswang committed
951

952
	generic_ocp_read(tp, index, sizeof(data), &data, type);
hayeswang's avatar
hayeswang committed
953
954
955
956
957
958

	return __le32_to_cpu(data);
}

static void ocp_write_dword(struct r8152 *tp, u16 type, u16 index, u32 data)
{
959
960
961
	__le32 tmp = __cpu_to_le32(data);

	generic_ocp_write(tp, index, BYTE_EN_DWORD, sizeof(tmp), &tmp, type);
hayeswang's avatar
hayeswang committed
962
963
964
965
966
}

static u16 ocp_read_word(struct r8152 *tp, u16 type, u16 index)
{
	u32 data;
967
	__le32 tmp;
968
	u16 byen = BYTE_EN_WORD;
hayeswang's avatar
hayeswang committed
969
970
971
	u8 shift = index & 2;

	index &= ~3;
972
	byen <<= shift;
hayeswang's avatar
hayeswang committed
973

974
	generic_ocp_read(tp, index, sizeof(tmp), &tmp, type | byen);
hayeswang's avatar
hayeswang committed
975

976
	data = __le32_to_cpu(tmp);
hayeswang's avatar
hayeswang committed
977
978
979
980
981
982
983
984
	data >>= (shift * 8);
	data &= 0xffff;

	return (u16)data;
}

static void ocp_write_word(struct r8152 *tp, u16 type, u16 index, u32 data)
{
985
986
	u32 mask = 0xffff;
	__le32 tmp;
hayeswang's avatar
hayeswang committed
987
988
989
990
991
992
993
994
995
996
997
998
	u16 byen = BYTE_EN_WORD;
	u8 shift = index & 2;

	data &= mask;

	if (index & 2) {
		byen <<= shift;
		mask <<= (shift * 8);
		data <<= (shift * 8);
		index &= ~3;
	}

999
	tmp = __cpu_to_le32(data);
hayeswang's avatar
hayeswang committed
1000

For faster browsing, not all history is shown. View entire blame