From nobody Wed Oct 29 17:10:23 2025 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.zohomail.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; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 1524735114142643.8150223876055; Thu, 26 Apr 2018 02:31:54 -0700 (PDT) Received: from localhost ([::1]:41175 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBdFp-0005ny-BY for importer@patchew.org; Thu, 26 Apr 2018 05:31:53 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:51556) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fBdCm-0003jY-G5 for qemu-devel@nongnu.org; Thu, 26 Apr 2018 05:28:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fBdCj-0002pn-SO for qemu-devel@nongnu.org; Thu, 26 Apr 2018 05:28:44 -0400 Received: from mx3-rdu2.redhat.com ([66.187.233.73]:52098 helo=mx1.redhat.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fBdCj-0002pb-Mg; Thu, 26 Apr 2018 05:28:41 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0BD1A10D43F; Thu, 26 Apr 2018 09:28:38 +0000 (UTC) Received: from thh440s.redhat.com (ovpn-116-75.ams2.redhat.com [10.36.116.75]) by smtp.corp.redhat.com (Postfix) with ESMTP id 537EE2166BAD; Thu, 26 Apr 2018 09:28:36 +0000 (UTC) From: Thomas Huth To: Christian Borntraeger , qemu-s390x@nongnu.org, Viktor Mihajlovski Date: Thu, 26 Apr 2018 11:28:28 +0200 Message-Id: <1524734910-17970-2-git-send-email-thuth@redhat.com> In-Reply-To: <1524734910-17970-1-git-send-email-thuth@redhat.com> References: <1524734910-17970-1-git-send-email-thuth@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.6 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 26 Apr 2018 09:28:38 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.1]); Thu, 26 Apr 2018 09:28:38 +0000 (UTC) for IP:'10.11.54.6' DOMAIN:'int-mx06.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'thuth@redhat.com' RCPT:'' X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 66.187.233.73 Subject: [Qemu-devel] [PATCH v4 1/3] pc-bios/s390-ccw/net: Split up net_load() into init, load and release parts 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: Farhan Ali , Collin Walling , Cornelia Huck , 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" When we want to support pxelinux-style network booting later, we've got to do several TFTP transfers - and we do not want to apply for a new IP address via DHCP each time. So split up net_load into three parts: 1. net_init(), which initializes virtio-net, gets an IP address via DHCP and prints out the related information. 2. The tftp_load call is now moved directly into the main() function 3. A new net_release() function which should tear down the network stack before we are done in the firmware. This will make it easier to extend the code in the next patches. Signed-off-by: Thomas Huth --- pc-bios/s390-ccw/netmain.c | 63 +++++++++++++++++++++++++++---------------= ---- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/pc-bios/s390-ccw/netmain.c b/pc-bios/s390-ccw/netmain.c index d86d46b..8fa9e6c 100644 --- a/pc-bios/s390-ccw/netmain.c +++ b/pc-bios/s390-ccw/netmain.c @@ -128,13 +128,13 @@ static void seed_rng(uint8_t mac[]) srand(seed); } =20 -static int tftp_load(filename_ip_t *fnip, void *buffer, int len, - unsigned int retries, int ip_vers) +static int tftp_load(filename_ip_t *fnip, void *buffer, int len) { tftp_err_t tftp_err; int rc; =20 - rc =3D tftp(fnip, buffer, len, retries, &tftp_err, 1, 1428, ip_vers); + rc =3D tftp(fnip, buffer, len, DEFAULT_TFTP_RETRIES, &tftp_err, 1, 142= 8, + ip_version); =20 if (rc > 0) { printf(" TFTP: Received %s (%d KBytes)\n", fnip->filename, @@ -199,20 +199,19 @@ static int tftp_load(filename_ip_t *fnip, void *buffe= r, int len, return rc; } =20 -static int net_load(char *buffer, int len) +static int net_init(filename_ip_t *fn_ip) { - filename_ip_t fn_ip; uint8_t mac[6]; int rc; =20 - memset(&fn_ip, 0, sizeof(filename_ip_t)); + memset(fn_ip, 0, sizeof(filename_ip_t)); =20 rc =3D virtio_net_init(mac); if (rc < 0) { puts("Could not initialize network device"); return -101; } - fn_ip.fd =3D rc; + fn_ip->fd =3D rc; =20 printf(" Using MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); @@ -220,10 +219,10 @@ static int net_load(char *buffer, int len) set_mac_address(mac); /* init ethernet layer */ seed_rng(mac); =20 - rc =3D dhcp(&fn_ip, DEFAULT_BOOT_RETRIES); + rc =3D dhcp(fn_ip, DEFAULT_BOOT_RETRIES); if (rc >=3D 0) { if (ip_version =3D=3D 4) { - set_ipv4_address(fn_ip.own_ip); + set_ipv4_address(fn_ip->own_ip); } } else { puts("Could not get IP address"); @@ -232,18 +231,18 @@ static int net_load(char *buffer, int len) =20 if (ip_version =3D=3D 4) { printf(" Using IPv4 address: %d.%d.%d.%d\n", - (fn_ip.own_ip >> 24) & 0xFF, (fn_ip.own_ip >> 16) & 0xFF, - (fn_ip.own_ip >> 8) & 0xFF, fn_ip.own_ip & 0xFF); + (fn_ip->own_ip >> 24) & 0xFF, (fn_ip->own_ip >> 16) & 0xFF, + (fn_ip->own_ip >> 8) & 0xFF, fn_ip->own_ip & 0xFF); } else if (ip_version =3D=3D 6) { char ip6_str[40]; - ipv6_to_str(fn_ip.own_ip6.addr, ip6_str); + ipv6_to_str(fn_ip->own_ip6.addr, ip6_str); printf(" Using IPv6 address: %s\n", ip6_str); } =20 if (rc =3D=3D -2) { printf("ARP request to TFTP server (%d.%d.%d.%d) failed\n", - (fn_ip.server_ip >> 24) & 0xFF, (fn_ip.server_ip >> 16) & 0= xFF, - (fn_ip.server_ip >> 8) & 0xFF, fn_ip.server_ip & 0xFF); + (fn_ip->server_ip >> 24) & 0xFF, (fn_ip->server_ip >> 16) &= 0xFF, + (fn_ip->server_ip >> 8) & 0xFF, fn_ip->server_ip & 0xFF); return -102; } if (rc =3D=3D -4 || rc =3D=3D -3) { @@ -251,28 +250,31 @@ static int net_load(char *buffer, int len) return -107; } =20 + printf(" Using TFTP server: "); if (ip_version =3D=3D 4) { - printf(" Requesting file \"%s\" via TFTP from %d.%d.%d.%d\n", - fn_ip.filename, - (fn_ip.server_ip >> 24) & 0xFF, (fn_ip.server_ip >> 16) & 0= xFF, - (fn_ip.server_ip >> 8) & 0xFF, fn_ip.server_ip & 0xFF); + printf("%d.%d.%d.%d\n", + (fn_ip->server_ip >> 24) & 0xFF, (fn_ip->server_ip >> 16) &= 0xFF, + (fn_ip->server_ip >> 8) & 0xFF, fn_ip->server_ip & 0xFF); } else if (ip_version =3D=3D 6) { char ip6_str[40]; - printf(" Requesting file \"%s\" via TFTP from ", fn_ip.filename); - ipv6_to_str(fn_ip.server_ip6.addr, ip6_str); + ipv6_to_str(fn_ip->server_ip6.addr, ip6_str); printf("%s\n", ip6_str); } =20 - /* Do the TFTP load and print error message if necessary */ - rc =3D tftp_load(&fn_ip, buffer, len, DEFAULT_TFTP_RETRIES, ip_version= ); - - if (ip_version =3D=3D 4) { - dhcp_send_release(fn_ip.fd); + if (strlen((char *)fn_ip->filename) > 0) { + printf(" Bootfile name: '%s'\n", fn_ip->filename); } =20 return rc; } =20 +static void net_release(filename_ip_t *fn_ip) +{ + if (ip_version =3D=3D 4) { + dhcp_send_release(fn_ip->fd); + } +} + void panic(const char *string) { sclp_print(string); @@ -344,6 +346,7 @@ static void virtio_setup(void) =20 void main(void) { + filename_ip_t fn_ip; int rc; =20 sclp_setup(); @@ -351,7 +354,15 @@ void main(void) =20 virtio_setup(); =20 - rc =3D net_load(NULL, (long)_start); + rc =3D net_init(&fn_ip); + if (rc) { + panic("Network initialization failed. Halting.\n"); + } + + rc =3D tftp_load(&fn_ip, NULL, (long)_start); + + net_release(&fn_ip); + if (rc > 0) { sclp_print("Network loading done, starting kernel...\n"); asm volatile (" lpsw 0(%0) " : : "r"(0) : "memory"); --=20 1.8.3.1