systemd: add configurable can-termination option
[AGL/meta-agl.git] / meta-agl-profile-core / recipes-core / systemd / systemd / 0001-network-add-CAN-Termination-tristate-option.patch
1 From 2885f0936d3069fba7bb0078897c98f50927875c Mon Sep 17 00:00:00 2001
2 From: Matt Ranostay <matt.ranostay@konsulko.com>
3 Date: Wed, 19 Feb 2020 12:14:53 -0800
4 Subject: [PATCH] network: add CAN Termination tristate option
5
6 Upstream-Status: Submitted
7 Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
8 ---
9  src/libsystemd/sd-netlink/netlink-types.c |  1 +
10  src/network/networkd-link.c               | 13 +++++++++++++
11  src/network/networkd-network-gperf.gperf  |  1 +
12  src/network/networkd-network.c            |  1 +
13  src/network/networkd-network.h            |  1 +
14  5 files changed, 17 insertions(+)
15
16 diff --git a/src/libsystemd/sd-netlink/netlink-types.c b/src/libsystemd/sd-netlink/netlink-types.c
17 index c93fe9cb4c..0ce950d5af 100644
18 --- a/src/libsystemd/sd-netlink/netlink-types.c
19 +++ b/src/libsystemd/sd-netlink/netlink-types.c
20 @@ -298,6 +298,7 @@ static const NLType rtnl_link_info_data_geneve_types[] = {
21  static const NLType rtnl_link_info_data_can_types[] = {
22          [IFLA_CAN_BITTIMING]            = { .size = sizeof(struct can_bittiming) },
23          [IFLA_CAN_RESTART_MS]           = { .type = NETLINK_TYPE_U32 },
24 +        [IFLA_CAN_TERMINATION]          = { .type = NETLINK_TYPE_U16 },
25  };
26  
27  /* these strings must match the .kind entries in the kernel */
28 diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
29 index 4afcf843bd..af1c4ef55c 100644
30 --- a/src/network/networkd-link.c
31 +++ b/src/network/networkd-link.c
32 @@ -27,6 +27,8 @@
33  #include "util.h"
34  #include "virt.h"
35  
36 +#define CAN_TERMINATION_OHM_VALUE 120
37 +
38  static bool link_dhcp6_enabled(Link *link) {
39          assert(link);
40  
41 @@ -1938,6 +1940,17 @@ static int link_set_can(Link *link) {
42                          return log_link_error_errno(link, r, "Could not append IFLA_CAN_RESTART_MS attribute: %m");
43          }
44  
45 +        if (link->network->can_termination >= 0) {
46 +
47 +                log_link_debug(link, "%sabling can-termination", link->network->can_termination ? "En" : "Dis");
48 +
49 +                r = sd_netlink_message_append_u16(m, IFLA_CAN_TERMINATION,
50 +                                link->network->can_termination ? CAN_TERMINATION_OHM_VALUE : 0);
51 +                if (r < 0)
52 +                        return log_link_error_errno(link, r, "Could not append IFLA_CAN_TERMINATION attribute: %m");
53 +
54 +        }
55 +
56          r = sd_netlink_message_close_container(m);
57          if (r < 0)
58                  return log_link_error_errno(link, r, "Failed to close netlink container: %m");
59 diff --git a/src/network/networkd-network-gperf.gperf b/src/network/networkd-network-gperf.gperf
60 index 6ad5257f79..2f6b42809f 100644
61 --- a/src/network/networkd-network-gperf.gperf
62 +++ b/src/network/networkd-network-gperf.gperf
63 @@ -182,6 +182,7 @@ IPv6Prefix.PreferredLifetimeSec,        config_parse_prefix_lifetime,
64  CAN.BitRate,                            config_parse_si_size,                           0,                             offsetof(Network, can_bitrate)
65  CAN.SamplePoint,                        config_parse_permille,                          0,                             offsetof(Network, can_sample_point)
66  CAN.RestartSec,                         config_parse_sec,                               0,                             offsetof(Network, can_restart_us)
67 +CAN.Termination,                        config_parse_tristate,                          0,                             offsetof(Network, can_termination)
68  /* backwards compatibility: do not add new entries to this section */
69  Network.IPv4LL,                         config_parse_ipv4ll,                            0,                             offsetof(Network, link_local)
70  DHCPv4.UseDNS,                          config_parse_bool,                              0,                             offsetof(Network, dhcp_use_dns)
71 diff --git a/src/network/networkd-network.c b/src/network/networkd-network.c
72 index 429aac5e6c..ded66f5f43 100644
73 --- a/src/network/networkd-network.c
74 +++ b/src/network/networkd-network.c
75 @@ -248,6 +248,7 @@ static int network_load_one(Manager *manager, const char *filename) {
76          network->ipv6_accept_ra_use_dns = true;
77          network->ipv6_accept_ra_route_table = RT_TABLE_MAIN;
78          network->ipv6_mtu = 0;
79 +        network->can_termination = -1;
80  
81          dropin_dirname = strjoina(network->name, ".network.d");
82  
83 diff --git a/src/network/networkd-network.h b/src/network/networkd-network.h
84 index 2d46d393ac..1178510107 100644
85 --- a/src/network/networkd-network.h
86 +++ b/src/network/networkd-network.h
87 @@ -190,6 +190,7 @@ struct Network {
88          size_t can_bitrate;
89          unsigned can_sample_point;
90          usec_t can_restart_us;
91 +        int can_termination;
92  
93          AddressFamilyBoolean ip_forward;
94          bool ip_masquerade;
95 -- 
96 2.25.0
97