18c2ecf20Sopenharmony_ci/* CoreChip-sz SR9800 one chip USB 2.0 Ethernet Devices 28c2ecf20Sopenharmony_ci * 38c2ecf20Sopenharmony_ci * Author : Liu Junliang <liujunliang_ljl@163.com> 48c2ecf20Sopenharmony_ci * 58c2ecf20Sopenharmony_ci * This file is licensed under the terms of the GNU General Public License 68c2ecf20Sopenharmony_ci * version 2. This program is licensed "as is" without any warranty of any 78c2ecf20Sopenharmony_ci * kind, whether express or implied. 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef _SR9800_H 118c2ecf20Sopenharmony_ci#define _SR9800_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci/* SR9800 spec. command table on Linux Platform */ 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci/* command : Software Station Management Control Reg */ 168c2ecf20Sopenharmony_ci#define SR_CMD_SET_SW_MII 0x06 178c2ecf20Sopenharmony_ci/* command : PHY Read Reg */ 188c2ecf20Sopenharmony_ci#define SR_CMD_READ_MII_REG 0x07 198c2ecf20Sopenharmony_ci/* command : PHY Write Reg */ 208c2ecf20Sopenharmony_ci#define SR_CMD_WRITE_MII_REG 0x08 218c2ecf20Sopenharmony_ci/* command : Hardware Station Management Control Reg */ 228c2ecf20Sopenharmony_ci#define SR_CMD_SET_HW_MII 0x0a 238c2ecf20Sopenharmony_ci/* command : SROM Read Reg */ 248c2ecf20Sopenharmony_ci#define SR_CMD_READ_EEPROM 0x0b 258c2ecf20Sopenharmony_ci/* command : SROM Write Reg */ 268c2ecf20Sopenharmony_ci#define SR_CMD_WRITE_EEPROM 0x0c 278c2ecf20Sopenharmony_ci/* command : SROM Write Enable Reg */ 288c2ecf20Sopenharmony_ci#define SR_CMD_WRITE_ENABLE 0x0d 298c2ecf20Sopenharmony_ci/* command : SROM Write Disable Reg */ 308c2ecf20Sopenharmony_ci#define SR_CMD_WRITE_DISABLE 0x0e 318c2ecf20Sopenharmony_ci/* command : RX Control Read Reg */ 328c2ecf20Sopenharmony_ci#define SR_CMD_READ_RX_CTL 0x0f 338c2ecf20Sopenharmony_ci#define SR_RX_CTL_PRO (1 << 0) 348c2ecf20Sopenharmony_ci#define SR_RX_CTL_AMALL (1 << 1) 358c2ecf20Sopenharmony_ci#define SR_RX_CTL_SEP (1 << 2) 368c2ecf20Sopenharmony_ci#define SR_RX_CTL_AB (1 << 3) 378c2ecf20Sopenharmony_ci#define SR_RX_CTL_AM (1 << 4) 388c2ecf20Sopenharmony_ci#define SR_RX_CTL_AP (1 << 5) 398c2ecf20Sopenharmony_ci#define SR_RX_CTL_ARP (1 << 6) 408c2ecf20Sopenharmony_ci#define SR_RX_CTL_SO (1 << 7) 418c2ecf20Sopenharmony_ci#define SR_RX_CTL_RH1M (1 << 8) 428c2ecf20Sopenharmony_ci#define SR_RX_CTL_RH2M (1 << 9) 438c2ecf20Sopenharmony_ci#define SR_RX_CTL_RH3M (1 << 10) 448c2ecf20Sopenharmony_ci/* command : RX Control Write Reg */ 458c2ecf20Sopenharmony_ci#define SR_CMD_WRITE_RX_CTL 0x10 468c2ecf20Sopenharmony_ci/* command : IPG0/IPG1/IPG2 Control Read Reg */ 478c2ecf20Sopenharmony_ci#define SR_CMD_READ_IPG012 0x11 488c2ecf20Sopenharmony_ci/* command : IPG0/IPG1/IPG2 Control Write Reg */ 498c2ecf20Sopenharmony_ci#define SR_CMD_WRITE_IPG012 0x12 508c2ecf20Sopenharmony_ci/* command : Node ID Read Reg */ 518c2ecf20Sopenharmony_ci#define SR_CMD_READ_NODE_ID 0x13 528c2ecf20Sopenharmony_ci/* command : Node ID Write Reg */ 538c2ecf20Sopenharmony_ci#define SR_CMD_WRITE_NODE_ID 0x14 548c2ecf20Sopenharmony_ci/* command : Multicast Filter Array Read Reg */ 558c2ecf20Sopenharmony_ci#define SR_CMD_READ_MULTI_FILTER 0x15 568c2ecf20Sopenharmony_ci/* command : Multicast Filter Array Write Reg */ 578c2ecf20Sopenharmony_ci#define SR_CMD_WRITE_MULTI_FILTER 0x16 588c2ecf20Sopenharmony_ci/* command : Eth/HomePNA PHY Address Reg */ 598c2ecf20Sopenharmony_ci#define SR_CMD_READ_PHY_ID 0x19 608c2ecf20Sopenharmony_ci/* command : Medium Status Read Reg */ 618c2ecf20Sopenharmony_ci#define SR_CMD_READ_MEDIUM_STATUS 0x1a 628c2ecf20Sopenharmony_ci#define SR_MONITOR_LINK (1 << 1) 638c2ecf20Sopenharmony_ci#define SR_MONITOR_MAGIC (1 << 2) 648c2ecf20Sopenharmony_ci#define SR_MONITOR_HSFS (1 << 4) 658c2ecf20Sopenharmony_ci/* command : Medium Status Write Reg */ 668c2ecf20Sopenharmony_ci#define SR_CMD_WRITE_MEDIUM_MODE 0x1b 678c2ecf20Sopenharmony_ci#define SR_MEDIUM_GM (1 << 0) 688c2ecf20Sopenharmony_ci#define SR_MEDIUM_FD (1 << 1) 698c2ecf20Sopenharmony_ci#define SR_MEDIUM_AC (1 << 2) 708c2ecf20Sopenharmony_ci#define SR_MEDIUM_ENCK (1 << 3) 718c2ecf20Sopenharmony_ci#define SR_MEDIUM_RFC (1 << 4) 728c2ecf20Sopenharmony_ci#define SR_MEDIUM_TFC (1 << 5) 738c2ecf20Sopenharmony_ci#define SR_MEDIUM_JFE (1 << 6) 748c2ecf20Sopenharmony_ci#define SR_MEDIUM_PF (1 << 7) 758c2ecf20Sopenharmony_ci#define SR_MEDIUM_RE (1 << 8) 768c2ecf20Sopenharmony_ci#define SR_MEDIUM_PS (1 << 9) 778c2ecf20Sopenharmony_ci#define SR_MEDIUM_RSV (1 << 10) 788c2ecf20Sopenharmony_ci#define SR_MEDIUM_SBP (1 << 11) 798c2ecf20Sopenharmony_ci#define SR_MEDIUM_SM (1 << 12) 808c2ecf20Sopenharmony_ci/* command : Monitor Mode Status Read Reg */ 818c2ecf20Sopenharmony_ci#define SR_CMD_READ_MONITOR_MODE 0x1c 828c2ecf20Sopenharmony_ci/* command : Monitor Mode Status Write Reg */ 838c2ecf20Sopenharmony_ci#define SR_CMD_WRITE_MONITOR_MODE 0x1d 848c2ecf20Sopenharmony_ci/* command : GPIO Status Read Reg */ 858c2ecf20Sopenharmony_ci#define SR_CMD_READ_GPIOS 0x1e 868c2ecf20Sopenharmony_ci#define SR_GPIO_GPO0EN (1 << 0) /* GPIO0 Output enable */ 878c2ecf20Sopenharmony_ci#define SR_GPIO_GPO_0 (1 << 1) /* GPIO0 Output value */ 888c2ecf20Sopenharmony_ci#define SR_GPIO_GPO1EN (1 << 2) /* GPIO1 Output enable */ 898c2ecf20Sopenharmony_ci#define SR_GPIO_GPO_1 (1 << 3) /* GPIO1 Output value */ 908c2ecf20Sopenharmony_ci#define SR_GPIO_GPO2EN (1 << 4) /* GPIO2 Output enable */ 918c2ecf20Sopenharmony_ci#define SR_GPIO_GPO_2 (1 << 5) /* GPIO2 Output value */ 928c2ecf20Sopenharmony_ci#define SR_GPIO_RESERVED (1 << 6) /* Reserved */ 938c2ecf20Sopenharmony_ci#define SR_GPIO_RSE (1 << 7) /* Reload serial EEPROM */ 948c2ecf20Sopenharmony_ci/* command : GPIO Status Write Reg */ 958c2ecf20Sopenharmony_ci#define SR_CMD_WRITE_GPIOS 0x1f 968c2ecf20Sopenharmony_ci/* command : Eth PHY Power and Reset Control Reg */ 978c2ecf20Sopenharmony_ci#define SR_CMD_SW_RESET 0x20 988c2ecf20Sopenharmony_ci#define SR_SWRESET_CLEAR 0x00 998c2ecf20Sopenharmony_ci#define SR_SWRESET_RR (1 << 0) 1008c2ecf20Sopenharmony_ci#define SR_SWRESET_RT (1 << 1) 1018c2ecf20Sopenharmony_ci#define SR_SWRESET_PRTE (1 << 2) 1028c2ecf20Sopenharmony_ci#define SR_SWRESET_PRL (1 << 3) 1038c2ecf20Sopenharmony_ci#define SR_SWRESET_BZ (1 << 4) 1048c2ecf20Sopenharmony_ci#define SR_SWRESET_IPRL (1 << 5) 1058c2ecf20Sopenharmony_ci#define SR_SWRESET_IPPD (1 << 6) 1068c2ecf20Sopenharmony_ci/* command : Software Interface Selection Status Read Reg */ 1078c2ecf20Sopenharmony_ci#define SR_CMD_SW_PHY_STATUS 0x21 1088c2ecf20Sopenharmony_ci/* command : Software Interface Selection Status Write Reg */ 1098c2ecf20Sopenharmony_ci#define SR_CMD_SW_PHY_SELECT 0x22 1108c2ecf20Sopenharmony_ci/* command : BULK in Buffer Size Reg */ 1118c2ecf20Sopenharmony_ci#define SR_CMD_BULKIN_SIZE 0x2A 1128c2ecf20Sopenharmony_ci/* command : LED_MUX Control Reg */ 1138c2ecf20Sopenharmony_ci#define SR_CMD_LED_MUX 0x70 1148c2ecf20Sopenharmony_ci#define SR_LED_MUX_TX_ACTIVE (1 << 0) 1158c2ecf20Sopenharmony_ci#define SR_LED_MUX_RX_ACTIVE (1 << 1) 1168c2ecf20Sopenharmony_ci#define SR_LED_MUX_COLLISION (1 << 2) 1178c2ecf20Sopenharmony_ci#define SR_LED_MUX_DUP_COL (1 << 3) 1188c2ecf20Sopenharmony_ci#define SR_LED_MUX_DUP (1 << 4) 1198c2ecf20Sopenharmony_ci#define SR_LED_MUX_SPEED (1 << 5) 1208c2ecf20Sopenharmony_ci#define SR_LED_MUX_LINK_ACTIVE (1 << 6) 1218c2ecf20Sopenharmony_ci#define SR_LED_MUX_LINK (1 << 7) 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ci/* Register Access Flags */ 1248c2ecf20Sopenharmony_ci#define SR_REQ_RD_REG (USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE) 1258c2ecf20Sopenharmony_ci#define SR_REQ_WR_REG (USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE) 1268c2ecf20Sopenharmony_ci 1278c2ecf20Sopenharmony_ci/* Multicast Filter Array size & Max Number */ 1288c2ecf20Sopenharmony_ci#define SR_MCAST_FILTER_SIZE 8 1298c2ecf20Sopenharmony_ci#define SR_MAX_MCAST 64 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci/* IPG0/1/2 Default Value */ 1328c2ecf20Sopenharmony_ci#define SR9800_IPG0_DEFAULT 0x15 1338c2ecf20Sopenharmony_ci#define SR9800_IPG1_DEFAULT 0x0c 1348c2ecf20Sopenharmony_ci#define SR9800_IPG2_DEFAULT 0x12 1358c2ecf20Sopenharmony_ci 1368c2ecf20Sopenharmony_ci/* Medium Status Default Mode */ 1378c2ecf20Sopenharmony_ci#define SR9800_MEDIUM_DEFAULT \ 1388c2ecf20Sopenharmony_ci (SR_MEDIUM_FD | SR_MEDIUM_RFC | \ 1398c2ecf20Sopenharmony_ci SR_MEDIUM_TFC | SR_MEDIUM_PS | \ 1408c2ecf20Sopenharmony_ci SR_MEDIUM_AC | SR_MEDIUM_RE) 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci/* RX Control Default Setting */ 1438c2ecf20Sopenharmony_ci#define SR_DEFAULT_RX_CTL \ 1448c2ecf20Sopenharmony_ci (SR_RX_CTL_SO | SR_RX_CTL_AB | SR_RX_CTL_RH1M) 1458c2ecf20Sopenharmony_ci 1468c2ecf20Sopenharmony_ci/* EEPROM Magic Number & EEPROM Size */ 1478c2ecf20Sopenharmony_ci#define SR_EEPROM_MAGIC 0xdeadbeef 1488c2ecf20Sopenharmony_ci#define SR9800_EEPROM_LEN 0xff 1498c2ecf20Sopenharmony_ci 1508c2ecf20Sopenharmony_ci/* SR9800 Driver Version and Driver Name */ 1518c2ecf20Sopenharmony_ci#define DRIVER_VERSION "11-Nov-2013" 1528c2ecf20Sopenharmony_ci#define DRIVER_NAME "CoreChips" 1538c2ecf20Sopenharmony_ci#define DRIVER_FLAG \ 1548c2ecf20Sopenharmony_ci (FLAG_ETHER | FLAG_FRAMING_AX | FLAG_LINK_INTR | FLAG_MULTI_PACKET) 1558c2ecf20Sopenharmony_ci 1568c2ecf20Sopenharmony_ci/* SR9800 BULKIN Buffer Size */ 1578c2ecf20Sopenharmony_ci#define SR9800_MAX_BULKIN_2K 0 1588c2ecf20Sopenharmony_ci#define SR9800_MAX_BULKIN_4K 1 1598c2ecf20Sopenharmony_ci#define SR9800_MAX_BULKIN_6K 2 1608c2ecf20Sopenharmony_ci#define SR9800_MAX_BULKIN_8K 3 1618c2ecf20Sopenharmony_ci#define SR9800_MAX_BULKIN_16K 4 1628c2ecf20Sopenharmony_ci#define SR9800_MAX_BULKIN_20K 5 1638c2ecf20Sopenharmony_ci#define SR9800_MAX_BULKIN_24K 6 1648c2ecf20Sopenharmony_ci#define SR9800_MAX_BULKIN_32K 7 1658c2ecf20Sopenharmony_ci 1668c2ecf20Sopenharmony_cistruct {unsigned short size, byte_cnt, threshold; } SR9800_BULKIN_SIZE[] = { 1678c2ecf20Sopenharmony_ci /* 2k */ 1688c2ecf20Sopenharmony_ci {2048, 0x8000, 0x8001}, 1698c2ecf20Sopenharmony_ci /* 4k */ 1708c2ecf20Sopenharmony_ci {4096, 0x8100, 0x8147}, 1718c2ecf20Sopenharmony_ci /* 6k */ 1728c2ecf20Sopenharmony_ci {6144, 0x8200, 0x81EB}, 1738c2ecf20Sopenharmony_ci /* 8k */ 1748c2ecf20Sopenharmony_ci {8192, 0x8300, 0x83D7}, 1758c2ecf20Sopenharmony_ci /* 16 */ 1768c2ecf20Sopenharmony_ci {16384, 0x8400, 0x851E}, 1778c2ecf20Sopenharmony_ci /* 20k */ 1788c2ecf20Sopenharmony_ci {20480, 0x8500, 0x8666}, 1798c2ecf20Sopenharmony_ci /* 24k */ 1808c2ecf20Sopenharmony_ci {24576, 0x8600, 0x87AE}, 1818c2ecf20Sopenharmony_ci /* 32k */ 1828c2ecf20Sopenharmony_ci {32768, 0x8700, 0x8A3D}, 1838c2ecf20Sopenharmony_ci}; 1848c2ecf20Sopenharmony_ci 1858c2ecf20Sopenharmony_ci/* This structure cannot exceed sizeof(unsigned long [5]) AKA 20 bytes */ 1868c2ecf20Sopenharmony_cistruct sr_data { 1878c2ecf20Sopenharmony_ci u8 multi_filter[SR_MCAST_FILTER_SIZE]; 1888c2ecf20Sopenharmony_ci u8 mac_addr[ETH_ALEN]; 1898c2ecf20Sopenharmony_ci u8 phymode; 1908c2ecf20Sopenharmony_ci u8 ledmode; 1918c2ecf20Sopenharmony_ci u8 eeprom_len; 1928c2ecf20Sopenharmony_ci}; 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_cistruct sr9800_int_data { 1958c2ecf20Sopenharmony_ci __le16 res1; 1968c2ecf20Sopenharmony_ci u8 link; 1978c2ecf20Sopenharmony_ci __le16 res2; 1988c2ecf20Sopenharmony_ci u8 status; 1998c2ecf20Sopenharmony_ci __le16 res3; 2008c2ecf20Sopenharmony_ci} __packed; 2018c2ecf20Sopenharmony_ci 2028c2ecf20Sopenharmony_ci#endif /* _SR9800_H */ 203