| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) 2021-2024 Linutronix GmbH |
| 4 | # Author Kurt Kanzenbach <[email protected]> |
| 5 | # |
| 6 | # SPDX-License-Identifier: BSD-2-Clause |
| 7 | # |
| 8 | # Setup the Rx and Tx traffic flows on Intel i226. |
| 9 | # |
| 10 | # Rx steering is based on PCP values. Tx steering is based on socket priorities |
| 11 | # which are mapped to traffic classes and to timeslots accordingly. |
| 12 | # |
| 13 | |
| 14 | set -e |
| 15 | |
| 16 | source ../../../lib/common.sh |
| 17 | source ../../../lib/igc.sh |
| 18 | |
| 19 | # |
| 20 | # Command line arguments. |
| 21 | # |
| 22 | INTERFACE=$1 |
| 23 | CYCLETIME_NS=$2 |
| 24 | BASETIME=$3 |
| 25 | |
| 26 | [ -z $INTERFACE ] && INTERFACE="enp3s0" # default: enp3s0 |
| 27 | [ -z $CYCLETIME_NS ] && CYCLETIME_NS="1000000" # default: 1ms |
| 28 | [ -z $BASETIME ] && BASETIME=$(date '+%s000000000' -d '-30 sec') # default: now + 60s |
| 29 | |
| 30 | load_kernel_modules |
| 31 | |
| 32 | setup_threaded_napi "${INTERFACE}" |
| 33 | |
| 34 | igc_start "${INTERFACE}" |
| 35 | |
| 36 | # |
| 37 | # Qbv configuration. |
| 38 | # |
| 39 | ENTRY1_NS=$(echo "$CYCLETIME_NS * 50 / 100" | bc) # TSN High / OPC/UA / AVTP |
| 40 | ENTRY2_NS=$(echo "$CYCLETIME_NS * 50 / 100" | bc) # Everything else |
| 41 | |
| 42 | # |
| 43 | # Tx Assignment with Qbv and full hardware offload. |
| 44 | # |
| 45 | # PCP 6/5/4/3 - Queue 0 - Real time |
| 46 | # PCP 7/2/1/0 - Queue 1 - Non-real time |
| 47 | # |
| 48 | tc qdisc replace dev ${INTERFACE} handle 100 parent root taprio num_tc 4 \ |
| 49 | map 3 3 3 3 3 2 1 0 3 3 3 3 3 3 3 3 \ |
| 50 | queues 1@0 1@1 1@2 1@3 \ |
| 51 | base-time ${BASETIME} \ |
| 52 | sched-entry S 0x01 ${ENTRY1_NS} \ |
| 53 | sched-entry S 0xfe ${ENTRY2_NS} \ |
| 54 | flags 0x02 |
| 55 | |
| 56 | # |
| 57 | # Enable Tx launch time support for TC 0. |
| 58 | # |
| 59 | tc qdisc replace dev ${INTERFACE} parent 100:1 etf \ |
| 60 | clockid CLOCK_TAI \ |
| 61 | delta 500000 \ |
| 62 | offload |
| 63 | |
| 64 | # |
| 65 | # Rx Queues Assignment. |
| 66 | # |
| 67 | # Rx Q 3 - AVTP / All other traffic |
| 68 | # Rx Q 2 - OPC/UA #2 |
| 69 | # Rx Q 1 - OPC/UA #1 |
| 70 | # Rx Q 0 - TSN High |
| 71 | # |
| 72 | RXQUEUES=(3 0 1 2 3 3 3 3 3 3) |
| 73 | igc_rx_queues_assign "${INTERFACE}" RXQUEUES |
| 74 | |
| 75 | igc_end "${INTERFACE}" |
| 76 | |
| 77 | setup_irqs "${INTERFACE}" |
| 78 | |
| 79 | exit 0 |