af1ede0
From: Eric Dumazet <edumazet@google.com>
af1ede0
af1ede0
Steinar reported reallocations of skb->head with IPv6, leading to
af1ede0
a warning in skb_try_coalesce()
af1ede0
af1ede0
It turns out iwl3945 has several problems :
af1ede0
af1ede0
1) skb->truesize is underestimated. 
af1ede0
   We really consume PAGE_SIZE bytes for a fragment,
af1ede0
   not the frame length.
af1ede0
2) 128 bytes of initial headroom is a bit low and forces reallocations.
af1ede0
3) We can avoid consuming a full page for small enough frames.
af1ede0
af1ede0
Reported-by: Steinar H. Gunderson <sesse@google.com>
af1ede0
Signed-off-by: Eric Dumazet <edumazet@google.com>
af1ede0
Cc: Paul Stewart <pstew@google.com>
af1ede0
---
af1ede0
v3: use regular memcpy(skb_put(...),...)
af1ede0
v2: SMALL_PACKET_SIZE define
af1ede0
af1ede0
 drivers/net/wireless/iwlegacy/3945.c |   31 +++++++++++++++----------
af1ede0
 1 file changed, 19 insertions(+), 12 deletions(-)
af1ede0
af1ede0
diff --git a/drivers/net/wireless/iwlegacy/3945.c b/drivers/net/wireless/iwlegacy/3945.c
af1ede0
index c092033..f09e257 100644
af1ede0
--- a/drivers/net/wireless/iwlegacy/3945.c
af1ede0
+++ b/drivers/net/wireless/iwlegacy/3945.c
af1ede0
@@ -475,6 +475,8 @@ il3945_is_network_packet(struct il_priv *il, struct ieee80211_hdr *header)
af1ede0
 	}
af1ede0
 }
af1ede0
 
af1ede0
+#define SMALL_PACKET_SIZE 256
af1ede0
+
af1ede0
 static void
af1ede0
 il3945_pass_packet_to_mac80211(struct il_priv *il, struct il_rx_buf *rxb,
af1ede0
 			       struct ieee80211_rx_status *stats)
af1ede0
@@ -483,14 +485,13 @@ il3945_pass_packet_to_mac80211(struct il_priv *il, struct il_rx_buf *rxb,
af1ede0
 	struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)IL_RX_DATA(pkt);
af1ede0
 	struct il3945_rx_frame_hdr *rx_hdr = IL_RX_HDR(pkt);
af1ede0
 	struct il3945_rx_frame_end *rx_end = IL_RX_END(pkt);
af1ede0
-	u16 len = le16_to_cpu(rx_hdr->len);
af1ede0
+	u32 len = le16_to_cpu(rx_hdr->len);
af1ede0
 	struct sk_buff *skb;
af1ede0
 	__le16 fc = hdr->frame_control;
af1ede0
+	u32 fraglen = PAGE_SIZE << il->hw_params.rx_page_order;
af1ede0
 
af1ede0
 	/* We received data from the HW, so stop the watchdog */
af1ede0
-	if (unlikely
af1ede0
-	    (len + IL39_RX_FRAME_SIZE >
af1ede0
-	     PAGE_SIZE << il->hw_params.rx_page_order)) {
af1ede0
+	if (unlikely(len + IL39_RX_FRAME_SIZE > fraglen)) {
af1ede0
 		D_DROP("Corruption detected!\n");
af1ede0
 		return;
af1ede0
 	}
af1ede0
@@ -506,26 +507,32 @@ il3945_pass_packet_to_mac80211(struct il_priv *il, struct il_rx_buf *rxb,
af1ede0
 		D_INFO("Woke queues - frame received on passive channel\n");
af1ede0
 	}
af1ede0
 
af1ede0
-	skb = dev_alloc_skb(128);
af1ede0
+	skb = dev_alloc_skb(SMALL_PACKET_SIZE);
af1ede0
 	if (!skb) {
af1ede0
 		IL_ERR("dev_alloc_skb failed\n");
af1ede0
 		return;
af1ede0
 	}
af1ede0
 
af1ede0
 	if (!il3945_mod_params.sw_crypto)
af1ede0
-		il_set_decrypted_flag(il, (struct ieee80211_hdr *)rxb_addr(rxb),
af1ede0
+		il_set_decrypted_flag(il, (struct ieee80211_hdr *)pkt,
af1ede0
 				      le32_to_cpu(rx_end->status), stats);
af1ede0
 
af1ede0
-	skb_add_rx_frag(skb, 0, rxb->page,
af1ede0
-			(void *)rx_hdr->payload - (void *)pkt, len,
af1ede0
-			len);
af1ede0
-
af1ede0
+	/* If frame is small enough to fit into skb->head, copy it
af1ede0
+	 * and do not consume a full page
af1ede0
+	 */
af1ede0
+	if (len <= SMALL_PACKET_SIZE) {
af1ede0
+		memcpy(skb_put(skb, len), rx_hdr->payload, len);
af1ede0
+	} else {
af1ede0
+		skb_add_rx_frag(skb, 0, rxb->page,
af1ede0
+				(void *)rx_hdr->payload - (void *)pkt, len,
af1ede0
+				fraglen);
af1ede0
+		il->alloc_rxb_page--;
af1ede0
+		rxb->page = NULL;
af1ede0
+	}
af1ede0
 	il_update_stats(il, false, fc, len);
af1ede0
 	memcpy(IEEE80211_SKB_RXCB(skb), stats, sizeof(*stats));
af1ede0
 
af1ede0
 	ieee80211_rx(il->hw, skb);
af1ede0
-	il->alloc_rxb_page--;
af1ede0
-	rxb->page = NULL;
af1ede0
 }
af1ede0
 
af1ede0
 #define IL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
af1ede0
af1ede0