Skip to content

Commit c538b06

Browse files
committed
firewire: ohci: use static function to handle endian issue on PowerPC platform
It is preferable to use static function instead of functional macro in some points. It checks type of argument, but would be optimized to embedded code instead of function calls. This commit obsoletes the functional macro with the static function. Additionally this commit refactors quirk detection to ease the later work. Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Takashi Sakamoto <[email protected]>
1 parent f26a38e commit c538b06

File tree

1 file changed

+27
-12
lines changed

1 file changed

+27
-12
lines changed

drivers/firewire/ohci.c

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -875,10 +875,25 @@ static void ar_sync_buffers_for_cpu(struct ar_context *ctx,
875875
}
876876

877877
#if defined(CONFIG_PPC_PMAC) && defined(CONFIG_PPC32)
878-
#define cond_le32_to_cpu(v) \
879-
(ohci->quirks & QUIRK_BE_HEADERS ? be32_to_cpu(v) : le32_to_cpu(v))
878+
static u32 cond_le32_to_cpu(__le32 value, bool has_be_header_quirk)
879+
{
880+
return has_be_header_quirk ? be32_to_cpu(value) : le32_to_cpu(value);
881+
}
882+
883+
static bool has_be_header_quirk(const struct fw_ohci *ohci)
884+
{
885+
return !!(ohci->quirks & QUIRK_BE_HEADERS);
886+
}
880887
#else
881-
#define cond_le32_to_cpu(v) le32_to_cpu(v)
888+
static u32 cond_le32_to_cpu(__le32 value, bool has_be_header_quirk __maybe_unused)
889+
{
890+
return le32_to_cpu(value);
891+
}
892+
893+
static bool has_be_header_quirk(const struct fw_ohci *ohci)
894+
{
895+
return false;
896+
}
882897
#endif
883898

884899
static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer)
@@ -888,9 +903,9 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer)
888903
u32 status, length, tcode;
889904
int evt;
890905

891-
p.header[0] = cond_le32_to_cpu(buffer[0]);
892-
p.header[1] = cond_le32_to_cpu(buffer[1]);
893-
p.header[2] = cond_le32_to_cpu(buffer[2]);
906+
p.header[0] = cond_le32_to_cpu(buffer[0], has_be_header_quirk(ohci));
907+
p.header[1] = cond_le32_to_cpu(buffer[1], has_be_header_quirk(ohci));
908+
p.header[2] = cond_le32_to_cpu(buffer[2], has_be_header_quirk(ohci));
894909

895910
tcode = async_header_get_tcode(p.header);
896911
switch (tcode) {
@@ -902,7 +917,7 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer)
902917
break;
903918

904919
case TCODE_READ_BLOCK_REQUEST :
905-
p.header[3] = cond_le32_to_cpu(buffer[3]);
920+
p.header[3] = cond_le32_to_cpu(buffer[3], has_be_header_quirk(ohci));
906921
p.header_length = 16;
907922
p.payload_length = 0;
908923
break;
@@ -911,7 +926,7 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer)
911926
case TCODE_READ_BLOCK_RESPONSE:
912927
case TCODE_LOCK_REQUEST:
913928
case TCODE_LOCK_RESPONSE:
914-
p.header[3] = cond_le32_to_cpu(buffer[3]);
929+
p.header[3] = cond_le32_to_cpu(buffer[3], has_be_header_quirk(ohci));
915930
p.header_length = 16;
916931
p.payload_length = async_header_get_data_length(p.header);
917932
if (p.payload_length > MAX_ASYNC_PAYLOAD) {
@@ -936,7 +951,7 @@ static __le32 *handle_ar_packet(struct ar_context *ctx, __le32 *buffer)
936951

937952
/* FIXME: What to do about evt_* errors? */
938953
length = (p.header_length + p.payload_length + 3) / 4;
939-
status = cond_le32_to_cpu(buffer[length]);
954+
status = cond_le32_to_cpu(buffer[length], has_be_header_quirk(ohci));
940955
evt = (status >> 16) & 0x1f;
941956

942957
p.ack = evt - 16;
@@ -2030,12 +2045,12 @@ static void bus_reset_work(struct work_struct *work)
20302045
return;
20312046
}
20322047

2033-
generation = (cond_le32_to_cpu(ohci->self_id[0]) >> 16) & 0xff;
2048+
generation = (cond_le32_to_cpu(ohci->self_id[0], has_be_header_quirk(ohci)) >> 16) & 0xff;
20342049
rmb();
20352050

20362051
for (i = 1, j = 0; j < self_id_count; i += 2, j++) {
2037-
u32 id = cond_le32_to_cpu(ohci->self_id[i]);
2038-
u32 id2 = cond_le32_to_cpu(ohci->self_id[i + 1]);
2052+
u32 id = cond_le32_to_cpu(ohci->self_id[i], has_be_header_quirk(ohci));
2053+
u32 id2 = cond_le32_to_cpu(ohci->self_id[i + 1], has_be_header_quirk(ohci));
20392054

20402055
if (id != ~id2) {
20412056
/*

0 commit comments

Comments
 (0)