Skip to content

Commit

Permalink
ramips: mt7621: add kernel 5.10 support with mtk_hnat
Browse files Browse the repository at this point in the history
  • Loading branch information
aiamadeus committed May 8, 2023
1 parent 0db2337 commit ef12a97
Show file tree
Hide file tree
Showing 17 changed files with 460 additions and 70 deletions.
8 changes: 0 additions & 8 deletions package/kernel/mt76/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,9 @@ PKG_LICENSE_FILES:=

PKG_SOURCE_URL:=https://github.com/openwrt/mt76
PKG_SOURCE_PROTO:=git

ifdef CONFIG_LINUX_5_4
PKG_SOURCE_DATE:=2022-12-22
PKG_SOURCE_VERSION:=5b509e80384ab019ac11aa90c81ec0dbb5b0d7f2
PKG_MIRROR_HASH:=6fc25df4d28becd010ff4971b23731c08b53e69381a9e4c868091899712f78a9
PATCH_DIR:=./patches-5.4
else
PKG_SOURCE_DATE:=2023-04-18
PKG_SOURCE_VERSION:=cddbd796bbc649debe457f7b34b200bbda4fcc53
PKG_MIRROR_HASH:=3c9e24863f3e045dbab1d05cf760ef0f4a21106766987558ce4df6c0964df11a
endif

PKG_MAINTAINER:=Felix Fietkau <nbd@nbd.name>
PKG_USE_NINJA:=0
Expand Down
4 changes: 2 additions & 2 deletions target/linux/ramips/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ BOARDNAME:=MediaTek Ralink MIPS
SUBTARGETS:=mt7620 mt7621 mt76x8 rt288x rt305x rt3883
FEATURES:=squashfs gpio boot-part rootfs-part

KERNEL_PATCHVER:=5.4
KERNEL_TESTING_PATCHVER:=5.10
KERNEL_PATCHVER:=5.10
KERNEL_TESTING_PATCHVER:=5.15

define Target/Description
Build firmware images for Ralink RT288x/RT3xxx based boards.
Expand Down
8 changes: 4 additions & 4 deletions target/linux/ramips/files/drivers/net/ethernet/mtk/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,28 @@
config NET_VENDOR_RAW_MEDIATEK
bool "MediaTek ethernet driver"
depends on ARCH_MEDIATEK || SOC_MT7621 || SOC_MT7620
---help---
help
If you have a Mediatek SoC with ethernet, say Y.

if NET_VENDOR_RAW_MEDIATEK

config NET_MEDIATEK_SOC_GE
tristate "MediaTek SoC Gigabit Ethernet support"
select PHYLINK
---help---
help
This driver supports the gigabit ethernet MACs in the
MediaTek SoC family.

config MEDIATEK_NETSYS_V2
tristate "MediaTek Ethernet NETSYS V2 support"
depends on ARCH_MEDIATEK && NET_MEDIATEK_SOC_GE
---help---
help
This options enable MTK Ethernet NETSYS V2 support

config NET_MEDIATEK_HNAT
tristate "MediaTek HW NAT support"
depends on NET_MEDIATEK_SOC_GE && NF_CONNTRACK && IP_NF_NAT
---help---
help
This driver supports the hardward Network Address Translation
in the MediaTek MT2701/MT7622/MT7629/MT7621 chipset family.

Expand Down
76 changes: 76 additions & 0 deletions target/linux/ramips/files/drivers/net/ethernet/mtk/mtk_eth_dbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <linux/ctype.h>
#include <linux/debugfs.h>
#include <linux/of_mdio.h>
#include <linux/version.h>

#include "mtk_eth_soc.h"
#include "mtk_eth_dbg.h"
Expand Down Expand Up @@ -610,13 +611,22 @@ static int switch_count_open(struct inode *inode, struct file *file)
return single_open(file, esw_cnt_read, 0);
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
static const struct file_operations switch_count_fops = {
.owner = THIS_MODULE,
.open = switch_count_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release
};
#else
static const struct proc_ops switch_count_fops = {
.proc_open = switch_count_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_release = single_release
};
#endif

static struct proc_dir_entry *proc_tx_ring, *proc_hwtx_ring, *proc_rx_ring;

Expand Down Expand Up @@ -662,13 +672,22 @@ static int tx_ring_open(struct inode *inode, struct file *file)
return single_open(file, tx_ring_read, NULL);
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
static const struct file_operations tx_ring_fops = {
.owner = THIS_MODULE,
.open = tx_ring_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release
};
#else
static const struct proc_ops tx_ring_fops = {
.proc_open = tx_ring_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_release = single_release
};
#endif

