Skip to content

Commit 5e3fb0a

Browse files
joabreudavem330
authored andcommitted
net: stmmac: selftests: Implement the ARP Offload test
Implement a test for ARP Offload feature. Signed-off-by: Jose Abreu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 5904a98 commit 5e3fb0a

File tree

1 file changed

+110
-0
lines changed

1 file changed

+110
-0
lines changed

drivers/net/ethernet/stmicro/stmmac/stmmac_selftests.c

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,24 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct stmmac_priv *priv,
196196
return skb;
197197
}
198198

199+
static struct sk_buff *stmmac_test_get_arp_skb(struct stmmac_priv *priv,
200+
struct stmmac_packet_attrs *attr)
201+
{
202+
__be32 ip_src = htonl(attr->ip_src);
203+
__be32 ip_dst = htonl(attr->ip_dst);
204+
struct sk_buff *skb = NULL;
205+
206+
skb = arp_create(ARPOP_REQUEST, ETH_P_ARP, ip_dst, priv->dev, ip_src,
207+
NULL, attr->src, attr->dst);
208+
if (!skb)
209+
return NULL;
210+
211+
skb->pkt_type = PACKET_HOST;
212+
skb->dev = priv->dev;
213+
214+
return skb;
215+
}
216+
199217
struct stmmac_test_priv {
200218
struct stmmac_packet_attrs *packet;
201219
struct packet_type pt;
@@ -1428,6 +1446,94 @@ static int stmmac_test_l4filt_sa_udp(struct stmmac_priv *priv)
14281446
return __stmmac_test_l4filt(priv, 0, dummy_port, 0, ~0, true);
14291447
}
14301448

1449+
static int stmmac_test_arp_validate(struct sk_buff *skb,
1450+
struct net_device *ndev,
1451+
struct packet_type *pt,
1452+
struct net_device *orig_ndev)
1453+
{
1454+
struct stmmac_test_priv *tpriv = pt->af_packet_priv;
1455+
struct ethhdr *ehdr;
1456+
struct arphdr *ahdr;
1457+
1458+
ehdr = (struct ethhdr *)skb_mac_header(skb);
1459+
if (!ether_addr_equal(ehdr->h_dest, tpriv->packet->src))
1460+
goto out;
1461+
1462+
ahdr = arp_hdr(skb);
1463+
if (ahdr->ar_op != htons(ARPOP_REPLY))
1464+
goto out;
1465+
1466+
tpriv->ok = true;
1467+
complete(&tpriv->comp);
1468+
out:
1469+
kfree_skb(skb);
1470+
return 0;
1471+
}
1472+
1473+
static int stmmac_test_arpoffload(struct stmmac_priv *priv)
1474+
{
1475+
unsigned char src[ETH_ALEN] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
1476+
unsigned char dst[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1477+
struct stmmac_packet_attrs attr = { };
1478+
struct stmmac_test_priv *tpriv;
1479+
struct sk_buff *skb = NULL;
1480+
u32 ip_addr = 0xdeadcafe;
1481+
u32 ip_src = 0xdeadbeef;
1482+
int ret;
1483+
1484+
if (!priv->dma_cap.arpoffsel)
1485+
return -EOPNOTSUPP;
1486+
1487+
tpriv = kzalloc(sizeof(*tpriv), GFP_KERNEL);
1488+
if (!tpriv)
1489+
return -ENOMEM;
1490+
1491+
tpriv->ok = false;
1492+
init_completion(&tpriv->comp);
1493+
1494+
tpriv->pt.type = htons(ETH_P_ARP);
1495+
tpriv->pt.func = stmmac_test_arp_validate;
1496+
tpriv->pt.dev = priv->dev;
1497+
tpriv->pt.af_packet_priv = tpriv;
1498+
tpriv->packet = &attr;
1499+
dev_add_pack(&tpriv->pt);
1500+
1501+
attr.src = src;
1502+
attr.ip_src = ip_src;
1503+
attr.dst = dst;
1504+
attr.ip_dst = ip_addr;
1505+
1506+
skb = stmmac_test_get_arp_skb(priv, &attr);
1507+
if (!skb) {
1508+
ret = -ENOMEM;
1509+
goto cleanup;
1510+
}
1511+
1512+
ret = stmmac_set_arp_offload(priv, priv->hw, true, ip_addr);
1513+
if (ret)
1514+
goto cleanup;
1515+
1516+
ret = dev_set_promiscuity(priv->dev, 1);
1517+
if (ret)
1518+
goto cleanup;
1519+
1520+
skb_set_queue_mapping(skb, 0);
1521+
ret = dev_queue_xmit(skb);
1522+
if (ret)
1523+
goto cleanup_promisc;
1524+
1525+
wait_for_completion_timeout(&tpriv->comp, STMMAC_LB_TIMEOUT);
1526+
ret = tpriv->ok ? 0 : -ETIMEDOUT;
1527+
1528+
cleanup_promisc:
1529+
dev_set_promiscuity(priv->dev, -1);
1530+
cleanup:
1531+
stmmac_set_arp_offload(priv, priv->hw, false, 0x0);
1532+
dev_remove_pack(&tpriv->pt);
1533+
kfree(tpriv);
1534+
return ret;
1535+
}
1536+
14311537
#define STMMAC_LOOPBACK_NONE 0
14321538
#define STMMAC_LOOPBACK_MAC 1
14331539
#define STMMAC_LOOPBACK_PHY 2
@@ -1537,6 +1643,10 @@ static const struct stmmac_test {
15371643
.name = "L4 SA UDP Filtering ",
15381644
.lb = STMMAC_LOOPBACK_PHY,
15391645
.fn = stmmac_test_l4filt_sa_udp,
1646+
}, {
1647+
.name = "ARP Offload ",
1648+
.lb = STMMAC_LOOPBACK_PHY,
1649+
.fn = stmmac_test_arpoffload,
15401650
},
15411651
};
15421652

0 commit comments

Comments
 (0)