Skip to content

Commit 3d5cc72

Browse files
committed
Merge branch 'dsa-b53-bcm_sf2-cleanups'
Florian Fainelli says: ==================== net: dsa: b53/bcm_sf2 cleanups This patch series is a first pass set of clean-ups to reduce the number of LOCs between b53 and bcm_sf2 and sharing as many functions as possible. There is a number of additional cleanups queued up locally that require more thorough testing. Changes in v3: - remove one extra argument for the b53_build_io_op macro (David Laight) - added additional Reviewed-by tags from Vivien Changes in v2: - added Reviewed-by tags from Vivien - added a missing EXPORT_SYMBOL() in patch 8 - fixed a typo in patch 5 ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents d43a9d1 + f86ad77 commit 3d5cc72

File tree

7 files changed

+228
-296
lines changed

7 files changed

+228
-296
lines changed

drivers/net/dsa/b53/b53_common.c

Lines changed: 136 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ static int b53_fast_age_vlan(struct b53_device *dev, u16 vid)
484484
return b53_flush_arl(dev, FAST_AGE_VLAN);
485485
}
486486

487-
static void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port)
487+
void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port)
488488
{
489489
struct b53_device *dev = ds->priv;
490490
unsigned int i;
@@ -500,9 +500,9 @@ static void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port)
500500
b53_write16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), pvlan);
501501
}
502502
}
503+
EXPORT_SYMBOL(b53_imp_vlan_setup);
503504

504-
static int b53_enable_port(struct dsa_switch *ds, int port,
505-
struct phy_device *phy)
505+
int b53_enable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
506506
{
507507
struct b53_device *dev = ds->priv;
508508
unsigned int cpu_port = dev->cpu_port;
@@ -523,11 +523,15 @@ static int b53_enable_port(struct dsa_switch *ds, int port,
523523

524524
b53_imp_vlan_setup(ds, cpu_port);
525525

526+
/* If EEE was enabled, restore it */
527+
if (dev->ports[port].eee.eee_enabled)
528+
b53_eee_enable_set(ds, port, true);
529+
526530
return 0;
527531
}
532+
EXPORT_SYMBOL(b53_enable_port);
528533

529-
static void b53_disable_port(struct dsa_switch *ds, int port,
530-
struct phy_device *phy)
534+
void b53_disable_port(struct dsa_switch *ds, int port, struct phy_device *phy)
531535
{
532536
struct b53_device *dev = ds->priv;
533537
u8 reg;
@@ -537,20 +541,67 @@ static void b53_disable_port(struct dsa_switch *ds, int port,
537541
reg |= PORT_CTRL_RX_DISABLE | PORT_CTRL_TX_DISABLE;
538542
b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), reg);
539543
}
544+
EXPORT_SYMBOL(b53_disable_port);
540545

541-
static void b53_enable_cpu_port(struct b53_device *dev)
546+
void b53_brcm_hdr_setup(struct dsa_switch *ds, int port)
547+
{
548+
struct b53_device *dev = ds->priv;
549+
u8 hdr_ctl, val;
550+
u16 reg;
551+
552+
/* Resolve which bit controls the Broadcom tag */
553+
switch (port) {
554+
case 8:
555+
val = BRCM_HDR_P8_EN;
556+
break;
557+
case 7:
558+
val = BRCM_HDR_P7_EN;
559+
break;
560+
case 5:
561+
val = BRCM_HDR_P5_EN;
562+
break;
563+
default:
564+
val = 0;
565+
break;
566+
}
567+
568+
/* Enable Broadcom tags for IMP port */
569+
b53_read8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, &hdr_ctl);
570+
hdr_ctl |= val;
571+
b53_write8(dev, B53_MGMT_PAGE, B53_BRCM_HDR, hdr_ctl);
572+
573+
/* Registers below are only accessible on newer devices */
574+
if (!is58xx(dev))
575+
return;
576+
577+
/* Enable reception Broadcom tag for CPU TX (switch RX) to
578+
* allow us to tag outgoing frames
579+
*/
580+
b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, &reg);
581+
reg &= ~BIT(port);
582+
b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_RX_DIS, reg);
583+
584+
/* Enable transmission of Broadcom tags from the switch (CPU RX) to
585+
* allow delivering frames to the per-port net_devices
586+
*/
587+
b53_read16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, &reg);
588+
reg &= ~BIT(port);
589+
b53_write16(dev, B53_MGMT_PAGE, B53_BRCM_HDR_TX_DIS, reg);
590+
}
591+
EXPORT_SYMBOL(b53_brcm_hdr_setup);
592+
593+
static void b53_enable_cpu_port(struct b53_device *dev, int port)
542594
{
543-
unsigned int cpu_port = dev->cpu_port;
544595
u8 port_ctrl;
545596

546597
/* BCM5325 CPU port is at 8 */
547-
if ((is5325(dev) || is5365(dev)) && cpu_port == B53_CPU_PORT_25)
548-
cpu_port = B53_CPU_PORT;
598+
if ((is5325(dev) || is5365(dev)) && port == B53_CPU_PORT_25)
599+
port = B53_CPU_PORT;
549600

550601
port_ctrl = PORT_CTRL_RX_BCST_EN |
551602
PORT_CTRL_RX_MCST_EN |
552603
PORT_CTRL_RX_UCST_EN;
553-
b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(cpu_port), port_ctrl);
604+
b53_write8(dev, B53_CTRL_PAGE, B53_PORT_CTRL(port), port_ctrl);
554605
}
555606

