-
Notifications
You must be signed in to change notification settings - Fork 0
/
pci.sh
executable file
·249 lines (216 loc) · 7.73 KB
/
pci.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#! /bin/bash
#
# Copyright 2017 Intel Corporation
#
# This file is part of LTP-DDT for IA to validate thunderbolt component
#
# This program file is free software; you can redistribute it and/or modify it
# under the terms and conditions of the GNU General Public License,
# version 1, as published by the Free Software Foundation.
#
# This program is distributed in the hope it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# Author:
# Pengfei Xu <[email protected]>
#
# History:
# April. 18, 2017
# @desc This script verify controllers files exist on sysfs for thunderbolt
# @params None
# @returns Fail the test if return code is non-zero (value set not found)
#source "common.sh" # Import do_cmd(), die() and other functions
############################# Functions ########################################
TIME_FMT="%Y%m%d-%H%M%S.%N"
CHECK_TIME=0
ROOT_PCI=""
TBT_PATH="/sys/bus/thunderbolt/devices"
REGEX_ITEM="-"
HOST_EXCLUDE="\-0"
usage()
{
cat <<-EOF >&2
usage: ./${0##*/} [-h help] Or no need parameter
EOF
exit 0
}
test_print_trc()
{
log_info=$1 # trace information
echo "|$(date +"$TIME_FMT")|TRACE|$log_info|"
echo "|$(date +"$TIME_FMT")|TRACE|$log_info|" >> /root/test_tbt_1.log
}
################################ CLI Params ####################################
# Please use getopts
while getopts :h arg
do case $arg in
h) usage;;
:) usage
exit 0
;;
\?) usage
exit 0
;;
esac
done
############################ Default Values for Params##########################
########################### REUSABLE TEST LOGIC ################################
PCI_PATH="/sys/bus/pci/devices"
rm -rf /root/test_tbt_1.log
parm=$1
find_root_pci()
{
local icl=$(dmidecode | grep "ICL")
if [[ -n "$icl" ]]; then
echo "ICL platform"
tbt_dev=$(ls ${TBT_PATH} \
| grep "$REGEX_ITEM" \
| grep -v "$HOST_EXCLUDE" \
| awk '{ print length(), $0 | "sort -n" }' \
| grep ^3 \
| cut -d ' ' -f 2 \
| head -n1)
case ${tbt_dev} in
0-1)
ROOT_PCI="0000:00:07.0"
;;
0-3)
ROOT_PCI="0000:00:07.1"
;;
1-1)
ROOT_PCI="0000:00:07.2"
;;
1-3)
ROOT_PCI="0000:00:07.3"
;;
*)
echo "ICL platform didn't find root pci, set 0000:00:07.0 as default!!!"
ROOT_PCI="0000:00:07.0"
;;
esac
else
ROOT_PCI=$(udevadm info --attribute-walk --path=/sys/bus/thunderbolt/devices/0-0 | grep KERNEL | tail -n 2 | grep -v pci0000 | cut -d "\"" -f 2)
#ROOT_PCI="0000:03:00.0"
fi
}
pci_main()
{
local par="$1"
local tbt="non-tbt"
local dev_path="/sys/bus/pci/devices"
local rstate=""
local icl=$(dmidecode | grep "ICL")
find_root_pci
if [[ -z "$ROOT_PCI" ]]; then
if [[ "$CHECK_TIME" -eq 0 ]]; then
CHECK_TIME=1
./cleware 1
sleep 30
find_root_pci
sleep 5
./cleware 0
else
echo "ICL could not find PCI 2nd time!!"
exit 1
fi
fi
rstate=$(cat $dev_path/$ROOT_PCI/power/runtime_status)
#rstate=$(lspci -vv -s 03:00 2> /dev/null | grep Status | grep "PME-" | cut -d ' ' -f 2)
echo "$ROOT_PCI runtime_status:$rstate"
if [[ -z "$icl" ]]; then
local ROOT_PCI=$(udevadm info --attribute-walk --path=/sys/bus/thunderbolt/devices/0-0 | grep KERNEL | tail -n 2 | grep -v pci0000 | cut -d "\"" -f 2)
else
[[ -z "$ROOT_PCI" ]] && echo "Error! ICL didn't find root pci:$ROOT_PCI"
fi
local pci_info=""
local pci_log="/tmp/tbt_pci.txt"
cat "/dev/null" > $pci_log
echo "tbt_ROOT_PCI: $ROOT_PCI"
PCI_LIST=$(ls $PCI_PATH)
echo "Path:$PCI_PATH/XXX_PCI_BUS/power/"
rstate=""
rstate=$(cat /sys/bus/pci/devices/$ROOT_PCI/power/runtime_status)
#rstate=$(lspci -vv -s 03:00 2> /dev/null | grep Status | grep "PME-" | cut -d ' ' -f 2)
local root_real_status=""
local port_status=""
local root_run_status=""
local root_control=""
local root_type=""
local acl_file="/sys/bus/thunderbolt/devices/domain0/boot_acl"
local power_control="/sys/bus/thunderbolt/devices/0-0/power/control"
echo "$ROOT_PCI runtime_status:$rstate"
if [[ -e "$acl_file" ]]; then
echo "cat $acl_file"
cat $acl_file
else
echo "set on in $power_control"
echo "on" > $power_control
echo "set auto in $power_control"
echo "auto" > $power_control
fi
echo "sleep 25"
sleep 25
root_real_status=$(cat $PCI_PATH/$ROOT_PCI/firmware_node/real_power_state 2>/dev/null)
root_port_status=$(cat $PCI_PATH/$ROOT_PCI/firmware_node/power_state 2>/dev/null)
root_run_status=$(cat $PCI_PATH/$ROOT_PCI/power/runtime_status)
root_control=$(cat $PCI_PATH/$ROOT_PCI/power/control)
root_type=$(lspci -v -s $ROOT_PCI 2> /dev/null | grep "Kernel driver in use:" | awk -F "in use: " '{print $2}')
for PCI in ${PCI_LIST}
do
tbt="non-tbt"
run_status=""
real_status=""
if [[ "$PCI" == "$ROOT_PCI" ]]; then
real_status="$root_real_status"
port_status="$root_port_status"
run_status="$root_run_status"
pci_control="$root_control"
pci_type="$root_type"
else
control=$(cat $PCI_PATH/$PCI/power/control)
run_status=$(cat $PCI_PATH/$PCI/power/runtime_status)
pci_type=$(lspci -v -s $PCI 2> /dev/null | grep "Kernel driver in use:" | awk -F "in use: " '{print $2}')
# comment line, due to if D3 cold, could not get the correct status. so use $PCI_PATH/XXX_PCI_BUS/power/firmware_node/real_power_state
real_status=$(cat $PCI_PATH/$PCI/firmware_node/real_power_state 2>/dev/null)
port_status=$(cat $PCI_PATH/$PCI/firmware_node/power_state 2>/dev/null)
[[ -z "$real_status" ]] && real_status=$(lspci -vv -s $PCI 2> /dev/null | grep Status | grep "PME-" | cut -d ' ' -f 2)
fi
pci_content=$(ls -ltra $PCI_PATH/$PCI)
#Check pci which contain ROOT_PCI pci, if yes it means it's tbt branch pci
if [[ -n "$ROOT_PCI" ]]; then
#echo "pci_content:$pci_content pci:$PCI"
[[ "$pci_content" == *"$ROOT_PCI"* ]] && tbt="tbt"
[[ "$PCI" == "$ROOT_PCI" ]] && tbt="tbt_root"
fi
if [[ $par == "tbt" ]]; then
[[ "$tbt" == "non-tbt" ]] && continue
fi
[[ -z "$pci_type" ]] && pci_type="NA"
[[ -z "$control" ]] && control="NA"
[[ -z "$run_status" ]] && run_status="NA"
[[ -z "$real_status" ]] && real_status="NA"
[[ -z "$port_status" ]] && port_status="NA"
# printf "$PCI->%-8s type:%-18s control:%-12s runtime_status:%-12s real_status:%-12s\n" \
# "$tbt" "$pci_type" "$control" "$run_status" "$real_status"
pci_info=$(printf "$PCI->%-8s type:%-18s control:%-12s runtime_status:%-12s real_status:%-12s, port_status:%-12s\n" \
"$tbt" "$pci_type" "$control" "$run_status" "$real_status" "$port_status")
echo "$pci_info" >> $pci_log
if [[ -n "$ROOT_PCI" ]]; then
[[ "$PCI" == "$ROOT_PCI" ]] && echo "auto" > $PCI_PATH/$PCI/power/control
fi
if [[ "$control" == "on" ]]; then
[[ "$tbt" == "tbt" ]] && {
[[ "$pci_type" == *"hci"* ]] && echo "auto" > $PCI_PATH/$PCI/power/control
}
#[[ "$pci_type" == "thunderbolt" ]] && echo "auto" > $PCI_PATH/$PCI/power/control
fi
done
cat $pci_log
echo "Before, root_real_status:$root_real_status"
root_real_status=$(cat $PCI_PATH/$ROOT_PCI/firmware_node/real_power_state 2>/dev/null)
echo "cat $PCI_PATH/$ROOT_PCI/firmware_node/real_power_state "
echo "Current, root pci real status:$root_real_status"
}
pci_main "$parm"