aboutsummaryrefslogtreecommitdiff
blob: b571138b192a1d430d7ea707b85f801086e8afe0 (plain)
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
#!/bin/bash

# Script to read EDD information from sysfs and
# echo the FCoE interface name and target info.
# This is a work in progress and will be enhanced
# with more options as we progress further.
#
# Author: Supreeth Venkataraman
#	  Yi Zou
#         Intel Corporation
#
# Usage: fcoe_edd.sh -t for getting FCoE boot target information.
#        fcoe_edd.sh -i for getting FCoE boot NIC name.
#        fcoe_edd.sh -m for getting FCoE boot NIC MAC.
#        fcoe_edd.sh -e for getting FCoE boot EDD information.
#        fcoe_edd.sh -r for getting FCoE boot EDD interface type and path.
#        fcoe_edd.sh -a for getting all FCoE boot information.
#        fcoe_edd.sh -h for usage information.
#        Optional: use -v to turn on verbose mode.
#
# Notes:
# FCoE Boot Disk is identified by the following format of boot information
# in its corresponding sysfs firmware edd entry, i.e.,
# 	/sys/firmware/edd/int13_dev??/interface
# which is formatted as (for FCoE):
# string format: FIBRE wwid: 8c1342b8a0001620 lun: 7f00
# Please ref. to T13 BIOS Enhanced Disk Drive Specification v3.0 for more
# defails on EDD.
#

SYSEDD=/sys/firmware/edd
PREFIX="FIBRE"
VERBOSE=
FCOE_INF=
FCOE_WWN=
FCOE_LUN=
FCOE_EDD=
FCOE_NIC=
FCOE_MAC=


#
#
#
LOG() {
	if [ -n "$1" ] && [ -n "${VERBOSE}" ]; then
		echo "LOG:$1"
	fi
}


find_fcoe_boot_disk() {
	local prefix=

	if [ ! -e $SYSEDD ]; then
		LOG "Need kernel EDD support!"
		return 1
	fi
#	for disk in `find ${SYSEDD} -maxdepth 1 -name 'int13*'`
	for disk in ${SYSEDD}/int13_*
	do
		LOG " checking $disk..."
		if [ ! -e ${disk}/interface ]; then
			continue;
		fi
		LOG " checking ${disk}/interface..."
		prefix=`awk '{printf $1}' < ${disk}/interface`
		if [ "${PREFIX}" != "${prefix}" ]; then
			LOG " The FCoE Boot prefix ${prefix} is invalid!"
			continue;
		fi
		FCOE_INF=`cat ${disk}/interface`
		LOG " found FCoE boot info. from boot rom:${FCOE_INF}..."

		FCOE_WWN=`awk '{printf $3}' < ${disk}/interface`
		if [ ${#FCOE_WWN} -ne 16 ]; then
			LOG " The FCoE Boot WWID ${FCOE_WWN} is invalid!"
			continue;
		fi
		FCOE_LUN=`awk '{printf $5}' < ${disk}/interface`
		if [ -z "${#FCOE_LUN}" ]; then
			LOG " The FCoE Boot LUN ${FCOE_WWN} is invalid!"
			continue;
		fi
		# look for the correponding nic
		# FIXME:
		# 1) only supporst PCI device?
		# 2) at initrd time, the nic name is always eth*?
		if [ ! -e ${disk}/pci_dev ]; then
			LOG "Failed to locate the corresponing PCI device!"
			continue;
		fi
		if [ ! -e ${disk}/pci_dev/net ]; then
			LOG "Failed to detect any NIC device!"
			continue;
		fi

		for nic in ${disk}/pci_dev/net/*
		do
			if [ -e ${nic}/address ]; then
				FCOE_MAC=`cat ${nic}/address`
				FCOE_NIC=$(basename ${nic})
				break;
			fi
		done
		if [ -z "${FCOE_MAC}" ] || [ -z "${FCOE_NIC}" ]; then
			LOG "Failed to locate the corresponing NIC device!"
			continue;
		fi
		# Found the FCoE Boot Device
		FCOE_EDD=$(basename ${disk})
		return 0;
	done
	return 1
}

get_fcoe_boot_all(){
	echo "### FCoE Boot Information ###"
	echo "EDD=${FCOE_EDD}"
	echo "INF=${FCOE_INF}"
	echo "WWN=${FCOE_WWN}"
	echo "LUN=${FCOE_LUN}"
	echo "NIC=${FCOE_NIC}"
	echo "MAC=${FCOE_MAC}"
	return 0
}

get_fcoe_boot_target() {
	if [ -z "${FCOE_WWN}" ] || [ -z "${FCOE_LUN}" ]; then
		LOG "No FCoE Boot Target information is found!"
		return 1
	fi
	echo "WWN=${FCOE_WWN}"
	echo "LUN=${FCOE_LUN}"
}

get_fcoe_boot_inf(){
	if [ -z "${FCOE_INF}" ]; then
		LOG "No FCoE Boot INF information is found!"
		return 1
	fi
	echo "INF=${FCOE_INF}"
	return 0
}

get_fcoe_boot_mac(){
	if [ -z "${FCOE_MAC}" ]; then
		LOG "No FCoE Boot NIC MAC information is found!"
		return 1
	fi
	echo "MAC=${FCOE_MAC}"
	return 0
}

get_fcoe_boot_ifname(){
	if [ -z "${FCOE_NIC}" ]; then
		LOG "No FCoE Boot NIC information is found!"
		return 1
	fi
	echo "NIC=${FCOE_NIC}"
	return 0
}

get_fcoe_boot_edd(){
	if [ -z "${FCOE_EDD}" ]; then
		LOG "No FCoE Boot Disk EDD information is found!"
		return 1
	fi
	echo "EDD=${FCOE_EDD}"
	return 0
}


# parse options
prog=$(basename $0)
while getopts "timeravh" OptionName; do
    case "$OptionName" in
        t)
		action=get_fcoe_boot_target
		;;
        i)
		action=get_fcoe_boot_ifname
		;;
        m)
		action=get_fcoe_boot_mac
		;;
        e)
		action=get_fcoe_boot_edd
		;;
        r)
		action=get_fcoe_boot_inf
		;;
	a)
		action=get_fcoe_boot_all
		;;
	v)
		VERBOSE="yes"
		;;
        h)
		echo "Usage: ${prog} -t for getting FCoE boot target information."
		echo "       ${prog} -i for getting FCoE boot NIC name."
		echo "       ${prog} -m for getting FCoE boot NIC MAC."
		echo "       ${prog} -e for getting FCoE boot EDD information."
		echo "       ${prog} -r for getting FCoE boot EDD interface type and path."
		echo "       ${prog} -a for getting all FCoE boot information."
		echo "       ${prog} -h for usage information."
		echo "       Optional: use -v to turn on verbose mode."
		exit 0
		;;
        *)
		echo "Invalid Option. Use -h option for help."
		exit 1
		;;
    esac
done
if [ -z "${action}" ]; then
	echo "Must specify at least -t, -i, -m, -e, -r, -a, or -h."
	echo "Use -h option for help."
	exit 1
fi
# Locate FCoE boot disk and nic information
find_fcoe_boot_disk
if [ $? -ne 0 ]; then
	echo "No FCoE boot disk information is found in EDD!"
	exit 1
fi
if [ -z "${FCOE_EDD}" ]; then
	echo "No FCoE boot disk is found in EDD!"
	exit 1;
fi

${action}

exit $?