mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-20 11:11:24 +00:00
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
This commit is contained in:
parent
9129ad2d70
commit
ca871fb75c
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=303069
@ -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;
|
||||
|
@ -57,7 +57,7 @@ MALLOC_DEFINE(M_NETVSC, "netvsc", "Hyper-V netvsc driver");
|
||||
/*
|
||||
* 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_channel *chan)
|
||||
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, void *additional_info)
|
||||
*/
|
||||
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, const struct vmbus_chanpkt_hdr *pkt)
|
||||
* 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;
|
||||
|
@ -274,7 +274,7 @@ static int create_storvsc_request(union ccb *ccb, struct hv_storvsc_request *req
|
||||
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_softc *sc,
|
||||
|
||||
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_softc *sc)
|
||||
/*
|
||||
* 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_softc *sc)
|
||||
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_softc *sc)
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -49,10 +49,9 @@ static const struct hyperv_guid service_guid = { .hv_guid =
|
||||
* 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);
|
||||
|
@ -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 error)
|
||||
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, int pending)
|
||||
|
||||
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, int pending)
|
||||
* 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, struct uio *uio, int ioflag __unused)
|
||||
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);
|
||||
|
@ -53,10 +53,9 @@ static const struct hyperv_guid service_guid = { .hv_guid =
|
||||
* 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);
|
||||
|
@ -130,9 +130,8 @@ void hv_adj_guesttime(hv_timesync_sc *sc, uint64_t hosttime, uint8_t flags)
|
||||
* 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;
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
|
@ -801,7 +801,7 @@ vmbus_chan_task(void *xchan, int pending __unused)
|
||||
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 pending __unused)
|
||||
{
|
||||
struct hv_vmbus_channel *chan = xchan;
|
||||
|
||||
chan->ch_cb(chan->ch_cbarg);
|
||||
chan->ch_cb(chan, chan->ch_cbarg);
|
||||
}
|
||||
|
||||
static __inline void
|
||||
|
Loading…
Reference in New Issue
Block a user