Patchwork [07/21] net: lib82596: use common rx_copybreak handling [strict refill!]

login
register
mail settings
Submitter Michał Mirosław
Date July 9, 2011, 5:17 p.m.
Message ID <041aed2721ea22ee6e7d122c3c21a59b4042f431.1310229312.git.mirq-linux@rere.qmqm.pl>
Download mbox | patch
Permalink /patch/104007/
State Superseded
Delegated to: David Miller
Headers show

Comments

Michał Mirosław - July 9, 2011, 5:17 p.m.
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 drivers/net/lib82596.c |   66 ++++++++++-------------------------------------
 1 files changed, 14 insertions(+), 52 deletions(-)
françois romieu - July 9, 2011, 10:25 p.m.
Michał Mirosław <mirq-linux@rere.qmqm.pl> :
[...]
> diff --git a/drivers/net/lib82596.c b/drivers/net/lib82596.c
> index 9e04289..d19e05b 100644
> --- a/drivers/net/lib82596.c
> +++ b/drivers/net/lib82596.c
> @@ -679,67 +679,29 @@ static inline int i596_rx(struct net_device *dev)
>  		if (rbd != NULL && (rfd->stat & SWAP16(STAT_OK))) {
>  			/* a good frame */
>  			int pkt_len = SWAP16(rbd->count) & 0x3fff;
> -			struct sk_buff *skb = rbd->skb;
> -			int rx_in_place = 0;
> +			struct sk_buff *skb;
> +			dma_addr_t dma_addr;
>  
>  			DEB(DEB_RXADDR, print_eth(rbd->v_data, "received"));
>  			frames++;
>  
> -			/* Check if the packet is long enough to just accept
> -			 * without copying to a properly sized skbuff.
> -			 */
> +			dma_addr = SWAP32(rbd->b_data);
> +			skb = dev_skb_finish_rx_dma_refill(&rbd->skb,
> +				pkt_len, rx_copybreak, NET_IP_ALIGN, 0,
> +				dev->dev.parent, &dma_addr, PKT_BUF_SZ);
[...]
> +			if (likely(skb)) {

s/skb/rbd->skb/

Patch

diff --git a/drivers/net/lib82596.c b/drivers/net/lib82596.c
index 9e04289..d19e05b 100644
--- a/drivers/net/lib82596.c
+++ b/drivers/net/lib82596.c
@@ -679,67 +679,29 @@  static inline int i596_rx(struct net_device *dev)
 		if (rbd != NULL && (rfd->stat & SWAP16(STAT_OK))) {
 			/* a good frame */
 			int pkt_len = SWAP16(rbd->count) & 0x3fff;
-			struct sk_buff *skb = rbd->skb;
-			int rx_in_place = 0;
+			struct sk_buff *skb;
+			dma_addr_t dma_addr;
 
 			DEB(DEB_RXADDR, print_eth(rbd->v_data, "received"));
 			frames++;
 
-			/* Check if the packet is long enough to just accept
-			 * without copying to a properly sized skbuff.
-			 */
+			dma_addr = SWAP32(rbd->b_data);
+			skb = dev_skb_finish_rx_dma_refill(&rbd->skb,
+				pkt_len, rx_copybreak, NET_IP_ALIGN, 0,
+				dev->dev.parent, &dma_addr, PKT_BUF_SZ);
+			rbd->v_data = rbd->skb->data;
+			rbd->b_data = SWAP32(dma_addr);
+			DMA_WBACK_INV(dev, rbd, sizeof(struct i596_rbd));
 
-			if (pkt_len > rx_copybreak) {
-				struct sk_buff *newskb;
-				dma_addr_t dma_addr;
-
-				dma_unmap_single(dev->dev.parent,
-						 (dma_addr_t)SWAP32(rbd->b_data),
-						 PKT_BUF_SZ, DMA_FROM_DEVICE);
-				/* Get fresh skbuff to replace filled one. */
-				newskb = netdev_alloc_skb_ip_align(dev,
-								   PKT_BUF_SZ);
-				if (newskb == NULL) {
-					skb = NULL;	/* drop pkt */
-					goto memory_squeeze;
-				}
-
-				/* Pass up the skb already on the Rx ring. */
-				skb_put(skb, pkt_len);
-				rx_in_place = 1;
-				rbd->skb = newskb;
-				dma_addr = dma_map_single(dev->dev.parent,
-							  newskb->data,
-							  PKT_BUF_SZ,
-							  DMA_FROM_DEVICE);
-				rbd->v_data = newskb->data;
-				rbd->b_data = SWAP32(dma_addr);
-				DMA_WBACK_INV(dev, rbd, sizeof(struct i596_rbd));
-			} else
-				skb = netdev_alloc_skb_ip_align(dev, pkt_len);
-memory_squeeze:
-			if (skb == NULL) {
-				/* XXX tulip.c can defer packets here!! */
-				printk(KERN_ERR
-				       "%s: i596_rx Memory squeeze, dropping packet.\n",
-				       dev->name);
-				dev->stats.rx_dropped++;
-			} else {
-				if (!rx_in_place) {
-					/* 16 byte align the data fields */
-					dma_sync_single_for_cpu(dev->dev.parent,
-								(dma_addr_t)SWAP32(rbd->b_data),
-								PKT_BUF_SZ, DMA_FROM_DEVICE);
-					memcpy(skb_put(skb, pkt_len), rbd->v_data, pkt_len);
-					dma_sync_single_for_device(dev->dev.parent,
-								   (dma_addr_t)SWAP32(rbd->b_data),
-								   PKT_BUF_SZ, DMA_FROM_DEVICE);
-				}
-				skb->len = pkt_len;
+			if (likely(skb)) {
 				skb->protocol = eth_type_trans(skb, dev);
 				netif_rx(skb);
 				dev->stats.rx_packets++;
 				dev->stats.rx_bytes += pkt_len;
+			} else {
+				netdev_err(dev,
+				       "i596_rx Memory squeeze, dropping packet.\n");
+				dev->stats.rx_dropped++;
 			}
 		} else {
 			DEB(DEB_ERRORS, printk(KERN_DEBUG