Skip to contentSkip to conversation

gianfar: Fall back to software tcp/udp checksum on older controllers

PATCH Superseded Alex Dubov 5 participants 8 messages Jan 27, 2011 – Jan 28, 2011

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Alex Dubov

author
#0 lore raw

PATCH 1/1 gianfar: Fall back to software tcp/udp checksum on older controllers

As specified by errata eTSEC49 of MPC8548 and errata eTSEC12 of MPC83xx,=0A= older revisions of gianfar controllers will be unable to calculate a TCP/UD= P=0Apacket checksum for some aligments of the appropriate FCB. This patch c= hecks=0Afor FCB alignment on such controllers and falls back to software ch= ecksumming=0Aif the aligment is known to be bad.=0A=0ASigned-off-by: Alex D= ubov <[email protected]>=0A---=0AThis is my, somewhat different approach to M=
atthew Creech proposed solution.=0A=0A drivers/net/gianfar.c | 21 +++++++=
++++++++++++--=0A drivers/net/gianfar.h | 1 +=0A 2 files changed, 20 ins=
ertions(+), 2 deletions(-)=0A=0Adiff --git a/drivers/net/gianfar.c b/driver= s/net/gianfar.c=0Aindex 5ed8f9f..b4f0e99 100644=0A--- a/drivers/net/gianfar= .c=0A+++ b/drivers/net/gianfar.c=0A@@ -950,6 +950,11 @@ static void gfar_de= tect_errata(struct gfar_private *priv)=0A =09=09=09(pvr =3D=3D 0x80861010 &= & (mod & 0xfff9) =3D=3D 0x80c0))=0A =09=09priv->errata |=3D GFAR_ERRATA_A00= 2;=0A =0A+=09/* MPC8313 Rev < 2.0, MPC8548 rev 2.0 */=0A+=09if ((pvr =3D=3D=
0x80850010 && mod =3D=3D 0x80b0 && rev < 0x0020)=0A+=09 || (pvr =3D=3D =
0x80210020 && mod =3D=3D 0x8030 && rev =3D=3D 0x0020))=0A+=09=09priv->errat= a |=3D GFAR_ERRATA_12;=0A+=0A =09if (priv->errata)=0A =09=09dev_info(dev, "= enabled errata workarounds, flags: 0x%x\n",=0A =09=09=09 priv->errata);=0A@= @ -2156,8 +2161,20 @@ static int gfar_start_xmit(struct sk_buff *skb, struc= t net_device *dev)=0A =09/* Set up checksumming */=0A =09if (CHECKSUM_PARTI= AL =3D=3D skb->ip_summed) {=0A =09=09fcb =3D gfar_add_fcb(skb);=0A-=09=09ls= tatus |=3D BD_LFLAG(TXBD_TOE);=0A-=09=09gfar_tx_checksum(skb, fcb);=0A+=09= =09switch (unlikely(gfar_has_errata(priv, GFAR_ERRATA_12))=0A+=09=09=09? 1 = : 0) {=0A+=09=09case 1:=0A+=09=09=09/* as specified by errata */=0A+=09=09= =09if (((unsigned long)fcb % 0x20) > 0x18) { =0A+=09=09=09=09__skb_pull(skb= , GMAC_FCB_LEN);=0A+=09=09=09=09skb_checksum_help(skb);=0A+=09=09=09=09brea= k;=0A+=09=09=09}=0A+=09=09=09/* otherwise, fall through */=0A+=09=09default= :=0A+=09=09=09lstatus |=3D BD_LFLAG(TXBD_TOE);=0A+=09=09=09gfar_tx_checksum= (skb, fcb);=0A+=09=09}=0A =09}=0A =0A =09if (vlan_tx_tag_present(skb)) {=0A=

drivers/net/gianfar.h=0Aindex 54de413.= renamed from drivers/net/gianfar.h +0 -0

.ec5d595 100644=0A--- a/drivers/net/gianfar.h=0A+++ b/drivers/net/gianfar.h= =0A@@ -1039,6 +1039,7 @@ enum gfar_errata {=0A =09GFAR_ERRATA_74=09=09=3D 0= x01,=0A =09GFAR_ERRATA_76=09=09=3D 0x02,=0A =09GFAR_ERRATA_A002=09=3D 0x04,= =0A+=09GFAR_ERRATA_12=09=09=3D 0x08, /* a.k.a errata eTSEC49 */=0A };=0A = =0A /* Struct stolen almost completely (and shamelessly) from the FCC enet = source=0A-- =0A1.7.3.2=0A=0A=0A=0A=0A

#1 lore raw

Hello Alex,

Quoted 19 lines · Alex Dubov

As specified by errata eTSEC49 of MPC8548 and errata eTSEC12 of MPC83xx, older revisions of gianfar controllers will be unable to calculate a TCP/UDP packet checksum for some aligments of the appropriate FCB. This patch checks for FCB alignment on such controllers and falls back to software checksumming if the aligment is known to be bad.

---
This is my, somewhat different approach to Matthew Creech proposed solution.

 drivers/net/gianfar.c |   21 +++++++++++++++++++--
 drivers/net/gianfar.h |    1 +
 2 files changed, 20 insertions(+), 2 deletions(-)
drivers/net/gianfar.c +0 -0
index 5ed8f9f..b4f0e99 100644

drivers/net/gianfar.c static void gfar_detect_errata(struct gfar_private *priv) · line 955

Quoted 6 lines
drivers/net/gianfar.c +3 -0
@@ -950,6 +950,11 @@ static void gfar_detect_errata(struct gfar_private *priv)
 			(pvr == 0x80861010 && (mod & 0xfff9) == 0x80c0))
 		priv->errata |= GFAR_ERRATA_A002;
 
+	/* MPC8313 Rev < 2.0, MPC8548 rev 2.0 */
+	if ((pvr == 0x80850010 && mod == 0x80b0 && rev < 0x0020)
+	    || (pvr == 0x80210020 && mod == 0x8030 && rev == 0x0020))

Please indent it like the above: with two tabs. This is to keep things consistent.

drivers/net/gianfar.c static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev) · line 2165

