Skip to content

Commit

Permalink
scsiata.cpp: Add '-d usbasm1352r,N' device type for ASM 1352R USB bri…
Browse files Browse the repository at this point in the history
…dges

(GH issues/167).
dev_interface.cpp: Update help text.
smartctl.8.in, smartd.conf.5.in: Document new option.

git-svn-id: https://svn.code.sf.net/p/smartmontools/code/trunk/smartmontools@5437 4ea69e1a-61f1-4043-bf83-b5c94c648137
  • Loading branch information
chrfranke committed Jan 23, 2023
1 parent 576aa69 commit 15da839
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ $Id$

2023-01-23 Christian Franke <[email protected]>

scsiata.cpp: Add '-d usbasm1352r,N' device type for ASM 1352R USB
bridges (GH issues/167).
dev_interface.cpp: Update help text.
smartctl.8.in, smartd.conf.5.in: Document new option.

scsiata.cpp: Use 'str_starts_with()' and 'set_err_np()' where
possible.

Expand Down
2 changes: 1 addition & 1 deletion dev_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ std::string smart_interface::get_valid_dev_types_str()
{
// default
std::string s =
"ata, scsi[+TYPE], nvme[,NSID], sat[,auto][,N][+TYPE], usbcypress[,X], "
"ata, scsi[+TYPE], nvme[,NSID], sat[,auto][,N][+TYPE], usbasm1352r,N, usbcypress[,X], "
"usbjmicron[,p][,x][,N], usbprolific, usbsunplus, sntasmedia, sntjmicron[,NSID], "
"sntrealtek, intelliprop,N[+TYPE], jmb39x[-q],N[,sLBA][,force][+TYPE], "
"jms56x,N[,sLBA][,force][+TYPE]";
Expand Down
29 changes: 25 additions & 4 deletions scsiata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,14 @@ class sat_device
sat_auto,
scsi_always
};
enum sat_variant {
sat_standard,
sat_asm1352r, // ASM1352R port 0 or 1
};

sat_device(smart_interface * intf, scsi_device * scsidev,
const char * req_type, sat_scsi_mode mode = sat_always, int passthrulen = 0);
const char * req_type, sat_scsi_mode mode = sat_always, int passthrulen = 0,
sat_variant variant = sat_standard, int port = 0);

virtual ~sat_device();

Expand All @@ -126,17 +131,20 @@ class sat_device
private:
int m_passthrulen;
sat_scsi_mode m_mode;
sat_variant m_variant;
int m_port;
};


sat_device::sat_device(smart_interface * intf, scsi_device * scsidev,
const char * req_type, sat_scsi_mode mode /* = sat_always */,
int passthrulen /* = 0 */)
int passthrulen /* = 0 */, sat_variant variant /* = sat_standard */, int port /* = 0 */)
: smart_device(intf, scsidev->get_dev_name(),
(mode == sat_always ? "sat" : mode == sat_auto ? "sat,auto" : "scsi"), req_type),
tunnelled_device<ata_device, scsi_device>(scsidev),
m_passthrulen(passthrulen),
m_mode(mode)
m_mode(mode),
m_variant(variant), m_port(port)
{
if (mode != sat_always)
hide_ata(); // Start as SCSI, switch to ATA in autodetect_open()
Expand All @@ -146,7 +154,9 @@ sat_device::sat_device(smart_interface * intf, scsi_device * scsidev,
set_info().dev_type += strprintf("+%s", scsidev->get_dev_type());

set_info().info_name = strprintf("%s [%s]", scsidev->get_info_name(),
(mode == sat_always ? "SAT" : mode == sat_auto ? "SCSI/SAT" : "SCSI"));
(variant == sat_standard ?
(mode == sat_always ? "SAT" : mode == sat_auto ? "SCSI/SAT" : "SCSI") :
(port == 0 ? "ASM1352R_0" : "ASM1352R_1") ));
}

sat_device::~sat_device()
Expand Down Expand Up @@ -292,6 +302,10 @@ bool sat_device::ata_pass_through(const ata_cmd_in & in, ata_cmd_out & out)
(int)in.direction);
}

// The ASM1352R uses reserved values for 'protocol' field to select drive
if (m_variant == sat_asm1352r)
protocol = (m_port == 0 ? 0xd : 0xe);

// Check condition if any output register needed
if (in.out_needed.is_set())
ck_cond = 1;
Expand Down Expand Up @@ -1448,6 +1462,13 @@ ata_device * smart_interface::get_sat_device(const char * type, scsi_device * sc
satdev = new usbsunplus_device(this, scsidev, type);
}

else if (str_starts_with(type, "usbasm1352r")) {
unsigned port = ~0; int n = -1;
if (!(sscanf(type, "usbasm1352r,%u%n", &port, &n) == 1 && n == (int)strlen(type) && port <= 1))
return set_err_np(EINVAL, "Option '-d usbasm1352r,<n>' requires <n> to be 0 or 1");
satdev = new sat_device(this, scsidev, type, sat_device::sat_always, 0, sat_device::sat_asm1352r, port);
}

else {
return set_err_np(EINVAL, "Unknown USB device type '%s'", type);
}
Expand Down
7 changes: 7 additions & 0 deletions smartctl.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,13 @@ If \*(Aq\-d sat,auto\*(Aq is specified, device type SAT (for ATA/SATA disks)
is only used if the SCSI INQUIRY data reports a SATL (VENDOR: "ATA ").
Otherwise device type SCSI (for SCSI/SAS disks) is used.
.Sp
.I usbasm1352r,PORT
\- [NEW EXPERIMENTAL SMARTCTL FEATURE]
this device type is for one or two SATA disks that are behind an ASMedia
ASM1352R USB to SATA (RAID) bridge.
The parameter PORT (0 or 1) selects the disk to monitor.
Note: \*(Aq\-d sat\*(Aq also works for the first disk.
.Sp
.I usbcypress
\- this device type is for ATA disks that are behind a Cypress USB to PATA
bridge. This will use the ATACB proprietary scsi pass through command.
Expand Down
7 changes: 7 additions & 0 deletions smartd.conf.5.in
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,13 @@ If \*(Aq\-d sat,auto\*(Aq is specified, device type SAT (for ATA/SATA disks)
is only used if the SCSI INQUIRY data reports a SATL (VENDOR: "ATA ").
Otherwise device type SCSI (for SCSI/SAS disks) is used.
.Sp
.I usbasm1352r,PORT
\- [NEW EXPERIMENTAL SMARTD FEATURE]
this device type is for one or two SATA disks that are behind an ASMedia
ASM1352R USB to SATA (RAID) bridge.
The parameter PORT (0 or 1) selects the disk to monitor.
Note: \*(Aq\-d sat\*(Aq also works for the first disk.
.Sp
.I usbcypress
\- this device type is for ATA disks that are behind a Cypress USB to PATA
bridge. This will use the ATACB proprietary scsi pass through command.
Expand Down

0 comments on commit 15da839

Please sign in to comment.