blob: fa57e42502a125632ea1059ffd4bdc0b712d85d5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001/* SPDX-License-Identifier: GPL-2.0 */
Ted Chen9b6dbd42016-01-20 14:24:52 +08002/*
3 * Copyright (c) 2015 Realtek Semiconductor Corp. All rights reserved.
4 *
Ted Chen9b6dbd42016-01-20 14:24:52 +08005 */
6
7#ifndef _RTL8152_ETH_H
8#define _RTL8152_ETH_H
9
Simon Glass4dcacfc2020-05-10 11:40:13 -060010#include <linux/bitops.h>
Ted Chen9b6dbd42016-01-20 14:24:52 +080011#define R8152_BASE_NAME "r8152"
12
13#define PLA_IDR 0xc000
14#define PLA_RCR 0xc010
15#define PLA_RMS 0xc016
16#define PLA_RXFIFO_CTRL0 0xc0a0
17#define PLA_RXFIFO_CTRL1 0xc0a4
18#define PLA_RXFIFO_CTRL2 0xc0a8
19#define PLA_DMY_REG0 0xc0b0
20#define PLA_FMC 0xc0b4
21#define PLA_CFG_WOL 0xc0b6
22#define PLA_TEREDO_CFG 0xc0bc
23#define PLA_MAR 0xcd00
24#define PLA_BACKUP 0xd000
Hayes Wang1bb3ee42020-05-22 16:54:11 +080025#define PLA_BDC_CR 0xd1a0
Ted Chen9b6dbd42016-01-20 14:24:52 +080026#define PLA_TEREDO_TIMER 0xd2cc
27#define PLA_REALWOW_TIMER 0xd2e8
Hayes Wanga587d3b2020-06-05 15:23:40 +080028#define PLA_EXTRA_STATUS 0xd398
Hayes Wangd215ca22020-06-16 17:09:47 +080029#define PLA_EFUSE_DATA 0xdd00
30#define PLA_EFUSE_CMD 0xdd02
Ted Chen9b6dbd42016-01-20 14:24:52 +080031#define PLA_LEDSEL 0xdd90
32#define PLA_LED_FEATURE 0xdd92
33#define PLA_PHYAR 0xde00
34#define PLA_BOOT_CTRL 0xe004
35#define PLA_GPHY_INTR_IMR 0xe022
36#define PLA_EEE_CR 0xe040
37#define PLA_EEEP_CR 0xe080
38#define PLA_MAC_PWR_CTRL 0xe0c0
39#define PLA_MAC_PWR_CTRL2 0xe0ca
40#define PLA_MAC_PWR_CTRL3 0xe0cc
41#define PLA_MAC_PWR_CTRL4 0xe0ce
42#define PLA_WDT6_CTRL 0xe428
43#define PLA_TCR0 0xe610
44#define PLA_TCR1 0xe612
45#define PLA_MTPS 0xe615
46#define PLA_TXFIFO_CTRL 0xe618
47#define PLA_RSTTALLY 0xe800
48#define BIST_CTRL 0xe810
49#define PLA_CR 0xe813
50#define PLA_CRWECR 0xe81c
51#define PLA_CONFIG12 0xe81e /* CONFIG1, CONFIG2 */
52#define PLA_CONFIG34 0xe820 /* CONFIG3, CONFIG4 */
53#define PLA_CONFIG5 0xe822
54#define PLA_PHY_PWR 0xe84c
55#define PLA_OOB_CTRL 0xe84f
56#define PLA_CPCR 0xe854
57#define PLA_MISC_0 0xe858
58#define PLA_MISC_1 0xe85a
59#define PLA_OCP_GPHY_BASE 0xe86c
60#define PLA_TALLYCNT 0xe890
61#define PLA_SFF_STS_7 0xe8de
62#define PLA_PHYSTATUS 0xe908
63#define PLA_BP_BA 0xfc26
64#define PLA_BP_0 0xfc28
65#define PLA_BP_1 0xfc2a
66#define PLA_BP_2 0xfc2c
67#define PLA_BP_3 0xfc2e
68#define PLA_BP_4 0xfc30
69#define PLA_BP_5 0xfc32
70#define PLA_BP_6 0xfc34
71#define PLA_BP_7 0xfc36
72#define PLA_BP_EN 0xfc38
73
74#define USB_USB2PHY 0xb41e
75#define USB_SSPHYLINK2 0xb428
76#define USB_U2P3_CTRL 0xb460
77#define USB_CSR_DUMMY1 0xb464
78#define USB_CSR_DUMMY2 0xb466
79#define USB_DEV_STAT 0xb808
80#define USB_CONNECT_TIMER 0xcbf8
Hayes Wangd215ca22020-06-16 17:09:47 +080081#define USB_MSC_TIMER 0xcbfc
Ted Chen9b6dbd42016-01-20 14:24:52 +080082#define USB_BURST_SIZE 0xcfc0
Hayes Wanga587d3b2020-06-05 15:23:40 +080083#define USB_FW_FIX_EN1 0xcfcc
Hayes Wangd215ca22020-06-16 17:09:47 +080084#define USB_LPM_CONFIG 0xcfd8
Ted Chen9b6dbd42016-01-20 14:24:52 +080085#define USB_USB_CTRL 0xd406
86#define USB_PHY_CTRL 0xd408
87#define USB_TX_AGG 0xd40a
88#define USB_RX_BUF_TH 0xd40c
89#define USB_USB_TIMER 0xd428
90#define USB_RX_EARLY_TIMEOUT 0xd42c
91#define USB_RX_EARLY_SIZE 0xd42e
Hayes Wangd215ca22020-06-16 17:09:47 +080092#define USB_PM_CTRL_STATUS 0xd432 /* RTL8153A */
93#define USB_RX_EXTRA_AGGR_TMR 0xd432 /* RTL8153B */
Ted Chen9b6dbd42016-01-20 14:24:52 +080094#define USB_TX_DMA 0xd434
95#define USB_TOLERANCE 0xd490
96#define USB_LPM_CTRL 0xd41a
Hayes Wang653d2e72020-06-16 17:09:44 +080097#define USB_BMU_RESET 0xd4b0
Hayes Wangd215ca22020-06-16 17:09:47 +080098#define USB_U1U2_TIMER 0xd4da
Ted Chen9b6dbd42016-01-20 14:24:52 +080099#define USB_UPS_CTRL 0xd800
Ted Chen9b6dbd42016-01-20 14:24:52 +0800100#define USB_POWER_CUT 0xd80a
Hayes Wang653d2e72020-06-16 17:09:44 +0800101#define USB_MISC_0 0xd81a
Ted Chen9b6dbd42016-01-20 14:24:52 +0800102#define USB_AFE_CTRL2 0xd824
Hayes Wangd215ca22020-06-16 17:09:47 +0800103#define USB_UPS_CFG 0xd842
Ted Chen9b6dbd42016-01-20 14:24:52 +0800104#define USB_WDT11_CTRL 0xe43c
Hayes Wang98e97912020-06-16 17:09:46 +0800105#define USB_BP_BA PLA_BP_BA
106#define USB_BP(n) (0xfc28 + 2 * (n))
Hayes Wangd215ca22020-06-16 17:09:47 +0800107#define USB_BP_EN PLA_BP_EN /* RTL8153A */
108#define USB_BP2_EN 0xfc48
Ted Chen9b6dbd42016-01-20 14:24:52 +0800109
110/* OCP Registers */
111#define OCP_ALDPS_CONFIG 0x2010
112#define OCP_EEE_CONFIG1 0x2080
113#define OCP_EEE_CONFIG2 0x2092
114#define OCP_EEE_CONFIG3 0x2094
115#define OCP_BASE_MII 0xa400
116#define OCP_EEE_AR 0xa41a
117#define OCP_EEE_DATA 0xa41c
118#define OCP_PHY_STATUS 0xa420
Hayes Wangd215ca22020-06-16 17:09:47 +0800119#define OCP_NCTL_CFG 0xa42c
Ted Chen9b6dbd42016-01-20 14:24:52 +0800120#define OCP_POWER_CFG 0xa430
121#define OCP_EEE_CFG 0xa432
122#define OCP_SRAM_ADDR 0xa436
123#define OCP_SRAM_DATA 0xa438
124#define OCP_DOWN_SPEED 0xa442
125#define OCP_EEE_ABLE 0xa5c4
126#define OCP_EEE_ADV 0xa5d0
127#define OCP_EEE_LPABLE 0xa5d2
128#define OCP_PHY_STATE 0xa708 /* nway state for 8153 */
Hayes Wangd215ca22020-06-16 17:09:47 +0800129#define OCP_ADC_IOFFSET 0xbcfc
Ted Chen9b6dbd42016-01-20 14:24:52 +0800130#define OCP_ADC_CFG 0xbc06
131
132/* SRAM Register */
Hayes Wangd215ca22020-06-16 17:09:47 +0800133#define SRAM_GREEN_CFG 0x8011
Ted Chen9b6dbd42016-01-20 14:24:52 +0800134#define SRAM_LPF_CFG 0x8012
135#define SRAM_10M_AMP1 0x8080
136#define SRAM_10M_AMP2 0x8082
137#define SRAM_IMPEDANCE 0x8084
138
139/* PLA_RCR */
140#define RCR_AAP 0x00000001
141#define RCR_APM 0x00000002
142#define RCR_AM 0x00000004
143#define RCR_AB 0x00000008
144#define RCR_ACPT_ALL (RCR_AAP | RCR_APM | RCR_AM | RCR_AB)
145
146/* PLA_RXFIFO_CTRL0 */
147#define RXFIFO_THR1_NORMAL 0x00080002
148#define RXFIFO_THR1_OOB 0x01800003
149
150/* PLA_RXFIFO_CTRL1 */
151#define RXFIFO_THR2_FULL 0x00000060
152#define RXFIFO_THR2_HIGH 0x00000038
153#define RXFIFO_THR2_OOB 0x0000004a
154#define RXFIFO_THR2_NORMAL 0x00a0
155
156/* PLA_RXFIFO_CTRL2 */
157#define RXFIFO_THR3_FULL 0x00000078
158#define RXFIFO_THR3_HIGH 0x00000048
159#define RXFIFO_THR3_OOB 0x0000005a
160#define RXFIFO_THR3_NORMAL 0x0110
161
162/* PLA_TXFIFO_CTRL */
163#define TXFIFO_THR_NORMAL 0x00400008
164#define TXFIFO_THR_NORMAL2 0x01000008
165
166/* PLA_DMY_REG0 */
167#define ECM_ALDPS 0x0002
168
169/* PLA_FMC */
170#define FMC_FCR_MCU_EN 0x0001
171
172/* PLA_EEEP_CR */
173#define EEEP_CR_EEEP_TX 0x0002
174
175/* PLA_WDT6_CTRL */
176#define WDT6_SET_MODE 0x0010
177
178/* PLA_TCR0 */
179#define TCR0_TX_EMPTY 0x0800
180#define TCR0_AUTO_FIFO 0x0080
181
182/* PLA_TCR1 */
183#define VERSION_MASK 0x7cf0
184
185/* PLA_MTPS */
186#define MTPS_JUMBO (12 * 1024 / 64)
187#define MTPS_DEFAULT (6 * 1024 / 64)
188
189/* PLA_RSTTALLY */
190#define TALLY_RESET 0x0001
191
192/* PLA_CR */
193#define PLA_CR_RST 0x10
194#define PLA_CR_RE 0x08
195#define PLA_CR_TE 0x04
196
197/* PLA_BIST_CTRL */
198#define BIST_CTRL_SW_RESET (0x10 << 24)
199
200/* PLA_CRWECR */
201#define CRWECR_NORAML 0x00
202#define CRWECR_CONFIG 0xc0
203
204/* PLA_OOB_CTRL */
205#define NOW_IS_OOB 0x80
206#define TXFIFO_EMPTY 0x20
207#define RXFIFO_EMPTY 0x10
208#define LINK_LIST_READY 0x02
209#define DIS_MCU_CLROOB 0x01
210#define FIFO_EMPTY (TXFIFO_EMPTY | RXFIFO_EMPTY)
211
212/* PLA_PHY_PWR */
213#define PLA_PHY_PWR_LLR (LINK_LIST_READY << 24)
214#define PLA_PHY_PWR_TXEMP (TXFIFO_EMPTY << 24)
Hayes Wangd215ca22020-06-16 17:09:47 +0800215#define TEST_IO_OFF BIT(4)
Ted Chen9b6dbd42016-01-20 14:24:52 +0800216
217/* PLA_MISC_1 */
218#define RXDY_GATED_EN 0x0008
219
220/* PLA_SFF_STS_7 */
221#define RE_INIT_LL 0x8000
222#define MCU_BORW_EN 0x4000
223
224/* PLA_CPCR */
225#define CPCR_RX_VLAN 0x0040
226
227/* PLA_CFG_WOL */
228#define MAGIC_EN 0x0001
229
230/* PLA_TEREDO_CFG */
231#define TEREDO_SEL 0x8000
232#define TEREDO_WAKE_MASK 0x7f00
233#define TEREDO_RS_EVENT_MASK 0x00fe
234#define OOB_TEREDO_EN 0x0001
235
Hayes Wang1bb3ee42020-05-22 16:54:11 +0800236/* PLA_BDC_CR */
Ted Chen9b6dbd42016-01-20 14:24:52 +0800237#define ALDPS_PROXY_MODE 0x0001
238
Hayes Wangd215ca22020-06-16 17:09:47 +0800239/* PLA_EFUSE_CMD */
240#define EFUSE_READ_CMD BIT(15)
241#define EFUSE_DATA_BIT16 BIT(7)
242
Ted Chen9b6dbd42016-01-20 14:24:52 +0800243/* PLA_CONFIG34 */
244#define LINK_ON_WAKE_EN 0x0010
245#define LINK_OFF_WAKE_EN 0x0008
246
247/* PLA_CONFIG5 */
248#define BWF_EN 0x0040
249#define MWF_EN 0x0020
250#define UWF_EN 0x0010
251#define LAN_WAKE_EN 0x0002
252
253/* PLA_LED_FEATURE */
254#define LED_MODE_MASK 0x0700
255
256/* PLA_PHY_PWR */
257#define TX_10M_IDLE_EN 0x0080
258#define PFM_PWM_SWITCH 0x0040
259
260/* PLA_MAC_PWR_CTRL */
261#define D3_CLK_GATED_EN 0x00004000
262#define MCU_CLK_RATIO 0x07010f07
263#define MCU_CLK_RATIO_MASK 0x0f0f0f0f
264#define ALDPS_SPDWN_RATIO 0x0f87
265
266/* PLA_MAC_PWR_CTRL2 */
267#define EEE_SPDWN_RATIO 0x8007
Hayes Wangd215ca22020-06-16 17:09:47 +0800268#define MAC_CLK_SPDWN_EN BIT(15)
Ted Chen9b6dbd42016-01-20 14:24:52 +0800269
270/* PLA_MAC_PWR_CTRL3 */
Hayes Wangd215ca22020-06-16 17:09:47 +0800271#define PLA_MCU_SPDWN_EN BIT(14)
Ted Chen9b6dbd42016-01-20 14:24:52 +0800272#define PKT_AVAIL_SPDWN_EN 0x0100
273#define SUSPEND_SPDWN_EN 0x0004
274#define U1U2_SPDWN_EN 0x0002
275#define L1_SPDWN_EN 0x0001
276
277/* PLA_MAC_PWR_CTRL4 */
278#define PWRSAVE_SPDWN_EN 0x1000
279#define RXDV_SPDWN_EN 0x0800
280#define TX10MIDLE_EN 0x0100
281#define TP100_SPDWN_EN 0x0020
282#define TP500_SPDWN_EN 0x0010
283#define TP1000_SPDWN_EN 0x0008
284#define EEE_SPDWN_EN 0x0001
285
286/* PLA_GPHY_INTR_IMR */
287#define GPHY_STS_MSK 0x0001
288#define SPEED_DOWN_MSK 0x0002
289#define SPDWN_RXDV_MSK 0x0004
290#define SPDWN_LINKCHG_MSK 0x0008
291
292/* PLA_PHYAR */
293#define PHYAR_FLAG 0x80000000
294
295/* PLA_EEE_CR */
296#define EEE_RX_EN 0x0001
297#define EEE_TX_EN 0x0002
298
299/* PLA_BOOT_CTRL */
300#define AUTOLOAD_DONE 0x0002
301
Hayes Wanga587d3b2020-06-05 15:23:40 +0800302/* PLA_EXTRA_STATUS */
303#define U3P3_CHECK_EN BIT(7)
304
Ted Chen9b6dbd42016-01-20 14:24:52 +0800305/* USB_USB2PHY */
306#define USB2PHY_SUSPEND 0x0001
307#define USB2PHY_L1 0x0002
308
309/* USB_SSPHYLINK2 */
310#define pwd_dn_scale_mask 0x3ffe
311#define pwd_dn_scale(x) ((x) << 1)
312
313/* USB_CSR_DUMMY1 */
314#define DYNAMIC_BURST 0x0001
315
316/* USB_CSR_DUMMY2 */
317#define EP4_FULL_FC 0x0001
318
319/* USB_DEV_STAT */
320#define STAT_SPEED_MASK 0x0006
321#define STAT_SPEED_HIGH 0x0000
322#define STAT_SPEED_FULL 0x0002
323
Hayes Wanga587d3b2020-06-05 15:23:40 +0800324/* USB_FW_FIX_EN1 */
325#define FW_IP_RESET_EN BIT(9)
326
Hayes Wangd215ca22020-06-16 17:09:47 +0800327/* USB_LPM_CONFIG */
328#define LPM_U1U2_EN BIT(0)
329
Ted Chen9b6dbd42016-01-20 14:24:52 +0800330/* USB_TX_AGG */
331#define TX_AGG_MAX_THRESHOLD 0x03
332
333/* USB_RX_BUF_TH */
334#define RX_THR_SUPPER 0x0c350180
335#define RX_THR_HIGH 0x7a120180
336#define RX_THR_SLOW 0xffff0180
337
Hayes Wangd215ca22020-06-16 17:09:47 +0800338/* USB_RX_EARLY_TIMEOUT */
339#define RX_AUXILIARY_TIMER 1264
340
Ted Chen9b6dbd42016-01-20 14:24:52 +0800341/* USB_TX_DMA */
342#define TEST_MODE_DISABLE 0x00000001
343#define TX_SIZE_ADJUST1 0x00000100
344
Hayes Wang653d2e72020-06-16 17:09:44 +0800345/* USB_BMU_RESET */
346#define BMU_RESET_EP_IN 0x01
347#define BMU_RESET_EP_OUT 0x02
348
Ted Chen9b6dbd42016-01-20 14:24:52 +0800349/* USB_UPS_CTRL */
350#define POWER_CUT 0x0100
351
352/* USB_PM_CTRL_STATUS */
353#define RESUME_INDICATE 0x0001
354
355/* USB_USB_CTRL */
356#define RX_AGG_DISABLE 0x0010
357#define RX_ZERO_EN 0x0080
358
359/* USB_U2P3_CTRL */
360#define U2P3_ENABLE 0x0001
361
362/* USB_POWER_CUT */
363#define PWR_EN 0x0001
364#define PHASE2_EN 0x0008
365
366/* USB_MISC_0 */
367#define PCUT_STATUS 0x0001
368
369/* USB_RX_EARLY_TIMEOUT */
370#define COALESCE_SUPER 85000U
371#define COALESCE_HIGH 250000U
372#define COALESCE_SLOW 524280U
373
374/* USB_WDT11_CTRL */
375#define TIMER11_EN 0x0001
376
377/* USB_LPM_CTRL */
378/* bit 4 ~ 5: fifo empty boundary */
379#define FIFO_EMPTY_1FB 0x30 /* 0x1fb * 64 = 32448 bytes */
380/* bit 2 ~ 3: LMP timer */
381#define LPM_TIMER_MASK 0x0c
382#define LPM_TIMER_500MS 0x04 /* 500 ms */
383#define LPM_TIMER_500US 0x0c /* 500 us */
384#define ROK_EXIT_LPM 0x02
385
386/* USB_AFE_CTRL2 */
387#define SEN_VAL_MASK 0xf800
388#define SEN_VAL_NORMAL 0xa000
389#define SEL_RXIDLE 0x0100
390
Hayes Wangd215ca22020-06-16 17:09:47 +0800391/* USB_UPS_CFG */
392#define SAW_CNT_1MS_MASK 0x0fff
393
Ted Chen9b6dbd42016-01-20 14:24:52 +0800394/* OCP_ALDPS_CONFIG */
395#define ENPWRSAVE 0x8000
396#define ENPDNPS 0x0200
397#define LINKENA 0x0100
398#define DIS_SDSAVE 0x0010
399
400/* OCP_PHY_STATUS */
401#define PHY_STAT_MASK 0x0007
402#define PHY_STAT_LAN_ON 3
403#define PHY_STAT_PWRDN 5
404
Hayes Wangd215ca22020-06-16 17:09:47 +0800405/* OCP_NCTL_CFG */
406#define PGA_RETURN_EN BIT(1)
407
Ted Chen9b6dbd42016-01-20 14:24:52 +0800408/* OCP_POWER_CFG */
409#define EEE_CLKDIV_EN 0x8000
410#define EN_ALDPS 0x0004
411#define EN_10M_PLLOFF 0x0001
412
413/* OCP_EEE_CONFIG1 */
414#define RG_TXLPI_MSK_HFDUP 0x8000
415#define RG_MATCLR_EN 0x4000
416#define EEE_10_CAP 0x2000
417#define EEE_NWAY_EN 0x1000
418#define TX_QUIET_EN 0x0200
419#define RX_QUIET_EN 0x0100
420#define sd_rise_time_mask 0x0070
421#define sd_rise_time(x) (min((x), 7) << 4) /* bit 4 ~ 6 */
422#define RG_RXLPI_MSK_HFDUP 0x0008
423#define SDFALLTIME 0x0007 /* bit 0 ~ 2 */
424
425/* OCP_EEE_CONFIG2 */
426#define RG_LPIHYS_NUM 0x7000 /* bit 12 ~ 15 */
427#define RG_DACQUIET_EN 0x0400
428#define RG_LDVQUIET_EN 0x0200
429#define RG_CKRSEL 0x0020
430#define RG_EEEPRG_EN 0x0010
431
432/* OCP_EEE_CONFIG3 */
433#define fast_snr_mask 0xff80
434#define fast_snr(x) (min((x), 0x1ff) << 7) /* bit 7 ~ 15 */
435#define RG_LFS_SEL 0x0060 /* bit 6 ~ 5 */
436#define MSK_PH 0x0006 /* bit 0 ~ 3 */
437
438/* OCP_EEE_AR */
439/* bit[15:14] function */
440#define FUN_ADDR 0x0000
441#define FUN_DATA 0x4000
442/* bit[4:0] device addr */
443
444/* OCP_EEE_CFG */
445#define CTAP_SHORT_EN 0x0040
446#define EEE10_EN 0x0010
447
448/* OCP_DOWN_SPEED */
449#define EN_10M_BGOFF 0x0080
450
451/* OCP_PHY_STATE */
452#define TXDIS_STATE 0x01
453#define ABD_STATE 0x02
454
455/* OCP_ADC_CFG */
456#define CKADSEL_L 0x0100
457#define ADC_EN 0x0080
458#define EN_EMI_L 0x0040
459
Hayes Wangd215ca22020-06-16 17:09:47 +0800460/* SRAM_GREEN_CFG */
461#define GREEN_ETH_EN BIT(15)
462#define R_TUNE_EN BIT(11)
463
Ted Chen9b6dbd42016-01-20 14:24:52 +0800464/* SRAM_LPF_CFG */
465#define LPF_AUTO_TUNE 0x8000
466
467/* SRAM_10M_AMP1 */
468#define GDAC_IB_UPALL 0x0008
469
470/* SRAM_10M_AMP2 */
471#define AMP_DN 0x0200
472
473/* SRAM_IMPEDANCE */
474#define RX_DRIVING_MASK 0x6000
475
476#define RTL8152_MAX_TX 4
477#define RTL8152_MAX_RX 10
478#define INTBUFSIZE 2
479#define CRC_SIZE 4
480#define TX_ALIGN 4
481#define RX_ALIGN 8
482
483#define INTR_LINK 0x0004
484
485#define RTL8152_REQT_READ 0xc0
486#define RTL8152_REQT_WRITE 0x40
487#define RTL8152_REQ_GET_REGS 0x05
488#define RTL8152_REQ_SET_REGS 0x05
489
490#define BYTE_EN_DWORD 0xff
491#define BYTE_EN_WORD 0x33
492#define BYTE_EN_BYTE 0x11
493#define BYTE_EN_SIX_BYTES 0x3f
494#define BYTE_EN_START_MASK 0x0f
495#define BYTE_EN_END_MASK 0xf0
496
497#define RTL8152_ETH_FRAME_LEN 1514
498#define RTL8152_AGG_BUF_SZ 2048
499
500#define RTL8152_RMS (RTL8152_ETH_FRAME_LEN + CRC_SIZE)
501#define RTL8153_RMS (RTL8152_ETH_FRAME_LEN + CRC_SIZE)
502#define RTL8152_TX_TIMEOUT (5 * HZ)
503
504#define MCU_TYPE_PLA 0x0100
505#define MCU_TYPE_USB 0x0000
506
507/* The forced speed, 10Mb, 100Mb, gigabit. */
508#define SPEED_10 10
509#define SPEED_100 100
510#define SPEED_1000 1000
511
512#define SPEED_UNKNOWN -1
513
514/* Duplex, half or full. */
515#define DUPLEX_HALF 0x00
516#define DUPLEX_FULL 0x01
517#define DUPLEX_UNKNOWN 0xff
518
519/* Enable or disable autonegotiation. */
520#define AUTONEG_DISABLE 0x00
521#define AUTONEG_ENABLE 0x01
522
523/* Generic MII registers. */
524#define MII_BMCR 0x00 /* Basic mode control register */
525#define MII_BMSR 0x01 /* Basic mode status register */
526#define MII_PHYSID1 0x02 /* PHYS ID 1 */
527#define MII_PHYSID2 0x03 /* PHYS ID 2 */
528#define MII_ADVERTISE 0x04 /* Advertisement control reg */
529#define MII_LPA 0x05 /* Link partner ability reg */
530#define MII_EXPANSION 0x06 /* Expansion register */
531#define MII_CTRL1000 0x09 /* 1000BASE-T control */
532#define MII_STAT1000 0x0a /* 1000BASE-T status */
533#define MII_MMD_CTRL 0x0d /* MMD Access Control Register */
534#define MII_MMD_DATA 0x0e /* MMD Access Data Register */
535#define MII_ESTATUS 0x0f /* Extended Status */
536#define MII_DCOUNTER 0x12 /* Disconnect counter */
537#define MII_FCSCOUNTER 0x13 /* False carrier counter */
538#define MII_NWAYTEST 0x14 /* N-way auto-neg test reg */
539#define MII_RERRCOUNTER 0x15 /* Receive error counter */
540#define MII_SREVISION 0x16 /* Silicon revision */
541#define MII_RESV1 0x17 /* Reserved... */
542#define MII_LBRERROR 0x18 /* Lpback, rx, bypass error */
543#define MII_PHYADDR 0x19 /* PHY address */
544#define MII_RESV2 0x1a /* Reserved... */
545#define MII_TPISTATUS 0x1b /* TPI status for 10mbps */
546#define MII_NCONFIG 0x1c /* Network interface config */
547
548#define TIMEOUT_RESOLUTION 50
549#define PHY_CONNECT_TIMEOUT 5000
550#define USB_BULK_SEND_TIMEOUT 5000
551#define USB_BULK_RECV_TIMEOUT 5000
552#define R8152_WAIT_TIMEOUT 2000
553
554struct rx_desc {
555 __le32 opts1;
556#define RD_CRC BIT(15)
557#define RX_LEN_MASK 0x7fff
558
559 __le32 opts2;
560#define RD_UDP_CS BIT(23)
561#define RD_TCP_CS BIT(22)
562#define RD_IPV6_CS BIT(20)
563#define RD_IPV4_CS BIT(19)
564
565 __le32 opts3;
566#define IPF BIT(23) /* IP checksum fail */
567#define UDPF BIT(22) /* UDP checksum fail */
568#define TCPF BIT(21) /* TCP checksum fail */
569#define RX_VLAN_TAG BIT(16)
570
571 __le32 opts4;
572 __le32 opts5;
573 __le32 opts6;
574};
575
576struct tx_desc {
577 __le32 opts1;
578#define TX_FS BIT(31) /* First segment of a packet */
579#define TX_LS BIT(30) /* Final segment of a packet */
580#define LGSEND BIT(29)
581#define GTSENDV4 BIT(28)
582#define GTSENDV6 BIT(27)
583#define GTTCPHO_SHIFT 18
584#define GTTCPHO_MAX 0x7fU
585#define TX_LEN_MAX 0x3ffffU
586
587 __le32 opts2;
588#define UDP_CS BIT(31) /* Calculate UDP/IP checksum */
589#define TCP_CS BIT(30) /* Calculate TCP/IP checksum */
590#define IPV4_CS BIT(29) /* Calculate IPv4 checksum */
591#define IPV6_CS BIT(28) /* Calculate IPv6 checksum */
592#define MSS_SHIFT 17
593#define MSS_MAX 0x7ffU
594#define TCPHO_SHIFT 17
595#define TCPHO_MAX 0x7ffU
596#define TX_VLAN_TAG BIT(16)
597};
598
599enum rtl_version {
600 RTL_VER_UNKNOWN = 0,
601 RTL_VER_01,
602 RTL_VER_02,
603 RTL_VER_03,
604 RTL_VER_04,
605 RTL_VER_05,
606 RTL_VER_06,
607 RTL_VER_07,
Hayes Wangd215ca22020-06-16 17:09:47 +0800608 RTL_VER_08,
609 RTL_VER_09,
Ted Chen9b6dbd42016-01-20 14:24:52 +0800610 RTL_VER_MAX
611};
612
613enum rtl_register_content {
614 _1000bps = 0x10,
615 _100bps = 0x08,
616 _10bps = 0x04,
617 LINK_STATUS = 0x02,
618 FULL_DUP = 0x01,
619};
620
621struct r8152 {
622 struct usb_device *udev;
623 struct usb_interface *intf;
624 bool supports_gmii;
625
626 struct rtl_ops {
627 void (*init)(struct r8152 *);
628 int (*enable)(struct r8152 *);
629 void (*disable)(struct r8152 *);
630 void (*up)(struct r8152 *);
631 void (*down)(struct r8152 *);
632 void (*unload)(struct r8152 *);
633 } rtl_ops;
634
635 u32 coalesce;
636 u16 ocp_base;
637
638 u8 version;
Stefan Roese47c50972016-06-29 07:58:05 +0200639
640#ifdef CONFIG_DM_ETH
641 struct ueth_data ueth;
642#endif
Ted Chen9b6dbd42016-01-20 14:24:52 +0800643};
644
645int generic_ocp_write(struct r8152 *tp, u16 index, u16 byteen,
646 u16 size, void *data, u16 type);
647int generic_ocp_read(struct r8152 *tp, u16 index, u16 size,
648 void *data, u16 type);
649
650int pla_ocp_read(struct r8152 *tp, u16 index, u16 size, void *data);
651int pla_ocp_write(struct r8152 *tp, u16 index, u16 byteen,
652 u16 size, void *data);
653
654int usb_ocp_read(struct r8152 *tp, u16 index, u16 size, void *data);
655int usb_ocp_write(struct r8152 *tp, u16 index, u16 byteen,
656 u16 size, void *data);
657
658u32 ocp_read_dword(struct r8152 *tp, u16 type, u16 index);
659void ocp_write_dword(struct r8152 *tp, u16 type, u16 index, u32 data);
660
661u16 ocp_read_word(struct r8152 *tp, u16 type, u16 index);
662void ocp_write_word(struct r8152 *tp, u16 type, u16 index, u32 data);
663
664u8 ocp_read_byte(struct r8152 *tp, u16 type, u16 index);
665void ocp_write_byte(struct r8152 *tp, u16 type, u16 index, u32 data);
666
667u16 ocp_reg_read(struct r8152 *tp, u16 addr);
668void ocp_reg_write(struct r8152 *tp, u16 addr, u16 data);
669
670void sram_write(struct r8152 *tp, u16 addr, u16 data);
671
672int r8152_wait_for_bit(struct r8152 *tp, bool ocp_reg, u16 type, u16 index,
673 const u32 mask, bool set, unsigned int timeout);
674
675void r8152b_firmware(struct r8152 *tp);
676void r8153_firmware(struct r8152 *tp);
Hayes Wangd215ca22020-06-16 17:09:47 +0800677void r8153b_firmware(struct r8152 *tp);
Ted Chen9b6dbd42016-01-20 14:24:52 +0800678#endif