hyperv/hn: Remove the useless rndis_device and related bits

MFC after:	1 week
Sponsored by:	Microsoft
Differential Revision:	https://reviews.freebsd.org/D7687
This commit is contained in:
Sepherosa Ziehau 2016-08-30 05:21:34 +00:00
parent 574e2cdce7
commit ecb735a3ac
5 changed files with 44 additions and 223 deletions

View file

@ -641,7 +641,7 @@ cleanup:
* Net VSC on device remove
*/
int
hv_nv_on_device_remove(struct hn_softc *sc, boolean_t destroy_channel)
hv_nv_on_device_remove(struct hn_softc *sc)
{
hv_nv_disconnect_from_vsp(sc);

View file

@ -237,8 +237,8 @@ typedef void (*pfn_on_send_rx_completion)(struct vmbus_channel *, void *);
#define TRANSPORT_TYPE_IPV6_UDP ((TYPE_IPV6 << 16) | TYPE_UDP)
typedef struct {
uint8_t mac_addr[6]; /* Assumption unsigned long */
uint8_t link_state;
uint8_t mac_addr[ETHER_ADDR_LEN];
uint32_t link_state;
} netvsc_device_info;
#define HN_XACT_REQ_PGCNT 2
@ -351,7 +351,6 @@ typedef struct hn_softc {
int hn_initdone;
/* See hv_netvsc_drv_freebsd.c for rules on how to use */
int temp_unusable;
struct rndis_device_ *rndis_dev;
struct vmbus_channel *hn_prichan;
int hn_rx_ring_cnt;
@ -400,8 +399,7 @@ struct hn_send_ctx;
void netvsc_linkstatus_callback(struct hn_softc *sc, uint32_t status);
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_device_remove(struct hn_softc *sc);
int hv_nv_on_send(struct vmbus_channel *chan, uint32_t rndis_mtype,
struct hn_send_ctx *sndc, struct vmbus_gpa *gpa, int gpa_cnt);
void hv_nv_subchan_attach(struct vmbus_channel *chan,

View file

@ -154,8 +154,8 @@ __FBSDID("$FreeBSD$");
#define HN_TX_DATA_BOUNDARY PAGE_SIZE
#define HN_TX_DATA_MAXSIZE IP_MAXPACKET
#define HN_TX_DATA_SEGSIZE PAGE_SIZE
#define HN_TX_DATA_SEGCNT_MAX \
(NETVSC_PACKET_MAXPAGE - HV_RF_NUM_TX_RESERVED_PAGE_BUFS)
/* -1 for RNDIS packet message */
#define HN_TX_DATA_SEGCNT_MAX (NETVSC_PACKET_MAXPAGE - 1)
#define HN_DIRECT_TX_SIZE_DEF 128
@ -651,7 +651,7 @@ netvsc_detach(device_t dev)
* the netdevice.
*/
hv_rf_on_device_remove(sc, HV_RF_NV_DESTROY_CHANNEL);
hv_rf_on_device_remove(sc);
hn_stop_tx_tasks(sc);
@ -1029,7 +1029,8 @@ hn_encap(struct hn_tx_ring *txr, struct hn_txdesc *txd, struct mbuf **m_head0)
}
*m_head0 = m_head;
txr->hn_gpa_cnt = nsegs + HV_RF_NUM_TX_RESERVED_PAGE_BUFS;
/* +1 RNDIS packet message */
txr->hn_gpa_cnt = nsegs + 1;
/* send packet with page buffer */
txr->hn_gpa[0].gpa_page = atop(txd->rndis_msg_paddr);
@ -1037,12 +1038,11 @@ hn_encap(struct hn_tx_ring *txr, struct hn_txdesc *txd, struct mbuf **m_head0)
txr->hn_gpa[0].gpa_len = rndis_msg_size;
/*
* Fill the page buffers with mbuf info starting at index
* HV_RF_NUM_TX_RESERVED_PAGE_BUFS.
* Fill the page buffers with mbuf info after the page
* buffer for RNDIS packet message.
*/
for (i = 0; i < nsegs; ++i) {
struct vmbus_gpa *gpa = &txr->hn_gpa[
i + HV_RF_NUM_TX_RESERVED_PAGE_BUFS];
struct vmbus_gpa *gpa = &txr->hn_gpa[i + 1];
gpa->gpa_page = atop(segs[i].ds_addr);
gpa->gpa_ofs = segs[i].ds_addr & PAGE_MASK;
@ -1576,7 +1576,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(sc, HV_RF_NV_RETAIN_CHANNEL);
error = hv_rf_on_device_remove(sc);
if (error) {
NV_LOCK(sc);
sc->temp_unusable = FALSE;

View file

@ -71,15 +71,14 @@ __FBSDID("$FreeBSD$");
/*
* Forward declarations
*/
static void hv_rf_receive_response(rndis_device *device,
const rndis_msg *response);
static void hv_rf_receive_indicate_status(rndis_device *device,
static void hv_rf_receive_indicate_status(struct hn_softc *sc,
const rndis_msg *response);
static void hv_rf_receive_data(struct hn_rx_ring *rxr,
const void *data, int dlen);
static inline int hv_rf_query_device_mac(rndis_device *device);
static inline int hv_rf_query_device_link_status(rndis_device *device);
static int hv_rf_init_device(rndis_device *device);
static int hv_rf_query_device_mac(struct hn_softc *sc, uint8_t *eaddr);
static int hv_rf_query_device_link_status(struct hn_softc *sc,
uint32_t *link_status);
static int hv_rf_init_device(struct hn_softc *sc);
static int hn_rndis_query(struct hn_softc *sc, uint32_t oid,
const void *idata, size_t idlen, void *odata, size_t *odlen0);
@ -157,94 +156,24 @@ hv_get_ppi_data(rndis_packet *rpkt, uint32_t type)
return (NULL);
}
/*
* Allow module_param to work and override to switch to promiscuous mode.
*/
static inline rndis_device *
hv_get_rndis_device(void)
{
rndis_device *device;
device = malloc(sizeof(rndis_device), M_NETVSC, M_WAITOK | M_ZERO);
mtx_init(&device->req_lock, "HV-FRL", NULL, MTX_DEF);
/* Same effect as STAILQ_HEAD_INITIALIZER() static initializer */
STAILQ_INIT(&device->myrequest_list);
device->state = RNDIS_DEV_UNINITIALIZED;
return (device);
}
/*
*
*/
static inline void
hv_put_rndis_device(rndis_device *device)
{
mtx_destroy(&device->req_lock);
free(device, M_NETVSC);
}
/*
* RNDIS filter receive response
*/
static void
hv_rf_receive_response(rndis_device *device, const rndis_msg *response)
{
rndis_request *request = NULL;
rndis_request *next_request;
boolean_t found = FALSE;
mtx_lock(&device->req_lock);
request = STAILQ_FIRST(&device->myrequest_list);
while (request != NULL) {
/*
* All request/response message contains request_id as the
* first field
*/
if (request->request_msg.msg.init_request.request_id ==
response->msg.init_complete.request_id) {
found = TRUE;
break;
}
next_request = STAILQ_NEXT(request, mylist_entry);
request = next_request;
}
mtx_unlock(&device->req_lock);
if (found) {
if (response->msg_len <= sizeof(rndis_msg)) {
memcpy(&request->response_msg, response,
response->msg_len);
} else {
request->response_msg.msg.init_complete.status =
RNDIS_STATUS_BUFFER_OVERFLOW;
}
sema_post(&request->wait_sema);
}
}
/*
* RNDIS filter receive indicate status
*/
static void
hv_rf_receive_indicate_status(rndis_device *device, const rndis_msg *response)
hv_rf_receive_indicate_status(struct hn_softc *sc, const rndis_msg *response)
{
const rndis_indicate_status *indicate = &response->msg.indicate_status;
switch(indicate->status) {
case RNDIS_STATUS_MEDIA_CONNECT:
netvsc_linkstatus_callback(device->sc, 1);
netvsc_linkstatus_callback(sc, 1);
break;
case RNDIS_STATUS_MEDIA_DISCONNECT:
netvsc_linkstatus_callback(device->sc, 0);
netvsc_linkstatus_callback(sc, 0);
break;
default:
/* TODO: */
device_printf(device->sc->hn_dev,
if_printf(sc->hn_ifp,
"unknown status %d received\n", indicate->status);
break;
}
@ -374,14 +303,9 @@ int
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;
const struct rndis_comp_hdr *comp;
rndis_dev = sc->rndis_dev;
if (rndis_dev->state == RNDIS_DEV_UNINITIALIZED)
return (EINVAL);
rndis_hdr = data;
switch (rndis_hdr->ndis_msg_type) {
/* data message */
@ -395,17 +319,14 @@ hv_rf_on_receive(struct hn_softc *sc, struct hn_rx_ring *rxr,
case REMOTE_NDIS_SET_CMPLT:
case REMOTE_NDIS_KEEPALIVE_CMPLT:
comp = data;
if (comp->rm_rid <= HN_RNDIS_RID_COMPAT_MAX) {
/* Transition time compat code */
hv_rf_receive_response(rndis_dev, rndis_hdr);
} else {
vmbus_xact_ctx_wakeup(sc->hn_xact, data, dlen);
}
KASSERT(comp->rm_rid > HN_RNDIS_RID_COMPAT_MAX,
("invalid rid 0x%08x\n", comp->rm_rid));
vmbus_xact_ctx_wakeup(sc->hn_xact, comp, dlen);
break;
/* notification message */
case REMOTE_NDIS_INDICATE_STATUS_MSG:
hv_rf_receive_indicate_status(rndis_dev, rndis_hdr);
hv_rf_receive_indicate_status(sc, rndis_hdr);
break;
case REMOTE_NDIS_RESET_CMPLT:
@ -431,19 +352,18 @@ hv_rf_on_receive(struct hn_softc *sc, struct hn_rx_ring *rxr,
* RNDIS filter query device MAC address
*/
static int
hv_rf_query_device_mac(rndis_device *device)
hv_rf_query_device_mac(struct hn_softc *sc, uint8_t *eaddr)
{
struct hn_softc *sc = device->sc;
size_t hwaddr_len;
size_t eaddr_len;
int error;
hwaddr_len = ETHER_ADDR_LEN;
eaddr_len = ETHER_ADDR_LEN;
error = hn_rndis_query(sc, OID_802_3_PERMANENT_ADDRESS, NULL, 0,
device->hw_mac_addr, &hwaddr_len);
eaddr, &eaddr_len);
if (error)
return (error);
if (hwaddr_len != ETHER_ADDR_LEN) {
if_printf(sc->hn_ifp, "invalid hwaddr len %zu\n", hwaddr_len);
if (eaddr_len != ETHER_ADDR_LEN) {
if_printf(sc->hn_ifp, "invalid eaddr len %zu\n", eaddr_len);
return (EINVAL);
}
return (0);
@ -452,16 +372,15 @@ hv_rf_query_device_mac(rndis_device *device)
/*
* RNDIS filter query device link status
*/
static inline int
hv_rf_query_device_link_status(rndis_device *device)
static int
hv_rf_query_device_link_status(struct hn_softc *sc, uint32_t *link_status)
{
struct hn_softc *sc = device->sc;
size_t size;
int error;
size = sizeof(uint32_t);
size = sizeof(*link_status);
error = hn_rndis_query(sc, OID_GEN_MEDIA_CONNECT_STATUS, NULL, 0,
&device->link_status, &size);
link_status, &size);
if (error)
return (error);
if (size != sizeof(uint32_t)) {
@ -875,9 +794,8 @@ hn_rndis_set_rxfilter(struct hn_softc *sc, uint32_t filter)
* RNDIS filter init device
*/
static int
hv_rf_init_device(rndis_device *device)
hv_rf_init_device(struct hn_softc *sc)
{
struct hn_softc *sc = device->sc;
struct rndis_init_req *req;
const struct rndis_init_comp *comp;
struct vmbus_xact *xact;
@ -885,9 +803,6 @@ hv_rf_init_device(rndis_device *device)
uint32_t rid;
int error;
/* XXX */
device->state = RNDIS_DEV_INITIALIZED;
xact = vmbus_xact_get(sc->hn_xact, sizeof(*req));
if (xact == NULL) {
if_printf(sc->hn_ifp, "no xact for RNDIS init\n");
@ -969,7 +884,6 @@ hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
int *nchan0, struct hn_rx_ring *rxr)
{
int ret;
rndis_device *rndis_dev;
netvsc_device_info *dev_info = (netvsc_device_info *)additl_info;
device_t dev = sc->hn_dev;
struct hn_nvs_subch_req *req;
@ -980,13 +894,6 @@ hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
int nchan = *nchan0;
int rxr_cnt;
rndis_dev = hv_get_rndis_device();
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
* NOTE! Once the channel is created, we may get a receive callback
@ -994,17 +901,15 @@ hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
* Note: Earlier code used a function pointer here.
*/
ret = hv_nv_on_device_add(sc, rxr);
if (ret != 0) {
hv_put_rndis_device(rndis_dev);
if (ret != 0)
return (ret);
}
/*
* Initialize the rndis device
*/
/* Send the rndis initialization message */
ret = hv_rf_init_device(rndis_dev);
ret = hv_rf_init_device(sc);
if (ret != 0) {
/*
* TODO: If rndis init failed, we will need to shut down
@ -1013,19 +918,15 @@ hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
}
/* Get the mac address */
ret = hv_rf_query_device_mac(rndis_dev);
ret = hv_rf_query_device_mac(sc, dev_info->mac_addr);
if (ret != 0) {
/* TODO: shut down rndis device and the channel */
}
/* Configure NDIS offload settings */
hn_rndis_conf_offload(sc);
memcpy(dev_info->mac_addr, rndis_dev->hw_mac_addr, ETHER_ADDR_LEN);
hv_rf_query_device_link_status(rndis_dev);
dev_info->link_state = rndis_dev->link_status;
hv_rf_query_device_link_status(sc, &dev_info->link_state);
if (sc->hn_ndis_ver < NDIS_VERSION_6_30 || nchan == 1) {
/*
@ -1121,19 +1022,15 @@ out:
* RNDIS filter on device remove
*/
int
hv_rf_on_device_remove(struct hn_softc *sc, boolean_t destroy_channel)
hv_rf_on_device_remove(struct hn_softc *sc)
{
rndis_device *rndis_dev = sc->rndis_dev;
int ret;
/* Halt and release the rndis device */
ret = hv_rf_halt_device(sc);
sc->rndis_dev = NULL;
hv_put_rndis_device(rndis_dev);
/* Pass control to inner driver to remove the device */
ret |= hv_nv_on_device_remove(sc, destroy_channel);
ret |= hv_nv_on_device_remove(sc);
return (ret);
}

View file

@ -35,80 +35,6 @@
#include <net/ethernet.h>
#include <dev/hyperv/netvsc/if_hnvar.h>
/*
* Defines
*/
/* Destroy or preserve channel on filter/netvsc teardown */
#define HV_RF_NV_DESTROY_CHANNEL TRUE
#define HV_RF_NV_RETAIN_CHANNEL FALSE
/*
* Number of page buffers to reserve for the RNDIS filter packet in the
* transmitted message.
*/
#define HV_RF_NUM_TX_RESERVED_PAGE_BUFS 1
/*
* Data types
*/
typedef enum {
RNDIS_DEV_UNINITIALIZED = 0,
RNDIS_DEV_INITIALIZING,
RNDIS_DEV_INITIALIZED,
RNDIS_DEV_DATAINITIALIZED,
} rndis_device_state;
typedef struct rndis_request_ {
STAILQ_ENTRY(rndis_request_) mylist_entry;
struct sema wait_sema;
/*
* The max response size is sizeof(rndis_msg) + PAGE_SIZE.
*
* XXX
* This is ugly and should be cleaned up once we busdma-fy
* RNDIS request bits.
*/
rndis_msg response_msg;
uint8_t buf_resp[PAGE_SIZE];
/* Simplify allocation by having a netvsc packet inline */
struct hn_send_ctx send_ctx;
/*
* The max request size is sizeof(rndis_msg) + PAGE_SIZE.
*
* NOTE:
* This is required for the large request like RSS settings.
*
* XXX
* This is ugly and should be cleaned up once we busdma-fy
* RNDIS request bits.
*/
rndis_msg request_msg;
uint8_t buf_req[PAGE_SIZE];
/* Fixme: Poor man's semaphore. */
uint32_t halt_complete_flag;
} rndis_request;
typedef struct rndis_device_ {
struct hn_softc *sc;
rndis_device_state state;
uint32_t link_status;
uint32_t new_request_id;
struct mtx req_lock;
STAILQ_HEAD(RQ, rndis_request_) myrequest_list;
uint8_t hw_mac_addr[ETHER_ADDR_LEN];
} rndis_device;
/*
* Externs
*/
@ -119,7 +45,7 @@ int hv_rf_on_receive(struct hn_softc *sc, struct hn_rx_ring *rxr,
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);
int hv_rf_on_device_remove(struct hn_softc *sc, boolean_t destroy_channel);
int hv_rf_on_device_remove(struct hn_softc *sc);
int hv_rf_on_open(struct hn_softc *sc);
int hv_rf_on_close(struct hn_softc *sc);