drivers: eth: Convert to use new logging
Convert the ethernet drivers to use the new logging system. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit is contained in:
parent
9b460b1105
commit
20295c821b
9 changed files with 170 additions and 165 deletions
|
@ -8,19 +8,13 @@
|
||||||
|
|
||||||
menu "Ethernet Drivers"
|
menu "Ethernet Drivers"
|
||||||
|
|
||||||
config SYS_LOG_ETHERNET_LEVEL
|
if NET_L2_ETHERNET
|
||||||
int "Ethernet driver log level"
|
module=ETHERNET
|
||||||
depends on SYS_LOG && NET_L2_ETHERNET
|
module-dep=LOG
|
||||||
default 0
|
module-str=Log level for Ethernet driver
|
||||||
range 0 4
|
module-help=Sets log level for Ethernet Device Drivers.
|
||||||
help
|
source "subsys/net/Kconfig.template.log_config.net"
|
||||||
Sets log level for Ethernet Device Drivers.
|
endif # NET_L2_ETHERNET
|
||||||
Levels are:
|
|
||||||
0 OFF, do not write
|
|
||||||
1 ERROR, only write SYS_LOG_ERR
|
|
||||||
2 WARNING, write SYS_LOG_WRN in addition to previous level
|
|
||||||
3 INFO, write SYS_LOG_INF in addition to previous levels
|
|
||||||
4 DEBUG, write SYS_LOG_DBG in addition to previous levels
|
|
||||||
|
|
||||||
config ETH_INIT_PRIORITY
|
config ETH_INIT_PRIORITY
|
||||||
int "Ethernet driver init priority"
|
int "Ethernet driver init priority"
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
*
|
*
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
#define SYS_LOG_DOMAIN "ETH DW"
|
#define LOG_MODULE_NAME eth_dw
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_ETHERNET_LEVEL
|
#define LOG_LEVEL CONFIG_ETHERNET_LOG_LEVEL
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
||||||
|
|
||||||
#include <board.h>
|
#include <board.h>
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
|
@ -51,19 +53,19 @@ static void eth_rx(struct device *port)
|
||||||
* process the received frame or an error that may have occurred.
|
* process the received frame or an error that may have occurred.
|
||||||
*/
|
*/
|
||||||
if (context->rx_desc.own) {
|
if (context->rx_desc.own) {
|
||||||
SYS_LOG_ERR("Spurious receive interrupt from Ethernet MAC");
|
LOG_ERR("Spurious receive interrupt from Ethernet MAC");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (context->rx_desc.err_summary) {
|
if (context->rx_desc.err_summary) {
|
||||||
SYS_LOG_ERR("Error receiving frame: RDES0 = %08x, RDES1 = %08x",
|
LOG_ERR("Error receiving frame: RDES0 = %08x, RDES1 = %08x",
|
||||||
context->rx_desc.rdes0, context->rx_desc.rdes1);
|
context->rx_desc.rdes0, context->rx_desc.rdes1);
|
||||||
goto release_desc;
|
goto release_desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
frm_len = context->rx_desc.frm_len;
|
frm_len = context->rx_desc.frm_len;
|
||||||
if (frm_len > sizeof(context->rx_buf)) {
|
if (frm_len > sizeof(context->rx_buf)) {
|
||||||
SYS_LOG_ERR("Frame too large: %u", frm_len);
|
LOG_ERR("Frame too large: %u", frm_len);
|
||||||
goto release_desc;
|
goto release_desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,7 +79,7 @@ static void eth_rx(struct device *port)
|
||||||
* received frame length by exactly 4 bytes.
|
* received frame length by exactly 4 bytes.
|
||||||
*/
|
*/
|
||||||
if (frm_len < sizeof(u32_t)) {
|
if (frm_len < sizeof(u32_t)) {
|
||||||
SYS_LOG_ERR("Frame too small: %u", frm_len);
|
LOG_ERR("Frame too small: %u", frm_len);
|
||||||
goto release_desc;
|
goto release_desc;
|
||||||
} else {
|
} else {
|
||||||
frm_len -= sizeof(u32_t);
|
frm_len -= sizeof(u32_t);
|
||||||
|
@ -85,20 +87,20 @@ static void eth_rx(struct device *port)
|
||||||
|
|
||||||
pkt = net_pkt_get_reserve_rx(0, K_NO_WAIT);
|
pkt = net_pkt_get_reserve_rx(0, K_NO_WAIT);
|
||||||
if (!pkt) {
|
if (!pkt) {
|
||||||
SYS_LOG_ERR("Failed to obtain RX buffer");
|
LOG_ERR("Failed to obtain RX buffer");
|
||||||
goto release_desc;
|
goto release_desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!net_pkt_append_all(pkt, frm_len, (u8_t *)context->rx_buf,
|
if (!net_pkt_append_all(pkt, frm_len, (u8_t *)context->rx_buf,
|
||||||
K_NO_WAIT)) {
|
K_NO_WAIT)) {
|
||||||
SYS_LOG_ERR("Failed to append RX buffer to context buffer");
|
LOG_ERR("Failed to append RX buffer to context buffer");
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
goto release_desc;
|
goto release_desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
r = net_recv_data(context->iface, pkt);
|
r = net_recv_data(context->iface, pkt);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
SYS_LOG_ERR("Failed to enqueue frame into RX queue: %d", r);
|
LOG_ERR("Failed to enqueue frame into RX queue: %d", r);
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -132,9 +134,9 @@ static void eth_tx_data(struct eth_runtime *context, u8_t *data, u16_t len)
|
||||||
#ifdef CONFIG_NET_DEBUG_L2_ETHERNET
|
#ifdef CONFIG_NET_DEBUG_L2_ETHERNET
|
||||||
/* Check whether an error occurred transmitting the previous frame. */
|
/* Check whether an error occurred transmitting the previous frame. */
|
||||||
if (context->tx_desc.err_summary) {
|
if (context->tx_desc.err_summary) {
|
||||||
SYS_LOG_ERR("Error transmitting frame: TDES0 = %08x,"
|
LOG_ERR("Error transmitting frame: TDES0 = %08x,"
|
||||||
"TDES1 = %08x", context->tx_desc.tdes0,
|
"TDES1 = %08x", context->tx_desc.tdes0,
|
||||||
context->tx_desc.tdes1);
|
context->tx_desc.tdes1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -313,7 +315,7 @@ static int eth_initialize_internal(struct net_if *iface)
|
||||||
/* Place the receiver state machine in the Running state. */
|
/* Place the receiver state machine in the Running state. */
|
||||||
OP_MODE_1_START_RX);
|
OP_MODE_1_START_RX);
|
||||||
|
|
||||||
SYS_LOG_INF("Enabled 100M full-duplex mode");
|
LOG_INF("Enabled 100M full-duplex mode");
|
||||||
|
|
||||||
config->config_func(port);
|
config->config_func(port);
|
||||||
|
|
||||||
|
@ -325,7 +327,7 @@ static void eth_initialize(struct net_if *iface)
|
||||||
int r = eth_initialize_internal(iface);
|
int r = eth_initialize_internal(iface);
|
||||||
|
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
SYS_LOG_ERR("Could not initialize ethernet device: %d", r);
|
LOG_ERR("Could not initialize ethernet device: %d", r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,9 +5,11 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_ETHERNET_LEVEL
|
#define LOG_MODULE_NAME eth_enc28j60
|
||||||
#define SYS_LOG_DOMAIN "dev/enc28j60"
|
#define LOG_LEVEL CONFIG_ETHERNET_LOG_LEVEL
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
||||||
|
|
||||||
#include <zephyr.h>
|
#include <zephyr.h>
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
|
@ -69,7 +71,7 @@ static void eth_enc28j60_set_bank(struct device *dev, u16_t reg_addr)
|
||||||
|
|
||||||
spi_write(context->spi, &context->spi_cfg, &tx);
|
spi_write(context->spi, &context->spi_cfg, &tx);
|
||||||
} else {
|
} else {
|
||||||
SYS_LOG_DBG("Failure while setting bank to 0x%04x", reg_addr);
|
LOG_DBG("Failure while setting bank to 0x%04x", reg_addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +129,7 @@ static void eth_enc28j60_read_reg(struct device *dev, u16_t reg_addr,
|
||||||
if (!spi_transceive(context->spi, &context->spi_cfg, &tx, &rx)) {
|
if (!spi_transceive(context->spi, &context->spi_cfg, &tx, &rx)) {
|
||||||
*value = buf[rx_size - 1];
|
*value = buf[rx_size - 1];
|
||||||
} else {
|
} else {
|
||||||
SYS_LOG_DBG("Failure while reading register 0x%04x", reg_addr);
|
LOG_DBG("Failure while reading register 0x%04x", reg_addr);
|
||||||
*value = 0;
|
*value = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -200,7 +202,7 @@ static void eth_enc28j60_write_mem(struct device *dev, u8_t *data_buffer,
|
||||||
tx_buf[1].len = MAX_BUFFER_LENGTH;
|
tx_buf[1].len = MAX_BUFFER_LENGTH;
|
||||||
|
|
||||||
if (spi_write(context->spi, &context->spi_cfg, &tx)) {
|
if (spi_write(context->spi, &context->spi_cfg, &tx)) {
|
||||||
SYS_LOG_ERR("Failed to write memory");
|
LOG_ERR("Failed to write memory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -210,7 +212,7 @@ static void eth_enc28j60_write_mem(struct device *dev, u8_t *data_buffer,
|
||||||
tx_buf[1].len = num_remaining;
|
tx_buf[1].len = num_remaining;
|
||||||
|
|
||||||
if (spi_write(context->spi, &context->spi_cfg, &tx)) {
|
if (spi_write(context->spi, &context->spi_cfg, &tx)) {
|
||||||
SYS_LOG_ERR("Failed to write memory");
|
LOG_ERR("Failed to write memory");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,7 +253,7 @@ static void eth_enc28j60_read_mem(struct device *dev, u8_t *data_buffer,
|
||||||
rx_buf[1].len = MAX_BUFFER_LENGTH;
|
rx_buf[1].len = MAX_BUFFER_LENGTH;
|
||||||
|
|
||||||
if (spi_transceive(context->spi, &context->spi_cfg, &tx, &rx)) {
|
if (spi_transceive(context->spi, &context->spi_cfg, &tx, &rx)) {
|
||||||
SYS_LOG_ERR("Failed to read memory");
|
LOG_ERR("Failed to read memory");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -261,7 +263,7 @@ static void eth_enc28j60_read_mem(struct device *dev, u8_t *data_buffer,
|
||||||
rx_buf[1].len = num_remaining;
|
rx_buf[1].len = num_remaining;
|
||||||
|
|
||||||
if (spi_transceive(context->spi, &context->spi_cfg, &tx, &rx)) {
|
if (spi_transceive(context->spi, &context->spi_cfg, &tx, &rx)) {
|
||||||
SYS_LOG_ERR("Failed to read memory");
|
LOG_ERR("Failed to read memory");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -415,7 +417,7 @@ static int eth_enc28j60_tx(struct net_if *iface, struct net_pkt *pkt)
|
||||||
struct net_buf *frag;
|
struct net_buf *frag;
|
||||||
u8_t tx_end;
|
u8_t tx_end;
|
||||||
|
|
||||||
SYS_LOG_DBG("pkt %p (len %u)", pkt, len);
|
LOG_DBG("pkt %p (len %u)", pkt, len);
|
||||||
|
|
||||||
k_sem_take(&context->tx_rx_sem, K_FOREVER);
|
k_sem_take(&context->tx_rx_sem, K_FOREVER);
|
||||||
|
|
||||||
|
@ -481,13 +483,13 @@ static int eth_enc28j60_tx(struct net_if *iface, struct net_pkt *pkt)
|
||||||
k_sem_give(&context->tx_rx_sem);
|
k_sem_give(&context->tx_rx_sem);
|
||||||
|
|
||||||
if (tx_end & ENC28J60_BIT_ESTAT_TXABRT) {
|
if (tx_end & ENC28J60_BIT_ESTAT_TXABRT) {
|
||||||
SYS_LOG_ERR("TX failed!");
|
LOG_ERR("TX failed!");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
|
|
||||||
SYS_LOG_DBG("Tx successful");
|
LOG_DBG("Tx successful");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -509,8 +511,6 @@ static int eth_enc28j60_rx(struct device *dev)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_DBG("");
|
|
||||||
|
|
||||||
k_sem_take(&context->tx_rx_sem, K_FOREVER);
|
k_sem_take(&context->tx_rx_sem, K_FOREVER);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
|
@ -555,7 +555,7 @@ static int eth_enc28j60_rx(struct device *dev)
|
||||||
/* Get the frame from the buffer */
|
/* Get the frame from the buffer */
|
||||||
pkt = net_pkt_get_reserve_rx(0, config->timeout);
|
pkt = net_pkt_get_reserve_rx(0, config->timeout);
|
||||||
if (!pkt) {
|
if (!pkt) {
|
||||||
SYS_LOG_ERR("Could not allocate rx buffer");
|
LOG_ERR("Could not allocate rx buffer");
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -567,7 +567,7 @@ static int eth_enc28j60_rx(struct device *dev)
|
||||||
/* Reserve a data frag to receive the frame */
|
/* Reserve a data frag to receive the frame */
|
||||||
pkt_buf = net_pkt_get_frag(pkt, config->timeout);
|
pkt_buf = net_pkt_get_frag(pkt, config->timeout);
|
||||||
if (!pkt_buf) {
|
if (!pkt_buf) {
|
||||||
SYS_LOG_ERR("Could not allocate data buffer");
|
LOG_ERR("Could not allocate data buffer");
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
|
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -611,7 +611,7 @@ static int eth_enc28j60_rx(struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Feed buffer frame to IP stack */
|
/* Feed buffer frame to IP stack */
|
||||||
SYS_LOG_DBG("Received packet of length %u", lengthfr);
|
LOG_DBG("Received packet of length %u", lengthfr);
|
||||||
net_recv_data(context->iface, pkt);
|
net_recv_data(context->iface, pkt);
|
||||||
done:
|
done:
|
||||||
/* Free buffer memory and decrement rx counter */
|
/* Free buffer memory and decrement rx counter */
|
||||||
|
@ -664,8 +664,6 @@ static void eth_enc28j60_iface_init(struct net_if *iface)
|
||||||
struct device *dev = net_if_get_device(iface);
|
struct device *dev = net_if_get_device(iface);
|
||||||
struct eth_enc28j60_runtime *context = dev->driver_data;
|
struct eth_enc28j60_runtime *context = dev->driver_data;
|
||||||
|
|
||||||
SYS_LOG_DBG("");
|
|
||||||
|
|
||||||
net_if_set_link_addr(iface, context->mac_address,
|
net_if_set_link_addr(iface, context->mac_address,
|
||||||
sizeof(context->mac_address),
|
sizeof(context->mac_address),
|
||||||
NET_LINK_ETHERNET);
|
NET_LINK_ETHERNET);
|
||||||
|
@ -692,7 +690,7 @@ static int eth_enc28j60_init(struct device *dev)
|
||||||
context->spi = device_get_binding((char *)config->spi_port);
|
context->spi = device_get_binding((char *)config->spi_port);
|
||||||
if (!context->spi) {
|
if (!context->spi) {
|
||||||
|
|
||||||
SYS_LOG_ERR("SPI master port %s not found", config->spi_port);
|
LOG_ERR("SPI master port %s not found", config->spi_port);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -700,7 +698,7 @@ static int eth_enc28j60_init(struct device *dev)
|
||||||
context->spi_cs.gpio_dev =
|
context->spi_cs.gpio_dev =
|
||||||
device_get_binding((char *)config->spi_cs_port);
|
device_get_binding((char *)config->spi_cs_port);
|
||||||
if (!context->spi_cs.gpio_dev) {
|
if (!context->spi_cs.gpio_dev) {
|
||||||
SYS_LOG_ERR("SPI CS port %s not found", config->spi_cs_port);
|
LOG_ERR("SPI CS port %s not found", config->spi_cs_port);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -711,14 +709,14 @@ static int eth_enc28j60_init(struct device *dev)
|
||||||
/* Initialize GPIO */
|
/* Initialize GPIO */
|
||||||
context->gpio = device_get_binding((char *)config->gpio_port);
|
context->gpio = device_get_binding((char *)config->gpio_port);
|
||||||
if (!context->gpio) {
|
if (!context->gpio) {
|
||||||
SYS_LOG_ERR("GPIO port %s not found", config->gpio_port);
|
LOG_ERR("GPIO port %s not found", config->gpio_port);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (gpio_pin_configure(context->gpio, config->gpio_pin,
|
if (gpio_pin_configure(context->gpio, config->gpio_pin,
|
||||||
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE
|
(GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE
|
||||||
| GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE))) {
|
| GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE))) {
|
||||||
SYS_LOG_ERR("Unable to configure GPIO pin %u",
|
LOG_ERR("Unable to configure GPIO pin %u",
|
||||||
config->gpio_pin);
|
config->gpio_pin);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
@ -735,7 +733,7 @@ static int eth_enc28j60_init(struct device *dev)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eth_enc28j60_soft_reset(dev)) {
|
if (eth_enc28j60_soft_reset(dev)) {
|
||||||
SYS_LOG_ERR("Soft-reset failed");
|
LOG_ERR("Soft-reset failed");
|
||||||
return -EIO;
|
return -EIO;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -762,7 +760,7 @@ static int eth_enc28j60_init(struct device *dev)
|
||||||
K_PRIO_COOP(CONFIG_ETH_ENC28J60_RX_THREAD_PRIO),
|
K_PRIO_COOP(CONFIG_ETH_ENC28J60_RX_THREAD_PRIO),
|
||||||
0, K_NO_WAIT);
|
0, K_NO_WAIT);
|
||||||
|
|
||||||
SYS_LOG_INF("ENC28J60 Initialized");
|
LOG_INF("ENC28J60 Initialized");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,9 +13,11 @@
|
||||||
* error behaviour.
|
* error behaviour.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "dev/eth_mcux"
|
#define LOG_MODULE_NAME eth_mcux
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_ETHERNET_LEVEL
|
#define LOG_LEVEL CONFIG_ETHERNET_LOG_LEVEL
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
||||||
|
|
||||||
#include <board.h>
|
#include <board.h>
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
|
@ -194,7 +196,7 @@ static void eth_mcux_phy_enter_reset(struct eth_context *context)
|
||||||
static void eth_mcux_phy_start(struct eth_context *context)
|
static void eth_mcux_phy_start(struct eth_context *context)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG
|
#ifdef CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG
|
||||||
SYS_LOG_DBG("phy_state=%s", phy_state_name(context->phy_state));
|
LOG_DBG("phy_state=%s", phy_state_name(context->phy_state));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
context->enabled = true;
|
context->enabled = true;
|
||||||
|
@ -218,7 +220,7 @@ static void eth_mcux_phy_start(struct eth_context *context)
|
||||||
void eth_mcux_phy_stop(struct eth_context *context)
|
void eth_mcux_phy_stop(struct eth_context *context)
|
||||||
{
|
{
|
||||||
#ifdef CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG
|
#ifdef CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG
|
||||||
SYS_LOG_DBG("phy_state=%s", phy_state_name(context->phy_state));
|
LOG_DBG("phy_state=%s", phy_state_name(context->phy_state));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
context->enabled = false;
|
context->enabled = false;
|
||||||
|
@ -255,7 +257,7 @@ static void eth_mcux_phy_event(struct eth_context *context)
|
||||||
const u32_t phy_addr = 0;
|
const u32_t phy_addr = 0;
|
||||||
|
|
||||||
#ifdef CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG
|
#ifdef CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG
|
||||||
SYS_LOG_DBG("phy_state=%s", phy_state_name(context->phy_state));
|
LOG_DBG("phy_state=%s", phy_state_name(context->phy_state));
|
||||||
#endif
|
#endif
|
||||||
switch (context->phy_state) {
|
switch (context->phy_state) {
|
||||||
case eth_mcux_phy_state_initial:
|
case eth_mcux_phy_state_initial:
|
||||||
|
@ -305,7 +307,7 @@ static void eth_mcux_phy_event(struct eth_context *context)
|
||||||
context->phy_state = eth_mcux_phy_state_read_duplex;
|
context->phy_state = eth_mcux_phy_state_read_duplex;
|
||||||
net_eth_carrier_on(context->iface);
|
net_eth_carrier_on(context->iface);
|
||||||
} else if (!link_up && context->link_up) {
|
} else if (!link_up && context->link_up) {
|
||||||
SYS_LOG_INF("Link down");
|
LOG_INF("Link down");
|
||||||
context->link_up = link_up;
|
context->link_up = link_up;
|
||||||
k_delayed_work_submit(&context->delayed_phy_work,
|
k_delayed_work_submit(&context->delayed_phy_work,
|
||||||
CONFIG_ETH_MCUX_PHY_TICK_MS);
|
CONFIG_ETH_MCUX_PHY_TICK_MS);
|
||||||
|
@ -333,9 +335,9 @@ static void eth_mcux_phy_event(struct eth_context *context)
|
||||||
(enet_mii_duplex_t) phy_duplex);
|
(enet_mii_duplex_t) phy_duplex);
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_INF("Enabled %sM %s-duplex mode.",
|
LOG_INF("Enabled %sM %s-duplex mode.",
|
||||||
(phy_speed ? "100" : "10"),
|
(phy_speed ? "100" : "10"),
|
||||||
(phy_duplex ? "full" : "half"));
|
(phy_duplex ? "full" : "half"));
|
||||||
k_delayed_work_submit(&context->delayed_phy_work,
|
k_delayed_work_submit(&context->delayed_phy_work,
|
||||||
CONFIG_ETH_MCUX_PHY_TICK_MS);
|
CONFIG_ETH_MCUX_PHY_TICK_MS);
|
||||||
context->phy_state = eth_mcux_phy_state_wait;
|
context->phy_state = eth_mcux_phy_state_wait;
|
||||||
|
@ -413,22 +415,21 @@ static bool eth_get_ptp_data(struct net_if *iface, struct net_pkt *pkt,
|
||||||
ptpTsData->sequenceId = ntohs(hdr->sequence_id);
|
ptpTsData->sequenceId = ntohs(hdr->sequence_id);
|
||||||
|
|
||||||
#ifdef CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG
|
#ifdef CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG
|
||||||
SYS_LOG_DBG("PTP packet: ver %d type %d len %d "
|
LOG_DBG("PTP packet: ver %d type %d len %d seq %d",
|
||||||
"clk %02x%02x%02x%02x%02x%02x%02x%02x port %d "
|
ptpTsData->version,
|
||||||
"seq %d",
|
ptpTsData->messageType,
|
||||||
ptpTsData->version,
|
ntohs(hdr->message_length),
|
||||||
ptpTsData->messageType,
|
ptpTsData->sequenceId);
|
||||||
ntohs(hdr->message_length),
|
LOG_DBG(" clk %02x%02x%02x%02x%02x%02x%02x%02x port %d",
|
||||||
hdr->port_id.clk_id[0],
|
hdr->port_id.clk_id[0],
|
||||||
hdr->port_id.clk_id[1],
|
hdr->port_id.clk_id[1],
|
||||||
hdr->port_id.clk_id[2],
|
hdr->port_id.clk_id[2],
|
||||||
hdr->port_id.clk_id[3],
|
hdr->port_id.clk_id[3],
|
||||||
hdr->port_id.clk_id[4],
|
hdr->port_id.clk_id[4],
|
||||||
hdr->port_id.clk_id[5],
|
hdr->port_id.clk_id[5],
|
||||||
hdr->port_id.clk_id[6],
|
hdr->port_id.clk_id[6],
|
||||||
hdr->port_id.clk_id[7],
|
hdr->port_id.clk_id[7],
|
||||||
ntohs(hdr->port_id.port_number),
|
ntohs(hdr->port_id.port_number));
|
||||||
ptpTsData->sequenceId);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -506,7 +507,7 @@ static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
|
||||||
irq_unlock(imask);
|
irq_unlock(imask);
|
||||||
|
|
||||||
if (status) {
|
if (status) {
|
||||||
SYS_LOG_ERR("ENET_SendFrame error: %d", (int)status);
|
LOG_ERR("ENET_SendFrame error: %d", (int)status);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -535,7 +536,7 @@ static void eth_rx(struct device *iface)
|
||||||
if (status) {
|
if (status) {
|
||||||
enet_data_error_stats_t error_stats;
|
enet_data_error_stats_t error_stats;
|
||||||
|
|
||||||
SYS_LOG_ERR("ENET_GetRxFrameSize return: %d", (int)status);
|
LOG_ERR("ENET_GetRxFrameSize return: %d", (int)status);
|
||||||
|
|
||||||
ENET_GetRxErrBeforeReadFrame(&context->enet_handle,
|
ENET_GetRxErrBeforeReadFrame(&context->enet_handle,
|
||||||
&error_stats);
|
&error_stats);
|
||||||
|
@ -564,7 +565,7 @@ static void eth_rx(struct device *iface)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sizeof(context->frame_buf) < frame_length) {
|
if (sizeof(context->frame_buf) < frame_length) {
|
||||||
SYS_LOG_ERR("frame too large (%d)", frame_length);
|
LOG_ERR("frame too large (%d)", frame_length);
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
status = ENET_ReadFrame(ENET, &context->enet_handle, NULL, 0);
|
status = ENET_ReadFrame(ENET, &context->enet_handle, NULL, 0);
|
||||||
assert(status == kStatus_Success);
|
assert(status == kStatus_Success);
|
||||||
|
@ -580,7 +581,7 @@ static void eth_rx(struct device *iface)
|
||||||
context->frame_buf, frame_length);
|
context->frame_buf, frame_length);
|
||||||
if (status) {
|
if (status) {
|
||||||
irq_unlock(imask);
|
irq_unlock(imask);
|
||||||
SYS_LOG_ERR("ENET_ReadFrame failed: %d", (int)status);
|
LOG_ERR("ENET_ReadFrame failed: %d", (int)status);
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -594,7 +595,7 @@ static void eth_rx(struct device *iface)
|
||||||
pkt_buf = net_pkt_get_frag(pkt, K_NO_WAIT);
|
pkt_buf = net_pkt_get_frag(pkt, K_NO_WAIT);
|
||||||
if (!pkt_buf) {
|
if (!pkt_buf) {
|
||||||
irq_unlock(imask);
|
irq_unlock(imask);
|
||||||
SYS_LOG_ERR("Failed to get fragment buf");
|
LOG_ERR("Failed to get fragment buf");
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
assert(status == kStatus_Success);
|
assert(status == kStatus_Success);
|
||||||
return;
|
return;
|
||||||
|
@ -690,7 +691,7 @@ static inline void ts_register_tx_event(struct eth_context *context)
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
} else {
|
} else {
|
||||||
if (IS_ENABLED(CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG) && pkt) {
|
if (IS_ENABLED(CONFIG_ETH_MCUX_PHY_EXTRA_DEBUG) && pkt) {
|
||||||
SYS_LOG_ERR("pkt %p already freed", pkt);
|
LOG_ERR("pkt %p already freed", pkt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -839,10 +840,10 @@ static int eth_0_init(struct device *dev)
|
||||||
|
|
||||||
ENET_SetSMI(ENET, sys_clock, false);
|
ENET_SetSMI(ENET, sys_clock, false);
|
||||||
|
|
||||||
SYS_LOG_DBG("MAC %02x:%02x:%02x:%02x:%02x:%02x",
|
LOG_DBG("MAC %02x:%02x:%02x:%02x:%02x:%02x",
|
||||||
context->mac_addr[0], context->mac_addr[1],
|
context->mac_addr[0], context->mac_addr[1],
|
||||||
context->mac_addr[2], context->mac_addr[3],
|
context->mac_addr[2], context->mac_addr[3],
|
||||||
context->mac_addr[4], context->mac_addr[5]);
|
context->mac_addr[4], context->mac_addr[5]);
|
||||||
|
|
||||||
ENET_SetCallback(&context->enet_handle, eth_callback, dev);
|
ENET_SetCallback(&context->enet_handle, eth_callback, dev);
|
||||||
eth_0_config_func();
|
eth_0_config_func();
|
||||||
|
|
|
@ -11,10 +11,12 @@
|
||||||
* connectivity between host and Zephyr.
|
* connectivity between host and Zephyr.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "eth-posix"
|
#define LOG_MODULE_NAME eth_posix
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_ETHERNET_LEVEL
|
#define LOG_LEVEL CONFIG_ETHERNET_LOG_LEVEL
|
||||||
|
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
||||||
|
|
||||||
#include <logging/sys_log.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
|
@ -239,11 +241,11 @@ static int eth_send(struct net_if *iface, struct net_pkt *pkt)
|
||||||
|
|
||||||
update_gptp(iface, pkt, true);
|
update_gptp(iface, pkt, true);
|
||||||
|
|
||||||
SYS_LOG_DBG("Send pkt %p len %d", pkt, count);
|
LOG_DBG("Send pkt %p len %d", pkt, count);
|
||||||
|
|
||||||
ret = eth_write_data(ctx->dev_fd, ctx->send, count);
|
ret = eth_write_data(ctx->dev_fd, ctx->send, count);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
SYS_LOG_DBG("Cannot send pkt %p (%d)", pkt, ret);
|
LOG_DBG("Cannot send pkt %p (%d)", pkt, ret);
|
||||||
} else {
|
} else {
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
}
|
}
|
||||||
|
@ -359,7 +361,7 @@ static int read_data(struct eth_context *ctx, int fd)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_DBG("Recv pkt %p len %d", pkt, pkt_len);
|
LOG_DBG("Recv pkt %p len %d", pkt, pkt_len);
|
||||||
|
|
||||||
update_gptp(iface, pkt, false);
|
update_gptp(iface, pkt, false);
|
||||||
|
|
||||||
|
@ -374,7 +376,7 @@ static void eth_rx(struct eth_context *ctx)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
SYS_LOG_DBG("Starting ZETH RX thread");
|
LOG_DBG("Starting ZETH RX thread");
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
if (net_if_is_up(ctx->iface)) {
|
if (net_if_is_up(ctx->iface)) {
|
||||||
|
@ -433,8 +435,8 @@ static void eth_iface_init(struct net_if *iface)
|
||||||
if (CONFIG_ETH_NATIVE_POSIX_MAC_ADDR[0] != 0) {
|
if (CONFIG_ETH_NATIVE_POSIX_MAC_ADDR[0] != 0) {
|
||||||
if (net_bytes_from_str(ctx->mac_addr, sizeof(ctx->mac_addr),
|
if (net_bytes_from_str(ctx->mac_addr, sizeof(ctx->mac_addr),
|
||||||
CONFIG_ETH_NATIVE_POSIX_MAC_ADDR) < 0) {
|
CONFIG_ETH_NATIVE_POSIX_MAC_ADDR) < 0) {
|
||||||
SYS_LOG_ERR("Invalid MAC address %s",
|
LOG_ERR("Invalid MAC address %s",
|
||||||
CONFIG_ETH_NATIVE_POSIX_MAC_ADDR);
|
CONFIG_ETH_NATIVE_POSIX_MAC_ADDR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -446,8 +448,7 @@ static void eth_iface_init(struct net_if *iface)
|
||||||
|
|
||||||
ctx->dev_fd = eth_iface_create(ctx->if_name, false);
|
ctx->dev_fd = eth_iface_create(ctx->if_name, false);
|
||||||
if (ctx->dev_fd < 0) {
|
if (ctx->dev_fd < 0) {
|
||||||
SYS_LOG_ERR("Cannot create %s (%d)", ctx->if_name,
|
LOG_ERR("Cannot create %s (%d)", ctx->if_name, ctx->dev_fd);
|
||||||
ctx->dev_fd);
|
|
||||||
} else {
|
} else {
|
||||||
/* Create a thread that will handle incoming data from host */
|
/* Create a thread that will handle incoming data from host */
|
||||||
create_rx_handler(ctx);
|
create_rx_handler(ctx);
|
||||||
|
|
|
@ -34,12 +34,14 @@
|
||||||
/* Zephyr include files. Be very careful here and only include minimum
|
/* Zephyr include files. Be very careful here and only include minimum
|
||||||
* things needed.
|
* things needed.
|
||||||
*/
|
*/
|
||||||
#define SYS_LOG_DOMAIN "eth-posix-adapt"
|
#define LOG_MODULE_NAME eth_posix_adapt
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_ETHERNET_LEVEL
|
#define LOG_LEVEL CONFIG_ETHERNET_LOG_LEVEL
|
||||||
|
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
||||||
|
|
||||||
#include <zephyr/types.h>
|
#include <zephyr/types.h>
|
||||||
#include <sys_clock.h>
|
#include <sys_clock.h>
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
|
||||||
#if defined(CONFIG_NET_GPTP)
|
#if defined(CONFIG_NET_GPTP)
|
||||||
#include <net/gptp.h>
|
#include <net/gptp.h>
|
||||||
|
|
|
@ -20,9 +20,11 @@
|
||||||
* RAM regions in Zephyr.
|
* RAM regions in Zephyr.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "dev/eth_sam"
|
#define LOG_MODULE_NAME eth_sam
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_ETHERNET_LEVEL
|
#define LOG_LEVEL CONFIG_ETHERNET_LOG_LEVEL
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
||||||
|
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
|
@ -275,7 +277,7 @@ static int rx_descriptors_init(Gmac *gmac, struct gmac_queue *queue)
|
||||||
rx_buf = net_pkt_get_reserve_rx_data(0, K_NO_WAIT);
|
rx_buf = net_pkt_get_reserve_rx_data(0, K_NO_WAIT);
|
||||||
if (rx_buf == NULL) {
|
if (rx_buf == NULL) {
|
||||||
free_rx_bufs(rx_frag_list);
|
free_rx_bufs(rx_frag_list);
|
||||||
SYS_LOG_ERR("Failed to reserve data net buffers");
|
LOG_ERR("Failed to reserve data net buffers");
|
||||||
return -ENOBUFS;
|
return -ENOBUFS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -550,7 +552,7 @@ static void tx_completed(Gmac *gmac, struct gmac_queue *queue)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
SYS_LOG_DBG("Dropping pkt %p", pkt);
|
LOG_DBG("Dropping pkt %p", pkt);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -575,7 +577,7 @@ static void tx_error_handler(Gmac *gmac, struct gmac_queue *queue)
|
||||||
/* Release net buffer to the buffer pool */
|
/* Release net buffer to the buffer pool */
|
||||||
pkt = UINT_TO_POINTER(tx_frames->buf[tx_frames->tail]);
|
pkt = UINT_TO_POINTER(tx_frames->buf[tx_frames->tail]);
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
SYS_LOG_DBG("Dropping pkt %p", pkt);
|
LOG_DBG("Dropping pkt %p", pkt);
|
||||||
MODULO_INC(tx_frames->tail, tx_frames->len);
|
MODULO_INC(tx_frames->tail, tx_frames->len);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -644,7 +646,7 @@ static int get_mck_clock_divisor(u32_t mck)
|
||||||
} else if (mck <= 240000000) {
|
} else if (mck <= 240000000) {
|
||||||
mck_divisor = GMAC_NCFGR_CLK_MCK_96;
|
mck_divisor = GMAC_NCFGR_CLK_MCK_96;
|
||||||
} else {
|
} else {
|
||||||
SYS_LOG_ERR("No valid MDC clock");
|
LOG_ERR("No valid MDC clock");
|
||||||
mck_divisor = -ENOTSUP;
|
mck_divisor = -ENOTSUP;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -987,7 +989,7 @@ static int nonpriority_queue_init(Gmac *gmac, struct gmac_queue *queue)
|
||||||
queue->err_rx_flushed_count = 0;
|
queue->err_rx_flushed_count = 0;
|
||||||
queue->err_tx_flushed_count = 0;
|
queue->err_tx_flushed_count = 0;
|
||||||
|
|
||||||
SYS_LOG_INF("Queue %d activated", queue->que_idx);
|
LOG_INF("Queue %d activated", queue->que_idx);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1194,7 +1196,7 @@ static struct net_pkt *frame_get(struct gmac_queue *queue)
|
||||||
}
|
}
|
||||||
|
|
||||||
rx_desc_list->tail = tail;
|
rx_desc_list->tail = tail;
|
||||||
SYS_LOG_DBG("Frame complete: rx=%p, tail=%d", rx_frame, tail);
|
LOG_DBG("Frame complete: rx=%p, tail=%d", rx_frame, tail);
|
||||||
__ASSERT_NO_MSG(frame_is_complete);
|
__ASSERT_NO_MSG(frame_is_complete);
|
||||||
|
|
||||||
return rx_frame;
|
return rx_frame;
|
||||||
|
@ -1219,7 +1221,7 @@ static void eth_rx(struct gmac_queue *queue)
|
||||||
*/
|
*/
|
||||||
rx_frame = frame_get(queue);
|
rx_frame = frame_get(queue);
|
||||||
while (rx_frame) {
|
while (rx_frame) {
|
||||||
SYS_LOG_DBG("ETH rx");
|
LOG_DBG("ETH rx");
|
||||||
|
|
||||||
#if defined(CONFIG_NET_VLAN)
|
#if defined(CONFIG_NET_VLAN)
|
||||||
/* FIXME: Instead of this, use the GMAC register to get
|
/* FIXME: Instead of this, use the GMAC register to get
|
||||||
|
@ -1307,7 +1309,7 @@ static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
|
||||||
__ASSERT(pkt, "buf pointer is NULL");
|
__ASSERT(pkt, "buf pointer is NULL");
|
||||||
__ASSERT(pkt->frags, "Frame data missing");
|
__ASSERT(pkt->frags, "Frame data missing");
|
||||||
|
|
||||||
SYS_LOG_DBG("ETH tx");
|
LOG_DBG("ETH tx");
|
||||||
|
|
||||||
/* Decide which queue should be used */
|
/* Decide which queue should be used */
|
||||||
pkt_prio = net_pkt_priority(pkt);
|
pkt_prio = net_pkt_priority(pkt);
|
||||||
|
@ -1429,7 +1431,7 @@ static void queue0_isr(void *arg)
|
||||||
|
|
||||||
/* Interrupt Status Register is cleared on read */
|
/* Interrupt Status Register is cleared on read */
|
||||||
isr = gmac->GMAC_ISR;
|
isr = gmac->GMAC_ISR;
|
||||||
SYS_LOG_DBG("GMAC_ISR=0x%08x", isr);
|
LOG_DBG("GMAC_ISR=0x%08x", isr);
|
||||||
|
|
||||||
queue = &dev_data->queue_list[0];
|
queue = &dev_data->queue_list[0];
|
||||||
rx_desc_list = &queue->rx_desc_list;
|
rx_desc_list = &queue->rx_desc_list;
|
||||||
|
@ -1440,9 +1442,9 @@ static void queue0_isr(void *arg)
|
||||||
rx_error_handler(gmac, queue);
|
rx_error_handler(gmac, queue);
|
||||||
} else if (isr & GMAC_ISR_RCOMP) {
|
} else if (isr & GMAC_ISR_RCOMP) {
|
||||||
tail_desc = &rx_desc_list->buf[rx_desc_list->tail];
|
tail_desc = &rx_desc_list->buf[rx_desc_list->tail];
|
||||||
SYS_LOG_DBG("rx.w1=0x%08x, tail=%d",
|
LOG_DBG("rx.w1=0x%08x, tail=%d",
|
||||||
gmac_desc_get_w1(tail_desc),
|
gmac_desc_get_w1(tail_desc),
|
||||||
rx_desc_list->tail);
|
rx_desc_list->tail);
|
||||||
eth_rx(queue);
|
eth_rx(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1451,9 +1453,9 @@ static void queue0_isr(void *arg)
|
||||||
tx_error_handler(gmac, queue);
|
tx_error_handler(gmac, queue);
|
||||||
} else if (isr & GMAC_ISR_TCOMP) {
|
} else if (isr & GMAC_ISR_TCOMP) {
|
||||||
tail_desc = &tx_desc_list->buf[tx_desc_list->tail];
|
tail_desc = &tx_desc_list->buf[tx_desc_list->tail];
|
||||||
SYS_LOG_DBG("tx.w1=0x%08x, tail=%d",
|
LOG_DBG("tx.w1=0x%08x, tail=%d",
|
||||||
gmac_desc_get_w1(tail_desc),
|
gmac_desc_get_w1(tail_desc),
|
||||||
tx_desc_list->tail);
|
tx_desc_list->tail);
|
||||||
|
|
||||||
/* Check if it is not too late */
|
/* Check if it is not too late */
|
||||||
if (k_delayed_work_cancel(&queue->tx_timeout_work) == 0) {
|
if (k_delayed_work_cancel(&queue->tx_timeout_work) == 0) {
|
||||||
|
@ -1462,7 +1464,7 @@ static void queue0_isr(void *arg)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isr & GMAC_IER_HRESP) {
|
if (isr & GMAC_IER_HRESP) {
|
||||||
SYS_LOG_DBG("IER HRESP");
|
LOG_DBG("IER HRESP");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1480,7 +1482,7 @@ static inline void priority_queue_isr(void *arg, unsigned int queue_idx)
|
||||||
u32_t isrpq;
|
u32_t isrpq;
|
||||||
|
|
||||||
isrpq = gmac->GMAC_ISRPQ[queue_idx - 1];
|
isrpq = gmac->GMAC_ISRPQ[queue_idx - 1];
|
||||||
SYS_LOG_DBG("GMAC_ISRPQ%d=0x%08x", queue_idx - 1, isrpq);
|
LOG_DBG("GMAC_ISRPQ%d=0x%08x", queue_idx - 1, isrpq);
|
||||||
|
|
||||||
queue = &dev_data->queue_list[queue_idx];
|
queue = &dev_data->queue_list[queue_idx];
|
||||||
rx_desc_list = &queue->rx_desc_list;
|
rx_desc_list = &queue->rx_desc_list;
|
||||||
|
@ -1491,9 +1493,9 @@ static inline void priority_queue_isr(void *arg, unsigned int queue_idx)
|
||||||
rx_error_handler(gmac, queue);
|
rx_error_handler(gmac, queue);
|
||||||
} else if (isrpq & GMAC_ISRPQ_RCOMP) {
|
} else if (isrpq & GMAC_ISRPQ_RCOMP) {
|
||||||
tail_desc = &rx_desc_list->buf[rx_desc_list->tail];
|
tail_desc = &rx_desc_list->buf[rx_desc_list->tail];
|
||||||
SYS_LOG_DBG("rx.w1=0x%08x, tail=%d",
|
LOG_DBG("rx.w1=0x%08x, tail=%d",
|
||||||
gmac_desc_get_w1(tail_desc),
|
gmac_desc_get_w1(tail_desc),
|
||||||
rx_desc_list->tail);
|
rx_desc_list->tail);
|
||||||
eth_rx(queue);
|
eth_rx(queue);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1502,9 +1504,9 @@ static inline void priority_queue_isr(void *arg, unsigned int queue_idx)
|
||||||
tx_error_handler(gmac, queue);
|
tx_error_handler(gmac, queue);
|
||||||
} else if (isrpq & GMAC_ISRPQ_TCOMP) {
|
} else if (isrpq & GMAC_ISRPQ_TCOMP) {
|
||||||
tail_desc = &tx_desc_list->buf[tx_desc_list->tail];
|
tail_desc = &tx_desc_list->buf[tx_desc_list->tail];
|
||||||
SYS_LOG_DBG("tx.w1=0x%08x, tail=%d",
|
LOG_DBG("tx.w1=0x%08x, tail=%d",
|
||||||
gmac_desc_get_w1(tail_desc),
|
gmac_desc_get_w1(tail_desc),
|
||||||
tx_desc_list->tail);
|
tx_desc_list->tail);
|
||||||
|
|
||||||
/* Check if it is not too late */
|
/* Check if it is not too late */
|
||||||
if (k_delayed_work_cancel(&queue->tx_timeout_work) == 0) {
|
if (k_delayed_work_cancel(&queue->tx_timeout_work) == 0) {
|
||||||
|
@ -1513,7 +1515,7 @@ static inline void priority_queue_isr(void *arg, unsigned int queue_idx)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isrpq & GMAC_IERPQ_HRESP) {
|
if (isrpq & GMAC_IERPQ_HRESP) {
|
||||||
SYS_LOG_DBG("IERPQ%d HRESP", queue_idx - 1);
|
LOG_DBG("IERPQ%d HRESP", queue_idx - 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1555,7 +1557,7 @@ static void get_mac_addr_from_i2c_eeprom(u8_t mac_addr[6])
|
||||||
|
|
||||||
dev = device_get_binding(CONFIG_ETH_SAM_GMAC_MAC_I2C_DEV_NAME);
|
dev = device_get_binding(CONFIG_ETH_SAM_GMAC_MAC_I2C_DEV_NAME);
|
||||||
if (!dev) {
|
if (!dev) {
|
||||||
SYS_LOG_ERR("I2C: Device not found");
|
LOG_ERR("I2C: Device not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1626,15 +1628,16 @@ static void eth0_iface_init(struct net_if *iface)
|
||||||
| GMAC_NCFGR_RXCOEN; /* Receive Checksum Offload Enable */
|
| GMAC_NCFGR_RXCOEN; /* Receive Checksum Offload Enable */
|
||||||
result = gmac_init(cfg->regs, gmac_ncfgr_val);
|
result = gmac_init(cfg->regs, gmac_ncfgr_val);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
SYS_LOG_ERR("Unable to initialize ETH driver");
|
LOG_ERR("Unable to initialize ETH driver");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
generate_mac(dev_data->mac_addr);
|
generate_mac(dev_data->mac_addr);
|
||||||
SYS_LOG_INF("MAC: %x:%x:%x:%x:%x:%x",
|
|
||||||
dev_data->mac_addr[0], dev_data->mac_addr[1],
|
LOG_INF("MAC: %x:%x:%x:%x:%x:%x",
|
||||||
dev_data->mac_addr[2], dev_data->mac_addr[3],
|
dev_data->mac_addr[0], dev_data->mac_addr[1],
|
||||||
dev_data->mac_addr[4], dev_data->mac_addr[5]);
|
dev_data->mac_addr[2], dev_data->mac_addr[3],
|
||||||
|
dev_data->mac_addr[4], dev_data->mac_addr[5]);
|
||||||
|
|
||||||
/* Set MAC Address for frame filtering logic */
|
/* Set MAC Address for frame filtering logic */
|
||||||
mac_addr_set(cfg->regs, 0, dev_data->mac_addr);
|
mac_addr_set(cfg->regs, 0, dev_data->mac_addr);
|
||||||
|
@ -1648,7 +1651,7 @@ static void eth0_iface_init(struct net_if *iface)
|
||||||
for (i = 0; i < GMAC_QUEUE_NO; i++) {
|
for (i = 0; i < GMAC_QUEUE_NO; i++) {
|
||||||
result = queue_init(cfg->regs, &dev_data->queue_list[i]);
|
result = queue_init(cfg->regs, &dev_data->queue_list[i]);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
SYS_LOG_ERR("Unable to initialize ETH queue%d", i);
|
LOG_ERR("Unable to initialize ETH queue%d", i);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1691,13 +1694,13 @@ static void eth0_iface_init(struct net_if *iface)
|
||||||
/* PHY initialize */
|
/* PHY initialize */
|
||||||
result = phy_sam_gmac_init(&cfg->phy);
|
result = phy_sam_gmac_init(&cfg->phy);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
SYS_LOG_ERR("ETH PHY Initialization Error");
|
LOG_ERR("ETH PHY Initialization Error");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* PHY auto-negotiate link parameters */
|
/* PHY auto-negotiate link parameters */
|
||||||
result = phy_sam_gmac_auto_negotiate(&cfg->phy, &link_status);
|
result = phy_sam_gmac_auto_negotiate(&cfg->phy, &link_status);
|
||||||
if (result < 0) {
|
if (result < 0) {
|
||||||
SYS_LOG_ERR("ETH PHY auto-negotiate sequence failed");
|
LOG_ERR("ETH PHY auto-negotiate sequence failed");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,9 +3,11 @@
|
||||||
* SPDX-License-Identifier: Apache-2.0
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "dev/eth_stm32_hal"
|
#define LOG_MODULE_NAME eth_stm32_hal
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_ETHERNET_LEVEL
|
#define LOG_LEVEL CONFIG_ETHERNET_LOG_LEVEL
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
||||||
|
|
||||||
#include <kernel.h>
|
#include <kernel.h>
|
||||||
#include <device.h>
|
#include <device.h>
|
||||||
|
@ -79,7 +81,7 @@ static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
|
||||||
|
|
||||||
total_len = net_pkt_ll_reserve(pkt) + net_pkt_get_len(pkt);
|
total_len = net_pkt_ll_reserve(pkt) + net_pkt_get_len(pkt);
|
||||||
if (total_len > ETH_TX_BUF_SIZE) {
|
if (total_len > ETH_TX_BUF_SIZE) {
|
||||||
SYS_LOG_ERR("PKT to big\n");
|
LOG_ERR("PKT to big");
|
||||||
res = -EIO;
|
res = -EIO;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -103,7 +105,7 @@ static int eth_tx(struct net_if *iface, struct net_pkt *pkt)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HAL_ETH_TransmitFrame(heth, total_len) != HAL_OK) {
|
if (HAL_ETH_TransmitFrame(heth, total_len) != HAL_OK) {
|
||||||
SYS_LOG_ERR("HAL_ETH_TransmitFrame failed\n");
|
LOG_ERR("HAL_ETH_TransmitFrame failed");
|
||||||
res = -EIO;
|
res = -EIO;
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
@ -157,12 +159,12 @@ static struct net_pkt *eth_rx(struct device *dev)
|
||||||
|
|
||||||
pkt = net_pkt_get_reserve_rx(0, K_NO_WAIT);
|
pkt = net_pkt_get_reserve_rx(0, K_NO_WAIT);
|
||||||
if (!pkt) {
|
if (!pkt) {
|
||||||
SYS_LOG_ERR("Failed to obtain RX buffer");
|
LOG_ERR("Failed to obtain RX buffer");
|
||||||
goto release_desc;
|
goto release_desc;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!net_pkt_append_all(pkt, total_len, dma_buffer, K_NO_WAIT)) {
|
if (!net_pkt_append_all(pkt, total_len, dma_buffer, K_NO_WAIT)) {
|
||||||
SYS_LOG_ERR("Failed to append RX buffer to context buffer");
|
LOG_ERR("Failed to append RX buffer to context buffer");
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
pkt = NULL;
|
pkt = NULL;
|
||||||
goto release_desc;
|
goto release_desc;
|
||||||
|
@ -218,7 +220,7 @@ static void rx_thread(void *arg1, void *unused1, void *unused2)
|
||||||
net_pkt_print_frags(pkt);
|
net_pkt_print_frags(pkt);
|
||||||
res = net_recv_data(dev_data->iface, pkt);
|
res = net_recv_data(dev_data->iface, pkt);
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
SYS_LOG_ERR("Failed to enqueue frame "
|
LOG_ERR("Failed to enqueue frame "
|
||||||
"into RX queue: %d", res);
|
"into RX queue: %d", res);
|
||||||
net_pkt_unref(pkt);
|
net_pkt_unref(pkt);
|
||||||
}
|
}
|
||||||
|
@ -337,9 +339,9 @@ static void eth_iface_init(struct net_if *iface)
|
||||||
/* HAL Init time out. This could be linked to */
|
/* HAL Init time out. This could be linked to */
|
||||||
/* a recoverable error. Log the issue and continue */
|
/* a recoverable error. Log the issue and continue */
|
||||||
/* dirver initialisation */
|
/* dirver initialisation */
|
||||||
SYS_LOG_ERR("HAL_ETH_Init Timed out\n");
|
LOG_ERR("HAL_ETH_Init Timed out");
|
||||||
} else if (hal_ret != HAL_OK) {
|
} else if (hal_ret != HAL_OK) {
|
||||||
SYS_LOG_ERR("HAL_ETH_Init failed: %d\n", hal_ret);
|
LOG_ERR("HAL_ETH_Init failed: %d", hal_ret);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -363,10 +365,10 @@ static void eth_iface_init(struct net_if *iface)
|
||||||
|
|
||||||
disable_mcast_filter(heth);
|
disable_mcast_filter(heth);
|
||||||
|
|
||||||
SYS_LOG_DBG("MAC %02x:%02x:%02x:%02x:%02x:%02x",
|
LOG_DBG("MAC %02x:%02x:%02x:%02x:%02x:%02x",
|
||||||
dev_data->mac_addr[0], dev_data->mac_addr[1],
|
dev_data->mac_addr[0], dev_data->mac_addr[1],
|
||||||
dev_data->mac_addr[2], dev_data->mac_addr[3],
|
dev_data->mac_addr[2], dev_data->mac_addr[3],
|
||||||
dev_data->mac_addr[4], dev_data->mac_addr[5]);
|
dev_data->mac_addr[4], dev_data->mac_addr[5]);
|
||||||
|
|
||||||
/* Register Ethernet MAC Address with the upper layer */
|
/* Register Ethernet MAC Address with the upper layer */
|
||||||
net_if_set_link_addr(iface, dev_data->mac_addr,
|
net_if_set_link_addr(iface, dev_data->mac_addr,
|
||||||
|
|
|
@ -12,9 +12,11 @@
|
||||||
#include <net/mii.h>
|
#include <net/mii.h>
|
||||||
#include "phy_sam_gmac.h"
|
#include "phy_sam_gmac.h"
|
||||||
|
|
||||||
#define SYS_LOG_DOMAIN "soc/soc_phy"
|
#define LOG_MODULE_NAME eth_sam_phy
|
||||||
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_ETHERNET_LEVEL
|
#define LOG_LEVEL CONFIG_ETHERNET_LOG_LEVEL
|
||||||
#include <logging/sys_log.h>
|
|
||||||
|
#include <logging/log.h>
|
||||||
|
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
||||||
|
|
||||||
/* Maximum time to establish a link through auto-negotiation for
|
/* Maximum time to establish a link through auto-negotiation for
|
||||||
* 10BASE-T, 100BASE-TX is 3.7s, to add an extra margin the timeout
|
* 10BASE-T, 100BASE-TX is 3.7s, to add an extra margin the timeout
|
||||||
|
@ -41,7 +43,7 @@ static int mdio_bus_wait(Gmac *gmac)
|
||||||
|
|
||||||
while (!(gmac->GMAC_NSR & GMAC_NSR_IDLE)) {
|
while (!(gmac->GMAC_NSR & GMAC_NSR_IDLE)) {
|
||||||
if (retries-- == 0) {
|
if (retries-- == 0) {
|
||||||
SYS_LOG_ERR("timeout");
|
LOG_ERR("timeout");
|
||||||
return -ETIMEDOUT;
|
return -ETIMEDOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,17 +145,17 @@ int phy_sam_gmac_init(const struct phy_sam_gmac_dev *phy)
|
||||||
|
|
||||||
mdio_bus_enable(gmac);
|
mdio_bus_enable(gmac);
|
||||||
|
|
||||||
SYS_LOG_INF("Soft Reset of ETH PHY");
|
LOG_INF("Soft Reset of ETH PHY");
|
||||||
phy_soft_reset(phy);
|
phy_soft_reset(phy);
|
||||||
|
|
||||||
/* Verify that the PHY device is responding */
|
/* Verify that the PHY device is responding */
|
||||||
phy_id = phy_sam_gmac_id_get(phy);
|
phy_id = phy_sam_gmac_id_get(phy);
|
||||||
if (phy_id == 0xFFFFFFFF) {
|
if (phy_id == 0xFFFFFFFF) {
|
||||||
SYS_LOG_ERR("Unable to detect a valid PHY");
|
LOG_ERR("Unable to detect a valid PHY");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_INF("PHYID: 0x%X at addr: %d", phy_id, phy->address);
|
LOG_INF("PHYID: 0x%X at addr: %d", phy_id, phy->address);
|
||||||
|
|
||||||
mdio_bus_disable(gmac);
|
mdio_bus_disable(gmac);
|
||||||
|
|
||||||
|
@ -197,7 +199,7 @@ int phy_sam_gmac_auto_negotiate(const struct phy_sam_gmac_dev *phy,
|
||||||
|
|
||||||
mdio_bus_enable(gmac);
|
mdio_bus_enable(gmac);
|
||||||
|
|
||||||
SYS_LOG_DBG("Starting ETH PHY auto-negotiate sequence");
|
LOG_DBG("Starting ETH PHY auto-negotiate sequence");
|
||||||
|
|
||||||
/* Read PHY default advertising parameters */
|
/* Read PHY default advertising parameters */
|
||||||
retval = phy_read(phy, MII_ANAR, &ability_adv);
|
retval = phy_read(phy, MII_ANAR, &ability_adv);
|
||||||
|
@ -234,7 +236,7 @@ int phy_sam_gmac_auto_negotiate(const struct phy_sam_gmac_dev *phy,
|
||||||
}
|
}
|
||||||
} while (!(val & MII_BMSR_AUTONEG_COMPLETE));
|
} while (!(val & MII_BMSR_AUTONEG_COMPLETE));
|
||||||
|
|
||||||
SYS_LOG_DBG("PHY auto-negotiate sequence completed");
|
LOG_DBG("PHY auto-negotiate sequence completed");
|
||||||
|
|
||||||
/* Read abilities of the remote device */
|
/* Read abilities of the remote device */
|
||||||
retval = phy_read(phy, MII_ANLPAR, &ability_rcvd);
|
retval = phy_read(phy, MII_ANLPAR, &ability_rcvd);
|
||||||
|
@ -253,9 +255,9 @@ int phy_sam_gmac_auto_negotiate(const struct phy_sam_gmac_dev *phy,
|
||||||
*status = PHY_DUPLEX_HALF | PHY_SPEED_10M;
|
*status = PHY_DUPLEX_HALF | PHY_SPEED_10M;
|
||||||
}
|
}
|
||||||
|
|
||||||
SYS_LOG_INF("common abilities: speed %s Mb, %s duplex",
|
LOG_INF("common abilities: speed %s Mb, %s duplex",
|
||||||
*status & PHY_SPEED_100M ? "100" : "10",
|
*status & PHY_SPEED_100M ? "100" : "10",
|
||||||
*status & PHY_DUPLEX_FULL ? "full" : "half");
|
*status & PHY_DUPLEX_FULL ? "full" : "half");
|
||||||
|
|
||||||
auto_negotiate_exit:
|
auto_negotiate_exit:
|
||||||
mdio_bus_disable(gmac);
|
mdio_bus_disable(gmac);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue