xref: /qemu/pc-bios/s390-ccw/netmain.c (revision 134f0b3d7ca5fbbd17f21fea87066967ce1d6de5)
13e4415a7SThomas Huth /*
23e4415a7SThomas Huth  * S390 virtio-ccw network boot loading program
33e4415a7SThomas Huth  *
43e4415a7SThomas Huth  * Copyright 2017 Thomas Huth, Red Hat Inc.
53e4415a7SThomas Huth  *
63e4415a7SThomas Huth  * Based on the S390 virtio-ccw loading program (main.c)
73e4415a7SThomas Huth  * Copyright (c) 2013 Alexander Graf <agraf@suse.de>
83e4415a7SThomas Huth  *
929d12216SThomas Huth  * And based on the network loading code from SLOF (netload.c)
1029d12216SThomas Huth  * Copyright (c) 2004, 2008 IBM Corporation
1129d12216SThomas Huth  *
123e4415a7SThomas Huth  * This code is free software; you can redistribute it and/or modify it
133e4415a7SThomas Huth  * under the terms of the GNU General Public License as published by the
143e4415a7SThomas Huth  * Free Software Foundation; either version 2 of the License, or (at your
153e4415a7SThomas Huth  * option) any later version.
163e4415a7SThomas Huth  */
173e4415a7SThomas Huth 
183e4415a7SThomas Huth #include <stdint.h>
193e4415a7SThomas Huth #include <stdbool.h>
203e4415a7SThomas Huth #include <stdio.h>
213e4415a7SThomas Huth #include <stdlib.h>
223e4415a7SThomas Huth #include <string.h>
233e4415a7SThomas Huth #include <unistd.h>
2429d12216SThomas Huth 
2529d12216SThomas Huth #include <tftp.h>
2629d12216SThomas Huth #include <ethernet.h>
2729d12216SThomas Huth #include <dhcp.h>
2829d12216SThomas Huth #include <dhcpv6.h>
2929d12216SThomas Huth #include <ipv4.h>
3029d12216SThomas Huth #include <ipv6.h>
3129d12216SThomas Huth #include <dns.h>
323e4415a7SThomas Huth #include <time.h>
333e4415a7SThomas Huth 
343e4415a7SThomas Huth #include "s390-ccw.h"
353e4415a7SThomas Huth #include "virtio.h"
363e4415a7SThomas Huth 
3729d12216SThomas Huth #define DEFAULT_BOOT_RETRIES 10
3829d12216SThomas Huth #define DEFAULT_TFTP_RETRIES 20
3929d12216SThomas Huth 
403e4415a7SThomas Huth extern char _start[];
413e4415a7SThomas Huth 
42c4942ee9SThomas Huth #define KERNEL_ADDR             ((void *)0L)
43c4942ee9SThomas Huth #define KERNEL_MAX_SIZE         ((long)_start)
44c4942ee9SThomas Huth 
453e4415a7SThomas Huth char stack[PAGE_SIZE * 8] __attribute__((aligned(PAGE_SIZE)));
463e4415a7SThomas Huth IplParameterBlock iplb __attribute__((aligned(PAGE_SIZE)));
47c4942ee9SThomas Huth static char cfgbuf[2048];
483e4415a7SThomas Huth 
493e4415a7SThomas Huth static SubChannelId net_schid = { .one = 1 };
503e4415a7SThomas Huth static uint64_t dest_timer;
513e4415a7SThomas Huth 
523e4415a7SThomas Huth static uint64_t get_timer_ms(void)
533e4415a7SThomas Huth {
543e4415a7SThomas Huth     uint64_t clk;
553e4415a7SThomas Huth 
563e4415a7SThomas Huth     asm volatile(" stck %0 " : : "Q"(clk) : "memory");
573e4415a7SThomas Huth 
583e4415a7SThomas Huth     /* Bit 51 is incremented each microsecond */
593e4415a7SThomas Huth     return (clk >> (63 - 51)) / 1000;
603e4415a7SThomas Huth }
613e4415a7SThomas Huth 
623e4415a7SThomas Huth void set_timer(int val)
633e4415a7SThomas Huth {
643e4415a7SThomas Huth     dest_timer = get_timer_ms() + val;
653e4415a7SThomas Huth }
663e4415a7SThomas Huth 
673e4415a7SThomas Huth int get_timer(void)
683e4415a7SThomas Huth {
693e4415a7SThomas Huth     return dest_timer - get_timer_ms();
703e4415a7SThomas Huth }
713e4415a7SThomas Huth 
723e4415a7SThomas Huth int get_sec_ticks(void)
733e4415a7SThomas Huth {
743e4415a7SThomas Huth     return 1000;    /* number of ticks in 1 second */
753e4415a7SThomas Huth }
763e4415a7SThomas Huth 
7729d12216SThomas Huth /**
7829d12216SThomas Huth  * Obtain IP and configuration info from DHCP server (either IPv4 or IPv6).
7929d12216SThomas Huth  * @param  fn_ip     contains the following configuration information:
8029d12216SThomas Huth  *                   client MAC, client IP, TFTP-server MAC, TFTP-server IP,
8129d12216SThomas Huth  *                   boot file name
8229d12216SThomas Huth  * @param  retries   Number of DHCP attempts
8329d12216SThomas Huth  * @return           0 : IP and configuration info obtained;
8429d12216SThomas Huth  *                   non-0 : error condition occurred.
8529d12216SThomas Huth  */
8629d12216SThomas Huth static int dhcp(struct filename_ip *fn_ip, int retries)
8729d12216SThomas Huth {
8829d12216SThomas Huth     int i = retries + 1;
8929d12216SThomas Huth     int rc = -1;
9029d12216SThomas Huth 
9129d12216SThomas Huth     printf("  Requesting information via DHCP:     ");
9229d12216SThomas Huth 
9329d12216SThomas Huth     dhcpv4_generate_transaction_id();
9429d12216SThomas Huth     dhcpv6_generate_transaction_id();
9529d12216SThomas Huth 
9629d12216SThomas Huth     do {
9729d12216SThomas Huth         printf("\b\b\b%03d", i - 1);
9829d12216SThomas Huth         if (!--i) {
9929d12216SThomas Huth             printf("\nGiving up after %d DHCP requests\n", retries);
10029d12216SThomas Huth             return -1;
10129d12216SThomas Huth         }
102*134f0b3dSThomas Huth         fn_ip->ip_version = 4;
10329d12216SThomas Huth         rc = dhcpv4(NULL, fn_ip);
10429d12216SThomas Huth         if (rc == -1) {
105*134f0b3dSThomas Huth             fn_ip->ip_version = 6;
10629d12216SThomas Huth             set_ipv6_address(fn_ip->fd, 0);
10729d12216SThomas Huth             rc = dhcpv6(NULL, fn_ip);
10829d12216SThomas Huth             if (rc == 0) {
10929d12216SThomas Huth                 memcpy(&fn_ip->own_ip6, get_ipv6_address(), 16);
11029d12216SThomas Huth                 break;
11129d12216SThomas Huth             }
11229d12216SThomas Huth         }
11329d12216SThomas Huth         if (rc != -1) {    /* either success or non-dhcp failure */
11429d12216SThomas Huth             break;
11529d12216SThomas Huth         }
11629d12216SThomas Huth     } while (1);
11729d12216SThomas Huth     printf("\b\b\b\bdone\n");
11829d12216SThomas Huth 
11929d12216SThomas Huth     return rc;
12029d12216SThomas Huth }
12129d12216SThomas Huth 
12229d12216SThomas Huth /**
12329d12216SThomas Huth  * Seed the random number generator with our mac and current timestamp
12429d12216SThomas Huth  */
12529d12216SThomas Huth static void seed_rng(uint8_t mac[])
12629d12216SThomas Huth {
12729d12216SThomas Huth     uint64_t seed;
12829d12216SThomas Huth 
12929d12216SThomas Huth     asm volatile(" stck %0 " : : "Q"(seed) : "memory");
13029d12216SThomas Huth     seed ^= (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5];
13129d12216SThomas Huth     srand(seed);
13229d12216SThomas Huth }
13329d12216SThomas Huth 
1340c188229SThomas Huth static int tftp_load(filename_ip_t *fnip, void *buffer, int len)
13529d12216SThomas Huth {
13629d12216SThomas Huth     tftp_err_t tftp_err;
13729d12216SThomas Huth     int rc;
13829d12216SThomas Huth 
139*134f0b3dSThomas Huth     rc = tftp(fnip, buffer, len, DEFAULT_TFTP_RETRIES, &tftp_err);
14029d12216SThomas Huth 
141c4942ee9SThomas Huth     if (rc < 0) {
142c4942ee9SThomas Huth         /* Make sure that error messages are put into a new line */
143c4942ee9SThomas Huth         printf("\n  ");
144c4942ee9SThomas Huth     }
145c4942ee9SThomas Huth 
146c4942ee9SThomas Huth     if (rc > 1024) {
147c4942ee9SThomas Huth         printf("  TFTP: Received %s (%d KBytes)\n", fnip->filename, rc / 1024);
148c4942ee9SThomas Huth     } else if (rc > 0) {
149c4942ee9SThomas Huth         printf("  TFTP: Received %s (%d Bytes)\n", fnip->filename, rc);
150*134f0b3dSThomas Huth     } else {
151*134f0b3dSThomas Huth         const char *errstr = NULL;
152*134f0b3dSThomas Huth         int ecode;
153*134f0b3dSThomas Huth         tftp_get_error_info(fnip, &tftp_err, rc, &errstr, &ecode);
154*134f0b3dSThomas Huth         printf("TFTP error: %s\n", errstr ? errstr : "unknown error");
15529d12216SThomas Huth     }
15629d12216SThomas Huth 
15729d12216SThomas Huth     return rc;
15829d12216SThomas Huth }
15929d12216SThomas Huth 
1600c188229SThomas Huth static int net_init(filename_ip_t *fn_ip)
16129d12216SThomas Huth {
16229d12216SThomas Huth     uint8_t mac[6];
16329d12216SThomas Huth     int rc;
16429d12216SThomas Huth 
1650c188229SThomas Huth     memset(fn_ip, 0, sizeof(filename_ip_t));
16629d12216SThomas Huth 
16729d12216SThomas Huth     rc = virtio_net_init(mac);
16829d12216SThomas Huth     if (rc < 0) {
16929d12216SThomas Huth         puts("Could not initialize network device");
17029d12216SThomas Huth         return -101;
17129d12216SThomas Huth     }
1720c188229SThomas Huth     fn_ip->fd = rc;
17329d12216SThomas Huth 
17429d12216SThomas Huth     printf("  Using MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n",
17529d12216SThomas Huth            mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
17629d12216SThomas Huth 
17729d12216SThomas Huth     set_mac_address(mac);    /* init ethernet layer */
17829d12216SThomas Huth     seed_rng(mac);
17929d12216SThomas Huth 
1800c188229SThomas Huth     rc = dhcp(fn_ip, DEFAULT_BOOT_RETRIES);
18129d12216SThomas Huth     if (rc >= 0) {
182*134f0b3dSThomas Huth         if (fn_ip->ip_version == 4) {
1830c188229SThomas Huth             set_ipv4_address(fn_ip->own_ip);
18429d12216SThomas Huth         }
18529d12216SThomas Huth     } else {
18629d12216SThomas Huth         puts("Could not get IP address");
18729d12216SThomas Huth         return -101;
18829d12216SThomas Huth     }
18929d12216SThomas Huth 
190*134f0b3dSThomas Huth     if (fn_ip->ip_version == 4) {
19129d12216SThomas Huth         printf("  Using IPv4 address: %d.%d.%d.%d\n",
1920c188229SThomas Huth               (fn_ip->own_ip >> 24) & 0xFF, (fn_ip->own_ip >> 16) & 0xFF,
1930c188229SThomas Huth               (fn_ip->own_ip >>  8) & 0xFF, fn_ip->own_ip & 0xFF);
194*134f0b3dSThomas Huth     } else if (fn_ip->ip_version == 6) {
19529d12216SThomas Huth         char ip6_str[40];
1960c188229SThomas Huth         ipv6_to_str(fn_ip->own_ip6.addr, ip6_str);
19729d12216SThomas Huth         printf("  Using IPv6 address: %s\n", ip6_str);
19829d12216SThomas Huth     }
19929d12216SThomas Huth 
20029d12216SThomas Huth     if (rc == -2) {
20129d12216SThomas Huth         printf("ARP request to TFTP server (%d.%d.%d.%d) failed\n",
2020c188229SThomas Huth                (fn_ip->server_ip >> 24) & 0xFF, (fn_ip->server_ip >> 16) & 0xFF,
2030c188229SThomas Huth                (fn_ip->server_ip >>  8) & 0xFF, fn_ip->server_ip & 0xFF);
20429d12216SThomas Huth         return -102;
20529d12216SThomas Huth     }
20629d12216SThomas Huth     if (rc == -4 || rc == -3) {
20729d12216SThomas Huth         puts("Can't obtain TFTP server IP address");
20829d12216SThomas Huth         return -107;
20929d12216SThomas Huth     }
21029d12216SThomas Huth 
2110c188229SThomas Huth     printf("  Using TFTP server: ");
212*134f0b3dSThomas Huth     if (fn_ip->ip_version == 4) {
2130c188229SThomas Huth         printf("%d.%d.%d.%d\n",
2140c188229SThomas Huth                (fn_ip->server_ip >> 24) & 0xFF, (fn_ip->server_ip >> 16) & 0xFF,
2150c188229SThomas Huth                (fn_ip->server_ip >>  8) & 0xFF, fn_ip->server_ip & 0xFF);
216*134f0b3dSThomas Huth     } else if (fn_ip->ip_version == 6) {
21729d12216SThomas Huth         char ip6_str[40];
2180c188229SThomas Huth         ipv6_to_str(fn_ip->server_ip6.addr, ip6_str);
21929d12216SThomas Huth         printf("%s\n", ip6_str);
22029d12216SThomas Huth     }
22129d12216SThomas Huth 
222*134f0b3dSThomas Huth     if (strlen(fn_ip->filename) > 0) {
2230c188229SThomas Huth         printf("  Bootfile name: '%s'\n", fn_ip->filename);
22429d12216SThomas Huth     }
22529d12216SThomas Huth 
22629d12216SThomas Huth     return rc;
22729d12216SThomas Huth }
22829d12216SThomas Huth 
2290c188229SThomas Huth static void net_release(filename_ip_t *fn_ip)
2300c188229SThomas Huth {
231*134f0b3dSThomas Huth     if (fn_ip->ip_version == 4) {
2320c188229SThomas Huth         dhcp_send_release(fn_ip->fd);
2330c188229SThomas Huth     }
2340c188229SThomas Huth }
2350c188229SThomas Huth 
236c4942ee9SThomas Huth /**
237c4942ee9SThomas Huth  * Load via information from a .INS file (which can be found on CD-ROMs
238c4942ee9SThomas Huth  * for example)
239c4942ee9SThomas Huth  */
240c4942ee9SThomas Huth static int handle_ins_cfg(filename_ip_t *fn_ip, char *cfg, int cfgsize)
241c4942ee9SThomas Huth {
242c4942ee9SThomas Huth     char *ptr;
243c4942ee9SThomas Huth     int rc = -1, llen;
244c4942ee9SThomas Huth     void *destaddr;
245c4942ee9SThomas Huth     char *insbuf = cfg;
246c4942ee9SThomas Huth 
247c4942ee9SThomas Huth     ptr = strchr(insbuf, '\n');
248c4942ee9SThomas Huth     if (!ptr) {
249c4942ee9SThomas Huth         puts("Does not seem to be a valid .INS file");
250c4942ee9SThomas Huth         return -1;
251c4942ee9SThomas Huth     }
252c4942ee9SThomas Huth 
253c4942ee9SThomas Huth     *ptr = 0;
254c4942ee9SThomas Huth     printf("\nParsing .INS file:\n %s\n", &insbuf[2]);
255c4942ee9SThomas Huth 
256c4942ee9SThomas Huth     insbuf = ptr + 1;
257c4942ee9SThomas Huth     while (*insbuf && insbuf < cfg + cfgsize) {
258c4942ee9SThomas Huth         ptr = strchr(insbuf, '\n');
259c4942ee9SThomas Huth         if (ptr) {
260c4942ee9SThomas Huth             *ptr = 0;
261c4942ee9SThomas Huth         }
262c4942ee9SThomas Huth         llen = strlen(insbuf);
263c4942ee9SThomas Huth         if (!llen) {
264c4942ee9SThomas Huth             insbuf = ptr + 1;
265c4942ee9SThomas Huth             continue;
266c4942ee9SThomas Huth         }
267c4942ee9SThomas Huth         ptr = strchr(insbuf, ' ');
268c4942ee9SThomas Huth         if (!ptr) {
269c4942ee9SThomas Huth             puts("Missing space separator in .INS file");
270c4942ee9SThomas Huth             return -1;
271c4942ee9SThomas Huth         }
272c4942ee9SThomas Huth         *ptr = 0;
273*134f0b3dSThomas Huth         strncpy(fn_ip->filename, insbuf, sizeof(fn_ip->filename));
274c4942ee9SThomas Huth         destaddr = (char *)atol(ptr + 1);
275c4942ee9SThomas Huth         rc = tftp_load(fn_ip, destaddr, (long)_start - (long)destaddr);
276c4942ee9SThomas Huth         if (rc <= 0) {
277c4942ee9SThomas Huth             break;
278c4942ee9SThomas Huth         }
279c4942ee9SThomas Huth         insbuf += llen + 1;
280c4942ee9SThomas Huth     }
281c4942ee9SThomas Huth 
282c4942ee9SThomas Huth     return rc;
283c4942ee9SThomas Huth }
284c4942ee9SThomas Huth 
285c4942ee9SThomas Huth static int net_try_direct_tftp_load(filename_ip_t *fn_ip)
286c4942ee9SThomas Huth {
287c4942ee9SThomas Huth     int rc;
288c4942ee9SThomas Huth     void *loadaddr = (void *)0x2000;  /* Load right after the low-core */
289c4942ee9SThomas Huth 
290c4942ee9SThomas Huth     rc = tftp_load(fn_ip, loadaddr, KERNEL_MAX_SIZE - (long)loadaddr);
291c4942ee9SThomas Huth     if (rc < 0) {
292c4942ee9SThomas Huth         return rc;
293c4942ee9SThomas Huth     } else if (rc < 8) {
294c4942ee9SThomas Huth         printf("'%s' is too small (%i bytes only).\n", fn_ip->filename, rc);
295c4942ee9SThomas Huth         return -1;
296c4942ee9SThomas Huth     }
297c4942ee9SThomas Huth 
298c4942ee9SThomas Huth     /* Check whether it is a configuration file instead of a kernel */
299c4942ee9SThomas Huth     if (rc < sizeof(cfgbuf) - 1) {
300c4942ee9SThomas Huth         memcpy(cfgbuf, loadaddr, rc);
301c4942ee9SThomas Huth         cfgbuf[rc] = 0;    /* Make sure that it is NUL-terminated */
302c4942ee9SThomas Huth         if (!strncmp("* ", cfgbuf, 2)) {
303c4942ee9SThomas Huth             return handle_ins_cfg(fn_ip, cfgbuf, rc);
304c4942ee9SThomas Huth         }
305c4942ee9SThomas Huth     }
306c4942ee9SThomas Huth 
307c4942ee9SThomas Huth     /* Move kernel to right location */
308c4942ee9SThomas Huth     memmove(KERNEL_ADDR, loadaddr, rc);
309c4942ee9SThomas Huth 
310c4942ee9SThomas Huth     return rc;
311c4942ee9SThomas Huth }
312c4942ee9SThomas Huth 
3133e4415a7SThomas Huth void panic(const char *string)
3143e4415a7SThomas Huth {
3153e4415a7SThomas Huth     sclp_print(string);
3163e4415a7SThomas Huth     for (;;) {
3173e4415a7SThomas Huth         disabled_wait();
3183e4415a7SThomas Huth     }
3193e4415a7SThomas Huth }
3203e4415a7SThomas Huth 
3219a848adfSThomas Huth void write_subsystem_identification(void)
3229a848adfSThomas Huth {
3239a848adfSThomas Huth     SubChannelId *schid = (SubChannelId *) 184;
3249a848adfSThomas Huth     uint32_t *zeroes = (uint32_t *) 188;
3259a848adfSThomas Huth 
3269a848adfSThomas Huth     *schid = net_schid;
3279a848adfSThomas Huth     *zeroes = 0;
3289a848adfSThomas Huth }
3299a848adfSThomas Huth 
3303e4415a7SThomas Huth static bool find_net_dev(Schib *schib, int dev_no)
3313e4415a7SThomas Huth {
3323e4415a7SThomas Huth     int i, r;
3333e4415a7SThomas Huth 
3343e4415a7SThomas Huth     for (i = 0; i < 0x10000; i++) {
3353e4415a7SThomas Huth         net_schid.sch_no = i;
3363e4415a7SThomas Huth         r = stsch_err(net_schid, schib);
3373e4415a7SThomas Huth         if (r == 3 || r == -EIO) {
3383e4415a7SThomas Huth             break;
3393e4415a7SThomas Huth         }
3403e4415a7SThomas Huth         if (!schib->pmcw.dnv) {
3413e4415a7SThomas Huth             continue;
3423e4415a7SThomas Huth         }
3433e4415a7SThomas Huth         if (!virtio_is_supported(net_schid)) {
3443e4415a7SThomas Huth             continue;
3453e4415a7SThomas Huth         }
3463e4415a7SThomas Huth         if (virtio_get_device_type() != VIRTIO_ID_NET) {
3473e4415a7SThomas Huth             continue;
3483e4415a7SThomas Huth         }
3493e4415a7SThomas Huth         if (dev_no < 0 || schib->pmcw.dev == dev_no) {
3503e4415a7SThomas Huth             return true;
3513e4415a7SThomas Huth         }
3523e4415a7SThomas Huth     }
3533e4415a7SThomas Huth 
3543e4415a7SThomas Huth     return false;
3553e4415a7SThomas Huth }
3563e4415a7SThomas Huth 
3573e4415a7SThomas Huth static void virtio_setup(void)
3583e4415a7SThomas Huth {
3593e4415a7SThomas Huth     Schib schib;
3603e4415a7SThomas Huth     int ssid;
3613e4415a7SThomas Huth     bool found = false;
3623e4415a7SThomas Huth     uint16_t dev_no;
3633e4415a7SThomas Huth 
3643e4415a7SThomas Huth     /*
3653e4415a7SThomas Huth      * We unconditionally enable mss support. In every sane configuration,
3663e4415a7SThomas Huth      * this will succeed; and even if it doesn't, stsch_err() can deal
3673e4415a7SThomas Huth      * with the consequences.
3683e4415a7SThomas Huth      */
3693e4415a7SThomas Huth     enable_mss_facility();
3703e4415a7SThomas Huth 
3713e4415a7SThomas Huth     if (store_iplb(&iplb)) {
3723e4415a7SThomas Huth         IPL_assert(iplb.pbt == S390_IPL_TYPE_CCW, "IPL_TYPE_CCW expected");
3733e4415a7SThomas Huth         dev_no = iplb.ccw.devno;
3743e4415a7SThomas Huth         debug_print_int("device no. ", dev_no);
3753e4415a7SThomas Huth         net_schid.ssid = iplb.ccw.ssid & 0x3;
3763e4415a7SThomas Huth         debug_print_int("ssid ", net_schid.ssid);
3773e4415a7SThomas Huth         found = find_net_dev(&schib, dev_no);
3783e4415a7SThomas Huth     } else {
3793e4415a7SThomas Huth         for (ssid = 0; ssid < 0x3; ssid++) {
3803e4415a7SThomas Huth             net_schid.ssid = ssid;
3813e4415a7SThomas Huth             found = find_net_dev(&schib, -1);
3823e4415a7SThomas Huth             if (found) {
3833e4415a7SThomas Huth                 break;
3843e4415a7SThomas Huth             }
3853e4415a7SThomas Huth         }
3863e4415a7SThomas Huth     }
3873e4415a7SThomas Huth 
3883e4415a7SThomas Huth     IPL_assert(found, "No virtio net device found");
3893e4415a7SThomas Huth }
3903e4415a7SThomas Huth 
3913e4415a7SThomas Huth void main(void)
3923e4415a7SThomas Huth {
3930c188229SThomas Huth     filename_ip_t fn_ip;
394c4942ee9SThomas Huth     int rc, fnlen;
39529d12216SThomas Huth 
3963e4415a7SThomas Huth     sclp_setup();
3973e4415a7SThomas Huth     sclp_print("Network boot starting...\n");
3983e4415a7SThomas Huth 
3993e4415a7SThomas Huth     virtio_setup();
4003e4415a7SThomas Huth 
4010c188229SThomas Huth     rc = net_init(&fn_ip);
4020c188229SThomas Huth     if (rc) {
4030c188229SThomas Huth         panic("Network initialization failed. Halting.\n");
4040c188229SThomas Huth     }
4050c188229SThomas Huth 
406*134f0b3dSThomas Huth     fnlen = strlen(fn_ip.filename);
407c4942ee9SThomas Huth     if (fnlen > 0 && fn_ip.filename[fnlen - 1] != '/') {
408c4942ee9SThomas Huth         rc = net_try_direct_tftp_load(&fn_ip);
409c4942ee9SThomas Huth     }
4100c188229SThomas Huth 
4110c188229SThomas Huth     net_release(&fn_ip);
4120c188229SThomas Huth 
41329d12216SThomas Huth     if (rc > 0) {
41429d12216SThomas Huth         sclp_print("Network loading done, starting kernel...\n");
4159a848adfSThomas Huth         jump_to_low_kernel();
41629d12216SThomas Huth     }
41729d12216SThomas Huth 
4183e4415a7SThomas Huth     panic("Failed to load OS from network\n");
4193e4415a7SThomas Huth }
420