net: enetc: fix wrong TPID registers and remove dead branch
Wei Fang
maintainerPATCH 1/1 net: enetc: fix wrong TPID registers and remove dead branch
Both PF and VF have rx-vlan-offload enabled, however, the PCVLANR1/2 registers are resources controlled by PF, so VF cannot access these two registers. Fortunately, the hardware provides SICVLANR1/2 registers for each SI to reflect the value of PCVLANR1/2 registers. Therefore, use SICVLANR1/2 instead of PCVLANR1/2.
In addition, since ENETC_RXBD_FLAG_TPID is defined as GENMASK(1, 0), the possible values are only 0, 1, 2, 3, so the default branch will never be true, so remove the default branch.
--- drivers/net/ethernet/freescale/enetc/enetc.c | 12 +++++------- drivers/net/ethernet/freescale/enetc/enetc_hw.h | 5 +++-- 2 files changed, 8 insertions(+), 9 deletions(-)
drivers/net/ethernet/freescale/enetc/enetc.c +5 -7
@@ -1375,6 +1375,7 @@ static void enetc_get_offloads(struct enetc_bdr *rx_ring, }if (le16_to_cpu (rxbd->r.flags) &ENETC_RXBD_FLAG_VLAN ) { +struct enetc_hw *hw = &priv->si->hw;__be16 tpid =0 ;switch (le16_to_cpu (rxbd->r.flags) &ENETC_RXBD_FLAG_TPID ) {
@@ -1385,15 +1386,12 @@ static void enetc_get_offloads(struct enetc_bdr *rx_ring, tpid =htons (ETH_P_8021AD );break ;case 2 : - tpid =htons (enetc_port_rd (&priv->si->hw, -ENETC_PCVLANR1 )); + tpid =htons (enetc_rd_hot (hw,ENETC_SICVLANR1 ) & +SICVLANR_ETYPE );break ;case 3 : - tpid =htons (enetc_port_rd (&priv->si->hw, -ENETC_PCVLANR2 )); -break ; -default : -break ; + tpid =htons (enetc_rd_hot (hw,ENETC_SICVLANR2 ) & +SICVLANR_ETYPE ); }__vlan_hwaccel_put_tag (skb, tpid,le16_to_cpu (rxbd->r.vlan_opt));
drivers/net/ethernet/freescale/enetc/enetc_hw.h +3 -2
@@ -43,6 +43,9 @@#define ENETC_SIPMAR0 0x80#define ENETC_SIPMAR1 0x84 +#define ENETC_SICVLANR1 0x90 +#define ENETC_SICVLANR2 0x94 +#define SICVLANR_ETYPE GENMASK(15, 0)/* VF-PF Message passing */ #define ENETC_DEFAULT_MSG_SIZE 1024/* and max size */
@@ -178,8 +181,6 @@ enum enetc_bdr_type {TX, RX};#define ENETC_PSIPMAR0 (n) (0x0100 + (n) * 0x8)/* n = SI index */ #define ENETC_PSIPMAR1 (n) (0x0104 + (n) * 0x8)#define ENETC_PVCLCTR 0x0208 -#define ENETC_PCVLANR1 0x0210 -#define ENETC_PCVLANR2 0x0214#define ENETC_VLAN_TYPE_C BIT(0)#define ENETC_VLAN_TYPE_S BIT(1)#define ENETC_PVCLCTR_OVTPIDL (bmp) ((bmp) & 0xff)/* VLAN_TYPE */
Signature · 1 line
2.34.1
Vladimir Oltean
maintainerHi Wei,
Quoted 6 lines · Wei Fang
Both PF and VF have rx-vlan-offload enabled, however, the PCVLANR1/2 registers are resources controlled by PF, so VF cannot access these two registers. Fortunately, the hardware provides SICVLANR1/2 registers for each SI to reflect the value of PCVLANR1/2 registers. Therefore, use SICVLANR1/2 instead of PCVLANR1/2.
Quoted 6 lines
In addition, since
ENETC_RXBD_FLAG_TPIDis defined asGENMASK(1, 0), the possible values are only 0, 1, 2, 3, so the default branch will never be true, so remove the default branch.Fixes 827b6fd04651 ("net: enetc: fix incorrect TPID when receiving 802.1ad tagged packets")Signed-off-by Wei Fang <[email protected]>
I see what the patch is trying to do, but how did you test/reproduce this? The CVLANR1/CVLANR2 registers are by default zero, and the driver doesn't write them, so I guess custom TPID values are never recognized in net-next. In such situations, I believe fixing a bug that has no consequences should also be considered net-next material (and net-next is currently closed until June 8th).
Quoted 52 lines
--- drivers/net/ethernet/freescale/enetc/enetc.c | 12 +++++------- drivers/net/ethernet/freescale/enetc/enetc_hw.h | 5 +++-- 2 files changed, 8 insertions(+), 9 deletions(-)drivers/net/ethernet/freescale/enetc/enetc.c +5
-7@@ -1375,6 +1375,7 @@ static void enetc_get_offloads(struct enetc_bdr *rx_ring, }if (le16_to_cpu (rxbd->r.flags) &ENETC_RXBD_FLAG_VLAN ) { +struct enetc_hw *hw = &priv->si->hw;__be16 tpid =0 ;switch (le16_to_cpu (rxbd->r.flags) &ENETC_RXBD_FLAG_TPID ) {@@ -1385,15 +1386,12 @@ static void enetc_get_offloads(struct enetc_bdr *rx_ring, tpid =htons (ETH_P_8021AD );break ;case 2 : - tpid =htons (enetc_port_rd (&priv->si->hw, -ENETC_PCVLANR1 )); + tpid =htons (enetc_rd_hot (hw,ENETC_SICVLANR1 ) & +SICVLANR_ETYPE );break ;case 3 : - tpid =htons (enetc_port_rd (&priv->si->hw, -ENETC_PCVLANR2 )); -break ; -default : -break ; + tpid =htons (enetc_rd_hot (hw,ENETC_SICVLANR2 ) & +SICVLANR_ETYPE ); }__vlan_hwaccel_put_tag (skb, tpid,le16_to_cpu (rxbd->r.vlan_opt));drivers/net/ethernet/freescale/enetc/enetc_hw.h +3
-0@@ -43,6 +43,9 @@#define ENETC_SIPMAR0 0x80#define ENETC_SIPMAR1 0x84 +#define ENETC_SICVLANR1 0x90 +#define ENETC_SICVLANR2 0x94 +#define SICVLANR_ETYPE GENMASK(15, 0)/* VF-PF Message passing */ #define ENETC_DEFAULT_MSG_SIZE 1024/* and max size */
drivers/net/ethernet/freescale/enetc/enetc_hw.h enum enetc_bdr_type {TX, RX}; · line 182
Quoted 5 lines
drivers/net/ethernet/freescale/enetc/enetc_hw.h +0
-2@@ -178,8 +181,6 @@ enum enetc_bdr_type {TX, RX};#define ENETC_PSIPMAR0 (n) (0x0100 + (n) * 0x8)/* n = SI index */ #define ENETC_PSIPMAR1 (n) (0x0104 + (n) * 0x8)#define ENETC_PVCLCTR 0x0208 -#define ENETC_PCVLANR1 0x0210 -#define ENETC_PCVLANR2 0x0214
I think you can leave these definitions in place. They will be useful if we ever add support for custom TPIDs. Having the definitions doesn't increase the compiled driver footprint in any way.
Quoted 6 lines
drivers/net/ethernet/freescale/enetc/enetc_hw.h +0
-0#define ENETC_VLAN_TYPE_C BIT(0)#define ENETC_VLAN_TYPE_S BIT(1)#define ENETC_PVCLCTR_OVTPIDL (bmp) ((bmp) & 0xff)/* VLAN_TYPE */ Signature · 1 line
2.34.1
Wei Fang
maintainerQuoted 6 lines
Quoted 5 lines
In addition, since
ENETC_RXBD_FLAG_TPIDis defined asGENMASK(1, 0), the possible values are only 0, 1, 2, 3, so the default branch will never be true, so remove the default branch.Fixes 827b6fd04651 ("net: enetc: fix incorrect TPID when receiving 802.1adtagged packets")
Quoted 9 lines
Quoted 1 line
Signed-off-by Wei Fang <[email protected]>I see what the patch is trying to do, but how did you test/reproduce this? The CVLANR1/CVLANR2 registers are by default zero, and the driver doesn't write them, so I guess custom TPID values are never recognized in net-next. In such situations, I believe fixing a bug that has no consequences should also be considered net-next material (and net-next is currently closed until June 8th).
This issue cannot be reproduced because, as you said, the current driver does not support custom TPID, so the issue will not be triggered in actual use. However, from the perspective of code and combined with hardware, this is problematic.
I agree with you, because it does not fix the issue in actual use, this patch can also be submitted to the net-next tree as an optimization.