From patchwork Fri Aug 27 10:17:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 12461841 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49E61C432BE for ; Fri, 27 Aug 2021 10:17:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2091960F4F for ; Fri, 27 Aug 2021 10:17:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244903AbhH0KSR (ORCPT ); Fri, 27 Aug 2021 06:18:17 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:8720 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244857AbhH0KSQ (ORCPT ); Fri, 27 Aug 2021 06:18:16 -0400 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17RA3awC090221 for ; Fri, 27 Aug 2021 06:17:27 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=h+XJS0O2VK81ak4qZU8h29PUmYbTsg+AHN215ko2/AA=; b=om7FzVoNuW3wywOMC54l2igbqFLkbq+KSgMETP2mJwPIJ/ABrZcjhxGBJG6S+NB01NsM 9OPT2Kvvg0NCAUdmlbnBifJOq7Rs03lVJOmboaP8CBGRiAw2w+uXw8Ro2KETgHW5bKPR H2z9DPhX7Uqa5+YXuiIkV6C0+P0wkKmVgekuEylEAVBC66uFve0/2y4J+LDdEuvi99wu oG6tg9SH2R9/3s5SbOL3Ryluns0SvY99LDggDwewD3By1ybllLHXjCbLOyp/je8/3KCs iF4PG1IZlWVthRi7OHyLMnsvZ9+Jfz3tsz/RoYbnjYE+nE6dRzBVxSeSVuu/S89nWh87 rg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3apw1n216b-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 27 Aug 2021 06:17:27 -0400 Received: from m0098396.ppops.net (m0098396.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 17RAHRxC157686 for ; Fri, 27 Aug 2021 06:17:27 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 3apw1n215w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 06:17:27 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 17RAD4HS004852; Fri, 27 Aug 2021 10:17:25 GMT Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by ppma03ams.nl.ibm.com with ESMTP id 3ajs48ka8a-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 10:17:24 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17RAHL2L57999730 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 10:17:21 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A16194C044; Fri, 27 Aug 2021 10:17:21 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 55F9E4C040; Fri, 27 Aug 2021 10:17:21 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.164.230]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Aug 2021 10:17:21 +0000 (GMT) From: Pierre Morel To: kvm@vger.kernel.org Cc: frankja@linux.ibm.com, david@redhat.com, thuth@redhat.com, cohuck@redhat.com, imbrenda@linux.ibm.com, drjones@redhat.com Subject: [kvm-unit-tests PATCH 1/7] arm: virtio: move VIRTIO transport initialization inside virtio-mmio Date: Fri, 27 Aug 2021 12:17:14 +0200 Message-Id: <1630059440-15586-2-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630059440-15586-1-git-send-email-pmorel@linux.ibm.com> References: <1630059440-15586-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: AvI_EcN0zzop18Aby6WbmYckd90Xroxe X-Proofpoint-GUID: hPU2ayeBW9F3EH_O7HijdhfFhvYm4qBf X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-08-27_03:2021-08-26,2021-08-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 mlxscore=0 spamscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270063 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org To be able to use different VIRTIO transport in the future we need the initialisation entry call of the transport to be inside the transport file and keep the VIRTIO level transport agnostic. Signed-off-by: Pierre Morel --- lib/virtio-mmio.c | 2 +- lib/virtio-mmio.h | 2 -- lib/virtio.c | 5 ----- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/virtio-mmio.c b/lib/virtio-mmio.c index e5e8f660..fb8a86a3 100644 --- a/lib/virtio-mmio.c +++ b/lib/virtio-mmio.c @@ -173,7 +173,7 @@ static struct virtio_device *virtio_mmio_dt_bind(u32 devid) return &vm_dev->vdev; } -struct virtio_device *virtio_mmio_bind(u32 devid) +struct virtio_device *virtio_bind(u32 devid) { return virtio_mmio_dt_bind(devid); } diff --git a/lib/virtio-mmio.h b/lib/virtio-mmio.h index 250f28a0..73ddbd23 100644 --- a/lib/virtio-mmio.h +++ b/lib/virtio-mmio.h @@ -60,6 +60,4 @@ struct virtio_mmio_device { void *base; }; -extern struct virtio_device *virtio_mmio_bind(u32 devid); - #endif /* _VIRTIO_MMIO_H_ */ diff --git a/lib/virtio.c b/lib/virtio.c index 69054757..e10153b9 100644 --- a/lib/virtio.c +++ b/lib/virtio.c @@ -123,8 +123,3 @@ void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len) return ret; } - -struct virtio_device *virtio_bind(u32 devid) -{ - return virtio_mmio_bind(devid); -} From patchwork Fri Aug 27 10:17:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 12461845 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9EDF7C4320A for ; Fri, 27 Aug 2021 10:17:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 72C0360F45 for ; Fri, 27 Aug 2021 10:17:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244918AbhH0KSS (ORCPT ); Fri, 27 Aug 2021 06:18:18 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:56004 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244893AbhH0KSR (ORCPT ); Fri, 27 Aug 2021 06:18:17 -0400 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17RA6djf032459 for ; Fri, 27 Aug 2021 06:17:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=QjT0sLJxQnBtiDNqea96LIa2fDtzrhQITGc+Zcfev7o=; b=UVB6ldm3VQ+feEHSCN/c0FN9CRuOJr/WysHo3K+UZ9OmwjZGEZeko0pxAyphHfmKkuDV J8mYoRfU35F3yz+zwzrDrEf+POJ7tPeN6X1Bcz7KIQabef9DHLqGerL/Jkxo387TpHrm NNxq/wrYlzTPUr8lO9DwPszblHXx2bXdFTIV9gh+krFrwyB1dF6J8586i/l2B01aaEeF 0XTVCW63mdYfu4V2+ZobDZfSjXWtFvCSSH5Ym8eTQ6JccQ/oTiNMNLZvynrxV8dIrU17 1jTgHcTm8pbHfvLDRWG6IULTy3sm99SLeaKhKwOP+70mnhA22HVl2t2fAOQtJnDILEhA 9w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3apv53jv92-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 27 Aug 2021 06:17:27 -0400 Received: from m0098419.ppops.net (m0098419.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 17RA6x8P034161 for ; Fri, 27 Aug 2021 06:17:27 -0400 Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 3apv53jv8h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 06:17:27 -0400 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 17RAD7sL017066; Fri, 27 Aug 2021 10:17:26 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma04fra.de.ibm.com with ESMTP id 3ajs48seyh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 10:17:25 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17RAHMhM50069788 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 10:17:22 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 05A754C058; Fri, 27 Aug 2021 10:17:22 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AFA014C040; Fri, 27 Aug 2021 10:17:21 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.164.230]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Aug 2021 10:17:21 +0000 (GMT) From: Pierre Morel To: kvm@vger.kernel.org Cc: frankja@linux.ibm.com, david@redhat.com, thuth@redhat.com, cohuck@redhat.com, imbrenda@linux.ibm.com, drjones@redhat.com Subject: [kvm-unit-tests PATCH 2/7] s390x: css: add callback for emnumeration Date: Fri, 27 Aug 2021 12:17:15 +0200 Message-Id: <1630059440-15586-3-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630059440-15586-1-git-send-email-pmorel@linux.ibm.com> References: <1630059440-15586-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: Q2A2oZQ1kGEHKJ63DQidOrT1EGBsalgG X-Proofpoint-ORIG-GUID: ld7r78Cu5WojcclrqgZf_WWDg_RIzDIw X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-08-27_03:2021-08-26,2021-08-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 spamscore=0 priorityscore=1501 adultscore=0 clxscore=1015 mlxscore=0 lowpriorityscore=0 mlxlogscore=999 suspectscore=0 malwarescore=0 bulkscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270063 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We will need to look for a device inside the channel subsystem based upon device specificities. Let's provide a callback for an upper layer to be called during the enumeration of the channel subsystem. Signed-off-by: Pierre Morel Reviewed-by: Thomas Huth --- lib/s390x/css.h | 3 ++- lib/s390x/css_lib.c | 4 +++- s390x/css.c | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/s390x/css.h b/lib/s390x/css.h index d644971f..2005f4d7 100644 --- a/lib/s390x/css.h +++ b/lib/s390x/css.h @@ -278,7 +278,8 @@ void dump_irb(struct irb *irbp); void dump_pmcw(struct pmcw *p); void dump_orb(struct orb *op); -int css_enumerate(void); +typedef int (enumerate_cb_t)(int); +int css_enumerate(enumerate_cb_t *f); #define MAX_ENABLE_RETRIES 5 #define IO_SCH_ISC 3 diff --git a/lib/s390x/css_lib.c b/lib/s390x/css_lib.c index efc70576..484f9c41 100644 --- a/lib/s390x/css_lib.c +++ b/lib/s390x/css_lib.c @@ -117,7 +117,7 @@ bool get_chsc_scsc(void) * On success return the first subchannel ID found. * On error return an invalid subchannel ID containing cc */ -int css_enumerate(void) +int css_enumerate(enumerate_cb_t *f) { struct pmcw *pmcw = &schib.pmcw; int scn_found = 0; @@ -153,6 +153,8 @@ int css_enumerate(void) schid = scn | SCHID_ONE; report_info("Found subchannel %08x", scn | SCHID_ONE); dev_found++; + if (f) + f(scn | SCHID_ONE); } out: diff --git a/s390x/css.c b/s390x/css.c index c340c539..b50fbc67 100644 --- a/s390x/css.c +++ b/s390x/css.c @@ -29,7 +29,7 @@ struct ccw1 *ccw; static void test_enumerate(void) { - test_device_sid = css_enumerate(); + test_device_sid = css_enumerate(NULL); if (test_device_sid & SCHID_ONE) { report(1, "Schid of first I/O device: 0x%08x", test_device_sid); return; From patchwork Fri Aug 27 10:17:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 12461847 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-14.0 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3BFF0C43216 for ; Fri, 27 Aug 2021 10:17:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 22DD960F4F for ; Fri, 27 Aug 2021 10:17:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244927AbhH0KSS (ORCPT ); Fri, 27 Aug 2021 06:18:18 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:64010 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244901AbhH0KSR (ORCPT ); Fri, 27 Aug 2021 06:18:17 -0400 Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17RA6hSF157080 for ; Fri, 27 Aug 2021 06:17:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=vOrQR7P0Ey6hNtW42UKrXv8D6ot43gvqIjGjvdzk+yQ=; b=btAbuwwNh3WZIpDn1lcdFIO5me0fFLMg2V6RtHClgt9v0nQjhkYhjzNW9wlq09GZdUVY 4zlpDZrQH3WXK5c835/14wjvvzSFDkhiTPl7QT2sEjPkMkCsHblC8wE16+DRtLAQtDLT 6OEKiwkq5ZZt4oJAZlr/SM/4QkQMDPnuxvZFq5CC90Q0vDjzS3HFJzqWly1WdCyKiiHl KFf4T0nhESG0gJJcCYYEd+UtlYaP0CDyzckQ0YOA1HfxoywEVUYPOGh39QP1xDkcyAx8 PzPBfiJPZKBwG1VohqnooFOh8L3M+ykGRwG5aPp30quy4BenbaKLTXFFaUD3xbIIj0AQ Kg== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3apwfm137m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 27 Aug 2021 06:17:28 -0400 Received: from m0127361.ppops.net (m0127361.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 17RA74Ym158995 for ; Fri, 27 Aug 2021 06:17:27 -0400 Received: from ppma06ams.nl.ibm.com (66.31.33a9.ip4.static.sl-reverse.com [169.51.49.102]) by mx0a-001b2d01.pphosted.com with ESMTP id 3apwfm1374-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 06:17:27 -0400 Received: from pps.filterd (ppma06ams.nl.ibm.com [127.0.0.1]) by ppma06ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 17RAD6j1013194; Fri, 27 Aug 2021 10:17:25 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma06ams.nl.ibm.com with ESMTP id 3ajrrhkbbc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 10:17:25 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17RAHMvZ49349094 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 10:17:22 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6334B4C044; Fri, 27 Aug 2021 10:17:22 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 13FAD4C040; Fri, 27 Aug 2021 10:17:22 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.164.230]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Aug 2021 10:17:22 +0000 (GMT) From: Pierre Morel To: kvm@vger.kernel.org Cc: frankja@linux.ibm.com, david@redhat.com, thuth@redhat.com, cohuck@redhat.com, imbrenda@linux.ibm.com, drjones@redhat.com Subject: [kvm-unit-tests PATCH 3/7] s390x: virtio: CCW transport implementation Date: Fri, 27 Aug 2021 12:17:16 +0200 Message-Id: <1630059440-15586-4-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630059440-15586-1-git-send-email-pmorel@linux.ibm.com> References: <1630059440-15586-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: It4zXu5jV9dZc-CI6eQGfXuT7H6QSRf4 X-Proofpoint-ORIG-GUID: 4zY6hS1JZbPoirwHnf180jghKiMLxf0E X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-08-27_03:2021-08-26,2021-08-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 spamscore=0 mlxscore=0 lowpriorityscore=0 impostorscore=0 suspectscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 clxscore=1015 priorityscore=1501 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270063 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This is the implementation of the virtio-ccw transport level. We only support VIRTIO revision 0. Signed-off-by: Pierre Morel --- lib/s390x/virtio-ccw.c | 374 +++++++++++++++++++++++++++++++++++++++++ lib/s390x/virtio-ccw.h | 111 ++++++++++++ lib/virtio-config.h | 30 ++++ s390x/Makefile | 2 + 4 files changed, 517 insertions(+) create mode 100644 lib/s390x/virtio-ccw.c create mode 100644 lib/s390x/virtio-ccw.h create mode 100644 lib/virtio-config.h diff --git a/lib/s390x/virtio-ccw.c b/lib/s390x/virtio-ccw.c new file mode 100644 index 00000000..cf447de6 --- /dev/null +++ b/lib/s390x/virtio-ccw.c @@ -0,0 +1,374 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Virtio CCW Library + * + * Copyright (c) 2021 IBM Corp + * + * Authors: + * Pierre Morel + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +static struct linked_list vcdev_list = { + .prev = &vcdev_list, + .next = &vcdev_list +}; + +static inline uint32_t swap16(uint32_t b) +{ + return (((b & 0xff00U) << 8) | + ((b & 0x00ff) >> 8)); +} + +static inline uint32_t swap32(uint32_t b) +{ + return (((b & 0x000000ffU) << 24) | + ((b & 0x0000ff00U) << 8) | + ((b & 0x00ff0000U) >> 8) | + ((b & 0xff000000U) >> 24)); +} + +static inline uint64_t swap64(uint64_t x) +{ + return (((x & 0x00000000000000ffULL) << 56) | + ((x & 0x000000000000ff00ULL) << 40) | + ((x & 0x0000000000ff0000ULL) << 24) | + ((x & 0x00000000ff000000ULL) << 8) | + ((x & 0x000000ff00000000ULL) >> 8) | + ((x & 0x0000ff0000000000ULL) >> 24) | + ((x & 0x00ff000000000000ULL) >> 40) | + ((x & 0xff00000000000000ULL) >> 56)); +} + +/* + * flags: flags for CCW + * Returns !0 on failure + * Returns 0 on success + */ +int ccw_send(struct virtio_ccw_device *vcdev, int code, void *data, int count, + unsigned char flags) +{ + struct ccw1 *ccw; + int ret = -1; + + ccw = alloc_io_mem(sizeof(*ccw), 0); + if (!ccw) + return ret; + + /* Build the CCW chain with a single CCW */ + ccw->code = code; + ccw->flags = flags; + ccw->count = count; + ccw->data_address = (unsigned long)data; + + ret = start_ccw1_chain(vcdev->schid, ccw); + if (!ret) + ret = wait_and_check_io_completion(vcdev->schid); + + free_io_mem(ccw, sizeof(*ccw)); + return ret; +} + +int virtio_ccw_set_revision(struct virtio_ccw_device *vcdev) +{ + struct virtio_rev_info *rev_info; + int ret = -1; + + rev_info = alloc_io_mem(sizeof(*rev_info), 0); + if (!rev_info) + return ret; + + rev_info->revision = VIRTIO_CCW_REV_MAX; + rev_info->revision = 0; + do { + ret = ccw_send(vcdev, CCW_CMD_SET_VIRTIO_REV, rev_info, + sizeof(*rev_info), 0); + } while (ret && rev_info->revision--); + + free_io_mem(rev_info, sizeof(*rev_info)); + + return ret ? -1 : rev_info->revision; +} + +int virtio_ccw_reset(struct virtio_ccw_device *vcdev) +{ + return ccw_send(vcdev, CCW_CMD_VDEV_RESET, 0, 0, 0); +} + +int virtio_ccw_read_status(struct virtio_ccw_device *vcdev) +{ + return ccw_send(vcdev, CCW_CMD_READ_STATUS, &vcdev->status, + sizeof(vcdev->status), 0); +} + +int virtio_ccw_write_status(struct virtio_ccw_device *vcdev) +{ + return ccw_send(vcdev, CCW_CMD_WRITE_STATUS, &vcdev->status, + sizeof(vcdev->status), 0); +} + +int virtio_ccw_read_features(struct virtio_ccw_device *vcdev, uint64_t *features) +{ + struct virtio_feature_desc *f_desc = &vcdev->f_desc; + + f_desc->index = 0; + if (ccw_send(vcdev, CCW_CMD_READ_FEAT, f_desc, sizeof(*f_desc), 0)) + return -1; + *features = swap32(f_desc->features); + + f_desc->index = 1; + if (ccw_send(vcdev, CCW_CMD_READ_FEAT, f_desc, sizeof(*f_desc), 0)) + return -1; + *features |= (uint64_t)swap32(f_desc->features) << 32; + + return 0; +} + +int virtio_ccw_write_features(struct virtio_ccw_device *vcdev, uint64_t features) +{ + struct virtio_feature_desc *f_desc = &vcdev->f_desc; + + f_desc->index = 0; + f_desc->features = swap32((uint32_t)features & 0xffffffff); + if (ccw_send(vcdev, CCW_CMD_WRITE_FEAT, &f_desc, sizeof(*f_desc), 0)) + return -1; + + f_desc->index = 1; + f_desc->features = swap32((uint32_t)(features >> 32) & 0xffffffff); + if (ccw_send(vcdev, CCW_CMD_WRITE_FEAT, &f_desc, sizeof(*f_desc), 0)) + return -1; + + return 0; +} + +int virtio_ccw_read_config(struct virtio_ccw_device *vcdev) +{ + return ccw_send(vcdev, CCW_CMD_READ_CONF, &vcdev->config, + sizeof(vcdev->config), 0); +} + +int virtio_ccw_write_config(struct virtio_ccw_device *vcdev) +{ + return ccw_send(vcdev, CCW_CMD_WRITE_CONF, &vcdev->config, + sizeof(vcdev->config), 0); +} + +int virtio_ccw_setup_indicators(struct virtio_ccw_device *vcdev) +{ + vcdev->ind = alloc_io_mem(sizeof(PAGE_SIZE), 0); + if (ccw_send(vcdev, CCW_CMD_SET_IND, &vcdev->ind, + sizeof(vcdev->ind), 0)) + return -1; + + vcdev->conf_ind = alloc_io_mem(PAGE_SIZE, 0); + if (ccw_send(vcdev, CCW_CMD_SET_CONF_IND, &vcdev->conf_ind, + sizeof(vcdev->conf_ind), 0)) + return -1; + + return 0; +} + +static uint64_t virtio_ccw_notify_host(int schid, int queue, uint64_t cookie) +{ + register unsigned long nr asm("1") = 0x03; + register unsigned long s asm("2") = schid; + register unsigned long q asm("3") = queue; + register long rc asm("2"); + register long c asm("4") = cookie; + + asm volatile ("diag 2,4,0x500\n" + : "=d" (rc) + : "d" (nr), "d" (s), "d" (q), "d"(c) + : "memory", "cc"); + return rc; +} + +static bool virtio_ccw_notify(struct virtqueue *vq) +{ + struct virtio_ccw_device *vcdev = to_vc_device(vq->vdev); + struct virtio_ccw_vq_info *info = vq->priv; + + info->cookie = virtio_ccw_notify_host(vcdev->schid, vq->index, + info->cookie); + if (info->cookie < 0) + return false; + return true; +} + +/* allocates a vring_virtqueue but returns a pointer to the + * virtqueue inside of it or NULL on error. + */ +static struct virtqueue *setup_vq(struct virtio_device *vdev, int index, + void (*callback)(struct virtqueue *vq), + const char *name) +{ + struct virtio_ccw_device *vcdev = to_vc_device(vdev); + struct virtio_ccw_vq_info *info; + struct vring_virtqueue *vq; + struct vring *vr; + void *queue; + + vq = alloc_io_mem(sizeof(*vq), 0); + info = alloc_io_mem(sizeof(*info), 0); + queue = alloc_io_mem(4 * PAGE_SIZE, 0); + assert(vq && queue && info); + + info->info_block = alloc_io_mem(sizeof(*info->info_block), 0); + assert(info->info_block); + + vcdev->vq_conf.index = index; + if (ccw_send(vcdev, CCW_CMD_READ_VQ_CONF, &vcdev->vq_conf, + sizeof(vcdev->vq_conf), 0)) + return NULL; + + vring_init_virtqueue(vq, index, vcdev->vq_conf.max_num, PAGE_SIZE, vdev, + queue, virtio_ccw_notify, callback, name); + + vr = &vq->vring; + info->info_block->s.desc = vr->desc; + info->info_block->s.index = index; + info->info_block->s.num = vr->num; + info->info_block->s.avail = vr->avail; + info->info_block->s.used = vr->used; + + info->info_block->l.desc = vr->desc; + info->info_block->l.index = index; + info->info_block->l.num = vr->num; + info->info_block->l.align = PAGE_SIZE; + + if (ccw_send(vcdev, CCW_CMD_SET_VQ, info->info_block, + sizeof(info->info_block->l), 0)) + return NULL; + + info->vq = &vq->vq; + vq->vq.priv = info; + + return &vq->vq; +} + +static int virtio_ccw_find_vqs(struct virtio_device *vdev, unsigned int nvqs, + struct virtqueue *vqs[], vq_callback_t *callbacks[], + const char *names[]) +{ + int i; + + for (i = 0; i < nvqs; ++i) { + vqs[i] = setup_vq(vdev, i, + callbacks ? callbacks[i] : NULL, + names ? names[i] : ""); + if (!vqs[i]) + return -1; + } + + return 0; +} + +static void virtio_ccw_config_get(struct virtio_device *vdev, + unsigned int offset, void *buf, + unsigned int len) +{ + struct virtio_ccw_device *vcdev = to_vc_device(vdev); + + if (virtio_ccw_read_config(vcdev)) + return; + memcpy(buf, vcdev->config, len); +} + +static void virtio_ccw_config_set(struct virtio_device *vdev, + unsigned int offset, const void *buf, + unsigned int len) +{ + struct virtio_ccw_device *vcdev = to_vc_device(vdev); + + memcpy(vcdev->config, buf, len); + virtio_ccw_write_config(vcdev); +} + +static const struct virtio_config_ops virtio_ccw_ops = { + .get = virtio_ccw_config_get, + .set = virtio_ccw_config_set, + .find_vqs = virtio_ccw_find_vqs, +}; + +const struct virtio_config_ops *virtio_ccw_register(void) +{ + return &virtio_ccw_ops; +} + +static int sense(struct virtio_ccw_device *vcdev) +{ + struct senseid *senseid; + + senseid = alloc_io_mem(sizeof(*senseid), 0); + assert(senseid); + + assert(!ccw_send(vcdev, CCW_CMD_SENSE_ID, senseid, sizeof(*senseid), 0)); + + assert(senseid->reserved == 0xff); + + vcdev->cu_type = senseid->cu_type; + vcdev->cu_model = senseid->cu_model; + vcdev->dev_type = senseid->dev_type; + vcdev->dev_model = senseid->dev_model; + + return 0; +} + +static struct virtio_ccw_device *find_vcdev_by_devid(int devid) +{ + struct virtio_ccw_device *dev; + struct linked_list *l; + + for (l = vcdev_list.next; l != &vcdev_list; l = l->next) { + dev = container_of(l, struct virtio_ccw_device, list); + if (dev->cu_model == devid) + return dev; + } + return NULL; +} + +struct virtio_device *virtio_bind(u32 devid) +{ + struct virtio_ccw_device *vcdev; + + vcdev = find_vcdev_by_devid(devid); + + return &vcdev->vdev; +} + +static int virtio_enumerate(int schid) +{ + struct virtio_ccw_device *vcdev; + + vcdev = alloc_io_mem(sizeof(*vcdev), 0); + assert(vcdev); + vcdev->schid = schid; + + list_add(&vcdev_list, &vcdev->list); + + assert(css_enable(schid, IO_SCH_ISC) == 0); + sense(vcdev); + + return 0; +} + +/* Must get a param */ +bool virtio_ccw_init(void) +{ + return css_enumerate(virtio_enumerate) != 0; +} diff --git a/lib/s390x/virtio-ccw.h b/lib/s390x/virtio-ccw.h new file mode 100644 index 00000000..961d8bed --- /dev/null +++ b/lib/s390x/virtio-ccw.h @@ -0,0 +1,111 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * VIRTIO-CCW definitions + * + * Copyright IBM, Corp. 2020 + * Author: Pierre Morel + * + */ + +#ifndef VIRTIO_CCW_H +#define VIRTIO_CCW_H + +#define CCW_CMD_WRITE_FEAT 0x11 +#define CCW_CMD_READ_FEAT 0x12 +#define CCW_CMD_SET_VQ 0x13 +#define CCW_CMD_WRITE_CONF 0x21 +#define CCW_CMD_READ_CONF 0x22 +#define CCW_CMD_WRITE_STATUS 0x31 +#define CCW_CMD_READ_VQ_CONF 0x32 +#define CCW_CMD_VDEV_RESET 0x33 +#define CCW_CMD_SET_IND 0x43 +#define CCW_CMD_SET_CONF_IND 0x53 +#define CCW_CMD_READ_STATUS 0x72 +#define CCW_CMD_SET_IND_ADAPTER 0x73 +#define CCW_CMD_SET_VIRTIO_REV 0x83 + +struct virtio_rev_info { +#define VIRTIO_CCW_REV_MAX 1 + uint16_t revision; + uint16_t length; + uint8_t data[]; +}; + +struct virtio_feature_desc { + uint32_t features; + uint8_t index; +} __attribute__ ((packed)); + +struct vq_config_block { + uint16_t index; + uint16_t max_num; +}; + +struct vq_info_block_legacy { + struct vring_desc *desc; + uint32_t align; + uint16_t index; + uint16_t num; +} __attribute__ ((packed)); + +struct vq_info_block { + struct vring_desc *desc; + uint32_t res0; + uint16_t index; + uint16_t num; + struct vring_avail *avail; + struct vring_used *used; +} __attribute__ ((packed)); + +#define VIRTIO_CCW_CONFIG_SIZE 0x100 + +#include +struct virtio_ccw_device { + struct virtio_device vdev; + uint8_t config[VIRTIO_CCW_CONFIG_SIZE]; + struct virtio_config_ops *config_ops; + struct virtio_feature_desc f_desc; + struct vq_config_block vq_conf; + struct linked_list list; + int schid; + uint16_t dev_type; + uint8_t dev_model; + uint16_t cu_type; + uint8_t cu_model; + uint8_t status; + uint64_t *ind; + uint64_t *conf_ind; +#define VCDEV_INIT 1 +#define VCDEV_ERROR 2 + int state; +}; + +struct virtio_ccw_vq_info { + struct virtqueue *vq; + int num; + union { + struct vq_info_block s; + struct vq_info_block_legacy l; + } *info_block; + int bit_nr; + long cookie; +}; + +#define to_vc_device(vdev_ptr) \ + container_of(vdev_ptr, struct virtio_ccw_device, vdev) + +int ccw_send(struct virtio_ccw_device *vdev, int code, void *data, int count, + unsigned char flags); +int virtio_ccw_set_revision(struct virtio_ccw_device *vdev); +int virtio_ccw_reset(struct virtio_ccw_device *vdev); +int virtio_ccw_read_config(struct virtio_ccw_device *vdev); +int virtio_ccw_write_config(struct virtio_ccw_device *vdev); +int virtio_ccw_read_status(struct virtio_ccw_device *vdev); +int virtio_ccw_write_status(struct virtio_ccw_device *vdev); +int virtio_ccw_read_features(struct virtio_ccw_device *vdev, uint64_t *f); +int virtio_ccw_write_features(struct virtio_ccw_device *vdev, uint64_t f); +int virtio_ccw_setup_indicators(struct virtio_ccw_device *vdev); + +bool virtio_ccw_init(void); +const struct virtio_config_ops *virtio_ccw_register(void); +#endif diff --git a/lib/virtio-config.h b/lib/virtio-config.h new file mode 100644 index 00000000..3507304c --- /dev/null +++ b/lib/virtio-config.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _VIRTIO_CONFIG_H_ +#define _VIRTIO_CONFIG_H_ + +#define VIRTIO_CONFIG_S_ACKNOWLEDGE 0x01 +#define VIRTIO_CONFIG_S_DRIVER 0x02 +#define VIRTIO_CONFIG_S_DRIVER_OK 0x04 +#define VIRTIO_CONFIG_S_FEATURES_OK 0x08 +#define VIRTIO_CONFIG_S_NEEDS_RESET 0x40 +#define VIRTIO_CONFIG_S_FAILED 0x80 + +/* Generic VIRTIO Features */ +#define VIRTIO_F_NOTIFY_ON_EMPTY 24 +#define VIRTIO_F_ANY_LAYOUT 27 + +/* Transport specific features */ +#define VIRTIO_TRANSPORT_F_START 28 +#define VIRTIO_F_RING_INDIRECT_DESC 28 +#define VIRTIO_F_RING_EVENT_IDX 29 +#define VIRTIO_TRANSPORT_F_END 38 + +/* New features starting with version 1 */ +#define VIRTIO_F_VERSION_1 32 +#define VIRTIO_F_IOMMU_PLATFORM 33 +#define VIRTIO_F_RING_PACKED 34 +#define VIRTIO_F_ORDER_PLATFORM 36 +#define VIRTIO_F_SR_IOV 37 + +#endif /* _VIRTIO_CONFIG_H_ */ diff --git a/s390x/Makefile b/s390x/Makefile index 6565561b..3f4acc3e 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -71,6 +71,8 @@ cflatobjs += lib/s390x/css_dump.o cflatobjs += lib/s390x/css_lib.o cflatobjs += lib/s390x/malloc_io.o cflatobjs += lib/s390x/uv.o +cflatobjs += lib/virtio.o +cflatobjs += lib/s390x/virtio-ccw.o OBJDIRS += lib/s390x From patchwork Fri Aug 27 10:17:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 12461849 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10F87C432BE for ; Fri, 27 Aug 2021 10:17:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EECC160F45 for ; Fri, 27 Aug 2021 10:17:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244931AbhH0KST (ORCPT ); Fri, 27 Aug 2021 06:18:19 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:1890 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244905AbhH0KSR (ORCPT ); Fri, 27 Aug 2021 06:18:17 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17RA8cUL121727 for ; Fri, 27 Aug 2021 06:17:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=gH+3Pa1uCvewHefIHc5QiScz4rUaSahk+Qq8/DXcgyE=; b=osKQmZjSc4pXTAa0uyo4cXitwv+R5sT4ljrjH+t0/AxeHc3wTYZylWqwvYxv/363Qjs6 ml86yTjzw5UlLoqXZju3896OwsoQvX1LmbTLaFKW7jK0H8b225VxYuqmpNA/nCCJevz8 p0dONON59tXkNkmcws6CpULFCd+T+a1UvInGEiaHVUQs2eCU70rtGbWzj+yvJ2VvFvD0 SuIDRwGXwqGrkYM8wGF1pLQSDYiz3QIRAzzM2dsm3PT9163Wf723eqbGK75JRWNDYoib ADeMAN2HCsRLk2sfaf3FvsTY+KoY3dA/ZxcWrsAVDNF65XH/z1WGwdCa5pzZQl0wVn4H JA== Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 3apv5b38wh-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 27 Aug 2021 06:17:28 -0400 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 17RA8o4v122654 for ; Fri, 27 Aug 2021 06:17:28 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0b-001b2d01.pphosted.com with ESMTP id 3apv5b38vy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 06:17:28 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 17RADEu2004885; Fri, 27 Aug 2021 10:17:26 GMT Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by ppma03ams.nl.ibm.com with ESMTP id 3ajs48ka8d-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 10:17:25 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17RAHMei49349096 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 10:17:22 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BB6324C046; Fri, 27 Aug 2021 10:17:22 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 70E614C059; Fri, 27 Aug 2021 10:17:22 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.164.230]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Aug 2021 10:17:22 +0000 (GMT) From: Pierre Morel To: kvm@vger.kernel.org Cc: frankja@linux.ibm.com, david@redhat.com, thuth@redhat.com, cohuck@redhat.com, imbrenda@linux.ibm.com, drjones@redhat.com Subject: [kvm-unit-tests PATCH 4/7] s390x: css: registering IRQ Date: Fri, 27 Aug 2021 12:17:17 +0200 Message-Id: <1630059440-15586-5-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630059440-15586-1-git-send-email-pmorel@linux.ibm.com> References: <1630059440-15586-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: cKAXLnKF3Xrp1hxeNpnz9U75Cl3G6qjv X-Proofpoint-ORIG-GUID: XdQkRijmYBeKZceHuVO3d7t9KBHMkHS6 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-08-27_03:2021-08-26,2021-08-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 lowpriorityscore=0 suspectscore=0 mlxscore=0 adultscore=0 malwarescore=0 mlxlogscore=999 priorityscore=1501 spamscore=0 bulkscore=0 phishscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270063 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Registering IRQ for the CSS level. Signed-off-by: Pierre Morel Reviewed-by: Thomas Huth --- lib/s390x/css.h | 21 +++++++++++++++++++++ lib/s390x/css_lib.c | 27 +++++++++++++++++++++++++-- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/lib/s390x/css.h b/lib/s390x/css.h index 2005f4d7..0422f2e7 100644 --- a/lib/s390x/css.h +++ b/lib/s390x/css.h @@ -402,4 +402,25 @@ struct measurement_block_format1 { uint32_t irq_prio_delay_time; }; +#include +static inline void disable_io_irq(void) +{ + uint64_t mask; + + mask = extract_psw_mask(); + mask &= ~PSW_MASK_IO; + load_psw_mask(mask); +} + +static inline void enable_io_irq(void) +{ + uint64_t mask; + + mask = extract_psw_mask(); + mask |= PSW_MASK_IO; + load_psw_mask(mask); +} + +int register_css_irq_func(void (*f)(void)); +int unregister_css_irq_func(void (*f)(void)); #endif diff --git a/lib/s390x/css_lib.c b/lib/s390x/css_lib.c index 484f9c41..a89fc93c 100644 --- a/lib/s390x/css_lib.c +++ b/lib/s390x/css_lib.c @@ -350,8 +350,29 @@ bool css_disable_mb(int schid) return retry_count > 0; } -static struct irb irb; +static void (*css_irq_func)(void); + +int register_css_irq_func(void (*f)(void)) +{ + if (css_irq_func) + return -1; + css_irq_func = f; + assert(register_io_int_func(css_irq_io) == 0); + enable_io_isc(0x80 >> IO_SCH_ISC); + return 0; +} +int unregister_css_irq_func(void (*f)(void)) +{ + if (css_irq_func != f) + return -1; + enable_io_isc(0); + unregister_io_int_func(css_irq_io); + css_irq_func = NULL; + return 0; +} + +static struct irb irb; void css_irq_io(void) { int ret = 0; @@ -386,7 +407,9 @@ void css_irq_io(void) report(0, "tsch reporting sch %08x as not operational", sid); break; case 0: - /* Stay humble on success */ + /* Call upper level IRQ routine */ + if (css_irq_func) + css_irq_func(); break; } pop: From patchwork Fri Aug 27 10:17:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 12461851 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C3210C43214 for ; Fri, 27 Aug 2021 10:17:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9FD5E60F4F for ; Fri, 27 Aug 2021 10:17:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244933AbhH0KSU (ORCPT ); Fri, 27 Aug 2021 06:18:20 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:55988 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244917AbhH0KSS (ORCPT ); Fri, 27 Aug 2021 06:18:18 -0400 Received: from pps.filterd (m0098409.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17RA7Fhc017884 for ; Fri, 27 Aug 2021 06:17:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=kSxvO69xU+QDVwvkIDlImVnpXpypanDLMyb1xgPYYR4=; b=KXlBxOTURfXMlDxAgcwfhliCt4ehIFM9/X4ksGJPLMkfL7Ddpl/CnRNcD+zyoiYBG7Er mhcuxt5qwZhN+MHx6kYBaL/MjLGpq7ZCCiLtKfedR4ehYToxONoDrvKeJfFyfFK78pnL OLkC7YoTa9Dl++nag3yiv8Rcs9g5oLAqWZ0V/XXUsOoH3K4lZR1ElcuFwrUWLJYqznfW yGDjBYaqzpvutRhwns9eHlZjuNFfjTvUhixl6ku6B9FYkQx2RJ7meThgp6szqFxklq0H QyJWej7285CZoCd0WXpL02BocPpWARRb4mTNZykMp6063VPfaRWy2FtfIQyXt0yZ+k3a /w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3apver2es5-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 27 Aug 2021 06:17:29 -0400 Received: from m0098409.ppops.net (m0098409.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 17RAHTQa063378 for ; Fri, 27 Aug 2021 06:17:29 -0400 Received: from ppma04fra.de.ibm.com (6a.4a.5195.ip4.static.sl-reverse.com [149.81.74.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 3apver2erb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 06:17:29 -0400 Received: from pps.filterd (ppma04fra.de.ibm.com [127.0.0.1]) by ppma04fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 17RAD3V8017053; Fri, 27 Aug 2021 10:17:26 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma04fra.de.ibm.com with ESMTP id 3ajs48seyj-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 10:17:26 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17RAHNJp30212416 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 10:17:23 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 16F054C05E; Fri, 27 Aug 2021 10:17:23 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C9A2F4C04A; Fri, 27 Aug 2021 10:17:22 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.164.230]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Aug 2021 10:17:22 +0000 (GMT) From: Pierre Morel To: kvm@vger.kernel.org Cc: frankja@linux.ibm.com, david@redhat.com, thuth@redhat.com, cohuck@redhat.com, imbrenda@linux.ibm.com, drjones@redhat.com Subject: [kvm-unit-tests PATCH 5/7] virtio: implement the virtio_add_inbuf routine Date: Fri, 27 Aug 2021 12:17:18 +0200 Message-Id: <1630059440-15586-6-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630059440-15586-1-git-send-email-pmorel@linux.ibm.com> References: <1630059440-15586-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: H7JWrOBiZolIo8ajoalkY-JIGnajfxaX X-Proofpoint-GUID: 6D_txT4PadQPObuBgWj0xZO5ElWJrmaj X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-08-27_03:2021-08-26,2021-08-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 phishscore=0 adultscore=0 malwarescore=0 lowpriorityscore=0 bulkscore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 priorityscore=1501 impostorscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270063 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org To communicate in both directions with a VIRTIO device we need to add the incoming communication to the VIRTIO level. Signed-off-by: Pierre Morel Reviewed-by: Andrew Jones --- lib/virtio.c | 32 ++++++++++++++++++++++++++++++++ lib/virtio.h | 2 ++ 2 files changed, 34 insertions(+) diff --git a/lib/virtio.c b/lib/virtio.c index e10153b9..b84bc680 100644 --- a/lib/virtio.c +++ b/lib/virtio.c @@ -47,6 +47,38 @@ void vring_init_virtqueue(struct vring_virtqueue *vq, unsigned index, vq->data[i] = NULL; } +int virtqueue_add_inbuf(struct virtqueue *_vq, char *buf, unsigned int len) +{ + struct vring_virtqueue *vq = to_vvq(_vq); + unsigned int avail; + int head; + + assert(buf); + assert(len); + + if (!vq->vq.num_free) + return -1; + + --vq->vq.num_free; + + head = vq->free_head; + + vq->vring.desc[head].flags = 0; + vq->vring.desc[head].addr = virt_to_phys(buf); + vq->vring.desc[head].len = len; + + vq->free_head = vq->vring.desc[head].next; + + vq->data[head] = buf; + + avail = (vq->vring.avail->idx & (vq->vring.num - 1)); + vq->vring.avail->ring[avail] = head; + wmb(); /* be sure to update the ring before updating the idx */ + vq->vring.avail->idx++; + vq->num_added++; + + return 0; +} int virtqueue_add_outbuf(struct virtqueue *_vq, char *buf, unsigned int len) { struct vring_virtqueue *vq = to_vvq(_vq); diff --git a/lib/virtio.h b/lib/virtio.h index 2c31fdc7..44b727f8 100644 --- a/lib/virtio.h +++ b/lib/virtio.h @@ -141,6 +141,8 @@ extern void vring_init_virtqueue(struct vring_virtqueue *vq, unsigned index, const char *name); extern int virtqueue_add_outbuf(struct virtqueue *vq, char *buf, unsigned int len); +extern int virtqueue_add_inbuf(struct virtqueue *vq, char *buf, + unsigned int len); extern bool virtqueue_kick(struct virtqueue *vq); extern void detach_buf(struct vring_virtqueue *vq, unsigned head); extern void *virtqueue_get_buf(struct virtqueue *_vq, unsigned int *len); From patchwork Fri Aug 27 10:17:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 12461853 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 92BE1C4320A for ; Fri, 27 Aug 2021 10:17:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7CE4F60560 for ; Fri, 27 Aug 2021 10:17:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244720AbhH0KSV (ORCPT ); Fri, 27 Aug 2021 06:18:21 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:22776 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244926AbhH0KSS (ORCPT ); Fri, 27 Aug 2021 06:18:18 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17RA4Rwo027298 for ; Fri, 27 Aug 2021 06:17:30 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=3T4FgP9AeH0NQHrp/R4MzARHy3e44BZguJfCVFUbHDc=; b=fEyO6biDk0JcW/uLT8C84ik8iiey5KJwFnACNYtGT/p0uI86oLr7d4MQTB1SAsiM7IiJ muohd5mm+Cze3+6UPOxEC8VD84aZ1cT1V0huIvC0mU6ezv8joN9Fci45vA/r+3LnMhvV uxh/ikW3r9r1UoUnmzeiYwAy+JSBm9arLS3j1LQHgVYzqj4zK3N6Godk9E0FF9PTyN1V eY+tI2NAO1cv4ZOHK8nnmzisiIXKyk4pBSHx0f7u/WS+p7bOjF8Vxgb4aVdk77T6xIPH K+ht78Eslkp2uvPb7xDF27a6Esx9o+Kqh2TJnUUqUd3MrDid4/l9BZeaW0BkQQgVwYQY /w== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3apwpm8st9-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 27 Aug 2021 06:17:29 -0400 Received: from m0098393.ppops.net (m0098393.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 17RA4TWC027496 for ; Fri, 27 Aug 2021 06:17:29 -0400 Received: from ppma03ams.nl.ibm.com (62.31.33a9.ip4.static.sl-reverse.com [169.51.49.98]) by mx0a-001b2d01.pphosted.com with ESMTP id 3apwpm8ssg-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 06:17:29 -0400 Received: from pps.filterd (ppma03ams.nl.ibm.com [127.0.0.1]) by ppma03ams.nl.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 17RADEu3004885; Fri, 27 Aug 2021 10:17:27 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma03ams.nl.ibm.com with ESMTP id 3ajs48ka8e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 10:17:27 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17RAHNuc29688150 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 10:17:23 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 7BB424C050; Fri, 27 Aug 2021 10:17:23 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 2F44B4C040; Fri, 27 Aug 2021 10:17:23 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.164.230]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Aug 2021 10:17:23 +0000 (GMT) From: Pierre Morel To: kvm@vger.kernel.org Cc: frankja@linux.ibm.com, david@redhat.com, thuth@redhat.com, cohuck@redhat.com, imbrenda@linux.ibm.com, drjones@redhat.com Subject: [kvm-unit-tests PATCH 6/7] s390x: virtio tests setup Date: Fri, 27 Aug 2021 12:17:19 +0200 Message-Id: <1630059440-15586-7-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630059440-15586-1-git-send-email-pmorel@linux.ibm.com> References: <1630059440-15586-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-ORIG-GUID: 6V5-QHZ4e41dhmnMsx8osjtDgu8N6V-K X-Proofpoint-GUID: WiheB8Un6wcMbQqt1F6xYeZTCzSNqWgX X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-08-27_03:2021-08-26,2021-08-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 impostorscore=0 mlxscore=0 phishscore=0 clxscore=1015 mlxlogscore=999 suspectscore=0 adultscore=0 priorityscore=1501 malwarescore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270063 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org This patch can be squatch with the next one, "s390x: virtio data transfer" and is separated to ease review. In this patch we initialize the VIRTIO device. There are currently no error insertion, the goal is to get an initialized device to check data transfer within the next patch. Future development will include error response checks. Signed-off-by: Pierre Morel --- s390x/Makefile | 1 + s390x/unittests.cfg | 4 + s390x/virtio_pong.c | 208 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 213 insertions(+) create mode 100644 s390x/virtio_pong.c diff --git a/s390x/Makefile b/s390x/Makefile index 3f4acc3e..633e1af1 100644 --- a/s390x/Makefile +++ b/s390x/Makefile @@ -24,6 +24,7 @@ tests += $(TEST_DIR)/mvpg.elf tests += $(TEST_DIR)/uv-host.elf tests += $(TEST_DIR)/edat.elf tests += $(TEST_DIR)/mvpg-sie.elf +tests += $(TEST_DIR)/virtio_pong.elf tests_binary = $(patsubst %.elf,%.bin,$(tests)) ifneq ($(HOST_KEY_DOCUMENT),) diff --git a/s390x/unittests.cfg b/s390x/unittests.cfg index 9e1802fd..dd84ed28 100644 --- a/s390x/unittests.cfg +++ b/s390x/unittests.cfg @@ -109,3 +109,7 @@ file = edat.elf [mvpg-sie] file = mvpg-sie.elf + +[virtio-pong] +file = uv-virtio.elf +extra_params = -device virtio-pong-cww diff --git a/s390x/virtio_pong.c b/s390x/virtio_pong.c new file mode 100644 index 00000000..1e050a4d --- /dev/null +++ b/s390x/virtio_pong.c @@ -0,0 +1,208 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Channel Subsystem tests + * + * Copyright (c) 2021 IBM Corp + * + * Authors: + * Pierre Morel + * + */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#define VIRTIO_ID_PONG 30 /* virtio pong */ + +#define VIRTIO_F_PONG_CKSUM 1 + +#define SUPPORTED_FEATURES (1UL << VIRTIO_F_RING_INDIRECT_DESC | \ + 1UL << VIRTIO_F_RING_EVENT_IDX | \ + 1UL << VIRTIO_F_NOTIFY_ON_EMPTY | \ + 1UL << VIRTIO_F_ANY_LAYOUT | \ + 1UL << VIRTIO_F_PONG_CKSUM) + +static struct virtio_ccw_device *vcdev; +static struct virtqueue *out_vq; +static struct virtqueue *in_vq; + +static void test_find_vqs(void) +{ + struct virtio_device *vdev = &vcdev->vdev; + static const char *io_names[] = {"pong_input", "pong_output"}; + struct virtqueue *vqs[2]; + int ret; + + if (vcdev->state != VCDEV_INIT) { + report_skip("Device non initialized"); + vcdev->state = VCDEV_ERROR; + return; + } + + ret = vdev->config->find_vqs(vdev, 2, vqs, NULL, io_names); + if (!ret) { + in_vq = vqs[0]; + out_vq = vqs[1]; + } + report(!ret, "Find virtqueues"); +} + +static int virtio_ccw_init_dev(struct virtio_ccw_device *vcdev) +{ + uint64_t features; + uint64_t unsupported_feat; + int ret; + + ret = virtio_ccw_set_revision(vcdev); + report(!ret, "Revision 0"); + if (ret) + return VCDEV_ERROR; + + ret = virtio_ccw_reset(vcdev); + report(!ret, "RESET"); + if (ret) + return VCDEV_ERROR; + + ret = virtio_ccw_read_status(vcdev); + report(!ret && vcdev->status == 0, "Read Status : 0x%08x", vcdev->status); + if (ret) + return VCDEV_ERROR; + + vcdev->status = VIRTIO_CONFIG_S_ACKNOWLEDGE | VIRTIO_CONFIG_S_DRIVER; + ret = virtio_ccw_write_status(vcdev); + report(!ret, "Write ACKNOWLEDGE and DRIVER Status: 0x%08x", vcdev->status); + if (ret) + return VCDEV_ERROR; + + /* Checking features */ + ret = virtio_ccw_read_features(vcdev, &features); + report(!ret, "Read features : 0x%016lx", features); + if (ret) + return VCDEV_ERROR; + + report(features & 1UL << VIRTIO_F_RING_INDIRECT_DESC, + "Feature: RING_INDIRECT_DESC"); + + report(features & 1UL << VIRTIO_F_RING_EVENT_IDX, + "Feature: RING_EVENT_IDX"); + + unsupported_feat = features & ~SUPPORTED_FEATURES; + report(!unsupported_feat, "Features supported: 0x%016lx got 0x%016lx", + SUPPORTED_FEATURES, features); + if (unsupported_feat) + return VCDEV_ERROR; + + /* Accept supported features */ + features &= SUPPORTED_FEATURES; + ret = virtio_ccw_write_features(vcdev, features); + report(!ret, "Write features: 0x%016lx", features); + if (ret) + return VCDEV_ERROR; + + vcdev->status |= VIRTIO_CONFIG_S_FEATURES_OK; + ret = virtio_ccw_write_status(vcdev); + report(!ret, "Write FEATURES_OK Status: 0x%08x", vcdev->status); + if (ret) + return VCDEV_ERROR; + + ret = virtio_ccw_read_status(vcdev); + report(!ret, "Read Status : 0x%08x", vcdev->status); + if (ret) + return VCDEV_ERROR; + report(vcdev->status & VIRTIO_CONFIG_S_FEATURES_OK, "Status: FEATURES_OK"); + if (!(vcdev->status & VIRTIO_CONFIG_S_FEATURES_OK)) + return VCDEV_ERROR; + + ret = virtio_ccw_setup_indicators(vcdev); + report(!ret, "Setup indicators"); + if (ret) + return VCDEV_ERROR; + + vcdev->vdev.config = virtio_ccw_register(); + if (!vcdev->vdev.config) + return VCDEV_ERROR; + + vcdev->status |= VIRTIO_CONFIG_S_DRIVER_OK; + ret = virtio_ccw_write_status(vcdev); + report(!ret, "Write DRIVER_OK Status: 0x%08x", vcdev->status); + if (ret) + return VCDEV_ERROR; + + return VCDEV_INIT; +} + +static void test_virtio_device_init(void) +{ + struct virtio_device *vdev; + + vdev = virtio_bind(VIRTIO_ID_PONG); + if (!vdev) { + report_abort("virtio_bind failed"); + return; + } + + vcdev = to_vc_device(vdev); + vcdev->state = virtio_ccw_init_dev(vcdev); + report(vcdev->state == VCDEV_INIT, "Initialization"); +} + +static void test_virtio_ccw_bus(void) +{ + report(virtio_ccw_init(), "Initialisation"); +} + +static void virtio_irq(void) +{ + /* + * Empty function currently needed to setup IRQ by providing + * an address to register_css_irq_func(). + * Will be use in the future to check parallel I/O. + */ +} + +static int css_init(void) +{ + assert(register_css_irq_func(virtio_irq) == 0); + return 0; +} + +static struct { + const char *name; + void (*func)(void); +} tests[] = { + { "CCW Bus", test_virtio_ccw_bus }, + { "CCW Device", test_virtio_device_init }, + { "Queues setup", test_find_vqs }, + { NULL, NULL } +}; + +int main(int argc, char *argv[]) +{ + int i; + + report_prefix_push("Virtio"); + + css_init(); + + for (i = 0; tests[i].name; i++) { + report_prefix_push(tests[i].name); + tests[i].func(); + report_prefix_pop(); + } + report_prefix_pop(); + + return report_summary(); +} From patchwork Fri Aug 27 10:17:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Morel X-Patchwork-Id: 12461855 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5BC77C432BE for ; Fri, 27 Aug 2021 10:17:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4152660F45 for ; Fri, 27 Aug 2021 10:17:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244944AbhH0KSW (ORCPT ); Fri, 27 Aug 2021 06:18:22 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:9282 "EHLO mx0b-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244893AbhH0KSS (ORCPT ); Fri, 27 Aug 2021 06:18:18 -0400 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.43/8.16.0.43) with SMTP id 17RA3k79015398 for ; Fri, 27 Aug 2021 06:17:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=from : to : cc : subject : date : message-id : in-reply-to : references; s=pp1; bh=e/TFctog32ZuAw/9ZFT3YqSS8y99KOD43Gkj0ce7l2U=; b=r6L9wwG8SM+LHaN6uhBFRnrJuhpoLhiU1SFhSlX2ke0zzHCr2lSe8i0U5PtwJ611kEVD KQEFW1kPIsdDYG9jeGIPYCB8LMqkZe2P7i3kE7q/c3uarwaNtanQnOeq2s72IXb0Yq7D jawsSLO4NZcmUpEJi5xuqxLeiHOROvSyKAiGj/XsDstx1HUDeu8jPdyF1Df3gzPbxxcT arvTY8cubkKZzMVg5+LF7RRx5YqElN1aOyiblVNxM0942oqaLHoX/T2WckmXXWDJj4kD aD39+V6z8N16hzwpXaL4P/RVhOTMsu8AsKVZkOq7Ab8LJzgk5PWDSvorr8DtkoNt1adW dw== Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 3apws50n2q-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Fri, 27 Aug 2021 06:17:29 -0400 Received: from m0098417.ppops.net (m0098417.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.43/8.16.0.43) with SMTP id 17RABFC4057206 for ; Fri, 27 Aug 2021 06:17:29 -0400 Received: from ppma01fra.de.ibm.com (46.49.7a9f.ip4.static.sl-reverse.com [159.122.73.70]) by mx0a-001b2d01.pphosted.com with ESMTP id 3apws50n1x-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 06:17:29 -0400 Received: from pps.filterd (ppma01fra.de.ibm.com [127.0.0.1]) by ppma01fra.de.ibm.com (8.16.1.2/8.16.1.2) with SMTP id 17RAD1Kg001860; Fri, 27 Aug 2021 10:17:27 GMT Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by ppma01fra.de.ibm.com with ESMTP id 3ajs48henc-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Aug 2021 10:17:27 +0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 17RAHNxs30212426 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 27 Aug 2021 10:17:24 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DE60C4C04A; Fri, 27 Aug 2021 10:17:23 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 88AAE4C046; Fri, 27 Aug 2021 10:17:23 +0000 (GMT) Received: from oc3016276355.ibm.com (unknown [9.145.164.230]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP; Fri, 27 Aug 2021 10:17:23 +0000 (GMT) From: Pierre Morel To: kvm@vger.kernel.org Cc: frankja@linux.ibm.com, david@redhat.com, thuth@redhat.com, cohuck@redhat.com, imbrenda@linux.ibm.com, drjones@redhat.com Subject: [kvm-unit-tests PATCH 7/7] s390x: virtio data transfer Date: Fri, 27 Aug 2021 12:17:20 +0200 Message-Id: <1630059440-15586-8-git-send-email-pmorel@linux.ibm.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1630059440-15586-1-git-send-email-pmorel@linux.ibm.com> References: <1630059440-15586-1-git-send-email-pmorel@linux.ibm.com> X-TM-AS-GCONF: 00 X-Proofpoint-GUID: QjccHXVGbIsylpDzqPCkfZgi9pzfRdkp X-Proofpoint-ORIG-GUID: EqEsT62DNVjMT4-FaXq8A2Y9MJrDnLz6 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.391,18.0.790 definitions=2021-08-27_03:2021-08-26,2021-08-27 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 bulkscore=0 lowpriorityscore=0 spamscore=0 impostorscore=0 malwarescore=0 clxscore=1015 mlxscore=0 mlxlogscore=999 adultscore=0 phishscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2107140000 definitions=main-2108270063 Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org We use a test device, "PONG" to transfer chunks of data of different size and alignment and compare a checksum calculated before the sending with the VIRTIO device checksum response. Signed-off-by: Pierre Morel --- s390x/virtio_pong.c | 107 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/s390x/virtio_pong.c b/s390x/virtio_pong.c index 1e050a4d..94d6acdc 100644 --- a/s390x/virtio_pong.c +++ b/s390x/virtio_pong.c @@ -39,6 +39,112 @@ static struct virtio_ccw_device *vcdev; static struct virtqueue *out_vq; static struct virtqueue *in_vq; +static bool virtio_read(struct virtqueue *q, char **buf, unsigned int *len) +{ + int ret; + char *p; + + ret = virtqueue_add_inbuf(q, *buf, *len); + if (ret < 0) + return false; + + disable_io_irq(); + virtqueue_kick(q); + wait_for_interrupt(PSW_MASK_IO); + + do { + p = virtqueue_get_buf(q, len); + } while (!p); + + *buf = (void *)p; + + return true; +} + +static bool virtio_write(struct virtqueue *q, char *buf, unsigned int len) +{ + int ret; + + ret = virtqueue_add_outbuf(q, buf, len); + if (ret < 0) + return false; + + virtqueue_kick(q); + while (!virtqueue_get_buf(q, &len)) + ; + + return true; +} + +static unsigned int simple_checksum(char *buf, unsigned int len) +{ + unsigned int sum = 0; + + while (len--) { + sum += *buf * *buf + 7 * *buf + 3; + buf++; + } + + return sum; +} + +static void pong_write(char *buf, unsigned int len) +{ + unsigned int cksum; + unsigned int cksum_ret; + char *ret_ptr = (char *)&cksum_ret; + + cksum = simple_checksum(buf, len); + report(virtio_write(out_vq, buf, len), "Sending data: %08x", cksum); + + len = sizeof(cksum_ret); + report(virtio_read(in_vq, &ret_ptr, &len), + "Receiving checksum: %08x", cksum_ret); + + report(cksum == cksum_ret, "Verifying checksum"); +} + +static struct { + const char *name; + int size; + int offset; +} chunks[] = { + { "Small buffer", 3, 0 }, + { "Page aligned", 4096, 0 }, + { "Large page aligned", 0x00100000, 0 }, + { "Page unaligned", 4096, 0x107 }, + { "Random data", 5119, 0x107 }, + { NULL, 0, 0 } +}; + +static void test_pong_data(void) +{ + char *buf; + char *p; + int len; + int i; + + if (vcdev->state != VCDEV_INIT) { + report_skip("Device non initialized"); + return; + } + + for (i = 0; chunks[i].name; i++) { + report_prefix_push(chunks[i].name); + + len = chunks[i].size + chunks[i].offset; + buf = alloc_io_mem(len, 0); + + p = buf + chunks[i].offset; + memset(p, 0xA5, chunks[i].size); + pong_write(p, chunks[i].size); + + free_io_mem(buf, len); + + report_prefix_pop(); + } +} + static void test_find_vqs(void) { struct virtio_device *vdev = &vcdev->vdev; @@ -186,6 +292,7 @@ static struct { { "CCW Bus", test_virtio_ccw_bus }, { "CCW Device", test_virtio_device_init }, { "Queues setup", test_find_vqs }, + { "Data transfer", test_pong_data }, { NULL, NULL } };