Skip to content

Commit 6a77422

Browse files
kmaincentkuba-moo
authored andcommitted
net: ethtool: tsconfig: Fix netlink type of hwtstamp flags
Fix the netlink type for hardware timestamp flags, which are represented as a bitset of flags. Although only one flag is supported currently, the correct netlink bitset type should be used instead of u32 to keep consistency with other fields. Address this by adding a new named string set description for the hwtstamp flag structure. The code has been introduced in the current release so the uAPI change is still okay. Signed-off-by: Kory Maincent <[email protected]> Fixes: 6e9e2ee ("net: ethtool: Add support for tsconfig command to get/set hwtstamp config") Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 3da81cb commit 6a77422

File tree

6 files changed

+39
-11
lines changed

6 files changed

+39
-11
lines changed

Documentation/netlink/specs/ethtool.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1524,7 +1524,8 @@ attribute-sets:
15241524
nested-attributes: bitset
15251525
-
15261526
name: hwtstamp-flags
1527-
type: u32
1527+
type: nest
1528+
nested-attributes: bitset
15281529

15291530
operations:
15301531
enum-model: directional

include/uapi/linux/ethtool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ enum ethtool_link_ext_substate_module {
682682
* @ETH_SS_STATS_ETH_CTRL: names of IEEE 802.3 MAC Control statistics
683683
* @ETH_SS_STATS_RMON: names of RMON statistics
684684
* @ETH_SS_STATS_PHY: names of PHY(dev) statistics
685+
* @ETH_SS_TS_FLAGS: hardware timestamping flags
685686
*
686687
* @ETH_SS_COUNT: number of defined string sets
687688
*/
@@ -708,6 +709,7 @@ enum ethtool_stringset {
708709
ETH_SS_STATS_ETH_CTRL,
709710
ETH_SS_STATS_RMON,
710711
ETH_SS_STATS_PHY,
712+
ETH_SS_TS_FLAGS,
711713

712714
/* add new constants above here */
713715
ETH_SS_COUNT

net/ethtool/common.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,11 @@ const char ts_rx_filter_names[][ETH_GSTRING_LEN] = {
462462
};
463463
static_assert(ARRAY_SIZE(ts_rx_filter_names) == __HWTSTAMP_FILTER_CNT);
464464

465+
const char ts_flags_names[][ETH_GSTRING_LEN] = {
466+
[const_ilog2(HWTSTAMP_FLAG_BONDED_PHC_INDEX)] = "bonded-phc-index",
467+
};
468+
static_assert(ARRAY_SIZE(ts_flags_names) == __HWTSTAMP_FLAG_CNT);
469+
465470
const char udp_tunnel_type_names[][ETH_GSTRING_LEN] = {
466471
[ETHTOOL_UDP_TUNNEL_TYPE_VXLAN] = "vxlan",
467472
[ETHTOOL_UDP_TUNNEL_TYPE_GENEVE] = "geneve",

net/ethtool/common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
ETHTOOL_LINK_MODE_ ## speed ## base ## type ## _ ## duplex ## _BIT
1414

1515
#define __SOF_TIMESTAMPING_CNT (const_ilog2(SOF_TIMESTAMPING_LAST) + 1)
16+
#define __HWTSTAMP_FLAG_CNT (const_ilog2(HWTSTAMP_FLAG_LAST) + 1)
1617

1718
struct link_mode_info {
1819
int speed;
@@ -38,6 +39,7 @@ extern const char wol_mode_names[][ETH_GSTRING_LEN];
3839
extern const char sof_timestamping_names[][ETH_GSTRING_LEN];
3940
extern const char ts_tx_type_names[][ETH_GSTRING_LEN];
4041
extern const char ts_rx_filter_names[][ETH_GSTRING_LEN];
42+
extern const char ts_flags_names[][ETH_GSTRING_LEN];
4143
extern const char udp_tunnel_type_names[][ETH_GSTRING_LEN];
4244

4345
int __ethtool_get_link(struct net_device *dev);

net/ethtool/strset.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,11 @@ static const struct strset_info info_template[] = {
7575
.count = __HWTSTAMP_FILTER_CNT,
7676
.strings = ts_rx_filter_names,
7777
},
78+
[ETH_SS_TS_FLAGS] = {
79+
.per_dev = false,
80+
.count = __HWTSTAMP_FLAG_CNT,
81+
.strings = ts_flags_names,
82+
},
7883
[ETH_SS_UDP_TUNNEL_TYPES] = {
7984
.per_dev = false,
8085
.count = __ETHTOOL_UDP_TUNNEL_TYPE_CNT,

net/ethtool/tsconfig.c

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ static int tsconfig_prepare_data(const struct ethnl_req_info *req_base,
5454

5555
data->hwtst_config.tx_type = BIT(cfg.tx_type);
5656
data->hwtst_config.rx_filter = BIT(cfg.rx_filter);
57-
data->hwtst_config.flags = BIT(cfg.flags);
57+
data->hwtst_config.flags = cfg.flags;
5858

5959
data->hwprov_desc.index = -1;
6060
hwprov = rtnl_dereference(dev->hwprov);
@@ -91,10 +91,16 @@ static int tsconfig_reply_size(const struct ethnl_req_info *req_base,
9191

9292
BUILD_BUG_ON(__HWTSTAMP_TX_CNT > 32);
9393
BUILD_BUG_ON(__HWTSTAMP_FILTER_CNT > 32);
94+
BUILD_BUG_ON(__HWTSTAMP_FLAG_CNT > 32);
9495

95-
if (data->hwtst_config.flags)
96-
/* _TSCONFIG_HWTSTAMP_FLAGS */
97-
len += nla_total_size(sizeof(u32));
96+
if (data->hwtst_config.flags) {
97+
ret = ethnl_bitset32_size(&data->hwtst_config.flags,
98+
NULL, __HWTSTAMP_FLAG_CNT,
99+
ts_flags_names, compact);
100+
if (ret < 0)
101+
return ret;
102+
len += ret; /* _TSCONFIG_HWTSTAMP_FLAGS */
103+
}
98104

99105
if (data->hwtst_config.tx_type) {
100106
ret = ethnl_bitset32_size(&data->hwtst_config.tx_type,
@@ -130,8 +136,10 @@ static int tsconfig_fill_reply(struct sk_buff *skb,
130136
int ret;
131137

132138
if (data->hwtst_config.flags) {
133-
ret = nla_put_u32(skb, ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS,
134-
data->hwtst_config.flags);
139+
ret = ethnl_put_bitset32(skb, ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS,
140+
&data->hwtst_config.flags, NULL,
141+
__HWTSTAMP_FLAG_CNT,
142+
ts_flags_names, compact);
135143
if (ret < 0)
136144
return ret;
137145
}
@@ -180,7 +188,7 @@ const struct nla_policy ethnl_tsconfig_set_policy[ETHTOOL_A_TSCONFIG_MAX + 1] =
180188
[ETHTOOL_A_TSCONFIG_HEADER] = NLA_POLICY_NESTED(ethnl_header_policy),
181189
[ETHTOOL_A_TSCONFIG_HWTSTAMP_PROVIDER] =
182190
NLA_POLICY_NESTED(ethnl_ts_hwtst_prov_policy),
183-
[ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS] = { .type = NLA_U32 },
191+
[ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS] = { .type = NLA_NESTED },
184192
[ETHTOOL_A_TSCONFIG_RX_FILTERS] = { .type = NLA_NESTED },
185193
[ETHTOOL_A_TSCONFIG_TX_TYPES] = { .type = NLA_NESTED },
186194
};
@@ -296,6 +304,7 @@ static int ethnl_set_tsconfig(struct ethnl_req_info *req_base,
296304

297305
BUILD_BUG_ON(__HWTSTAMP_TX_CNT >= 32);
298306
BUILD_BUG_ON(__HWTSTAMP_FILTER_CNT >= 32);
307+
BUILD_BUG_ON(__HWTSTAMP_FLAG_CNT > 32);
299308

300309
if (!netif_device_present(dev))
301310
return -ENODEV;
@@ -377,9 +386,13 @@ static int ethnl_set_tsconfig(struct ethnl_req_info *req_base,
377386
}
378387

379388
if (tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS]) {
380-
ethnl_update_u32(&hwtst_config.flags,
381-
tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS],
382-
&config_mod);
389+
ret = ethnl_update_bitset32(&hwtst_config.flags,
390+
__HWTSTAMP_FLAG_CNT,
391+
tb[ETHTOOL_A_TSCONFIG_HWTSTAMP_FLAGS],
392+
ts_flags_names, info->extack,
393+
&config_mod);
394+
if (ret < 0)
395+
goto err_free_hwprov;
383396
}
384397

385398
ret = net_hwtstamp_validate(&hwtst_config);

0 commit comments

Comments
 (0)