Skip to content

Commit 6dc8b74

Browse files
hkallweitdavem330
authored andcommitted
r8169: improve rx buffer allocation
8 years ago, as part of 6f0333b ("r8169: use 50% less ram for RX ring"), the alignment requirement for rx buffers was silently changed from 8 bytes to 16 bytes. I found nothing explaining this, also the chip specs I have only mention an 8 byte requirement. AFAICS kmalloc_node() guarantees allocated memory to be at least "long long" aligned, what is 8 bytes on a 32 bit machine. So we can take this memory as-is and avoid some overhead by changing the alignment requirement back to 8 bytes. Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a599698 commit 6dc8b74

File tree

1 file changed

+5
-13
lines changed
  • drivers/net/ethernet/realtek

1 file changed

+5
-13
lines changed

drivers/net/ethernet/realtek/r8169.c

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5659,11 +5659,6 @@ static inline void rtl8169_mark_to_asic(struct RxDesc *desc)
56595659
desc->opts1 = cpu_to_le32(DescOwn | eor | R8169_RX_BUF_SIZE);
56605660
}
56615661

5662-
static inline void *rtl8169_align(void *data)
5663-
{
5664-
return (void *)ALIGN((long)data, 16);
5665-
}
5666-
56675662
static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp,
56685663
struct RxDesc *desc)
56695664
{
@@ -5676,15 +5671,13 @@ static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp,
56765671
if (!data)
56775672
return NULL;
56785673

5679-
if (rtl8169_align(data) != data) {
5680-
kfree(data);
5681-
data = kmalloc_node(R8169_RX_BUF_SIZE + 15, GFP_KERNEL, node);
5682-
if (!data)
5683-
return NULL;
5674+
/* Memory should be properly aligned, but better check. */
5675+
if (!IS_ALIGNED((unsigned long)data, 8)) {
5676+
netdev_err_once(tp->dev, "RX buffer not 8-byte-aligned\n");
5677+
goto err_out;
56845678
}
56855679

5686-
mapping = dma_map_single(d, rtl8169_align(data), R8169_RX_BUF_SIZE,
5687-
DMA_FROM_DEVICE);
5680+
mapping = dma_map_single(d, data, R8169_RX_BUF_SIZE, DMA_FROM_DEVICE);
56885681
if (unlikely(dma_mapping_error(d, mapping))) {
56895682
if (net_ratelimit())
56905683
netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n");
@@ -6290,7 +6283,6 @@ static struct sk_buff *rtl8169_try_rx_copy(void *data,
62906283
struct sk_buff *skb;
62916284
struct device *d = tp_to_dev(tp);
62926285

6293-
data = rtl8169_align(data);
62946286
dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE);
62956287
prefetch(data);
62966288
skb = napi_alloc_skb(&tp->napi, pkt_size);

0 commit comments

Comments
 (0)