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 42*c4942ee9SThomas Huth #define KERNEL_ADDR ((void *)0L) 43*c4942ee9SThomas Huth #define KERNEL_MAX_SIZE ((long)_start) 44*c4942ee9SThomas Huth 453e4415a7SThomas Huth char stack[PAGE_SIZE * 8] __attribute__((aligned(PAGE_SIZE))); 463e4415a7SThomas Huth IplParameterBlock iplb __attribute__((aligned(PAGE_SIZE))); 47*c4942ee9SThomas Huth static char cfgbuf[2048]; 483e4415a7SThomas Huth 493e4415a7SThomas Huth static SubChannelId net_schid = { .one = 1 }; 5029d12216SThomas Huth static int ip_version = 4; 513e4415a7SThomas Huth static uint64_t dest_timer; 523e4415a7SThomas Huth 533e4415a7SThomas Huth static uint64_t get_timer_ms(void) 543e4415a7SThomas Huth { 553e4415a7SThomas Huth uint64_t clk; 563e4415a7SThomas Huth 573e4415a7SThomas Huth asm volatile(" stck %0 " : : "Q"(clk) : "memory"); 583e4415a7SThomas Huth 593e4415a7SThomas Huth /* Bit 51 is incremented each microsecond */ 603e4415a7SThomas Huth return (clk >> (63 - 51)) / 1000; 613e4415a7SThomas Huth } 623e4415a7SThomas Huth 633e4415a7SThomas Huth void set_timer(int val) 643e4415a7SThomas Huth { 653e4415a7SThomas Huth dest_timer = get_timer_ms() + val; 663e4415a7SThomas Huth } 673e4415a7SThomas Huth 683e4415a7SThomas Huth int get_timer(void) 693e4415a7SThomas Huth { 703e4415a7SThomas Huth return dest_timer - get_timer_ms(); 713e4415a7SThomas Huth } 723e4415a7SThomas Huth 733e4415a7SThomas Huth int get_sec_ticks(void) 743e4415a7SThomas Huth { 753e4415a7SThomas Huth return 1000; /* number of ticks in 1 second */ 763e4415a7SThomas Huth } 773e4415a7SThomas Huth 7829d12216SThomas Huth /** 7929d12216SThomas Huth * Obtain IP and configuration info from DHCP server (either IPv4 or IPv6). 8029d12216SThomas Huth * @param fn_ip contains the following configuration information: 8129d12216SThomas Huth * client MAC, client IP, TFTP-server MAC, TFTP-server IP, 8229d12216SThomas Huth * boot file name 8329d12216SThomas Huth * @param retries Number of DHCP attempts 8429d12216SThomas Huth * @return 0 : IP and configuration info obtained; 8529d12216SThomas Huth * non-0 : error condition occurred. 8629d12216SThomas Huth */ 8729d12216SThomas Huth static int dhcp(struct filename_ip *fn_ip, int retries) 8829d12216SThomas Huth { 8929d12216SThomas Huth int i = retries + 1; 9029d12216SThomas Huth int rc = -1; 9129d12216SThomas Huth 9229d12216SThomas Huth printf(" Requesting information via DHCP: "); 9329d12216SThomas Huth 9429d12216SThomas Huth dhcpv4_generate_transaction_id(); 9529d12216SThomas Huth dhcpv6_generate_transaction_id(); 9629d12216SThomas Huth 9729d12216SThomas Huth do { 9829d12216SThomas Huth printf("\b\b\b%03d", i - 1); 9929d12216SThomas Huth if (!--i) { 10029d12216SThomas Huth printf("\nGiving up after %d DHCP requests\n", retries); 10129d12216SThomas Huth return -1; 10229d12216SThomas Huth } 10329d12216SThomas Huth ip_version = 4; 10429d12216SThomas Huth rc = dhcpv4(NULL, fn_ip); 10529d12216SThomas Huth if (rc == -1) { 10629d12216SThomas Huth ip_version = 6; 10729d12216SThomas Huth set_ipv6_address(fn_ip->fd, 0); 10829d12216SThomas Huth rc = dhcpv6(NULL, fn_ip); 10929d12216SThomas Huth if (rc == 0) { 11029d12216SThomas Huth memcpy(&fn_ip->own_ip6, get_ipv6_address(), 16); 11129d12216SThomas Huth break; 11229d12216SThomas Huth } 11329d12216SThomas Huth } 11429d12216SThomas Huth if (rc != -1) { /* either success or non-dhcp failure */ 11529d12216SThomas Huth break; 11629d12216SThomas Huth } 11729d12216SThomas Huth } while (1); 11829d12216SThomas Huth printf("\b\b\b\bdone\n"); 11929d12216SThomas Huth 12029d12216SThomas Huth return rc; 12129d12216SThomas Huth } 12229d12216SThomas Huth 12329d12216SThomas Huth /** 12429d12216SThomas Huth * Seed the random number generator with our mac and current timestamp 12529d12216SThomas Huth */ 12629d12216SThomas Huth static void seed_rng(uint8_t mac[]) 12729d12216SThomas Huth { 12829d12216SThomas Huth uint64_t seed; 12929d12216SThomas Huth 13029d12216SThomas Huth asm volatile(" stck %0 " : : "Q"(seed) : "memory"); 13129d12216SThomas Huth seed ^= (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5]; 13229d12216SThomas Huth srand(seed); 13329d12216SThomas Huth } 13429d12216SThomas Huth 1350c188229SThomas Huth static int tftp_load(filename_ip_t *fnip, void *buffer, int len) 13629d12216SThomas Huth { 13729d12216SThomas Huth tftp_err_t tftp_err; 13829d12216SThomas Huth int rc; 13929d12216SThomas Huth 1400c188229SThomas Huth rc = tftp(fnip, buffer, len, DEFAULT_TFTP_RETRIES, &tftp_err, 1, 1428, 1410c188229SThomas Huth ip_version); 14229d12216SThomas Huth 143*c4942ee9SThomas Huth if (rc < 0) { 144*c4942ee9SThomas Huth /* Make sure that error messages are put into a new line */ 145*c4942ee9SThomas Huth printf("\n "); 146*c4942ee9SThomas Huth } 147*c4942ee9SThomas Huth 148*c4942ee9SThomas Huth if (rc > 1024) { 149*c4942ee9SThomas Huth printf(" TFTP: Received %s (%d KBytes)\n", fnip->filename, rc / 1024); 150*c4942ee9SThomas Huth } else if (rc > 0) { 151*c4942ee9SThomas Huth printf(" TFTP: Received %s (%d Bytes)\n", fnip->filename, rc); 15229d12216SThomas Huth } else if (rc == -1) { 15329d12216SThomas Huth puts("unknown TFTP error"); 15429d12216SThomas Huth } else if (rc == -2) { 15529d12216SThomas Huth printf("TFTP buffer of %d bytes is too small for %s\n", 15629d12216SThomas Huth len, fnip->filename); 15729d12216SThomas Huth } else if (rc == -3) { 15829d12216SThomas Huth printf("file not found: %s\n", fnip->filename); 15929d12216SThomas Huth } else if (rc == -4) { 16029d12216SThomas Huth puts("TFTP access violation"); 16129d12216SThomas Huth } else if (rc == -5) { 16229d12216SThomas Huth puts("illegal TFTP operation"); 16329d12216SThomas Huth } else if (rc == -6) { 16429d12216SThomas Huth puts("unknown TFTP transfer ID"); 16529d12216SThomas Huth } else if (rc == -7) { 16629d12216SThomas Huth puts("no such TFTP user"); 16729d12216SThomas Huth } else if (rc == -8) { 16829d12216SThomas Huth puts("TFTP blocksize negotiation failed"); 16929d12216SThomas Huth } else if (rc == -9) { 17029d12216SThomas Huth puts("file exceeds maximum TFTP transfer size"); 17129d12216SThomas Huth } else if (rc <= -10 && rc >= -15) { 17229d12216SThomas Huth const char *icmp_err_str; 17329d12216SThomas Huth switch (rc) { 17429d12216SThomas Huth case -ICMP_NET_UNREACHABLE - 10: 17529d12216SThomas Huth icmp_err_str = "net unreachable"; 17629d12216SThomas Huth break; 17729d12216SThomas Huth case -ICMP_HOST_UNREACHABLE - 10: 17829d12216SThomas Huth icmp_err_str = "host unreachable"; 17929d12216SThomas Huth break; 18029d12216SThomas Huth case -ICMP_PROTOCOL_UNREACHABLE - 10: 18129d12216SThomas Huth icmp_err_str = "protocol unreachable"; 18229d12216SThomas Huth break; 18329d12216SThomas Huth case -ICMP_PORT_UNREACHABLE - 10: 18429d12216SThomas Huth icmp_err_str = "port unreachable"; 18529d12216SThomas Huth break; 18629d12216SThomas Huth case -ICMP_FRAGMENTATION_NEEDED - 10: 18729d12216SThomas Huth icmp_err_str = "fragmentation needed and DF set"; 18829d12216SThomas Huth break; 18929d12216SThomas Huth case -ICMP_SOURCE_ROUTE_FAILED - 10: 19029d12216SThomas Huth icmp_err_str = "source route failed"; 19129d12216SThomas Huth break; 19229d12216SThomas Huth default: 19329d12216SThomas Huth icmp_err_str = " UNKNOWN"; 19429d12216SThomas Huth break; 19529d12216SThomas Huth } 19629d12216SThomas Huth printf("ICMP ERROR \"%s\"\n", icmp_err_str); 19729d12216SThomas Huth } else if (rc == -40) { 19829d12216SThomas Huth printf("TFTP error occurred after %d bad packets received", 19929d12216SThomas Huth tftp_err.bad_tftp_packets); 20029d12216SThomas Huth } else if (rc == -41) { 20129d12216SThomas Huth printf("TFTP error occurred after missing %d responses", 20229d12216SThomas Huth tftp_err.no_packets); 20329d12216SThomas Huth } else if (rc == -42) { 20429d12216SThomas Huth printf("TFTP error missing block %d, expected block was %d", 20529d12216SThomas Huth tftp_err.blocks_missed, 20629d12216SThomas Huth tftp_err.blocks_received); 20729d12216SThomas Huth } 20829d12216SThomas Huth 20929d12216SThomas Huth return rc; 21029d12216SThomas Huth } 21129d12216SThomas Huth 2120c188229SThomas Huth static int net_init(filename_ip_t *fn_ip) 21329d12216SThomas Huth { 21429d12216SThomas Huth uint8_t mac[6]; 21529d12216SThomas Huth int rc; 21629d12216SThomas Huth 2170c188229SThomas Huth memset(fn_ip, 0, sizeof(filename_ip_t)); 21829d12216SThomas Huth 21929d12216SThomas Huth rc = virtio_net_init(mac); 22029d12216SThomas Huth if (rc < 0) { 22129d12216SThomas Huth puts("Could not initialize network device"); 22229d12216SThomas Huth return -101; 22329d12216SThomas Huth } 2240c188229SThomas Huth fn_ip->fd = rc; 22529d12216SThomas Huth 22629d12216SThomas Huth printf(" Using MAC address: %02x:%02x:%02x:%02x:%02x:%02x\n", 22729d12216SThomas Huth mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); 22829d12216SThomas Huth 22929d12216SThomas Huth set_mac_address(mac); /* init ethernet layer */ 23029d12216SThomas Huth seed_rng(mac); 23129d12216SThomas Huth 2320c188229SThomas Huth rc = dhcp(fn_ip, DEFAULT_BOOT_RETRIES); 23329d12216SThomas Huth if (rc >= 0) { 23429d12216SThomas Huth if (ip_version == 4) { 2350c188229SThomas Huth set_ipv4_address(fn_ip->own_ip); 23629d12216SThomas Huth } 23729d12216SThomas Huth } else { 23829d12216SThomas Huth puts("Could not get IP address"); 23929d12216SThomas Huth return -101; 24029d12216SThomas Huth } 24129d12216SThomas Huth 24229d12216SThomas Huth if (ip_version == 4) { 24329d12216SThomas Huth printf(" Using IPv4 address: %d.%d.%d.%d\n", 2440c188229SThomas Huth (fn_ip->own_ip >> 24) & 0xFF, (fn_ip->own_ip >> 16) & 0xFF, 2450c188229SThomas Huth (fn_ip->own_ip >> 8) & 0xFF, fn_ip->own_ip & 0xFF); 24629d12216SThomas Huth } else if (ip_version == 6) { 24729d12216SThomas Huth char ip6_str[40]; 2480c188229SThomas Huth ipv6_to_str(fn_ip->own_ip6.addr, ip6_str); 24929d12216SThomas Huth printf(" Using IPv6 address: %s\n", ip6_str); 25029d12216SThomas Huth } 25129d12216SThomas Huth 25229d12216SThomas Huth if (rc == -2) { 25329d12216SThomas Huth printf("ARP request to TFTP server (%d.%d.%d.%d) failed\n", 2540c188229SThomas Huth (fn_ip->server_ip >> 24) & 0xFF, (fn_ip->server_ip >> 16) & 0xFF, 2550c188229SThomas Huth (fn_ip->server_ip >> 8) & 0xFF, fn_ip->server_ip & 0xFF); 25629d12216SThomas Huth return -102; 25729d12216SThomas Huth } 25829d12216SThomas Huth if (rc == -4 || rc == -3) { 25929d12216SThomas Huth puts("Can't obtain TFTP server IP address"); 26029d12216SThomas Huth return -107; 26129d12216SThomas Huth } 26229d12216SThomas Huth 2630c188229SThomas Huth printf(" Using TFTP server: "); 26429d12216SThomas Huth if (ip_version == 4) { 2650c188229SThomas Huth printf("%d.%d.%d.%d\n", 2660c188229SThomas Huth (fn_ip->server_ip >> 24) & 0xFF, (fn_ip->server_ip >> 16) & 0xFF, 2670c188229SThomas Huth (fn_ip->server_ip >> 8) & 0xFF, fn_ip->server_ip & 0xFF); 26829d12216SThomas Huth } else if (ip_version == 6) { 26929d12216SThomas Huth char ip6_str[40]; 2700c188229SThomas Huth ipv6_to_str(fn_ip->server_ip6.addr, ip6_str); 27129d12216SThomas Huth printf("%s\n", ip6_str); 27229d12216SThomas Huth } 27329d12216SThomas Huth 2740c188229SThomas Huth if (strlen((char *)fn_ip->filename) > 0) { 2750c188229SThomas Huth printf(" Bootfile name: '%s'\n", fn_ip->filename); 27629d12216SThomas Huth } 27729d12216SThomas Huth 27829d12216SThomas Huth return rc; 27929d12216SThomas Huth } 28029d12216SThomas Huth 2810c188229SThomas Huth static void net_release(filename_ip_t *fn_ip) 2820c188229SThomas Huth { 2830c188229SThomas Huth if (ip_version == 4) { 2840c188229SThomas Huth dhcp_send_release(fn_ip->fd); 2850c188229SThomas Huth } 2860c188229SThomas Huth } 2870c188229SThomas Huth 288*c4942ee9SThomas Huth /** 289*c4942ee9SThomas Huth * Load via information from a .INS file (which can be found on CD-ROMs 290*c4942ee9SThomas Huth * for example) 291*c4942ee9SThomas Huth */ 292*c4942ee9SThomas Huth static int handle_ins_cfg(filename_ip_t *fn_ip, char *cfg, int cfgsize) 293*c4942ee9SThomas Huth { 294*c4942ee9SThomas Huth char *ptr; 295*c4942ee9SThomas Huth int rc = -1, llen; 296*c4942ee9SThomas Huth void *destaddr; 297*c4942ee9SThomas Huth char *insbuf = cfg; 298*c4942ee9SThomas Huth 299*c4942ee9SThomas Huth ptr = strchr(insbuf, '\n'); 300*c4942ee9SThomas Huth if (!ptr) { 301*c4942ee9SThomas Huth puts("Does not seem to be a valid .INS file"); 302*c4942ee9SThomas Huth return -1; 303*c4942ee9SThomas Huth } 304*c4942ee9SThomas Huth 305*c4942ee9SThomas Huth *ptr = 0; 306*c4942ee9SThomas Huth printf("\nParsing .INS file:\n %s\n", &insbuf[2]); 307*c4942ee9SThomas Huth 308*c4942ee9SThomas Huth insbuf = ptr + 1; 309*c4942ee9SThomas Huth while (*insbuf && insbuf < cfg + cfgsize) { 310*c4942ee9SThomas Huth ptr = strchr(insbuf, '\n'); 311*c4942ee9SThomas Huth if (ptr) { 312*c4942ee9SThomas Huth *ptr = 0; 313*c4942ee9SThomas Huth } 314*c4942ee9SThomas Huth llen = strlen(insbuf); 315*c4942ee9SThomas Huth if (!llen) { 316*c4942ee9SThomas Huth insbuf = ptr + 1; 317*c4942ee9SThomas Huth continue; 318*c4942ee9SThomas Huth } 319*c4942ee9SThomas Huth ptr = strchr(insbuf, ' '); 320*c4942ee9SThomas Huth if (!ptr) { 321*c4942ee9SThomas Huth puts("Missing space separator in .INS file"); 322*c4942ee9SThomas Huth return -1; 323*c4942ee9SThomas Huth } 324*c4942ee9SThomas Huth *ptr = 0; 325*c4942ee9SThomas Huth strncpy((char *)fn_ip->filename, insbuf, sizeof(fn_ip->filename)); 326*c4942ee9SThomas Huth destaddr = (char *)atol(ptr + 1); 327*c4942ee9SThomas Huth rc = tftp_load(fn_ip, destaddr, (long)_start - (long)destaddr); 328*c4942ee9SThomas Huth if (rc <= 0) { 329*c4942ee9SThomas Huth break; 330*c4942ee9SThomas Huth } 331*c4942ee9SThomas Huth insbuf += llen + 1; 332*c4942ee9SThomas Huth } 333*c4942ee9SThomas Huth 334*c4942ee9SThomas Huth return rc; 335*c4942ee9SThomas Huth } 336*c4942ee9SThomas Huth 337*c4942ee9SThomas Huth static int net_try_direct_tftp_load(filename_ip_t *fn_ip) 338*c4942ee9SThomas Huth { 339*c4942ee9SThomas Huth int rc; 340*c4942ee9SThomas Huth void *loadaddr = (void *)0x2000; /* Load right after the low-core */ 341*c4942ee9SThomas Huth 342*c4942ee9SThomas Huth rc = tftp_load(fn_ip, loadaddr, KERNEL_MAX_SIZE - (long)loadaddr); 343*c4942ee9SThomas Huth if (rc < 0) { 344*c4942ee9SThomas Huth return rc; 345*c4942ee9SThomas Huth } else if (rc < 8) { 346*c4942ee9SThomas Huth printf("'%s' is too small (%i bytes only).\n", fn_ip->filename, rc); 347*c4942ee9SThomas Huth return -1; 348*c4942ee9SThomas Huth } 349*c4942ee9SThomas Huth 350*c4942ee9SThomas Huth /* Check whether it is a configuration file instead of a kernel */ 351*c4942ee9SThomas Huth if (rc < sizeof(cfgbuf) - 1) { 352*c4942ee9SThomas Huth memcpy(cfgbuf, loadaddr, rc); 353*c4942ee9SThomas Huth cfgbuf[rc] = 0; /* Make sure that it is NUL-terminated */ 354*c4942ee9SThomas Huth if (!strncmp("* ", cfgbuf, 2)) { 355*c4942ee9SThomas Huth return handle_ins_cfg(fn_ip, cfgbuf, rc); 356*c4942ee9SThomas Huth } 357*c4942ee9SThomas Huth } 358*c4942ee9SThomas Huth 359*c4942ee9SThomas Huth /* Move kernel to right location */ 360*c4942ee9SThomas Huth memmove(KERNEL_ADDR, loadaddr, rc); 361*c4942ee9SThomas Huth 362*c4942ee9SThomas Huth return rc; 363*c4942ee9SThomas Huth } 364*c4942ee9SThomas Huth 3653e4415a7SThomas Huth void panic(const char *string) 3663e4415a7SThomas Huth { 3673e4415a7SThomas Huth sclp_print(string); 3683e4415a7SThomas Huth for (;;) { 3693e4415a7SThomas Huth disabled_wait(); 3703e4415a7SThomas Huth } 3713e4415a7SThomas Huth } 3723e4415a7SThomas Huth 3739a848adfSThomas Huth void write_subsystem_identification(void) 3749a848adfSThomas Huth { 3759a848adfSThomas Huth SubChannelId *schid = (SubChannelId *) 184; 3769a848adfSThomas Huth uint32_t *zeroes = (uint32_t *) 188; 3779a848adfSThomas Huth 3789a848adfSThomas Huth *schid = net_schid; 3799a848adfSThomas Huth *zeroes = 0; 3809a848adfSThomas Huth } 3819a848adfSThomas Huth 3823e4415a7SThomas Huth static bool find_net_dev(Schib *schib, int dev_no) 3833e4415a7SThomas Huth { 3843e4415a7SThomas Huth int i, r; 3853e4415a7SThomas Huth 3863e4415a7SThomas Huth for (i = 0; i < 0x10000; i++) { 3873e4415a7SThomas Huth net_schid.sch_no = i; 3883e4415a7SThomas Huth r = stsch_err(net_schid, schib); 3893e4415a7SThomas Huth if (r == 3 || r == -EIO) { 3903e4415a7SThomas Huth break; 3913e4415a7SThomas Huth } 3923e4415a7SThomas Huth if (!schib->pmcw.dnv) { 3933e4415a7SThomas Huth continue; 3943e4415a7SThomas Huth } 3953e4415a7SThomas Huth if (!virtio_is_supported(net_schid)) { 3963e4415a7SThomas Huth continue; 3973e4415a7SThomas Huth } 3983e4415a7SThomas Huth if (virtio_get_device_type() != VIRTIO_ID_NET) { 3993e4415a7SThomas Huth continue; 4003e4415a7SThomas Huth } 4013e4415a7SThomas Huth if (dev_no < 0 || schib->pmcw.dev == dev_no) { 4023e4415a7SThomas Huth return true; 4033e4415a7SThomas Huth } 4043e4415a7SThomas Huth } 4053e4415a7SThomas Huth 4063e4415a7SThomas Huth return false; 4073e4415a7SThomas Huth } 4083e4415a7SThomas Huth 4093e4415a7SThomas Huth static void virtio_setup(void) 4103e4415a7SThomas Huth { 4113e4415a7SThomas Huth Schib schib; 4123e4415a7SThomas Huth int ssid; 4133e4415a7SThomas Huth bool found = false; 4143e4415a7SThomas Huth uint16_t dev_no; 4153e4415a7SThomas Huth 4163e4415a7SThomas Huth /* 4173e4415a7SThomas Huth * We unconditionally enable mss support. In every sane configuration, 4183e4415a7SThomas Huth * this will succeed; and even if it doesn't, stsch_err() can deal 4193e4415a7SThomas Huth * with the consequences. 4203e4415a7SThomas Huth */ 4213e4415a7SThomas Huth enable_mss_facility(); 4223e4415a7SThomas Huth 4233e4415a7SThomas Huth if (store_iplb(&iplb)) { 4243e4415a7SThomas Huth IPL_assert(iplb.pbt == S390_IPL_TYPE_CCW, "IPL_TYPE_CCW expected"); 4253e4415a7SThomas Huth dev_no = iplb.ccw.devno; 4263e4415a7SThomas Huth debug_print_int("device no. ", dev_no); 4273e4415a7SThomas Huth net_schid.ssid = iplb.ccw.ssid & 0x3; 4283e4415a7SThomas Huth debug_print_int("ssid ", net_schid.ssid); 4293e4415a7SThomas Huth found = find_net_dev(&schib, dev_no); 4303e4415a7SThomas Huth } else { 4313e4415a7SThomas Huth for (ssid = 0; ssid < 0x3; ssid++) { 4323e4415a7SThomas Huth net_schid.ssid = ssid; 4333e4415a7SThomas Huth found = find_net_dev(&schib, -1); 4343e4415a7SThomas Huth if (found) { 4353e4415a7SThomas Huth break; 4363e4415a7SThomas Huth } 4373e4415a7SThomas Huth } 4383e4415a7SThomas Huth } 4393e4415a7SThomas Huth 4403e4415a7SThomas Huth IPL_assert(found, "No virtio net device found"); 4413e4415a7SThomas Huth } 4423e4415a7SThomas Huth 4433e4415a7SThomas Huth void main(void) 4443e4415a7SThomas Huth { 4450c188229SThomas Huth filename_ip_t fn_ip; 446*c4942ee9SThomas Huth int rc, fnlen; 44729d12216SThomas Huth 4483e4415a7SThomas Huth sclp_setup(); 4493e4415a7SThomas Huth sclp_print("Network boot starting...\n"); 4503e4415a7SThomas Huth 4513e4415a7SThomas Huth virtio_setup(); 4523e4415a7SThomas Huth 4530c188229SThomas Huth rc = net_init(&fn_ip); 4540c188229SThomas Huth if (rc) { 4550c188229SThomas Huth panic("Network initialization failed. Halting.\n"); 4560c188229SThomas Huth } 4570c188229SThomas Huth 458*c4942ee9SThomas Huth fnlen = strlen((char *)fn_ip.filename); 459*c4942ee9SThomas Huth if (fnlen > 0 && fn_ip.filename[fnlen - 1] != '/') { 460*c4942ee9SThomas Huth rc = net_try_direct_tftp_load(&fn_ip); 461*c4942ee9SThomas Huth } 4620c188229SThomas Huth 4630c188229SThomas Huth net_release(&fn_ip); 4640c188229SThomas Huth 46529d12216SThomas Huth if (rc > 0) { 46629d12216SThomas Huth sclp_print("Network loading done, starting kernel...\n"); 4679a848adfSThomas Huth jump_to_low_kernel(); 46829d12216SThomas Huth } 46929d12216SThomas Huth 4703e4415a7SThomas Huth panic("Failed to load OS from network\n"); 4713e4415a7SThomas Huth } 472