hyperv/hn: Move send context to NVS domain.

Since all sends are encapsulated in NVS messages.

MFC after:	1 week
Sponsored by:	Microsoft
Differential Revision:	https://reviews.freebsd.org/D8346
This commit is contained in:
Sepherosa Ziehau 2016-10-27 05:26:04 +00:00
parent 19b2340a76
commit e3946ae44a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=307990
5 changed files with 119 additions and 136 deletions

View File

@ -39,18 +39,24 @@
#include <sys/socket.h>
#include <sys/limits.h>
#include <sys/lock.h>
#include <sys/taskqueue.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/if_arp.h>
#include <machine/bus.h>
#include <machine/atomic.h>
#include <net/if_media.h>
#include <netinet/in.h>
#include <netinet/tcp_lro.h>
#include <dev/hyperv/include/hyperv.h>
#include <dev/hyperv/include/hyperv_busdma.h>
#include <dev/hyperv/include/vmbus.h>
#include <dev/hyperv/include/vmbus_xact.h>
#include <dev/hyperv/netvsc/hv_net_vsc.h>
#include <dev/hyperv/netvsc/hv_rndis_filter.h>
#include <dev/hyperv/netvsc/ndis.h>
#include <dev/hyperv/netvsc/if_hnreg.h>
#include <dev/hyperv/netvsc/if_hnvar.h>
#include <dev/hyperv/netvsc/hv_net_vsc.h>
/*
* Forward declarations
@ -59,12 +65,12 @@ static int hn_nvs_conn_chim(struct hn_softc *sc);
static int hn_nvs_conn_rxbuf(struct hn_softc *);
static int hn_nvs_disconn_chim(struct hn_softc *sc);
static int hn_nvs_disconn_rxbuf(struct hn_softc *sc);
static void hn_nvs_sent_none(struct hn_send_ctx *sndc,
static void hn_nvs_sent_none(struct hn_nvs_sendctx *sndc,
struct hn_softc *, struct vmbus_channel *chan,
const void *, int);
struct hn_send_ctx hn_send_ctx_none =
HN_SEND_CTX_INITIALIZER(hn_nvs_sent_none, NULL);
struct hn_nvs_sendctx hn_nvs_sendctx_none =
HN_NVS_SENDCTX_INITIALIZER(hn_nvs_sent_none, NULL);
static const uint32_t hn_nvs_version[] = {
HN_NVS_VERSION_5,
@ -77,7 +83,7 @@ static const void *
hn_nvs_xact_execute(struct hn_softc *sc, struct vmbus_xact *xact,
void *req, int reqlen, size_t *resplen0, uint32_t type)
{
struct hn_send_ctx sndc;
struct hn_nvs_sendctx sndc;
size_t resplen, min_resplen = *resplen0;
const struct hn_nvs_hdr *hdr;
int error;
@ -88,7 +94,7 @@ hn_nvs_xact_execute(struct hn_softc *sc, struct vmbus_xact *xact,
/*
* Execute the xact setup by the caller.
*/
hn_send_ctx_init(&sndc, hn_nvs_sent_xact, xact);
hn_nvs_sendctx_init(&sndc, hn_nvs_sent_xact, xact);
vmbus_xact_activate(xact);
error = hn_nvs_send(sc->hn_prichan, VMBUS_CHANPKT_FLAG_RC,
@ -121,7 +127,7 @@ hn_nvs_req_send(struct hn_softc *sc, void *req, int reqlen)
{
return (hn_nvs_send(sc->hn_prichan, VMBUS_CHANPKT_FLAG_NONE,
req, reqlen, &hn_send_ctx_none));
req, reqlen, &hn_nvs_sendctx_none));
}
static int
@ -604,7 +610,7 @@ hn_nvs_detach(struct hn_softc *sc)
}
void
hn_nvs_sent_xact(struct hn_send_ctx *sndc,
hn_nvs_sent_xact(struct hn_nvs_sendctx *sndc,
struct hn_softc *sc __unused, struct vmbus_channel *chan __unused,
const void *data, int dlen)
{
@ -613,7 +619,7 @@ hn_nvs_sent_xact(struct hn_send_ctx *sndc,
}
static void
hn_nvs_sent_none(struct hn_send_ctx *sndc __unused,
hn_nvs_sent_none(struct hn_nvs_sendctx *sndc __unused,
struct hn_softc *sc __unused, struct vmbus_channel *chan __unused,
const void *data __unused, int dlen __unused)
{
@ -670,3 +676,12 @@ hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch0)
vmbus_xact_put(xact);
return (error);
}
int
hn_nvs_send_rndis_ctrl(struct vmbus_channel *chan,
struct hn_nvs_sendctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt)
{
return hn_nvs_send_rndis_sglist(chan, HN_NVS_RNDIS_MTYPE_CTRL,
sndc, gpa, gpa_cnt);
}

View File

@ -31,31 +31,76 @@
#ifndef __HV_NET_VSC_H__
#define __HV_NET_VSC_H__
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/queue.h>
#include <sys/taskqueue.h>
#include <sys/sema.h>
#include <sys/sx.h>
struct hn_nvs_sendctx;
struct vmbus_channel;
struct hn_softc;
#include <machine/bus.h>
#include <sys/bus.h>
#include <sys/bus_dma.h>
typedef void (*hn_nvs_sent_t)
(struct hn_nvs_sendctx *, struct hn_softc *,
struct vmbus_channel *, const void *, int);
#include <netinet/in.h>
#include <netinet/tcp_lro.h>
struct hn_nvs_sendctx {
hn_nvs_sent_t hn_cb;
void *hn_cbarg;
};
#include <net/ethernet.h>
#include <net/if.h>
#include <net/if_media.h>
#define HN_NVS_SENDCTX_INITIALIZER(cb, cbarg) \
{ \
.hn_cb = cb, \
.hn_cbarg = cbarg \
}
#include <dev/hyperv/include/hyperv.h>
#include <dev/hyperv/include/hyperv_busdma.h>
#include <dev/hyperv/include/vmbus.h>
static __inline void
hn_nvs_sendctx_init(struct hn_nvs_sendctx *sndc, hn_nvs_sent_t cb, void *cbarg)
{
#include <dev/hyperv/netvsc/ndis.h>
sndc->hn_cb = cb;
sndc->hn_cbarg = cbarg;
}
static __inline int
hn_nvs_send(struct vmbus_channel *chan, uint16_t flags,
void *nvs_msg, int nvs_msglen, struct hn_nvs_sendctx *sndc)
{
return (vmbus_chan_send(chan, VMBUS_CHANPKT_TYPE_INBAND, flags,
nvs_msg, nvs_msglen, (uint64_t)(uintptr_t)sndc));
}
static __inline int
hn_nvs_send_sglist(struct vmbus_channel *chan, struct vmbus_gpa sg[], int sglen,
void *nvs_msg, int nvs_msglen, struct hn_nvs_sendctx *sndc)
{
return (vmbus_chan_send_sglist(chan, sg, sglen, nvs_msg, nvs_msglen,
(uint64_t)(uintptr_t)sndc));
}
static __inline int
hn_nvs_send_rndis_sglist(struct vmbus_channel *chan, uint32_t rndis_mtype,
struct hn_nvs_sendctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt)
{
struct hn_nvs_rndis rndis;
rndis.nvs_type = HN_NVS_TYPE_RNDIS;
rndis.nvs_rndis_mtype = rndis_mtype;
rndis.nvs_chim_idx = HN_NVS_CHIM_IDX_INVALID;
rndis.nvs_chim_sz = 0;
return (hn_nvs_send_sglist(chan, gpa, gpa_cnt,
&rndis, sizeof(rndis), sndc));
}
int hn_nvs_attach(struct hn_softc *sc, int mtu);
void hn_nvs_detach(struct hn_softc *sc);
int hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch);
void hn_nvs_sent_xact(struct hn_nvs_sendctx *sndc,
struct hn_softc *sc, struct vmbus_channel *chan,
const void *data, int dlen);
int hn_nvs_send_rndis_ctrl(struct vmbus_channel *chan,
struct hn_nvs_sendctx *sndc, struct vmbus_gpa *gpa,
int gpa_cnt);
extern struct hn_nvs_sendctx hn_nvs_sendctx_none;
#endif /* __HV_NET_VSC_H__ */

View File

@ -174,7 +174,7 @@ struct hn_txdesc {
struct hn_tx_ring *txr;
int refs;
uint32_t flags; /* HN_TXD_FLAG_ */
struct hn_send_ctx send_ctx;
struct hn_nvs_sendctx send_ctx;
uint32_t chim_index;
int chim_size;
@ -412,37 +412,13 @@ hn_set_lro_lenlim(struct hn_softc *sc, int lenlim)
}
#endif
static __inline int
hn_nvs_send_rndis_sglist1(struct vmbus_channel *chan, uint32_t rndis_mtype,
struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt)
{
struct hn_nvs_rndis rndis;
rndis.nvs_type = HN_NVS_TYPE_RNDIS;
rndis.nvs_rndis_mtype = rndis_mtype;
rndis.nvs_chim_idx = HN_NVS_CHIM_IDX_INVALID;
rndis.nvs_chim_sz = 0;
return (hn_nvs_send_sglist(chan, gpa, gpa_cnt,
&rndis, sizeof(rndis), sndc));
}
int
hn_nvs_send_rndis_ctrl(struct vmbus_channel *chan,
struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt)
{
return hn_nvs_send_rndis_sglist1(chan, HN_NVS_RNDIS_MTYPE_CTRL,
sndc, gpa, gpa_cnt);
}
static int
hn_sendpkt_rndis_sglist(struct hn_tx_ring *txr, struct hn_txdesc *txd)
{
KASSERT(txd->chim_index == HN_NVS_CHIM_IDX_INVALID &&
txd->chim_size == 0, ("invalid rndis sglist txd"));
return (hn_nvs_send_rndis_sglist1(txr->hn_chan, HN_NVS_RNDIS_MTYPE_DATA,
return (hn_nvs_send_rndis_sglist(txr->hn_chan, HN_NVS_RNDIS_MTYPE_DATA,
&txd->send_ctx, txr->hn_gpa, txr->hn_gpa_cnt));
}
@ -1190,7 +1166,7 @@ hn_txeof(struct hn_tx_ring *txr)
}
static void
hn_tx_done(struct hn_send_ctx *sndc, struct hn_softc *sc,
hn_tx_done(struct hn_nvs_sendctx *sndc, struct hn_softc *sc,
struct vmbus_channel *chan, const void *data __unused, int dlen __unused)
{
struct hn_txdesc *txd = sndc->hn_cbarg;
@ -1429,7 +1405,7 @@ hn_encap(struct hn_tx_ring *txr, struct hn_txdesc *txd, struct mbuf **m_head0)
txd->m = m_head;
/* Set the completion routine */
hn_send_ctx_init(&txd->send_ctx, hn_tx_done, txd);
hn_nvs_sendctx_init(&txd->send_ctx, hn_tx_done, txd);
return 0;
}
@ -4070,9 +4046,9 @@ static void
hn_nvs_handle_comp(struct hn_softc *sc, struct vmbus_channel *chan,
const struct vmbus_chanpkt_hdr *pkt)
{
struct hn_send_ctx *sndc;
struct hn_nvs_sendctx *sndc;
sndc = (struct hn_send_ctx *)(uintptr_t)pkt->cph_xactid;
sndc = (struct hn_nvs_sendctx *)(uintptr_t)pkt->cph_xactid;
sndc->hn_cb(sndc, sc, chan, VMBUS_CHANPKT_CONST_DATA(pkt),
VMBUS_CHANPKT_DATALEN(pkt));
/*

View File

@ -34,26 +34,30 @@ __FBSDID("$FreeBSD$");
#include <sys/socket.h>
#include <sys/lock.h>
#include <sys/mutex.h>
#include <net/if.h>
#include <net/if_arp.h>
#include <net/if_var.h>
#include <sys/taskqueue.h>
#include <machine/atomic.h>
#include <net/ethernet.h>
#include <net/if.h>
#include <net/if_var.h>
#include <net/if_media.h>
#include <net/rndis.h>
#include <netinet/in.h>
#include <netinet/ip.h>
#include <sys/types.h>
#include <machine/atomic.h>
#include <sys/sema.h>
#include <vm/vm.h>
#include <vm/vm_param.h>
#include <vm/pmap.h>
#include <netinet/tcp_lro.h>
#include <dev/hyperv/include/hyperv.h>
#include <dev/hyperv/include/hyperv_busdma.h>
#include <dev/hyperv/include/vmbus.h>
#include <dev/hyperv/include/vmbus_xact.h>
#include <dev/hyperv/netvsc/ndis.h>
#include <dev/hyperv/netvsc/if_hnreg.h>
#include <dev/hyperv/netvsc/if_hnvar.h>
#include <dev/hyperv/netvsc/hv_net_vsc.h>
#include <dev/hyperv/netvsc/hv_rndis_filter.h>
#include <dev/hyperv/netvsc/if_hnreg.h>
#include <dev/hyperv/netvsc/ndis.h>
#define HV_RF_RECVINFO_VLAN 0x1
#define HV_RF_RECVINFO_CSUM 0x2
@ -549,7 +553,7 @@ hn_rndis_get_linkstatus(struct hn_softc *sc, uint32_t *link_status)
static const void *
hn_rndis_xact_exec1(struct hn_softc *sc, struct vmbus_xact *xact, size_t reqlen,
struct hn_send_ctx *sndc, size_t *comp_len)
struct hn_nvs_sendctx *sndc, size_t *comp_len)
{
struct vmbus_gpa gpa[HN_XACT_REQ_PGCNT];
int gpa_cnt, error;
@ -608,7 +612,7 @@ hn_rndis_xact_execute(struct hn_softc *sc, struct vmbus_xact *xact, uint32_t rid
/*
* Execute the xact setup by the caller.
*/
comp = hn_rndis_xact_exec1(sc, xact, reqlen, &hn_send_ctx_none,
comp = hn_rndis_xact_exec1(sc, xact, reqlen, &hn_nvs_sendctx_none,
&comp_len);
if (comp == NULL)
return (NULL);
@ -1214,7 +1218,7 @@ hn_rndis_halt(struct hn_softc *sc)
{
struct vmbus_xact *xact;
struct rndis_halt_req *halt;
struct hn_send_ctx sndc;
struct hn_nvs_sendctx sndc;
size_t comp_len;
xact = vmbus_xact_get(sc->hn_xact, sizeof(*halt));
@ -1228,7 +1232,7 @@ hn_rndis_halt(struct hn_softc *sc)
halt->rm_rid = hn_rndis_rid(sc);
/* No RNDIS completion; rely on NVS message send completion */
hn_send_ctx_init(&sndc, hn_nvs_sent_xact, xact);
hn_nvs_sendctx_init(&sndc, hn_nvs_sent_xact, xact);
hn_rndis_xact_exec1(sc, xact, sizeof(*halt), &sndc, &comp_len);
vmbus_xact_put(xact);

View File

@ -51,25 +51,6 @@
#define HN_GPACNT_MAX 32
struct vmbus_channel;
struct hn_softc;
struct hn_send_ctx;
typedef void (*hn_sent_callback_t)
(struct hn_send_ctx *, struct hn_softc *,
struct vmbus_channel *, const void *, int);
struct hn_send_ctx {
hn_sent_callback_t hn_cb;
void *hn_cbarg;
};
#define HN_SEND_CTX_INITIALIZER(cb, cbarg) \
{ \
.hn_cb = cb, \
.hn_cbarg = cbarg \
}
#define HN_NDIS_VLAN_INFO_INVALID 0xffffffff
#define HN_NDIS_RXCSUM_INFO_INVALID 0
#define HN_NDIS_HASH_INFO_INVALID 0
@ -261,33 +242,6 @@ struct hn_softc {
#define HN_LINK_FLAG_LINKUP 0x0001
#define HN_LINK_FLAG_NETCHG 0x0002
static __inline void
hn_send_ctx_init(struct hn_send_ctx *sndc, hn_sent_callback_t cb, void *cbarg)
{
sndc->hn_cb = cb;
sndc->hn_cbarg = cbarg;
}
static __inline int
hn_nvs_send(struct vmbus_channel *chan, uint16_t flags,
void *nvs_msg, int nvs_msglen, struct hn_send_ctx *sndc)
{
return (vmbus_chan_send(chan, VMBUS_CHANPKT_TYPE_INBAND, flags,
nvs_msg, nvs_msglen, (uint64_t)(uintptr_t)sndc));
}
static __inline int
hn_nvs_send_sglist(struct vmbus_channel *chan, struct vmbus_gpa sg[], int sglen,
void *nvs_msg, int nvs_msglen, struct hn_send_ctx *sndc)
{
return (vmbus_chan_send_sglist(chan, sg, sglen, nvs_msg, nvs_msglen,
(uint64_t)(uintptr_t)sndc));
}
struct vmbus_xact;
struct rndis_packet_msg;
int hn_rndis_attach(struct hn_softc *sc, int mtu);
@ -302,21 +256,10 @@ int hn_rndis_get_linkstatus(struct hn_softc *sc,
/* filter: NDIS_PACKET_TYPE_. */
int hn_rndis_set_rxfilter(struct hn_softc *sc, uint32_t filter);
int hn_nvs_attach(struct hn_softc *sc, int mtu);
void hn_nvs_detach(struct hn_softc *sc);
int hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch);
void hn_nvs_sent_xact(struct hn_send_ctx *sndc, struct hn_softc *sc,
struct vmbus_channel *chan, const void *data, int dlen);
int hn_nvs_send_rndis_ctrl(struct vmbus_channel *chan,
struct hn_send_ctx *sndc, struct vmbus_gpa *gpa,
int gpa_cnt);
int hn_rxpkt(struct hn_rx_ring *rxr, const void *data, int dlen,
const struct hn_recvinfo *info);
void hn_chan_rollup(struct hn_rx_ring *rxr, struct hn_tx_ring *txr);
void hn_link_status_update(struct hn_softc *sc);
void hn_network_change(struct hn_softc *sc);
extern struct hn_send_ctx hn_send_ctx_none;
#endif /* !_IF_HNVAR_H_ */