| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2023 Linutronix GmbH |
| 4 | # Author Kurt Kanzenbach <[email protected]> |
| 5 | # |
| 6 | # SPDX-License-Identifier: BSD-2-Clause |
| 7 | # |
| 8 | # Setup the Tx and Rx traffic flows for Intel i225 for profinet scenario. |
| 9 | # |
| 10 | |
| 11 | set -e |
| 12 | |
| 13 | # |
| 14 | # Command line arguments. |
| 15 | # |
| 16 | INTERFACE=$1 |
| 17 | CYCLETIME_NS=$2 |
| 18 | BASETIME=$3 |
| 19 | |
| 20 | [ -z $INTERFACE ] && INTERFACE="enp3s0" # default: enp3s0 |
| 21 | [ -z $CYCLETIME_NS ] && CYCLETIME_NS="1000000" # default: 1ms |
| 22 | [ -z $BASETIME ] && BASETIME=$(date '+%s000000000' -d '-30 sec') # default: now - 30s |
| 23 | |
| 24 | # Load needed kernel modules |
| 25 | modprobe sch_taprio || true |
| 26 | |
| 27 | # |
| 28 | # Enable NAPI threaded mode: This allows the NAPI processing being executed in |
| 29 | # dedicated kernel threads instead of using NET_RX soft irq. Using these allows |
| 30 | # to prioritize the Rx processing in accordance to use case. |
| 31 | # |
| 32 | echo 1 >/sys/class/net/${INTERFACE}/threaded |
| 33 | |
| 34 | # |
| 35 | # Reduce link speed. |
| 36 | # |
| 37 | ethtool -s ${INTERFACE} speed 1000 autoneg on duplex full |
| 38 | |
| 39 | # |
| 40 | # Split traffic between TSN streams, real time and everything else. |
| 41 | # |
| 42 | ENTRY1_NS="50000" # TSN High |
| 43 | ENTRY2_NS="50000" # TSN Low |
| 44 | ENTRY3_NS="100000" # RTC |
| 45 | ENTRY4_NS="800000" # RTA and everything else |
| 46 | |
| 47 | # |
| 48 | # Tx Assignment with Qbv and full hardware offload. |
| 49 | # |
| 50 | # PCP 6 - Tx Q 0 - TSN High |
| 51 | # PCP 5 - Tx Q 1 - TSN Low |
| 52 | # PCP 4 - Tx Q 2 - RTC |
| 53 | # PCP 3/X - Tx Q 3 - RTA and Everything else |
| 54 | # |
| 55 | tc qdisc replace dev ${INTERFACE} handle 100 parent root taprio num_tc 4 \ |
| 56 | map 3 3 3 3 3 2 1 0 3 3 3 3 3 3 3 3 \ |
| 57 | queues 1@0 1@1 1@2 1@3 \ |
| 58 | base-time ${BASETIME} \ |
| 59 | sched-entry S 0x01 ${ENTRY1_NS} \ |
| 60 | sched-entry S 0x02 ${ENTRY2_NS} \ |
| 61 | sched-entry S 0x04 ${ENTRY3_NS} \ |
| 62 | sched-entry S 0x08 ${ENTRY4_NS} \ |
| 63 | flags 0x02 |
| 64 | |
| 65 | # |
| 66 | # Rx Queues Assignment. |
| 67 | # |
| 68 | # Rx Q 3 - All Traffic |
| 69 | # Rx Q 2 - RTC |
| 70 | # Rx Q 1 - TSN Low |
| 71 | # Rx Q 0 - TSN High |
| 72 | # |
| 73 | ethtool -K ${INTERFACE} ntuple on |
| 74 | |
| 75 | # TSN High: PCP 6 -> Queue 0 |
| 76 | ethtool -N ${INTERFACE} flow-type ether vlan 0xc000 m 0x1fff action 0 |
| 77 | |
| 78 | # TSN Low: PCP 5 -> Queue 1 |
| 79 | ethtool -N ${INTERFACE} flow-type ether vlan 0xa000 m 0x1fff action 1 |
| 80 | |
| 81 | # RTC: PCP 4 -> Queue 2 |
| 82 | ethtool -N ${INTERFACE} flow-type ether vlan 0x8000 m 0x1fff action 2 |
| 83 | |
| 84 | # RTA: PCP 3 -> Queue 3 |
| 85 | ethtool -N ${INTERFACE} flow-type ether vlan 0x6000 m 0x1fff action 3 |
| 86 | |
| 87 | # DCP: PCP 2 -> Queue 3 |
| 88 | ethtool -N ${INTERFACE} flow-type ether vlan 0x4000 m 0x1fff action 3 |
| 89 | |
| 90 | # LLDP/PTP: PCP 7 -> Queue 3 |
| 91 | ethtool -N ${INTERFACE} flow-type ether vlan 0xe000 m 0x1fff action 3 |
| 92 | |
| 93 | # UDP Low: PCP 1 -> Queue 3 |
| 94 | ethtool -N ${INTERFACE} flow-type ether vlan 0x2000 m 0x1fff action 3 |
| 95 | |
| 96 | # UDP High: PCP 0 -> Queue 3 |
| 97 | ethtool -N ${INTERFACE} flow-type ether vlan 0x0000 m 0x1fff action 3 |
| 98 | |
| 99 | # |
| 100 | # PTP and LLDP are transmitted untagged. Steer them via EtherType. |
| 101 | # |
| 102 | ethtool -N ${INTERFACE} flow-type ether proto 0x88f7 action 3 |
| 103 | ethtool -N ${INTERFACE} flow-type ether proto 0x88cc action 3 |
| 104 | |
| 105 | # |
| 106 | # Increase Tx and Rx ring sizes. |
| 107 | # |
| 108 | ethtool -G ${INTERFACE} rx 4096 tx 4096 |
| 109 | |
| 110 | # |
| 111 | # Increase IRQ thread priorities. By default, every IRQ thread has priority 50. |
| 112 | # |
| 113 | IRQTHREADS=$(ps aux | grep irq | grep ${INTERFACE} | awk '{ print $2; }') |
| 114 | for task in ${IRQTHREADS}; do |
| 115 | chrt -p -f 85 $task |
| 116 | done |
| 117 | |
| 118 | # |
| 119 | # Increase NAPI thread priorities. By default, every NAPI thread uses |
| 120 | # SCHED_OTHER. |
| 121 | # |
| 122 | NAPITHREADS=$(ps aux | grep napi | grep ${INTERFACE} | awk '{ print $2; }') |
| 123 | for task in ${NAPITHREADS}; do |
| 124 | chrt -p -f 85 $task |
| 125 | done |
| 126 | |
| 127 | exit 0 |