hyperv/hn: Remove the useless num_channel

MFC after:	1 week
Sponsored by:	Microsoft
Differential Revision:	https://reviews.freebsd.org/D7555
This commit is contained in:
Sepherosa Ziehau 2016-08-19 05:30:39 +00:00
parent 2a137ab6fd
commit d981413bcb
4 changed files with 29 additions and 34 deletions

View File

@ -236,8 +236,6 @@ typedef struct netvsc_dev_ {
/* Holds rndis device info */ /* Holds rndis device info */
void *extension; void *extension;
uint32_t num_channel;
struct hyperv_dma rxbuf_dma; struct hyperv_dma rxbuf_dma;
struct hyperv_dma txbuf_dma; struct hyperv_dma txbuf_dma;
} netvsc_dev; } netvsc_dev;

View File

@ -551,26 +551,25 @@ netvsc_attach(device_t dev)
if (sc->hn_xact == NULL) if (sc->hn_xact == NULL)
goto failed; goto failed;
error = hv_rf_on_device_add(sc, &device_info, ring_cnt, error = hv_rf_on_device_add(sc, &device_info, &ring_cnt,
&sc->hn_rx_ring[0]); &sc->hn_rx_ring[0]);
if (error) if (error)
goto failed; goto failed;
KASSERT(sc->net_dev->num_channel > 0 && KASSERT(ring_cnt > 0 && ring_cnt <= sc->hn_rx_ring_inuse,
sc->net_dev->num_channel <= sc->hn_rx_ring_inuse, ("invalid channel count %d, should be less than %d",
("invalid channel count %u, should be less than %d", ring_cnt, sc->hn_rx_ring_inuse));
sc->net_dev->num_channel, sc->hn_rx_ring_inuse));
/* /*
* Set the # of TX/RX rings that could be used according to * Set the # of TX/RX rings that could be used according to
* the # of channels that host offered. * the # of channels that host offered.
*/ */
if (sc->hn_tx_ring_inuse > sc->net_dev->num_channel) if (sc->hn_tx_ring_inuse > ring_cnt)
sc->hn_tx_ring_inuse = sc->net_dev->num_channel; sc->hn_tx_ring_inuse = ring_cnt;
sc->hn_rx_ring_inuse = sc->net_dev->num_channel; sc->hn_rx_ring_inuse = ring_cnt;
device_printf(dev, "%d TX ring, %d RX ring\n", device_printf(dev, "%d TX ring, %d RX ring\n",
sc->hn_tx_ring_inuse, sc->hn_rx_ring_inuse); sc->hn_tx_ring_inuse, sc->hn_rx_ring_inuse);
if (sc->net_dev->num_channel > 1) if (sc->hn_rx_ring_inuse > 1)
hn_subchan_setup(sc); hn_subchan_setup(sc);
#if __FreeBSD_version >= 1100099 #if __FreeBSD_version >= 1100099
@ -1511,7 +1510,7 @@ hn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
struct ifaddr *ifa = (struct ifaddr *)data; struct ifaddr *ifa = (struct ifaddr *)data;
#endif #endif
netvsc_device_info device_info; netvsc_device_info device_info;
int mask, error = 0; int mask, error = 0, ring_cnt;
int retry_cnt = 500; int retry_cnt = 500;
switch(cmd) { switch(cmd) {
@ -1585,18 +1584,20 @@ hn_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
/* Wait for subchannels to be destroyed */ /* Wait for subchannels to be destroyed */
vmbus_subchan_drain(sc->hn_prichan); vmbus_subchan_drain(sc->hn_prichan);
error = hv_rf_on_device_add(sc, &device_info, ring_cnt = sc->hn_rx_ring_inuse;
sc->hn_rx_ring_inuse, &sc->hn_rx_ring[0]); error = hv_rf_on_device_add(sc, &device_info, &ring_cnt,
&sc->hn_rx_ring[0]);
if (error) { if (error) {
NV_LOCK(sc); NV_LOCK(sc);
sc->temp_unusable = FALSE; sc->temp_unusable = FALSE;
NV_UNLOCK(sc); NV_UNLOCK(sc);
break; break;
} }
KASSERT(sc->hn_rx_ring_cnt == sc->net_dev->num_channel, /* # of channels can _not_ be changed */
KASSERT(sc->hn_rx_ring_inuse == ring_cnt,
("RX ring count %d and channel count %u mismatch", ("RX ring count %d and channel count %u mismatch",
sc->hn_rx_ring_cnt, sc->net_dev->num_channel)); sc->hn_rx_ring_cnt, ring_cnt));
if (sc->net_dev->num_channel > 1) { if (sc->hn_rx_ring_inuse > 1) {
int r; int r;
/* /*
@ -2966,7 +2967,7 @@ static void
hn_subchan_setup(struct hn_softc *sc) hn_subchan_setup(struct hn_softc *sc)
{ {
struct vmbus_channel **subchans; struct vmbus_channel **subchans;
int subchan_cnt = sc->net_dev->num_channel - 1; int subchan_cnt = sc->hn_rx_ring_inuse - 1;
int i; int i;
/* Wait for sub-channels setup to complete. */ /* Wait for sub-channels setup to complete. */

View File

@ -1035,7 +1035,7 @@ hv_rf_close_device(rndis_device *device)
*/ */
int int
hv_rf_on_device_add(struct hn_softc *sc, void *additl_info, hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
int nchan, struct hn_rx_ring *rxr) int *nchan0, struct hn_rx_ring *rxr)
{ {
struct hn_send_ctx sndc; struct hn_send_ctx sndc;
int ret; int ret;
@ -1051,6 +1051,7 @@ hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
size_t resp_len; size_t resp_len;
struct vmbus_xact *xact; struct vmbus_xact *xact;
uint32_t status, nsubch; uint32_t status, nsubch;
int nchan = *nchan0;
rndis_dev = hv_get_rndis_device(); rndis_dev = hv_get_rndis_device();
if (rndis_dev == NULL) { if (rndis_dev == NULL) {
@ -1114,7 +1115,6 @@ hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
dev_info->link_state = rndis_dev->link_status; dev_info->link_state = rndis_dev->link_status;
net_dev->num_channel = 1;
if (sc->hn_nvs_ver < NVSP_PROTOCOL_VERSION_5 || nchan == 1) if (sc->hn_nvs_ver < NVSP_PROTOCOL_VERSION_5 || nchan == 1)
return (0); return (0);
@ -1131,10 +1131,9 @@ hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
rsscaps.num_recv_que, nchan); rsscaps.num_recv_que, nchan);
if (nchan > rsscaps.num_recv_que) if (nchan > rsscaps.num_recv_que)
nchan = rsscaps.num_recv_que; nchan = rsscaps.num_recv_que;
net_dev->num_channel = nchan;
if (net_dev->num_channel == 1) { if (nchan == 1) {
device_printf(dev, "net_dev->num_channel == 1 under VRSS\n"); device_printf(dev, "only 1 channel is supported, no vRSS\n");
goto out; goto out;
} }
@ -1151,7 +1150,7 @@ hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
req = vmbus_xact_req_data(xact); req = vmbus_xact_req_data(xact);
req->nvs_type = HN_NVS_TYPE_SUBCH_REQ; req->nvs_type = HN_NVS_TYPE_SUBCH_REQ;
req->nvs_op = HN_NVS_SUBCH_OP_ALLOC; req->nvs_op = HN_NVS_SUBCH_OP_ALLOC;
req->nvs_nsubch = net_dev->num_channel - 1; req->nvs_nsubch = nchan - 1;
hn_send_ctx_init_simple(&sndc, hn_nvs_sent_xact, xact); hn_send_ctx_init_simple(&sndc, hn_nvs_sent_xact, xact);
vmbus_xact_activate(xact); vmbus_xact_activate(xact);
@ -1190,19 +1189,16 @@ hv_rf_on_device_add(struct hn_softc *sc, void *additl_info,
ret = EIO; ret = EIO;
goto out; goto out;
} }
if (nsubch > net_dev->num_channel - 1) { if (nsubch > nchan - 1) {
if_printf(sc->hn_ifp, "%u subchans are allocated, requested %u\n", if_printf(sc->hn_ifp, "%u subchans are allocated, requested %u\n",
nsubch, net_dev->num_channel - 1); nsubch, nchan - 1);
nsubch = net_dev->num_channel - 1; nsubch = nchan - 1;
} }
net_dev->num_channel = nsubch + 1; nchan = nsubch + 1;
ret = hv_rf_set_rss_param(rndis_dev, net_dev->num_channel);
ret = hv_rf_set_rss_param(rndis_dev, nchan);
*nchan0 = nchan;
out: out:
if (ret)
net_dev->num_channel = 1;
return (ret); return (ret);
} }

View File

@ -119,7 +119,7 @@ int hv_rf_on_receive(netvsc_dev *net_dev, struct hn_rx_ring *rxr,
const void *data, int dlen); const void *data, int dlen);
void hv_rf_receive_rollup(netvsc_dev *net_dev); void hv_rf_receive_rollup(netvsc_dev *net_dev);
void hv_rf_channel_rollup(struct hn_rx_ring *rxr, struct hn_tx_ring *txr); 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, int hv_rf_on_device_add(struct hn_softc *sc, void *additl_info, int *nchan,
struct hn_rx_ring *rxr); 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, boolean_t destroy_channel);
int hv_rf_on_open(struct hn_softc *sc); int hv_rf_on_open(struct hn_softc *sc);