162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
262306a36Sopenharmony_ci/* drivers/net/ethernet/micrel/ks8851.h
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright 2009 Simtec Electronics
562306a36Sopenharmony_ci *      Ben Dooks <ben@simtec.co.uk>
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * KS8851 register definitions
862306a36Sopenharmony_ci*/
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#ifndef __KS8851_H__
1162306a36Sopenharmony_ci#define __KS8851_H__
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci#include <linux/eeprom_93cx6.h>
1462306a36Sopenharmony_ci
1562306a36Sopenharmony_ci#define KS_CCR					0x08
1662306a36Sopenharmony_ci#define CCR_LE					(1 << 10)   /* KSZ8851-16MLL */
1762306a36Sopenharmony_ci#define CCR_EEPROM				(1 << 9)
1862306a36Sopenharmony_ci#define CCR_SPI					(1 << 8)    /* KSZ8851SNL    */
1962306a36Sopenharmony_ci#define CCR_8BIT				(1 << 7)    /* KSZ8851-16MLL */
2062306a36Sopenharmony_ci#define CCR_16BIT				(1 << 6)    /* KSZ8851-16MLL */
2162306a36Sopenharmony_ci#define CCR_32BIT				(1 << 5)    /* KSZ8851-16MLL */
2262306a36Sopenharmony_ci#define CCR_SHARED				(1 << 4)    /* KSZ8851-16MLL */
2362306a36Sopenharmony_ci#define CCR_48PIN				(1 << 1)    /* KSZ8851-16MLL */
2462306a36Sopenharmony_ci#define CCR_32PIN				(1 << 0)    /* KSZ8851SNL    */
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci/* MAC address registers */
2762306a36Sopenharmony_ci#define KS_MAR(_m)				(0x14 - (_m))
2862306a36Sopenharmony_ci#define KS_MARL					0x10
2962306a36Sopenharmony_ci#define KS_MARM					0x12
3062306a36Sopenharmony_ci#define KS_MARH					0x14
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#define KS_OBCR					0x20
3362306a36Sopenharmony_ci#define OBCR_ODS_16mA				(1 << 6)
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci#define KS_EEPCR				0x22
3662306a36Sopenharmony_ci#define EEPCR_EESRWA				(1 << 5)
3762306a36Sopenharmony_ci#define EEPCR_EESA				(1 << 4)
3862306a36Sopenharmony_ci#define EEPCR_EESB				(1 << 3)
3962306a36Sopenharmony_ci#define EEPCR_EEDO				(1 << 2)
4062306a36Sopenharmony_ci#define EEPCR_EESCK				(1 << 1)
4162306a36Sopenharmony_ci#define EEPCR_EECS				(1 << 0)
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci#define KS_MBIR					0x24
4462306a36Sopenharmony_ci#define MBIR_TXMBF				(1 << 12)
4562306a36Sopenharmony_ci#define MBIR_TXMBFA				(1 << 11)
4662306a36Sopenharmony_ci#define MBIR_RXMBF				(1 << 4)
4762306a36Sopenharmony_ci#define MBIR_RXMBFA				(1 << 3)
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#define KS_GRR					0x26
5062306a36Sopenharmony_ci#define GRR_QMU					(1 << 1)
5162306a36Sopenharmony_ci#define GRR_GSR					(1 << 0)
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci#define KS_WFCR					0x2A
5462306a36Sopenharmony_ci#define WFCR_MPRXE				(1 << 7)
5562306a36Sopenharmony_ci#define WFCR_WF3E				(1 << 3)
5662306a36Sopenharmony_ci#define WFCR_WF2E				(1 << 2)
5762306a36Sopenharmony_ci#define WFCR_WF1E				(1 << 1)
5862306a36Sopenharmony_ci#define WFCR_WF0E				(1 << 0)
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_ci#define KS_WF0CRC0				0x30
6162306a36Sopenharmony_ci#define KS_WF0CRC1				0x32
6262306a36Sopenharmony_ci#define KS_WF0BM0				0x34
6362306a36Sopenharmony_ci#define KS_WF0BM1				0x36
6462306a36Sopenharmony_ci#define KS_WF0BM2				0x38
6562306a36Sopenharmony_ci#define KS_WF0BM3				0x3A
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci#define KS_WF1CRC0				0x40
6862306a36Sopenharmony_ci#define KS_WF1CRC1				0x42
6962306a36Sopenharmony_ci#define KS_WF1BM0				0x44
7062306a36Sopenharmony_ci#define KS_WF1BM1				0x46
7162306a36Sopenharmony_ci#define KS_WF1BM2				0x48
7262306a36Sopenharmony_ci#define KS_WF1BM3				0x4A
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci#define KS_WF2CRC0				0x50
7562306a36Sopenharmony_ci#define KS_WF2CRC1				0x52
7662306a36Sopenharmony_ci#define KS_WF2BM0				0x54
7762306a36Sopenharmony_ci#define KS_WF2BM1				0x56
7862306a36Sopenharmony_ci#define KS_WF2BM2				0x58
7962306a36Sopenharmony_ci#define KS_WF2BM3				0x5A
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci#define KS_WF3CRC0				0x60
8262306a36Sopenharmony_ci#define KS_WF3CRC1				0x62
8362306a36Sopenharmony_ci#define KS_WF3BM0				0x64
8462306a36Sopenharmony_ci#define KS_WF3BM1				0x66
8562306a36Sopenharmony_ci#define KS_WF3BM2				0x68
8662306a36Sopenharmony_ci#define KS_WF3BM3				0x6A
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci#define KS_TXCR					0x70
8962306a36Sopenharmony_ci#define TXCR_TCGICMP				(1 << 8)
9062306a36Sopenharmony_ci#define TXCR_TCGUDP				(1 << 7)
9162306a36Sopenharmony_ci#define TXCR_TCGTCP				(1 << 6)
9262306a36Sopenharmony_ci#define TXCR_TCGIP				(1 << 5)
9362306a36Sopenharmony_ci#define TXCR_FTXQ				(1 << 4)
9462306a36Sopenharmony_ci#define TXCR_TXFCE				(1 << 3)
9562306a36Sopenharmony_ci#define TXCR_TXPE				(1 << 2)
9662306a36Sopenharmony_ci#define TXCR_TXCRC				(1 << 1)
9762306a36Sopenharmony_ci#define TXCR_TXE				(1 << 0)
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ci#define KS_TXSR					0x72
10062306a36Sopenharmony_ci#define TXSR_TXLC				(1 << 13)
10162306a36Sopenharmony_ci#define TXSR_TXMC				(1 << 12)
10262306a36Sopenharmony_ci#define TXSR_TXFID_MASK				(0x3f << 0)
10362306a36Sopenharmony_ci#define TXSR_TXFID_SHIFT			(0)
10462306a36Sopenharmony_ci#define TXSR_TXFID_GET(_v)			(((_v) >> 0) & 0x3f)
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ci#define KS_RXCR1				0x74
10762306a36Sopenharmony_ci#define RXCR1_FRXQ				(1 << 15)
10862306a36Sopenharmony_ci#define RXCR1_RXUDPFCC				(1 << 14)
10962306a36Sopenharmony_ci#define RXCR1_RXTCPFCC				(1 << 13)
11062306a36Sopenharmony_ci#define RXCR1_RXIPFCC				(1 << 12)
11162306a36Sopenharmony_ci#define RXCR1_RXPAFMA				(1 << 11)
11262306a36Sopenharmony_ci#define RXCR1_RXFCE				(1 << 10)
11362306a36Sopenharmony_ci#define RXCR1_RXEFE				(1 << 9)
11462306a36Sopenharmony_ci#define RXCR1_RXMAFMA				(1 << 8)
11562306a36Sopenharmony_ci#define RXCR1_RXBE				(1 << 7)
11662306a36Sopenharmony_ci#define RXCR1_RXME				(1 << 6)
11762306a36Sopenharmony_ci#define RXCR1_RXUE				(1 << 5)
11862306a36Sopenharmony_ci#define RXCR1_RXAE				(1 << 4)
11962306a36Sopenharmony_ci#define RXCR1_RXINVF				(1 << 1)
12062306a36Sopenharmony_ci#define RXCR1_RXE				(1 << 0)
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci#define KS_RXCR2				0x76
12362306a36Sopenharmony_ci#define RXCR2_SRDBL_MASK			(0x7 << 5)  /* KSZ8851SNL    */
12462306a36Sopenharmony_ci#define RXCR2_SRDBL_SHIFT			(5)	    /* KSZ8851SNL    */
12562306a36Sopenharmony_ci#define RXCR2_SRDBL_4B				(0x0 << 5)  /* KSZ8851SNL    */
12662306a36Sopenharmony_ci#define RXCR2_SRDBL_8B				(0x1 << 5)  /* KSZ8851SNL    */
12762306a36Sopenharmony_ci#define RXCR2_SRDBL_16B				(0x2 << 5)  /* KSZ8851SNL    */
12862306a36Sopenharmony_ci#define RXCR2_SRDBL_32B				(0x3 << 5)  /* KSZ8851SNL    */
12962306a36Sopenharmony_ci#define RXCR2_SRDBL_FRAME			(0x4 << 5)  /* KSZ8851SNL    */
13062306a36Sopenharmony_ci#define RXCR2_IUFFP				(1 << 4)
13162306a36Sopenharmony_ci#define RXCR2_RXIUFCEZ				(1 << 3)
13262306a36Sopenharmony_ci#define RXCR2_UDPLFE				(1 << 2)
13362306a36Sopenharmony_ci#define RXCR2_RXICMPFCC				(1 << 1)
13462306a36Sopenharmony_ci#define RXCR2_RXSAF				(1 << 0)
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci#define KS_TXMIR				0x78
13762306a36Sopenharmony_ci
13862306a36Sopenharmony_ci#define KS_RXFHSR				0x7C
13962306a36Sopenharmony_ci#define RXFSHR_RXFV				(1 << 15)
14062306a36Sopenharmony_ci#define RXFSHR_RXICMPFCS			(1 << 13)
14162306a36Sopenharmony_ci#define RXFSHR_RXIPFCS				(1 << 12)
14262306a36Sopenharmony_ci#define RXFSHR_RXTCPFCS				(1 << 11)
14362306a36Sopenharmony_ci#define RXFSHR_RXUDPFCS				(1 << 10)
14462306a36Sopenharmony_ci#define RXFSHR_RXBF				(1 << 7)
14562306a36Sopenharmony_ci#define RXFSHR_RXMF				(1 << 6)
14662306a36Sopenharmony_ci#define RXFSHR_RXUF				(1 << 5)
14762306a36Sopenharmony_ci#define RXFSHR_RXMR				(1 << 4)
14862306a36Sopenharmony_ci#define RXFSHR_RXFT				(1 << 3)
14962306a36Sopenharmony_ci#define RXFSHR_RXFTL				(1 << 2)
15062306a36Sopenharmony_ci#define RXFSHR_RXRF				(1 << 1)
15162306a36Sopenharmony_ci#define RXFSHR_RXCE				(1 << 0)
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ci#define KS_RXFHBCR				0x7E
15462306a36Sopenharmony_ci#define RXFHBCR_CNT_MASK			(0xfff << 0)
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci#define KS_TXQCR				0x80
15762306a36Sopenharmony_ci#define TXQCR_AETFE				(1 << 2)    /* KSZ8851SNL    */
15862306a36Sopenharmony_ci#define TXQCR_TXQMAM				(1 << 1)
15962306a36Sopenharmony_ci#define TXQCR_METFE				(1 << 0)
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci#define KS_RXQCR				0x82
16262306a36Sopenharmony_ci#define RXQCR_RXDTTS				(1 << 12)
16362306a36Sopenharmony_ci#define RXQCR_RXDBCTS				(1 << 11)
16462306a36Sopenharmony_ci#define RXQCR_RXFCTS				(1 << 10)
16562306a36Sopenharmony_ci#define RXQCR_RXIPHTOE				(1 << 9)
16662306a36Sopenharmony_ci#define RXQCR_RXDTTE				(1 << 7)
16762306a36Sopenharmony_ci#define RXQCR_RXDBCTE				(1 << 6)
16862306a36Sopenharmony_ci#define RXQCR_RXFCTE				(1 << 5)
16962306a36Sopenharmony_ci#define RXQCR_ADRFE				(1 << 4)
17062306a36Sopenharmony_ci#define RXQCR_SDA				(1 << 3)
17162306a36Sopenharmony_ci#define RXQCR_RRXEF				(1 << 0)
17262306a36Sopenharmony_ci
17362306a36Sopenharmony_ci#define KS_TXFDPR				0x84
17462306a36Sopenharmony_ci#define TXFDPR_TXFPAI				(1 << 14)
17562306a36Sopenharmony_ci#define TXFDPR_TXFP_MASK			(0x7ff << 0)
17662306a36Sopenharmony_ci#define TXFDPR_TXFP_SHIFT			(0)
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci#define KS_RXFDPR				0x86
17962306a36Sopenharmony_ci#define RXFDPR_RXFPAI				(1 << 14)
18062306a36Sopenharmony_ci#define RXFDPR_WST				(1 << 12)   /* KSZ8851-16MLL */
18162306a36Sopenharmony_ci#define RXFDPR_EMS				(1 << 11)   /* KSZ8851-16MLL */
18262306a36Sopenharmony_ci#define RXFDPR_RXFP_MASK			(0x7ff << 0)
18362306a36Sopenharmony_ci#define RXFDPR_RXFP_SHIFT			(0)
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci#define KS_RXDTTR				0x8C
18662306a36Sopenharmony_ci#define KS_RXDBCTR				0x8E
18762306a36Sopenharmony_ci
18862306a36Sopenharmony_ci#define KS_IER					0x90
18962306a36Sopenharmony_ci#define KS_ISR					0x92
19062306a36Sopenharmony_ci#define IRQ_LCI					(1 << 15)
19162306a36Sopenharmony_ci#define IRQ_TXI					(1 << 14)
19262306a36Sopenharmony_ci#define IRQ_RXI					(1 << 13)
19362306a36Sopenharmony_ci#define IRQ_RXOI				(1 << 11)
19462306a36Sopenharmony_ci#define IRQ_TXPSI				(1 << 9)
19562306a36Sopenharmony_ci#define IRQ_RXPSI				(1 << 8)
19662306a36Sopenharmony_ci#define IRQ_TXSAI				(1 << 6)
19762306a36Sopenharmony_ci#define IRQ_RXWFDI				(1 << 5)
19862306a36Sopenharmony_ci#define IRQ_RXMPDI				(1 << 4)
19962306a36Sopenharmony_ci#define IRQ_LDI					(1 << 3)
20062306a36Sopenharmony_ci#define IRQ_EDI					(1 << 2)
20162306a36Sopenharmony_ci#define IRQ_SPIBEI				(1 << 1)    /* KSZ8851SNL    */
20262306a36Sopenharmony_ci#define IRQ_DEDI				(1 << 0)
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci#define KS_RXFCTR				0x9C
20562306a36Sopenharmony_ci#define KS_RXFC					0x9D
20662306a36Sopenharmony_ci#define RXFCTR_RXFC_MASK			(0xff << 8)
20762306a36Sopenharmony_ci#define RXFCTR_RXFC_SHIFT			(8)
20862306a36Sopenharmony_ci#define RXFCTR_RXFC_GET(_v)			(((_v) >> 8) & 0xff)
20962306a36Sopenharmony_ci#define RXFCTR_RXFCT_MASK			(0xff << 0)
21062306a36Sopenharmony_ci#define RXFCTR_RXFCT_SHIFT			(0)
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_ci#define KS_TXNTFSR				0x9E
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_ci#define KS_MAHTR0				0xA0
21562306a36Sopenharmony_ci#define KS_MAHTR1				0xA2
21662306a36Sopenharmony_ci#define KS_MAHTR2				0xA4
21762306a36Sopenharmony_ci#define KS_MAHTR3				0xA6
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci#define KS_FCLWR				0xB0
22062306a36Sopenharmony_ci#define KS_FCHWR				0xB2
22162306a36Sopenharmony_ci#define KS_FCOWR				0xB4
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ci#define KS_CIDER				0xC0
22462306a36Sopenharmony_ci#define CIDER_ID				0x8870
22562306a36Sopenharmony_ci#define CIDER_REV_MASK				(0x7 << 1)
22662306a36Sopenharmony_ci#define CIDER_REV_SHIFT				(1)
22762306a36Sopenharmony_ci#define CIDER_REV_GET(_v)			(((_v) >> 1) & 0x7)
22862306a36Sopenharmony_ci
22962306a36Sopenharmony_ci#define KS_CGCR					0xC6
23062306a36Sopenharmony_ci
23162306a36Sopenharmony_ci#define KS_IACR					0xC8
23262306a36Sopenharmony_ci#define IACR_RDEN				(1 << 12)
23362306a36Sopenharmony_ci#define IACR_TSEL_MASK				(0x3 << 10)
23462306a36Sopenharmony_ci#define IACR_TSEL_SHIFT				(10)
23562306a36Sopenharmony_ci#define IACR_TSEL_MIB				(0x3 << 10)
23662306a36Sopenharmony_ci#define IACR_ADDR_MASK				(0x1f << 0)
23762306a36Sopenharmony_ci#define IACR_ADDR_SHIFT				(0)
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_ci#define KS_IADLR				0xD0
24062306a36Sopenharmony_ci#define KS_IAHDR				0xD2
24162306a36Sopenharmony_ci
24262306a36Sopenharmony_ci#define KS_PMECR				0xD4
24362306a36Sopenharmony_ci#define PMECR_PME_DELAY				(1 << 14)
24462306a36Sopenharmony_ci#define PMECR_PME_POL				(1 << 12)
24562306a36Sopenharmony_ci#define PMECR_WOL_WAKEUP			(1 << 11)
24662306a36Sopenharmony_ci#define PMECR_WOL_MAGICPKT			(1 << 10)
24762306a36Sopenharmony_ci#define PMECR_WOL_LINKUP			(1 << 9)
24862306a36Sopenharmony_ci#define PMECR_WOL_ENERGY			(1 << 8)
24962306a36Sopenharmony_ci#define PMECR_AUTO_WAKE_EN			(1 << 7)
25062306a36Sopenharmony_ci#define PMECR_WAKEUP_NORMAL			(1 << 6)
25162306a36Sopenharmony_ci#define PMECR_WKEVT_MASK			(0xf << 2)
25262306a36Sopenharmony_ci#define PMECR_WKEVT_SHIFT			(2)
25362306a36Sopenharmony_ci#define PMECR_WKEVT_GET(_v)			(((_v) >> 2) & 0xf)
25462306a36Sopenharmony_ci#define PMECR_WKEVT_ENERGY			(0x1 << 2)
25562306a36Sopenharmony_ci#define PMECR_WKEVT_LINK			(0x2 << 2)
25662306a36Sopenharmony_ci#define PMECR_WKEVT_MAGICPKT			(0x4 << 2)
25762306a36Sopenharmony_ci#define PMECR_WKEVT_FRAME			(0x8 << 2)
25862306a36Sopenharmony_ci#define PMECR_PM_MASK				(0x3 << 0)
25962306a36Sopenharmony_ci#define PMECR_PM_SHIFT				(0)
26062306a36Sopenharmony_ci#define PMECR_PM_NORMAL				(0x0 << 0)
26162306a36Sopenharmony_ci#define PMECR_PM_ENERGY				(0x1 << 0)
26262306a36Sopenharmony_ci#define PMECR_PM_SOFTDOWN			(0x2 << 0)
26362306a36Sopenharmony_ci#define PMECR_PM_POWERSAVE			(0x3 << 0)
26462306a36Sopenharmony_ci
26562306a36Sopenharmony_ci/* Standard MII PHY data */
26662306a36Sopenharmony_ci#define KS_P1MBCR				0xE4
26762306a36Sopenharmony_ci#define KS_P1MBSR				0xE6
26862306a36Sopenharmony_ci#define KS_PHY1ILR				0xE8
26962306a36Sopenharmony_ci#define KS_PHY1IHR				0xEA
27062306a36Sopenharmony_ci#define KS_P1ANAR				0xEC
27162306a36Sopenharmony_ci#define KS_P1ANLPR				0xEE
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_ci#define KS_P1SCLMD				0xF4
27462306a36Sopenharmony_ci
27562306a36Sopenharmony_ci#define KS_P1CR					0xF6
27662306a36Sopenharmony_ci#define P1CR_LEDOFF				(1 << 15)
27762306a36Sopenharmony_ci#define P1CR_TXIDS				(1 << 14)
27862306a36Sopenharmony_ci#define P1CR_RESTARTAN				(1 << 13)
27962306a36Sopenharmony_ci#define P1CR_DISAUTOMDIX			(1 << 10)
28062306a36Sopenharmony_ci#define P1CR_FORCEMDIX				(1 << 9)
28162306a36Sopenharmony_ci#define P1CR_AUTONEGEN				(1 << 7)
28262306a36Sopenharmony_ci#define P1CR_FORCE100				(1 << 6)
28362306a36Sopenharmony_ci#define P1CR_FORCEFDX				(1 << 5)
28462306a36Sopenharmony_ci#define P1CR_ADV_FLOW				(1 << 4)
28562306a36Sopenharmony_ci#define P1CR_ADV_100BT_FDX			(1 << 3)
28662306a36Sopenharmony_ci#define P1CR_ADV_100BT_HDX			(1 << 2)
28762306a36Sopenharmony_ci#define P1CR_ADV_10BT_FDX			(1 << 1)
28862306a36Sopenharmony_ci#define P1CR_ADV_10BT_HDX			(1 << 0)
28962306a36Sopenharmony_ci
29062306a36Sopenharmony_ci#define KS_P1SR					0xF8
29162306a36Sopenharmony_ci#define P1SR_HP_MDIX				(1 << 15)
29262306a36Sopenharmony_ci#define P1SR_REV_POL				(1 << 13)
29362306a36Sopenharmony_ci#define P1SR_OP_100M				(1 << 10)
29462306a36Sopenharmony_ci#define P1SR_OP_FDX				(1 << 9)
29562306a36Sopenharmony_ci#define P1SR_OP_MDI				(1 << 7)
29662306a36Sopenharmony_ci#define P1SR_AN_DONE				(1 << 6)
29762306a36Sopenharmony_ci#define P1SR_LINK_GOOD				(1 << 5)
29862306a36Sopenharmony_ci#define P1SR_PNTR_FLOW				(1 << 4)
29962306a36Sopenharmony_ci#define P1SR_PNTR_100BT_FDX			(1 << 3)
30062306a36Sopenharmony_ci#define P1SR_PNTR_100BT_HDX			(1 << 2)
30162306a36Sopenharmony_ci#define P1SR_PNTR_10BT_FDX			(1 << 1)
30262306a36Sopenharmony_ci#define P1SR_PNTR_10BT_HDX			(1 << 0)
30362306a36Sopenharmony_ci
30462306a36Sopenharmony_ci/* TX Frame control */
30562306a36Sopenharmony_ci#define TXFR_TXIC				(1 << 15)
30662306a36Sopenharmony_ci#define TXFR_TXFID_MASK				(0x3f << 0)
30762306a36Sopenharmony_ci#define TXFR_TXFID_SHIFT			(0)
30862306a36Sopenharmony_ci
30962306a36Sopenharmony_ci/**
31062306a36Sopenharmony_ci * struct ks8851_rxctrl - KS8851 driver rx control
31162306a36Sopenharmony_ci * @mchash: Multicast hash-table data.
31262306a36Sopenharmony_ci * @rxcr1: KS_RXCR1 register setting
31362306a36Sopenharmony_ci * @rxcr2: KS_RXCR2 register setting
31462306a36Sopenharmony_ci *
31562306a36Sopenharmony_ci * Representation of the settings needs to control the receive filtering
31662306a36Sopenharmony_ci * such as the multicast hash-filter and the receive register settings. This
31762306a36Sopenharmony_ci * is used to make the job of working out if the receive settings change and
31862306a36Sopenharmony_ci * then issuing the new settings to the worker that will send the necessary
31962306a36Sopenharmony_ci * commands.
32062306a36Sopenharmony_ci */
32162306a36Sopenharmony_cistruct ks8851_rxctrl {
32262306a36Sopenharmony_ci	u16	mchash[4];
32362306a36Sopenharmony_ci	u16	rxcr1;
32462306a36Sopenharmony_ci	u16	rxcr2;
32562306a36Sopenharmony_ci};
32662306a36Sopenharmony_ci
32762306a36Sopenharmony_ci/**
32862306a36Sopenharmony_ci * union ks8851_tx_hdr - tx header data
32962306a36Sopenharmony_ci * @txb: The header as bytes
33062306a36Sopenharmony_ci * @txw: The header as 16bit, little-endian words
33162306a36Sopenharmony_ci *
33262306a36Sopenharmony_ci * A dual representation of the tx header data to allow
33362306a36Sopenharmony_ci * access to individual bytes, and to allow 16bit accesses
33462306a36Sopenharmony_ci * with 16bit alignment.
33562306a36Sopenharmony_ci */
33662306a36Sopenharmony_ciunion ks8851_tx_hdr {
33762306a36Sopenharmony_ci	u8	txb[6];
33862306a36Sopenharmony_ci	__le16	txw[3];
33962306a36Sopenharmony_ci};
34062306a36Sopenharmony_ci
34162306a36Sopenharmony_ci/**
34262306a36Sopenharmony_ci * struct ks8851_net - KS8851 driver private data
34362306a36Sopenharmony_ci * @netdev: The network device we're bound to
34462306a36Sopenharmony_ci * @statelock: Lock on this structure for tx list.
34562306a36Sopenharmony_ci * @mii: The MII state information for the mii calls.
34662306a36Sopenharmony_ci * @rxctrl: RX settings for @rxctrl_work.
34762306a36Sopenharmony_ci * @rxctrl_work: Work queue for updating RX mode and multicast lists
34862306a36Sopenharmony_ci * @txq: Queue of packets for transmission.
34962306a36Sopenharmony_ci * @txh: Space for generating packet TX header in DMA-able data
35062306a36Sopenharmony_ci * @rxd: Space for receiving SPI data, in DMA-able space.
35162306a36Sopenharmony_ci * @txd: Space for transmitting SPI data, in DMA-able space.
35262306a36Sopenharmony_ci * @msg_enable: The message flags controlling driver output (see ethtool).
35362306a36Sopenharmony_ci * @tx_space: Free space in the hardware TX buffer (cached copy of KS_TXMIR).
35462306a36Sopenharmony_ci * @queued_len: Space required in hardware TX buffer for queued packets in txq.
35562306a36Sopenharmony_ci * @fid: Incrementing frame id tag.
35662306a36Sopenharmony_ci * @rc_ier: Cached copy of KS_IER.
35762306a36Sopenharmony_ci * @rc_ccr: Cached copy of KS_CCR.
35862306a36Sopenharmony_ci * @rc_rxqcr: Cached copy of KS_RXQCR.
35962306a36Sopenharmony_ci * @eeprom: 93CX6 EEPROM state for accessing on-board EEPROM.
36062306a36Sopenharmony_ci * @vdd_reg:	Optional regulator supplying the chip
36162306a36Sopenharmony_ci * @vdd_io: Optional digital power supply for IO
36262306a36Sopenharmony_ci * @gpio: Optional reset_n gpio
36362306a36Sopenharmony_ci * @mii_bus: Pointer to MII bus structure
36462306a36Sopenharmony_ci * @lock: Bus access lock callback
36562306a36Sopenharmony_ci * @unlock: Bus access unlock callback
36662306a36Sopenharmony_ci * @rdreg16: 16bit register read callback
36762306a36Sopenharmony_ci * @wrreg16: 16bit register write callback
36862306a36Sopenharmony_ci * @rdfifo: FIFO read callback
36962306a36Sopenharmony_ci * @wrfifo: FIFO write callback
37062306a36Sopenharmony_ci * @start_xmit: start_xmit() implementation callback
37162306a36Sopenharmony_ci * @rx_skb: rx_skb() implementation callback
37262306a36Sopenharmony_ci * @flush_tx_work: flush_tx_work() implementation callback
37362306a36Sopenharmony_ci *
37462306a36Sopenharmony_ci * The @statelock is used to protect information in the structure which may
37562306a36Sopenharmony_ci * need to be accessed via several sources, such as the network driver layer
37662306a36Sopenharmony_ci * or one of the work queues.
37762306a36Sopenharmony_ci *
37862306a36Sopenharmony_ci * We align the buffers we may use for rx/tx to ensure that if the SPI driver
37962306a36Sopenharmony_ci * wants to DMA map them, it will not have any problems with data the driver
38062306a36Sopenharmony_ci * modifies.
38162306a36Sopenharmony_ci */
38262306a36Sopenharmony_cistruct ks8851_net {
38362306a36Sopenharmony_ci	struct net_device	*netdev;
38462306a36Sopenharmony_ci	spinlock_t		statelock;
38562306a36Sopenharmony_ci
38662306a36Sopenharmony_ci	union ks8851_tx_hdr	txh ____cacheline_aligned;
38762306a36Sopenharmony_ci	u8			rxd[8];
38862306a36Sopenharmony_ci	u8			txd[8];
38962306a36Sopenharmony_ci
39062306a36Sopenharmony_ci	u32			msg_enable ____cacheline_aligned;
39162306a36Sopenharmony_ci	u16			tx_space;
39262306a36Sopenharmony_ci	u8			fid;
39362306a36Sopenharmony_ci
39462306a36Sopenharmony_ci	u16			rc_ier;
39562306a36Sopenharmony_ci	u16			rc_rxqcr;
39662306a36Sopenharmony_ci	u16			rc_ccr;
39762306a36Sopenharmony_ci
39862306a36Sopenharmony_ci	struct mii_if_info	mii;
39962306a36Sopenharmony_ci	struct ks8851_rxctrl	rxctrl;
40062306a36Sopenharmony_ci
40162306a36Sopenharmony_ci	struct work_struct	rxctrl_work;
40262306a36Sopenharmony_ci
40362306a36Sopenharmony_ci	struct sk_buff_head	txq;
40462306a36Sopenharmony_ci	unsigned int		queued_len;
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_ci	struct eeprom_93cx6	eeprom;
40762306a36Sopenharmony_ci	struct regulator	*vdd_reg;
40862306a36Sopenharmony_ci	struct regulator	*vdd_io;
40962306a36Sopenharmony_ci	struct gpio_desc	*gpio;
41062306a36Sopenharmony_ci	struct mii_bus		*mii_bus;
41162306a36Sopenharmony_ci
41262306a36Sopenharmony_ci	void			(*lock)(struct ks8851_net *ks,
41362306a36Sopenharmony_ci					unsigned long *flags);
41462306a36Sopenharmony_ci	void			(*unlock)(struct ks8851_net *ks,
41562306a36Sopenharmony_ci					  unsigned long *flags);
41662306a36Sopenharmony_ci	unsigned int		(*rdreg16)(struct ks8851_net *ks,
41762306a36Sopenharmony_ci					   unsigned int reg);
41862306a36Sopenharmony_ci	void			(*wrreg16)(struct ks8851_net *ks,
41962306a36Sopenharmony_ci					   unsigned int reg, unsigned int val);
42062306a36Sopenharmony_ci	void			(*rdfifo)(struct ks8851_net *ks, u8 *buff,
42162306a36Sopenharmony_ci					  unsigned int len);
42262306a36Sopenharmony_ci	void			(*wrfifo)(struct ks8851_net *ks,
42362306a36Sopenharmony_ci					  struct sk_buff *txp, bool irq);
42462306a36Sopenharmony_ci	netdev_tx_t		(*start_xmit)(struct sk_buff *skb,
42562306a36Sopenharmony_ci					      struct net_device *dev);
42662306a36Sopenharmony_ci	void			(*rx_skb)(struct ks8851_net *ks,
42762306a36Sopenharmony_ci					  struct sk_buff *skb);
42862306a36Sopenharmony_ci	void			(*flush_tx_work)(struct ks8851_net *ks);
42962306a36Sopenharmony_ci};
43062306a36Sopenharmony_ci
43162306a36Sopenharmony_ciint ks8851_probe_common(struct net_device *netdev, struct device *dev,
43262306a36Sopenharmony_ci			int msg_en);
43362306a36Sopenharmony_civoid ks8851_remove_common(struct device *dev);
43462306a36Sopenharmony_ciint ks8851_suspend(struct device *dev);
43562306a36Sopenharmony_ciint ks8851_resume(struct device *dev);
43662306a36Sopenharmony_ci
43762306a36Sopenharmony_cistatic __maybe_unused SIMPLE_DEV_PM_OPS(ks8851_pm_ops,
43862306a36Sopenharmony_ci					ks8851_suspend, ks8851_resume);
43962306a36Sopenharmony_ci
44062306a36Sopenharmony_ci/**
44162306a36Sopenharmony_ci * ks8851_done_tx - update and then free skbuff after transmitting
44262306a36Sopenharmony_ci * @ks: The device state
44362306a36Sopenharmony_ci * @txb: The buffer transmitted
44462306a36Sopenharmony_ci */
44562306a36Sopenharmony_cistatic void __maybe_unused ks8851_done_tx(struct ks8851_net *ks,
44662306a36Sopenharmony_ci					  struct sk_buff *txb)
44762306a36Sopenharmony_ci{
44862306a36Sopenharmony_ci	struct net_device *dev = ks->netdev;
44962306a36Sopenharmony_ci
45062306a36Sopenharmony_ci	dev->stats.tx_bytes += txb->len;
45162306a36Sopenharmony_ci	dev->stats.tx_packets++;
45262306a36Sopenharmony_ci
45362306a36Sopenharmony_ci	dev_kfree_skb(txb);
45462306a36Sopenharmony_ci}
45562306a36Sopenharmony_ci
45662306a36Sopenharmony_ci#endif /* __KS8851_H__ */
457