Skip to content

Commit f9a2283

Browse files
committed
firewire: ohci: use helper inline functions to serialize/deserialize self ID packet
This commit replaces the existing implementation with the helper functions for self ID packet. Link: https://lore.kernel.org/r/20240605235155.116468-10-o-takashi@sakamocchi.jp Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
1 parent 8f03514 commit f9a2283

1 file changed

Lines changed: 45 additions & 24 deletions

File tree

drivers/firewire/ohci.c

Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ static void log_selfids(struct fw_ohci *ohci, int generation, int self_id_count)
477477
ohci_notice(ohci,
478478
"selfID 0: %08x, phy %d [%c%c%c] %s gc=%d %s %s%s%s\n",
479479
*s,
480-
*s >> 24 & 63,
480+
phy_packet_self_id_get_phy_id(*s),
481481
port[self_id_sequence_get_port_status(s, quadlet_count, 0)],
482482
port[self_id_sequence_get_port_status(s, quadlet_count, 1)],
483483
port[self_id_sequence_get_port_status(s, quadlet_count, 2)],
@@ -490,7 +490,7 @@ static void log_selfids(struct fw_ohci *ohci, int generation, int self_id_count)
490490
ohci_notice(ohci,
491491
"selfID n: %08x, phy %d [%c%c%c%c%c%c%c%c]\n",
492492
s[i],
493-
s[i] >> 24 & 63,
493+
phy_packet_self_id_get_phy_id(s[i]),
494494
port[self_id_sequence_get_port_status(s, quadlet_count, port_index)],
495495
port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 1)],
496496
port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 2)],
@@ -1846,7 +1846,8 @@ static u32 update_bus_time(struct fw_ohci *ohci)
18461846
return ohci->bus_time | cycle_time_seconds;
18471847
}
18481848

1849-
static int get_status_for_port(struct fw_ohci *ohci, int port_index)
1849+
static int get_status_for_port(struct fw_ohci *ohci, int port_index,
1850+
enum phy_packet_self_id_port_status *status)
18501851
{
18511852
int reg;
18521853

@@ -1860,33 +1861,44 @@ static int get_status_for_port(struct fw_ohci *ohci, int port_index)
18601861

18611862
switch (reg & 0x0f) {
18621863
case 0x06:
1863-
return 2; /* is child node (connected to parent node) */
1864+
// is child node (connected to parent node)
1865+
*status = PHY_PACKET_SELF_ID_PORT_STATUS_PARENT;
1866+
break;
18641867
case 0x0e:
1865-
return 3; /* is parent node (connected to child node) */
1868+
// is parent node (connected to child node)
1869+
*status = PHY_PACKET_SELF_ID_PORT_STATUS_CHILD;
1870+
break;
1871+
default:
1872+
// not connected
1873+
*status = PHY_PACKET_SELF_ID_PORT_STATUS_NCONN;
1874+
break;
18661875
}
1867-
return 1; /* not connected */
1876+
1877+
return 0;
18681878
}
18691879

18701880
static int get_self_id_pos(struct fw_ohci *ohci, u32 self_id,
18711881
int self_id_count)
18721882
{
1883+
unsigned int left_phy_id = phy_packet_self_id_get_phy_id(self_id);
18731884
int i;
1874-
u32 entry;
18751885

18761886
for (i = 0; i < self_id_count; i++) {
1877-
entry = ohci->self_id_buffer[i];
1878-
if ((self_id & 0xff000000) == (entry & 0xff000000))
1887+
u32 entry = ohci->self_id_buffer[i];
1888+
unsigned int right_phy_id = phy_packet_self_id_get_phy_id(entry);
1889+
1890+
if (left_phy_id == right_phy_id)
18791891
return -1;
1880-
if ((self_id & 0xff000000) < (entry & 0xff000000))
1892+
if (left_phy_id < right_phy_id)
18811893
return i;
18821894
}
18831895
return i;
18841896
}
18851897

1886-
static int initiated_reset(struct fw_ohci *ohci)
1898+
static bool initiated_reset(struct fw_ohci *ohci)
18871899
{
18881900
int reg;
1889-
int ret = 0;
1901+
int ret = false;
18901902

18911903
mutex_lock(&ohci->phy_reg_mutex);
18921904
reg = write_phy_reg(ohci, 7, 0xe0); /* Select page 7 */
@@ -1899,7 +1911,7 @@ static int initiated_reset(struct fw_ohci *ohci)
18991911
if (reg >= 0) {
19001912
if ((reg & 0x08) == 0x08) {
19011913
/* bit 3 indicates "initiated reset" */
1902-
ret = 0x2;
1914+
ret = true;
19031915
}
19041916
}
19051917
}
@@ -1915,36 +1927,45 @@ static int initiated_reset(struct fw_ohci *ohci)
19151927
*/
19161928
static int find_and_insert_self_id(struct fw_ohci *ohci, int self_id_count)
19171929
{
1918-
int reg, i, pos, status;
1919-
/* link active 1, speed 3, bridge 0, contender 1, more packets 0 */
1920-
u32 self_id = 0x8040c800;
1930+
int reg, i, pos;
1931+
u32 self_id = 0;
1932+
1933+
// link active 1, speed 3, bridge 0, contender 1, more packets 0.
1934+
phy_packet_set_packet_identifier(&self_id, PHY_PACKET_PACKET_IDENTIFIER_SELF_ID);
1935+
phy_packet_self_id_zero_set_link_active(&self_id, true);
1936+
phy_packet_self_id_zero_set_scode(&self_id, SCODE_800);
1937+
phy_packet_self_id_zero_set_contender(&self_id, true);
19211938

19221939
reg = reg_read(ohci, OHCI1394_NodeID);
19231940
if (!(reg & OHCI1394_NodeID_idValid)) {
19241941
ohci_notice(ohci,
19251942
"node ID not valid, new bus reset in progress\n");
19261943
return -EBUSY;
19271944
}
1928-
self_id |= ((reg & 0x3f) << 24); /* phy ID */
1945+
phy_packet_self_id_set_phy_id(&self_id, reg & 0x3f);
19291946

19301947
reg = ohci_read_phy_reg(&ohci->card, 4);
19311948
if (reg < 0)
19321949
return reg;
1933-
self_id |= ((reg & 0x07) << 8); /* power class */
1950+
phy_packet_self_id_zero_set_power_class(&self_id, reg & 0x07);
19341951

19351952
reg = ohci_read_phy_reg(&ohci->card, 1);
19361953
if (reg < 0)
19371954
return reg;
1938-
self_id |= ((reg & 0x3f) << 16); /* gap count */
1955+
phy_packet_self_id_zero_set_gap_count(&self_id, reg & 0x3f);
19391956

19401957
for (i = 0; i < 3; i++) {
1941-
status = get_status_for_port(ohci, i);
1942-
if (status < 0)
1943-
return status;
1944-
self_id |= ((status & 0x3) << (6 - (i * 2)));
1958+
enum phy_packet_self_id_port_status status;
1959+
int err;
1960+
1961+
err = get_status_for_port(ohci, i, &status);
1962+
if (err < 0)
1963+
return err;
1964+
1965+
self_id_sequence_set_port_status(&self_id, 1, i, status);
19451966
}
19461967

1947-
self_id |= initiated_reset(ohci);
1968+
phy_packet_self_id_zero_set_initiated_reset(&self_id, initiated_reset(ohci));
19481969

19491970
pos = get_self_id_pos(ohci, self_id, self_id_count);
19501971
if (pos >= 0) {

0 commit comments

Comments
 (0)