From patchwork Thu Jan 12 07:25:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dong Jia Shi X-Patchwork-Id: 9512303 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id CCDB7601E5 for ; Thu, 12 Jan 2017 07:44:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BD45228511 for ; Thu, 12 Jan 2017 07:44:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AEF5E2861D; Thu, 12 Jan 2017 07:44:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2EF5D28511 for ; Thu, 12 Jan 2017 07:44:00 +0000 (UTC) Received: from localhost ([::1]:60273 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRa3D-0002AG-5l for patchwork-qemu-devel@patchwork.kernel.org; Thu, 12 Jan 2017 02:43:59 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:36298) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cRZlY-0000Kl-SW for qemu-devel@nongnu.org; Thu, 12 Jan 2017 02:25:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cRZlU-0005Ra-1j for qemu-devel@nongnu.org; Thu, 12 Jan 2017 02:25:44 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:33014 helo=mx0a-001b2d01.pphosted.com) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cRZlT-0005RR-LG for qemu-devel@nongnu.org; Thu, 12 Jan 2017 02:25:39 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.17/8.16.0.17) with SMTP id v0C7O44Z079993 for ; Thu, 12 Jan 2017 02:25:38 -0500 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0b-001b2d01.pphosted.com with ESMTP id 27x1rcpm5y-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 12 Jan 2017 02:25:38 -0500 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 12 Jan 2017 00:25:38 -0700 Received: from d03dlp03.boulder.ibm.com (9.17.202.179) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 12 Jan 2017 00:25:36 -0700 Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by d03dlp03.boulder.ibm.com (Postfix) with ESMTP id C329419D8026; Thu, 12 Jan 2017 00:24:52 -0700 (MST) Received: from b03ledav003.gho.boulder.ibm.com (b03ledav003.gho.boulder.ibm.com [9.17.130.234]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v0C7PYLZ12779970; Thu, 12 Jan 2017 00:25:34 -0700 Received: from b03ledav003.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D0A846A042; Thu, 12 Jan 2017 00:25:34 -0700 (MST) Received: from tuxmaker.boeblingen.de.ibm.com (unknown [9.152.85.9]) by b03ledav003.gho.boulder.ibm.com (Postfix) with ESMTP id CC7BC6A03D; Thu, 12 Jan 2017 00:25:32 -0700 (MST) From: Dong Jia Shi To: kvm@vger.kernel.org, linux-s390@vger.kernel.org, qemu-devel@nongnu.org Date: Thu, 12 Jan 2017 08:25:06 +0100 X-Mailer: git-send-email 2.8.4 In-Reply-To: <20170112072513.98411-1-bjsdjshi@linux.vnet.ibm.com> References: <20170112072513.98411-1-bjsdjshi@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17011207-0012-0000-0000-000012EE3370 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00006418; HX=3.00000240; KW=3.00000007; PH=3.00000004; SC=3.00000199; SDB=6.00806506; UDB=6.00392483; IPR=6.00583837; BA=6.00005049; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00013900; XFM=3.00000011; UTC=2017-01-12 07:25:37 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17011207-0013-0000-0000-00004A0C911B Message-Id: <20170112072513.98411-6-bjsdjshi@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-01-12_04:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=2 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1701120099 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PATCH RFC v2 05/12] s390x/css: realize css_create_sch X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pasic@linux.vnet.ibm.com, pmorel@linux.vnet.ibm.com, borntraeger@de.ibm.com, alex.williamson@redhat.com, renxiaof@linux.vnet.ibm.com, wkywang@linux.vnet.ibm.com, cornelia.huck@de.ibm.com, bjsdjshi@linux.vnet.ibm.com, agraf@suse.com Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP The S390 virtual css support already has a mechanism to create a virtual subchannel and provide it to the guest. However, to pass-through subchannels to a guest, we need to introduce a new mechanism to create the subchannel according to the real device information. Thus we realize a new css_create_sch function to allocate and initialize the subchannel according to the real device information. Signed-off-by: Dong Jia Shi Reviewed-by: Pierre Morel --- hw/s390x/css.c | 39 +++++++++++++++++++++++++++++++++++++++ include/hw/s390x/css.h | 15 +++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/hw/s390x/css.c b/hw/s390x/css.c index 8703bc3..67fe468 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -1486,6 +1486,19 @@ bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16_t devno) channel_subsys.css[cssid]->sch_set[ssid]->devnos_used); } +bool css_schid_used(uint8_t cssid, uint8_t ssid, uint16_t schid) +{ + if (!channel_subsys.css[cssid]) { + return false; + } + if (!channel_subsys.css[cssid]->sch_set[ssid]) { + return false; + } + + return !!test_bit(schid, + channel_subsys.css[cssid]->sch_set[ssid]->schids_used); +} + void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid, uint16_t devno, SubchDev *sch) { @@ -1911,6 +1924,32 @@ SubchDev *css_create_virtual_sch(CssDevId bus_id, Error **errp) return sch; } +SubchDev *css_create_sch(CssDevId bus_id, Error **errp) +{ + uint32_t devno; + SubchDev *sch; + + if (css_schid_used(bus_id.cssid, bus_id.ssid, bus_id.devid)) { + error_setg(errp, "Subchannel %x.%x.%04x already exists", + bus_id.cssid, bus_id.ssid, bus_id.devid); + return NULL; + } + + devno = css_find_free_devno(bus_id.cssid, bus_id.ssid, bus_id.devid); + if (devno > MAX_DEVNO) { + error_setg(errp, "No free devno found"); + return NULL; + } + + sch = g_malloc0(sizeof(*sch)); + sch->cssid = bus_id.cssid; + sch->ssid = bus_id.ssid; + sch->devno = devno; + sch->schid = bus_id.devid; + css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, sch); + return sch; +} + static int css_sch_get_chpids(SubchDev *sch, CssDevId *dev_id) { char *fid_path; diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h index 648ea2f..c92f624 100644 --- a/include/hw/s390x/css.h +++ b/include/hw/s390x/css.h @@ -128,6 +128,7 @@ void subch_device_save(SubchDev *s, QEMUFile *f); int subch_device_load(SubchDev *s, QEMUFile *f); int css_create_css_image(uint8_t cssid, bool default_image); bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16_t devno); +bool css_schid_used(uint8_t cssid, uint8_t ssid, uint16_t schid); void css_subch_assign(uint8_t cssid, uint8_t ssid, uint16_t schid, uint16_t devno, SubchDev *sch); void css_sch_build_virtual_schib(SubchDev *sch, uint8_t chpid, uint8_t type); @@ -189,4 +190,18 @@ bool css_present(uint8_t cssid); * is responsible for unregistering and freeing it. */ SubchDev *css_create_virtual_sch(CssDevId bus_id, Error **errp); + +/** + * Create a subchannel for the given bus id. + * + * If @p bus_id is valid, verify that it is not already in use, and find + * a free devno for it. + * Allocate a subchannel structure, initialise it with the bus id, + * subchannel id and device number, register it with the CSS and return + * it. Otherwise return NULL. + * + * The caller becomes owner of the returned subchannel structure and + * is responsible for unregistering and freeing it. + */ +SubchDev *css_create_sch(CssDevId bus_id, Error **errp); #endif