Quoted 13 lines
drivers/net/gianfar.c +4 -2
+		priv->errata |= GFAR_ERRATA_12;
+
 	if (priv->errata)
 		dev_info(dev, "enabled errata workarounds, flags: 0x%x\n",
 			 priv->errata);
@@ -2156,8 +2161,20 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	/* Set up checksumming */
 	if (CHECKSUM_PARTIAL == skb->ip_summed) {
 		fcb = gfar_add_fcb(skb);
-		lstatus |= BD_LFLAG(TXBD_TOE);
-		gfar_tx_checksum(skb, fcb);
+		switch (unlikely(gfar_has_errata(priv, GFAR_ERRATA_12))
+			? 1 : 0) {

The switch construction is quite bizarre. ;-) Why not

if (gfar_has_errata() && (ulong)fcb % 0x20 > 18) {
	csum_help();
} else {
	lstatus |=...
	tx_csum();
}

?

Thanks,

Quoted 13 lines
drivers/net/gianfar.c +12 -0
+		case 1:
+			/* as specified by errata */
+			if (((unsigned long)fcb % 0x20) > 0x18) { 
+				__skb_pull(skb, GMAC_FCB_LEN);
+				skb_checksum_help(skb);
+				break;
+			}
+			/* otherwise, fall through */
+		default:
+			lstatus |= BD_LFLAG(TXBD_TOE);
+			gfar_tx_checksum(skb, fcb);
+		}
 	}
Signature · 2 lines
Anton Vorontsov
Email: [email protected]
maintainer
#2 lore raw

Please CC: netdev on future submissions of this patch, otherwise I won't see it in my queue.

