1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2019 Synopsys, Inc. and/or its affiliates.
4 * stmmac Selftests Support
6 * Author: Jose Abreu <joabreu@synopsys.com>
9 #include <linux/bitrev.h>
10 #include <linux/completion.h>
11 #include <linux/crc32.h>
12 #include <linux/ethtool.h>
14 #include <linux/phy.h>
15 #include <linux/udp.h>
16 #include <net/pkt_cls.h>
19 #include <net/tc_act/tc_gact.h>
28 #define STMMAC_TEST_PKT_SIZE (sizeof(struct ethhdr) + sizeof(struct iphdr) + \
29 sizeof(struct stmmachdr))
30 #define STMMAC_TEST_PKT_MAGIC 0xdeadcafecafedeadULL
31 #define STMMAC_LB_TIMEOUT msecs_to_jiffies(200)
33 struct stmmac_packet_attrs {
55 static u8 stmmac_test_next_id;
57 static struct sk_buff *stmmac_test_get_udp_skb(struct stmmac_priv *priv,
58 struct stmmac_packet_attrs *attr)
60 struct sk_buff *skb = NULL;
61 struct udphdr *uhdr = NULL;
62 struct tcphdr *thdr = NULL;
63 struct stmmachdr *shdr;
68 size = attr->size + STMMAC_TEST_PKT_SIZE;
76 size += sizeof(struct tcphdr);
78 size += sizeof(struct udphdr);
80 if (attr->max_size && (attr->max_size > size))
81 size = attr->max_size;
83 skb = netdev_alloc_skb_ip_align(priv->dev, size);
90 ehdr = skb_push(skb, ETH_HLEN + 8);
92 ehdr = skb_push(skb, ETH_HLEN + 4);
93 else if (attr->remove_sa)
94 ehdr = skb_push(skb, ETH_HLEN - 6);
96 ehdr = skb_push(skb, ETH_HLEN);
97 skb_reset_mac_header(skb);
99 skb_set_network_header(skb, skb->len);
100 ihdr = skb_put(skb, sizeof(*ihdr));
102 skb_set_transport_header(skb, skb->len);
104 thdr = skb_put(skb, sizeof(*thdr));
106 uhdr = skb_put(skb, sizeof(*uhdr));
108 if (!attr->remove_sa)
109 eth_zero_addr(ehdr->h_source);
110 eth_zero_addr(ehdr->h_dest);
111 if (attr->src && !attr->remove_sa)
112 ether_addr_copy(ehdr->h_source, attr->src);
114 ether_addr_copy(ehdr->h_dest, attr->dst);
116 if (!attr->remove_sa) {
117 ehdr->h_proto = htons(ETH_P_IP);
119 __be16 *ptr = (__be16 *)ehdr;
122 ptr[3] = htons(ETH_P_IP);
128 if (!attr->remove_sa) {
129 tag = (void *)ehdr + ETH_HLEN;
130 proto = (void *)ehdr + (2 * ETH_ALEN);
132 tag = (void *)ehdr + ETH_HLEN - 6;
133 proto = (void *)ehdr + ETH_ALEN;
136 proto[0] = htons(ETH_P_8021Q);
137 tag[0] = htons(attr->vlan_id_out);
138 tag[1] = htons(ETH_P_IP);
139 if (attr->vlan > 1) {
140 proto[0] = htons(ETH_P_8021AD);
141 tag[1] = htons(ETH_P_8021Q);
142 tag[2] = htons(attr->vlan_id_in);
143 tag[3] = htons(ETH_P_IP);
148 thdr->source = htons(attr->sport);
149 thdr->dest = htons(attr->dport);
150 thdr->doff = sizeof(struct tcphdr) / 4;
153 uhdr->source = htons(attr->sport);
154 uhdr->dest = htons(attr->dport);
155 uhdr->len = htons(sizeof(*shdr) + sizeof(*uhdr) + attr->size);
157 uhdr->len = htons(attr->max_size -
158 (sizeof(*ihdr) + sizeof(*ehdr)));
166 ihdr->protocol = IPPROTO_TCP;
168 ihdr->protocol = IPPROTO_UDP;
169 iplen = sizeof(*ihdr) + sizeof(*shdr) + attr->size;
171 iplen += sizeof(*thdr);
173 iplen += sizeof(*uhdr);
176 iplen = attr->max_size - sizeof(*ehdr);
178 ihdr->tot_len = htons(iplen);
180 ihdr->saddr = htonl(attr->ip_src);
181 ihdr->daddr = htonl(attr->ip_dst);
186 shdr = skb_put(skb, sizeof(*shdr));
188 shdr->magic = cpu_to_be64(STMMAC_TEST_PKT_MAGIC);
189 attr->id = stmmac_test_next_id;
190 shdr->id = stmmac_test_next_id++;
193 skb_put(skb, attr->size);
194 if (attr->max_size && (attr->max_size > skb->len))
195 skb_put(skb, attr->max_size - skb->len);
198 skb->ip_summed = CHECKSUM_PARTIAL;
200 thdr->check = ~tcp_v4_check(skb->len, ihdr->saddr, ihdr->daddr, 0);
201 skb->csum_start = skb_transport_header(skb) - skb->head;
202 skb->csum_offset = offsetof(struct tcphdr, check);
204 udp4_hwcsum(skb, ihdr->saddr, ihdr->daddr);
207 skb->protocol = htons(ETH_P_IP);
208 skb->pkt_type = PACKET_HOST;
209 skb->dev = priv->dev;
214 static struct sk_buff *stmmac_test_get_arp_skb(struct stmmac_priv *priv,
215 struct stmmac_packet_attrs *attr)
217 __be32 ip_src = htonl(attr->ip_src);
218 __be32 ip_dst = htonl(attr->ip_dst);
219 struct sk_buff *skb = NULL;
221 skb = arp_create(ARPOP_REQUEST, ETH_P_ARP, ip_dst, priv->dev, ip_src,
222 NULL, attr->src, attr->dst);
226 skb->pkt_type = PACKET_HOST;
227 skb->dev = priv->dev;
232 struct stmmac_test_priv {
233 struct stmmac_packet_attrs *packet;
234 struct packet_type pt;
235 struct completion comp;
241 static int stmmac_test_loopback_validate(struct sk_buff *skb,
242 struct net_device *ndev,
243 struct packet_type *pt,
244 struct net_device *orig_ndev)
246 struct stmmac_test_priv *tpriv = pt->af_packet_priv;
247 struct stmmachdr *shdr;
253 skb = skb_unshare(skb, GFP_ATOMIC);
257 if (skb_linearize(skb))
259 if (skb_headlen(skb) < (STMMAC_TEST_PKT_SIZE - ETH_HLEN))
262 ehdr = (struct ethhdr *)skb_mac_header(skb);
263 if (tpriv->packet->dst) {
264 if (!ether_addr_equal(ehdr->h_dest, tpriv->packet->dst))
267 if (tpriv->packet->sarc) {
268 if (!ether_addr_equal(ehdr->h_source, ehdr->h_dest))
270 } else if (tpriv->packet->src) {
271 if (!ether_addr_equal(ehdr->h_source, tpriv->packet->src))
276 if (tpriv->double_vlan)
277 ihdr = (struct iphdr *)(skb_network_header(skb) + 4);
279 if (tpriv->packet->tcp) {
280 if (ihdr->protocol != IPPROTO_TCP)
283 thdr = (struct tcphdr *)((u8 *)ihdr + 4 * ihdr->ihl);
284 if (thdr->dest != htons(tpriv->packet->dport))
287 shdr = (struct stmmachdr *)((u8 *)thdr + sizeof(*thdr));
289 if (ihdr->protocol != IPPROTO_UDP)
292 uhdr = (struct udphdr *)((u8 *)ihdr + 4 * ihdr->ihl);
293 if (uhdr->dest != htons(tpriv->packet->dport))
296 shdr = (struct stmmachdr *)((u8 *)uhdr + sizeof(*uhdr));
299 if (shdr->magic != cpu_to_be64(STMMAC_TEST_PKT_MAGIC))
301 if (tpriv->packet->exp_hash && !skb->hash)
303 if (tpriv->packet->id != shdr->id)
307 complete(&tpriv->comp);
313 static int __stmmac_test_loopback(struct stmmac_priv *priv,
314 struct stmmac_packet_attrs *attr)
316 struct stmmac_test_priv *tpriv;
317 struct sk_buff *skb = NULL;
320 tpriv = kzalloc(sizeof(*tpriv), GFP_KERNEL);
325 init_completion(&tpriv->comp);
327 tpriv->pt.type = htons(ETH_P_IP);
328 tpriv->pt.func = stmmac_test_loopback_validate;
329 tpriv->pt.dev = priv->dev;
330 tpriv->pt.af_packet_priv = tpriv;
331 tpriv->packet = attr;
333 if (!attr->dont_wait)
334 dev_add_pack(&tpriv->pt);
336 skb = stmmac_test_get_udp_skb(priv, attr);
342 skb_set_queue_mapping(skb, attr->queue_mapping);
343 ret = dev_queue_xmit(skb);
351 attr->timeout = STMMAC_LB_TIMEOUT;
353 wait_for_completion_timeout(&tpriv->comp, attr->timeout);
354 ret = tpriv->ok ? 0 : -ETIMEDOUT;
357 if (!attr->dont_wait)
358 dev_remove_pack(&tpriv->pt);
363 static int stmmac_test_mac_loopback(struct stmmac_priv *priv)
365 struct stmmac_packet_attrs attr = { };
367 attr.dst = priv->dev->dev_addr;
368 return __stmmac_test_loopback(priv, &attr);
371 static int stmmac_test_phy_loopback(struct stmmac_priv *priv)
373 struct stmmac_packet_attrs attr = { };
376 if (!priv->dev->phydev)
379 ret = phy_loopback(priv->dev->phydev, true);
383 attr.dst = priv->dev->dev_addr;
384 ret = __stmmac_test_loopback(priv, &attr);
386 phy_loopback(priv->dev->phydev, false);
390 static int stmmac_test_mmc(struct stmmac_priv *priv)
392 struct stmmac_counters initial, final;
395 memset(&initial, 0, sizeof(initial));
396 memset(&final, 0, sizeof(final));
398 if (!priv->dma_cap.rmon)
401 /* Save previous results into internal struct */
402 stmmac_mmc_read(priv, priv->mmcaddr, &priv->mmc);
404 ret = stmmac_test_mac_loopback(priv);
408 /* These will be loopback results so no need to save them */
409 stmmac_mmc_read(priv, priv->mmcaddr, &final);
412 * The number of MMC counters available depends on HW configuration
413 * so we just use this one to validate the feature. I hope there is
414 * not a version without this counter.
416 if (final.mmc_tx_framecount_g <= initial.mmc_tx_framecount_g)
422 static int stmmac_test_eee(struct stmmac_priv *priv)
424 struct stmmac_extra_stats *initial, *final;
428 if (!priv->dma_cap.eee || !priv->eee_active)
431 initial = kzalloc(sizeof(*initial), GFP_KERNEL);
435 final = kzalloc(sizeof(*final), GFP_KERNEL);
438 goto out_free_initial;
441 memcpy(initial, &priv->xstats, sizeof(*initial));
443 ret = stmmac_test_mac_loopback(priv);
447 /* We have no traffic in the line so, sooner or later it will go LPI */
449 memcpy(final, &priv->xstats, sizeof(*final));
451 if (final->irq_tx_path_in_lpi_mode_n >
452 initial->irq_tx_path_in_lpi_mode_n)
462 if (final->irq_tx_path_in_lpi_mode_n <=
463 initial->irq_tx_path_in_lpi_mode_n) {
468 if (final->irq_tx_path_exit_lpi_mode_n <=
469 initial->irq_tx_path_exit_lpi_mode_n) {
481 static int stmmac_filter_check(struct stmmac_priv *priv)
483 if (!(priv->dev->flags & IFF_PROMISC))
486 netdev_warn(priv->dev, "Test can't be run in promiscuous mode!\n");
490 static bool stmmac_hash_check(struct stmmac_priv *priv, unsigned char *addr)
492 int mc_offset = 32 - priv->hw->mcast_bits_log2;
493 struct netdev_hw_addr *ha;
496 /* First compute the hash for desired addr */
497 hash = bitrev32(~crc32_le(~0, addr, 6)) >> mc_offset;
499 hash = 1 << (hash & 0x1f);
501 /* Now, check if it collides with any existing one */
502 netdev_for_each_mc_addr(ha, priv->dev) {
503 u32 nr = bitrev32(~crc32_le(~0, ha->addr, ETH_ALEN)) >> mc_offset;
504 if (((nr >> 5) == hash_nr) && ((1 << (nr & 0x1f)) == hash))
508 /* No collisions, address is good to go */
512 static bool stmmac_perfect_check(struct stmmac_priv *priv, unsigned char *addr)
514 struct netdev_hw_addr *ha;
516 /* Check if it collides with any existing one */
517 netdev_for_each_uc_addr(ha, priv->dev) {
518 if (!memcmp(ha->addr, addr, ETH_ALEN))
522 /* No collisions, address is good to go */
526 static int stmmac_test_hfilt(struct stmmac_priv *priv)
528 unsigned char gd_addr[ETH_ALEN] = {0xf1, 0xee, 0xdd, 0xcc, 0xbb, 0xaa};
529 unsigned char bd_addr[ETH_ALEN] = {0xf1, 0xff, 0xff, 0xff, 0xff, 0xff};
530 struct stmmac_packet_attrs attr = { };
531 int ret, tries = 256;
533 ret = stmmac_filter_check(priv);
537 if (netdev_mc_count(priv->dev) >= priv->hw->multicast_filter_bins)
541 /* We only need to check the bd_addr for collisions */
542 bd_addr[ETH_ALEN - 1] = tries;
543 if (stmmac_hash_check(priv, bd_addr))
550 ret = dev_mc_add(priv->dev, gd_addr);
556 /* Shall receive packet */
557 ret = __stmmac_test_loopback(priv, &attr);
563 /* Shall NOT receive packet */
564 ret = __stmmac_test_loopback(priv, &attr);
565 ret = ret ? 0 : -EINVAL;
568 dev_mc_del(priv->dev, gd_addr);
572 static int stmmac_test_pfilt(struct stmmac_priv *priv)
574 unsigned char gd_addr[ETH_ALEN] = {0xf0, 0x01, 0x44, 0x55, 0x66, 0x77};
575 unsigned char bd_addr[ETH_ALEN] = {0xf0, 0xff, 0xff, 0xff, 0xff, 0xff};
576 struct stmmac_packet_attrs attr = { };
577 int ret, tries = 256;
579 if (stmmac_filter_check(priv))
581 if (netdev_uc_count(priv->dev) >= priv->hw->unicast_filter_entries)
585 /* We only need to check the bd_addr for collisions */
586 bd_addr[ETH_ALEN - 1] = tries;
587 if (stmmac_perfect_check(priv, bd_addr))
594 ret = dev_uc_add(priv->dev, gd_addr);
600 /* Shall receive packet */
601 ret = __stmmac_test_loopback(priv, &attr);
607 /* Shall NOT receive packet */
608 ret = __stmmac_test_loopback(priv, &attr);
609 ret = ret ? 0 : -EINVAL;
612 dev_uc_del(priv->dev, gd_addr);
616 static int stmmac_test_mcfilt(struct stmmac_priv *priv)
618 unsigned char uc_addr[ETH_ALEN] = {0xf0, 0xff, 0xff, 0xff, 0xff, 0xff};
619 unsigned char mc_addr[ETH_ALEN] = {0xf1, 0xff, 0xff, 0xff, 0xff, 0xff};
620 struct stmmac_packet_attrs attr = { };
621 int ret, tries = 256;
623 if (stmmac_filter_check(priv))
625 if (netdev_uc_count(priv->dev) >= priv->hw->unicast_filter_entries)
629 /* We only need to check the mc_addr for collisions */
630 mc_addr[ETH_ALEN - 1] = tries;
631 if (stmmac_hash_check(priv, mc_addr))
638 ret = dev_uc_add(priv->dev, uc_addr);
644 /* Shall receive packet */
645 ret = __stmmac_test_loopback(priv, &attr);
651 /* Shall NOT receive packet */
652 ret = __stmmac_test_loopback(priv, &attr);
653 ret = ret ? 0 : -EINVAL;
656 dev_uc_del(priv->dev, uc_addr);
660 static int stmmac_test_ucfilt(struct stmmac_priv *priv)
662 unsigned char uc_addr[ETH_ALEN] = {0xf0, 0xff, 0xff, 0xff, 0xff, 0xff};
663 unsigned char mc_addr[ETH_ALEN] = {0xf1, 0xff, 0xff, 0xff, 0xff, 0xff};
664 struct stmmac_packet_attrs attr = { };
665 int ret, tries = 256;
667 if (stmmac_filter_check(priv))
669 if (netdev_mc_count(priv->dev) >= priv->hw->multicast_filter_bins)
673 /* We only need to check the uc_addr for collisions */
674 uc_addr[ETH_ALEN - 1] = tries;
675 if (stmmac_perfect_check(priv, uc_addr))
682 ret = dev_mc_add(priv->dev, mc_addr);
688 /* Shall receive packet */
689 ret = __stmmac_test_loopback(priv, &attr);
695 /* Shall NOT receive packet */
696 ret = __stmmac_test_loopback(priv, &attr);
697 ret = ret ? 0 : -EINVAL;
700 dev_mc_del(priv->dev, mc_addr);
704 static int stmmac_test_flowctrl_validate(struct sk_buff *skb,
705 struct net_device *ndev,
706 struct packet_type *pt,
707 struct net_device *orig_ndev)
709 struct stmmac_test_priv *tpriv = pt->af_packet_priv;
712 ehdr = (struct ethhdr *)skb_mac_header(skb);
713 if (!ether_addr_equal(ehdr->h_source, orig_ndev->dev_addr))
715 if (ehdr->h_proto != htons(ETH_P_PAUSE))
719 complete(&tpriv->comp);
725 static int stmmac_test_flowctrl(struct stmmac_priv *priv)
727 unsigned char paddr[ETH_ALEN] = {0x01, 0x80, 0xC2, 0x00, 0x00, 0x01};
728 struct phy_device *phydev = priv->dev->phydev;
729 u32 rx_cnt = priv->plat->rx_queues_to_use;
730 struct stmmac_test_priv *tpriv;
731 unsigned int pkt_count;
734 if (!phydev || (!phydev->pause && !phydev->asym_pause))
737 tpriv = kzalloc(sizeof(*tpriv), GFP_KERNEL);
742 init_completion(&tpriv->comp);
743 tpriv->pt.type = htons(ETH_P_PAUSE);
744 tpriv->pt.func = stmmac_test_flowctrl_validate;
745 tpriv->pt.dev = priv->dev;
746 tpriv->pt.af_packet_priv = tpriv;
747 dev_add_pack(&tpriv->pt);
749 /* Compute minimum number of packets to make FIFO full */
750 pkt_count = priv->plat->rx_fifo_size;
752 pkt_count = priv->dma_cap.rx_fifo_size;
756 for (i = 0; i < rx_cnt; i++)
757 stmmac_stop_rx(priv, priv->ioaddr, i);
759 ret = dev_set_promiscuity(priv->dev, 1);
763 ret = dev_mc_add(priv->dev, paddr);
767 for (i = 0; i < pkt_count; i++) {
768 struct stmmac_packet_attrs attr = { };
770 attr.dst = priv->dev->dev_addr;
771 attr.dont_wait = true;
774 ret = __stmmac_test_loopback(priv, &attr);
781 /* Wait for some time in case RX Watchdog is enabled */
784 for (i = 0; i < rx_cnt; i++) {
785 struct stmmac_channel *ch = &priv->channel[i];
788 tail = priv->rx_queue[i].dma_rx_phy +
789 (DMA_RX_SIZE * sizeof(struct dma_desc));
791 stmmac_set_rx_tail_ptr(priv, priv->ioaddr, tail, i);
792 stmmac_start_rx(priv, priv->ioaddr, i);
795 napi_reschedule(&ch->rx_napi);
799 wait_for_completion_timeout(&tpriv->comp, STMMAC_LB_TIMEOUT);
800 ret = tpriv->ok ? 0 : -ETIMEDOUT;
803 dev_mc_del(priv->dev, paddr);
804 dev_set_promiscuity(priv->dev, -1);
805 dev_remove_pack(&tpriv->pt);
810 static int stmmac_test_rss(struct stmmac_priv *priv)
812 struct stmmac_packet_attrs attr = { };
814 if (!priv->dma_cap.rssen || !priv->rss.enable)
817 attr.dst = priv->dev->dev_addr;
818 attr.exp_hash = true;
822 return __stmmac_test_loopback(priv, &attr);
825 static int stmmac_test_vlan_validate(struct sk_buff *skb,
826 struct net_device *ndev,
827 struct packet_type *pt,
828 struct net_device *orig_ndev)
830 struct stmmac_test_priv *tpriv = pt->af_packet_priv;
831 struct stmmachdr *shdr;
837 proto = tpriv->double_vlan ? ETH_P_8021AD : ETH_P_8021Q;
839 skb = skb_unshare(skb, GFP_ATOMIC);
843 if (skb_linearize(skb))
845 if (skb_headlen(skb) < (STMMAC_TEST_PKT_SIZE - ETH_HLEN))
847 if (tpriv->vlan_id) {
848 if (skb->vlan_proto != htons(proto))
850 if (skb->vlan_tci != tpriv->vlan_id)
854 ehdr = (struct ethhdr *)skb_mac_header(skb);
855 if (!ether_addr_equal(ehdr->h_dest, tpriv->packet->dst))
859 if (tpriv->double_vlan)
860 ihdr = (struct iphdr *)(skb_network_header(skb) + 4);
861 if (ihdr->protocol != IPPROTO_UDP)
864 uhdr = (struct udphdr *)((u8 *)ihdr + 4 * ihdr->ihl);
865 if (uhdr->dest != htons(tpriv->packet->dport))
868 shdr = (struct stmmachdr *)((u8 *)uhdr + sizeof(*uhdr));
869 if (shdr->magic != cpu_to_be64(STMMAC_TEST_PKT_MAGIC))
873 complete(&tpriv->comp);
880 static int stmmac_test_vlanfilt(struct stmmac_priv *priv)
882 struct stmmac_packet_attrs attr = { };
883 struct stmmac_test_priv *tpriv;
884 struct sk_buff *skb = NULL;
887 if (!priv->dma_cap.vlhash)
890 tpriv = kzalloc(sizeof(*tpriv), GFP_KERNEL);
895 init_completion(&tpriv->comp);
897 tpriv->pt.type = htons(ETH_P_IP);
898 tpriv->pt.func = stmmac_test_vlan_validate;
899 tpriv->pt.dev = priv->dev;
900 tpriv->pt.af_packet_priv = tpriv;
901 tpriv->packet = &attr;
904 * As we use HASH filtering, false positives may appear. This is a
905 * specially chosen ID so that adjacent IDs (+4) have different
908 tpriv->vlan_id = 0x123;
909 dev_add_pack(&tpriv->pt);
911 ret = vlan_vid_add(priv->dev, htons(ETH_P_8021Q), tpriv->vlan_id);
915 for (i = 0; i < 4; i++) {
917 attr.vlan_id_out = tpriv->vlan_id + i;
918 attr.dst = priv->dev->dev_addr;
922 skb = stmmac_test_get_udp_skb(priv, &attr);
928 skb_set_queue_mapping(skb, 0);
929 ret = dev_queue_xmit(skb);
933 wait_for_completion_timeout(&tpriv->comp, STMMAC_LB_TIMEOUT);
934 ret = tpriv->ok ? 0 : -ETIMEDOUT;
937 } else if (!ret && i) {
948 vlan_vid_del(priv->dev, htons(ETH_P_8021Q), tpriv->vlan_id);
950 dev_remove_pack(&tpriv->pt);
955 static int stmmac_test_dvlanfilt(struct stmmac_priv *priv)
957 struct stmmac_packet_attrs attr = { };
958 struct stmmac_test_priv *tpriv;
959 struct sk_buff *skb = NULL;
962 if (!priv->dma_cap.vlhash)
965 tpriv = kzalloc(sizeof(*tpriv), GFP_KERNEL);
970 tpriv->double_vlan = true;
971 init_completion(&tpriv->comp);
973 tpriv->pt.type = htons(ETH_P_8021Q);
974 tpriv->pt.func = stmmac_test_vlan_validate;
975 tpriv->pt.dev = priv->dev;
976 tpriv->pt.af_packet_priv = tpriv;
977 tpriv->packet = &attr;
980 * As we use HASH filtering, false positives may appear. This is a
981 * specially chosen ID so that adjacent IDs (+4) have different
984 tpriv->vlan_id = 0x123;
985 dev_add_pack(&tpriv->pt);
987 ret = vlan_vid_add(priv->dev, htons(ETH_P_8021AD), tpriv->vlan_id);
991 for (i = 0; i < 4; i++) {
993 attr.vlan_id_out = tpriv->vlan_id + i;
994 attr.dst = priv->dev->dev_addr;
998 skb = stmmac_test_get_udp_skb(priv, &attr);
1004 skb_set_queue_mapping(skb, 0);
1005 ret = dev_queue_xmit(skb);
1009 wait_for_completion_timeout(&tpriv->comp, STMMAC_LB_TIMEOUT);
1010 ret = tpriv->ok ? 0 : -ETIMEDOUT;
1013 } else if (!ret && i) {
1024 vlan_vid_del(priv->dev, htons(ETH_P_8021AD), tpriv->vlan_id);
1026 dev_remove_pack(&tpriv->pt);
1031 #ifdef CONFIG_NET_CLS_ACT
1032 static int stmmac_test_rxp(struct stmmac_priv *priv)
1034 unsigned char addr[ETH_ALEN] = {0xde, 0xad, 0xbe, 0xef, 0x00, 0x00};
1035 struct tc_cls_u32_offload cls_u32 = { };
1036 struct stmmac_packet_attrs attr = { };
1037 struct tc_action **actions, *act;
1038 struct tc_u32_sel *sel;
1039 struct tcf_exts *exts;
1042 if (!tc_can_offload(priv->dev))
1044 if (!priv->dma_cap.frpsel)
1047 sel = kzalloc(sizeof(*sel) + nk * sizeof(struct tc_u32_key), GFP_KERNEL);
1051 exts = kzalloc(sizeof(*exts), GFP_KERNEL);
1057 actions = kzalloc(nk * sizeof(*actions), GFP_KERNEL);
1063 act = kzalloc(nk * sizeof(*act), GFP_KERNEL);
1066 goto cleanup_actions;
1069 cls_u32.command = TC_CLSU32_NEW_KNODE;
1070 cls_u32.common.chain_index = 0;
1071 cls_u32.common.protocol = htons(ETH_P_ALL);
1072 cls_u32.knode.exts = exts;
1073 cls_u32.knode.sel = sel;
1074 cls_u32.knode.handle = 0x123;
1076 exts->nr_actions = nk;
1077 exts->actions = actions;
1078 for (i = 0; i < nk; i++) {
1079 struct tcf_gact *gact = to_gact(&act[i]);
1081 actions[i] = &act[i];
1082 gact->tcf_action = TC_ACT_SHOT;
1087 sel->keys[0].off = 6;
1088 sel->keys[0].val = htonl(0xdeadbeef);
1089 sel->keys[0].mask = ~0x0;
1091 ret = stmmac_tc_setup_cls_u32(priv, priv, &cls_u32);
1095 attr.dst = priv->dev->dev_addr;
1098 ret = __stmmac_test_loopback(priv, &attr);
1099 ret = ret ? 0 : -EINVAL; /* Shall NOT receive packet */
1101 cls_u32.command = TC_CLSU32_DELETE_KNODE;
1102 stmmac_tc_setup_cls_u32(priv, priv, &cls_u32);
1115 static int stmmac_test_rxp(struct stmmac_priv *priv)
1121 static int stmmac_test_desc_sai(struct stmmac_priv *priv)
1123 unsigned char src[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1124 struct stmmac_packet_attrs attr = { };
1127 if (!priv->dma_cap.vlins)
1130 attr.remove_sa = true;
1133 attr.dst = priv->dev->dev_addr;
1135 priv->sarc_type = 0x1;
1137 ret = __stmmac_test_loopback(priv, &attr);
1139 priv->sarc_type = 0x0;
1143 static int stmmac_test_desc_sar(struct stmmac_priv *priv)
1145 unsigned char src[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1146 struct stmmac_packet_attrs attr = { };
1149 if (!priv->dma_cap.vlins)
1154 attr.dst = priv->dev->dev_addr;
1156 priv->sarc_type = 0x2;
1158 ret = __stmmac_test_loopback(priv, &attr);
1160 priv->sarc_type = 0x0;
1164 static int stmmac_test_reg_sai(struct stmmac_priv *priv)
1166 unsigned char src[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1167 struct stmmac_packet_attrs attr = { };
1170 if (!priv->dma_cap.vlins)
1173 attr.remove_sa = true;
1176 attr.dst = priv->dev->dev_addr;
1178 if (stmmac_sarc_configure(priv, priv->ioaddr, 0x2))
1181 ret = __stmmac_test_loopback(priv, &attr);
1183 stmmac_sarc_configure(priv, priv->ioaddr, 0x0);
1187 static int stmmac_test_reg_sar(struct stmmac_priv *priv)
1189 unsigned char src[ETH_ALEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1190 struct stmmac_packet_attrs attr = { };
1193 if (!priv->dma_cap.vlins)
1198 attr.dst = priv->dev->dev_addr;
1200 if (stmmac_sarc_configure(priv, priv->ioaddr, 0x3))
1203 ret = __stmmac_test_loopback(priv, &attr);
1205 stmmac_sarc_configure(priv, priv->ioaddr, 0x0);
1209 static int stmmac_test_vlanoff_common(struct stmmac_priv *priv, bool svlan)
1211 struct stmmac_packet_attrs attr = { };
1212 struct stmmac_test_priv *tpriv;
1213 struct sk_buff *skb = NULL;
1217 if (!priv->dma_cap.vlins)
1220 tpriv = kzalloc(sizeof(*tpriv), GFP_KERNEL);
1224 proto = svlan ? ETH_P_8021AD : ETH_P_8021Q;
1227 tpriv->double_vlan = svlan;
1228 init_completion(&tpriv->comp);
1230 tpriv->pt.type = svlan ? htons(ETH_P_8021Q) : htons(ETH_P_IP);
1231 tpriv->pt.func = stmmac_test_vlan_validate;
1232 tpriv->pt.dev = priv->dev;
1233 tpriv->pt.af_packet_priv = tpriv;
1234 tpriv->packet = &attr;
1235 tpriv->vlan_id = 0x123;
1236 dev_add_pack(&tpriv->pt);
1238 ret = vlan_vid_add(priv->dev, htons(proto), tpriv->vlan_id);
1242 attr.dst = priv->dev->dev_addr;
1244 skb = stmmac_test_get_udp_skb(priv, &attr);
1250 __vlan_hwaccel_put_tag(skb, htons(proto), tpriv->vlan_id);
1251 skb->protocol = htons(proto);
1253 skb_set_queue_mapping(skb, 0);
1254 ret = dev_queue_xmit(skb);
1258 wait_for_completion_timeout(&tpriv->comp, STMMAC_LB_TIMEOUT);
1259 ret = tpriv->ok ? 0 : -ETIMEDOUT;
1262 vlan_vid_del(priv->dev, htons(proto), tpriv->vlan_id);
1264 dev_remove_pack(&tpriv->pt);
1269 static int stmmac_test_vlanoff(struct stmmac_priv *priv)
1271 return stmmac_test_vlanoff_common(priv, false);
1274 static int stmmac_test_svlanoff(struct stmmac_priv *priv)
1276 if (!priv->dma_cap.dvlan)
1278 return stmmac_test_vlanoff_common(priv, true);
1281 #ifdef CONFIG_NET_CLS_ACT
1282 static int __stmmac_test_l3filt(struct stmmac_priv *priv, u32 dst, u32 src,
1283 u32 dst_mask, u32 src_mask)
1285 struct flow_dissector_key_ipv4_addrs key, mask;
1286 unsigned long dummy_cookie = 0xdeadbeef;
1287 struct stmmac_packet_attrs attr = { };
1288 struct flow_dissector *dissector;
1289 struct flow_cls_offload *cls;
1290 struct flow_rule *rule;
1293 if (!tc_can_offload(priv->dev))
1295 if (!priv->dma_cap.l3l4fnum)
1297 if (priv->rss.enable)
1298 stmmac_rss_configure(priv, priv->hw, NULL,
1299 priv->plat->rx_queues_to_use);
1301 dissector = kzalloc(sizeof(*dissector), GFP_KERNEL);
1307 dissector->used_keys |= (1 << FLOW_DISSECTOR_KEY_IPV4_ADDRS);
1308 dissector->offset[FLOW_DISSECTOR_KEY_IPV4_ADDRS] = 0;
1310 cls = kzalloc(sizeof(*cls), GFP_KERNEL);
1313 goto cleanup_dissector;
1316 cls->common.chain_index = 0;
1317 cls->command = FLOW_CLS_REPLACE;
1318 cls->cookie = dummy_cookie;
1320 rule = kzalloc(struct_size(rule, action.entries, 1), GFP_KERNEL);
1326 rule->match.dissector = dissector;
1327 rule->match.key = (void *)&key;
1328 rule->match.mask = (void *)&mask;
1330 key.src = htonl(src);
1331 key.dst = htonl(dst);
1332 mask.src = src_mask;
1333 mask.dst = dst_mask;
1337 rule->action.entries[0].id = FLOW_ACTION_DROP;
1338 rule->action.num_entries = 1;
1340 attr.dst = priv->dev->dev_addr;
1344 /* Shall receive packet */
1345 ret = __stmmac_test_loopback(priv, &attr);
1349 ret = stmmac_tc_setup_cls(priv, priv, cls);
1353 /* Shall NOT receive packet */
1354 ret = __stmmac_test_loopback(priv, &attr);
1355 ret = ret ? 0 : -EINVAL;
1357 cls->command = FLOW_CLS_DESTROY;
1358 stmmac_tc_setup_cls(priv, priv, cls);
1366 if (priv->rss.enable) {
1367 stmmac_rss_configure(priv, priv->hw, &priv->rss,
1368 priv->plat->rx_queues_to_use);
1374 static int __stmmac_test_l3filt(struct stmmac_priv *priv, u32 dst, u32 src,
1375 u32 dst_mask, u32 src_mask)
1381 static int stmmac_test_l3filt_da(struct stmmac_priv *priv)
1383 u32 addr = 0x10203040;
1385 return __stmmac_test_l3filt(priv, addr, 0, ~0, 0);
1388 static int stmmac_test_l3filt_sa(struct stmmac_priv *priv)
1390 u32 addr = 0x10203040;
1392 return __stmmac_test_l3filt(priv, 0, addr, 0, ~0);
1395 #ifdef CONFIG_NET_CLS_ACT
1396 static int __stmmac_test_l4filt(struct stmmac_priv *priv, u32 dst, u32 src,
1397 u32 dst_mask, u32 src_mask, bool udp)
1400 struct flow_dissector_key_basic bkey;
1401 struct flow_dissector_key_ports key;
1402 } __aligned(BITS_PER_LONG / 8) keys;
1404 struct flow_dissector_key_basic bmask;
1405 struct flow_dissector_key_ports mask;
1406 } __aligned(BITS_PER_LONG / 8) masks;
1407 unsigned long dummy_cookie = 0xdeadbeef;
1408 struct stmmac_packet_attrs attr = { };
1409 struct flow_dissector *dissector;
1410 struct flow_cls_offload *cls;
1411 struct flow_rule *rule;
1414 if (!tc_can_offload(priv->dev))
1416 if (!priv->dma_cap.l3l4fnum)
1418 if (priv->rss.enable)
1419 stmmac_rss_configure(priv, priv->hw, NULL,
1420 priv->plat->rx_queues_to_use);
1422 dissector = kzalloc(sizeof(*dissector), GFP_KERNEL);
1428 dissector->used_keys |= (1 << FLOW_DISSECTOR_KEY_BASIC);
1429 dissector->used_keys |= (1 << FLOW_DISSECTOR_KEY_PORTS);
1430 dissector->offset[FLOW_DISSECTOR_KEY_BASIC] = 0;
1431 dissector->offset[FLOW_DISSECTOR_KEY_PORTS] = offsetof(typeof(keys), key);
1433 cls = kzalloc(sizeof(*cls), GFP_KERNEL);
1436 goto cleanup_dissector;
1439 cls->common.chain_index = 0;
1440 cls->command = FLOW_CLS_REPLACE;
1441 cls->cookie = dummy_cookie;
1443 rule = kzalloc(struct_size(rule, action.entries, 1), GFP_KERNEL);
1449 rule->match.dissector = dissector;
1450 rule->match.key = (void *)&keys;
1451 rule->match.mask = (void *)&masks;
1453 keys.bkey.ip_proto = udp ? IPPROTO_UDP : IPPROTO_TCP;
1454 keys.key.src = htons(src);
1455 keys.key.dst = htons(dst);
1456 masks.mask.src = src_mask;
1457 masks.mask.dst = dst_mask;
1461 rule->action.entries[0].id = FLOW_ACTION_DROP;
1462 rule->action.num_entries = 1;
1464 attr.dst = priv->dev->dev_addr;
1470 /* Shall receive packet */
1471 ret = __stmmac_test_loopback(priv, &attr);
1475 ret = stmmac_tc_setup_cls(priv, priv, cls);
1479 /* Shall NOT receive packet */
1480 ret = __stmmac_test_loopback(priv, &attr);
1481 ret = ret ? 0 : -EINVAL;
1483 cls->command = FLOW_CLS_DESTROY;
1484 stmmac_tc_setup_cls(priv, priv, cls);
1492 if (priv->rss.enable) {
1493 stmmac_rss_configure(priv, priv->hw, &priv->rss,
1494 priv->plat->rx_queues_to_use);
1500 static int __stmmac_test_l4filt(struct stmmac_priv *priv, u32 dst, u32 src,
1501 u32 dst_mask, u32 src_mask, bool udp)
1507 static int stmmac_test_l4filt_da_tcp(struct stmmac_priv *priv)
1509 u16 dummy_port = 0x123;
1511 return __stmmac_test_l4filt(priv, dummy_port, 0, ~0, 0, false);
1514 static int stmmac_test_l4filt_sa_tcp(struct stmmac_priv *priv)
1516 u16 dummy_port = 0x123;
1518 return __stmmac_test_l4filt(priv, 0, dummy_port, 0, ~0, false);
1521 static int stmmac_test_l4filt_da_udp(struct stmmac_priv *priv)
1523 u16 dummy_port = 0x123;
1525 return __stmmac_test_l4filt(priv, dummy_port, 0, ~0, 0, true);
1528 static int stmmac_test_l4filt_sa_udp(struct stmmac_priv *priv)
1530 u16 dummy_port = 0x123;
1532 return __stmmac_test_l4filt(priv, 0, dummy_port, 0, ~0, true);
1535 static int stmmac_test_arp_validate(struct sk_buff *skb,
1536 struct net_device *ndev,
1537 struct packet_type *pt,
1538 struct net_device *orig_ndev)
1540 struct stmmac_test_priv *tpriv = pt->af_packet_priv;
1541 struct ethhdr *ehdr;
1542 struct arphdr *ahdr;
1544 ehdr = (struct ethhdr *)skb_mac_header(skb);
1545 if (!ether_addr_equal(ehdr->h_dest, tpriv->packet->src))
1548 ahdr = arp_hdr(skb);
1549 if (ahdr->ar_op != htons(ARPOP_REPLY))
1553 complete(&tpriv->comp);
1559 static int stmmac_test_arpoffload(struct stmmac_priv *priv)
1561 unsigned char src[ETH_ALEN] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
1562 unsigned char dst[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
1563 struct stmmac_packet_attrs attr = { };
1564 struct stmmac_test_priv *tpriv;
1565 struct sk_buff *skb = NULL;
1566 u32 ip_addr = 0xdeadcafe;
1567 u32 ip_src = 0xdeadbeef;
1570 if (!priv->dma_cap.arpoffsel)
1573 tpriv = kzalloc(sizeof(*tpriv), GFP_KERNEL);
1578 init_completion(&tpriv->comp);
1580 tpriv->pt.type = htons(ETH_P_ARP);
1581 tpriv->pt.func = stmmac_test_arp_validate;
1582 tpriv->pt.dev = priv->dev;
1583 tpriv->pt.af_packet_priv = tpriv;
1584 tpriv->packet = &attr;
1585 dev_add_pack(&tpriv->pt);
1588 attr.ip_src = ip_src;
1590 attr.ip_dst = ip_addr;
1592 skb = stmmac_test_get_arp_skb(priv, &attr);
1598 ret = stmmac_set_arp_offload(priv, priv->hw, true, ip_addr);
1602 ret = dev_set_promiscuity(priv->dev, 1);
1606 skb_set_queue_mapping(skb, 0);
1607 ret = dev_queue_xmit(skb);
1609 goto cleanup_promisc;
1611 wait_for_completion_timeout(&tpriv->comp, STMMAC_LB_TIMEOUT);
1612 ret = tpriv->ok ? 0 : -ETIMEDOUT;
1615 dev_set_promiscuity(priv->dev, -1);
1617 stmmac_set_arp_offload(priv, priv->hw, false, 0x0);
1618 dev_remove_pack(&tpriv->pt);
1623 static int __stmmac_test_jumbo(struct stmmac_priv *priv, u16 queue)
1625 struct stmmac_packet_attrs attr = { };
1626 int size = priv->dma_buf_sz;
1628 attr.dst = priv->dev->dev_addr;
1629 attr.max_size = size - ETH_FCS_LEN;
1630 attr.queue_mapping = queue;
1632 return __stmmac_test_loopback(priv, &attr);
1635 static int stmmac_test_jumbo(struct stmmac_priv *priv)
1637 return __stmmac_test_jumbo(priv, 0);
1640 static int stmmac_test_mjumbo(struct stmmac_priv *priv)
1642 u32 chan, tx_cnt = priv->plat->tx_queues_to_use;
1648 for (chan = 0; chan < tx_cnt; chan++) {
1649 ret = __stmmac_test_jumbo(priv, chan);
1657 static int stmmac_test_sph(struct stmmac_priv *priv)
1659 unsigned long cnt_end, cnt_start = priv->xstats.rx_split_hdr_pkt_n;
1660 struct stmmac_packet_attrs attr = { };
1666 /* Check for UDP first */
1667 attr.dst = priv->dev->dev_addr;
1670 ret = __stmmac_test_loopback(priv, &attr);
1674 cnt_end = priv->xstats.rx_split_hdr_pkt_n;
1675 if (cnt_end <= cnt_start)
1678 /* Check for TCP now */
1679 cnt_start = cnt_end;
1681 attr.dst = priv->dev->dev_addr;
1684 ret = __stmmac_test_loopback(priv, &attr);
1688 cnt_end = priv->xstats.rx_split_hdr_pkt_n;
1689 if (cnt_end <= cnt_start)
1695 #define STMMAC_LOOPBACK_NONE 0
1696 #define STMMAC_LOOPBACK_MAC 1
1697 #define STMMAC_LOOPBACK_PHY 2
1699 static const struct stmmac_test {
1700 char name[ETH_GSTRING_LEN];
1702 int (*fn)(struct stmmac_priv *priv);
1703 } stmmac_selftests[] = {
1705 .name = "MAC Loopback ",
1706 .lb = STMMAC_LOOPBACK_MAC,
1707 .fn = stmmac_test_mac_loopback,
1709 .name = "PHY Loopback ",
1710 .lb = STMMAC_LOOPBACK_NONE, /* Test will handle it */
1711 .fn = stmmac_test_phy_loopback,
1713 .name = "MMC Counters ",
1714 .lb = STMMAC_LOOPBACK_PHY,
1715 .fn = stmmac_test_mmc,
1718 .lb = STMMAC_LOOPBACK_PHY,
1719 .fn = stmmac_test_eee,
1721 .name = "Hash Filter MC ",
1722 .lb = STMMAC_LOOPBACK_PHY,
1723 .fn = stmmac_test_hfilt,
1725 .name = "Perfect Filter UC ",
1726 .lb = STMMAC_LOOPBACK_PHY,
1727 .fn = stmmac_test_pfilt,
1729 .name = "MC Filter ",
1730 .lb = STMMAC_LOOPBACK_PHY,
1731 .fn = stmmac_test_mcfilt,
1733 .name = "UC Filter ",
1734 .lb = STMMAC_LOOPBACK_PHY,
1735 .fn = stmmac_test_ucfilt,
1737 .name = "Flow Control ",
1738 .lb = STMMAC_LOOPBACK_PHY,
1739 .fn = stmmac_test_flowctrl,
1742 .lb = STMMAC_LOOPBACK_PHY,
1743 .fn = stmmac_test_rss,
1745 .name = "VLAN Filtering ",
1746 .lb = STMMAC_LOOPBACK_PHY,
1747 .fn = stmmac_test_vlanfilt,
1749 .name = "Double VLAN Filtering",
1750 .lb = STMMAC_LOOPBACK_PHY,
1751 .fn = stmmac_test_dvlanfilt,
1753 .name = "Flexible RX Parser ",
1754 .lb = STMMAC_LOOPBACK_PHY,
1755 .fn = stmmac_test_rxp,
1757 .name = "SA Insertion (desc) ",
1758 .lb = STMMAC_LOOPBACK_PHY,
1759 .fn = stmmac_test_desc_sai,
1761 .name = "SA Replacement (desc)",
1762 .lb = STMMAC_LOOPBACK_PHY,
1763 .fn = stmmac_test_desc_sar,
1765 .name = "SA Insertion (reg) ",
1766 .lb = STMMAC_LOOPBACK_PHY,
1767 .fn = stmmac_test_reg_sai,
1769 .name = "SA Replacement (reg)",
1770 .lb = STMMAC_LOOPBACK_PHY,
1771 .fn = stmmac_test_reg_sar,
1773 .name = "VLAN TX Insertion ",
1774 .lb = STMMAC_LOOPBACK_PHY,
1775 .fn = stmmac_test_vlanoff,
1777 .name = "SVLAN TX Insertion ",
1778 .lb = STMMAC_LOOPBACK_PHY,
1779 .fn = stmmac_test_svlanoff,
1781 .name = "L3 DA Filtering ",
1782 .lb = STMMAC_LOOPBACK_PHY,
1783 .fn = stmmac_test_l3filt_da,
1785 .name = "L3 SA Filtering ",
1786 .lb = STMMAC_LOOPBACK_PHY,
1787 .fn = stmmac_test_l3filt_sa,
1789 .name = "L4 DA TCP Filtering ",
1790 .lb = STMMAC_LOOPBACK_PHY,
1791 .fn = stmmac_test_l4filt_da_tcp,
1793 .name = "L4 SA TCP Filtering ",
1794 .lb = STMMAC_LOOPBACK_PHY,
1795 .fn = stmmac_test_l4filt_sa_tcp,
1797 .name = "L4 DA UDP Filtering ",
1798 .lb = STMMAC_LOOPBACK_PHY,
1799 .fn = stmmac_test_l4filt_da_udp,
1801 .name = "L4 SA UDP Filtering ",
1802 .lb = STMMAC_LOOPBACK_PHY,
1803 .fn = stmmac_test_l4filt_sa_udp,
1805 .name = "ARP Offload ",
1806 .lb = STMMAC_LOOPBACK_PHY,
1807 .fn = stmmac_test_arpoffload,
1809 .name = "Jumbo Frame ",
1810 .lb = STMMAC_LOOPBACK_PHY,
1811 .fn = stmmac_test_jumbo,
1813 .name = "Multichannel Jumbo ",
1814 .lb = STMMAC_LOOPBACK_PHY,
1815 .fn = stmmac_test_mjumbo,
1817 .name = "Split Header ",
1818 .lb = STMMAC_LOOPBACK_PHY,
1819 .fn = stmmac_test_sph,
1823 void stmmac_selftest_run(struct net_device *dev,
1824 struct ethtool_test *etest, u64 *buf)
1826 struct stmmac_priv *priv = netdev_priv(dev);
1827 int count = stmmac_selftest_get_count(priv);
1828 int carrier = netif_carrier_ok(dev);
1831 memset(buf, 0, sizeof(*buf) * count);
1832 stmmac_test_next_id = 0;
1834 if (etest->flags != ETH_TEST_FL_OFFLINE) {
1835 netdev_err(priv->dev, "Only offline tests are supported\n");
1836 etest->flags |= ETH_TEST_FL_FAILED;
1838 } else if (!carrier) {
1839 netdev_err(priv->dev, "You need valid Link to execute tests\n");
1840 etest->flags |= ETH_TEST_FL_FAILED;
1844 /* We don't want extra traffic */
1845 netif_carrier_off(dev);
1847 /* Wait for queues drain */
1850 for (i = 0; i < count; i++) {
1853 switch (stmmac_selftests[i].lb) {
1854 case STMMAC_LOOPBACK_PHY:
1857 ret = phy_loopback(dev->phydev, true);
1861 case STMMAC_LOOPBACK_MAC:
1862 ret = stmmac_set_mac_loopback(priv, priv->ioaddr, true);
1864 case STMMAC_LOOPBACK_NONE:
1872 * First tests will always be MAC / PHY loobpack. If any of
1873 * them is not supported we abort earlier.
1876 netdev_err(priv->dev, "Loopback is not supported\n");
1877 etest->flags |= ETH_TEST_FL_FAILED;
1881 ret = stmmac_selftests[i].fn(priv);
1882 if (ret && (ret != -EOPNOTSUPP))
1883 etest->flags |= ETH_TEST_FL_FAILED;
1886 switch (stmmac_selftests[i].lb) {
1887 case STMMAC_LOOPBACK_PHY:
1890 ret = phy_loopback(dev->phydev, false);
1894 case STMMAC_LOOPBACK_MAC:
1895 stmmac_set_mac_loopback(priv, priv->ioaddr, false);
1902 /* Restart everything */
1904 netif_carrier_on(dev);
1907 void stmmac_selftest_get_strings(struct stmmac_priv *priv, u8 *data)
1912 for (i = 0; i < stmmac_selftest_get_count(priv); i++) {
1913 snprintf(p, ETH_GSTRING_LEN, "%2d. %s", i + 1,
1914 stmmac_selftests[i].name);
1915 p += ETH_GSTRING_LEN;
1919 int stmmac_selftest_get_count(struct stmmac_priv *priv)
1921 return ARRAY_SIZE(stmmac_selftests);