Skip to content

Commit d2f1cbe

Browse files
Jiri Pirkokubalewski
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(). v8->v9: - net_device->dpll_pin is only valid if IS_ENABLED(CONFIG_DPLL) fix the code in net/core/rtnetlink.c to respect that. - move dpll_msg_add_pin_handle to "dpll: netlink" patch + export the function with this patch Signed-off-by: Jiri Pirko <jiri@nvidia.com> Signed-off-by: Arkadiusz Kubalewski <arkadiusz.kubalewski@intel.com>
1 parent e95421d commit d2f1cbe

6 files changed

Lines changed: 103 additions & 3 deletions

File tree

drivers/dpll/dpll_netlink.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ int dpll_msg_add_pin_handle(struct sk_buff *msg, struct dpll_pin *pin)
6666
return -EMSGSIZE;
6767
return 0;
6868
}
69+
EXPORT_SYMBOL_GPL(dpll_msg_add_pin_handle);
6970

7071
static int
7172
dpll_msg_add_mode(struct sk_buff *msg, struct dpll_device *dpll,
@@ -320,10 +321,9 @@ dpll_msg_add_pin_parents(struct sk_buff *msg, struct dpll_pin *pin,
320321
nest = nla_nest_start(msg, DPLL_A_PIN_PARENT_PIN);
321322
if (!nest)
322323
return -EMSGSIZE;
323-
if (nla_put_u32(msg, DPLL_A_PIN_ID, ppin->id)) {
324-
ret = -EMSGSIZE;
324+
ret = dpll_msg_add_pin_handle(msg, ppin);
325+
if (ret)
325326
goto nest_cancel;
326-
}
327327
if (nla_put_u8(msg, DPLL_A_PIN_STATE, state)) {
328328
ret = -EMSGSIZE;
329329
goto nest_cancel;
@@ -386,6 +386,7 @@ dpll_cmd_pin_get_one(struct sk_buff *msg, struct dpll_pin *pin,
386386

387387
ref = dpll_xa_ref_dpll_first(&pin->dpll_refs);
388388
ASSERT_NOT_NULL(ref);
389+
389390
ret = dpll_msg_add_pin_handle(msg, pin);
390391
if (ret)
391392
return ret;

include/linux/dpll.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,26 @@ struct dpll_pin_properties {
125125
struct dpll_pin_phase_adjust_range phase_range;
126126
};
127127

128+
#if IS_ENABLED(CONFIG_DPLL)
129+
130+
size_t dpll_msg_pin_handle_size(struct dpll_pin *pin);
131+
132+
int dpll_msg_add_pin_handle(struct sk_buff *msg, struct dpll_pin *pin);
133+
134+
#else
135+
136+
static inline size_t dpll_msg_pin_handle_size(struct dpll_pin *pin)
137+
{
138+
return 0;
139+
}
140+
141+
static inline int dpll_msg_add_pin_handle(struct sk_buff *msg, struct dpll_pin *pin)
142+
{
143+
return 0;
144+
}
145+
146+
#endif
147+
128148
struct dpll_device
129149
*dpll_device_get(u64 clock_id, u32 dev_driver_id, struct module *module);
130150

include/linux/netdevice.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#include <linux/rculist.h>
3535
#include <linux/workqueue.h>
3636
#include <linux/dynamic_queue_limits.h>
37+
#include <linux/dpll.h>
3738

3839
#include <net/net_namespace.h>
3940
#ifdef CONFIG_DCB
@@ -2058,6 +2059,9 @@ enum netdev_ml_priv_type {
20582059
* SET_NETDEV_DEVLINK_PORT macro. This pointer is static
20592060
* during the time netdevice is registered.
20602061
*
2062+
* @dpll_pin: Pointer to the SyncE source pin of a DPLL subsystem,
2063+
* where the clock is recovered.
2064+
*
20612065
* FIXME: cleanup struct net_device such that network protocol info
20622066
* moves out.
20632067
*/
@@ -2414,6 +2418,10 @@ struct net_device {
24142418
struct rtnl_hw_stats64 *offload_xstats_l3;
24152419

24162420
struct devlink_port *devlink_port;
2421+
2422+
#if IS_ENABLED(CONFIG_DPLL)
2423+
struct dpll_pin *dpll_pin;
2424+
#endif
24172425
};
24182426
#define to_net_dev(d) container_of(d, struct net_device, dev)
24192427

@@ -3961,6 +3969,18 @@ int dev_get_mac_address(struct sockaddr *sa, struct net *net, char *dev_name);
39613969
int dev_get_port_parent_id(struct net_device *dev,
39623970
struct netdev_phys_item_id *ppid, bool recurse);
39633971
bool netdev_port_same_parent_id(struct net_device *a, struct net_device *b);
3972+
void netdev_dpll_pin_set(struct net_device *dev, struct dpll_pin *dpll_pin);
3973+
void netdev_dpll_pin_clear(struct net_device *dev);
3974+
3975+
static inline struct dpll_pin *netdev_dpll_pin(const struct net_device *dev)
3976+
{
3977+
#if IS_ENABLED(CONFIG_DPLL)
3978+
return dev->dpll_pin;
3979+
#else
3980+
return NULL;
3981+
#endif
3982+
}
3983+
39643984
struct sk_buff *validate_xmit_skb_list(struct sk_buff *skb, struct net_device *dev, bool *again);
39653985
struct sk_buff *dev_hard_start_xmit(struct sk_buff *skb, struct net_device *dev,
39663986
struct netdev_queue *txq, int *ret);

include/uapi/linux/if_link.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,8 @@ enum {
377377
IFLA_GSO_IPV4_MAX_SIZE,
378378
IFLA_GRO_IPV4_MAX_SIZE,
379379

380+
IFLA_DPLL_PIN,
381+
380382
__IFLA_MAX
381383
};
382384

net/core/dev.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8956,6 +8956,28 @@ bool netdev_port_same_parent_id(struct net_device *a, struct net_device *b)
89568956
}
89578957
EXPORT_SYMBOL(netdev_port_same_parent_id);
89588958

8959+
static void netdev_dpll_pin_assign(struct net_device *dev, struct dpll_pin *dpll_pin)
8960+
{
8961+
#if IS_ENABLED(CONFIG_DPLL)
8962+
rtnl_lock();
8963+
dev->dpll_pin = dpll_pin;
8964+
rtnl_unlock();
8965+
#endif
8966+
}
8967+
8968+
void netdev_dpll_pin_set(struct net_device *dev, struct dpll_pin *dpll_pin)
8969+
{
8970+
WARN_ON(!dpll_pin);
8971+
netdev_dpll_pin_assign(dev, dpll_pin);
8972+
}
8973+
EXPORT_SYMBOL(netdev_dpll_pin_set);
8974+
8975+
void netdev_dpll_pin_clear(struct net_device *dev)
8976+
{
8977+
netdev_dpll_pin_assign(dev, NULL);
8978+
}
8979+
EXPORT_SYMBOL(netdev_dpll_pin_clear);
8980+
89598981
/**
89608982
* dev_change_proto_down - set carrier according to proto_down.
89618983
*

net/core/rtnetlink.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,15 @@ static size_t rtnl_devlink_port_size(const struct net_device *dev)
10551055
return size;
10561056
}
10571057

1058+
static size_t rtnl_dpll_pin_size(const struct net_device *dev)
1059+
{
1060+
size_t size = nla_total_size(0); /* nest IFLA_DPLL_PIN */
1061+
1062+
size += dpll_msg_pin_handle_size(netdev_dpll_pin(dev));
1063+
1064+
return size;
1065+
}
1066+
10581067
static noinline size_t if_nlmsg_size(const struct net_device *dev,
10591068
u32 ext_filter_mask)
10601069
{
@@ -1111,6 +1120,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
11111120
+ rtnl_prop_list_size(dev)
11121121
+ nla_total_size(MAX_ADDR_LEN) /* IFLA_PERM_ADDRESS */
11131122
+ rtnl_devlink_port_size(dev)
1123+
+ rtnl_dpll_pin_size(dev)
11141124
+ 0;
11151125
}
11161126

@@ -1775,6 +1785,28 @@ static int rtnl_fill_devlink_port(struct sk_buff *skb,
17751785
return ret;
17761786
}
17771787

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+
17781810
static int rtnl_fill_ifinfo(struct sk_buff *skb,
17791811
struct net_device *dev, struct net *src_net,
17801812
int type, u32 pid, u32 seq, u32 change,
@@ -1917,6 +1949,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
19171949
if (rtnl_fill_devlink_port(skb, dev))
19181950
goto nla_put_failure;
19191951

1952+
if (rtnl_fill_dpll_pin(skb, dev))
1953+
goto nla_put_failure;
1954+
19201955
nlmsg_end(skb, nlh);
19211956
return 0;
19221957

0 commit comments

Comments
 (0)