author
#3 lore raw
In reply to Anton Vorontsov
Quoted 1 line
Quoted 1 line

-=A0=A0=A0 =A0=A0=A0=0A> gfar_tx_checksum(skb, fcb);=0A> > +=A0=A0=A0 =

=A0=A0=A0 switch=0A> (unlikely(gfar_has_errata(priv, GFAR_ERRATA_12))=0A> >=
+=A0=A0=A0 =A0=A0=A0=0A> =A0=A0=A0 ? 1 : 0) {=0A> =0A> The switch construc=
tion is quite bizarre. ;-) Why not=0A> =0A=0AMy testing shows that even on = broken chips unaligned packets are quite rare=0A(only some SYN packets seem=
to be affected). So I tried to leave the=0Achecksum offload path as the mo=
st preferred one.=0A=0A=0A=0A

author
#4 lore raw

PATCH v2 1/1 gianfar: Fall back to software tcp/udp checksum on older controllers

In reply to Anton Vorontsov

As specified by errata eTSEC49 of MPC8548 and errata eTSEC12 of MPC83xx,=0A= older revisions of gianfar controllers will be unable to calculate a TCP/UD= P=0Apacket checksum for some alignments of the appropriate FCB. This patch = checks=0Afor FCB alignment on such controllers and falls back to software c= hecksumming=0Aif the alignment is known to be bad.=0A=0ASigned-off-by: Alex=
Dubov <[email protected]>=0A---=0AChanges for v2:=0A - Make indentation sl=
ightly more consistent.=0A - Replace bizarre switch-based condition with =
plain boring one.=0A=0A drivers/net/gianfar.c | 16 ++++++++++++++--=0A dr=
ivers/net/gianfar.h | 1 +=0A 2 files changed, 15 insertions(+), 2 deleti=
ons(-)=0A=0Adiff --git a/drivers/net/gianfar.c b/drivers/net/gianfar.c=0Ain= dex 5ed8f9f..3da19a5 100644=0A--- a/drivers/net/gianfar.c=0A+++ b/drivers/n= et/gianfar.c=0A@@ -950,6 +950,11 @@ static void gfar_detect_errata(struct g= far_private *priv)=0A =09=09=09(pvr =3D=3D 0x80861010 && (mod & 0xfff9) =3D= =3D 0x80c0))=0A =09=09priv->errata |=3D GFAR_ERRATA_A002;=0A =0A+=09/* MPC8= 313 Rev < 2.0, MPC8548 rev 2.0 */=0A+=09if ((pvr =3D=3D 0x80850010 && mod = =3D=3D 0x80b0 && rev < 0x0020) ||=0A+=09=09=09(pvr =3D=3D 0x80210020 && mod=
=3D=3D 0x8030 && rev =3D=3D 0x0020))=0A+=09=09priv->errata |=3D GFAR_ERRAT=
A_12;=0A+=0A =09if (priv->errata)=0A =09=09dev_info(dev, "enabled errata wo= rkarounds, flags: 0x%x\n",=0A =09=09=09 priv->errata);=0A@@ -2156,8 +2161,1= 5 @@ static int gfar_start_xmit(struct sk_buff *skb, struct net_device *dev= )=0A =09/* Set up checksumming */=0A =09if (CHECKSUM_PARTIAL =3D=3D skb->ip= _summed) {=0A =09=09fcb =3D gfar_add_fcb(skb);=0A-=09=09lstatus |=3D BD_LFL= AG(TXBD_TOE);=0A-=09=09gfar_tx_checksum(skb, fcb);=0A+=09=09/* as specified=
by errata */=0A+=09=09if (unlikely(gfar_has_errata(priv, GFAR_ERRATA_12)=
=0A+=09=09=09 && ((unsigned long)fcb % 0x20) > 0x18)) {=0A+=09=09=09__s=
kb_pull(skb, GMAC_FCB_LEN);=0A+=09=09=09skb_checksum_help(skb);=0A+=09=09} = else {=0A+=09=09=09lstatus |=3D BD_LFLAG(TXBD_TOE);=0A+=09=09=09gfar_tx_che= cksum(skb, fcb);=0A+=09=09}=0A =09}=0A =0A =09if (vlan_tx_tag_present(skb))=
{=0Adiff --git a/drivers/net/gianfar.h b/drivers/net/gianfar.h=0Aindex 54d=
e413..ec5d595 100644=0A--- a/drivers/net/gianfar.h=0A+++ b/drivers/net/gian= far.h=0A@@ -1039,6 +1039,7 @@ enum gfar_errata {=0A =09GFAR_ERRATA_74=09=09= =3D 0x01,=0A =09GFAR_ERRATA_76=09=09=3D 0x02,=0A =09GFAR_ERRATA_A002=09=3D = 0x04,=0A+=09GFAR_ERRATA_12=09=09=3D 0x08, /* a.k.a errata eTSEC49 */=0A };= =0A =0A /* Struct stolen almost completely (and shamelessly) from the FCC e= net source=0A-- =0A1.7.3.2=0A=0A=0A=0A=0A

#5 lore raw

RE: [PATCH v2] gianfar: Fall back to software tcp/udp checksum on oldercontrollers

Review

Quoted 3 lines
(quoted diff) +2 -0
+		if (unlikely(gfar_has_errata(priv, GFAR_ERRATA_12)
+			     && ((unsigned long)fcb % 0x20) > 0x18)) {

You need to check the generated code, but I think you need:

if (unlikely(gfar_has_errata(priv, GFAR_ERRATA_12))
&& unlikely(((unsigned long)fcb % 0x20) > 0x18))

ie unlikely() around both the primitive comparisons.

David

#6 lore raw

Re: [PATCH v2] gianfar: Fall back to software tcp/udp checksum on oldercontrollers

Quoted 10 lines · On Fri, 28 Jan 2011 09:10:46 +0000 David Laight <[email protected]> wrote:

Review

Quoted 3 lines
(quoted diff) +2 -0
+		if (unlikely(gfar_has_errata(priv, GFAR_ERRATA_12)
+			     && ((unsigned long)fcb % 0x20) > 0x18)) {

You need to check the generated code, but I think you need:

if (unlikely(gfar_has_errata(priv, GFAR_ERRATA_12))
&& unlikely(((unsigned long)fcb % 0x20) > 0x18))

ie unlikely() around both the primitive comparisons.

Is the first condition actually unlikely? If you've got affected hardware, you'll hit it every time.

If packets with the problematic alignment are rare, seems like it'd be better to check that first.

-Scott

maintainer
#7 lore raw

Re: [PATCH v2] gianfar: Fall back to software tcp/udp checksum on oldercontrollers

From: Scott Wood <[email protected]>
Date: Fri, 28 Jan 2011 10:56:10 -0600

Quoted 12 lines
Quoted 9 lines · On Fri, 28 Jan 2011 09:10:46 +0000 David Laight <[email protected]> wrote:

Review

Quoted 3 lines
(quoted diff) +2 -0
+		if (unlikely(gfar_has_errata(priv, GFAR_ERRATA_12)
+			     && ((unsigned long)fcb % 0x20) > 0x18)) {

You need to check the generated code, but I think you need:

if (unlikely(gfar_has_errata(priv, GFAR_ERRATA_12))
&& unlikely(((unsigned long)fcb % 0x20) > 0x18))

Quoted 7 lines
Quoted 1 line

ie unlikely() around both the primitive comparisons.

Is the first condition actually unlikely? If you've got affected hardware, you'll hit it every time.

If packets with the problematic alignment are rare, seems like it'd be better to check that first.

In cases like this gfar_has_errata() case, better to leave it's likelyhood unmarked.

And yes, since it's cheaper, checking the alignment should be done first.