Skip to contentSkip to conversation

sensors-detect: DDR3 SPD EEPROM support

PATCH In review Clemens Ladisch 3 participants 4 messages Feb 11, 2011 – Feb 16, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sensors-detect: DDR3 SPD EEPROM support

This adds CRC-16 calculation, needed to correctly detect DDR3 SPD EEPROMs.

prog/detect/sensors-detect +29 -4
@@ -5265,18 +5265,43 @@
 
 # Registers used:
 #   0-63: SPD Data and Checksum
+#   0-127: SPD data and CRC (DDR3)
 sub eeprom_detect
 {
 	my ($file, $addr) = @_;
+	my $device_type = i2c_smbus_read_byte_data($file, 2);
 	my $checksum = 0;
 
 	# Check the checksum for validity (works for most DIMMs and RIMMs)
-	for (my $i = 0; $i <= 62; $i++) {
-		$checksum += i2c_smbus_read_byte_data($file, $i);
+	if ($device_type >= 1 and $device_type <= 10) {
+		for (my $i = 0; $i <= 62; $i++) {
+			$checksum += i2c_smbus_read_byte_data($file, $i);
+		}
+		$checksum &= 255;
+
+		return 8 if $checksum = i2c_smbus_read_byte_data($file, 63);
+	} elsif ($device_type = 11) {
+		# see JEDEC 21-C 4.1.2.11 2.4
+		my $crc_coverage = i2c_smbus_read_byte_data($file, 0);
+		$crc_coverage = ($crc_coverage & 0x80) ? 117 : 126;
+		for (my $i = 0; $i < $crc_coverage; $i++) {
+			$checksum ^= i2c_smbus_read_byte_data($file, $i) << 8;
+			for (my $bit = 0; $bit < 8; $bit++) {
+				if ($checksum & 0x8000) {
+					$checksum = ($checksum << 1) ^ 0x1021;
+				} else {
+					$checksum <<= 1;
+				}
+			}
+		}
+		$checksum &= 0xffff;
+
+		return 8 if ($checksum & 0xff) = i2c_smbus_read_byte_data($file, 126) and
+			    ($checksum >> 8) = i2c_smbus_read_byte_data($file, 127);
+
+		# note: if bit 7 of byte 32 is set, a jc42 sensor is at $addr-0x38
 	}
-	$checksum &= 255;
 
-	return 8 if $checksum = i2c_smbus_read_byte_data($file, 63);
 	return;
 }
 

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#1 lore raw
Quoted 2 lines · Clemens Ladisch

This adds CRC-16 calculation, needed to correctly detect DDR3 SPD EEPROMs.

For DDR3: Tested-by: Guenter Roeck <[email protected]>

Quoted 51 lines
prog/detect/sensors-detect +29 -4
@@ -5265,18 +5265,43 @@
 
 # Registers used:
 #   0-63: SPD Data and Checksum
+#   0-127: SPD data and CRC (DDR3)
 sub eeprom_detect
 {
 	my ($file, $addr) = @_;
+	my $device_type = i2c_smbus_read_byte_data($file, 2);
 	my $checksum = 0;
 
 	# Check the checksum for validity (works for most DIMMs and RIMMs)
-	for (my $i = 0; $i <= 62; $i++) {
-		$checksum += i2c_smbus_read_byte_data($file, $i);
+	if ($device_type >= 1 and $device_type <= 10) {
+		for (my $i = 0; $i <= 62; $i++) {
+			$checksum += i2c_smbus_read_byte_data($file, $i);
+		}
+		$checksum &= 255;
+
+		return 8 if $checksum = i2c_smbus_read_byte_data($file, 63);
+	} elsif ($device_type = 11) {
+		# see JEDEC 21-C 4.1.2.11 2.4
+		my $crc_coverage = i2c_smbus_read_byte_data($file, 0);
+		$crc_coverage = ($crc_coverage & 0x80) ? 117 : 126;
+		for (my $i = 0; $i < $crc_coverage; $i++) {
+			$checksum ^= i2c_smbus_read_byte_data($file, $i) << 8;
+			for (my $bit = 0; $bit < 8; $bit++) {
+				if ($checksum & 0x8000) {
+					$checksum = ($checksum << 1) ^ 0x1021;
+				} else {
+					$checksum <<= 1;
+				}
+			}
+		}
+		$checksum &= 0xffff;
+
+		return 8 if ($checksum & 0xff) = i2c_smbus_read_byte_data($file, 126) and
+			    ($checksum >> 8) = i2c_smbus_read_byte_data($file, 127);
+
+		# note: if bit 7 of byte 32 is set, a jc42 sensor is at $addr-0x38
 	}
-	$checksum &= 255;
 
-	return 8 if $checksum = i2c_smbus_read_byte_data($file, 63);
 	return;
 }
 
Quoted 4 lines

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

#2 lore raw
In reply to Clemens Ladisch

Hi Clemens,

Quoted 9 lines · Clemens Ladisch

This adds CRC-16 calculation, needed to correctly detect DDR3 SPD EEPROMs.

prog/detect/sensors-detect +1 -0
@@ -5265,18 +5265,43 @@
 
 # Registers used:
 #   0-63: SPD Data and Checksum
+#   0-127: SPD data and CRC (DDR3)

prog/detect/sensors-detect line 5276

Quoted 10 lines
prog/detect/sensors-detect +2 -2
 sub eeprom_detect
 {
 	my ($file, $addr) = @_;
+	my $device_type = i2c_smbus_read_byte_data($file, 2);
 	my $checksum = 0;
 
 	# Check the checksum for validity (works for most DIMMs and RIMMs)
-	for (my $i = 0; $i <= 62; $i++) {
-		$checksum += i2c_smbus_read_byte_data($file, $i);
+	if ($device_type >= 1 and $device_type <= 10) {

Device type 9 (FB-DIMM) also uses the CRC16, so this test is not correct. Not sure about type 10 (what the hell is "FB-DIMM Probe"?)

Quoted 22 lines
prog/detect/sensors-detect +22 -0
+		for (my $i = 0; $i <= 62; $i++) {
+			$checksum += i2c_smbus_read_byte_data($file, $i);
+		}
+		$checksum &= 255;
+
+		return 8 if $checksum = i2c_smbus_read_byte_data($file, 63);
+	} elsif ($device_type = 11) {
+		# see JEDEC 21-C 4.1.2.11 2.4
+		my $crc_coverage = i2c_smbus_read_byte_data($file, 0);
+		$crc_coverage = ($crc_coverage & 0x80) ? 117 : 126;
+		for (my $i = 0; $i < $crc_coverage; $i++) {
+			$checksum ^= i2c_smbus_read_byte_data($file, $i) << 8;
+			for (my $bit = 0; $bit < 8; $bit++) {
+				if ($checksum & 0x8000) {
+					$checksum = ($checksum << 1) ^ 0x1021;
+				} else {
+					$checksum <<= 1;
+				}
+			}
+		}
+		$checksum &= 0xffff;
+

prog/detect/sensors-detect line 5306

Quoted 10 lines
prog/detect/sensors-detect +4 -2
+		return 8 if ($checksum & 0xff) = i2c_smbus_read_byte_data($file, 126) and
+			    ($checksum >> 8) = i2c_smbus_read_byte_data($file, 127);
+
+		# note: if bit 7 of byte 32 is set, a jc42 sensor is at $addr-0x38
 	}
-	$checksum &= 255;
 
-	return 8 if $checksum = i2c_smbus_read_byte_data($file, 63);
 	return;
 }

Other than this, your patch looks good and works for me. So I've applied it with just the device type checks changed. Thanks for your contribution!

Signature · 6 lines
Jean Delvare

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
#3 lore raw
In reply to Clemens Ladisch
Quoted 5 lines · Jean Delvare

prog/detect/sensors-detect line 5276

Quoted 1 line · Clemens Ladisch
prog/detect/sensors-detect +1 -0
+	if ($device_type >= 1 and $device_type <= 10) {

Device type 9 (FB-DIMM) also uses the CRC16, so this test is not correct. Not sure about type 10 (what the hell is "FB-DIMM Probe"?)

4.1.2 7.3:

| This field identifies the fundamental type of memory used on the
| assembly. The fundamental type of memory for FBDIMMs are DDR2 or
| FB-DIMM Probe (a unique Fundamental Type value to indicate logic
| analysis probe boards).

I don't think that such boards pretend to be memory modules (or that somebody who uses them would expect sensors-detect to know about them).

Regards,
Clemens

_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors