Commit 5e3fb0a6 authored by Jose Abreu's avatar Jose Abreu Committed by David S. Miller

net: stmmac: selftests: Implement the ARP Offload test

Implement a test for ARP Offload feature.
Signed-off-by: default avatarJose Abreu <joabreu@synopsys.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 5904a980
......@@ -196,6 +196,24 @@ static struct sk_buff *stmmac_test_get_udp_skb(struct stmmac_priv *priv,
return skb;
}
static struct sk_buff *stmmac_test_get_arp_skb(struct stmmac_priv *priv,
struct stmmac_packet_attrs *attr)
{
__be32 ip_src = htonl(attr->ip_src);
__be32 ip_dst = htonl(attr->ip_dst);
struct sk_buff *skb = NULL;
skb = arp_create(ARPOP_REQUEST, ETH_P_ARP, ip_dst, priv->dev, ip_src,
NULL, attr->src, attr->dst);
if (!skb)
return NULL;
skb->pkt_type = PACKET_HOST;
skb->dev = priv->dev;
return skb;
}
struct stmmac_test_priv {
struct stmmac_packet_attrs *packet;
struct packet_type pt;
......@@ -1428,6 +1446,94 @@ static int stmmac_test_l4filt_sa_udp(struct stmmac_priv *priv)
return __stmmac_test_l4filt(priv, 0, dummy_port, 0, ~0, true);
}
static int stmmac_test_arp_validate(struct sk_buff *skb,
struct net_device *ndev,
struct packet_type *pt,
struct net_device *orig_ndev)
{
struct stmmac_test_priv *tpriv = pt->af_packet_priv;
struct ethhdr *ehdr;
struct arphdr *ahdr;
ehdr = (struct ethhdr *)skb_mac_header(skb);
if (!ether_addr_equal(ehdr->h_dest, tpriv->packet->src))
goto out;
ahdr = arp_hdr(skb);
if (ahdr->ar_op != htons(ARPOP_REPLY))
goto out;
tpriv->ok = true;
complete(&tpriv->comp);
out:
kfree_skb(skb);
return 0;
}
static int stmmac_test_arpoffload(struct stmmac_priv *priv)
{
unsigned char src[ETH_ALEN] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
unsigned char dst[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
struct stmmac_packet_attrs attr = { };
struct stmmac_test_priv *tpriv;
struct sk_buff *skb = NULL;
u32 ip_addr = 0xdeadcafe;
u32 ip_src = 0xdeadbeef;
int ret;
if (!priv->dma_cap.arpoffsel)
return -EOPNOTSUPP;
tpriv = kzalloc(sizeof(*tpriv), GFP_KERNEL);
if (!tpriv)
return -ENOMEM;
tpriv->ok = false;
init_completion(&tpriv->comp);
tpriv->pt.type = htons(ETH_P_ARP);
tpriv->pt.func = stmmac_test_arp_validate;
tpriv->pt.dev = priv->dev;
tpriv->pt.af_packet_priv = tpriv;
tpriv->packet = &attr;
dev_add_pack(&tpriv->pt);
attr.src = src;
attr.ip_src = ip_src;
attr.dst = dst;
attr.ip_dst = ip_addr;
skb = stmmac_test_get_arp_skb(priv, &attr);
if (!skb) {
ret = -ENOMEM;
goto cleanup;
}
ret = stmmac_set_arp_offload(priv, priv->hw, true, ip_addr);
if (ret)
goto cleanup;
ret = dev_set_promiscuity(priv->dev, 1);
if (ret)
goto cleanup;
skb_set_queue_mapping(skb, 0);
ret = dev_queue_xmit(skb);
if (ret)
goto cleanup_promisc;
wait_for_completion_timeout(&tpriv->comp, STMMAC_LB_TIMEOUT);
ret = tpriv->ok ? 0 : -ETIMEDOUT;
cleanup_promisc:
dev_set_promiscuity(priv->dev, -1);
cleanup:
stmmac_set_arp_offload(priv, priv->hw, false, 0x0);
dev_remove_pack(&tpriv->pt);
kfree(tpriv);
return ret;
}
#define STMMAC_LOOPBACK_NONE 0
#define STMMAC_LOOPBACK_MAC 1
#define STMMAC_LOOPBACK_PHY 2
......@@ -1537,6 +1643,10 @@ static const struct stmmac_test {
.name = "L4 SA UDP Filtering ",
.lb = STMMAC_LOOPBACK_PHY,
.fn = stmmac_test_l4filt_sa_udp,
}, {
.name = "ARP Offload ",
.lb = STMMAC_LOOPBACK_PHY,
.fn = stmmac_test_arpoffload,
},
};
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment