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