svn commit: r303069 - in head/sys/dev/hyperv: include netvsc storvsc utilities vmbus
Sepherosa Ziehau
sephe at FreeBSD.org
Wed Jul 20 05:34:31 UTC 2016
Author: sephe
Date: Wed Jul 20 05:34:28 2016
New Revision: 303069
URL: https://svnweb.freebsd.org/changeset/base/303069
Log:
hyperv/vmbus: Pass channel as the first argument for channel callback
The prepares to kill device private fields in channel struct, which
are not flexible and extensible.
MFC after: 1 week
Sponsored by: Microsoft OSTC
Differential Revision: https://reviews.freebsd.org/D7243
Modified:
head/sys/dev/hyperv/include/hyperv.h
head/sys/dev/hyperv/netvsc/hv_net_vsc.c
head/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c
head/sys/dev/hyperv/utilities/hv_heartbeat.c
head/sys/dev/hyperv/utilities/hv_kvp.c
head/sys/dev/hyperv/utilities/hv_shutdown.c
head/sys/dev/hyperv/utilities/hv_timesync.c
head/sys/dev/hyperv/utilities/hv_util.c
head/sys/dev/hyperv/utilities/hv_util.h
head/sys/dev/hyperv/vmbus/vmbus_chan.c
Modified: head/sys/dev/hyperv/include/hyperv.h
==============================================================================
--- head/sys/dev/hyperv/include/hyperv.h Wed Jul 20 05:26:04 2016 (r303068)
+++ head/sys/dev/hyperv/include/hyperv.h Wed Jul 20 05:34:28 2016 (r303069)
@@ -113,7 +113,9 @@ typedef struct {
uint32_t ring_data_size; /* ring_size */
} hv_vmbus_ring_buffer_info;
-typedef void (*vmbus_chan_callback_t)(void *);
+struct hv_vmbus_channel;
+
+typedef void (*vmbus_chan_callback_t)(struct hv_vmbus_channel *, void *);
typedef struct hv_vmbus_channel {
device_t ch_dev;
Modified: head/sys/dev/hyperv/netvsc/hv_net_vsc.c
==============================================================================
--- head/sys/dev/hyperv/netvsc/hv_net_vsc.c Wed Jul 20 05:26:04 2016 (r303068)
+++ head/sys/dev/hyperv/netvsc/hv_net_vsc.c Wed Jul 20 05:34:28 2016 (r303069)
@@ -57,7 +57,7 @@ MALLOC_DEFINE(M_NETVSC, "netvsc", "Hyper
/*
* Forward declarations
*/
-static void hv_nv_on_channel_callback(void *xchan);
+static void hv_nv_on_channel_callback(struct hv_vmbus_channel *chan, void *arg);
static int hv_nv_init_send_buffer_with_net_vsp(struct hn_softc *sc);
static int hv_nv_init_rx_buffer_with_net_vsp(struct hn_softc *);
static int hv_nv_destroy_send_buffer(netvsc_dev *net_dev);
@@ -647,7 +647,7 @@ hv_nv_subchan_attach(struct hv_vmbus_cha
chan->ch_dev_rdbuf = malloc(NETVSC_PACKET_SIZE, M_NETVSC, M_WAITOK);
vmbus_chan_open(chan, NETVSC_DEVICE_RING_BUFFER_SIZE,
NETVSC_DEVICE_RING_BUFFER_SIZE, NULL, 0,
- hv_nv_on_channel_callback, chan);
+ hv_nv_on_channel_callback, NULL);
}
/*
@@ -677,7 +677,7 @@ hv_nv_on_device_add(struct hn_softc *sc,
*/
ret = vmbus_chan_open(chan,
NETVSC_DEVICE_RING_BUFFER_SIZE, NETVSC_DEVICE_RING_BUFFER_SIZE,
- NULL, 0, hv_nv_on_channel_callback, chan);
+ NULL, 0, hv_nv_on_channel_callback, NULL);
if (ret != 0) {
free(chan->ch_dev_rdbuf, M_NETVSC);
goto cleanup;
@@ -973,9 +973,8 @@ hv_nv_send_table(struct hn_softc *sc, co
* Net VSC on channel callback
*/
static void
-hv_nv_on_channel_callback(void *xchan)
+hv_nv_on_channel_callback(struct hv_vmbus_channel *chan, void *arg __unused)
{
- struct hv_vmbus_channel *chan = xchan;
device_t dev = chan->ch_dev;
struct hn_softc *sc = device_get_softc(dev);
netvsc_dev *net_dev;
Modified: head/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c
==============================================================================
--- head/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c Wed Jul 20 05:26:04 2016 (r303068)
+++ head/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c Wed Jul 20 05:34:28 2016 (r303069)
@@ -274,7 +274,7 @@ static int create_storvsc_request(union
static void storvsc_free_request(struct storvsc_softc *sc, struct hv_storvsc_request *reqp);
static enum hv_storage_type storvsc_get_storage_type(device_t dev);
static void hv_storvsc_rescan_target(struct storvsc_softc *sc);
-static void hv_storvsc_on_channel_callback(void *xchan);
+static void hv_storvsc_on_channel_callback(struct hv_vmbus_channel *chan, void *xsc);
static void hv_storvsc_on_iocompletion( struct storvsc_softc *sc,
struct vstor_packet *vstor_packet,
struct hv_storvsc_request *request);
@@ -316,15 +316,13 @@ storvsc_subchan_attach(struct storvsc_so
memset(&props, 0, sizeof(props));
- new_channel->ch_dev_priv1 = sc;
vmbus_chan_cpu_rr(new_channel);
ret = vmbus_chan_open(new_channel,
sc->hs_drv_props->drv_ringbuffer_size,
sc->hs_drv_props->drv_ringbuffer_size,
(void *)&props,
sizeof(struct vmstor_chan_props),
- hv_storvsc_on_channel_callback,
- new_channel);
+ hv_storvsc_on_channel_callback, sc);
}
/**
@@ -575,7 +573,6 @@ hv_storvsc_connect_vsp(struct storvsc_so
/*
* Open the channel
*/
- KASSERT(sc->hs_chan->ch_dev_priv1 == sc, ("invalid chan priv1"));
vmbus_chan_cpu_rr(sc->hs_chan);
ret = vmbus_chan_open(
sc->hs_chan,
@@ -583,8 +580,7 @@ hv_storvsc_connect_vsp(struct storvsc_so
sc->hs_drv_props->drv_ringbuffer_size,
(void *)&props,
sizeof(struct vmstor_chan_props),
- hv_storvsc_on_channel_callback,
- sc->hs_chan);
+ hv_storvsc_on_channel_callback, sc);
if (ret != 0) {
return ret;
@@ -769,11 +765,10 @@ hv_storvsc_rescan_target(struct storvsc_
}
static void
-hv_storvsc_on_channel_callback(void *xchan)
+hv_storvsc_on_channel_callback(struct hv_vmbus_channel *channel, void *xsc)
{
int ret = 0;
- hv_vmbus_channel *channel = xchan;
- struct storvsc_softc *sc = channel->ch_dev_priv1;
+ struct storvsc_softc *sc = xsc;
uint32_t bytes_recvd;
uint64_t request_id;
uint8_t packet[roundup2(sizeof(struct vstor_packet), 8)];
@@ -915,7 +910,6 @@ storvsc_attach(device_t dev)
sc = device_get_softc(dev);
sc->hs_chan = vmbus_get_channel(dev);
- sc->hs_chan->ch_dev_priv1 = sc;
stor_type = storvsc_get_storage_type(dev);
@@ -1265,7 +1259,7 @@ storvsc_poll(struct cam_sim *sim)
mtx_assert(&sc->hs_lock, MA_OWNED);
mtx_unlock(&sc->hs_lock);
- hv_storvsc_on_channel_callback(sc->hs_chan);
+ hv_storvsc_on_channel_callback(sc->hs_chan, sc);
mtx_lock(&sc->hs_lock);
}
Modified: head/sys/dev/hyperv/utilities/hv_heartbeat.c
==============================================================================
--- head/sys/dev/hyperv/utilities/hv_heartbeat.c Wed Jul 20 05:26:04 2016 (r303068)
+++ head/sys/dev/hyperv/utilities/hv_heartbeat.c Wed Jul 20 05:34:28 2016 (r303069)
@@ -49,10 +49,9 @@ static const struct hyperv_guid service_
* Process heartbeat message
*/
static void
-hv_heartbeat_cb(void *context)
+hv_heartbeat_cb(struct hv_vmbus_channel *channel, void *context)
{
uint8_t* buf;
- hv_vmbus_channel* channel;
int recvlen;
uint64_t requestid;
int ret;
@@ -63,7 +62,6 @@ hv_heartbeat_cb(void *context)
softc = (hv_util_sc*)context;
buf = softc->receive_buffer;
- channel = softc->channel;
recvlen = PAGE_SIZE;
ret = vmbus_chan_recv(channel, buf, &recvlen, &requestid);
Modified: head/sys/dev/hyperv/utilities/hv_kvp.c
==============================================================================
--- head/sys/dev/hyperv/utilities/hv_kvp.c Wed Jul 20 05:26:04 2016 (r303068)
+++ head/sys/dev/hyperv/utilities/hv_kvp.c Wed Jul 20 05:34:28 2016 (r303069)
@@ -121,6 +121,7 @@ static struct cdevsw hv_kvp_cdevsw =
*/
typedef struct hv_kvp_sc {
struct hv_util_sc util_sc;
+ device_t dev;
/* Unless specified the pending mutex should be
* used to alter the values of the following parameters:
@@ -576,7 +577,7 @@ hv_kvp_respond_host(hv_kvp_sc *sc, int e
hv_icmsg_hdrp->status = error;
hv_icmsg_hdrp->icflags = HV_ICMSGHDRFLAG_TRANSACTION | HV_ICMSGHDRFLAG_RESPONSE;
- error = vmbus_chan_send(sc->util_sc.channel,
+ error = vmbus_chan_send(vmbus_get_channel(sc->dev),
VMBUS_CHANPKT_TYPE_INBAND, 0, sc->rcv_buf, sc->host_msg_len,
sc->host_msg_id);
if (error)
@@ -625,7 +626,7 @@ hv_kvp_process_request(void *context, in
sc = (hv_kvp_sc*)context;
kvp_buf = sc->util_sc.receive_buffer;
- channel = sc->util_sc.channel;
+ channel = vmbus_get_channel(sc->dev);
recvlen = 2 * PAGE_SIZE;
ret = vmbus_chan_recv(channel, kvp_buf, &recvlen, &requestid);
@@ -709,7 +710,7 @@ hv_kvp_process_request(void *context, in
* Callback routine that gets called whenever there is a message from host
*/
static void
-hv_kvp_callback(void *context)
+hv_kvp_callback(struct hv_vmbus_channel *chan __unused, void *context)
{
hv_kvp_sc *sc = (hv_kvp_sc*)context;
/*
@@ -813,7 +814,7 @@ hv_kvp_dev_daemon_write(struct cdev *dev
if (sc->register_done == false) {
if (sc->daemon_kvp_msg.kvp_hdr.operation == HV_KVP_OP_REGISTER) {
sc->register_done = true;
- hv_kvp_callback(dev->si_drv1);
+ hv_kvp_callback(vmbus_get_channel(sc->dev), dev->si_drv1);
}
else {
hv_kvp_log_info("%s, KVP Registration Failed\n", __func__);
@@ -891,6 +892,7 @@ hv_kvp_attach(device_t dev)
hv_kvp_sc *sc = (hv_kvp_sc*)device_get_softc(dev);
sc->util_sc.callback = hv_kvp_callback;
+ sc->dev = dev;
sema_init(&sc->dev_sema, 0, "hv_kvp device semaphore");
mtx_init(&sc->pending_mutex, "hv-kvp pending mutex",
NULL, MTX_DEF);
Modified: head/sys/dev/hyperv/utilities/hv_shutdown.c
==============================================================================
--- head/sys/dev/hyperv/utilities/hv_shutdown.c Wed Jul 20 05:26:04 2016 (r303068)
+++ head/sys/dev/hyperv/utilities/hv_shutdown.c Wed Jul 20 05:34:28 2016 (r303069)
@@ -53,10 +53,9 @@ static const struct hyperv_guid service_
* Shutdown
*/
static void
-hv_shutdown_cb(void *context)
+hv_shutdown_cb(struct hv_vmbus_channel *channel, void *context)
{
uint8_t* buf;
- hv_vmbus_channel* channel;
uint8_t execute_shutdown = 0;
hv_vmbus_icmsg_hdr* icmsghdrp;
uint32_t recv_len;
@@ -67,7 +66,6 @@ hv_shutdown_cb(void *context)
softc = (hv_util_sc*)context;
buf = softc->receive_buffer;
- channel = softc->channel;
recv_len = PAGE_SIZE;
ret = vmbus_chan_recv(channel, buf, &recv_len, &request_id);
Modified: head/sys/dev/hyperv/utilities/hv_timesync.c
==============================================================================
--- head/sys/dev/hyperv/utilities/hv_timesync.c Wed Jul 20 05:26:04 2016 (r303068)
+++ head/sys/dev/hyperv/utilities/hv_timesync.c Wed Jul 20 05:34:28 2016 (r303069)
@@ -130,9 +130,8 @@ void hv_adj_guesttime(hv_timesync_sc *sc
* Time Sync Channel message handler
*/
static void
-hv_timesync_cb(void *context)
+hv_timesync_cb(struct hv_vmbus_channel *channel, void *context)
{
- hv_vmbus_channel* channel;
hv_vmbus_icmsg_hdr* icmsghdrp;
uint32_t recvlen;
uint64_t requestId;
@@ -142,7 +141,6 @@ hv_timesync_cb(void *context)
hv_timesync_sc *softc;
softc = (hv_timesync_sc*)context;
- channel = softc->util_sc.channel;
time_buf = softc->util_sc.receive_buffer;
recvlen = PAGE_SIZE;
Modified: head/sys/dev/hyperv/utilities/hv_util.c
==============================================================================
--- head/sys/dev/hyperv/utilities/hv_util.c Wed Jul 20 05:26:04 2016 (r303068)
+++ head/sys/dev/hyperv/utilities/hv_util.c Wed Jul 20 05:34:28 2016 (r303069)
@@ -77,12 +77,13 @@ int
hv_util_attach(device_t dev)
{
struct hv_util_sc* softc;
+ struct hv_vmbus_channel *chan;
int ret;
softc = device_get_softc(dev);
- softc->channel = vmbus_get_channel(dev);
softc->receive_buffer =
malloc(4 * PAGE_SIZE, M_DEVBUF, M_WAITOK | M_ZERO);
+ chan = vmbus_get_channel(dev);
/*
* These services are not performance critical and do not need
@@ -91,11 +92,10 @@ hv_util_attach(device_t dev)
* Turn off batched reading for all util drivers before we open the
* channel.
*/
- vmbus_chan_set_readbatch(softc->channel, false);
+ vmbus_chan_set_readbatch(chan, false);
- ret = vmbus_chan_open(softc->channel, 4 * PAGE_SIZE,
- 4 * PAGE_SIZE, NULL, 0,
- softc->callback, softc);
+ ret = vmbus_chan_open(chan, 4 * PAGE_SIZE, 4 * PAGE_SIZE, NULL, 0,
+ softc->callback, softc);
if (ret)
goto error0;
@@ -112,7 +112,7 @@ hv_util_detach(device_t dev)
{
struct hv_util_sc *sc = device_get_softc(dev);
- vmbus_chan_close(sc->channel);
+ vmbus_chan_close(vmbus_get_channel(dev));
free(sc->receive_buffer, M_DEVBUF);
return (0);
Modified: head/sys/dev/hyperv/utilities/hv_util.h
==============================================================================
--- head/sys/dev/hyperv/utilities/hv_util.h Wed Jul 20 05:26:04 2016 (r303068)
+++ head/sys/dev/hyperv/utilities/hv_util.h Wed Jul 20 05:34:28 2016 (r303069)
@@ -39,9 +39,7 @@ typedef struct hv_util_sc {
/*
* function to process Hyper-V messages
*/
- void (*callback)(void *);
-
- struct hv_vmbus_channel *channel;
+ void (*callback)(struct hv_vmbus_channel *, void *);
uint8_t *receive_buffer;
} hv_util_sc;
Modified: head/sys/dev/hyperv/vmbus/vmbus_chan.c
==============================================================================
--- head/sys/dev/hyperv/vmbus/vmbus_chan.c Wed Jul 20 05:26:04 2016 (r303068)
+++ head/sys/dev/hyperv/vmbus/vmbus_chan.c Wed Jul 20 05:34:28 2016 (r303069)
@@ -801,7 +801,7 @@ vmbus_chan_task(void *xchan, int pending
for (;;) {
uint32_t left;
- cb(cbarg);
+ cb(chan, cbarg);
left = hv_ring_buffer_read_end(&chan->ch_rxbr);
if (left == 0) {
@@ -817,7 +817,7 @@ vmbus_chan_task_nobatch(void *xchan, int
{
struct hv_vmbus_channel *chan = xchan;
- chan->ch_cb(chan->ch_cbarg);
+ chan->ch_cb(chan, chan->ch_cbarg);
}
static __inline void
More information about the svn-src-head
mailing list