Open tasleson opened 3 years ago
That is a worry, there is supposed to be some code that works out whether the host is big or little endian and represent the word data (16 bit) accordingly. Could you try hdparm, I believe you can give it sg nodes which is useful when a SATA disk is behind a SAS expander and HBA . My guess is whichever way hdparm represents it will be correct.
As requested (SN redacted again, replaced with spaces) run on LE system:
# hdparm --Istdout /dev/sdf
/dev/sdf:
0040 3fff c837 0010 0000 0000 003f 0000
0000 0000 2020 2020 2020 2020 2020 2020
2020 2020 2020 2020 0000 0000 0000 454d
5430 3142 3651 5361 6d73 756e 6720 5353
4420 3835 3020 4556 4f20 3154 4220 2020
2020 2020 2020 2020 2020 2020 2020 8001
4001 2f00 4000 0200 0200 0007 3fff 0010
003f fc10 00fb 0101 ffff 0fff 0000 0007
0003 0078 0078 0078 0078 0f10 0000 0000
0000 0000 0000 001f 850e 00c4 016c 0060
03fc 0039 746b 7d01 4163 7469 bc01 4163
407f 0001 0004 0000 fffe 0000 0000 0000
0000 0000 0000 0000 6db0 7470 0000 0000
0000 0008 4000 0000 5002 5388 700a daad
0000 0000 0000 0000 0000 0000 0000 401e
401c 0000 0000 0000 0000 0000 0000 0000
0021 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0001 2020 2020 2020 2020 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 003d 0000
0000 4000 0000 0000 0000 0000 0000 0000
0000 0001 0000 0000 0000 0000 107f 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0800 0000 0000 0000 0000
0000 0000 0000 4000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 87a5
Also run on BE system which results in the same byte ordering output. The data is slightly different as the negotiated bus speed is lower on BE system (word 77) etc.
# uname -m
ppc64
# hdparm --Istdout /dev/sdb
/dev/sdb:
0040 3fff c837 0010 0000 0000 003f 0000
0000 0000 2020 2020 2020 2020 2020 2020
2020 2020 2020 2020 0000 0000 0000 454d
5430 3142 3651 5361 6d73 756e 6720 5353
4420 3835 3020 4556 4f20 3154 4220 2020
2020 2020 2020 2020 2020 2020 2020 8001
4001 2f00 4000 0200 0200 0007 3fff 0010
003f fc10 00fb 0101 ffff 0fff 0000 0007
0003 0078 0078 0078 0078 0f10 0000 0000
0000 0000 0000 001f 850e 00c2 016c 0060
03fc 0039 746b 7d01 4163 7469 bc01 4163
407f 0001 0004 0000 fffe 0000 0000 0000
0000 0000 0000 0000 6db0 7470 0000 0000
0000 0008 4000 0000 5002 5388 700a daad
0000 0000 0000 0000 0000 0000 0000 401e
401c 0000 0000 0000 0000 0000 0000 0000
0021 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0001 2020 2020 2020 2020 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 003d 0000
0000 4000 0000 0000 0000 0000 0000 0000
0000 0001 0000 0000 0000 0000 107f 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0800 0000 0000 0000 0000
0000 0000 0000 4000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 89a5
Finding a big endian (BE) machine is getting harder and harder. NetBSD has a BE RPi image which I loaded up on a sd card and it boots. Unfortunately it does not use FreeBSD's SCSI stack so I made a sg_pt_dummy.c for it. Using the hex bytes that you provided in a file called vpd_pg89.hex I did this on the RPi BE netBSD machine:
arm64# ./sg_inq --in=/tmp/vpd_pg89.hex
VPD INQUIRY: ATA information page
SAT Vendor identification: linux
SAT Product identification: libata
SAT Product revision level: 3.00
Signature (Device to host FIS):
00 34 80 40 00 01 00 00 00 00 00 00 00 01 00 00 00
10 00 00 00 00
sg_is_big_endian=1
ATA command IDENTIFY DEVICE response summary:
model: Samsung SSD 850 EVO 1TB
serial number:
firmware revision: EMT01B6Q
response in hex:
00 0040 3fff c837 0010 0000 0000 003f 0000 .@ ?. .7 .. .. .. .? ..
08 0000 0000 2020 2020 2020 2020 2020 2020 .. ..
10 2020 2020 2020 2020 0000 0000 0000 454d .. .. .. EM
18 5430 3142 3651 5361 6d73 756e 6720 5353 T0 1B 6Q Sa ms un g SS
20 4420 3835 3020 4556 4f20 3154 4220 2020 D 85 0 EV O 1T B
28 2020 2020 2020 2020 2020 2020 2020 8001 ..
30 4001 2f00 4000 0200 0200 0007 3fff 0010 @. /. @. .. .. .. ?. ..
38 003f fc10 00fb 0101 ffff 0fff 0000 0007 .? .. .. .. .. .. .. ..
40 0003 0078 0078 0078 0078 0f10 0000 0000 .. .x .x .x .x .. .. ..
48 0000 0000 0000 001f 850e 00c4 016c 0060 .. .. .. .. .. .. .l .`
50 03fc 0039 746b 7d01 4163 7469 bc01 4163 .. .9 tk }. Ac ti .. Ac
58 407f 0001 0004 0000 fffe 0000 0000 0000 @. .. .. .. .. .. .. ..
60 0000 0000 0000 0000 6db0 7470 0000 0000 .. .. .. .. m. tp .. ..
68 0000 0008 4000 0000 5002 5388 700a daad .. .. @. .. P. S. p. ..
70 0000 0000 0000 0000 0000 0000 0000 401e .. .. .. .. .. .. .. @.
78 401c 0000 0000 0000 0000 0000 0000 0000 @. .. .. .. .. .. .. ..
80 0021 0000 0000 0000 0000 0000 0000 0000 .! .. .. .. .. .. .. ..
88 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
90 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
98 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
a0 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
a8 0000 0001 2020 2020 2020 2020 0000 0000 .. .. .. ..
b0 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
b8 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
c0 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
c8 0000 0000 0000 0000 0000 0000 003d 0000 .. .. .. .. .. .. .= ..
d0 0000 4000 0000 0000 0000 0000 0000 0000 .. @. .. .. .. .. .. ..
d8 0000 0001 0000 0000 0000 0000 107f 0000 .. .. .. .. .. .. .. ..
e0 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
e8 0000 0000 0000 0800 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
f0 0000 0000 0000 4000 0000 0000 0000 0000 .. .. .. @. .. .. .. ..
f8 0000 0000 0000 0000 0000 0000 0000 87a5 .. .. .. .. .. .. .. ..
That looks correct. It is the same output as I get on a LE machine (my laptop). I added some debug output which produces the line: "sg_is_big_endian=1" and on my laptop it says: "sg_is_big_endian=0". So is there something strange about your BE machine?
System is a Apple G5 Powermac. Hdparm works fine for same device on it and a Intel x86_64. sg_inq does correctly detect that it's a BE system. Anything else you would like to assist in debug? Maybe take the raw buffer and write out the array of bytes to a file on BE system?
Update: I'll try doing the raw buffer dump tomorrow on both BE and LE system. They should theoretically be virtually identical right? It should be in the interpretation and presentation that would need to be different for each arch.
The SAT-5 revision 5, section 12.4.3.2 says about the ATA IDENTIFY DEVICE DATA field: "The data shall be returned with byte preservation (i.e., ATA byte n maps to SCSI byte n), as shown in table 221". And that table shows Byte 0 is "ATA IDENTIFY DEVICE data word 0 bits 7:0 (i.e., byte 0)" and Byte 1 is "ATA IDENTIFY DEVICE data word 0 bits 15:8 (i.e., byte 1)" and carries on like that. So I would expect the byte representation (e.g. as shown with '-H') to be the same on BE and LE machines.
The patch I added to sg_inq.c looks like this:
if (len < 60)
return;
is_be = sg_is_big_endian();
pr2serr("sg_is_big_endian=%d\n", is_be);
if ((0xec == buff[56]) || (0xa1 == buff[56])) {
printf(" ATA command IDENTIFY %sDEVICE response summary:\n",
((0xa1 == buff[56]) ? "PACKET " : ""));
The addition is the line starting with pr2serr.
Since you are probably using Linux, then if you can load the scsi_debug driver, it simulates VPD page 89h, among others. So that might give you another BE data point.
So we believe this is a kernel issue? ref. https://lore.kernel.org/linux-ide/f0d1073e-b4a0-c255-41a3-ff52f1553c0f@interlog.com/
Yes, but I can't test my proposed solution. Can you?
@doug-gilbert I'll see what I can do.
@doug-gilbert I created the following commit against the 5.10 stable branch so that I didn't need to go through a bunch of kernel config options for my ppc64 system.
$ cat 0001-libata-Correct-big-endian-in-ata_scsiop_inq_89.patch
From a40d9eb5dc663d35624195987166706f4d8cd89e Mon Sep 17 00:00:00 2001
From: Douglas Gilbert <dgilbert@interlog.com>
Date: Tue, 22 Jun 2021 10:33:56 -0500
Subject: [PATCH] libata: Correct big endian in ata_scsiop_inq_89
The returned VPD 0x89 as detailed in the specification
should be in little endian format. Byte swap the returned
data as needed on big endian systems.
Tested-by: Tony Asleson <tasleson@redhat.com>
Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
---
drivers/ata/libata-scsi.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
index 48b8934970f3..6c5ff14aecea 100644
--- a/drivers/ata/libata-scsi.c
+++ b/drivers/ata/libata-scsi.c
@@ -2075,6 +2075,7 @@ static unsigned int ata_scsiop_inq_89(struct ata_scsi_args *args, u8 *rbuf)
rbuf[56] = ATA_CMD_ID_ATA;
memcpy(&rbuf[60], &args->id[0], 512);
+ swap_buf_le16((u16 *)(rbuf + 60), ATA_ID_WORDS);
return 0;
}
base-commit: 2c85ebc57b3e1817b6ce1a6b703928e113a90442
--
2.32.0
Without the patch I get the following:
# sg_inq -p 0x89 /dev/sda
VPD INQUIRY: ATA information page
SAT Vendor identification: linux
SAT Product identification: libata
SAT Product revision level: 3.00
Signature (Device to host FIS):
00 34 80 40 00 01 00 00 00 00 00 00 00 01 00 00 00
10 00 00 00 00
ATA command IDENTIFY DEVICE response summary:
model: DW CDW5200SJ4-M1BV 1
serial number: W -DCWNA1Y248002
firmware revision: 010.E210
response in hex:
00 7a42 ff3f 37c8 1000 0000 0000 3f00 0000 zB .? 7. .. .. .. ?. ..
08 0000 0000 2020 2020 5720 2d44 4357 4e41 .. .. W -D CW NA
10 3159 3234 3830 3032 0000 0040 3200 3031 1Y 24 80 02 .. .@ 2. 01
18 302e 4532 3130 4457 2043 4457 3532 3030 0. E2 10 DW C DW 52 00
20 534a 342d 4d31 4256 2031 2020 2020 2020 SJ 4- M1 BV 1
28 2020 2020 2020 2020 2020 2020 2020 1080 ..
30 0000 002f 0140 0000 0000 0700 ff3f 1000 .. ./ .@ .. .. .. .? ..
38 3f00 10fc fb00 1001 ffff ff0f 0000 0700 ?. .. .. .. .. .. .. ..
40 0300 7800 7800 7800 7800 0000 0000 0000 .. x. x. x. x. .. .. ..
48 0000 0000 0000 0000 0606 0000 4000 4000 .. .. .. .. .. .. @. @.
50 fe00 0000 6b70 617e 6340 6970 413c 6340 .. .. kp a~ c@ ip A< c@
58 7f40 0000 0000 0000 feff 0000 fe80 0000 .@ .. .. .. .. .. .. ..
60 0000 0000 0000 0000 7059 1c1d 0000 0000 .. .. .. .. pY .. .. ..
68 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
70 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
78 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
80 0100 0000 0000 0000 0000 6316 0000 0000 .. .. .. .. .. c. .. ..
88 0000 0000 0000 0000 0000 0000 0400 0000 .. .. .. .. .. .. .. ..
90 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
98 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
a0 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
a8 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
b0 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
b8 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
c0 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
c8 0000 0000 0000 0000 0000 0000 3f10 0000 .. .. .. .. .. .. ?. ..
d0 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
d8 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
e0 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
e8 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
f0 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
f8 0000 0000 0000 0000 0000 0000 0000 a5ef .. .. .. .. .. .. .. ..
With the patch I get:
# sg_inq -p 0x89 /dev/sda
VPD INQUIRY: ATA information page
SAT Vendor identification: linux
SAT Product identification: libata
SAT Product revision level: 3.00
Signature (Device to host FIS):
00 34 80 40 00 01 00 00 00 00 00 00 00 01 00 00 00
10 00 00 00 00
ATA command IDENTIFY DEVICE response summary:
model: WDC WD2500JS-41MVB1
serial number: WD-WCANY1420820
firmware revision: 10.02E01
response in hex:
00 427a 3fff c837 0010 0000 0000 003f 0000 Bz ?. .7 .. .. .. .? ..
08 0000 0000 2020 2020 2057 442d 5743 414e .. .. W D- WC AN
10 5931 3432 3038 3230 0000 4000 0032 3130 Y1 42 08 20 .. @. .2 10
18 2e30 3245 3031 5744 4320 5744 3235 3030 .0 2E 01 WD C WD 25 00
20 4a53 2d34 314d 5642 3120 2020 2020 2020 JS -4 1M VB 1
28 2020 2020 2020 2020 2020 2020 2020 8010 ..
30 0000 2f00 4001 0000 0000 0007 3fff 0010 .. /. @. .. .. .. ?. ..
38 003f fc10 00fb 0110 ffff 0fff 0000 0007 .? .. .. .. .. .. .. ..
40 0003 0078 0078 0078 0078 0000 0000 0000 .. .x .x .x .x .. .. ..
48 0000 0000 0000 0000 0606 0000 0040 0040 .. .. .. .. .. .. .@ .@
50 00fe 0000 706b 7e61 4063 7069 3c41 4063 .. .. pk ~a @c pi <A @c
58 407f 0000 0000 0000 fffe 0000 80fe 0000 @. .. .. .. .. .. .. ..
60 0000 0000 0000 0000 5970 1d1c 0000 0000 .. .. .. .. Yp .. .. ..
68 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
70 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
78 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
80 0001 0000 0000 0000 0000 1663 0000 0000 .. .. .. .. .. .c .. ..
88 0000 0000 0000 0000 0000 0000 0004 0000 .. .. .. .. .. .. .. ..
90 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
98 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
a0 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
a8 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
b0 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
b8 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
c0 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
c8 0000 0000 0000 0000 0000 0000 103f 0000 .. .. .. .. .. .. .? ..
d0 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
d8 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
e0 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
e8 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
f0 0000 0000 0000 0000 0000 0000 0000 0000 .. .. .. .. .. .. .. ..
f8 0000 0000 0000 0000 0000 0000 0000 efa5 .. .. .. .. .. .. .. ..
If you're OK with my patch, please submit upstream for inclusion. Thanks for digging into this!
@doug-gilbert Update?
When I run
sg_inq -p 0x89 /dev/sdf
for a SSD I have in a little endian system, I get the following (SN redacted):Same device in a big endian system:
From looking at the ATA specification,
seems to fit the description as "little endian". Looking at the output, things look correct from a strings stand point on LE system for model etc., but the hex dump for "little endian" system output looks like "big endian" output, in that the LSB is in the higher address/byte location.
If I do the following on a LE hardware, I'm assuming it's dumping the bytes in the order from the request:
I'm not sure at this point what the correct answer is.