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

Merge branch 'net-renesas-cleanup-usage-of-gptp-flags'

Niklas Söderlund says:

====================
net: renesas: Cleanup usage of gPTP flags

This series aim is to prepare for future work that will enable the use
of gPTP on R-Car RAVB on Gen4. Currently RAVB have a dedicated gPTP
implementation supported on Gen2 and Gen3 (ravb_ptp.c). For Gen4 a new
implementation that is already upstream (rcar_gen4_ptp.c) and used by
other Gen4 devices such as RTSN and RSWITCH is needed.

Unfortunately the design of the Gen2/Gen3 RAVB driver where driver
specific flags to control gPTP behavior have been mimicked in RTSN and
RSWITCH. This was OK as there was no overlap between the two gPTP
implementations. Now that RAVB needs to be able to use both having to
translate between driver specific flags and common net code flags
becomes even more cumbersome as there are two sets of driver specific
flags to pick from.

This series cleans this up for all Renesas drivers using gPTP by
removing all driver specific flags and using the common flags directly.
This simplifies drivers while at the same time prepare RAVB to be
extended with Gen4 support.

Patch 1/7 is a drive by patch where RSWITCH specific define was added in
the wrong header. Patch 2/7 removes a short-cut used in RTSN and RSWITCH
that prevents extending Gen4 support to RAVB without fuss. While patch
3/7 to 7/7 rework the Renesas drivers to use the common flags instead of
driver specific ones.

There is no intentional behavior change and only a small rework in logic
in the RAVB driver. Looking at patch 3/7, 4/7 and 7/7 one can clearly
see how the code have been copied from RAVB to the later implementations
in RTSN and RSWITCH.
====================

