Skip to content

Commit 58aae0a

Browse files
committed
firewire: test: add test of device attributes for legacy AV/C device
Some legacy devices have configuration ROM against standard AV/C device. They have vendor directory to store model identifier. It is described in annex of the following document. - Configuration ROM for AV/C Devices 1.0 (Dec. 12, 2000, 1394 Trading Association) In the case, current implementation of core function does not detect the model identifier, thus device attributes and modalias of unit have lack of it. Another KUnit test is required for the case, and this commit is for the purpose. The following output is the parse result for the hard-coded data, by config-rom-pretty-printer in linux-firewire-utils (https://git.kernel.org/pub/scm/utils/ieee1394/linux-firewire-utils.git/). The data is written by my hand. $ config-rom-pretty-printer < /tmp/rom.img ROM header and bus information block ----------------------------------------------------------------- 1024 04199fe7 bus_info_length 4, crc_length 25, crc 40935 1028 31333934 bus_name "1394" 1032 e0644000 irmc 1, cmc 1, isc 1, bmc 0, cyc_clk_acc 100, max_rec 4 (32) 1036 00112233 company_id 001122 | 1040 44556677 device_id 220189779575 | EUI-64 4822678189205111 root directory ----------------------------------------------------------------- 1044 0005dace directory_length 5, crc 56014 1048 03012345 vendor 1052 0c0083c0 node capabilities: per IEEE 1394 1056 8d000009 --> eui-64 leaf at 1092 1060 d1000002 --> unit directory at 1068 1064 c3000004 --> vendor directory at 1080 unit directory at 1068 ----------------------------------------------------------------- 1068 0002e107 directory_length 2, crc 57607 1072 12abcdef specifier id 1076 13543210 version vendor directory at 1080 ----------------------------------------------------------------- 1080 0002cb73 directory_length 2, crc 52083 1084 17fedcba model 1088 81000004 --> descriptor leaf at 1104 eui-64 leaf at 1092 ----------------------------------------------------------------- 1092 00026dc1 leaf_length 2, crc 28097 1096 00112233 company_id 001122 | 1100 44556677 device_id 220189779575 | EUI-64 4822678189205111 descriptor leaf at 1104 ----------------------------------------------------------------- 1104 00050e84 leaf_length 5, crc 3716 1108 00000000 textual descriptor 1112 00000000 minimal ASCII 1116 41424344 "ABCD" 1120 45464748 "EFGH" 1124 494a000 "IJ" Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Sakamoto <[email protected]>
1 parent 1c8506d commit 58aae0a

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

drivers/firewire/device-attribute-test.c

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,40 @@ static const u32 simple_avc_config_rom[] = {
4545
0x6d650000,
4646
};
4747

48+
// Ibid.
49+
// Annex A:Consideration for configuration ROM reader design (informative)
50+
// A.1 Vendor directory
51+
//
52+
// Written by hand.
53+
static const u32 legacy_avc_config_rom[] = {
54+
0x04199fe7,
55+
0x31333934,
56+
0xe0644000,
57+
0x00112233,
58+
0x44556677,
59+
0x0005dace, // root directory.
60+
0x03012345,
61+
0x0c0083c0,
62+
0x8d000009,
63+
0xd1000002,
64+
0xc3000004,
65+
0x0002e107, // unit 0 directory.
66+
0x12abcdef,
67+
0x13543210,
68+
0x0002cb73, // vendor directory.
69+
0x17fedcba,
70+
0x81000004,
71+
0x00026dc1, // leaf for EUI-64.
72+
0x00112233,
73+
0x44556677,
74+
0x00050e84, // leaf for textual descriptor.
75+
0x00000000,
76+
0x00000000,
77+
0x41424344,
78+
0x45464748,
79+
0x494a0000,
80+
};
81+
4882
static void device_attr_simple_avc(struct kunit *test)
4983
{
5084
static const struct fw_device node = {
@@ -126,8 +160,85 @@ static void device_attr_simple_avc(struct kunit *test)
126160
KUNIT_EXPECT_MEMEQ(test, ids, unit0_expected_ids, sizeof(ids));
127161
}
128162

163+
static void device_attr_legacy_avc(struct kunit *test)
164+
{
165+
static const struct fw_device node = {
166+
.device = {
167+
.type = &fw_device_type,
168+
},
169+
.config_rom = legacy_avc_config_rom,
170+
.config_rom_length = sizeof(legacy_avc_config_rom),
171+
};
172+
static const struct fw_unit unit0 = {
173+
.device = {
174+
.type = &fw_unit_type,
175+
.parent = (struct device *)&node.device,
176+
},
177+
.directory = &legacy_avc_config_rom[11],
178+
};
179+
struct device *node_dev = (struct device *)&node.device;
180+
struct device *unit0_dev = (struct device *)&unit0.device;
181+
static const int unit0_expected_ids[] = {0x00012345, 0x00000000, 0x00abcdef, 0x00543210};
182+
char *buf = kunit_kzalloc(test, PAGE_SIZE, GFP_KERNEL);
183+
int ids[4] = {0, 0, 0, 0};
184+
185+
// Ensure associations for node and unit devices.
186+
187+
KUNIT_ASSERT_TRUE(test, is_fw_device(node_dev));
188+
KUNIT_ASSERT_FALSE(test, is_fw_unit(node_dev));
189+
KUNIT_ASSERT_PTR_EQ(test, fw_device((node_dev)), &node);
190+
191+
KUNIT_ASSERT_FALSE(test, is_fw_device(unit0_dev));
192+
KUNIT_ASSERT_TRUE(test, is_fw_unit(unit0_dev));
193+
KUNIT_ASSERT_PTR_EQ(test, fw_parent_device((&unit0)), &node);
194+
KUNIT_ASSERT_PTR_EQ(test, fw_unit(unit0_dev), &unit0);
195+
196+
// For entries in root directory.
197+
198+
// Vendor immediate entry is found.
199+
KUNIT_EXPECT_GT(test, show_immediate(node_dev, &config_rom_attributes[0].attr, buf), 0);
200+
KUNIT_EXPECT_STREQ(test, buf, "0x012345\n");
201+
202+
// Model immediate entry is not found.
203+
KUNIT_EXPECT_LT(test, show_immediate(node_dev, &config_rom_attributes[4].attr, buf), 0);
204+
205+
// Descriptor leaf entry for vendor is not found.
206+
KUNIT_EXPECT_LT(test, show_text_leaf(node_dev, &config_rom_attributes[5].attr, buf), 0);
207+
208+
// Descriptor leaf entry for model is not found.
209+
KUNIT_EXPECT_LT(test, show_text_leaf(node_dev, &config_rom_attributes[6].attr, buf), 0);
210+
211+
// For entries in unit 0 directory.
212+
213+
// Vendor immediate entry is not found.
214+
KUNIT_EXPECT_LT(test, show_immediate(unit0_dev, &config_rom_attributes[0].attr, buf), 0);
215+
216+
// Model immediate entry is not found.
217+
KUNIT_EXPECT_LT(test, show_immediate(unit0_dev, &config_rom_attributes[4].attr, buf), 0);
218+
219+
// Descriptor leaf entry for vendor is not found.
220+
KUNIT_EXPECT_LT(test, show_text_leaf(unit0_dev, &config_rom_attributes[5].attr, buf), 0);
221+
222+
// Descriptor leaf entry for model is not found.
223+
KUNIT_EXPECT_LT(test, show_text_leaf(unit0_dev, &config_rom_attributes[6].attr, buf), 0);
224+
225+
// Specifier_ID immediate entry is found.
226+
KUNIT_EXPECT_GT(test, show_immediate(unit0_dev, &config_rom_attributes[2].attr, buf), 0);
227+
KUNIT_EXPECT_STREQ(test, buf, "0xabcdef\n");
228+
229+
// Version immediate entry is found.
230+
KUNIT_EXPECT_GT(test, show_immediate(unit0_dev, &config_rom_attributes[3].attr, buf), 0);
231+
KUNIT_EXPECT_STREQ(test, buf, "0x543210\n");
232+
233+
kunit_kfree(test, buf);
234+
235+
get_modalias_ids(&unit0, ids);
236+
KUNIT_EXPECT_MEMEQ(test, ids, unit0_expected_ids, sizeof(ids));
237+
}
238+
129239
static struct kunit_case device_attr_test_cases[] = {
130240
KUNIT_CASE(device_attr_simple_avc),
241+
KUNIT_CASE(device_attr_legacy_avc),
131242
{}
132243
};
133244

0 commit comments

Comments
 (0)