// SPDX-License-Identifier: GPL-2.0
#define pr_fmt(fmt) "bcmasp_intf: " fmt
#include <asm/byteorder.h>
#include <linux/brcmphy.h>
#include <linux/clk.h>
#include <linux/delay.h>
#include <linux/etherdevice.h>
#include <linux/netdevice.h>
#include <linux/of_net.h>
#include <linux/of_mdio.h>
#include <linux/phy.h>
#include <linux/phy_fixed.h>
#include <linux/ptp_classify.h>
#include <linux/platform_device.h>
#include <net/ip.h>
#include <net/ipv6.h>
#include "bcmasp.h"
#include "bcmasp_intf_defs.h"
static int incr_ring(int index, int ring_count)
{
index++;
if (index == ring_count)
return 0;
return index;
}
/* Points to last byte of descriptor */
static dma_addr_t incr_last_byte(dma_addr_t addr, dma_addr_t beg,
int ring_count)
{
dma_addr_t end = beg + (ring_count * DESC_SIZE);
addr += DESC_SIZE;
if (addr > end)
return beg + DESC_SIZE - 1;
return addr;
}
/* Points to first byte of descriptor */
static dma_addr_t incr_first_byte(dma_addr_t addr, dma_addr_t beg,
int ring_count)
{
dma_addr_t end = beg + (ring_count * DESC_SIZE);
addr += DESC_SIZE;
if (addr >= end)
return beg;
return addr;
}
static void bcmasp_enable_tx(struct bcmasp_intf *intf, int en)
{
if (en) {
tx_spb_ctrl_wl(intf, TX_SPB_CTRL_ENABLE_EN, TX_SPB_CTRL_ENABLE);
tx_epkt_core_wl(intf, (TX_EPKT_C_CFG_MISC_EN |
TX_EPKT_C_CFG_MISC_PT |
(intf->port << TX_EPKT_C_CFG_MISC_PS_SHIFT)),
TX_EPKT_C_CFG_MISC);
} else {