hyperv/hn: Get rid of netvsc_dev
MFC after: 1 week Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D7575
This commit is contained in:
parent
fdd6031b04
commit
ef56e63fb3
@ -68,7 +68,7 @@ static void hv_nv_on_send_completion(struct hn_softc *sc,
|
||||
struct vmbus_channel *, const struct vmbus_chanpkt_hdr *pkt);
|
||||
static void hv_nv_on_receive_completion(struct vmbus_channel *chan,
|
||||
uint64_t tid);
|
||||
static void hv_nv_on_receive(netvsc_dev *net_dev,
|
||||
static void hv_nv_on_receive(struct hn_softc *sc,
|
||||
struct hn_rx_ring *rxr, struct vmbus_channel *chan,
|
||||
const struct vmbus_chanpkt_hdr *pkt);
|
||||
static void hn_nvs_sent_none(struct hn_send_ctx *sndc,
|
||||
@ -78,40 +78,6 @@ static void hn_nvs_sent_none(struct hn_send_ctx *sndc,
|
||||
static struct hn_send_ctx hn_send_ctx_none =
|
||||
HN_SEND_CTX_INITIALIZER(hn_nvs_sent_none, NULL);
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
static inline netvsc_dev *
|
||||
hv_nv_alloc_net_device(struct hn_softc *sc)
|
||||
{
|
||||
netvsc_dev *net_dev;
|
||||
|
||||
net_dev = malloc(sizeof(netvsc_dev), M_NETVSC, M_WAITOK | M_ZERO);
|
||||
|
||||
net_dev->sc = sc;
|
||||
sc->net_dev = net_dev;
|
||||
|
||||
return (net_dev);
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX unnecessary; nuke it.
|
||||
*/
|
||||
static inline netvsc_dev *
|
||||
hv_nv_get_outbound_net_device(struct hn_softc *sc)
|
||||
{
|
||||
return sc->net_dev;
|
||||
}
|
||||
|
||||
/*
|
||||
* XXX unnecessary; nuke it.
|
||||
*/
|
||||
static inline netvsc_dev *
|
||||
hv_nv_get_inbound_net_device(struct hn_softc *sc)
|
||||
{
|
||||
return sc->net_dev;
|
||||
}
|
||||
|
||||
uint32_t
|
||||
hn_chim_alloc(struct hn_softc *sc)
|
||||
{
|
||||
@ -451,8 +417,7 @@ hv_nv_destroy_send_buffer(struct hn_softc *sc)
|
||||
}
|
||||
|
||||
static int
|
||||
hv_nv_negotiate_nvsp_protocol(struct hn_softc *sc, netvsc_dev *net_dev,
|
||||
uint32_t nvs_ver)
|
||||
hv_nv_negotiate_nvsp_protocol(struct hn_softc *sc, uint32_t nvs_ver)
|
||||
{
|
||||
struct hn_send_ctx sndc;
|
||||
struct vmbus_xact *xact;
|
||||
@ -540,7 +505,6 @@ hv_nv_send_ndis_config(struct hn_softc *sc, uint32_t mtu)
|
||||
static int
|
||||
hv_nv_connect_to_vsp(struct hn_softc *sc)
|
||||
{
|
||||
netvsc_dev *net_dev;
|
||||
uint32_t protocol_list[] = { NVSP_PROTOCOL_VERSION_1,
|
||||
NVSP_PROTOCOL_VERSION_2,
|
||||
NVSP_PROTOCOL_VERSION_4,
|
||||
@ -553,14 +517,11 @@ hv_nv_connect_to_vsp(struct hn_softc *sc)
|
||||
struct hn_nvs_ndis_init ndis;
|
||||
int rxbuf_size;
|
||||
|
||||
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(sc, net_dev,
|
||||
protocol_list[i]) == 0) {
|
||||
if (hv_nv_negotiate_nvsp_protocol(sc, protocol_list[i]) == 0) {
|
||||
sc->hn_nvs_ver = protocol_list[i];
|
||||
if (bootverbose) {
|
||||
device_printf(dev, "NVS version 0x%x\n",
|
||||
@ -644,20 +605,12 @@ hv_nv_subchan_attach(struct vmbus_channel *chan, struct hn_rx_ring *rxr)
|
||||
*
|
||||
* Callback when the device belonging to this driver is added
|
||||
*/
|
||||
netvsc_dev *
|
||||
hv_nv_on_device_add(struct hn_softc *sc, void *additional_info,
|
||||
struct hn_rx_ring *rxr)
|
||||
int
|
||||
hv_nv_on_device_add(struct hn_softc *sc, struct hn_rx_ring *rxr)
|
||||
{
|
||||
struct vmbus_channel *chan = sc->hn_prichan;
|
||||
netvsc_dev *net_dev;
|
||||
int ret = 0;
|
||||
|
||||
net_dev = hv_nv_alloc_net_device(sc);
|
||||
if (net_dev == NULL)
|
||||
return NULL;
|
||||
|
||||
/* Initialize the NetVSC channel extension */
|
||||
|
||||
/*
|
||||
* Open the channel
|
||||
*/
|
||||
@ -677,20 +630,13 @@ hv_nv_on_device_add(struct hn_softc *sc, void *additional_info,
|
||||
if (ret != 0)
|
||||
goto close;
|
||||
|
||||
return (net_dev);
|
||||
return (0);
|
||||
|
||||
close:
|
||||
/* Now, we can close the channel safely */
|
||||
vmbus_chan_close(chan);
|
||||
|
||||
cleanup:
|
||||
/*
|
||||
* Free the packet buffers on the netvsc device packet queue.
|
||||
* Release other resources.
|
||||
*/
|
||||
free(net_dev, M_NETVSC);
|
||||
|
||||
return (NULL);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
@ -706,8 +652,6 @@ hv_nv_on_device_remove(struct hn_softc *sc, boolean_t destroy_channel)
|
||||
|
||||
vmbus_chan_close(sc->hn_prichan);
|
||||
|
||||
free(sc->net_dev, M_NETVSC);
|
||||
|
||||
return (0);
|
||||
}
|
||||
|
||||
@ -801,7 +745,7 @@ hv_nv_on_send(struct vmbus_channel *chan, uint32_t rndis_mtype,
|
||||
* with virtual addresses.
|
||||
*/
|
||||
static void
|
||||
hv_nv_on_receive(netvsc_dev *net_dev, struct hn_rx_ring *rxr,
|
||||
hv_nv_on_receive(struct hn_softc *sc, struct hn_rx_ring *rxr,
|
||||
struct vmbus_channel *chan, const struct vmbus_chanpkt_hdr *pkthdr)
|
||||
{
|
||||
const struct vmbus_chanpkt_rxbuf *pkt;
|
||||
@ -829,7 +773,7 @@ hv_nv_on_receive(netvsc_dev *net_dev, struct hn_rx_ring *rxr,
|
||||
|
||||
/* Each range represents 1 RNDIS pkt that contains 1 Ethernet frame */
|
||||
for (i = 0; i < count; i++) {
|
||||
hv_rf_on_receive(net_dev, rxr,
|
||||
hv_rf_on_receive(sc, rxr,
|
||||
rxr->hn_rxbuf + pkt->cp_rxbuf[i].rb_ofs,
|
||||
pkt->cp_rxbuf[i].rb_len);
|
||||
}
|
||||
@ -896,14 +840,9 @@ hv_nv_on_channel_callback(struct vmbus_channel *chan, void *xrxr)
|
||||
{
|
||||
struct hn_rx_ring *rxr = xrxr;
|
||||
struct hn_softc *sc = rxr->hn_ifp->if_softc;
|
||||
netvsc_dev *net_dev;
|
||||
void *buffer;
|
||||
int bufferlen = NETVSC_PACKET_SIZE;
|
||||
|
||||
net_dev = hv_nv_get_inbound_net_device(sc);
|
||||
if (net_dev == NULL)
|
||||
return;
|
||||
|
||||
buffer = rxr->hn_rdbuf;
|
||||
do {
|
||||
struct vmbus_chanpkt_hdr *pkt = buffer;
|
||||
@ -919,7 +858,7 @@ hv_nv_on_channel_callback(struct vmbus_channel *chan, void *xrxr)
|
||||
hv_nv_on_send_completion(sc, chan, pkt);
|
||||
break;
|
||||
case VMBUS_CHANPKT_TYPE_RXBUF:
|
||||
hv_nv_on_receive(net_dev, rxr, chan, pkt);
|
||||
hv_nv_on_receive(sc, rxr, chan, pkt);
|
||||
break;
|
||||
case VMBUS_CHANPKT_TYPE_INBAND:
|
||||
hn_proc_notify(sc, pkt);
|
||||
|
@ -212,15 +212,6 @@ typedef struct rndis_recv_scale_param_ {
|
||||
* Data types
|
||||
*/
|
||||
|
||||
/*
|
||||
* Per netvsc channel-specific
|
||||
*/
|
||||
typedef struct netvsc_dev_ {
|
||||
struct hn_softc *sc;
|
||||
/* Holds rndis device info */
|
||||
void *extension;
|
||||
} netvsc_dev;
|
||||
|
||||
struct vmbus_channel;
|
||||
|
||||
typedef void (*pfn_on_send_rx_completion)(struct vmbus_channel *, void *);
|
||||
@ -353,7 +344,7 @@ typedef struct hn_softc {
|
||||
int hn_initdone;
|
||||
/* See hv_netvsc_drv_freebsd.c for rules on how to use */
|
||||
int temp_unusable;
|
||||
netvsc_dev *net_dev;
|
||||
struct rndis_device_ *rndis_dev;
|
||||
struct vmbus_channel *hn_prichan;
|
||||
|
||||
int hn_rx_ring_cnt;
|
||||
@ -396,8 +387,7 @@ extern int hv_promisc_mode;
|
||||
struct hn_send_ctx;
|
||||
|
||||
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, struct hn_rx_ring *rxr);
|
||||
int hv_nv_on_device_add(struct hn_softc *sc, struct hn_rx_ring *rxr);
|
||||
int hv_nv_on_device_remove(struct hn_softc *sc,
|
||||
boolean_t destroy_channel);
|
||||
int hv_nv_on_send(struct vmbus_channel *chan, uint32_t rndis_mtype,
|
||||
|
@ -240,7 +240,7 @@ static int
|
||||
hv_rf_send_request(rndis_device *device, rndis_request *request,
|
||||
uint32_t message_type)
|
||||
{
|
||||
struct hn_softc *sc = device->net_dev->sc;
|
||||
struct hn_softc *sc = device->sc;
|
||||
uint32_t send_buf_section_idx, tot_data_buf_len;
|
||||
struct vmbus_gpa gpa[2];
|
||||
int gpa_cnt, send_buf_section_size;
|
||||
@ -346,9 +346,8 @@ hv_rf_send_offload_request(struct hn_softc *sc,
|
||||
rndis_set_request *set;
|
||||
rndis_offload_params *offload_req;
|
||||
rndis_set_complete *set_complete;
|
||||
rndis_device *rndis_dev;
|
||||
rndis_device *rndis_dev = sc->rndis_dev;
|
||||
device_t dev = sc->hn_dev;
|
||||
netvsc_dev *net_dev = sc->net_dev;
|
||||
uint32_t extlen = sizeof(rndis_offload_params);
|
||||
int ret;
|
||||
|
||||
@ -361,8 +360,6 @@ hv_rf_send_offload_request(struct hn_softc *sc,
|
||||
offloads->udp_ipv6_csum = 0;
|
||||
}
|
||||
|
||||
rndis_dev = net_dev->extension;
|
||||
|
||||
request = hv_rndis_request(rndis_dev, REMOTE_NDIS_SET_MSG,
|
||||
RNDIS_MESSAGE_SIZE(rndis_set_request) + extlen);
|
||||
if (!request)
|
||||
@ -423,14 +420,14 @@ hv_rf_receive_indicate_status(rndis_device *device, const rndis_msg *response)
|
||||
|
||||
switch(indicate->status) {
|
||||
case RNDIS_STATUS_MEDIA_CONNECT:
|
||||
netvsc_linkstatus_callback(device->net_dev->sc, 1);
|
||||
netvsc_linkstatus_callback(device->sc, 1);
|
||||
break;
|
||||
case RNDIS_STATUS_MEDIA_DISCONNECT:
|
||||
netvsc_linkstatus_callback(device->net_dev->sc, 0);
|
||||
netvsc_linkstatus_callback(device->sc, 0);
|
||||
break;
|
||||
default:
|
||||
/* TODO: */
|
||||
device_printf(device->net_dev->sc->hn_dev,
|
||||
device_printf(device->sc->hn_dev,
|
||||
"unknown status %d received\n", indicate->status);
|
||||
break;
|
||||
}
|
||||
@ -557,17 +554,13 @@ hv_rf_receive_data(struct hn_rx_ring *rxr, const void *data, int dlen)
|
||||
* RNDIS filter on receive
|
||||
*/
|
||||
int
|
||||
hv_rf_on_receive(netvsc_dev *net_dev,
|
||||
struct hn_rx_ring *rxr, const void *data, int dlen)
|
||||
hv_rf_on_receive(struct hn_softc *sc, struct hn_rx_ring *rxr,
|
||||
const void *data, int dlen)
|
||||
{
|
||||
rndis_device *rndis_dev;
|
||||
const rndis_msg *rndis_hdr;
|
||||
|
||||
/* Make sure the rndis device state is initialized */
|
||||
if (net_dev->extension == NULL)
|
||||
return (ENODEV);
|
||||
|
||||
rndis_dev = (rndis_device *)net_dev->extension;
|
||||
rndis_dev = sc->rndis_dev;
|
||||
if (rndis_dev->state == RNDIS_DEV_UNINITIALIZED)
|
||||
return (EINVAL);
|
||||
|
||||
@ -1039,7 +1032,6 @@ hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
|
||||
{
|
||||
struct hn_send_ctx sndc;
|
||||
int ret;
|
||||
netvsc_dev *net_dev;
|
||||
rndis_device *rndis_dev;
|
||||
rndis_offload_params offloads;
|
||||
struct rndis_recv_scale_cap rsscaps;
|
||||
@ -1057,6 +1049,8 @@ hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
|
||||
if (rndis_dev == NULL) {
|
||||
return (ENOMEM);
|
||||
}
|
||||
sc->rndis_dev = rndis_dev;
|
||||
rndis_dev->sc = sc;
|
||||
|
||||
/*
|
||||
* Let the inner driver handle this first to create the netvsc channel
|
||||
@ -1064,20 +1058,16 @@ hv_rf_on_device_add(struct hn_softc *sc, 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(sc, additl_info, rxr);
|
||||
if (!net_dev) {
|
||||
ret = hv_nv_on_device_add(sc, rxr);
|
||||
if (ret != 0) {
|
||||
hv_put_rndis_device(rndis_dev);
|
||||
|
||||
return (ENOMEM);
|
||||
return (ret);
|
||||
}
|
||||
|
||||
/*
|
||||
* Initialize the rndis device
|
||||
*/
|
||||
|
||||
net_dev->extension = rndis_dev;
|
||||
rndis_dev->net_dev = net_dev;
|
||||
|
||||
/* Send the rndis initialization message */
|
||||
ret = hv_rf_init_device(rndis_dev);
|
||||
if (ret != 0) {
|
||||
@ -1208,15 +1198,14 @@ hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
|
||||
int
|
||||
hv_rf_on_device_remove(struct hn_softc *sc, boolean_t destroy_channel)
|
||||
{
|
||||
netvsc_dev *net_dev = sc->net_dev;
|
||||
rndis_device *rndis_dev = (rndis_device *)net_dev->extension;
|
||||
rndis_device *rndis_dev = sc->rndis_dev;
|
||||
int ret;
|
||||
|
||||
/* Halt and release the rndis device */
|
||||
ret = hv_rf_halt_device(rndis_dev);
|
||||
|
||||
sc->rndis_dev = NULL;
|
||||
hv_put_rndis_device(rndis_dev);
|
||||
net_dev->extension = NULL;
|
||||
|
||||
/* Pass control to inner driver to remove the device */
|
||||
ret |= hv_nv_on_device_remove(sc, destroy_channel);
|
||||
@ -1230,9 +1219,8 @@ hv_rf_on_device_remove(struct hn_softc *sc, boolean_t destroy_channel)
|
||||
int
|
||||
hv_rf_on_open(struct hn_softc *sc)
|
||||
{
|
||||
netvsc_dev *net_dev = sc->net_dev;
|
||||
|
||||
return (hv_rf_open_device((rndis_device *)net_dev->extension));
|
||||
return (hv_rf_open_device(sc->rndis_dev));
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1241,9 +1229,8 @@ hv_rf_on_open(struct hn_softc *sc)
|
||||
int
|
||||
hv_rf_on_close(struct hn_softc *sc)
|
||||
{
|
||||
netvsc_dev *net_dev = sc->net_dev;
|
||||
|
||||
return (hv_rf_close_device((rndis_device *)net_dev->extension));
|
||||
return (hv_rf_close_device(sc->rndis_dev));
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -96,7 +96,7 @@ typedef struct rndis_request_ {
|
||||
} rndis_request;
|
||||
|
||||
typedef struct rndis_device_ {
|
||||
netvsc_dev *net_dev;
|
||||
struct hn_softc *sc;
|
||||
|
||||
rndis_device_state state;
|
||||
uint32_t link_status;
|
||||
@ -112,12 +112,10 @@ typedef struct rndis_device_ {
|
||||
/*
|
||||
* Externs
|
||||
*/
|
||||
struct hn_softc;
|
||||
struct hn_rx_ring;
|
||||
|
||||
int hv_rf_on_receive(netvsc_dev *net_dev, struct hn_rx_ring *rxr,
|
||||
int hv_rf_on_receive(struct hn_softc *sc, struct hn_rx_ring *rxr,
|
||||
const void *data, int dlen);
|
||||
void hv_rf_receive_rollup(netvsc_dev *net_dev);
|
||||
void hv_rf_channel_rollup(struct hn_rx_ring *rxr, struct hn_tx_ring *txr);
|
||||
int hv_rf_on_device_add(struct hn_softc *sc, void *additl_info, int *nchan,
|
||||
struct hn_rx_ring *rxr);
|
||||
|
Loading…
Reference in New Issue
Block a user