int hwtx_ring_read(struct seq_file *seq, void *v)
{
Expand Down Expand Up @@ -709,13 +728,22 @@ static int hwtx_ring_open(struct inode *inode, struct file *file)
return single_open(file, hwtx_ring_read, NULL);
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
static const struct file_operations hwtx_ring_fops = {
.owner = THIS_MODULE,
.open = hwtx_ring_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release
};
#else
static const struct proc_ops hwtx_ring_fops = {
.proc_open = hwtx_ring_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_release = single_release
};
#endif

int rx_ring_read(struct seq_file *seq, void *v)
{
Expand Down Expand Up @@ -757,13 +785,22 @@ static int rx_ring_open(struct inode *inode, struct file *file)
return single_open(file, rx_ring_read, NULL);
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
static const struct file_operations rx_ring_fops = {
.owner = THIS_MODULE,
.open = rx_ring_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release
};
#else
static const struct proc_ops rx_ring_fops = {
.proc_open = rx_ring_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_release = single_release
};
#endif

static inline u32 mtk_dbg_r32(u32 reg)
{
Expand Down Expand Up @@ -885,13 +922,22 @@ static int dbg_regs_open(struct inode *inode, struct file *file)
return single_open(file, dbg_regs_read, 0);
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
static const struct file_operations dbg_regs_fops = {
.owner = THIS_MODULE,
.open = dbg_regs_open,
.read = seq_read,
.llseek = seq_lseek,
.release = single_release
};
#else
static const struct proc_ops dbg_regs_fops = {
.proc_open = dbg_regs_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_release = single_release
};
#endif

void hw_lro_stats_update(u32 ring_no, struct mtk_rx_dma *rxd)
{
Expand Down Expand Up @@ -1177,6 +1223,7 @@ static int hw_lro_stats_open(struct inode *inode, struct file *file)
return single_open(file, hw_lro_stats_read_wrapper, NULL);
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
static const struct file_operations hw_lro_stats_fops = {
.owner = THIS_MODULE,
.open = hw_lro_stats_open,
Expand All @@ -1185,6 +1232,15 @@ static const struct file_operations hw_lro_stats_fops = {
.write = hw_lro_stats_write,
.release = single_release
};
#else
static const struct proc_ops hw_lro_stats_fops = {
.proc_open = hw_lro_stats_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_write = hw_lro_stats_write,
.proc_release = single_release
};
#endif

int hwlro_agg_cnt_ctrl(int cnt)
{
Expand Down Expand Up @@ -1485,6 +1541,7 @@ static int hw_lro_auto_tlb_open(struct inode *inode, struct file *file)
return single_open(file, hw_lro_auto_tlb_read, NULL);
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
static const struct file_operations hw_lro_auto_tlb_fops = {
.owner = THIS_MODULE,
.open = hw_lro_auto_tlb_open,
Expand All @@ -1493,6 +1550,15 @@ static const struct file_operations hw_lro_auto_tlb_fops = {
.write = hw_lro_auto_tlb_write,
.release = single_release
};
#else
static const struct proc_ops hw_lro_auto_tlb_fops = {
.proc_open = hwtx_ring_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_write = hw_lro_auto_tlb_write,
.proc_release = single_release
};
#endif

int reset_event_read(struct seq_file *seq, void *v)
{
Expand Down Expand Up @@ -1542,6 +1608,7 @@ ssize_t reset_event_write(struct file *file, const char __user *buffer,
return count;
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
static const struct file_operations reset_event_fops = {
.owner = THIS_MODULE,
.open = reset_event_open,
Expand All @@ -1550,6 +1617,15 @@ static const struct file_operations reset_event_fops = {
.write = reset_event_write,
.release = single_release
};
#else
static const struct proc_ops reset_event_fops = {
.proc_open = reset_event_open,
.proc_read = seq_read,
.proc_lseek = seq_lseek,
.proc_write = reset_event_write,
.proc_release = single_release
};
#endif

struct proc_dir_entry *proc_reg_dir;
static struct proc_dir_entry *proc_esw_cnt, *proc_dbg_regs, *proc_reset_event;
Expand Down
35 changes: 34 additions & 1 deletion target/linux/ramips/files/drivers/net/ethernet/mtk/mtk_eth_soc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <linux/interrupt.h>
#include <linux/pinctrl/devinfo.h>
#include <linux/phylink.h>
#include <linux/version.h>
#include <net/dsa.h>

#include "mtk_eth_soc.h"
Expand Down Expand Up @@ -437,7 +438,11 @@ static void mtk_mac_config(struct phylink_config *config, unsigned int mode,
mac->id, phy_modes(state->interface), err);
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)
static int mtk_mac_link_state(struct phylink_config *config,
#else
static void mtk_mac_pcs_get_state(struct phylink_config *config,
#endif
struct phylink_link_state *state)
{
struct mtk_mac *mac = container_of(config, struct mtk_mac,
Expand Down Expand Up @@ -468,7 +473,9 @@ static int mtk_mac_link_state(struct phylink_config *config,
if (pmsr & MAC_MSR_TX_FC)
state->pause |= MLO_PAUSE_TX;

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)
return 1;
#endif
}

static void mtk_mac_an_restart(struct phylink_config *config)
Expand All @@ -490,9 +497,16 @@ static void mtk_mac_link_down(struct phylink_config *config, unsigned int mode,
mtk_w32(mac->hw, mcr, MTK_MAC_MCR(mac->id));
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 7, 0)
static void mtk_mac_link_up(struct phylink_config *config, unsigned int mode,
phy_interface_t interface,
struct phy_device *phy)
#else
static void mtk_mac_link_up(struct phylink_config *config,
struct phy_device *phy,
unsigned int mode, phy_interface_t interface,
int speed, int duplex, bool tx_pause, bool rx_pause)
#endif
{
struct mtk_mac *mac = container_of(config, struct mtk_mac,
phylink_config);
Expand Down Expand Up @@ -590,7 +604,11 @@ static void mtk_validate(struct phylink_config *config,

static const struct phylink_mac_ops mtk_phylink_ops = {
.validate = mtk_validate,
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)
.mac_link_state = mtk_mac_link_state,
#else
.mac_pcs_get_state = mtk_mac_pcs_get_state,
#endif
.mac_an_restart = mtk_mac_an_restart,
.mac_config = mtk_mac_config,
.mac_link_down = mtk_mac_link_down,
Expand Down Expand Up @@ -2490,7 +2508,11 @@ static void mtk_dma_free(struct mtk_eth *eth)
}
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
static void mtk_tx_timeout(struct net_device *dev)
#else
static void mtk_tx_timeout(struct net_device *dev, unsigned int txqueue)
#endif
{
struct mtk_mac *mac = netdev_priv(dev);
struct mtk_eth *eth = mac->hw;
Expand Down Expand Up @@ -3402,9 +3424,15 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
{
const __be32 *_id = of_get_property(np, "reg", NULL);
struct phylink *phylink;
int phy_mode, id, err;
struct mtk_mac *mac;

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)
int phy_mode, id, err;
#else
int id, err;
phy_interface_t phy_mode = PHY_INTERFACE_MODE_NA;
#endif

if (!_id) {
dev_err(eth->dev, "missing mac id\n");
return -EINVAL;
Expand Down Expand Up @@ -3448,8 +3476,13 @@ static int mtk_add_mac(struct mtk_eth *eth, struct device_node *np)
mac->hw_stats->reg_offset = id * MTK_STAT_OFFSET;

/* phylink create */
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 10, 0)
phy_mode = of_get_phy_mode(np);
if (phy_mode < 0) {
#else
of_get_phy_mode(np, &phy_mode);
if (phy_mode == PHY_INTERFACE_MODE_NA) {
#endif
dev_err(eth->dev, "incorrect phy-mode\n");
err = -EINVAL;
goto free_netdev;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -735,7 +735,11 @@ static int hnat_probe(struct platform_device *pdev)
if (!res)
return -ENOENT;

#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 6, 0)
hnat_priv->fe_base = devm_ioremap_nocache(&pdev->dev, res->start,
#else
hnat_priv->fe_base = devm_ioremap(&pdev->dev, res->start,
#endif
res->end - res->start + 1);
if (!hnat_priv->fe_base)
return -EADDRNOTAVAIL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,13 @@
#include <linux/if_ether.h>
#include <net/netevent.h>
#include <linux/mod_devicetable.h>
#include <linux/version.h>
#include "hnat_mcast.h"

#if LINUX_VERSION_CODE > KERNEL_VERSION(5, 4, 0)
#include <net/netfilter/nf_hnat.h>
#endif

/*--------------------------------------------------------------------------*/
/* Register Offset*/
/*--------------------------------------------------------------------------*/
Expand Down
Loading

0 comments on commit ef12a97

Please sign in to comment.