Skip to content

Commit 5f18426

Browse files
Jiri Pirkodavem330
authored andcommitted
netdev: expose DPLL pin handle for netdevice
In case netdevice represents a SyncE port, the user needs to understand the connection between netdevice and associated DPLL pin. There might me multiple netdevices pointing to the same pin, in case of VF/SF implementation. Add a IFLA Netlink attribute to nest the DPLL pin handle, similar to how it is implemented for devlink port. Add a struct dpll_pin pointer to netdev and protect access to it by RTNL. Expose netdev_dpll_pin_set() and netdev_dpll_pin_clear() helpers to the drivers so they can set/clear the DPLL pin relationship to netdev. Note that during the lifetime of struct dpll_pin the pin handle does not change. Therefore it is save to access it lockless. It is drivers responsibility to call netdev_dpll_pin_clear() before dpll_pin_put(). Signed-off-by: Jiri Pirko <[email protected]> Signed-off-by: Arkadiusz Kubalewski <[email protected]> Signed-off-by: Vadim Fedorenko <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9d71b54 commit 5f18426

File tree

6 files changed

+109
-3
lines changed

6 files changed

+109
-3
lines changed

drivers/dpll/dpll_netlink.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ dpll_msg_add_dev_parent_handle(struct sk_buff *msg, u32 id)
4747
return 0;
4848
}
4949

50+
/**
51+
* dpll_msg_pin_handle_size - get size of pin handle attribute for given pin
52+
* @pin: pin pointer
53+
*
54+
* Return: byte size of pin handle attribute for given pin.
55+
*/
56+
size_t dpll_msg_pin_handle_size(struct dpll_pin *pin)
57+
{
58+
return pin ? nla_total_size(4) : 0; /* DPLL_A_PIN_ID */
59+
}
60+
EXPORT_SYMBOL_GPL(dpll_msg_pin_handle_size);
61+
5062
/**
5163
* dpll_msg_add_pin_handle - attach pin handle attribute to a given message
5264
* @msg: pointer to sk_buff message to attach a pin handle
@@ -56,15 +68,15 @@ dpll_msg_add_dev_parent_handle(struct sk_buff *msg, u32 id)
5668
* * 0 - success
5769
* * -EMSGSIZE - no space in message to attach pin handle
5870
*/
59-
static int
60-
dpll_msg_add_pin_handle(struct sk_buff *msg, struct dpll_pin *pin)
71+
int dpll_msg_add_pin_handle(struct sk_buff *msg, struct dpll_pin *pin)
6172
{
6273
if (!pin)
6374
return 0;
6475
if (nla_put_u32(msg, DPLL_A_PIN_ID, pin->id))
6576
return -EMSGSIZE;
6677
return 0;
6778
}
79+
EXPORT_SYMBOL_GPL(dpll_msg_add_pin_handle);
6880

6981
static int
7082
dpll_msg_add_mode(struct sk_buff *msg, struct dpll_device *dpll,

include/linux/dpll.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,21 @@ struct dpll_pin_properties {
101101
struct dpll_pin_frequency *freq_supported;
102102
};
103103

104+
#if IS_ENABLED(CONFIG_DPLL)
105+
size_t dpll_msg_pin_handle_size(struct dpll_pin *pin);
106+
int dpll_msg_add_pin_handle(struct sk_buff *msg, struct dpll_pin *pin);
107+
#else
108+
static inline size_t dpll_msg_pin_handle_size(struct dpll_pin *pin)
109+
{
110+
return 0;
111+
}
112+
113+
static inline int dpll_msg_add_pin_handle(struct sk_buff *msg, struct dpll_pin *pin)
114+
{
115+
return 0;
116+
}
117+
#endif
118+
104119
struct dpll_device *
105120
dpll_device_get(u64 clock_id, u32 dev_driver_id, struct module *module);
106121

include/linux/netdevice.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ struct xdp_buff;
7979
struct xdp_frame;
8080
struct xdp_metadata_ops;
8181
struct xdp_md;
82+
/* DPLL specific */
83+
struct dpll_pin;
8284

8385
typedef u32 xdp_features_t;
8486

@@ -2049,6 +2051,9 @@ enum netdev_ml_priv_type {
20492051
* SET_NETDEV_DEVLINK_PORT macro. This pointer is static
20502052
* during the time netdevice is registered.
20512053
*
2054+
* @dpll_pin: Pointer to the SyncE source pin of a DPLL subsystem,
2055+
* where the clock is recovered.
2056+
*
20522057
* FIXME: cleanup struct net_device such that network protocol info
20532058
* moves out.
20542059
*/
@@ -2405,6 +2410,10 @@ struct net_device {
24052410
struct rtnl_hw_stats64 *offload_xstats_l3;
24062411

24072412
struct devlink_port *devlink_port;
2413+
2414+
#if IS_ENABLED(CONFIG_DPLL)
2415+
struct dpll_pin *dpll_pin;
2416+
#endif
24082417
};
24092418
#define to_net_dev(d) container_of(d, struct net_device, dev)
24102419

@@ -3940,6 +3949,18 @@ int dev_get_mac_address(struct sockaddr *sa, struct net *net, char *dev_name);
39403949
int dev_get_port_parent_id(struct net_device *dev,
39413950
struct netdev_phys_item_id *ppid, bool recurse);
39423951
bool netdev_port_same_parent_id(struct net_device *a, struct net_device *b);
3952+
void netdev_dpll_pin_set(struct net_device *dev, struct dpll_pin *dpll_pin);
3953+
void netdev_dpll_pin_clear(struct net_device *dev);
3954+
3955+
static inline struct dpll_pin *netdev_dpll_pin(const struct net_device *dev)
3956+
{
3957+
#if IS_ENABLED(CONFIG_DPLL)
3958+
return dev->dpll_pin;
3959+
#else
3960+
return NULL;
3961+
#endif
3962+
}
3963+
39433964
struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev, bool *again);
39443965
struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
39453966
struct netdev_queue *txq, int *ret);

