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

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>

+45 -24
+45 -24
drivers/firewire/ohci.c
··· 477 477 ohci_notice(ohci, 478 478 "selfID 0: %08x, phy %d [%c%c%c] %s gc=%d %s %s%s%s\n", 479 479 *s, 480 - *s >> 24 & 63, 480 + phy_packet_self_id_get_phy_id(*s), 481 481 port[self_id_sequence_get_port_status(s, quadlet_count, 0)], 482 482 port[self_id_sequence_get_port_status(s, quadlet_count, 1)], 483 483 port[self_id_sequence_get_port_status(s, quadlet_count, 2)], ··· 490 490 ohci_notice(ohci, 491 491 "selfID n: %08x, phy %d [%c%c%c%c%c%c%c%c]\n", 492 492 s[i], 493 - s[i] >> 24 & 63, 493 + phy_packet_self_id_get_phy_id(s[i]), 494 494 port[self_id_sequence_get_port_status(s, quadlet_count, port_index)], 495 495 port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 1)], 496 496 port[self_id_sequence_get_port_status(s, quadlet_count, port_index + 2)], ··· 1846 1846 return ohci->bus_time | cycle_time_seconds; 1847 1847 } 1848 1848 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) 1850 1851 { 1851 1852 int reg; 1852 1853 ··· 1861 1860 1862 1861 switch (reg & 0x0f) { 1863 1862 case 0x06: 1864 - return 2; /* is child node (connected to parent node) */ 1863 + // is child node (connected to parent node) 1864 + *status = PHY_PACKET_SELF_ID_PORT_STATUS_PARENT; 1865 + break; 1865 1866 case 0x0e: 1866 - return 3; /* is parent node (connected to child node) */ 1867 + // is parent node (connected to child node) 1868 + *status = PHY_PACKET_SELF_ID_PORT_STATUS_CHILD; 1869 + break; 1870 + default: 1871 + // not connected 1872 + *status = PHY_PACKET_SELF_ID_PORT_STATUS_NCONN; 1873 + break; 1867 1874 } 1868 - return 1; /* not connected */ 1875 + 1876 + return 0; 1869 1877 } 1870 1878 1871 1879 static int get_self_id_pos(struct fw_ohci *ohci, u32 self_id, 1872 1880 int self_id_count) 1873 1881 { 1882 + unsigned int left_phy_id = phy_packet_self_id_get_phy_id(self_id); 1874 1883 int i; 1875 - u32 entry; 1876 1884 1877 1885 for (i = 0; i < self_id_count; i++) { 1878 - entry = ohci->self_id_buffer[i]; 1879 - if ((self_id & 0xff000000) == (entry & 0xff000000)) 1886 + u32 entry = ohci->self_id_buffer[i]; 1887 + unsigned int right_phy_id = phy_packet_self_id_get_phy_id(entry); 1888 + 1889 + if (left_phy_id == right_phy_id) 1880 1890 return -1; 1881 - if ((self_id & 0xff000000) < (entry & 0xff000000)) 1891 + if (left_phy_id < right_phy_id) 1882 1892 return i; 1883 1893 } 1884 1894 return i; 1885 1895 } 1886 1896 1887 - static int initiated_reset(struct fw_ohci *ohci) 1897 + static bool initiated_reset(struct fw_ohci *ohci) 1888 1898 { 1889 1899 int reg; 1890 - int ret = 0; 1900 + int ret = false; 1891 1901 1892 1902 mutex_lock(&ohci->phy_reg_mutex); 1893 1903 reg = write_phy_reg(ohci, 7, 0xe0); /* Select page 7 */ ··· 1911 1899 if (reg >= 0) { 1912 1900 if ((reg & 0x08) == 0x08) { 1913 1901 /* bit 3 indicates "initiated reset" */ 1914 - ret = 0x2; 1902 + ret = true; 1915 1903 } 1916 1904 } 1917 1905 } ··· 1927 1915 */ 1928 1916 static int find_and_insert_self_id(struct fw_ohci *ohci, int self_id_count) 1929 1917 { 1930 - int reg, i, pos, status; 1931 - /* link active 1, speed 3, bridge 0, contender 1, more packets 0 */ 1932 - u32 self_id = 0x8040c800; 1918 + int reg, i, pos; 1919 + u32 self_id = 0; 1920 + 1921 + // link active 1, speed 3, bridge 0, contender 1, more packets 0. 1922 + phy_packet_set_packet_identifier(&self_id, PHY_PACKET_PACKET_IDENTIFIER_SELF_ID); 1923 + phy_packet_self_id_zero_set_link_active(&self_id, true); 1924 + phy_packet_self_id_zero_set_scode(&self_id, SCODE_800); 1925 + phy_packet_self_id_zero_set_contender(&self_id, true); 1933 1926 1934 1927 reg = reg_read(ohci, OHCI1394_NodeID); 1935 1928 if (!(reg & OHCI1394_NodeID_idValid)) { ··· 1942 1925 "node ID not valid, new bus reset in progress\n"); 1943 1926 return -EBUSY; 1944 1927 } 1945 - self_id |= ((reg & 0x3f) << 24); /* phy ID */ 1928 + phy_packet_self_id_set_phy_id(&self_id, reg & 0x3f); 1946 1929 1947 1930 reg = ohci_read_phy_reg(&ohci->card, 4); 1948 1931 if (reg < 0) 1949 1932 return reg; 1950 - self_id |= ((reg & 0x07) << 8); /* power class */ 1933 + phy_packet_self_id_zero_set_power_class(&self_id, reg & 0x07); 1951 1934 1952 1935 reg = ohci_read_phy_reg(&ohci->card, 1); 1953 1936 if (reg < 0) 1954 1937 return reg; 1955 - self_id |= ((reg & 0x3f) << 16); /* gap count */ 1938 + phy_packet_self_id_zero_set_gap_count(&self_id, reg & 0x3f); 1956 1939 1957 1940 for (i = 0; i < 3; i++) { 1958 - status = get_status_for_port(ohci, i); 1959 - if (status < 0) 1960 - return status; 1961 - self_id |= ((status & 0x3) << (6 - (i * 2))); 1941 + enum phy_packet_self_id_port_status status; 1942 + int err; 1943 + 1944 + err = get_status_for_port(ohci, i, &status); 1945 + if (err < 0) 1946 + return err; 1947 + 1948 + self_id_sequence_set_port_status(&self_id, 1, i, status); 1962 1949 } 1963 1950 1964 - self_id |= initiated_reset(ohci); 1951 + phy_packet_self_id_zero_set_initiated_reset(&self_id, initiated_reset(ohci)); 1965 1952 1966 1953 pos = get_self_id_pos(ohci, self_id, self_id_count); 1967 1954 if (pos >= 0) {