From patchwork Wed Feb 22 12:15:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cornelia Huck X-Patchwork-Id: 731094 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vSxFT3whPz9s73 for ; Wed, 22 Feb 2017 23:17:17 +1100 (AEDT) Received: from localhost ([::1]:51812 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVr9-0000B6-0w for incoming@patchwork.ozlabs.org; Wed, 22 Feb 2017 07:17:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35791) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVpi-0006eb-MP for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:47 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgVpf-0003i2-Fi for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:46 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:55958) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgVpf-0003hv-15 for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:43 -0500 Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1MC9mwW014980 for ; Wed, 22 Feb 2017 07:15:41 -0500 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 28ruy0gcm6-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Feb 2017 07:15:41 -0500 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Feb 2017 12:15:38 -0000 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Feb 2017 12:15:37 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 14B6C17D805D; Wed, 22 Feb 2017 12:18:47 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1MCFaI810617274; Wed, 22 Feb 2017 12:15:36 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 48485AE053; Wed, 22 Feb 2017 11:13:27 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 092EDAE051; Wed, 22 Feb 2017 11:13:27 +0000 (GMT) Received: from gondolin.boeblingen.de.ibm.com (unknown [9.152.224.55]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Wed, 22 Feb 2017 11:13:26 +0000 (GMT) From: Cornelia Huck To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2017 13:15:21 +0100 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170222121527.7009-1-cornelia.huck@de.ibm.com> References: <20170222121527.7009-1-cornelia.huck@de.ibm.com> X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 17022212-0020-0000-0000-00000278E0E8 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17022212-0021-0000-0000-00001F77ECEB Message-Id: <20170222121527.7009-3-cornelia.huck@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-02-22_08:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 suspectscore=3 malwarescore=0 phishscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1612050000 definitions=main-1702220118 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PATCH 2/8] s390x/css: Add an algorithm to find a free chpid 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: Jing Liu , agraf@suse.de, borntraeger@de.ibm.com, jfrei@linux.vnet.ibm.com, pbonzini@redhat.com, Cornelia Huck , marcandre.lureau@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Jing Liu This introduces a function named css_find_free_chpid() to find a free channel path. Because virtio-ccw device used zero as its channel path number, it would be sensible to skip the reserved one and search upwards. Signed-off-by: Jing Liu Reviewed-by: QingFeng Hao Reviewed-by: Dong Jia Shi Signed-off-by: Cornelia Huck --- hw/s390x/css.c | 21 +++++++++++++++++++++ include/hw/s390x/css.h | 2 ++ 2 files changed, 23 insertions(+) diff --git a/hw/s390x/css.c b/hw/s390x/css.c index 0f2580d644..ecafaab096 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -1278,6 +1278,27 @@ bool css_schid_final(int m, uint8_t cssid, uint8_t ssid, uint16_t schid) (MAX_SCHID + 1) / sizeof(unsigned long)); } +unsigned int css_find_free_chpid(uint8_t cssid) +{ + CssImage *css = channel_subsys.css[cssid]; + unsigned int chpid; + + if (!css) { + return MAX_CHPID + 1; + } + + for (chpid = 0; chpid <= MAX_CHPID; chpid++) { + /* skip reserved chpid */ + if (chpid == VIRTIO_CCW_CHPID) { + continue; + } + if (!css->chpids[chpid].in_use) { + return chpid; + } + } + return MAX_CHPID + 1; +} + static int css_add_virtual_chpid(uint8_t cssid, uint8_t chpid, uint8_t type) { CssImage *css; diff --git a/include/hw/s390x/css.h b/include/hw/s390x/css.h index c96c862057..43b9d466fa 100644 --- a/include/hw/s390x/css.h +++ b/include/hw/s390x/css.h @@ -26,6 +26,7 @@ #define MAX_CIWS 62 #define VIRTUAL_CSSID 0xfe +#define VIRTIO_CCW_CHPID 0 /* used by convention */ typedef struct CIW { uint8_t type; @@ -113,6 +114,7 @@ bool css_devno_used(uint8_t cssid, uint8_t ssid, uint16_t devno); 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); +unsigned int css_find_free_chpid(uint8_t cssid); uint16_t css_build_subchannel_id(SubchDev *sch); void css_reset(void); void css_reset_sch(SubchDev *sch);