mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-15 18:03:30 +00:00
kernel: rtl8367: detect rtl8367d chip family
Detect the RTL8367D chip family and set the appropriate extif Co-authored-by: Serge Vasilugin <vasilugin@yandex.ru> Signed-off-by: Mieczyslaw Nalewaj <namiltd@yahoo.com> Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
This commit is contained in:
parent
0263cb3835
commit
8730dc18a4
@ -254,7 +254,7 @@ static int __rtl8366_smi_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data)
|
||||
#define MDC_MDIO_WRITE_OP 0x0003
|
||||
#define MDC_REALTEK_PHY_ADDR 0x0
|
||||
|
||||
static int __rtl8366_mdio_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data)
|
||||
int __rtl8366_mdio_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data)
|
||||
{
|
||||
u32 phy_id = smi->phy_id;
|
||||
struct mii_bus *mbus = smi->ext_mbus;
|
||||
@ -1527,7 +1527,7 @@ static void rtl8366_smi_reset(struct rtl8366_smi *smi, bool active)
|
||||
reset_control_deassert(smi->reset);
|
||||
}
|
||||
|
||||
static int rtl8366_smi_probe_of(struct platform_device *pdev, struct rtl8366_smi *smi)
|
||||
int rtl8366_smi_probe_of(struct platform_device *pdev, struct rtl8366_smi *smi)
|
||||
{
|
||||
int sck = of_get_named_gpio(pdev->dev.of_node, "gpio-sck", 0);
|
||||
int sda = of_get_named_gpio(pdev->dev.of_node, "gpio-sda", 0);
|
||||
@ -1577,7 +1577,7 @@ static inline int rtl8366_smi_probe_of(struct platform_device *pdev, struct rtl8
|
||||
}
|
||||
#endif
|
||||
|
||||
static int rtl8366_smi_probe_plat(struct platform_device *pdev, struct rtl8366_smi *smi)
|
||||
int rtl8366_smi_probe_plat(struct platform_device *pdev, struct rtl8366_smi *smi)
|
||||
{
|
||||
struct rtl8366_platform_data *pdata = pdev->dev.platform_data;
|
||||
|
||||
|
@ -30,7 +30,9 @@ typedef enum rtl8367b_chip_e {
|
||||
RTL8367B_CHIP_RTL8367R_VB, /* chip with exception in extif assignment */
|
||||
/* Family C */
|
||||
RTL8367B_CHIP_RTL8367RB_VB,
|
||||
RTL8367B_CHIP_RTL8367S
|
||||
RTL8367B_CHIP_RTL8367S,
|
||||
/* Family D */
|
||||
RTL8367B_CHIP_RTL8367S_VB /* chip with exception in extif assignment */
|
||||
} rtl8367b_chip_t;
|
||||
|
||||
struct rtl8366_mib_counter {
|
||||
@ -76,6 +78,7 @@ struct rtl8366_smi {
|
||||
u32 phy_id;
|
||||
rtl8367b_chip_t rtl8367b_chip;
|
||||
struct mii_bus *ext_mbus;
|
||||
struct rtl8366_vlan_mc *emu_vlanmc;
|
||||
};
|
||||
|
||||
struct rtl8366_vlan_mc {
|
||||
|
@ -1078,21 +1078,37 @@ static int rtl8367_led_blinkrate_set(struct rtl8366_smi *smi, unsigned int rate)
|
||||
}
|
||||
|
||||
#ifdef CONFIG_OF
|
||||
static int rtl8367_extif_init_of(struct rtl8366_smi *smi, int id,
|
||||
static int rtl8367_extif_init_of(struct rtl8366_smi *smi,
|
||||
const char *name)
|
||||
{
|
||||
struct rtl8367_extif_config *cfg;
|
||||
const __be32 *prop;
|
||||
int size;
|
||||
int err;
|
||||
unsigned cpu_port;
|
||||
unsigned id = UINT_MAX;
|
||||
|
||||
prop = of_get_property(smi->parent->of_node, name, &size);
|
||||
if (!prop)
|
||||
return rtl8367_extif_init(smi, id, NULL);
|
||||
if (!prop || (size != (10 * sizeof(*prop)))) {
|
||||
dev_err(smi->parent, "%s property is not defined or invalid\n", name);
|
||||
err = -EINVAL;
|
||||
goto err_init;
|
||||
}
|
||||
|
||||
if (size != (9 * sizeof(*prop))) {
|
||||
dev_err(smi->parent, "%s property is invalid\n", name);
|
||||
return -EINVAL;
|
||||
cpu_port = be32_to_cpup(prop++);
|
||||
switch (cpu_port) {
|
||||
case RTL8367_CPU_PORT_NUM - 1:
|
||||
case RTL8367_CPU_PORT_NUM:
|
||||
id = RTL8367_CPU_PORT_NUM - cpu_port;
|
||||
if (smi->cpu_port == UINT_MAX) {
|
||||
dev_info(smi->parent, "cpu_port:%u, assigned to extif%u\n", cpu_port, id);
|
||||
smi->cpu_port = cpu_port;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
dev_err(smi->parent, "wrong cpu_port %u in %s property\n", cpu_port, name);
|
||||
err = -EINVAL;
|
||||
goto err_init;
|
||||
}
|
||||
|
||||
cfg = kzalloc(sizeof(struct rtl8367_extif_config), GFP_KERNEL);
|
||||
@ -1112,10 +1128,14 @@ static int rtl8367_extif_init_of(struct rtl8366_smi *smi, int id,
|
||||
err = rtl8367_extif_init(smi, id, cfg);
|
||||
kfree(cfg);
|
||||
|
||||
err_init:
|
||||
if (id != 0) rtl8367_extif_init(smi, 0, NULL);
|
||||
if (id != 1) rtl8367_extif_init(smi, 1, NULL);
|
||||
|
||||
return err;
|
||||
}
|
||||
#else
|
||||
static int rtl8367_extif_init_of(struct rtl8366_smi *smi, int id,
|
||||
static int rtl8367_extif_init_of(struct rtl8366_smi *smi,
|
||||
const char *name)
|
||||
{
|
||||
return -EINVAL;
|
||||
@ -1136,11 +1156,7 @@ static int rtl8367_setup(struct rtl8366_smi *smi)
|
||||
|
||||
/* initialize external interfaces */
|
||||
if (smi->parent->of_node) {
|
||||
err = rtl8367_extif_init_of(smi, 0, "realtek,extif0");
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = rtl8367_extif_init_of(smi, 1, "realtek,extif1");
|
||||
err = rtl8367_extif_init_of(smi, "realtek,extif");
|
||||
if (err)
|
||||
return err;
|
||||
} else {
|
||||
@ -1723,11 +1739,6 @@ static int rtl8367_detect(struct rtl8366_smi *smi)
|
||||
dev_info(smi->parent, "RTL%s ver. %u chip found\n",
|
||||
chip_name, rtl_ver & RTL8367_RTL_VER_MASK);
|
||||
|
||||
if (of_property_present(smi->parent->of_node, "realtek,extif1"))
|
||||
smi->cpu_port = RTL8367_CPU_PORT_NUM - 1;
|
||||
|
||||
dev_info(smi->parent, "CPU port: %u\n", smi->cpu_port);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1765,7 +1776,7 @@ static int rtl8367_probe(struct platform_device *pdev)
|
||||
smi->cmd_read = 0xb9;
|
||||
smi->cmd_write = 0xb8;
|
||||
smi->ops = &rtl8367_smi_ops;
|
||||
smi->cpu_port = RTL8367_CPU_PORT_NUM;
|
||||
smi->cpu_port = UINT_MAX; /* not defined yet */
|
||||
smi->num_ports = RTL8367_NUM_PORTS;
|
||||
smi->num_vlan_mc = RTL8367_NUM_VLANS;
|
||||
smi->mib_counters = rtl8367_mib_counters;
|
||||
|
@ -1,6 +1,7 @@
|
||||
/*
|
||||
* Platform driver for Realtek RTL8367B family chips, i.e. RTL8367RB and RTL8367R-VB
|
||||
* extended with support for RTL8367C family chips, i.e. RTL8367RB-VB and RTL8367S
|
||||
* extended with support for RTL8367D family chips, i.e. RTL8367S-VB
|
||||
*
|
||||
* Copyright (C) 2012 Gabor Juhos <juhosg@openwrt.org>
|
||||
*
|
||||
@ -122,6 +123,8 @@
|
||||
#define RTL8367B_CHIP_NUMBER_REG 0x1300/*GOOD*/
|
||||
|
||||
#define RTL8367B_CHIP_VER_REG 0x1301/*GOOD*/
|
||||
#define RTL8367B_CHIP_VER_RLVID_SHIFT 12/*GOOD*/
|
||||
#define RTL8367B_CHIP_VER_RLVID_MASK 0xf/*GOOD*/
|
||||
#define RTL8367B_CHIP_VER_MCID_SHIFT 8/*GOOD*/
|
||||
#define RTL8367B_CHIP_VER_MCID_MASK 0xf/*GOOD*/
|
||||
#define RTL8367B_CHIP_VER_BOID_SHIFT 4/*GOOD*/
|
||||
@ -266,6 +269,37 @@ struct rtl8367b_initval {
|
||||
#define RTL8367B_MIB_RXB_ID 0 /* IfInOctets */
|
||||
#define RTL8367B_MIB_TXB_ID 28 /* IfOutOctets */
|
||||
|
||||
#define RTL8367D_PORT_STATUS_REG(_p) (0x12d0 + (_p))
|
||||
|
||||
#define RTL8367D_PORT_STATUS_SPEED1_MASK 0x3000
|
||||
#define RTL8367D_PORT_STATUS_SPEED1_SHIFT 10 /*12-2*/
|
||||
|
||||
#define RTL8367D_REG_MAC0_FORCE_SELECT 0x12c0
|
||||
#define RTL8367D_REG_MAC0_FORCE_SELECT_EN 0x12c8
|
||||
|
||||
#define RTL8367D_VLAN_PVID_CTRL_REG(_p) (0x0700 + (_p))
|
||||
#define RTL8367D_VLAN_PVID_CTRL_MASK 0xfff
|
||||
#define RTL8367D_VLAN_PVID_CTRL_SHIFT(_p) 0
|
||||
|
||||
#define RTL8367D_FIDMAX 3
|
||||
#define RTL8367D_FID_MASK 3
|
||||
#define RTL8367D_TA_VLAN1_FID_SHIFT 0
|
||||
#define RTL8367D_TA_VLAN1_FID_MASK RTL8367D_FID_MASK
|
||||
|
||||
#define RTL8367D_VID_MASK 0xfff
|
||||
#define RTL8367D_TA_VLAN_VID_MASK RTL8367D_VID_MASK
|
||||
|
||||
#define RTL8367D_REG_EXT_TXC_DLY 0x13f9
|
||||
#define RTL8367D_EXT1_RGMII_TX_DLY_MASK 0x38
|
||||
|
||||
#define RTL8367D_REG_TOP_CON0 0x1d70
|
||||
#define RTL8367D_MAC7_SEL_EXT1_MASK 0x2000
|
||||
#define RTL8367D_MAC4_SEL_EXT1_MASK 0x1000
|
||||
|
||||
#define RTL8367D_REG_SDS1_MISC0 0x1d78
|
||||
#define RTL8367D_SDS1_MODE_MASK 0x1f
|
||||
#define RTL8367D_PORT_SDS_MODE_DISABLE 0x1f
|
||||
|
||||
static struct rtl8366_mib_counter
|
||||
rtl8367b_mib_counters[RTL8367B_NUM_MIB_COUNTERS] = {
|
||||
{0, 0, 4, "ifInOctets" },
|
||||
@ -527,8 +561,13 @@ static int rtl8367b_init_regs(struct rtl8366_smi *smi)
|
||||
break;
|
||||
case RTL8367B_CHIP_RTL8367RB_VB:
|
||||
case RTL8367B_CHIP_RTL8367S:
|
||||
case RTL8367B_CHIP_RTL8367S_VB:
|
||||
initvals = rtl8367c_initvals;
|
||||
count = ARRAY_SIZE(rtl8367c_initvals);
|
||||
if ((smi->rtl8367b_chip == RTL8367B_CHIP_RTL8367S_VB) && (smi->emu_vlanmc == NULL)) {
|
||||
smi->emu_vlanmc = kzalloc(sizeof(struct rtl8366_vlan_mc) * smi->num_vlan_mc, GFP_KERNEL);
|
||||
dev_info(smi->parent, "alloc vlan mc emulator");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -ENODEV;
|
||||
@ -566,6 +605,7 @@ static int rtl8367b_extif_set_mode(struct rtl8366_smi *smi, int id,
|
||||
enum rtl8367_extif_mode mode)
|
||||
{
|
||||
int err;
|
||||
u32 data;
|
||||
|
||||
/* set port mode */
|
||||
switch (mode) {
|
||||
@ -585,6 +625,15 @@ static int rtl8367b_extif_set_mode(struct rtl8366_smi *smi, int id,
|
||||
RTL8367B_DEBUG1_DP_MASK(id),
|
||||
(7 << RTL8367B_DEBUG1_DN_SHIFT(id)) |
|
||||
(7 << RTL8367B_DEBUG1_DP_SHIFT(id)));
|
||||
if ((smi->rtl8367b_chip == RTL8367B_CHIP_RTL8367S_VB) && (id == 1)) {
|
||||
REG_RMW(smi, RTL8367D_REG_EXT_TXC_DLY, RTL8367D_EXT1_RGMII_TX_DLY_MASK, 0);
|
||||
/* Configure RGMII/MII mux to port 7 if UTP_PORT4 is not RGMII mode */
|
||||
REG_RD(smi, RTL8367D_REG_TOP_CON0, &data);
|
||||
data &= RTL8367D_MAC4_SEL_EXT1_MASK;
|
||||
if (data == 0)
|
||||
REG_RMW(smi, RTL8367D_REG_TOP_CON0, RTL8367D_MAC7_SEL_EXT1_MASK, RTL8367D_MAC7_SEL_EXT1_MASK);
|
||||
REG_RMW(smi, RTL8367D_REG_SDS1_MISC0, RTL8367D_SDS1_MODE_MASK, RTL8367D_PORT_SDS_MODE_DISABLE);
|
||||
}
|
||||
} else {
|
||||
REG_RMW(smi, RTL8367B_CHIP_DEBUG2_REG,
|
||||
RTL8367B_DEBUG2_DRI_EXT2 |
|
||||
@ -643,23 +692,31 @@ static int rtl8367b_extif_set_force(struct rtl8366_smi *smi, int id,
|
||||
u32 val;
|
||||
int err;
|
||||
|
||||
mask = (RTL8367B_DI_FORCE_MODE |
|
||||
RTL8367B_DI_FORCE_NWAY |
|
||||
RTL8367B_DI_FORCE_TXPAUSE |
|
||||
RTL8367B_DI_FORCE_RXPAUSE |
|
||||
RTL8367B_DI_FORCE_LINK |
|
||||
RTL8367B_DI_FORCE_DUPLEX |
|
||||
RTL8367B_DI_FORCE_SPEED_MASK);
|
||||
|
||||
val = pa->speed;
|
||||
val |= pa->force_mode ? RTL8367B_DI_FORCE_MODE : 0;
|
||||
val = pa->speed & RTL8367B_DI_FORCE_SPEED_MASK;
|
||||
val |= pa->nway ? RTL8367B_DI_FORCE_NWAY : 0;
|
||||
val |= pa->txpause ? RTL8367B_DI_FORCE_TXPAUSE : 0;
|
||||
val |= pa->rxpause ? RTL8367B_DI_FORCE_RXPAUSE : 0;
|
||||
val |= pa->link ? RTL8367B_DI_FORCE_LINK : 0;
|
||||
val |= pa->duplex ? RTL8367B_DI_FORCE_DUPLEX : 0;
|
||||
|
||||
REG_RMW(smi, RTL8367B_DI_FORCE_REG(id), mask, val);
|
||||
if (smi->rtl8367b_chip >= RTL8367B_CHIP_RTL8367S_VB) { /* Family D */
|
||||
val |= (pa->speed << RTL8367D_PORT_STATUS_SPEED1_SHIFT) & RTL8367D_PORT_STATUS_SPEED1_MASK;
|
||||
if (smi->cpu_port != UINT_MAX) {
|
||||
REG_WR(smi, RTL8367D_REG_MAC0_FORCE_SELECT + smi->cpu_port, val);
|
||||
REG_WR(smi, RTL8367D_REG_MAC0_FORCE_SELECT_EN + smi->cpu_port, pa->force_mode ? 0xffff : 0x0000);
|
||||
}
|
||||
} else {
|
||||
val |= pa->force_mode ? RTL8367B_DI_FORCE_MODE : 0;
|
||||
mask = (RTL8367B_DI_FORCE_MODE |
|
||||
RTL8367B_DI_FORCE_NWAY |
|
||||
RTL8367B_DI_FORCE_TXPAUSE |
|
||||
RTL8367B_DI_FORCE_RXPAUSE |
|
||||
RTL8367B_DI_FORCE_LINK |
|
||||
RTL8367B_DI_FORCE_DUPLEX |
|
||||
RTL8367B_DI_FORCE_SPEED_MASK);
|
||||
|
||||
REG_RMW(smi, RTL8367B_DI_FORCE_REG(id), mask, val);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -710,21 +767,56 @@ static int rtl8367b_extif_init(struct rtl8366_smi *smi, int id,
|
||||
}
|
||||
|
||||
#ifdef CONFIG_OF
|
||||
static int rtl8367b_extif_init_of(struct rtl8366_smi *smi, int id,
|
||||
static int rtl8367b_extif_init_of(struct rtl8366_smi *smi,
|
||||
const char *name)
|
||||
{
|
||||
struct rtl8367_extif_config *cfg;
|
||||
const __be32 *prop;
|
||||
int size;
|
||||
int err;
|
||||
unsigned cpu_port;
|
||||
unsigned id = UINT_MAX;
|
||||
|
||||
prop = of_get_property(smi->parent->of_node, name, &size);
|
||||
if (!prop)
|
||||
return rtl8367b_extif_init(smi, id, NULL);
|
||||
if (!prop || (size != (10 * sizeof(*prop)))) {
|
||||
dev_err(smi->parent, "%s property is not defined or invalid\n", name);
|
||||
err = -EINVAL;
|
||||
goto err_init;
|
||||
}
|
||||
|
||||
if (size != (9 * sizeof(*prop))) {
|
||||
dev_err(smi->parent, "%s property is invalid\n", name);
|
||||
return -EINVAL;
|
||||
cpu_port = be32_to_cpup(prop++);
|
||||
switch (cpu_port) {
|
||||
case RTL8367B_CPU_PORT_NUM:
|
||||
case RTL8367B_CPU_PORT_NUM + 1:
|
||||
case RTL8367B_CPU_PORT_NUM + 2:
|
||||
if (smi->rtl8367b_chip == RTL8367B_CHIP_RTL8367R_VB) { /* for the RTL8367R-VB chip, cpu_port 5 corresponds to extif1 */
|
||||
if (cpu_port == RTL8367B_CPU_PORT_NUM)
|
||||
id = 1;
|
||||
else {
|
||||
dev_err(smi->parent, "wrong cpu_port %u in %s property\n", cpu_port, name);
|
||||
err = -EINVAL;
|
||||
goto err_init;
|
||||
}
|
||||
} else if (smi->rtl8367b_chip == RTL8367B_CHIP_RTL8367S_VB) { /* for the RTL8367S-VB chip, cpu_port 7 corresponds to extif1, cpu_port 6 corresponds to extif0 */
|
||||
if (cpu_port != RTL8367B_CPU_PORT_NUM) {
|
||||
id = cpu_port - RTL8367B_CPU_PORT_NUM - 1;
|
||||
} else {
|
||||
dev_err(smi->parent, "wrong cpu_port %u in %s property\n", cpu_port, name);
|
||||
err = -EINVAL;
|
||||
goto err_init;
|
||||
}
|
||||
} else {
|
||||
id = cpu_port - RTL8367B_CPU_PORT_NUM;
|
||||
}
|
||||
if (smi->cpu_port == UINT_MAX) {
|
||||
dev_info(smi->parent, "cpu_port:%u, assigned to extif%u\n", cpu_port, id);
|
||||
smi->cpu_port = cpu_port;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
dev_err(smi->parent, "wrong cpu_port %u in %s property\n", cpu_port, name);
|
||||
err = -EINVAL;
|
||||
goto err_init;
|
||||
}
|
||||
|
||||
cfg = kzalloc(sizeof(struct rtl8367_extif_config), GFP_KERNEL);
|
||||
@ -744,10 +836,15 @@ static int rtl8367b_extif_init_of(struct rtl8366_smi *smi, int id,
|
||||
err = rtl8367b_extif_init(smi, id, cfg);
|
||||
kfree(cfg);
|
||||
|
||||
err_init:
|
||||
if (id != 0) rtl8367b_extif_init(smi, 0, NULL);
|
||||
if (id != 1) rtl8367b_extif_init(smi, 1, NULL);
|
||||
if (id != 2) rtl8367b_extif_init(smi, 2, NULL);
|
||||
|
||||
return err;
|
||||
}
|
||||
#else
|
||||
static int rtl8367b_extif_init_of(struct rtl8366_smi *smi, int id,
|
||||
static int rtl8367b_extif_init_of(struct rtl8366_smi *smi,
|
||||
const char *name)
|
||||
{
|
||||
return -EINVAL;
|
||||
@ -768,15 +865,7 @@ static int rtl8367b_setup(struct rtl8366_smi *smi)
|
||||
|
||||
/* initialize external interfaces */
|
||||
if (smi->parent->of_node) {
|
||||
err = rtl8367b_extif_init_of(smi, 0, "realtek,extif0");
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = rtl8367b_extif_init_of(smi, 1, "realtek,extif1");
|
||||
if (err)
|
||||
return err;
|
||||
|
||||
err = rtl8367b_extif_init_of(smi, 2, "realtek,extif2");
|
||||
err = rtl8367b_extif_init_of(smi, "realtek,extif");
|
||||
if (err)
|
||||
return err;
|
||||
} else {
|
||||
@ -886,8 +975,12 @@ static int rtl8367b_get_vlan_4k(struct rtl8366_smi *smi, u32 vid,
|
||||
RTL8367B_TA_VLAN0_MEMBER_MASK;
|
||||
vlan4k->untag = (data[0] >> RTL8367B_TA_VLAN0_UNTAG_SHIFT) &
|
||||
RTL8367B_TA_VLAN0_UNTAG_MASK;
|
||||
vlan4k->fid = (data[1] >> RTL8367B_TA_VLAN1_FID_SHIFT) &
|
||||
RTL8367B_TA_VLAN1_FID_MASK;
|
||||
if (smi->rtl8367b_chip >= RTL8367B_CHIP_RTL8367S_VB) /* Family D */
|
||||
vlan4k->fid = (data[1] >> RTL8367D_TA_VLAN1_FID_SHIFT) &
|
||||
RTL8367D_TA_VLAN1_FID_MASK;
|
||||
else
|
||||
vlan4k->fid = (data[1] >> RTL8367B_TA_VLAN1_FID_SHIFT) &
|
||||
RTL8367B_TA_VLAN1_FID_MASK;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -902,7 +995,7 @@ static int rtl8367b_set_vlan_4k(struct rtl8366_smi *smi,
|
||||
if (vlan4k->vid >= RTL8367B_NUM_VIDS ||
|
||||
vlan4k->member > RTL8367B_TA_VLAN0_MEMBER_MASK ||
|
||||
vlan4k->untag > RTL8367B_UNTAG_MASK ||
|
||||
vlan4k->fid > RTL8367B_FIDMAX)
|
||||
vlan4k->fid > ((smi->rtl8367b_chip >= RTL8367B_CHIP_RTL8367S_VB) ? RTL8367D_FIDMAX : RTL8367B_FIDMAX))
|
||||
return -EINVAL;
|
||||
|
||||
memset(data, 0, sizeof(data));
|
||||
@ -911,15 +1004,24 @@ static int rtl8367b_set_vlan_4k(struct rtl8366_smi *smi,
|
||||
RTL8367B_TA_VLAN0_MEMBER_SHIFT;
|
||||
data[0] |= (vlan4k->untag & RTL8367B_TA_VLAN0_UNTAG_MASK) <<
|
||||
RTL8367B_TA_VLAN0_UNTAG_SHIFT;
|
||||
data[1] = (vlan4k->fid & RTL8367B_TA_VLAN1_FID_MASK) <<
|
||||
RTL8367B_TA_VLAN1_FID_SHIFT;
|
||||
|
||||
if (smi->rtl8367b_chip >= RTL8367B_CHIP_RTL8367S_VB) /* Family D */
|
||||
data[1] = ((vlan4k->fid & RTL8367D_TA_VLAN1_FID_MASK) <<
|
||||
RTL8367D_TA_VLAN1_FID_SHIFT) | 12; /* ivl_svl - BIT(3), svlan_chek_ivl_svl - BIT(2) */
|
||||
else
|
||||
data[1] = (vlan4k->fid & RTL8367B_TA_VLAN1_FID_MASK) <<
|
||||
RTL8367B_TA_VLAN1_FID_SHIFT;
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(data); i++)
|
||||
REG_WR(smi, RTL8367B_TA_WRDATA_REG(i), data[i]);
|
||||
|
||||
/* write VID */
|
||||
REG_WR(smi, RTL8367B_TA_ADDR_REG,
|
||||
vlan4k->vid & RTL8367B_TA_VLAN_VID_MASK);
|
||||
if (smi->rtl8367b_chip >= RTL8367B_CHIP_RTL8367S_VB) /* Family D */
|
||||
REG_WR(smi, RTL8367B_TA_ADDR_REG,
|
||||
vlan4k->vid & RTL8367D_TA_VLAN_VID_MASK);
|
||||
else
|
||||
REG_WR(smi, RTL8367B_TA_ADDR_REG,
|
||||
vlan4k->vid & RTL8367B_TA_VLAN_VID_MASK);
|
||||
|
||||
/* write table access control word */
|
||||
REG_WR(smi, RTL8367B_TA_CTRL_REG, RTL8367B_TA_CTRL_CVLAN_WRITE);
|
||||
@ -939,6 +1041,14 @@ static int rtl8367b_get_vlan_mc(struct rtl8366_smi *smi, u32 index,
|
||||
if (index >= RTL8367B_NUM_VLANS)
|
||||
return -EINVAL;
|
||||
|
||||
if (smi->emu_vlanmc) { /* use vlan mc emulation */
|
||||
vlanmc->vid = smi->emu_vlanmc[index].vid;
|
||||
vlanmc->member = smi->emu_vlanmc[index].member;
|
||||
vlanmc->fid = smi->emu_vlanmc[index].fid;
|
||||
vlanmc->untag = smi->emu_vlanmc[index].untag;
|
||||
return 0;
|
||||
}
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(data); i++)
|
||||
REG_RD(smi, RTL8367B_VLAN_MC_BASE(index) + i, &data[i]);
|
||||
|
||||
@ -964,9 +1074,17 @@ static int rtl8367b_set_vlan_mc(struct rtl8366_smi *smi, u32 index,
|
||||
vlanmc->priority > RTL8367B_PRIORITYMAX ||
|
||||
vlanmc->member > RTL8367B_VLAN_MC0_MEMBER_MASK ||
|
||||
vlanmc->untag > RTL8367B_UNTAG_MASK ||
|
||||
vlanmc->fid > RTL8367B_FIDMAX)
|
||||
vlanmc->fid > ((smi->rtl8367b_chip >= RTL8367B_CHIP_RTL8367S_VB) ? RTL8367D_FIDMAX : RTL8367B_FIDMAX))
|
||||
return -EINVAL;
|
||||
|
||||
if (smi->emu_vlanmc) { /* use vlanmc emulation */
|
||||
smi->emu_vlanmc[index].vid = vlanmc->vid;
|
||||
smi->emu_vlanmc[index].member = vlanmc->member;
|
||||
smi->emu_vlanmc[index].fid = vlanmc->fid;
|
||||
smi->emu_vlanmc[index].untag = vlanmc->untag;
|
||||
return 0;
|
||||
}
|
||||
|
||||
data[0] = (vlanmc->member & RTL8367B_VLAN_MC0_MEMBER_MASK) <<
|
||||
RTL8367B_VLAN_MC0_MEMBER_SHIFT;
|
||||
data[1] = (vlanmc->fid & RTL8367B_VLAN_MC1_FID_MASK) <<
|
||||
@ -989,10 +1107,41 @@ static int rtl8367b_get_mc_index(struct rtl8366_smi *smi, int port, int *val)
|
||||
if (port >= RTL8367B_NUM_PORTS)
|
||||
return -EINVAL;
|
||||
|
||||
REG_RD(smi, RTL8367B_VLAN_PVID_CTRL_REG(port), &data);
|
||||
if (smi->rtl8367b_chip >= RTL8367B_CHIP_RTL8367S_VB) { /* Family D */
|
||||
int i;
|
||||
struct rtl8366_vlan_mc vlanmc;
|
||||
|
||||
*val = (data >> RTL8367B_VLAN_PVID_CTRL_SHIFT(port)) &
|
||||
RTL8367B_VLAN_PVID_CTRL_MASK;
|
||||
err = rtl8366_smi_read_reg(smi, RTL8367D_VLAN_PVID_CTRL_REG(port), &data);
|
||||
|
||||
if (err) {
|
||||
dev_err(smi->parent, "read pvid register 0x%04x fail", RTL8367D_VLAN_PVID_CTRL_REG(port));
|
||||
return err;
|
||||
}
|
||||
|
||||
data &= RTL8367D_VLAN_PVID_CTRL_MASK;
|
||||
for (i = 0; i < smi->num_vlan_mc; i++) {
|
||||
err = rtl8367b_get_vlan_mc(smi, i, &vlanmc);
|
||||
|
||||
if (err) {
|
||||
dev_err(smi->parent, "get vlan mc index %d fail", i);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (data == vlanmc.vid) break;
|
||||
}
|
||||
|
||||
if (i < smi->num_vlan_mc) {
|
||||
*val = i;
|
||||
} else {
|
||||
dev_err(smi->parent, "vlan mc index for pvid %d not found", data);
|
||||
return -EINVAL;
|
||||
}
|
||||
} else {
|
||||
REG_RD(smi, RTL8367B_VLAN_PVID_CTRL_REG(port), &data);
|
||||
|
||||
*val = (data >> RTL8367B_VLAN_PVID_CTRL_SHIFT(port)) &
|
||||
RTL8367B_VLAN_PVID_CTRL_MASK;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -1002,7 +1151,28 @@ static int rtl8367b_set_mc_index(struct rtl8366_smi *smi, int port, int index)
|
||||
if (port >= RTL8367B_NUM_PORTS || index >= RTL8367B_NUM_VLANS)
|
||||
return -EINVAL;
|
||||
|
||||
return rtl8366_smi_rmwr(smi, RTL8367B_VLAN_PVID_CTRL_REG(port),
|
||||
if (smi->rtl8367b_chip >= RTL8367B_CHIP_RTL8367S_VB) { /* Family D */
|
||||
int pvid, err;
|
||||
struct rtl8366_vlan_mc vlanmc;
|
||||
|
||||
err = rtl8367b_get_vlan_mc(smi, index, &vlanmc);
|
||||
|
||||
if (err) {
|
||||
dev_err(smi->parent, "get vlan mc index %d fail", index);
|
||||
return err;
|
||||
}
|
||||
|
||||
pvid = vlanmc.vid & RTL8367D_VLAN_PVID_CTRL_MASK;
|
||||
err = rtl8366_smi_write_reg(smi, RTL8367D_VLAN_PVID_CTRL_REG(port), pvid);
|
||||
|
||||
if (err) {
|
||||
dev_err(smi->parent, "set port %d pvid %d fail", port, pvid);
|
||||
return err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
} else
|
||||
return rtl8366_smi_rmwr(smi, RTL8367B_VLAN_PVID_CTRL_REG(port),
|
||||
RTL8367B_VLAN_PVID_CTRL_MASK <<
|
||||
RTL8367B_VLAN_PVID_CTRL_SHIFT(port),
|
||||
(index & RTL8367B_VLAN_PVID_CTRL_MASK) <<
|
||||
@ -1065,7 +1235,10 @@ static int rtl8367b_sw_get_port_link(struct switch_dev *dev,
|
||||
if (port >= RTL8367B_NUM_PORTS)
|
||||
return -EINVAL;
|
||||
|
||||
rtl8366_smi_read_reg(smi, RTL8367B_PORT_STATUS_REG(port), &data);
|
||||
if (smi->rtl8367b_chip >= RTL8367B_CHIP_RTL8367S_VB) /* Family D */
|
||||
rtl8366_smi_read_reg(smi, RTL8367D_PORT_STATUS_REG(port), &data);
|
||||
else
|
||||
rtl8366_smi_read_reg(smi, RTL8367B_PORT_STATUS_REG(port), &data);
|
||||
|
||||
link->link = !!(data & RTL8367B_PORT_STATUS_LINK);
|
||||
if (!link->link)
|
||||
@ -1076,15 +1249,18 @@ static int rtl8367b_sw_get_port_link(struct switch_dev *dev,
|
||||
link->tx_flow = !!(data & RTL8367B_PORT_STATUS_TXPAUSE);
|
||||
link->aneg = !!(data & RTL8367B_PORT_STATUS_NWAY);
|
||||
|
||||
speed = (data & RTL8367B_PORT_STATUS_SPEED_MASK);
|
||||
if (smi->rtl8367b_chip >= RTL8367B_CHIP_RTL8367S_VB) /* Family D */
|
||||
speed = (data & RTL8367B_PORT_STATUS_SPEED_MASK) | ((data & RTL8367D_PORT_STATUS_SPEED1_MASK) >> RTL8367D_PORT_STATUS_SPEED1_SHIFT);
|
||||
else
|
||||
speed = (data & RTL8367B_PORT_STATUS_SPEED_MASK);
|
||||
switch (speed) {
|
||||
case 0:
|
||||
case RTL8367B_PORT_STATUS_SPEED_10:
|
||||
link->speed = SWITCH_PORT_SPEED_10;
|
||||
break;
|
||||
case 1:
|
||||
case RTL8367B_PORT_STATUS_SPEED_100:
|
||||
link->speed = SWITCH_PORT_SPEED_100;
|
||||
break;
|
||||
case 2:
|
||||
case RTL8367B_PORT_STATUS_SPEED_1000:
|
||||
link->speed = SWITCH_PORT_SPEED_1000;
|
||||
break;
|
||||
default:
|
||||
@ -1303,6 +1479,7 @@ static int rtl8367b_detect(struct rtl8366_smi *smi)
|
||||
u32 chip_ver;
|
||||
int ret;
|
||||
|
||||
smi->emu_vlanmc = NULL;
|
||||
smi->rtl8367b_chip = RTL8367B_CHIP_UNKNOWN;
|
||||
|
||||
rtl8366_smi_write_reg(smi, RTL8367B_RTL_MAGIC_ID_REG,
|
||||
@ -1323,6 +1500,12 @@ static int rtl8367b_detect(struct rtl8366_smi *smi)
|
||||
}
|
||||
|
||||
switch (chip_ver) {
|
||||
case 0x0010:
|
||||
if (chip_num == 0x6642) {
|
||||
chip_name = "8367S-VB";
|
||||
smi->rtl8367b_chip = RTL8367B_CHIP_RTL8367S_VB;
|
||||
}
|
||||
break;
|
||||
case 0x0020:
|
||||
if (chip_num == 0x6367) {
|
||||
chip_name = "8367RB-VB";
|
||||
@ -1353,14 +1536,6 @@ static int rtl8367b_detect(struct rtl8366_smi *smi)
|
||||
|
||||
dev_info(smi->parent, "RTL%s chip found (num:%04x ver:%04x)\n", chip_name, chip_num, chip_ver);
|
||||
|
||||
/* for the RTL8367R-VB chip, extif1 corresponds to cpu_port 5 */
|
||||
if (of_property_present(smi->parent->of_node, "realtek,extif2"))
|
||||
smi->cpu_port = RTL8367B_CPU_PORT_NUM + 2;
|
||||
else if (of_property_present(smi->parent->of_node, "realtek,extif1") && (smi->rtl8367b_chip != RTL8367B_CHIP_RTL8367R_VB))
|
||||
smi->cpu_port = RTL8367B_CPU_PORT_NUM + 1;
|
||||
|
||||
dev_info(smi->parent, "CPU port: %u\n", smi->cpu_port);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1399,7 +1574,7 @@ static int rtl8367b_probe(struct platform_device *pdev)
|
||||
smi->cmd_write = 0xb8;
|
||||
smi->ops = &rtl8367b_smi_ops;
|
||||
smi->num_ports = RTL8367B_NUM_PORTS;
|
||||
smi->cpu_port = RTL8367B_CPU_PORT_NUM;
|
||||
smi->cpu_port = UINT_MAX; /* not defined yet */
|
||||
smi->num_vlan_mc = RTL8367B_NUM_VLANS;
|
||||
smi->mib_counters = rtl8367b_mib_counters;
|
||||
smi->num_mib_counters = ARRAY_SIZE(rtl8367b_mib_counters);
|
||||
@ -1420,6 +1595,8 @@ static int rtl8367b_probe(struct platform_device *pdev)
|
||||
platform_set_drvdata(pdev, NULL);
|
||||
rtl8366_smi_cleanup(smi);
|
||||
err_free_smi:
|
||||
if (smi->emu_vlanmc)
|
||||
kfree(smi->emu_vlanmc);
|
||||
kfree(smi);
|
||||
return err;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user