1/* 2 * Copyright 2020, Data61, CSIRO (ABN 41 687 119 230) 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 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 struct eth_driver *eth_driver; 42 int error = ps_calloc(&io_ops->malloc_ops, 1, sizeof(*eth_driver), (void **)ð_driver); 43 if (error) { 44 ZF_LOGE("Failed to allocate struct for ethdriver"); 45 return error; 46 } 47 48 error = ethif_init(eth_driver, io_ops); 49 if (error) { 50 ZF_LOGE("Failed to initialize ethernet driver"); 51 return error; 52 } 53 return 0; 54} 55 56 57CAMKES_PRE_INIT_MODULE_DEFINE(ethdriver_setup, init_device); 58 59