Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Documentation/nvme-ocp-hardware-component-log.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ OPTIONS
|0x0009 \| 'sn'| Device Serial Number
|0x000A \| 'country'| Country of Origin
|0x000B \| 'hw-rev'| Global Device Hardware Revision
|0x000C-0x7FFF| Reserved
|0x000C \| 'born-on-date'| Born on Date
|0x000D-0x7FFF| Reserved
|0x8000 \| 'vendor'| Vendor Unique Component
|0x8001-0xFFFF| Vendor Unique Component
|=================
Expand Down
12 changes: 12 additions & 0 deletions plugins/cmds-ocp/ocp-hardware-component-log.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ const char *hwcomp_id_to_string(__u32 id)
return "Reserved";
}

/*
* CITYPE-11 and CITYPE-15 define these as strings; any other Additional
* Information is hex (COMPD-8).
*/
bool hwcomp_add_info_is_string(struct hwcomp_desc_entry *e)
{
__u32 id = le32_to_cpu(e->desc->id);

return e->add_info &&
(id == HWCOMP_ID_COUNTRY || id == HWCOMP_ID_BORN_ON_DATE);
}

/*
* The descriptor at offset of the descriptors of log. Returns false at the
* end, and when the descriptor does not fit into the rest of the log.
Expand Down
1 change: 1 addition & 0 deletions plugins/cmds-ocp/ocp-hardware-component-log.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ enum hwcomp_id {

int ocp_hwcomp_log(int argc, char **argv, struct command *acmd, struct plugin *plugin);
const char *hwcomp_id_to_string(__u32 id);
bool hwcomp_add_info_is_string(struct hwcomp_desc_entry *e);
bool hwcomp_desc_entry(struct hwcomp_log *log, __u64 offset,
struct hwcomp_desc_entry *e);
2 changes: 1 addition & 1 deletion plugins/cmds-ocp/ocp-print-json.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ static void print_hwcomp_desc_json(struct hwcomp_desc_entry *e, struct json_obje
json_object_add_0nprix64(r, "Revision", le64_to_cpu(e->desc->rev), 16);
json_object_add_0nprix64(r, "Manufacture Code", le64_to_cpu(e->desc->mfg_code), 16);
json_object_add_byte_array(r, "Date/Lot Code", e->date_lot_code, e->date_lot_size);
if (le32_to_cpu(e->desc->id) == HWCOMP_ID_COUNTRY) {
if (hwcomp_add_info_is_string(e)) {
hw_comp_id = shr_buf2str((const char *)e->add_info, e->add_info_size);
json_object_add_value_string(r,
"Additional Information",
Expand Down
2 changes: 1 addition & 1 deletion plugins/cmds-ocp/ocp-print-stdout.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ static void print_hwcomp_desc(struct hwcomp_desc_entry *e, bool list, int num)
printf(" Revision: 0x%016"PRIx64"\n", le64_to_cpu(e->desc->rev));
printf(" Manufacture Code: 0x%016"PRIx64"\n", le64_to_cpu(e->desc->mfg_code));
print_array(" Date/Lot Code", e->date_lot_code, e->date_lot_size);
if (le32_to_cpu(e->desc->id) == HWCOMP_ID_COUNTRY) {
if (hwcomp_add_info_is_string(e)) {
hw_comp_id = shr_buf2str((const char *)e->add_info, e->add_info_size);
printf(" Additional Information: %s\n", hw_comp_id);
} else {
Expand Down
64 changes: 57 additions & 7 deletions tests/cli/cmds_ocp/ocp_hwcomp_log_mock_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
* Every descriptor field decodes to the value in the page in text and
JSON, a field of size 0 is absent, and each Component Identifier is
named as the CITYPE table describes it.
* The Additional Information of Country of Origin and Born on Date
decodes as a string less its right padding, that of every other
identifier as a little-endian number.
* --comp-id selects the descriptors of one identifier and --list prints
only their names.
* A descriptor that does not fit into the log is not decoded, a log
Expand Down Expand Up @@ -56,7 +59,11 @@
rev=0x090A0B0C0D0E0F10, mfg_code=0x1A1B1C1D1E1F2021,
date_lot=bytes(range(0x61, 0x65)))
SERIAL = Descriptor(layout.ID_SN, add_info=b'SN0123456789ABCD')
DESCRIPTORS = (ASIC, NAND, SERIAL)
# Space padded, as NVMe Base 2.1 section 1.4.2 pads a string. Reversed, the
# date would read 52025170.
COUNTRY = Descriptor(layout.ID_COUNTRY, add_info=b'UNITED KINGDOM ')
BORN_ON_DATE = Descriptor(layout.ID_BORN_ON_DATE, add_info=b'07152025')
DESCRIPTORS = (ASIC, NAND, SERIAL, COUNTRY, BORN_ON_DATE)


def le_hex(data, upper):
Expand All @@ -65,6 +72,14 @@ def le_hex(data, upper):
return '0x' + (text.upper() if upper else text)


def add_info_text(d, text):
"""The Additional Information of @d as the text (@text) or JSON report
shows it."""
if d.ident in layout.STRING_IDS:
return d.add_info.rstrip(b' \0').decode()
return le_hex(d.add_info, upper=text)


def expected_fields(d, text):
"""The decoded fields of descriptor @d, as the text (@text) or JSON
report shows them. Text leaves out a field of size 0."""
Expand All @@ -74,10 +89,11 @@ def expected_fields(d, text):
'Revision': f'0x{d.rev:016x}',
'Manufacture Code': f'0x{d.mfg_code:016x}',
}
for label, value in (('Date/Lot Code', d.date_lot),
('Additional Information', d.add_info)):
for label, value, shown in (
('Date/Lot Code', d.date_lot, le_hex(d.date_lot, upper=text)),
('Additional Information', d.add_info, add_info_text(d, text))):
if value:
fields[label] = le_hex(value, upper=text)
fields[label] = shown
elif not text:
fields[label] = NO_INFORMATION
return fields
Expand Down Expand Up @@ -174,11 +190,14 @@ def test_without_the_ocp_uuid_index_0_is_used(self):
[0, 0])

def test_version_1_size_counts_dwords(self):
"""HWCLOG-4 is in dwords in log page version 1 (OCP 2.5)."""
self.serve(layout.pack(DESCRIPTORS, version=1))
"""HWCLOG-4 is in dwords in log page version 1 (OCP 2.5), which
does not define 000Ch."""
descriptors = [d for d in DESCRIPTORS
if d.ident != layout.ID_BORN_ON_DATE]
self.serve(layout.pack(descriptors, version=1))
_, components = self.text_log()
self.assertEqual([c['name'] for c in components],
[layout.id_name(d.ident) for d in DESCRIPTORS])
[layout.id_name(d.ident) for d in descriptors])
reads = self.server.log_reads(layout.LID)
self.assertEqual(reads[-1].data_len,
len(self.page) - layout.HEADER_SIZE)
Expand Down Expand Up @@ -308,6 +327,37 @@ def test_comp_id_vendor_selects_the_vendor_range(self):
'--comp-id', 'vendor', '--list')


class TestHwcompLogStrings(HwcompLogTestBase):
"""Additional Information that CITYPE defines as a string."""

def add_info(self):
"""The Additional Information of the first component, by mode."""
_, components = self.text_log()
return {'text': components[0].get('Additional Information'),
'json': json_components(self.json_log())[0][
'Additional Information']}

def test_string_padding(self):
"""NVMe Base 2.1 section 1.4.2 pads a string with spaces, or a
null-terminated one with nulls."""
for padded in (b'JAPAN ', b'JAPAN\0\0\0'):
self.serve(layout.pack([Descriptor(layout.ID_COUNTRY,
add_info=padded)]))
for mode, value in self.add_info().items():
with self.subTest(padded=padded, mode=mode):
self.assertEqual(value, 'JAPAN')

def test_empty_string_field_is_absent(self):
"""COMPD-2: size 0h means the field does not exist."""
descriptors = [Descriptor(i) for i in sorted(layout.STRING_IDS)]
self.serve(layout.pack(descriptors))
result = self.assertOk(self.run_c6())
self.assertNotIn('Additional Information:', result.stdout)
components = json_components(self.json_log())
self.assertEqual([c['Additional Information'] for c in components],
[NO_INFORMATION] * len(descriptors))


class TestHwcompLogBounds(HwcompLogTestBase):
"""Descriptors that do not fit into the log end the list."""

Expand Down
7 changes: 6 additions & 1 deletion tests/e2e/plugins/cmds_ocp/ocp_c6_layout.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
version 1 (OCP 2.5) and bytes from version 2 (OCP 2.6 and 2.7). The
Date/Lot Size and Additional Information Size of a descriptor (COMPD-1,
COMPD-2) count dwords in every version. Born on Date (000Ch) is defined
from OCP 2.6.
from OCP 2.6. The Additional Information of Country of Origin and Born on
Date is a string; that of every other identifier is hex.
"""

from __future__ import annotations
Expand Down Expand Up @@ -76,6 +77,10 @@
ID_HW_REV: 'Global Device Hardware Revision',
ID_BORN_ON_DATE: 'Born on Date',
}
# The identifiers whose Additional Information is a string: UTF-8 for
# CITYPE-11, ASCII MMDDYYYY for CITYPE-15. The rest are hex (COMPD-8).
STRING_IDS = frozenset({ID_COUNTRY, ID_BORN_ON_DATE})

RESERVED_NAME = 'Reserved'
VENDOR_NAME = 'Vendor Unique Component'

Expand Down