Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libethdrivers,imx: Reintroduce ethif_imx6_init #112

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion libethdrivers/include/ethdrivers/imx6.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,15 @@

#pragma once

/* nothing here */
#include <platsupport/io.h>
#include <ethdrivers/raw.h>

/**
* This function initialises the hardware and conforms to the ethif_driver_init
* type in raw.h
* @param[out] eth_driver Ethernet driver structure to fill out
* @param[in] io_ops A structure containing os specific data and
* functions.
* @param[in] config Platform Specific configuration data
*/
int ethif_imx6_init(struct eth_driver *eth_driver, ps_io_ops_t io_ops, void *config);
2 changes: 1 addition & 1 deletion libethdrivers/plat_include/imx6/ethdrivers/plat/eth_plat.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
#include <ethdrivers/imx6.h>
#include <utils/attribute.h>
#include <ethdrivers/raw.h>
#include "../src/plat/imx6/enet.h"
Copy link
Member

@axel-h axel-h Dec 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly we had to include this here to address a nasty include problem and make these prototypes available to other C file in our driver:

int enet_mdio_read(struct enet *enet, uint16_t phy, uint16_t reg);
int enet_mdio_write(struct enet *enet, uint16_t phy, uint16_t reg, uint16_t data);

Could you leave this in for now. I'd make this a separate issue (#116) than that should be cleaned up.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does seem possible to declare just those symbols at the bottom of this file:

int enet_mdio_read(struct enet* enet, uint16_t phy, uint16_t reg);
int enet_mdio_write(struct enet* enet, uint16_t phy, uint16_t reg, uint16_t data);

Adding a relative include into a private header file breaks if these public headers are installed somewhere else which breaks how I'm using the library.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, sounds feasible, I don't remember why we did not do this. Can you put removing this header here in a separate commit, so this is separate from adding the NIC_CONFIG_NO_CLOCK_SYS flag or adding the interface again?


struct enet *get_enet_from_driver(struct eth_driver *driver);

enum {
NIC_CONFIG_FORCE_MAC = 1u << 0, /**< Use MAC from config (if not 0) */
NIC_CONFIG_PROMISCUOUS_MODE = 1u << 1, /**< Enable promiscuous mode */
NIC_CONFIG_DROP_FRAME_CRC = 1u << 2, /**< Drop ethernet frame CRC */
NIC_CONFIG_NO_CLOCK_SYS = 1u << 3, /**< Don't use clock_sys interface */
} nic_config_flags_t;

typedef int (*sync_func_t)(void);
Expand Down
24 changes: 14 additions & 10 deletions libethdrivers/src/plat/imx6/enet.c
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ void enet_crc_strip_disable(struct enet *enet)
regs->rcr &= ~RCR_CRCSTRIP;
}

struct enet *enet_init(void *mapped_peripheral, uintptr_t tx_phys,
struct enet *enet_init(const nic_config_t *nic_config, void *mapped_peripheral, uintptr_t tx_phys,
uintptr_t rx_phys, size_t rx_bufsize, uint64_t mac,
ps_io_ops_t *io_ops)
{
Expand All @@ -552,11 +552,13 @@ struct enet *enet_init(void *mapped_peripheral, uintptr_t tx_phys,

#if defined(CONFIG_PLAT_IMX6)

/* Set the ethernet clock frequency */
clock_sys_t *clk_sys = malloc(sizeof(clock_sys_t));
clock_sys_init(io_ops, clk_sys);
enet_clk_ptr = clk_get_clock(clk_sys, CLK_ENET);
clk_set_freq(enet_clk_ptr, ENET_FREQ);
if (!(nic_config && (nic_config->flags & NIC_CONFIG_NO_CLOCK_SYS))) {
/* Set the ethernet clock frequency */
clock_sys_t *clk_sys = malloc(sizeof(clock_sys_t));
clock_sys_init(io_ops, clk_sys);
enet_clk_ptr = clk_get_clock(clk_sys, CLK_ENET);
clk_set_freq(enet_clk_ptr, ENET_FREQ);
}

#elif defined(CONFIG_PLAT_IMX8MQ_EVK)

Expand Down Expand Up @@ -592,10 +594,12 @@ struct enet *enet_init(void *mapped_peripheral, uintptr_t tx_phys,

#endif

/* Set the MDIO clock frequency */
mdc_clk.priv = (void *)regs;
clk_register_child(enet_clk_ptr, &mdc_clk);
clk_set_freq(&mdc_clk, MDC_FREQ);
if (!(nic_config && (nic_config->flags & NIC_CONFIG_NO_CLOCK_SYS))) {
/* Set the MDIO clock frequency */
mdc_clk.priv = (void *)regs;
clk_register_child(enet_clk_ptr, &mdc_clk);
clk_set_freq(&mdc_clk, MDC_FREQ);
}

/* Clear out MIB */
enet_clear_mib(enet);
Expand Down
2 changes: 2 additions & 0 deletions libethdrivers/src/plat/imx6/enet.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <stdint.h>
#include <platsupport/io.h>
#include <ethdrivers/plat/eth_plat.h>

#define NETIRQ_BABR (1UL << 30) /* Babbling Receive Error */
#define NETIRQ_BABT (1UL << 29) /* Babbling Transmit Error */
Expand All @@ -30,6 +31,7 @@
struct enet;

struct enet *enet_init(
const nic_config_t *nic_config,
void *mapped_peripheral,
uintptr_t tx_phys,
uintptr_t rx_phys,
Expand Down
Loading