netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH resend] sky2: Account for VLAN tag in tx_le_req
@ 2009-09-13 23:07 Mike McCormack
  2009-09-14 16:12 ` [PATCH alt] sky2: transmit ring accounting Stephen Hemminger
  0 siblings, 1 reply; 3+ messages in thread
From: Mike McCormack @ 2009-09-13 23:07 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev

With VLAN enabled, tx_le_req could return fewer list elements than required,
 leading to a potential wrap around of the transmit ring buffer.

Signed-off-by: Mike McCormack <mikem@ring3k.org>
---
 drivers/net/sky2.c |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/net/sky2.c b/drivers/net/sky2.c
index 00bc65a..c8ebc03 100644
--- a/drivers/net/sky2.c
+++ b/drivers/net/sky2.c
@@ -1563,7 +1563,7 @@ static inline int tx_avail(const struct sky2_port *sky2)
 }
 
 /* Estimate of number of transmit list elements required */
-static unsigned tx_le_req(const struct sk_buff *skb)
+static unsigned tx_le_req(const struct sk_buff *skb, int vlan_tag)
 {
 	unsigned count;
 
@@ -1573,6 +1573,9 @@ static unsigned tx_le_req(const struct sk_buff *skb)
 	if (skb_is_gso(skb))
 		++count;
 
+	else if (sizeof(dma_addr_t) == sizeof(u32) && vlan_tag)
+		++count;
+
 	if (skb->ip_summed == CHECKSUM_PARTIAL)
 		++count;
 
@@ -1611,8 +1614,13 @@ static netdev_tx_t sky2_xmit_frame(struct sk_buff *skb,
 	u16 slot;
 	u16 mss;
 	u8 ctrl;
+	unsigned vlan_tag = 0;
+
+#ifdef SKY2_VLAN_TAG_USED
+	vlan_tag = sky2->vlgrp && vlan_tx_tag_present(skb);
+#endif
 
- 	if (unlikely(tx_avail(sky2) < tx_le_req(skb)))
+ 	if (unlikely(tx_avail(sky2) < tx_le_req(skb, vlan_tag)))
   		return NETDEV_TX_BUSY;
 
 	len = skb_headlen(skb);
@@ -1657,7 +1665,7 @@ static netdev_tx_t sky2_xmit_frame(struct sk_buff *skb,
 	ctrl = 0;
 #ifdef SKY2_VLAN_TAG_USED
 	/* Add VLAN tag, can piggyback on LRGLEN or ADDR64 */
-	if (sky2->vlgrp && vlan_tx_tag_present(skb)) {
+	if (vlan_tag) {
 		if (!le) {
 			le = get_tx_le(sky2, &slot);
 			le->addr = 0;
-- 
1.5.6.5



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH alt] sky2: transmit ring accounting
  2009-09-13 23:07 [PATCH resend] sky2: Account for VLAN tag in tx_le_req Mike McCormack
@ 2009-09-14 16:12 ` Stephen Hemminger
  2009-09-15  9:50   ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2009-09-14 16:12 UTC (permalink / raw)
  To: Mike McCormack, David Miller; +Cc: netdev

Be more accurate about number of transmit list elements required.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

---
Note: this is an optimization, the old code guaranteed more space
than necessary (MAX_SKB_TX_LE was always bigger than needed).

--- a/drivers/net/sky2.c	2009-09-14 08:45:55.730729606 -0700
+++ b/drivers/net/sky2.c	2009-09-14 09:09:42.395712810 -0700
@@ -65,8 +65,8 @@
 #define RX_DEF_PENDING		RX_MAX_PENDING
 
 /* This is the worst case number of transmit list elements for a single skb:
-   VLAN + TSO + CKSUM + Data + skb_frags * DMA */
-#define MAX_SKB_TX_LE	(4 + (sizeof(dma_addr_t)/sizeof(u32))*MAX_SKB_FRAGS)
+   VLAN:GSO + CKSUM + Data + skb_frags * DMA */
+#define MAX_SKB_TX_LE	(2 + (sizeof(dma_addr_t)/sizeof(u32))*(MAX_SKB_FRAGS+1))
 #define TX_MIN_PENDING		(MAX_SKB_TX_LE+1)
 #define TX_MAX_PENDING		4096
 #define TX_DEF_PENDING		127
@@ -1567,11 +1567,13 @@ static unsigned tx_le_req(const struct s
 {
 	unsigned count;
 
-	count = sizeof(dma_addr_t) / sizeof(u32);
-	count += skb_shinfo(skb)->nr_frags * count;
+	count = (skb_shinfo(skb)->nr_frags + 1)
+		* (sizeof(dma_addr_t) / sizeof(u32));
 
 	if (skb_is_gso(skb))
 		++count;
+	else if (sizeof(dma_addr_t) == sizeof(u32))
+		++count;	/* possible vlan */
 
 	if (skb->ip_summed == CHECKSUM_PARTIAL)
 		++count;

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH alt] sky2: transmit ring accounting
  2009-09-14 16:12 ` [PATCH alt] sky2: transmit ring accounting Stephen Hemminger
@ 2009-09-15  9:50   ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2009-09-15  9:50 UTC (permalink / raw)
  To: shemminger; +Cc: mikem, netdev

From: Stephen Hemminger <shemminger@linux-foundation.org>
Date: Mon, 14 Sep 2009 09:12:55 -0700

> Be more accurate about number of transmit list elements required.
> 
> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>

Applied.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2009-09-15  9:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-09-13 23:07 [PATCH resend] sky2: Account for VLAN tag in tx_le_req Mike McCormack
2009-09-14 16:12 ` [PATCH alt] sky2: transmit ring accounting Stephen Hemminger
2009-09-15  9:50   ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).