Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge branch '1GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/net-queue

Tony Nguyen says:

====================
Intel Wired LAN Driver Updates 2022-12-15 (igc)

Muhammad Husaini Zulkifli says:

This patch series fixes bugs for the Time-Sensitive Networking(TSN)
Qbv Scheduling features.

An overview of each patch series is given below:

Patch 1: Using a first flag bit to schedule a packet to the next cycle if
packet cannot fit in current Qbv cycle.
Patch 2: Enable strict cycle for Qbv scheduling.
Patch 3: Prevent user to set basetime less than zero during tc config.
Patch 4: Allow the basetime enrollment with zero value.
Patch 5: Calculate the new end time value to exclude the time interval that
exceed the cycle time as user can specify the cycle time in tc config.
Patch 6: Resolve the HW bugs where the gate is not fully closed.
---
This contains the net patches from this original pull request:
https://lore.kernel.org/netdev/20221205212414.3197525-1-anthony.l.nguyen@intel.com/

====================

Signed-off-by: David S. Miller <davem@davemloft.net>

+188 -40
+3
drivers/net/ethernet/intel/igc/igc.h
··· 94 94 u8 queue_index; /* logical index of the ring*/ 95 95 u8 reg_idx; /* physical index of the ring */ 96 96 bool launchtime_enable; /* true if LaunchTime is enabled */ 97 + ktime_t last_tx_cycle; /* end of the cycle with a launchtime transmission */ 98 + ktime_t last_ff_cycle; /* Last cycle with an active first flag */ 97 99 98 100 u32 start_time; 99 101 u32 end_time; ··· 184 182 185 183 ktime_t base_time; 186 184 ktime_t cycle_time; 185 + bool qbv_enable; 187 186 188 187 /* OS defined structs */ 189 188 struct pci_dev *pdev;
+2
drivers/net/ethernet/intel/igc/igc_defines.h
··· 321 321 #define IGC_ADVTXD_L4LEN_SHIFT 8 /* Adv ctxt L4LEN shift */ 322 322 #define IGC_ADVTXD_MSS_SHIFT 16 /* Adv ctxt MSS shift */ 323 323 324 + #define IGC_ADVTXD_TSN_CNTX_FIRST 0x00000080 325 + 324 326 /* Transmit Control */ 325 327 #define IGC_TCTL_EN 0x00000002 /* enable Tx */ 326 328 #define IGC_TCTL_PSP 0x00000008 /* pad short packets */
+180 -30
drivers/net/ethernet/intel/igc/igc_main.c
··· 1000 1000 return netdev_mc_count(netdev); 1001 1001 } 1002 1002 1003 - static __le32 igc_tx_launchtime(struct igc_adapter *adapter, ktime_t txtime) 1003 + static __le32 igc_tx_launchtime(struct igc_ring *ring, ktime_t txtime, 1004 + bool *first_flag, bool *insert_empty) 1004 1005 { 1006 + struct igc_adapter *adapter = netdev_priv(ring->netdev); 1005 1007 ktime_t cycle_time = adapter->cycle_time; 1006 1008 ktime_t base_time = adapter->base_time; 1009 + ktime_t now = ktime_get_clocktai(); 1010 + ktime_t baset_est, end_of_cycle; 1007 1011 u32 launchtime; 1012 + s64 n; 1008 1013 1009 - /* FIXME: when using ETF together with taprio, we may have a 1010 - * case where 'delta' is larger than the cycle_time, this may 1011 - * cause problems if we don't read the current value of 1012 - * IGC_BASET, as the value writen into the launchtime 1013 - * descriptor field may be misinterpreted. 1014 + n = div64_s64(ktime_sub_ns(now, base_time), cycle_time); 1015 + 1016 + baset_est = ktime_add_ns(base_time, cycle_time * (n)); 1017 + end_of_cycle = ktime_add_ns(baset_est, cycle_time); 1018 + 1019 + if (ktime_compare(txtime, end_of_cycle) >= 0) { 1020 + if (baset_est != ring->last_ff_cycle) { 1021 + *first_flag = true; 1022 + ring->last_ff_cycle = baset_est; 1023 + 1024 + if (ktime_compare(txtime, ring->last_tx_cycle) > 0) 1025 + *insert_empty = true; 1026 + } 1027 + } 1028 + 1029 + /* Introducing a window at end of cycle on which packets 1030 + * potentially not honor launchtime. Window of 5us chosen 1031 + * considering software update the tail pointer and packets 1032 + * are dma'ed to packet buffer. 1014 1033 */ 1015 - div_s64_rem(ktime_sub_ns(txtime, base_time), cycle_time, &launchtime); 1034 + if ((ktime_sub_ns(end_of_cycle, now) < 5 * NSEC_PER_USEC)) 1035 + netdev_warn(ring->netdev, "Packet with txtime=%llu may not be honoured\n", 1036 + txtime); 1037 + 1038 + ring->last_tx_cycle = end_of_cycle; 1039 + 1040 + launchtime = ktime_sub_ns(txtime, baset_est); 1041 + if (launchtime > 0) 1042 + div_s64_rem(launchtime, cycle_time, &launchtime); 1043 + else 1044 + launchtime = 0; 1016 1045 1017 1046 return cpu_to_le32(launchtime); 1018 1047 } 1019 1048 1049 + static int igc_init_empty_frame(struct igc_ring *ring, 1050 + struct igc_tx_buffer *buffer, 1051 + struct sk_buff *skb) 1052 + { 1053 + unsigned int size; 1054 + dma_addr_t dma; 1055 + 1056 + size = skb_headlen(skb); 1057 + 1058 + dma = dma_map_single(ring->dev, skb->data, size, DMA_TO_DEVICE); 1059 + if (dma_mapping_error(ring->dev, dma)) { 1060 + netdev_err_once(ring->netdev, "Failed to map DMA for TX\n"); 1061 + return -ENOMEM; 1062 + } 1063 + 1064 + buffer->skb = skb; 1065 + buffer->protocol = 0; 1066 + buffer->bytecount = skb->len; 1067 + buffer->gso_segs = 1; 1068 + buffer->time_stamp = jiffies; 1069 + dma_unmap_len_set(buffer, len, skb->len); 1070 + dma_unmap_addr_set(buffer, dma, dma); 1071 + 1072 + return 0; 1073 + } 1074 + 1075 + static int igc_init_tx_empty_descriptor(struct igc_ring *ring, 1076 + struct sk_buff *skb, 1077 + struct igc_tx_buffer *first) 1078 + { 1079 + union igc_adv_tx_desc *desc; 1080 + u32 cmd_type, olinfo_status; 1081 + int err; 1082 + 1083 + if (!igc_desc_unused(ring)) 1084 + return -EBUSY; 1085 + 1086 + err = igc_init_empty_frame(ring, first, skb); 1087 + if (err) 1088 + return err; 1089 + 1090 + cmd_type = IGC_ADVTXD_DTYP_DATA | IGC_ADVTXD_DCMD_DEXT | 1091 + IGC_ADVTXD_DCMD_IFCS | IGC_TXD_DCMD | 1092 + first->bytecount; 1093 + olinfo_status = first->bytecount << IGC_ADVTXD_PAYLEN_SHIFT; 1094 + 1095 + desc = IGC_TX_DESC(ring, ring->next_to_use); 1096 + desc->read.cmd_type_len = cpu_to_le32(cmd_type); 1097 + desc->read.olinfo_status = cpu_to_le32(olinfo_status); 1098 + desc->read.buffer_addr = cpu_to_le64(dma_unmap_addr(first, dma)); 1099 + 1100 + netdev_tx_sent_queue(txring_txq(ring), skb->len); 1101 + 1102 + first->next_to_watch = desc; 1103 + 1104 + ring->next_to_use++; 1105 + if (ring->next_to_use == ring->count) 1106 + ring->next_to_use = 0; 1107 + 1108 + return 0; 1109 + } 1110 + 1111 + #define IGC_EMPTY_FRAME_SIZE 60 1112 + 1020 1113 static void igc_tx_ctxtdesc(struct igc_ring *tx_ring, 1021 - struct igc_tx_buffer *first, 1114 + __le32 launch_time, bool first_flag, 1022 1115 u32 vlan_macip_lens, u32 type_tucmd, 1023 1116 u32 mss_l4len_idx) 1024 1117 { ··· 1130 1037 if (test_bit(IGC_RING_FLAG_TX_CTX_IDX, &tx_ring->flags)) 1131 1038 mss_l4len_idx |= tx_ring->reg_idx << 4; 1132 1039 1040 + if (first_flag) 1041 + mss_l4len_idx |= IGC_ADVTXD_TSN_CNTX_FIRST; 1042 + 1133 1043 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); 1134 1044 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd); 1135 1045 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); 1136 - 1137 - /* We assume there is always a valid Tx time available. Invalid times 1138 - * should have been handled by the upper layers. 1139 - */ 1140 - if (tx_ring->launchtime_enable) { 1141 - struct igc_adapter *adapter = netdev_priv(tx_ring->netdev); 1142 - ktime_t txtime = first->skb->tstamp; 1143 - 1144 - skb_txtime_consumed(first->skb); 1145 - context_desc->launch_time = igc_tx_launchtime(adapter, 1146 - txtime); 1147 - } else { 1148 - context_desc->launch_time = 0; 1149 - } 1046 + context_desc->launch_time = launch_time; 1150 1047 } 1151 1048 1152 - static void igc_tx_csum(struct igc_ring *tx_ring, struct igc_tx_buffer *first) 1049 + static void igc_tx_csum(struct igc_ring *tx_ring, struct igc_tx_buffer *first, 1050 + __le32 launch_time, bool first_flag) 1153 1051 { 1154 1052 struct sk_buff *skb = first->skb; 1155 1053 u32 vlan_macip_lens = 0; ··· 1180 1096 vlan_macip_lens |= skb_network_offset(skb) << IGC_ADVTXD_MACLEN_SHIFT; 1181 1097 vlan_macip_lens |= first->tx_flags & IGC_TX_FLAGS_VLAN_MASK; 1182 1098 1183 - igc_tx_ctxtdesc(tx_ring, first, vlan_macip_lens, type_tucmd, 0); 1099 + igc_tx_ctxtdesc(tx_ring, launch_time, first_flag, 1100 + vlan_macip_lens, type_tucmd, 0); 1184 1101 } 1185 1102 1186 1103 static int __igc_maybe_stop_tx(struct igc_ring *tx_ring, const u16 size) ··· 1405 1320 1406 1321 static int igc_tso(struct igc_ring *tx_ring, 1407 1322 struct igc_tx_buffer *first, 1323 + __le32 launch_time, bool first_flag, 1408 1324 u8 *hdr_len) 1409 1325 { 1410 1326 u32 vlan_macip_lens, type_tucmd, mss_l4len_idx; ··· 1492 1406 vlan_macip_lens |= (ip.hdr - skb->data) << IGC_ADVTXD_MACLEN_SHIFT; 1493 1407 vlan_macip_lens |= first->tx_flags & IGC_TX_FLAGS_VLAN_MASK; 1494 1408 1495 - igc_tx_ctxtdesc(tx_ring, first, vlan_macip_lens, 1496 - type_tucmd, mss_l4len_idx); 1409 + igc_tx_ctxtdesc(tx_ring, launch_time, first_flag, 1410 + vlan_macip_lens, type_tucmd, mss_l4len_idx); 1497 1411 1498 1412 return 1; 1499 1413 } ··· 1501 1415 static netdev_tx_t igc_xmit_frame_ring(struct sk_buff *skb, 1502 1416 struct igc_ring *tx_ring) 1503 1417 { 1418 + bool first_flag = false, insert_empty = false; 1504 1419 u16 count = TXD_USE_COUNT(skb_headlen(skb)); 1505 1420 __be16 protocol = vlan_get_protocol(skb); 1506 1421 struct igc_tx_buffer *first; 1422 + __le32 launch_time = 0; 1507 1423 u32 tx_flags = 0; 1508 1424 unsigned short f; 1425 + ktime_t txtime; 1509 1426 u8 hdr_len = 0; 1510 1427 int tso = 0; 1511 1428 ··· 1522 1433 count += TXD_USE_COUNT(skb_frag_size( 1523 1434 &skb_shinfo(skb)->frags[f])); 1524 1435 1525 - if (igc_maybe_stop_tx(tx_ring, count + 3)) { 1436 + if (igc_maybe_stop_tx(tx_ring, count + 5)) { 1526 1437 /* this is a hard error */ 1527 1438 return NETDEV_TX_BUSY; 1528 1439 } 1529 1440 1441 + if (!tx_ring->launchtime_enable) 1442 + goto done; 1443 + 1444 + txtime = skb->tstamp; 1445 + skb->tstamp = ktime_set(0, 0); 1446 + launch_time = igc_tx_launchtime(tx_ring, txtime, &first_flag, &insert_empty); 1447 + 1448 + if (insert_empty) { 1449 + struct igc_tx_buffer *empty_info; 1450 + struct sk_buff *empty; 1451 + void *data; 1452 + 1453 + empty_info = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; 1454 + empty = alloc_skb(IGC_EMPTY_FRAME_SIZE, GFP_ATOMIC); 1455 + if (!empty) 1456 + goto done; 1457 + 1458 + data = skb_put(empty, IGC_EMPTY_FRAME_SIZE); 1459 + memset(data, 0, IGC_EMPTY_FRAME_SIZE); 1460 + 1461 + igc_tx_ctxtdesc(tx_ring, 0, false, 0, 0, 0); 1462 + 1463 + if (igc_init_tx_empty_descriptor(tx_ring, 1464 + empty, 1465 + empty_info) < 0) 1466 + dev_kfree_skb_any(empty); 1467 + } 1468 + 1469 + done: 1530 1470 /* record the location of the first descriptor for this packet */ 1531 1471 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use]; 1532 1472 first->type = IGC_TX_BUFFER_TYPE_SKB; ··· 1592 1474 first->tx_flags = tx_flags; 1593 1475 first->protocol = protocol; 1594 1476 1595 - tso = igc_tso(tx_ring, first, &hdr_len); 1477 + tso = igc_tso(tx_ring, first, launch_time, first_flag, &hdr_len); 1596 1478 if (tso < 0) 1597 1479 goto out_drop; 1598 1480 else if (!tso) 1599 - igc_tx_csum(tx_ring, first); 1481 + igc_tx_csum(tx_ring, first, launch_time, first_flag); 1600 1482 1601 1483 igc_tx_map(tx_ring, first, hdr_len); 1602 1484 ··· 6043 5925 bool queue_configured[IGC_MAX_TX_QUEUES] = { }; 6044 5926 u32 start_time = 0, end_time = 0; 6045 5927 size_t n; 5928 + int i; 5929 + 5930 + adapter->qbv_enable = qopt->enable; 6046 5931 6047 5932 if (!qopt->enable) 6048 5933 return igc_tsn_clear_schedule(adapter); 5934 + 5935 + if (qopt->base_time < 0) 5936 + return -ERANGE; 6049 5937 6050 5938 if (adapter->base_time) 6051 5939 return -EALREADY; ··· 6064 5940 6065 5941 for (n = 0; n < qopt->num_entries; n++) { 6066 5942 struct tc_taprio_sched_entry *e = &qopt->entries[n]; 6067 - int i; 6068 5943 6069 5944 end_time += e->interval; 5945 + 5946 + /* If any of the conditions below are true, we need to manually 5947 + * control the end time of the cycle. 5948 + * 1. Qbv users can specify a cycle time that is not equal 5949 + * to the total GCL intervals. Hence, recalculation is 5950 + * necessary here to exclude the time interval that 5951 + * exceeds the cycle time. 5952 + * 2. According to IEEE Std. 802.1Q-2018 section 8.6.9.2, 5953 + * once the end of the list is reached, it will switch 5954 + * to the END_OF_CYCLE state and leave the gates in the 5955 + * same state until the next cycle is started. 5956 + */ 5957 + if (end_time > adapter->cycle_time || 5958 + n + 1 == qopt->num_entries) 5959 + end_time = adapter->cycle_time; 6070 5960 6071 5961 for (i = 0; i < adapter->num_tx_queues; i++) { 6072 5962 struct igc_ring *ring = adapter->tx_ring[i]; ··· 6100 5962 } 6101 5963 6102 5964 start_time += e->interval; 5965 + } 5966 + 5967 + /* Check whether a queue gets configured. 5968 + * If not, set the start and end time to be end time. 5969 + */ 5970 + for (i = 0; i < adapter->num_tx_queues; i++) { 5971 + if (!queue_configured[i]) { 5972 + struct igc_ring *ring = adapter->tx_ring[i]; 5973 + 5974 + ring->start_time = end_time; 5975 + ring->end_time = end_time; 5976 + } 6103 5977 } 6104 5978 6105 5979 return 0;
+3 -10
drivers/net/ethernet/intel/igc/igc_tsn.c
··· 36 36 { 37 37 unsigned int new_flags = adapter->flags & ~IGC_FLAG_TSN_ANY_ENABLED; 38 38 39 - if (adapter->base_time) 39 + if (adapter->qbv_enable) 40 40 new_flags |= IGC_FLAG_TSN_QBV_ENABLED; 41 41 42 42 if (is_any_launchtime(adapter)) ··· 140 140 wr32(IGC_STQT(i), ring->start_time); 141 141 wr32(IGC_ENDQT(i), ring->end_time); 142 142 143 - if (adapter->base_time) { 144 - /* If we have a base_time we are in "taprio" 145 - * mode and we need to be strict about the 146 - * cycles: only transmit a packet if it can be 147 - * completed during that cycle. 148 - */ 149 - txqctl |= IGC_TXQCTL_STRICT_CYCLE | 150 - IGC_TXQCTL_STRICT_END; 151 - } 143 + txqctl |= IGC_TXQCTL_STRICT_CYCLE | 144 + IGC_TXQCTL_STRICT_END; 152 145 153 146 if (ring->launchtime_enable) 154 147 txqctl |= IGC_TXQCTL_QUEUE_MODE_LAUNCHT;