aboutsummaryrefslogtreecommitdiff
path: root/net
diff options
context:
space:
mode:
authorPeter Maydell <peter.maydell@linaro.org>2020-10-01 12:23:19 +0100
committerPeter Maydell <peter.maydell@linaro.org>2020-10-01 12:23:19 +0100
commit37a712a0f969ca2df7f01182409a6c4825cebfb5 (patch)
tree6eeb0b7f0bde4c8a0f8e1115b990530c5c62e9fe /net
parentcbba3dc6ea3fc9aa66e9f9eb41051536e3ad7cd0 (diff)
parent37aeb7a28ddbf52dd25dd53ae1b8391bc2287858 (diff)
downloadqemu-37a712a0f969ca2df7f01182409a6c4825cebfb5.zip
qemu-37a712a0f969ca2df7f01182409a6c4825cebfb5.tar.gz
qemu-37a712a0f969ca2df7f01182409a6c4825cebfb5.tar.bz2
Merge remote-tracking branch 'remotes/bonzini-gitlab/tags/for-upstream' into staging
* SCSI fix (Dmitry, Li Feng, Li Qiang) * memory API fixes (Eduardo) * removal of deprecated '-numa node', 'cpu-add', '-smp' (Igor) * ACPI fix for VMBus (Jon) * relocatable install (myself) * always remove docker containers (myself) * serial cleanups (Philippe) * vmware cpuid leaf for tsc and apic frequency (Sunil) * KVM_FEATURE_ASYNC_PF_INT support (Vitaly) * i386 XSAVE bugfix (Xiaoyao) * QOM developer documentation in docs/devel (Eduardo) * new checkpatch tests (Dov) * x86_64 syscall fix (Douglas) * interrupt-based APF fix (Vitaly) * always create kvmclock (Vitaly) * fix bios-tables-test (Eduardo) * KVM PV features cleanup (myself) * CAN FD (Pavel) meson: * fixes (Marc-André, Max, Stefan, Alexander, myself) * moved libmpathpersist, cocoa, malloc tests (myself) * support for 0.56 introspected test dependencies (myself) # gpg: Signature made Wed 30 Sep 2020 18:11:45 BST # gpg: using RSA key F13338574B662389866C7682BFFBD25F78C7AE83 # gpg: issuer "pbonzini@redhat.com" # gpg: Good signature from "Paolo Bonzini <bonzini@gnu.org>" [full] # gpg: aka "Paolo Bonzini <pbonzini@redhat.com>" [full] # Primary key fingerprint: 46F5 9FBD 57D6 12E7 BFD4 E2F7 7E15 100C CD36 69B1 # Subkey fingerprint: F133 3857 4B66 2389 866C 7682 BFFB D25F 78C7 AE83 * remotes/bonzini-gitlab/tags/for-upstream: (86 commits) hw/net/can: Correct Kconfig dependencies hw/net/can: Documentation for CTU CAN FD IP open hardware core emulation. hw/net/can: CTU CAN FD IP open hardware core emulation. hw/net/can/ctucafd: Add CTU CAN FD core register definitions. net/can: Add can_dlc2len and can_len2dlc for CAN FD. hw/net/can: sja1000 ignore CAN FD frames net/can: Initial host SocketCan support for CAN FD. target/i386: kvm: do not use kvm_check_extension to find paravirtual capabilities bios-tables-test: Remove kernel-irqchip=off option target/i386: always create kvmclock device target/i386: Fix VM migration when interrupt based APF is enabled helper_syscall x86_64: clear exception_is_int checkpatch: Detect '%#' or '%0#' in printf-style format strings typedefs: Restrict PCMachineState to 'hw/i386/pc.h' hw/xen: Split x86-specific declaration from generic hardware ones stubs: Split accelerator / hardware related stubs sysemu/xen: Add missing 'exec/cpu-common.h' header for ram_addr_t type hw/i386/xen: Rename X86/PC specific function as xen_hvm_init_pc() docs: Move object.h overview doc comment to qom.rst docs: Create docs/devel/qom.rst ... Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'net')
-rw-r--r--net/can/can_core.c36
-rw-r--r--net/can/can_socketcan.c47
-rw-r--r--net/tap.c26
3 files changed, 99 insertions, 10 deletions
diff --git a/net/can/can_core.c b/net/can/can_core.c
index 90f4d85..0115d78 100644
--- a/net/can/can_core.c
+++ b/net/can/can_core.c
@@ -33,6 +33,42 @@
#include "net/can_emu.h"
#include "qom/object_interfaces.h"
+/* CAN DLC to real data length conversion helpers */
+
+static const uint8_t dlc2len[] = {
+ 0, 1, 2, 3, 4, 5, 6, 7,
+ 8, 12, 16, 20, 24, 32, 48, 64
+};
+
+/* get data length from can_dlc with sanitized can_dlc */
+uint8_t can_dlc2len(uint8_t can_dlc)
+{
+ return dlc2len[can_dlc & 0x0F];
+}
+
+static const uint8_t len2dlc[] = {
+ 0, 1, 2, 3, 4, 5, 6, 7, 8, /* 0 - 8 */
+ 9, 9, 9, 9, /* 9 - 12 */
+ 10, 10, 10, 10, /* 13 - 16 */
+ 11, 11, 11, 11, /* 17 - 20 */
+ 12, 12, 12, 12, /* 21 - 24 */
+ 13, 13, 13, 13, 13, 13, 13, 13, /* 25 - 32 */
+ 14, 14, 14, 14, 14, 14, 14, 14, /* 33 - 40 */
+ 14, 14, 14, 14, 14, 14, 14, 14, /* 41 - 48 */
+ 15, 15, 15, 15, 15, 15, 15, 15, /* 49 - 56 */
+ 15, 15, 15, 15, 15, 15, 15, 15 /* 57 - 64 */
+};
+
+/* map the sanitized data length to an appropriate data length code */
+uint8_t can_len2dlc(uint8_t len)
+{
+ if (unlikely(len > 64)) {
+ return 0xF;
+ }
+
+ return len2dlc[len];
+}
+
struct CanBusState {
Object object;
diff --git a/net/can/can_socketcan.c b/net/can/can_socketcan.c
index ce8c254..92b1f79 100644
--- a/net/can/can_socketcan.c
+++ b/net/can/can_socketcan.c
@@ -103,6 +103,14 @@ static void can_host_socketcan_read(void *opaque)
return;
}
+ if (!ch->bus_client.fd_mode) {
+ c->buf[0].flags = 0;
+ } else {
+ if (c->bufcnt > CAN_MTU) {
+ c->buf[0].flags |= QEMU_CAN_FRMF_TYPE_FD;
+ }
+ }
+
can_bus_client_send(&ch->bus_client, c->buf, 1);
if (DEBUG_CAN) {
@@ -121,12 +129,21 @@ static ssize_t can_host_socketcan_receive(CanBusClientState *client,
CanHostState *ch = container_of(client, CanHostState, bus_client);
CanHostSocketCAN *c = CAN_HOST_SOCKETCAN(ch);
- size_t len = sizeof(qemu_can_frame);
+ size_t len;
int res;
if (c->fd < 0) {
return -1;
}
+ if (frames->flags & QEMU_CAN_FRMF_TYPE_FD) {
+ if (!ch->bus_client.fd_mode) {
+ return 0;
+ }
+ len = CANFD_MTU;
+ } else {
+ len = CAN_MTU;
+
+ }
res = write(c->fd, frames, len);
@@ -172,6 +189,8 @@ static void can_host_socketcan_connect(CanHostState *ch, Error **errp)
{
CanHostSocketCAN *c = CAN_HOST_SOCKETCAN(ch);
int s; /* can raw socket */
+ int mtu;
+ int enable_canfd = 1;
struct sockaddr_can addr;
struct ifreq ifr;
@@ -185,13 +204,34 @@ static void can_host_socketcan_connect(CanHostState *ch, Error **errp)
addr.can_family = AF_CAN;
memset(&ifr.ifr_name, 0, sizeof(ifr.ifr_name));
strcpy(ifr.ifr_name, c->ifname);
+ /* check if the frame fits into the CAN netdevice */
if (ioctl(s, SIOCGIFINDEX, &ifr) < 0) {
error_setg_errno(errp, errno,
- "SocketCAN host interface %s not available", c->ifname);
+ "SocketCAN host interface %s not available",
+ c->ifname);
goto fail;
}
addr.can_ifindex = ifr.ifr_ifindex;
+ if (ioctl(s, SIOCGIFMTU, &ifr) < 0) {
+ error_setg_errno(errp, errno,
+ "SocketCAN host interface %s SIOCGIFMTU failed",
+ c->ifname);
+ goto fail;
+ }
+ mtu = ifr.ifr_mtu;
+
+ if (mtu >= CANFD_MTU) {
+ /* interface is ok - try to switch the socket into CAN FD mode */
+ if (setsockopt(s, SOL_CAN_RAW, CAN_RAW_FD_FRAMES,
+ &enable_canfd, sizeof(enable_canfd))) {
+ warn_report("SocketCAN host interface %s enabling CAN FD failed",
+ c->ifname);
+ } else {
+ c->parent.bus_client.fd_mode = true;
+ }
+ }
+
c->err_mask = 0xffffffff; /* Receive error frame. */
setsockopt(s, SOL_CAN_RAW, CAN_RAW_ERR_FILTER,
&c->err_mask, sizeof(c->err_mask));
@@ -232,7 +272,8 @@ static char *can_host_socketcan_get_if(Object *obj, Error **errp)
return g_strdup(c->ifname);
}
-static void can_host_socketcan_set_if(Object *obj, const char *value, Error **errp)
+static void can_host_socketcan_set_if(Object *obj, const char *value,
+ Error **errp)
{
CanHostSocketCAN *c = CAN_HOST_SOCKETCAN(obj);
struct ifreq ifr;
diff --git a/net/tap.c b/net/tap.c
index 14dc904..04ce72d 100644
--- a/net/tap.c
+++ b/net/tap.c
@@ -478,6 +478,7 @@ static int net_bridge_run_helper(const char *helper, const char *bridge,
Error **errp)
{
sigset_t oldmask, mask;
+ g_autofree char *default_helper = NULL;
int pid, status;
char *args[5];
char **parg;
@@ -487,6 +488,10 @@ static int net_bridge_run_helper(const char *helper, const char *bridge,
sigaddset(&mask, SIGCHLD);
sigprocmask(SIG_BLOCK, &mask, &oldmask);
+ if (!helper) {
+ helper = default_helper = get_relocated_path(DEFAULT_BRIDGE_HELPER);
+ }
+
if (socketpair(PF_UNIX, SOCK_STREAM, 0, sv) == -1) {
error_setg_errno(errp, errno, "socketpair() failed");
return -1;
@@ -588,8 +593,7 @@ int net_init_bridge(const Netdev *netdev, const char *name,
assert(netdev->type == NET_CLIENT_DRIVER_BRIDGE);
bridge = &netdev->u.bridge;
-
- helper = bridge->has_helper ? bridge->helper : DEFAULT_BRIDGE_HELPER;
+ helper = bridge->has_helper ? bridge->helper : NULL;
br = bridge->has_br ? bridge->br : DEFAULT_BRIDGE_INTERFACE;
fd = net_bridge_run_helper(helper, br, errp);
@@ -773,8 +777,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
const NetdevTapOptions *tap;
int fd, vnet_hdr = 0, i = 0, queues;
/* for the no-fd, no-helper case */
- const char *script = NULL; /* suppress wrong "uninit'd use" gcc warning */
- const char *downscript = NULL;
+ const char *script;
+ const char *downscript;
Error *err = NULL;
const char *vhostfdname;
char ifname[128];
@@ -784,6 +788,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
tap = &netdev->u.tap;
queues = tap->has_queues ? tap->queues : 1;
vhostfdname = tap->has_vhostfd ? tap->vhostfd : NULL;
+ script = tap->has_script ? tap->script : NULL;
+ downscript = tap->has_downscript ? tap->downscript : NULL;
/* QEMU hubs do not support multiqueue tap, in this case peer is set.
* For -netdev, peer is always NULL. */
@@ -934,13 +940,19 @@ free_fail:
return -1;
}
} else {
+ g_autofree char *default_script = NULL;
+ g_autofree char *default_downscript = NULL;
if (tap->has_vhostfds) {
error_setg(errp, "vhostfds= is invalid if fds= wasn't specified");
return -1;
}
- script = tap->has_script ? tap->script : DEFAULT_NETWORK_SCRIPT;
- downscript = tap->has_downscript ? tap->downscript :
- DEFAULT_NETWORK_DOWN_SCRIPT;
+
+ if (!script) {
+ script = default_script = get_relocated_path(DEFAULT_NETWORK_SCRIPT);
+ }
+ if (!downscript) {
+ downscript = default_downscript = get_relocated_path(DEFAULT_NETWORK_SCRIPT);
+ }
if (tap->has_ifname) {
pstrcpy(ifname, sizeof ifname, tap->ifname);