Date: Mon, 12 Sep 2016 05:37:44 +0000 (UTC) From: Sepherosa Ziehau <sephe@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r305728 - head/sys/dev/hyperv/netvsc Message-ID: <201609120537.u8C5biRx067991@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: sephe Date: Mon Sep 12 05:37:44 2016 New Revision: 305728 URL: https://svnweb.freebsd.org/changeset/base/305728 Log: hyperv/hn: Reorganize sub-channel allocation. MFC after: 1 week Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D7829 Modified: head/sys/dev/hyperv/netvsc/hv_net_vsc.c head/sys/dev/hyperv/netvsc/hv_rndis_filter.c head/sys/dev/hyperv/netvsc/if_hnvar.h Modified: head/sys/dev/hyperv/netvsc/hv_net_vsc.c ============================================================================== --- head/sys/dev/hyperv/netvsc/hv_net_vsc.c Mon Sep 12 05:28:50 2016 (r305727) +++ head/sys/dev/hyperv/netvsc/hv_net_vsc.c Mon Sep 12 05:37:44 2016 (r305728) @@ -102,7 +102,7 @@ hn_chim_alloc(struct hn_softc *sc) return (ret); } -const void * +static const void * hn_nvs_xact_execute(struct hn_softc *sc, struct vmbus_xact *xact, void *req, int reqlen, size_t *resplen0, uint32_t type) { @@ -653,3 +653,54 @@ hv_nv_on_send(struct vmbus_channel *chan return (ret); } + +int +hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch0) +{ + struct vmbus_xact *xact; + struct hn_nvs_subch_req *req; + const struct hn_nvs_subch_resp *resp; + int error, nsubch_req; + uint32_t nsubch; + size_t resp_len; + + nsubch_req = *nsubch0; + KASSERT(nsubch_req > 0, ("invalid # of sub-channels %d", nsubch_req)); + + xact = vmbus_xact_get(sc->hn_xact, sizeof(*req)); + if (xact == NULL) { + if_printf(sc->hn_ifp, "no xact for nvs subch alloc\n"); + return (ENXIO); + } + req = vmbus_xact_req_data(xact); + req->nvs_type = HN_NVS_TYPE_SUBCH_REQ; + req->nvs_op = HN_NVS_SUBCH_OP_ALLOC; + req->nvs_nsubch = nsubch_req; + + resp_len = sizeof(*resp); + resp = hn_nvs_xact_execute(sc, xact, req, sizeof(*req), &resp_len, + HN_NVS_TYPE_SUBCH_RESP); + if (resp == NULL) { + if_printf(sc->hn_ifp, "exec nvs subch alloc failed\n"); + error = EIO; + goto done; + } + if (resp->nvs_status != HN_NVS_STATUS_OK) { + if_printf(sc->hn_ifp, "nvs subch alloc failed: %x\n", + resp->nvs_status); + error = EIO; + goto done; + } + + nsubch = resp->nvs_nsubch; + if (nsubch > nsubch_req) { + if_printf(sc->hn_ifp, "%u subchans are allocated, " + "requested %d\n", nsubch, nsubch_req); + nsubch = nsubch_req; + } + *nsubch0 = nsubch; + error = 0; +done: + vmbus_xact_put(xact); + return (error); +} Modified: head/sys/dev/hyperv/netvsc/hv_rndis_filter.c ============================================================================== --- head/sys/dev/hyperv/netvsc/hv_rndis_filter.c Mon Sep 12 05:28:50 2016 (r305727) +++ head/sys/dev/hyperv/netvsc/hv_rndis_filter.c Mon Sep 12 05:37:44 2016 (r305728) @@ -1017,13 +1017,7 @@ hv_rf_on_device_add(struct hn_softc *sc, int ret; netvsc_device_info *dev_info = (netvsc_device_info *)additl_info; device_t dev = sc->hn_dev; - struct hn_nvs_subch_req *req; - const struct hn_nvs_subch_resp *resp; - size_t resp_len; - struct vmbus_xact *xact = NULL; - uint32_t status, nsubch; - int nchan = *nchan0; - int rxr_cnt; + int nchan = *nchan0, rxr_cnt, nsubch; ret = hn_nvs_attach(sc, mtu); if (ret != 0) @@ -1072,65 +1066,40 @@ hv_rf_on_device_add(struct hn_softc *sc, *nchan0 = 1; return (0); } - if (nchan > rxr_cnt) - nchan = rxr_cnt; if_printf(sc->hn_ifp, "RX rings offered %u, requested %d\n", rxr_cnt, nchan); + if (nchan > rxr_cnt) + nchan = rxr_cnt; if (nchan == 1) { device_printf(dev, "only 1 channel is supported, no vRSS\n"); - goto out; + *nchan0 = 1; + return (0); } /* - * Ask NVS to allocate sub-channels. + * Allocate sub-channels from NVS. */ - xact = vmbus_xact_get(sc->hn_xact, sizeof(*req)); - if (xact == NULL) { - if_printf(sc->hn_ifp, "no xact for nvs subch req\n"); - ret = ENXIO; - goto out; - } - req = vmbus_xact_req_data(xact); - req->nvs_type = HN_NVS_TYPE_SUBCH_REQ; - req->nvs_op = HN_NVS_SUBCH_OP_ALLOC; - req->nvs_nsubch = nchan - 1; - - resp_len = sizeof(*resp); - resp = hn_nvs_xact_execute(sc, xact, req, sizeof(*req), &resp_len, - HN_NVS_TYPE_SUBCH_RESP); - if (resp == NULL) { - if_printf(sc->hn_ifp, "exec subch failed\n"); - ret = EIO; - goto out; - } - - status = resp->nvs_status; - nsubch = resp->nvs_nsubch; - vmbus_xact_put(xact); - xact = NULL; - - if (status != HN_NVS_STATUS_OK) { - if_printf(sc->hn_ifp, "subch req failed: %x\n", status); - ret = EIO; - goto out; - } - if (nsubch > nchan - 1) { - if_printf(sc->hn_ifp, "%u subchans are allocated, requested %u\n", - nsubch, nchan - 1); - nsubch = nchan - 1; + nsubch = nchan - 1; + ret = hn_nvs_alloc_subchans(sc, &nsubch); + if (ret || nsubch == 0) { + /* Failed to allocate sub-channels. */ + *nchan0 = 1; + return (0); } nchan = nsubch + 1; + /* + * Configure RSS key and indirect table after all sub-channels + * are allocated. + */ ret = hn_rndis_conf_rss(sc, nchan); - if (ret != 0) - *nchan0 = 1; - else - *nchan0 = nchan; -out: - if (xact != NULL) - vmbus_xact_put(xact); - return (ret); + if (ret != 0) { + /* Failed to configure RSS key or indirect table. */ + nchan = 1; + } + *nchan0 = nchan; + return (0); } /* Modified: head/sys/dev/hyperv/netvsc/if_hnvar.h ============================================================================== --- head/sys/dev/hyperv/netvsc/if_hnvar.h Mon Sep 12 05:28:50 2016 (r305727) +++ head/sys/dev/hyperv/netvsc/if_hnvar.h Mon Sep 12 05:37:44 2016 (r305728) @@ -114,9 +114,6 @@ hn_nvs_send_sglist(struct vmbus_channel struct vmbus_xact; struct rndis_packet_msg; -const void *hn_nvs_xact_execute(struct hn_softc *sc, - struct vmbus_xact *xact, void *req, int reqlen, - size_t *resp_len, uint32_t type); void hn_nvs_sent_xact(struct hn_send_ctx *sndc, struct hn_softc *sc, struct vmbus_channel *chan, const void *data, int dlen); uint32_t hn_chim_alloc(struct hn_softc *sc); @@ -125,6 +122,7 @@ void hn_chim_free(struct hn_softc *sc, void *hn_rndis_pktinfo_append(struct rndis_packet_msg *, size_t pktsize, size_t pi_dlen, uint32_t pi_type); +int hn_nvs_alloc_subchans(struct hn_softc *sc, int *nsubch); int hn_rxpkt(struct hn_rx_ring *rxr, const void *data, int dlen, const struct hn_recvinfo *info); void hn_chan_rollup(struct hn_rx_ring *rxr, struct hn_tx_ring *txr);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201609120537.u8C5biRx067991>