From nobody Mon Apr 29 11:13:50 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 1493895024753424.41776901241315; Thu, 4 May 2017 03:50:24 -0700 (PDT) Received: from localhost ([::1]:40975 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EL1-0008Sz-DL for importer@patchew.org; Thu, 04 May 2017 06:50:23 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60092) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EJ4-0006tQ-Jm for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6EIz-00061i-Vs for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:22 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:58127 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 1d6EIz-00060t-Pa for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:17 -0400 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v44AiNJf151396 for ; Thu, 4 May 2017 06:48:17 -0400 Received: from e06smtp13.uk.ibm.com (e06smtp13.uk.ibm.com [195.75.94.109]) by mx0b-001b2d01.pphosted.com with ESMTP id 2a7m0rav4c-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 04 May 2017 06:48:16 -0400 Received: from localhost by e06smtp13.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 4 May 2017 11:48:12 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp13.uk.ibm.com (192.168.101.143) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 4 May 2017 11:48:09 +0100 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v44Am9Z119595598; Thu, 4 May 2017 10:48:09 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4A86842049; Thu, 4 May 2017 11:46:48 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 03EF642045; Thu, 4 May 2017 11:46:48 +0100 (BST) Received: from gondolin.boeblingen.de.ibm.com (unknown [9.152.224.119]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 4 May 2017 11:46:47 +0100 (BST) From: Cornelia Huck To: peter.maydell@linaro.org Date: Thu, 4 May 2017 12:47:59 +0200 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170504104806.8120-1-cornelia.huck@de.ibm.com> References: <20170504104806.8120-1-cornelia.huck@de.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 17050410-0012-0000-0000-00000520CE62 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17050410-0013-0000-0000-00001853068E Message-Id: <20170504104806.8120-2-cornelia.huck@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-04_07:, , 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-1703280000 definitions=main-1705040177 Content-Transfer-Encoding: quoted-printable X-MIME-Autoconverted: from 8bit to quoted-printable by mx0b-001b2d01.pphosted.com id v44AiNJf151396 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL 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, qemu-devel@nongnu.org, borntraeger@de.ibm.com, Cornelia Huck , Yang Chen Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_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 Reviewed-by: Marc-Andr=C3=A9 Lureau --- 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 36ab0d633a..175fb8c3ec 100644 --- a/chardev/char-socket.c +++ b/chardev/char-socket.c @@ -55,6 +55,7 @@ typedef struct { SocketAddress *addr; bool is_listen; bool is_telnet; + bool is_tn3270; =20 guint reconnect_timer; int64_t reconnect_time; @@ -141,19 +142,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; @@ -174,6 +181,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++; } @@ -512,7 +531,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 @@ -550,9 +569,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; \ @@ -560,12 +576,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 @@ -585,7 +615,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); @@ -824,12 +855,14 @@ 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; =20 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; @@ -879,7 +912,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) { @@ -933,6 +966,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"); @@ -968,6 +1002,8 @@ static void qemu_chr_parse_socket(QemuOpts *opts, Char= devBackend *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 3df116350b..309734f2b7 100644 --- a/chardev/char.c +++ b/chardev/char.c @@ -696,7 +696,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) @@ -712,8 +713,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)) { @@ -1177,6 +1181,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 01b087fa16..5bb8cb79fb 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -4877,6 +4877,8 @@ # @nodelay: set TCP_NODELAY socket option (default: false) # @telnet: enable telnet protocol on server # sockets (default: false) +# @tn3270: enable tn3270 protocol on server +# sockets (default: false) (Since: 2.10) # @reconnect: 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) @@ -4890,6 +4892,7 @@ '*wait' : 'bool', '*nodelay' : 'bool', '*telnet' : 'bool', + '*tn3270' : 'bool', '*reconnect' : 'int' }, 'base': 'ChardevCommon' } =20 --=20 2.11.0 From nobody Mon Apr 29 11:13:50 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 1493895004509580.3186902265645; Thu, 4 May 2017 03:50:04 -0700 (PDT) Received: from localhost ([::1]:40973 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EKh-0008EK-5t for importer@patchew.org; Thu, 04 May 2017 06:50:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60062) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EJ1-0006rI-J6 for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:20 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6EIx-0005xo-Rw for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:19 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:57513 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 1d6EIx-0005vh-Lk for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:15 -0400 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 v44AiCtj052250 for ; Thu, 4 May 2017 06:48:14 -0400 Received: from e06smtp11.uk.ibm.com (e06smtp11.uk.ibm.com [195.75.94.107]) by mx0b-001b2d01.pphosted.com with ESMTP id 2a7w8kxs52-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 04 May 2017 06:48:14 -0400 Received: from localhost by e06smtp11.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 4 May 2017 11:48:13 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp11.uk.ibm.com (192.168.101.141) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 4 May 2017 11:48:10 +0100 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v44AmAFe40173712; Thu, 4 May 2017 10:48:10 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8C2B742045; Thu, 4 May 2017 11:46:49 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 5731242041; Thu, 4 May 2017 11:46:49 +0100 (BST) Received: from gondolin.boeblingen.de.ibm.com (unknown [9.152.224.119]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 4 May 2017 11:46:49 +0100 (BST) From: Cornelia Huck To: peter.maydell@linaro.org Date: Thu, 4 May 2017 12:48:00 +0200 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170504104806.8120-1-cornelia.huck@de.ibm.com> References: <20170504104806.8120-1-cornelia.huck@de.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17050410-0040-0000-0000-0000039DCFDF X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17050410-0041-0000-0000-00001FF9F9F5 Message-Id: <20170504104806.8120-3-cornelia.huck@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-04_07:, , 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-1703280000 definitions=main-1705040177 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL 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: Cornelia Huck , borntraeger@de.ibm.com, Jing Liu , agraf@suse.de, qemu-devel@nongnu.org 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 c03bb20bc9..d94498a97b 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -1302,6 +1302,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 f1f0d7f07a..e61fa74d9b 100644 --- a/include/hw/s390x/css.h +++ b/include/hw/s390x/css.h @@ -28,6 +28,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; @@ -115,6 +116,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 Apr 29 11:13:50 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 1493895132914509.40427474628746; Thu, 4 May 2017 03:52:12 -0700 (PDT) Received: from localhost ([::1]:40984 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EMl-0001li-Cw for importer@patchew.org; Thu, 04 May 2017 06:52:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60114) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EJ6-0006vC-WC for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6EIz-00061c-Ui for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:25 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:42366) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d6EIz-000609-LA for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:17 -0400 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 v44AiOLo130417 for ; Thu, 4 May 2017 06:48:16 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2a7ufatx9k-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 04 May 2017 06:48:16 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 4 May 2017 11:48:13 +0100 Received: from b06cxnps4075.portsmouth.uk.ibm.com (9.149.109.197) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 4 May 2017 11:48:12 +0100 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps4075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v44AmBBA37617812; Thu, 4 May 2017 10:48:11 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D355C4204B; Thu, 4 May 2017 11:46:50 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9958C42042; Thu, 4 May 2017 11:46:50 +0100 (BST) Received: from gondolin.boeblingen.de.ibm.com (unknown [9.152.224.119]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 4 May 2017 11:46:50 +0100 (BST) From: Cornelia Huck To: peter.maydell@linaro.org Date: Thu, 4 May 2017 12:48:01 +0200 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170504104806.8120-1-cornelia.huck@de.ibm.com> References: <20170504104806.8120-1-cornelia.huck@de.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17050410-0008-0000-0000-0000043B95BD X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17050410-0009-0000-0000-00001D870B2C Message-Id: <20170504104806.8120-4-cornelia.huck@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-04_07:, , 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-1703280000 definitions=main-1705040177 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL 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, qemu-devel@nongnu.org, borntraeger@de.ibm.com, Cornelia Huck , 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 | 99 +++++++++++++++++++++++++++++++++++++++++= ++++ hw/s390x/Makefile.objs | 1 + include/hw/s390x/3270-ccw.h | 44 ++++++++++++++++++++ 3 files changed, 144 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..47b9e89bb7 --- /dev/null +++ b/hw/s390x/3270-ccw.c @@ -0,0 +1,99 @@ +/* + * 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); + CCWDeviceClass *cdk =3D CCW_DEVICE_GET_CLASS(cdev); + SubchDev *sch =3D css_create_virtual_sch(cdev->devno, 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(&err, "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) { + goto out_err; + } + + cdk->realize(cdev, &err); + if (err) { + goto out_err; + } + + return; + +out_err: + error_propagate(errp, 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_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 Apr 29 11:13:50 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 1493895022688223.49502307452292; Thu, 4 May 2017 03:50:22 -0700 (PDT) Received: from localhost ([::1]:40974 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EKz-0008Rg-9U for importer@patchew.org; Thu, 04 May 2017 06:50:21 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60113) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EJ6-0006vB-WC for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6EJ1-00063b-Bc for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:25 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:42766) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d6EJ1-00062I-3F for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:19 -0400 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 v44AiRxM084830 for ; Thu, 4 May 2017 06:48:17 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2a7ux51t01-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 04 May 2017 06:48:17 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 4 May 2017 11:48:15 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 4 May 2017 11:48:13 +0100 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v44AmDuv14221810; Thu, 4 May 2017 10:48:13 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1C64C4203F; Thu, 4 May 2017 11:46:52 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id E065842045; Thu, 4 May 2017 11:46:51 +0100 (BST) Received: from gondolin.boeblingen.de.ibm.com (unknown [9.152.224.119]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 4 May 2017 11:46:51 +0100 (BST) From: Cornelia Huck To: peter.maydell@linaro.org Date: Thu, 4 May 2017 12:48:02 +0200 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170504104806.8120-1-cornelia.huck@de.ibm.com> References: <20170504104806.8120-1-cornelia.huck@de.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17050410-0016-0000-0000-000004918E09 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17050410-0017-0000-0000-00002784418A Message-Id: <20170504104806.8120-5-cornelia.huck@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-04_07:, , 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-1703280000 definitions=main-1705040177 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL 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, qemu-devel@nongnu.org, borntraeger@de.ibm.com, Cornelia Huck , 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 Apr 29 11:13:50 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 1493895157050676.4730515347056; Thu, 4 May 2017 03:52:37 -0700 (PDT) Received: from localhost ([::1]:40986 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EN8-0002OG-KN for importer@patchew.org; Thu, 04 May 2017 06:52:34 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60132) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EJ8-0006w8-3z for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6EJ2-00064p-CO for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:26 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:60352 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 1d6EJ2-00064I-5h for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:20 -0400 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 v44AiRkI119531 for ; Thu, 4 May 2017 06:48:19 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0a-001b2d01.pphosted.com with ESMTP id 2a7vsqfrcc-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 04 May 2017 06:48:19 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 4 May 2017 11:48:17 +0100 Received: from b06cxnps3075.portsmouth.uk.ibm.com (9.149.109.195) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 4 May 2017 11:48:14 +0100 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps3075.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v44AmEYK19005920; Thu, 4 May 2017 10:48:14 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 77B2442045; Thu, 4 May 2017 11:46:53 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 330994203F; Thu, 4 May 2017 11:46:53 +0100 (BST) Received: from gondolin.boeblingen.de.ibm.com (unknown [9.152.224.119]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 4 May 2017 11:46:53 +0100 (BST) From: Cornelia Huck To: peter.maydell@linaro.org Date: Thu, 4 May 2017 12:48:03 +0200 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170504104806.8120-1-cornelia.huck@de.ibm.com> References: <20170504104806.8120-1-cornelia.huck@de.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17050410-0016-0000-0000-000004918E0B X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17050410-0017-0000-0000-00002784418F Message-Id: <20170504104806.8120-6-cornelia.huck@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-04_07:, , 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-1703280000 definitions=main-1705040177 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL 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, qemu-devel@nongnu.org, borntraeger@de.ibm.com, Cornelia Huck , 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 47b9e89bb7..a7a5b412e4 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; @@ -48,6 +122,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 d94498a97b..15c4f4b249 100644 --- a/hw/s390x/css.c +++ b/hw/s390x/css.c @@ -576,6 +576,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 Apr 29 11:13:50 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 1493895152012520.3337559847112; Thu, 4 May 2017 03:52:32 -0700 (PDT) Received: from localhost ([::1]:40985 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EN4-0002F2-DE for importer@patchew.org; Thu, 04 May 2017 06:52:30 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60154) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EJB-0006yG-B7 for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:33 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6EJ4-00066t-GZ for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:29 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:59621) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d6EJ4-00065v-89 for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:22 -0400 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 v44Ai6DB044919 for ; Thu, 4 May 2017 06:48:21 -0400 Received: from e06smtp10.uk.ibm.com (e06smtp10.uk.ibm.com [195.75.94.106]) by mx0a-001b2d01.pphosted.com with ESMTP id 2a7vc3h1kt-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 04 May 2017 06:48:20 -0400 Received: from localhost by e06smtp10.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 4 May 2017 11:48:18 +0100 Received: from b06cxnps4074.portsmouth.uk.ibm.com (9.149.109.196) by e06smtp10.uk.ibm.com (192.168.101.140) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 4 May 2017 11:48:16 +0100 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v44AmEZ939583898; Thu, 4 May 2017 10:48:15 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B8D2C4204B; Thu, 4 May 2017 11:46:54 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 843E64204F; Thu, 4 May 2017 11:46:54 +0100 (BST) Received: from gondolin.boeblingen.de.ibm.com (unknown [9.152.224.119]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 4 May 2017 11:46:54 +0100 (BST) From: Cornelia Huck To: peter.maydell@linaro.org Date: Thu, 4 May 2017 12:48:04 +0200 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170504104806.8120-1-cornelia.huck@de.ibm.com> References: <20170504104806.8120-1-cornelia.huck@de.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17050410-0040-0000-0000-0000037E8C66 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17050410-0041-0000-0000-0000253A008C Message-Id: <20170504104806.8120-7-cornelia.huck@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-04_07:, , 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-1703280000 definitions=main-1705040177 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL 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: Cornelia Huck , borntraeger@de.ibm.com, Jing Liu , agraf@suse.de, qemu-devel@nongnu.org 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 Apr 29 11:13:50 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 1493895281250303.9447937272038; Thu, 4 May 2017 03:54:41 -0700 (PDT) Received: from localhost ([::1]:40994 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EPA-000497-1r for importer@patchew.org; Thu, 04 May 2017 06:54:40 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60176) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EJD-0006zZ-7h for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6EJ7-0006AG-VG for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:31 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:58477) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1d6EJ7-00069P-MK for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:25 -0400 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v44AiODM119687 for ; Thu, 4 May 2017 06:48:24 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2a7vsy7sse-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 04 May 2017 06:48:24 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 4 May 2017 11:48:21 +0100 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 4 May 2017 11:48:17 +0100 Received: from d06av24.portsmouth.uk.ibm.com (d06av24.portsmouth.uk.ibm.com [9.149.105.60]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v44AmGlr40828952; Thu, 4 May 2017 10:48:16 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id F16E44203F; Thu, 4 May 2017 11:46:55 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C584942041; Thu, 4 May 2017 11:46:55 +0100 (BST) Received: from gondolin.boeblingen.de.ibm.com (unknown [9.152.224.119]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 4 May 2017 11:46:55 +0100 (BST) From: Cornelia Huck To: peter.maydell@linaro.org Date: Thu, 4 May 2017 12:48:05 +0200 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170504104806.8120-1-cornelia.huck@de.ibm.com> References: <20170504104806.8120-1-cornelia.huck@de.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17050410-0008-0000-0000-0000043B95C2 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17050410-0009-0000-0000-00001D870B42 Message-Id: <20170504104806.8120-8-cornelia.huck@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-04_07:, , 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-1703280000 definitions=main-1705040177 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.156.1 Subject: [Qemu-devel] [PULL 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: Cornelia Huck , borntraeger@de.ibm.com, Jing Liu , agraf@suse.de, qemu-devel@nongnu.org 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 Apr 29 11:13:50 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 149389527830559.54604485975494; Thu, 4 May 2017 03:54:38 -0700 (PDT) Received: from localhost ([::1]:40993 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EP7-000462-2W for importer@patchew.org; Thu, 04 May 2017 06:54:37 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60190) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d6EJE-0006zb-Rw for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d6EJ9-0006Bp-IO for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:32 -0400 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:40570 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 1d6EJ9-0006B6-CL for qemu-devel@nongnu.org; Thu, 04 May 2017 06:48:27 -0400 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 v44Ai8l3103811 for ; Thu, 4 May 2017 06:48:26 -0400 Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110]) by mx0b-001b2d01.pphosted.com with ESMTP id 2a7rcx0jcw-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 04 May 2017 06:48:26 -0400 Received: from localhost by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 4 May 2017 11:48:20 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 4 May 2017 11:48:18 +0100 Received: from d06av24.portsmouth.uk.ibm.com (mk.ibm.com [9.149.105.60]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id v44AmIaG1638866; Thu, 4 May 2017 10:48:18 GMT Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4E67842049; Thu, 4 May 2017 11:46:57 +0100 (BST) Received: from d06av24.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 1452742041; Thu, 4 May 2017 11:46:57 +0100 (BST) Received: from gondolin.boeblingen.de.ibm.com (unknown [9.152.224.119]) by d06av24.portsmouth.uk.ibm.com (Postfix) with ESMTPS; Thu, 4 May 2017 11:46:57 +0100 (BST) From: Cornelia Huck To: peter.maydell@linaro.org Date: Thu, 4 May 2017 12:48:06 +0200 X-Mailer: git-send-email 2.11.0 In-Reply-To: <20170504104806.8120-1-cornelia.huck@de.ibm.com> References: <20170504104806.8120-1-cornelia.huck@de.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17050410-0016-0000-0000-000004918E0F X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17050410-0017-0000-0000-00002784419C Message-Id: <20170504104806.8120-9-cornelia.huck@de.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-05-04_07:, , 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-1703280000 definitions=main-1705040177 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [generic] [fuzzy] X-Received-From: 148.163.158.5 Subject: [Qemu-devel] [PULL 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, qemu-devel@nongnu.org, borntraeger@de.ibm.com, Cornelia Huck , 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 725fdc46f4..55fcb68fd2 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