Skip to contentSkip to conversation

mv643xx: fix byte order when checksum offload is enabled

PATCH In review Byron Bradley 3 participants 5 messages Jan 19, 2008 – Jan 20, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mv643xx: fix byte order when checksum offload is enabled

The Marvell Orion system on chips have an integrated mv643xx MAC. On these little endian ARM devices mv643xx will oops when checksum offload is enabled. Swapping the byte order of the protocol and checksum solves this problem.

Cc Dale Farnsworth <[email protected]>
Cc Manish Lachwani <[email protected]>
Cc Tzachi Perelstein <[email protected]>

---

This patch has only been tested on two Marvell Orion based boards so it should be considered only very lightly tested. It applies against 2.6.24-rc8-mm1.

 drivers/net/mv643xx_eth.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/mv643xx_eth.c +3 -3
index 651c269..5d16a5d 100644
@@ -1689,7 +1689,7 @@ static void eth_tx_submit_descs_for_skb(struct mv643xx_private *mp,
 	desc->buf_ptr = dma_map_single(NULL, skb->data, length, DMA_TO_DEVICE);
 
 	if (skb->ip_summed == CHECKSUM_PARTIAL) {
-		BUG_ON(skb->protocol != ETH_P_IP);
+		BUG_ON(skb->protocol != htons(ETH_P_IP));
 
 		cmd_sts |= ETH_GEN_TCP_UDP_CHECKSUM |
 			   ETH_GEN_IP_V_4_CHECKSUM  |
@@ -1698,10 +1698,10 @@ static void eth_tx_submit_descs_for_skb(struct mv643xx_private *mp,
 		switch (ip_hdr(skb)->protocol) {
 		case IPPROTO_UDP:
 			cmd_sts |= ETH_UDP_FRAME;
-			desc->l4i_chk = udp_hdr(skb)->check;
+			desc->l4i_chk = htons(udp_hdr(skb)->check);
 			break;
 		case IPPROTO_TCP:
-			desc->l4i_chk = tcp_hdr(skb)->check;
+			desc->l4i_chk = htons(tcp_hdr(skb)->check);
 			break;
 		default:
 			BUG();
Signature · 1 line
1.5.4.rc2.38.gd6da3
#1 lore raw

drivers/net/mv643xx_eth.c static void eth_tx_submit_descs_for_skb(struct mv643xx_private *mp, · line 1705

Quoted 9 lines · Byron Bradley
drivers/net/mv643xx_eth.c +2 -2
 		case IPPROTO_UDP:
 			cmd_sts |= ETH_UDP_FRAME;
-			desc->l4i_chk = udp_hdr(skb)->check;
+			desc->l4i_chk = htons(udp_hdr(skb)->check);
 			break;
 		case IPPROTO_TCP:
-			desc->l4i_chk = tcp_hdr(skb)->check;
+			desc->l4i_chk = htons(tcp_hdr(skb)->check);
 			break;

The first part was OK, but this one... AFAICS, the sucker byteswaps 64bit words in descriptors wholesale, right? Then the right way to spell that would be ntohs((__force __be16)....->check).

What's happening here is that we take a fixed-endian (checksum) and then correct for conversion done in hardware - i.e. we store it in something that expects a _host_-endian value and would convert that to fixed-endian. So we need to counter that correction and that's where the damn thing is coming from.

It's not particulary rare - drivers that do hardware byteswap tend to need it. For now I'd suggest explicit form (with force-cast from __csum to __be16 and ntohs() on top of it); if anybody has good ideas for helper names, though... csum_as_le() and csum_as_be(), perhaps? Interpret __csum (fixed-endian) and another fixed-endian type, with proper checks; i.e. something along the lines of
static inline __be16 csum_as_be(__csum sum)

{
	return (__force __be16)sum;
}

and this stuff becoming ntohs(csum_as_be(udp_hdr(skb)->check)), etc.

#3 lore raw

PATCH 1/1 mv643xx_eth: fix byte order when checksum offload is enabled

In reply to Byron Bradley

From: Byron Bradley <[email protected]>

The Marvell Orion system on chips have an integrated mv643xx MAC. On these little endian ARM devices mv643xx will oops when checksum offload is enabled. Swapping the byte order of the protocol and checksum solves this problem.

Cc Manish Lachwani <[email protected]>
Cc Tzachi Perelstein <[email protected]>

---

Quoted 3 lines · Byron Bradley

This patch has only been tested on two Marvell Orion based boards so it should be considered only very lightly tested. It applies against 2.6.24-rc8-mm1.

Dale Farnsworth:
Looks good to me and I successfully booted it on a big-endian prpmc2800 board.

Jeff, please pick this up. My mv643xx queue is otherwise empty.

Thanks,
-Dale

 drivers/net/mv643xx_eth.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/mv643xx_eth.c +3 -3
index 651c269..5d16a5d 100644
@@ -1689,7 +1689,7 @@ static void eth_tx_submit_descs_for_skb(struct mv643xx_private *mp,
 	desc->buf_ptr = dma_map_single(NULL, skb->data, length, DMA_TO_DEVICE);
 
 	if (skb->ip_summed == CHECKSUM_PARTIAL) {
-		BUG_ON(skb->protocol != ETH_P_IP);
+		BUG_ON(skb->protocol != htons(ETH_P_IP));
 
 		cmd_sts |= ETH_GEN_TCP_UDP_CHECKSUM |
 			   ETH_GEN_IP_V_4_CHECKSUM  |
@@ -1698,10 +1698,10 @@ static void eth_tx_submit_descs_for_skb(struct mv643xx_private *mp,
 		switch (ip_hdr(skb)->protocol) {
 		case IPPROTO_UDP:
 			cmd_sts |= ETH_UDP_FRAME;
-			desc->l4i_chk = udp_hdr(skb)->check;
+			desc->l4i_chk = htons(udp_hdr(skb)->check);
 			break;
 		case IPPROTO_TCP:
-			desc->l4i_chk = tcp_hdr(skb)->check;
+			desc->l4i_chk = htons(tcp_hdr(skb)->check);
 			break;
 		default:
 			BUG();
Signature · 1 line
1.5.4.rc2.38.gd6da3
#4 lore raw

Re: [PATCH] mv643xx_eth: fix byte order when checksum offload is enabled

OK, after digesting Al Viro's comments on this, I agree with him and retract this. These multiple byte swaps sure are confusing.

Byron, would you please resubmit?

Thanks,
-Dale

Quoted 60 lines · Dale Farnsworth

From: Byron Bradley <[email protected]>

The Marvell Orion system on chips have an integrated mv643xx MAC. On these little endian ARM devices mv643xx will oops when checksum offload is enabled. Swapping the byte order of the protocol and checksum solves this problem.

Cc Manish Lachwani <[email protected]>
Cc Tzachi Perelstein <[email protected]>

---

Quoted 3 lines · Byron Bradley

This patch has only been tested on two Marvell Orion based boards so it should be considered only very lightly tested. It applies against 2.6.24-rc8-mm1.

Dale Farnsworth:
Looks good to me and I successfully booted it on a big-endian prpmc2800 board.

Jeff, please pick this up. My mv643xx queue is otherwise empty.

Thanks,

(quoted diff) +0 -1
-Dale
 
 drivers/net/mv643xx_eth.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
drivers/net/mv643xx_eth.c +3 -3
index 651c269..5d16a5d 100644
@@ -1689,7 +1689,7 @@ static void eth_tx_submit_descs_for_skb(struct mv643xx_private *mp,
 	desc->buf_ptr = dma_map_single(NULL, skb->data, length, DMA_TO_DEVICE);
 
 	if (skb->ip_summed == CHECKSUM_PARTIAL) {
-		BUG_ON(skb->protocol != ETH_P_IP);
+		BUG_ON(skb->protocol != htons(ETH_P_IP));
 
 		cmd_sts |= ETH_GEN_TCP_UDP_CHECKSUM |
 			   ETH_GEN_IP_V_4_CHECKSUM  |
@@ -1698,10 +1698,10 @@ static void eth_tx_submit_descs_for_skb(struct mv643xx_private *mp,
 		switch (ip_hdr(skb)->protocol) {
 		case IPPROTO_UDP:
 			cmd_sts |= ETH_UDP_FRAME;
-			desc->l4i_chk = udp_hdr(skb)->check;
+			desc->l4i_chk = htons(udp_hdr(skb)->check);
 			break;
 		case IPPROTO_TCP:
-			desc->l4i_chk = tcp_hdr(skb)->check;
+			desc->l4i_chk = htons(tcp_hdr(skb)->check);
 			break;
 		default:
 			BUG();
Signature · 1 line
1.5.4.rc2.38.gd6da3
#2 lore raw

Re: [PATCH] mv643xx_eth: fix byte order when checksum offload is enabled

In reply to Al Viro

The Marvell Orion system on chips have an integrated mv643xx MAC. On these little endian ARM devices mv643xx will oops when checksum offload is enabled. Swapping the byte order of the protocol and checksum solves this problem.

Cc Dale Farnsworth <[email protected]>
Cc Manish Lachwani <[email protected]>

---

Resubmitted after comments from Al Viro. udp_hdr(skb)->check returns a __sum16 so I have called the function sum16_as_be(). Again lightly tested only on two Marvell Orion boards.

 drivers/net/mv643xx_eth.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
drivers/net/mv643xx_eth.c +8 -3
index 651c269..b528ce7 100644
@@ -1652,6 +1652,11 @@ static void eth_tx_fill_frag_descs(struct mv643xx_private *mp,
 	}
 }
 
+static inline __be16 sum16_as_be(__sum16 sum)
+{
+	return (__force __be16)sum;
+}
+
 /**
  * eth_tx_submit_descs_for_skb - submit data from an skb to the tx hw
  *
@@ -1689,7 +1694,7 @@ static void eth_tx_submit_descs_for_skb(struct mv643xx_private *mp,
 	desc->buf_ptr = dma_map_single(NULL, skb->data, length, DMA_TO_DEVICE);
 
 	if (skb->ip_summed == CHECKSUM_PARTIAL) {
-		BUG_ON(skb->protocol != ETH_P_IP);
+		BUG_ON(skb->protocol != htons(ETH_P_IP));
 
 		cmd_sts |= ETH_GEN_TCP_UDP_CHECKSUM |
 			   ETH_GEN_IP_V_4_CHECKSUM  |
@@ -1698,10 +1703,10 @@ static void eth_tx_submit_descs_for_skb(struct mv643xx_private *mp,
 		switch (ip_hdr(skb)->protocol) {
 		case IPPROTO_UDP:
 			cmd_sts |= ETH_UDP_FRAME;
-			desc->l4i_chk = udp_hdr(skb)->check;
+			desc->l4i_chk = ntohs(sum16_as_be(udp_hdr(skb)->check));
 			break;
 		case IPPROTO_TCP:
-			desc->l4i_chk = tcp_hdr(skb)->check;
+			desc->l4i_chk = ntohs(sum16_as_be(tcp_hdr(skb)->check));
 			break;
 		default:
 			BUG();
Signature · 1 line
1.5.4.rc2.38.gd6da3