m/p/scsi: add SCSI package
This adds a SCSI package to interact with SCSI devices.
It implements a subset of commands from the SPC-5 and SBC-4 standard
useful for discovery and health assessment.
A follow-up will add SAT (SCSI-to-ATA translation) support.
Change-Id: I7f084d26f11d9c951f51051040160e351cf5594c
Reviewed-on: https://review.monogon.dev/c/monogon/+/1066
Reviewed-by: Serge Bazanski <serge@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/pkg/scsi/health.go b/metropolis/pkg/scsi/health.go
new file mode 100644
index 0000000..724fd75
--- /dev/null
+++ b/metropolis/pkg/scsi/health.go
@@ -0,0 +1,26 @@
+package scsi
+
+import "errors"
+
+type InformationalExceptions struct {
+ InformationalSenseCode AdditionalSenseCode
+ Temperature uint8
+}
+
+func (d *Device) GetInformationalExceptions() (*InformationalExceptions, error) {
+ raw, err := d.LogSenseParameters(LogSenseRequest{PageCode: 0x0b})
+ if err != nil {
+ return nil, err
+ }
+ if len(raw[0x1]) == 0 {
+ return nil, errors.New("mandatory parameter 0001h missing")
+ }
+ param1 := raw[0x01][0]
+ if len(param1.Data) < 3 {
+ return nil, errors.New("parameter 0001h too short")
+ }
+ return &InformationalExceptions{
+ InformationalSenseCode: AdditionalSenseCode(uint16(param1.Data[0])<<8 | uint16(param1.Data[1])),
+ Temperature: param1.Data[2],
+ }, nil
+}