[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#454493: Display PCI slot for nics, if available



Package: hw-detect
Version: 1.58
Severity: wishlist
Tags: patch

The linux kernel may expose slot information for PCI devices in
sysfs. Currently slot info is only exposed if the PCI device is
hotpluggable and the associated hotplug driver is loaded. However,
work is underway[1] to expose slot information for non-hotplug pci
devices that are exposed via ACPI.

This patch to hw-detect adds slot information, if available, to the
network device name. Its not uncommon for HP (or our customers) to
have systems with many network devices, and knowing the physical slot
number of an adapter makes configuration that much easier.

Currently this patch only attempts to load the acpiphp driver - it
should probably try and load others as well (e.g. pciehp & shchp, and
the future possible pci_slot).

Attached is a screen shot of a d-i build w/ this patch. Some nics
share the same slot because they are dual-port cards, and some nics
have no slot info because they are not hotplug and I'm using a
standard kernel that does not yet have non-hotplug slot support.

[1] http://lkml.org/lkml/2007/11/12/263
    http://lkml.org/lkml/2007/11/14/331
    http://lkml.org/lkml/2007/11/17/126

Index: hw-detect/debian/changelog
===================================================================
--- hw-detect/debian/changelog	(revision 50286)
+++ hw-detect/debian/changelog	(working copy)
@@ -1,3 +1,9 @@
+hw-detect (1.59) UNRELEASED; urgency=low
+
+  * Display the PCI slot for network device, if exported in sysfs
+
+ -- dann frazier <dannf@debian.org>  Tue, 04 Dec 2007 18:02:24 -0700
+
 hw-detect (1.58) unstable; urgency=low
 
   * Install acpi-support-base, needed now to get power button shutdowns to
Index: hw-detect/sysfs-update-devnames.sh
===================================================================
--- hw-detect/sysfs-update-devnames.sh	(revision 50286)
+++ hw-detect/sysfs-update-devnames.sh	(working copy)
@@ -2,6 +2,35 @@
 # Make sure that /etc/network/devnames is up to date, using sysfs. In
 # hotplug land, we may not get a chance to update it otherwise.
 
+# This currently only works for hotplug devices, but may work for
+# others devices in the future.
+iface_to_slot() {
+	iface="$1"
+
+	if [ ! -h "/sys/class/net/$iface/device" ]; then
+		return 1
+	fi
+
+	modprobe acpiphp || true
+
+	if [ ! -d /sys/bus/pci/slots ]; then
+		return 2
+	fi
+
+	ifdevpath=$(readlink "/sys/class/net/$iface/device")
+	ifaddr=${ifdevpath##*/}
+	ifaddr=${ifaddr%.*}
+
+	ifslot=""
+	for slot in /sys/bus/pci/slots/*; do
+	if [ "$ifaddr" = "$(cat $slot/address)" ]; then
+		echo ${slot##*/}
+		return 0
+	fi
+	done
+	return 4
+}
+
 if [ ! -d /sys/class/net ] || ! type lspci >/dev/null 2>&1; then
 	exit
 fi
@@ -14,12 +43,13 @@
 	   [ -f "/sys/class/net/$dev/device/device" ]; then
 		vendor="$(sed 's/^0x//' "/sys/class/net/$dev/device/vendor")"
 		device="$(sed 's/^0x//' "/sys/class/net/$dev/device/device")"
+		slot="[Slot $(iface_to_slot $dev)] " || slot=""
 		# 'tail -n 1' because for some reason lspci outputs two
 		# Device: lines.
 		vendorname="$(lspci -d "$vendor:$device" -m -v | grep ^Vendor: | tail -n 1 | sed 's/^Vendor:[[:space:]]*//; s/,/\\,/g')"
 		devicename="$(lspci -d "$vendor:$device" -m -v | grep ^Device: | tail -n 1 | sed 's/^Device:[[:space:]]*//; s/,/\\,/g')"
-		if [ "$vendorname" ] || [ "$devicename" ]; then
-			echo "$dev:$vendorname $devicename" >> /etc/network/devnames
+		if [ "$vendorname" ] || [ "$devicename" ] || [ "$slot" ]; then
+			echo "$dev:$slot$vendorname $devicename" >> /etc/network/devnames
 		fi
 	elif [ "$(readlink -f /sys/class/net/$dev/device/bus)" = /sys/bus/ieee1394 ] || \
 	     [ "$(readlink -f /sys/class/net/$dev/device/bus)" = /sys/bus/firewire ]; then

-- 
dann frazier

Attachment: nic-slot-info.png
Description: PNG image


Reply to: