Compare commits

...

6 Commits

Author SHA1 Message Date
Yu Watanabe a834cb5247
Merge pull request #15036 from yuwata/can-termination-mod
network: add CAN Termination tristate option
2020-03-07 19:11:03 +09:00
Yu Watanabe 084f99afce
Merge pull request #15038 from lucaswerkmeister/docs
docs: fix misplaced close-paren
2020-03-07 19:10:04 +09:00
Lucas Werkmeister e1ef1e5d53 docs: fix typo 2020-03-06 22:58:53 +01:00
Lucas Werkmeister afcb3e758c docs: fix misplaced close-paren
I assume it’s supposed to be “see Home Directories for details” and not
“… and embeds these JSON records directly in the home directory images …
for details”, but the previous text suggested the latter reading to me.
2020-03-06 22:12:37 +01:00
Matt Ranostay 52aa38f14a network: add CAN Termination tristate option 2020-03-07 02:00:02 +09:00
Yu Watanabe 9c01b203a7 linux: add can/netlink.h 2020-03-07 01:53:06 +09:00
9 changed files with 171 additions and 2 deletions

View File

@ -14,7 +14,7 @@ pairs, encoded as JSON. Specifically:
1. [`systemd-homed.service`](https://www.freedesktop.org/software/systemd/man/systemd-homed.service.html) 1. [`systemd-homed.service`](https://www.freedesktop.org/software/systemd/man/systemd-homed.service.html)
manages `human` user home directories and embeds these JSON records manages `human` user home directories and embeds these JSON records
directly in the home directory images (see [Home directly in the home directory images (see [Home
Directories](https://systemd.io/HOME_DIRECTORY)) for details. Directories](https://systemd.io/HOME_DIRECTORY) for details).
2. [`pam_systemd`](https://www.freedesktop.org/software/systemd/man/pam_systemd.html) 2. [`pam_systemd`](https://www.freedesktop.org/software/systemd/man/pam_systemd.html)
processes these JSON records for users that log in, and applies various processes these JSON records for users that log in, and applies various
@ -541,7 +541,7 @@ below). It's undefined how precise the URI is: during log-in it is tested
against all plugged in security tokens and if there's exactly one matching against all plugged in security tokens and if there's exactly one matching
private key found with it it is used. private key found with it it is used.
`privileged` → An object, which contains the fields of he `privileged` section `privileged` → An object, which contains the fields of the `privileged` section
of the user record, see below. of the user record, see below.
`perMachine` → An array of objects, which contain the `perMachine` section of `perMachine` → An array of objects, which contain the `perMachine` section of

View File

@ -2303,6 +2303,13 @@
automatic restart off. By default automatic restart is disabled.</para> automatic restart off. By default automatic restart is disabled.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><varname>Termination=</varname></term>
<listitem>
<para>Takes a boolean. When <literal>yes</literal>, the termination resistor will be selected for
the bias network. When unset, the kernel's default will be used.</para>
</listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><varname>TripleSampling=</varname></term> <term><varname>TripleSampling=</varname></term>
<listitem> <listitem>

View File

@ -0,0 +1,144 @@
/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
/*
* linux/can/netlink.h
*
* Definitions for the CAN netlink interface
*
* Copyright (c) 2009 Wolfgang Grandegger <wg@grandegger.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the version 2 of the GNU General Public License
* as published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef _UAPI_CAN_NETLINK_H
#define _UAPI_CAN_NETLINK_H
#include <linux/types.h>
/*
* CAN bit-timing parameters
*
* For further information, please read chapter "8 BIT TIMING
* REQUIREMENTS" of the "Bosch CAN Specification version 2.0"
* at http://www.semiconductors.bosch.de/pdf/can2spec.pdf.
*/
struct can_bittiming {
__u32 bitrate; /* Bit-rate in bits/second */
__u32 sample_point; /* Sample point in one-tenth of a percent */
__u32 tq; /* Time quanta (TQ) in nanoseconds */
__u32 prop_seg; /* Propagation segment in TQs */
__u32 phase_seg1; /* Phase buffer segment 1 in TQs */
__u32 phase_seg2; /* Phase buffer segment 2 in TQs */
__u32 sjw; /* Synchronisation jump width in TQs */
__u32 brp; /* Bit-rate prescaler */
};
/*
* CAN hardware-dependent bit-timing constant
*
* Used for calculating and checking bit-timing parameters
*/
struct can_bittiming_const {
char name[16]; /* Name of the CAN controller hardware */
__u32 tseg1_min; /* Time segment 1 = prop_seg + phase_seg1 */
__u32 tseg1_max;
__u32 tseg2_min; /* Time segment 2 = phase_seg2 */
__u32 tseg2_max;
__u32 sjw_max; /* Synchronisation jump width */
__u32 brp_min; /* Bit-rate prescaler */
__u32 brp_max;
__u32 brp_inc;
};
/*
* CAN clock parameters
*/
struct can_clock {
__u32 freq; /* CAN system clock frequency in Hz */
};
/*
* CAN operational and error states
*/
enum can_state {
CAN_STATE_ERROR_ACTIVE = 0, /* RX/TX error count < 96 */
CAN_STATE_ERROR_WARNING, /* RX/TX error count < 128 */
CAN_STATE_ERROR_PASSIVE, /* RX/TX error count < 256 */
CAN_STATE_BUS_OFF, /* RX/TX error count >= 256 */
CAN_STATE_STOPPED, /* Device is stopped */
CAN_STATE_SLEEPING, /* Device is sleeping */
CAN_STATE_MAX
};
/*
* CAN bus error counters
*/
struct can_berr_counter {
__u16 txerr;
__u16 rxerr;
};
/*
* CAN controller mode
*/
struct can_ctrlmode {
__u32 mask;
__u32 flags;
};
#define CAN_CTRLMODE_LOOPBACK 0x01 /* Loopback mode */
#define CAN_CTRLMODE_LISTENONLY 0x02 /* Listen-only mode */
#define CAN_CTRLMODE_3_SAMPLES 0x04 /* Triple sampling mode */
#define CAN_CTRLMODE_ONE_SHOT 0x08 /* One-Shot mode */
#define CAN_CTRLMODE_BERR_REPORTING 0x10 /* Bus-error reporting */
#define CAN_CTRLMODE_FD 0x20 /* CAN FD mode */
#define CAN_CTRLMODE_PRESUME_ACK 0x40 /* Ignore missing CAN ACKs */
#define CAN_CTRLMODE_FD_NON_ISO 0x80 /* CAN FD in non-ISO mode */
/*
* CAN device statistics
*/
struct can_device_stats {
__u32 bus_error; /* Bus errors */
__u32 error_warning; /* Changes to error warning state */
__u32 error_passive; /* Changes to error passive state */
__u32 bus_off; /* Changes to bus off state */
__u32 arbitration_lost; /* Arbitration lost errors */
__u32 restarts; /* CAN controller re-starts */
};
/*
* CAN netlink interface
*/
enum {
IFLA_CAN_UNSPEC,
IFLA_CAN_BITTIMING,
IFLA_CAN_BITTIMING_CONST,
IFLA_CAN_CLOCK,
IFLA_CAN_STATE,
IFLA_CAN_CTRLMODE,
IFLA_CAN_RESTART_MS,
IFLA_CAN_RESTART,
IFLA_CAN_BERR_COUNTER,
IFLA_CAN_DATA_BITTIMING,
IFLA_CAN_DATA_BITTIMING_CONST,
IFLA_CAN_TERMINATION,
IFLA_CAN_TERMINATION_CONST,
IFLA_CAN_BITRATE_CONST,
IFLA_CAN_DATA_BITRATE_CONST,
IFLA_CAN_BITRATE_MAX,
__IFLA_CAN_MAX
};
#define IFLA_CAN_MAX (__IFLA_CAN_MAX - 1)
/* u16 termination range: 1..65535 Ohms */
#define CAN_TERMINATION_DISABLED 0
#endif /* !_UAPI_CAN_NETLINK_H */

View File

@ -316,6 +316,7 @@ static const NLType rtnl_link_info_data_can_types[] = {
[IFLA_CAN_BITTIMING] = { .size = sizeof(struct can_bittiming) }, [IFLA_CAN_BITTIMING] = { .size = sizeof(struct can_bittiming) },
[IFLA_CAN_RESTART_MS] = { .type = NETLINK_TYPE_U32 }, [IFLA_CAN_RESTART_MS] = { .type = NETLINK_TYPE_U32 },
[IFLA_CAN_CTRLMODE] = { .size = sizeof(struct can_ctrlmode) }, [IFLA_CAN_CTRLMODE] = { .size = sizeof(struct can_ctrlmode) },
[IFLA_CAN_TERMINATION] = { .type = NETLINK_TYPE_U16 },
}; };
static const NLType rtnl_link_info_data_macsec_types[] = { static const NLType rtnl_link_info_data_macsec_types[] = {

View File

@ -9,6 +9,8 @@
#include "networkd-manager.h" #include "networkd-manager.h"
#include "string-util.h" #include "string-util.h"
#define CAN_TERMINATION_OHM_VALUE 120
static int link_up_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) { static int link_up_handler(sd_netlink *rtnl, sd_netlink_message *m, Link *link) {
int r; int r;
@ -152,6 +154,17 @@ static int link_set_can(Link *link) {
return log_link_error_errno(link, r, "Could not append IFLA_CAN_CTRLMODE attribute: %m"); return log_link_error_errno(link, r, "Could not append IFLA_CAN_CTRLMODE attribute: %m");
} }
if (link->network->can_termination >= 0) {
log_link_debug(link, "%sabling can-termination", link->network->can_termination ? "En" : "Dis");
r = sd_netlink_message_append_u16(m, IFLA_CAN_TERMINATION,
link->network->can_termination ? CAN_TERMINATION_OHM_VALUE : 0);
if (r < 0)
return log_link_error_errno(link, r, "Could not append IFLA_CAN_TERMINATION attribute: %m");
}
r = sd_netlink_message_close_container(m); r = sd_netlink_message_close_container(m);
if (r < 0) if (r < 0)
return log_link_error_errno(link, r, "Failed to close netlink container: %m"); return log_link_error_errno(link, r, "Failed to close netlink container: %m");

View File

@ -255,6 +255,7 @@ CAN.BitRate, config_parse_si_uint64,
CAN.SamplePoint, config_parse_permille, 0, offsetof(Network, can_sample_point) CAN.SamplePoint, config_parse_permille, 0, offsetof(Network, can_sample_point)
CAN.RestartSec, config_parse_sec, 0, offsetof(Network, can_restart_us) CAN.RestartSec, config_parse_sec, 0, offsetof(Network, can_restart_us)
CAN.TripleSampling, config_parse_tristate, 0, offsetof(Network, can_triple_sampling) CAN.TripleSampling, config_parse_tristate, 0, offsetof(Network, can_triple_sampling)
CAN.Termination, config_parse_tristate, 0, offsetof(Network, can_termination)
QDisc.Parent, config_parse_qdisc_parent, _QDISC_KIND_INVALID, 0 QDisc.Parent, config_parse_qdisc_parent, _QDISC_KIND_INVALID, 0
QDisc.Handle, config_parse_qdisc_handle, _QDISC_KIND_INVALID, 0 QDisc.Handle, config_parse_qdisc_handle, _QDISC_KIND_INVALID, 0
CAKE.Parent, config_parse_qdisc_parent, QDISC_KIND_CAKE, 0 CAKE.Parent, config_parse_qdisc_parent, QDISC_KIND_CAKE, 0

View File

@ -457,6 +457,7 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
.keep_configuration = _KEEP_CONFIGURATION_INVALID, .keep_configuration = _KEEP_CONFIGURATION_INVALID,
.can_triple_sampling = -1, .can_triple_sampling = -1,
.can_termination = -1,
.ip_service_type = -1, .ip_service_type = -1,
}; };

View File

@ -199,6 +199,7 @@ struct Network {
unsigned can_sample_point; unsigned can_sample_point;
usec_t can_restart_us; usec_t can_restart_us;
int can_triple_sampling; int can_triple_sampling;
int can_termination;
AddressFamily ip_forward; AddressFamily ip_forward;
bool ip_masquerade; bool ip_masquerade;

View File

@ -200,6 +200,7 @@ SamplePoint=
BitRate= BitRate=
RestartSec= RestartSec=
TripleSampling= TripleSampling=
Termination=
[Address] [Address]
DuplicateAddressDetection= DuplicateAddressDetection=
AutoJoin= AutoJoin=