Skip to content

Commit

Permalink
Hyper-V: hn: add switch to turn on and off RSC
Browse files Browse the repository at this point in the history
Currently RSC offloading is enabled by default.
With this new change rsc will be disabled by default.
By using sysctl we can enable and disable it.

Reviewed by:	whu
Signed-off-by:	Souradeep Chakrabarti <schakrabarti@microsoft.com>
Fixes:		a491581 Enable vSwitch RSC support in hn netvsc driver
MFC after:	1 week
Sponsored by:	Microsoft
Differential Revision:	https://reviews.freebsd.org/D34507
  • Loading branch information
Wei Hu authored and Wei Hu committed Mar 15, 2022
1 parent 734782a commit 80c3eb7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
9 changes: 8 additions & 1 deletion sys/dev/hyperv/netvsc/hn_rndis.c
Expand Up @@ -579,6 +579,12 @@ hn_rndis_set(struct hn_softc *sc, uint32_t oid, const void *data, size_t dlen)
return (error);
}

int
hn_rndis_reconf_offload(struct hn_softc *sc, int mtu)
{
return(hn_rndis_conf_offload(sc, mtu));
}

static int
hn_rndis_conf_offload(struct hn_softc *sc, int mtu)
{
Expand Down Expand Up @@ -725,7 +731,8 @@ hn_rndis_conf_offload(struct hn_softc *sc, int mtu)

/* RSC offload */
if (hwcaps.ndis_hdr.ndis_rev >= NDIS_OFFLOAD_PARAMS_REV_3) {
if (hwcaps.ndis_rsc.ndis_ip4 && hwcaps.ndis_rsc.ndis_ip6) {
if (hwcaps.ndis_rsc.ndis_ip4 && hwcaps.ndis_rsc.ndis_ip6 &&
sc->hn_rsc_ctrl) {
params.ndis_rsc_ip4 = NDIS_OFFLOAD_RSC_ON;
params.ndis_rsc_ip6 = NDIS_OFFLOAD_RSC_ON;
} else {
Expand Down
1 change: 1 addition & 0 deletions sys/dev/hyperv/netvsc/hn_rndis.h
Expand Up @@ -46,5 +46,6 @@ int hn_rndis_get_mtu(struct hn_softc *sc, uint32_t *mtu);
int hn_rndis_set_rxfilter(struct hn_softc *sc, uint32_t filter);
void hn_rndis_rx_ctrl(struct hn_softc *sc, const void *data,
int dlen);
int hn_rndis_reconf_offload(struct hn_softc *sc, int mtu);

#endif /* !_HN_RNDIS_H_ */
30 changes: 30 additions & 0 deletions sys/dev/hyperv/netvsc/if_hn.c
Expand Up @@ -454,6 +454,8 @@ static void hn_start_txeof(struct hn_tx_ring *);
static void hn_start_txeof_taskfunc(void *, int);
#endif

static int hn_rsc_sysctl(SYSCTL_HANDLER_ARGS);

SYSCTL_NODE(_hw, OID_AUTO, hn, CTLFLAG_RD | CTLFLAG_MPSAFE, NULL,
"Hyper-V network interface");

Expand Down Expand Up @@ -2370,6 +2372,10 @@ hn_attach(device_t dev)
"Accurate BPF for transparent VF");
}

SYSCTL_ADD_PROC(ctx, child, OID_AUTO, "rsc_switch",
CTLTYPE_UINT | CTLFLAG_RW, sc, 0, hn_rsc_sysctl, "A",
"switch to rsc");

/*
* Setup the ifmedia, which has been initialized earlier.
*/
Expand Down Expand Up @@ -4567,6 +4573,30 @@ hn_rxfilter_sysctl(SYSCTL_HANDLER_ARGS)
return sysctl_handle_string(oidp, filter_str, sizeof(filter_str), req);
}

static int
hn_rsc_sysctl(SYSCTL_HANDLER_ARGS)
{
struct hn_softc *sc = arg1;
uint32_t mtu;
int error;
HN_LOCK(sc);
error = hn_rndis_get_mtu(sc, &mtu);
if (error) {
if_printf(sc->hn_ifp, "failed to get mtu\n");
goto back;
}
error = SYSCTL_OUT(req, &(sc->hn_rsc_ctrl), sizeof(sc->hn_rsc_ctrl));
if (error || req->newptr == NULL)
goto back;

error = SYSCTL_IN(req, &(sc->hn_rsc_ctrl), sizeof(sc->hn_rsc_ctrl));
if (error)
goto back;
error = hn_rndis_reconf_offload(sc, mtu);
back:
HN_UNLOCK(sc);
return (error);
}
#ifndef RSS

static int
Expand Down
5 changes: 5 additions & 0 deletions sys/dev/hyperv/netvsc/if_hnvar.h
Expand Up @@ -282,6 +282,11 @@ struct hn_softc {
u_int hn_saved_tsomax;
u_int hn_saved_tsosegcnt;
u_int hn_saved_tsosegsz;

/*
* RSC switch, default off
*/
u_int hn_rsc_ctrl;
};

#define HN_FLAG_RXBUF_CONNECTED 0x0001
Expand Down

0 comments on commit 80c3eb7

Please sign in to comment.