1 // SPDX-License-Identifier: GPL-2.0-or-later
3 // packet-serdes-test.c - An application of Kunit to check serialization/deserialization of packets
4 // defined by IEEE 1394.
6 // Copyright (c) 2024 Takashi Sakamoto
8 #include <kunit/test.h>
10 #include <linux/firewire-constants.h>
12 #include "packet-header-definitions.h"
13 #include "phy-packet-definitions.h"
15 static void serialize_async_header_common(u32 header
[ASYNC_HEADER_QUADLET_COUNT
],
16 unsigned int dst_id
, unsigned int tlabel
,
17 unsigned int retry
, unsigned int tcode
,
18 unsigned int priority
, unsigned int src_id
)
20 async_header_set_destination(header
, dst_id
);
21 async_header_set_tlabel(header
, tlabel
);
22 async_header_set_retry(header
, retry
);
23 async_header_set_tcode(header
, tcode
);
24 async_header_set_priority(header
, priority
);
25 async_header_set_source(header
, src_id
);
28 static void serialize_async_header_request(u32 header
[ASYNC_HEADER_QUADLET_COUNT
],
29 unsigned int dst_id
, unsigned int tlabel
,
30 unsigned int retry
, unsigned int tcode
,
31 unsigned int priority
, unsigned int src_id
, u64 offset
)
33 serialize_async_header_common(header
, dst_id
, tlabel
, retry
, tcode
, priority
, src_id
);
34 async_header_set_offset(header
, offset
);
37 static void serialize_async_header_quadlet_request(u32 header
[ASYNC_HEADER_QUADLET_COUNT
],
38 unsigned int dst_id
, unsigned int tlabel
,
39 unsigned int retry
, unsigned int tcode
,
40 unsigned int priority
, unsigned int src_id
,
43 serialize_async_header_request(header
, dst_id
, tlabel
, retry
, tcode
, priority
, src_id
,
47 static void serialize_async_header_block_request(u32 header
[ASYNC_HEADER_QUADLET_COUNT
],
48 unsigned int dst_id
, unsigned int tlabel
,
49 unsigned int retry
, unsigned int tcode
,
50 unsigned int priority
, unsigned int src_id
,
51 u64 offset
, unsigned int data_length
,
52 unsigned int extended_tcode
)
54 serialize_async_header_request(header
, dst_id
, tlabel
, retry
, tcode
, priority
, src_id
,
56 async_header_set_data_length(header
, data_length
);
57 async_header_set_extended_tcode(header
, extended_tcode
);
60 static void serialize_async_header_response(u32 header
[ASYNC_HEADER_QUADLET_COUNT
],
61 unsigned int dst_id
, unsigned int tlabel
,
62 unsigned int retry
, unsigned int tcode
,
63 unsigned int priority
, unsigned int src_id
,
66 serialize_async_header_common(header
, dst_id
, tlabel
, retry
, tcode
, priority
, src_id
);
67 async_header_set_rcode(header
, rcode
);
70 static void serialize_async_header_quadlet_response(u32 header
[ASYNC_HEADER_QUADLET_COUNT
],
71 unsigned int dst_id
, unsigned int tlabel
,
72 unsigned int retry
, unsigned int tcode
,
73 unsigned int priority
, unsigned int src_id
,
76 serialize_async_header_response(header
, dst_id
, tlabel
, retry
, tcode
, priority
, src_id
,
80 static void serialize_async_header_block_response(u32 header
[ASYNC_HEADER_QUADLET_COUNT
],
81 unsigned int dst_id
, unsigned int tlabel
,
82 unsigned int retry
, unsigned int tcode
,
83 unsigned int priority
, unsigned int src_id
,
84 unsigned int rcode
, unsigned int data_length
,
85 unsigned int extended_tcode
)
87 serialize_async_header_response(header
, dst_id
, tlabel
, retry
, tcode
, priority
, src_id
,
89 async_header_set_data_length(header
, data_length
);
90 async_header_set_extended_tcode(header
, extended_tcode
);
93 static void deserialize_async_header_common(const u32 header
[ASYNC_HEADER_QUADLET_COUNT
],
94 unsigned int *dst_id
, unsigned int *tlabel
,
95 unsigned int *retry
, unsigned int *tcode
,
96 unsigned int *priority
, unsigned int *src_id
)
98 *dst_id
= async_header_get_destination(header
);
99 *tlabel
= async_header_get_tlabel(header
);
100 *retry
= async_header_get_retry(header
);
101 *tcode
= async_header_get_tcode(header
);
102 *priority
= async_header_get_priority(header
);
103 *src_id
= async_header_get_source(header
);
106 static void deserialize_async_header_request(const u32 header
[ASYNC_HEADER_QUADLET_COUNT
],
107 unsigned int *dst_id
, unsigned int *tlabel
,
108 unsigned int *retry
, unsigned int *tcode
,
109 unsigned int *priority
, unsigned int *src_id
,
112 deserialize_async_header_common(header
, dst_id
, tlabel
, retry
, tcode
, priority
, src_id
);
113 *offset
= async_header_get_offset(header
);
116 static void deserialize_async_header_quadlet_request(const u32 header
[ASYNC_HEADER_QUADLET_COUNT
],
117 unsigned int *dst_id
, unsigned int *tlabel
,
118 unsigned int *retry
, unsigned int *tcode
,
119 unsigned int *priority
, unsigned int *src_id
,
122 deserialize_async_header_request(header
, dst_id
, tlabel
, retry
, tcode
, priority
, src_id
,
126 static void deserialize_async_header_block_request(const u32 header
[ASYNC_HEADER_QUADLET_COUNT
],
127 unsigned int *dst_id
, unsigned int *tlabel
,
128 unsigned int *retry
, unsigned int *tcode
,
129 unsigned int *priority
, unsigned int *src_id
,
131 unsigned int *data_length
,
132 unsigned int *extended_tcode
)
134 deserialize_async_header_request(header
, dst_id
, tlabel
, retry
, tcode
, priority
, src_id
,
136 *data_length
= async_header_get_data_length(header
);
137 *extended_tcode
= async_header_get_extended_tcode(header
);
140 static void deserialize_async_header_response(const u32 header
[ASYNC_HEADER_QUADLET_COUNT
],
141 unsigned int *dst_id
, unsigned int *tlabel
,
142 unsigned int *retry
, unsigned int *tcode
,
143 unsigned int *priority
, unsigned int *src_id
,
146 deserialize_async_header_common(header
, dst_id
, tlabel
, retry
, tcode
, priority
, src_id
);
147 *rcode
= async_header_get_rcode(header
);
150 static void deserialize_async_header_quadlet_response(const u32 header
[ASYNC_HEADER_QUADLET_COUNT
],
151 unsigned int *dst_id
, unsigned int *tlabel
,
152 unsigned int *retry
, unsigned int *tcode
,
153 unsigned int *priority
, unsigned int *src_id
,
156 deserialize_async_header_response(header
, dst_id
, tlabel
, retry
, tcode
, priority
, src_id
, rcode
);
159 static void deserialize_async_header_block_response(const u32 header
[ASYNC_HEADER_QUADLET_COUNT
],
160 unsigned int *dst_id
, unsigned int *tlabel
,
161 unsigned int *retry
, unsigned int *tcode
,
162 unsigned int *priority
, unsigned int *src_id
,
163 unsigned int *rcode
, unsigned int *data_length
,
164 unsigned int *extended_tcode
)
166 deserialize_async_header_response(header
, dst_id
, tlabel
, retry
, tcode
, priority
, src_id
, rcode
);
167 *data_length
= async_header_get_data_length(header
);
168 *extended_tcode
= async_header_get_extended_tcode(header
);
171 static void serialize_isoc_header(u32
*header
, unsigned int data_length
, unsigned int tag
,
172 unsigned int channel
, unsigned int tcode
, unsigned int sy
)
174 isoc_header_set_data_length(header
, data_length
);
175 isoc_header_set_tag(header
, tag
);
176 isoc_header_set_channel(header
, channel
);
177 isoc_header_set_tcode(header
, tcode
);
178 isoc_header_set_sy(header
, sy
);
181 static void deserialize_isoc_header(u32 header
, unsigned int *data_length
, unsigned int *tag
,
182 unsigned int *channel
, unsigned int *tcode
, unsigned int *sy
)
184 *data_length
= isoc_header_get_data_length(header
);
185 *tag
= isoc_header_get_tag(header
);
186 *channel
= isoc_header_get_channel(header
);
187 *tcode
= isoc_header_get_tcode(header
);
188 *sy
= isoc_header_get_sy(header
);
191 static void serialize_phy_packet_self_id_zero(u32
*quadlet
, unsigned int packet_identifier
,
192 unsigned int phy_id
, bool extended
,
193 bool link_is_active
, unsigned int gap_count
,
194 unsigned int scode
, bool is_contender
,
195 unsigned int power_class
, bool is_initiated_reset
,
196 bool has_more_packets
)
198 phy_packet_set_packet_identifier(quadlet
, packet_identifier
);
199 phy_packet_self_id_set_phy_id(quadlet
, phy_id
);
200 phy_packet_self_id_set_extended(quadlet
, extended
);
201 phy_packet_self_id_zero_set_link_active(quadlet
, link_is_active
);
202 phy_packet_self_id_zero_set_gap_count(quadlet
, gap_count
);
203 phy_packet_self_id_zero_set_scode(quadlet
, scode
);
204 phy_packet_self_id_zero_set_contender(quadlet
, is_contender
);
205 phy_packet_self_id_zero_set_power_class(quadlet
, power_class
);
206 phy_packet_self_id_zero_set_initiated_reset(quadlet
, is_initiated_reset
);
207 phy_packet_self_id_set_more_packets(quadlet
, has_more_packets
);
210 static void deserialize_phy_packet_self_id_zero(u32 quadlet
, unsigned int *packet_identifier
,
211 unsigned int *phy_id
, bool *extended
,
212 bool *link_is_active
, unsigned int *gap_count
,
213 unsigned int *scode
, bool *is_contender
,
214 unsigned int *power_class
,
215 bool *is_initiated_reset
, bool *has_more_packets
)
217 *packet_identifier
= phy_packet_get_packet_identifier(quadlet
);
218 *phy_id
= phy_packet_self_id_get_phy_id(quadlet
);
219 *extended
= phy_packet_self_id_get_extended(quadlet
);
220 *link_is_active
= phy_packet_self_id_zero_get_link_active(quadlet
);
221 *gap_count
= phy_packet_self_id_zero_get_gap_count(quadlet
);
222 *scode
= phy_packet_self_id_zero_get_scode(quadlet
);
223 *is_contender
= phy_packet_self_id_zero_get_contender(quadlet
);
224 *power_class
= phy_packet_self_id_zero_get_power_class(quadlet
);
225 *is_initiated_reset
= phy_packet_self_id_zero_get_initiated_reset(quadlet
);
226 *has_more_packets
= phy_packet_self_id_get_more_packets(quadlet
);
229 static void serialize_phy_packet_self_id_extended(u32
*quadlet
, unsigned int packet_identifier
,
230 unsigned int phy_id
, bool extended
,
231 unsigned int sequence
, bool has_more_packets
)
233 phy_packet_set_packet_identifier(quadlet
, packet_identifier
);
234 phy_packet_self_id_set_phy_id(quadlet
, phy_id
);
235 phy_packet_self_id_set_extended(quadlet
, extended
);
236 phy_packet_self_id_extended_set_sequence(quadlet
, sequence
);
237 phy_packet_self_id_set_more_packets(quadlet
, has_more_packets
);
240 static void deserialize_phy_packet_self_id_extended(u32 quadlet
, unsigned int *packet_identifier
,
241 unsigned int *phy_id
, bool *extended
,
242 unsigned int *sequence
, bool *has_more_packets
)
244 *packet_identifier
= phy_packet_get_packet_identifier(quadlet
);
245 *phy_id
= phy_packet_self_id_get_phy_id(quadlet
);
246 *extended
= phy_packet_self_id_get_extended(quadlet
);
247 *sequence
= phy_packet_self_id_extended_get_sequence(quadlet
);
248 *has_more_packets
= phy_packet_self_id_get_more_packets(quadlet
);
251 static void serialize_phy_packet_phy_config(u32
*quadlet
, unsigned int packet_identifier
,
252 unsigned int root_id
, bool has_force_root_node
,
253 bool has_gap_count_optimization
, unsigned int gap_count
)
255 phy_packet_set_packet_identifier(quadlet
, packet_identifier
);
256 phy_packet_phy_config_set_root_id(quadlet
, root_id
);
257 phy_packet_phy_config_set_force_root_node(quadlet
, has_force_root_node
);
258 phy_packet_phy_config_set_gap_count_optimization(quadlet
, has_gap_count_optimization
);
259 phy_packet_phy_config_set_gap_count(quadlet
, gap_count
);
262 static void deserialize_phy_packet_phy_config(u32 quadlet
, unsigned int *packet_identifier
,
263 unsigned int *root_id
, bool *has_force_root_node
,
264 bool *has_gap_count_optimization
,
265 unsigned int *gap_count
)
267 *packet_identifier
= phy_packet_get_packet_identifier(quadlet
);
268 *root_id
= phy_packet_phy_config_get_root_id(quadlet
);
269 *has_force_root_node
= phy_packet_phy_config_get_force_root_node(quadlet
);
270 *has_gap_count_optimization
= phy_packet_phy_config_get_gap_count_optimization(quadlet
);
271 *gap_count
= phy_packet_phy_config_get_gap_count(quadlet
);
274 static void test_async_header_write_quadlet_request(struct kunit
*test
)
276 static const u32 expected
[ASYNC_HEADER_QUADLET_COUNT
] = {
282 u32 header
[ASYNC_HEADER_QUADLET_COUNT
] = {0, 0, 0, 0};
288 unsigned int priority
;
293 deserialize_async_header_quadlet_request(expected
, &dst_id
, &tlabel
, &retry
, &tcode
,
294 &priority
, &src_id
, &offset
);
295 quadlet_data
= async_header_get_quadlet_data(expected
);
297 KUNIT_EXPECT_EQ(test
, 0xffc0, dst_id
);
298 KUNIT_EXPECT_EQ(test
, 0x14, tlabel
);
299 KUNIT_EXPECT_EQ(test
, 0x01, retry
);
300 KUNIT_EXPECT_EQ(test
, TCODE_WRITE_QUADLET_REQUEST
, tcode
);
301 KUNIT_EXPECT_EQ(test
, 0x00, priority
);
302 KUNIT_EXPECT_EQ(test
, 0xffc1, src_id
);
303 KUNIT_EXPECT_EQ(test
, 0xfffff0000234, offset
);
304 KUNIT_EXPECT_EQ(test
, 0x1f0000c0, quadlet_data
);
306 serialize_async_header_quadlet_request(header
, dst_id
, tlabel
, retry
, tcode
, priority
,
308 async_header_set_quadlet_data(header
, quadlet_data
);
310 KUNIT_EXPECT_MEMEQ(test
, header
, expected
, sizeof(expected
));
313 static void test_async_header_write_block_request(struct kunit
*test
)
315 static const u32 expected
[ASYNC_HEADER_QUADLET_COUNT
] = {
321 u32 header
[ASYNC_HEADER_QUADLET_COUNT
] = {0, 0, 0, 0};
327 unsigned int priority
;
330 unsigned int data_length
;
331 unsigned int extended_tcode
;
333 deserialize_async_header_block_request(expected
, &dst_id
, &tlabel
, &retry
, &tcode
,
334 &priority
, &src_id
, &offset
, &data_length
,
337 KUNIT_EXPECT_EQ(test
, 0xffc0, dst_id
);
338 KUNIT_EXPECT_EQ(test
, 0x19, tlabel
);
339 KUNIT_EXPECT_EQ(test
, 0x01, retry
);
340 KUNIT_EXPECT_EQ(test
, TCODE_WRITE_BLOCK_REQUEST
, tcode
);
341 KUNIT_EXPECT_EQ(test
, 0x00, priority
);
342 KUNIT_EXPECT_EQ(test
, 0xffc1, src_id
);
343 KUNIT_EXPECT_EQ(test
, 0xecc000000000, offset
);
344 KUNIT_EXPECT_EQ(test
, 0x0018, data_length
);
345 KUNIT_EXPECT_EQ(test
, 0x0000, extended_tcode
);
347 serialize_async_header_block_request(header
, dst_id
, tlabel
, retry
, tcode
, priority
, src_id
,
348 offset
, data_length
, extended_tcode
);
350 KUNIT_EXPECT_MEMEQ(test
, header
, expected
, sizeof(expected
));
353 static void test_async_header_write_response(struct kunit
*test
)
355 static const u32 expected
[ASYNC_HEADER_QUADLET_COUNT
] = {
361 u32 header
[ASYNC_HEADER_QUADLET_COUNT
] = {0, 0, 0, 0};
367 unsigned int priority
;
371 deserialize_async_header_quadlet_response(expected
, &dst_id
, &tlabel
, &retry
, &tcode
,
372 &priority
, &src_id
, &rcode
);
374 KUNIT_EXPECT_EQ(test
, 0xffc1, dst_id
);
375 KUNIT_EXPECT_EQ(test
, 0x14, tlabel
);
376 KUNIT_EXPECT_EQ(test
, 0x01, retry
);
377 KUNIT_EXPECT_EQ(test
, TCODE_WRITE_RESPONSE
, tcode
);
378 KUNIT_EXPECT_EQ(test
, 0x00, priority
);
379 KUNIT_EXPECT_EQ(test
, 0xffc0, src_id
);
380 KUNIT_EXPECT_EQ(test
, RCODE_COMPLETE
, rcode
);
382 serialize_async_header_quadlet_response(header
, dst_id
, tlabel
, retry
, tcode
, priority
,
385 KUNIT_EXPECT_MEMEQ(test
, header
, expected
, sizeof(expected
) - sizeof(expected
[0]));
388 static void test_async_header_read_quadlet_request(struct kunit
*test
)
390 static const u32 expected
[ASYNC_HEADER_QUADLET_COUNT
] = {
396 u32 header
[ASYNC_HEADER_QUADLET_COUNT
] = {0, 0, 0, 0};
402 unsigned int priority
;
406 deserialize_async_header_quadlet_request(expected
, &dst_id
, &tlabel
, &retry
, &tcode
,
407 &priority
, &src_id
, &offset
);
409 KUNIT_EXPECT_EQ(test
, 0xffc0, dst_id
);
410 KUNIT_EXPECT_EQ(test
, 0x3c, tlabel
);
411 KUNIT_EXPECT_EQ(test
, 0x01, retry
);
412 KUNIT_EXPECT_EQ(test
, TCODE_READ_QUADLET_REQUEST
, tcode
);
413 KUNIT_EXPECT_EQ(test
, 0x00, priority
);
414 KUNIT_EXPECT_EQ(test
, 0xffc1, src_id
);
415 KUNIT_EXPECT_EQ(test
, 0xfffff0000984, offset
);
417 serialize_async_header_quadlet_request(header
, dst_id
, tlabel
, retry
, tcode
, priority
,
420 KUNIT_EXPECT_MEMEQ(test
, header
, expected
, sizeof(expected
));
423 static void test_async_header_read_quadlet_response(struct kunit
*test
)
425 static const u32 expected
[ASYNC_HEADER_QUADLET_COUNT
] = {
431 u32 header
[ASYNC_HEADER_QUADLET_COUNT
] = {0, 0, 0, 0};
437 unsigned int priority
;
442 deserialize_async_header_quadlet_response(expected
, &dst_id
, &tlabel
, &retry
, &tcode
,
443 &priority
, &src_id
, &rcode
);
444 quadlet_data
= async_header_get_quadlet_data(expected
);
446 KUNIT_EXPECT_EQ(test
, 0xffc1, dst_id
);
447 KUNIT_EXPECT_EQ(test
, 0x3c, tlabel
);
448 KUNIT_EXPECT_EQ(test
, 0x01, retry
);
449 KUNIT_EXPECT_EQ(test
, TCODE_READ_QUADLET_RESPONSE
, tcode
);
450 KUNIT_EXPECT_EQ(test
, 0x00, priority
);
451 KUNIT_EXPECT_EQ(test
, 0xffc0, src_id
);
452 KUNIT_EXPECT_EQ(test
, RCODE_COMPLETE
, rcode
);
453 KUNIT_EXPECT_EQ(test
, 0x00000180, quadlet_data
);
455 serialize_async_header_quadlet_response(header
, dst_id
, tlabel
, retry
, tcode
, priority
,
457 async_header_set_quadlet_data(header
, quadlet_data
);
459 KUNIT_EXPECT_MEMEQ(test
, header
, expected
, sizeof(expected
));
462 static void test_async_header_read_block_request(struct kunit
*test
)
464 static const u32 expected
[ASYNC_HEADER_QUADLET_COUNT
] = {
470 u32 header
[ASYNC_HEADER_QUADLET_COUNT
] = {0, 0, 0, 0};
476 unsigned int priority
;
479 unsigned int data_length
;
480 unsigned int extended_tcode
;
482 deserialize_async_header_block_request(expected
, &dst_id
, &tlabel
, &retry
, &tcode
,
483 &priority
, &src_id
, &offset
, &data_length
,
486 KUNIT_EXPECT_EQ(test
, 0xffc0, dst_id
);
487 KUNIT_EXPECT_EQ(test
, 0x38, tlabel
);
488 KUNIT_EXPECT_EQ(test
, 0x01, retry
);
489 KUNIT_EXPECT_EQ(test
, TCODE_READ_BLOCK_REQUEST
, tcode
);
490 KUNIT_EXPECT_EQ(test
, 0x00, priority
);
491 KUNIT_EXPECT_EQ(test
, 0xffc1, src_id
);
492 KUNIT_EXPECT_EQ(test
, 0xfffff0000400, offset
);
493 KUNIT_EXPECT_EQ(test
, 0x0020, data_length
);
494 KUNIT_EXPECT_EQ(test
, 0x0000, extended_tcode
);
496 serialize_async_header_block_request(header
, dst_id
, tlabel
, retry
, tcode
, priority
, src_id
,
497 offset
, data_length
, extended_tcode
);
499 KUNIT_EXPECT_MEMEQ(test
, header
, expected
, sizeof(expected
));
502 static void test_async_header_read_block_response(struct kunit
*test
)
504 static const u32 expected
[ASYNC_HEADER_QUADLET_COUNT
] = {
510 u32 header
[ASYNC_HEADER_QUADLET_COUNT
] = {0, 0, 0, 0};
516 unsigned int priority
;
519 unsigned int data_length
;
520 unsigned int extended_tcode
;
522 deserialize_async_header_block_response(expected
, &dst_id
, &tlabel
, &retry
, &tcode
,
523 &priority
, &src_id
, &rcode
, &data_length
,
526 KUNIT_EXPECT_EQ(test
, 0xffc1, dst_id
);
527 KUNIT_EXPECT_EQ(test
, 0x38, tlabel
);
528 KUNIT_EXPECT_EQ(test
, 0x01, retry
);
529 KUNIT_EXPECT_EQ(test
, TCODE_READ_BLOCK_RESPONSE
, tcode
);
530 KUNIT_EXPECT_EQ(test
, 0x00, priority
);
531 KUNIT_EXPECT_EQ(test
, 0xffc0, src_id
);
532 KUNIT_EXPECT_EQ(test
, RCODE_COMPLETE
, rcode
);
533 KUNIT_EXPECT_EQ(test
, 0x0020, data_length
);
534 KUNIT_EXPECT_EQ(test
, 0x0000, extended_tcode
);
536 serialize_async_header_block_response(header
, dst_id
, tlabel
, retry
, tcode
, priority
,
537 src_id
, rcode
, data_length
, extended_tcode
);
539 KUNIT_EXPECT_MEMEQ(test
, header
, expected
, sizeof(expected
));
542 static void test_async_header_lock_request(struct kunit
*test
)
544 static const u32 expected
[ASYNC_HEADER_QUADLET_COUNT
] = {
550 u32 header
[ASYNC_HEADER_QUADLET_COUNT
] = {0, 0, 0, 0};
556 unsigned int priority
;
559 unsigned int data_length
;
560 unsigned int extended_tcode
;
562 deserialize_async_header_block_request(expected
, &dst_id
, &tlabel
, &retry
, &tcode
,
563 &priority
, &src_id
, &offset
, &data_length
,
566 KUNIT_EXPECT_EQ(test
, 0xffc0, dst_id
);
567 KUNIT_EXPECT_EQ(test
, 0x0b, tlabel
);
568 KUNIT_EXPECT_EQ(test
, 0x01, retry
);
569 KUNIT_EXPECT_EQ(test
, TCODE_LOCK_REQUEST
, tcode
);
570 KUNIT_EXPECT_EQ(test
, 0x00, priority
);
571 KUNIT_EXPECT_EQ(test
, 0xffc1, src_id
);
572 KUNIT_EXPECT_EQ(test
, 0xfffff0000984, offset
);
573 KUNIT_EXPECT_EQ(test
, 0x0008, data_length
);
574 KUNIT_EXPECT_EQ(test
, EXTCODE_COMPARE_SWAP
, extended_tcode
);
576 serialize_async_header_block_request(header
, dst_id
, tlabel
, retry
, tcode
, priority
, src_id
,
577 offset
, data_length
, extended_tcode
);
579 KUNIT_EXPECT_MEMEQ(test
, header
, expected
, sizeof(expected
));
582 static void test_async_header_lock_response(struct kunit
*test
)
584 static const u32 expected
[ASYNC_HEADER_QUADLET_COUNT
] = {
590 u32 header
[ASYNC_HEADER_QUADLET_COUNT
] = {0, 0, 0, 0};
596 unsigned int priority
;
599 unsigned int data_length
;
600 unsigned int extended_tcode
;
602 deserialize_async_header_block_response(expected
, &dst_id
, &tlabel
, &retry
, &tcode
,
603 &priority
, &src_id
, &rcode
, &data_length
,
606 KUNIT_EXPECT_EQ(test
, 0xffc1, dst_id
);
607 KUNIT_EXPECT_EQ(test
, 0x0b, tlabel
);
608 KUNIT_EXPECT_EQ(test
, 0x01, retry
);
609 KUNIT_EXPECT_EQ(test
, TCODE_LOCK_RESPONSE
, tcode
);
610 KUNIT_EXPECT_EQ(test
, 0x00, priority
);
611 KUNIT_EXPECT_EQ(test
, 0xffc0, src_id
);
612 KUNIT_EXPECT_EQ(test
, RCODE_COMPLETE
, rcode
);
613 KUNIT_EXPECT_EQ(test
, 0x0004, data_length
);
614 KUNIT_EXPECT_EQ(test
, EXTCODE_COMPARE_SWAP
, extended_tcode
);
616 serialize_async_header_block_response(header
, dst_id
, tlabel
, retry
, tcode
, priority
,
617 src_id
, rcode
, data_length
, extended_tcode
);
619 KUNIT_EXPECT_MEMEQ(test
, header
, expected
, sizeof(expected
));
622 static void test_isoc_header(struct kunit
*test
)
624 const u32 expected
= 0x00d08dec;
627 unsigned int data_length
;
629 unsigned int channel
;
633 deserialize_isoc_header(expected
, &data_length
, &tag
, &channel
, &tcode
, &sy
);
635 KUNIT_EXPECT_EQ(test
, 0xd0, data_length
);
636 KUNIT_EXPECT_EQ(test
, 0x02, tag
);
637 KUNIT_EXPECT_EQ(test
, 0x0d, channel
);
638 KUNIT_EXPECT_EQ(test
, 0x0e, tcode
);
639 KUNIT_EXPECT_EQ(test
, 0x0c, sy
);
641 serialize_isoc_header(&header
, data_length
, tag
, channel
, tcode
, sy
);
643 KUNIT_EXPECT_EQ(test
, header
, expected
);
646 static void test_phy_packet_self_id_zero_case0(struct kunit
*test
)
648 // TSB41AB1/2 with 1 port.
649 const u32 expected
[] = {0x80458c80};
650 u32 quadlets
[] = {0};
652 unsigned int packet_identifier
;
656 unsigned int gap_count
;
659 unsigned int power_class
;
660 enum phy_packet_self_id_port_status port_status
[3];
661 bool is_initiated_reset
;
662 bool has_more_packets
;
663 unsigned int port_index
;
665 deserialize_phy_packet_self_id_zero(expected
[0], &packet_identifier
, &phy_id
, &extended
,
666 &link_is_active
, &gap_count
, &scode
, &is_contender
,
667 &power_class
, &is_initiated_reset
, &has_more_packets
);
669 KUNIT_EXPECT_EQ(test
, PHY_PACKET_PACKET_IDENTIFIER_SELF_ID
, packet_identifier
);
670 KUNIT_EXPECT_EQ(test
, 0, phy_id
);
671 KUNIT_EXPECT_FALSE(test
, extended
);
672 KUNIT_EXPECT_TRUE(test
, link_is_active
);
673 KUNIT_EXPECT_EQ(test
, 0x05, gap_count
);
674 KUNIT_EXPECT_EQ(test
, SCODE_400
, scode
);
675 KUNIT_EXPECT_TRUE(test
, is_contender
);
676 KUNIT_EXPECT_EQ(test
, 0x4, power_class
);
677 KUNIT_EXPECT_FALSE(test
, is_initiated_reset
);
678 KUNIT_EXPECT_FALSE(test
, has_more_packets
);
680 serialize_phy_packet_self_id_zero(quadlets
, packet_identifier
, phy_id
, extended
,
681 link_is_active
, gap_count
, scode
, is_contender
,
682 power_class
, is_initiated_reset
, has_more_packets
);
684 for (port_index
= 0; port_index
< ARRAY_SIZE(port_status
); ++port_index
) {
685 port_status
[port_index
] =
686 self_id_sequence_get_port_status(expected
, ARRAY_SIZE(expected
), port_index
);
689 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_PARENT
, port_status
[0]);
690 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_NONE
, port_status
[1]);
691 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_NONE
, port_status
[2]);
693 for (port_index
= 0; port_index
< ARRAY_SIZE(port_status
); ++port_index
) {
694 self_id_sequence_set_port_status(quadlets
, ARRAY_SIZE(quadlets
), port_index
,
695 port_status
[port_index
]);
698 KUNIT_EXPECT_MEMEQ(test
, quadlets
, expected
, sizeof(expected
));
701 static void test_phy_packet_self_id_zero_case1(struct kunit
*test
)
703 // XIO2213 and TSB81BA3E with 3 ports.
704 const u32 expected
[] = {0x817fcc5e};
705 u32 quadlets
[] = {0};
707 unsigned int packet_identifier
;
711 unsigned int gap_count
;
714 unsigned int power_class
;
715 enum phy_packet_self_id_port_status port_status
[3];
716 bool is_initiated_reset
;
717 bool has_more_packets
;
718 unsigned int port_index
;
720 deserialize_phy_packet_self_id_zero(expected
[0], &packet_identifier
, &phy_id
, &extended
,
721 &link_is_active
, &gap_count
, &scode
, &is_contender
,
722 &power_class
, &is_initiated_reset
, &has_more_packets
);
724 KUNIT_EXPECT_EQ(test
, PHY_PACKET_PACKET_IDENTIFIER_SELF_ID
, packet_identifier
);
725 KUNIT_EXPECT_EQ(test
, 1, phy_id
);
726 KUNIT_EXPECT_FALSE(test
, extended
);
727 KUNIT_EXPECT_TRUE(test
, link_is_active
);
728 KUNIT_EXPECT_EQ(test
, 0x3f, gap_count
);
729 KUNIT_EXPECT_EQ(test
, SCODE_800
, scode
);
730 KUNIT_EXPECT_TRUE(test
, is_contender
);
731 KUNIT_EXPECT_EQ(test
, 0x4, power_class
);
732 KUNIT_EXPECT_TRUE(test
, is_initiated_reset
);
733 KUNIT_EXPECT_FALSE(test
, has_more_packets
);
735 serialize_phy_packet_self_id_zero(quadlets
, packet_identifier
, phy_id
, extended
,
736 link_is_active
, gap_count
, scode
, is_contender
,
737 power_class
, is_initiated_reset
, has_more_packets
);
739 for (port_index
= 0; port_index
< ARRAY_SIZE(port_status
); ++port_index
) {
740 port_status
[port_index
] =
741 self_id_sequence_get_port_status(expected
, ARRAY_SIZE(expected
), port_index
);
744 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN
, port_status
[0]);
745 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN
, port_status
[1]);
746 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_CHILD
, port_status
[2]);
748 for (port_index
= 0; port_index
< ARRAY_SIZE(port_status
); ++port_index
) {
749 self_id_sequence_set_port_status(quadlets
, ARRAY_SIZE(quadlets
), port_index
,
750 port_status
[port_index
]);
753 KUNIT_EXPECT_MEMEQ(test
, quadlets
, expected
, sizeof(expected
));
756 static void test_phy_packet_self_id_zero_and_one(struct kunit
*test
)
758 // TSB41LV06A with 6 ports.
759 const u32 expected
[] = {
763 u32 quadlets
[] = {0, 0};
765 unsigned int packet_identifier
;
769 unsigned int gap_count
;
772 unsigned int power_class
;
773 enum phy_packet_self_id_port_status port_status
[11];
774 bool is_initiated_reset
;
775 bool has_more_packets
;
777 unsigned int sequence
;
778 unsigned int port_index
;
780 deserialize_phy_packet_self_id_zero(expected
[0], &packet_identifier
, &phy_id
, &extended
,
781 &link_is_active
, &gap_count
, &scode
, &is_contender
,
782 &power_class
, &is_initiated_reset
, &has_more_packets
);
784 KUNIT_EXPECT_EQ(test
, PHY_PACKET_PACKET_IDENTIFIER_SELF_ID
, packet_identifier
);
785 KUNIT_EXPECT_EQ(test
, 0, phy_id
);
786 KUNIT_EXPECT_FALSE(test
, extended
);
787 KUNIT_EXPECT_FALSE(test
, link_is_active
);
788 KUNIT_EXPECT_EQ(test
, 0x3f, gap_count
);
789 KUNIT_EXPECT_EQ(test
, SCODE_400
, scode
);
790 KUNIT_EXPECT_FALSE(test
, is_contender
);
791 KUNIT_EXPECT_EQ(test
, 0x4, power_class
);
792 KUNIT_EXPECT_FALSE(test
, is_initiated_reset
);
793 KUNIT_EXPECT_TRUE(test
, has_more_packets
);
795 serialize_phy_packet_self_id_zero(quadlets
, packet_identifier
, phy_id
, extended
,
796 link_is_active
, gap_count
, scode
, is_contender
,
797 power_class
, is_initiated_reset
, has_more_packets
);
799 deserialize_phy_packet_self_id_extended(expected
[1], &packet_identifier
, &phy_id
, &extended
,
800 &sequence
, &has_more_packets
);
802 KUNIT_EXPECT_EQ(test
, PHY_PACKET_PACKET_IDENTIFIER_SELF_ID
, packet_identifier
);
803 KUNIT_EXPECT_EQ(test
, 0, phy_id
);
804 KUNIT_EXPECT_TRUE(test
, extended
);
805 KUNIT_EXPECT_EQ(test
, 0, sequence
);
806 KUNIT_EXPECT_FALSE(test
, has_more_packets
);
808 serialize_phy_packet_self_id_extended(&quadlets
[1], packet_identifier
, phy_id
, extended
,
809 sequence
, has_more_packets
);
812 for (port_index
= 0; port_index
< ARRAY_SIZE(port_status
); ++port_index
) {
813 port_status
[port_index
] =
814 self_id_sequence_get_port_status(expected
, ARRAY_SIZE(expected
), port_index
);
817 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN
, port_status
[0]);
818 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN
, port_status
[1]);
819 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_PARENT
, port_status
[2]);
820 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN
, port_status
[3]);
821 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN
, port_status
[4]);
822 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_NCONN
, port_status
[5]);
823 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_NONE
, port_status
[6]);
824 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_NONE
, port_status
[7]);
825 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_NONE
, port_status
[8]);
826 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_NONE
, port_status
[9]);
827 KUNIT_EXPECT_EQ(test
, PHY_PACKET_SELF_ID_PORT_STATUS_NONE
, port_status
[10]);
829 for (port_index
= 0; port_index
< ARRAY_SIZE(port_status
); ++port_index
) {
830 self_id_sequence_set_port_status(quadlets
, ARRAY_SIZE(quadlets
), port_index
,
831 port_status
[port_index
]);
834 KUNIT_EXPECT_MEMEQ(test
, quadlets
, expected
, sizeof(expected
));
837 static void test_phy_packet_phy_config_force_root_node(struct kunit
*test
)
839 const u32 expected
= 0x02800000;
842 unsigned int packet_identifier
;
843 unsigned int root_id
;
844 bool has_force_root_node
;
845 bool has_gap_count_optimization
;
846 unsigned int gap_count
;
848 deserialize_phy_packet_phy_config(expected
, &packet_identifier
, &root_id
,
849 &has_force_root_node
, &has_gap_count_optimization
,
852 KUNIT_EXPECT_EQ(test
, PHY_PACKET_PACKET_IDENTIFIER_PHY_CONFIG
, packet_identifier
);
853 KUNIT_EXPECT_EQ(test
, 0x02, root_id
);
854 KUNIT_EXPECT_TRUE(test
, has_force_root_node
);
855 KUNIT_EXPECT_FALSE(test
, has_gap_count_optimization
);
856 KUNIT_EXPECT_EQ(test
, 0, gap_count
);
858 serialize_phy_packet_phy_config(&quadlet
, packet_identifier
, root_id
, has_force_root_node
,
859 has_gap_count_optimization
, gap_count
);
861 KUNIT_EXPECT_EQ(test
, quadlet
, expected
);
864 static void test_phy_packet_phy_config_gap_count_optimization(struct kunit
*test
)
866 const u32 expected
= 0x034f0000;
869 unsigned int packet_identifier
;
870 unsigned int root_id
;
871 bool has_force_root_node
;
872 bool has_gap_count_optimization
;
873 unsigned int gap_count
;
875 deserialize_phy_packet_phy_config(expected
, &packet_identifier
, &root_id
,
876 &has_force_root_node
, &has_gap_count_optimization
,
879 KUNIT_EXPECT_EQ(test
, PHY_PACKET_PACKET_IDENTIFIER_PHY_CONFIG
, packet_identifier
);
880 KUNIT_EXPECT_EQ(test
, 0x03, root_id
);
881 KUNIT_EXPECT_FALSE(test
, has_force_root_node
);
882 KUNIT_EXPECT_TRUE(test
, has_gap_count_optimization
);
883 KUNIT_EXPECT_EQ(test
, 0x0f, gap_count
);
885 serialize_phy_packet_phy_config(&quadlet
, packet_identifier
, root_id
, has_force_root_node
,
886 has_gap_count_optimization
, gap_count
);
888 KUNIT_EXPECT_EQ(test
, quadlet
, expected
);
891 static struct kunit_case packet_serdes_test_cases
[] = {
892 KUNIT_CASE(test_async_header_write_quadlet_request
),
893 KUNIT_CASE(test_async_header_write_block_request
),
894 KUNIT_CASE(test_async_header_write_response
),
895 KUNIT_CASE(test_async_header_read_quadlet_request
),
896 KUNIT_CASE(test_async_header_read_quadlet_response
),
897 KUNIT_CASE(test_async_header_read_block_request
),
898 KUNIT_CASE(test_async_header_read_block_response
),
899 KUNIT_CASE(test_async_header_lock_request
),
900 KUNIT_CASE(test_async_header_lock_response
),
901 KUNIT_CASE(test_isoc_header
),
902 KUNIT_CASE(test_phy_packet_self_id_zero_case0
),
903 KUNIT_CASE(test_phy_packet_self_id_zero_case1
),
904 KUNIT_CASE(test_phy_packet_self_id_zero_and_one
),
905 KUNIT_CASE(test_phy_packet_phy_config_force_root_node
),
906 KUNIT_CASE(test_phy_packet_phy_config_gap_count_optimization
),
910 static struct kunit_suite packet_serdes_test_suite
= {
911 .name
= "firewire-packet-serdes",
912 .test_cases
= packet_serdes_test_cases
,
914 kunit_test_suite(packet_serdes_test_suite
);
916 MODULE_DESCRIPTION("FireWire packet serialization/deserialization unit test suite");
917 MODULE_LICENSE("GPL");