From owner-svn-src-head@freebsd.org Mon Apr 25 09:00:08 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 41A7FB12202; Mon, 25 Apr 2016 09:00:08 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E2A291320; Mon, 25 Apr 2016 09:00:07 +0000 (UTC) (envelope-from sephe@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id u3P907Tr076126; Mon, 25 Apr 2016 09:00:07 GMT (envelope-from sephe@FreeBSD.org) Received: (from sephe@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id u3P906Xd076124; Mon, 25 Apr 2016 09:00:07 GMT (envelope-from sephe@FreeBSD.org) Message-Id: <201604250900.u3P906Xd076124@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: sephe set sender to sephe@FreeBSD.org using -f From: Sepherosa Ziehau Date: Mon, 25 Apr 2016 09:00:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r298574 - in head/sys/dev/hyperv: include vmbus X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Apr 2016 09:00:08 -0000 Author: sephe Date: Mon Apr 25 09:00:06 2016 New Revision: 298574 URL: https://svnweb.freebsd.org/changeset/base/298574 Log: hyperv/channel: Add functions to synchronize sub-channel offers MFC after: 1 week Sponsored by: Microsoft OSTC Modified: head/sys/dev/hyperv/include/hyperv.h head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Modified: head/sys/dev/hyperv/include/hyperv.h ============================================================================== --- head/sys/dev/hyperv/include/hyperv.h Mon Apr 25 06:08:45 2016 (r298573) +++ head/sys/dev/hyperv/include/hyperv.h Mon Apr 25 09:00:06 2016 (r298574) @@ -818,6 +818,7 @@ typedef struct hv_vmbus_channel { */ TAILQ_HEAD(, hv_vmbus_channel) sc_list_anchor; TAILQ_ENTRY(hv_vmbus_channel) sc_list_entry; + int subchan_cnt; /* * The primary channel this sub-channle belongs to. @@ -914,6 +915,9 @@ int hv_vmbus_channel_teardown_gpdal( struct hv_vmbus_channel* vmbus_select_outgoing_channel(struct hv_vmbus_channel *promary); void vmbus_channel_cpu_set(struct hv_vmbus_channel *chan, int cpu); +struct hv_vmbus_channel ** + vmbus_get_subchan(struct hv_vmbus_channel *pri_chan, int subchan_cnt); +void vmbus_rel_subchan(struct hv_vmbus_channel **subchan, int subchan_cnt); /** * @brief Get physical address from virtual Modified: head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c ============================================================================== --- head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Mon Apr 25 06:08:45 2016 (r298573) +++ head/sys/dev/hyperv/vmbus/hv_channel_mgmt.c Mon Apr 25 09:00:06 2016 (r298574) @@ -239,6 +239,17 @@ vmbus_channel_process_offer(hv_vmbus_cha new_channel->state = HV_CHANNEL_OPEN_STATE; if (channel->sc_creation_callback != NULL) channel->sc_creation_callback(new_channel); + + /* + * Bump up sub-channel count and notify anyone that is + * interested in this sub-channel, after this sub-channel + * is setup. + */ + mtx_lock(&channel->sc_lock); + channel->subchan_cnt++; + mtx_unlock(&channel->sc_lock); + wakeup(channel); + return; } @@ -771,3 +782,41 @@ vmbus_scan(void) mtx_sleep(&vmbus_devcnt, &vmbus_chwait_lock, 0, "waitdev", 0); mtx_unlock(&vmbus_chwait_lock); } + +struct hv_vmbus_channel ** +vmbus_get_subchan(struct hv_vmbus_channel *pri_chan, int subchan_cnt) +{ + struct hv_vmbus_channel **ret, *chan; + int i; + + ret = malloc(subchan_cnt * sizeof(struct hv_vmbus_channel *), M_TEMP, + M_WAITOK); + + mtx_lock(&pri_chan->sc_lock); + + while (pri_chan->subchan_cnt < subchan_cnt) + mtx_sleep(pri_chan, &pri_chan->sc_lock, 0, "subch", 0); + + i = 0; + TAILQ_FOREACH(chan, &pri_chan->sc_list_anchor, sc_list_entry) { + /* TODO: refcnt chan */ + ret[i] = chan; + + ++i; + if (i == subchan_cnt) + break; + } + KASSERT(i == subchan_cnt, ("invalid subchan count %d, should be %d", + pri_chan->subchan_cnt, subchan_cnt)); + + mtx_unlock(&pri_chan->sc_lock); + + return ret; +} + +void +vmbus_rel_subchan(struct hv_vmbus_channel **subchan, int subchan_cnt __unused) +{ + + free(subchan, M_TEMP); +}