summaryrefslogtreecommitdiffstats
path: root/sys/dev/hyperv/netvsc
diff options
context:
space:
mode:
authorsephe <sephe@FreeBSD.org>2016-10-11 07:30:59 +0000
committersephe <sephe@FreeBSD.org>2016-10-11 07:30:59 +0000
commite454e6f1254efd4b2d767a04a4e076f85863c58c (patch)
tree7062d628c193dc4f758f1b55865b14a9e36a53b0 /sys/dev/hyperv/netvsc
parent5aca196a1235050ca5edda3bcef3ce631a06097b (diff)
downloadFreeBSD-src-e454e6f1254efd4b2d767a04a4e076f85863c58c.zip
FreeBSD-src-e454e6f1254efd4b2d767a04a4e076f85863c58c.tar.gz
MFC 302698-302704,302706
302698 hyperv/vmbus: Add vmbus method for GUID base device probing. Reduce the exposure of hv_device. Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D7024 302699 hyperv/vmbus: All ivars are read-only; nuke unnecessary write_ivar Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D7025 302700 hyperv/vmbus: Add channel ivar accessor. This makes life easier during the transition period to nuke the hv_device. Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D7026 302701 hyperv/stor: Avoid the hv_device and nuke the broken get_stor_device This paves way to nuke the hv_device, which is actually an unncessary indirection. Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D7027 302702 hyperv/util: Avoid the hv_device This paves way to nuke the hv_device, which is actually an unncessary indirection. Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D7028 302703 hyperv/vmbus: Deprecate the usage of hv_device. This paves way to nuke the hv_device, which is actually an unncessary indirection. Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D7032 302704 hyperv/hn: Avoid the hv_device This paves way to nuke the hv_device, which is actually an unncessary indirection. Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D7033 302706 hyperv: Get rid of hv_device, which is unnecessary indirection. Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D7034
Diffstat (limited to 'sys/dev/hyperv/netvsc')
-rw-r--r--sys/dev/hyperv/netvsc/hv_net_vsc.c148
-rw-r--r--sys/dev/hyperv/netvsc/hv_net_vsc.h11
-rw-r--r--sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c53
-rw-r--r--sys/dev/hyperv/netvsc/hv_rndis_filter.c40
-rw-r--r--sys/dev/hyperv/netvsc/hv_rndis_filter.h11
5 files changed, 103 insertions, 160 deletions
diff --git a/sys/dev/hyperv/netvsc/hv_net_vsc.c b/sys/dev/hyperv/netvsc/hv_net_vsc.c
index a62f450..a3fe0e2 100644
--- a/sys/dev/hyperv/netvsc/hv_net_vsc.c
+++ b/sys/dev/hyperv/netvsc/hv_net_vsc.c
@@ -57,31 +57,30 @@ MALLOC_DEFINE(M_NETVSC, "netvsc", "Hyper-V netvsc driver");
* Forward declarations
*/
static void hv_nv_on_channel_callback(void *xchan);
-static int hv_nv_init_send_buffer_with_net_vsp(struct hv_device *device);
-static int hv_nv_init_rx_buffer_with_net_vsp(struct hv_device *device);
+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);
static int hv_nv_destroy_rx_buffer(netvsc_dev *net_dev);
-static int hv_nv_connect_to_vsp(struct hv_device *device);
+static int hv_nv_connect_to_vsp(struct hn_softc *sc);
static void hv_nv_on_send_completion(netvsc_dev *net_dev,
- struct hv_device *device, struct hv_vmbus_channel *, hv_vm_packet_descriptor *pkt);
+ struct hv_vmbus_channel *, hv_vm_packet_descriptor *pkt);
static void hv_nv_on_receive_completion(struct hv_vmbus_channel *chan,
uint64_t tid, uint32_t status);
static void hv_nv_on_receive(netvsc_dev *net_dev,
- struct hv_device *device, struct hv_vmbus_channel *chan,
+ struct hn_softc *sc, struct hv_vmbus_channel *chan,
hv_vm_packet_descriptor *pkt);
/*
*
*/
static inline netvsc_dev *
-hv_nv_alloc_net_device(struct hv_device *device)
+hv_nv_alloc_net_device(struct hn_softc *sc)
{
netvsc_dev *net_dev;
- hn_softc_t *sc = device_get_softc(device->device);
net_dev = malloc(sizeof(netvsc_dev), M_NETVSC, M_WAITOK | M_ZERO);
- net_dev->dev = device;
+ net_dev->sc = sc;
net_dev->destroy = FALSE;
sc->net_dev = net_dev;
@@ -89,43 +88,21 @@ hv_nv_alloc_net_device(struct hv_device *device)
}
/*
- *
+ * XXX unnecessary; nuke it.
*/
static inline netvsc_dev *
-hv_nv_get_outbound_net_device(struct hv_device *device)
+hv_nv_get_outbound_net_device(struct hn_softc *sc)
{
- hn_softc_t *sc = device_get_softc(device->device);
- netvsc_dev *net_dev = sc->net_dev;;
-
- if ((net_dev != NULL) && net_dev->destroy) {
- return (NULL);
- }
-
- return (net_dev);
+ return sc->net_dev;
}
/*
- *
+ * XXX unnecessary; nuke it.
*/
static inline netvsc_dev *
-hv_nv_get_inbound_net_device(struct hv_device *device)
+hv_nv_get_inbound_net_device(struct hn_softc *sc)
{
- hn_softc_t *sc = device_get_softc(device->device);
- netvsc_dev *net_dev = sc->net_dev;;
-
- if (net_dev == NULL) {
- return (net_dev);
- }
- /*
- * When the device is being destroyed; we only
- * permit incoming packets if and only if there
- * are outstanding sends.
- */
- if (net_dev->destroy) {
- return (NULL);
- }
-
- return (net_dev);
+ return sc->net_dev;
}
int
@@ -163,13 +140,13 @@ hv_nv_get_next_send_section(netvsc_dev *net_dev)
* Hyper-V extensible switch and the synthetic data path.
*/
static int
-hv_nv_init_rx_buffer_with_net_vsp(struct hv_device *device)
+hv_nv_init_rx_buffer_with_net_vsp(struct hn_softc *sc)
{
netvsc_dev *net_dev;
nvsp_msg *init_pkt;
int ret = 0;
- net_dev = hv_nv_get_outbound_net_device(device);
+ net_dev = hv_nv_get_outbound_net_device(sc);
if (!net_dev) {
return (ENODEV);
}
@@ -184,7 +161,7 @@ hv_nv_init_rx_buffer_with_net_vsp(struct hv_device *device)
* GPADL: Guest physical address descriptor list.
*/
ret = hv_vmbus_channel_establish_gpadl(
- device->channel, net_dev->rx_buf,
+ sc->hn_prichan, net_dev->rx_buf,
net_dev->rx_buf_size, &net_dev->rx_buf_gpadl_handle);
if (ret != 0) {
goto cleanup;
@@ -205,7 +182,7 @@ hv_nv_init_rx_buffer_with_net_vsp(struct hv_device *device)
/* Send the gpadl notification request */
- ret = hv_vmbus_channel_send_packet(device->channel, init_pkt,
+ ret = hv_vmbus_channel_send_packet(sc->hn_prichan, init_pkt,
sizeof(nvsp_msg), (uint64_t)(uintptr_t)init_pkt,
HV_VMBUS_PACKET_TYPE_DATA_IN_BAND,
HV_VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
@@ -255,13 +232,13 @@ exit:
* Net VSC initialize send buffer with net VSP
*/
static int
-hv_nv_init_send_buffer_with_net_vsp(struct hv_device *device)
+hv_nv_init_send_buffer_with_net_vsp(struct hn_softc *sc)
{
netvsc_dev *net_dev;
nvsp_msg *init_pkt;
int ret = 0;
- net_dev = hv_nv_get_outbound_net_device(device);
+ net_dev = hv_nv_get_outbound_net_device(sc);
if (!net_dev) {
return (ENODEV);
}
@@ -278,7 +255,7 @@ hv_nv_init_send_buffer_with_net_vsp(struct hv_device *device)
* Note: This call uses the vmbus connection rather than the
* channel to establish the gpadl handle.
*/
- ret = hv_vmbus_channel_establish_gpadl(device->channel,
+ ret = hv_vmbus_channel_establish_gpadl(sc->hn_prichan,
net_dev->send_buf, net_dev->send_buf_size,
&net_dev->send_buf_gpadl_handle);
if (ret != 0) {
@@ -299,7 +276,7 @@ hv_nv_init_send_buffer_with_net_vsp(struct hv_device *device)
/* Send the gpadl notification request */
- ret = hv_vmbus_channel_send_packet(device->channel, init_pkt,
+ ret = hv_vmbus_channel_send_packet(sc->hn_prichan, init_pkt,
sizeof(nvsp_msg), (uint64_t)init_pkt,
HV_VMBUS_PACKET_TYPE_DATA_IN_BAND,
HV_VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
@@ -359,7 +336,7 @@ hv_nv_destroy_rx_buffer(netvsc_dev *net_dev)
revoke_pkt->msgs.vers_1_msgs.revoke_rx_buf.id =
NETVSC_RECEIVE_BUFFER_ID;
- ret = hv_vmbus_channel_send_packet(net_dev->dev->channel,
+ ret = hv_vmbus_channel_send_packet(net_dev->sc->hn_prichan,
revoke_pkt, sizeof(nvsp_msg),
(uint64_t)(uintptr_t)revoke_pkt,
HV_VMBUS_PACKET_TYPE_DATA_IN_BAND, 0);
@@ -375,7 +352,7 @@ hv_nv_destroy_rx_buffer(netvsc_dev *net_dev)
/* Tear down the gpadl on the vsp end */
if (net_dev->rx_buf_gpadl_handle) {
- ret = hv_vmbus_channel_teardown_gpdal(net_dev->dev->channel,
+ ret = hv_vmbus_channel_teardown_gpdal(net_dev->sc->hn_prichan,
net_dev->rx_buf_gpadl_handle);
/*
* If we failed here, we might as well return and have a leak
@@ -427,7 +404,7 @@ hv_nv_destroy_send_buffer(netvsc_dev *net_dev)
revoke_pkt->msgs.vers_1_msgs.revoke_send_buf.id =
NETVSC_SEND_BUFFER_ID;
- ret = hv_vmbus_channel_send_packet(net_dev->dev->channel,
+ ret = hv_vmbus_channel_send_packet(net_dev->sc->hn_prichan,
revoke_pkt, sizeof(nvsp_msg),
(uint64_t)(uintptr_t)revoke_pkt,
HV_VMBUS_PACKET_TYPE_DATA_IN_BAND, 0);
@@ -442,7 +419,7 @@ hv_nv_destroy_send_buffer(netvsc_dev *net_dev)
/* Tear down the gpadl on the vsp end */
if (net_dev->send_buf_gpadl_handle) {
- ret = hv_vmbus_channel_teardown_gpdal(net_dev->dev->channel,
+ ret = hv_vmbus_channel_teardown_gpdal(net_dev->sc->hn_prichan,
net_dev->send_buf_gpadl_handle);
/*
@@ -477,7 +454,7 @@ hv_nv_destroy_send_buffer(netvsc_dev *net_dev)
* to the negotiated version, so we cannot rely on that.
*/
static int
-hv_nv_negotiate_nvsp_protocol(struct hv_device *device, netvsc_dev *net_dev,
+hv_nv_negotiate_nvsp_protocol(struct hn_softc *sc, netvsc_dev *net_dev,
uint32_t nvsp_ver)
{
nvsp_msg *init_pkt;
@@ -494,7 +471,7 @@ hv_nv_negotiate_nvsp_protocol(struct hv_device *device, netvsc_dev *net_dev,
init_pkt->msgs.init_msgs.init.protocol_version_2 = nvsp_ver;
/* Send the init request */
- ret = hv_vmbus_channel_send_packet(device->channel, init_pkt,
+ ret = hv_vmbus_channel_send_packet(sc->hn_prichan, init_pkt,
sizeof(nvsp_msg), (uint64_t)(uintptr_t)init_pkt,
HV_VMBUS_PACKET_TYPE_DATA_IN_BAND,
HV_VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
@@ -515,13 +492,13 @@ hv_nv_negotiate_nvsp_protocol(struct hv_device *device, netvsc_dev *net_dev,
* Not valid for NDIS version 1.
*/
static int
-hv_nv_send_ndis_config(struct hv_device *device, uint32_t mtu)
+hv_nv_send_ndis_config(struct hn_softc *sc, uint32_t mtu)
{
netvsc_dev *net_dev;
nvsp_msg *init_pkt;
int ret;
- net_dev = hv_nv_get_outbound_net_device(device);
+ net_dev = hv_nv_get_outbound_net_device(sc);
if (!net_dev)
return (-ENODEV);
@@ -538,7 +515,7 @@ hv_nv_send_ndis_config(struct hv_device *device, uint32_t mtu)
= 1;
/* Send the configuration packet */
- ret = hv_vmbus_channel_send_packet(device->channel, init_pkt,
+ ret = hv_vmbus_channel_send_packet(sc->hn_prichan, init_pkt,
sizeof(nvsp_msg), (uint64_t)(uintptr_t)init_pkt,
HV_VMBUS_PACKET_TYPE_DATA_IN_BAND, 0);
if (ret != 0)
@@ -551,7 +528,7 @@ hv_nv_send_ndis_config(struct hv_device *device, uint32_t mtu)
* Net VSC connect to VSP
*/
static int
-hv_nv_connect_to_vsp(struct hv_device *device)
+hv_nv_connect_to_vsp(struct hn_softc *sc)
{
netvsc_dev *net_dev;
nvsp_msg *init_pkt;
@@ -563,20 +540,16 @@ hv_nv_connect_to_vsp(struct hv_device *device)
int i;
int protocol_number = nitems(protocol_list);
int ret = 0;
- device_t dev = device->device;
- hn_softc_t *sc = device_get_softc(dev);
+ device_t dev = sc->hn_dev;
struct ifnet *ifp = sc->arpcom.ac_ifp;
- net_dev = hv_nv_get_outbound_net_device(device);
- if (!net_dev) {
- return (ENODEV);
- }
+ net_dev = hv_nv_get_outbound_net_device(sc);
/*
* Negotiate the NVSP version. Try the latest NVSP first.
*/
for (i = protocol_number - 1; i >= 0; i--) {
- if (hv_nv_negotiate_nvsp_protocol(device, net_dev,
+ if (hv_nv_negotiate_nvsp_protocol(sc, net_dev,
protocol_list[i]) == 0) {
net_dev->nvsp_version = protocol_list[i];
if (bootverbose)
@@ -598,7 +571,7 @@ hv_nv_connect_to_vsp(struct hv_device *device)
* This needs to be right after the NVSP init message per Haiyang
*/
if (net_dev->nvsp_version >= NVSP_PROTOCOL_VERSION_2)
- ret = hv_nv_send_ndis_config(device, ifp->if_mtu);
+ ret = hv_nv_send_ndis_config(sc, ifp->if_mtu);
/*
* Send the NDIS version
@@ -621,7 +594,7 @@ hv_nv_connect_to_vsp(struct hv_device *device)
/* Send the init request */
- ret = hv_vmbus_channel_send_packet(device->channel, init_pkt,
+ ret = hv_vmbus_channel_send_packet(sc->hn_prichan, init_pkt,
sizeof(nvsp_msg), (uint64_t)(uintptr_t)init_pkt,
HV_VMBUS_PACKET_TYPE_DATA_IN_BAND, 0);
if (ret != 0) {
@@ -642,9 +615,9 @@ hv_nv_connect_to_vsp(struct hv_device *device)
net_dev->rx_buf_size = NETVSC_RECEIVE_BUFFER_SIZE;
net_dev->send_buf_size = NETVSC_SEND_BUFFER_SIZE;
- ret = hv_nv_init_rx_buffer_with_net_vsp(device);
+ ret = hv_nv_init_rx_buffer_with_net_vsp(sc);
if (ret == 0)
- ret = hv_nv_init_send_buffer_with_net_vsp(device);
+ ret = hv_nv_init_send_buffer_with_net_vsp(sc);
cleanup:
return (ret);
@@ -676,13 +649,13 @@ hv_nv_subchan_attach(struct hv_vmbus_channel *chan)
* Callback when the device belonging to this driver is added
*/
netvsc_dev *
-hv_nv_on_device_add(struct hv_device *device, void *additional_info)
+hv_nv_on_device_add(struct hn_softc *sc, void *additional_info)
{
- struct hv_vmbus_channel *chan = device->channel;
+ struct hv_vmbus_channel *chan = sc->hn_prichan;
netvsc_dev *net_dev;
int ret = 0;
- net_dev = hv_nv_alloc_net_device(device);
+ net_dev = hv_nv_alloc_net_device(sc);
if (net_dev == NULL)
return NULL;
@@ -706,7 +679,7 @@ hv_nv_on_device_add(struct hv_device *device, void *additional_info)
/*
* Connect with the NetVsp
*/
- ret = hv_nv_connect_to_vsp(device);
+ ret = hv_nv_connect_to_vsp(sc);
if (ret != 0)
goto close;
@@ -732,9 +705,8 @@ cleanup:
* Net VSC on device remove
*/
int
-hv_nv_on_device_remove(struct hv_device *device, boolean_t destroy_channel)
+hv_nv_on_device_remove(struct hn_softc *sc, boolean_t destroy_channel)
{
- hn_softc_t *sc = device_get_softc(device->device);
netvsc_dev *net_dev = sc->net_dev;;
/* Stop outbound traffic ie sends and receives completions */
@@ -747,12 +719,12 @@ hv_nv_on_device_remove(struct hv_device *device, boolean_t destroy_channel)
/* Now, we can close the channel safely */
if (!destroy_channel) {
- device->channel->state =
+ sc->hn_prichan->state =
HV_CHANNEL_CLOSING_NONDESTRUCTIVE_STATE;
}
- free(device->channel->hv_chan_rdbuf, M_NETVSC);
- hv_vmbus_channel_close(device->channel);
+ free(sc->hn_prichan->hv_chan_rdbuf, M_NETVSC);
+ hv_vmbus_channel_close(sc->hn_prichan);
sema_destroy(&net_dev->channel_init_sema);
free(net_dev, M_NETVSC);
@@ -764,8 +736,7 @@ hv_nv_on_device_remove(struct hv_device *device, boolean_t destroy_channel)
* Net VSC on send completion
*/
static void
-hv_nv_on_send_completion(netvsc_dev *net_dev,
- struct hv_device *device, struct hv_vmbus_channel *chan,
+hv_nv_on_send_completion(netvsc_dev *net_dev, struct hv_vmbus_channel *chan,
hv_vm_packet_descriptor *pkt)
{
nvsp_msg *nvsp_msg_pkt;
@@ -870,14 +841,14 @@ hv_nv_on_send(struct hv_vmbus_channel *chan, netvsc_packet *pkt)
* with virtual addresses.
*/
static void
-hv_nv_on_receive(netvsc_dev *net_dev, struct hv_device *device,
+hv_nv_on_receive(netvsc_dev *net_dev, struct hn_softc *sc,
struct hv_vmbus_channel *chan, hv_vm_packet_descriptor *pkt)
{
hv_vm_transfer_page_packet_header *vm_xfer_page_pkt;
nvsp_msg *nvsp_msg_pkt;
netvsc_packet vsc_pkt;
netvsc_packet *net_vsc_pkt = &vsc_pkt;
- device_t dev = device->device;
+ device_t dev = sc->hn_dev;
int count = 0;
int i = 0;
int status = nvsp_status_success;
@@ -911,7 +882,6 @@ hv_nv_on_receive(netvsc_dev *net_dev, struct hv_device *device,
}
count = vm_xfer_page_pkt->range_count;
- net_vsc_pkt->device = device;
/* Each range represents 1 RNDIS pkt that contains 1 Ethernet frame */
for (i = 0; i < count; i++) {
@@ -921,7 +891,7 @@ hv_nv_on_receive(netvsc_dev *net_dev, struct hv_device *device,
net_vsc_pkt->tot_data_buf_len =
vm_xfer_page_pkt->ranges[i].byte_count;
- hv_rf_on_receive(net_dev, device, chan, net_vsc_pkt);
+ hv_rf_on_receive(net_dev, chan, net_vsc_pkt);
if (net_vsc_pkt->status != nvsp_status_success) {
status = nvsp_status_failure;
}
@@ -977,14 +947,14 @@ retry_send_cmplt:
* Net VSC receiving vRSS send table from VSP
*/
static void
-hv_nv_send_table(struct hv_device *device, hv_vm_packet_descriptor *pkt)
+hv_nv_send_table(struct hn_softc *sc, hv_vm_packet_descriptor *pkt)
{
netvsc_dev *net_dev;
nvsp_msg *nvsp_msg_pkt;
int i;
uint32_t count, *table;
- net_dev = hv_nv_get_inbound_net_device(device);
+ net_dev = hv_nv_get_inbound_net_device(sc);
if (!net_dev)
return;
@@ -1020,9 +990,9 @@ static void
hv_nv_on_channel_callback(void *xchan)
{
struct hv_vmbus_channel *chan = xchan;
- struct hv_device *device = chan->device;
+ device_t dev = chan->ch_dev;
+ struct hn_softc *sc = device_get_softc(dev);
netvsc_dev *net_dev;
- device_t dev = device->device;
uint32_t bytes_rxed;
uint64_t request_id;
hv_vm_packet_descriptor *desc;
@@ -1030,7 +1000,7 @@ hv_nv_on_channel_callback(void *xchan)
int bufferlen = NETVSC_PACKET_SIZE;
int ret = 0;
- net_dev = hv_nv_get_inbound_net_device(device);
+ net_dev = hv_nv_get_inbound_net_device(sc);
if (net_dev == NULL)
return;
@@ -1044,14 +1014,14 @@ hv_nv_on_channel_callback(void *xchan)
desc = (hv_vm_packet_descriptor *)buffer;
switch (desc->type) {
case HV_VMBUS_PACKET_TYPE_COMPLETION:
- hv_nv_on_send_completion(net_dev, device,
- chan, desc);
+ hv_nv_on_send_completion(net_dev, chan,
+ desc);
break;
case HV_VMBUS_PACKET_TYPE_DATA_USING_TRANSFER_PAGES:
- hv_nv_on_receive(net_dev, device, chan, desc);
+ hv_nv_on_receive(net_dev, sc, chan, desc);
break;
case HV_VMBUS_PACKET_TYPE_DATA_IN_BAND:
- hv_nv_send_table(device, desc);
+ hv_nv_send_table(sc, desc);
break;
default:
device_printf(dev,
diff --git a/sys/dev/hyperv/netvsc/hv_net_vsc.h b/sys/dev/hyperv/netvsc/hv_net_vsc.h
index 7c43f64..b41dced 100644
--- a/sys/dev/hyperv/netvsc/hv_net_vsc.h
+++ b/sys/dev/hyperv/netvsc/hv_net_vsc.h
@@ -1040,7 +1040,7 @@ typedef struct nvsp_msg_ {
* Per netvsc channel-specific
*/
typedef struct netvsc_dev_ {
- struct hv_device *dev;
+ struct hn_softc *sc;
/* Send buffer allocated by us but manages by NetVSP */
void *send_buf;
@@ -1107,7 +1107,6 @@ typedef void (*pfn_on_send_rx_completion)(struct hv_vmbus_channel *, void *);
#endif
typedef struct netvsc_packet_ {
- struct hv_device *device;
hv_bool_uint8_t is_data_pkt; /* One byte */
uint16_t vlan_tci;
uint32_t status;
@@ -1240,8 +1239,8 @@ typedef struct hn_softc {
int hn_initdone;
/* See hv_netvsc_drv_freebsd.c for rules on how to use */
int temp_unusable;
- struct hv_device *hn_dev_obj;
netvsc_dev *net_dev;
+ struct hv_vmbus_channel *hn_prichan;
int hn_rx_ring_cnt;
int hn_rx_ring_inuse;
@@ -1263,10 +1262,10 @@ typedef struct hn_softc {
*/
extern int hv_promisc_mode;
-void netvsc_linkstatus_callback(struct hv_device *device_obj, uint32_t status);
-netvsc_dev *hv_nv_on_device_add(struct hv_device *device,
+void netvsc_linkstatus_callback(struct hn_softc *sc, uint32_t status);
+netvsc_dev *hv_nv_on_device_add(struct hn_softc *sc,
void *additional_info);
-int hv_nv_on_device_remove(struct hv_device *device,
+int hv_nv_on_device_remove(struct hn_softc *sc,
boolean_t destroy_channel);
int hv_nv_on_send(struct hv_vmbus_channel *chan, netvsc_packet *pkt);
int hv_nv_get_next_send_section(netvsc_dev *net_dev);
diff --git a/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c b/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
index 8f1e1e7..f8b68cb 100644
--- a/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
+++ b/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
@@ -415,18 +415,12 @@ static const hv_guid g_net_vsc_device_type = {
static int
netvsc_probe(device_t dev)
{
- const char *p;
-
- p = vmbus_get_type(dev);
- if (!memcmp(p, &g_net_vsc_device_type.data, sizeof(hv_guid))) {
+ if (VMBUS_PROBE_GUID(device_get_parent(dev), dev,
+ &g_net_vsc_device_type) == 0) {
device_set_desc(dev, "Hyper-V Network Interface");
- if (bootverbose)
- printf("Netvsc probe... DONE \n");
-
- return (BUS_PROBE_DEFAULT);
+ return BUS_PROBE_DEFAULT;
}
-
- return (ENXIO);
+ return ENXIO;
}
static void
@@ -451,8 +445,6 @@ hn_cpuset_setthread_task(void *xmask, int pending __unused)
static int
netvsc_attach(device_t dev)
{
- struct hv_device *device_ctx = vmbus_get_devctx(dev);
- struct hv_vmbus_channel *pri_chan;
netvsc_device_info device_info;
hn_softc_t *sc;
int unit = device_get_unit(dev);
@@ -464,6 +456,7 @@ netvsc_attach(device_t dev)
sc->hn_unit = unit;
sc->hn_dev = dev;
+ sc->hn_prichan = vmbus_get_channel(dev);
if (hn_tx_taskq == NULL) {
sc->hn_tx_taskq = taskqueue_create("hn_tx", M_WAITOK,
@@ -488,8 +481,6 @@ netvsc_attach(device_t dev)
}
NV_LOCK_INIT(sc, "NetVSCLock");
- sc->hn_dev_obj = device_ctx;
-
ifp = sc->hn_ifp = sc->arpcom.ac_ifp = if_alloc(IFT_ETHER);
ifp->if_softc = sc;
if_initname(ifp, device_get_name(dev), device_get_unit(dev));
@@ -532,12 +523,7 @@ netvsc_attach(device_t dev)
/*
* Associate the first TX/RX ring w/ the primary channel.
*/
- pri_chan = device_ctx->channel;
- KASSERT(HV_VMBUS_CHAN_ISPRIMARY(pri_chan), ("not primary channel"));
- KASSERT(pri_chan->ch_subidx == 0,
- ("primary channel subidx %u",
- pri_chan->ch_subidx));
- hn_channel_attach(sc, pri_chan);
+ hn_channel_attach(sc, sc->hn_prichan);
ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
ifp->if_ioctl = hn_ioctl;
@@ -574,7 +560,7 @@ netvsc_attach(device_t dev)
IFCAP_LRO;
ifp->if_hwassist = sc->hn_tx_ring[0].hn_csum_assist | CSUM_TSO;
- error = hv_rf_on_device_add(device_ctx, &device_info, ring_cnt);
+ error = hv_rf_on_device_add(sc, &device_info, ring_cnt);
if (error)
goto failed;
KASSERT(sc->net_dev->num_channel > 0 &&
@@ -644,7 +630,6 @@ static int
netvsc_detach(device_t dev)
{
struct hn_softc *sc = device_get_softc(dev);
- struct hv_device *hv_device = vmbus_get_devctx(dev);
if (bootverbose)
printf("netvsc_detach\n");
@@ -660,7 +645,7 @@ netvsc_detach(device_t dev)
* the netdevice.
*/
- hv_rf_on_device_remove(hv_device, HV_RF_NV_DESTROY_CHANNEL);
+ hv_rf_on_device_remove(sc, HV_RF_NV_DESTROY_CHANNEL);
hn_stop_tx_tasks(sc);
@@ -1224,10 +1209,8 @@ hn_start_locked(struct hn_tx_ring *txr, int len)
* Link up/down notification
*/
void
-netvsc_linkstatus_callback(struct hv_device *device_obj, uint32_t status)
+netvsc_linkstatus_callback(struct hn_softc *sc, uint32_t status)
{
- hn_softc_t *sc = device_get_softc(device_obj->device);
-
if (status == 1) {
sc->hn_carrier = 1;
} else {
@@ -1548,7 +1531,6 @@ hn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
struct ifaddr *ifa = (struct ifaddr *)data;
#endif
netvsc_device_info device_info;
- struct hv_device *hn_dev;
int mask, error = 0;
int retry_cnt = 500;
@@ -1566,8 +1548,6 @@ hn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
error = ether_ioctl(ifp, cmd, data);
break;
case SIOCSIFMTU:
- hn_dev = vmbus_get_devctx(sc->hn_dev);
-
/* Check MTU value change */
if (ifp->if_mtu == ifr->ifr_mtu)
break;
@@ -1614,7 +1594,7 @@ hn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
* MTU to take effect. This includes tearing down, but not
* deleting the channel, then bringing it back up.
*/
- error = hv_rf_on_device_remove(hn_dev, HV_RF_NV_RETAIN_CHANNEL);
+ error = hv_rf_on_device_remove(sc, HV_RF_NV_RETAIN_CHANNEL);
if (error) {
NV_LOCK(sc);
sc->temp_unusable = FALSE;
@@ -1623,9 +1603,9 @@ hn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
}
/* Wait for subchannels to be destroyed */
- vmbus_drain_subchan(hn_dev->channel);
+ vmbus_drain_subchan(sc->hn_prichan);
- error = hv_rf_on_device_add(hn_dev, &device_info,
+ error = hv_rf_on_device_add(sc, &device_info,
sc->hn_rx_ring_inuse);
if (error) {
NV_LOCK(sc);
@@ -1790,7 +1770,6 @@ hn_stop(hn_softc_t *sc)
{
struct ifnet *ifp;
int ret, i;
- struct hv_device *device_ctx = vmbus_get_devctx(sc->hn_dev);
ifp = sc->hn_ifp;
@@ -1805,7 +1784,7 @@ hn_stop(hn_softc_t *sc)
if_link_state_change(ifp, LINK_STATE_DOWN);
sc->hn_initdone = 0;
- ret = hv_rf_on_close(device_ctx);
+ ret = hv_rf_on_close(sc);
}
/*
@@ -1873,7 +1852,6 @@ static void
hn_ifinit_locked(hn_softc_t *sc)
{
struct ifnet *ifp;
- struct hv_device *device_ctx = vmbus_get_devctx(sc->hn_dev);
int ret, i;
ifp = sc->hn_ifp;
@@ -1884,7 +1862,7 @@ hn_ifinit_locked(hn_softc_t *sc)
hv_promisc_mode = 1;
- ret = hv_rf_on_open(device_ctx);
+ ret = hv_rf_on_open(sc);
if (ret != 0) {
return;
} else {
@@ -3046,13 +3024,12 @@ hn_subchan_attach(struct hn_softc *sc, struct hv_vmbus_channel *chan)
static void
hn_subchan_setup(struct hn_softc *sc)
{
- struct hv_device *device_ctx = vmbus_get_devctx(sc->hn_dev);
struct hv_vmbus_channel **subchan;
int subchan_cnt = sc->net_dev->num_channel - 1;
int i;
/* Wait for sub-channels setup to complete. */
- subchan = vmbus_get_subchan(device_ctx->channel, subchan_cnt);
+ subchan = vmbus_get_subchan(sc->hn_prichan, subchan_cnt);
/* Attach the sub-channels. */
for (i = 0; i < subchan_cnt; ++i) {
diff --git a/sys/dev/hyperv/netvsc/hv_rndis_filter.c b/sys/dev/hyperv/netvsc/hv_rndis_filter.c
index 8e95510..3e2c9d9 100644
--- a/sys/dev/hyperv/netvsc/hv_rndis_filter.c
+++ b/sys/dev/hyperv/netvsc/hv_rndis_filter.c
@@ -89,7 +89,7 @@ static int hv_rf_close_device(rndis_device *device);
static void hv_rf_on_send_request_completion(struct hv_vmbus_channel *, void *context);
static void hv_rf_on_send_request_halt_completion(struct hv_vmbus_channel *, void *context);
int
-hv_rf_send_offload_request(struct hv_device *device,
+hv_rf_send_offload_request(struct hn_softc *sc,
rndis_offload_params *offloads);
/*
* Set the Per-Packet-Info with the specified type
@@ -299,7 +299,7 @@ hv_rf_send_request(rndis_device *device, rndis_request *request,
packet->send_buf_section_size = 0;
sendit:
- ret = hv_nv_on_send(device->net_dev->dev->channel, packet);
+ ret = hv_nv_on_send(device->net_dev->sc->hn_prichan, packet);
return (ret);
}
@@ -351,7 +351,7 @@ hv_rf_receive_response(rndis_device *device, rndis_msg *response)
}
int
-hv_rf_send_offload_request(struct hv_device *device,
+hv_rf_send_offload_request(struct hn_softc *sc,
rndis_offload_params *offloads)
{
rndis_request *request;
@@ -359,8 +359,7 @@ hv_rf_send_offload_request(struct hv_device *device,
rndis_offload_params *offload_req;
rndis_set_complete *set_complete;
rndis_device *rndis_dev;
- hn_softc_t *sc = device_get_softc(device->device);
- device_t dev = device->device;
+ device_t dev = sc->hn_dev;
netvsc_dev *net_dev = sc->net_dev;
uint32_t vsp_version = net_dev->nvsp_version;
uint32_t extlen = sizeof(rndis_offload_params);
@@ -437,14 +436,14 @@ hv_rf_receive_indicate_status(rndis_device *device, rndis_msg *response)
switch(indicate->status) {
case RNDIS_STATUS_MEDIA_CONNECT:
- netvsc_linkstatus_callback(device->net_dev->dev, 1);
+ netvsc_linkstatus_callback(device->net_dev->sc, 1);
break;
case RNDIS_STATUS_MEDIA_DISCONNECT:
- netvsc_linkstatus_callback(device->net_dev->dev, 0);
+ netvsc_linkstatus_callback(device->net_dev->sc, 0);
break;
default:
/* TODO: */
- device_printf(device->net_dev->dev->device,
+ device_printf(device->net_dev->sc->hn_dev,
"unknown status %d received\n", indicate->status);
break;
}
@@ -537,7 +536,7 @@ hv_rf_receive_data(rndis_device *device, rndis_msg *message,
{
rndis_packet *rndis_pkt;
uint32_t data_offset;
- device_t dev = device->net_dev->dev->device;
+ device_t dev = device->net_dev->sc->hn_dev;
struct hv_rf_recvinfo info;
rndis_pkt = &message->msg.packet;
@@ -580,7 +579,7 @@ hv_rf_receive_data(rndis_device *device, rndis_msg *message,
* RNDIS filter on receive
*/
int
-hv_rf_on_receive(netvsc_dev *net_dev, struct hv_device *device,
+hv_rf_on_receive(netvsc_dev *net_dev,
struct hv_vmbus_channel *chan, netvsc_packet *pkt)
{
rndis_device *rndis_dev;
@@ -1062,7 +1061,7 @@ hv_rf_close_device(rndis_device *device)
* RNDIS filter on device add
*/
int
-hv_rf_on_device_add(struct hv_device *device, void *additl_info,
+hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
int nchan)
{
int ret;
@@ -1073,7 +1072,7 @@ hv_rf_on_device_add(struct hv_device *device, void *additl_info,
struct rndis_recv_scale_cap rsscaps;
uint32_t rsscaps_size = sizeof(struct rndis_recv_scale_cap);
netvsc_device_info *dev_info = (netvsc_device_info *)additl_info;
- device_t dev = device->device;
+ device_t dev = sc->hn_dev;
rndis_dev = hv_get_rndis_device();
if (rndis_dev == NULL) {
@@ -1086,7 +1085,7 @@ hv_rf_on_device_add(struct hv_device *device, void *additl_info,
* (hv_rf_on_receive()) before this call is completed.
* Note: Earlier code used a function pointer here.
*/
- net_dev = hv_nv_on_device_add(device, additl_info);
+ net_dev = hv_nv_on_device_add(sc, additl_info);
if (!net_dev) {
hv_put_rndis_device(rndis_dev);
@@ -1124,7 +1123,7 @@ hv_rf_on_device_add(struct hv_device *device, void *additl_info,
offloads.udp_ipv6_csum = RNDIS_OFFLOAD_PARAMETERS_TX_RX_ENABLED;
offloads.lso_v2_ipv4 = RNDIS_OFFLOAD_PARAMETERS_LSOV2_ENABLED;
- ret = hv_rf_send_offload_request(device, &offloads);
+ ret = hv_rf_send_offload_request(sc, &offloads);
if (ret != 0) {
/* TODO: shut down rndis device and the channel */
device_printf(dev,
@@ -1171,7 +1170,7 @@ hv_rf_on_device_add(struct hv_device *device, void *additl_info,
init_pkt->msgs.vers_5_msgs.subchannel_request.num_subchannels =
net_dev->num_channel - 1;
- ret = hv_vmbus_channel_send_packet(device->channel, init_pkt,
+ ret = hv_vmbus_channel_send_packet(sc->hn_prichan, init_pkt,
sizeof(nvsp_msg), (uint64_t)(uintptr_t)init_pkt,
HV_VMBUS_PACKET_TYPE_DATA_IN_BAND,
HV_VMBUS_DATA_PACKET_FLAG_COMPLETION_REQUESTED);
@@ -1205,9 +1204,8 @@ out:
* RNDIS filter on device remove
*/
int
-hv_rf_on_device_remove(struct hv_device *device, boolean_t destroy_channel)
+hv_rf_on_device_remove(struct hn_softc *sc, boolean_t destroy_channel)
{
- hn_softc_t *sc = device_get_softc(device->device);
netvsc_dev *net_dev = sc->net_dev;
rndis_device *rndis_dev = (rndis_device *)net_dev->extension;
int ret;
@@ -1219,7 +1217,7 @@ hv_rf_on_device_remove(struct hv_device *device, boolean_t destroy_channel)
net_dev->extension = NULL;
/* Pass control to inner driver to remove the device */
- ret |= hv_nv_on_device_remove(device, destroy_channel);
+ ret |= hv_nv_on_device_remove(sc, destroy_channel);
return (ret);
}
@@ -1228,9 +1226,8 @@ hv_rf_on_device_remove(struct hv_device *device, boolean_t destroy_channel)
* RNDIS filter on open
*/
int
-hv_rf_on_open(struct hv_device *device)
+hv_rf_on_open(struct hn_softc *sc)
{
- hn_softc_t *sc = device_get_softc(device->device);
netvsc_dev *net_dev = sc->net_dev;
return (hv_rf_open_device((rndis_device *)net_dev->extension));
@@ -1240,9 +1237,8 @@ hv_rf_on_open(struct hv_device *device)
* RNDIS filter on close
*/
int
-hv_rf_on_close(struct hv_device *device)
+hv_rf_on_close(struct hn_softc *sc)
{
- hn_softc_t *sc = device_get_softc(device->device);
netvsc_dev *net_dev = sc->net_dev;
return (hv_rf_close_device((rndis_device *)net_dev->extension));
diff --git a/sys/dev/hyperv/netvsc/hv_rndis_filter.h b/sys/dev/hyperv/netvsc/hv_rndis_filter.h
index dbaaa42..2d97a09 100644
--- a/sys/dev/hyperv/netvsc/hv_rndis_filter.h
+++ b/sys/dev/hyperv/netvsc/hv_rndis_filter.h
@@ -111,15 +111,16 @@ typedef struct rndis_device_ {
* Externs
*/
struct hv_vmbus_channel;
+struct hn_softc;
-int hv_rf_on_receive(netvsc_dev *net_dev, struct hv_device *device,
+int hv_rf_on_receive(netvsc_dev *net_dev,
struct hv_vmbus_channel *chan, netvsc_packet *pkt);
void hv_rf_receive_rollup(netvsc_dev *net_dev);
void hv_rf_channel_rollup(struct hv_vmbus_channel *chan);
-int hv_rf_on_device_add(struct hv_device *device, void *additl_info, int nchan);
-int hv_rf_on_device_remove(struct hv_device *device, boolean_t destroy_channel);
-int hv_rf_on_open(struct hv_device *device);
-int hv_rf_on_close(struct hv_device *device);
+int hv_rf_on_device_add(struct hn_softc *sc, void *additl_info, int nchan);
+int hv_rf_on_device_remove(struct hn_softc *sc, boolean_t destroy_channel);
+int hv_rf_on_open(struct hn_softc *sc);
+int hv_rf_on_close(struct hn_softc *sc);
#endif /* __HV_RNDIS_FILTER_H__ */
OpenPOWER on IntegriCloud