17a14f78dSTakashi Sakamoto // SPDX-License-Identifier: GPL-2.0-or-later
27a14f78dSTakashi Sakamoto //
37a14f78dSTakashi Sakamoto // ohci-serdes-test.c - An application of Kunit to check serialization/deserialization of data in
47a14f78dSTakashi Sakamoto // buffers and registers defined in 1394 OHCI specification.
57a14f78dSTakashi Sakamoto //
67a14f78dSTakashi Sakamoto // Copyright (c) 2024 Takashi Sakamoto
77a14f78dSTakashi Sakamoto
87a14f78dSTakashi Sakamoto #include <kunit/test.h>
97a14f78dSTakashi Sakamoto
107a14f78dSTakashi Sakamoto #include "ohci.h"
117a14f78dSTakashi Sakamoto
127a14f78dSTakashi Sakamoto
test_self_id_count_register_deserialization(struct kunit * test)137a14f78dSTakashi Sakamoto static void test_self_id_count_register_deserialization(struct kunit *test)
147a14f78dSTakashi Sakamoto {
157a14f78dSTakashi Sakamoto const u32 expected = 0x803d0594;
167a14f78dSTakashi Sakamoto
177a14f78dSTakashi Sakamoto bool is_error = ohci1394_self_id_count_is_error(expected);
187a14f78dSTakashi Sakamoto u8 generation = ohci1394_self_id_count_get_generation(expected);
197a14f78dSTakashi Sakamoto u32 size = ohci1394_self_id_count_get_size(expected);
207a14f78dSTakashi Sakamoto
217a14f78dSTakashi Sakamoto KUNIT_EXPECT_TRUE(test, is_error);
227a14f78dSTakashi Sakamoto KUNIT_EXPECT_EQ(test, 0x3d, generation);
237a14f78dSTakashi Sakamoto KUNIT_EXPECT_EQ(test, 0x165, size);
247a14f78dSTakashi Sakamoto }
257a14f78dSTakashi Sakamoto
test_self_id_receive_buffer_deserialization(struct kunit * test)267a14f78dSTakashi Sakamoto static void test_self_id_receive_buffer_deserialization(struct kunit *test)
277a14f78dSTakashi Sakamoto {
287a14f78dSTakashi Sakamoto const u32 buffer[] = {
297a14f78dSTakashi Sakamoto 0x0006f38b,
307a14f78dSTakashi Sakamoto 0x807fcc56,
317a14f78dSTakashi Sakamoto 0x7f8033a9,
327a14f78dSTakashi Sakamoto 0x8145cc5e,
337a14f78dSTakashi Sakamoto 0x7eba33a1,
347a14f78dSTakashi Sakamoto };
357a14f78dSTakashi Sakamoto
367a14f78dSTakashi Sakamoto u8 generation = ohci1394_self_id_receive_q0_get_generation(buffer[0]);
377a14f78dSTakashi Sakamoto u16 timestamp = ohci1394_self_id_receive_q0_get_timestamp(buffer[0]);
387a14f78dSTakashi Sakamoto
397a14f78dSTakashi Sakamoto KUNIT_EXPECT_EQ(test, 0x6, generation);
407a14f78dSTakashi Sakamoto KUNIT_EXPECT_EQ(test, 0xf38b, timestamp);
417a14f78dSTakashi Sakamoto }
427a14f78dSTakashi Sakamoto
test_at_data_serdes(struct kunit * test)438db9d155STakashi Sakamoto static void test_at_data_serdes(struct kunit *test)
448db9d155STakashi Sakamoto {
458db9d155STakashi Sakamoto static const __le32 expected[] = {
468db9d155STakashi Sakamoto cpu_to_le32(0x00020e80),
478db9d155STakashi Sakamoto cpu_to_le32(0xffc2ffff),
488db9d155STakashi Sakamoto cpu_to_le32(0xe0000000),
498db9d155STakashi Sakamoto };
508db9d155STakashi Sakamoto __le32 quadlets[] = {0, 0, 0};
518db9d155STakashi Sakamoto bool has_src_bus_id = ohci1394_at_data_get_src_bus_id(expected);
528db9d155STakashi Sakamoto unsigned int speed = ohci1394_at_data_get_speed(expected);
538db9d155STakashi Sakamoto unsigned int tlabel = ohci1394_at_data_get_tlabel(expected);
548db9d155STakashi Sakamoto unsigned int retry = ohci1394_at_data_get_retry(expected);
558db9d155STakashi Sakamoto unsigned int tcode = ohci1394_at_data_get_tcode(expected);
568db9d155STakashi Sakamoto unsigned int destination_id = ohci1394_at_data_get_destination_id(expected);
578db9d155STakashi Sakamoto u64 destination_offset = ohci1394_at_data_get_destination_offset(expected);
588db9d155STakashi Sakamoto
598db9d155STakashi Sakamoto KUNIT_EXPECT_FALSE(test, has_src_bus_id);
608db9d155STakashi Sakamoto KUNIT_EXPECT_EQ(test, 0x02, speed);
618db9d155STakashi Sakamoto KUNIT_EXPECT_EQ(test, 0x03, tlabel);
628db9d155STakashi Sakamoto KUNIT_EXPECT_EQ(test, 0x02, retry);
638db9d155STakashi Sakamoto KUNIT_EXPECT_EQ(test, 0x08, tcode);
648db9d155STakashi Sakamoto
658db9d155STakashi Sakamoto ohci1394_at_data_set_src_bus_id(quadlets, has_src_bus_id);
668db9d155STakashi Sakamoto ohci1394_at_data_set_speed(quadlets, speed);
678db9d155STakashi Sakamoto ohci1394_at_data_set_tlabel(quadlets, tlabel);
688db9d155STakashi Sakamoto ohci1394_at_data_set_retry(quadlets, retry);
698db9d155STakashi Sakamoto ohci1394_at_data_set_tcode(quadlets, tcode);
708db9d155STakashi Sakamoto ohci1394_at_data_set_destination_id(quadlets, destination_id);
718db9d155STakashi Sakamoto ohci1394_at_data_set_destination_offset(quadlets, destination_offset);
728db9d155STakashi Sakamoto
738db9d155STakashi Sakamoto KUNIT_EXPECT_MEMEQ(test, quadlets, expected, sizeof(expected));
748db9d155STakashi Sakamoto }
758db9d155STakashi Sakamoto
test_it_data_serdes(struct kunit * test)76*1ce2a92bSTakashi Sakamoto static void test_it_data_serdes(struct kunit *test)
77*1ce2a92bSTakashi Sakamoto {
78*1ce2a92bSTakashi Sakamoto static const __le32 expected[] = {
79*1ce2a92bSTakashi Sakamoto cpu_to_le32(0x000349a7),
80*1ce2a92bSTakashi Sakamoto cpu_to_le32(0x02300000),
81*1ce2a92bSTakashi Sakamoto };
82*1ce2a92bSTakashi Sakamoto __le32 quadlets[] = {0, 0};
83*1ce2a92bSTakashi Sakamoto unsigned int scode = ohci1394_it_data_get_speed(expected);
84*1ce2a92bSTakashi Sakamoto unsigned int tag = ohci1394_it_data_get_tag(expected);
85*1ce2a92bSTakashi Sakamoto unsigned int channel = ohci1394_it_data_get_channel(expected);
86*1ce2a92bSTakashi Sakamoto unsigned int tcode = ohci1394_it_data_get_tcode(expected);
87*1ce2a92bSTakashi Sakamoto unsigned int sync = ohci1394_it_data_get_sync(expected);
88*1ce2a92bSTakashi Sakamoto unsigned int data_length = ohci1394_it_data_get_data_length(expected);
89*1ce2a92bSTakashi Sakamoto
90*1ce2a92bSTakashi Sakamoto KUNIT_EXPECT_EQ(test, 0x03, scode);
91*1ce2a92bSTakashi Sakamoto KUNIT_EXPECT_EQ(test, 0x01, tag);
92*1ce2a92bSTakashi Sakamoto KUNIT_EXPECT_EQ(test, 0x09, channel);
93*1ce2a92bSTakashi Sakamoto KUNIT_EXPECT_EQ(test, 0x0a, tcode);
94*1ce2a92bSTakashi Sakamoto KUNIT_EXPECT_EQ(test, 0x7, sync);
95*1ce2a92bSTakashi Sakamoto KUNIT_EXPECT_EQ(test, 0x0230, data_length);
96*1ce2a92bSTakashi Sakamoto
97*1ce2a92bSTakashi Sakamoto ohci1394_it_data_set_speed(quadlets, scode);
98*1ce2a92bSTakashi Sakamoto ohci1394_it_data_set_tag(quadlets, tag);
99*1ce2a92bSTakashi Sakamoto ohci1394_it_data_set_channel(quadlets, channel);
100*1ce2a92bSTakashi Sakamoto ohci1394_it_data_set_tcode(quadlets, tcode);
101*1ce2a92bSTakashi Sakamoto ohci1394_it_data_set_sync(quadlets, sync);
102*1ce2a92bSTakashi Sakamoto ohci1394_it_data_set_data_length(quadlets, data_length);
103*1ce2a92bSTakashi Sakamoto
104*1ce2a92bSTakashi Sakamoto KUNIT_EXPECT_MEMEQ(test, quadlets, expected, sizeof(expected));
105*1ce2a92bSTakashi Sakamoto }
106*1ce2a92bSTakashi Sakamoto
1077a14f78dSTakashi Sakamoto static struct kunit_case ohci_serdes_test_cases[] = {
1087a14f78dSTakashi Sakamoto KUNIT_CASE(test_self_id_count_register_deserialization),
1097a14f78dSTakashi Sakamoto KUNIT_CASE(test_self_id_receive_buffer_deserialization),
1108db9d155STakashi Sakamoto KUNIT_CASE(test_at_data_serdes),
111*1ce2a92bSTakashi Sakamoto KUNIT_CASE(test_it_data_serdes),
1127a14f78dSTakashi Sakamoto {}
1137a14f78dSTakashi Sakamoto };
1147a14f78dSTakashi Sakamoto
1157a14f78dSTakashi Sakamoto static struct kunit_suite ohci_serdes_test_suite = {
1167a14f78dSTakashi Sakamoto .name = "firewire-ohci-serdes",
1177a14f78dSTakashi Sakamoto .test_cases = ohci_serdes_test_cases,
1187a14f78dSTakashi Sakamoto };
1197a14f78dSTakashi Sakamoto kunit_test_suite(ohci_serdes_test_suite);
1207a14f78dSTakashi Sakamoto
1217a14f78dSTakashi Sakamoto MODULE_DESCRIPTION("FireWire buffers and registers serialization/deserialization unit test suite");
1227a14f78dSTakashi Sakamoto MODULE_LICENSE("GPL");
123