18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */
28c2ecf20Sopenharmony_ci/* drivers/net/ethernet/micrel/ks8851.h
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright 2009 Simtec Electronics
58c2ecf20Sopenharmony_ci *      Ben Dooks <ben@simtec.co.uk>
68c2ecf20Sopenharmony_ci *
78c2ecf20Sopenharmony_ci * KS8851 register definitions
88c2ecf20Sopenharmony_ci*/
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci#ifndef __KS8851_H__
118c2ecf20Sopenharmony_ci#define __KS8851_H__
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#include <linux/eeprom_93cx6.h>
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_ci#define KS_CCR					0x08
168c2ecf20Sopenharmony_ci#define CCR_LE					(1 << 10)   /* KSZ8851-16MLL */
178c2ecf20Sopenharmony_ci#define CCR_EEPROM				(1 << 9)
188c2ecf20Sopenharmony_ci#define CCR_SPI					(1 << 8)    /* KSZ8851SNL    */
198c2ecf20Sopenharmony_ci#define CCR_8BIT				(1 << 7)    /* KSZ8851-16MLL */
208c2ecf20Sopenharmony_ci#define CCR_16BIT				(1 << 6)    /* KSZ8851-16MLL */
218c2ecf20Sopenharmony_ci#define CCR_32BIT				(1 << 5)    /* KSZ8851-16MLL */
228c2ecf20Sopenharmony_ci#define CCR_SHARED				(1 << 4)    /* KSZ8851-16MLL */
238c2ecf20Sopenharmony_ci#define CCR_48PIN				(1 << 1)    /* KSZ8851-16MLL */
248c2ecf20Sopenharmony_ci#define CCR_32PIN				(1 << 0)    /* KSZ8851SNL    */
258c2ecf20Sopenharmony_ci
268c2ecf20Sopenharmony_ci/* MAC address registers */
278c2ecf20Sopenharmony_ci#define KS_MAR(_m)				(0x14 - (_m))
288c2ecf20Sopenharmony_ci#define KS_MARL					0x10
298c2ecf20Sopenharmony_ci#define KS_MARM					0x12
308c2ecf20Sopenharmony_ci#define KS_MARH					0x14
318c2ecf20Sopenharmony_ci
328c2ecf20Sopenharmony_ci#define KS_OBCR					0x20
338c2ecf20Sopenharmony_ci#define OBCR_ODS_16mA				(1 << 6)
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#define KS_EEPCR				0x22
368c2ecf20Sopenharmony_ci#define EEPCR_EESRWA				(1 << 5)
378c2ecf20Sopenharmony_ci#define EEPCR_EESA				(1 << 4)
388c2ecf20Sopenharmony_ci#define EEPCR_EESB				(1 << 3)
398c2ecf20Sopenharmony_ci#define EEPCR_EEDO				(1 << 2)
408c2ecf20Sopenharmony_ci#define EEPCR_EESCK				(1 << 1)
418c2ecf20Sopenharmony_ci#define EEPCR_EECS				(1 << 0)
428c2ecf20Sopenharmony_ci
438c2ecf20Sopenharmony_ci#define KS_MBIR					0x24
448c2ecf20Sopenharmony_ci#define MBIR_TXMBF				(1 << 12)
458c2ecf20Sopenharmony_ci#define MBIR_TXMBFA				(1 << 11)
468c2ecf20Sopenharmony_ci#define MBIR_RXMBF				(1 << 4)
478c2ecf20Sopenharmony_ci#define MBIR_RXMBFA				(1 << 3)
488c2ecf20Sopenharmony_ci
498c2ecf20Sopenharmony_ci#define KS_GRR					0x26
508c2ecf20Sopenharmony_ci#define GRR_QMU					(1 << 1)
518c2ecf20Sopenharmony_ci#define GRR_GSR					(1 << 0)
528c2ecf20Sopenharmony_ci
538c2ecf20Sopenharmony_ci#define KS_WFCR					0x2A
548c2ecf20Sopenharmony_ci#define WFCR_MPRXE				(1 << 7)
558c2ecf20Sopenharmony_ci#define WFCR_WF3E				(1 << 3)
568c2ecf20Sopenharmony_ci#define WFCR_WF2E				(1 << 2)
578c2ecf20Sopenharmony_ci#define WFCR_WF1E				(1 << 1)
588c2ecf20Sopenharmony_ci#define WFCR_WF0E				(1 << 0)
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ci#define KS_WF0CRC0				0x30
618c2ecf20Sopenharmony_ci#define KS_WF0CRC1				0x32
628c2ecf20Sopenharmony_ci#define KS_WF0BM0				0x34
638c2ecf20Sopenharmony_ci#define KS_WF0BM1				0x36
648c2ecf20Sopenharmony_ci#define KS_WF0BM2				0x38
658c2ecf20Sopenharmony_ci#define KS_WF0BM3				0x3A
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci#define KS_WF1CRC0				0x40
688c2ecf20Sopenharmony_ci#define KS_WF1CRC1				0x42
698c2ecf20Sopenharmony_ci#define KS_WF1BM0				0x44
708c2ecf20Sopenharmony_ci#define KS_WF1BM1				0x46
718c2ecf20Sopenharmony_ci#define KS_WF1BM2				0x48
728c2ecf20Sopenharmony_ci#define KS_WF1BM3				0x4A
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci#define KS_WF2CRC0				0x50
758c2ecf20Sopenharmony_ci#define KS_WF2CRC1				0x52
768c2ecf20Sopenharmony_ci#define KS_WF2BM0				0x54
778c2ecf20Sopenharmony_ci#define KS_WF2BM1				0x56
788c2ecf20Sopenharmony_ci#define KS_WF2BM2				0x58
798c2ecf20Sopenharmony_ci#define KS_WF2BM3				0x5A
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci#define KS_WF3CRC0				0x60
828c2ecf20Sopenharmony_ci#define KS_WF3CRC1				0x62
838c2ecf20Sopenharmony_ci#define KS_WF3BM0				0x64
848c2ecf20Sopenharmony_ci#define KS_WF3BM1				0x66
858c2ecf20Sopenharmony_ci#define KS_WF3BM2				0x68
868c2ecf20Sopenharmony_ci#define KS_WF3BM3				0x6A
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci#define KS_TXCR					0x70
898c2ecf20Sopenharmony_ci#define TXCR_TCGICMP				(1 << 8)
908c2ecf20Sopenharmony_ci#define TXCR_TCGUDP				(1 << 7)
918c2ecf20Sopenharmony_ci#define TXCR_TCGTCP				(1 << 6)
928c2ecf20Sopenharmony_ci#define TXCR_TCGIP				(1 << 5)
938c2ecf20Sopenharmony_ci#define TXCR_FTXQ				(1 << 4)
948c2ecf20Sopenharmony_ci#define TXCR_TXFCE				(1 << 3)
958c2ecf20Sopenharmony_ci#define TXCR_TXPE				(1 << 2)
968c2ecf20Sopenharmony_ci#define TXCR_TXCRC				(1 << 1)
978c2ecf20Sopenharmony_ci#define TXCR_TXE				(1 << 0)
988c2ecf20Sopenharmony_ci
998c2ecf20Sopenharmony_ci#define KS_TXSR					0x72
1008c2ecf20Sopenharmony_ci#define TXSR_TXLC				(1 << 13)
1018c2ecf20Sopenharmony_ci#define TXSR_TXMC				(1 << 12)
1028c2ecf20Sopenharmony_ci#define TXSR_TXFID_MASK				(0x3f << 0)
1038c2ecf20Sopenharmony_ci#define TXSR_TXFID_SHIFT			(0)
1048c2ecf20Sopenharmony_ci#define TXSR_TXFID_GET(_v)			(((_v) >> 0) & 0x3f)
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci#define KS_RXCR1				0x74
1078c2ecf20Sopenharmony_ci#define RXCR1_FRXQ				(1 << 15)
1088c2ecf20Sopenharmony_ci#define RXCR1_RXUDPFCC				(1 << 14)
1098c2ecf20Sopenharmony_ci#define RXCR1_RXTCPFCC				(1 << 13)
1108c2ecf20Sopenharmony_ci#define RXCR1_RXIPFCC				(1 << 12)
1118c2ecf20Sopenharmony_ci#define RXCR1_RXPAFMA				(1 << 11)
1128c2ecf20Sopenharmony_ci#define RXCR1_RXFCE				(1 << 10)
1138c2ecf20Sopenharmony_ci#define RXCR1_RXEFE				(1 << 9)
1148c2ecf20Sopenharmony_ci#define RXCR1_RXMAFMA				(1 << 8)
1158c2ecf20Sopenharmony_ci#define RXCR1_RXBE				(1 << 7)
1168c2ecf20Sopenharmony_ci#define RXCR1_RXME				(1 << 6)
1178c2ecf20Sopenharmony_ci#define RXCR1_RXUE				(1 << 5)
1188c2ecf20Sopenharmony_ci#define RXCR1_RXAE				(1 << 4)
1198c2ecf20Sopenharmony_ci#define RXCR1_RXINVF				(1 << 1)
1208c2ecf20Sopenharmony_ci#define RXCR1_RXE				(1 << 0)
1218c2ecf20Sopenharmony_ci
1228c2ecf20Sopenharmony_ci#define KS_RXCR2				0x76
1238c2ecf20Sopenharmony_ci#define RXCR2_SRDBL_MASK			(0x7 << 5)  /* KSZ8851SNL    */
1248c2ecf20Sopenharmony_ci#define RXCR2_SRDBL_SHIFT			(5)	    /* KSZ8851SNL    */
1258c2ecf20Sopenharmony_ci#define RXCR2_SRDBL_4B				(0x0 << 5)  /* KSZ8851SNL    */
1268c2ecf20Sopenharmony_ci#define RXCR2_SRDBL_8B				(0x1 << 5)  /* KSZ8851SNL    */
1278c2ecf20Sopenharmony_ci#define RXCR2_SRDBL_16B				(0x2 << 5)  /* KSZ8851SNL    */
1288c2ecf20Sopenharmony_ci#define RXCR2_SRDBL_32B				(0x3 << 5)  /* KSZ8851SNL    */
1298c2ecf20Sopenharmony_ci#define RXCR2_SRDBL_FRAME			(0x4 << 5)  /* KSZ8851SNL    */
1308c2ecf20Sopenharmony_ci#define RXCR2_IUFFP				(1 << 4)
1318c2ecf20Sopenharmony_ci#define RXCR2_RXIUFCEZ				(1 << 3)
1328c2ecf20Sopenharmony_ci#define RXCR2_UDPLFE				(1 << 2)
1338c2ecf20Sopenharmony_ci#define RXCR2_RXICMPFCC				(1 << 1)
1348c2ecf20Sopenharmony_ci#define RXCR2_RXSAF				(1 << 0)
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci#define KS_TXMIR				0x78
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_ci#define KS_RXFHSR				0x7C
1398c2ecf20Sopenharmony_ci#define RXFSHR_RXFV				(1 << 15)
1408c2ecf20Sopenharmony_ci#define RXFSHR_RXICMPFCS			(1 << 13)
1418c2ecf20Sopenharmony_ci#define RXFSHR_RXIPFCS				(1 << 12)
1428c2ecf20Sopenharmony_ci#define RXFSHR_RXTCPFCS				(1 << 11)
1438c2ecf20Sopenharmony_ci#define RXFSHR_RXUDPFCS				(1 << 10)
1448c2ecf20Sopenharmony_ci#define RXFSHR_RXBF				(1 << 7)
1458c2ecf20Sopenharmony_ci#define RXFSHR_RXMF				(1 << 6)
1468c2ecf20Sopenharmony_ci#define RXFSHR_RXUF				(1 << 5)
1478c2ecf20Sopenharmony_ci#define RXFSHR_RXMR				(1 << 4)
1488c2ecf20Sopenharmony_ci#define RXFSHR_RXFT				(1 << 3)
1498c2ecf20Sopenharmony_ci#define RXFSHR_RXFTL				(1 << 2)
1508c2ecf20Sopenharmony_ci#define RXFSHR_RXRF				(1 << 1)
1518c2ecf20Sopenharmony_ci#define RXFSHR_RXCE				(1 << 0)
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci#define KS_RXFHBCR				0x7E
1548c2ecf20Sopenharmony_ci#define RXFHBCR_CNT_MASK			(0xfff << 0)
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci#define KS_TXQCR				0x80
1578c2ecf20Sopenharmony_ci#define TXQCR_AETFE				(1 << 2)    /* KSZ8851SNL    */
1588c2ecf20Sopenharmony_ci#define TXQCR_TXQMAM				(1 << 1)
1598c2ecf20Sopenharmony_ci#define TXQCR_METFE				(1 << 0)
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci#define KS_RXQCR				0x82
1628c2ecf20Sopenharmony_ci#define RXQCR_RXDTTS				(1 << 12)
1638c2ecf20Sopenharmony_ci#define RXQCR_RXDBCTS				(1 << 11)
1648c2ecf20Sopenharmony_ci#define RXQCR_RXFCTS				(1 << 10)
1658c2ecf20Sopenharmony_ci#define RXQCR_RXIPHTOE				(1 << 9)
1668c2ecf20Sopenharmony_ci#define RXQCR_RXDTTE				(1 << 7)
1678c2ecf20Sopenharmony_ci#define RXQCR_RXDBCTE				(1 << 6)
1688c2ecf20Sopenharmony_ci#define RXQCR_RXFCTE				(1 << 5)
1698c2ecf20Sopenharmony_ci#define RXQCR_ADRFE				(1 << 4)
1708c2ecf20Sopenharmony_ci#define RXQCR_SDA				(1 << 3)
1718c2ecf20Sopenharmony_ci#define RXQCR_RRXEF				(1 << 0)
1728c2ecf20Sopenharmony_ci
1738c2ecf20Sopenharmony_ci#define KS_TXFDPR				0x84
1748c2ecf20Sopenharmony_ci#define TXFDPR_TXFPAI				(1 << 14)
1758c2ecf20Sopenharmony_ci#define TXFDPR_TXFP_MASK			(0x7ff << 0)
1768c2ecf20Sopenharmony_ci#define TXFDPR_TXFP_SHIFT			(0)
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci#define KS_RXFDPR				0x86
1798c2ecf20Sopenharmony_ci#define RXFDPR_RXFPAI				(1 << 14)
1808c2ecf20Sopenharmony_ci#define RXFDPR_WST				(1 << 12)   /* KSZ8851-16MLL */
1818c2ecf20Sopenharmony_ci#define RXFDPR_EMS				(1 << 11)   /* KSZ8851-16MLL */
1828c2ecf20Sopenharmony_ci#define RXFDPR_RXFP_MASK			(0x7ff << 0)
1838c2ecf20Sopenharmony_ci#define RXFDPR_RXFP_SHIFT			(0)
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci#define KS_RXDTTR				0x8C
1868c2ecf20Sopenharmony_ci#define KS_RXDBCTR				0x8E
1878c2ecf20Sopenharmony_ci
1888c2ecf20Sopenharmony_ci#define KS_IER					0x90
1898c2ecf20Sopenharmony_ci#define KS_ISR					0x92
1908c2ecf20Sopenharmony_ci#define IRQ_LCI					(1 << 15)
1918c2ecf20Sopenharmony_ci#define IRQ_TXI					(1 << 14)
1928c2ecf20Sopenharmony_ci#define IRQ_RXI					(1 << 13)
1938c2ecf20Sopenharmony_ci#define IRQ_RXOI				(1 << 11)
1948c2ecf20Sopenharmony_ci#define IRQ_TXPSI				(1 << 9)
1958c2ecf20Sopenharmony_ci#define IRQ_RXPSI				(1 << 8)
1968c2ecf20Sopenharmony_ci#define IRQ_TXSAI				(1 << 6)
1978c2ecf20Sopenharmony_ci#define IRQ_RXWFDI				(1 << 5)
1988c2ecf20Sopenharmony_ci#define IRQ_RXMPDI				(1 << 4)
1998c2ecf20Sopenharmony_ci#define IRQ_LDI					(1 << 3)
2008c2ecf20Sopenharmony_ci#define IRQ_EDI					(1 << 2)
2018c2ecf20Sopenharmony_ci#define IRQ_SPIBEI				(1 << 1)    /* KSZ8851SNL    */
2028c2ecf20Sopenharmony_ci#define IRQ_DEDI				(1 << 0)
2038c2ecf20Sopenharmony_ci
2048c2ecf20Sopenharmony_ci#define KS_RXFCTR				0x9C
2058c2ecf20Sopenharmony_ci#define KS_RXFC					0x9D
2068c2ecf20Sopenharmony_ci#define RXFCTR_RXFC_MASK			(0xff << 8)
2078c2ecf20Sopenharmony_ci#define RXFCTR_RXFC_SHIFT			(8)
2088c2ecf20Sopenharmony_ci#define RXFCTR_RXFC_GET(_v)			(((_v) >> 8) & 0xff)
2098c2ecf20Sopenharmony_ci#define RXFCTR_RXFCT_MASK			(0xff << 0)
2108c2ecf20Sopenharmony_ci#define RXFCTR_RXFCT_SHIFT			(0)
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci#define KS_TXNTFSR				0x9E
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci#define KS_MAHTR0				0xA0
2158c2ecf20Sopenharmony_ci#define KS_MAHTR1				0xA2
2168c2ecf20Sopenharmony_ci#define KS_MAHTR2				0xA4
2178c2ecf20Sopenharmony_ci#define KS_MAHTR3				0xA6
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci#define KS_FCLWR				0xB0
2208c2ecf20Sopenharmony_ci#define KS_FCHWR				0xB2
2218c2ecf20Sopenharmony_ci#define KS_FCOWR				0xB4
2228c2ecf20Sopenharmony_ci
2238c2ecf20Sopenharmony_ci#define KS_CIDER				0xC0
2248c2ecf20Sopenharmony_ci#define CIDER_ID				0x8870
2258c2ecf20Sopenharmony_ci#define CIDER_REV_MASK				(0x7 << 1)
2268c2ecf20Sopenharmony_ci#define CIDER_REV_SHIFT				(1)
2278c2ecf20Sopenharmony_ci#define CIDER_REV_GET(_v)			(((_v) >> 1) & 0x7)
2288c2ecf20Sopenharmony_ci
2298c2ecf20Sopenharmony_ci#define KS_CGCR					0xC6
2308c2ecf20Sopenharmony_ci
2318c2ecf20Sopenharmony_ci#define KS_IACR					0xC8
2328c2ecf20Sopenharmony_ci#define IACR_RDEN				(1 << 12)
2338c2ecf20Sopenharmony_ci#define IACR_TSEL_MASK				(0x3 << 10)
2348c2ecf20Sopenharmony_ci#define IACR_TSEL_SHIFT				(10)
2358c2ecf20Sopenharmony_ci#define IACR_TSEL_MIB				(0x3 << 10)
2368c2ecf20Sopenharmony_ci#define IACR_ADDR_MASK				(0x1f << 0)
2378c2ecf20Sopenharmony_ci#define IACR_ADDR_SHIFT				(0)
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci#define KS_IADLR				0xD0
2408c2ecf20Sopenharmony_ci#define KS_IAHDR				0xD2
2418c2ecf20Sopenharmony_ci
2428c2ecf20Sopenharmony_ci#define KS_PMECR				0xD4
2438c2ecf20Sopenharmony_ci#define PMECR_PME_DELAY				(1 << 14)
2448c2ecf20Sopenharmony_ci#define PMECR_PME_POL				(1 << 12)
2458c2ecf20Sopenharmony_ci#define PMECR_WOL_WAKEUP			(1 << 11)
2468c2ecf20Sopenharmony_ci#define PMECR_WOL_MAGICPKT			(1 << 10)
2478c2ecf20Sopenharmony_ci#define PMECR_WOL_LINKUP			(1 << 9)
2488c2ecf20Sopenharmony_ci#define PMECR_WOL_ENERGY			(1 << 8)
2498c2ecf20Sopenharmony_ci#define PMECR_AUTO_WAKE_EN			(1 << 7)
2508c2ecf20Sopenharmony_ci#define PMECR_WAKEUP_NORMAL			(1 << 6)
2518c2ecf20Sopenharmony_ci#define PMECR_WKEVT_MASK			(0xf << 2)
2528c2ecf20Sopenharmony_ci#define PMECR_WKEVT_SHIFT			(2)
2538c2ecf20Sopenharmony_ci#define PMECR_WKEVT_GET(_v)			(((_v) >> 2) & 0xf)
2548c2ecf20Sopenharmony_ci#define PMECR_WKEVT_ENERGY			(0x1 << 2)
2558c2ecf20Sopenharmony_ci#define PMECR_WKEVT_LINK			(0x2 << 2)
2568c2ecf20Sopenharmony_ci#define PMECR_WKEVT_MAGICPKT			(0x4 << 2)
2578c2ecf20Sopenharmony_ci#define PMECR_WKEVT_FRAME			(0x8 << 2)
2588c2ecf20Sopenharmony_ci#define PMECR_PM_MASK				(0x3 << 0)
2598c2ecf20Sopenharmony_ci#define PMECR_PM_SHIFT				(0)
2608c2ecf20Sopenharmony_ci#define PMECR_PM_NORMAL				(0x0 << 0)
2618c2ecf20Sopenharmony_ci#define PMECR_PM_ENERGY				(0x1 << 0)
2628c2ecf20Sopenharmony_ci#define PMECR_PM_SOFTDOWN			(0x2 << 0)
2638c2ecf20Sopenharmony_ci#define PMECR_PM_POWERSAVE			(0x3 << 0)
2648c2ecf20Sopenharmony_ci
2658c2ecf20Sopenharmony_ci/* Standard MII PHY data */
2668c2ecf20Sopenharmony_ci#define KS_P1MBCR				0xE4
2678c2ecf20Sopenharmony_ci#define KS_P1MBSR				0xE6
2688c2ecf20Sopenharmony_ci#define KS_PHY1ILR				0xE8
2698c2ecf20Sopenharmony_ci#define KS_PHY1IHR				0xEA
2708c2ecf20Sopenharmony_ci#define KS_P1ANAR				0xEC
2718c2ecf20Sopenharmony_ci#define KS_P1ANLPR				0xEE
2728c2ecf20Sopenharmony_ci
2738c2ecf20Sopenharmony_ci#define KS_P1SCLMD				0xF4
2748c2ecf20Sopenharmony_ci
2758c2ecf20Sopenharmony_ci#define KS_P1CR					0xF6
2768c2ecf20Sopenharmony_ci#define P1CR_LEDOFF				(1 << 15)
2778c2ecf20Sopenharmony_ci#define P1CR_TXIDS				(1 << 14)
2788c2ecf20Sopenharmony_ci#define P1CR_RESTARTAN				(1 << 13)
2798c2ecf20Sopenharmony_ci#define P1CR_DISAUTOMDIX			(1 << 10)
2808c2ecf20Sopenharmony_ci#define P1CR_FORCEMDIX				(1 << 9)
2818c2ecf20Sopenharmony_ci#define P1CR_AUTONEGEN				(1 << 7)
2828c2ecf20Sopenharmony_ci#define P1CR_FORCE100				(1 << 6)
2838c2ecf20Sopenharmony_ci#define P1CR_FORCEFDX				(1 << 5)
2848c2ecf20Sopenharmony_ci#define P1CR_ADV_FLOW				(1 << 4)
2858c2ecf20Sopenharmony_ci#define P1CR_ADV_100BT_FDX			(1 << 3)
2868c2ecf20Sopenharmony_ci#define P1CR_ADV_100BT_HDX			(1 << 2)
2878c2ecf20Sopenharmony_ci#define P1CR_ADV_10BT_FDX			(1 << 1)
2888c2ecf20Sopenharmony_ci#define P1CR_ADV_10BT_HDX			(1 << 0)
2898c2ecf20Sopenharmony_ci
2908c2ecf20Sopenharmony_ci#define KS_P1SR					0xF8
2918c2ecf20Sopenharmony_ci#define P1SR_HP_MDIX				(1 << 15)
2928c2ecf20Sopenharmony_ci#define P1SR_REV_POL				(1 << 13)
2938c2ecf20Sopenharmony_ci#define P1SR_OP_100M				(1 << 10)
2948c2ecf20Sopenharmony_ci#define P1SR_OP_FDX				(1 << 9)
2958c2ecf20Sopenharmony_ci#define P1SR_OP_MDI				(1 << 7)
2968c2ecf20Sopenharmony_ci#define P1SR_AN_DONE				(1 << 6)
2978c2ecf20Sopenharmony_ci#define P1SR_LINK_GOOD				(1 << 5)
2988c2ecf20Sopenharmony_ci#define P1SR_PNTR_FLOW				(1 << 4)
2998c2ecf20Sopenharmony_ci#define P1SR_PNTR_100BT_FDX			(1 << 3)
3008c2ecf20Sopenharmony_ci#define P1SR_PNTR_100BT_HDX			(1 << 2)
3018c2ecf20Sopenharmony_ci#define P1SR_PNTR_10BT_FDX			(1 << 1)
3028c2ecf20Sopenharmony_ci#define P1SR_PNTR_10BT_HDX			(1 << 0)
3038c2ecf20Sopenharmony_ci
3048c2ecf20Sopenharmony_ci/* TX Frame control */
3058c2ecf20Sopenharmony_ci#define TXFR_TXIC				(1 << 15)
3068c2ecf20Sopenharmony_ci#define TXFR_TXFID_MASK				(0x3f << 0)
3078c2ecf20Sopenharmony_ci#define TXFR_TXFID_SHIFT			(0)
3088c2ecf20Sopenharmony_ci
3098c2ecf20Sopenharmony_ci/**
3108c2ecf20Sopenharmony_ci * struct ks8851_rxctrl - KS8851 driver rx control
3118c2ecf20Sopenharmony_ci * @mchash: Multicast hash-table data.
3128c2ecf20Sopenharmony_ci * @rxcr1: KS_RXCR1 register setting
3138c2ecf20Sopenharmony_ci * @rxcr2: KS_RXCR2 register setting
3148c2ecf20Sopenharmony_ci *
3158c2ecf20Sopenharmony_ci * Representation of the settings needs to control the receive filtering
3168c2ecf20Sopenharmony_ci * such as the multicast hash-filter and the receive register settings. This
3178c2ecf20Sopenharmony_ci * is used to make the job of working out if the receive settings change and
3188c2ecf20Sopenharmony_ci * then issuing the new settings to the worker that will send the necessary
3198c2ecf20Sopenharmony_ci * commands.
3208c2ecf20Sopenharmony_ci */
3218c2ecf20Sopenharmony_cistruct ks8851_rxctrl {
3228c2ecf20Sopenharmony_ci	u16	mchash[4];
3238c2ecf20Sopenharmony_ci	u16	rxcr1;
3248c2ecf20Sopenharmony_ci	u16	rxcr2;
3258c2ecf20Sopenharmony_ci};
3268c2ecf20Sopenharmony_ci
3278c2ecf20Sopenharmony_ci/**
3288c2ecf20Sopenharmony_ci * union ks8851_tx_hdr - tx header data
3298c2ecf20Sopenharmony_ci * @txb: The header as bytes
3308c2ecf20Sopenharmony_ci * @txw: The header as 16bit, little-endian words
3318c2ecf20Sopenharmony_ci *
3328c2ecf20Sopenharmony_ci * A dual representation of the tx header data to allow
3338c2ecf20Sopenharmony_ci * access to individual bytes, and to allow 16bit accesses
3348c2ecf20Sopenharmony_ci * with 16bit alignment.
3358c2ecf20Sopenharmony_ci */
3368c2ecf20Sopenharmony_ciunion ks8851_tx_hdr {
3378c2ecf20Sopenharmony_ci	u8	txb[6];
3388c2ecf20Sopenharmony_ci	__le16	txw[3];
3398c2ecf20Sopenharmony_ci};
3408c2ecf20Sopenharmony_ci
3418c2ecf20Sopenharmony_ci/**
3428c2ecf20Sopenharmony_ci * struct ks8851_net - KS8851 driver private data
3438c2ecf20Sopenharmony_ci * @netdev: The network device we're bound to
3448c2ecf20Sopenharmony_ci * @statelock: Lock on this structure for tx list.
3458c2ecf20Sopenharmony_ci * @mii: The MII state information for the mii calls.
3468c2ecf20Sopenharmony_ci * @rxctrl: RX settings for @rxctrl_work.
3478c2ecf20Sopenharmony_ci * @rxctrl_work: Work queue for updating RX mode and multicast lists
3488c2ecf20Sopenharmony_ci * @txq: Queue of packets for transmission.
3498c2ecf20Sopenharmony_ci * @txh: Space for generating packet TX header in DMA-able data
3508c2ecf20Sopenharmony_ci * @rxd: Space for receiving SPI data, in DMA-able space.
3518c2ecf20Sopenharmony_ci * @txd: Space for transmitting SPI data, in DMA-able space.
3528c2ecf20Sopenharmony_ci * @msg_enable: The message flags controlling driver output (see ethtool).
3538c2ecf20Sopenharmony_ci * @tx_space: Free space in the hardware TX buffer (cached copy of KS_TXMIR).
3548c2ecf20Sopenharmony_ci * @queued_len: Space required in hardware TX buffer for queued packets in txq.
3558c2ecf20Sopenharmony_ci * @fid: Incrementing frame id tag.
3568c2ecf20Sopenharmony_ci * @rc_ier: Cached copy of KS_IER.
3578c2ecf20Sopenharmony_ci * @rc_ccr: Cached copy of KS_CCR.
3588c2ecf20Sopenharmony_ci * @rc_rxqcr: Cached copy of KS_RXQCR.
3598c2ecf20Sopenharmony_ci * @eeprom: 93CX6 EEPROM state for accessing on-board EEPROM.
3608c2ecf20Sopenharmony_ci * @vdd_reg:	Optional regulator supplying the chip
3618c2ecf20Sopenharmony_ci * @vdd_io: Optional digital power supply for IO
3628c2ecf20Sopenharmony_ci * @gpio: Optional reset_n gpio
3638c2ecf20Sopenharmony_ci * @lock: Bus access lock callback
3648c2ecf20Sopenharmony_ci * @unlock: Bus access unlock callback
3658c2ecf20Sopenharmony_ci * @rdreg16: 16bit register read callback
3668c2ecf20Sopenharmony_ci * @wrreg16: 16bit register write callback
3678c2ecf20Sopenharmony_ci * @rdfifo: FIFO read callback
3688c2ecf20Sopenharmony_ci * @wrfifo: FIFO write callback
3698c2ecf20Sopenharmony_ci * @start_xmit: start_xmit() implementation callback
3708c2ecf20Sopenharmony_ci * @rx_skb: rx_skb() implementation callback
3718c2ecf20Sopenharmony_ci * @flush_tx_work: flush_tx_work() implementation callback
3728c2ecf20Sopenharmony_ci *
3738c2ecf20Sopenharmony_ci * The @statelock is used to protect information in the structure which may
3748c2ecf20Sopenharmony_ci * need to be accessed via several sources, such as the network driver layer
3758c2ecf20Sopenharmony_ci * or one of the work queues.
3768c2ecf20Sopenharmony_ci *
3778c2ecf20Sopenharmony_ci * We align the buffers we may use for rx/tx to ensure that if the SPI driver
3788c2ecf20Sopenharmony_ci * wants to DMA map them, it will not have any problems with data the driver
3798c2ecf20Sopenharmony_ci * modifies.
3808c2ecf20Sopenharmony_ci */
3818c2ecf20Sopenharmony_cistruct ks8851_net {
3828c2ecf20Sopenharmony_ci	struct net_device	*netdev;
3838c2ecf20Sopenharmony_ci	spinlock_t		statelock;
3848c2ecf20Sopenharmony_ci
3858c2ecf20Sopenharmony_ci	union ks8851_tx_hdr	txh ____cacheline_aligned;
3868c2ecf20Sopenharmony_ci	u8			rxd[8];
3878c2ecf20Sopenharmony_ci	u8			txd[8];
3888c2ecf20Sopenharmony_ci
3898c2ecf20Sopenharmony_ci	u32			msg_enable ____cacheline_aligned;
3908c2ecf20Sopenharmony_ci	u16			tx_space;
3918c2ecf20Sopenharmony_ci	u8			fid;
3928c2ecf20Sopenharmony_ci
3938c2ecf20Sopenharmony_ci	u16			rc_ier;
3948c2ecf20Sopenharmony_ci	u16			rc_rxqcr;
3958c2ecf20Sopenharmony_ci	u16			rc_ccr;
3968c2ecf20Sopenharmony_ci
3978c2ecf20Sopenharmony_ci	struct mii_if_info	mii;
3988c2ecf20Sopenharmony_ci	struct ks8851_rxctrl	rxctrl;
3998c2ecf20Sopenharmony_ci
4008c2ecf20Sopenharmony_ci	struct work_struct	rxctrl_work;
4018c2ecf20Sopenharmony_ci
4028c2ecf20Sopenharmony_ci	struct sk_buff_head	txq;
4038c2ecf20Sopenharmony_ci	unsigned int		queued_len;
4048c2ecf20Sopenharmony_ci
4058c2ecf20Sopenharmony_ci	struct eeprom_93cx6	eeprom;
4068c2ecf20Sopenharmony_ci	struct regulator	*vdd_reg;
4078c2ecf20Sopenharmony_ci	struct regulator	*vdd_io;
4088c2ecf20Sopenharmony_ci	int			gpio;
4098c2ecf20Sopenharmony_ci
4108c2ecf20Sopenharmony_ci	void			(*lock)(struct ks8851_net *ks,
4118c2ecf20Sopenharmony_ci					unsigned long *flags);
4128c2ecf20Sopenharmony_ci	void			(*unlock)(struct ks8851_net *ks,
4138c2ecf20Sopenharmony_ci					  unsigned long *flags);
4148c2ecf20Sopenharmony_ci	unsigned int		(*rdreg16)(struct ks8851_net *ks,
4158c2ecf20Sopenharmony_ci					   unsigned int reg);
4168c2ecf20Sopenharmony_ci	void			(*wrreg16)(struct ks8851_net *ks,
4178c2ecf20Sopenharmony_ci					   unsigned int reg, unsigned int val);
4188c2ecf20Sopenharmony_ci	void			(*rdfifo)(struct ks8851_net *ks, u8 *buff,
4198c2ecf20Sopenharmony_ci					  unsigned int len);
4208c2ecf20Sopenharmony_ci	void			(*wrfifo)(struct ks8851_net *ks,
4218c2ecf20Sopenharmony_ci					  struct sk_buff *txp, bool irq);
4228c2ecf20Sopenharmony_ci	netdev_tx_t		(*start_xmit)(struct sk_buff *skb,
4238c2ecf20Sopenharmony_ci					      struct net_device *dev);
4248c2ecf20Sopenharmony_ci	void			(*rx_skb)(struct ks8851_net *ks,
4258c2ecf20Sopenharmony_ci					  struct sk_buff *skb);
4268c2ecf20Sopenharmony_ci	void			(*flush_tx_work)(struct ks8851_net *ks);
4278c2ecf20Sopenharmony_ci};
4288c2ecf20Sopenharmony_ci
4298c2ecf20Sopenharmony_ciint ks8851_probe_common(struct net_device *netdev, struct device *dev,
4308c2ecf20Sopenharmony_ci			int msg_en);
4318c2ecf20Sopenharmony_ciint ks8851_remove_common(struct device *dev);
4328c2ecf20Sopenharmony_ciint ks8851_suspend(struct device *dev);
4338c2ecf20Sopenharmony_ciint ks8851_resume(struct device *dev);
4348c2ecf20Sopenharmony_ci
4358c2ecf20Sopenharmony_cistatic __maybe_unused SIMPLE_DEV_PM_OPS(ks8851_pm_ops,
4368c2ecf20Sopenharmony_ci					ks8851_suspend, ks8851_resume);
4378c2ecf20Sopenharmony_ci
4388c2ecf20Sopenharmony_ci/**
4398c2ecf20Sopenharmony_ci * ks8851_done_tx - update and then free skbuff after transmitting
4408c2ecf20Sopenharmony_ci * @ks: The device state
4418c2ecf20Sopenharmony_ci * @txb: The buffer transmitted
4428c2ecf20Sopenharmony_ci */
4438c2ecf20Sopenharmony_cistatic void __maybe_unused ks8851_done_tx(struct ks8851_net *ks,
4448c2ecf20Sopenharmony_ci					  struct sk_buff *txb)
4458c2ecf20Sopenharmony_ci{
4468c2ecf20Sopenharmony_ci	struct net_device *dev = ks->netdev;
4478c2ecf20Sopenharmony_ci
4488c2ecf20Sopenharmony_ci	dev->stats.tx_bytes += txb->len;
4498c2ecf20Sopenharmony_ci	dev->stats.tx_packets++;
4508c2ecf20Sopenharmony_ci
4518c2ecf20Sopenharmony_ci	dev_kfree_skb(txb);
4528c2ecf20Sopenharmony_ci}
4538c2ecf20Sopenharmony_ci
4548c2ecf20Sopenharmony_ci#endif /* __KS8851_H__ */
455