1/*
2 * Copyright 2019, Data61, CSIRO (ABN 41 687 119 230)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
7#include <camkes.h>
8#include <utils/util.h>
9#include <ethdrivers/raw.h>
10#include <ethdrivers/intel.h>
11
12
13int ethif_init(struct eth_driver *eth_driver, ps_io_ops_t *io_ops)
14{
15    ethif_intel_config_t *eth_config = calloc(1, sizeof(ethif_intel_config_t) + sizeof(ps_irq_t));
16    *eth_config = (ethif_intel_config_t) {
17        /* Ethdriver component dataport */
18        .bar0 = (void *)EthDriver,
19        .prom_mode = (uint8_t) promiscuous_mode,
20        .num_irqs = 1
21    };
22
23    eth_config->irq_info[0] = (ps_irq_t) {
24        .type = PS_IOAPIC, .ioapic = { .ioapic = 0, .pin = 20,
25                                       .level = 1, .polarity = 1,
26                                       .vector = 20
27                                     }
28    };
29
30    int error = ethif_e82574_init(eth_driver, *io_ops, eth_config);
31    if (error) {
32        ZF_LOGF("ERROR init ethernet");
33        return error;
34    }
35
36    return 0;
37}
38
39static int init_device(ps_io_ops_t *io_ops)
40{
41
42    struct eth_driver *eth_driver;
43    int error = ps_calloc(&io_ops->malloc_ops, 1, sizeof(*eth_driver), (void **)&eth_driver);
44    if (error) {
45        ZF_LOGE("Failed to allocate struct for ethdriver");
46        return error;
47    }
48
49    error = ethif_init(eth_driver, io_ops);
50    if (error) {
51        ZF_LOGE("Failed to initialize ethernet driver");
52        return error;
53    }
54    return 0;
55}
56
57
58CAMKES_PRE_INIT_MODULE_DEFINE(ethdriver_setup, init_device);
59
60