hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/net/ethernet/intel/igc/igc_main.c
....@@ -600,7 +600,6 @@
600600 /* disable the queue */
601601 wr32(IGC_TXDCTL(reg_idx), 0);
602602 wrfl();
603
- mdelay(10);
604603
605604 wr32(IGC_TDLEN(reg_idx),
606605 ring->count * sizeof(union igc_adv_tx_desc));
....@@ -898,25 +897,118 @@
898897 return netdev_mc_count(netdev);
899898 }
900899
901
-static __le32 igc_tx_launchtime(struct igc_adapter *adapter, ktime_t txtime)
900
+static __le32 igc_tx_launchtime(struct igc_ring *ring, ktime_t txtime,
901
+ bool *first_flag, bool *insert_empty)
902902 {
903
+ struct igc_adapter *adapter = netdev_priv(ring->netdev);
903904 ktime_t cycle_time = adapter->cycle_time;
904905 ktime_t base_time = adapter->base_time;
905
- u32 launchtime;
906
+ ktime_t now = ktime_get_clocktai();
907
+ ktime_t baset_est, end_of_cycle;
908
+ s32 launchtime;
909
+ s64 n;
906910
907
- /* FIXME: when using ETF together with taprio, we may have a
908
- * case where 'delta' is larger than the cycle_time, this may
909
- * cause problems if we don't read the current value of
910
- * IGC_BASET, as the value writen into the launchtime
911
- * descriptor field may be misinterpreted.
911
+ n = div64_s64(ktime_sub_ns(now, base_time), cycle_time);
912
+
913
+ baset_est = ktime_add_ns(base_time, cycle_time * (n));
914
+ end_of_cycle = ktime_add_ns(baset_est, cycle_time);
915
+
916
+ if (ktime_compare(txtime, end_of_cycle) >= 0) {
917
+ if (baset_est != ring->last_ff_cycle) {
918
+ *first_flag = true;
919
+ ring->last_ff_cycle = baset_est;
920
+
921
+ if (ktime_compare(end_of_cycle, ring->last_tx_cycle) > 0)
922
+ *insert_empty = true;
923
+ }
924
+ }
925
+
926
+ /* Introducing a window at end of cycle on which packets
927
+ * potentially not honor launchtime. Window of 5us chosen
928
+ * considering software update the tail pointer and packets
929
+ * are dma'ed to packet buffer.
912930 */
913
- div_s64_rem(ktime_sub_ns(txtime, base_time), cycle_time, &launchtime);
931
+ if ((ktime_sub_ns(end_of_cycle, now) < 5 * NSEC_PER_USEC))
932
+ netdev_warn(ring->netdev, "Packet with txtime=%llu may not be honoured\n",
933
+ txtime);
934
+
935
+ ring->last_tx_cycle = end_of_cycle;
936
+
937
+ launchtime = ktime_sub_ns(txtime, baset_est);
938
+ if (launchtime > 0)
939
+ div_s64_rem(launchtime, cycle_time, &launchtime);
940
+ else
941
+ launchtime = 0;
914942
915943 return cpu_to_le32(launchtime);
916944 }
917945
946
+static int igc_init_empty_frame(struct igc_ring *ring,
947
+ struct igc_tx_buffer *buffer,
948
+ struct sk_buff *skb)
949
+{
950
+ unsigned int size;
951
+ dma_addr_t dma;
952
+
953
+ size = skb_headlen(skb);
954
+
955
+ dma = dma_map_single(ring->dev, skb->data, size, DMA_TO_DEVICE);
956
+ if (dma_mapping_error(ring->dev, dma)) {
957
+ netdev_err_once(ring->netdev, "Failed to map DMA for TX\n");
958
+ return -ENOMEM;
959
+ }
960
+
961
+ buffer->skb = skb;
962
+ buffer->protocol = 0;
963
+ buffer->bytecount = skb->len;
964
+ buffer->gso_segs = 1;
965
+ buffer->time_stamp = jiffies;
966
+ dma_unmap_len_set(buffer, len, skb->len);
967
+ dma_unmap_addr_set(buffer, dma, dma);
968
+
969
+ return 0;
970
+}
971
+
972
+static int igc_init_tx_empty_descriptor(struct igc_ring *ring,
973
+ struct sk_buff *skb,
974
+ struct igc_tx_buffer *first)
975
+{
976
+ union igc_adv_tx_desc *desc;
977
+ u32 cmd_type, olinfo_status;
978
+ int err;
979
+
980
+ if (!igc_desc_unused(ring))
981
+ return -EBUSY;
982
+
983
+ err = igc_init_empty_frame(ring, first, skb);
984
+ if (err)
985
+ return err;
986
+
987
+ cmd_type = IGC_ADVTXD_DTYP_DATA | IGC_ADVTXD_DCMD_DEXT |
988
+ IGC_ADVTXD_DCMD_IFCS | IGC_TXD_DCMD |
989
+ first->bytecount;
990
+ olinfo_status = first->bytecount << IGC_ADVTXD_PAYLEN_SHIFT;
991
+
992
+ desc = IGC_TX_DESC(ring, ring->next_to_use);
993
+ desc->read.cmd_type_len = cpu_to_le32(cmd_type);
994
+ desc->read.olinfo_status = cpu_to_le32(olinfo_status);
995
+ desc->read.buffer_addr = cpu_to_le64(dma_unmap_addr(first, dma));
996
+
997
+ netdev_tx_sent_queue(txring_txq(ring), skb->len);
998
+
999
+ first->next_to_watch = desc;
1000
+
1001
+ ring->next_to_use++;
1002
+ if (ring->next_to_use == ring->count)
1003
+ ring->next_to_use = 0;
1004
+
1005
+ return 0;
1006
+}
1007
+
1008
+#define IGC_EMPTY_FRAME_SIZE 60
1009
+
9181010 static void igc_tx_ctxtdesc(struct igc_ring *tx_ring,
919
- struct igc_tx_buffer *first,
1011
+ __le32 launch_time, bool first_flag,
9201012 u32 vlan_macip_lens, u32 type_tucmd,
9211013 u32 mss_l4len_idx)
9221014 {
....@@ -935,35 +1027,17 @@
9351027 if (test_bit(IGC_RING_FLAG_TX_CTX_IDX, &tx_ring->flags))
9361028 mss_l4len_idx |= tx_ring->reg_idx << 4;
9371029
1030
+ if (first_flag)
1031
+ mss_l4len_idx |= IGC_ADVTXD_TSN_CNTX_FIRST;
1032
+
9381033 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
9391034 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
9401035 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
941
-
942
- /* We assume there is always a valid Tx time available. Invalid times
943
- * should have been handled by the upper layers.
944
- */
945
- if (tx_ring->launchtime_enable) {
946
- struct igc_adapter *adapter = netdev_priv(tx_ring->netdev);
947
- ktime_t txtime = first->skb->tstamp;
948
-
949
- first->skb->tstamp = ktime_set(0, 0);
950
- context_desc->launch_time = igc_tx_launchtime(adapter,
951
- txtime);
952
- } else {
953
- context_desc->launch_time = 0;
954
- }
1036
+ context_desc->launch_time = launch_time;
9551037 }
9561038
957
-static inline bool igc_ipv6_csum_is_sctp(struct sk_buff *skb)
958
-{
959
- unsigned int offset = 0;
960
-
961
- ipv6_find_hdr(skb, &offset, IPPROTO_SCTP, NULL, NULL);
962
-
963
- return offset == skb_checksum_start_offset(skb);
964
-}
965
-
966
-static void igc_tx_csum(struct igc_ring *tx_ring, struct igc_tx_buffer *first)
1039
+static void igc_tx_csum(struct igc_ring *tx_ring, struct igc_tx_buffer *first,
1040
+ __le32 launch_time, bool first_flag)
9671041 {
9681042 struct sk_buff *skb = first->skb;
9691043 u32 vlan_macip_lens = 0;
....@@ -985,10 +1059,7 @@
9851059 break;
9861060 case offsetof(struct sctphdr, checksum):
9871061 /* validate that this is actually an SCTP request */
988
- if ((first->protocol == htons(ETH_P_IP) &&
989
- (ip_hdr(skb)->protocol == IPPROTO_SCTP)) ||
990
- (first->protocol == htons(ETH_P_IPV6) &&
991
- igc_ipv6_csum_is_sctp(skb))) {
1062
+ if (skb_csum_is_sctp(skb)) {
9921063 type_tucmd = IGC_ADVTXD_TUCMD_L4T_SCTP;
9931064 break;
9941065 }
....@@ -1006,7 +1077,8 @@
10061077 vlan_macip_lens |= skb_network_offset(skb) << IGC_ADVTXD_MACLEN_SHIFT;
10071078 vlan_macip_lens |= first->tx_flags & IGC_TX_FLAGS_VLAN_MASK;
10081079
1009
- igc_tx_ctxtdesc(tx_ring, first, vlan_macip_lens, type_tucmd, 0);
1080
+ igc_tx_ctxtdesc(tx_ring, launch_time, first_flag,
1081
+ vlan_macip_lens, type_tucmd, 0);
10101082 }
10111083
10121084 static int __igc_maybe_stop_tx(struct igc_ring *tx_ring, const u16 size)
....@@ -1230,6 +1302,7 @@
12301302
12311303 static int igc_tso(struct igc_ring *tx_ring,
12321304 struct igc_tx_buffer *first,
1305
+ __le32 launch_time, bool first_flag,
12331306 u8 *hdr_len)
12341307 {
12351308 u32 vlan_macip_lens, type_tucmd, mss_l4len_idx;
....@@ -1316,8 +1389,8 @@
13161389 vlan_macip_lens |= (ip.hdr - skb->data) << IGC_ADVTXD_MACLEN_SHIFT;
13171390 vlan_macip_lens |= first->tx_flags & IGC_TX_FLAGS_VLAN_MASK;
13181391
1319
- igc_tx_ctxtdesc(tx_ring, first, vlan_macip_lens,
1320
- type_tucmd, mss_l4len_idx);
1392
+ igc_tx_ctxtdesc(tx_ring, launch_time, first_flag,
1393
+ vlan_macip_lens, type_tucmd, mss_l4len_idx);
13211394
13221395 return 1;
13231396 }
....@@ -1325,11 +1398,14 @@
13251398 static netdev_tx_t igc_xmit_frame_ring(struct sk_buff *skb,
13261399 struct igc_ring *tx_ring)
13271400 {
1401
+ bool first_flag = false, insert_empty = false;
13281402 u16 count = TXD_USE_COUNT(skb_headlen(skb));
13291403 __be16 protocol = vlan_get_protocol(skb);
13301404 struct igc_tx_buffer *first;
1405
+ __le32 launch_time = 0;
13311406 u32 tx_flags = 0;
13321407 unsigned short f;
1408
+ ktime_t txtime;
13331409 u8 hdr_len = 0;
13341410 int tso = 0;
13351411
....@@ -1343,11 +1419,40 @@
13431419 count += TXD_USE_COUNT(skb_frag_size(
13441420 &skb_shinfo(skb)->frags[f]));
13451421
1346
- if (igc_maybe_stop_tx(tx_ring, count + 3)) {
1422
+ if (igc_maybe_stop_tx(tx_ring, count + 5)) {
13471423 /* this is a hard error */
13481424 return NETDEV_TX_BUSY;
13491425 }
13501426
1427
+ if (!tx_ring->launchtime_enable)
1428
+ goto done;
1429
+
1430
+ txtime = skb->tstamp;
1431
+ skb->tstamp = ktime_set(0, 0);
1432
+ launch_time = igc_tx_launchtime(tx_ring, txtime, &first_flag, &insert_empty);
1433
+
1434
+ if (insert_empty) {
1435
+ struct igc_tx_buffer *empty_info;
1436
+ struct sk_buff *empty;
1437
+ void *data;
1438
+
1439
+ empty_info = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
1440
+ empty = alloc_skb(IGC_EMPTY_FRAME_SIZE, GFP_ATOMIC);
1441
+ if (!empty)
1442
+ goto done;
1443
+
1444
+ data = skb_put(empty, IGC_EMPTY_FRAME_SIZE);
1445
+ memset(data, 0, IGC_EMPTY_FRAME_SIZE);
1446
+
1447
+ igc_tx_ctxtdesc(tx_ring, 0, false, 0, 0, 0);
1448
+
1449
+ if (igc_init_tx_empty_descriptor(tx_ring,
1450
+ empty,
1451
+ empty_info) < 0)
1452
+ dev_kfree_skb_any(empty);
1453
+ }
1454
+
1455
+done:
13511456 /* record the location of the first descriptor for this packet */
13521457 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
13531458 first->skb = skb;
....@@ -1361,9 +1466,10 @@
13611466 * the other timer registers before skipping the
13621467 * timestamping request.
13631468 */
1364
- if (adapter->tstamp_config.tx_type == HWTSTAMP_TX_ON &&
1365
- !test_and_set_bit_lock(__IGC_PTP_TX_IN_PROGRESS,
1366
- &adapter->state)) {
1469
+ unsigned long flags;
1470
+
1471
+ spin_lock_irqsave(&adapter->ptp_tx_lock, flags);
1472
+ if (adapter->tstamp_config.tx_type == HWTSTAMP_TX_ON && !adapter->ptp_tx_skb) {
13671473 skb_shinfo(skb)->tx_flags |= SKBTX_IN_PROGRESS;
13681474 tx_flags |= IGC_TX_FLAGS_TSTAMP;
13691475
....@@ -1372,17 +1478,19 @@
13721478 } else {
13731479 adapter->tx_hwtstamp_skipped++;
13741480 }
1481
+
1482
+ spin_unlock_irqrestore(&adapter->ptp_tx_lock, flags);
13751483 }
13761484
13771485 /* record initial flags and protocol */
13781486 first->tx_flags = tx_flags;
13791487 first->protocol = protocol;
13801488
1381
- tso = igc_tso(tx_ring, first, &hdr_len);
1489
+ tso = igc_tso(tx_ring, first, launch_time, first_flag, &hdr_len);
13821490 if (tso < 0)
13831491 goto out_drop;
13841492 else if (!tso)
1385
- igc_tx_csum(tx_ring, first);
1493
+ igc_tx_csum(tx_ring, first, launch_time, first_flag);
13861494
13871495 igc_tx_map(tx_ring, first, hdr_len);
13881496
....@@ -1463,14 +1571,36 @@
14631571 le32_to_cpu(rx_desc->wb.upper.status_error));
14641572 }
14651573
1574
+/* Mapping HW RSS Type to enum pkt_hash_types */
1575
+static const enum pkt_hash_types igc_rss_type_table[IGC_RSS_TYPE_MAX_TABLE] = {
1576
+ [IGC_RSS_TYPE_NO_HASH] = PKT_HASH_TYPE_L2,
1577
+ [IGC_RSS_TYPE_HASH_TCP_IPV4] = PKT_HASH_TYPE_L4,
1578
+ [IGC_RSS_TYPE_HASH_IPV4] = PKT_HASH_TYPE_L3,
1579
+ [IGC_RSS_TYPE_HASH_TCP_IPV6] = PKT_HASH_TYPE_L4,
1580
+ [IGC_RSS_TYPE_HASH_IPV6_EX] = PKT_HASH_TYPE_L3,
1581
+ [IGC_RSS_TYPE_HASH_IPV6] = PKT_HASH_TYPE_L3,
1582
+ [IGC_RSS_TYPE_HASH_TCP_IPV6_EX] = PKT_HASH_TYPE_L4,
1583
+ [IGC_RSS_TYPE_HASH_UDP_IPV4] = PKT_HASH_TYPE_L4,
1584
+ [IGC_RSS_TYPE_HASH_UDP_IPV6] = PKT_HASH_TYPE_L4,
1585
+ [IGC_RSS_TYPE_HASH_UDP_IPV6_EX] = PKT_HASH_TYPE_L4,
1586
+ [10] = PKT_HASH_TYPE_NONE, /* RSS Type above 9 "Reserved" by HW */
1587
+ [11] = PKT_HASH_TYPE_NONE, /* keep array sized for SW bit-mask */
1588
+ [12] = PKT_HASH_TYPE_NONE, /* to handle future HW revisons */
1589
+ [13] = PKT_HASH_TYPE_NONE,
1590
+ [14] = PKT_HASH_TYPE_NONE,
1591
+ [15] = PKT_HASH_TYPE_NONE,
1592
+};
1593
+
14661594 static inline void igc_rx_hash(struct igc_ring *ring,
14671595 union igc_adv_rx_desc *rx_desc,
14681596 struct sk_buff *skb)
14691597 {
1470
- if (ring->netdev->features & NETIF_F_RXHASH)
1471
- skb_set_hash(skb,
1472
- le32_to_cpu(rx_desc->wb.lower.hi_dword.rss),
1473
- PKT_HASH_TYPE_L3);
1598
+ if (ring->netdev->features & NETIF_F_RXHASH) {
1599
+ u32 rss_hash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
1600
+ u32 rss_type = igc_rss_type(rx_desc);
1601
+
1602
+ skb_set_hash(skb, rss_hash, igc_rss_type_table[rss_type]);
1603
+ }
14741604 }
14751605
14761606 /**
....@@ -4756,9 +4886,10 @@
47564886 return false;
47574887
47584888 for (n = 0; n < qopt->num_entries; n++) {
4759
- const struct tc_taprio_sched_entry *e;
4889
+ const struct tc_taprio_sched_entry *e, *prev;
47604890 int i;
47614891
4892
+ prev = n ? &qopt->entries[n - 1] : NULL;
47624893 e = &qopt->entries[n];
47634894
47644895 /* i225 only supports "global" frame preemption
....@@ -4767,13 +4898,18 @@
47674898 if (e->command != TC_TAPRIO_CMD_SET_GATES)
47684899 return false;
47694900
4770
- for (i = 0; i < adapter->num_tx_queues; i++) {
4771
- if (e->gate_mask & BIT(i))
4901
+ for (i = 0; i < adapter->num_tx_queues; i++)
4902
+ if (e->gate_mask & BIT(i)) {
47724903 queue_uses[i]++;
47734904
4774
- if (queue_uses[i] > 1)
4775
- return false;
4776
- }
4905
+ /* There are limitations: A single queue cannot
4906
+ * be opened and closed multiple times per cycle
4907
+ * unless the gate stays open. Check for it.
4908
+ */
4909
+ if (queue_uses[i] > 1 &&
4910
+ !(prev->gate_mask & BIT(i)))
4911
+ return false;
4912
+ }
47774913 }
47784914
47794915 return true;
....@@ -4798,13 +4934,18 @@
47984934 static int igc_save_qbv_schedule(struct igc_adapter *adapter,
47994935 struct tc_taprio_qopt_offload *qopt)
48004936 {
4937
+ bool queue_configured[IGC_MAX_TX_QUEUES] = { };
48014938 u32 start_time = 0, end_time = 0;
48024939 size_t n;
4940
+ int i;
48034941
48044942 if (!qopt->enable) {
48054943 adapter->base_time = 0;
48064944 return 0;
48074945 }
4946
+
4947
+ if (qopt->base_time < 0)
4948
+ return -ERANGE;
48084949
48094950 if (adapter->base_time)
48104951 return -EALREADY;
....@@ -4815,14 +4956,25 @@
48154956 adapter->cycle_time = qopt->cycle_time;
48164957 adapter->base_time = qopt->base_time;
48174958
4818
- /* FIXME: be a little smarter about cases when the gate for a
4819
- * queue stays open for more than one entry.
4820
- */
48214959 for (n = 0; n < qopt->num_entries; n++) {
48224960 struct tc_taprio_sched_entry *e = &qopt->entries[n];
4823
- int i;
48244961
48254962 end_time += e->interval;
4963
+
4964
+ /* If any of the conditions below are true, we need to manually
4965
+ * control the end time of the cycle.
4966
+ * 1. Qbv users can specify a cycle time that is not equal
4967
+ * to the total GCL intervals. Hence, recalculation is
4968
+ * necessary here to exclude the time interval that
4969
+ * exceeds the cycle time.
4970
+ * 2. According to IEEE Std. 802.1Q-2018 section 8.6.9.2,
4971
+ * once the end of the list is reached, it will switch
4972
+ * to the END_OF_CYCLE state and leave the gates in the
4973
+ * same state until the next cycle is started.
4974
+ */
4975
+ if (end_time > adapter->cycle_time ||
4976
+ n + 1 == qopt->num_entries)
4977
+ end_time = adapter->cycle_time;
48264978
48274979 for (i = 0; i < adapter->num_tx_queues; i++) {
48284980 struct igc_ring *ring = adapter->tx_ring[i];
....@@ -4830,11 +4982,30 @@
48304982 if (!(e->gate_mask & BIT(i)))
48314983 continue;
48324984
4833
- ring->start_time = start_time;
4985
+ /* Check whether a queue stays open for more than one
4986
+ * entry. If so, keep the start and advance the end
4987
+ * time.
4988
+ */
4989
+ if (!queue_configured[i])
4990
+ ring->start_time = start_time;
48344991 ring->end_time = end_time;
4992
+
4993
+ queue_configured[i] = true;
48354994 }
48364995
48374996 start_time += e->interval;
4997
+ }
4998
+
4999
+ /* Check whether a queue gets configured.
5000
+ * If not, set the start and end time to be end time.
5001
+ */
5002
+ for (i = 0; i < adapter->num_tx_queues; i++) {
5003
+ if (!queue_configured[i]) {
5004
+ struct igc_ring *ring = adapter->tx_ring[i];
5005
+
5006
+ ring->start_time = end_time;
5007
+ ring->end_time = end_time;
5008
+ }
48385009 }
48395010
48405011 return 0;
....@@ -5110,6 +5281,7 @@
51105281 netdev->features |= NETIF_F_TSO;
51115282 netdev->features |= NETIF_F_TSO6;
51125283 netdev->features |= NETIF_F_TSO_ECN;
5284
+ netdev->features |= NETIF_F_RXHASH;
51135285 netdev->features |= NETIF_F_RXCSUM;
51145286 netdev->features |= NETIF_F_HW_CSUM;
51155287 netdev->features |= NETIF_F_SCTP_CRC;