@@ -484,7 +484,7 @@ static int b53_fast_age_vlan(struct b53_device *dev, u16 vid)
484
484
return b53_flush_arl (dev , FAST_AGE_VLAN );
485
485
}
486
486
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 )
488
488
{
489
489
struct b53_device * dev = ds -> priv ;
490
490
unsigned int i ;
@@ -500,9 +500,9 @@ static void b53_imp_vlan_setup(struct dsa_switch *ds, int cpu_port)
500
500
b53_write16 (dev , B53_PVLAN_PAGE , B53_PVLAN_PORT_MASK (i ), pvlan );
501
501
}
502
502
}
503
+ EXPORT_SYMBOL (b53_imp_vlan_setup );
503
504
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 )
506
506
{
507
507
struct b53_device * dev = ds -> priv ;
508
508
unsigned int cpu_port = dev -> cpu_port ;
@@ -523,11 +523,15 @@ static int b53_enable_port(struct dsa_switch *ds, int port,
523
523
524
524
b53_imp_vlan_setup (ds , cpu_port );
525
525
526
+ /* If EEE was enabled, restore it */
527
+ if (dev -> ports [port ].eee .eee_enabled )
528
+ b53_eee_enable_set (ds , port , true);
529
+
526
530
return 0 ;
527
531
}
532
+ EXPORT_SYMBOL (b53_enable_port );
528
533
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 )
531
535
{
532
536
struct b53_device * dev = ds -> priv ;
533
537
u8 reg ;
@@ -537,20 +541,67 @@ static void b53_disable_port(struct dsa_switch *ds, int port,
537
541
reg |= PORT_CTRL_RX_DISABLE | PORT_CTRL_TX_DISABLE ;
538
542
b53_write8 (dev , B53_CTRL_PAGE , B53_PORT_CTRL (port ), reg );
539
543
}
544
+ EXPORT_SYMBOL (b53_disable_port );
540
545
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 )
542
594
{
543
- unsigned int cpu_port = dev -> cpu_port ;
544
595
u8 port_ctrl ;
545
596
546
597
/* 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 ;
549
600
550
601
port_ctrl = PORT_CTRL_RX_BCST_EN |
551
602
PORT_CTRL_RX_MCST_EN |
552
603
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 );
554
605
}
555
606
556
607
static void b53_enable_mib (struct b53_device * dev )
@@ -816,12 +867,13 @@ static int b53_setup(struct dsa_switch *ds)
816
867
if (ret )
817
868
dev_err (ds -> dev , "failed to apply configuration\n" );
818
869
870
+ /* Configure IMP/CPU port, disable unused ports. Enabled
871
+ * ports will be configured with .port_enable
872
+ */
819
873
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 ))
825
877
b53_disable_port (ds , port , NULL );
826
878
}
827
879
@@ -832,6 +884,7 @@ static void b53_adjust_link(struct dsa_switch *ds, int port,
832
884
struct phy_device * phydev )
833
885
{
834
886
struct b53_device * dev = ds -> priv ;
887
+ struct ethtool_eee * p = & dev -> ports [port ].eee ;
835
888
u8 rgmii_ctrl = 0 , reg = 0 , off ;
836
889
837
890
if (!phy_is_pseudo_fixed_link (phydev ))
@@ -953,6 +1006,9 @@ static void b53_adjust_link(struct dsa_switch *ds, int port,
953
1006
b53_write8 (dev , B53_CTRL_PAGE , po_reg , gmii_po );
954
1007
}
955
1008
}
1009
+
1010
+ /* Re-negotiate EEE if it was enabled already */
1011
+ p -> eee_enabled = b53_eee_init (ds , port , phydev );
956
1012
}
957
1013
958
1014
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,
1484
1540
}
1485
1541
EXPORT_SYMBOL (b53_mirror_del );
1486
1542
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
+
1487
1606
static const struct dsa_switch_ops b53_switch_ops = {
1488
1607
.get_tag_protocol = b53_get_tag_protocol ,
1489
1608
.setup = b53_setup ,
@@ -1495,6 +1614,8 @@ static const struct dsa_switch_ops b53_switch_ops = {
1495
1614
.adjust_link = b53_adjust_link ,
1496
1615
.port_enable = b53_enable_port ,
1497
1616
.port_disable = b53_disable_port ,
1617
+ .get_mac_eee = b53_get_mac_eee ,
1618
+ .set_mac_eee = b53_set_mac_eee ,
1498
1619
.port_bridge_join = b53_br_join ,
1499
1620
.port_bridge_leave = b53_br_leave ,
1500
1621
.port_stp_state_set = b53_br_set_stp_state ,
0 commit comments