Skip to content

Commit a16931a

Browse files
committed
firewire: ohci: use helper functions for self ID sequence
This commit replaces the existing implementation with the helper functions for self ID sequence. Link: https://lore.kernel.org/r/20240605235155.116468-7-o-takashi@sakamocchi.jp Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
1 parent 24b7f8e commit a16931a

1 file changed

Lines changed: 49 additions & 28 deletions

File tree

drivers/firewire/ohci.c

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "core.h"
4242
#include "ohci.h"
4343
#include "packet-header-definitions.h"
44+
#include "phy-packet-definitions.h"
4445

4546
#define ohci_info(ohci, f, args...) dev_info(ohci->card.device, f, ##args)
4647
#define ohci_notice(ohci, f, args...) dev_notice(ohci->card.device, f, ##args)
@@ -437,11 +438,6 @@ static void log_irqs(struct fw_ohci *ohci, u32 evt)
437438
? " ?" : "");
438439
}
439440

440-
static unsigned int _p(u32 *s, int shift)
441-
{
442-
return *s >> shift & 3;
443-
}
444-
445441
static void log_selfids(struct fw_ohci *ohci, int generation, int self_id_count)
446442
{
447443
static const char *const speed[] = {
@@ -451,38 +447,63 @@ static void log_selfids(struct fw_ohci *ohci, int generation, int self_id_count)
451447
[0] = "+0W", [1] = "+15W", [2] = "+30W", [3] = "+45W",
452448
[4] = "-3W", [5] = " ?W", [6] = "-3..-6W", [7] = "-3..-10W",
453449
};
454-
static const char port[] = { '.', '-', 'p', 'c', };
455-
u32 *s;
450+
static const char port[] = {
451+
[PHY_PACKET_SELF_ID_PORT_STATUS_NONE] = '.',
452+
[PHY_PACKET_SELF_ID_PORT_STATUS_NCONN] = '-',
453+
[PHY_PACKET_SELF_ID_PORT_STATUS_PARENT] = 'p',
454+
[PHY_PACKET_SELF_ID_PORT_STATUS_CHILD] = 'c',
455+
};
456+
struct self_id_sequence_enumerator enumerator = {
457+
.cursor = ohci->self_id_buffer,
458+
.quadlet_count = self_id_count,
459+
};
456460

457461
if (likely(!(param_debug & OHCI_PARAM_DEBUG_SELFIDS)))
458462
return;
459463

460464
ohci_notice(ohci, "%d selfIDs, generation %d, local node ID %04x\n",
461465
self_id_count, generation, ohci->node_id);
462466

463-
for (s = ohci->self_id_buffer; self_id_count--; ++s)
464-
if ((*s & 1 << 23) == 0)
465-
ohci_notice(ohci,
466-
"selfID 0: %08x, phy %d [%c%c%c] %s gc=%d %s %s%s%s\n",
467-
*s, *s >> 24 & 63,
468-
port[_p(s, 6)],
469-
port[_p(s, 4)],
470-
port[_p(s, 2)],
471-
speed[*s >> 14 & 3], *s >> 16 & 63,
472-
power[*s >> 8 & 7], *s >> 22 & 1 ? "L" : "",
473-
*s >> 11 & 1 ? "c" : "", *s & 2 ? "i" : "");
474-
else
467+
while (enumerator.quadlet_count > 0) {
468+
unsigned int quadlet_count;
469+
unsigned int port_index;
470+
const u32 *s;
471+
int i;
472+
473+
s = self_id_sequence_enumerator_next(&enumerator, &quadlet_count);
474+
if (IS_ERR(s))
475+
break;
476+
477+
ohci_notice(ohci,
478+
"selfID 0: %08x, phy %d [%c%c%c] %s gc=%d %s %s%s%s\n",
479+
*s,
480+
*s >> 24 & 63,
481+
port[self_id_sequence_get_port_status(s, quadlet_count, 0)],
482+
port[self_id_sequence_get_port_status(s, quadlet_count, 1)],
483+
port[self_id_sequence_get_port_status(s, quadlet_count, 2)],
484+
speed[*s >> 14 & 3], *s >> 16 & 63,
485+
power[*s >> 8 & 7], *s >> 22 & 1 ? "L" : "",
486+
*s >> 11 & 1 ? "c" : "", *s & 2 ? "i" : "");
487+
488+
port_index = 3;
489+
for (i = 1; i < quadlet_count; ++i) {
475490
ohci_notice(ohci,
476491
"selfID n: %08x, phy %d [%c%c%c%c%c%c%c%c]\n",
477-
*s, *s >> 24 & 63,
478-
port[_p(s, 16)],
479-
port[_p(s, 14)],
480-
port[_p(s, 12)],
481-
port[_p(s, 10)],
482-
port[_p(s, 8)],
483-
port[_p(s, 6)],
484-
port[_p(s, 4)],
485-
port[_p(s, 2)]);
492+
s[i],
493+
s[i] >> 24 & 63,
494+
port[self_id_sequence_get_port_status(s, quadlet_count, port_index)],
495+
port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 1)],
496+
port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 2)],
497+
port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 3)],
498+
port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 4)],
499+
port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 5)],
500+
port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 6)],
501+
port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 7)]
502+
);
503+
504+
port_index += 8;
505+
}
506+
}
486507
}
487508

488509
static const char *evts[] = {

0 commit comments

Comments
 (0)