Subject: Re: gsip sends byte-swapped vlan tags
To: None <tech-net@netbsd.org>
From: Pavel Cahyna <pcah8322@artax.karlin.mff.cuni.cz>
List: tech-net
Date: 01/24/2006 18:15:02
On Tue, Jan 24, 2006 at 05:35:18PM +0100, Pavel Cahyna wrote:
> Hello,
> 
> I have tried a gigabit card with the gsip driver and a tagged VLAN. When
> this did not work, I discovered that the VLAN tag is sent byte-swapped. If
> I configure it as 4, I see 1024 on the wire. If I configure 1024, I see 4.
> If I configure 2, I see 512.
> 
> This is on i386 with 3.0.
> 
> This quick patch seems to fix it, but probably is still not right for BE
> machines, where the value will be initially correct, but then swapped by
> htole32. Any better idea? Maybe use bswap16 instead of htons?

I can confirm that using bswap16 makes it send correct tag from a BE
machine (sgimips). To correctly receive tags, it is necessary to change
another already existing ntohs to bswap16. Then the tagged VLAN work
correctly. This final patch is below.

Pavel Cahyna

Index: if_sip.c
===================================================================
RCS file: /cvsroot/src/sys/dev/pci/if_sip.c,v
retrieving revision 1.101
diff -u -r1.101 if_sip.c
--- if_sip.c	27 Feb 2005 00:27:33 -0000	1.101
+++ if_sip.c	24 Jan 2006 17:13:50 -0000
@@ -1357,7 +1357,7 @@
 		if ((mtag = VLAN_OUTPUT_TAG(&sc->sc_ethercom, m0)) != NULL) {
 			sc->sc_txdescs[lasttx].sipd_extsts |=
 			    htole32(EXTSTS_VPKT |
-				    (VLAN_TAG_VALUE(mtag) & EXTSTS_VTCI));
+				    (bswap16(VLAN_TAG_VALUE(mtag)) & EXTSTS_VTCI));
 		}
 
 		/*
@@ -1970,7 +1970,7 @@
 		 * for us.  Associate the tag with the packet.
 		 */
 		if ((extsts & EXTSTS_VPKT) != 0) {
-			VLAN_INPUT_TAG(ifp, m, ntohs(extsts & EXTSTS_VTCI),
+			VLAN_INPUT_TAG(ifp, m, bswap16(extsts & EXTSTS_VTCI),
 			    continue);
 		}