git: f35cec70639f - releng/14.0 - mana: add ioctl to support toggling offloading features
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Mon, 18 Sep 2023 14:59:55 UTC
The branch releng/14.0 has been updated by whu:
URL: https://cgit.FreeBSD.org/src/commit/?id=f35cec70639f3c937807feb6dc4081ae7d605265
commit f35cec70639f3c937807feb6dc4081ae7d605265
Author: Wei Hu <whu@FreeBSD.org>
AuthorDate: 2023-09-13 10:48:02 +0000
Commit: Wei Hu <whu@FreeBSD.org>
CommitDate: 2023-09-18 14:56:48 +0000
mana: add ioctl to support toggling offloading features
With this support, users can enable or disable offloading features
such as txcsum, rxcsum, tso and software lro through ifconfig.
To enable or disable tx features, do it on mana interface first,
then hn/netvsc to sync it up with mana. For example:
ifconfig mana0 -txcsum
ifconfig hn0 -tscsum
To enable or disable rx features, just applying on mana interface
would be sufficient.
Disabling txcsum imples disabling tso. Enabling tso when txcsum
is disabled will result in an error message in dmesg requesting
to enable txcsum first.
Above applies to ipv6 offloading features as well.
Approved by: re (gjb)
Tested by: whu
Sponsored by: Microsoft
(cherry picked from commit ab7dc1ceb6d36fd804bedb818086ae3ff6692bf7)
(cherry picked from commit 4edfbe719bf6a15dee388e65b39a116e9307be7f)
---
sys/dev/mana/mana_en.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 76 insertions(+), 1 deletion(-)
diff --git a/sys/dev/mana/mana_en.c b/sys/dev/mana/mana_en.c
index 56fa4e51ba26..064b28fa94a4 100644
--- a/sys/dev/mana/mana_en.c
+++ b/sys/dev/mana/mana_en.c
@@ -169,7 +169,7 @@ mana_ioctl(if_t ifp, u_long command, caddr_t data)
struct ifrsshash *ifrh;
struct ifreq *ifr;
uint16_t new_mtu;
- int rc = 0;
+ int rc = 0, mask;
switch (command) {
case SIOCSIFMTU:
@@ -214,6 +214,81 @@ mana_ioctl(if_t ifp, u_long command, caddr_t data)
}
break;
+ case SIOCSIFCAP:
+ MANA_APC_LOCK_LOCK(apc);
+ ifr = (struct ifreq *)data;
+ /*
+ * Fix up requested capabilities w/ supported capabilities,
+ * since the supported capabilities could have been changed.
+ */
+ mask = (ifr->ifr_reqcap & if_getcapabilities(ifp)) ^
+ if_getcapenable(ifp);
+
+ if (mask & IFCAP_TXCSUM) {
+ if_togglecapenable(ifp, IFCAP_TXCSUM);
+ if_togglehwassist(ifp, (CSUM_TCP | CSUM_UDP | CSUM_IP));
+
+ if ((IFCAP_TSO4 & if_getcapenable(ifp)) &&
+ !(IFCAP_TXCSUM & if_getcapenable(ifp))) {
+ mask &= ~IFCAP_TSO4;
+ if_setcapenablebit(ifp, 0, IFCAP_TSO4);
+ if_sethwassistbits(ifp, 0, CSUM_IP_TSO);
+ mana_warn(NULL,
+ "Also disabled tso4 due to -txcsum.\n");
+ }
+ }
+
+ if (mask & IFCAP_TXCSUM_IPV6) {
+ if_togglecapenable(ifp, IFCAP_TXCSUM_IPV6);
+ if_togglehwassist(ifp, (CSUM_UDP_IPV6 | CSUM_TCP_IPV6));
+
+ if ((IFCAP_TSO6 & if_getcapenable(ifp)) &&
+ !(IFCAP_TXCSUM_IPV6 & if_getcapenable(ifp))) {
+ mask &= ~IFCAP_TSO6;
+ if_setcapenablebit(ifp, 0, IFCAP_TSO6);
+ if_sethwassistbits(ifp, 0, CSUM_IP6_TSO);
+ mana_warn(ifp,
+ "Also disabled tso6 due to -txcsum6.\n");
+ }
+ }
+
+ if (mask & IFCAP_RXCSUM)
+ if_togglecapenable(ifp, IFCAP_RXCSUM);
+ /* We can't diff IPv6 packets from IPv4 packets on RX path. */
+ if (mask & IFCAP_RXCSUM_IPV6)
+ if_togglecapenable(ifp, IFCAP_RXCSUM_IPV6);
+
+ if (mask & IFCAP_LRO)
+ if_togglecapenable(ifp, IFCAP_LRO);
+
+ if (mask & IFCAP_TSO4) {
+ if (!(IFCAP_TSO4 & if_getcapenable(ifp)) &&
+ !(IFCAP_TXCSUM & if_getcapenable(ifp))) {
+ MANA_APC_LOCK_UNLOCK(apc);
+ if_printf(ifp, "Enable txcsum first.\n");
+ rc = EAGAIN;
+ goto out;
+ }
+ if_togglecapenable(ifp, IFCAP_TSO4);
+ if_togglehwassist(ifp, CSUM_IP_TSO);
+ }
+
+ if (mask & IFCAP_TSO6) {
+ if (!(IFCAP_TSO6 & if_getcapenable(ifp)) &&
+ !(IFCAP_TXCSUM_IPV6 & if_getcapenable(ifp))) {
+ MANA_APC_LOCK_UNLOCK(apc);
+ if_printf(ifp, "Enable txcsum6 first.\n");
+ rc = EAGAIN;
+ goto out;
+ }
+ if_togglecapenable(ifp, IFCAP_TSO6);
+ if_togglehwassist(ifp, CSUM_IP6_TSO);
+ }
+
+ MANA_APC_LOCK_UNLOCK(apc);
+out:
+ break;
+
case SIOCSIFMEDIA:
case SIOCGIFMEDIA:
case SIOCGIFXMEDIA: