1 From 861a32edce13ccba86647507fefcfd4910972dd7 Mon Sep 17 00:00:00 2001
2 From: Vladimir Oltean <vladimir.oltean@nxp.com>
3 Date: Thu, 14 Nov 2019 17:03:22 +0200
4 Subject: [PATCH] net: mscc: ocelot: move invariant configs out of adjust_link
6 It doesn't make sense to rewrite all these registers every time the PHY
7 library notifies us about a link state change.
9 In a future patch we will customize the MTU for the CPU port, and since
10 the MTU was previously configured from adjust_link, if we don't make
11 this change, its value would have got overridden.
13 Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
14 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
15 Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
16 Signed-off-by: David S. Miller <davem@davemloft.net>
18 drivers/net/ethernet/mscc/ocelot.c | 85 +++++++++++++++++++-------------------
19 1 file changed, 43 insertions(+), 42 deletions(-)
21 --- a/drivers/net/ethernet/mscc/ocelot.c
22 +++ b/drivers/net/ethernet/mscc/ocelot.c
23 @@ -408,7 +408,7 @@ static void ocelot_adjust_link(struct oc
24 struct phy_device *phydev)
26 struct ocelot_port *ocelot_port = ocelot->ports[port];
27 - int speed, atop_wm, mode = 0;
28 + int speed, mode = 0;
30 switch (phydev->speed) {
32 @@ -440,32 +440,9 @@ static void ocelot_adjust_link(struct oc
33 ocelot_port_writel(ocelot_port, DEV_MAC_MODE_CFG_FDX_ENA |
34 mode, DEV_MAC_MODE_CFG);
37 - * FDX: TX_IFG = 5, RX_IFG1 = RX_IFG2 = 0
38 - * !FDX: TX_IFG = 5, RX_IFG1 = RX_IFG2 = 5
40 - ocelot_port_writel(ocelot_port, DEV_MAC_IFG_CFG_TX_IFG(5),
43 - /* Load seed (0) and set MAC HDX late collision */
44 - ocelot_port_writel(ocelot_port, DEV_MAC_HDX_CFG_LATE_COL_POS(67) |
45 - DEV_MAC_HDX_CFG_SEED_LOAD,
48 - ocelot_port_writel(ocelot_port, DEV_MAC_HDX_CFG_LATE_COL_POS(67),
51 if (ocelot->ops->pcs_init)
52 ocelot->ops->pcs_init(ocelot, port);
54 - /* Set Max Length and maximum tags allowed */
55 - ocelot_port_writel(ocelot_port, VLAN_ETH_FRAME_LEN,
56 - DEV_MAC_MAXLEN_CFG);
57 - ocelot_port_writel(ocelot_port, DEV_MAC_TAGS_CFG_TAG_ID(ETH_P_8021AD) |
58 - DEV_MAC_TAGS_CFG_VLAN_AWR_ENA |
59 - DEV_MAC_TAGS_CFG_VLAN_LEN_AWR_ENA,
62 /* Enable MAC module */
63 ocelot_port_writel(ocelot_port, DEV_MAC_ENA_CFG_RX_ENA |
64 DEV_MAC_ENA_CFG_TX_ENA, DEV_MAC_ENA_CFG);
65 @@ -475,22 +452,10 @@ static void ocelot_adjust_link(struct oc
66 ocelot_port_writel(ocelot_port, DEV_CLOCK_CFG_LINK_SPEED(speed),
69 - /* Set SMAC of Pause frame (00:00:00:00:00:00) */
70 - ocelot_port_writel(ocelot_port, 0, DEV_MAC_FC_MAC_HIGH_CFG);
71 - ocelot_port_writel(ocelot_port, 0, DEV_MAC_FC_MAC_LOW_CFG);
74 ocelot_write_gix(ocelot, ANA_PFC_PFC_CFG_FC_LINK_SPEED(speed),
75 ANA_PFC_PFC_CFG, port);
77 - /* Set Pause WM hysteresis
78 - * 152 = 6 * VLAN_ETH_FRAME_LEN / OCELOT_BUFFER_CELL_SZ
79 - * 101 = 4 * VLAN_ETH_FRAME_LEN / OCELOT_BUFFER_CELL_SZ
81 - ocelot_write_rix(ocelot, SYS_PAUSE_CFG_PAUSE_ENA |
82 - SYS_PAUSE_CFG_PAUSE_STOP(101) |
83 - SYS_PAUSE_CFG_PAUSE_START(152), SYS_PAUSE_CFG, port);
85 /* Core: Enable port for frame transfer */
86 ocelot_write_rix(ocelot, QSYS_SWITCH_PORT_MODE_INGRESS_DROP_MODE |
87 QSYS_SWITCH_PORT_MODE_SCH_NEXT_CFG(1) |
88 @@ -505,12 +470,6 @@ static void ocelot_adjust_link(struct oc
89 SYS_MAC_FC_CFG_FC_LINK_SPEED(speed),
90 SYS_MAC_FC_CFG, port);
91 ocelot_write_rix(ocelot, 0, ANA_POL_FLOWC, port);
93 - /* Tail dropping watermark */
94 - atop_wm = (ocelot->shared_queue_sz - 9 * VLAN_ETH_FRAME_LEN) / OCELOT_BUFFER_CELL_SZ;
95 - ocelot_write_rix(ocelot, ocelot_wm_enc(9 * VLAN_ETH_FRAME_LEN),
97 - ocelot_write(ocelot, ocelot_wm_enc(atop_wm), SYS_ATOP_TOT_CFG);
100 static void ocelot_port_adjust_link(struct net_device *dev)
101 @@ -2145,11 +2104,53 @@ static int ocelot_init_timestamp(struct
102 static void ocelot_init_port(struct ocelot *ocelot, int port)
104 struct ocelot_port *ocelot_port = ocelot->ports[port];
107 INIT_LIST_HEAD(&ocelot_port->skbs);
109 /* Basic L2 initialization */
111 + /* Set MAC IFG Gaps
112 + * FDX: TX_IFG = 5, RX_IFG1 = RX_IFG2 = 0
113 + * !FDX: TX_IFG = 5, RX_IFG1 = RX_IFG2 = 5
115 + ocelot_port_writel(ocelot_port, DEV_MAC_IFG_CFG_TX_IFG(5),
118 + /* Load seed (0) and set MAC HDX late collision */
119 + ocelot_port_writel(ocelot_port, DEV_MAC_HDX_CFG_LATE_COL_POS(67) |
120 + DEV_MAC_HDX_CFG_SEED_LOAD,
123 + ocelot_port_writel(ocelot_port, DEV_MAC_HDX_CFG_LATE_COL_POS(67),
126 + /* Set Max Length and maximum tags allowed */
127 + ocelot_port_writel(ocelot_port, VLAN_ETH_FRAME_LEN,
128 + DEV_MAC_MAXLEN_CFG);
129 + ocelot_port_writel(ocelot_port, DEV_MAC_TAGS_CFG_TAG_ID(ETH_P_8021AD) |
130 + DEV_MAC_TAGS_CFG_VLAN_AWR_ENA |
131 + DEV_MAC_TAGS_CFG_VLAN_LEN_AWR_ENA,
134 + /* Set SMAC of Pause frame (00:00:00:00:00:00) */
135 + ocelot_port_writel(ocelot_port, 0, DEV_MAC_FC_MAC_HIGH_CFG);
136 + ocelot_port_writel(ocelot_port, 0, DEV_MAC_FC_MAC_LOW_CFG);
138 + /* Set Pause WM hysteresis
139 + * 152 = 6 * VLAN_ETH_FRAME_LEN / OCELOT_BUFFER_CELL_SZ
140 + * 101 = 4 * VLAN_ETH_FRAME_LEN / OCELOT_BUFFER_CELL_SZ
142 + ocelot_write_rix(ocelot, SYS_PAUSE_CFG_PAUSE_ENA |
143 + SYS_PAUSE_CFG_PAUSE_STOP(101) |
144 + SYS_PAUSE_CFG_PAUSE_START(152), SYS_PAUSE_CFG, port);
146 + /* Tail dropping watermark */
147 + atop_wm = (ocelot->shared_queue_sz - 9 * VLAN_ETH_FRAME_LEN) / OCELOT_BUFFER_CELL_SZ;
148 + ocelot_write_rix(ocelot, ocelot_wm_enc(9 * VLAN_ETH_FRAME_LEN),
150 + ocelot_write(ocelot, ocelot_wm_enc(atop_wm), SYS_ATOP_TOT_CFG);
152 /* Drop frames with multicast source address */
153 ocelot_rmw_gix(ocelot, ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA,
154 ANA_PORT_DROP_CFG_DROP_MC_SMAC_ENA,