18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: (GPL-2.0 OR MIT)
28c2ecf20Sopenharmony_ci/* Copyright 2017 Microsemi Corporation
38c2ecf20Sopenharmony_ci * Copyright 2018-2019 NXP Semiconductors
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci#include <linux/fsl/enetc_mdio.h>
68c2ecf20Sopenharmony_ci#include <soc/mscc/ocelot_qsys.h>
78c2ecf20Sopenharmony_ci#include <soc/mscc/ocelot_vcap.h>
88c2ecf20Sopenharmony_ci#include <soc/mscc/ocelot_ptp.h>
98c2ecf20Sopenharmony_ci#include <soc/mscc/ocelot_sys.h>
108c2ecf20Sopenharmony_ci#include <soc/mscc/ocelot.h>
118c2ecf20Sopenharmony_ci#include <linux/packing.h>
128c2ecf20Sopenharmony_ci#include <linux/pcs-lynx.h>
138c2ecf20Sopenharmony_ci#include <net/pkt_sched.h>
148c2ecf20Sopenharmony_ci#include <linux/iopoll.h>
158c2ecf20Sopenharmony_ci#include <linux/mdio.h>
168c2ecf20Sopenharmony_ci#include <linux/pci.h>
178c2ecf20Sopenharmony_ci#include "felix.h"
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci#define VSC9959_TAS_GCL_ENTRY_MAX	63
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_cistatic const u32 vsc9959_ana_regmap[] = {
228c2ecf20Sopenharmony_ci	REG(ANA_ADVLEARN,			0x0089a0),
238c2ecf20Sopenharmony_ci	REG(ANA_VLANMASK,			0x0089a4),
248c2ecf20Sopenharmony_ci	REG_RESERVED(ANA_PORT_B_DOMAIN),
258c2ecf20Sopenharmony_ci	REG(ANA_ANAGEFIL,			0x0089ac),
268c2ecf20Sopenharmony_ci	REG(ANA_ANEVENTS,			0x0089b0),
278c2ecf20Sopenharmony_ci	REG(ANA_STORMLIMIT_BURST,		0x0089b4),
288c2ecf20Sopenharmony_ci	REG(ANA_STORMLIMIT_CFG,			0x0089b8),
298c2ecf20Sopenharmony_ci	REG(ANA_ISOLATED_PORTS,			0x0089c8),
308c2ecf20Sopenharmony_ci	REG(ANA_COMMUNITY_PORTS,		0x0089cc),
318c2ecf20Sopenharmony_ci	REG(ANA_AUTOAGE,			0x0089d0),
328c2ecf20Sopenharmony_ci	REG(ANA_MACTOPTIONS,			0x0089d4),
338c2ecf20Sopenharmony_ci	REG(ANA_LEARNDISC,			0x0089d8),
348c2ecf20Sopenharmony_ci	REG(ANA_AGENCTRL,			0x0089dc),
358c2ecf20Sopenharmony_ci	REG(ANA_MIRRORPORTS,			0x0089e0),
368c2ecf20Sopenharmony_ci	REG(ANA_EMIRRORPORTS,			0x0089e4),
378c2ecf20Sopenharmony_ci	REG(ANA_FLOODING,			0x0089e8),
388c2ecf20Sopenharmony_ci	REG(ANA_FLOODING_IPMC,			0x008a08),
398c2ecf20Sopenharmony_ci	REG(ANA_SFLOW_CFG,			0x008a0c),
408c2ecf20Sopenharmony_ci	REG(ANA_PORT_MODE,			0x008a28),
418c2ecf20Sopenharmony_ci	REG(ANA_CUT_THRU_CFG,			0x008a48),
428c2ecf20Sopenharmony_ci	REG(ANA_PGID_PGID,			0x008400),
438c2ecf20Sopenharmony_ci	REG(ANA_TABLES_ANMOVED,			0x007f1c),
448c2ecf20Sopenharmony_ci	REG(ANA_TABLES_MACHDATA,		0x007f20),
458c2ecf20Sopenharmony_ci	REG(ANA_TABLES_MACLDATA,		0x007f24),
468c2ecf20Sopenharmony_ci	REG(ANA_TABLES_STREAMDATA,		0x007f28),
478c2ecf20Sopenharmony_ci	REG(ANA_TABLES_MACACCESS,		0x007f2c),
488c2ecf20Sopenharmony_ci	REG(ANA_TABLES_MACTINDX,		0x007f30),
498c2ecf20Sopenharmony_ci	REG(ANA_TABLES_VLANACCESS,		0x007f34),
508c2ecf20Sopenharmony_ci	REG(ANA_TABLES_VLANTIDX,		0x007f38),
518c2ecf20Sopenharmony_ci	REG(ANA_TABLES_ISDXACCESS,		0x007f3c),
528c2ecf20Sopenharmony_ci	REG(ANA_TABLES_ISDXTIDX,		0x007f40),
538c2ecf20Sopenharmony_ci	REG(ANA_TABLES_ENTRYLIM,		0x007f00),
548c2ecf20Sopenharmony_ci	REG(ANA_TABLES_PTP_ID_HIGH,		0x007f44),
558c2ecf20Sopenharmony_ci	REG(ANA_TABLES_PTP_ID_LOW,		0x007f48),
568c2ecf20Sopenharmony_ci	REG(ANA_TABLES_STREAMACCESS,		0x007f4c),
578c2ecf20Sopenharmony_ci	REG(ANA_TABLES_STREAMTIDX,		0x007f50),
588c2ecf20Sopenharmony_ci	REG(ANA_TABLES_SEQ_HISTORY,		0x007f54),
598c2ecf20Sopenharmony_ci	REG(ANA_TABLES_SEQ_MASK,		0x007f58),
608c2ecf20Sopenharmony_ci	REG(ANA_TABLES_SFID_MASK,		0x007f5c),
618c2ecf20Sopenharmony_ci	REG(ANA_TABLES_SFIDACCESS,		0x007f60),
628c2ecf20Sopenharmony_ci	REG(ANA_TABLES_SFIDTIDX,		0x007f64),
638c2ecf20Sopenharmony_ci	REG(ANA_MSTI_STATE,			0x008600),
648c2ecf20Sopenharmony_ci	REG(ANA_OAM_UPM_LM_CNT,			0x008000),
658c2ecf20Sopenharmony_ci	REG(ANA_SG_ACCESS_CTRL,			0x008a64),
668c2ecf20Sopenharmony_ci	REG(ANA_SG_CONFIG_REG_1,		0x007fb0),
678c2ecf20Sopenharmony_ci	REG(ANA_SG_CONFIG_REG_2,		0x007fb4),
688c2ecf20Sopenharmony_ci	REG(ANA_SG_CONFIG_REG_3,		0x007fb8),
698c2ecf20Sopenharmony_ci	REG(ANA_SG_CONFIG_REG_4,		0x007fbc),
708c2ecf20Sopenharmony_ci	REG(ANA_SG_CONFIG_REG_5,		0x007fc0),
718c2ecf20Sopenharmony_ci	REG(ANA_SG_GCL_GS_CONFIG,		0x007f80),
728c2ecf20Sopenharmony_ci	REG(ANA_SG_GCL_TI_CONFIG,		0x007f90),
738c2ecf20Sopenharmony_ci	REG(ANA_SG_STATUS_REG_1,		0x008980),
748c2ecf20Sopenharmony_ci	REG(ANA_SG_STATUS_REG_2,		0x008984),
758c2ecf20Sopenharmony_ci	REG(ANA_SG_STATUS_REG_3,		0x008988),
768c2ecf20Sopenharmony_ci	REG(ANA_PORT_VLAN_CFG,			0x007800),
778c2ecf20Sopenharmony_ci	REG(ANA_PORT_DROP_CFG,			0x007804),
788c2ecf20Sopenharmony_ci	REG(ANA_PORT_QOS_CFG,			0x007808),
798c2ecf20Sopenharmony_ci	REG(ANA_PORT_VCAP_CFG,			0x00780c),
808c2ecf20Sopenharmony_ci	REG(ANA_PORT_VCAP_S1_KEY_CFG,		0x007810),
818c2ecf20Sopenharmony_ci	REG(ANA_PORT_VCAP_S2_CFG,		0x00781c),
828c2ecf20Sopenharmony_ci	REG(ANA_PORT_PCP_DEI_MAP,		0x007820),
838c2ecf20Sopenharmony_ci	REG(ANA_PORT_CPU_FWD_CFG,		0x007860),
848c2ecf20Sopenharmony_ci	REG(ANA_PORT_CPU_FWD_BPDU_CFG,		0x007864),
858c2ecf20Sopenharmony_ci	REG(ANA_PORT_CPU_FWD_GARP_CFG,		0x007868),
868c2ecf20Sopenharmony_ci	REG(ANA_PORT_CPU_FWD_CCM_CFG,		0x00786c),
878c2ecf20Sopenharmony_ci	REG(ANA_PORT_PORT_CFG,			0x007870),
888c2ecf20Sopenharmony_ci	REG(ANA_PORT_POL_CFG,			0x007874),
898c2ecf20Sopenharmony_ci	REG(ANA_PORT_PTP_CFG,			0x007878),
908c2ecf20Sopenharmony_ci	REG(ANA_PORT_PTP_DLY1_CFG,		0x00787c),
918c2ecf20Sopenharmony_ci	REG(ANA_PORT_PTP_DLY2_CFG,		0x007880),
928c2ecf20Sopenharmony_ci	REG(ANA_PORT_SFID_CFG,			0x007884),
938c2ecf20Sopenharmony_ci	REG(ANA_PFC_PFC_CFG,			0x008800),
948c2ecf20Sopenharmony_ci	REG_RESERVED(ANA_PFC_PFC_TIMER),
958c2ecf20Sopenharmony_ci	REG_RESERVED(ANA_IPT_OAM_MEP_CFG),
968c2ecf20Sopenharmony_ci	REG_RESERVED(ANA_IPT_IPT),
978c2ecf20Sopenharmony_ci	REG_RESERVED(ANA_PPT_PPT),
988c2ecf20Sopenharmony_ci	REG_RESERVED(ANA_FID_MAP_FID_MAP),
998c2ecf20Sopenharmony_ci	REG(ANA_AGGR_CFG,			0x008a68),
1008c2ecf20Sopenharmony_ci	REG(ANA_CPUQ_CFG,			0x008a6c),
1018c2ecf20Sopenharmony_ci	REG_RESERVED(ANA_CPUQ_CFG2),
1028c2ecf20Sopenharmony_ci	REG(ANA_CPUQ_8021_CFG,			0x008a74),
1038c2ecf20Sopenharmony_ci	REG(ANA_DSCP_CFG,			0x008ab4),
1048c2ecf20Sopenharmony_ci	REG(ANA_DSCP_REWR_CFG,			0x008bb4),
1058c2ecf20Sopenharmony_ci	REG(ANA_VCAP_RNG_TYPE_CFG,		0x008bf4),
1068c2ecf20Sopenharmony_ci	REG(ANA_VCAP_RNG_VAL_CFG,		0x008c14),
1078c2ecf20Sopenharmony_ci	REG_RESERVED(ANA_VRAP_CFG),
1088c2ecf20Sopenharmony_ci	REG_RESERVED(ANA_VRAP_HDR_DATA),
1098c2ecf20Sopenharmony_ci	REG_RESERVED(ANA_VRAP_HDR_MASK),
1108c2ecf20Sopenharmony_ci	REG(ANA_DISCARD_CFG,			0x008c40),
1118c2ecf20Sopenharmony_ci	REG(ANA_FID_CFG,			0x008c44),
1128c2ecf20Sopenharmony_ci	REG(ANA_POL_PIR_CFG,			0x004000),
1138c2ecf20Sopenharmony_ci	REG(ANA_POL_CIR_CFG,			0x004004),
1148c2ecf20Sopenharmony_ci	REG(ANA_POL_MODE_CFG,			0x004008),
1158c2ecf20Sopenharmony_ci	REG(ANA_POL_PIR_STATE,			0x00400c),
1168c2ecf20Sopenharmony_ci	REG(ANA_POL_CIR_STATE,			0x004010),
1178c2ecf20Sopenharmony_ci	REG_RESERVED(ANA_POL_STATE),
1188c2ecf20Sopenharmony_ci	REG(ANA_POL_FLOWC,			0x008c48),
1198c2ecf20Sopenharmony_ci	REG(ANA_POL_HYST,			0x008cb4),
1208c2ecf20Sopenharmony_ci	REG_RESERVED(ANA_POL_MISC_CFG),
1218c2ecf20Sopenharmony_ci};
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_cistatic const u32 vsc9959_qs_regmap[] = {
1248c2ecf20Sopenharmony_ci	REG(QS_XTR_GRP_CFG,			0x000000),
1258c2ecf20Sopenharmony_ci	REG(QS_XTR_RD,				0x000008),
1268c2ecf20Sopenharmony_ci	REG(QS_XTR_FRM_PRUNING,			0x000010),
1278c2ecf20Sopenharmony_ci	REG(QS_XTR_FLUSH,			0x000018),
1288c2ecf20Sopenharmony_ci	REG(QS_XTR_DATA_PRESENT,		0x00001c),
1298c2ecf20Sopenharmony_ci	REG(QS_XTR_CFG,				0x000020),
1308c2ecf20Sopenharmony_ci	REG(QS_INJ_GRP_CFG,			0x000024),
1318c2ecf20Sopenharmony_ci	REG(QS_INJ_WR,				0x00002c),
1328c2ecf20Sopenharmony_ci	REG(QS_INJ_CTRL,			0x000034),
1338c2ecf20Sopenharmony_ci	REG(QS_INJ_STATUS,			0x00003c),
1348c2ecf20Sopenharmony_ci	REG(QS_INJ_ERR,				0x000040),
1358c2ecf20Sopenharmony_ci	REG_RESERVED(QS_INH_DBG),
1368c2ecf20Sopenharmony_ci};
1378c2ecf20Sopenharmony_ci
1388c2ecf20Sopenharmony_cistatic const u32 vsc9959_vcap_regmap[] = {
1398c2ecf20Sopenharmony_ci	/* VCAP_CORE_CFG */
1408c2ecf20Sopenharmony_ci	REG(VCAP_CORE_UPDATE_CTRL,		0x000000),
1418c2ecf20Sopenharmony_ci	REG(VCAP_CORE_MV_CFG,			0x000004),
1428c2ecf20Sopenharmony_ci	/* VCAP_CORE_CACHE */
1438c2ecf20Sopenharmony_ci	REG(VCAP_CACHE_ENTRY_DAT,		0x000008),
1448c2ecf20Sopenharmony_ci	REG(VCAP_CACHE_MASK_DAT,		0x000108),
1458c2ecf20Sopenharmony_ci	REG(VCAP_CACHE_ACTION_DAT,		0x000208),
1468c2ecf20Sopenharmony_ci	REG(VCAP_CACHE_CNT_DAT,			0x000308),
1478c2ecf20Sopenharmony_ci	REG(VCAP_CACHE_TG_DAT,			0x000388),
1488c2ecf20Sopenharmony_ci	/* VCAP_CONST */
1498c2ecf20Sopenharmony_ci	REG(VCAP_CONST_VCAP_VER,		0x000398),
1508c2ecf20Sopenharmony_ci	REG(VCAP_CONST_ENTRY_WIDTH,		0x00039c),
1518c2ecf20Sopenharmony_ci	REG(VCAP_CONST_ENTRY_CNT,		0x0003a0),
1528c2ecf20Sopenharmony_ci	REG(VCAP_CONST_ENTRY_SWCNT,		0x0003a4),
1538c2ecf20Sopenharmony_ci	REG(VCAP_CONST_ENTRY_TG_WIDTH,		0x0003a8),
1548c2ecf20Sopenharmony_ci	REG(VCAP_CONST_ACTION_DEF_CNT,		0x0003ac),
1558c2ecf20Sopenharmony_ci	REG(VCAP_CONST_ACTION_WIDTH,		0x0003b0),
1568c2ecf20Sopenharmony_ci	REG(VCAP_CONST_CNT_WIDTH,		0x0003b4),
1578c2ecf20Sopenharmony_ci	REG(VCAP_CONST_CORE_CNT,		0x0003b8),
1588c2ecf20Sopenharmony_ci	REG(VCAP_CONST_IF_CNT,			0x0003bc),
1598c2ecf20Sopenharmony_ci};
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_cistatic const u32 vsc9959_qsys_regmap[] = {
1628c2ecf20Sopenharmony_ci	REG(QSYS_PORT_MODE,			0x00f460),
1638c2ecf20Sopenharmony_ci	REG(QSYS_SWITCH_PORT_MODE,		0x00f480),
1648c2ecf20Sopenharmony_ci	REG(QSYS_STAT_CNT_CFG,			0x00f49c),
1658c2ecf20Sopenharmony_ci	REG(QSYS_EEE_CFG,			0x00f4a0),
1668c2ecf20Sopenharmony_ci	REG(QSYS_EEE_THRES,			0x00f4b8),
1678c2ecf20Sopenharmony_ci	REG(QSYS_IGR_NO_SHARING,		0x00f4bc),
1688c2ecf20Sopenharmony_ci	REG(QSYS_EGR_NO_SHARING,		0x00f4c0),
1698c2ecf20Sopenharmony_ci	REG(QSYS_SW_STATUS,			0x00f4c4),
1708c2ecf20Sopenharmony_ci	REG(QSYS_EXT_CPU_CFG,			0x00f4e0),
1718c2ecf20Sopenharmony_ci	REG_RESERVED(QSYS_PAD_CFG),
1728c2ecf20Sopenharmony_ci	REG(QSYS_CPU_GROUP_MAP,			0x00f4e8),
1738c2ecf20Sopenharmony_ci	REG_RESERVED(QSYS_QMAP),
1748c2ecf20Sopenharmony_ci	REG_RESERVED(QSYS_ISDX_SGRP),
1758c2ecf20Sopenharmony_ci	REG_RESERVED(QSYS_TIMED_FRAME_ENTRY),
1768c2ecf20Sopenharmony_ci	REG(QSYS_TFRM_MISC,			0x00f50c),
1778c2ecf20Sopenharmony_ci	REG(QSYS_TFRM_PORT_DLY,			0x00f510),
1788c2ecf20Sopenharmony_ci	REG(QSYS_TFRM_TIMER_CFG_1,		0x00f514),
1798c2ecf20Sopenharmony_ci	REG(QSYS_TFRM_TIMER_CFG_2,		0x00f518),
1808c2ecf20Sopenharmony_ci	REG(QSYS_TFRM_TIMER_CFG_3,		0x00f51c),
1818c2ecf20Sopenharmony_ci	REG(QSYS_TFRM_TIMER_CFG_4,		0x00f520),
1828c2ecf20Sopenharmony_ci	REG(QSYS_TFRM_TIMER_CFG_5,		0x00f524),
1838c2ecf20Sopenharmony_ci	REG(QSYS_TFRM_TIMER_CFG_6,		0x00f528),
1848c2ecf20Sopenharmony_ci	REG(QSYS_TFRM_TIMER_CFG_7,		0x00f52c),
1858c2ecf20Sopenharmony_ci	REG(QSYS_TFRM_TIMER_CFG_8,		0x00f530),
1868c2ecf20Sopenharmony_ci	REG(QSYS_RED_PROFILE,			0x00f534),
1878c2ecf20Sopenharmony_ci	REG(QSYS_RES_QOS_MODE,			0x00f574),
1888c2ecf20Sopenharmony_ci	REG(QSYS_RES_CFG,			0x00c000),
1898c2ecf20Sopenharmony_ci	REG(QSYS_RES_STAT,			0x00c004),
1908c2ecf20Sopenharmony_ci	REG(QSYS_EGR_DROP_MODE,			0x00f578),
1918c2ecf20Sopenharmony_ci	REG(QSYS_EQ_CTRL,			0x00f57c),
1928c2ecf20Sopenharmony_ci	REG_RESERVED(QSYS_EVENTS_CORE),
1938c2ecf20Sopenharmony_ci	REG(QSYS_QMAXSDU_CFG_0,			0x00f584),
1948c2ecf20Sopenharmony_ci	REG(QSYS_QMAXSDU_CFG_1,			0x00f5a0),
1958c2ecf20Sopenharmony_ci	REG(QSYS_QMAXSDU_CFG_2,			0x00f5bc),
1968c2ecf20Sopenharmony_ci	REG(QSYS_QMAXSDU_CFG_3,			0x00f5d8),
1978c2ecf20Sopenharmony_ci	REG(QSYS_QMAXSDU_CFG_4,			0x00f5f4),
1988c2ecf20Sopenharmony_ci	REG(QSYS_QMAXSDU_CFG_5,			0x00f610),
1998c2ecf20Sopenharmony_ci	REG(QSYS_QMAXSDU_CFG_6,			0x00f62c),
2008c2ecf20Sopenharmony_ci	REG(QSYS_QMAXSDU_CFG_7,			0x00f648),
2018c2ecf20Sopenharmony_ci	REG(QSYS_PREEMPTION_CFG,		0x00f664),
2028c2ecf20Sopenharmony_ci	REG(QSYS_CIR_CFG,			0x000000),
2038c2ecf20Sopenharmony_ci	REG(QSYS_EIR_CFG,			0x000004),
2048c2ecf20Sopenharmony_ci	REG(QSYS_SE_CFG,			0x000008),
2058c2ecf20Sopenharmony_ci	REG(QSYS_SE_DWRR_CFG,			0x00000c),
2068c2ecf20Sopenharmony_ci	REG_RESERVED(QSYS_SE_CONNECT),
2078c2ecf20Sopenharmony_ci	REG(QSYS_SE_DLB_SENSE,			0x000040),
2088c2ecf20Sopenharmony_ci	REG(QSYS_CIR_STATE,			0x000044),
2098c2ecf20Sopenharmony_ci	REG(QSYS_EIR_STATE,			0x000048),
2108c2ecf20Sopenharmony_ci	REG_RESERVED(QSYS_SE_STATE),
2118c2ecf20Sopenharmony_ci	REG(QSYS_HSCH_MISC_CFG,			0x00f67c),
2128c2ecf20Sopenharmony_ci	REG(QSYS_TAG_CONFIG,			0x00f680),
2138c2ecf20Sopenharmony_ci	REG(QSYS_TAS_PARAM_CFG_CTRL,		0x00f698),
2148c2ecf20Sopenharmony_ci	REG(QSYS_PORT_MAX_SDU,			0x00f69c),
2158c2ecf20Sopenharmony_ci	REG(QSYS_PARAM_CFG_REG_1,		0x00f440),
2168c2ecf20Sopenharmony_ci	REG(QSYS_PARAM_CFG_REG_2,		0x00f444),
2178c2ecf20Sopenharmony_ci	REG(QSYS_PARAM_CFG_REG_3,		0x00f448),
2188c2ecf20Sopenharmony_ci	REG(QSYS_PARAM_CFG_REG_4,		0x00f44c),
2198c2ecf20Sopenharmony_ci	REG(QSYS_PARAM_CFG_REG_5,		0x00f450),
2208c2ecf20Sopenharmony_ci	REG(QSYS_GCL_CFG_REG_1,			0x00f454),
2218c2ecf20Sopenharmony_ci	REG(QSYS_GCL_CFG_REG_2,			0x00f458),
2228c2ecf20Sopenharmony_ci	REG(QSYS_PARAM_STATUS_REG_1,		0x00f400),
2238c2ecf20Sopenharmony_ci	REG(QSYS_PARAM_STATUS_REG_2,		0x00f404),
2248c2ecf20Sopenharmony_ci	REG(QSYS_PARAM_STATUS_REG_3,		0x00f408),
2258c2ecf20Sopenharmony_ci	REG(QSYS_PARAM_STATUS_REG_4,		0x00f40c),
2268c2ecf20Sopenharmony_ci	REG(QSYS_PARAM_STATUS_REG_5,		0x00f410),
2278c2ecf20Sopenharmony_ci	REG(QSYS_PARAM_STATUS_REG_6,		0x00f414),
2288c2ecf20Sopenharmony_ci	REG(QSYS_PARAM_STATUS_REG_7,		0x00f418),
2298c2ecf20Sopenharmony_ci	REG(QSYS_PARAM_STATUS_REG_8,		0x00f41c),
2308c2ecf20Sopenharmony_ci	REG(QSYS_PARAM_STATUS_REG_9,		0x00f420),
2318c2ecf20Sopenharmony_ci	REG(QSYS_GCL_STATUS_REG_1,		0x00f424),
2328c2ecf20Sopenharmony_ci	REG(QSYS_GCL_STATUS_REG_2,		0x00f428),
2338c2ecf20Sopenharmony_ci};
2348c2ecf20Sopenharmony_ci
2358c2ecf20Sopenharmony_cistatic const u32 vsc9959_rew_regmap[] = {
2368c2ecf20Sopenharmony_ci	REG(REW_PORT_VLAN_CFG,			0x000000),
2378c2ecf20Sopenharmony_ci	REG(REW_TAG_CFG,			0x000004),
2388c2ecf20Sopenharmony_ci	REG(REW_PORT_CFG,			0x000008),
2398c2ecf20Sopenharmony_ci	REG(REW_DSCP_CFG,			0x00000c),
2408c2ecf20Sopenharmony_ci	REG(REW_PCP_DEI_QOS_MAP_CFG,		0x000010),
2418c2ecf20Sopenharmony_ci	REG(REW_PTP_CFG,			0x000050),
2428c2ecf20Sopenharmony_ci	REG(REW_PTP_DLY1_CFG,			0x000054),
2438c2ecf20Sopenharmony_ci	REG(REW_RED_TAG_CFG,			0x000058),
2448c2ecf20Sopenharmony_ci	REG(REW_DSCP_REMAP_DP1_CFG,		0x000410),
2458c2ecf20Sopenharmony_ci	REG(REW_DSCP_REMAP_CFG,			0x000510),
2468c2ecf20Sopenharmony_ci	REG_RESERVED(REW_STAT_CFG),
2478c2ecf20Sopenharmony_ci	REG_RESERVED(REW_REW_STICKY),
2488c2ecf20Sopenharmony_ci	REG_RESERVED(REW_PPT),
2498c2ecf20Sopenharmony_ci};
2508c2ecf20Sopenharmony_ci
2518c2ecf20Sopenharmony_cistatic const u32 vsc9959_sys_regmap[] = {
2528c2ecf20Sopenharmony_ci	REG(SYS_COUNT_RX_OCTETS,		0x000000),
2538c2ecf20Sopenharmony_ci	REG(SYS_COUNT_RX_MULTICAST,		0x000008),
2548c2ecf20Sopenharmony_ci	REG(SYS_COUNT_RX_SHORTS,		0x000010),
2558c2ecf20Sopenharmony_ci	REG(SYS_COUNT_RX_FRAGMENTS,		0x000014),
2568c2ecf20Sopenharmony_ci	REG(SYS_COUNT_RX_JABBERS,		0x000018),
2578c2ecf20Sopenharmony_ci	REG(SYS_COUNT_RX_64,			0x000024),
2588c2ecf20Sopenharmony_ci	REG(SYS_COUNT_RX_65_127,		0x000028),
2598c2ecf20Sopenharmony_ci	REG(SYS_COUNT_RX_128_255,		0x00002c),
2608c2ecf20Sopenharmony_ci	REG(SYS_COUNT_RX_256_1023,		0x000030),
2618c2ecf20Sopenharmony_ci	REG(SYS_COUNT_RX_1024_1526,		0x000034),
2628c2ecf20Sopenharmony_ci	REG(SYS_COUNT_RX_1527_MAX,		0x000038),
2638c2ecf20Sopenharmony_ci	REG(SYS_COUNT_RX_LONGS,			0x000044),
2648c2ecf20Sopenharmony_ci	REG(SYS_COUNT_TX_OCTETS,		0x000200),
2658c2ecf20Sopenharmony_ci	REG(SYS_COUNT_TX_COLLISION,		0x000210),
2668c2ecf20Sopenharmony_ci	REG(SYS_COUNT_TX_DROPS,			0x000214),
2678c2ecf20Sopenharmony_ci	REG(SYS_COUNT_TX_64,			0x00021c),
2688c2ecf20Sopenharmony_ci	REG(SYS_COUNT_TX_65_127,		0x000220),
2698c2ecf20Sopenharmony_ci	REG(SYS_COUNT_TX_128_511,		0x000224),
2708c2ecf20Sopenharmony_ci	REG(SYS_COUNT_TX_512_1023,		0x000228),
2718c2ecf20Sopenharmony_ci	REG(SYS_COUNT_TX_1024_1526,		0x00022c),
2728c2ecf20Sopenharmony_ci	REG(SYS_COUNT_TX_1527_MAX,		0x000230),
2738c2ecf20Sopenharmony_ci	REG(SYS_COUNT_TX_AGING,			0x000278),
2748c2ecf20Sopenharmony_ci	REG(SYS_RESET_CFG,			0x000e00),
2758c2ecf20Sopenharmony_ci	REG(SYS_SR_ETYPE_CFG,			0x000e04),
2768c2ecf20Sopenharmony_ci	REG(SYS_VLAN_ETYPE_CFG,			0x000e08),
2778c2ecf20Sopenharmony_ci	REG(SYS_PORT_MODE,			0x000e0c),
2788c2ecf20Sopenharmony_ci	REG(SYS_FRONT_PORT_MODE,		0x000e2c),
2798c2ecf20Sopenharmony_ci	REG(SYS_FRM_AGING,			0x000e44),
2808c2ecf20Sopenharmony_ci	REG(SYS_STAT_CFG,			0x000e48),
2818c2ecf20Sopenharmony_ci	REG(SYS_SW_STATUS,			0x000e4c),
2828c2ecf20Sopenharmony_ci	REG_RESERVED(SYS_MISC_CFG),
2838c2ecf20Sopenharmony_ci	REG(SYS_REW_MAC_HIGH_CFG,		0x000e6c),
2848c2ecf20Sopenharmony_ci	REG(SYS_REW_MAC_LOW_CFG,		0x000e84),
2858c2ecf20Sopenharmony_ci	REG(SYS_TIMESTAMP_OFFSET,		0x000e9c),
2868c2ecf20Sopenharmony_ci	REG(SYS_PAUSE_CFG,			0x000ea0),
2878c2ecf20Sopenharmony_ci	REG(SYS_PAUSE_TOT_CFG,			0x000ebc),
2888c2ecf20Sopenharmony_ci	REG(SYS_ATOP,				0x000ec0),
2898c2ecf20Sopenharmony_ci	REG(SYS_ATOP_TOT_CFG,			0x000edc),
2908c2ecf20Sopenharmony_ci	REG(SYS_MAC_FC_CFG,			0x000ee0),
2918c2ecf20Sopenharmony_ci	REG(SYS_MMGT,				0x000ef8),
2928c2ecf20Sopenharmony_ci	REG_RESERVED(SYS_MMGT_FAST),
2938c2ecf20Sopenharmony_ci	REG_RESERVED(SYS_EVENTS_DIF),
2948c2ecf20Sopenharmony_ci	REG_RESERVED(SYS_EVENTS_CORE),
2958c2ecf20Sopenharmony_ci	REG_RESERVED(SYS_CNT),
2968c2ecf20Sopenharmony_ci	REG(SYS_PTP_STATUS,			0x000f14),
2978c2ecf20Sopenharmony_ci	REG(SYS_PTP_TXSTAMP,			0x000f18),
2988c2ecf20Sopenharmony_ci	REG(SYS_PTP_NXT,			0x000f1c),
2998c2ecf20Sopenharmony_ci	REG(SYS_PTP_CFG,			0x000f20),
3008c2ecf20Sopenharmony_ci	REG(SYS_RAM_INIT,			0x000f24),
3018c2ecf20Sopenharmony_ci	REG_RESERVED(SYS_CM_ADDR),
3028c2ecf20Sopenharmony_ci	REG_RESERVED(SYS_CM_DATA_WR),
3038c2ecf20Sopenharmony_ci	REG_RESERVED(SYS_CM_DATA_RD),
3048c2ecf20Sopenharmony_ci	REG_RESERVED(SYS_CM_OP),
3058c2ecf20Sopenharmony_ci	REG_RESERVED(SYS_CM_DATA),
3068c2ecf20Sopenharmony_ci};
3078c2ecf20Sopenharmony_ci
3088c2ecf20Sopenharmony_cistatic const u32 vsc9959_ptp_regmap[] = {
3098c2ecf20Sopenharmony_ci	REG(PTP_PIN_CFG,			0x000000),
3108c2ecf20Sopenharmony_ci	REG(PTP_PIN_TOD_SEC_MSB,		0x000004),
3118c2ecf20Sopenharmony_ci	REG(PTP_PIN_TOD_SEC_LSB,		0x000008),
3128c2ecf20Sopenharmony_ci	REG(PTP_PIN_TOD_NSEC,			0x00000c),
3138c2ecf20Sopenharmony_ci	REG(PTP_PIN_WF_HIGH_PERIOD,		0x000014),
3148c2ecf20Sopenharmony_ci	REG(PTP_PIN_WF_LOW_PERIOD,		0x000018),
3158c2ecf20Sopenharmony_ci	REG(PTP_CFG_MISC,			0x0000a0),
3168c2ecf20Sopenharmony_ci	REG(PTP_CLK_CFG_ADJ_CFG,		0x0000a4),
3178c2ecf20Sopenharmony_ci	REG(PTP_CLK_CFG_ADJ_FREQ,		0x0000a8),
3188c2ecf20Sopenharmony_ci};
3198c2ecf20Sopenharmony_ci
3208c2ecf20Sopenharmony_cistatic const u32 vsc9959_gcb_regmap[] = {
3218c2ecf20Sopenharmony_ci	REG(GCB_SOFT_RST,			0x000004),
3228c2ecf20Sopenharmony_ci};
3238c2ecf20Sopenharmony_ci
3248c2ecf20Sopenharmony_cistatic const u32 vsc9959_dev_gmii_regmap[] = {
3258c2ecf20Sopenharmony_ci	REG(DEV_CLOCK_CFG,			0x0),
3268c2ecf20Sopenharmony_ci	REG(DEV_PORT_MISC,			0x4),
3278c2ecf20Sopenharmony_ci	REG(DEV_EVENTS,				0x8),
3288c2ecf20Sopenharmony_ci	REG(DEV_EEE_CFG,			0xc),
3298c2ecf20Sopenharmony_ci	REG(DEV_RX_PATH_DELAY,			0x10),
3308c2ecf20Sopenharmony_ci	REG(DEV_TX_PATH_DELAY,			0x14),
3318c2ecf20Sopenharmony_ci	REG(DEV_PTP_PREDICT_CFG,		0x18),
3328c2ecf20Sopenharmony_ci	REG(DEV_MAC_ENA_CFG,			0x1c),
3338c2ecf20Sopenharmony_ci	REG(DEV_MAC_MODE_CFG,			0x20),
3348c2ecf20Sopenharmony_ci	REG(DEV_MAC_MAXLEN_CFG,			0x24),
3358c2ecf20Sopenharmony_ci	REG(DEV_MAC_TAGS_CFG,			0x28),
3368c2ecf20Sopenharmony_ci	REG(DEV_MAC_ADV_CHK_CFG,		0x2c),
3378c2ecf20Sopenharmony_ci	REG(DEV_MAC_IFG_CFG,			0x30),
3388c2ecf20Sopenharmony_ci	REG(DEV_MAC_HDX_CFG,			0x34),
3398c2ecf20Sopenharmony_ci	REG(DEV_MAC_DBG_CFG,			0x38),
3408c2ecf20Sopenharmony_ci	REG(DEV_MAC_FC_MAC_LOW_CFG,		0x3c),
3418c2ecf20Sopenharmony_ci	REG(DEV_MAC_FC_MAC_HIGH_CFG,		0x40),
3428c2ecf20Sopenharmony_ci	REG(DEV_MAC_STICKY,			0x44),
3438c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_CFG),
3448c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_MODE_CFG),
3458c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_SD_CFG),
3468c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_ANEG_CFG),
3478c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_ANEG_NP_CFG),
3488c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_LB_CFG),
3498c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_DBG_CFG),
3508c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_CDET_CFG),
3518c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_ANEG_STATUS),
3528c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_ANEG_NP_STATUS),
3538c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_LINK_STATUS),
3548c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_LINK_DOWN_CNT),
3558c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_STICKY),
3568c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_DEBUG_STATUS),
3578c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_LPI_CFG),
3588c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_LPI_WAKE_ERROR_CNT),
3598c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_LPI_STATUS),
3608c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_TSTPAT_MODE_CFG),
3618c2ecf20Sopenharmony_ci	REG_RESERVED(PCS1G_TSTPAT_STATUS),
3628c2ecf20Sopenharmony_ci	REG_RESERVED(DEV_PCS_FX100_CFG),
3638c2ecf20Sopenharmony_ci	REG_RESERVED(DEV_PCS_FX100_STATUS),
3648c2ecf20Sopenharmony_ci};
3658c2ecf20Sopenharmony_ci
3668c2ecf20Sopenharmony_cistatic const u32 *vsc9959_regmap[TARGET_MAX] = {
3678c2ecf20Sopenharmony_ci	[ANA]	= vsc9959_ana_regmap,
3688c2ecf20Sopenharmony_ci	[QS]	= vsc9959_qs_regmap,
3698c2ecf20Sopenharmony_ci	[QSYS]	= vsc9959_qsys_regmap,
3708c2ecf20Sopenharmony_ci	[REW]	= vsc9959_rew_regmap,
3718c2ecf20Sopenharmony_ci	[SYS]	= vsc9959_sys_regmap,
3728c2ecf20Sopenharmony_ci	[S0]	= vsc9959_vcap_regmap,
3738c2ecf20Sopenharmony_ci	[S1]	= vsc9959_vcap_regmap,
3748c2ecf20Sopenharmony_ci	[S2]	= vsc9959_vcap_regmap,
3758c2ecf20Sopenharmony_ci	[PTP]	= vsc9959_ptp_regmap,
3768c2ecf20Sopenharmony_ci	[GCB]	= vsc9959_gcb_regmap,
3778c2ecf20Sopenharmony_ci	[DEV_GMII] = vsc9959_dev_gmii_regmap,
3788c2ecf20Sopenharmony_ci};
3798c2ecf20Sopenharmony_ci
3808c2ecf20Sopenharmony_ci/* Addresses are relative to the PCI device's base address */
3818c2ecf20Sopenharmony_cistatic const struct resource vsc9959_target_io_res[TARGET_MAX] = {
3828c2ecf20Sopenharmony_ci	[ANA] = {
3838c2ecf20Sopenharmony_ci		.start	= 0x0280000,
3848c2ecf20Sopenharmony_ci		.end	= 0x028ffff,
3858c2ecf20Sopenharmony_ci		.name	= "ana",
3868c2ecf20Sopenharmony_ci	},
3878c2ecf20Sopenharmony_ci	[QS] = {
3888c2ecf20Sopenharmony_ci		.start	= 0x0080000,
3898c2ecf20Sopenharmony_ci		.end	= 0x00800ff,
3908c2ecf20Sopenharmony_ci		.name	= "qs",
3918c2ecf20Sopenharmony_ci	},
3928c2ecf20Sopenharmony_ci	[QSYS] = {
3938c2ecf20Sopenharmony_ci		.start	= 0x0200000,
3948c2ecf20Sopenharmony_ci		.end	= 0x021ffff,
3958c2ecf20Sopenharmony_ci		.name	= "qsys",
3968c2ecf20Sopenharmony_ci	},
3978c2ecf20Sopenharmony_ci	[REW] = {
3988c2ecf20Sopenharmony_ci		.start	= 0x0030000,
3998c2ecf20Sopenharmony_ci		.end	= 0x003ffff,
4008c2ecf20Sopenharmony_ci		.name	= "rew",
4018c2ecf20Sopenharmony_ci	},
4028c2ecf20Sopenharmony_ci	[SYS] = {
4038c2ecf20Sopenharmony_ci		.start	= 0x0010000,
4048c2ecf20Sopenharmony_ci		.end	= 0x001ffff,
4058c2ecf20Sopenharmony_ci		.name	= "sys",
4068c2ecf20Sopenharmony_ci	},
4078c2ecf20Sopenharmony_ci	[S0] = {
4088c2ecf20Sopenharmony_ci		.start	= 0x0040000,
4098c2ecf20Sopenharmony_ci		.end	= 0x00403ff,
4108c2ecf20Sopenharmony_ci		.name	= "s0",
4118c2ecf20Sopenharmony_ci	},
4128c2ecf20Sopenharmony_ci	[S1] = {
4138c2ecf20Sopenharmony_ci		.start	= 0x0050000,
4148c2ecf20Sopenharmony_ci		.end	= 0x00503ff,
4158c2ecf20Sopenharmony_ci		.name	= "s1",
4168c2ecf20Sopenharmony_ci	},
4178c2ecf20Sopenharmony_ci	[S2] = {
4188c2ecf20Sopenharmony_ci		.start	= 0x0060000,
4198c2ecf20Sopenharmony_ci		.end	= 0x00603ff,
4208c2ecf20Sopenharmony_ci		.name	= "s2",
4218c2ecf20Sopenharmony_ci	},
4228c2ecf20Sopenharmony_ci	[PTP] = {
4238c2ecf20Sopenharmony_ci		.start	= 0x0090000,
4248c2ecf20Sopenharmony_ci		.end	= 0x00900cb,
4258c2ecf20Sopenharmony_ci		.name	= "ptp",
4268c2ecf20Sopenharmony_ci	},
4278c2ecf20Sopenharmony_ci	[GCB] = {
4288c2ecf20Sopenharmony_ci		.start	= 0x0070000,
4298c2ecf20Sopenharmony_ci		.end	= 0x00701ff,
4308c2ecf20Sopenharmony_ci		.name	= "devcpu_gcb",
4318c2ecf20Sopenharmony_ci	},
4328c2ecf20Sopenharmony_ci};
4338c2ecf20Sopenharmony_ci
4348c2ecf20Sopenharmony_cistatic const struct resource vsc9959_port_io_res[] = {
4358c2ecf20Sopenharmony_ci	{
4368c2ecf20Sopenharmony_ci		.start	= 0x0100000,
4378c2ecf20Sopenharmony_ci		.end	= 0x010ffff,
4388c2ecf20Sopenharmony_ci		.name	= "port0",
4398c2ecf20Sopenharmony_ci	},
4408c2ecf20Sopenharmony_ci	{
4418c2ecf20Sopenharmony_ci		.start	= 0x0110000,
4428c2ecf20Sopenharmony_ci		.end	= 0x011ffff,
4438c2ecf20Sopenharmony_ci		.name	= "port1",
4448c2ecf20Sopenharmony_ci	},
4458c2ecf20Sopenharmony_ci	{
4468c2ecf20Sopenharmony_ci		.start	= 0x0120000,
4478c2ecf20Sopenharmony_ci		.end	= 0x012ffff,
4488c2ecf20Sopenharmony_ci		.name	= "port2",
4498c2ecf20Sopenharmony_ci	},
4508c2ecf20Sopenharmony_ci	{
4518c2ecf20Sopenharmony_ci		.start	= 0x0130000,
4528c2ecf20Sopenharmony_ci		.end	= 0x013ffff,
4538c2ecf20Sopenharmony_ci		.name	= "port3",
4548c2ecf20Sopenharmony_ci	},
4558c2ecf20Sopenharmony_ci	{
4568c2ecf20Sopenharmony_ci		.start	= 0x0140000,
4578c2ecf20Sopenharmony_ci		.end	= 0x014ffff,
4588c2ecf20Sopenharmony_ci		.name	= "port4",
4598c2ecf20Sopenharmony_ci	},
4608c2ecf20Sopenharmony_ci	{
4618c2ecf20Sopenharmony_ci		.start	= 0x0150000,
4628c2ecf20Sopenharmony_ci		.end	= 0x015ffff,
4638c2ecf20Sopenharmony_ci		.name	= "port5",
4648c2ecf20Sopenharmony_ci	},
4658c2ecf20Sopenharmony_ci};
4668c2ecf20Sopenharmony_ci
4678c2ecf20Sopenharmony_ci/* Port MAC 0 Internal MDIO bus through which the SerDes acting as an
4688c2ecf20Sopenharmony_ci * SGMII/QSGMII MAC PCS can be found.
4698c2ecf20Sopenharmony_ci */
4708c2ecf20Sopenharmony_cistatic const struct resource vsc9959_imdio_res = {
4718c2ecf20Sopenharmony_ci	.start		= 0x8030,
4728c2ecf20Sopenharmony_ci	.end		= 0x8040,
4738c2ecf20Sopenharmony_ci	.name		= "imdio",
4748c2ecf20Sopenharmony_ci};
4758c2ecf20Sopenharmony_ci
4768c2ecf20Sopenharmony_cistatic const struct reg_field vsc9959_regfields[REGFIELD_MAX] = {
4778c2ecf20Sopenharmony_ci	[ANA_ADVLEARN_VLAN_CHK] = REG_FIELD(ANA_ADVLEARN, 6, 6),
4788c2ecf20Sopenharmony_ci	[ANA_ADVLEARN_LEARN_MIRROR] = REG_FIELD(ANA_ADVLEARN, 0, 5),
4798c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_FLOOD_DISCARD] = REG_FIELD(ANA_ANEVENTS, 30, 30),
4808c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_AUTOAGE] = REG_FIELD(ANA_ANEVENTS, 26, 26),
4818c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_STORM_DROP] = REG_FIELD(ANA_ANEVENTS, 24, 24),
4828c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_LEARN_DROP] = REG_FIELD(ANA_ANEVENTS, 23, 23),
4838c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_AGED_ENTRY] = REG_FIELD(ANA_ANEVENTS, 22, 22),
4848c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_CPU_LEARN_FAILED] = REG_FIELD(ANA_ANEVENTS, 21, 21),
4858c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_AUTO_LEARN_FAILED] = REG_FIELD(ANA_ANEVENTS, 20, 20),
4868c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_LEARN_REMOVE] = REG_FIELD(ANA_ANEVENTS, 19, 19),
4878c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_AUTO_LEARNED] = REG_FIELD(ANA_ANEVENTS, 18, 18),
4888c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_AUTO_MOVED] = REG_FIELD(ANA_ANEVENTS, 17, 17),
4898c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_CLASSIFIED_DROP] = REG_FIELD(ANA_ANEVENTS, 15, 15),
4908c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_CLASSIFIED_COPY] = REG_FIELD(ANA_ANEVENTS, 14, 14),
4918c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_VLAN_DISCARD] = REG_FIELD(ANA_ANEVENTS, 13, 13),
4928c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_FWD_DISCARD] = REG_FIELD(ANA_ANEVENTS, 12, 12),
4938c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_MULTICAST_FLOOD] = REG_FIELD(ANA_ANEVENTS, 11, 11),
4948c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_UNICAST_FLOOD] = REG_FIELD(ANA_ANEVENTS, 10, 10),
4958c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_DEST_KNOWN] = REG_FIELD(ANA_ANEVENTS, 9, 9),
4968c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_BUCKET3_MATCH] = REG_FIELD(ANA_ANEVENTS, 8, 8),
4978c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_BUCKET2_MATCH] = REG_FIELD(ANA_ANEVENTS, 7, 7),
4988c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_BUCKET1_MATCH] = REG_FIELD(ANA_ANEVENTS, 6, 6),
4998c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_BUCKET0_MATCH] = REG_FIELD(ANA_ANEVENTS, 5, 5),
5008c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_CPU_OPERATION] = REG_FIELD(ANA_ANEVENTS, 4, 4),
5018c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_DMAC_LOOKUP] = REG_FIELD(ANA_ANEVENTS, 3, 3),
5028c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_SMAC_LOOKUP] = REG_FIELD(ANA_ANEVENTS, 2, 2),
5038c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_SEQ_GEN_ERR_0] = REG_FIELD(ANA_ANEVENTS, 1, 1),
5048c2ecf20Sopenharmony_ci	[ANA_ANEVENTS_SEQ_GEN_ERR_1] = REG_FIELD(ANA_ANEVENTS, 0, 0),
5058c2ecf20Sopenharmony_ci	[ANA_TABLES_MACACCESS_B_DOM] = REG_FIELD(ANA_TABLES_MACACCESS, 16, 16),
5068c2ecf20Sopenharmony_ci	[ANA_TABLES_MACTINDX_BUCKET] = REG_FIELD(ANA_TABLES_MACTINDX, 11, 12),
5078c2ecf20Sopenharmony_ci	[ANA_TABLES_MACTINDX_M_INDEX] = REG_FIELD(ANA_TABLES_MACTINDX, 0, 10),
5088c2ecf20Sopenharmony_ci	[SYS_RESET_CFG_CORE_ENA] = REG_FIELD(SYS_RESET_CFG, 0, 0),
5098c2ecf20Sopenharmony_ci	[GCB_SOFT_RST_SWC_RST] = REG_FIELD(GCB_SOFT_RST, 0, 0),
5108c2ecf20Sopenharmony_ci	/* Replicated per number of ports (7), register size 4 per port */
5118c2ecf20Sopenharmony_ci	[QSYS_SWITCH_PORT_MODE_PORT_ENA] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 14, 14, 7, 4),
5128c2ecf20Sopenharmony_ci	[QSYS_SWITCH_PORT_MODE_SCH_NEXT_CFG] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 11, 13, 7, 4),
5138c2ecf20Sopenharmony_ci	[QSYS_SWITCH_PORT_MODE_YEL_RSRVD] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 10, 10, 7, 4),
5148c2ecf20Sopenharmony_ci	[QSYS_SWITCH_PORT_MODE_INGRESS_DROP_MODE] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 9, 9, 7, 4),
5158c2ecf20Sopenharmony_ci	[QSYS_SWITCH_PORT_MODE_TX_PFC_ENA] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 1, 8, 7, 4),
5168c2ecf20Sopenharmony_ci	[QSYS_SWITCH_PORT_MODE_TX_PFC_MODE] = REG_FIELD_ID(QSYS_SWITCH_PORT_MODE, 0, 0, 7, 4),
5178c2ecf20Sopenharmony_ci	[SYS_PORT_MODE_DATA_WO_TS] = REG_FIELD_ID(SYS_PORT_MODE, 5, 6, 7, 4),
5188c2ecf20Sopenharmony_ci	[SYS_PORT_MODE_INCL_INJ_HDR] = REG_FIELD_ID(SYS_PORT_MODE, 3, 4, 7, 4),
5198c2ecf20Sopenharmony_ci	[SYS_PORT_MODE_INCL_XTR_HDR] = REG_FIELD_ID(SYS_PORT_MODE, 1, 2, 7, 4),
5208c2ecf20Sopenharmony_ci	[SYS_PORT_MODE_INCL_HDR_ERR] = REG_FIELD_ID(SYS_PORT_MODE, 0, 0, 7, 4),
5218c2ecf20Sopenharmony_ci	[SYS_PAUSE_CFG_PAUSE_START] = REG_FIELD_ID(SYS_PAUSE_CFG, 10, 18, 7, 4),
5228c2ecf20Sopenharmony_ci	[SYS_PAUSE_CFG_PAUSE_STOP] = REG_FIELD_ID(SYS_PAUSE_CFG, 1, 9, 7, 4),
5238c2ecf20Sopenharmony_ci	[SYS_PAUSE_CFG_PAUSE_ENA] = REG_FIELD_ID(SYS_PAUSE_CFG, 0, 1, 7, 4),
5248c2ecf20Sopenharmony_ci};
5258c2ecf20Sopenharmony_ci
5268c2ecf20Sopenharmony_cistatic const struct ocelot_stat_layout vsc9959_stats_layout[] = {
5278c2ecf20Sopenharmony_ci	{ .offset = 0x00,	.name = "rx_octets", },
5288c2ecf20Sopenharmony_ci	{ .offset = 0x01,	.name = "rx_unicast", },
5298c2ecf20Sopenharmony_ci	{ .offset = 0x02,	.name = "rx_multicast", },
5308c2ecf20Sopenharmony_ci	{ .offset = 0x03,	.name = "rx_broadcast", },
5318c2ecf20Sopenharmony_ci	{ .offset = 0x04,	.name = "rx_shorts", },
5328c2ecf20Sopenharmony_ci	{ .offset = 0x05,	.name = "rx_fragments", },
5338c2ecf20Sopenharmony_ci	{ .offset = 0x06,	.name = "rx_jabbers", },
5348c2ecf20Sopenharmony_ci	{ .offset = 0x07,	.name = "rx_crc_align_errs", },
5358c2ecf20Sopenharmony_ci	{ .offset = 0x08,	.name = "rx_sym_errs", },
5368c2ecf20Sopenharmony_ci	{ .offset = 0x09,	.name = "rx_frames_below_65_octets", },
5378c2ecf20Sopenharmony_ci	{ .offset = 0x0A,	.name = "rx_frames_65_to_127_octets", },
5388c2ecf20Sopenharmony_ci	{ .offset = 0x0B,	.name = "rx_frames_128_to_255_octets", },
5398c2ecf20Sopenharmony_ci	{ .offset = 0x0C,	.name = "rx_frames_256_to_511_octets", },
5408c2ecf20Sopenharmony_ci	{ .offset = 0x0D,	.name = "rx_frames_512_to_1023_octets", },
5418c2ecf20Sopenharmony_ci	{ .offset = 0x0E,	.name = "rx_frames_1024_to_1526_octets", },
5428c2ecf20Sopenharmony_ci	{ .offset = 0x0F,	.name = "rx_frames_over_1526_octets", },
5438c2ecf20Sopenharmony_ci	{ .offset = 0x10,	.name = "rx_pause", },
5448c2ecf20Sopenharmony_ci	{ .offset = 0x11,	.name = "rx_control", },
5458c2ecf20Sopenharmony_ci	{ .offset = 0x12,	.name = "rx_longs", },
5468c2ecf20Sopenharmony_ci	{ .offset = 0x13,	.name = "rx_classified_drops", },
5478c2ecf20Sopenharmony_ci	{ .offset = 0x14,	.name = "rx_red_prio_0", },
5488c2ecf20Sopenharmony_ci	{ .offset = 0x15,	.name = "rx_red_prio_1", },
5498c2ecf20Sopenharmony_ci	{ .offset = 0x16,	.name = "rx_red_prio_2", },
5508c2ecf20Sopenharmony_ci	{ .offset = 0x17,	.name = "rx_red_prio_3", },
5518c2ecf20Sopenharmony_ci	{ .offset = 0x18,	.name = "rx_red_prio_4", },
5528c2ecf20Sopenharmony_ci	{ .offset = 0x19,	.name = "rx_red_prio_5", },
5538c2ecf20Sopenharmony_ci	{ .offset = 0x1A,	.name = "rx_red_prio_6", },
5548c2ecf20Sopenharmony_ci	{ .offset = 0x1B,	.name = "rx_red_prio_7", },
5558c2ecf20Sopenharmony_ci	{ .offset = 0x1C,	.name = "rx_yellow_prio_0", },
5568c2ecf20Sopenharmony_ci	{ .offset = 0x1D,	.name = "rx_yellow_prio_1", },
5578c2ecf20Sopenharmony_ci	{ .offset = 0x1E,	.name = "rx_yellow_prio_2", },
5588c2ecf20Sopenharmony_ci	{ .offset = 0x1F,	.name = "rx_yellow_prio_3", },
5598c2ecf20Sopenharmony_ci	{ .offset = 0x20,	.name = "rx_yellow_prio_4", },
5608c2ecf20Sopenharmony_ci	{ .offset = 0x21,	.name = "rx_yellow_prio_5", },
5618c2ecf20Sopenharmony_ci	{ .offset = 0x22,	.name = "rx_yellow_prio_6", },
5628c2ecf20Sopenharmony_ci	{ .offset = 0x23,	.name = "rx_yellow_prio_7", },
5638c2ecf20Sopenharmony_ci	{ .offset = 0x24,	.name = "rx_green_prio_0", },
5648c2ecf20Sopenharmony_ci	{ .offset = 0x25,	.name = "rx_green_prio_1", },
5658c2ecf20Sopenharmony_ci	{ .offset = 0x26,	.name = "rx_green_prio_2", },
5668c2ecf20Sopenharmony_ci	{ .offset = 0x27,	.name = "rx_green_prio_3", },
5678c2ecf20Sopenharmony_ci	{ .offset = 0x28,	.name = "rx_green_prio_4", },
5688c2ecf20Sopenharmony_ci	{ .offset = 0x29,	.name = "rx_green_prio_5", },
5698c2ecf20Sopenharmony_ci	{ .offset = 0x2A,	.name = "rx_green_prio_6", },
5708c2ecf20Sopenharmony_ci	{ .offset = 0x2B,	.name = "rx_green_prio_7", },
5718c2ecf20Sopenharmony_ci	{ .offset = 0x80,	.name = "tx_octets", },
5728c2ecf20Sopenharmony_ci	{ .offset = 0x81,	.name = "tx_unicast", },
5738c2ecf20Sopenharmony_ci	{ .offset = 0x82,	.name = "tx_multicast", },
5748c2ecf20Sopenharmony_ci	{ .offset = 0x83,	.name = "tx_broadcast", },
5758c2ecf20Sopenharmony_ci	{ .offset = 0x84,	.name = "tx_collision", },
5768c2ecf20Sopenharmony_ci	{ .offset = 0x85,	.name = "tx_drops", },
5778c2ecf20Sopenharmony_ci	{ .offset = 0x86,	.name = "tx_pause", },
5788c2ecf20Sopenharmony_ci	{ .offset = 0x87,	.name = "tx_frames_below_65_octets", },
5798c2ecf20Sopenharmony_ci	{ .offset = 0x88,	.name = "tx_frames_65_to_127_octets", },
5808c2ecf20Sopenharmony_ci	{ .offset = 0x89,	.name = "tx_frames_128_255_octets", },
5818c2ecf20Sopenharmony_ci	{ .offset = 0x8A,	.name = "tx_frames_256_511_octets", },
5828c2ecf20Sopenharmony_ci	{ .offset = 0x8B,	.name = "tx_frames_512_1023_octets", },
5838c2ecf20Sopenharmony_ci	{ .offset = 0x8C,	.name = "tx_frames_1024_1526_octets", },
5848c2ecf20Sopenharmony_ci	{ .offset = 0x8D,	.name = "tx_frames_over_1526_octets", },
5858c2ecf20Sopenharmony_ci	{ .offset = 0x8E,	.name = "tx_yellow_prio_0", },
5868c2ecf20Sopenharmony_ci	{ .offset = 0x8F,	.name = "tx_yellow_prio_1", },
5878c2ecf20Sopenharmony_ci	{ .offset = 0x90,	.name = "tx_yellow_prio_2", },
5888c2ecf20Sopenharmony_ci	{ .offset = 0x91,	.name = "tx_yellow_prio_3", },
5898c2ecf20Sopenharmony_ci	{ .offset = 0x92,	.name = "tx_yellow_prio_4", },
5908c2ecf20Sopenharmony_ci	{ .offset = 0x93,	.name = "tx_yellow_prio_5", },
5918c2ecf20Sopenharmony_ci	{ .offset = 0x94,	.name = "tx_yellow_prio_6", },
5928c2ecf20Sopenharmony_ci	{ .offset = 0x95,	.name = "tx_yellow_prio_7", },
5938c2ecf20Sopenharmony_ci	{ .offset = 0x96,	.name = "tx_green_prio_0", },
5948c2ecf20Sopenharmony_ci	{ .offset = 0x97,	.name = "tx_green_prio_1", },
5958c2ecf20Sopenharmony_ci	{ .offset = 0x98,	.name = "tx_green_prio_2", },
5968c2ecf20Sopenharmony_ci	{ .offset = 0x99,	.name = "tx_green_prio_3", },
5978c2ecf20Sopenharmony_ci	{ .offset = 0x9A,	.name = "tx_green_prio_4", },
5988c2ecf20Sopenharmony_ci	{ .offset = 0x9B,	.name = "tx_green_prio_5", },
5998c2ecf20Sopenharmony_ci	{ .offset = 0x9C,	.name = "tx_green_prio_6", },
6008c2ecf20Sopenharmony_ci	{ .offset = 0x9D,	.name = "tx_green_prio_7", },
6018c2ecf20Sopenharmony_ci	{ .offset = 0x9E,	.name = "tx_aged", },
6028c2ecf20Sopenharmony_ci	{ .offset = 0x100,	.name = "drop_local", },
6038c2ecf20Sopenharmony_ci	{ .offset = 0x101,	.name = "drop_tail", },
6048c2ecf20Sopenharmony_ci	{ .offset = 0x102,	.name = "drop_yellow_prio_0", },
6058c2ecf20Sopenharmony_ci	{ .offset = 0x103,	.name = "drop_yellow_prio_1", },
6068c2ecf20Sopenharmony_ci	{ .offset = 0x104,	.name = "drop_yellow_prio_2", },
6078c2ecf20Sopenharmony_ci	{ .offset = 0x105,	.name = "drop_yellow_prio_3", },
6088c2ecf20Sopenharmony_ci	{ .offset = 0x106,	.name = "drop_yellow_prio_4", },
6098c2ecf20Sopenharmony_ci	{ .offset = 0x107,	.name = "drop_yellow_prio_5", },
6108c2ecf20Sopenharmony_ci	{ .offset = 0x108,	.name = "drop_yellow_prio_6", },
6118c2ecf20Sopenharmony_ci	{ .offset = 0x109,	.name = "drop_yellow_prio_7", },
6128c2ecf20Sopenharmony_ci	{ .offset = 0x10A,	.name = "drop_green_prio_0", },
6138c2ecf20Sopenharmony_ci	{ .offset = 0x10B,	.name = "drop_green_prio_1", },
6148c2ecf20Sopenharmony_ci	{ .offset = 0x10C,	.name = "drop_green_prio_2", },
6158c2ecf20Sopenharmony_ci	{ .offset = 0x10D,	.name = "drop_green_prio_3", },
6168c2ecf20Sopenharmony_ci	{ .offset = 0x10E,	.name = "drop_green_prio_4", },
6178c2ecf20Sopenharmony_ci	{ .offset = 0x10F,	.name = "drop_green_prio_5", },
6188c2ecf20Sopenharmony_ci	{ .offset = 0x110,	.name = "drop_green_prio_6", },
6198c2ecf20Sopenharmony_ci	{ .offset = 0x111,	.name = "drop_green_prio_7", },
6208c2ecf20Sopenharmony_ci};
6218c2ecf20Sopenharmony_ci
6228c2ecf20Sopenharmony_cistatic const struct vcap_field vsc9959_vcap_es0_keys[] = {
6238c2ecf20Sopenharmony_ci	[VCAP_ES0_EGR_PORT]			= {  0,  3},
6248c2ecf20Sopenharmony_ci	[VCAP_ES0_IGR_PORT]			= {  3,  3},
6258c2ecf20Sopenharmony_ci	[VCAP_ES0_RSV]				= {  6,  2},
6268c2ecf20Sopenharmony_ci	[VCAP_ES0_L2_MC]			= {  8,  1},
6278c2ecf20Sopenharmony_ci	[VCAP_ES0_L2_BC]			= {  9,  1},
6288c2ecf20Sopenharmony_ci	[VCAP_ES0_VID]				= { 10, 12},
6298c2ecf20Sopenharmony_ci	[VCAP_ES0_DP]				= { 22,  1},
6308c2ecf20Sopenharmony_ci	[VCAP_ES0_PCP]				= { 23,  3},
6318c2ecf20Sopenharmony_ci};
6328c2ecf20Sopenharmony_ci
6338c2ecf20Sopenharmony_cistatic const struct vcap_field vsc9959_vcap_es0_actions[] = {
6348c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_PUSH_OUTER_TAG]		= {  0,  2},
6358c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_PUSH_INNER_TAG]		= {  2,  1},
6368c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_TAG_A_TPID_SEL]		= {  3,  2},
6378c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_TAG_A_VID_SEL]		= {  5,  1},
6388c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_TAG_A_PCP_SEL]		= {  6,  2},
6398c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_TAG_A_DEI_SEL]		= {  8,  2},
6408c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_TAG_B_TPID_SEL]		= { 10,  2},
6418c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_TAG_B_VID_SEL]		= { 12,  1},
6428c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_TAG_B_PCP_SEL]		= { 13,  2},
6438c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_TAG_B_DEI_SEL]		= { 15,  2},
6448c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_VID_A_VAL]		= { 17, 12},
6458c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_PCP_A_VAL]		= { 29,  3},
6468c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_DEI_A_VAL]		= { 32,  1},
6478c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_VID_B_VAL]		= { 33, 12},
6488c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_PCP_B_VAL]		= { 45,  3},
6498c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_DEI_B_VAL]		= { 48,  1},
6508c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_RSV]			= { 49, 23},
6518c2ecf20Sopenharmony_ci	[VCAP_ES0_ACT_HIT_STICKY]		= { 72,  1},
6528c2ecf20Sopenharmony_ci};
6538c2ecf20Sopenharmony_ci
6548c2ecf20Sopenharmony_cistatic const struct vcap_field vsc9959_vcap_is1_keys[] = {
6558c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_TYPE]			= {  0,   1},
6568c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_LOOKUP]			= {  1,   2},
6578c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IGR_PORT_MASK]		= {  3,   7},
6588c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_RSV]			= { 10,   9},
6598c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_OAM_Y1731]			= { 19,   1},
6608c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_L2_MC]			= { 20,   1},
6618c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_L2_BC]			= { 21,   1},
6628c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP_MC]			= { 22,   1},
6638c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_VLAN_TAGGED]		= { 23,   1},
6648c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_VLAN_DBL_TAGGED]		= { 24,   1},
6658c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_TPID]			= { 25,   1},
6668c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_VID]			= { 26,  12},
6678c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_DEI]			= { 38,   1},
6688c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_PCP]			= { 39,   3},
6698c2ecf20Sopenharmony_ci	/* Specific Fields for IS1 Half Key S1_NORMAL */
6708c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_L2_SMAC]			= { 42,  48},
6718c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_ETYPE_LEN]			= { 90,   1},
6728c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_ETYPE]			= { 91,  16},
6738c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP_SNAP]			= {107,   1},
6748c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4]			= {108,   1},
6758c2ecf20Sopenharmony_ci	/* Layer-3 Information */
6768c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_L3_FRAGMENT]		= {109,   1},
6778c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_L3_FRAG_OFS_GT0]		= {110,   1},
6788c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_L3_OPTIONS]		= {111,   1},
6798c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_L3_DSCP]			= {112,   6},
6808c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_L3_IP4_SIP]		= {118,  32},
6818c2ecf20Sopenharmony_ci	/* Layer-4 Information */
6828c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_TCP_UDP]			= {150,   1},
6838c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_TCP]			= {151,   1},
6848c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_L4_SPORT]			= {152,  16},
6858c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_L4_RNG]			= {168,   8},
6868c2ecf20Sopenharmony_ci	/* Specific Fields for IS1 Half Key S1_5TUPLE_IP4 */
6878c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4_INNER_TPID]            = { 42,   1},
6888c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4_INNER_VID]		= { 43,  12},
6898c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4_INNER_DEI]		= { 55,   1},
6908c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4_INNER_PCP]		= { 56,   3},
6918c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4_IP4]			= { 59,   1},
6928c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4_L3_FRAGMENT]		= { 60,   1},
6938c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4_L3_FRAG_OFS_GT0]	= { 61,   1},
6948c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4_L3_OPTIONS]		= { 62,   1},
6958c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4_L3_DSCP]		= { 63,   6},
6968c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4_L3_IP4_DIP]		= { 69,  32},
6978c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4_L3_IP4_SIP]		= {101,  32},
6988c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4_L3_PROTO]		= {133,   8},
6998c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4_TCP_UDP]		= {141,   1},
7008c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4_TCP]			= {142,   1},
7018c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4_L4_RNG]		= {143,   8},
7028c2ecf20Sopenharmony_ci	[VCAP_IS1_HK_IP4_IP_PAYLOAD_S1_5TUPLE]	= {151,  32},
7038c2ecf20Sopenharmony_ci};
7048c2ecf20Sopenharmony_ci
7058c2ecf20Sopenharmony_cistatic const struct vcap_field vsc9959_vcap_is1_actions[] = {
7068c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_DSCP_ENA]			= {  0,  1},
7078c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_DSCP_VAL]			= {  1,  6},
7088c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_QOS_ENA]			= {  7,  1},
7098c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_QOS_VAL]			= {  8,  3},
7108c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_DP_ENA]			= { 11,  1},
7118c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_DP_VAL]			= { 12,  1},
7128c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_PAG_OVERRIDE_MASK]	= { 13,  8},
7138c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_PAG_VAL]			= { 21,  8},
7148c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_RSV]			= { 29,  9},
7158c2ecf20Sopenharmony_ci	/* The fields below are incorrectly shifted by 2 in the manual */
7168c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_VID_REPLACE_ENA]		= { 38,  1},
7178c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_VID_ADD_VAL]		= { 39, 12},
7188c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_FID_SEL]			= { 51,  2},
7198c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_FID_VAL]			= { 53, 13},
7208c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_PCP_DEI_ENA]		= { 66,  1},
7218c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_PCP_VAL]			= { 67,  3},
7228c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_DEI_VAL]			= { 70,  1},
7238c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_VLAN_POP_CNT_ENA]		= { 71,  1},
7248c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_VLAN_POP_CNT]		= { 72,  2},
7258c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_CUSTOM_ACE_TYPE_ENA]	= { 74,  4},
7268c2ecf20Sopenharmony_ci	[VCAP_IS1_ACT_HIT_STICKY]		= { 78,  1},
7278c2ecf20Sopenharmony_ci};
7288c2ecf20Sopenharmony_ci
7298c2ecf20Sopenharmony_cistatic struct vcap_field vsc9959_vcap_is2_keys[] = {
7308c2ecf20Sopenharmony_ci	/* Common: 41 bits */
7318c2ecf20Sopenharmony_ci	[VCAP_IS2_TYPE]				= {  0,   4},
7328c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_FIRST]			= {  4,   1},
7338c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_PAG]			= {  5,   8},
7348c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_IGR_PORT_MASK]		= { 13,   7},
7358c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_RSV2]			= { 20,   1},
7368c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_HOST_MATCH]		= { 21,   1},
7378c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L2_MC]			= { 22,   1},
7388c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L2_BC]			= { 23,   1},
7398c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_VLAN_TAGGED]		= { 24,   1},
7408c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_VID]			= { 25,  12},
7418c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_DEI]			= { 37,   1},
7428c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_PCP]			= { 38,   3},
7438c2ecf20Sopenharmony_ci	/* MAC_ETYPE / MAC_LLC / MAC_SNAP / OAM common */
7448c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L2_DMAC]			= { 41,  48},
7458c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L2_SMAC]			= { 89,  48},
7468c2ecf20Sopenharmony_ci	/* MAC_ETYPE (TYPE=000) */
7478c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_ETYPE_ETYPE]		= {137,  16},
7488c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD0]	= {153,  16},
7498c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD1]	= {169,   8},
7508c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_ETYPE_L2_PAYLOAD2]	= {177,   3},
7518c2ecf20Sopenharmony_ci	/* MAC_LLC (TYPE=001) */
7528c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_LLC_L2_LLC]		= {137,  40},
7538c2ecf20Sopenharmony_ci	/* MAC_SNAP (TYPE=010) */
7548c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_SNAP_L2_SNAP]		= {137,  40},
7558c2ecf20Sopenharmony_ci	/* MAC_ARP (TYPE=011) */
7568c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_ARP_SMAC]		= { 41,  48},
7578c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_ARP_ADDR_SPACE_OK]	= { 89,   1},
7588c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_ARP_PROTO_SPACE_OK]	= { 90,   1},
7598c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_ARP_LEN_OK]		= { 91,   1},
7608c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_ARP_TARGET_MATCH]	= { 92,   1},
7618c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_ARP_SENDER_MATCH]	= { 93,   1},
7628c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_ARP_OPCODE_UNKNOWN]	= { 94,   1},
7638c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_ARP_OPCODE]		= { 95,   2},
7648c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_ARP_L3_IP4_DIP]	= { 97,  32},
7658c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_ARP_L3_IP4_SIP]	= {129,  32},
7668c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_MAC_ARP_DIP_EQ_SIP]	= {161,   1},
7678c2ecf20Sopenharmony_ci	/* IP4_TCP_UDP / IP4_OTHER common */
7688c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_IP4]			= { 41,   1},
7698c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L3_FRAGMENT]		= { 42,   1},
7708c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L3_FRAG_OFS_GT0]		= { 43,   1},
7718c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L3_OPTIONS]		= { 44,   1},
7728c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_IP4_L3_TTL_GT0]		= { 45,   1},
7738c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L3_TOS]			= { 46,   8},
7748c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L3_IP4_DIP]		= { 54,  32},
7758c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L3_IP4_SIP]		= { 86,  32},
7768c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_DIP_EQ_SIP]		= {118,   1},
7778c2ecf20Sopenharmony_ci	/* IP4_TCP_UDP (TYPE=100) */
7788c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_TCP]			= {119,   1},
7798c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L4_DPORT]			= {120,  16},
7808c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L4_SPORT]			= {136,  16},
7818c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L4_RNG]			= {152,   8},
7828c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L4_SPORT_EQ_DPORT]		= {160,   1},
7838c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L4_SEQUENCE_EQ0]		= {161,   1},
7848c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L4_FIN]			= {162,   1},
7858c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L4_SYN]			= {163,   1},
7868c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L4_RST]			= {164,   1},
7878c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L4_PSH]			= {165,   1},
7888c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L4_ACK]			= {166,   1},
7898c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L4_URG]			= {167,   1},
7908c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L4_1588_DOM]		= {168,   8},
7918c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L4_1588_VER]		= {176,   4},
7928c2ecf20Sopenharmony_ci	/* IP4_OTHER (TYPE=101) */
7938c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_IP4_L3_PROTO]		= {119,   8},
7948c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L3_PAYLOAD]		= {127,  56},
7958c2ecf20Sopenharmony_ci	/* IP6_STD (TYPE=110) */
7968c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_IP6_L3_TTL_GT0]		= { 41,   1},
7978c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_L3_IP6_SIP]		= { 42, 128},
7988c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_IP6_L3_PROTO]		= {170,   8},
7998c2ecf20Sopenharmony_ci	/* OAM (TYPE=111) */
8008c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_OAM_MEL_FLAGS]		= {137,   7},
8018c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_OAM_VER]			= {144,   5},
8028c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_OAM_OPCODE]		= {149,   8},
8038c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_OAM_FLAGS]			= {157,   8},
8048c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_OAM_MEPID]			= {165,  16},
8058c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_OAM_CCM_CNTS_EQ0]		= {181,   1},
8068c2ecf20Sopenharmony_ci	[VCAP_IS2_HK_OAM_IS_Y1731]		= {182,   1},
8078c2ecf20Sopenharmony_ci};
8088c2ecf20Sopenharmony_ci
8098c2ecf20Sopenharmony_cistatic struct vcap_field vsc9959_vcap_is2_actions[] = {
8108c2ecf20Sopenharmony_ci	[VCAP_IS2_ACT_HIT_ME_ONCE]		= {  0,  1},
8118c2ecf20Sopenharmony_ci	[VCAP_IS2_ACT_CPU_COPY_ENA]		= {  1,  1},
8128c2ecf20Sopenharmony_ci	[VCAP_IS2_ACT_CPU_QU_NUM]		= {  2,  3},
8138c2ecf20Sopenharmony_ci	[VCAP_IS2_ACT_MASK_MODE]		= {  5,  2},
8148c2ecf20Sopenharmony_ci	[VCAP_IS2_ACT_MIRROR_ENA]		= {  7,  1},
8158c2ecf20Sopenharmony_ci	[VCAP_IS2_ACT_LRN_DIS]			= {  8,  1},
8168c2ecf20Sopenharmony_ci	[VCAP_IS2_ACT_POLICE_ENA]		= {  9,  1},
8178c2ecf20Sopenharmony_ci	[VCAP_IS2_ACT_POLICE_IDX]		= { 10,  9},
8188c2ecf20Sopenharmony_ci	[VCAP_IS2_ACT_POLICE_VCAP_ONLY]		= { 19,  1},
8198c2ecf20Sopenharmony_ci	[VCAP_IS2_ACT_PORT_MASK]		= { 20,  6},
8208c2ecf20Sopenharmony_ci	[VCAP_IS2_ACT_REW_OP]			= { 26,  9},
8218c2ecf20Sopenharmony_ci	[VCAP_IS2_ACT_SMAC_REPLACE_ENA]		= { 35,  1},
8228c2ecf20Sopenharmony_ci	[VCAP_IS2_ACT_RSV]			= { 36,  2},
8238c2ecf20Sopenharmony_ci	[VCAP_IS2_ACT_ACL_ID]			= { 38,  6},
8248c2ecf20Sopenharmony_ci	[VCAP_IS2_ACT_HIT_CNT]			= { 44, 32},
8258c2ecf20Sopenharmony_ci};
8268c2ecf20Sopenharmony_ci
8278c2ecf20Sopenharmony_cistatic struct vcap_props vsc9959_vcap_props[] = {
8288c2ecf20Sopenharmony_ci	[VCAP_ES0] = {
8298c2ecf20Sopenharmony_ci		.action_type_width = 0,
8308c2ecf20Sopenharmony_ci		.action_table = {
8318c2ecf20Sopenharmony_ci			[ES0_ACTION_TYPE_NORMAL] = {
8328c2ecf20Sopenharmony_ci				.width = 72, /* HIT_STICKY not included */
8338c2ecf20Sopenharmony_ci				.count = 1,
8348c2ecf20Sopenharmony_ci			},
8358c2ecf20Sopenharmony_ci		},
8368c2ecf20Sopenharmony_ci		.target = S0,
8378c2ecf20Sopenharmony_ci		.keys = vsc9959_vcap_es0_keys,
8388c2ecf20Sopenharmony_ci		.actions = vsc9959_vcap_es0_actions,
8398c2ecf20Sopenharmony_ci	},
8408c2ecf20Sopenharmony_ci	[VCAP_IS1] = {
8418c2ecf20Sopenharmony_ci		.action_type_width = 0,
8428c2ecf20Sopenharmony_ci		.action_table = {
8438c2ecf20Sopenharmony_ci			[IS1_ACTION_TYPE_NORMAL] = {
8448c2ecf20Sopenharmony_ci				.width = 78, /* HIT_STICKY not included */
8458c2ecf20Sopenharmony_ci				.count = 4,
8468c2ecf20Sopenharmony_ci			},
8478c2ecf20Sopenharmony_ci		},
8488c2ecf20Sopenharmony_ci		.target = S1,
8498c2ecf20Sopenharmony_ci		.keys = vsc9959_vcap_is1_keys,
8508c2ecf20Sopenharmony_ci		.actions = vsc9959_vcap_is1_actions,
8518c2ecf20Sopenharmony_ci	},
8528c2ecf20Sopenharmony_ci	[VCAP_IS2] = {
8538c2ecf20Sopenharmony_ci		.action_type_width = 1,
8548c2ecf20Sopenharmony_ci		.action_table = {
8558c2ecf20Sopenharmony_ci			[IS2_ACTION_TYPE_NORMAL] = {
8568c2ecf20Sopenharmony_ci				.width = 44,
8578c2ecf20Sopenharmony_ci				.count = 2
8588c2ecf20Sopenharmony_ci			},
8598c2ecf20Sopenharmony_ci			[IS2_ACTION_TYPE_SMAC_SIP] = {
8608c2ecf20Sopenharmony_ci				.width = 6,
8618c2ecf20Sopenharmony_ci				.count = 4
8628c2ecf20Sopenharmony_ci			},
8638c2ecf20Sopenharmony_ci		},
8648c2ecf20Sopenharmony_ci		.target = S2,
8658c2ecf20Sopenharmony_ci		.keys = vsc9959_vcap_is2_keys,
8668c2ecf20Sopenharmony_ci		.actions = vsc9959_vcap_is2_actions,
8678c2ecf20Sopenharmony_ci	},
8688c2ecf20Sopenharmony_ci};
8698c2ecf20Sopenharmony_ci
8708c2ecf20Sopenharmony_cistatic const struct ptp_clock_info vsc9959_ptp_caps = {
8718c2ecf20Sopenharmony_ci	.owner		= THIS_MODULE,
8728c2ecf20Sopenharmony_ci	.name		= "felix ptp",
8738c2ecf20Sopenharmony_ci	.max_adj	= 0x7fffffff,
8748c2ecf20Sopenharmony_ci	.n_alarm	= 0,
8758c2ecf20Sopenharmony_ci	.n_ext_ts	= 0,
8768c2ecf20Sopenharmony_ci	.n_per_out	= OCELOT_PTP_PINS_NUM,
8778c2ecf20Sopenharmony_ci	.n_pins		= OCELOT_PTP_PINS_NUM,
8788c2ecf20Sopenharmony_ci	.pps		= 0,
8798c2ecf20Sopenharmony_ci	.gettime64	= ocelot_ptp_gettime64,
8808c2ecf20Sopenharmony_ci	.settime64	= ocelot_ptp_settime64,
8818c2ecf20Sopenharmony_ci	.adjtime	= ocelot_ptp_adjtime,
8828c2ecf20Sopenharmony_ci	.adjfine	= ocelot_ptp_adjfine,
8838c2ecf20Sopenharmony_ci	.verify		= ocelot_ptp_verify,
8848c2ecf20Sopenharmony_ci	.enable		= ocelot_ptp_enable,
8858c2ecf20Sopenharmony_ci};
8868c2ecf20Sopenharmony_ci
8878c2ecf20Sopenharmony_ci#define VSC9959_INIT_TIMEOUT			50000
8888c2ecf20Sopenharmony_ci#define VSC9959_GCB_RST_SLEEP			100
8898c2ecf20Sopenharmony_ci#define VSC9959_SYS_RAMINIT_SLEEP		80
8908c2ecf20Sopenharmony_ci
8918c2ecf20Sopenharmony_cistatic int vsc9959_gcb_soft_rst_status(struct ocelot *ocelot)
8928c2ecf20Sopenharmony_ci{
8938c2ecf20Sopenharmony_ci	int val;
8948c2ecf20Sopenharmony_ci
8958c2ecf20Sopenharmony_ci	ocelot_field_read(ocelot, GCB_SOFT_RST_SWC_RST, &val);
8968c2ecf20Sopenharmony_ci
8978c2ecf20Sopenharmony_ci	return val;
8988c2ecf20Sopenharmony_ci}
8998c2ecf20Sopenharmony_ci
9008c2ecf20Sopenharmony_cistatic int vsc9959_sys_ram_init_status(struct ocelot *ocelot)
9018c2ecf20Sopenharmony_ci{
9028c2ecf20Sopenharmony_ci	return ocelot_read(ocelot, SYS_RAM_INIT);
9038c2ecf20Sopenharmony_ci}
9048c2ecf20Sopenharmony_ci
9058c2ecf20Sopenharmony_ci/* CORE_ENA is in SYS:SYSTEM:RESET_CFG
9068c2ecf20Sopenharmony_ci * RAM_INIT is in SYS:RAM_CTRL:RAM_INIT
9078c2ecf20Sopenharmony_ci */
9088c2ecf20Sopenharmony_cistatic int vsc9959_reset(struct ocelot *ocelot)
9098c2ecf20Sopenharmony_ci{
9108c2ecf20Sopenharmony_ci	int val, err;
9118c2ecf20Sopenharmony_ci
9128c2ecf20Sopenharmony_ci	/* soft-reset the switch core */
9138c2ecf20Sopenharmony_ci	ocelot_field_write(ocelot, GCB_SOFT_RST_SWC_RST, 1);
9148c2ecf20Sopenharmony_ci
9158c2ecf20Sopenharmony_ci	err = readx_poll_timeout(vsc9959_gcb_soft_rst_status, ocelot, val, !val,
9168c2ecf20Sopenharmony_ci				 VSC9959_GCB_RST_SLEEP, VSC9959_INIT_TIMEOUT);
9178c2ecf20Sopenharmony_ci	if (err) {
9188c2ecf20Sopenharmony_ci		dev_err(ocelot->dev, "timeout: switch core reset\n");
9198c2ecf20Sopenharmony_ci		return err;
9208c2ecf20Sopenharmony_ci	}
9218c2ecf20Sopenharmony_ci
9228c2ecf20Sopenharmony_ci	/* initialize switch mem ~40us */
9238c2ecf20Sopenharmony_ci	ocelot_write(ocelot, SYS_RAM_INIT_RAM_INIT, SYS_RAM_INIT);
9248c2ecf20Sopenharmony_ci	err = readx_poll_timeout(vsc9959_sys_ram_init_status, ocelot, val, !val,
9258c2ecf20Sopenharmony_ci				 VSC9959_SYS_RAMINIT_SLEEP,
9268c2ecf20Sopenharmony_ci				 VSC9959_INIT_TIMEOUT);
9278c2ecf20Sopenharmony_ci	if (err) {
9288c2ecf20Sopenharmony_ci		dev_err(ocelot->dev, "timeout: switch sram init\n");
9298c2ecf20Sopenharmony_ci		return err;
9308c2ecf20Sopenharmony_ci	}
9318c2ecf20Sopenharmony_ci
9328c2ecf20Sopenharmony_ci	/* enable switch core */
9338c2ecf20Sopenharmony_ci	ocelot_field_write(ocelot, SYS_RESET_CFG_CORE_ENA, 1);
9348c2ecf20Sopenharmony_ci
9358c2ecf20Sopenharmony_ci	return 0;
9368c2ecf20Sopenharmony_ci}
9378c2ecf20Sopenharmony_ci
9388c2ecf20Sopenharmony_cistatic void vsc9959_phylink_validate(struct ocelot *ocelot, int port,
9398c2ecf20Sopenharmony_ci				     unsigned long *supported,
9408c2ecf20Sopenharmony_ci				     struct phylink_link_state *state)
9418c2ecf20Sopenharmony_ci{
9428c2ecf20Sopenharmony_ci	struct ocelot_port *ocelot_port = ocelot->ports[port];
9438c2ecf20Sopenharmony_ci	__ETHTOOL_DECLARE_LINK_MODE_MASK(mask) = { 0, };
9448c2ecf20Sopenharmony_ci
9458c2ecf20Sopenharmony_ci	if (state->interface != PHY_INTERFACE_MODE_NA &&
9468c2ecf20Sopenharmony_ci	    state->interface != ocelot_port->phy_mode) {
9478c2ecf20Sopenharmony_ci		bitmap_zero(supported, __ETHTOOL_LINK_MODE_MASK_NBITS);
9488c2ecf20Sopenharmony_ci		return;
9498c2ecf20Sopenharmony_ci	}
9508c2ecf20Sopenharmony_ci
9518c2ecf20Sopenharmony_ci	phylink_set_port_modes(mask);
9528c2ecf20Sopenharmony_ci	phylink_set(mask, Autoneg);
9538c2ecf20Sopenharmony_ci	phylink_set(mask, Pause);
9548c2ecf20Sopenharmony_ci	phylink_set(mask, Asym_Pause);
9558c2ecf20Sopenharmony_ci	phylink_set(mask, 10baseT_Half);
9568c2ecf20Sopenharmony_ci	phylink_set(mask, 10baseT_Full);
9578c2ecf20Sopenharmony_ci	phylink_set(mask, 100baseT_Half);
9588c2ecf20Sopenharmony_ci	phylink_set(mask, 100baseT_Full);
9598c2ecf20Sopenharmony_ci	phylink_set(mask, 1000baseT_Half);
9608c2ecf20Sopenharmony_ci	phylink_set(mask, 1000baseT_Full);
9618c2ecf20Sopenharmony_ci
9628c2ecf20Sopenharmony_ci	if (state->interface == PHY_INTERFACE_MODE_INTERNAL ||
9638c2ecf20Sopenharmony_ci	    state->interface == PHY_INTERFACE_MODE_2500BASEX ||
9648c2ecf20Sopenharmony_ci	    state->interface == PHY_INTERFACE_MODE_USXGMII) {
9658c2ecf20Sopenharmony_ci		phylink_set(mask, 2500baseT_Full);
9668c2ecf20Sopenharmony_ci		phylink_set(mask, 2500baseX_Full);
9678c2ecf20Sopenharmony_ci	}
9688c2ecf20Sopenharmony_ci
9698c2ecf20Sopenharmony_ci	bitmap_and(supported, supported, mask,
9708c2ecf20Sopenharmony_ci		   __ETHTOOL_LINK_MODE_MASK_NBITS);
9718c2ecf20Sopenharmony_ci	bitmap_and(state->advertising, state->advertising, mask,
9728c2ecf20Sopenharmony_ci		   __ETHTOOL_LINK_MODE_MASK_NBITS);
9738c2ecf20Sopenharmony_ci}
9748c2ecf20Sopenharmony_ci
9758c2ecf20Sopenharmony_cistatic int vsc9959_prevalidate_phy_mode(struct ocelot *ocelot, int port,
9768c2ecf20Sopenharmony_ci					phy_interface_t phy_mode)
9778c2ecf20Sopenharmony_ci{
9788c2ecf20Sopenharmony_ci	switch (phy_mode) {
9798c2ecf20Sopenharmony_ci	case PHY_INTERFACE_MODE_INTERNAL:
9808c2ecf20Sopenharmony_ci		if (port != 4 && port != 5)
9818c2ecf20Sopenharmony_ci			return -ENOTSUPP;
9828c2ecf20Sopenharmony_ci		return 0;
9838c2ecf20Sopenharmony_ci	case PHY_INTERFACE_MODE_SGMII:
9848c2ecf20Sopenharmony_ci	case PHY_INTERFACE_MODE_QSGMII:
9858c2ecf20Sopenharmony_ci	case PHY_INTERFACE_MODE_USXGMII:
9868c2ecf20Sopenharmony_ci	case PHY_INTERFACE_MODE_2500BASEX:
9878c2ecf20Sopenharmony_ci		/* Not supported on internal to-CPU ports */
9888c2ecf20Sopenharmony_ci		if (port == 4 || port == 5)
9898c2ecf20Sopenharmony_ci			return -ENOTSUPP;
9908c2ecf20Sopenharmony_ci		return 0;
9918c2ecf20Sopenharmony_ci	default:
9928c2ecf20Sopenharmony_ci		return -ENOTSUPP;
9938c2ecf20Sopenharmony_ci	}
9948c2ecf20Sopenharmony_ci}
9958c2ecf20Sopenharmony_ci
9968c2ecf20Sopenharmony_ci/* Watermark encode
9978c2ecf20Sopenharmony_ci * Bit 8:   Unit; 0:1, 1:16
9988c2ecf20Sopenharmony_ci * Bit 7-0: Value to be multiplied with unit
9998c2ecf20Sopenharmony_ci */
10008c2ecf20Sopenharmony_cistatic u16 vsc9959_wm_enc(u16 value)
10018c2ecf20Sopenharmony_ci{
10028c2ecf20Sopenharmony_ci	WARN_ON(value >= 16 * BIT(8));
10038c2ecf20Sopenharmony_ci
10048c2ecf20Sopenharmony_ci	if (value >= BIT(8))
10058c2ecf20Sopenharmony_ci		return BIT(8) | (value / 16);
10068c2ecf20Sopenharmony_ci
10078c2ecf20Sopenharmony_ci	return value;
10088c2ecf20Sopenharmony_ci}
10098c2ecf20Sopenharmony_ci
10108c2ecf20Sopenharmony_cistatic const struct ocelot_ops vsc9959_ops = {
10118c2ecf20Sopenharmony_ci	.reset			= vsc9959_reset,
10128c2ecf20Sopenharmony_ci	.wm_enc			= vsc9959_wm_enc,
10138c2ecf20Sopenharmony_ci	.port_to_netdev		= felix_port_to_netdev,
10148c2ecf20Sopenharmony_ci	.netdev_to_port		= felix_netdev_to_port,
10158c2ecf20Sopenharmony_ci};
10168c2ecf20Sopenharmony_ci
10178c2ecf20Sopenharmony_cistatic int vsc9959_mdio_bus_alloc(struct ocelot *ocelot)
10188c2ecf20Sopenharmony_ci{
10198c2ecf20Sopenharmony_ci	struct felix *felix = ocelot_to_felix(ocelot);
10208c2ecf20Sopenharmony_ci	struct enetc_mdio_priv *mdio_priv;
10218c2ecf20Sopenharmony_ci	struct device *dev = ocelot->dev;
10228c2ecf20Sopenharmony_ci	void __iomem *imdio_regs;
10238c2ecf20Sopenharmony_ci	struct resource res;
10248c2ecf20Sopenharmony_ci	struct enetc_hw *hw;
10258c2ecf20Sopenharmony_ci	struct mii_bus *bus;
10268c2ecf20Sopenharmony_ci	int port;
10278c2ecf20Sopenharmony_ci	int rc;
10288c2ecf20Sopenharmony_ci
10298c2ecf20Sopenharmony_ci	felix->pcs = devm_kcalloc(dev, felix->info->num_ports,
10308c2ecf20Sopenharmony_ci				  sizeof(struct lynx_pcs *),
10318c2ecf20Sopenharmony_ci				  GFP_KERNEL);
10328c2ecf20Sopenharmony_ci	if (!felix->pcs) {
10338c2ecf20Sopenharmony_ci		dev_err(dev, "failed to allocate array for PCS PHYs\n");
10348c2ecf20Sopenharmony_ci		return -ENOMEM;
10358c2ecf20Sopenharmony_ci	}
10368c2ecf20Sopenharmony_ci
10378c2ecf20Sopenharmony_ci	memcpy(&res, felix->info->imdio_res, sizeof(res));
10388c2ecf20Sopenharmony_ci	res.flags = IORESOURCE_MEM;
10398c2ecf20Sopenharmony_ci	res.start += felix->imdio_base;
10408c2ecf20Sopenharmony_ci	res.end += felix->imdio_base;
10418c2ecf20Sopenharmony_ci
10428c2ecf20Sopenharmony_ci	imdio_regs = devm_ioremap_resource(dev, &res);
10438c2ecf20Sopenharmony_ci	if (IS_ERR(imdio_regs)) {
10448c2ecf20Sopenharmony_ci		dev_err(dev, "failed to map internal MDIO registers\n");
10458c2ecf20Sopenharmony_ci		return PTR_ERR(imdio_regs);
10468c2ecf20Sopenharmony_ci	}
10478c2ecf20Sopenharmony_ci
10488c2ecf20Sopenharmony_ci	hw = enetc_hw_alloc(dev, imdio_regs);
10498c2ecf20Sopenharmony_ci	if (IS_ERR(hw)) {
10508c2ecf20Sopenharmony_ci		dev_err(dev, "failed to allocate ENETC HW structure\n");
10518c2ecf20Sopenharmony_ci		return PTR_ERR(hw);
10528c2ecf20Sopenharmony_ci	}
10538c2ecf20Sopenharmony_ci
10548c2ecf20Sopenharmony_ci	bus = devm_mdiobus_alloc_size(dev, sizeof(*mdio_priv));
10558c2ecf20Sopenharmony_ci	if (!bus)
10568c2ecf20Sopenharmony_ci		return -ENOMEM;
10578c2ecf20Sopenharmony_ci
10588c2ecf20Sopenharmony_ci	bus->name = "VSC9959 internal MDIO bus";
10598c2ecf20Sopenharmony_ci	bus->read = enetc_mdio_read;
10608c2ecf20Sopenharmony_ci	bus->write = enetc_mdio_write;
10618c2ecf20Sopenharmony_ci	bus->parent = dev;
10628c2ecf20Sopenharmony_ci	mdio_priv = bus->priv;
10638c2ecf20Sopenharmony_ci	mdio_priv->hw = hw;
10648c2ecf20Sopenharmony_ci	/* This gets added to imdio_regs, which already maps addresses
10658c2ecf20Sopenharmony_ci	 * starting with the proper offset.
10668c2ecf20Sopenharmony_ci	 */
10678c2ecf20Sopenharmony_ci	mdio_priv->mdio_base = 0;
10688c2ecf20Sopenharmony_ci	snprintf(bus->id, MII_BUS_ID_SIZE, "%s-imdio", dev_name(dev));
10698c2ecf20Sopenharmony_ci
10708c2ecf20Sopenharmony_ci	/* Needed in order to initialize the bus mutex lock */
10718c2ecf20Sopenharmony_ci	rc = mdiobus_register(bus);
10728c2ecf20Sopenharmony_ci	if (rc < 0) {
10738c2ecf20Sopenharmony_ci		dev_err(dev, "failed to register MDIO bus\n");
10748c2ecf20Sopenharmony_ci		return rc;
10758c2ecf20Sopenharmony_ci	}
10768c2ecf20Sopenharmony_ci
10778c2ecf20Sopenharmony_ci	felix->imdio = bus;
10788c2ecf20Sopenharmony_ci
10798c2ecf20Sopenharmony_ci	for (port = 0; port < felix->info->num_ports; port++) {
10808c2ecf20Sopenharmony_ci		struct ocelot_port *ocelot_port = ocelot->ports[port];
10818c2ecf20Sopenharmony_ci		struct mdio_device *pcs;
10828c2ecf20Sopenharmony_ci		struct lynx_pcs *lynx;
10838c2ecf20Sopenharmony_ci
10848c2ecf20Sopenharmony_ci		if (dsa_is_unused_port(felix->ds, port))
10858c2ecf20Sopenharmony_ci			continue;
10868c2ecf20Sopenharmony_ci
10878c2ecf20Sopenharmony_ci		if (ocelot_port->phy_mode == PHY_INTERFACE_MODE_INTERNAL)
10888c2ecf20Sopenharmony_ci			continue;
10898c2ecf20Sopenharmony_ci
10908c2ecf20Sopenharmony_ci		pcs = mdio_device_create(felix->imdio, port);
10918c2ecf20Sopenharmony_ci		if (IS_ERR(pcs))
10928c2ecf20Sopenharmony_ci			continue;
10938c2ecf20Sopenharmony_ci
10948c2ecf20Sopenharmony_ci		lynx = lynx_pcs_create(pcs);
10958c2ecf20Sopenharmony_ci		if (!lynx) {
10968c2ecf20Sopenharmony_ci			mdio_device_free(pcs);
10978c2ecf20Sopenharmony_ci			continue;
10988c2ecf20Sopenharmony_ci		}
10998c2ecf20Sopenharmony_ci
11008c2ecf20Sopenharmony_ci		felix->pcs[port] = lynx;
11018c2ecf20Sopenharmony_ci
11028c2ecf20Sopenharmony_ci		dev_info(dev, "Found PCS at internal MDIO address %d\n", port);
11038c2ecf20Sopenharmony_ci	}
11048c2ecf20Sopenharmony_ci
11058c2ecf20Sopenharmony_ci	return 0;
11068c2ecf20Sopenharmony_ci}
11078c2ecf20Sopenharmony_ci
11088c2ecf20Sopenharmony_cistatic void vsc9959_mdio_bus_free(struct ocelot *ocelot)
11098c2ecf20Sopenharmony_ci{
11108c2ecf20Sopenharmony_ci	struct felix *felix = ocelot_to_felix(ocelot);
11118c2ecf20Sopenharmony_ci	int port;
11128c2ecf20Sopenharmony_ci
11138c2ecf20Sopenharmony_ci	for (port = 0; port < ocelot->num_phys_ports; port++) {
11148c2ecf20Sopenharmony_ci		struct lynx_pcs *pcs = felix->pcs[port];
11158c2ecf20Sopenharmony_ci
11168c2ecf20Sopenharmony_ci		if (!pcs)
11178c2ecf20Sopenharmony_ci			continue;
11188c2ecf20Sopenharmony_ci
11198c2ecf20Sopenharmony_ci		mdio_device_free(pcs->mdio);
11208c2ecf20Sopenharmony_ci		lynx_pcs_destroy(pcs);
11218c2ecf20Sopenharmony_ci	}
11228c2ecf20Sopenharmony_ci	mdiobus_unregister(felix->imdio);
11238c2ecf20Sopenharmony_ci}
11248c2ecf20Sopenharmony_ci
11258c2ecf20Sopenharmony_cistatic void vsc9959_sched_speed_set(struct ocelot *ocelot, int port,
11268c2ecf20Sopenharmony_ci				    u32 speed)
11278c2ecf20Sopenharmony_ci{
11288c2ecf20Sopenharmony_ci	u8 tas_speed;
11298c2ecf20Sopenharmony_ci
11308c2ecf20Sopenharmony_ci	switch (speed) {
11318c2ecf20Sopenharmony_ci	case SPEED_10:
11328c2ecf20Sopenharmony_ci		tas_speed = OCELOT_SPEED_10;
11338c2ecf20Sopenharmony_ci		break;
11348c2ecf20Sopenharmony_ci	case SPEED_100:
11358c2ecf20Sopenharmony_ci		tas_speed = OCELOT_SPEED_100;
11368c2ecf20Sopenharmony_ci		break;
11378c2ecf20Sopenharmony_ci	case SPEED_1000:
11388c2ecf20Sopenharmony_ci		tas_speed = OCELOT_SPEED_1000;
11398c2ecf20Sopenharmony_ci		break;
11408c2ecf20Sopenharmony_ci	case SPEED_2500:
11418c2ecf20Sopenharmony_ci		tas_speed = OCELOT_SPEED_2500;
11428c2ecf20Sopenharmony_ci		break;
11438c2ecf20Sopenharmony_ci	default:
11448c2ecf20Sopenharmony_ci		tas_speed = OCELOT_SPEED_1000;
11458c2ecf20Sopenharmony_ci		break;
11468c2ecf20Sopenharmony_ci	}
11478c2ecf20Sopenharmony_ci
11488c2ecf20Sopenharmony_ci	ocelot_rmw_rix(ocelot,
11498c2ecf20Sopenharmony_ci		       QSYS_TAG_CONFIG_LINK_SPEED(tas_speed),
11508c2ecf20Sopenharmony_ci		       QSYS_TAG_CONFIG_LINK_SPEED_M,
11518c2ecf20Sopenharmony_ci		       QSYS_TAG_CONFIG, port);
11528c2ecf20Sopenharmony_ci}
11538c2ecf20Sopenharmony_ci
11548c2ecf20Sopenharmony_cistatic void vsc9959_new_base_time(struct ocelot *ocelot, ktime_t base_time,
11558c2ecf20Sopenharmony_ci				  u64 cycle_time,
11568c2ecf20Sopenharmony_ci				  struct timespec64 *new_base_ts)
11578c2ecf20Sopenharmony_ci{
11588c2ecf20Sopenharmony_ci	struct timespec64 ts;
11598c2ecf20Sopenharmony_ci	ktime_t new_base_time;
11608c2ecf20Sopenharmony_ci	ktime_t current_time;
11618c2ecf20Sopenharmony_ci
11628c2ecf20Sopenharmony_ci	ocelot_ptp_gettime64(&ocelot->ptp_info, &ts);
11638c2ecf20Sopenharmony_ci	current_time = timespec64_to_ktime(ts);
11648c2ecf20Sopenharmony_ci	new_base_time = base_time;
11658c2ecf20Sopenharmony_ci
11668c2ecf20Sopenharmony_ci	if (base_time < current_time) {
11678c2ecf20Sopenharmony_ci		u64 nr_of_cycles = current_time - base_time;
11688c2ecf20Sopenharmony_ci
11698c2ecf20Sopenharmony_ci		do_div(nr_of_cycles, cycle_time);
11708c2ecf20Sopenharmony_ci		new_base_time += cycle_time * (nr_of_cycles + 1);
11718c2ecf20Sopenharmony_ci	}
11728c2ecf20Sopenharmony_ci
11738c2ecf20Sopenharmony_ci	*new_base_ts = ktime_to_timespec64(new_base_time);
11748c2ecf20Sopenharmony_ci}
11758c2ecf20Sopenharmony_ci
11768c2ecf20Sopenharmony_cistatic u32 vsc9959_tas_read_cfg_status(struct ocelot *ocelot)
11778c2ecf20Sopenharmony_ci{
11788c2ecf20Sopenharmony_ci	return ocelot_read(ocelot, QSYS_TAS_PARAM_CFG_CTRL);
11798c2ecf20Sopenharmony_ci}
11808c2ecf20Sopenharmony_ci
11818c2ecf20Sopenharmony_cistatic void vsc9959_tas_gcl_set(struct ocelot *ocelot, const u32 gcl_ix,
11828c2ecf20Sopenharmony_ci				struct tc_taprio_sched_entry *entry)
11838c2ecf20Sopenharmony_ci{
11848c2ecf20Sopenharmony_ci	ocelot_write(ocelot,
11858c2ecf20Sopenharmony_ci		     QSYS_GCL_CFG_REG_1_GCL_ENTRY_NUM(gcl_ix) |
11868c2ecf20Sopenharmony_ci		     QSYS_GCL_CFG_REG_1_GATE_STATE(entry->gate_mask),
11878c2ecf20Sopenharmony_ci		     QSYS_GCL_CFG_REG_1);
11888c2ecf20Sopenharmony_ci	ocelot_write(ocelot, entry->interval, QSYS_GCL_CFG_REG_2);
11898c2ecf20Sopenharmony_ci}
11908c2ecf20Sopenharmony_ci
11918c2ecf20Sopenharmony_cistatic int vsc9959_qos_port_tas_set(struct ocelot *ocelot, int port,
11928c2ecf20Sopenharmony_ci				    struct tc_taprio_qopt_offload *taprio)
11938c2ecf20Sopenharmony_ci{
11948c2ecf20Sopenharmony_ci	struct timespec64 base_ts;
11958c2ecf20Sopenharmony_ci	int ret, i;
11968c2ecf20Sopenharmony_ci	u32 val;
11978c2ecf20Sopenharmony_ci
11988c2ecf20Sopenharmony_ci	if (!taprio->enable) {
11998c2ecf20Sopenharmony_ci		ocelot_rmw_rix(ocelot,
12008c2ecf20Sopenharmony_ci			       QSYS_TAG_CONFIG_INIT_GATE_STATE(0xFF),
12018c2ecf20Sopenharmony_ci			       QSYS_TAG_CONFIG_ENABLE |
12028c2ecf20Sopenharmony_ci			       QSYS_TAG_CONFIG_INIT_GATE_STATE_M,
12038c2ecf20Sopenharmony_ci			       QSYS_TAG_CONFIG, port);
12048c2ecf20Sopenharmony_ci
12058c2ecf20Sopenharmony_ci		return 0;
12068c2ecf20Sopenharmony_ci	}
12078c2ecf20Sopenharmony_ci
12088c2ecf20Sopenharmony_ci	if (taprio->cycle_time > NSEC_PER_SEC ||
12098c2ecf20Sopenharmony_ci	    taprio->cycle_time_extension >= NSEC_PER_SEC)
12108c2ecf20Sopenharmony_ci		return -EINVAL;
12118c2ecf20Sopenharmony_ci
12128c2ecf20Sopenharmony_ci	if (taprio->num_entries > VSC9959_TAS_GCL_ENTRY_MAX)
12138c2ecf20Sopenharmony_ci		return -ERANGE;
12148c2ecf20Sopenharmony_ci
12158c2ecf20Sopenharmony_ci	ocelot_rmw(ocelot, QSYS_TAS_PARAM_CFG_CTRL_PORT_NUM(port) |
12168c2ecf20Sopenharmony_ci		   QSYS_TAS_PARAM_CFG_CTRL_ALWAYS_GUARD_BAND_SCH_Q,
12178c2ecf20Sopenharmony_ci		   QSYS_TAS_PARAM_CFG_CTRL_PORT_NUM_M |
12188c2ecf20Sopenharmony_ci		   QSYS_TAS_PARAM_CFG_CTRL_ALWAYS_GUARD_BAND_SCH_Q,
12198c2ecf20Sopenharmony_ci		   QSYS_TAS_PARAM_CFG_CTRL);
12208c2ecf20Sopenharmony_ci
12218c2ecf20Sopenharmony_ci	/* Hardware errata -  Admin config could not be overwritten if
12228c2ecf20Sopenharmony_ci	 * config is pending, need reset the TAS module
12238c2ecf20Sopenharmony_ci	 */
12248c2ecf20Sopenharmony_ci	val = ocelot_read(ocelot, QSYS_PARAM_STATUS_REG_8);
12258c2ecf20Sopenharmony_ci	if (val & QSYS_PARAM_STATUS_REG_8_CONFIG_PENDING)
12268c2ecf20Sopenharmony_ci		return  -EBUSY;
12278c2ecf20Sopenharmony_ci
12288c2ecf20Sopenharmony_ci	ocelot_rmw_rix(ocelot,
12298c2ecf20Sopenharmony_ci		       QSYS_TAG_CONFIG_ENABLE |
12308c2ecf20Sopenharmony_ci		       QSYS_TAG_CONFIG_INIT_GATE_STATE(0xFF) |
12318c2ecf20Sopenharmony_ci		       QSYS_TAG_CONFIG_SCH_TRAFFIC_QUEUES(0xFF),
12328c2ecf20Sopenharmony_ci		       QSYS_TAG_CONFIG_ENABLE |
12338c2ecf20Sopenharmony_ci		       QSYS_TAG_CONFIG_INIT_GATE_STATE_M |
12348c2ecf20Sopenharmony_ci		       QSYS_TAG_CONFIG_SCH_TRAFFIC_QUEUES_M,
12358c2ecf20Sopenharmony_ci		       QSYS_TAG_CONFIG, port);
12368c2ecf20Sopenharmony_ci
12378c2ecf20Sopenharmony_ci	vsc9959_new_base_time(ocelot, taprio->base_time,
12388c2ecf20Sopenharmony_ci			      taprio->cycle_time, &base_ts);
12398c2ecf20Sopenharmony_ci	ocelot_write(ocelot, base_ts.tv_nsec, QSYS_PARAM_CFG_REG_1);
12408c2ecf20Sopenharmony_ci	ocelot_write(ocelot, lower_32_bits(base_ts.tv_sec), QSYS_PARAM_CFG_REG_2);
12418c2ecf20Sopenharmony_ci	val = upper_32_bits(base_ts.tv_sec);
12428c2ecf20Sopenharmony_ci	ocelot_write(ocelot,
12438c2ecf20Sopenharmony_ci		     QSYS_PARAM_CFG_REG_3_BASE_TIME_SEC_MSB(val) |
12448c2ecf20Sopenharmony_ci		     QSYS_PARAM_CFG_REG_3_LIST_LENGTH(taprio->num_entries),
12458c2ecf20Sopenharmony_ci		     QSYS_PARAM_CFG_REG_3);
12468c2ecf20Sopenharmony_ci	ocelot_write(ocelot, taprio->cycle_time, QSYS_PARAM_CFG_REG_4);
12478c2ecf20Sopenharmony_ci	ocelot_write(ocelot, taprio->cycle_time_extension, QSYS_PARAM_CFG_REG_5);
12488c2ecf20Sopenharmony_ci
12498c2ecf20Sopenharmony_ci	for (i = 0; i < taprio->num_entries; i++)
12508c2ecf20Sopenharmony_ci		vsc9959_tas_gcl_set(ocelot, i, &taprio->entries[i]);
12518c2ecf20Sopenharmony_ci
12528c2ecf20Sopenharmony_ci	ocelot_rmw(ocelot, QSYS_TAS_PARAM_CFG_CTRL_CONFIG_CHANGE,
12538c2ecf20Sopenharmony_ci		   QSYS_TAS_PARAM_CFG_CTRL_CONFIG_CHANGE,
12548c2ecf20Sopenharmony_ci		   QSYS_TAS_PARAM_CFG_CTRL);
12558c2ecf20Sopenharmony_ci
12568c2ecf20Sopenharmony_ci	ret = readx_poll_timeout(vsc9959_tas_read_cfg_status, ocelot, val,
12578c2ecf20Sopenharmony_ci				 !(val & QSYS_TAS_PARAM_CFG_CTRL_CONFIG_CHANGE),
12588c2ecf20Sopenharmony_ci				 10, 100000);
12598c2ecf20Sopenharmony_ci
12608c2ecf20Sopenharmony_ci	return ret;
12618c2ecf20Sopenharmony_ci}
12628c2ecf20Sopenharmony_ci
12638c2ecf20Sopenharmony_cistatic int vsc9959_qos_port_cbs_set(struct dsa_switch *ds, int port,
12648c2ecf20Sopenharmony_ci				    struct tc_cbs_qopt_offload *cbs_qopt)
12658c2ecf20Sopenharmony_ci{
12668c2ecf20Sopenharmony_ci	struct ocelot *ocelot = ds->priv;
12678c2ecf20Sopenharmony_ci	int port_ix = port * 8 + cbs_qopt->queue;
12688c2ecf20Sopenharmony_ci	u32 rate, burst;
12698c2ecf20Sopenharmony_ci
12708c2ecf20Sopenharmony_ci	if (cbs_qopt->queue >= ds->num_tx_queues)
12718c2ecf20Sopenharmony_ci		return -EINVAL;
12728c2ecf20Sopenharmony_ci
12738c2ecf20Sopenharmony_ci	if (!cbs_qopt->enable) {
12748c2ecf20Sopenharmony_ci		ocelot_write_gix(ocelot, QSYS_CIR_CFG_CIR_RATE(0) |
12758c2ecf20Sopenharmony_ci				 QSYS_CIR_CFG_CIR_BURST(0),
12768c2ecf20Sopenharmony_ci				 QSYS_CIR_CFG, port_ix);
12778c2ecf20Sopenharmony_ci
12788c2ecf20Sopenharmony_ci		ocelot_rmw_gix(ocelot, 0, QSYS_SE_CFG_SE_AVB_ENA,
12798c2ecf20Sopenharmony_ci			       QSYS_SE_CFG, port_ix);
12808c2ecf20Sopenharmony_ci
12818c2ecf20Sopenharmony_ci		return 0;
12828c2ecf20Sopenharmony_ci	}
12838c2ecf20Sopenharmony_ci
12848c2ecf20Sopenharmony_ci	/* Rate unit is 100 kbps */
12858c2ecf20Sopenharmony_ci	rate = DIV_ROUND_UP(cbs_qopt->idleslope, 100);
12868c2ecf20Sopenharmony_ci	/* Avoid using zero rate */
12878c2ecf20Sopenharmony_ci	rate = clamp_t(u32, rate, 1, GENMASK(14, 0));
12888c2ecf20Sopenharmony_ci	/* Burst unit is 4kB */
12898c2ecf20Sopenharmony_ci	burst = DIV_ROUND_UP(cbs_qopt->hicredit, 4096);
12908c2ecf20Sopenharmony_ci	/* Avoid using zero burst size */
12918c2ecf20Sopenharmony_ci	burst = clamp_t(u32, burst, 1, GENMASK(5, 0));
12928c2ecf20Sopenharmony_ci	ocelot_write_gix(ocelot,
12938c2ecf20Sopenharmony_ci			 QSYS_CIR_CFG_CIR_RATE(rate) |
12948c2ecf20Sopenharmony_ci			 QSYS_CIR_CFG_CIR_BURST(burst),
12958c2ecf20Sopenharmony_ci			 QSYS_CIR_CFG,
12968c2ecf20Sopenharmony_ci			 port_ix);
12978c2ecf20Sopenharmony_ci
12988c2ecf20Sopenharmony_ci	ocelot_rmw_gix(ocelot,
12998c2ecf20Sopenharmony_ci		       QSYS_SE_CFG_SE_FRM_MODE(0) |
13008c2ecf20Sopenharmony_ci		       QSYS_SE_CFG_SE_AVB_ENA,
13018c2ecf20Sopenharmony_ci		       QSYS_SE_CFG_SE_AVB_ENA |
13028c2ecf20Sopenharmony_ci		       QSYS_SE_CFG_SE_FRM_MODE_M,
13038c2ecf20Sopenharmony_ci		       QSYS_SE_CFG,
13048c2ecf20Sopenharmony_ci		       port_ix);
13058c2ecf20Sopenharmony_ci
13068c2ecf20Sopenharmony_ci	return 0;
13078c2ecf20Sopenharmony_ci}
13088c2ecf20Sopenharmony_ci
13098c2ecf20Sopenharmony_cistatic int vsc9959_port_setup_tc(struct dsa_switch *ds, int port,
13108c2ecf20Sopenharmony_ci				 enum tc_setup_type type,
13118c2ecf20Sopenharmony_ci				 void *type_data)
13128c2ecf20Sopenharmony_ci{
13138c2ecf20Sopenharmony_ci	struct ocelot *ocelot = ds->priv;
13148c2ecf20Sopenharmony_ci
13158c2ecf20Sopenharmony_ci	switch (type) {
13168c2ecf20Sopenharmony_ci	case TC_SETUP_QDISC_TAPRIO:
13178c2ecf20Sopenharmony_ci		return vsc9959_qos_port_tas_set(ocelot, port, type_data);
13188c2ecf20Sopenharmony_ci	case TC_SETUP_QDISC_CBS:
13198c2ecf20Sopenharmony_ci		return vsc9959_qos_port_cbs_set(ds, port, type_data);
13208c2ecf20Sopenharmony_ci	default:
13218c2ecf20Sopenharmony_ci		return -EOPNOTSUPP;
13228c2ecf20Sopenharmony_ci	}
13238c2ecf20Sopenharmony_ci}
13248c2ecf20Sopenharmony_ci
13258c2ecf20Sopenharmony_cistatic void vsc9959_xmit_template_populate(struct ocelot *ocelot, int port)
13268c2ecf20Sopenharmony_ci{
13278c2ecf20Sopenharmony_ci	struct ocelot_port *ocelot_port = ocelot->ports[port];
13288c2ecf20Sopenharmony_ci	u8 *template = ocelot_port->xmit_template;
13298c2ecf20Sopenharmony_ci	u64 bypass, dest, src;
13308c2ecf20Sopenharmony_ci	__be32 *prefix;
13318c2ecf20Sopenharmony_ci	u8 *injection;
13328c2ecf20Sopenharmony_ci
13338c2ecf20Sopenharmony_ci	/* Set the source port as the CPU port module and not the
13348c2ecf20Sopenharmony_ci	 * NPI port
13358c2ecf20Sopenharmony_ci	 */
13368c2ecf20Sopenharmony_ci	src = ocelot->num_phys_ports;
13378c2ecf20Sopenharmony_ci	dest = BIT(port);
13388c2ecf20Sopenharmony_ci	bypass = true;
13398c2ecf20Sopenharmony_ci
13408c2ecf20Sopenharmony_ci	injection = template + OCELOT_SHORT_PREFIX_LEN;
13418c2ecf20Sopenharmony_ci	prefix = (__be32 *)template;
13428c2ecf20Sopenharmony_ci
13438c2ecf20Sopenharmony_ci	packing(injection, &bypass, 127, 127, OCELOT_TAG_LEN, PACK, 0);
13448c2ecf20Sopenharmony_ci	packing(injection, &dest,    68,  56, OCELOT_TAG_LEN, PACK, 0);
13458c2ecf20Sopenharmony_ci	packing(injection, &src,     46,  43, OCELOT_TAG_LEN, PACK, 0);
13468c2ecf20Sopenharmony_ci
13478c2ecf20Sopenharmony_ci	*prefix = cpu_to_be32(0x8880000a);
13488c2ecf20Sopenharmony_ci}
13498c2ecf20Sopenharmony_ci
13508c2ecf20Sopenharmony_cistatic const struct felix_info felix_info_vsc9959 = {
13518c2ecf20Sopenharmony_ci	.target_io_res		= vsc9959_target_io_res,
13528c2ecf20Sopenharmony_ci	.port_io_res		= vsc9959_port_io_res,
13538c2ecf20Sopenharmony_ci	.imdio_res		= &vsc9959_imdio_res,
13548c2ecf20Sopenharmony_ci	.regfields		= vsc9959_regfields,
13558c2ecf20Sopenharmony_ci	.map			= vsc9959_regmap,
13568c2ecf20Sopenharmony_ci	.ops			= &vsc9959_ops,
13578c2ecf20Sopenharmony_ci	.stats_layout		= vsc9959_stats_layout,
13588c2ecf20Sopenharmony_ci	.num_stats		= ARRAY_SIZE(vsc9959_stats_layout),
13598c2ecf20Sopenharmony_ci	.vcap			= vsc9959_vcap_props,
13608c2ecf20Sopenharmony_ci	.shared_queue_sz	= 128 * 1024,
13618c2ecf20Sopenharmony_ci	.num_mact_rows		= 2048,
13628c2ecf20Sopenharmony_ci	.num_ports		= 6,
13638c2ecf20Sopenharmony_ci	.num_tx_queues		= FELIX_NUM_TC,
13648c2ecf20Sopenharmony_ci	.switch_pci_bar		= 4,
13658c2ecf20Sopenharmony_ci	.imdio_pci_bar		= 0,
13668c2ecf20Sopenharmony_ci	.ptp_caps		= &vsc9959_ptp_caps,
13678c2ecf20Sopenharmony_ci	.mdio_bus_alloc		= vsc9959_mdio_bus_alloc,
13688c2ecf20Sopenharmony_ci	.mdio_bus_free		= vsc9959_mdio_bus_free,
13698c2ecf20Sopenharmony_ci	.phylink_validate	= vsc9959_phylink_validate,
13708c2ecf20Sopenharmony_ci	.prevalidate_phy_mode	= vsc9959_prevalidate_phy_mode,
13718c2ecf20Sopenharmony_ci	.port_setup_tc		= vsc9959_port_setup_tc,
13728c2ecf20Sopenharmony_ci	.port_sched_speed_set	= vsc9959_sched_speed_set,
13738c2ecf20Sopenharmony_ci	.xmit_template_populate	= vsc9959_xmit_template_populate,
13748c2ecf20Sopenharmony_ci};
13758c2ecf20Sopenharmony_ci
13768c2ecf20Sopenharmony_cistatic irqreturn_t felix_irq_handler(int irq, void *data)
13778c2ecf20Sopenharmony_ci{
13788c2ecf20Sopenharmony_ci	struct ocelot *ocelot = (struct ocelot *)data;
13798c2ecf20Sopenharmony_ci
13808c2ecf20Sopenharmony_ci	/* The INTB interrupt is used for both PTP TX timestamp interrupt
13818c2ecf20Sopenharmony_ci	 * and preemption status change interrupt on each port.
13828c2ecf20Sopenharmony_ci	 *
13838c2ecf20Sopenharmony_ci	 * - Get txtstamp if have
13848c2ecf20Sopenharmony_ci	 * - TODO: handle preemption. Without handling it, driver may get
13858c2ecf20Sopenharmony_ci	 *   interrupt storm.
13868c2ecf20Sopenharmony_ci	 */
13878c2ecf20Sopenharmony_ci
13888c2ecf20Sopenharmony_ci	ocelot_get_txtstamp(ocelot);
13898c2ecf20Sopenharmony_ci
13908c2ecf20Sopenharmony_ci	return IRQ_HANDLED;
13918c2ecf20Sopenharmony_ci}
13928c2ecf20Sopenharmony_ci
13938c2ecf20Sopenharmony_cistatic int felix_pci_probe(struct pci_dev *pdev,
13948c2ecf20Sopenharmony_ci			   const struct pci_device_id *id)
13958c2ecf20Sopenharmony_ci{
13968c2ecf20Sopenharmony_ci	struct dsa_switch *ds;
13978c2ecf20Sopenharmony_ci	struct ocelot *ocelot;
13988c2ecf20Sopenharmony_ci	struct felix *felix;
13998c2ecf20Sopenharmony_ci	int err;
14008c2ecf20Sopenharmony_ci
14018c2ecf20Sopenharmony_ci	if (pdev->dev.of_node && !of_device_is_available(pdev->dev.of_node)) {
14028c2ecf20Sopenharmony_ci		dev_info(&pdev->dev, "device is disabled, skipping\n");
14038c2ecf20Sopenharmony_ci		return -ENODEV;
14048c2ecf20Sopenharmony_ci	}
14058c2ecf20Sopenharmony_ci
14068c2ecf20Sopenharmony_ci	err = pci_enable_device(pdev);
14078c2ecf20Sopenharmony_ci	if (err) {
14088c2ecf20Sopenharmony_ci		dev_err(&pdev->dev, "device enable failed\n");
14098c2ecf20Sopenharmony_ci		goto err_pci_enable;
14108c2ecf20Sopenharmony_ci	}
14118c2ecf20Sopenharmony_ci
14128c2ecf20Sopenharmony_ci	/* set up for high or low dma */
14138c2ecf20Sopenharmony_ci	err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(64));
14148c2ecf20Sopenharmony_ci	if (err) {
14158c2ecf20Sopenharmony_ci		err = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(32));
14168c2ecf20Sopenharmony_ci		if (err) {
14178c2ecf20Sopenharmony_ci			dev_err(&pdev->dev,
14188c2ecf20Sopenharmony_ci				"DMA configuration failed: 0x%x\n", err);
14198c2ecf20Sopenharmony_ci			goto err_dma;
14208c2ecf20Sopenharmony_ci		}
14218c2ecf20Sopenharmony_ci	}
14228c2ecf20Sopenharmony_ci
14238c2ecf20Sopenharmony_ci	felix = kzalloc(sizeof(struct felix), GFP_KERNEL);
14248c2ecf20Sopenharmony_ci	if (!felix) {
14258c2ecf20Sopenharmony_ci		err = -ENOMEM;
14268c2ecf20Sopenharmony_ci		dev_err(&pdev->dev, "Failed to allocate driver memory\n");
14278c2ecf20Sopenharmony_ci		goto err_alloc_felix;
14288c2ecf20Sopenharmony_ci	}
14298c2ecf20Sopenharmony_ci
14308c2ecf20Sopenharmony_ci	pci_set_drvdata(pdev, felix);
14318c2ecf20Sopenharmony_ci	ocelot = &felix->ocelot;
14328c2ecf20Sopenharmony_ci	ocelot->dev = &pdev->dev;
14338c2ecf20Sopenharmony_ci	ocelot->num_flooding_pgids = FELIX_NUM_TC;
14348c2ecf20Sopenharmony_ci	felix->info = &felix_info_vsc9959;
14358c2ecf20Sopenharmony_ci	felix->switch_base = pci_resource_start(pdev,
14368c2ecf20Sopenharmony_ci						felix->info->switch_pci_bar);
14378c2ecf20Sopenharmony_ci	felix->imdio_base = pci_resource_start(pdev,
14388c2ecf20Sopenharmony_ci					       felix->info->imdio_pci_bar);
14398c2ecf20Sopenharmony_ci
14408c2ecf20Sopenharmony_ci	pci_set_master(pdev);
14418c2ecf20Sopenharmony_ci
14428c2ecf20Sopenharmony_ci	err = devm_request_threaded_irq(&pdev->dev, pdev->irq, NULL,
14438c2ecf20Sopenharmony_ci					&felix_irq_handler, IRQF_ONESHOT,
14448c2ecf20Sopenharmony_ci					"felix-intb", ocelot);
14458c2ecf20Sopenharmony_ci	if (err) {
14468c2ecf20Sopenharmony_ci		dev_err(&pdev->dev, "Failed to request irq\n");
14478c2ecf20Sopenharmony_ci		goto err_alloc_irq;
14488c2ecf20Sopenharmony_ci	}
14498c2ecf20Sopenharmony_ci
14508c2ecf20Sopenharmony_ci	ocelot->ptp = 1;
14518c2ecf20Sopenharmony_ci
14528c2ecf20Sopenharmony_ci	ds = kzalloc(sizeof(struct dsa_switch), GFP_KERNEL);
14538c2ecf20Sopenharmony_ci	if (!ds) {
14548c2ecf20Sopenharmony_ci		err = -ENOMEM;
14558c2ecf20Sopenharmony_ci		dev_err(&pdev->dev, "Failed to allocate DSA switch\n");
14568c2ecf20Sopenharmony_ci		goto err_alloc_ds;
14578c2ecf20Sopenharmony_ci	}
14588c2ecf20Sopenharmony_ci
14598c2ecf20Sopenharmony_ci	ds->dev = &pdev->dev;
14608c2ecf20Sopenharmony_ci	ds->num_ports = felix->info->num_ports;
14618c2ecf20Sopenharmony_ci	ds->num_tx_queues = felix->info->num_tx_queues;
14628c2ecf20Sopenharmony_ci	ds->ops = &felix_switch_ops;
14638c2ecf20Sopenharmony_ci	ds->priv = ocelot;
14648c2ecf20Sopenharmony_ci	felix->ds = ds;
14658c2ecf20Sopenharmony_ci
14668c2ecf20Sopenharmony_ci	err = dsa_register_switch(ds);
14678c2ecf20Sopenharmony_ci	if (err) {
14688c2ecf20Sopenharmony_ci		dev_err_probe(&pdev->dev, err, "Failed to register DSA switch\n");
14698c2ecf20Sopenharmony_ci		goto err_register_ds;
14708c2ecf20Sopenharmony_ci	}
14718c2ecf20Sopenharmony_ci
14728c2ecf20Sopenharmony_ci	return 0;
14738c2ecf20Sopenharmony_ci
14748c2ecf20Sopenharmony_cierr_register_ds:
14758c2ecf20Sopenharmony_ci	kfree(ds);
14768c2ecf20Sopenharmony_cierr_alloc_ds:
14778c2ecf20Sopenharmony_cierr_alloc_irq:
14788c2ecf20Sopenharmony_cierr_alloc_felix:
14798c2ecf20Sopenharmony_ci	kfree(felix);
14808c2ecf20Sopenharmony_cierr_dma:
14818c2ecf20Sopenharmony_ci	pci_disable_device(pdev);
14828c2ecf20Sopenharmony_cierr_pci_enable:
14838c2ecf20Sopenharmony_ci	return err;
14848c2ecf20Sopenharmony_ci}
14858c2ecf20Sopenharmony_ci
14868c2ecf20Sopenharmony_cistatic void felix_pci_remove(struct pci_dev *pdev)
14878c2ecf20Sopenharmony_ci{
14888c2ecf20Sopenharmony_ci	struct felix *felix;
14898c2ecf20Sopenharmony_ci
14908c2ecf20Sopenharmony_ci	felix = pci_get_drvdata(pdev);
14918c2ecf20Sopenharmony_ci
14928c2ecf20Sopenharmony_ci	dsa_unregister_switch(felix->ds);
14938c2ecf20Sopenharmony_ci
14948c2ecf20Sopenharmony_ci	kfree(felix->ds);
14958c2ecf20Sopenharmony_ci	kfree(felix);
14968c2ecf20Sopenharmony_ci
14978c2ecf20Sopenharmony_ci	pci_disable_device(pdev);
14988c2ecf20Sopenharmony_ci}
14998c2ecf20Sopenharmony_ci
15008c2ecf20Sopenharmony_cistatic struct pci_device_id felix_ids[] = {
15018c2ecf20Sopenharmony_ci	{
15028c2ecf20Sopenharmony_ci		/* NXP LS1028A */
15038c2ecf20Sopenharmony_ci		PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, 0xEEF0),
15048c2ecf20Sopenharmony_ci	},
15058c2ecf20Sopenharmony_ci	{ 0, }
15068c2ecf20Sopenharmony_ci};
15078c2ecf20Sopenharmony_ciMODULE_DEVICE_TABLE(pci, felix_ids);
15088c2ecf20Sopenharmony_ci
15098c2ecf20Sopenharmony_cistatic struct pci_driver felix_vsc9959_pci_driver = {
15108c2ecf20Sopenharmony_ci	.name		= "mscc_felix",
15118c2ecf20Sopenharmony_ci	.id_table	= felix_ids,
15128c2ecf20Sopenharmony_ci	.probe		= felix_pci_probe,
15138c2ecf20Sopenharmony_ci	.remove		= felix_pci_remove,
15148c2ecf20Sopenharmony_ci};
15158c2ecf20Sopenharmony_cimodule_pci_driver(felix_vsc9959_pci_driver);
15168c2ecf20Sopenharmony_ci
15178c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Felix Switch driver");
15188c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL v2");
1519