556607
static void b53_enable_mib(struct b53_device *dev)
@@ -816,12 +867,13 @@ static int b53_setup(struct dsa_switch *ds)
816867
if (ret)
817868
dev_err(ds->dev, "failed to apply configuration\n");
818869

870+
/* Configure IMP/CPU port, disable unused ports. Enabled
871+
* ports will be configured with .port_enable
872+
*/
819873
for (port = 0; port < dev->num_ports; port++) {
820-
if (BIT(port) & ds->enabled_port_mask)
821-
b53_enable_port(ds, port, NULL);
822-
else if (dsa_is_cpu_port(ds, port))
823-
b53_enable_cpu_port(dev);
824-
else
874+
if (dsa_is_cpu_port(ds, port))
875+
b53_enable_cpu_port(dev, port);
876+
else if (!(BIT(port) & ds->enabled_port_mask))
825877
b53_disable_port(ds, port, NULL);
826878
}
827879

@@ -832,6 +884,7 @@ static void b53_adjust_link(struct dsa_switch *ds, int port,
832884
struct phy_device *phydev)
833885
{
834886
struct b53_device *dev = ds->priv;
887+
struct ethtool_eee *p = &dev->ports[port].eee;
835888
u8 rgmii_ctrl = 0, reg = 0, off;
836889

837890
if (!phy_is_pseudo_fixed_link(phydev))
@@ -953,6 +1006,9 @@ static void b53_adjust_link(struct dsa_switch *ds, int port,
9531006
b53_write8(dev, B53_CTRL_PAGE, po_reg, gmii_po);
9541007
}
9551008
}
1009+
1010+
/* Re-negotiate EEE if it was enabled already */
1011+
p->eee_enabled = b53_eee_init(ds, port, phydev);
9561012
}
9571013

9581014
int b53_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering)
@@ -1484,6 +1540,69 @@ void b53_mirror_del(struct dsa_switch *ds, int port,
14841540
}
14851541
EXPORT_SYMBOL(b53_mirror_del);
14861542

1543+
void b53_eee_enable_set(struct dsa_switch *ds, int port, bool enable)
1544+
{
1545+
struct b53_device *dev = ds->priv;
1546+
u16 reg;
1547+
1548+
b53_read16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, &reg);
1549+
if (enable)
1550+
reg |= BIT(port);
1551+
else
1552+
reg &= ~BIT(port);
1553+
b53_write16(dev, B53_EEE_PAGE, B53_EEE_EN_CTRL, reg);
1554+
}
1555+
EXPORT_SYMBOL(b53_eee_enable_set);
1556+
1557+
1558+
/* Returns 0 if EEE was not enabled, or 1 otherwise
1559+
*/
1560+
int b53_eee_init(struct dsa_switch *ds, int port, struct phy_device *phy)
1561+
{
1562+
int ret;
1563+
1564+
ret = phy_init_eee(phy, 0);
1565+
if (ret)
1566+
return 0;
1567+
1568+
b53_eee_enable_set(ds, port, true);
1569+
1570+
return 1;
1571+
}
1572+
EXPORT_SYMBOL(b53_eee_init);
1573+
1574+
int b53_get_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
1575+
{
1576+
struct b53_device *dev = ds->priv;
1577+
struct ethtool_eee *p = &dev->ports[port].eee;
1578+
u16 reg;
1579+
1580+
if (is5325(dev) || is5365(dev))
1581+
return -EOPNOTSUPP;
1582+
1583+
b53_read16(dev, B53_EEE_PAGE, B53_EEE_LPI_INDICATE, &reg);
1584+
e->eee_enabled = p->eee_enabled;
1585+
e->eee_active = !!(reg & BIT(port));
1586+
1587+
return 0;
1588+
}
1589+
EXPORT_SYMBOL(b53_get_mac_eee);
1590+
1591+
int b53_set_mac_eee(struct dsa_switch *ds, int port, struct ethtool_eee *e)
1592+
{
1593+
struct b53_device *dev = ds->priv;
1594+
struct ethtool_eee *p = &dev->ports[port].eee;
1595+
1596+
if (is5325(dev) || is5365(dev))
1597+
return -EOPNOTSUPP;
1598+
1599+
p->eee_enabled = e->eee_enabled;
1600+
b53_eee_enable_set(ds, port, e->eee_enabled);
1601+
1602+
return 0;
1603+
}
1604+
EXPORT_SYMBOL(b53_set_mac_eee);
1605+
14871606
static const struct dsa_switch_ops b53_switch_ops = {
14881607
.get_tag_protocol = b53_get_tag_protocol,
14891608
.setup = b53_setup,
@@ -1495,6 +1614,8 @@ static const struct dsa_switch_ops b53_switch_ops = {
14951614
.adjust_link = b53_adjust_link,
14961615
.port_enable = b53_enable_port,
14971616
.port_disable = b53_disable_port,
1617+
.get_mac_eee = b53_get_mac_eee,
1618+
.set_mac_eee = b53_set_mac_eee,
14981619
.port_bridge_join = b53_br_join,
14991620
.port_bridge_leave = b53_br_leave,
15001621
.port_stp_state_set = b53_br_set_stp_state,

0 commit comments

Comments
 (0)