include/uapi/linux/if_link.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ enum {
376376

377377
IFLA_GSO_IPV4_MAX_SIZE,
378378
IFLA_GRO_IPV4_MAX_SIZE,
379-
379+
IFLA_DPLL_PIN,
380380
__IFLA_MAX
381381
};
382382

net/core/dev.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9023,6 +9023,28 @@ bool netdev_port_same_parent_id(struct net_device *a, struct net_device *b)
90239023
}
90249024
EXPORT_SYMBOL(netdev_port_same_parent_id);
90259025

9026+
static void netdev_dpll_pin_assign(struct net_device *dev, struct dpll_pin *dpll_pin)
9027+
{
9028+
#if IS_ENABLED(CONFIG_DPLL)
9029+
rtnl_lock();
9030+
dev->dpll_pin = dpll_pin;
9031+
rtnl_unlock();
9032+
#endif
9033+
}
9034+
9035+
void netdev_dpll_pin_set(struct net_device *dev, struct dpll_pin *dpll_pin)
9036+
{
9037+
WARN_ON(!dpll_pin);
9038+
netdev_dpll_pin_assign(dev, dpll_pin);
9039+
}
9040+
EXPORT_SYMBOL(netdev_dpll_pin_set);
9041+
9042+
void netdev_dpll_pin_clear(struct net_device *dev)
9043+
{
9044+
netdev_dpll_pin_assign(dev, NULL);
9045+
}
9046+
EXPORT_SYMBOL(netdev_dpll_pin_clear);
9047+
90269048
/**
90279049
* dev_change_proto_down - set carrier according to proto_down.
90289050
*

net/core/rtnetlink.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
#if IS_ENABLED(CONFIG_IPV6)
5858
#include <net/addrconf.h>
5959
#endif
60+
#include <linux/dpll.h>
6061

6162
#include "dev.h"
6263

@@ -1055,6 +1056,15 @@ static size_t rtnl_devlink_port_size(const struct net_device *dev)
10551056
return size;
10561057
}
10571058

1059+
static size_t rtnl_dpll_pin_size(const struct net_device *dev)
1060+
{
1061+
size_t size = nla_total_size(0); /* nest IFLA_DPLL_PIN */
1062+
1063+
size += dpll_msg_pin_handle_size(netdev_dpll_pin(dev));
1064+
1065+
return size;
1066+
}
1067+
10581068
static noinline size_t if_nlmsg_size(const struct net_device *dev,
10591069
u32 ext_filter_mask)
10601070
{
@@ -1111,6 +1121,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
11111121
+ rtnl_prop_list_size(dev)
11121122
+ nla_total_size(MAX_ADDR_LEN) /* IFLA_PERM_ADDRESS */
11131123
+ rtnl_devlink_port_size(dev)
1124+
+ rtnl_dpll_pin_size(dev)
11141125
+ 0;
11151126
}
11161127

@@ -1774,6 +1785,28 @@ static int rtnl_fill_devlink_port(struct sk_buff *skb,
17741785
return ret;
17751786
}
17761787

1788+
static int rtnl_fill_dpll_pin(struct sk_buff *skb,
1789+
const struct net_device *dev)
1790+
{
1791+
struct nlattr *dpll_pin_nest;
1792+
int ret;
1793+
1794+
dpll_pin_nest = nla_nest_start(skb, IFLA_DPLL_PIN);
1795+
if (!dpll_pin_nest)
1796+
return -EMSGSIZE;
1797+
1798+
ret = dpll_msg_add_pin_handle(skb, netdev_dpll_pin(dev));
1799+
if (ret < 0)
1800+
goto nest_cancel;
1801+
1802+
nla_nest_end(skb, dpll_pin_nest);
1803+
return 0;
1804+
1805+
nest_cancel:
1806+
nla_nest_cancel(skb, dpll_pin_nest);
1807+
return ret;
1808+
}
1809+
17771810
static int rtnl_fill_ifinfo(struct sk_buff *skb,
17781811
struct net_device *dev, struct net *src_net,
17791812
int type, u32 pid, u32 seq, u32 change,
@@ -1916,6 +1949,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
19161949
if (rtnl_fill_devlink_port(skb, dev))
19171950
goto nla_put_failure;
19181951

1952+
if (rtnl_fill_dpll_pin(skb, dev))
1953+
goto nla_put_failure;
1954+
19191955
nlmsg_end(skb, nlh);
19201956
return 0;
19211957

0 commit comments

Comments
 (0)