1/*
2 * Copyright 2020, Data61
3 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
4 * ABN 41 687 119 230.
5 *
6 * This software may be distributed and modified according to the terms of
7 * the GNU General Public License version 2. Note that NO WARRANTY is provided.
8 * See "LICENSE_GPLv2.txt" for details.
9 *
10 * @TAG(DATA61_GPL)
11 */
12
13#include <camkes.h>
14#include <utils/util.h>
15#include <ethdrivers/raw.h>
16#include <ethdrivers/intel.h>
17
18
19int ethif_init(struct eth_driver *eth_driver, ps_io_ops_t *io_ops)
20{
21    ps_irq_t irq_info = (ps_irq_t) {
22        .type = PS_IOAPIC, .ioapic = { .ioapic = 0, .pin = 20,
23                                       .level = 1, .polarity = 1,
24                                       .vector = 20
25                                     }
26    };
27
28    ethif_intel_config_t *eth_config = calloc(1, sizeof(ethif_intel_config_t) + sizeof(ps_irq_t));
29    *eth_config = (ethif_intel_config_t) {
30        /* Ethdriver component dataport */
31        .bar0 = (void *)EthDriver,
32        .prom_mode = (uint8_t) promiscuous_mode,
33        .num_irqs = 1
34    };
35
36    eth_config->irq_info[0] = (ps_irq_t) {
37        .type = PS_IOAPIC, .ioapic = { .ioapic = 0, .pin = 20,
38                                       .level = 1, .polarity = 1,
39                                       .vector = 20
40                                     }
41    };
42
43    int error = ethif_e82580_init(eth_driver, *io_ops, eth_config);
44    if (error) {
45        ZF_LOGF("ERROR init ethernet");
46        return error;
47    }
48
49    return 0;
50}
51
52static int init_device(ps_io_ops_t *io_ops)
53{
54
55    struct eth_driver *eth_driver;
56    int error = ps_calloc(&io_ops->malloc_ops, 1, sizeof(*eth_driver), (void **)&eth_driver);
57    if (error) {
58        ZF_LOGE("Failed to allocate struct for ethdriver");
59        return error;
60    }
61
62    error = ethif_init(eth_driver, io_ops);
63    if (error) {
64        ZF_LOGE("Failed to initialize ethernet driver");
65        return error;
66    }
67    return 0;
68}
69
70
71CAMKES_PRE_INIT_MODULE_DEFINE(ethdriver_setup, init_device);
72
73