hyperv/hn: Factor out hn_nvs_send/hn_nvs_send_sglist
Avoid unnecessary message type setting and centralize the send context to transaction id cast. MFC after: 1 week Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D7500
This commit is contained in:
parent
8452c1b345
commit
5ac4acb202
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=304204
@ -83,6 +83,7 @@ struct vmbus_chanpkt_hdr {
|
||||
#define VMBUS_CHANPKT_TYPE_GPA 0x0009
|
||||
#define VMBUS_CHANPKT_TYPE_COMP 0x000b
|
||||
|
||||
#define VMBUS_CHANPKT_FLAG_NONE 0
|
||||
#define VMBUS_CHANPKT_FLAG_RC 0x0001 /* report completion */
|
||||
|
||||
#define VMBUS_CHANPKT_CONST_DATA(pkt) \
|
||||
|
@ -206,9 +206,8 @@ hv_nv_init_rx_buffer_with_net_vsp(struct hn_softc *sc)
|
||||
hn_send_ctx_init_simple(&sndc, hn_nvs_sent_xact, xact);
|
||||
vmbus_xact_activate(xact);
|
||||
|
||||
error = vmbus_chan_send(sc->hn_prichan,
|
||||
VMBUS_CHANPKT_TYPE_INBAND, VMBUS_CHANPKT_FLAG_RC,
|
||||
conn, sizeof(*conn), (uint64_t)(uintptr_t)&sndc);
|
||||
error = hn_nvs_send(sc->hn_prichan, VMBUS_CHANPKT_FLAG_RC,
|
||||
conn, sizeof(*conn), &sndc);
|
||||
if (error != 0) {
|
||||
if_printf(sc->hn_ifp, "send nvs rxbuf conn failed: %d\n",
|
||||
error);
|
||||
@ -313,9 +312,8 @@ hv_nv_init_send_buffer_with_net_vsp(struct hn_softc *sc)
|
||||
hn_send_ctx_init_simple(&sndc, hn_nvs_sent_xact, xact);
|
||||
vmbus_xact_activate(xact);
|
||||
|
||||
error = vmbus_chan_send(sc->hn_prichan,
|
||||
VMBUS_CHANPKT_TYPE_INBAND, VMBUS_CHANPKT_FLAG_RC,
|
||||
chim, sizeof(*chim), (uint64_t)(uintptr_t)&sndc);
|
||||
error = hn_nvs_send(sc->hn_prichan, VMBUS_CHANPKT_FLAG_RC,
|
||||
chim, sizeof(*chim), &sndc);
|
||||
if (error) {
|
||||
if_printf(sc->hn_ifp, "send nvs chim conn failed: %d\n",
|
||||
error);
|
||||
@ -393,9 +391,10 @@ hv_nv_destroy_rx_buffer(netvsc_dev *net_dev)
|
||||
disconn.nvs_type = HN_NVS_TYPE_RXBUF_DISCONN;
|
||||
disconn.nvs_sig = HN_NVS_RXBUF_SIG;
|
||||
|
||||
ret = vmbus_chan_send(net_dev->sc->hn_prichan,
|
||||
VMBUS_CHANPKT_TYPE_INBAND, 0, &disconn, sizeof(disconn),
|
||||
(uint64_t)(uintptr_t)&hn_send_ctx_none);
|
||||
/* NOTE: No response. */
|
||||
ret = hn_nvs_send(net_dev->sc->hn_prichan,
|
||||
VMBUS_CHANPKT_FLAG_NONE, &disconn, sizeof(disconn),
|
||||
&hn_send_ctx_none);
|
||||
if (ret != 0) {
|
||||
if_printf(net_dev->sc->hn_ifp,
|
||||
"send rxbuf disconn failed: %d\n", ret);
|
||||
@ -445,9 +444,10 @@ hv_nv_destroy_send_buffer(netvsc_dev *net_dev)
|
||||
disconn.nvs_type = HN_NVS_TYPE_CHIM_DISCONN;
|
||||
disconn.nvs_sig = HN_NVS_CHIM_SIG;
|
||||
|
||||
ret = vmbus_chan_send(net_dev->sc->hn_prichan,
|
||||
VMBUS_CHANPKT_TYPE_INBAND, 0, &disconn, sizeof(disconn),
|
||||
(uint64_t)(uintptr_t)&hn_send_ctx_none);
|
||||
/* NOTE: No response. */
|
||||
ret = hn_nvs_send(net_dev->sc->hn_prichan,
|
||||
VMBUS_CHANPKT_FLAG_NONE, &disconn, sizeof(disconn),
|
||||
&hn_send_ctx_none);
|
||||
if (ret != 0) {
|
||||
if_printf(net_dev->sc->hn_ifp,
|
||||
"send chim disconn failed: %d\n", ret);
|
||||
@ -509,9 +509,8 @@ hv_nv_negotiate_nvsp_protocol(struct hn_softc *sc, netvsc_dev *net_dev,
|
||||
vmbus_xact_activate(xact);
|
||||
hn_send_ctx_init_simple(&sndc, hn_nvs_sent_xact, xact);
|
||||
|
||||
error = vmbus_chan_send(sc->hn_prichan,
|
||||
VMBUS_CHANPKT_TYPE_INBAND, VMBUS_CHANPKT_FLAG_RC,
|
||||
init, sizeof(*init), (uint64_t)(uintptr_t)&sndc);
|
||||
error = hn_nvs_send(sc->hn_prichan, VMBUS_CHANPKT_FLAG_RC,
|
||||
init, sizeof(*init), &sndc);
|
||||
if (error) {
|
||||
if_printf(sc->hn_ifp, "send nvs init failed: %d\n", error);
|
||||
vmbus_xact_deactivate(xact);
|
||||
@ -560,8 +559,9 @@ hv_nv_send_ndis_config(struct hn_softc *sc, uint32_t mtu)
|
||||
conf.nvs_mtu = mtu;
|
||||
conf.nvs_caps = HN_NVS_NDIS_CONF_VLAN;
|
||||
|
||||
error = vmbus_chan_send(sc->hn_prichan, VMBUS_CHANPKT_TYPE_INBAND, 0,
|
||||
&conf, sizeof(conf), (uint64_t)(uintptr_t)&hn_send_ctx_none);
|
||||
/* NOTE: No response. */
|
||||
error = hn_nvs_send(sc->hn_prichan, VMBUS_CHANPKT_FLAG_NONE,
|
||||
&conf, sizeof(conf), &hn_send_ctx_none);
|
||||
if (error)
|
||||
if_printf(sc->hn_ifp, "send nvs ndis conf failed: %d\n", error);
|
||||
return (error);
|
||||
@ -627,8 +627,9 @@ hv_nv_connect_to_vsp(struct hn_softc *sc)
|
||||
else
|
||||
ndis.nvs_ndis_minor = NDIS_VERSION_MINOR_30;
|
||||
|
||||
ret = vmbus_chan_send(sc->hn_prichan, VMBUS_CHANPKT_TYPE_INBAND, 0,
|
||||
&ndis, sizeof(ndis), (uint64_t)(uintptr_t)&hn_send_ctx_none);
|
||||
/* NOTE: No response. */
|
||||
ret = hn_nvs_send(sc->hn_prichan, VMBUS_CHANPKT_FLAG_NONE,
|
||||
&ndis, sizeof(ndis), &hn_send_ctx_none);
|
||||
if (ret != 0) {
|
||||
if_printf(sc->hn_ifp, "send nvs ndis init failed: %d\n", ret);
|
||||
goto cleanup;
|
||||
@ -834,12 +835,11 @@ hv_nv_on_send(struct vmbus_channel *chan, bool is_data_pkt,
|
||||
sndc->hn_chim_sz;
|
||||
|
||||
if (gpa_cnt) {
|
||||
ret = vmbus_chan_send_sglist(chan, gpa, gpa_cnt,
|
||||
&send_msg, sizeof(nvsp_msg), (uint64_t)(uintptr_t)sndc);
|
||||
ret = hn_nvs_send_sglist(chan, gpa, gpa_cnt,
|
||||
&send_msg, sizeof(nvsp_msg), sndc);
|
||||
} else {
|
||||
ret = vmbus_chan_send(chan,
|
||||
VMBUS_CHANPKT_TYPE_INBAND, VMBUS_CHANPKT_FLAG_RC,
|
||||
&send_msg, sizeof(nvsp_msg), (uint64_t)(uintptr_t)sndc);
|
||||
ret = hn_nvs_send(chan, VMBUS_CHANPKT_FLAG_RC,
|
||||
&send_msg, sizeof(nvsp_msg), sndc);
|
||||
}
|
||||
|
||||
return (ret);
|
||||
|
@ -1177,9 +1177,8 @@ hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
|
||||
hn_send_ctx_init_simple(&sndc, hn_nvs_sent_xact, xact);
|
||||
vmbus_xact_activate(xact);
|
||||
|
||||
ret = vmbus_chan_send(sc->hn_prichan,
|
||||
VMBUS_CHANPKT_TYPE_INBAND, VMBUS_CHANPKT_FLAG_RC,
|
||||
req, sizeof(*req), (uint64_t)(uintptr_t)&sndc);
|
||||
ret = hn_nvs_send(sc->hn_prichan, VMBUS_CHANPKT_FLAG_RC,
|
||||
req, sizeof(*req), &sndc);
|
||||
if (ret != 0) {
|
||||
if_printf(sc->hn_ifp, "send nvs subch req failed: %d\n", ret);
|
||||
vmbus_xact_deactivate(xact);
|
||||
|
@ -30,6 +30,8 @@
|
||||
#define _IF_HNVAR_H_
|
||||
|
||||
#include <sys/param.h>
|
||||
|
||||
#include <dev/hyperv/include/vmbus.h>
|
||||
#include <dev/hyperv/netvsc/hv_net_vsc.h>
|
||||
|
||||
struct netvsc_dev_;
|
||||
@ -61,6 +63,7 @@ static __inline void
|
||||
hn_send_ctx_init(struct hn_send_ctx *sndc, hn_sent_callback_t cb,
|
||||
void *cbarg, uint32_t chim_idx, int chim_sz)
|
||||
{
|
||||
|
||||
sndc->hn_cb = cb;
|
||||
sndc->hn_cbarg = cbarg;
|
||||
sndc->hn_chim_idx = chim_idx;
|
||||
@ -71,10 +74,29 @@ static __inline void
|
||||
hn_send_ctx_init_simple(struct hn_send_ctx *sndc, hn_sent_callback_t cb,
|
||||
void *cbarg)
|
||||
{
|
||||
|
||||
hn_send_ctx_init(sndc, cb, cbarg,
|
||||
NVSP_1_CHIMNEY_SEND_INVALID_SECTION_INDEX, 0);
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
void hn_nvs_sent_xact(struct hn_send_ctx *sndc,
|
||||
struct netvsc_dev_ *net_dev, struct vmbus_channel *chan,
|
||||
const struct nvsp_msg_ *msg, int dlen);
|
||||
|
Loading…
Reference in New Issue
Block a user