Link: https://patch.msgid.link/20251104222420.882731-1-niklas.soderlund+renesas@ragnatech.se
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+64 -123
+2 -12
drivers/net/ethernet/renesas/ravb.h
··· 35 35 /* Driver's parameters */ 36 36 #define RAVB_ALIGN 128 37 37 38 - /* Hardware time stamp */ 39 - #define RAVB_TXTSTAMP_VALID 0x00000001 /* TX timestamp valid */ 40 - #define RAVB_TXTSTAMP_ENABLED 0x00000010 /* Enable TX timestamping */ 41 - 42 - #define RAVB_RXTSTAMP_VALID 0x00000001 /* RX timestamp valid */ 43 - #define RAVB_RXTSTAMP_TYPE 0x00000006 /* RX type mask */ 44 - #define RAVB_RXTSTAMP_TYPE_V2_L2_EVENT 0x00000002 45 - #define RAVB_RXTSTAMP_TYPE_ALL 0x00000006 46 - #define RAVB_RXTSTAMP_ENABLED 0x00000010 /* Enable RX timestamping */ 47 - 48 38 enum ravb_reg { 49 39 /* AVB-DMAC registers */ 50 40 CCC = 0x0000, ··· 1104 1114 u32 rx_over_errors; 1105 1115 u32 rx_fifo_errors; 1106 1116 struct net_device_stats stats[NUM_RX_QUEUE]; 1107 - u32 tstamp_tx_ctrl; 1108 - u32 tstamp_rx_ctrl; 1117 + enum hwtstamp_tx_types tstamp_tx_ctrl; 1118 + enum hwtstamp_rx_filters tstamp_rx_ctrl; 1109 1119 struct list_head ts_skb_list; 1110 1120 u32 ts_skb_tag; 1111 1121 struct ravb_ptp ptp;
+32 -35
drivers/net/ethernet/renesas/ravb_main.c
··· 946 946 return rx_packets; 947 947 } 948 948 949 + static void ravb_rx_rcar_hwstamp(struct ravb_private *priv, int q, 950 + struct ravb_ex_rx_desc *desc, 951 + struct sk_buff *skb) 952 + { 953 + struct skb_shared_hwtstamps *shhwtstamps; 954 + struct timespec64 ts; 955 + bool get_ts; 956 + 957 + if (q == RAVB_NC) 958 + get_ts = priv->tstamp_rx_ctrl == HWTSTAMP_FILTER_PTP_V2_L2_EVENT; 959 + else 960 + get_ts = priv->tstamp_rx_ctrl != HWTSTAMP_FILTER_PTP_V2_L2_EVENT; 961 + 962 + if (!get_ts) 963 + return; 964 + 965 + shhwtstamps = skb_hwtstamps(skb); 966 + memset(shhwtstamps, 0, sizeof(*shhwtstamps)); 967 + ts.tv_sec = ((u64)le16_to_cpu(desc->ts_sh) << 32) 968 + | le32_to_cpu(desc->ts_sl); 969 + ts.tv_nsec = le32_to_cpu(desc->ts_n); 970 + shhwtstamps->hwtstamp = timespec64_to_ktime(ts); 971 + } 972 + 949 973 /* Packet receive function for Ethernet AVB */ 950 974 static int ravb_rx_rcar(struct net_device *ndev, int budget, int q) 951 975 { ··· 979 955 struct ravb_ex_rx_desc *desc; 980 956 unsigned int limit, i; 981 957 struct sk_buff *skb; 982 - struct timespec64 ts; 983 958 int rx_packets = 0; 984 959 u8 desc_status; 985 960 u16 pkt_len; ··· 1015 992 if (desc_status & MSC_CEEF) 1016 993 stats->rx_missed_errors++; 1017 994 } else { 1018 - u32 get_ts = priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE; 1019 995 struct ravb_rx_buffer *rx_buff; 1020 996 void *rx_addr; 1021 997 ··· 1032 1010 break; 1033 1011 } 1034 1012 skb_mark_for_recycle(skb); 1035 - get_ts &= (q == RAVB_NC) ? 1036 - RAVB_RXTSTAMP_TYPE_V2_L2_EVENT : 1037 - ~RAVB_RXTSTAMP_TYPE_V2_L2_EVENT; 1038 - if (get_ts) { 1039 - struct skb_shared_hwtstamps *shhwtstamps; 1040 1013 1041 - shhwtstamps = skb_hwtstamps(skb); 1042 - memset(shhwtstamps, 0, sizeof(*shhwtstamps)); 1043 - ts.tv_sec = ((u64) le16_to_cpu(desc->ts_sh) << 1044 - 32) | le32_to_cpu(desc->ts_sl); 1045 - ts.tv_nsec = le32_to_cpu(desc->ts_n); 1046 - shhwtstamps->hwtstamp = timespec64_to_ktime(ts); 1047 - } 1014 + ravb_rx_rcar_hwstamp(priv, q, desc, skb); 1048 1015 1049 1016 skb_put(skb, pkt_len); 1050 1017 skb->protocol = eth_type_trans(skb, ndev); ··· 2425 2414 struct ravb_private *priv = netdev_priv(ndev); 2426 2415 2427 2416 config->flags = 0; 2428 - config->tx_type = priv->tstamp_tx_ctrl ? HWTSTAMP_TX_ON : 2429 - HWTSTAMP_TX_OFF; 2430 - switch (priv->tstamp_rx_ctrl & RAVB_RXTSTAMP_TYPE) { 2431 - case RAVB_RXTSTAMP_TYPE_V2_L2_EVENT: 2432 - config->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; 2433 - break; 2434 - case RAVB_RXTSTAMP_TYPE_ALL: 2435 - config->rx_filter = HWTSTAMP_FILTER_ALL; 2436 - break; 2437 - default: 2438 - config->rx_filter = HWTSTAMP_FILTER_NONE; 2439 - } 2417 + config->tx_type = priv->tstamp_tx_ctrl; 2418 + config->rx_filter = priv->tstamp_rx_ctrl; 2440 2419 2441 2420 return 0; 2442 2421 } ··· 2437 2436 struct netlink_ext_ack *extack) 2438 2437 { 2439 2438 struct ravb_private *priv = netdev_priv(ndev); 2440 - u32 tstamp_rx_ctrl = RAVB_RXTSTAMP_ENABLED; 2441 - u32 tstamp_tx_ctrl; 2439 + enum hwtstamp_rx_filters tstamp_rx_ctrl; 2440 + enum hwtstamp_tx_types tstamp_tx_ctrl; 2442 2441 2443 2442 switch (config->tx_type) { 2444 2443 case HWTSTAMP_TX_OFF: 2445 - tstamp_tx_ctrl = 0; 2446 - break; 2447 2444 case HWTSTAMP_TX_ON: 2448 - tstamp_tx_ctrl = RAVB_TXTSTAMP_ENABLED; 2445 + tstamp_tx_ctrl = config->tx_type; 2449 2446 break; 2450 2447 default: 2451 2448 return -ERANGE; ··· 2451 2452 2452 2453 switch (config->rx_filter) { 2453 2454 case HWTSTAMP_FILTER_NONE: 2454 - tstamp_rx_ctrl = 0; 2455 - break; 2456 2455 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: 2457 - tstamp_rx_ctrl |= RAVB_RXTSTAMP_TYPE_V2_L2_EVENT; 2456 + tstamp_rx_ctrl = config->rx_filter; 2458 2457 break; 2459 2458 default: 2460 2459 config->rx_filter = HWTSTAMP_FILTER_ALL; 2461 - tstamp_rx_ctrl |= RAVB_RXTSTAMP_TYPE_ALL; 2460 + tstamp_rx_ctrl = HWTSTAMP_FILTER_ALL; 2462 2461 } 2463 2462 2464 2463 priv->tstamp_tx_ctrl = tstamp_tx_ctrl;
-13
drivers/net/ethernet/renesas/rcar_gen4_ptp.h
··· 9 9 10 10 #include <linux/ptp_clock_kernel.h> 11 11 12 - #define RCAR_GEN4_GPTP_OFFSET_S4 0x00018000 13 - 14 - /* driver's definitions */ 15 - #define RCAR_GEN4_RXTSTAMP_ENABLED BIT(0) 16 - #define RCAR_GEN4_RXTSTAMP_TYPE_V2_L2_EVENT BIT(1) 17 - #define RCAR_GEN4_RXTSTAMP_TYPE_ALL (RCAR_GEN4_RXTSTAMP_TYPE_V2_L2_EVENT | BIT(2)) 18 - #define RCAR_GEN4_RXTSTAMP_TYPE RCAR_GEN4_RXTSTAMP_TYPE_ALL 19 - 20 - #define RCAR_GEN4_TXTSTAMP_ENABLED BIT(0) 21 - 22 - 23 12 struct rcar_gen4_ptp_private { 24 13 void __iomem *addr; 25 14 struct ptp_clock *clock; 26 15 struct ptp_clock_info info; 27 16 spinlock_t lock; /* For multiple registers access */ 28 - u32 tstamp_tx_ctrl; 29 - u32 tstamp_rx_ctrl; 30 17 s64 default_addend; 31 18 bool initialized; 32 19 };
+3
drivers/net/ethernet/renesas/rswitch.h
··· 1063 1063 bool etha_no_runtime_change; 1064 1064 bool gwca_halt; 1065 1065 struct net_device *offload_brdev; 1066 + 1067 + enum hwtstamp_tx_types tstamp_tx_ctrl; 1068 + enum hwtstamp_rx_filters tstamp_rx_ctrl; 1066 1069 }; 1067 1070 1068 1071 bool is_rdev(const struct net_device *ndev);
+14 -29
drivers/net/ethernet/renesas/rswitch_main.c
··· 30 30 #include "rswitch.h" 31 31 #include "rswitch_l2.h" 32 32 33 + #define RSWITCH_GPTP_OFFSET_S4 0x00018000 34 + 33 35 static int rswitch_reg_wait(void __iomem *addr, u32 offs, u32 mask, u32 expected) 34 36 { 35 37 u32 val; ··· 845 843 if (!skb) 846 844 goto out; 847 845 848 - get_ts = rdev->priv->ptp_priv->tstamp_rx_ctrl & RCAR_GEN4_RXTSTAMP_TYPE_V2_L2_EVENT; 846 + get_ts = rdev->priv->tstamp_rx_ctrl != HWTSTAMP_FILTER_NONE; 849 847 if (get_ts) { 850 848 struct skb_shared_hwtstamps *shhwtstamps; 851 849 struct timespec64 ts; ··· 1799 1797 struct kernel_hwtstamp_config *config) 1800 1798 { 1801 1799 struct rswitch_device *rdev = netdev_priv(ndev); 1802 - struct rcar_gen4_ptp_private *ptp_priv; 1803 - 1804 - ptp_priv = rdev->priv->ptp_priv; 1800 + struct rswitch_private *priv = rdev->priv; 1805 1801 1806 1802 config->flags = 0; 1807 - config->tx_type = ptp_priv->tstamp_tx_ctrl ? HWTSTAMP_TX_ON : 1808 - HWTSTAMP_TX_OFF; 1809 - switch (ptp_priv->tstamp_rx_ctrl & RCAR_GEN4_RXTSTAMP_TYPE) { 1810 - case RCAR_GEN4_RXTSTAMP_TYPE_V2_L2_EVENT: 1811 - config->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; 1812 - break; 1813 - case RCAR_GEN4_RXTSTAMP_TYPE_ALL: 1814 - config->rx_filter = HWTSTAMP_FILTER_ALL; 1815 - break; 1816 - default: 1817 - config->rx_filter = HWTSTAMP_FILTER_NONE; 1818 - break; 1819 - } 1803 + config->tx_type = priv->tstamp_tx_ctrl; 1804 + config->rx_filter = priv->tstamp_rx_ctrl; 1820 1805 1821 1806 return 0; 1822 1807 } ··· 1813 1824 struct netlink_ext_ack *extack) 1814 1825 { 1815 1826 struct rswitch_device *rdev = netdev_priv(ndev); 1816 - u32 tstamp_rx_ctrl = RCAR_GEN4_RXTSTAMP_ENABLED; 1817 - u32 tstamp_tx_ctrl; 1827 + enum hwtstamp_rx_filters tstamp_rx_ctrl; 1828 + enum hwtstamp_tx_types tstamp_tx_ctrl; 1818 1829 1819 1830 if (config->flags) 1820 1831 return -EINVAL; 1821 1832 1822 1833 switch (config->tx_type) { 1823 1834 case HWTSTAMP_TX_OFF: 1824 - tstamp_tx_ctrl = 0; 1825 - break; 1826 1835 case HWTSTAMP_TX_ON: 1827 - tstamp_tx_ctrl = RCAR_GEN4_TXTSTAMP_ENABLED; 1836 + tstamp_tx_ctrl = config->tx_type; 1828 1837 break; 1829 1838 default: 1830 1839 return -ERANGE; ··· 1830 1843 1831 1844 switch (config->rx_filter) { 1832 1845 case HWTSTAMP_FILTER_NONE: 1833 - tstamp_rx_ctrl = 0; 1834 - break; 1835 1846 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: 1836 - tstamp_rx_ctrl |= RCAR_GEN4_RXTSTAMP_TYPE_V2_L2_EVENT; 1847 + tstamp_rx_ctrl = config->rx_filter; 1837 1848 break; 1838 1849 default: 1839 1850 config->rx_filter = HWTSTAMP_FILTER_ALL; 1840 - tstamp_rx_ctrl |= RCAR_GEN4_RXTSTAMP_TYPE_ALL; 1851 + tstamp_rx_ctrl = HWTSTAMP_FILTER_ALL; 1841 1852 break; 1842 1853 } 1843 1854 1844 - rdev->priv->ptp_priv->tstamp_tx_ctrl = tstamp_tx_ctrl; 1845 - rdev->priv->ptp_priv->tstamp_rx_ctrl = tstamp_rx_ctrl; 1855 + rdev->priv->tstamp_tx_ctrl = tstamp_tx_ctrl; 1856 + rdev->priv->tstamp_rx_ctrl = tstamp_rx_ctrl; 1846 1857 1847 1858 return 0; 1848 1859 } ··· 2160 2175 if (IS_ERR(priv->addr)) 2161 2176 return PTR_ERR(priv->addr); 2162 2177 2163 - priv->ptp_priv->addr = priv->addr + RCAR_GEN4_GPTP_OFFSET_S4; 2178 + priv->ptp_priv->addr = priv->addr + RSWITCH_GPTP_OFFSET_S4; 2164 2179 2165 2180 ret = dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(40)); 2166 2181 if (ret < 0) {
+13 -34
drivers/net/ethernet/renesas/rtsn.c
··· 62 62 63 63 int tx_data_irq; 64 64 int rx_data_irq; 65 + 66 + u32 tstamp_tx_ctrl; 67 + u32 tstamp_rx_ctrl; 65 68 }; 66 69 67 70 static u32 rtsn_read(struct rtsn_private *priv, enum rtsn_reg reg) ··· 165 162 unsigned int i; 166 163 bool get_ts; 167 164 168 - get_ts = priv->ptp_priv->tstamp_rx_ctrl & 169 - RCAR_GEN4_RXTSTAMP_TYPE_V2_L2_EVENT; 165 + get_ts = priv->tstamp_rx_ctrl != HWTSTAMP_FILTER_NONE; 170 166 171 167 ndescriptors = priv->dirty_rx + priv->num_rx_ring - priv->cur_rx; 172 168 rx_packets = 0; ··· 1124 1122 static int rtsn_hwtstamp_get(struct net_device *ndev, 1125 1123 struct kernel_hwtstamp_config *config) 1126 1124 { 1127 - struct rcar_gen4_ptp_private *ptp_priv; 1128 1125 struct rtsn_private *priv; 1129 1126 1130 1127 if (!netif_running(ndev)) 1131 1128 return -ENODEV; 1132 1129 1133 1130 priv = netdev_priv(ndev); 1134 - ptp_priv = priv->ptp_priv; 1135 1131 1136 1132 config->flags = 0; 1137 - 1138 - config->tx_type = 1139 - ptp_priv->tstamp_tx_ctrl ? HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF; 1140 - 1141 - switch (ptp_priv->tstamp_rx_ctrl & RCAR_GEN4_RXTSTAMP_TYPE) { 1142 - case RCAR_GEN4_RXTSTAMP_TYPE_V2_L2_EVENT: 1143 - config->rx_filter = HWTSTAMP_FILTER_PTP_V2_L2_EVENT; 1144 - break; 1145 - case RCAR_GEN4_RXTSTAMP_TYPE_ALL: 1146 - config->rx_filter = HWTSTAMP_FILTER_ALL; 1147 - break; 1148 - default: 1149 - config->rx_filter = HWTSTAMP_FILTER_NONE; 1150 - break; 1151 - } 1133 + config->tx_type = priv->tstamp_tx_ctrl; 1134 + config->rx_filter = priv->tstamp_rx_ctrl; 1152 1135 1153 1136 return 0; 1154 1137 } ··· 1142 1155 struct kernel_hwtstamp_config *config, 1143 1156 struct netlink_ext_ack *extack) 1144 1157 { 1145 - struct rcar_gen4_ptp_private *ptp_priv; 1158 + enum hwtstamp_rx_filters tstamp_rx_ctrl; 1159 + enum hwtstamp_tx_types tstamp_tx_ctrl; 1146 1160 struct rtsn_private *priv; 1147 - u32 tstamp_rx_ctrl; 1148 - u32 tstamp_tx_ctrl; 1149 1161 1150 1162 if (!netif_running(ndev)) 1151 1163 return -ENODEV; 1152 1164 1153 1165 priv = netdev_priv(ndev); 1154 - ptp_priv = priv->ptp_priv; 1155 1166 1156 1167 if (config->flags) 1157 1168 return -EINVAL; 1158 1169 1159 1170 switch (config->tx_type) { 1160 1171 case HWTSTAMP_TX_OFF: 1161 - tstamp_tx_ctrl = 0; 1162 - break; 1163 1172 case HWTSTAMP_TX_ON: 1164 - tstamp_tx_ctrl = RCAR_GEN4_TXTSTAMP_ENABLED; 1173 + tstamp_tx_ctrl = config->tx_type; 1165 1174 break; 1166 1175 default: 1167 1176 return -ERANGE; ··· 1165 1182 1166 1183 switch (config->rx_filter) { 1167 1184 case HWTSTAMP_FILTER_NONE: 1168 - tstamp_rx_ctrl = 0; 1169 - break; 1170 1185 case HWTSTAMP_FILTER_PTP_V2_L2_EVENT: 1171 - tstamp_rx_ctrl = RCAR_GEN4_RXTSTAMP_ENABLED | 1172 - RCAR_GEN4_RXTSTAMP_TYPE_V2_L2_EVENT; 1186 + tstamp_rx_ctrl = config->rx_filter; 1173 1187 break; 1174 1188 default: 1175 1189 config->rx_filter = HWTSTAMP_FILTER_ALL; 1176 - tstamp_rx_ctrl = RCAR_GEN4_RXTSTAMP_ENABLED | 1177 - RCAR_GEN4_RXTSTAMP_TYPE_ALL; 1190 + tstamp_rx_ctrl = HWTSTAMP_FILTER_ALL; 1178 1191 break; 1179 1192 } 1180 1193 1181 - ptp_priv->tstamp_tx_ctrl = tstamp_tx_ctrl; 1182 - ptp_priv->tstamp_rx_ctrl = tstamp_rx_ctrl; 1194 + priv->tstamp_tx_ctrl = tstamp_tx_ctrl; 1195 + priv->tstamp_rx_ctrl = tstamp_rx_ctrl; 1183 1196 1184 1197 return 0; 1185 1198 }