Skip to content

Commit

Permalink
memory debug
Browse files Browse the repository at this point in the history
  • Loading branch information
jurkovic-nikola committed Nov 15, 2024
1 parent 54f0a87 commit 1124571
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/devices/lsh/lsh.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,10 @@ var (
{DeviceId: 7, Model: 3, Name: "iCUE LINK H170i", LedChannels: 20, ContainsPump: true, Desc: "AIO", AIO: true, HasSpeed: true},
{DeviceId: 7, Model: 0, Name: "iCUE LINK H100i", LedChannels: 20, ContainsPump: true, Desc: "AIO", AIO: true, HasSpeed: true},
{DeviceId: 7, Model: 4, Name: "iCUE LINK H100i", LedChannels: 20, ContainsPump: true, Desc: "AIO", AIO: true, HasSpeed: true},
{DeviceId: 9, Model: 0, Name: "iCUE LINK XC7 Elite", LedChannels: 24, ContainsPump: false, Desc: "CPU Block", TemperatureProbe: true},
{DeviceId: 9, Model: 0, Name: "iCUE LINK XC7 ELITE", LedChannels: 24, ContainsPump: false, Desc: "CPU Block", TemperatureProbe: true},
{DeviceId: 9, Model: 1, Name: "iCUE LINK XC7 Elite", LedChannels: 24, ContainsPump: false, Desc: "CPU Block", TemperatureProbe: true},
{DeviceId: 10, Model: 0, Name: "iCUE LINK XG3 HYBRID", LedChannels: 22, ContainsPump: false, Desc: "GPU Block", HasSpeed: true},
{DeviceId: 13, Model: 1, Name: "iCUE LINK XG7", LedChannels: 16, ContainsPump: false, Desc: "GPU Hybrid Block"},
{DeviceId: 13, Model: 0, Name: "iCUE LINK XG7 RGB", LedChannels: 16, ContainsPump: false, Desc: "GPU Hybrid Block"},
{DeviceId: 12, Model: 0, Name: "iCUE LINK XD5 Elite", LedChannels: 22, ContainsPump: true, Desc: "Pump/Res", HasSpeed: true},
{DeviceId: 16, Model: 0, Name: "VRM Cooler Module", LedChannels: 0, ContainsPump: false, Desc: "Fan", HasSpeed: true},
{DeviceId: 17, Model: 0, Name: "iCUE LINK TITAN 240", LedChannels: 20, ContainsPump: true, Desc: "AIO", AIO: true, HasSpeed: true},
Expand Down
59 changes: 59 additions & 0 deletions src/devices/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"OpenLinkHub/src/smbus"
"OpenLinkHub/src/temperatures"
"encoding/json"
"fmt"
"github.com/godbus/dbus/v5"
"math"
"os"
Expand Down Expand Up @@ -164,6 +165,7 @@ func Init(device, product string) *Device {
LEDChannels: 0,
}

d.getDebugMode() // Debug mode
d.loadDeviceProfiles() // Load all device profiles
count := d.getDevices()
if count == 0 {
Expand All @@ -179,6 +181,11 @@ func Init(device, product string) *Device {
return d
}

// getManufacturer will return device manufacturer
func (d *Device) getDebugMode() {
d.Debug = config.GetConfig().Debug
}

// getDevices will get a list of DIMMs
func (d *Device) getDevices() int {
var devices = make(map[int]*Devices, 0)
Expand All @@ -192,26 +199,40 @@ func (d *Device) getDevices() int {
skuRangeLow = byte(0x89)
skuRangeHigh = byte(0x9b)
}

if d.Debug {
logger.Log(logger.Fields{"skuRangeLow": skuRangeLow, "skuRangeHigh": skuRangeHigh}).Info("DEBUG skuRange")
}
for i := 0; i < maximumRegisters; i++ {
if d.Debug {
logger.Log(logger.Fields{"address": dimmInfoAddresses[i]}).Info("Probing address")
}

// Probe for register
_, err := smbus.ReadRegister(d.dev.File, dimmInfoAddresses[i], 0x00)
if err != nil {
logger.Log(logger.Fields{"register": dimmInfoAddresses[i]}).Info("No such register found. Skipping...")
continue
}

if d.Debug {
logger.Log(logger.Fields{"memoryType": config.GetConfig().MemoryType}).Info("Probing address")
}

if config.GetConfig().MemoryType == 5 {
// DDR5 has no SPA0 and SPA1, it uses actual DIMM info addresses for different info
// 0x0b with 0x04 decodes memory SKU
err = smbus.WriteRegister(d.dev.File, dimmInfoAddresses[i], 0x0b, 0x04)
if err != nil {
logger.Log(logger.Fields{"error": err}).Error("Failed to activate DIMM info")
continue
}
} else {
// We send 0x00 to 0x00 to SPA addresses
for _, cmdActivation := range cmdActivations {
err = smbus.WriteRegister(d.dev.File, cmdActivation, 0x00, 0x00)
if err != nil {
logger.Log(logger.Fields{"error": err}).Error("Failed to activate DIMM info")
continue
}
activated++
Expand All @@ -225,12 +246,18 @@ func (d *Device) getDevices() int {
// Check SKU 1st letter, must match to C = Corsair
check, err := smbus.ReadRegister(d.dev.File, dimmInfoAddresses[i], skuRangeLow)
if err != nil {
logger.Log(logger.Fields{"error": err, "register": skuRangeLow}).Error("Failed to get first letter of SKU")
continue
}
if string(check) != "C" {
logger.Log(logger.Fields{"error": err, "register": skuRangeLow, "letter": string(check)}).Warn("First SKU letter does not match to letter C")
continue
}

if d.Debug {
logger.Log(logger.Fields{"skuLetter": string(check)}).Info("Memory SKU - First letter")
}

// Get SKU
var buf []byte
for addr := skuRangeLow; addr <= skuRangeHigh; addr++ {
Expand All @@ -244,15 +271,28 @@ func (d *Device) getDevices() int {
buf = append(buf, reg)
}

if d.Debug {
logger.Log(logger.Fields{"sku": buf, "skuString": string(buf), "skuLen": len(buf)}).Info("Memory SKU")
}

if len(buf) > 15 {
// https://help.corsair.com/hc/en-us/articles/8528259685901-RAM-How-to-Read-the-CORSAIR-memory-part-number
// https://help.corsair.com/hc/en-us/articles/360051011331-RAM-DDR4-memory-module-dimensions
dimmInfo := string(buf)

if d.Debug {
logger.Log(logger.Fields{"dimmInfo": dimmInfo}).Info("Memory DIMM Info")
}

skuLine := ""
ledChannels := 0
vendor := dimmInfo[0:2]
colorRegister := 0

if d.Debug {
logger.Log(logger.Fields{"dimmInfoVendor": vendor}).Info("Memory DIMM Info - Vendor")
}

if vendor == "CM" { // Corsair Memory
line := dimmInfo[2:3]
size, e := strconv.Atoi(dimmInfo[3:5])
Expand All @@ -276,6 +316,16 @@ func (d *Device) getDevices() int {
continue
}

if d.Debug {
logger.Log(logger.Fields{
"dimmInfoLine": line,
"memoryType": memoryType,
"amount": amount,
"speed": speed,
"latency": latency,
}).Info("Memory DIMM Info - Data")
}

if config.GetConfig().MemoryType == 4 {
// DDR4
switch line {
Expand Down Expand Up @@ -393,6 +443,9 @@ func (d *Device) getDevices() int {
RGB: rgbProfile,
HasTemps: hasTemp,
}
if d.Debug {
logger.Log(logger.Fields{"memoryDevice": device}).Info("Memory DIMM Info - Device")
}
devices[i] = device
d.LEDChannels += ledChannels
}
Expand Down Expand Up @@ -1166,11 +1219,17 @@ func (d *Device) transfer(buffer []byte, address, ledDevices byte, colorRegister
buf = append(buf, buffer[i])
}
buf = append(buf, d.calculateChecksum(buf))
if d.Debug {
logger.Log(logger.Fields{"colorPacket": fmt.Sprint("% 2x", buf)}).Info("Memory Color")
}
if len(buf) > 32 {
// We have more than 10 LEDs, we need to chunk packet and increment color register.
// This is relevant for DOMINATOR PLATINUM RGB that has 12 LEDs.
chunks := common.ProcessMultiChunkPacket(buf, 32)
for _, chunk := range chunks {
if d.Debug {
logger.Log(logger.Fields{"colorPacket": fmt.Sprint("% 2x", chunk)}).Info("Memory Color - Chunk")
}
err := smbus.WriteBlockData(d.dev.File, address, colorRegister, chunk)
if err != nil {
logger.Log(logger.Fields{"error": err, "address": address}).Error("Unable to write to i2c register")
Expand Down

0 comments on commit 1124571

Please sign in to comment.