netifd: fix auto-negotiate for out-of-tree ethernet drivers

Signed-off-by: Tianling Shen <cnsztl@immortalwrt.org>
This commit is contained in:
Tianling Shen 2023-02-24 14:44:37 +08:00
parent e252dd0177
commit 891bf5b61d
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
2 changed files with 149 additions and 1 deletions

View File

@ -1,7 +1,7 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=netifd PKG_NAME:=netifd
PKG_RELEASE:=1 PKG_RELEASE:=2
PKG_SOURCE_PROTO:=git PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL=$(PROJECT_GIT)/project/netifd.git PKG_SOURCE_URL=$(PROJECT_GIT)/project/netifd.git

View File

@ -0,0 +1,148 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
Date: Fri, 24 Feb 2023 13:28:52 +0800
Subject: [PATCH] Revert "device: add support for configuring device link
speed/duplex"
Fixes auto-negotiate for out-of-tree ethernet drivers.
This reverts commit 1eb0fafaa9865b729509a7d47ecf1f05c2c0595c.
---
device.c | 14 --------------
device.h | 6 ------
system-linux.c | 52 --------------------------------------------------
3 files changed, 72 deletions(-)
--- a/device.c
+++ b/device.c
@@ -61,8 +61,6 @@ static const struct blobmsg_policy dev_a
[DEV_ATTR_DROP_UNSOLICITED_NA] = { .name = "drop_unsolicited_na", .type = BLOBMSG_TYPE_BOOL },
[DEV_ATTR_ARP_ACCEPT] = { .name = "arp_accept", .type = BLOBMSG_TYPE_BOOL },
[DEV_ATTR_AUTH] = { .name = "auth", .type = BLOBMSG_TYPE_BOOL },
- [DEV_ATTR_SPEED] = { .name = "speed", .type = BLOBMSG_TYPE_INT32 },
- [DEV_ATTR_DUPLEX] = { .name = "duplex", .type = BLOBMSG_TYPE_BOOL },
};
const struct uci_blob_param_list device_attr_list = {
@@ -278,8 +276,6 @@ device_merge_settings(struct device *dev
n->arp_accept = s->flags & DEV_OPT_ARP_ACCEPT ?
s->arp_accept : os->arp_accept;
n->auth = s->flags & DEV_OPT_AUTH ? s->auth : os->auth;
- n->speed = s->flags & DEV_OPT_SPEED ? s->speed : os->speed;
- n->duplex = s->flags & DEV_OPT_DUPLEX ? s->duplex : os->duplex;
n->flags = s->flags | os->flags | os->valid_flags;
}
@@ -454,16 +450,6 @@ device_init_settings(struct device *dev,
s->flags |= DEV_OPT_AUTH;
}
- if ((cur = tb[DEV_ATTR_SPEED])) {
- s->speed = blobmsg_get_u32(cur);
- s->flags |= DEV_OPT_SPEED;
- }
-
- if ((cur = tb[DEV_ATTR_DUPLEX])) {
- s->duplex = blobmsg_get_bool(cur);
- s->flags |= DEV_OPT_DUPLEX;
- }
-
device_set_disabled(dev, disabled);
}
--- a/device.h
+++ b/device.h
@@ -60,8 +60,6 @@ enum {
DEV_ATTR_DROP_UNSOLICITED_NA,
DEV_ATTR_ARP_ACCEPT,
DEV_ATTR_AUTH,
- DEV_ATTR_SPEED,
- DEV_ATTR_DUPLEX,
__DEV_ATTR_MAX,
};
@@ -124,8 +122,6 @@ enum {
DEV_OPT_DROP_GRATUITOUS_ARP = (1ULL << 27),
DEV_OPT_DROP_UNSOLICITED_NA = (1ULL << 28),
DEV_OPT_ARP_ACCEPT = (1ULL << 29),
- DEV_OPT_SPEED = (1ULL << 30),
- DEV_OPT_DUPLEX = (1ULL << 31),
};
/* events broadcasted to all users of a device */
@@ -201,8 +197,6 @@ struct device_settings {
bool drop_unsolicited_na;
bool arp_accept;
bool auth;
- unsigned int speed;
- bool duplex;
};
/*
--- a/system-linux.c
+++ b/system-linux.c
@@ -1715,57 +1715,6 @@ int system_vlandev_del(struct device *vl
return system_link_del(vlandev->ifname);
}
-static void
-system_set_ethtool_settings(struct device *dev, struct device_settings *s)
-{
- struct ethtool_cmd ecmd = {
- .cmd = ETHTOOL_GSET,
- };
- struct ifreq ifr = {
- .ifr_data = (caddr_t)&ecmd,
- };
- static const struct {
- int speed;
- uint8_t bit_half;
- uint8_t bit_full;
- } speed_mask[] = {
- { 10, ETHTOOL_LINK_MODE_10baseT_Half_BIT, ETHTOOL_LINK_MODE_10baseT_Full_BIT },
- { 100, ETHTOOL_LINK_MODE_100baseT_Half_BIT, ETHTOOL_LINK_MODE_100baseT_Full_BIT },
- { 1000, ETHTOOL_LINK_MODE_1000baseT_Half_BIT, ETHTOOL_LINK_MODE_1000baseT_Full_BIT },
- };
- uint32_t adv;
- int i;
-
- strncpy(ifr.ifr_name, dev->ifname, sizeof(ifr.ifr_name) - 1);
-
- if (ioctl(sock_ioctl, SIOCETHTOOL, &ifr) != 0)
- return;
-
- adv = ecmd.supported;
- for (i = 0; i < ARRAY_SIZE(speed_mask); i++) {
- if (s->flags & DEV_OPT_DUPLEX) {
- int bit = s->duplex ? speed_mask[i].bit_half : speed_mask[i].bit_full;
- adv &= ~(1 << bit);
- }
-
- if (!(s->flags & DEV_OPT_SPEED) ||
- s->speed == speed_mask[i].speed)
- continue;
-
- adv &= ~(1 << speed_mask[i].bit_full);
- adv &= ~(1 << speed_mask[i].bit_half);
- }
-
-
- if (ecmd.autoneg && ecmd.advertising == adv)
- return;
-
- ecmd.autoneg = 1;
- ecmd.advertising = adv;
- ecmd.cmd = ETHTOOL_SSET;
- ioctl(sock_ioctl, SIOCETHTOOL, &ifr);
-}
-
void
system_if_get_settings(struct device *dev, struct device_settings *s)
{
@@ -1989,7 +1938,6 @@ system_if_apply_settings(struct device *
system_set_drop_unsolicited_na(dev, s->drop_unsolicited_na ? "1" : "0");
if (apply_mask & DEV_OPT_ARP_ACCEPT)
system_set_arp_accept(dev, s->arp_accept ? "1" : "0");
- system_set_ethtool_settings(dev, s);
}
int system_if_up(struct device *dev)