forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 223293205a7265c8b02882461ba8996650048ade
kernel/drivers/net/ethernet/amd/xgbe/xgbe-drv.c
....@@ -119,7 +119,6 @@
119119 #include <linux/tcp.h>
120120 #include <linux/if_vlan.h>
121121 #include <linux/interrupt.h>
122
-#include <net/busy_poll.h>
123122 #include <linux/clk.h>
124123 #include <linux/if_ether.h>
125124 #include <linux/net_tstamp.h>
....@@ -404,9 +403,9 @@
404403 return false;
405404 }
406405
407
-static void xgbe_ecc_isr_task(unsigned long data)
406
+static void xgbe_ecc_isr_task(struct tasklet_struct *t)
408407 {
409
- struct xgbe_prv_data *pdata = (struct xgbe_prv_data *)data;
408
+ struct xgbe_prv_data *pdata = from_tasklet(pdata, t, tasklet_ecc);
410409 unsigned int ecc_isr;
411410 bool stop = false;
412411
....@@ -469,14 +468,14 @@
469468 if (pdata->isr_as_tasklet)
470469 tasklet_schedule(&pdata->tasklet_ecc);
471470 else
472
- xgbe_ecc_isr_task((unsigned long)pdata);
471
+ xgbe_ecc_isr_task(&pdata->tasklet_ecc);
473472
474473 return IRQ_HANDLED;
475474 }
476475
477
-static void xgbe_isr_task(unsigned long data)
476
+static void xgbe_isr_task(struct tasklet_struct *t)
478477 {
479
- struct xgbe_prv_data *pdata = (struct xgbe_prv_data *)data;
478
+ struct xgbe_prv_data *pdata = from_tasklet(pdata, t, tasklet_dev);
480479 struct xgbe_hw_if *hw_if = &pdata->hw_if;
481480 struct xgbe_channel *channel;
482481 unsigned int dma_isr, dma_ch_isr;
....@@ -583,7 +582,7 @@
583582
584583 /* If there is not a separate ECC irq, handle it here */
585584 if (pdata->vdata->ecc_support && (pdata->dev_irq == pdata->ecc_irq))
586
- xgbe_ecc_isr_task((unsigned long)pdata);
585
+ xgbe_ecc_isr_task(&pdata->tasklet_ecc);
587586
588587 /* If there is not a separate I2C irq, handle it here */
589588 if (pdata->vdata->i2c_support && (pdata->dev_irq == pdata->i2c_irq))
....@@ -608,7 +607,7 @@
608607 if (pdata->isr_as_tasklet)
609608 tasklet_schedule(&pdata->tasklet_dev);
610609 else
611
- xgbe_isr_task((unsigned long)pdata);
610
+ xgbe_isr_task(&pdata->tasklet_dev);
612611
613612 return IRQ_HANDLED;
614613 }
....@@ -907,114 +906,40 @@
907906 }
908907 }
909908
910
-static void xgbe_disable_vxlan_offloads(struct xgbe_prv_data *pdata)
909
+static int xgbe_vxlan_set_port(struct net_device *netdev, unsigned int table,
910
+ unsigned int entry, struct udp_tunnel_info *ti)
911911 {
912
- struct net_device *netdev = pdata->netdev;
912
+ struct xgbe_prv_data *pdata = netdev_priv(netdev);
913913
914
- if (!pdata->vxlan_offloads_set)
915
- return;
914
+ pdata->vxlan_port = be16_to_cpu(ti->port);
915
+ pdata->hw_if.enable_vxlan(pdata);
916916
917
- netdev_info(netdev, "disabling VXLAN offloads\n");
918
-
919
- netdev->hw_enc_features &= ~(NETIF_F_SG |
920
- NETIF_F_IP_CSUM |
921
- NETIF_F_IPV6_CSUM |
922
- NETIF_F_RXCSUM |
923
- NETIF_F_TSO |
924
- NETIF_F_TSO6 |
925
- NETIF_F_GRO |
926
- NETIF_F_GSO_UDP_TUNNEL |
927
- NETIF_F_GSO_UDP_TUNNEL_CSUM);
928
-
929
- netdev->features &= ~(NETIF_F_GSO_UDP_TUNNEL |
930
- NETIF_F_GSO_UDP_TUNNEL_CSUM);
931
-
932
- pdata->vxlan_offloads_set = 0;
917
+ return 0;
933918 }
934919
935
-static void xgbe_disable_vxlan_hw(struct xgbe_prv_data *pdata)
920
+static int xgbe_vxlan_unset_port(struct net_device *netdev, unsigned int table,
921
+ unsigned int entry, struct udp_tunnel_info *ti)
936922 {
937
- if (!pdata->vxlan_port_set)
938
- return;
923
+ struct xgbe_prv_data *pdata = netdev_priv(netdev);
939924
940925 pdata->hw_if.disable_vxlan(pdata);
941
-
942
- pdata->vxlan_port_set = 0;
943926 pdata->vxlan_port = 0;
927
+
928
+ return 0;
944929 }
945930
946
-static void xgbe_disable_vxlan_accel(struct xgbe_prv_data *pdata)
931
+static const struct udp_tunnel_nic_info xgbe_udp_tunnels = {
932
+ .set_port = xgbe_vxlan_set_port,
933
+ .unset_port = xgbe_vxlan_unset_port,
934
+ .flags = UDP_TUNNEL_NIC_INFO_OPEN_ONLY,
935
+ .tables = {
936
+ { .n_entries = 1, .tunnel_types = UDP_TUNNEL_TYPE_VXLAN, },
937
+ },
938
+};
939
+
940
+const struct udp_tunnel_nic_info *xgbe_get_udp_tunnel_info(void)
947941 {
948
- xgbe_disable_vxlan_offloads(pdata);
949
-
950
- xgbe_disable_vxlan_hw(pdata);
951
-}
952
-
953
-static void xgbe_enable_vxlan_offloads(struct xgbe_prv_data *pdata)
954
-{
955
- struct net_device *netdev = pdata->netdev;
956
-
957
- if (pdata->vxlan_offloads_set)
958
- return;
959
-
960
- netdev_info(netdev, "enabling VXLAN offloads\n");
961
-
962
- netdev->hw_enc_features |= NETIF_F_SG |
963
- NETIF_F_IP_CSUM |
964
- NETIF_F_IPV6_CSUM |
965
- NETIF_F_RXCSUM |
966
- NETIF_F_TSO |
967
- NETIF_F_TSO6 |
968
- NETIF_F_GRO |
969
- pdata->vxlan_features;
970
-
971
- netdev->features |= pdata->vxlan_features;
972
-
973
- pdata->vxlan_offloads_set = 1;
974
-}
975
-
976
-static void xgbe_enable_vxlan_hw(struct xgbe_prv_data *pdata)
977
-{
978
- struct xgbe_vxlan_data *vdata;
979
-
980
- if (pdata->vxlan_port_set)
981
- return;
982
-
983
- if (list_empty(&pdata->vxlan_ports))
984
- return;
985
-
986
- vdata = list_first_entry(&pdata->vxlan_ports,
987
- struct xgbe_vxlan_data, list);
988
-
989
- pdata->vxlan_port_set = 1;
990
- pdata->vxlan_port = be16_to_cpu(vdata->port);
991
-
992
- pdata->hw_if.enable_vxlan(pdata);
993
-}
994
-
995
-static void xgbe_enable_vxlan_accel(struct xgbe_prv_data *pdata)
996
-{
997
- /* VXLAN acceleration desired? */
998
- if (!pdata->vxlan_features)
999
- return;
1000
-
1001
- /* VXLAN acceleration possible? */
1002
- if (pdata->vxlan_force_disable)
1003
- return;
1004
-
1005
- xgbe_enable_vxlan_hw(pdata);
1006
-
1007
- xgbe_enable_vxlan_offloads(pdata);
1008
-}
1009
-
1010
-static void xgbe_reset_vxlan_accel(struct xgbe_prv_data *pdata)
1011
-{
1012
- xgbe_disable_vxlan_hw(pdata);
1013
-
1014
- if (pdata->vxlan_features)
1015
- xgbe_enable_vxlan_offloads(pdata);
1016
-
1017
- pdata->vxlan_force_disable = 0;
942
+ return &xgbe_udp_tunnels;
1018943 }
1019944
1020945 static void xgbe_napi_enable(struct xgbe_prv_data *pdata, unsigned int add)
....@@ -1068,9 +993,8 @@
1068993 unsigned int i;
1069994 int ret;
1070995
1071
- tasklet_init(&pdata->tasklet_dev, xgbe_isr_task, (unsigned long)pdata);
1072
- tasklet_init(&pdata->tasklet_ecc, xgbe_ecc_isr_task,
1073
- (unsigned long)pdata);
996
+ tasklet_setup(&pdata->tasklet_dev, xgbe_isr_task);
997
+ tasklet_setup(&pdata->tasklet_ecc, xgbe_ecc_isr_task);
1074998
1075999 ret = devm_request_irq(pdata->dev, pdata->dev_irq, xgbe_isr, 0,
10761000 netdev_name(netdev), pdata);
....@@ -1409,7 +1333,7 @@
14091333 hw_if->enable_tx(pdata);
14101334 hw_if->enable_rx(pdata);
14111335
1412
- udp_tunnel_get_rx_info(netdev);
1336
+ udp_tunnel_nic_reset_ntf(netdev);
14131337
14141338 netif_tx_start_all_queues(netdev);
14151339
....@@ -1451,7 +1375,7 @@
14511375 xgbe_stop_timers(pdata);
14521376 flush_workqueue(pdata->dev_workqueue);
14531377
1454
- xgbe_reset_vxlan_accel(pdata);
1378
+ xgbe_vxlan_unset_port(netdev, 0, 0, NULL);
14551379
14561380 hw_if->disable_tx(pdata);
14571381 hw_if->disable_rx(pdata);
....@@ -1616,7 +1540,7 @@
16161540 /* PTP v2, UDP, any kind of event packet */
16171541 case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
16181542 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1);
1619
- /* PTP v1, UDP, any kind of event packet */
1543
+ fallthrough; /* to PTP v1, UDP, any kind of event packet */
16201544 case HWTSTAMP_FILTER_PTP_V1_L4_EVENT:
16211545 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1);
16221546 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1);
....@@ -1627,7 +1551,7 @@
16271551 /* PTP v2, UDP, Sync packet */
16281552 case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
16291553 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1);
1630
- /* PTP v1, UDP, Sync packet */
1554
+ fallthrough; /* to PTP v1, UDP, Sync packet */
16311555 case HWTSTAMP_FILTER_PTP_V1_L4_SYNC:
16321556 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1);
16331557 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1);
....@@ -1638,7 +1562,7 @@
16381562 /* PTP v2, UDP, Delay_req packet */
16391563 case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
16401564 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSVER2ENA, 1);
1641
- /* PTP v1, UDP, Delay_req packet */
1565
+ fallthrough; /* to PTP v1, UDP, Delay_req packet */
16421566 case HWTSTAMP_FILTER_PTP_V1_L4_DELAY_REQ:
16431567 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV4ENA, 1);
16441568 XGMAC_SET_BITS(mac_tscr, MAC_TSCR, TSIPV6ENA, 1);
....@@ -1777,13 +1701,8 @@
17771701 return 0;
17781702 }
17791703
1780
-static bool xgbe_is_vxlan(struct xgbe_prv_data *pdata, struct sk_buff *skb)
1704
+static bool xgbe_is_vxlan(struct sk_buff *skb)
17811705 {
1782
- struct xgbe_vxlan_data *vdata;
1783
-
1784
- if (pdata->vxlan_force_disable)
1785
- return false;
1786
-
17871706 if (!skb->encapsulation)
17881707 return false;
17891708
....@@ -1805,19 +1724,13 @@
18051724 return false;
18061725 }
18071726
1808
- /* See if we have the UDP port in our list */
1809
- list_for_each_entry(vdata, &pdata->vxlan_ports, list) {
1810
- if ((skb->protocol == htons(ETH_P_IP)) &&
1811
- (vdata->sa_family == AF_INET) &&
1812
- (vdata->port == udp_hdr(skb)->dest))
1813
- return true;
1814
- else if ((skb->protocol == htons(ETH_P_IPV6)) &&
1815
- (vdata->sa_family == AF_INET6) &&
1816
- (vdata->port == udp_hdr(skb)->dest))
1817
- return true;
1818
- }
1727
+ if (skb->inner_protocol_type != ENCAP_TYPE_ETHER ||
1728
+ skb->inner_protocol != htons(ETH_P_TEB) ||
1729
+ (skb_inner_mac_header(skb) - skb_transport_header(skb) !=
1730
+ sizeof(struct udphdr) + sizeof(struct vxlanhdr)))
1731
+ return false;
18191732
1820
- return false;
1733
+ return true;
18211734 }
18221735
18231736 static int xgbe_is_tso(struct sk_buff *skb)
....@@ -1837,7 +1750,7 @@
18371750 struct xgbe_ring *ring, struct sk_buff *skb,
18381751 struct xgbe_packet_data *packet)
18391752 {
1840
- struct skb_frag_struct *frag;
1753
+ skb_frag_t *frag;
18411754 unsigned int context_desc;
18421755 unsigned int len;
18431756 unsigned int i;
....@@ -1868,7 +1781,7 @@
18681781 XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
18691782 CSUM_ENABLE, 1);
18701783
1871
- if (xgbe_is_vxlan(pdata, skb))
1784
+ if (xgbe_is_vxlan(skb))
18721785 XGMAC_SET_BITS(packet->attributes, TX_PACKET_ATTRIBUTES,
18731786 VXLAN, 1);
18741787
....@@ -2156,7 +2069,7 @@
21562069 return 0;
21572070 }
21582071
2159
-static void xgbe_tx_timeout(struct net_device *netdev)
2072
+static void xgbe_tx_timeout(struct net_device *netdev, unsigned int txqueue)
21602073 {
21612074 struct xgbe_prv_data *pdata = netdev_priv(netdev);
21622075
....@@ -2275,23 +2188,12 @@
22752188 netdev_features_t features)
22762189 {
22772190 struct xgbe_prv_data *pdata = netdev_priv(netdev);
2278
- netdev_features_t vxlan_base, vxlan_mask;
2191
+ netdev_features_t vxlan_base;
22792192
22802193 vxlan_base = NETIF_F_GSO_UDP_TUNNEL | NETIF_F_RX_UDP_TUNNEL_PORT;
2281
- vxlan_mask = vxlan_base | NETIF_F_GSO_UDP_TUNNEL_CSUM;
22822194
2283
- pdata->vxlan_features = features & vxlan_mask;
2284
-
2285
- /* Only fix VXLAN-related features */
2286
- if (!pdata->vxlan_features)
2287
- return features;
2288
-
2289
- /* If VXLAN isn't supported then clear any features:
2290
- * This is needed because NETIF_F_RX_UDP_TUNNEL_PORT gets
2291
- * automatically set if ndo_udp_tunnel_add is set.
2292
- */
22932195 if (!pdata->hw_feat.vxn)
2294
- return features & ~vxlan_mask;
2196
+ return features;
22952197
22962198 /* VXLAN CSUM requires VXLAN base */
22972199 if ((features & NETIF_F_GSO_UDP_TUNNEL_CSUM) &&
....@@ -2322,15 +2224,6 @@
23222224 }
23232225 }
23242226
2325
- pdata->vxlan_features = features & vxlan_mask;
2326
-
2327
- /* Adjust UDP Tunnel based on current state */
2328
- if (pdata->vxlan_force_disable) {
2329
- netdev_notice(netdev,
2330
- "VXLAN acceleration disabled, turning off udp tunnel features\n");
2331
- features &= ~vxlan_mask;
2332
- }
2333
-
23342227 return features;
23352228 }
23362229
....@@ -2340,14 +2233,12 @@
23402233 struct xgbe_prv_data *pdata = netdev_priv(netdev);
23412234 struct xgbe_hw_if *hw_if = &pdata->hw_if;
23422235 netdev_features_t rxhash, rxcsum, rxvlan, rxvlan_filter;
2343
- netdev_features_t udp_tunnel;
23442236 int ret = 0;
23452237
23462238 rxhash = pdata->netdev_features & NETIF_F_RXHASH;
23472239 rxcsum = pdata->netdev_features & NETIF_F_RXCSUM;
23482240 rxvlan = pdata->netdev_features & NETIF_F_HW_VLAN_CTAG_RX;
23492241 rxvlan_filter = pdata->netdev_features & NETIF_F_HW_VLAN_CTAG_FILTER;
2350
- udp_tunnel = pdata->netdev_features & NETIF_F_GSO_UDP_TUNNEL;
23512242
23522243 if ((features & NETIF_F_RXHASH) && !rxhash)
23532244 ret = hw_if->enable_rss(pdata);
....@@ -2371,111 +2262,11 @@
23712262 else if (!(features & NETIF_F_HW_VLAN_CTAG_FILTER) && rxvlan_filter)
23722263 hw_if->disable_rx_vlan_filtering(pdata);
23732264
2374
- if ((features & NETIF_F_GSO_UDP_TUNNEL) && !udp_tunnel)
2375
- xgbe_enable_vxlan_accel(pdata);
2376
- else if (!(features & NETIF_F_GSO_UDP_TUNNEL) && udp_tunnel)
2377
- xgbe_disable_vxlan_accel(pdata);
2378
-
23792265 pdata->netdev_features = features;
23802266
23812267 DBGPR("<--xgbe_set_features\n");
23822268
23832269 return 0;
2384
-}
2385
-
2386
-static void xgbe_udp_tunnel_add(struct net_device *netdev,
2387
- struct udp_tunnel_info *ti)
2388
-{
2389
- struct xgbe_prv_data *pdata = netdev_priv(netdev);
2390
- struct xgbe_vxlan_data *vdata;
2391
-
2392
- if (!pdata->hw_feat.vxn)
2393
- return;
2394
-
2395
- if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
2396
- return;
2397
-
2398
- pdata->vxlan_port_count++;
2399
-
2400
- netif_dbg(pdata, drv, netdev,
2401
- "adding VXLAN tunnel, family=%hx/port=%hx\n",
2402
- ti->sa_family, be16_to_cpu(ti->port));
2403
-
2404
- if (pdata->vxlan_force_disable)
2405
- return;
2406
-
2407
- vdata = kzalloc(sizeof(*vdata), GFP_ATOMIC);
2408
- if (!vdata) {
2409
- /* Can no longer properly track VXLAN ports */
2410
- pdata->vxlan_force_disable = 1;
2411
- netif_dbg(pdata, drv, netdev,
2412
- "internal error, disabling VXLAN accelerations\n");
2413
-
2414
- xgbe_disable_vxlan_accel(pdata);
2415
-
2416
- return;
2417
- }
2418
- vdata->sa_family = ti->sa_family;
2419
- vdata->port = ti->port;
2420
-
2421
- list_add_tail(&vdata->list, &pdata->vxlan_ports);
2422
-
2423
- /* First port added? */
2424
- if (pdata->vxlan_port_count == 1) {
2425
- xgbe_enable_vxlan_accel(pdata);
2426
-
2427
- return;
2428
- }
2429
-}
2430
-
2431
-static void xgbe_udp_tunnel_del(struct net_device *netdev,
2432
- struct udp_tunnel_info *ti)
2433
-{
2434
- struct xgbe_prv_data *pdata = netdev_priv(netdev);
2435
- struct xgbe_vxlan_data *vdata;
2436
-
2437
- if (!pdata->hw_feat.vxn)
2438
- return;
2439
-
2440
- if (ti->type != UDP_TUNNEL_TYPE_VXLAN)
2441
- return;
2442
-
2443
- netif_dbg(pdata, drv, netdev,
2444
- "deleting VXLAN tunnel, family=%hx/port=%hx\n",
2445
- ti->sa_family, be16_to_cpu(ti->port));
2446
-
2447
- /* Don't need safe version since loop terminates with deletion */
2448
- list_for_each_entry(vdata, &pdata->vxlan_ports, list) {
2449
- if (vdata->sa_family != ti->sa_family)
2450
- continue;
2451
-
2452
- if (vdata->port != ti->port)
2453
- continue;
2454
-
2455
- list_del(&vdata->list);
2456
- kfree(vdata);
2457
-
2458
- break;
2459
- }
2460
-
2461
- pdata->vxlan_port_count--;
2462
- if (!pdata->vxlan_port_count) {
2463
- xgbe_reset_vxlan_accel(pdata);
2464
-
2465
- return;
2466
- }
2467
-
2468
- if (pdata->vxlan_force_disable)
2469
- return;
2470
-
2471
- /* See if VXLAN tunnel id needs to be changed */
2472
- vdata = list_first_entry(&pdata->vxlan_ports,
2473
- struct xgbe_vxlan_data, list);
2474
- if (pdata->vxlan_port == be16_to_cpu(vdata->port))
2475
- return;
2476
-
2477
- pdata->vxlan_port = be16_to_cpu(vdata->port);
2478
- pdata->hw_if.set_vxlan_id(pdata);
24792270 }
24802271
24812272 static netdev_features_t xgbe_features_check(struct sk_buff *skb,
....@@ -2507,8 +2298,8 @@
25072298 .ndo_setup_tc = xgbe_setup_tc,
25082299 .ndo_fix_features = xgbe_fix_features,
25092300 .ndo_set_features = xgbe_set_features,
2510
- .ndo_udp_tunnel_add = xgbe_udp_tunnel_add,
2511
- .ndo_udp_tunnel_del = xgbe_udp_tunnel_del,
2301
+ .ndo_udp_tunnel_add = udp_tunnel_nic_add_port,
2302
+ .ndo_udp_tunnel_del = udp_tunnel_nic_del_port,
25122303 .ndo_features_check = xgbe_features_check,
25132304 };
25142305