Skip to content

Commit

Permalink
general cxl 2.0 support (#5)
Browse files Browse the repository at this point in the history
* Update CEDT struct and parsing function

* Update for parsing CXL memory device registers

* parse component register

* some improvements on memory device register parsing

* turn klog level into constant

* basic mailbox structure

* adding a few functions with 0 sized payload

* Change payload input and output to []byte.
MMIO requires 32bit operations but payload length need to be byte level

* adding supported mailbox commands

* parse serial number from PCIE config space

* fix register locator address calculation

* Print help content if no argument supplied

* check possible type2 device with class code 12
Processing Accelerator

* fix 64bit mailbox address

* Add some validations for register locator

* revert Processing Accelerator support.
only Type 3 memory expander with PCIE class code 050210

* force serial number to 64bits length

* clean up comments
  • Loading branch information
HJ-Fan authored Oct 5, 2023
1 parent 0995780 commit 2d5b821
Show file tree
Hide file tree
Showing 5 changed files with 1,104 additions and 292 deletions.
54 changes: 46 additions & 8 deletions cmd/cxl-util/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ func (s *Settings) InitContext(args []string, ctx context.Context) (error, conte
s.PCIE = *pcie
s.CEDT = *cedt

if len(args) == 1 {
s.Help = true
}

return nil, newContext
}

Expand Down Expand Up @@ -120,15 +124,15 @@ func main() {

devList := cxl.InitCxlDevList()
if settings.List {
prFmt := "%12s | %20s | %10s | %10s | %15s \n"
prFmt := "%12s | %20s | %10s | %10s | %15s | %18s \n"
fmt.Printf("Print the list of CXL devs. Total devices found: %d\n", len(devList))
fmt.Printf(prFmt, "BUS:DEV.FUN", "Vendor", "Device", "Rev", "Type")
fmt.Printf(prFmt, "BUS:DEV.FUN", "Vendor", "Device", "Rev", "Type", "SN")
for _, dev := range devList {
vendorName := dev.GetVendorInfo()
if len(vendorName) > 15 {
vendorName = vendorName[:15] + "..."
}
fmt.Printf(prFmt, dev.GetBdfString(), vendorName, dev.GetDeviceInfo(), dev.GetCxlRev(), dev.GetCxlType())
fmt.Printf(prFmt, dev.GetBdfString(), vendorName, dev.GetDeviceInfo(), dev.GetCxlRev(), dev.GetCxlType(), dev.GetSerialNumber())
}
}

Expand All @@ -150,6 +154,35 @@ func main() {
fmt.Printf("\nDVSEC %s [ID:%d] at offset 0x%x:\n", id.String(), id, dvsec_ofs)
PrintTableToStdout(dev.GetDvsec(id), " ", " ")
}

if dev.Memdev != nil {
fmt.Printf("\nCXL Device Capabilities Array Register:\n")
PrintTableToStdout(dev.Memdev.Device_Capabilities_Array_Register, " ", " ")
for i, cap := range dev.Memdev.Device_Capability_Header {
fmt.Printf("\nCXL Device Capability %d Header:\n", i)
PrintTableToStdout(cap, " ", " ")
fmt.Printf("\nCXL Device Capability %d Content:\n", i)
PrintTableToStdout(dev.GetMemDevRegStruct(i), " ", " ")
}
}

if dev.CmpReg != nil {
fmt.Printf("\nCXL Component Register:\n")
if dev.CmpReg.Ras_Cap != nil {
fmt.Printf("\nRAS CAP:\n")
PrintTableToStdout(dev.CmpReg.Ras_Cap, " ", " ")
}
if dev.CmpReg.Link_Cap != nil {
fmt.Printf("\nLINK CAP:\n")
PrintTableToStdout(dev.CmpReg.Link_Cap, " ", " ")
}
if dev.CmpReg.HDM_Decoder_Cap != nil {
fmt.Printf("\nHDM DECODER CAP:\n")
PrintTableToStdout(dev.CmpReg.HDM_Decoder_Cap, " ", " ")
}

}

} else {
fmt.Printf("No CXL dev on BDF %s \n", settings.PCIE)

Expand All @@ -161,12 +194,17 @@ func main() {
fmt.Printf("No CEDT table found on the system.\n")
} else {
fmt.Printf("\nCEDT table header:\n")
PrintTableToStdout(cxl.ACPITables.CEDT.Header, " ", " ")

for i := 0; i < cxl.ACPITables.GetCedtCount(); i++ {
fmt.Printf("\nCEDT subtable [%d] :\n", i)
PrintTableToStdout(cxl.ACPITables.GetCedtSubtable(i), " ", " ")
cedtHdr := cxl.ACPITables.GetCedtHeader()
PrintTableToStdout(cedtHdr, " ", " ")

// iterate sub tables
ofs := cxl.ACPITables.CedtHeaderSize()
for uint32(ofs) < cedtHdr.Table_Length {
subT := cxl.ACPITables.GetCedtSubtable(ofs)
PrintTableToStdout(subT, " ", " ")
ofs += cxl.ACPITables.GetCedtSubtableSize(ofs)
}

}

}
Expand Down
17 changes: 11 additions & 6 deletions pkg/cxl/bitfield.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,20 @@ type bitfield_31b uint32
type bitfield_32b uint32
type bitfield_64b uint64

// StructSize returns the size of a structure in Bytes
func StructSize(s any) int {
return dataSize(reflect.ValueOf(s))
}

// dataSize returns the number of bytes the actual data represented by v occupies in memory.
// For compound structures, it sums the sizes of the elements. Thus, for instance, for a slice
// it returns the length of the slice times the element size and does not count the memory
// occupied by the header. If the type of v is not acceptable, dataSize returns -1.
func dataSize(v reflect.Value) int {
klog.V(4).InfoS("bitfield.dataSize", "type", v.Type().Name(), "kind", v.Kind().String())
klog.V(DBG_LVL_DEEP_DETAIL).InfoS("bitfield.dataSize", "type", v.Type().Name(), "kind", v.Kind().String())
switch v.Kind() {
case reflect.Slice, reflect.Array:
klog.V(4).InfoS("bitfield.dataSize", "len", v.Len())
klog.V(DBG_LVL_DEEP_DETAIL).InfoS("bitfield.dataSize", "len", v.Len())
if v.Len() == 0 { // deal with empty slice
return 0
}
Expand All @@ -80,7 +85,7 @@ func dataSize(v reflect.Value) int {
return sum

default:
klog.V(2).InfoS("bitfield.dataSize", "Size", v.Type().Size())
klog.V(DBG_LVL_DEEP_DETAIL).InfoS("bitfield.dataSize", "Size", v.Type().Size())
return int(v.Type().Size())
}
}
Expand Down Expand Up @@ -108,7 +113,7 @@ func BitFieldRead(r io.Reader, data any) error {

v := reflect.ValueOf(data)
size := -1
klog.V(4).InfoS("bitfield.BitFieldRead", "type", reflect.TypeOf(data).String(), "kind", v.Kind().String())
klog.V(DBG_LVL_DEEP_DETAIL).InfoS("bitfield.BitFieldRead", "type", reflect.TypeOf(data).String(), "kind", v.Kind().String())
switch v.Kind() {
case reflect.Pointer:
v = v.Elem()
Expand Down Expand Up @@ -140,7 +145,7 @@ func ReadByBit(r io.Reader, buf []byte, m []int) {
bitWidthMask := uint64((1 << width) - 1)
bitShift := bitOfs - startByte*8
val := uint64(0)
klog.V(4).InfoS("bitfield.ReadByBit", "bitOfs", bitOfs, "bitWidth", width, "endBit", endBit, "startByte", startByte, "endByte", endByte, "bitShift", bitShift, "bitWidthMask", hex(bitWidthMask))
klog.V(DBG_LVL_DEEP_DETAIL).InfoS("bitfield.ReadByBit", "bitOfs", bitOfs, "bitWidth", width, "endBit", endBit, "startByte", startByte, "endByte", endByte, "bitShift", bitShift, "bitWidthMask", hex(bitWidthMask))

// extract related field into a uint32, and then apply the shift and mask
structByteSize := endByte - startByte
Expand Down Expand Up @@ -264,7 +269,7 @@ func bitSizeOfArray(v reflect.Value) []int {
reflect.Float32, reflect.Float64, reflect.Complex64, reflect.Complex128:
return []int{int(t.Size()) * 8}
}
klog.V(2).InfoS("bitfield.bitSizeOfArray error", "kind", t.Kind().String())
klog.V(DBG_LVL_INFO).InfoS("bitfield.bitSizeOfArray error", "kind", t.Kind().String())

return []int{}
}
Expand Down
Loading

0 comments on commit 2d5b821

Please sign in to comment.