mirror of
https://github.com/coolsnowwolf/lede.git
synced 2025-04-16 04:13:31 +00:00
r8125: bump to 9.005.01 (#6457)
Enabled RSS support for performance. Signed-off-by: CN_SZTL <cnsztl@project-openwrt.eu.org>
This commit is contained in:
parent
26721a994c
commit
ec4de4d31c
@ -65,7 +65,7 @@ include $(TOPDIR)/rules.mk
|
||||
include $(INCLUDE_DIR)/kernel.mk
|
||||
|
||||
PKG_NAME:=r8125
|
||||
PKG_VERSION:=9.004.01
|
||||
PKG_VERSION:=9.005.01
|
||||
PKG_RELEASE:=1
|
||||
|
||||
#PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.bz2
|
||||
|
@ -4,7 +4,7 @@
|
||||
# r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2019 Realtek Semiconductor Corp. All rights reserved.
|
||||
# Copyright(c) 2021 Realtek Semiconductor Corp. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
@ -43,7 +43,8 @@ ENABLE_S0_MAGIC_PACKET = n
|
||||
ENABLE_TX_NO_CLOSE = y
|
||||
ENABLE_MULTIPLE_TX_QUEUE = n
|
||||
ENABLE_PTP_SUPPORT = n
|
||||
ENABLE_RSS_SUPPORT = n
|
||||
ENABLE_PTP_MASTER_MODE = n
|
||||
ENABLE_RSS_SUPPORT = y
|
||||
ENABLE_LIB_SUPPORT = n
|
||||
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
@ -94,6 +95,9 @@ ifneq ($(KERNELRELEASE),)
|
||||
r8125-objs += r8125_ptp.o
|
||||
EXTRA_CFLAGS += -DENABLE_PTP_SUPPORT
|
||||
endif
|
||||
ifeq ($(ENABLE_PTP_MASTER_MODE), y)
|
||||
EXTRA_CFLAGS += -DENABLE_PTP_MASTER_MODE
|
||||
endif
|
||||
ifeq ($(ENABLE_RSS_SUPPORT), y)
|
||||
r8125-objs += r8125_rss.o
|
||||
EXTRA_CFLAGS += -DENABLE_RSS_SUPPORT
|
||||
|
@ -4,7 +4,7 @@
|
||||
# r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2019 Realtek Semiconductor Corp. All rights reserved.
|
||||
# Copyright(c) 2021 Realtek Semiconductor Corp. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
|
@ -5,7 +5,7 @@
|
||||
# r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2020 Realtek Semiconductor Corp. All rights reserved.
|
||||
# Copyright(c) 2021 Realtek Semiconductor Corp. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
@ -47,6 +47,10 @@
|
||||
#include "r8125_lib.h"
|
||||
#endif
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,12,0)&& !defined(ENABLE_LIB_SUPPORT)
|
||||
#define RTL_USE_NEW_INTR_API
|
||||
#endif
|
||||
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
|
||||
#define skb_transport_offset(skb) (skb->h.raw - skb->data)
|
||||
#endif
|
||||
@ -353,12 +357,12 @@ do { \
|
||||
#define RSS_SUFFIX ""
|
||||
#endif
|
||||
|
||||
#define RTL8125_VERSION "9.004.01" NAPI_SUFFIX DASH_SUFFIX REALWOW_SUFFIX PTP_SUFFIX RSS_SUFFIX
|
||||
#define RTL8125_VERSION "9.005.01" NAPI_SUFFIX DASH_SUFFIX REALWOW_SUFFIX PTP_SUFFIX RSS_SUFFIX
|
||||
#define MODULENAME "r8125"
|
||||
#define PFX MODULENAME ": "
|
||||
|
||||
#define GPL_CLAIM "\
|
||||
r8125 Copyright (C) 2020 Realtek NIC software team <nicfae@realtek.com> \n \
|
||||
r8125 Copyright (C) 2021 Realtek NIC software team <nicfae@realtek.com> \n \
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details, please see <http://www.gnu.org/licenses/>. \n \
|
||||
This is free software, and you are welcome to redistribute it under certain conditions; see <http://www.gnu.org/licenses/>. \n"
|
||||
|
||||
@ -538,6 +542,17 @@ This is free software, and you are welcome to redistribute it under certain cond
|
||||
#define ETH_MIN_MTU 68
|
||||
#endif
|
||||
|
||||
#define D0_SPEED_UP_SPEED_DISABLE 0
|
||||
#define D0_SPEED_UP_SPEED_1000 1
|
||||
#define D0_SPEED_UP_SPEED_2500 2
|
||||
|
||||
#ifndef WRITE_ONCE
|
||||
#define WRITE_ONCE(var, val) (*((volatile typeof(val) *)(&(var))) = (val))
|
||||
#endif
|
||||
#ifndef READ_ONCE
|
||||
#define READ_ONCE(var) (*((volatile typeof(var) *)(&(var))))
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
//#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,3)
|
||||
@ -624,6 +639,23 @@ typedef int napi_budget;
|
||||
#define RTL_NAPI_DEL(priv) netif_napi_del(&priv->napi)
|
||||
#endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
|
||||
|
||||
/*****************************************************************************/
|
||||
#ifdef CONFIG_R8125_NAPI
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0)
|
||||
#define RTL_NAPI_CONSUME_SKB_ANY(skb, budget) napi_consume_skb(skb, budget)
|
||||
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)
|
||||
#define RTL_NAPI_CONSUME_SKB_ANY(skb, budget) dev_consume_skb_any(skb);
|
||||
#else
|
||||
#define RTL_NAPI_CONSUME_SKB_ANY(skb, budget) dev_kfree_skb_any(skb);
|
||||
#endif //LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0)
|
||||
#else //CONFIG_R8125_NAPI
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,14,0)
|
||||
#define RTL_NAPI_CONSUME_SKB_ANY(skb, budget) dev_consume_skb_any(skb);
|
||||
#else
|
||||
#define RTL_NAPI_CONSUME_SKB_ANY(skb, budget) dev_kfree_skb_any(skb);
|
||||
#endif
|
||||
#endif //CONFIG_R8125_NAPI
|
||||
|
||||
/*****************************************************************************/
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9)
|
||||
#ifdef __CHECKER__
|
||||
@ -1420,6 +1452,7 @@ enum RTL8125_register_content {
|
||||
ISRIMR_V2_ROK_Q0 = (1 << 0),
|
||||
ISRIMR_TOK_Q0 = (1 << 16),
|
||||
ISRIMR_TOK_Q1 = (1 << 18),
|
||||
ISRIMR_V2_LINKCHG = (1 << 21),
|
||||
|
||||
/* Magic Number */
|
||||
RTL8125_MAGIC_NUMBER = 0x0badbadbadbadbadull,
|
||||
@ -1725,6 +1758,14 @@ struct r8125_irq {
|
||||
char name[IFNAMSIZ + 10];
|
||||
};
|
||||
|
||||
/* Flow Control Settings */
|
||||
enum rtl8125_fc_mode {
|
||||
rtl8125_fc_none = 0,
|
||||
rtl8125_fc_rx_pause,
|
||||
rtl8125_fc_tx_pause,
|
||||
rtl8125_fc_full,
|
||||
rtl8125_fc_default
|
||||
};
|
||||
|
||||
struct rtl8125_private {
|
||||
void __iomem *mmio_addr; /* memory map physical address */
|
||||
@ -1797,6 +1838,7 @@ struct rtl8125_private {
|
||||
u8 duplex;
|
||||
u32 speed;
|
||||
u32 advertising;
|
||||
enum rtl8125_fc_mode fcpause;
|
||||
u16 eeprom_len;
|
||||
u16 cur_page;
|
||||
u32 bios_setting;
|
||||
@ -1840,10 +1882,6 @@ struct rtl8125_private {
|
||||
u8 ShortPacketSwChecksum;
|
||||
|
||||
u8 UseSwPaddingShortPkt;
|
||||
u16 SwPaddingShortPktLen;
|
||||
|
||||
void *ShortPacketEmptyBuffer;
|
||||
dma_addr_t ShortPacketEmptyBufferPhy;
|
||||
|
||||
u8 RequireAdcBiasPatch;
|
||||
u16 AdcBiasPatchIoffset;
|
||||
@ -1867,6 +1905,8 @@ struct rtl8125_private {
|
||||
|
||||
u8 HwSuppMagicPktVer;
|
||||
|
||||
u8 HwSuppLinkChgWakeUpVer;
|
||||
|
||||
u8 HwSuppCheckPhyDisableModeVer;
|
||||
|
||||
u8 random_mac;
|
||||
@ -1885,6 +1925,12 @@ struct rtl8125_private {
|
||||
|
||||
u8 HwSuppIntMitiVer;
|
||||
|
||||
u8 check_keep_link_speed;
|
||||
u8 resume_not_chg_speed;
|
||||
|
||||
u8 HwSuppD0SpeedUpVer;
|
||||
u8 D0SpeedUpSpeed;
|
||||
|
||||
//Dash+++++++++++++++++
|
||||
u8 HwSuppDashVer;
|
||||
u8 DASH;
|
||||
@ -1987,6 +2033,7 @@ struct rtl8125_private {
|
||||
|
||||
u8 HwSuppPtpVer;
|
||||
u8 EnablePtp;
|
||||
u8 ptp_master_mode;
|
||||
s64 ptp_adjust;
|
||||
#ifdef ENABLE_PTP_SUPPORT
|
||||
u32 tx_hwtstamp_timeouts;
|
||||
@ -2109,7 +2156,7 @@ enum mcfg {
|
||||
#define NIC_RAMCODE_VERSION_CFG_METHOD_2 (0x0b11)
|
||||
#define NIC_RAMCODE_VERSION_CFG_METHOD_3 (0x0b33)
|
||||
#define NIC_RAMCODE_VERSION_CFG_METHOD_4 (0x0b17)
|
||||
#define NIC_RAMCODE_VERSION_CFG_METHOD_5 (0x0b36)
|
||||
#define NIC_RAMCODE_VERSION_CFG_METHOD_5 (0x0b55)
|
||||
|
||||
//hwoptimize
|
||||
#define HW_PATCH_SOC_LAN (BIT_0)
|
||||
@ -2206,6 +2253,7 @@ static inline void rtl8125_lib_reset_complete(struct rtl8125_private *tp) { }
|
||||
|
||||
#define HW_SUPPORT_CHECK_PHY_DISABLE_MODE(_M) ((_M)->HwSuppCheckPhyDisableModeVer > 0 )
|
||||
#define HW_HAS_WRITE_PHY_MCU_RAM_CODE(_M) (((_M)->HwHasWrRamCodeToMicroP == TRUE) ? 1 : 0)
|
||||
#define HW_SUPPORT_D0_SPEED_UP(_M) ((_M)->HwSuppD0SpeedUpVer > 0)
|
||||
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34)
|
||||
#define netdev_mc_count(dev) ((dev)->mc_count)
|
||||
|
@ -5,7 +5,7 @@
|
||||
# r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2020 Realtek Semiconductor Corp. All rights reserved.
|
||||
# Copyright(c) 2021 Realtek Semiconductor Corp. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
|
File diff suppressed because it is too large
Load Diff
594
package/lean/r8125/src/r8125_ptp.c
Normal file
594
package/lean/r8125/src/r8125_ptp.c
Normal file
@ -0,0 +1,594 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
################################################################################
|
||||
#
|
||||
# r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2021 Realtek Semiconductor Corp. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation; either version 2 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Author:
|
||||
# Realtek NIC software team <nicfae@realtek.com>
|
||||
# No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
|
||||
#
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
/************************************************************************************
|
||||
* This product is covered by one or more of the following patents:
|
||||
* US6,570,884, US6,115,776, and US6,327,625.
|
||||
***********************************************************************************/
|
||||
|
||||
#include <linux/module.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/pci.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/mii.h>
|
||||
#include <linux/in.h>
|
||||
#include <linux/ethtool.h>
|
||||
|
||||
#include "r8125.h"
|
||||
#include "r8125_ptp.h"
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0)
|
||||
static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64)
|
||||
{
|
||||
return *(const struct timespec *)&ts64;
|
||||
}
|
||||
|
||||
static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
|
||||
{
|
||||
return *(const struct timespec64 *)&ts;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int _rtl8125_phc_gettime(struct rtl8125_private *tp, struct timespec64 *ts64)
|
||||
{
|
||||
//get local time
|
||||
RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_LATCHED_LOCAL_TIME | PTP_EXEC_CMD));
|
||||
|
||||
/* nanoseconds */
|
||||
//0x6808[29:0]
|
||||
ts64->tv_nsec = (RTL_R32(tp, PTP_SOFT_CONFIG_Time_NS_8125) & 0x3fffffff) +
|
||||
tp->ptp_adjust;
|
||||
|
||||
/* seconds */
|
||||
//0x680C[47:0]
|
||||
ts64->tv_sec = RTL_R16(tp, PTP_SOFT_CONFIG_Time_S_8125 + 4);
|
||||
ts64->tv_sec <<= 32;
|
||||
ts64->tv_sec |= RTL_R32(tp, PTP_SOFT_CONFIG_Time_S_8125);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _rtl8125_phc_settime(struct rtl8125_private *tp, const struct timespec64 *ts64)
|
||||
{
|
||||
/* nanoseconds */
|
||||
//0x6808[29:0]
|
||||
RTL_W32(tp, PTP_SOFT_CONFIG_Time_NS_8125, (ts64->tv_nsec & 0x3fffffff));
|
||||
|
||||
/* seconds */
|
||||
//0x680C[47:0]
|
||||
RTL_W32(tp, PTP_SOFT_CONFIG_Time_S_8125, ts64->tv_sec);
|
||||
RTL_W16(tp, PTP_SOFT_CONFIG_Time_S_8125 + 4, (ts64->tv_sec >> 32));
|
||||
|
||||
//set local time
|
||||
RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_SET_LOCAL_TIME | PTP_EXEC_CMD));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if 0
|
||||
static int _rtl8125_phc_adjtime(struct rtl8125_private *tp, s64 delta)
|
||||
{
|
||||
struct timespec64 now, then = ns_to_timespec64(delta);
|
||||
u32 nsec;
|
||||
u64 sec;
|
||||
|
||||
_rtl8125_phc_gettime(tp, &now);
|
||||
now = timespec64_add(now, then);
|
||||
|
||||
nsec = now.tv_nsec & 0x3fffffff;
|
||||
sec = now.tv_sec & 0x0000ffffffffffff;
|
||||
|
||||
/* nanoseconds */
|
||||
//0x6808[29:0]
|
||||
RTL_W32(tp, PTP_SOFT_CONFIG_Time_NS_8125, nsec);
|
||||
|
||||
/* seconds */
|
||||
//0x680C[47:0]
|
||||
RTL_W32(tp, PTP_SOFT_CONFIG_Time_S_8125, sec);
|
||||
RTL_W16(tp, PTP_SOFT_CONFIG_Time_S_8125 + 4, (sec >> 32));
|
||||
|
||||
//adjust local time
|
||||
//RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_DRIFT_LOCAL_TIME | PTP_EXEC_CMD));
|
||||
RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_SET_LOCAL_TIME | PTP_EXEC_CMD));
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int rtl8125_phc_adjtime(struct ptp_clock_info *ptp, s64 delta)
|
||||
{
|
||||
struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
|
||||
unsigned long flags;
|
||||
//int ret = 0;
|
||||
|
||||
//netif_info(tp, drv, tp->dev, "phc adjust time\n");
|
||||
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
//ret = _rtl8125_phc_adjtime(tp, delta);
|
||||
tp->ptp_adjust += delta;
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
1ppm means every 125MHz plus 125Hz. It also means every 8ns minus 8ns*10^(-6)
|
||||
|
||||
1ns=2^30 sub_ns
|
||||
|
||||
8ns*10^(-6) = 8 * 2^30 sub_ns * 10^(-6) = 2^33 sub_ns * 10^(-6) = 8590 = 0x218E sub_ns
|
||||
|
||||
1ppb means every 125MHz plus 0.125Hz. It also means every 8ns minus 8ns*10^(-9)
|
||||
|
||||
1ns=2^30 sub_ns
|
||||
|
||||
8ns*10^(-9) = 8 * 2^30 sub_ns * 10^(-9) = 2^33 sub_ns * 10^(-9) = 8.59 sub_ns = 9 sub_ns
|
||||
*/
|
||||
static int _rtl8125_phc_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
|
||||
{
|
||||
struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
|
||||
bool negative = false;
|
||||
u32 sub_ns;
|
||||
|
||||
if (ppb < 0) {
|
||||
negative = true;
|
||||
ppb = -ppb;
|
||||
}
|
||||
|
||||
sub_ns = ppb * 9;
|
||||
if (negative) {
|
||||
sub_ns = -sub_ns;
|
||||
sub_ns &= 0x3fffffff;
|
||||
sub_ns |= PTP_ADJUST_TIME_NS_NEGATIVE;
|
||||
} else
|
||||
sub_ns &= 0x3fffffff;
|
||||
|
||||
/* nanoseconds */
|
||||
//0x6808[29:0]
|
||||
RTL_W32(tp, PTP_SOFT_CONFIG_Time_NS_8125, sub_ns);
|
||||
|
||||
//adjust local time
|
||||
RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_DRIFT_LOCAL_TIME | PTP_EXEC_CMD));
|
||||
//RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_SET_LOCAL_TIME | PTP_EXEC_CMD));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rtl8125_phc_adjfreq(struct ptp_clock_info *ptp, s32 delta)
|
||||
{
|
||||
//struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
|
||||
|
||||
//netif_info(tp, drv, tp->dev, "phc adjust freq\n");
|
||||
|
||||
if (delta > ptp->max_adj || delta < -ptp->max_adj)
|
||||
return -EINVAL;
|
||||
|
||||
_rtl8125_phc_adjfreq(ptp, delta);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rtl8125_phc_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts64)
|
||||
{
|
||||
struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
|
||||
unsigned long flags;
|
||||
int ret;
|
||||
|
||||
//netif_info(tp, drv, tp->dev, "phc get ts\n");
|
||||
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
ret = _rtl8125_phc_gettime(tp, ts64);
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rtl8125_phc_settime(struct ptp_clock_info *ptp,
|
||||
const struct timespec64 *ts64)
|
||||
{
|
||||
struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
|
||||
unsigned long flags;
|
||||
int ret;
|
||||
|
||||
//netif_info(tp, drv, tp->dev, "phc set ts\n");
|
||||
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
ret = _rtl8125_phc_settime(tp, ts64);
|
||||
tp->ptp_adjust = 0;
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rtl8125_phc_enable(struct ptp_clock_info *ptp,
|
||||
struct ptp_clock_request *rq, int on)
|
||||
{
|
||||
struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
|
||||
unsigned long flags;
|
||||
u16 ptp_ctrl;
|
||||
|
||||
//netif_info(tp, drv, tp->dev, "phc enable type %x on %d\n", rq->type, on);
|
||||
|
||||
switch (rq->type) {
|
||||
case PTP_CLK_REQ_PPS:
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
ptp_ctrl = RTL_R16(tp, PTP_CTRL_8125);
|
||||
ptp_ctrl &= ~BIT_15;
|
||||
if (on)
|
||||
ptp_ctrl |= BIT_14;
|
||||
else
|
||||
ptp_ctrl &= ~BIT_14;
|
||||
RTL_W16(tp, PTP_CTRL_8125, ptp_ctrl);
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
return 0;
|
||||
default:
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
}
|
||||
|
||||
int rtl8125_get_ts_info(struct net_device *netdev,
|
||||
struct ethtool_ts_info *info)
|
||||
{
|
||||
struct rtl8125_private *tp = netdev_priv(netdev);
|
||||
|
||||
/* we always support timestamping disabled */
|
||||
info->rx_filters = BIT(HWTSTAMP_FILTER_NONE);
|
||||
|
||||
if (tp->HwSuppPtpVer == 0)
|
||||
return ethtool_op_get_ts_info(netdev, info);
|
||||
|
||||
info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
|
||||
SOF_TIMESTAMPING_RX_SOFTWARE |
|
||||
SOF_TIMESTAMPING_SOFTWARE |
|
||||
SOF_TIMESTAMPING_TX_HARDWARE |
|
||||
SOF_TIMESTAMPING_RX_HARDWARE |
|
||||
SOF_TIMESTAMPING_RAW_HARDWARE;
|
||||
|
||||
if (tp->ptp_clock)
|
||||
info->phc_index = ptp_clock_index(tp->ptp_clock);
|
||||
else
|
||||
info->phc_index = -1;
|
||||
|
||||
info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
|
||||
|
||||
info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
|
||||
BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
|
||||
BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
|
||||
BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
|
||||
BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
|
||||
BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
|
||||
BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct ptp_clock_info rtl_ptp_clock_info = {
|
||||
.owner = THIS_MODULE,
|
||||
.n_alarm = 0,
|
||||
.n_ext_ts = 0,
|
||||
.n_per_out = 0,
|
||||
.n_pins = 0,
|
||||
.pps = 1,
|
||||
.adjfreq = rtl8125_phc_adjfreq,
|
||||
.adjtime = rtl8125_phc_adjtime,
|
||||
.gettime64 = rtl8125_phc_gettime,
|
||||
.settime64 = rtl8125_phc_settime,
|
||||
.enable = rtl8125_phc_enable,
|
||||
};
|
||||
|
||||
static int rtl8125_get_tx_ptp_pkt_tstamp(struct rtl8125_private *tp, struct timespec64 *ts64)
|
||||
{
|
||||
return _rtl8125_phc_gettime(tp, ts64);
|
||||
}
|
||||
|
||||
static void rtl8125_ptp_tx_hwtstamp(struct rtl8125_private *tp)
|
||||
{
|
||||
struct sk_buff *skb = tp->ptp_tx_skb;
|
||||
struct skb_shared_hwtstamps shhwtstamps = {0};
|
||||
struct timespec64 ts64;
|
||||
|
||||
RTL_W8(tp, PTP_ISR_8125, PTP_ISR_TOK | PTP_ISR_TER);
|
||||
|
||||
rtl8125_get_tx_ptp_pkt_tstamp(tp, &ts64);
|
||||
|
||||
/* Upper 32 bits contain s, lower 32 bits contain ns. */
|
||||
shhwtstamps.hwtstamp = ktime_set(ts64.tv_sec,
|
||||
ts64.tv_nsec);
|
||||
|
||||
/* Clear the lock early before calling skb_tstamp_tx so that
|
||||
* applications are not woken up before the lock bit is clear. We use
|
||||
* a copy of the skb pointer to ensure other threads can't change it
|
||||
* while we're notifying the stack.
|
||||
*/
|
||||
tp->ptp_tx_skb = NULL;
|
||||
|
||||
/* Notify the stack and free the skb after we've unlocked */
|
||||
skb_tstamp_tx(skb, &shhwtstamps);
|
||||
dev_kfree_skb_any(skb);
|
||||
}
|
||||
|
||||
#define RTL8125_PTP_TX_TIMEOUT (HZ * 15)
|
||||
static void rtl8125_ptp_tx_work(struct work_struct *work)
|
||||
{
|
||||
struct rtl8125_private *tp = container_of(work, struct rtl8125_private,
|
||||
ptp_tx_work);
|
||||
unsigned long flags;
|
||||
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
|
||||
if (!tp->ptp_tx_skb)
|
||||
goto Exit;
|
||||
|
||||
if (time_is_before_jiffies(tp->ptp_tx_start +
|
||||
RTL8125_PTP_TX_TIMEOUT)) {
|
||||
dev_kfree_skb_any(tp->ptp_tx_skb);
|
||||
tp->ptp_tx_skb = NULL;
|
||||
tp->tx_hwtstamp_timeouts++;
|
||||
/* Clear the tx valid bit in TSYNCTXCTL register to enable
|
||||
* interrupt
|
||||
*/
|
||||
RTL_W8(tp, PTP_ISR_8125, PTP_ISR_TOK | PTP_ISR_TER);
|
||||
goto Exit;
|
||||
}
|
||||
|
||||
if (RTL_R8(tp, PTP_ISR_8125) & (PTP_ISR_TOK))
|
||||
rtl8125_ptp_tx_hwtstamp(tp);
|
||||
else
|
||||
/* reschedule to check later */
|
||||
schedule_work(&tp->ptp_tx_work);
|
||||
|
||||
Exit:
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
}
|
||||
|
||||
static int rtl8125_hwtstamp_enable(struct rtl8125_private *tp, bool enable)
|
||||
{
|
||||
RTL_W16(tp, PTP_CTRL_8125, 0);
|
||||
if (enable) {
|
||||
u16 ptp_ctrl;
|
||||
struct timespec64 ts64;
|
||||
|
||||
//clear ptp isr
|
||||
RTL_W8(tp, PTP_ISR_8125, 0xff);
|
||||
//ptp source 0:gphy 1:mac
|
||||
rtl8125_mac_ocp_write(tp, 0xDC00, rtl8125_mac_ocp_read(tp, 0xDC00) | BIT_6);
|
||||
//enable ptp
|
||||
ptp_ctrl = (BIT_0 | BIT_3 | BIT_4 | BIT_6 | BIT_10 | BIT_12 | BIT_13);
|
||||
if (tp->ptp_master_mode) {
|
||||
ptp_ctrl &= ~BIT_13;
|
||||
ptp_ctrl |= BIT_1;
|
||||
}
|
||||
RTL_W16(tp, PTP_CTRL_8125, ptp_ctrl);
|
||||
|
||||
//set system time
|
||||
/*
|
||||
if (ktime_to_timespec64_cond(ktime_get_real(), &ts64))
|
||||
_rtl8125_phc_settime(tp, timespec64_to_timespec(ts64));
|
||||
*/
|
||||
ktime_get_real_ts64(&ts64);
|
||||
ts64.tv_nsec += tp->ptp_adjust;
|
||||
_rtl8125_phc_settime(tp, &ts64);
|
||||
tp->ptp_adjust = 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static long rtl8125_ptp_create_clock(struct rtl8125_private *tp)
|
||||
{
|
||||
struct net_device *netdev = tp->dev;
|
||||
long err;
|
||||
|
||||
if (!IS_ERR_OR_NULL(tp->ptp_clock))
|
||||
return 0;
|
||||
|
||||
if (tp->HwSuppPtpVer == 0) {
|
||||
tp->ptp_clock = NULL;
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
tp->ptp_clock_info = rtl_ptp_clock_info;
|
||||
snprintf(tp->ptp_clock_info.name, sizeof(tp->ptp_clock_info.name),
|
||||
"%pm", tp->dev->dev_addr);
|
||||
tp->ptp_clock_info.max_adj = 119304647;
|
||||
tp->ptp_clock = ptp_clock_register(&tp->ptp_clock_info, &tp->pci_dev->dev);
|
||||
if (IS_ERR(tp->ptp_clock)) {
|
||||
err = PTR_ERR(tp->ptp_clock);
|
||||
tp->ptp_clock = NULL;
|
||||
netif_err(tp, drv, tp->dev, "ptp_clock_register failed\n");
|
||||
return err;
|
||||
} else
|
||||
netif_info(tp, drv, tp->dev, "registered PHC device on %s\n", netdev->name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rtl8125_ptp_reset(struct rtl8125_private *tp)
|
||||
{
|
||||
if (!tp->ptp_clock)
|
||||
return;
|
||||
|
||||
netif_info(tp, drv, tp->dev, "reset PHC clock\n");
|
||||
|
||||
rtl8125_hwtstamp_enable(tp, false);
|
||||
}
|
||||
|
||||
void rtl8125_ptp_init(struct rtl8125_private *tp)
|
||||
{
|
||||
/* obtain a PTP device, or re-use an existing device */
|
||||
if (rtl8125_ptp_create_clock(tp))
|
||||
return;
|
||||
|
||||
/* we have a clock so we can initialize work now */
|
||||
INIT_WORK(&tp->ptp_tx_work, rtl8125_ptp_tx_work);
|
||||
|
||||
tp->ptp_adjust = 0;
|
||||
|
||||
/* reset the PTP related hardware bits */
|
||||
rtl8125_ptp_reset(tp);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void rtl8125_ptp_suspend(struct rtl8125_private *tp)
|
||||
{
|
||||
if (!tp->ptp_clock)
|
||||
return;
|
||||
|
||||
netif_info(tp, drv, tp->dev, "suspend PHC clock\n");
|
||||
|
||||
rtl8125_hwtstamp_enable(tp, false);
|
||||
|
||||
/* ensure that we cancel any pending PTP Tx work item in progress */
|
||||
cancel_work_sync(&tp->ptp_tx_work);
|
||||
}
|
||||
|
||||
void rtl8125_ptp_stop(struct rtl8125_private *tp)
|
||||
{
|
||||
struct net_device *netdev = tp->dev;
|
||||
|
||||
netif_info(tp, drv, tp->dev, "stop PHC clock\n");
|
||||
|
||||
/* first, suspend PTP activity */
|
||||
rtl8125_ptp_suspend(tp);
|
||||
|
||||
/* disable the PTP clock device */
|
||||
if (tp->ptp_clock) {
|
||||
ptp_clock_unregister(tp->ptp_clock);
|
||||
tp->ptp_clock = NULL;
|
||||
netif_info(tp, drv, tp->dev, "removed PHC on %s\n",
|
||||
netdev->name);
|
||||
}
|
||||
}
|
||||
|
||||
static int rtl8125_set_tstamp(struct net_device *netdev, struct ifreq *ifr)
|
||||
{
|
||||
struct rtl8125_private *tp = netdev_priv(netdev);
|
||||
struct hwtstamp_config config;
|
||||
bool hwtstamp = 0;
|
||||
|
||||
//netif_info(tp, drv, tp->dev, "ptp set ts\n");
|
||||
|
||||
if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
|
||||
return -EFAULT;
|
||||
|
||||
if (config.flags)
|
||||
return -EINVAL;
|
||||
|
||||
switch (config.tx_type) {
|
||||
case HWTSTAMP_TX_ON:
|
||||
hwtstamp = 1;
|
||||
case HWTSTAMP_TX_OFF:
|
||||
break;
|
||||
case HWTSTAMP_TX_ONESTEP_SYNC:
|
||||
default:
|
||||
return -ERANGE;
|
||||
}
|
||||
|
||||
switch (config.rx_filter) {
|
||||
case HWTSTAMP_FILTER_PTP_V2_EVENT:
|
||||
case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
|
||||
case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
|
||||
case HWTSTAMP_FILTER_PTP_V2_SYNC:
|
||||
case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
|
||||
case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
|
||||
case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
|
||||
case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
|
||||
case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
|
||||
config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
|
||||
hwtstamp = 1;
|
||||
case HWTSTAMP_FILTER_NONE:
|
||||
break;
|
||||
default:
|
||||
return -ERANGE;
|
||||
}
|
||||
|
||||
if (tp->hwtstamp_config.tx_type != config.tx_type ||
|
||||
tp->hwtstamp_config.rx_filter != config.rx_filter) {
|
||||
tp->hwtstamp_config = config;
|
||||
rtl8125_hwtstamp_enable(tp, hwtstamp);
|
||||
}
|
||||
|
||||
return copy_to_user(ifr->ifr_data, &config,
|
||||
sizeof(config)) ? -EFAULT : 0;
|
||||
}
|
||||
|
||||
static int rtl8125_get_tstamp(struct net_device *netdev, struct ifreq *ifr)
|
||||
{
|
||||
struct rtl8125_private *tp = netdev_priv(netdev);
|
||||
|
||||
//netif_info(tp, drv, tp->dev, "ptp get ts\n");
|
||||
|
||||
return copy_to_user(ifr->ifr_data, &tp->hwtstamp_config,
|
||||
sizeof(tp->hwtstamp_config)) ? -EFAULT : 0;
|
||||
}
|
||||
|
||||
int rtl8125_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
|
||||
{
|
||||
struct rtl8125_private *tp = netdev_priv(netdev);
|
||||
int ret;
|
||||
unsigned long flags;
|
||||
|
||||
//netif_info(tp, drv, tp->dev, "ptp ioctl\n");
|
||||
|
||||
ret = 0;
|
||||
switch (cmd) {
|
||||
#ifdef ENABLE_PTP_SUPPORT
|
||||
case SIOCSHWTSTAMP:
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
ret = rtl8125_set_tstamp(netdev, ifr);
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
break;
|
||||
case SIOCGHWTSTAMP:
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
ret = rtl8125_get_tstamp(netdev, ifr);
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
ret = -EOPNOTSUPP;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void rtl8125_rx_ptp_pktstamp(struct rtl8125_private *tp, struct sk_buff *skb,
|
||||
struct RxDescV3 *descv3)
|
||||
{
|
||||
time64_t tv_sec;
|
||||
long tv_nsec;
|
||||
|
||||
tv_sec = le32_to_cpu(descv3->RxDescTimeStamp.TimeStampHigh) +
|
||||
((u64)le32_to_cpu(descv3->RxDescPTPDDWord4.TimeStampHHigh) << 32);
|
||||
tv_nsec = le32_to_cpu(descv3->RxDescTimeStamp.TimeStampLow) + tp->ptp_adjust;
|
||||
|
||||
skb_hwtstamps(skb)->hwtstamp = ktime_set(tv_sec, tv_nsec);
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
# r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2020 Realtek Semiconductor Corp. All rights reserved.
|
||||
# Copyright(c) 2021 Realtek Semiconductor Corp. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
|
@ -5,7 +5,7 @@
|
||||
# r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2020 Realtek Semiconductor Corp. All rights reserved.
|
||||
# Copyright(c) 2021 Realtek Semiconductor Corp. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
|
484
package/lean/r8125/src/r8125_rss.c
Normal file
484
package/lean/r8125/src/r8125_rss.c
Normal file
@ -0,0 +1,484 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
################################################################################
|
||||
#
|
||||
# r8168 is the Linux device driver released for Realtek Gigabit Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2021 Realtek Semiconductor Corp. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
# Software Foundation; either version 2 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful, but WITHOUT
|
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
||||
# more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along with
|
||||
# this program; if not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
# Author:
|
||||
# Realtek NIC software team <nicfae@realtek.com>
|
||||
# No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
|
||||
#
|
||||
################################################################################
|
||||
*/
|
||||
|
||||
/************************************************************************************
|
||||
* This product is covered by one or more of the following patents:
|
||||
* US6,570,884, US6,115,776, and US6,327,625.
|
||||
***********************************************************************************/
|
||||
|
||||
#include <linux/version.h>
|
||||
#include "r8125.h"
|
||||
|
||||
enum rtl8125_rss_register_content {
|
||||
/* RSS */
|
||||
RSS_CTRL_TCP_IPV4_SUPP = (1 << 0),
|
||||
RSS_CTRL_IPV4_SUPP = (1 << 1),
|
||||
RSS_CTRL_TCP_IPV6_SUPP = (1 << 2),
|
||||
RSS_CTRL_IPV6_SUPP = (1 << 3),
|
||||
RSS_HALF_SUPP = (1 << 7),
|
||||
RSS_CTRL_UDP_IPV4_SUPP = (1 << 11),
|
||||
RSS_CTRL_UDP_IPV6_SUPP = (1 << 12),
|
||||
RSS_QUAD_CPU_EN = (1 << 16),
|
||||
RSS_HQ_Q_SUP_R = (1 << 31),
|
||||
};
|
||||
|
||||
static int rtl8125_get_rss_hash_opts(struct rtl8125_private *tp,
|
||||
struct ethtool_rxnfc *cmd)
|
||||
{
|
||||
cmd->data = 0;
|
||||
|
||||
/* Report default options for RSS */
|
||||
switch (cmd->flow_type) {
|
||||
case TCP_V4_FLOW:
|
||||
cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
|
||||
/* fallthrough */
|
||||
case UDP_V4_FLOW:
|
||||
if (tp->rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV4)
|
||||
cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
|
||||
/* fallthrough */
|
||||
case IPV4_FLOW:
|
||||
cmd->data |= RXH_IP_SRC | RXH_IP_DST;
|
||||
break;
|
||||
case TCP_V6_FLOW:
|
||||
cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
|
||||
/* fallthrough */
|
||||
case UDP_V6_FLOW:
|
||||
if (tp->rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV6)
|
||||
cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
|
||||
/* fallthrough */
|
||||
case IPV6_FLOW:
|
||||
cmd->data |= RXH_IP_SRC | RXH_IP_DST;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rtl8125_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
|
||||
u32 *rule_locs)
|
||||
{
|
||||
struct rtl8125_private *tp = netdev_priv(dev);
|
||||
int ret = -EOPNOTSUPP;
|
||||
|
||||
netif_info(tp, drv, tp->dev, "rss get rxnfc\n");
|
||||
|
||||
if (!(dev->features & NETIF_F_RXHASH))
|
||||
return ret;
|
||||
|
||||
switch (cmd->cmd) {
|
||||
case ETHTOOL_GRXRINGS:
|
||||
cmd->data = rtl8125_tot_rx_rings(tp);
|
||||
ret = 0;
|
||||
break;
|
||||
case ETHTOOL_GRXFH:
|
||||
ret = rtl8125_get_rss_hash_opts(tp, cmd);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
u32 rtl8125_rss_indir_tbl_entries(struct rtl8125_private *tp)
|
||||
{
|
||||
return tp->HwSuppIndirTblEntries;
|
||||
}
|
||||
|
||||
#define RSS_MASK_BITS_OFFSET (8)
|
||||
#define RSS_CPU_NUM_OFFSET (16)
|
||||
#define RTL8125_UDP_RSS_FLAGS (RTL_8125_RSS_FLAG_HASH_UDP_IPV4 | \
|
||||
RTL_8125_RSS_FLAG_HASH_UDP_IPV6)
|
||||
static int _rtl8125_set_rss_hash_opt(struct rtl8125_private *tp)
|
||||
{
|
||||
u32 rss_flags = tp->rss_flags;
|
||||
u32 hash_mask_len;
|
||||
u32 rss_ctrl;
|
||||
|
||||
rss_ctrl = ilog2(rtl8125_tot_rx_rings(tp));
|
||||
rss_ctrl &= (BIT_0 | BIT_1 | BIT_2);
|
||||
rss_ctrl <<= RSS_CPU_NUM_OFFSET;
|
||||
|
||||
/* Perform hash on these packet types */
|
||||
rss_ctrl |= RSS_CTRL_TCP_IPV4_SUPP
|
||||
| RSS_CTRL_IPV4_SUPP
|
||||
| RSS_CTRL_IPV6_SUPP
|
||||
| RSS_CTRL_TCP_IPV6_SUPP;
|
||||
|
||||
if (rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV4)
|
||||
rss_ctrl |= RSS_CTRL_UDP_IPV4_SUPP;
|
||||
|
||||
if (rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV6)
|
||||
rss_ctrl |= RSS_CTRL_UDP_IPV6_SUPP;
|
||||
|
||||
hash_mask_len = ilog2(rtl8125_rss_indir_tbl_entries(tp));
|
||||
hash_mask_len &= (BIT_0 | BIT_1 | BIT_2);
|
||||
rss_ctrl |= hash_mask_len << RSS_MASK_BITS_OFFSET;
|
||||
|
||||
RTL_W32(tp, RSS_CTRL_8125, rss_ctrl);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rtl8125_set_rss_hash_opt(struct rtl8125_private *tp,
|
||||
struct ethtool_rxnfc *nfc)
|
||||
{
|
||||
u32 rss_flags = tp->rss_flags;
|
||||
|
||||
netif_info(tp, drv, tp->dev, "rss set hash\n");
|
||||
|
||||
/*
|
||||
* RSS does not support anything other than hashing
|
||||
* to queues on src and dst IPs and ports
|
||||
*/
|
||||
if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
|
||||
RXH_L4_B_0_1 | RXH_L4_B_2_3))
|
||||
return -EINVAL;
|
||||
|
||||
switch (nfc->flow_type) {
|
||||
case TCP_V4_FLOW:
|
||||
case TCP_V6_FLOW:
|
||||
if (!(nfc->data & RXH_IP_SRC) ||
|
||||
!(nfc->data & RXH_IP_DST) ||
|
||||
!(nfc->data & RXH_L4_B_0_1) ||
|
||||
!(nfc->data & RXH_L4_B_2_3))
|
||||
return -EINVAL;
|
||||
break;
|
||||
case UDP_V4_FLOW:
|
||||
if (!(nfc->data & RXH_IP_SRC) ||
|
||||
!(nfc->data & RXH_IP_DST))
|
||||
return -EINVAL;
|
||||
switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
|
||||
case 0:
|
||||
rss_flags &= ~RTL_8125_RSS_FLAG_HASH_UDP_IPV4;
|
||||
break;
|
||||
case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
|
||||
rss_flags |= RTL_8125_RSS_FLAG_HASH_UDP_IPV4;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
break;
|
||||
case UDP_V6_FLOW:
|
||||
if (!(nfc->data & RXH_IP_SRC) ||
|
||||
!(nfc->data & RXH_IP_DST))
|
||||
return -EINVAL;
|
||||
switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
|
||||
case 0:
|
||||
rss_flags &= ~RTL_8125_RSS_FLAG_HASH_UDP_IPV6;
|
||||
break;
|
||||
case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
|
||||
rss_flags |= RTL_8125_RSS_FLAG_HASH_UDP_IPV6;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
break;
|
||||
case SCTP_V4_FLOW:
|
||||
case AH_ESP_V4_FLOW:
|
||||
case AH_V4_FLOW:
|
||||
case ESP_V4_FLOW:
|
||||
case SCTP_V6_FLOW:
|
||||
case AH_ESP_V6_FLOW:
|
||||
case AH_V6_FLOW:
|
||||
case ESP_V6_FLOW:
|
||||
case IP_USER_FLOW:
|
||||
case ETHER_FLOW:
|
||||
/* RSS is not supported for these protocols */
|
||||
if (nfc->data) {
|
||||
netif_err(tp, drv, tp->dev, "Command parameters not supported\n");
|
||||
return -EINVAL;
|
||||
}
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
/* if we changed something we need to update flags */
|
||||
if (rss_flags != tp->rss_flags) {
|
||||
u32 rss_ctrl = RTL_R32(tp, RSS_CTRL_8125);
|
||||
|
||||
if ((rss_flags & RTL8125_UDP_RSS_FLAGS) &&
|
||||
!(tp->rss_flags & RTL8125_UDP_RSS_FLAGS))
|
||||
netdev_warn(tp->dev,
|
||||
"enabling UDP RSS: fragmented packets may "
|
||||
"arrive out of order to the stack above\n");
|
||||
|
||||
tp->rss_flags = rss_flags;
|
||||
|
||||
/* Perform hash on these packet types */
|
||||
rss_ctrl |= RSS_CTRL_TCP_IPV4_SUPP
|
||||
| RSS_CTRL_IPV4_SUPP
|
||||
| RSS_CTRL_IPV6_SUPP
|
||||
| RSS_CTRL_TCP_IPV6_SUPP;
|
||||
|
||||
rss_ctrl &= ~(RSS_CTRL_UDP_IPV4_SUPP |
|
||||
RSS_CTRL_UDP_IPV6_SUPP);
|
||||
|
||||
if (rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV4)
|
||||
rss_ctrl |= RSS_CTRL_UDP_IPV4_SUPP;
|
||||
|
||||
if (rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV6)
|
||||
rss_ctrl |= RSS_CTRL_UDP_IPV6_SUPP;
|
||||
|
||||
RTL_W32(tp, RSS_CTRL_8125, rss_ctrl);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int rtl8125_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
|
||||
{
|
||||
struct rtl8125_private *tp = netdev_priv(dev);
|
||||
int ret = -EOPNOTSUPP;
|
||||
|
||||
netif_info(tp, drv, tp->dev, "rss set rxnfc\n");
|
||||
|
||||
if (!(dev->features & NETIF_F_RXHASH))
|
||||
return ret;
|
||||
|
||||
switch (cmd->cmd) {
|
||||
case ETHTOOL_SRXFH:
|
||||
ret = rtl8125_set_rss_hash_opt(tp, cmd);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static u32 _rtl8125_get_rxfh_key_size(struct rtl8125_private *tp)
|
||||
{
|
||||
return sizeof(tp->rss_key);
|
||||
}
|
||||
|
||||
u32 rtl8125_get_rxfh_key_size(struct net_device *dev)
|
||||
{
|
||||
struct rtl8125_private *tp = netdev_priv(dev);
|
||||
|
||||
netif_info(tp, drv, tp->dev, "rss get key size\n");
|
||||
|
||||
if (!(dev->features & NETIF_F_RXHASH))
|
||||
return 0;
|
||||
|
||||
return _rtl8125_get_rxfh_key_size(tp);
|
||||
}
|
||||
|
||||
u32 rtl8125_rss_indir_size(struct net_device *dev)
|
||||
{
|
||||
struct rtl8125_private *tp = netdev_priv(dev);
|
||||
|
||||
netif_info(tp, drv, tp->dev, "rss get indir tbl size\n");
|
||||
|
||||
if (!(dev->features & NETIF_F_RXHASH))
|
||||
return 0;
|
||||
|
||||
return rtl8125_rss_indir_tbl_entries(tp);
|
||||
}
|
||||
|
||||
static void rtl8125_get_reta(struct rtl8125_private *tp, u32 *indir)
|
||||
{
|
||||
int i, reta_size = rtl8125_rss_indir_tbl_entries(tp);
|
||||
|
||||
for (i = 0; i < reta_size; i++)
|
||||
indir[i] = tp->rss_indir_tbl[i];
|
||||
}
|
||||
|
||||
int rtl8125_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
|
||||
u8 *hfunc)
|
||||
{
|
||||
struct rtl8125_private *tp = netdev_priv(dev);
|
||||
|
||||
netif_info(tp, drv, tp->dev, "rss get rxfh\n");
|
||||
|
||||
if (!(dev->features & NETIF_F_RXHASH))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
if (hfunc)
|
||||
*hfunc = ETH_RSS_HASH_TOP;
|
||||
|
||||
if (indir)
|
||||
rtl8125_get_reta(tp, indir);
|
||||
|
||||
if (key)
|
||||
memcpy(key, tp->rss_key, rtl8125_get_rxfh_key_size(dev));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define RSS_KEY_8125 0x4600
|
||||
#define RSS_INDIRECTION_TBL_8125_V2 0x4700
|
||||
|
||||
static u32 rtl8125_rss_key_reg(struct rtl8125_private *tp)
|
||||
{
|
||||
return RSS_KEY_8125;
|
||||
}
|
||||
|
||||
static u32 rtl8125_rss_indir_tbl_reg(struct rtl8125_private *tp)
|
||||
{
|
||||
return RSS_INDIRECTION_TBL_8125_V2;
|
||||
}
|
||||
|
||||
static void rtl8125_store_reta(struct rtl8125_private *tp)
|
||||
{
|
||||
u16 indir_tbl_reg = rtl8125_rss_indir_tbl_reg(tp);
|
||||
u32 i, reta_entries = rtl8125_rss_indir_tbl_entries(tp);
|
||||
u32 reta = 0;
|
||||
u8 *indir_tbl = tp->rss_indir_tbl;
|
||||
|
||||
/* Write redirection table to HW */
|
||||
for (i = 0; i < reta_entries; i++) {
|
||||
reta |= indir_tbl[i] << (i & 0x3) * 8;
|
||||
if ((i & 3) == 3) {
|
||||
RTL_W32(tp, indir_tbl_reg, reta);
|
||||
|
||||
indir_tbl_reg += 4;
|
||||
reta = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void rtl8125_store_rss_key(struct rtl8125_private *tp)
|
||||
{
|
||||
const u16 rss_key_reg = rtl8125_rss_key_reg(tp);
|
||||
u32 i, rss_key_size = _rtl8125_get_rxfh_key_size(tp);
|
||||
u32 *rss_key = (u32*)tp->rss_key;
|
||||
|
||||
/* Write redirection table to HW */
|
||||
for (i = 0; i < rss_key_size; i+=4)
|
||||
RTL_W32(tp, rss_key_reg + i, *rss_key++);
|
||||
}
|
||||
|
||||
int rtl8125_set_rxfh(struct net_device *dev, const u32 *indir,
|
||||
const u8 *key, const u8 hfunc)
|
||||
{
|
||||
struct rtl8125_private *tp = netdev_priv(dev);
|
||||
int i;
|
||||
u32 reta_entries = rtl8125_rss_indir_tbl_entries(tp);
|
||||
|
||||
netif_info(tp, drv, tp->dev, "rss set rxfh\n");
|
||||
|
||||
/* We require at least one supported parameter to be changed and no
|
||||
* change in any of the unsupported parameters
|
||||
*/
|
||||
if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
/* Fill out the redirection table */
|
||||
if (indir) {
|
||||
int max_queues = tp->num_rx_rings;
|
||||
|
||||
/* Verify user input. */
|
||||
for (i = 0; i < reta_entries; i++)
|
||||
if (indir[i] >= max_queues)
|
||||
return -EINVAL;
|
||||
|
||||
for (i = 0; i < reta_entries; i++)
|
||||
tp->rss_indir_tbl[i] = indir[i];
|
||||
}
|
||||
|
||||
/* Fill out the rss hash key */
|
||||
if (key)
|
||||
memcpy(tp->rss_key, key, rtl8125_get_rxfh_key_size(dev));
|
||||
|
||||
rtl8125_store_reta(tp);
|
||||
|
||||
rtl8125_store_rss_key(tp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static u32 rtl8125_get_rx_desc_hash(struct rtl8125_private *tp,
|
||||
struct RxDescV3 *descv3)
|
||||
{
|
||||
return le32_to_cpu(descv3->RxDescNormalDDWord2.RSSResult);
|
||||
}
|
||||
|
||||
#define RXS_8125B_RSS_UDP BIT(9)
|
||||
#define RXS_8125_RSS_IPV4 BIT(10)
|
||||
#define RXS_8125_RSS_IPV6 BIT(12)
|
||||
#define RXS_8125_RSS_TCP BIT(13)
|
||||
#define RTL8125_RXS_RSS_L3_TYPE_MASK (RXS_8125_RSS_IPV4 | RXS_8125_RSS_IPV6)
|
||||
#define RTL8125_RXS_RSS_L4_TYPE_MASK (RXS_8125_RSS_TCP | RXS_8125B_RSS_UDP)
|
||||
void rtl8125_rx_hash(struct rtl8125_private *tp,
|
||||
struct RxDescV3 *descv3,
|
||||
struct sk_buff *skb)
|
||||
{
|
||||
u16 rss_header_info;
|
||||
|
||||
if (!(tp->dev->features & NETIF_F_RXHASH))
|
||||
return;
|
||||
|
||||
rss_header_info = le16_to_cpu(descv3->RxDescNormalDDWord2.HeaderInfo);
|
||||
|
||||
if (!(rss_header_info & RTL8125_RXS_RSS_L3_TYPE_MASK))
|
||||
return;
|
||||
|
||||
skb_set_hash(skb, rtl8125_get_rx_desc_hash(tp, descv3),
|
||||
(RTL8125_RXS_RSS_L4_TYPE_MASK & rss_header_info) ?
|
||||
PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
|
||||
}
|
||||
|
||||
void rtl8125_disable_rss(struct rtl8125_private *tp)
|
||||
{
|
||||
RTL_W32(tp, RSS_CTRL_8125, 0x00);
|
||||
}
|
||||
|
||||
void _rtl8125_config_rss(struct rtl8125_private *tp)
|
||||
{
|
||||
_rtl8125_set_rss_hash_opt(tp);
|
||||
|
||||
rtl8125_store_reta(tp);
|
||||
|
||||
rtl8125_store_rss_key(tp);
|
||||
}
|
||||
|
||||
void rtl8125_config_rss(struct rtl8125_private *tp)
|
||||
{
|
||||
if (!tp->EnableRss) {
|
||||
rtl8125_disable_rss(tp);
|
||||
return;
|
||||
}
|
||||
|
||||
_rtl8125_config_rss(tp);
|
||||
}
|
||||
|
||||
void rtl8125_init_rss(struct rtl8125_private *tp)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < rtl8125_rss_indir_tbl_entries(tp); i++)
|
||||
tp->rss_indir_tbl[i] = ethtool_rxfh_indir_default(i, tp->num_rx_rings);
|
||||
|
||||
netdev_rss_key_fill(tp->rss_key, RTL8125_RSS_KEY_SIZE);
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
# r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2020 Realtek Semiconductor Corp. All rights reserved.
|
||||
# Copyright(c) 2021 Realtek Semiconductor Corp. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
|
@ -5,7 +5,7 @@
|
||||
# r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2020 Realtek Semiconductor Corp. All rights reserved.
|
||||
# Copyright(c) 2021 Realtek Semiconductor Corp. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
|
@ -5,7 +5,7 @@
|
||||
# r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2020 Realtek Semiconductor Corp. All rights reserved.
|
||||
# Copyright(c) 2021 Realtek Semiconductor Corp. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
|
@ -5,7 +5,7 @@
|
||||
# r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2020 Realtek Semiconductor Corp. All rights reserved.
|
||||
# Copyright(c) 2021 Realtek Semiconductor Corp. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
|
@ -5,7 +5,7 @@
|
||||
# r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2020 Realtek Semiconductor Corp. All rights reserved.
|
||||
# Copyright(c) 2021 Realtek Semiconductor Corp. All rights reserved.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify it
|
||||
# under the terms of the GNU General Public License as published by the Free
|
||||
|
Loading…
Reference in New Issue
Block a user