2016-12-24 03:58:38 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Piotr Mienkowski
|
2018-04-18 16:13:05 +02:00
|
|
|
* Copyringt (c) 2018 Antmicro Ltd
|
|
|
|
*
|
2016-12-24 03:58:38 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
/** @file
|
|
|
|
* @brief Atmel SAM MCU family Ethernet MAC (GMAC) driver.
|
|
|
|
*
|
2017-04-05 11:14:50 +02:00
|
|
|
* This is a zero-copy networking implementation of an Ethernet driver. To
|
|
|
|
* prepare for the incoming frames the driver will permanently reserve a defined
|
|
|
|
* amount of RX data net buffers when the interface is brought up and thus
|
|
|
|
* reduce the total amount of RX data net buffers available to the application.
|
2016-12-24 03:58:38 +01:00
|
|
|
*
|
|
|
|
* Limitations:
|
|
|
|
* - one shot PHY setup, no support for PHY disconnect/reconnect
|
|
|
|
* - no statistics collection
|
|
|
|
*/
|
|
|
|
|
2020-03-29 03:20:08 +09:00
|
|
|
#define DT_DRV_COMPAT atmel_sam_gmac
|
|
|
|
|
2018-07-09 12:51:28 +03:00
|
|
|
#define LOG_MODULE_NAME eth_sam
|
|
|
|
#define LOG_LEVEL CONFIG_ETHERNET_LOG_LEVEL
|
|
|
|
|
|
|
|
#include <logging/log.h>
|
|
|
|
LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
#include <kernel.h>
|
|
|
|
#include <device.h>
|
2019-06-26 10:33:39 -04:00
|
|
|
#include <sys/__assert.h>
|
2019-06-26 10:33:55 -04:00
|
|
|
#include <sys/util.h>
|
2016-12-24 03:58:38 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stdbool.h>
|
2017-04-03 17:14:35 +02:00
|
|
|
#include <net/net_pkt.h>
|
2016-12-24 03:58:38 +01:00
|
|
|
#include <net/net_if.h>
|
2018-03-14 10:55:19 +02:00
|
|
|
#include <net/ethernet.h>
|
2018-12-05 14:52:59 +01:00
|
|
|
#include <ethernet/eth_stats.h>
|
2019-06-25 15:53:54 -04:00
|
|
|
#include <drivers/i2c.h>
|
2016-12-24 03:58:38 +01:00
|
|
|
#include <soc.h>
|
|
|
|
#include "phy_sam_gmac.h"
|
|
|
|
#include "eth_sam_gmac_priv.h"
|
|
|
|
|
2020-04-23 12:28:00 -05:00
|
|
|
#include "eth.h"
|
|
|
|
|
2020-03-06 02:08:44 +09:00
|
|
|
#ifdef CONFIG_SOC_FAMILY_SAM0
|
|
|
|
#include "eth_sam0_gmac.h"
|
|
|
|
#endif
|
|
|
|
|
2018-04-18 16:13:05 +02:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
2021-03-24 08:53:53 -05:00
|
|
|
#include <drivers/ptp_clock.h>
|
2018-04-18 16:13:05 +02:00
|
|
|
#include <net/gptp.h>
|
|
|
|
#endif
|
|
|
|
|
2020-02-19 23:49:01 -03:00
|
|
|
#ifdef __DCACHE_PRESENT
|
|
|
|
static bool dcache_enabled;
|
|
|
|
|
|
|
|
static inline void dcache_is_enabled(void)
|
|
|
|
{
|
|
|
|
dcache_enabled = (SCB->CCR & SCB_CCR_DC_Msk);
|
|
|
|
}
|
2020-05-27 11:26:57 -05:00
|
|
|
static inline void dcache_invalidate(uint32_t addr, uint32_t size)
|
2020-02-19 23:49:01 -03:00
|
|
|
{
|
|
|
|
if (!dcache_enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure it is aligned to 32B */
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t start_addr = addr & (uint32_t)~(GMAC_DCACHE_ALIGNMENT - 1);
|
|
|
|
uint32_t size_full = size + addr - start_addr;
|
2020-02-19 23:49:01 -03:00
|
|
|
|
|
|
|
SCB_InvalidateDCache_by_Addr((uint32_t *)start_addr, size_full);
|
|
|
|
}
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
static inline void dcache_clean(uint32_t addr, uint32_t size)
|
2020-02-19 23:49:01 -03:00
|
|
|
{
|
|
|
|
if (!dcache_enabled) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure it is aligned to 32B */
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t start_addr = addr & (uint32_t)~(GMAC_DCACHE_ALIGNMENT - 1);
|
|
|
|
uint32_t size_full = size + addr - start_addr;
|
2020-02-19 23:49:01 -03:00
|
|
|
|
|
|
|
SCB_CleanDCache_by_Addr((uint32_t *)start_addr, size_full);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define dcache_is_enabled()
|
|
|
|
#define dcache_invalidate(addr, size)
|
|
|
|
#define dcache_clean(addr, size)
|
|
|
|
#endif
|
|
|
|
|
2020-03-06 02:08:44 +09:00
|
|
|
#ifdef CONFIG_SOC_FAMILY_SAM0
|
|
|
|
#define MCK_FREQ_HZ SOC_ATMEL_SAM0_MCK_FREQ_HZ
|
|
|
|
#elif CONFIG_SOC_FAMILY_SAM
|
|
|
|
#define MCK_FREQ_HZ SOC_ATMEL_SAM_MCK_FREQ_HZ
|
|
|
|
#else
|
|
|
|
#error Unsupported SoC family
|
|
|
|
#endif
|
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
/*
|
|
|
|
* Verify Kconfig configuration
|
|
|
|
*/
|
2018-03-19 11:34:00 +02:00
|
|
|
/* No need to verify things for unit tests */
|
|
|
|
#if !defined(CONFIG_NET_TEST)
|
2017-04-03 17:14:35 +02:00
|
|
|
#if CONFIG_NET_BUF_DATA_SIZE * CONFIG_ETH_SAM_GMAC_BUF_RX_COUNT \
|
2017-03-15 01:30:35 +01:00
|
|
|
< GMAC_FRAME_SIZE_MAX
|
2017-04-03 17:14:35 +02:00
|
|
|
#error CONFIG_NET_BUF_DATA_SIZE * CONFIG_ETH_SAM_GMAC_BUF_RX_COUNT is \
|
2017-03-15 01:30:35 +01:00
|
|
|
not large enough to hold a full frame
|
2016-12-24 03:58:38 +01:00
|
|
|
#endif
|
|
|
|
|
2017-04-03 17:14:35 +02:00
|
|
|
#if CONFIG_NET_BUF_DATA_SIZE * (CONFIG_NET_BUF_RX_COUNT - \
|
|
|
|
CONFIG_ETH_SAM_GMAC_BUF_RX_COUNT) < GMAC_FRAME_SIZE_MAX
|
2019-04-03 11:22:39 +03:00
|
|
|
#error (CONFIG_NET_BUF_RX_COUNT - CONFIG_ETH_SAM_GMAC_BUF_RX_COUNT) * \
|
|
|
|
CONFIG_NET_BUF_DATA_SIZE are not large enough to hold a full frame
|
2016-12-24 03:58:38 +01:00
|
|
|
#endif
|
|
|
|
|
2017-04-03 17:14:35 +02:00
|
|
|
#if CONFIG_NET_BUF_DATA_SIZE & 0x3F
|
|
|
|
#pragma message "CONFIG_NET_BUF_DATA_SIZE should be a multiple of 64 bytes " \
|
2016-12-24 03:58:38 +01:00
|
|
|
"due to the granularity of RX DMA"
|
|
|
|
#endif
|
|
|
|
|
2020-02-19 18:56:37 -03:00
|
|
|
#if (CONFIG_ETH_SAM_GMAC_BUF_RX_COUNT + 1) * GMAC_ACTIVE_QUEUE_NUM \
|
2018-06-19 10:01:16 +02:00
|
|
|
> CONFIG_NET_BUF_RX_COUNT
|
|
|
|
#error Not enough RX buffers to allocate descriptors for each HW queue
|
|
|
|
#endif
|
2018-08-02 09:01:46 +02:00
|
|
|
#endif /* !CONFIG_NET_TEST */
|
2018-06-19 10:01:16 +02:00
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
/* RX descriptors list */
|
|
|
|
static struct gmac_desc rx_desc_que0[MAIN_QUEUE_RX_DESC_COUNT]
|
2018-12-08 01:49:12 +01:00
|
|
|
__nocache __aligned(GMAC_DESC_ALIGNMENT);
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_PRIORITY_QUEUE_NUM >= 1
|
2018-06-19 10:01:16 +02:00
|
|
|
static struct gmac_desc rx_desc_que1[PRIORITY_QUEUE1_RX_DESC_COUNT]
|
2018-12-08 01:49:12 +01:00
|
|
|
__nocache __aligned(GMAC_DESC_ALIGNMENT);
|
2020-02-19 18:56:37 -03:00
|
|
|
#endif
|
|
|
|
#if GMAC_PRIORITY_QUEUE_NUM >= 2
|
2018-06-19 10:01:16 +02:00
|
|
|
static struct gmac_desc rx_desc_que2[PRIORITY_QUEUE2_RX_DESC_COUNT]
|
2018-12-08 01:49:12 +01:00
|
|
|
__nocache __aligned(GMAC_DESC_ALIGNMENT);
|
2020-02-19 18:56:37 -03:00
|
|
|
#endif
|
|
|
|
#if GMAC_PRIORITY_QUEUE_NUM >= 3
|
2019-01-11 18:50:42 +01:00
|
|
|
static struct gmac_desc rx_desc_que3[PRIORITY_QUEUE3_RX_DESC_COUNT]
|
|
|
|
__nocache __aligned(GMAC_DESC_ALIGNMENT);
|
2020-02-19 18:56:37 -03:00
|
|
|
#endif
|
|
|
|
#if GMAC_PRIORITY_QUEUE_NUM >= 4
|
2019-01-11 18:50:42 +01:00
|
|
|
static struct gmac_desc rx_desc_que4[PRIORITY_QUEUE4_RX_DESC_COUNT]
|
|
|
|
__nocache __aligned(GMAC_DESC_ALIGNMENT);
|
2020-02-19 18:56:37 -03:00
|
|
|
#endif
|
|
|
|
#if GMAC_PRIORITY_QUEUE_NUM >= 5
|
2019-01-11 18:50:42 +01:00
|
|
|
static struct gmac_desc rx_desc_que5[PRIORITY_QUEUE5_RX_DESC_COUNT]
|
|
|
|
__nocache __aligned(GMAC_DESC_ALIGNMENT);
|
|
|
|
#endif
|
2020-02-19 18:56:37 -03:00
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
/* TX descriptors list */
|
|
|
|
static struct gmac_desc tx_desc_que0[MAIN_QUEUE_TX_DESC_COUNT]
|
2018-12-08 01:49:12 +01:00
|
|
|
__nocache __aligned(GMAC_DESC_ALIGNMENT);
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_PRIORITY_QUEUE_NUM >= 1
|
2018-06-19 10:01:16 +02:00
|
|
|
static struct gmac_desc tx_desc_que1[PRIORITY_QUEUE1_TX_DESC_COUNT]
|
2018-12-08 01:49:12 +01:00
|
|
|
__nocache __aligned(GMAC_DESC_ALIGNMENT);
|
2020-02-19 18:56:37 -03:00
|
|
|
#endif
|
|
|
|
#if GMAC_PRIORITY_QUEUE_NUM >= 2
|
2018-06-19 10:01:16 +02:00
|
|
|
static struct gmac_desc tx_desc_que2[PRIORITY_QUEUE2_TX_DESC_COUNT]
|
2018-12-08 01:49:12 +01:00
|
|
|
__nocache __aligned(GMAC_DESC_ALIGNMENT);
|
2020-02-19 18:56:37 -03:00
|
|
|
#endif
|
|
|
|
#if GMAC_PRIORITY_QUEUE_NUM >= 3
|
2019-01-11 18:50:42 +01:00
|
|
|
static struct gmac_desc tx_desc_que3[PRIORITY_QUEUE3_TX_DESC_COUNT]
|
|
|
|
__nocache __aligned(GMAC_DESC_ALIGNMENT);
|
2020-02-19 18:56:37 -03:00
|
|
|
#endif
|
|
|
|
#if GMAC_PRIORITY_QUEUE_NUM >= 4
|
2019-01-11 18:50:42 +01:00
|
|
|
static struct gmac_desc tx_desc_que4[PRIORITY_QUEUE4_TX_DESC_COUNT]
|
|
|
|
__nocache __aligned(GMAC_DESC_ALIGNMENT);
|
2020-02-19 18:56:37 -03:00
|
|
|
#endif
|
|
|
|
#if GMAC_PRIORITY_QUEUE_NUM >= 5
|
2019-01-11 18:50:42 +01:00
|
|
|
static struct gmac_desc tx_desc_que5[PRIORITY_QUEUE5_TX_DESC_COUNT]
|
|
|
|
__nocache __aligned(GMAC_DESC_ALIGNMENT);
|
|
|
|
#endif
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
/* RX buffer accounting list */
|
2017-04-21 16:47:10 +02:00
|
|
|
static struct net_buf *rx_frag_list_que0[MAIN_QUEUE_RX_DESC_COUNT];
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 1
|
2018-06-19 10:01:16 +02:00
|
|
|
static struct net_buf *rx_frag_list_que1[PRIORITY_QUEUE1_RX_DESC_COUNT];
|
|
|
|
#endif
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 2
|
2018-06-19 10:01:16 +02:00
|
|
|
static struct net_buf *rx_frag_list_que2[PRIORITY_QUEUE2_RX_DESC_COUNT];
|
|
|
|
#endif
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 3
|
|
|
|
static struct net_buf *rx_frag_list_que3[PRIORITY_QUEUE3_RX_DESC_COUNT];
|
|
|
|
#endif
|
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 4
|
|
|
|
static struct net_buf *rx_frag_list_que4[PRIORITY_QUEUE4_RX_DESC_COUNT];
|
|
|
|
#endif
|
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 5
|
|
|
|
static struct net_buf *rx_frag_list_que5[PRIORITY_QUEUE5_RX_DESC_COUNT];
|
|
|
|
#endif
|
|
|
|
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
2019-02-06 21:33:19 +01:00
|
|
|
/* TX buffer accounting list */
|
|
|
|
static struct net_buf *tx_frag_list_que0[MAIN_QUEUE_TX_DESC_COUNT];
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 1
|
2019-02-06 21:33:19 +01:00
|
|
|
static struct net_buf *tx_frag_list_que1[PRIORITY_QUEUE1_TX_DESC_COUNT];
|
|
|
|
#endif
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 2
|
2019-02-06 21:33:19 +01:00
|
|
|
static struct net_buf *tx_frag_list_que2[PRIORITY_QUEUE2_TX_DESC_COUNT];
|
|
|
|
#endif
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 3
|
|
|
|
static struct net_buf *tx_frag_list_que3[PRIORITY_QUEUE3_TX_DESC_COUNT];
|
|
|
|
#endif
|
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 4
|
|
|
|
static struct net_buf *tx_frag_list_que4[PRIORITY_QUEUE4_TX_DESC_COUNT];
|
|
|
|
#endif
|
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 5
|
|
|
|
static struct net_buf *tx_frag_list_que5[PRIORITY_QUEUE5_TX_DESC_COUNT];
|
|
|
|
#endif
|
|
|
|
|
2019-02-06 21:44:47 +01:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
2016-12-24 03:58:38 +01:00
|
|
|
/* TX frames accounting list */
|
2017-04-05 08:37:44 +02:00
|
|
|
static struct net_pkt *tx_frame_list_que0[CONFIG_NET_PKT_TX_COUNT + 1];
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 1
|
2018-06-19 10:01:16 +02:00
|
|
|
static struct net_pkt *tx_frame_list_que1[CONFIG_NET_PKT_TX_COUNT + 1];
|
|
|
|
#endif
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 2
|
2018-06-19 10:01:16 +02:00
|
|
|
static struct net_pkt *tx_frame_list_que2[CONFIG_NET_PKT_TX_COUNT + 1];
|
|
|
|
#endif
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 3
|
|
|
|
static struct net_pkt *tx_frame_list_que3[CONFIG_NET_PKT_TX_COUNT + 1];
|
|
|
|
#endif
|
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 4
|
|
|
|
static struct net_pkt *tx_frame_list_que4[CONFIG_NET_PKT_TX_COUNT + 1];
|
|
|
|
#endif
|
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 5
|
|
|
|
static struct net_pkt *tx_frame_list_que5[CONFIG_NET_PKT_TX_COUNT + 1];
|
|
|
|
#endif
|
2019-02-06 21:44:47 +01:00
|
|
|
#endif
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
#define MODULO_INC(val, max) {val = (++val < max) ? val : 0; }
|
|
|
|
|
2020-02-25 23:47:46 -03:00
|
|
|
static int rx_descriptors_init(Gmac *gmac, struct gmac_queue *queue);
|
|
|
|
static void tx_descriptors_init(Gmac *gmac, struct gmac_queue *queue);
|
|
|
|
static int nonpriority_queue_init(Gmac *gmac, struct gmac_queue *queue);
|
|
|
|
|
|
|
|
#if GMAC_PRIORITY_QUEUE_NUM >= 1
|
|
|
|
static inline void set_receive_buf_queue_pointer(
|
|
|
|
Gmac *gmac,
|
|
|
|
struct gmac_queue *queue)
|
|
|
|
{
|
|
|
|
/* Set Receive Buffer Queue Pointer Register */
|
|
|
|
if (queue->que_idx == GMAC_QUE_0) {
|
2020-05-27 11:26:57 -05:00
|
|
|
gmac->GMAC_RBQB = (uint32_t)queue->rx_desc_list.buf;
|
2020-02-25 23:47:46 -03:00
|
|
|
} else {
|
|
|
|
gmac->GMAC_RBQBAPQ[queue->que_idx - 1] =
|
2020-05-27 11:26:57 -05:00
|
|
|
(uint32_t)queue->rx_desc_list.buf;
|
2020-02-25 23:47:46 -03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void disable_all_priority_queue_interrupt(Gmac *gmac)
|
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t idx;
|
2020-02-25 23:47:46 -03:00
|
|
|
|
|
|
|
for (idx = 0; idx < GMAC_PRIORITY_QUEUE_NUM; idx++) {
|
|
|
|
gmac->GMAC_IDRPQ[idx] = UINT32_MAX;
|
|
|
|
(void)gmac->GMAC_ISRPQ[idx];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-25 22:30:55 -03:00
|
|
|
static int priority_queue_init(Gmac *gmac, struct gmac_queue *queue)
|
|
|
|
{
|
|
|
|
int result;
|
|
|
|
int queue_index;
|
|
|
|
|
|
|
|
__ASSERT_NO_MSG(queue->rx_desc_list.len > 0);
|
|
|
|
__ASSERT_NO_MSG(queue->tx_desc_list.len > 0);
|
2020-05-27 11:26:57 -05:00
|
|
|
__ASSERT(!((uint32_t)queue->rx_desc_list.buf & ~GMAC_RBQB_ADDR_Msk),
|
2020-02-25 22:30:55 -03:00
|
|
|
"RX descriptors have to be word aligned");
|
2020-05-27 11:26:57 -05:00
|
|
|
__ASSERT(!((uint32_t)queue->tx_desc_list.buf & ~GMAC_TBQB_ADDR_Msk),
|
2020-02-25 22:30:55 -03:00
|
|
|
"TX descriptors have to be word aligned");
|
|
|
|
|
|
|
|
/* Extract queue index for easier referencing */
|
|
|
|
queue_index = queue->que_idx - 1;
|
|
|
|
|
|
|
|
/* Setup descriptor lists */
|
|
|
|
result = rx_descriptors_init(gmac, queue);
|
|
|
|
if (result < 0) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_descriptors_init(gmac, queue);
|
|
|
|
|
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 0
|
|
|
|
k_sem_init(&queue->tx_sem, 0, 1);
|
|
|
|
#else
|
|
|
|
k_sem_init(&queue->tx_desc_sem, queue->tx_desc_list.len - 1,
|
|
|
|
queue->tx_desc_list.len - 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Setup RX buffer size for DMA */
|
|
|
|
gmac->GMAC_RBSRPQ[queue_index] =
|
|
|
|
GMAC_RBSRPQ_RBS(CONFIG_NET_BUF_DATA_SIZE >> 6);
|
|
|
|
|
|
|
|
/* Set Receive Buffer Queue Pointer Register */
|
2020-05-27 11:26:57 -05:00
|
|
|
gmac->GMAC_RBQBAPQ[queue_index] = (uint32_t)queue->rx_desc_list.buf;
|
2020-02-25 22:30:55 -03:00
|
|
|
/* Set Transmit Buffer Queue Pointer Register */
|
2020-05-27 11:26:57 -05:00
|
|
|
gmac->GMAC_TBQBAPQ[queue_index] = (uint32_t)queue->tx_desc_list.buf;
|
2020-02-25 22:30:55 -03:00
|
|
|
|
|
|
|
/* Enable RX/TX completion and error interrupts */
|
|
|
|
gmac->GMAC_IERPQ[queue_index] = GMAC_INTPQ_EN_FLAGS;
|
|
|
|
|
|
|
|
queue->err_rx_frames_dropped = 0U;
|
|
|
|
queue->err_rx_flushed_count = 0U;
|
|
|
|
queue->err_tx_flushed_count = 0U;
|
|
|
|
|
|
|
|
LOG_INF("Queue %d activated", queue->que_idx);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int priority_queue_init_as_idle(Gmac *gmac, struct gmac_queue *queue)
|
|
|
|
{
|
|
|
|
struct gmac_desc_list *rx_desc_list = &queue->rx_desc_list;
|
|
|
|
struct gmac_desc_list *tx_desc_list = &queue->tx_desc_list;
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
__ASSERT(!((uint32_t)rx_desc_list->buf & ~GMAC_RBQB_ADDR_Msk),
|
2020-02-25 22:30:55 -03:00
|
|
|
"RX descriptors have to be word aligned");
|
2020-05-27 11:26:57 -05:00
|
|
|
__ASSERT(!((uint32_t)tx_desc_list->buf & ~GMAC_TBQB_ADDR_Msk),
|
2020-02-25 22:30:55 -03:00
|
|
|
"TX descriptors have to be word aligned");
|
|
|
|
__ASSERT((rx_desc_list->len == 1U) && (tx_desc_list->len == 1U),
|
|
|
|
"Priority queues are currently not supported, descriptor "
|
|
|
|
"list has to have a single entry");
|
|
|
|
|
|
|
|
/* Setup RX descriptor lists */
|
|
|
|
/* Take ownership from GMAC and set the wrap bit */
|
|
|
|
rx_desc_list->buf[0].w0 = GMAC_RXW0_WRAP;
|
|
|
|
rx_desc_list->buf[0].w1 = 0U;
|
|
|
|
/* Setup TX descriptor lists */
|
|
|
|
tx_desc_list->buf[0].w0 = 0U;
|
|
|
|
/* Take ownership from GMAC and set the wrap bit */
|
|
|
|
tx_desc_list->buf[0].w1 = GMAC_TXW1_USED | GMAC_TXW1_WRAP;
|
|
|
|
|
|
|
|
/* Set Receive Buffer Queue Pointer Register */
|
2020-05-27 11:26:57 -05:00
|
|
|
gmac->GMAC_RBQBAPQ[queue->que_idx - 1] = (uint32_t)rx_desc_list->buf;
|
2020-02-25 22:30:55 -03:00
|
|
|
/* Set Transmit Buffer Queue Pointer Register */
|
2020-05-27 11:26:57 -05:00
|
|
|
gmac->GMAC_TBQBAPQ[queue->que_idx - 1] = (uint32_t)tx_desc_list->buf;
|
2020-02-25 22:30:55 -03:00
|
|
|
|
|
|
|
LOG_INF("Queue %d set to idle", queue->que_idx);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int queue_init(Gmac *gmac, struct gmac_queue *queue)
|
|
|
|
{
|
|
|
|
if (queue->que_idx == GMAC_QUE_0) {
|
|
|
|
return nonpriority_queue_init(gmac, queue);
|
|
|
|
} else if (queue->que_idx <= GMAC_ACTIVE_PRIORITY_QUEUE_NUM) {
|
|
|
|
return priority_queue_init(gmac, queue);
|
|
|
|
} else {
|
|
|
|
return priority_queue_init_as_idle(gmac, queue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-25 23:47:46 -03:00
|
|
|
#else
|
|
|
|
|
|
|
|
static inline void set_receive_buf_queue_pointer(
|
|
|
|
Gmac *gmac,
|
|
|
|
struct gmac_queue *queue)
|
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
gmac->GMAC_RBQB = (uint32_t)queue->rx_desc_list.buf;
|
2020-02-25 23:47:46 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
static int queue_init(Gmac *gmac, struct gmac_queue *queue)
|
|
|
|
{
|
|
|
|
return nonpriority_queue_init(gmac, queue);
|
|
|
|
}
|
|
|
|
|
2020-03-10 23:42:55 -03:00
|
|
|
#define disable_all_priority_queue_interrupt(gmac)
|
2020-02-25 23:47:46 -03:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 1
|
|
|
|
static int eth_sam_gmac_setup_qav(Gmac *gmac, int queue_id, bool enable);
|
|
|
|
|
|
|
|
static inline void eth_sam_gmac_init_qav(Gmac *gmac)
|
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t idx;
|
2020-02-25 23:47:46 -03:00
|
|
|
|
|
|
|
for (idx = GMAC_QUE_1; idx <= GMAC_ACTIVE_PRIORITY_QUEUE_NUM; idx++) {
|
|
|
|
eth_sam_gmac_setup_qav(gmac, idx, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
#define eth_sam_gmac_init_qav(gmac)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
2016-12-24 03:58:38 +01:00
|
|
|
/*
|
|
|
|
* Reset ring buffer
|
|
|
|
*/
|
|
|
|
static void ring_buf_reset(struct ring_buf *rb)
|
|
|
|
{
|
2018-11-29 11:12:22 -08:00
|
|
|
rb->head = 0U;
|
|
|
|
rb->tail = 0U;
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get one 32 bit item from the ring buffer
|
|
|
|
*/
|
2020-05-27 11:26:57 -05:00
|
|
|
static uint32_t ring_buf_get(struct ring_buf *rb)
|
2016-12-24 03:58:38 +01:00
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t val;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
__ASSERT(rb->tail != rb->head,
|
|
|
|
"retrieving data from empty ring buffer");
|
|
|
|
|
|
|
|
val = rb->buf[rb->tail];
|
|
|
|
MODULO_INC(rb->tail, rb->len);
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Put one 32 bit item into the ring buffer
|
|
|
|
*/
|
2020-05-27 11:26:57 -05:00
|
|
|
static void ring_buf_put(struct ring_buf *rb, uint32_t val)
|
2016-12-24 03:58:38 +01:00
|
|
|
{
|
|
|
|
rb->buf[rb->head] = val;
|
|
|
|
MODULO_INC(rb->head, rb->len);
|
|
|
|
|
|
|
|
__ASSERT(rb->tail != rb->head,
|
|
|
|
"ring buffer overflow");
|
|
|
|
}
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Free pre-reserved RX buffers
|
|
|
|
*/
|
2020-05-27 11:26:57 -05:00
|
|
|
static void free_rx_bufs(struct net_buf **rx_frag_list, uint16_t len)
|
2016-12-24 03:58:38 +01:00
|
|
|
{
|
2019-02-08 01:06:01 +01:00
|
|
|
for (int i = 0; i < len; i++) {
|
|
|
|
if (rx_frag_list[i]) {
|
|
|
|
net_buf_unref(rx_frag_list[i]);
|
|
|
|
rx_frag_list[i] = NULL;
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set MAC Address for frame filtering logic
|
|
|
|
*/
|
2020-05-27 11:26:57 -05:00
|
|
|
static void mac_addr_set(Gmac *gmac, uint8_t index,
|
|
|
|
uint8_t mac_addr[6])
|
2016-12-24 03:58:38 +01:00
|
|
|
{
|
|
|
|
__ASSERT(index < 4, "index has to be in the range 0..3");
|
|
|
|
|
|
|
|
gmac->GMAC_SA[index].GMAC_SAB = (mac_addr[3] << 24)
|
|
|
|
| (mac_addr[2] << 16)
|
|
|
|
| (mac_addr[1] << 8)
|
|
|
|
| (mac_addr[0]);
|
|
|
|
gmac->GMAC_SA[index].GMAC_SAT = (mac_addr[5] << 8)
|
|
|
|
| (mac_addr[4]);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize RX descriptor list
|
|
|
|
*/
|
|
|
|
static int rx_descriptors_init(Gmac *gmac, struct gmac_queue *queue)
|
|
|
|
{
|
|
|
|
struct gmac_desc_list *rx_desc_list = &queue->rx_desc_list;
|
2019-02-08 01:06:01 +01:00
|
|
|
struct net_buf **rx_frag_list = queue->rx_frag_list;
|
2016-12-24 03:58:38 +01:00
|
|
|
struct net_buf *rx_buf;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t *rx_buf_addr;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2019-02-08 01:06:01 +01:00
|
|
|
__ASSERT_NO_MSG(rx_frag_list);
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2018-11-29 11:12:22 -08:00
|
|
|
rx_desc_list->tail = 0U;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < rx_desc_list->len; i++) {
|
2018-06-28 17:10:37 +02:00
|
|
|
rx_buf = net_pkt_get_reserve_rx_data(K_NO_WAIT);
|
2016-12-24 03:58:38 +01:00
|
|
|
if (rx_buf == NULL) {
|
2019-02-08 01:06:01 +01:00
|
|
|
free_rx_bufs(rx_frag_list, rx_desc_list->len);
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_ERR("Failed to reserve data net buffers");
|
2016-12-24 03:58:38 +01:00
|
|
|
return -ENOBUFS;
|
|
|
|
}
|
|
|
|
|
2019-02-08 01:06:01 +01:00
|
|
|
rx_frag_list[i] = rx_buf;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
rx_buf_addr = rx_buf->data;
|
2020-05-27 11:26:57 -05:00
|
|
|
__ASSERT(!((uint32_t)rx_buf_addr & ~GMAC_RXW0_ADDR),
|
2016-12-24 03:58:38 +01:00
|
|
|
"Misaligned RX buffer address");
|
2017-04-03 17:14:35 +02:00
|
|
|
__ASSERT(rx_buf->size == CONFIG_NET_BUF_DATA_SIZE,
|
2016-12-24 03:58:38 +01:00
|
|
|
"Incorrect length of RX data buffer");
|
|
|
|
/* Give ownership to GMAC and remove the wrap bit */
|
2020-05-27 11:26:57 -05:00
|
|
|
rx_desc_list->buf[i].w0 = (uint32_t)rx_buf_addr & GMAC_RXW0_ADDR;
|
2019-03-26 19:57:45 -06:00
|
|
|
rx_desc_list->buf[i].w1 = 0U;
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the wrap bit on the last descriptor */
|
2019-03-26 19:57:45 -06:00
|
|
|
rx_desc_list->buf[rx_desc_list->len - 1U].w0 |= GMAC_RXW0_WRAP;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize TX descriptor list
|
|
|
|
*/
|
|
|
|
static void tx_descriptors_init(Gmac *gmac, struct gmac_queue *queue)
|
|
|
|
{
|
|
|
|
struct gmac_desc_list *tx_desc_list = &queue->tx_desc_list;
|
|
|
|
|
2018-11-29 11:12:22 -08:00
|
|
|
tx_desc_list->head = 0U;
|
|
|
|
tx_desc_list->tail = 0U;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < tx_desc_list->len; i++) {
|
2019-03-26 19:57:45 -06:00
|
|
|
tx_desc_list->buf[i].w0 = 0U;
|
2018-12-08 01:49:12 +01:00
|
|
|
tx_desc_list->buf[i].w1 = GMAC_TXW1_USED;
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Set the wrap bit on the last descriptor */
|
2019-03-26 19:57:45 -06:00
|
|
|
tx_desc_list->buf[tx_desc_list->len - 1U].w1 |= GMAC_TXW1_WRAP;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
2016-12-24 03:58:38 +01:00
|
|
|
/* Reset TX frame list */
|
2019-02-06 21:33:19 +01:00
|
|
|
ring_buf_reset(&queue->tx_frag_list);
|
2019-02-06 21:44:47 +01:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
2016-12-24 03:58:38 +01:00
|
|
|
ring_buf_reset(&queue->tx_frames);
|
2019-02-06 21:44:47 +01:00
|
|
|
#endif
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
|
2018-04-18 16:13:05 +02:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
|
|
|
static struct gptp_hdr *check_gptp_msg(struct net_if *iface,
|
2018-12-10 17:03:30 +02:00
|
|
|
struct net_pkt *pkt,
|
|
|
|
bool is_tx)
|
2018-04-18 16:13:05 +02:00
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t *msg_start = net_pkt_data(pkt);
|
2018-04-18 16:13:05 +02:00
|
|
|
struct ethernet_context *eth_ctx;
|
2018-12-10 17:03:30 +02:00
|
|
|
struct gptp_hdr *gptp_hdr;
|
|
|
|
int eth_hlen;
|
2018-04-18 16:13:05 +02:00
|
|
|
|
|
|
|
#if defined(CONFIG_NET_VLAN)
|
|
|
|
eth_ctx = net_if_l2_data(iface);
|
|
|
|
if (net_eth_is_vlan_enabled(eth_ctx, iface)) {
|
|
|
|
struct net_eth_vlan_hdr *hdr_vlan;
|
|
|
|
|
|
|
|
hdr_vlan = (struct net_eth_vlan_hdr *)msg_start;
|
|
|
|
if (ntohs(hdr_vlan->type) != NET_ETH_PTYPE_PTP) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-12-10 17:03:30 +02:00
|
|
|
|
|
|
|
eth_hlen = sizeof(struct net_eth_vlan_hdr);
|
2018-04-18 16:13:05 +02:00
|
|
|
} else
|
|
|
|
#else
|
|
|
|
ARG_UNUSED(eth_ctx);
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
struct net_eth_hdr *hdr;
|
|
|
|
|
|
|
|
hdr = (struct net_eth_hdr *)msg_start;
|
|
|
|
if (ntohs(hdr->type) != NET_ETH_PTYPE_PTP) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-12-10 17:03:30 +02:00
|
|
|
|
|
|
|
eth_hlen = sizeof(struct net_eth_hdr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* In TX, the first net_buf contains the Ethernet header
|
|
|
|
* and the actual gPTP header is in the second net_buf.
|
|
|
|
* In RX, the Ethernet header + other headers are in the
|
|
|
|
* first net_buf.
|
|
|
|
*/
|
|
|
|
if (is_tx) {
|
|
|
|
if (pkt->frags->frags == NULL) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
gptp_hdr = (struct gptp_hdr *)pkt->frags->frags->data;
|
|
|
|
} else {
|
|
|
|
gptp_hdr = (struct gptp_hdr *)(pkt->frags->data + eth_hlen);
|
2018-04-18 16:13:05 +02:00
|
|
|
}
|
|
|
|
|
2018-12-10 17:03:30 +02:00
|
|
|
return gptp_hdr;
|
2018-04-18 16:13:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool need_timestamping(struct gptp_hdr *hdr)
|
|
|
|
{
|
|
|
|
switch (hdr->message_type) {
|
|
|
|
case GPTP_SYNC_MESSAGE:
|
|
|
|
case GPTP_PATH_DELAY_RESP_MESSAGE:
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void update_pkt_priority(struct gptp_hdr *hdr, struct net_pkt *pkt)
|
|
|
|
{
|
|
|
|
if (GPTP_IS_EVENT_MSG(hdr->message_type)) {
|
|
|
|
net_pkt_set_priority(pkt, NET_PRIORITY_CA);
|
|
|
|
} else {
|
|
|
|
net_pkt_set_priority(pkt, NET_PRIORITY_IC);
|
|
|
|
}
|
|
|
|
}
|
2018-06-14 10:25:27 +02:00
|
|
|
|
|
|
|
static inline struct net_ptp_time get_ptp_event_rx_ts(Gmac *gmac)
|
|
|
|
{
|
|
|
|
struct net_ptp_time ts;
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
ts.second = ((uint64_t)(gmac->GMAC_EFRSH & 0xffff) << 32)
|
2018-06-14 10:25:27 +02:00
|
|
|
| gmac->GMAC_EFRSL;
|
|
|
|
ts.nanosecond = gmac->GMAC_EFRN;
|
|
|
|
|
|
|
|
return ts;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct net_ptp_time get_ptp_peer_event_rx_ts(Gmac *gmac)
|
|
|
|
{
|
|
|
|
struct net_ptp_time ts;
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
ts.second = ((uint64_t)(gmac->GMAC_PEFRSH & 0xffff) << 32)
|
2018-06-14 10:25:27 +02:00
|
|
|
| gmac->GMAC_PEFRSL;
|
|
|
|
ts.nanosecond = gmac->GMAC_PEFRN;
|
|
|
|
|
|
|
|
return ts;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct net_ptp_time get_ptp_event_tx_ts(Gmac *gmac)
|
|
|
|
{
|
|
|
|
struct net_ptp_time ts;
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
ts.second = ((uint64_t)(gmac->GMAC_EFTSH & 0xffff) << 32)
|
2018-06-14 10:25:27 +02:00
|
|
|
| gmac->GMAC_EFTSL;
|
|
|
|
ts.nanosecond = gmac->GMAC_EFTN;
|
|
|
|
|
|
|
|
return ts;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct net_ptp_time get_ptp_peer_event_tx_ts(Gmac *gmac)
|
|
|
|
{
|
|
|
|
struct net_ptp_time ts;
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
ts.second = ((uint64_t)(gmac->GMAC_PEFTSH & 0xffff) << 32)
|
2018-06-14 10:25:27 +02:00
|
|
|
| gmac->GMAC_PEFTSL;
|
|
|
|
ts.nanosecond = gmac->GMAC_PEFTN;
|
|
|
|
|
|
|
|
return ts;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct net_ptp_time get_current_ts(Gmac *gmac)
|
|
|
|
{
|
|
|
|
struct net_ptp_time ts;
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
ts.second = ((uint64_t)(gmac->GMAC_TSH & 0xffff) << 32) | gmac->GMAC_TSL;
|
2018-06-14 10:25:27 +02:00
|
|
|
ts.nanosecond = gmac->GMAC_TN;
|
|
|
|
|
|
|
|
return ts;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static inline void timestamp_tx_pkt(Gmac *gmac, struct gptp_hdr *hdr,
|
|
|
|
struct net_pkt *pkt)
|
|
|
|
{
|
|
|
|
struct net_ptp_time timestamp;
|
|
|
|
|
|
|
|
if (hdr) {
|
|
|
|
switch (hdr->message_type) {
|
|
|
|
case GPTP_SYNC_MESSAGE:
|
|
|
|
timestamp = get_ptp_event_tx_ts(gmac);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
timestamp = get_ptp_peer_event_tx_ts(gmac);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
timestamp = get_current_ts(gmac);
|
|
|
|
}
|
|
|
|
|
|
|
|
net_pkt_set_timestamp(pkt, ×tamp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void timestamp_rx_pkt(Gmac *gmac, struct gptp_hdr *hdr,
|
|
|
|
struct net_pkt *pkt)
|
|
|
|
{
|
|
|
|
struct net_ptp_time timestamp;
|
|
|
|
|
|
|
|
if (hdr) {
|
|
|
|
switch (hdr->message_type) {
|
|
|
|
case GPTP_SYNC_MESSAGE:
|
|
|
|
timestamp = get_ptp_event_rx_ts(gmac);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
timestamp = get_ptp_peer_event_rx_ts(gmac);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
timestamp = get_current_ts(gmac);
|
|
|
|
}
|
|
|
|
|
|
|
|
net_pkt_set_timestamp(pkt, ×tamp);
|
|
|
|
}
|
|
|
|
|
2018-04-18 16:13:05 +02:00
|
|
|
#endif
|
|
|
|
|
2018-04-20 11:13:52 +02:00
|
|
|
static inline struct net_if *get_iface(struct eth_sam_dev_data *ctx,
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t vlan_tag)
|
2018-04-20 11:13:52 +02:00
|
|
|
{
|
|
|
|
#if defined(CONFIG_NET_VLAN)
|
|
|
|
struct net_if *iface;
|
|
|
|
|
|
|
|
iface = net_eth_get_vlan_iface(ctx->iface, vlan_tag);
|
|
|
|
if (!iface) {
|
|
|
|
return ctx->iface;
|
|
|
|
}
|
|
|
|
|
|
|
|
return iface;
|
|
|
|
#else
|
|
|
|
ARG_UNUSED(vlan_tag);
|
|
|
|
|
|
|
|
return ctx->iface;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
/*
|
|
|
|
* Process successfully sent packets
|
|
|
|
*/
|
|
|
|
static void tx_completed(Gmac *gmac, struct gmac_queue *queue)
|
|
|
|
{
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 0
|
|
|
|
k_sem_give(&queue->tx_sem);
|
|
|
|
#else
|
2016-12-24 03:58:38 +01:00
|
|
|
struct gmac_desc_list *tx_desc_list = &queue->tx_desc_list;
|
|
|
|
struct gmac_desc *tx_desc;
|
2019-02-06 21:33:19 +01:00
|
|
|
struct net_buf *frag;
|
2018-04-18 16:13:05 +02:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
2019-02-06 21:44:47 +01:00
|
|
|
struct net_pkt *pkt;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t vlan_tag = NET_VLAN_TAG_UNSPEC;
|
2018-04-18 16:13:05 +02:00
|
|
|
struct gptp_hdr *hdr;
|
|
|
|
struct eth_sam_dev_data *dev_data =
|
2018-06-19 10:01:16 +02:00
|
|
|
CONTAINER_OF(queue, struct eth_sam_dev_data,
|
|
|
|
queue_list[queue->que_idx]);
|
2018-04-18 16:13:05 +02:00
|
|
|
#endif
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2018-12-08 01:49:12 +01:00
|
|
|
__ASSERT(tx_desc_list->buf[tx_desc_list->tail].w1 & GMAC_TXW1_USED,
|
2016-12-24 03:58:38 +01:00
|
|
|
"first buffer of a frame is not marked as own by GMAC");
|
|
|
|
|
|
|
|
while (tx_desc_list->tail != tx_desc_list->head) {
|
|
|
|
|
|
|
|
tx_desc = &tx_desc_list->buf[tx_desc_list->tail];
|
|
|
|
MODULO_INC(tx_desc_list->tail, tx_desc_list->len);
|
2017-03-15 01:30:35 +01:00
|
|
|
k_sem_give(&queue->tx_desc_sem);
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2019-02-06 21:33:19 +01:00
|
|
|
/* Release net buffer to the buffer pool */
|
|
|
|
frag = UINT_TO_POINTER(ring_buf_get(&queue->tx_frag_list));
|
|
|
|
net_pkt_frag_unref(frag);
|
|
|
|
LOG_DBG("Dropping frag %p", frag);
|
|
|
|
|
2018-12-08 01:49:12 +01:00
|
|
|
if (tx_desc->w1 & GMAC_TXW1_LASTBUFFER) {
|
2019-02-06 21:44:47 +01:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
2019-02-06 21:33:19 +01:00
|
|
|
/* Release net packet to the packet pool */
|
2017-04-05 08:37:44 +02:00
|
|
|
pkt = UINT_TO_POINTER(ring_buf_get(&queue->tx_frames));
|
2018-04-20 11:13:52 +02:00
|
|
|
#if defined(CONFIG_NET_VLAN)
|
|
|
|
struct net_eth_hdr *eth_hdr = NET_ETH_HDR(pkt);
|
|
|
|
|
|
|
|
if (ntohs(eth_hdr->type) == NET_ETH_PTYPE_VLAN) {
|
|
|
|
vlan_tag = net_pkt_vlan_tag(pkt);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
hdr = check_gptp_msg(get_iface(dev_data, vlan_tag),
|
2018-12-10 17:03:30 +02:00
|
|
|
pkt, true);
|
2018-06-14 10:25:27 +02:00
|
|
|
|
|
|
|
timestamp_tx_pkt(gmac, hdr, pkt);
|
|
|
|
|
2018-04-18 16:13:05 +02:00
|
|
|
if (hdr && need_timestamping(hdr)) {
|
|
|
|
net_if_add_tx_timestamp(pkt);
|
|
|
|
}
|
2017-04-05 08:37:44 +02:00
|
|
|
net_pkt_unref(pkt);
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_DBG("Dropping pkt %p", pkt);
|
2019-02-06 21:44:47 +01:00
|
|
|
#endif
|
2016-12-24 03:58:38 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Reset TX queue when errors are detected
|
|
|
|
*/
|
|
|
|
static void tx_error_handler(Gmac *gmac, struct gmac_queue *queue)
|
|
|
|
{
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
2019-02-06 21:33:19 +01:00
|
|
|
struct net_buf *frag;
|
|
|
|
struct ring_buf *tx_frag_list = &queue->tx_frag_list;
|
2019-02-06 21:44:47 +01:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
|
|
|
struct net_pkt *pkt;
|
2017-03-15 01:30:35 +01:00
|
|
|
struct ring_buf *tx_frames = &queue->tx_frames;
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
2019-02-06 21:44:47 +01:00
|
|
|
#endif
|
2017-03-15 01:30:35 +01:00
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
queue->err_tx_flushed_count++;
|
|
|
|
|
|
|
|
/* Stop transmission, clean transmit pipeline and control registers */
|
|
|
|
gmac->GMAC_NCR &= ~GMAC_NCR_TXEN;
|
|
|
|
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
2019-02-06 21:33:19 +01:00
|
|
|
/* Free all frag resources in the TX path */
|
|
|
|
while (tx_frag_list->tail != tx_frag_list->head) {
|
|
|
|
/* Release net buffer to the buffer pool */
|
|
|
|
frag = UINT_TO_POINTER(tx_frag_list->buf[tx_frag_list->tail]);
|
|
|
|
net_pkt_frag_unref(frag);
|
|
|
|
LOG_DBG("Dropping frag %p", frag);
|
|
|
|
MODULO_INC(tx_frag_list->tail, tx_frag_list->len);
|
|
|
|
}
|
|
|
|
|
2019-02-06 21:44:47 +01:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
2017-04-03 17:14:35 +02:00
|
|
|
/* Free all pkt resources in the TX path */
|
2017-03-15 01:30:35 +01:00
|
|
|
while (tx_frames->tail != tx_frames->head) {
|
2019-02-06 21:33:19 +01:00
|
|
|
/* Release net packet to the packet pool */
|
2017-04-05 08:37:44 +02:00
|
|
|
pkt = UINT_TO_POINTER(tx_frames->buf[tx_frames->tail]);
|
|
|
|
net_pkt_unref(pkt);
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_DBG("Dropping pkt %p", pkt);
|
2017-03-15 01:30:35 +01:00
|
|
|
MODULO_INC(tx_frames->tail, tx_frames->len);
|
|
|
|
}
|
2019-02-06 21:44:47 +01:00
|
|
|
#endif
|
2017-03-15 01:30:35 +01:00
|
|
|
|
|
|
|
/* Reinitialize TX descriptor list */
|
|
|
|
k_sem_reset(&queue->tx_desc_sem);
|
|
|
|
for (int i = 0; i < queue->tx_desc_list.len - 1; i++) {
|
|
|
|
k_sem_give(&queue->tx_desc_sem);
|
|
|
|
}
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
|
|
|
tx_descriptors_init(gmac, queue);
|
|
|
|
|
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 0
|
|
|
|
/* Reinitialize TX mutex */
|
|
|
|
k_sem_give(&queue->tx_sem);
|
|
|
|
#endif
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
/* Restart transmission */
|
|
|
|
gmac->GMAC_NCR |= GMAC_NCR_TXEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-03-15 01:30:35 +01:00
|
|
|
* Clean RX queue, any received data still stored in the buffers is abandoned.
|
2016-12-24 03:58:38 +01:00
|
|
|
*/
|
|
|
|
static void rx_error_handler(Gmac *gmac, struct gmac_queue *queue)
|
|
|
|
{
|
|
|
|
queue->err_rx_flushed_count++;
|
|
|
|
|
|
|
|
/* Stop reception */
|
|
|
|
gmac->GMAC_NCR &= ~GMAC_NCR_RXEN;
|
|
|
|
|
2018-11-29 11:12:22 -08:00
|
|
|
queue->rx_desc_list.tail = 0U;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < queue->rx_desc_list.len; i++) {
|
2019-03-26 19:57:45 -06:00
|
|
|
queue->rx_desc_list.buf[i].w1 = 0U;
|
2018-12-08 01:49:12 +01:00
|
|
|
queue->rx_desc_list.buf[i].w0 &= ~GMAC_RXW0_OWNERSHIP;
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
|
2020-02-25 23:47:46 -03:00
|
|
|
set_receive_buf_queue_pointer(gmac, queue);
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
/* Restart reception */
|
|
|
|
gmac->GMAC_NCR |= GMAC_NCR_RXEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set MCK to MDC clock divisor.
|
|
|
|
*
|
|
|
|
* According to 802.3 MDC should be less then 2.5 MHz.
|
|
|
|
*/
|
2020-05-27 11:26:57 -05:00
|
|
|
static int get_mck_clock_divisor(uint32_t mck)
|
2016-12-24 03:58:38 +01:00
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t mck_divisor;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2019-03-26 19:57:45 -06:00
|
|
|
if (mck <= 20000000U) {
|
2016-12-24 03:58:38 +01:00
|
|
|
mck_divisor = GMAC_NCFGR_CLK_MCK_8;
|
2019-03-26 19:57:45 -06:00
|
|
|
} else if (mck <= 40000000U) {
|
2016-12-24 03:58:38 +01:00
|
|
|
mck_divisor = GMAC_NCFGR_CLK_MCK_16;
|
2019-03-26 19:57:45 -06:00
|
|
|
} else if (mck <= 80000000U) {
|
2016-12-24 03:58:38 +01:00
|
|
|
mck_divisor = GMAC_NCFGR_CLK_MCK_32;
|
2019-03-26 19:57:45 -06:00
|
|
|
} else if (mck <= 120000000U) {
|
2016-12-24 03:58:38 +01:00
|
|
|
mck_divisor = GMAC_NCFGR_CLK_MCK_48;
|
2019-03-26 19:57:45 -06:00
|
|
|
} else if (mck <= 160000000U) {
|
2016-12-24 03:58:38 +01:00
|
|
|
mck_divisor = GMAC_NCFGR_CLK_MCK_64;
|
2019-03-26 19:57:45 -06:00
|
|
|
} else if (mck <= 240000000U) {
|
2016-12-24 03:58:38 +01:00
|
|
|
mck_divisor = GMAC_NCFGR_CLK_MCK_96;
|
|
|
|
} else {
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_ERR("No valid MDC clock");
|
2016-12-24 03:58:38 +01:00
|
|
|
mck_divisor = -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mck_divisor;
|
|
|
|
}
|
|
|
|
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 1
|
2018-07-31 09:38:08 +02:00
|
|
|
static int eth_sam_gmac_setup_qav(Gmac *gmac, int queue_id, bool enable)
|
|
|
|
{
|
|
|
|
/* Verify queue id */
|
2020-02-19 18:56:37 -03:00
|
|
|
if (queue_id < GMAC_QUE_1 || queue_id > GMAC_ACTIVE_PRIORITY_QUEUE_NUM) {
|
2018-07-31 09:38:08 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
drivers: eth: gmac: Swap Qav queue registers
Throughout the manual, the queues GMAC is equipped with are identified
by a number - Queue 0, Queue 1 and Queue 2.
However in the context of Qav, the queues are identified with a
character (note that there are only two queues as Qav is not used for
the non-priority queue) - Queue A and Queue B.
Queue B and Queue 2 are also called "the highest priority queues".
Based on that, the previous implementation was using the following
mapping:
Queue 1 - Queue A
Queue 2 - Queue B
However when running some specific tests, that is for example forcing
all the traffic to Queue 1, it showed that this queue is actually
affected by the Queue B registers. Similarly, Queue 2 seems to be
affected by the Queue A registers.
Based on that observation, this commit changes the registers used to
work with the following mapping:
Queue 1 - Queue B
Queue 2 - Queue A
Note that this is based solely on observations, there is nothing in the
datasheet that confirms this, and the "highest priority" label suggests
it is otherwise.
Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2019-03-04 13:28:17 +01:00
|
|
|
if (queue_id == GMAC_QUE_2) {
|
2018-07-31 09:38:08 +02:00
|
|
|
if (enable) {
|
|
|
|
gmac->GMAC_CBSCR |= GMAC_CBSCR_QAE;
|
|
|
|
} else {
|
|
|
|
gmac->GMAC_CBSCR &= ~GMAC_CBSCR_QAE;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (enable) {
|
|
|
|
gmac->GMAC_CBSCR |= GMAC_CBSCR_QBE;
|
|
|
|
} else {
|
|
|
|
gmac->GMAC_CBSCR &= ~GMAC_CBSCR_QBE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int eth_sam_gmac_get_qav_status(Gmac *gmac, int queue_id, bool *enabled)
|
|
|
|
{
|
|
|
|
/* Verify queue id */
|
2020-02-19 18:56:37 -03:00
|
|
|
if (queue_id < GMAC_QUE_1 || queue_id > GMAC_ACTIVE_PRIORITY_QUEUE_NUM) {
|
2018-07-31 09:38:08 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
drivers: eth: gmac: Swap Qav queue registers
Throughout the manual, the queues GMAC is equipped with are identified
by a number - Queue 0, Queue 1 and Queue 2.
However in the context of Qav, the queues are identified with a
character (note that there are only two queues as Qav is not used for
the non-priority queue) - Queue A and Queue B.
Queue B and Queue 2 are also called "the highest priority queues".
Based on that, the previous implementation was using the following
mapping:
Queue 1 - Queue A
Queue 2 - Queue B
However when running some specific tests, that is for example forcing
all the traffic to Queue 1, it showed that this queue is actually
affected by the Queue B registers. Similarly, Queue 2 seems to be
affected by the Queue A registers.
Based on that observation, this commit changes the registers used to
work with the following mapping:
Queue 1 - Queue B
Queue 2 - Queue A
Note that this is based solely on observations, there is nothing in the
datasheet that confirms this, and the "highest priority" label suggests
it is otherwise.
Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2019-03-04 13:28:17 +01:00
|
|
|
if (queue_id == GMAC_QUE_2) {
|
2018-07-31 09:38:08 +02:00
|
|
|
*enabled = gmac->GMAC_CBSCR & GMAC_CBSCR_QAE;
|
|
|
|
} else {
|
|
|
|
*enabled = gmac->GMAC_CBSCR & GMAC_CBSCR_QBE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-07-30 11:26:00 +02:00
|
|
|
static int eth_sam_gmac_setup_qav_idle_slope(Gmac *gmac, int queue_id,
|
2018-08-01 15:08:03 +02:00
|
|
|
unsigned int idle_slope)
|
2018-07-30 11:26:00 +02:00
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t cbscr_val;
|
2018-08-01 13:57:33 +02:00
|
|
|
|
2018-07-30 11:26:00 +02:00
|
|
|
/* Verify queue id */
|
2020-02-19 18:56:37 -03:00
|
|
|
if (queue_id < GMAC_QUE_1 || queue_id > GMAC_ACTIVE_PRIORITY_QUEUE_NUM) {
|
2018-07-30 11:26:00 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-08-01 13:57:33 +02:00
|
|
|
cbscr_val = gmac->GMAC_CBSISQA;
|
|
|
|
|
drivers: eth: gmac: Swap Qav queue registers
Throughout the manual, the queues GMAC is equipped with are identified
by a number - Queue 0, Queue 1 and Queue 2.
However in the context of Qav, the queues are identified with a
character (note that there are only two queues as Qav is not used for
the non-priority queue) - Queue A and Queue B.
Queue B and Queue 2 are also called "the highest priority queues".
Based on that, the previous implementation was using the following
mapping:
Queue 1 - Queue A
Queue 2 - Queue B
However when running some specific tests, that is for example forcing
all the traffic to Queue 1, it showed that this queue is actually
affected by the Queue B registers. Similarly, Queue 2 seems to be
affected by the Queue A registers.
Based on that observation, this commit changes the registers used to
work with the following mapping:
Queue 1 - Queue B
Queue 2 - Queue A
Note that this is based solely on observations, there is nothing in the
datasheet that confirms this, and the "highest priority" label suggests
it is otherwise.
Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2019-03-04 13:28:17 +01:00
|
|
|
if (queue_id == GMAC_QUE_2) {
|
2018-07-30 11:26:00 +02:00
|
|
|
gmac->GMAC_CBSCR &= ~GMAC_CBSCR_QAE;
|
|
|
|
gmac->GMAC_CBSISQA = idle_slope;
|
|
|
|
} else {
|
|
|
|
gmac->GMAC_CBSCR &= ~GMAC_CBSCR_QBE;
|
|
|
|
gmac->GMAC_CBSISQB = idle_slope;
|
|
|
|
}
|
|
|
|
|
2018-08-01 13:57:33 +02:00
|
|
|
gmac->GMAC_CBSCR = cbscr_val;
|
|
|
|
|
2018-07-30 11:26:00 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
static uint32_t eth_sam_gmac_get_bandwidth(Gmac *gmac)
|
2018-07-30 11:26:00 +02:00
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t bandwidth;
|
2018-07-30 11:26:00 +02:00
|
|
|
|
|
|
|
/* See if we operate in 10Mbps or 100Mbps mode,
|
|
|
|
* Note: according to the manual, portTransmitRate is 0x07735940 for
|
|
|
|
* 1Gbps - therefore we cannot use the KB/MB macros - we have to
|
|
|
|
* multiply it by a round 1000 to get it right.
|
|
|
|
*/
|
|
|
|
if (gmac->GMAC_NCFGR & GMAC_NCFGR_SPD) {
|
|
|
|
/* 100Mbps */
|
|
|
|
bandwidth = (100 * 1000 * 1000) / 8;
|
|
|
|
} else {
|
|
|
|
/* 10Mbps */
|
|
|
|
bandwidth = (10 * 1000 * 1000) / 8;
|
|
|
|
}
|
|
|
|
|
2018-08-01 15:08:03 +02:00
|
|
|
return bandwidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int eth_sam_gmac_get_qav_idle_slope(Gmac *gmac, int queue_id,
|
|
|
|
unsigned int *idle_slope)
|
|
|
|
{
|
|
|
|
/* Verify queue id */
|
2020-02-19 18:56:37 -03:00
|
|
|
if (queue_id < GMAC_QUE_1 || queue_id > GMAC_ACTIVE_PRIORITY_QUEUE_NUM) {
|
2018-08-01 15:08:03 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
drivers: eth: gmac: Swap Qav queue registers
Throughout the manual, the queues GMAC is equipped with are identified
by a number - Queue 0, Queue 1 and Queue 2.
However in the context of Qav, the queues are identified with a
character (note that there are only two queues as Qav is not used for
the non-priority queue) - Queue A and Queue B.
Queue B and Queue 2 are also called "the highest priority queues".
Based on that, the previous implementation was using the following
mapping:
Queue 1 - Queue A
Queue 2 - Queue B
However when running some specific tests, that is for example forcing
all the traffic to Queue 1, it showed that this queue is actually
affected by the Queue B registers. Similarly, Queue 2 seems to be
affected by the Queue A registers.
Based on that observation, this commit changes the registers used to
work with the following mapping:
Queue 1 - Queue B
Queue 2 - Queue A
Note that this is based solely on observations, there is nothing in the
datasheet that confirms this, and the "highest priority" label suggests
it is otherwise.
Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2019-03-04 13:28:17 +01:00
|
|
|
if (queue_id == GMAC_QUE_2) {
|
2018-08-01 15:08:03 +02:00
|
|
|
*idle_slope = gmac->GMAC_CBSISQA;
|
|
|
|
} else {
|
|
|
|
*idle_slope = gmac->GMAC_CBSISQB;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Convert to bps as expected by upper layer */
|
2019-03-26 19:57:45 -06:00
|
|
|
*idle_slope *= 8U;
|
2018-08-01 15:08:03 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int eth_sam_gmac_get_qav_delta_bandwidth(Gmac *gmac, int queue_id,
|
|
|
|
unsigned int *delta_bandwidth)
|
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t bandwidth;
|
2018-08-01 15:08:03 +02:00
|
|
|
unsigned int idle_slope;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = eth_sam_gmac_get_qav_idle_slope(gmac, queue_id, &idle_slope);
|
|
|
|
if (ret) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Calculate in Bps */
|
2019-03-26 19:57:45 -06:00
|
|
|
idle_slope /= 8U;
|
2018-08-01 15:08:03 +02:00
|
|
|
|
|
|
|
/* Get bandwidth and convert to bps */
|
|
|
|
bandwidth = eth_sam_gmac_get_bandwidth(gmac);
|
|
|
|
|
|
|
|
/* Calculate percentage - instead of multiplying idle_slope by 100,
|
|
|
|
* divide bandwidth - these numbers are so large that it should not
|
|
|
|
* influence the outcome and saves us from employing larger data types.
|
|
|
|
*/
|
2019-03-26 19:57:45 -06:00
|
|
|
*delta_bandwidth = idle_slope / (bandwidth / 100U);
|
2018-08-01 15:08:03 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int eth_sam_gmac_setup_qav_delta_bandwidth(Gmac *gmac, int queue_id,
|
|
|
|
int queue_share)
|
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t bandwidth;
|
|
|
|
uint32_t idle_slope;
|
2018-08-01 15:08:03 +02:00
|
|
|
|
|
|
|
/* Verify queue id */
|
2020-02-19 18:56:37 -03:00
|
|
|
if (queue_id < GMAC_QUE_1 || queue_id > GMAC_ACTIVE_PRIORITY_QUEUE_NUM) {
|
2018-08-01 15:08:03 +02:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
bandwidth = eth_sam_gmac_get_bandwidth(gmac);
|
|
|
|
|
2019-03-26 19:57:45 -06:00
|
|
|
idle_slope = (bandwidth * queue_share) / 100U;
|
2018-07-30 11:26:00 +02:00
|
|
|
|
|
|
|
return eth_sam_gmac_setup_qav_idle_slope(gmac, queue_id, idle_slope);
|
|
|
|
}
|
2018-08-08 12:21:04 +02:00
|
|
|
#endif
|
2018-07-30 11:26:00 +02:00
|
|
|
|
2018-08-30 12:09:17 +02:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
|
|
|
static void gmac_setup_ptp_clock_divisors(Gmac *gmac)
|
|
|
|
{
|
|
|
|
int mck_divs[] = {10, 5, 2};
|
|
|
|
double min_cycles;
|
|
|
|
double min_period;
|
|
|
|
int div;
|
|
|
|
int i;
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t cns, acns, nit;
|
2018-08-30 12:09:17 +02:00
|
|
|
|
2020-03-06 02:08:44 +09:00
|
|
|
min_cycles = MCK_FREQ_HZ;
|
2018-08-30 12:09:17 +02:00
|
|
|
min_period = NSEC_PER_SEC;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(mck_divs); ++i) {
|
|
|
|
div = mck_divs[i];
|
|
|
|
while ((double)(min_cycles / div) == (int)(min_cycles / div) &&
|
|
|
|
(double)(min_period / div) == (int)(min_period / div)) {
|
|
|
|
min_cycles /= div;
|
|
|
|
min_period /= div;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nit = min_cycles - 1;
|
2018-11-29 11:12:22 -08:00
|
|
|
cns = 0U;
|
|
|
|
acns = 0U;
|
2018-08-30 12:09:17 +02:00
|
|
|
|
|
|
|
while ((cns + 2) * nit < min_period) {
|
|
|
|
cns++;
|
|
|
|
}
|
|
|
|
|
|
|
|
acns = min_period - (nit * cns);
|
|
|
|
|
|
|
|
gmac->GMAC_TI =
|
|
|
|
GMAC_TI_CNS(cns) | GMAC_TI_ACNS(acns) | GMAC_TI_NIT(nit);
|
|
|
|
gmac->GMAC_TISUBN = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
static int gmac_init(Gmac *gmac, uint32_t gmac_ncfgr_val)
|
2016-12-24 03:58:38 +01:00
|
|
|
{
|
|
|
|
int mck_divisor;
|
|
|
|
|
2020-03-06 02:08:44 +09:00
|
|
|
mck_divisor = get_mck_clock_divisor(MCK_FREQ_HZ);
|
2016-12-24 03:58:38 +01:00
|
|
|
if (mck_divisor < 0) {
|
|
|
|
return mck_divisor;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set Network Control Register to its default value, clear stats. */
|
|
|
|
gmac->GMAC_NCR = GMAC_NCR_CLRSTAT;
|
|
|
|
|
|
|
|
/* Disable all interrupts */
|
|
|
|
gmac->GMAC_IDR = UINT32_MAX;
|
|
|
|
/* Clear all interrupts */
|
|
|
|
(void)gmac->GMAC_ISR;
|
2020-02-25 23:47:46 -03:00
|
|
|
disable_all_priority_queue_interrupt(gmac);
|
2020-02-19 18:56:37 -03:00
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
/* Setup Hash Registers - enable reception of all multicast frames when
|
|
|
|
* GMAC_NCFGR_MTIHEN is set.
|
|
|
|
*/
|
|
|
|
gmac->GMAC_HRB = UINT32_MAX;
|
|
|
|
gmac->GMAC_HRT = UINT32_MAX;
|
|
|
|
/* Setup Network Configuration Register */
|
|
|
|
gmac->GMAC_NCFGR = gmac_ncfgr_val | mck_divisor;
|
|
|
|
|
2020-04-30 13:25:19 -05:00
|
|
|
gmac->GMAC_UR = DT_ENUM_IDX(DT_DRV_INST(0), phy_connection_type);
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2018-04-18 16:13:05 +02:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
|
|
|
/* Initialize PTP Clock Registers */
|
2018-08-30 12:09:17 +02:00
|
|
|
gmac_setup_ptp_clock_divisors(gmac);
|
|
|
|
|
2018-04-18 16:13:05 +02:00
|
|
|
gmac->GMAC_TN = 0;
|
|
|
|
gmac->GMAC_TSH = 0;
|
|
|
|
gmac->GMAC_TSL = 0;
|
|
|
|
#endif
|
|
|
|
|
2018-07-30 11:26:00 +02:00
|
|
|
/* Enable Qav if priority queues are used, and setup the default delta
|
|
|
|
* bandwidth according to IEEE802.1Qav (34.3.1)
|
|
|
|
*/
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM == 1
|
2018-07-30 11:26:00 +02:00
|
|
|
eth_sam_gmac_setup_qav_delta_bandwidth(gmac, 1, 75);
|
2020-02-19 18:56:37 -03:00
|
|
|
#elif GMAC_ACTIVE_PRIORITY_QUEUE_NUM == 2
|
drivers: eth: gmac: fix qav bandwidth sharing issues
Removing the TX timeout handling in the GMAC driver (commit 18b07e09e0)
revealed some issues with the way hardware priority queues work.
For cases with both hardware priority queues enabled, with the default
recommended delta bandwidths (0% - 75%), the lower priority queue (0%)
is hardly able to send any packets. This became visible, because without
the timeout mechanism, we quickly ran out of available TX buffers if
there were multiple packets being queued to the queue.
Here is an excerpt from 802.1Q, chapter 34.3.1 which describes how Qav
bandwidth sharing SHOULD work:
The deltaBandwidth(N) for a given N, plus the deltaBandwidth(N) values
for any higher priority queues (larger values of N) defines the total
percentage of the Port’s bandwidth that can be reserved for that queue
and all higher priority queues. For the highest priority queue, this
means that the maximum value of operIdleSlope(N) is deltaBandwidth(N)%
of portTransmitRate. However, if operIdleSlope(N) is actually less
than this maximum value, any lower priority queue that supports the
credit-based shaper algorithm can make use of the reservable bandwidth
that is unused by the higher priority queue. So, for queue N-1, the
maximum value of (operIdleSlope(N) + operIdleSlope(N-1)) is
(deltaBandwidth(N) + deltaBandwidth(N1))% of portTransmitRate.
However in reality, the lower priority queues (N-1) on the SAM GMAC
hardware DO NOT use the bandwidth available from the higher priority
queues (N).
This commits fixes the issue by changing the defaults. These are still
set to the recommended 75% (total), but this percentage is split between
the priority queues manually.
Signed-off-by: Tomasz Gorochowik <tgorochowik@antmicro.com>
2019-03-05 14:31:39 +01:00
|
|
|
/* For multiple priority queues, 802.1Qav suggests using 75% for the
|
|
|
|
* highest priority queue, and 0% for the lower priority queues.
|
|
|
|
* This is because the lower priority queues are supposed to be using
|
|
|
|
* the bandwidth available from the higher priority queues AND its own
|
|
|
|
* available bandwidth (see 802.1Q 34.3.1 for more details).
|
|
|
|
* This does not work like that in SAM GMAC - the lower priority queues
|
|
|
|
* are not using the bandwidth reserved for the higher priority queues
|
|
|
|
* at all. Thus we still set the default to a total of the recommended
|
|
|
|
* 75%, but split the bandwidth between them manually.
|
|
|
|
*/
|
|
|
|
eth_sam_gmac_setup_qav_delta_bandwidth(gmac, 1, 25);
|
|
|
|
eth_sam_gmac_setup_qav_delta_bandwidth(gmac, 2, 50);
|
2020-02-19 18:56:37 -03:00
|
|
|
#elif GMAC_ACTIVE_PRIORITY_QUEUE_NUM == 3
|
|
|
|
eth_sam_gmac_setup_qav_delta_bandwidth(gmac, 1, 25);
|
|
|
|
eth_sam_gmac_setup_qav_delta_bandwidth(gmac, 2, 25);
|
|
|
|
eth_sam_gmac_setup_qav_delta_bandwidth(gmac, 3, 25);
|
|
|
|
#elif GMAC_ACTIVE_PRIORITY_QUEUE_NUM == 4
|
|
|
|
eth_sam_gmac_setup_qav_delta_bandwidth(gmac, 1, 21);
|
|
|
|
eth_sam_gmac_setup_qav_delta_bandwidth(gmac, 2, 18);
|
|
|
|
eth_sam_gmac_setup_qav_delta_bandwidth(gmac, 3, 18);
|
|
|
|
eth_sam_gmac_setup_qav_delta_bandwidth(gmac, 4, 18);
|
|
|
|
#elif GMAC_ACTIVE_PRIORITY_QUEUE_NUM == 5
|
|
|
|
eth_sam_gmac_setup_qav_delta_bandwidth(gmac, 1, 15);
|
|
|
|
eth_sam_gmac_setup_qav_delta_bandwidth(gmac, 2, 15);
|
|
|
|
eth_sam_gmac_setup_qav_delta_bandwidth(gmac, 3, 15);
|
|
|
|
eth_sam_gmac_setup_qav_delta_bandwidth(gmac, 4, 15);
|
|
|
|
eth_sam_gmac_setup_qav_delta_bandwidth(gmac, 5, 15);
|
2018-07-30 11:26:00 +02:00
|
|
|
#endif
|
|
|
|
|
2020-02-25 23:47:46 -03:00
|
|
|
eth_sam_gmac_init_qav(gmac);
|
2020-02-19 18:56:37 -03:00
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
static void link_configure(Gmac *gmac, uint32_t flags)
|
2016-12-24 03:58:38 +01:00
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t val;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
val = gmac->GMAC_NCFGR;
|
|
|
|
|
|
|
|
val &= ~(GMAC_NCFGR_FD | GMAC_NCFGR_SPD);
|
|
|
|
val |= flags & (GMAC_NCFGR_FD | GMAC_NCFGR_SPD);
|
|
|
|
|
|
|
|
gmac->GMAC_NCFGR = val;
|
|
|
|
|
|
|
|
gmac->GMAC_NCR |= (GMAC_NCR_RXEN | GMAC_NCR_TXEN);
|
|
|
|
}
|
|
|
|
|
2018-06-19 10:01:16 +02:00
|
|
|
static int nonpriority_queue_init(Gmac *gmac, struct gmac_queue *queue)
|
2016-12-24 03:58:38 +01:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
|
|
|
|
__ASSERT_NO_MSG(queue->rx_desc_list.len > 0);
|
|
|
|
__ASSERT_NO_MSG(queue->tx_desc_list.len > 0);
|
2020-05-27 11:26:57 -05:00
|
|
|
__ASSERT(!((uint32_t)queue->rx_desc_list.buf & ~GMAC_RBQB_ADDR_Msk),
|
2016-12-24 03:58:38 +01:00
|
|
|
"RX descriptors have to be word aligned");
|
2020-05-27 11:26:57 -05:00
|
|
|
__ASSERT(!((uint32_t)queue->tx_desc_list.buf & ~GMAC_TBQB_ADDR_Msk),
|
2016-12-24 03:58:38 +01:00
|
|
|
"TX descriptors have to be word aligned");
|
|
|
|
|
|
|
|
/* Setup descriptor lists */
|
|
|
|
result = rx_descriptors_init(gmac, queue);
|
|
|
|
if (result < 0) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
tx_descriptors_init(gmac, queue);
|
|
|
|
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 0
|
|
|
|
/* Initialize TX semaphore. This semaphore is used to wait until the TX
|
|
|
|
* data has been sent.
|
|
|
|
*/
|
|
|
|
k_sem_init(&queue->tx_sem, 0, 1);
|
|
|
|
#else
|
2017-03-15 01:30:35 +01:00
|
|
|
/* Initialize TX descriptors semaphore. The semaphore is required as the
|
|
|
|
* size of the TX descriptor list is limited while the number of TX data
|
|
|
|
* buffers is not.
|
|
|
|
*/
|
|
|
|
k_sem_init(&queue->tx_desc_sem, queue->tx_desc_list.len - 1,
|
|
|
|
queue->tx_desc_list.len - 1);
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
2017-03-15 01:30:35 +01:00
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
/* Set Receive Buffer Queue Pointer Register */
|
2020-05-27 11:26:57 -05:00
|
|
|
gmac->GMAC_RBQB = (uint32_t)queue->rx_desc_list.buf;
|
2016-12-24 03:58:38 +01:00
|
|
|
/* Set Transmit Buffer Queue Pointer Register */
|
2020-05-27 11:26:57 -05:00
|
|
|
gmac->GMAC_TBQB = (uint32_t)queue->tx_desc_list.buf;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
/* Configure GMAC DMA transfer */
|
|
|
|
gmac->GMAC_DCFGR =
|
2020-02-26 00:14:11 -03:00
|
|
|
/* Receive Buffer Size (defined in multiples of 64 bytes) */
|
|
|
|
GMAC_DCFGR_DRBS(CONFIG_NET_BUF_DATA_SIZE >> 6) |
|
|
|
|
/* Attempt to use INCR4 AHB bursts (Default) */
|
|
|
|
GMAC_DCFGR_FBLDO_INCR4 |
|
|
|
|
/* DMA Queue Flags */
|
|
|
|
GMAC_DMA_QUEUE_FLAGS;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
/* Setup RX/TX completion and error interrupts */
|
|
|
|
gmac->GMAC_IER = GMAC_INT_EN_FLAGS;
|
|
|
|
|
2018-11-29 11:12:22 -08:00
|
|
|
queue->err_rx_frames_dropped = 0U;
|
|
|
|
queue->err_rx_flushed_count = 0U;
|
|
|
|
queue->err_tx_flushed_count = 0U;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_INF("Queue %d activated", queue->que_idx);
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-21 16:47:10 +02:00
|
|
|
static struct net_pkt *frame_get(struct gmac_queue *queue)
|
2016-12-24 03:58:38 +01:00
|
|
|
{
|
|
|
|
struct gmac_desc_list *rx_desc_list = &queue->rx_desc_list;
|
|
|
|
struct gmac_desc *rx_desc;
|
2019-02-08 01:06:01 +01:00
|
|
|
struct net_buf **rx_frag_list = queue->rx_frag_list;
|
2017-04-05 08:37:44 +02:00
|
|
|
struct net_pkt *rx_frame;
|
2016-12-24 03:58:38 +01:00
|
|
|
bool frame_is_complete;
|
|
|
|
struct net_buf *frag;
|
|
|
|
struct net_buf *new_frag;
|
2017-05-15 10:15:06 +02:00
|
|
|
struct net_buf *last_frag = NULL;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t *frag_data;
|
|
|
|
uint32_t frag_len;
|
|
|
|
uint32_t frame_len = 0U;
|
|
|
|
uint16_t tail;
|
|
|
|
uint8_t wrap;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
/* Check if there exists a complete frame in RX descriptor list */
|
|
|
|
tail = rx_desc_list->tail;
|
|
|
|
rx_desc = &rx_desc_list->buf[tail];
|
|
|
|
frame_is_complete = false;
|
2018-12-08 01:49:12 +01:00
|
|
|
while ((rx_desc->w0 & GMAC_RXW0_OWNERSHIP)
|
2018-06-08 12:50:47 +02:00
|
|
|
&& !frame_is_complete) {
|
2018-12-08 01:49:12 +01:00
|
|
|
frame_is_complete = (bool)(rx_desc->w1
|
2018-06-08 12:50:47 +02:00
|
|
|
& GMAC_RXW1_EOF);
|
2016-12-24 03:58:38 +01:00
|
|
|
MODULO_INC(tail, rx_desc_list->len);
|
|
|
|
rx_desc = &rx_desc_list->buf[tail];
|
|
|
|
}
|
|
|
|
/* Frame which is not complete can be dropped by GMAC. Do not process
|
|
|
|
* it, even partially.
|
|
|
|
*/
|
|
|
|
if (!frame_is_complete) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2019-03-14 09:02:26 +01:00
|
|
|
rx_frame = net_pkt_rx_alloc(K_NO_WAIT);
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
/* Process a frame */
|
|
|
|
tail = rx_desc_list->tail;
|
|
|
|
rx_desc = &rx_desc_list->buf[tail];
|
|
|
|
frame_is_complete = false;
|
|
|
|
|
|
|
|
/* TODO: Don't assume first RX fragment will have SOF (Start of frame)
|
|
|
|
* bit set. If SOF bit is missing recover gracefully by dropping
|
|
|
|
* invalid frame.
|
|
|
|
*/
|
2018-12-08 01:49:12 +01:00
|
|
|
__ASSERT(rx_desc->w1 & GMAC_RXW1_SOF,
|
2016-12-24 03:58:38 +01:00
|
|
|
"First RX fragment is missing SOF bit");
|
|
|
|
|
|
|
|
/* TODO: We know already tail and head indexes of fragments containing
|
|
|
|
* complete frame. Loop over those indexes, don't search for them
|
|
|
|
* again.
|
|
|
|
*/
|
2018-12-08 01:49:12 +01:00
|
|
|
while ((rx_desc->w0 & GMAC_RXW0_OWNERSHIP)
|
2018-06-08 12:50:47 +02:00
|
|
|
&& !frame_is_complete) {
|
2019-02-08 01:06:01 +01:00
|
|
|
frag = rx_frag_list[tail];
|
2018-06-08 12:50:47 +02:00
|
|
|
frag_data =
|
2020-05-27 11:26:57 -05:00
|
|
|
(uint8_t *)(rx_desc->w0 & GMAC_RXW0_ADDR);
|
2016-12-24 03:58:38 +01:00
|
|
|
__ASSERT(frag->data == frag_data,
|
|
|
|
"RX descriptor and buffer list desynchronized");
|
2018-12-08 01:49:12 +01:00
|
|
|
frame_is_complete = (bool)(rx_desc->w1 & GMAC_RXW1_EOF);
|
2016-12-24 03:58:38 +01:00
|
|
|
if (frame_is_complete) {
|
2018-12-08 01:49:12 +01:00
|
|
|
frag_len = (rx_desc->w1 & GMAC_RXW1_LEN) - frame_len;
|
2016-12-24 03:58:38 +01:00
|
|
|
} else {
|
2017-04-03 17:14:35 +02:00
|
|
|
frag_len = CONFIG_NET_BUF_DATA_SIZE;
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
frame_len += frag_len;
|
|
|
|
|
|
|
|
/* Link frame fragments only if RX net buffer is valid */
|
|
|
|
if (rx_frame != NULL) {
|
|
|
|
/* Assure cache coherency after DMA write operation */
|
2020-05-27 11:26:57 -05:00
|
|
|
dcache_invalidate((uint32_t)frag_data, frag->size);
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
/* Get a new data net buffer from the buffer pool */
|
2017-04-03 17:14:35 +02:00
|
|
|
new_frag = net_pkt_get_frag(rx_frame, K_NO_WAIT);
|
2016-12-24 03:58:38 +01:00
|
|
|
if (new_frag == NULL) {
|
|
|
|
queue->err_rx_frames_dropped++;
|
2017-04-05 08:37:44 +02:00
|
|
|
net_pkt_unref(rx_frame);
|
2016-12-24 03:58:38 +01:00
|
|
|
rx_frame = NULL;
|
|
|
|
} else {
|
|
|
|
net_buf_add(frag, frag_len);
|
2017-05-15 10:15:06 +02:00
|
|
|
if (!last_frag) {
|
|
|
|
net_pkt_frag_insert(rx_frame, frag);
|
|
|
|
} else {
|
|
|
|
net_buf_frag_insert(last_frag, frag);
|
|
|
|
}
|
|
|
|
last_frag = frag;
|
2016-12-24 03:58:38 +01:00
|
|
|
frag = new_frag;
|
2019-02-08 01:06:01 +01:00
|
|
|
rx_frag_list[tail] = frag;
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Update buffer descriptor status word */
|
2019-03-26 19:57:45 -06:00
|
|
|
rx_desc->w1 = 0U;
|
2016-12-24 03:58:38 +01:00
|
|
|
/* Guarantee that status word is written before the address
|
|
|
|
* word to avoid race condition.
|
|
|
|
*/
|
|
|
|
__DMB(); /* data memory barrier */
|
|
|
|
/* Update buffer descriptor address word */
|
2019-03-26 19:57:45 -06:00
|
|
|
wrap = (tail == rx_desc_list->len-1U ? GMAC_RXW0_WRAP : 0);
|
2020-05-27 11:26:57 -05:00
|
|
|
rx_desc->w0 = ((uint32_t)frag->data & GMAC_RXW0_ADDR) | wrap;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
MODULO_INC(tail, rx_desc_list->len);
|
|
|
|
rx_desc = &rx_desc_list->buf[tail];
|
|
|
|
}
|
|
|
|
|
|
|
|
rx_desc_list->tail = tail;
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_DBG("Frame complete: rx=%p, tail=%d", rx_frame, tail);
|
2016-12-24 03:58:38 +01:00
|
|
|
__ASSERT_NO_MSG(frame_is_complete);
|
|
|
|
|
|
|
|
return rx_frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void eth_rx(struct gmac_queue *queue)
|
|
|
|
{
|
|
|
|
struct eth_sam_dev_data *dev_data =
|
2018-06-19 10:01:16 +02:00
|
|
|
CONTAINER_OF(queue, struct eth_sam_dev_data,
|
|
|
|
queue_list[queue->que_idx]);
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t vlan_tag = NET_VLAN_TAG_UNSPEC;
|
2017-04-05 08:37:44 +02:00
|
|
|
struct net_pkt *rx_frame;
|
2018-04-18 16:13:05 +02:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
2020-04-30 20:33:38 +02:00
|
|
|
const struct device *dev = net_if_get_device(dev_data->iface);
|
2018-04-18 16:13:05 +02:00
|
|
|
const struct eth_sam_dev_cfg *const cfg = DEV_CFG(dev);
|
|
|
|
Gmac *gmac = cfg->regs;
|
2018-06-14 10:25:27 +02:00
|
|
|
struct gptp_hdr *hdr;
|
2018-04-18 16:13:05 +02:00
|
|
|
#endif
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
/* More than one frame could have been received by GMAC, get all
|
|
|
|
* complete frames stored in the GMAC RX descriptor list.
|
|
|
|
*/
|
|
|
|
rx_frame = frame_get(queue);
|
|
|
|
while (rx_frame) {
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_DBG("ETH rx");
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2018-03-21 17:04:10 +02:00
|
|
|
#if defined(CONFIG_NET_VLAN)
|
|
|
|
/* FIXME: Instead of this, use the GMAC register to get
|
|
|
|
* the used VLAN tag.
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
struct net_eth_hdr *hdr = NET_ETH_HDR(rx_frame);
|
|
|
|
|
|
|
|
if (ntohs(hdr->type) == NET_ETH_PTYPE_VLAN) {
|
|
|
|
struct net_eth_vlan_hdr *hdr_vlan =
|
|
|
|
(struct net_eth_vlan_hdr *)
|
|
|
|
NET_ETH_HDR(rx_frame);
|
|
|
|
|
|
|
|
net_pkt_set_vlan_tci(rx_frame,
|
|
|
|
ntohs(hdr_vlan->vlan.tci));
|
|
|
|
vlan_tag = net_pkt_vlan_tag(rx_frame);
|
|
|
|
|
|
|
|
#if CONFIG_NET_TC_RX_COUNT > 1
|
|
|
|
{
|
|
|
|
enum net_priority prio;
|
|
|
|
|
|
|
|
prio = net_vlan2priority(
|
|
|
|
net_pkt_vlan_priority(rx_frame));
|
|
|
|
net_pkt_set_priority(rx_frame, prio);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2018-04-18 16:13:05 +02:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
2018-12-10 17:03:30 +02:00
|
|
|
hdr = check_gptp_msg(get_iface(dev_data, vlan_tag), rx_frame,
|
|
|
|
false);
|
2018-04-18 16:13:05 +02:00
|
|
|
|
2018-06-14 10:25:27 +02:00
|
|
|
timestamp_rx_pkt(gmac, hdr, rx_frame);
|
2018-04-18 16:13:05 +02:00
|
|
|
|
|
|
|
if (hdr) {
|
|
|
|
update_pkt_priority(hdr, rx_frame);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_PTP_CLOCK_SAM_GMAC */
|
|
|
|
|
2018-03-21 17:04:10 +02:00
|
|
|
if (net_recv_data(get_iface(dev_data, vlan_tag),
|
|
|
|
rx_frame) < 0) {
|
2018-12-05 14:52:59 +01:00
|
|
|
eth_stats_update_errors_rx(get_iface(dev_data,
|
|
|
|
vlan_tag));
|
2017-04-03 17:14:35 +02:00
|
|
|
net_pkt_unref(rx_frame);
|
2017-04-11 00:04:54 +02:00
|
|
|
}
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
rx_frame = frame_get(queue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-04 13:21:20 +01:00
|
|
|
#if !defined(CONFIG_ETH_SAM_GMAC_FORCE_QUEUE) && \
|
2020-02-19 18:56:37 -03:00
|
|
|
((GMAC_ACTIVE_QUEUE_NUM != NET_TC_TX_COUNT) || \
|
2019-03-04 13:21:20 +01:00
|
|
|
((NET_TC_TX_COUNT != NET_TC_RX_COUNT) && defined(CONFIG_NET_VLAN)))
|
2018-06-19 10:01:16 +02:00
|
|
|
static int priority2queue(enum net_priority priority)
|
|
|
|
{
|
2020-05-27 11:26:57 -05:00
|
|
|
static const uint8_t queue_priority_map[] = {
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_QUEUE_NUM == 1
|
2018-06-19 10:01:16 +02:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0
|
|
|
|
#endif
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_QUEUE_NUM == 2
|
2018-06-19 10:01:16 +02:00
|
|
|
0, 0, 0, 0, 1, 1, 1, 1
|
|
|
|
#endif
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_QUEUE_NUM == 3
|
2018-06-19 10:01:16 +02:00
|
|
|
0, 0, 0, 0, 1, 1, 2, 2
|
2020-02-19 18:56:37 -03:00
|
|
|
#endif
|
|
|
|
#if GMAC_ACTIVE_QUEUE_NUM == 4
|
|
|
|
0, 0, 0, 0, 1, 1, 2, 3
|
|
|
|
#endif
|
|
|
|
#if GMAC_ACTIVE_QUEUE_NUM == 5
|
|
|
|
0, 0, 0, 0, 1, 2, 3, 4
|
|
|
|
#endif
|
|
|
|
#if GMAC_ACTIVE_QUEUE_NUM == 6
|
|
|
|
0, 0, 0, 1, 2, 3, 4, 5
|
2018-06-19 10:01:16 +02:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
return queue_priority_map[priority];
|
|
|
|
}
|
2018-08-03 12:12:07 +02:00
|
|
|
#endif
|
2018-06-19 10:01:16 +02:00
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int eth_tx(const struct device *dev, struct net_pkt *pkt)
|
2016-12-24 03:58:38 +01:00
|
|
|
{
|
|
|
|
const struct eth_sam_dev_cfg *const cfg = DEV_CFG(dev);
|
|
|
|
struct eth_sam_dev_data *const dev_data = DEV_DATA(dev);
|
|
|
|
Gmac *gmac = cfg->regs;
|
2018-06-19 10:01:16 +02:00
|
|
|
struct gmac_queue *queue;
|
|
|
|
struct gmac_desc_list *tx_desc_list;
|
2016-12-24 03:58:38 +01:00
|
|
|
struct gmac_desc *tx_desc;
|
2019-01-18 21:33:03 +01:00
|
|
|
struct gmac_desc *tx_first_desc;
|
2016-12-24 03:58:38 +01:00
|
|
|
struct net_buf *frag;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t *frag_data;
|
|
|
|
uint16_t frag_len;
|
|
|
|
uint32_t err_tx_flushed_count_at_entry;
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
2017-03-15 01:30:35 +01:00
|
|
|
unsigned int key;
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
2020-05-27 11:26:57 -05:00
|
|
|
uint8_t pkt_prio;
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 0
|
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
2020-05-27 11:26:57 -05:00
|
|
|
uint16_t vlan_tag = NET_VLAN_TAG_UNSPEC;
|
2019-02-12 22:21:06 +01:00
|
|
|
struct gptp_hdr *hdr;
|
|
|
|
#if defined(CONFIG_NET_VLAN)
|
|
|
|
struct net_eth_hdr *eth_hdr;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2017-04-05 08:37:44 +02:00
|
|
|
__ASSERT(pkt, "buf pointer is NULL");
|
|
|
|
__ASSERT(pkt->frags, "Frame data missing");
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_DBG("ETH tx");
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2018-06-19 10:01:16 +02:00
|
|
|
/* Decide which queue should be used */
|
2018-08-03 12:12:07 +02:00
|
|
|
pkt_prio = net_pkt_priority(pkt);
|
|
|
|
|
2019-03-04 13:21:20 +01:00
|
|
|
#if defined(CONFIG_ETH_SAM_GMAC_FORCE_QUEUE)
|
|
|
|
/* Route eveything to the forced queue */
|
|
|
|
queue = &dev_data->queue_list[CONFIG_ETH_SAM_GMAC_FORCED_QUEUE];
|
2020-02-19 18:56:37 -03:00
|
|
|
#elif GMAC_ACTIVE_QUEUE_NUM == CONFIG_NET_TC_TX_COUNT
|
2018-08-03 12:12:07 +02:00
|
|
|
/* Prefer to chose queue based on its traffic class */
|
|
|
|
queue = &dev_data->queue_list[net_tx_priority2tc(pkt_prio)];
|
|
|
|
#else
|
|
|
|
/* If that's not possible due to config - use builtin mapping */
|
|
|
|
queue = &dev_data->queue_list[priority2queue(pkt_prio)];
|
|
|
|
#endif
|
2018-06-19 10:01:16 +02:00
|
|
|
|
|
|
|
tx_desc_list = &queue->tx_desc_list;
|
|
|
|
err_tx_flushed_count_at_entry = queue->err_tx_flushed_count;
|
|
|
|
|
2017-04-05 08:37:44 +02:00
|
|
|
frag = pkt->frags;
|
2019-01-18 21:33:03 +01:00
|
|
|
|
|
|
|
/* Keep reference to the descriptor */
|
|
|
|
tx_first_desc = &tx_desc_list->buf[tx_desc_list->head];
|
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
while (frag) {
|
2017-04-01 00:05:29 +02:00
|
|
|
frag_data = frag->data;
|
|
|
|
frag_len = frag->len;
|
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
/* Assure cache coherency before DMA read operation */
|
2020-05-27 11:26:57 -05:00
|
|
|
dcache_clean((uint32_t)frag_data, frag->size);
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
2017-03-15 01:30:35 +01:00
|
|
|
k_sem_take(&queue->tx_desc_sem, K_FOREVER);
|
|
|
|
|
|
|
|
/* The following section becomes critical and requires IRQ lock
|
|
|
|
* / unlock protection only due to the possibility of executing
|
|
|
|
* tx_error_handler() function.
|
|
|
|
*/
|
|
|
|
key = irq_lock();
|
|
|
|
|
|
|
|
/* Check if tx_error_handler() function was executed */
|
2018-05-07 16:15:39 +02:00
|
|
|
if (queue->err_tx_flushed_count !=
|
|
|
|
err_tx_flushed_count_at_entry) {
|
2017-03-15 01:30:35 +01:00
|
|
|
irq_unlock(key);
|
|
|
|
return -EIO;
|
|
|
|
}
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
2017-03-15 01:30:35 +01:00
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
tx_desc = &tx_desc_list->buf[tx_desc_list->head];
|
|
|
|
|
|
|
|
/* Update buffer descriptor address word */
|
2020-05-27 11:26:57 -05:00
|
|
|
tx_desc->w0 = (uint32_t)frag_data;
|
2018-06-08 12:50:47 +02:00
|
|
|
|
2019-01-18 21:33:03 +01:00
|
|
|
/* Update buffer descriptor status word (clear used bit except
|
|
|
|
* for the first frag).
|
2016-12-24 03:58:38 +01:00
|
|
|
*/
|
2018-12-08 01:49:12 +01:00
|
|
|
tx_desc->w1 = (frag_len & GMAC_TXW1_LEN)
|
|
|
|
| (!frag->frags ? GMAC_TXW1_LASTBUFFER : 0)
|
2019-03-26 19:57:45 -06:00
|
|
|
| (tx_desc_list->head == tx_desc_list->len - 1U
|
2018-12-08 01:49:12 +01:00
|
|
|
? GMAC_TXW1_WRAP : 0)
|
|
|
|
| (tx_desc == tx_first_desc ? GMAC_TXW1_USED : 0);
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
/* Update descriptor position */
|
|
|
|
MODULO_INC(tx_desc_list->head, tx_desc_list->len);
|
|
|
|
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
2016-12-24 03:58:38 +01:00
|
|
|
__ASSERT(tx_desc_list->head != tx_desc_list->tail,
|
|
|
|
"tx_desc_list overflow");
|
|
|
|
|
2019-02-06 21:33:19 +01:00
|
|
|
/* Account for a sent frag */
|
|
|
|
ring_buf_put(&queue->tx_frag_list, POINTER_TO_UINT(frag));
|
|
|
|
|
|
|
|
/* frag is internally queued, so it requires to hold a reference */
|
|
|
|
net_pkt_frag_ref(frag);
|
|
|
|
|
2017-03-15 01:30:35 +01:00
|
|
|
irq_unlock(key);
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
2017-03-15 01:30:35 +01:00
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
/* Continue with the rest of fragments (only data) */
|
|
|
|
frag = frag->frags;
|
|
|
|
}
|
|
|
|
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
2017-03-15 01:30:35 +01:00
|
|
|
key = irq_lock();
|
|
|
|
|
|
|
|
/* Check if tx_error_handler() function was executed */
|
|
|
|
if (queue->err_tx_flushed_count != err_tx_flushed_count_at_entry) {
|
|
|
|
irq_unlock(key);
|
|
|
|
return -EIO;
|
|
|
|
}
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
2017-03-15 01:30:35 +01:00
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
/* Ensure the descriptor following the last one is marked as used */
|
2018-12-08 01:49:12 +01:00
|
|
|
tx_desc_list->buf[tx_desc_list->head].w1 = GMAC_TXW1_USED;
|
2019-01-18 21:33:03 +01:00
|
|
|
|
|
|
|
/* Guarantee that all the fragments have been written before removing
|
|
|
|
* the used bit to avoid race condition.
|
|
|
|
*/
|
|
|
|
__DMB(); /* data memory barrier */
|
|
|
|
|
|
|
|
/* Remove the used bit of the first fragment to allow the controller
|
|
|
|
* to process it and the following fragments.
|
|
|
|
*/
|
2018-12-08 01:49:12 +01:00
|
|
|
tx_first_desc->w1 &= ~GMAC_TXW1_USED;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
2019-02-06 21:44:47 +01:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
2016-12-24 03:58:38 +01:00
|
|
|
/* Account for a sent frame */
|
2017-04-05 08:37:44 +02:00
|
|
|
ring_buf_put(&queue->tx_frames, POINTER_TO_UINT(pkt));
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2018-06-26 14:51:05 +02:00
|
|
|
/* pkt is internally queued, so it requires to hold a reference */
|
|
|
|
net_pkt_ref(pkt);
|
2019-02-06 21:44:47 +01:00
|
|
|
#endif
|
2018-06-26 14:51:05 +02:00
|
|
|
|
2019-01-26 01:11:10 +01:00
|
|
|
irq_unlock(key);
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
2019-01-26 01:11:10 +01:00
|
|
|
|
2019-01-18 21:33:03 +01:00
|
|
|
/* Guarantee that the first fragment got its bit removed before starting
|
|
|
|
* sending packets to avoid packets getting stuck.
|
|
|
|
*/
|
|
|
|
__DMB(); /* data memory barrier */
|
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
/* Start transmission */
|
|
|
|
gmac->GMAC_NCR |= GMAC_NCR_TSTART;
|
|
|
|
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 0
|
|
|
|
/* Wait until the packet is sent */
|
|
|
|
k_sem_take(&queue->tx_sem, K_FOREVER);
|
|
|
|
|
|
|
|
/* Check if transmit successful or not */
|
|
|
|
if (queue->err_tx_flushed_count != err_tx_flushed_count_at_entry) {
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
|
|
|
#if defined(CONFIG_NET_VLAN)
|
|
|
|
eth_hdr = NET_ETH_HDR(pkt);
|
|
|
|
if (ntohs(eth_hdr->type) == NET_ETH_PTYPE_VLAN) {
|
|
|
|
vlan_tag = net_pkt_vlan_tag(pkt);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
hdr = check_gptp_msg(get_iface(dev_data, vlan_tag), pkt, true);
|
|
|
|
timestamp_tx_pkt(gmac, hdr, pkt);
|
|
|
|
if (hdr && need_timestamping(hdr)) {
|
|
|
|
net_if_add_tx_timestamp(pkt);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
isr: Normalize usage of device instance through ISR
The goal of this patch is to replace the 'void *' parameter by 'struct
device *' if they use such variable or just 'const void *' on all
relevant ISRs
This will avoid not-so-nice const qualifier tweaks when device instances
will be constant.
Note that only the ISR passed to IRQ_CONNECT are of interest here.
In order to do so, the script fix_isr.py below is necessary:
from pathlib import Path
import subprocess
import pickle
import mmap
import sys
import re
import os
cocci_template = """
@r_fix_isr_0
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
...
(
const struct device *D = (const struct device *)P;
|
const struct device *D = P;
)
...
}
@r_fix_isr_1
@
type ret_type;
identifier P;
identifier D;
@@
-ret_type <!fn!>(void *P)
+ret_type <!fn!>(const struct device *P)
{
...
const struct device *D;
...
(
D = (const struct device *)P;
|
D = P;
)
...
}
@r_fix_isr_2
@
type ret_type;
identifier A;
@@
-ret_type <!fn!>(void *A)
+ret_type <!fn!>(const void *A)
{
...
}
@r_fix_isr_3
@
const struct device *D;
@@
-<!fn!>((void *)D);
+<!fn!>(D);
@r_fix_isr_4
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
...
(
-const struct device *D = (const struct device *)P;
|
-const struct device *D = P;
)
...
}
@r_fix_isr_5
@
type ret_type;
identifier D;
identifier P;
@@
-ret_type <!fn!>(const struct device *P)
+ret_type <!fn!>(const struct device *D)
{
...
-const struct device *D;
...
(
-D = (const struct device *)P;
|
-D = P;
)
...
}
"""
def find_isr(fn):
db = []
data = None
start = 0
try:
with open(fn, 'r+') as f:
data = str(mmap.mmap(f.fileno(), 0).read())
except Exception as e:
return db
while True:
isr = ""
irq = data.find('IRQ_CONNECT', start)
while irq > -1:
p = 1
arg = 1
p_o = data.find('(', irq)
if p_o < 0:
irq = -1
break;
pos = p_o + 1
while p > 0:
if data[pos] == ')':
p -= 1
elif data[pos] == '(':
p += 1
elif data[pos] == ',' and p == 1:
arg += 1
if arg == 3:
isr += data[pos]
pos += 1
isr = isr.strip(',\\n\\t ')
if isr not in db and len(isr) > 0:
db.append(isr)
start = pos
break
if irq < 0:
break
return db
def patch_isr(fn, isr_list):
if len(isr_list) <= 0:
return
for isr in isr_list:
tmplt = cocci_template.replace('<!fn!>', isr)
with open('/tmp/isr_fix.cocci', 'w') as f:
f.write(tmplt)
cmd = ['spatch', '--sp-file', '/tmp/isr_fix.cocci', '--in-place', fn]
subprocess.run(cmd)
def process_files(path):
if path.is_file() and path.suffix in ['.h', '.c']:
p = str(path.parent) + '/' + path.name
isr_list = find_isr(p)
patch_isr(p, isr_list)
elif path.is_dir():
for p in path.iterdir():
process_files(p)
if len(sys.argv) < 2:
print("You need to provide a dir/file path")
sys.exit(1)
process_files(Path(sys.argv[1]))
And is run: ./fix_isr.py <zephyr root directory>
Finally, some files needed manual fixes such.
Fixes #27399
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2020-06-17 14:58:56 +02:00
|
|
|
static void queue0_isr(const struct device *dev)
|
2016-12-24 03:58:38 +01:00
|
|
|
{
|
|
|
|
const struct eth_sam_dev_cfg *const cfg = DEV_CFG(dev);
|
|
|
|
struct eth_sam_dev_data *const dev_data = DEV_DATA(dev);
|
|
|
|
Gmac *gmac = cfg->regs;
|
2018-06-19 10:01:16 +02:00
|
|
|
struct gmac_queue *queue;
|
|
|
|
struct gmac_desc_list *rx_desc_list;
|
|
|
|
struct gmac_desc_list *tx_desc_list;
|
2018-06-08 12:50:47 +02:00
|
|
|
struct gmac_desc *tail_desc;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t isr;
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
/* Interrupt Status Register is cleared on read */
|
|
|
|
isr = gmac->GMAC_ISR;
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_DBG("GMAC_ISR=0x%08x", isr);
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2018-06-19 10:01:16 +02:00
|
|
|
queue = &dev_data->queue_list[0];
|
|
|
|
rx_desc_list = &queue->rx_desc_list;
|
|
|
|
tx_desc_list = &queue->tx_desc_list;
|
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
/* RX packet */
|
|
|
|
if (isr & GMAC_INT_RX_ERR_BITS) {
|
|
|
|
rx_error_handler(gmac, queue);
|
|
|
|
} else if (isr & GMAC_ISR_RCOMP) {
|
2018-06-19 10:01:16 +02:00
|
|
|
tail_desc = &rx_desc_list->buf[rx_desc_list->tail];
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_DBG("rx.w1=0x%08x, tail=%d",
|
2018-12-08 01:49:12 +01:00
|
|
|
tail_desc->w1,
|
2018-07-09 12:51:28 +03:00
|
|
|
rx_desc_list->tail);
|
2016-12-24 03:58:38 +01:00
|
|
|
eth_rx(queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TX packet */
|
|
|
|
if (isr & GMAC_INT_TX_ERR_BITS) {
|
|
|
|
tx_error_handler(gmac, queue);
|
|
|
|
} else if (isr & GMAC_ISR_TCOMP) {
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
2018-06-19 10:01:16 +02:00
|
|
|
tail_desc = &tx_desc_list->buf[tx_desc_list->tail];
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_DBG("tx.w1=0x%08x, tail=%d",
|
2018-12-08 01:49:12 +01:00
|
|
|
tail_desc->w1,
|
2018-07-09 12:51:28 +03:00
|
|
|
tx_desc_list->tail);
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
2018-06-19 10:01:16 +02:00
|
|
|
|
2019-01-18 21:33:03 +01:00
|
|
|
tx_completed(gmac, queue);
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isr & GMAC_IER_HRESP) {
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_DBG("IER HRESP");
|
2018-06-19 10:01:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 1
|
2020-07-14 17:02:00 +02:00
|
|
|
static inline void priority_queue_isr(const struct device *dev,
|
|
|
|
unsigned int queue_idx)
|
2018-06-19 10:01:16 +02:00
|
|
|
{
|
|
|
|
const struct eth_sam_dev_cfg *const cfg = DEV_CFG(dev);
|
|
|
|
struct eth_sam_dev_data *const dev_data = DEV_DATA(dev);
|
|
|
|
Gmac *gmac = cfg->regs;
|
|
|
|
struct gmac_queue *queue;
|
|
|
|
struct gmac_desc_list *rx_desc_list;
|
|
|
|
struct gmac_desc_list *tx_desc_list;
|
|
|
|
struct gmac_desc *tail_desc;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t isrpq;
|
2018-06-19 10:01:16 +02:00
|
|
|
|
|
|
|
isrpq = gmac->GMAC_ISRPQ[queue_idx - 1];
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_DBG("GMAC_ISRPQ%d=0x%08x", queue_idx - 1, isrpq);
|
2018-06-19 10:01:16 +02:00
|
|
|
|
|
|
|
queue = &dev_data->queue_list[queue_idx];
|
|
|
|
rx_desc_list = &queue->rx_desc_list;
|
|
|
|
tx_desc_list = &queue->tx_desc_list;
|
|
|
|
|
|
|
|
/* RX packet */
|
|
|
|
if (isrpq & GMAC_INTPQ_RX_ERR_BITS) {
|
|
|
|
rx_error_handler(gmac, queue);
|
|
|
|
} else if (isrpq & GMAC_ISRPQ_RCOMP) {
|
|
|
|
tail_desc = &rx_desc_list->buf[rx_desc_list->tail];
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_DBG("rx.w1=0x%08x, tail=%d",
|
2018-12-08 01:49:12 +01:00
|
|
|
tail_desc->w1,
|
2018-07-09 12:51:28 +03:00
|
|
|
rx_desc_list->tail);
|
2018-06-19 10:01:16 +02:00
|
|
|
eth_rx(queue);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* TX packet */
|
|
|
|
if (isrpq & GMAC_INTPQ_TX_ERR_BITS) {
|
|
|
|
tx_error_handler(gmac, queue);
|
|
|
|
} else if (isrpq & GMAC_ISRPQ_TCOMP) {
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
2018-06-19 10:01:16 +02:00
|
|
|
tail_desc = &tx_desc_list->buf[tx_desc_list->tail];
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_DBG("tx.w1=0x%08x, tail=%d",
|
2018-12-08 01:49:12 +01:00
|
|
|
tail_desc->w1,
|
2018-07-09 12:51:28 +03:00
|
|
|
tx_desc_list->tail);
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
2018-06-19 10:01:16 +02:00
|
|
|
|
2019-01-18 21:33:03 +01:00
|
|
|
tx_completed(gmac, queue);
|
2018-06-19 10:01:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isrpq & GMAC_IERPQ_HRESP) {
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_DBG("IERPQ%d HRESP", queue_idx - 1);
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
}
|
2018-06-19 10:01:16 +02:00
|
|
|
#endif
|
|
|
|
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 1
|
2020-07-14 17:02:00 +02:00
|
|
|
static void queue1_isr(const struct device *dev)
|
2018-06-19 10:01:16 +02:00
|
|
|
{
|
2020-07-14 17:02:00 +02:00
|
|
|
priority_queue_isr(dev, 1);
|
2018-06-19 10:01:16 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 2
|
2020-07-14 17:02:00 +02:00
|
|
|
static void queue2_isr(const struct device *dev)
|
2018-06-19 10:01:16 +02:00
|
|
|
{
|
2020-07-14 17:02:00 +02:00
|
|
|
priority_queue_isr(dev, 2);
|
2018-06-19 10:01:16 +02:00
|
|
|
}
|
|
|
|
#endif
|
2016-12-24 03:58:38 +01:00
|
|
|
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 3
|
2020-07-14 17:02:00 +02:00
|
|
|
static void queue3_isr(const struct device *dev)
|
2020-02-19 18:56:37 -03:00
|
|
|
{
|
2020-07-14 17:02:00 +02:00
|
|
|
priority_queue_isr(dev, 3);
|
2020-02-19 18:56:37 -03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 4
|
2020-07-14 17:02:00 +02:00
|
|
|
static void queue4_isr(const struct device *dev)
|
2020-02-19 18:56:37 -03:00
|
|
|
{
|
2020-07-14 17:02:00 +02:00
|
|
|
priority_queue_isr(dev, 4);
|
2020-02-19 18:56:37 -03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 5
|
2020-07-14 17:02:00 +02:00
|
|
|
static void queue5_isr(const struct device *dev)
|
2020-02-19 18:56:37 -03:00
|
|
|
{
|
2020-07-14 17:02:00 +02:00
|
|
|
priority_queue_isr(dev, 5);
|
2020-02-19 18:56:37 -03:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int eth_initialize(const struct device *dev)
|
2016-12-24 03:58:38 +01:00
|
|
|
{
|
|
|
|
const struct eth_sam_dev_cfg *const cfg = DEV_CFG(dev);
|
|
|
|
|
|
|
|
cfg->config_func();
|
|
|
|
|
2020-03-06 02:08:44 +09:00
|
|
|
#ifdef CONFIG_SOC_FAMILY_SAM
|
2016-12-24 03:58:38 +01:00
|
|
|
/* Enable GMAC module's clock */
|
|
|
|
soc_pmc_peripheral_enable(cfg->periph_id);
|
|
|
|
|
2017-04-05 11:14:50 +02:00
|
|
|
/* Connect pins to the peripheral */
|
|
|
|
soc_gpio_list_configure(cfg->pin_list, cfg->pin_list_size);
|
2020-03-06 02:08:44 +09:00
|
|
|
#else
|
|
|
|
/* Enable MCLK clock on GMAC */
|
|
|
|
MCLK->AHBMASK.reg |= MCLK_AHBMASK_GMAC;
|
|
|
|
*MCLK_GMAC |= MCLK_GMAC_MASK;
|
|
|
|
#endif
|
2017-04-05 11:14:50 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-04-22 21:47:58 +02:00
|
|
|
#ifdef CONFIG_ETH_SAM_GMAC_MAC_I2C_EEPROM
|
2020-05-27 11:26:57 -05:00
|
|
|
static void get_mac_addr_from_i2c_eeprom(uint8_t mac_addr[6])
|
2017-04-22 21:47:58 +02:00
|
|
|
{
|
2020-04-30 20:33:38 +02:00
|
|
|
const struct device *dev;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t iaddr = CONFIG_ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS;
|
2021-03-11 12:35:26 +00:00
|
|
|
int ret;
|
2017-04-22 21:47:58 +02:00
|
|
|
|
|
|
|
dev = device_get_binding(CONFIG_ETH_SAM_GMAC_MAC_I2C_DEV_NAME);
|
|
|
|
if (!dev) {
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_ERR("I2C: Device not found");
|
2017-04-22 21:47:58 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-11 12:35:26 +00:00
|
|
|
ret = i2c_write_read(dev, CONFIG_ETH_SAM_GMAC_MAC_I2C_SLAVE_ADDRESS,
|
|
|
|
&iaddr, CONFIG_ETH_SAM_GMAC_MAC_I2C_INT_ADDRESS_SIZE,
|
|
|
|
mac_addr, 6);
|
|
|
|
|
|
|
|
if (ret != 0) {
|
|
|
|
LOG_ERR("I2C: failed to read MAC addr");
|
|
|
|
return;
|
|
|
|
}
|
2017-04-22 21:47:58 +02:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
static void generate_mac(uint8_t mac_addr[6])
|
2018-09-27 16:51:49 +08:00
|
|
|
{
|
|
|
|
#if defined(CONFIG_ETH_SAM_GMAC_MAC_I2C_EEPROM)
|
|
|
|
get_mac_addr_from_i2c_eeprom(mac_addr);
|
2020-04-23 12:28:00 -05:00
|
|
|
#elif DT_INST_PROP(0, zephyr_random_mac_address)
|
|
|
|
gen_random_mac(mac_addr, ATMEL_OUI_B0, ATMEL_OUI_B1, ATMEL_OUI_B2);
|
2018-09-27 16:51:49 +08:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-03-11 23:24:56 +09:00
|
|
|
static void monitor_work_handler(struct k_work *work)
|
|
|
|
{
|
|
|
|
struct eth_sam_dev_data *const dev_data =
|
|
|
|
CONTAINER_OF(work, struct eth_sam_dev_data, monitor_work);
|
2020-04-30 20:33:38 +02:00
|
|
|
const struct device *dev = net_if_get_device(dev_data->iface);
|
2020-03-11 23:24:56 +09:00
|
|
|
const struct eth_sam_dev_cfg *const cfg = DEV_CFG(dev);
|
|
|
|
bool link_status;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t link_config;
|
2020-03-11 23:24:56 +09:00
|
|
|
int result;
|
|
|
|
|
|
|
|
/* Poll PHY link status */
|
|
|
|
link_status = phy_sam_gmac_link_status_get(&cfg->phy);
|
|
|
|
|
|
|
|
if (link_status && !dev_data->link_up) {
|
|
|
|
LOG_INF("Link up");
|
|
|
|
|
|
|
|
/* Announce link up status */
|
|
|
|
dev_data->link_up = true;
|
|
|
|
net_eth_carrier_on(dev_data->iface);
|
|
|
|
|
|
|
|
/* PHY auto-negotiate link parameters */
|
|
|
|
result = phy_sam_gmac_auto_negotiate(&cfg->phy, &link_config);
|
|
|
|
if (result < 0) {
|
|
|
|
LOG_ERR("ETH PHY auto-negotiate sequence failed");
|
|
|
|
goto finally;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up link parameters */
|
|
|
|
link_configure(cfg->regs, link_config);
|
|
|
|
} else if (!link_status && dev_data->link_up) {
|
|
|
|
LOG_INF("Link down");
|
|
|
|
|
|
|
|
/* Announce link down status */
|
|
|
|
dev_data->link_up = false;
|
|
|
|
net_eth_carrier_off(dev_data->iface);
|
|
|
|
}
|
|
|
|
|
|
|
|
finally:
|
|
|
|
/* Submit delayed work */
|
|
|
|
k_delayed_work_submit(&dev_data->monitor_work,
|
2020-05-01 20:37:25 +03:00
|
|
|
K_MSEC(CONFIG_ETH_SAM_GMAC_MONITOR_PERIOD));
|
2020-03-11 23:24:56 +09:00
|
|
|
}
|
|
|
|
|
2017-04-05 11:14:50 +02:00
|
|
|
static void eth0_iface_init(struct net_if *iface)
|
|
|
|
{
|
2020-04-30 20:33:38 +02:00
|
|
|
const struct device *dev = net_if_get_device(iface);
|
2017-04-05 11:14:50 +02:00
|
|
|
struct eth_sam_dev_data *const dev_data = DEV_DATA(dev);
|
|
|
|
const struct eth_sam_dev_cfg *const cfg = DEV_CFG(dev);
|
2018-03-21 17:04:10 +02:00
|
|
|
static bool init_done;
|
2020-05-27 11:26:57 -05:00
|
|
|
uint32_t gmac_ncfgr_val;
|
2017-04-05 11:14:50 +02:00
|
|
|
int result;
|
2018-06-19 10:01:16 +02:00
|
|
|
int i;
|
2017-04-05 11:14:50 +02:00
|
|
|
|
2020-01-29 13:19:09 +02:00
|
|
|
/* For VLAN, this value is only used to get the correct L2 driver.
|
|
|
|
* The iface pointer in context should contain the main interface
|
|
|
|
* if the VLANs are enabled.
|
|
|
|
*/
|
|
|
|
if (dev_data->iface == NULL) {
|
|
|
|
dev_data->iface = iface;
|
|
|
|
}
|
2017-04-05 11:14:50 +02:00
|
|
|
|
2018-03-21 17:04:10 +02:00
|
|
|
ethernet_init(iface);
|
|
|
|
|
|
|
|
/* The rest of initialization should only be done once */
|
|
|
|
if (init_done) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-06-19 13:12:53 +02:00
|
|
|
/* Check the status of data caches */
|
2020-02-19 23:49:01 -03:00
|
|
|
dcache_is_enabled();
|
2018-06-19 13:12:53 +02:00
|
|
|
|
2020-02-27 23:15:14 -03:00
|
|
|
/* Initialize GMAC driver */
|
2016-12-24 03:58:38 +01:00
|
|
|
gmac_ncfgr_val =
|
|
|
|
GMAC_NCFGR_MTIHEN /* Multicast Hash Enable */
|
|
|
|
| GMAC_NCFGR_LFERD /* Length Field Error Frame Discard */
|
|
|
|
| GMAC_NCFGR_RFCS /* Remove Frame Check Sequence */
|
2020-02-27 23:15:14 -03:00
|
|
|
| GMAC_NCFGR_RXCOEN /* Receive Checksum Offload Enable */
|
|
|
|
| GMAC_MAX_FRAME_SIZE;
|
2016-12-24 03:58:38 +01:00
|
|
|
result = gmac_init(cfg->regs, gmac_ncfgr_val);
|
|
|
|
if (result < 0) {
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_ERR("Unable to initialize ETH driver");
|
2017-04-05 11:14:50 +02:00
|
|
|
return;
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
|
2018-09-27 16:51:49 +08:00
|
|
|
generate_mac(dev_data->mac_addr);
|
2018-07-09 12:51:28 +03:00
|
|
|
|
2019-04-01 15:42:39 +02:00
|
|
|
LOG_INF("MAC: %02x:%02x:%02x:%02x:%02x:%02x",
|
2018-07-09 12:51:28 +03:00
|
|
|
dev_data->mac_addr[0], dev_data->mac_addr[1],
|
|
|
|
dev_data->mac_addr[2], dev_data->mac_addr[3],
|
|
|
|
dev_data->mac_addr[4], dev_data->mac_addr[5]);
|
2017-04-22 21:47:58 +02:00
|
|
|
|
2017-04-05 11:14:50 +02:00
|
|
|
/* Set MAC Address for frame filtering logic */
|
|
|
|
mac_addr_set(cfg->regs, 0, dev_data->mac_addr);
|
|
|
|
|
|
|
|
/* Register Ethernet MAC Address with the upper layer */
|
|
|
|
net_if_set_link_addr(iface, dev_data->mac_addr,
|
|
|
|
sizeof(dev_data->mac_addr),
|
|
|
|
NET_LINK_ETHERNET);
|
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
/* Initialize GMAC queues */
|
2020-02-19 18:56:37 -03:00
|
|
|
for (i = GMAC_QUE_0; i < GMAC_QUEUE_NUM; i++) {
|
2018-06-19 10:01:16 +02:00
|
|
|
result = queue_init(cfg->regs, &dev_data->queue_list[i]);
|
|
|
|
if (result < 0) {
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_ERR("Unable to initialize ETH queue%d", i);
|
2018-06-19 10:01:16 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 1
|
2019-03-04 13:21:20 +01:00
|
|
|
#if defined(CONFIG_ETH_SAM_GMAC_FORCE_QUEUE)
|
|
|
|
for (i = 0; i < CONFIG_NET_TC_RX_COUNT; ++i) {
|
|
|
|
cfg->regs->GMAC_ST1RPQ[i] =
|
|
|
|
GMAC_ST1RPQ_DSTCM(i) |
|
|
|
|
GMAC_ST1RPQ_QNB(CONFIG_ETH_SAM_GMAC_FORCED_QUEUE);
|
|
|
|
}
|
2020-02-19 18:56:37 -03:00
|
|
|
#elif GMAC_ACTIVE_QUEUE_NUM == NET_TC_RX_COUNT
|
2018-08-03 12:12:07 +02:00
|
|
|
/* If TC configuration is compatible with HW configuration, setup the
|
|
|
|
* screening registers based on the DS/TC values.
|
|
|
|
* Map them 1:1 - TC 0 -> Queue 0, TC 1 -> Queue 1 etc.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < CONFIG_NET_TC_RX_COUNT; ++i) {
|
|
|
|
cfg->regs->GMAC_ST1RPQ[i] =
|
|
|
|
GMAC_ST1RPQ_DSTCM(i) | GMAC_ST1RPQ_QNB(i);
|
|
|
|
}
|
|
|
|
#elif defined(CONFIG_NET_VLAN)
|
2018-06-19 10:01:16 +02:00
|
|
|
/* If VLAN is enabled, route packets according to VLAN priority */
|
|
|
|
int j;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
for (j = NET_PRIORITY_NC; j >= 0; --j) {
|
|
|
|
if (priority2queue(j) == 0) {
|
|
|
|
/* No point to set rules for the regular queue */
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2019-03-01 17:05:46 +01:00
|
|
|
if (i >= ARRAY_SIZE(cfg->regs->GMAC_ST2RPQ)) {
|
|
|
|
/* No more screening registers available */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-06-19 10:01:16 +02:00
|
|
|
cfg->regs->GMAC_ST2RPQ[i++] =
|
|
|
|
GMAC_ST2RPQ_QNB(priority2queue(j))
|
|
|
|
| GMAC_ST2RPQ_VLANP(j)
|
|
|
|
| GMAC_ST2RPQ_VLANE;
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
|
2018-06-19 10:01:16 +02:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2016-12-24 03:58:38 +01:00
|
|
|
/* PHY initialize */
|
|
|
|
result = phy_sam_gmac_init(&cfg->phy);
|
|
|
|
if (result < 0) {
|
2018-07-09 12:51:28 +03:00
|
|
|
LOG_ERR("ETH PHY Initialization Error");
|
2017-04-05 11:14:50 +02:00
|
|
|
return;
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
|
2020-03-11 23:24:56 +09:00
|
|
|
/* Initialise monitor */
|
|
|
|
k_delayed_work_init(&dev_data->monitor_work, monitor_work_handler);
|
|
|
|
k_delayed_work_submit(&dev_data->monitor_work,
|
2020-05-01 20:37:25 +03:00
|
|
|
K_MSEC(CONFIG_ETH_SAM_GMAC_MONITOR_PERIOD));
|
2020-03-11 23:24:56 +09:00
|
|
|
|
|
|
|
/* Do not start the interface until PHY link is up */
|
|
|
|
net_if_flag_set(iface, NET_IF_NO_AUTO_START);
|
2018-03-21 17:04:10 +02:00
|
|
|
|
|
|
|
init_done = true;
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static enum ethernet_hw_caps eth_sam_gmac_get_capabilities(const struct device *dev)
|
2018-03-21 17:04:10 +02:00
|
|
|
{
|
|
|
|
ARG_UNUSED(dev);
|
|
|
|
|
2018-04-06 10:57:13 +02:00
|
|
|
return ETHERNET_HW_VLAN | ETHERNET_LINK_10BASE_T |
|
2018-04-18 16:13:05 +02:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
|
|
|
ETHERNET_PTP |
|
|
|
|
#endif
|
2018-07-30 10:25:58 +02:00
|
|
|
ETHERNET_PRIORITY_QUEUES |
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 1
|
2018-07-30 11:26:00 +02:00
|
|
|
ETHERNET_QAV |
|
2018-08-08 12:21:04 +02:00
|
|
|
#endif
|
2018-04-06 10:57:13 +02:00
|
|
|
ETHERNET_LINK_100BASE_T;
|
2018-03-21 17:04:10 +02:00
|
|
|
}
|
|
|
|
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 1
|
2020-04-30 20:33:38 +02:00
|
|
|
static int eth_sam_gmac_set_qav_param(const struct device *dev,
|
2018-08-01 11:11:47 +02:00
|
|
|
enum ethernet_config_type type,
|
|
|
|
const struct ethernet_config *config)
|
2018-07-30 11:26:00 +02:00
|
|
|
{
|
|
|
|
const struct eth_sam_dev_cfg *const cfg = DEV_CFG(dev);
|
|
|
|
Gmac *gmac = cfg->regs;
|
2018-08-01 11:11:47 +02:00
|
|
|
enum ethernet_qav_param_type qav_param_type;
|
2018-07-30 11:26:00 +02:00
|
|
|
unsigned int delta_bandwidth;
|
|
|
|
unsigned int idle_slope;
|
2018-08-01 11:11:47 +02:00
|
|
|
int queue_id;
|
2018-07-31 09:38:08 +02:00
|
|
|
bool enable;
|
2018-07-30 11:26:00 +02:00
|
|
|
|
2018-08-01 11:11:47 +02:00
|
|
|
/* Priority queue IDs start from 1 for SAM GMAC */
|
|
|
|
queue_id = config->qav_param.queue_id + 1;
|
2018-07-31 09:38:08 +02:00
|
|
|
|
2018-08-01 11:11:47 +02:00
|
|
|
qav_param_type = config->qav_param.type;
|
2018-07-31 09:38:08 +02:00
|
|
|
|
2018-08-01 11:11:47 +02:00
|
|
|
switch (qav_param_type) {
|
|
|
|
case ETHERNET_QAV_PARAM_TYPE_STATUS:
|
|
|
|
enable = config->qav_param.enabled;
|
2018-07-31 09:38:08 +02:00
|
|
|
return eth_sam_gmac_setup_qav(gmac, queue_id, enable);
|
2018-08-01 11:11:47 +02:00
|
|
|
case ETHERNET_QAV_PARAM_TYPE_DELTA_BANDWIDTH:
|
|
|
|
delta_bandwidth = config->qav_param.delta_bandwidth;
|
2018-07-30 11:26:00 +02:00
|
|
|
|
|
|
|
return eth_sam_gmac_setup_qav_delta_bandwidth(gmac, queue_id,
|
|
|
|
delta_bandwidth);
|
2018-08-01 11:11:47 +02:00
|
|
|
case ETHERNET_QAV_PARAM_TYPE_IDLE_SLOPE:
|
|
|
|
idle_slope = config->qav_param.idle_slope;
|
2018-07-30 11:26:00 +02:00
|
|
|
|
2018-08-01 13:02:20 +02:00
|
|
|
/* The standard uses bps, SAM GMAC uses Bps - convert now */
|
2019-03-26 19:57:45 -06:00
|
|
|
idle_slope /= 8U;
|
2018-08-01 13:02:20 +02:00
|
|
|
|
2018-07-30 11:26:00 +02:00
|
|
|
return eth_sam_gmac_setup_qav_idle_slope(gmac, queue_id,
|
|
|
|
idle_slope);
|
|
|
|
default:
|
2018-08-01 11:11:47 +02:00
|
|
|
break;
|
2018-07-30 11:26:00 +02:00
|
|
|
}
|
2018-08-01 11:11:47 +02:00
|
|
|
|
|
|
|
return -ENOTSUP;
|
2018-07-30 11:26:00 +02:00
|
|
|
}
|
2018-08-08 12:21:04 +02:00
|
|
|
#endif
|
2018-07-30 11:26:00 +02:00
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int eth_sam_gmac_set_config(const struct device *dev,
|
2018-07-30 10:25:58 +02:00
|
|
|
enum ethernet_config_type type,
|
2018-08-01 11:11:47 +02:00
|
|
|
const struct ethernet_config *config)
|
|
|
|
{
|
|
|
|
switch (type) {
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 1
|
2018-08-01 11:11:47 +02:00
|
|
|
case ETHERNET_CONFIG_TYPE_QAV_PARAM:
|
|
|
|
return eth_sam_gmac_set_qav_param(dev, type, config);
|
2018-08-08 12:21:04 +02:00
|
|
|
#endif
|
2018-08-01 11:11:47 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
|
|
|
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 1
|
2020-04-30 20:33:38 +02:00
|
|
|
static int eth_sam_gmac_get_qav_param(const struct device *dev,
|
2018-08-01 11:11:47 +02:00
|
|
|
enum ethernet_config_type type,
|
|
|
|
struct ethernet_config *config)
|
2018-07-30 10:25:58 +02:00
|
|
|
{
|
2018-07-31 09:38:08 +02:00
|
|
|
const struct eth_sam_dev_cfg *const cfg = DEV_CFG(dev);
|
|
|
|
Gmac *gmac = cfg->regs;
|
2018-08-01 11:11:47 +02:00
|
|
|
enum ethernet_qav_param_type qav_param_type;
|
2018-07-31 09:38:08 +02:00
|
|
|
int queue_id;
|
|
|
|
bool *enabled;
|
2018-08-01 15:08:03 +02:00
|
|
|
unsigned int *idle_slope;
|
|
|
|
unsigned int *delta_bandwidth;
|
2018-07-31 09:38:08 +02:00
|
|
|
|
2018-08-01 11:11:47 +02:00
|
|
|
/* Priority queue IDs start from 1 for SAM GMAC */
|
|
|
|
queue_id = config->qav_param.queue_id + 1;
|
|
|
|
|
|
|
|
qav_param_type = config->qav_param.type;
|
|
|
|
|
|
|
|
switch (qav_param_type) {
|
|
|
|
case ETHERNET_QAV_PARAM_TYPE_STATUS:
|
|
|
|
enabled = &config->qav_param.enabled;
|
|
|
|
return eth_sam_gmac_get_qav_status(gmac, queue_id, enabled);
|
2018-08-01 15:08:03 +02:00
|
|
|
case ETHERNET_QAV_PARAM_TYPE_IDLE_SLOPE:
|
|
|
|
idle_slope = &config->qav_param.idle_slope;
|
|
|
|
return eth_sam_gmac_get_qav_idle_slope(gmac, queue_id,
|
|
|
|
idle_slope);
|
|
|
|
case ETHERNET_QAV_PARAM_TYPE_OPER_IDLE_SLOPE:
|
|
|
|
idle_slope = &config->qav_param.oper_idle_slope;
|
|
|
|
return eth_sam_gmac_get_qav_idle_slope(gmac, queue_id,
|
|
|
|
idle_slope);
|
|
|
|
case ETHERNET_QAV_PARAM_TYPE_DELTA_BANDWIDTH:
|
|
|
|
delta_bandwidth = &config->qav_param.delta_bandwidth;
|
|
|
|
return eth_sam_gmac_get_qav_delta_bandwidth(gmac, queue_id,
|
|
|
|
delta_bandwidth);
|
|
|
|
case ETHERNET_QAV_PARAM_TYPE_TRAFFIC_CLASS:
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_QUEUE_NUM == NET_TC_TX_COUNT
|
2018-08-01 15:08:03 +02:00
|
|
|
config->qav_param.traffic_class = queue_id;
|
|
|
|
return 0;
|
|
|
|
#else
|
|
|
|
/* Invalid configuration - no direct TC to queue mapping */
|
|
|
|
return -ENOTSUP;
|
|
|
|
#endif
|
2018-08-01 11:11:47 +02:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -ENOTSUP;
|
|
|
|
}
|
2018-08-08 12:21:04 +02:00
|
|
|
#endif
|
2018-08-01 11:11:47 +02:00
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int eth_sam_gmac_get_config(const struct device *dev,
|
2018-08-01 11:11:47 +02:00
|
|
|
enum ethernet_config_type type,
|
|
|
|
struct ethernet_config *config)
|
|
|
|
{
|
2018-07-30 10:25:58 +02:00
|
|
|
switch (type) {
|
|
|
|
case ETHERNET_CONFIG_TYPE_PRIORITY_QUEUES_NUM:
|
2020-02-19 18:56:37 -03:00
|
|
|
config->priority_queues_num = GMAC_ACTIVE_PRIORITY_QUEUE_NUM;
|
2018-08-01 11:11:47 +02:00
|
|
|
return 0;
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 1
|
2018-08-01 11:11:47 +02:00
|
|
|
case ETHERNET_CONFIG_TYPE_QAV_PARAM:
|
|
|
|
return eth_sam_gmac_get_qav_param(dev, type, config);
|
2018-08-08 12:21:04 +02:00
|
|
|
#endif
|
2018-07-30 10:25:58 +02:00
|
|
|
default:
|
2018-08-01 11:11:47 +02:00
|
|
|
break;
|
2018-07-30 10:25:58 +02:00
|
|
|
}
|
|
|
|
|
2018-08-01 11:11:47 +02:00
|
|
|
return -ENOTSUP;
|
2018-07-30 10:25:58 +02:00
|
|
|
}
|
|
|
|
|
2018-04-18 16:13:05 +02:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
2020-04-30 20:33:38 +02:00
|
|
|
static const struct device *eth_sam_gmac_get_ptp_clock(const struct device *dev)
|
2018-04-18 16:13:05 +02:00
|
|
|
{
|
|
|
|
struct eth_sam_dev_data *const dev_data = DEV_DATA(dev);
|
|
|
|
|
|
|
|
return dev_data->ptp_clock;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-03-27 12:29:33 +02:00
|
|
|
static const struct ethernet_api eth_api = {
|
2018-03-14 10:55:19 +02:00
|
|
|
.iface_api.init = eth0_iface_init,
|
2018-03-21 17:04:10 +02:00
|
|
|
|
2018-03-27 12:29:33 +02:00
|
|
|
.get_capabilities = eth_sam_gmac_get_capabilities,
|
2018-07-30 11:26:00 +02:00
|
|
|
.set_config = eth_sam_gmac_set_config,
|
2018-07-30 10:25:58 +02:00
|
|
|
.get_config = eth_sam_gmac_get_config,
|
2018-06-26 14:51:05 +02:00
|
|
|
.send = eth_tx,
|
2018-04-18 16:13:05 +02:00
|
|
|
|
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
|
|
|
.get_ptp_clock = eth_sam_gmac_get_ptp_clock,
|
|
|
|
#endif
|
2016-12-24 03:58:38 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static void eth0_irq_config(void)
|
|
|
|
{
|
2020-03-29 03:20:08 +09:00
|
|
|
IRQ_CONNECT(DT_INST_IRQ_BY_NAME(0, gmac, irq),
|
|
|
|
DT_INST_IRQ_BY_NAME(0, gmac, priority),
|
2020-12-16 11:17:24 -06:00
|
|
|
queue0_isr, DEVICE_DT_INST_GET(0), 0);
|
2020-03-29 03:20:08 +09:00
|
|
|
irq_enable(DT_INST_IRQ_BY_NAME(0, gmac, irq));
|
2018-06-19 10:01:16 +02:00
|
|
|
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 1
|
2020-03-29 03:20:08 +09:00
|
|
|
IRQ_CONNECT(DT_INST_IRQ_BY_NAME(0, q1, irq),
|
|
|
|
DT_INST_IRQ_BY_NAME(0, q1, priority),
|
2020-12-16 11:17:24 -06:00
|
|
|
queue1_isr, DEVICE_DT_INST_GET(0), 0);
|
2020-03-29 03:20:08 +09:00
|
|
|
irq_enable(DT_INST_IRQ_BY_NAME(0, q1, irq));
|
2018-06-19 10:01:16 +02:00
|
|
|
#endif
|
|
|
|
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 2
|
2020-03-29 03:20:08 +09:00
|
|
|
IRQ_CONNECT(DT_INST_IRQ_BY_NAME(0, q2, irq),
|
|
|
|
DT_INST_IRQ_BY_NAME(0, q1, priority),
|
2020-12-16 11:17:24 -06:00
|
|
|
queue2_isr, DEVICE_DT_INST_GET(0), 0);
|
2020-03-29 03:20:08 +09:00
|
|
|
irq_enable(DT_INST_IRQ_BY_NAME(0, q2, irq));
|
2018-06-19 10:01:16 +02:00
|
|
|
#endif
|
2020-02-19 18:56:37 -03:00
|
|
|
|
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 3
|
2020-03-29 03:20:08 +09:00
|
|
|
IRQ_CONNECT(DT_INST_IRQ_BY_NAME(0, q3, irq),
|
|
|
|
DT_INST_IRQ_BY_NAME(0, q3, priority),
|
2020-12-16 11:17:24 -06:00
|
|
|
queue3_isr, DEVICE_DT_INST_GET(0), 0);
|
2020-03-29 03:20:08 +09:00
|
|
|
irq_enable(DT_INST_IRQ_BY_NAME(0, q3, irq));
|
2020-02-19 18:56:37 -03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 4
|
2020-03-29 03:20:08 +09:00
|
|
|
IRQ_CONNECT(DT_INST_IRQ_BY_NAME(0, q4, irq),
|
|
|
|
DT_INST_IRQ_BY_NAME(0, q4, priority),
|
2020-12-16 11:17:24 -06:00
|
|
|
queue4_isr, DEVICE_DT_INST_GET(0), 0);
|
2020-03-29 03:20:08 +09:00
|
|
|
irq_enable(DT_INST_IRQ_BY_NAME(0, q4, irq));
|
2020-02-19 18:56:37 -03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 5
|
2020-03-29 03:20:08 +09:00
|
|
|
IRQ_CONNECT(DT_INST_IRQ_BY_NAME(0, q5, irq),
|
|
|
|
DT_INST_IRQ_BY_NAME(0, q5, priority),
|
2020-12-16 11:17:24 -06:00
|
|
|
queue5_isr, DEVICE_DT_INST_GET(0), 0);
|
2020-03-29 03:20:08 +09:00
|
|
|
irq_enable(DT_INST_IRQ_BY_NAME(0, q5, irq));
|
2020-02-19 18:56:37 -03:00
|
|
|
#endif
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
|
2020-03-06 02:08:44 +09:00
|
|
|
#ifdef CONFIG_SOC_FAMILY_SAM
|
2020-04-30 13:25:19 -05:00
|
|
|
static const struct soc_gpio_pin pins_eth0[] = ATMEL_SAM_DT_PINS(0);
|
2020-03-06 02:08:44 +09:00
|
|
|
#endif
|
2016-12-24 03:58:38 +01:00
|
|
|
|
|
|
|
static const struct eth_sam_dev_cfg eth0_config = {
|
|
|
|
.regs = GMAC,
|
|
|
|
.periph_id = ID_GMAC,
|
2020-03-06 02:08:44 +09:00
|
|
|
#ifdef CONFIG_SOC_FAMILY_SAM
|
2016-12-24 03:58:38 +01:00
|
|
|
.pin_list = pins_eth0,
|
|
|
|
.pin_list_size = ARRAY_SIZE(pins_eth0),
|
2020-03-06 02:08:44 +09:00
|
|
|
#endif
|
2016-12-24 03:58:38 +01:00
|
|
|
.config_func = eth0_irq_config,
|
|
|
|
.phy = {GMAC, CONFIG_ETH_SAM_GMAC_PHY_ADDR},
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct eth_sam_dev_data eth0_data = {
|
2020-04-23 12:37:38 -05:00
|
|
|
#if NODE_HAS_VALID_MAC_ADDR(DT_DRV_INST(0))
|
2020-03-29 03:20:08 +09:00
|
|
|
.mac_addr = DT_INST_PROP(0, local_mac_address),
|
2017-04-22 21:47:58 +02:00
|
|
|
#endif
|
2020-02-19 18:56:37 -03:00
|
|
|
.queue_list = {
|
|
|
|
{
|
2016-12-24 03:58:38 +01:00
|
|
|
.que_idx = GMAC_QUE_0,
|
|
|
|
.rx_desc_list = {
|
|
|
|
.buf = rx_desc_que0,
|
|
|
|
.len = ARRAY_SIZE(rx_desc_que0),
|
|
|
|
},
|
|
|
|
.tx_desc_list = {
|
|
|
|
.buf = tx_desc_que0,
|
|
|
|
.len = ARRAY_SIZE(tx_desc_que0),
|
|
|
|
},
|
2019-02-08 01:06:01 +01:00
|
|
|
.rx_frag_list = rx_frag_list_que0,
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
2019-02-06 21:33:19 +01:00
|
|
|
.tx_frag_list = {
|
2020-05-27 11:26:57 -05:00
|
|
|
.buf = (uint32_t *)tx_frag_list_que0,
|
2019-02-06 21:33:19 +01:00
|
|
|
.len = ARRAY_SIZE(tx_frag_list_que0),
|
|
|
|
},
|
2019-02-06 21:44:47 +01:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
2016-12-24 03:58:38 +01:00
|
|
|
.tx_frames = {
|
2020-05-27 11:26:57 -05:00
|
|
|
.buf = (uint32_t *)tx_frame_list_que0,
|
2016-12-24 03:58:38 +01:00
|
|
|
.len = ARRAY_SIZE(tx_frame_list_que0),
|
|
|
|
},
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
2019-02-06 21:44:47 +01:00
|
|
|
#endif
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_PRIORITY_QUEUE_NUM >= 1
|
2016-12-24 03:58:38 +01:00
|
|
|
}, {
|
|
|
|
.que_idx = GMAC_QUE_1,
|
|
|
|
.rx_desc_list = {
|
2018-06-19 10:01:16 +02:00
|
|
|
.buf = rx_desc_que1,
|
|
|
|
.len = ARRAY_SIZE(rx_desc_que1),
|
2016-12-24 03:58:38 +01:00
|
|
|
},
|
|
|
|
.tx_desc_list = {
|
2018-06-19 10:01:16 +02:00
|
|
|
.buf = tx_desc_que1,
|
|
|
|
.len = ARRAY_SIZE(tx_desc_que1),
|
|
|
|
},
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 1
|
2019-02-08 01:06:01 +01:00
|
|
|
.rx_frag_list = rx_frag_list_que1,
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
2019-02-06 21:33:19 +01:00
|
|
|
.tx_frag_list = {
|
2020-05-27 11:26:57 -05:00
|
|
|
.buf = (uint32_t *)tx_frag_list_que1,
|
2019-02-06 21:33:19 +01:00
|
|
|
.len = ARRAY_SIZE(tx_frag_list_que1),
|
|
|
|
},
|
2019-02-06 21:44:47 +01:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
2018-06-19 10:01:16 +02:00
|
|
|
.tx_frames = {
|
2020-05-27 11:26:57 -05:00
|
|
|
.buf = (uint32_t *)tx_frame_list_que1,
|
2018-06-19 10:01:16 +02:00
|
|
|
.len = ARRAY_SIZE(tx_frame_list_que1),
|
|
|
|
}
|
2019-02-06 21:44:47 +01:00
|
|
|
#endif
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
2018-06-19 10:01:16 +02:00
|
|
|
#endif
|
2020-02-19 18:56:37 -03:00
|
|
|
#endif
|
|
|
|
#if GMAC_PRIORITY_QUEUE_NUM >= 2
|
2016-12-24 03:58:38 +01:00
|
|
|
}, {
|
|
|
|
.que_idx = GMAC_QUE_2,
|
|
|
|
.rx_desc_list = {
|
2018-06-19 10:01:16 +02:00
|
|
|
.buf = rx_desc_que2,
|
|
|
|
.len = ARRAY_SIZE(rx_desc_que2),
|
2016-12-24 03:58:38 +01:00
|
|
|
},
|
|
|
|
.tx_desc_list = {
|
2018-06-19 10:01:16 +02:00
|
|
|
.buf = tx_desc_que2,
|
|
|
|
.len = ARRAY_SIZE(tx_desc_que2),
|
2016-12-24 03:58:38 +01:00
|
|
|
},
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 2
|
2019-02-08 01:06:01 +01:00
|
|
|
.rx_frag_list = rx_frag_list_que2,
|
2019-02-12 22:21:06 +01:00
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
2019-02-06 21:33:19 +01:00
|
|
|
.tx_frag_list = {
|
2020-05-27 11:26:57 -05:00
|
|
|
.buf = (uint32_t *)tx_frag_list_que2,
|
2019-02-06 21:33:19 +01:00
|
|
|
.len = ARRAY_SIZE(tx_frag_list_que2),
|
|
|
|
},
|
2019-02-06 21:44:47 +01:00
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
2018-06-19 10:01:16 +02:00
|
|
|
.tx_frames = {
|
2020-05-27 11:26:57 -05:00
|
|
|
.buf = (uint32_t *)tx_frame_list_que2,
|
2018-06-19 10:01:16 +02:00
|
|
|
.len = ARRAY_SIZE(tx_frame_list_que2),
|
|
|
|
}
|
2019-02-06 21:44:47 +01:00
|
|
|
#endif
|
2019-02-12 22:21:06 +01:00
|
|
|
#endif
|
2019-01-11 18:50:42 +01:00
|
|
|
#endif
|
2020-02-19 18:56:37 -03:00
|
|
|
#endif
|
|
|
|
#if GMAC_PRIORITY_QUEUE_NUM >= 3
|
2019-01-11 18:50:42 +01:00
|
|
|
}, {
|
|
|
|
.que_idx = GMAC_QUE_3,
|
|
|
|
.rx_desc_list = {
|
|
|
|
.buf = rx_desc_que3,
|
|
|
|
.len = ARRAY_SIZE(rx_desc_que3),
|
|
|
|
},
|
|
|
|
.tx_desc_list = {
|
|
|
|
.buf = tx_desc_que3,
|
|
|
|
.len = ARRAY_SIZE(tx_desc_que3),
|
|
|
|
},
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 3
|
|
|
|
.rx_frag_list = rx_frag_list_que3,
|
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
|
|
|
.tx_frag_list = {
|
2020-05-27 11:26:57 -05:00
|
|
|
.buf = (uint32_t *)tx_frag_list_que3,
|
2020-02-19 18:56:37 -03:00
|
|
|
.len = ARRAY_SIZE(tx_frag_list_que3),
|
|
|
|
},
|
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
|
|
|
.tx_frames = {
|
2020-05-27 11:26:57 -05:00
|
|
|
.buf = (uint32_t *)tx_frame_list_que3,
|
2020-02-19 18:56:37 -03:00
|
|
|
.len = ARRAY_SIZE(tx_frame_list_que3),
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if GMAC_PRIORITY_QUEUE_NUM >= 4
|
2019-01-11 18:50:42 +01:00
|
|
|
}, {
|
|
|
|
.que_idx = GMAC_QUE_4,
|
|
|
|
.rx_desc_list = {
|
|
|
|
.buf = rx_desc_que4,
|
|
|
|
.len = ARRAY_SIZE(rx_desc_que4),
|
|
|
|
},
|
|
|
|
.tx_desc_list = {
|
|
|
|
.buf = tx_desc_que4,
|
|
|
|
.len = ARRAY_SIZE(tx_desc_que4),
|
|
|
|
},
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 4
|
|
|
|
.rx_frag_list = rx_frag_list_que4,
|
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
|
|
|
.tx_frag_list = {
|
2020-05-27 11:26:57 -05:00
|
|
|
.buf = (uint32_t *)tx_frag_list_que4,
|
2020-02-19 18:56:37 -03:00
|
|
|
.len = ARRAY_SIZE(tx_frag_list_que4),
|
|
|
|
},
|
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
|
|
|
.tx_frames = {
|
2020-05-27 11:26:57 -05:00
|
|
|
.buf = (uint32_t *)tx_frame_list_que4,
|
2020-02-19 18:56:37 -03:00
|
|
|
.len = ARRAY_SIZE(tx_frame_list_que4),
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#if GMAC_PRIORITY_QUEUE_NUM >= 5
|
2019-01-11 18:50:42 +01:00
|
|
|
}, {
|
|
|
|
.que_idx = GMAC_QUE_5,
|
|
|
|
.rx_desc_list = {
|
|
|
|
.buf = rx_desc_que5,
|
|
|
|
.len = ARRAY_SIZE(rx_desc_que5),
|
|
|
|
},
|
|
|
|
.tx_desc_list = {
|
|
|
|
.buf = tx_desc_que5,
|
|
|
|
.len = ARRAY_SIZE(tx_desc_que5),
|
|
|
|
},
|
2020-02-19 18:56:37 -03:00
|
|
|
#if GMAC_ACTIVE_PRIORITY_QUEUE_NUM >= 5
|
|
|
|
.rx_frag_list = rx_frag_list_que5,
|
|
|
|
#if GMAC_MULTIPLE_TX_PACKETS == 1
|
|
|
|
.tx_frag_list = {
|
2020-05-27 11:26:57 -05:00
|
|
|
.buf = (uint32_t *)tx_frag_list_que5,
|
2020-02-19 18:56:37 -03:00
|
|
|
.len = ARRAY_SIZE(tx_frag_list_que5),
|
|
|
|
},
|
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
|
|
|
.tx_frames = {
|
2020-05-27 11:26:57 -05:00
|
|
|
.buf = (uint32_t *)tx_frame_list_que5,
|
2020-02-19 18:56:37 -03:00
|
|
|
.len = ARRAY_SIZE(tx_frame_list_que5),
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#endif
|
2018-06-19 10:01:16 +02:00
|
|
|
#endif
|
2016-12-24 03:58:38 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2020-12-16 11:17:24 -06:00
|
|
|
ETH_NET_DEVICE_DT_INST_DEFINE(0,
|
2020-02-26 22:56:10 +09:00
|
|
|
eth_initialize, device_pm_control_nop, ð0_data,
|
|
|
|
ð0_config, CONFIG_ETH_INIT_PRIORITY, ð_api,
|
|
|
|
GMAC_MTU);
|
2018-04-18 16:13:05 +02:00
|
|
|
|
|
|
|
#if defined(CONFIG_PTP_CLOCK_SAM_GMAC)
|
|
|
|
struct ptp_context {
|
2020-04-30 20:33:38 +02:00
|
|
|
const struct device *eth_dev;
|
2018-04-18 16:13:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct ptp_context ptp_gmac_0_context;
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int ptp_clock_sam_gmac_set(const struct device *dev,
|
2018-04-18 16:13:05 +02:00
|
|
|
struct net_ptp_time *tm)
|
|
|
|
{
|
2020-05-28 21:23:02 +02:00
|
|
|
struct ptp_context *ptp_context = dev->data;
|
2018-04-18 16:13:05 +02:00
|
|
|
const struct eth_sam_dev_cfg *const cfg = DEV_CFG(ptp_context->eth_dev);
|
|
|
|
Gmac *gmac = cfg->regs;
|
|
|
|
|
|
|
|
gmac->GMAC_TSH = tm->_sec.high & 0xffff;
|
|
|
|
gmac->GMAC_TSL = tm->_sec.low & 0xffffffff;
|
|
|
|
gmac->GMAC_TN = tm->nanosecond & 0xffffffff;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int ptp_clock_sam_gmac_get(const struct device *dev,
|
2018-04-18 16:13:05 +02:00
|
|
|
struct net_ptp_time *tm)
|
|
|
|
{
|
2020-05-28 21:23:02 +02:00
|
|
|
struct ptp_context *ptp_context = dev->data;
|
2018-04-18 16:13:05 +02:00
|
|
|
const struct eth_sam_dev_cfg *const cfg = DEV_CFG(ptp_context->eth_dev);
|
|
|
|
Gmac *gmac = cfg->regs;
|
|
|
|
|
2020-05-27 11:26:57 -05:00
|
|
|
tm->second = ((uint64_t)(gmac->GMAC_TSH & 0xffff) << 32) | gmac->GMAC_TSL;
|
2018-04-18 16:13:05 +02:00
|
|
|
tm->nanosecond = gmac->GMAC_TN;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int ptp_clock_sam_gmac_adjust(const struct device *dev, int increment)
|
2018-04-18 16:13:05 +02:00
|
|
|
{
|
2020-05-28 21:23:02 +02:00
|
|
|
struct ptp_context *ptp_context = dev->data;
|
2018-04-18 16:13:05 +02:00
|
|
|
const struct eth_sam_dev_cfg *const cfg = DEV_CFG(ptp_context->eth_dev);
|
|
|
|
Gmac *gmac = cfg->regs;
|
|
|
|
|
|
|
|
if ((increment <= -NSEC_PER_SEC) || (increment >= NSEC_PER_SEC)) {
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (increment < 0) {
|
2020-02-26 01:26:35 +09:00
|
|
|
gmac->GMAC_TA = GMAC_TA_ADJ | GMAC_TA_ITDT(-increment);
|
2018-04-18 16:13:05 +02:00
|
|
|
} else {
|
2020-02-26 01:26:35 +09:00
|
|
|
gmac->GMAC_TA = GMAC_TA_ITDT(increment);
|
2018-04-18 16:13:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int ptp_clock_sam_gmac_rate_adjust(const struct device *dev,
|
|
|
|
float ratio)
|
2018-04-18 16:13:05 +02:00
|
|
|
{
|
2018-08-30 12:09:17 +02:00
|
|
|
return -ENOTSUP;
|
2018-04-18 16:13:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ptp_clock_driver_api ptp_api = {
|
|
|
|
.set = ptp_clock_sam_gmac_set,
|
|
|
|
.get = ptp_clock_sam_gmac_get,
|
|
|
|
.adjust = ptp_clock_sam_gmac_adjust,
|
|
|
|
.rate_adjust = ptp_clock_sam_gmac_rate_adjust,
|
|
|
|
};
|
|
|
|
|
2020-04-30 20:33:38 +02:00
|
|
|
static int ptp_gmac_init(const struct device *port)
|
2018-04-18 16:13:05 +02:00
|
|
|
{
|
2020-12-16 11:17:24 -06:00
|
|
|
const struct device *eth_dev = DEVICE_DT_INST_GET(0);
|
2020-05-28 21:23:02 +02:00
|
|
|
struct eth_sam_dev_data *dev_data = eth_dev->data;
|
|
|
|
struct ptp_context *ptp_context = port->data;
|
2018-04-18 16:13:05 +02:00
|
|
|
|
|
|
|
dev_data->ptp_clock = port;
|
|
|
|
ptp_context->eth_dev = eth_dev;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-18 08:53:15 -06:00
|
|
|
DEVICE_DEFINE(gmac_ptp_clock_0, PTP_CLOCK_NAME, ptp_gmac_init,
|
|
|
|
device_pm_control_nop, &ptp_gmac_0_context, NULL, POST_KERNEL,
|
|
|
|
CONFIG_APPLICATION_INIT_PRIORITY, &ptp_api);
|
2018-04-18 16:13:05 +02:00
|
|
|
|
|
|
|
#endif /* CONFIG_PTP_CLOCK_SAM_GMAC */
|