From nobody Mon May 6 22:26:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487765872388883.5546551517183; Wed, 22 Feb 2017 04:17:52 -0800 (PST) Received: from localhost ([::1]:51813 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVrg-0000Bg-As for importer@patchew.org; Wed, 22 Feb 2017 07:17:48 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVph-0006e3-4t for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:46 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgVpd-0003hn-LX for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:45 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:46433 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 1cgVpd-0003hX-6y for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:41 -0500 Received: from pps.filterd (m0098413.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1MC9pxK014496 for ; Wed, 22 Feb 2017 07:15:40 -0500 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0b-001b2d01.pphosted.com with ESMTP id 28s7gxfwmw-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Feb 2017 07:15:40 -0500 Received: from localhost by e06smtp10.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 e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Feb 2017 12:15:35 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id AC76A17D805A; Wed, 22 Feb 2017 12:18:45 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1MCFZPI56557742; Wed, 22 Feb 2017 12:15:35 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E659BAE04D; Wed, 22 Feb 2017 11:13:25 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9ECA0AE056; Wed, 22 Feb 2017 11:13:25 +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:25 +0000 (GMT) From: Cornelia Huck To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2017 13:15:20 +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-0040-0000-0000-0000032FCB44 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17022212-0041-0000-0000-00002440C931 Message-Id: <20170222121527.7009-2-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=1 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.158.5 Subject: [Qemu-devel] [PATCH 1/8] chardev: Basic support for TN3270 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, Yang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jing Liu This introduces basic support for TN3270, which needs to negotiate three Telnet options during handshake: - End of Record - Binary Transmission - Terminal-Type As a basic implementation, this simply ignores NOP and Interrupt Process(IP) commands. More work should be done for them later. For more details, please refer to RFC 854 and 1576. Signed-off-by: Jing Liu Signed-off-by: Yang Chen Reviewed-by: QingFeng Hao Acked-by: Dong Jia Shi Signed-off-by: Cornelia Huck --- chardev/char-socket.c | 76 +++++++++++++++++++++++++++++++++++++----------= ---- chardev/char.c | 11 ++++++-- include/sysemu/char.h | 8 ++++++ qapi-schema.json | 3 ++ 4 files changed, 76 insertions(+), 22 deletions(-) diff --git a/chardev/char-socket.c b/chardev/char-socket.c index 865c52762e..9819320058 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -56,6 +56,7 @@ typedef struct { SocketAddress *addr; bool is_listen; bool is_telnet; + bool is_tn3270; =20 guint reconnect_timer; int64_t reconnect_time; @@ -142,19 +143,25 @@ static int tcp_chr_read_poll(void *opaque) return s->max_size; } =20 -#define IAC 255 -#define IAC_BREAK 243 static void tcp_chr_process_IAC_bytes(Chardev *chr, SocketChardev *s, uint8_t *buf, int *size) { - /* Handle any telnet client's basic IAC options to satisfy char by - * char mode with no echo. All IAC options will be removed from - * the buf and the do_telnetopt variable will be used to track the - * state of the width of the IAC information. + /* Handle any telnet or tn3270 client's basic IAC options. + * For telnet options, it satisfies char by char mode with no echo. + * For tn3270 options, it satisfies binary mode with EOR. + * All IAC options will be removed from the buf and the do_opt + * pointer will be used to track the state of the width of the + * IAC information. * - * IAC commands come in sets of 3 bytes with the exception of the - * "IAC BREAK" command and the double IAC. + * RFC854: "All TELNET commands consist of at least a two byte sequenc= e. + * The commands dealing with option negotiation are three byte sequenc= es, + * the third byte being the code for the option referenced." + * "IAC BREAK", "IAC IP", "IAC NOP" and the double IAC are two bytes. + * "IAC SB", "IAC SE" and "IAC EOR" are saved to split up data boundary + * for tn3270. + * NOP, Break and Interrupt Process(IP) might be encountered during a = TN3270 + * session, and NOP and IP need to be done later. */ =20 int i; @@ -175,6 +182,18 @@ static void tcp_chr_process_IAC_bytes(Chardev *chr, /* Handle IAC break commands by sending a serial break= */ qemu_chr_be_event(chr, CHR_EVENT_BREAK); s->do_telnetopt++; + } else if (s->is_tn3270 && ((unsigned char)buf[i] =3D=3D I= AC_EOR + || (unsigned char)buf[i] =3D=3D IAC_SB + || (unsigned char)buf[i] =3D=3D IAC_SE) + && s->do_telnetopt =3D=3D 2) { + buf[j++] =3D IAC; + buf[j++] =3D buf[i]; + s->do_telnetopt++; + } else if (s->is_tn3270 && ((unsigned char)buf[i] =3D=3D I= AC_IP + || (unsigned char)buf[i] =3D=3D IAC_NOP) + && s->do_telnetopt =3D=3D 2) { + /* TODO: IP and NOP need to be implemented later. */ + s->do_telnetopt++; } s->do_telnetopt++; } @@ -509,7 +528,7 @@ static void tcp_chr_update_read_handler(Chardev *chr, =20 typedef struct { Chardev *chr; - char buf[12]; + char buf[21]; size_t buflen; } TCPChardevTelnetInit; =20 @@ -547,9 +566,6 @@ static void tcp_chr_telnet_init(Chardev *chr) TCPChardevTelnetInit *init =3D g_new0(TCPChardevTelnetInit, 1); size_t n =3D 0; =20 - init->chr =3D chr; - init->buflen =3D 12; - #define IACSET(x, a, b, c) \ do { \ x[n++] =3D a; \ @@ -557,12 +573,26 @@ static void tcp_chr_telnet_init(Chardev *chr) x[n++] =3D c; \ } while (0) =20 - /* Prep the telnet negotion to put telnet in binary, - * no echo, single char mode */ - IACSET(init->buf, 0xff, 0xfb, 0x01); /* IAC WILL ECHO */ - IACSET(init->buf, 0xff, 0xfb, 0x03); /* IAC WILL Suppress go ahead */ - IACSET(init->buf, 0xff, 0xfb, 0x00); /* IAC WILL Binary */ - IACSET(init->buf, 0xff, 0xfd, 0x00); /* IAC DO Binary */ + init->chr =3D chr; + if (!s->is_tn3270) { + init->buflen =3D 12; + /* Prep the telnet negotion to put telnet in binary, + * no echo, single char mode */ + IACSET(init->buf, 0xff, 0xfb, 0x01); /* IAC WILL ECHO */ + IACSET(init->buf, 0xff, 0xfb, 0x03); /* IAC WILL Suppress go ahea= d */ + IACSET(init->buf, 0xff, 0xfb, 0x00); /* IAC WILL Binary */ + IACSET(init->buf, 0xff, 0xfd, 0x00); /* IAC DO Binary */ + } else { + init->buflen =3D 21; + /* Prep the TN3270 negotion based on RFC1576 */ + IACSET(init->buf, 0xff, 0xfd, 0x19); /* IAC DO EOR */ + IACSET(init->buf, 0xff, 0xfb, 0x19); /* IAC WILL EOR */ + IACSET(init->buf, 0xff, 0xfd, 0x00); /* IAC DO BINARY */ + IACSET(init->buf, 0xff, 0xfb, 0x00); /* IAC WILL BINARY */ + IACSET(init->buf, 0xff, 0xfd, 0x18); /* IAC DO TERMINAL TYPE */ + IACSET(init->buf, 0xff, 0xfa, 0x18); /* IAC SB TERMINAL TYPE */ + IACSET(init->buf, 0x01, 0xff, 0xf0); /* SEND IAC SE */ + } =20 #undef IACSET =20 @@ -582,7 +612,8 @@ static void tcp_chr_tls_handshake(QIOTask *task, if (qio_task_propagate_error(task, NULL)) { tcp_chr_disconnect(chr); } else { - if (s->do_telnetopt) { + /* tn3270 does not support TLS yet */ + if (s->do_telnetopt && !s->is_tn3270) { tcp_chr_telnet_init(chr); } else { tcp_chr_connect(chr); @@ -821,6 +852,7 @@ static void qmp_chardev_open_socket(Chardev *chr, bool do_nodelay =3D sock->has_nodelay ? sock->nodelay : false; bool is_listen =3D sock->has_server ? sock->server : true; bool is_telnet =3D sock->has_telnet ? sock->telnet : false; + bool is_tn3270 =3D sock->has_tn3270 ? sock->tn3270 : false; bool is_waitconnect =3D sock->has_wait ? sock->wait : false; int64_t reconnect =3D sock->has_reconnect ? sock->reconnect : 0; QIOChannelSocket *sioc =3D NULL; @@ -828,6 +860,7 @@ static void qmp_chardev_open_socket(Chardev *chr, s->is_unix =3D addr->type =3D=3D SOCKET_ADDRESS_KIND_UNIX; s->is_listen =3D is_listen; s->is_telnet =3D is_telnet; + s->is_tn3270 =3D is_tn3270; s->do_nodelay =3D do_nodelay; if (sock->tls_creds) { Object *creds; @@ -876,7 +909,7 @@ static void qmp_chardev_open_socket(Chardev *chr, addr, is_listen, is_telnet); =20 if (is_listen) { - if (is_telnet) { + if (is_telnet || is_tn3270) { s->do_telnetopt =3D 1; } } else if (reconnect > 0) { @@ -930,6 +963,7 @@ static void qemu_chr_parse_socket(QemuOpts *opts, Chard= evBackend *backend, bool is_listen =3D qemu_opt_get_bool(opts, "server", false); bool is_waitconnect =3D is_listen && qemu_opt_get_bool(opts, "wait", t= rue); bool is_telnet =3D qemu_opt_get_bool(opts, "telnet", false); + bool is_tn3270 =3D qemu_opt_get_bool(opts, "tn3270", false); bool do_nodelay =3D !qemu_opt_get_bool(opts, "delay", true); int64_t reconnect =3D qemu_opt_get_number(opts, "reconnect", 0); const char *path =3D qemu_opt_get(opts, "path"); @@ -965,6 +999,8 @@ static void qemu_chr_parse_socket(QemuOpts *opts, Chard= evBackend *backend, sock->server =3D is_listen; sock->has_telnet =3D true; sock->telnet =3D is_telnet; + sock->has_tn3270 =3D true; + sock->tn3270 =3D is_tn3270; sock->has_wait =3D true; sock->wait =3D is_waitconnect; sock->has_reconnect =3D true; diff --git a/chardev/char.c b/chardev/char.c index abd525f75e..cd6d694d1f 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -695,7 +695,8 @@ QemuOpts *qemu_chr_parse_compat(const char *label, cons= t char *filename) return opts; } if (strstart(filename, "tcp:", &p) || - strstart(filename, "telnet:", &p)) { + strstart(filename, "telnet:", &p) || + strstart(filename, "tn3270:", &p)) { if (sscanf(p, "%64[^:]:%32[^,]%n", host, port, &pos) < 2) { host[0] =3D 0; if (sscanf(p, ":%32[^,]%n", port, &pos) < 1) @@ -711,8 +712,11 @@ QemuOpts *qemu_chr_parse_compat(const char *label, con= st char *filename) goto fail; } } - if (strstart(filename, "telnet:", &p)) + if (strstart(filename, "telnet:", &p)) { qemu_opt_set(opts, "telnet", "on", &error_abort); + } else if (strstart(filename, "tn3270:", &p)) { + qemu_opt_set(opts, "tn3270", "on", &error_abort); + } return opts; } if (strstart(filename, "udp:", &p)) { @@ -1176,6 +1180,9 @@ QemuOptsList qemu_chardev_opts =3D { .name =3D "telnet", .type =3D QEMU_OPT_BOOL, },{ + .name =3D "tn3270", + .type =3D QEMU_OPT_BOOL, + },{ .name =3D "tls-creds", .type =3D QEMU_OPT_STRING, },{ diff --git a/include/sysemu/char.h b/include/sysemu/char.h index 450881d42c..f6d5cd0c9b 100644 --- a/include/sysemu/char.h +++ b/include/sysemu/char.h @@ -7,6 +7,14 @@ #include "qemu/bitmap.h" #include "qom/object.h" =20 +#define IAC_EOR 239 +#define IAC_SE 240 +#define IAC_NOP 241 +#define IAC_BREAK 243 +#define IAC_IP 244 +#define IAC_SB 250 +#define IAC 255 + /* character device */ =20 typedef enum { diff --git a/qapi-schema.json b/qapi-schema.json index baa0d263d6..ee144871bf 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4774,6 +4774,8 @@ # @nodelay: #optional set TCP_NODELAY socket option (default: false) # @telnet: #optional enable telnet protocol on server # sockets (default: false) +# @tn3270: #optional enable tn3270 protocol on server +# sockets (default: false) # @reconnect: #optional For a client socket, if a socket is disconnected, # then attempt a reconnect after the given number of seconds. # Setting this to zero disables this function. (default: 0) @@ -4787,6 +4789,7 @@ '*wait' : 'bool', '*nodelay' : 'bool', '*telnet' : 'bool', + '*tn3270' : 'bool', '*reconnect' : 'int' }, 'base': 'ChardevCommon' } =20 --=20 2.11.0 From nobody Mon May 6 22:26:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487765868930758.3395253181988; Wed, 22 Feb 2017 04:17:48 -0800 (PST) Received: from localhost ([::1]:51812 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVrf-0000B6-L4 for importer@patchew.org; Wed, 22 Feb 2017 07:17:47 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" 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 s= sid, uint16_t schid) (MAX_SCHID + 1) / sizeof(unsigned long)); } =20 +unsigned int css_find_free_chpid(uint8_t cssid) +{ + CssImage *css =3D channel_subsys.css[cssid]; + unsigned int chpid; + + if (!css) { + return MAX_CHPID + 1; + } + + for (chpid =3D 0; chpid <=3D MAX_CHPID; chpid++) { + /* skip reserved chpid */ + if (chpid =3D=3D 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 typ= e) { 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 =20 #define VIRTUAL_CSSID 0xfe +#define VIRTIO_CCW_CHPID 0 /* used by convention */ =20 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 typ= e); +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); --=20 2.11.0 From nobody Mon May 6 22:26:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487766151781696.1228285323537; Wed, 22 Feb 2017 04:22:31 -0800 (PST) Received: from localhost ([::1]:51835 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVwA-000440-F6 for importer@patchew.org; Wed, 22 Feb 2017 07:22:26 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35806) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVpk-0006fx-MD for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgVph-0003iX-AY for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:48 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:48450) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgVph-0003iB-1T for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:45 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1MCC0P0052301 for ; Wed, 22 Feb 2017 07:15:43 -0500 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 28s7ww6yyt-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Feb 2017 07:15:43 -0500 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Feb 2017 12:15:40 -0000 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Feb 2017 12:15:38 -0000 Received: from b06cxnps3075.portsmouth.uk.ibm.com (d06relay10.portsmouth.uk.ibm.com [9.149.109.195]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id 572B717D8056; Wed, 22 Feb 2017 12:18:48 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1MCFb7b8847796; Wed, 22 Feb 2017 12:15:37 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 91382AE05D; Wed, 22 Feb 2017 11:13:28 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5555DAE045; Wed, 22 Feb 2017 11:13:28 +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:28 +0000 (GMT) From: Cornelia Huck To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2017 13:15:22 +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-0040-0000-0000-0000032FCB47 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17022212-0041-0000-0000-00002440C936 Message-Id: <20170222121527.7009-4-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 3/8] s390x/3270: Add abstract emulated ccw-attached 3270 device 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, Yang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Yang Chen This introduces the infrastructure for the emulated 3270 devices, which will be attached to the virtual-css-bus. Signed-off-by: Yang Chen Signed-off-by: Jing Liu Reviewed-by: QingFeng Hao Reviewed-by: Dong Jia Shi Signed-off-by: Cornelia Huck --- hw/s390x/3270-ccw.c | 94 +++++++++++++++++++++++++++++++++++++++++= ++++ hw/s390x/Makefile.objs | 1 + include/hw/s390x/3270-ccw.h | 44 +++++++++++++++++++++ 3 files changed, 139 insertions(+) create mode 100644 hw/s390x/3270-ccw.c create mode 100644 include/hw/s390x/3270-ccw.h diff --git a/hw/s390x/3270-ccw.c b/hw/s390x/3270-ccw.c new file mode 100644 index 0000000000..3a84c5b9dc --- /dev/null +++ b/hw/s390x/3270-ccw.c @@ -0,0 +1,94 @@ +/* + * Emulated ccw-attached 3270 implementation + * + * Copyright 2017 IBM Corp. + * Author(s): Yang Chen + * Jing Liu + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at + * your option) any later version. See the COPYING file in the top-level + * directory. + */ +#include "qemu/osdep.h" +#include "qapi/error.h" +#include "qemu/module.h" +#include "cpu.h" +#include "hw/s390x/css.h" +#include "hw/s390x/css-bridge.h" +#include "hw/s390x/3270-ccw.h" + +static void emulated_ccw_3270_realize(DeviceState *ds, Error **errp) +{ + uint16_t chpid; + EmulatedCcw3270Device *dev =3D EMULATED_CCW_3270(ds); + EmulatedCcw3270Class *ck =3D EMULATED_CCW_3270_GET_CLASS(dev); + CcwDevice *cdev =3D CCW_DEVICE(ds); + SubchDev *sch =3D css_create_virtual_sch(cdev->bus_id, errp); + Error *err =3D NULL; + + if (!sch) { + return; + } + + if (!ck->init) { + goto out_err; + } + + sch->driver_data =3D dev; + cdev->sch =3D sch; + chpid =3D css_find_free_chpid(sch->cssid); + + if (chpid > MAX_CHPID) { + error_setg(errp, "No available chpid to use."); + goto out_err; + } + + sch->id.reserved =3D 0xff; + sch->id.cu_type =3D EMULATED_CCW_3270_CU_TYPE; + css_sch_build_virtual_schib(sch, (uint8_t)chpid, + EMULATED_CCW_3270_CHPID_TYPE); + + ck->init(dev, &err); + if (err) { + error_propagate(errp, err); + goto out_err; + } + + return; + +out_err: + css_subch_assign(sch->cssid, sch->ssid, sch->schid, sch->devno, NULL); + cdev->sch =3D NULL; + g_free(sch); +} + +static Property emulated_ccw_3270_properties[] =3D { + DEFINE_PROP_CSS_DEV_ID("devno", EmulatedCcw3270Device, parent_obj.bus_= id), + DEFINE_PROP_END_OF_LIST(), +}; + +static void emulated_ccw_3270_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc =3D DEVICE_CLASS(klass); + + dc->props =3D emulated_ccw_3270_properties; + dc->bus_type =3D TYPE_VIRTUAL_CSS_BUS; + dc->realize =3D emulated_ccw_3270_realize; + dc->hotpluggable =3D false; +} + +static const TypeInfo emulated_ccw_3270_info =3D { + .name =3D TYPE_EMULATED_CCW_3270, + .parent =3D TYPE_CCW_DEVICE, + .instance_size =3D sizeof(EmulatedCcw3270Device), + .class_init =3D emulated_ccw_3270_class_init, + .class_size =3D sizeof(EmulatedCcw3270Class), + .abstract =3D true, +}; + +static void emulated_ccw_register(void) +{ + type_register_static(&emulated_ccw_3270_info); +} + +type_init(emulated_ccw_register) diff --git a/hw/s390x/Makefile.objs b/hw/s390x/Makefile.objs index 41ac4ec325..36bd4b1645 100644 --- a/hw/s390x/Makefile.objs +++ b/hw/s390x/Makefile.objs @@ -7,6 +7,7 @@ obj-y +=3D sclpcpu.o obj-y +=3D ipl.o obj-y +=3D css.o obj-y +=3D s390-virtio-ccw.o +obj-y +=3D 3270-ccw.o obj-y +=3D virtio-ccw.o obj-y +=3D css-bridge.o obj-y +=3D ccw-device.o diff --git a/include/hw/s390x/3270-ccw.h b/include/hw/s390x/3270-ccw.h new file mode 100644 index 0000000000..45ea515e9f --- /dev/null +++ b/include/hw/s390x/3270-ccw.h @@ -0,0 +1,44 @@ +/* + * Emulated ccw-attached 3270 definitions + * + * Copyright 2017 IBM Corp. + * Author(s): Yang Chen + * Jing Liu + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at + * your option) any later version. See the COPYING file in the top-level + * directory. + */ + +#ifndef HW_S390X_3270_CCW_H +#define HW_S390X_3270_CCW_H + +#include "hw/sysbus.h" +#include "hw/s390x/css.h" +#include "hw/s390x/ccw-device.h" + +#define EMULATED_CCW_3270_CU_TYPE 0x3270 +#define EMULATED_CCW_3270_CHPID_TYPE 0x1a + +#define TYPE_EMULATED_CCW_3270 "emulated-ccw-3270" +#define EMULATED_CCW_3270(obj) \ + OBJECT_CHECK(EmulatedCcw3270Device, (obj), TYPE_EMULATED_CCW_3270) +#define EMULATED_CCW_3270_CLASS(klass) \ + OBJECT_CLASS_CHECK(EmulatedCcw3270Class, (klass), TYPE_EMULATED_CCW_3= 270) +#define EMULATED_CCW_3270_GET_CLASS(obj) \ + OBJECT_GET_CLASS(EmulatedCcw3270Class, (obj), TYPE_EMULATED_CCW_3270) + +typedef struct EmulatedCcw3270Device { + CcwDevice parent_obj; +} EmulatedCcw3270Device; + +typedef struct EmulatedCcw3270Class { + CCWDeviceClass parent_class; + + void (*init)(EmulatedCcw3270Device *, Error **); + int (*read_payload_3270)(EmulatedCcw3270Device *, uint32_t, uint16_t); + int (*write_payload_3270)(EmulatedCcw3270Device *, uint8_t, uint32_t, + uint16_t); +} EmulatedCcw3270Class; + +#endif --=20 2.11.0 From nobody Mon May 6 22:26:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487766144596874.566934055067; Wed, 22 Feb 2017 04:22:24 -0800 (PST) Received: from localhost ([::1]:51834 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVw5-00040R-TC for importer@patchew.org; Wed, 22 Feb 2017 07:22:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35800) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVpk-0006fh-AY for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:49 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgVpg-0003iJ-Jq for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:48 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:57590 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 1cgVpg-0003i6-Ci for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:44 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1MC9vtD144066 for ; Wed, 22 Feb 2017 07:15:43 -0500 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0b-001b2d01.pphosted.com with ESMTP id 28s9r3t5nk-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Feb 2017 07:15:43 -0500 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Feb 2017 12:15:41 -0000 Received: from d06dlp01.portsmouth.uk.ibm.com (9.149.20.13) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Feb 2017 12:15:39 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp01.portsmouth.uk.ibm.com (Postfix) with ESMTP id ADA0A17D805A; Wed, 22 Feb 2017 12:18:49 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1MCFdRT64749708; Wed, 22 Feb 2017 12:15:39 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E4833AE053; Wed, 22 Feb 2017 11:13:29 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id A8A7FAE045; Wed, 22 Feb 2017 11:13:29 +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:29 +0000 (GMT) From: Cornelia Huck To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2017 13:15:23 +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-0028-0000-0000-000002AFCF11 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17022212-0029-0000-0000-00002277AFD9 Message-Id: <20170222121527.7009-5-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=1 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.158.5 Subject: [Qemu-devel] [PATCH 4/8] s390x/3270: Add emulated terminal3270 device 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, Yang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Yang Chen This is a basic implementation of the emulated ccw-attached 3270 called x-terminal3270, which provides visibility of the device in the qemu monitor and guest. The x prefix indicates that this is just an experimental implementation for the current stage. This device will not be compiled until the basic functions are available. Signed-off-by: Yang Chen Signed-off-by: Jing Liu Reviewed-by: QingFeng Hao Reviewed-by: Dong Jia Shi Signed-off-by: Cornelia Huck --- hw/char/terminal3270.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 54 insertions(+) create mode 100644 hw/char/terminal3270.c diff --git a/hw/char/terminal3270.c b/hw/char/terminal3270.c new file mode 100644 index 0000000000..bef3812c18 --- /dev/null +++ b/hw/char/terminal3270.c @@ -0,0 +1,54 @@ +/* + * Terminal 3270 implementation + * + * Copyright 2017 IBM Corp. + * + * Authors: Yang Chen + * Jing Liu + * + * This work is licensed under the terms of the GNU GPL, version 2 or (at + * your option) any later version. See the COPYING file in the top-level + * directory. + */ + +#include "qemu/osdep.h" +#include "hw/s390x/3270-ccw.h" + +typedef struct Terminal3270 { + EmulatedCcw3270Device cdev; +} Terminal3270; + +#define TYPE_TERMINAL_3270 "x-terminal3270" + +static void terminal_init(EmulatedCcw3270Device *dev, Error **errp) +{ + static bool terminal_available; + + if (terminal_available) { + error_setg(errp, "Multiple 3270 terminals are not supported."); + return; + } + terminal_available =3D true; +} + +static void terminal_class_init(ObjectClass *klass, void *data) +{ + EmulatedCcw3270Class *ck =3D EMULATED_CCW_3270_CLASS(klass); + + ck->init =3D terminal_init; +} + +static const TypeInfo ccw_terminal_info =3D { + .name =3D TYPE_TERMINAL_3270, + .parent =3D TYPE_EMULATED_CCW_3270, + .instance_size =3D sizeof(Terminal3270), + .class_init =3D terminal_class_init, + .class_size =3D sizeof(EmulatedCcw3270Class), +}; + +static void register_types(void) +{ + type_register_static(&ccw_terminal_info); +} + +type_init(register_types) --=20 2.11.0 From nobody Mon May 6 22:26:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148776613689372.92841235492313; Wed, 22 Feb 2017 04:22:16 -0800 (PST) Received: from localhost ([::1]:51833 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVvz-0003mA-F2 for importer@patchew.org; Wed, 22 Feb 2017 07:22:15 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35831) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVpm-0006hz-JA for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:53 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgVpj-0003j8-9K for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:50 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:51586 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 1cgVpj-0003it-0O for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:47 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1MC9gmu032079 for ; Wed, 22 Feb 2017 07:15:46 -0500 Received: from e06smtp08.uk.ibm.com (e06smtp08.uk.ibm.com [195.75.94.104]) by mx0b-001b2d01.pphosted.com with ESMTP id 28s6qehqks-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Feb 2017 07:15:46 -0500 Received: from localhost by e06smtp08.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Feb 2017 12:15:44 -0000 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp08.uk.ibm.com (192.168.101.138) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Feb 2017 12:15:41 -0000 Received: from b06cxnps4075.portsmouth.uk.ibm.com (d06relay12.portsmouth.uk.ibm.com [9.149.109.197]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 44C491B0804B; Wed, 22 Feb 2017 12:18:40 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1MCFe1k60096564; Wed, 22 Feb 2017 12:15:40 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 64AADAE065; Wed, 22 Feb 2017 11:13:31 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 060B5AE045; Wed, 22 Feb 2017 11:13:31 +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:30 +0000 (GMT) From: Cornelia Huck To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2017 13:15:24 +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-0032-0000-0000-00000722A840 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17022212-0033-0000-0000-0000238606B5 Message-Id: <20170222121527.7009-6-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=1 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.158.5 Subject: [Qemu-devel] [PATCH 5/8] s390x/3270: 3270 data stream handling 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, Yang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jing Liu This introduces the input and output handlers for 3270 device, setting up the data tunnel among guest kernel, qemu and the 3270 client. After the client connected and TN3270 handshake done, signal the not-ready to ready status by an unsolicited device-end interrupt, and then the 3270 data stream could be handled correctly between the channel and socket. Multiple commands generated by "Reset" key on x3270 are not supported now, just simply terminate the connection. Signed-off-by: Jing Liu Signed-off-by: Yang Chen Reviewed-by: QingFeng Hao Reviewed-by: Dong Jia Shi Signed-off-by: Cornelia Huck --- hw/char/terminal3270.c | 180 ++++++++++++++++++++++++++++++++++++++++= ++++ hw/s390x/3270-ccw.c | 75 ++++++++++++++++++ hw/s390x/css.c | 3 + include/hw/s390x/3270-ccw.h | 9 +++ 4 files changed, 267 insertions(+) diff --git a/hw/char/terminal3270.c b/hw/char/terminal3270.c index bef3812c18..55eed5622a 100644 --- a/hw/char/terminal3270.c +++ b/hw/char/terminal3270.c @@ -12,16 +12,114 @@ */ =20 #include "qemu/osdep.h" +#include "qapi/error.h" +#include "sysemu/char.h" #include "hw/s390x/3270-ccw.h" =20 +/* Enough spaces for different window sizes. */ +#define INPUT_BUFFER_SIZE 1000 +/* + * 1 for header, 1024*2 for datastream, 2 for tail + * Reserve enough spaces for telnet IAC escape. + */ +#define OUTPUT_BUFFER_SIZE 2051 + typedef struct Terminal3270 { EmulatedCcw3270Device cdev; + CharBackend chr; + uint8_t inv[INPUT_BUFFER_SIZE]; + uint8_t outv[OUTPUT_BUFFER_SIZE]; + int in_len; + int out_len; + bool handshake_done; } Terminal3270; =20 #define TYPE_TERMINAL_3270 "x-terminal3270" +#define TERMINAL_3270(obj) \ + OBJECT_CHECK(Terminal3270, (obj), TYPE_TERMINAL_3270) + +static int terminal_can_read(void *opaque) +{ + Terminal3270 *t =3D opaque; + + return INPUT_BUFFER_SIZE - t->in_len; +} + +/* + * Protocol handshake done, + * signal guest by an unsolicited DE irq. + */ +static void TN3270_handshake_done(Terminal3270 *t) +{ + CcwDevice *ccw_dev =3D CCW_DEVICE(t); + SubchDev *sch =3D ccw_dev->sch; + + t->handshake_done =3D true; + sch->curr_status.scsw.dstat =3D SCSW_DSTAT_DEVICE_END; + css_conditional_io_interrupt(sch); +} + +/* + * Receive inbound data from socket. + * For data given to guest, drop the data boundary IAC, IAC_EOR. + * TODO: + * Using "Reset" key on x3270 may result multiple commands in one packet. + * This usually happens when the user meets a poor traffic of the network. + * As of now, for such case, we simply terminate the connection, + * and we should come back here later with a better solution. + */ +static void terminal_read(void *opaque, const uint8_t *buf, int size) +{ + Terminal3270 *t =3D opaque; + CcwDevice *ccw_dev =3D CCW_DEVICE(t); + SubchDev *sch =3D ccw_dev->sch; + int end; + + assert(size <=3D (INPUT_BUFFER_SIZE - t->in_len)); + + memcpy(&t->inv[t->in_len], buf, size); + t->in_len +=3D size; + if (t->in_len < 2) { + return; + } + + if (!t->handshake_done) { + /* + * Receiving Terminal Type is the last step of handshake. + * The data format: IAC SB Terminal-Type IS IAC SE + * The code for Terminal-Type is 0x18, for IS is 0. + * Simply check the data format and mark handshake_done. + */ + if (t->in_len > 6 && t->inv[2] =3D=3D 0x18 && t->inv[3] =3D=3D 0x0= && + t->inv[t->in_len - 2] =3D=3D IAC && t->inv[t->in_len - 1] =3D= =3D IAC_SE) { + TN3270_handshake_done(t); + t->in_len =3D 0; + } + return; + } + + for (end =3D 0; end < t->in_len - 1; end++) { + if (t->inv[end] =3D=3D IAC && t->inv[end + 1] =3D=3D IAC_EOR) { + break; + } + } + if (end =3D=3D t->in_len - 2) { + /* Data is valid for consuming. */ + t->in_len -=3D 2; + sch->curr_status.scsw.dstat =3D SCSW_DSTAT_ATTENTION; + css_conditional_io_interrupt(sch); + } else if (end < t->in_len - 2) { + /* "Reset" key is used. */ + qemu_chr_fe_disconnect(&t->chr); + } else { + /* Gathering data. */ + return; + } +} =20 static void terminal_init(EmulatedCcw3270Device *dev, Error **errp) { + Terminal3270 *t =3D TERMINAL_3270(dev); static bool terminal_available; =20 if (terminal_available) { @@ -29,13 +127,95 @@ static void terminal_init(EmulatedCcw3270Device *dev, = Error **errp) return; } terminal_available =3D true; + qemu_chr_fe_set_handlers(&t->chr, terminal_can_read, + terminal_read, NULL, t, NULL, true); +} + +static int read_payload_3270(EmulatedCcw3270Device *dev, uint32_t cda, + uint16_t count) +{ + Terminal3270 *t =3D TERMINAL_3270(dev); + int len; + + len =3D MIN(count, t->in_len); + cpu_physical_memory_write(cda, t->inv, len); + t->in_len -=3D len; + + return len; +} + +/* TN3270 uses binary transmission, which needs escape IAC to IAC IAC */ +static int insert_IAC_escape_char(uint8_t *outv, int out_len) +{ + int IAC_num =3D 0, new_out_len, i, j; + + for (i =3D 0; i < out_len; i++) { + if (outv[i] =3D=3D IAC) { + IAC_num++; + } + } + if (IAC_num =3D=3D 0) { + return out_len; + } + new_out_len =3D out_len + IAC_num; + for (i =3D out_len - 1, j =3D new_out_len - 1; j > i && i >=3D 0; i--,= j--) { + outv[j] =3D outv[i]; + if (outv[i] =3D=3D IAC) { + outv[--j] =3D IAC; + } + } + return new_out_len; } =20 +/* + * Write 3270 outbound to socket. + * Return the count of 3270 data field if succeeded, zero if failed. + */ +static int write_payload_3270(EmulatedCcw3270Device *dev, uint8_t cmd, + uint32_t cda, uint16_t count) +{ + Terminal3270 *t =3D TERMINAL_3270(dev); + int retval =3D 0; + + assert(count <=3D (OUTPUT_BUFFER_SIZE - 3) / 2); + + if (!t->handshake_done) { + /* + * Before having finished 3270 negotiation, + * sending outbound data is prohibited. + */ + return 0; + } + if (!qemu_chr_fe_get_driver(&t->chr)) { + /* We just say we consumed all data if there's no backend. */ + return count; + } + t->outv[0] =3D cmd; + cpu_physical_memory_read(cda, &t->outv[1], count); + t->out_len =3D count + 1; + + t->out_len =3D insert_IAC_escape_char(t->outv, t->out_len); + t->outv[t->out_len++] =3D IAC; + t->outv[t->out_len++] =3D IAC_EOR; + + retval =3D qemu_chr_fe_write_all(&t->chr, t->outv, t->out_len); + return (retval <=3D 0) ? 0 : (retval - 3); +} + +static Property terminal_properties[] =3D { + DEFINE_PROP_CHR("chardev", Terminal3270, chr), + DEFINE_PROP_END_OF_LIST(), +}; + static void terminal_class_init(ObjectClass *klass, void *data) { + DeviceClass *dc =3D DEVICE_CLASS(klass); EmulatedCcw3270Class *ck =3D EMULATED_CCW_3270_CLASS(klass); =20 + dc->props =3D terminal_properties; ck->init =3D terminal_init; + ck->read_payload_3270 =3D read_payload_3270; + ck->write_payload_3270 =3D write_payload_3270; } =20 static const TypeInfo ccw_terminal_info =3D { diff --git a/hw/s390x/3270-ccw.c b/hw/s390x/3270-ccw.c index 3a84c5b9dc..1f203abe0a 100644 --- a/hw/s390x/3270-ccw.c +++ b/hw/s390x/3270-ccw.c @@ -17,6 +17,80 @@ #include "hw/s390x/css-bridge.h" #include "hw/s390x/3270-ccw.h" =20 +/* Handle READ ccw commands from guest */ +static int handle_payload_3270_read(EmulatedCcw3270Device *dev, CCW1 *ccw) +{ + EmulatedCcw3270Class *ck =3D EMULATED_CCW_3270_GET_CLASS(dev); + CcwDevice *ccw_dev =3D CCW_DEVICE(dev); + int len; + + if (!ccw->cda) { + return -EFAULT; + } + + len =3D ck->read_payload_3270(dev, ccw->cda, ccw->count); + ccw_dev->sch->curr_status.scsw.count =3D ccw->count - len; + + return 0; +} + +/* Handle WRITE ccw commands to write data to client */ +static int handle_payload_3270_write(EmulatedCcw3270Device *dev, CCW1 *ccw) +{ + EmulatedCcw3270Class *ck =3D EMULATED_CCW_3270_GET_CLASS(dev); + CcwDevice *ccw_dev =3D CCW_DEVICE(dev); + int len; + + if (!ccw->cda) { + return -EFAULT; + } + + len =3D ck->write_payload_3270(dev, ccw->cmd_code, ccw->cda, ccw->coun= t); + + if (len <=3D 0) { + return -EIO; + } + + ccw_dev->sch->curr_status.scsw.count =3D ccw->count - len; + return 0; +} + +static int emulated_ccw_3270_cb(SubchDev *sch, CCW1 ccw) +{ + int rc =3D 0; + EmulatedCcw3270Device *dev =3D sch->driver_data; + + switch (ccw.cmd_code) { + case TC_WRITESF: + case TC_WRITE: + case TC_EWRITE: + case TC_EWRITEA: + rc =3D handle_payload_3270_write(dev, &ccw); + break; + case TC_RDBUF: + case TC_READMOD: + rc =3D handle_payload_3270_read(dev, &ccw); + break; + default: + rc =3D -ENOSYS; + break; + } + + if (rc =3D=3D -EIO) { + /* I/O error, specific devices generate specific conditions */ + SCSW *s =3D &sch->curr_status.scsw; + + sch->curr_status.scsw.dstat =3D SCSW_DSTAT_UNIT_CHECK; + sch->sense_data[0] =3D 0x40; /* intervention-req */ + s->ctrl &=3D ~SCSW_ACTL_START_PEND; + s->ctrl &=3D ~SCSW_CTRL_MASK_STCTL; + s->ctrl |=3D SCSW_STCTL_PRIMARY | SCSW_STCTL_SECONDARY | + SCSW_STCTL_ALERT | SCSW_STCTL_STATUS_PEND; + } + + return rc; +} + static void emulated_ccw_3270_realize(DeviceState *ds, Error **errp) { uint16_t chpid; @@ -47,6 +121,7 @@ static void emulated_ccw_3270_realize(DeviceState *ds, E= rror **errp) sch->id.cu_type =3D EMULATED_CCW_3270_CU_TYPE; css_sch_build_virtual_schib(sch, (uint8_t)chpid, EMULATED_CCW_3270_CHPID_TYPE); + sch->ccw_cb =3D emulated_ccw_3270_cb; =20 ck->init(dev, &err); if (err) { diff --git a/hw/s390x/css.c b/hw/s390x/css.c index ecafaab096..03f36970ed 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -552,6 +552,9 @@ static void sch_handle_start_func(SubchDev *sch, ORB *o= rb) s->dstat =3D SCSW_DSTAT_CHANNEL_END | SCSW_DSTAT_DEVICE_END; s->cpa =3D sch->channel_prog + 8; break; + case -EIO: + /* I/O errors, status depends on specific devices */ + break; case -ENOSYS: /* unsupported command, generate unit check (command reject) */ s->ctrl &=3D ~SCSW_ACTL_START_PEND; diff --git a/include/hw/s390x/3270-ccw.h b/include/hw/s390x/3270-ccw.h index 45ea515e9f..46bee2533c 100644 --- a/include/hw/s390x/3270-ccw.h +++ b/include/hw/s390x/3270-ccw.h @@ -21,6 +21,15 @@ #define EMULATED_CCW_3270_CHPID_TYPE 0x1a =20 #define TYPE_EMULATED_CCW_3270 "emulated-ccw-3270" + +/* Local Channel Commands */ +#define TC_WRITE 0x01 /* Write */ +#define TC_RDBUF 0x02 /* Read buffer */ +#define TC_EWRITE 0x05 /* Erase write */ +#define TC_READMOD 0x06 /* Read modified */ +#define TC_EWRITEA 0x0d /* Erase write alternate */ +#define TC_WRITESF 0x11 /* Write structured field */ + #define EMULATED_CCW_3270(obj) \ OBJECT_CHECK(EmulatedCcw3270Device, (obj), TYPE_EMULATED_CCW_3270) #define EMULATED_CCW_3270_CLASS(klass) \ --=20 2.11.0 From nobody Mon May 6 22:26:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 148776636761661.702933874938594; Wed, 22 Feb 2017 04:26:07 -0800 (PST) Received: from localhost ([::1]:51863 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVzh-00082Z-79 for importer@patchew.org; Wed, 22 Feb 2017 07:26:05 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35876) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVpq-0006lH-2I for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:57 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgVpm-0003k0-Kk for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:54 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:48284) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgVpm-0003jj-BH for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:50 -0500 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1MCABbp043851 for ; Wed, 22 Feb 2017 07:15:49 -0500 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0a-001b2d01.pphosted.com with ESMTP id 28rt1knd1x-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Feb 2017 07:15:48 -0500 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Feb 2017 12:15:45 -0000 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Feb 2017 12:15:42 -0000 Received: from b06cxnps3074.portsmouth.uk.ibm.com (d06relay09.portsmouth.uk.ibm.com [9.149.109.194]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 87B061B08023; Wed, 22 Feb 2017 12:18:41 +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 v1MCFgp115728924; Wed, 22 Feb 2017 12:15:42 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B0094AE045; Wed, 22 Feb 2017 11:13:32 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6FFE5AE05F; Wed, 22 Feb 2017 11:13:32 +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:32 +0000 (GMT) From: Cornelia Huck To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2017 13:15:25 +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-0012-0000-0000-000004D2DD2A X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17022212-0013-0000-0000-00001757DA37 Message-Id: <20170222121527.7009-7-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=1 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 6/8] s390x/3270: Add the TCP socket events handler for 3270 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jing Liu This introduces a chr_event handler to handle the 3270 connection and disconnection events. Signed-off-by: Jing Liu Reviewed-by: QingFeng Hao Reviewed-by: Dong Jia Shi Signed-off-by: Cornelia Huck --- hw/char/terminal3270.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/hw/char/terminal3270.c b/hw/char/terminal3270.c index 55eed5622a..450608e3c3 100644 --- a/hw/char/terminal3270.c +++ b/hw/char/terminal3270.c @@ -117,6 +117,32 @@ static void terminal_read(void *opaque, const uint8_t = *buf, int size) } } =20 +static void chr_event(void *opaque, int event) +{ + Terminal3270 *t =3D opaque; + CcwDevice *ccw_dev =3D CCW_DEVICE(t); + SubchDev *sch =3D ccw_dev->sch; + + /* Ensure the initial status correct, always reset them. */ + t->in_len =3D 0; + t->out_len =3D 0; + t->handshake_done =3D false; + + switch (event) { + case CHR_EVENT_OPENED: + /* + * 3270 does handshake firstly by the negotiate options in + * char-socket.c. Once qemu receives the terminal-type of the + * client, mark handshake done and trigger everything rolling agai= n. + */ + break; + case CHR_EVENT_CLOSED: + sch->curr_status.scsw.dstat =3D SCSW_DSTAT_DEVICE_END; + css_conditional_io_interrupt(sch); + break; + } +} + static void terminal_init(EmulatedCcw3270Device *dev, Error **errp) { Terminal3270 *t =3D TERMINAL_3270(dev); @@ -128,7 +154,7 @@ static void terminal_init(EmulatedCcw3270Device *dev, E= rror **errp) } terminal_available =3D true; qemu_chr_fe_set_handlers(&t->chr, terminal_can_read, - terminal_read, NULL, t, NULL, true); + terminal_read, chr_event, t, NULL, true); } =20 static int read_payload_3270(EmulatedCcw3270Device *dev, uint32_t cda, --=20 2.11.0 From nobody Mon May 6 22:26:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487765885888739.945187481172; Wed, 22 Feb 2017 04:18:05 -0800 (PST) Received: from localhost ([::1]:51814 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVrv-0000Nw-I5 for importer@patchew.org; Wed, 22 Feb 2017 07:18:03 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35891) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVpr-0006mo-UV for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:59 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgVpo-0003kX-G8 for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:55 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:34854) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cgVpo-0003kF-7D for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:52 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1MCEcfr052749 for ; Wed, 22 Feb 2017 07:15:51 -0500 Received: from e06smtp15.uk.ibm.com (e06smtp15.uk.ibm.com [195.75.94.111]) by mx0a-001b2d01.pphosted.com with ESMTP id 28s411yacn-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Feb 2017 07:15:51 -0500 Received: from localhost by e06smtp15.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Feb 2017 12:15:48 -0000 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp15.uk.ibm.com (192.168.101.145) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Feb 2017 12:15:44 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (d06relay13.portsmouth.uk.ibm.com [9.149.109.198]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id E45C01B0805F; Wed, 22 Feb 2017 12:18:42 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1MCFhUg4456826; Wed, 22 Feb 2017 12:15:43 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F23FEAE051; Wed, 22 Feb 2017 11:13:33 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BCCA3AE058; Wed, 22 Feb 2017 11:13:33 +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:33 +0000 (GMT) From: Cornelia Huck To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2017 13:15:26 +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-0000030CEFF0 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17022212-0021-0000-0000-0000407D9AD8 Message-Id: <20170222121527.7009-8-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=1 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 7/8] s390x/3270: Detect for continued presence of a 3270 client 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jing Liu To ensure that we do not keep any 3270 sockets where the client is not connected anymore, we send a packet with the timing mark option after ten minutes of client inactivity. If the client does not answer it, then the socket will be closed automatically. This helps to ensure that there is no half-open situation on the 3270 socket. Signed-off-by: Jing Liu Reviewed-by: QingFeng Hao Reviewed-by: Dong Jia Shi Signed-off-by: Cornelia Huck --- hw/char/terminal3270.c | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/hw/char/terminal3270.c b/hw/char/terminal3270.c index 450608e3c3..58bcc4be15 100644 --- a/hw/char/terminal3270.c +++ b/hw/char/terminal3270.c @@ -32,6 +32,7 @@ typedef struct Terminal3270 { int in_len; int out_len; bool handshake_done; + guint timer_tag; } Terminal3270; =20 #define TYPE_TERMINAL_3270 "x-terminal3270" @@ -60,6 +61,19 @@ static void TN3270_handshake_done(Terminal3270 *t) } =20 /* + * Called when the interval is timeout to detect + * if the client is still alive by Timing Mark. + */ +static gboolean send_timing_mark_cb(gpointer opaque) +{ + Terminal3270 *t =3D opaque; + const uint8_t timing[] =3D {0xff, 0xfd, 0x06}; + + qemu_chr_fe_write_all(&t->chr, timing, sizeof(timing)); + return true; +} + +/* * Receive inbound data from socket. * For data given to guest, drop the data boundary IAC, IAC_EOR. * TODO: @@ -77,6 +91,12 @@ static void terminal_read(void *opaque, const uint8_t *b= uf, int size) =20 assert(size <=3D (INPUT_BUFFER_SIZE - t->in_len)); =20 + if (t->timer_tag) { + g_source_remove(t->timer_tag); + t->timer_tag =3D 0; + } + t->timer_tag =3D g_timeout_add_seconds(600, send_timing_mark_cb, t); + memcpy(&t->inv[t->in_len], buf, size); t->in_len +=3D size; if (t->in_len < 2) { @@ -127,6 +147,10 @@ static void chr_event(void *opaque, int event) t->in_len =3D 0; t->out_len =3D 0; t->handshake_done =3D false; + if (t->timer_tag) { + g_source_remove(t->timer_tag); + t->timer_tag =3D 0; + } =20 switch (event) { case CHR_EVENT_OPENED: @@ -135,6 +159,7 @@ static void chr_event(void *opaque, int event) * char-socket.c. Once qemu receives the terminal-type of the * client, mark handshake done and trigger everything rolling agai= n. */ + t->timer_tag =3D g_timeout_add_seconds(600, send_timing_mark_cb, t= ); break; case CHR_EVENT_CLOSED: sch->curr_status.scsw.dstat =3D SCSW_DSTAT_DEVICE_END; @@ -206,11 +231,13 @@ static int write_payload_3270(EmulatedCcw3270Device *= dev, uint8_t cmd, assert(count <=3D (OUTPUT_BUFFER_SIZE - 3) / 2); =20 if (!t->handshake_done) { - /* - * Before having finished 3270 negotiation, - * sending outbound data is prohibited. - */ - return 0; + if (!(t->outv[0] =3D=3D IAC && t->outv[1] !=3D IAC)) { + /* + * Before having finished 3270 negotiation, + * sending outbound data except protocol options is prohibited. + */ + return 0; + } } if (!qemu_chr_fe_get_driver(&t->chr)) { /* We just say we consumed all data if there's no backend. */ --=20 2.11.0 From nobody Mon May 6 22:26:26 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1487766157557360.89889369771856; Wed, 22 Feb 2017 04:22:37 -0800 (PST) Received: from localhost ([::1]:51836 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVwK-0004CH-Ai for importer@patchew.org; Wed, 22 Feb 2017 07:22:36 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35921) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cgVpv-0006oX-83 for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:16:02 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cgVps-0003lS-1S for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:59 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:39752 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 1cgVpr-0003lA-Rc for qemu-devel@nongnu.org; Wed, 22 Feb 2017 07:15:55 -0500 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v1MC9rBs003502 for ; Wed, 22 Feb 2017 07:15:55 -0500 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 28s6y119h8-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Wed, 22 Feb 2017 07:15:54 -0500 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 22 Feb 2017 12:15:53 -0000 Received: from d06dlp03.portsmouth.uk.ibm.com (9.149.20.15) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 22 Feb 2017 12:15:50 -0000 Received: from b06cxnps4074.portsmouth.uk.ibm.com (d06relay11.portsmouth.uk.ibm.com [9.149.109.196]) by d06dlp03.portsmouth.uk.ibm.com (Postfix) with ESMTP id 256F11B08019; Wed, 22 Feb 2017 12:18:44 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v1MCFiJE7012784; Wed, 22 Feb 2017 12:15:44 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 50DACAE051; Wed, 22 Feb 2017 11:13:35 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1557DAE045; Wed, 22 Feb 2017 11:13:35 +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:35 +0000 (GMT) From: Cornelia Huck To: qemu-devel@nongnu.org Date: Wed, 22 Feb 2017 13:15:27 +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-0028-0000-0000-000002AFCF14 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17022212-0029-0000-0000-00002277AFED Message-Id: <20170222121527.7009-9-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=1 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.158.5 Subject: [Qemu-devel] [PATCH 8/8] s390x/3270: Mark non-migratable and enable the device 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, Yang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Jing Liu Mark 3270 as non-migratable for the experimental stage. Enable the 3270 device so that we can use x3270 client to operate the guest. Run qemu with the arguments: -chardev socket,id=3Dchar3270_0,host=3D0.0.0.0,port=3D23,nowait,server,= tn3270 \ -device x-terminal3270,chardev=3Dchar3270_0,devno=3Dfe.0.000a,id=3Dterm= inal3270_0 \ There are some restrictions for the first stage: We don't support SSL connections, multiple client connections and client resizing. Only tested with the x3270 client. Signed-off-by: Jing Liu Signed-off-by: Yang Chen Reviewed-by: QingFeng Hao Reviewed-by: Dong Jia Shi Signed-off-by: Cornelia Huck --- default-configs/s390x-softmmu.mak | 1 + hw/char/Makefile.objs | 1 + hw/char/terminal3270.c | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/default-configs/s390x-softmmu.mak b/default-configs/s390x-soft= mmu.mak index 36e15de336..9615a48f80 100644 --- a/default-configs/s390x-softmmu.mak +++ b/default-configs/s390x-softmmu.mak @@ -2,6 +2,7 @@ CONFIG_PCI=3Dy CONFIG_VIRTIO_PCI=3Dy CONFIG_VIRTIO=3Dy CONFIG_SCLPCONSOLE=3Dy +CONFIG_TERMINAL3270=3Dy CONFIG_S390_FLIC=3Dy CONFIG_S390_FLIC_KVM=3D$(CONFIG_KVM) CONFIG_WDT_DIAG288=3Dy diff --git a/hw/char/Makefile.objs b/hw/char/Makefile.objs index 6ea76feb12..a346820bd3 100644 --- a/hw/char/Makefile.objs +++ b/hw/char/Makefile.objs @@ -29,3 +29,4 @@ common-obj-$(CONFIG_MILKYMIST) +=3D milkymist-uart.o common-obj-$(CONFIG_SCLPCONSOLE) +=3D sclpconsole.o sclpconsole-lm.o =20 obj-$(CONFIG_VIRTIO) +=3D virtio-serial-bus.o +obj-$(CONFIG_TERMINAL3270) +=3D terminal3270.o diff --git a/hw/char/terminal3270.c b/hw/char/terminal3270.c index 58bcc4be15..b2dda01baa 100644 --- a/hw/char/terminal3270.c +++ b/hw/char/terminal3270.c @@ -260,12 +260,18 @@ static Property terminal_properties[] =3D { DEFINE_PROP_END_OF_LIST(), }; =20 +static const VMStateDescription terminal3270_vmstate =3D { + .name =3D TYPE_TERMINAL_3270, + .unmigratable =3D 1, +}; + static void terminal_class_init(ObjectClass *klass, void *data) { DeviceClass *dc =3D DEVICE_CLASS(klass); EmulatedCcw3270Class *ck =3D EMULATED_CCW_3270_CLASS(klass); =20 dc->props =3D terminal_properties; + dc->vmsd =3D &terminal3270_vmstate; ck->init =3D terminal_init; ck->read_payload_3270 =3D read_payload_3270; ck->write_payload_3270 =3D write_payload_3270; --=20 2.11.0