Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

firewire: ohci: add static inline functions to serialize/deserialize data of AT DMA

In 1394 OHCI specification, the format of data for AT DMA is different from
the format of asynchronous packet in IEEE 1394 specification, in its spd
and srcBusID fields.

This commit adds some static inline functions to serialize/deserialize the
data of AT DMA.

Link: https://lore.kernel.org/r/20240802003606.109402-2-o-takashi@sakamocchi.jp
Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>

+149
+34
drivers/firewire/ohci-serdes-test.c
··· 40 40 KUNIT_EXPECT_EQ(test, 0xf38b, timestamp); 41 41 } 42 42 43 + static void test_at_data_serdes(struct kunit *test) 44 + { 45 + static const __le32 expected[] = { 46 + cpu_to_le32(0x00020e80), 47 + cpu_to_le32(0xffc2ffff), 48 + cpu_to_le32(0xe0000000), 49 + }; 50 + __le32 quadlets[] = {0, 0, 0}; 51 + bool has_src_bus_id = ohci1394_at_data_get_src_bus_id(expected); 52 + unsigned int speed = ohci1394_at_data_get_speed(expected); 53 + unsigned int tlabel = ohci1394_at_data_get_tlabel(expected); 54 + unsigned int retry = ohci1394_at_data_get_retry(expected); 55 + unsigned int tcode = ohci1394_at_data_get_tcode(expected); 56 + unsigned int destination_id = ohci1394_at_data_get_destination_id(expected); 57 + u64 destination_offset = ohci1394_at_data_get_destination_offset(expected); 58 + 59 + KUNIT_EXPECT_FALSE(test, has_src_bus_id); 60 + KUNIT_EXPECT_EQ(test, 0x02, speed); 61 + KUNIT_EXPECT_EQ(test, 0x03, tlabel); 62 + KUNIT_EXPECT_EQ(test, 0x02, retry); 63 + KUNIT_EXPECT_EQ(test, 0x08, tcode); 64 + 65 + ohci1394_at_data_set_src_bus_id(quadlets, has_src_bus_id); 66 + ohci1394_at_data_set_speed(quadlets, speed); 67 + ohci1394_at_data_set_tlabel(quadlets, tlabel); 68 + ohci1394_at_data_set_retry(quadlets, retry); 69 + ohci1394_at_data_set_tcode(quadlets, tcode); 70 + ohci1394_at_data_set_destination_id(quadlets, destination_id); 71 + ohci1394_at_data_set_destination_offset(quadlets, destination_offset); 72 + 73 + KUNIT_EXPECT_MEMEQ(test, quadlets, expected, sizeof(expected)); 74 + } 75 + 43 76 static struct kunit_case ohci_serdes_test_cases[] = { 44 77 KUNIT_CASE(test_self_id_count_register_deserialization), 45 78 KUNIT_CASE(test_self_id_receive_buffer_deserialization), 79 + KUNIT_CASE(test_at_data_serdes), 46 80 {} 47 81 }; 48 82
+115
drivers/firewire/ohci.h
··· 154 154 #define OHCI1394_evt_flushed 0xf 155 155 156 156 157 + // Asynchronous Transmit DMA. 158 + // 159 + // The content of first two quadlets of data for AT DMA is different from the header for IEEE 1394 160 + // asynchronous packet. 161 + 162 + #define OHCI1394_AT_DATA_Q0_srcBusID_MASK 0x00800000 163 + #define OHCI1394_AT_DATA_Q0_srcBusID_SHIFT 23 164 + #define OHCI1394_AT_DATA_Q0_spd_MASK 0x00070000 165 + #define OHCI1394_AT_DATA_Q0_spd_SHIFT 16 166 + #define OHCI1394_AT_DATA_Q0_tLabel_MASK 0x0000fc00 167 + #define OHCI1394_AT_DATA_Q0_tLabel_SHIFT 10 168 + #define OHCI1394_AT_DATA_Q0_rt_MASK 0x00000300 169 + #define OHCI1394_AT_DATA_Q0_rt_SHIFT 8 170 + #define OHCI1394_AT_DATA_Q0_tCode_MASK 0x000000f0 171 + #define OHCI1394_AT_DATA_Q0_tCode_SHIFT 4 172 + #define OHCI1394_AT_DATA_Q1_destinationId_MASK 0xffff0000 173 + #define OHCI1394_AT_DATA_Q1_destinationId_SHIFT 16 174 + #define OHCI1394_AT_DATA_Q1_destinationOffsetHigh_MASK 0x0000ffff 175 + #define OHCI1394_AT_DATA_Q1_destinationOffsetHigh_SHIFT 0 176 + #define OHCI1394_AT_DATA_Q1_rCode_MASK 0x0000f000 177 + #define OHCI1394_AT_DATA_Q1_rCode_SHIFT 12 178 + 179 + static inline bool ohci1394_at_data_get_src_bus_id(const __le32 *data) 180 + { 181 + return !!((data[0] & OHCI1394_AT_DATA_Q0_srcBusID_MASK) >> OHCI1394_AT_DATA_Q0_srcBusID_SHIFT); 182 + } 183 + 184 + static inline void ohci1394_at_data_set_src_bus_id(__le32 *data, bool src_bus_id) 185 + { 186 + data[0] &= cpu_to_le32(~OHCI1394_AT_DATA_Q0_srcBusID_MASK); 187 + data[0] |= cpu_to_le32((src_bus_id << OHCI1394_AT_DATA_Q0_srcBusID_SHIFT) & OHCI1394_AT_DATA_Q0_srcBusID_MASK); 188 + } 189 + 190 + static inline unsigned int ohci1394_at_data_get_speed(const __le32 *data) 191 + { 192 + return (le32_to_cpu(data[0]) & OHCI1394_AT_DATA_Q0_spd_MASK) >> OHCI1394_AT_DATA_Q0_spd_SHIFT; 193 + } 194 + 195 + static inline void ohci1394_at_data_set_speed(__le32 *data, unsigned int scode) 196 + { 197 + data[0] &= cpu_to_le32(~OHCI1394_AT_DATA_Q0_spd_MASK); 198 + data[0] |= cpu_to_le32((scode << OHCI1394_AT_DATA_Q0_spd_SHIFT) & OHCI1394_AT_DATA_Q0_spd_MASK); 199 + } 200 + 201 + static inline unsigned int ohci1394_at_data_get_tlabel(const __le32 *data) 202 + { 203 + return (le32_to_cpu(data[0]) & OHCI1394_AT_DATA_Q0_tLabel_MASK) >> OHCI1394_AT_DATA_Q0_tLabel_SHIFT; 204 + } 205 + 206 + static inline void ohci1394_at_data_set_tlabel(__le32 *data, unsigned int tlabel) 207 + { 208 + data[0] &= cpu_to_le32(~OHCI1394_AT_DATA_Q0_tLabel_MASK); 209 + data[0] |= cpu_to_le32((tlabel << OHCI1394_AT_DATA_Q0_tLabel_SHIFT) & OHCI1394_AT_DATA_Q0_tLabel_MASK); 210 + } 211 + 212 + static inline unsigned int ohci1394_at_data_get_retry(const __le32 *data) 213 + { 214 + return (le32_to_cpu(data[0]) & OHCI1394_AT_DATA_Q0_rt_MASK) >> OHCI1394_AT_DATA_Q0_rt_SHIFT; 215 + } 216 + 217 + static inline void ohci1394_at_data_set_retry(__le32 *data, unsigned int retry) 218 + { 219 + data[0] &= cpu_to_le32(~OHCI1394_AT_DATA_Q0_rt_MASK); 220 + data[0] |= cpu_to_le32((retry << OHCI1394_AT_DATA_Q0_rt_SHIFT) & OHCI1394_AT_DATA_Q0_rt_MASK); 221 + } 222 + 223 + static inline unsigned int ohci1394_at_data_get_tcode(const __le32 *data) 224 + { 225 + return (le32_to_cpu(data[0]) & OHCI1394_AT_DATA_Q0_tCode_MASK) >> OHCI1394_AT_DATA_Q0_tCode_SHIFT; 226 + } 227 + 228 + static inline void ohci1394_at_data_set_tcode(__le32 *data, unsigned int tcode) 229 + { 230 + data[0] &= cpu_to_le32(~OHCI1394_AT_DATA_Q0_tCode_MASK); 231 + data[0] |= cpu_to_le32((tcode << OHCI1394_AT_DATA_Q0_tCode_SHIFT) & OHCI1394_AT_DATA_Q0_tCode_MASK); 232 + } 233 + 234 + static inline unsigned int ohci1394_at_data_get_destination_id(const __le32 *data) 235 + { 236 + return (le32_to_cpu(data[1]) & OHCI1394_AT_DATA_Q1_destinationId_MASK) >> OHCI1394_AT_DATA_Q1_destinationId_SHIFT; 237 + } 238 + 239 + static inline void ohci1394_at_data_set_destination_id(__le32 *data, unsigned int destination_id) 240 + { 241 + data[1] &= cpu_to_le32(~OHCI1394_AT_DATA_Q1_destinationId_MASK); 242 + data[1] |= cpu_to_le32((destination_id << OHCI1394_AT_DATA_Q1_destinationId_SHIFT) & OHCI1394_AT_DATA_Q1_destinationId_MASK); 243 + } 244 + 245 + static inline u64 ohci1394_at_data_get_destination_offset(const __le32 *data) 246 + { 247 + u64 hi = (u64)((le32_to_cpu(data[1]) & OHCI1394_AT_DATA_Q1_destinationOffsetHigh_MASK) >> OHCI1394_AT_DATA_Q1_destinationOffsetHigh_SHIFT); 248 + u64 lo = (u64)le32_to_cpu(data[2]); 249 + return (hi << 32) | lo; 250 + } 251 + 252 + static inline void ohci1394_at_data_set_destination_offset(__le32 *data, u64 offset) 253 + { 254 + u32 hi = (u32)(offset >> 32); 255 + u32 lo = (u32)(offset & 0x00000000ffffffff); 256 + data[1] &= cpu_to_le32(~OHCI1394_AT_DATA_Q1_destinationOffsetHigh_MASK); 257 + data[1] |= cpu_to_le32((hi << OHCI1394_AT_DATA_Q1_destinationOffsetHigh_SHIFT) & OHCI1394_AT_DATA_Q1_destinationOffsetHigh_MASK); 258 + data[2] = cpu_to_le32(lo); 259 + } 260 + 261 + static inline unsigned int ohci1394_at_data_get_rcode(const __le32 *data) 262 + { 263 + return (le32_to_cpu(data[1]) & OHCI1394_AT_DATA_Q1_rCode_MASK) >> OHCI1394_AT_DATA_Q1_rCode_SHIFT; 264 + } 265 + 266 + static inline void ohci1394_at_data_set_rcode(__le32 *data, unsigned int rcode) 267 + { 268 + data[1] &= cpu_to_le32(~OHCI1394_AT_DATA_Q1_rCode_MASK); 269 + data[1] |= cpu_to_le32((rcode << OHCI1394_AT_DATA_Q1_rCode_SHIFT) & OHCI1394_AT_DATA_Q1_rCode_MASK); 270 + } 271 + 157 272 // Self-ID DMA. 158 273 159 274 #define OHCI1394_SelfIDCount_selfIDError_MASK 0x80000000