init r8101-1.037.01
This commit is contained in:
commit
ae3e3ed8c4
34
Makefile
Normal file
34
Makefile
Normal file
@ -0,0 +1,34 @@
|
||||
#
|
||||
# Download realtek r8101 linux driver from official site:
|
||||
# [https://www.realtek.com/component/zoo/category/network-interface-controllers-10-100-1000m-gigabit-ethernet-pci-express-software]
|
||||
#
|
||||
|
||||
include $(TOPDIR)/rules.mk
|
||||
include $(INCLUDE_DIR)/kernel.mk
|
||||
|
||||
PKG_NAME:=r8101
|
||||
PKG_VERSION:=1.037.01
|
||||
PKG_RELEASE:=1
|
||||
|
||||
PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
|
||||
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define KernelPackage/r8101
|
||||
TITLE:=Driver for Realtek r8101 chipsets
|
||||
SUBMENU:=Network Devices
|
||||
VERSION:=$(LINUX_VERSION)+$(PKG_VERSION)-$(BOARD)-$(PKG_RELEASE)
|
||||
DEPENDS:=@PCI_SUPPORT
|
||||
FILES:= $(PKG_BUILD_DIR)/r8101.ko
|
||||
AUTOLOAD:=$(call AutoProbe,r8101)
|
||||
endef
|
||||
|
||||
define Package/r8101/description
|
||||
This package contains a driver for Realtek r8101 chipsets.
|
||||
endef
|
||||
|
||||
define Build/Compile
|
||||
$(KERNEL_MAKE) M=$(PKG_BUILD_DIR) modules
|
||||
endef
|
||||
|
||||
$(eval $(call KernelPackage,r8101))
|
142
src/Makefile
Normal file
142
src/Makefile
Normal file
@ -0,0 +1,142 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
################################################################################
|
||||
#
|
||||
# r8101 is the Linux device driver released for Realtek Fast Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2022 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.
|
||||
################################################################################
|
||||
|
||||
CONFIG_SOC_LAN = n
|
||||
CONFIG_ASPM = y
|
||||
ENABLE_S5WOL = y
|
||||
ENABLE_S5_KEEP_CURR_MAC = n
|
||||
ENABLE_EEE = y
|
||||
ENABLE_S0_MAGIC_PACKET = n
|
||||
CONFIG_CTAP_SHORT_OFF = n
|
||||
|
||||
ifneq ($(KERNELRELEASE),)
|
||||
obj-m := r8101.o
|
||||
r8101-objs := r8101_n.o rtl_eeprom.o rtltool.o
|
||||
EXTRA_CFLAGS += -DCONFIG_R8101_NAPI
|
||||
EXTRA_CFLAGS += -DCONFIG_R8101_VLAN
|
||||
ifeq ($(CONFIG_SOC_LAN), y)
|
||||
EXTRA_CFLAGS += -DCONFIG_SOC_LAN
|
||||
endif
|
||||
ifeq ($(CONFIG_ASPM), y)
|
||||
EXTRA_CFLAGS += -DCONFIG_ASPM
|
||||
endif
|
||||
ifeq ($(ENABLE_S5WOL), y)
|
||||
EXTRA_CFLAGS += -DENABLE_S5WOL
|
||||
endif
|
||||
ifeq ($(ENABLE_S5_KEEP_CURR_MAC), y)
|
||||
EXTRA_CFLAGS += -DENABLE_S5_KEEP_CURR_MAC
|
||||
endif
|
||||
ifeq ($(ENABLE_EEE), y)
|
||||
EXTRA_CFLAGS += -DENABLE_EEE
|
||||
endif
|
||||
ifeq ($(ENABLE_S0_MAGIC_PACKET), y)
|
||||
EXTRA_CFLAGS += -DENABLE_S0_MAGIC_PACKET
|
||||
endif
|
||||
ifeq ($(CONFIG_CTAP_SHORT_OFF), y)
|
||||
EXTRA_CFLAGS += -DCONFIG_CTAP_SHORT_OFF
|
||||
endif
|
||||
else
|
||||
BASEDIR := /lib/modules/$(shell uname -r)
|
||||
KERNELDIR ?= $(BASEDIR)/build
|
||||
PWD :=$(shell pwd)
|
||||
DRIVERDIR := $(shell find $(BASEDIR)/kernel/drivers/net/ethernet -name realtek -type d)
|
||||
ifeq ($(DRIVERDIR),)
|
||||
DRIVERDIR := $(shell find $(BASEDIR)/kernel/drivers/net -name realtek -type d)
|
||||
endif
|
||||
ifeq ($(DRIVERDIR),)
|
||||
DRIVERDIR := $(BASEDIR)/kernel/drivers/net
|
||||
endif
|
||||
RTKDIR := $(subst $(BASEDIR)/,,$(DRIVERDIR))
|
||||
|
||||
KERNEL_GCC_VERSION := $(shell cat /proc/version | sed -n 's/.*gcc version \([[:digit:]]\.[[:digit:]]\.[[:digit:]]\).*/\1/p')
|
||||
CCVERSION = $(shell $(CC) -dumpversion)
|
||||
|
||||
KVER = $(shell uname -r)
|
||||
KMAJ = $(shell echo $(KVER) | \
|
||||
sed -e 's/^\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*.*/\1/')
|
||||
KMIN = $(shell echo $(KVER) | \
|
||||
sed -e 's/^[0-9][0-9]*\.\([0-9][0-9]*\)\.[0-9][0-9]*.*/\1/')
|
||||
KREV = $(shell echo $(KVER) | \
|
||||
sed -e 's/^[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/')
|
||||
|
||||
kver_ge = $(shell \
|
||||
echo test | awk '{if($(KMAJ) < $(1)) {print 0} else { \
|
||||
if($(KMAJ) > $(1)) {print 1} else { \
|
||||
if($(KMIN) < $(2)) {print 0} else { \
|
||||
if($(KMIN) > $(2)) {print 1} else { \
|
||||
if($(KREV) < $(3)) {print 0} else { print 1 } \
|
||||
}}}}}' \
|
||||
)
|
||||
|
||||
.PHONY: all
|
||||
all: print_vars clean modules install
|
||||
|
||||
print_vars:
|
||||
@echo
|
||||
@echo "CC: " $(CC)
|
||||
@echo "CCVERSION: " $(CCVERSION)
|
||||
@echo "KERNEL_GCC_VERSION: " $(KERNEL_GCC_VERSION)
|
||||
@echo "KVER: " $(KVER)
|
||||
@echo "KMAJ: " $(KMAJ)
|
||||
@echo "KMIN: " $(KMIN)
|
||||
@echo "KREV: " $(KREV)
|
||||
@echo "BASEDIR: " $(BASEDIR)
|
||||
@echo "DRIVERDIR: " $(DRIVERDIR)
|
||||
@echo "PWD: " $(PWD)
|
||||
@echo "RTKDIR: " $(RTKDIR)
|
||||
@echo
|
||||
|
||||
.PHONY:modules
|
||||
modules:
|
||||
#ifeq ($(call kver_ge,5,0,0),1)
|
||||
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
|
||||
#else
|
||||
# $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) modules
|
||||
#endif
|
||||
|
||||
.PHONY:clean
|
||||
clean:
|
||||
#ifeq ($(call kver_ge,5,0,0),1)
|
||||
$(MAKE) -C $(KERNELDIR) M=$(PWD) clean
|
||||
#else
|
||||
# $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) clean
|
||||
#endif
|
||||
|
||||
.PHONY:install
|
||||
install:
|
||||
#ifeq ($(call kver_ge,5,0,0),1)
|
||||
$(MAKE) -C $(KERNELDIR) M=$(PWD) INSTALL_MOD_DIR=$(RTKDIR) modules_install
|
||||
#else
|
||||
# $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) INSTALL_MOD_DIR=$(RTKDIR) modules_install
|
||||
#endif
|
||||
|
||||
endif
|
75
src/Makefile_linux24x
Normal file
75
src/Makefile_linux24x
Normal file
@ -0,0 +1,75 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
################################################################################
|
||||
#
|
||||
# r8101 is the Linux device driver released for Realtek Fast Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2022 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.
|
||||
################################################################################
|
||||
|
||||
CC := gcc
|
||||
LD := ld
|
||||
ARCH := $(shell uname -m | sed 's/i.86/i386/')
|
||||
KSRC := /lib/modules/$(shell uname -r)/build
|
||||
CONFIG_FILE := $(KSRC)/include/linux/autoconf.h
|
||||
KMISC := /lib/modules/$(shell uname -r)/kernel/drivers/net/
|
||||
|
||||
|
||||
ifeq ($(ARCH),x86_64)
|
||||
MODCFLAGS += -mcmodel=kernel -mno-red-zone
|
||||
endif
|
||||
|
||||
#standard flags for module builds
|
||||
MODCFLAGS += -DLINUX -D__KERNEL__ -DMODULE -O2 -pipe -Wall
|
||||
MODCFLAGS += -I$(KSRC)/include -I.
|
||||
MODCFLAGS += -DMODVERSIONS -DEXPORT_SYMTAB -include $(KSRC)/include/linux/modversions.h
|
||||
SOURCE := r8101_n.c rtl_eeprom.c rtltool.c
|
||||
OBJS := $(SOURCE:.c=.o)
|
||||
|
||||
|
||||
SMP := $(shell $(CC) $(MODCFLAGS) -E -dM $(CONFIG_FILE) | \
|
||||
grep CONFIG_SMP | awk '{print $$3}')
|
||||
|
||||
ifneq ($(SMP),1)
|
||||
SMP := 0
|
||||
endif
|
||||
|
||||
ifeq ($(SMP),1)
|
||||
MODCFLAGS += -D__SMP__
|
||||
endif
|
||||
|
||||
modules: $(OBJS)
|
||||
$(LD) -r $^ -o r8101.o
|
||||
strip --strip-debug r8101.o
|
||||
|
||||
%.o: %.c
|
||||
$(CC) $(MODCFLAGS) -c $< -o $@
|
||||
|
||||
clean:
|
||||
rm *.o -f
|
||||
|
||||
install:
|
||||
install -m 744 -c r8101.o $(KMISC)
|
1593
src/r8101.h
Normal file
1593
src/r8101.h
Normal file
File diff suppressed because it is too large
Load Diff
14209
src/r8101_n.c
Normal file
14209
src/r8101_n.c
Normal file
File diff suppressed because it is too large
Load Diff
289
src/rtl_eeprom.c
Normal file
289
src/rtl_eeprom.c
Normal file
@ -0,0 +1,289 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
################################################################################
|
||||
#
|
||||
# r8101 is the Linux device driver released for Realtek Fast Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2022 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/init.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/version.h>
|
||||
#include <linux/ethtool.h>
|
||||
#include <linux/netdevice.h>
|
||||
#include <linux/delay.h>
|
||||
|
||||
#include <asm/io.h>
|
||||
|
||||
#include "r8101.h"
|
||||
#include "rtl_eeprom.h"
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
//rtl8101_eeprom_type():
|
||||
// tell the eeprom type
|
||||
//return value:
|
||||
// 0: the eeprom type is 93C46
|
||||
// 1: the eeprom type is 93C56 or 93C66
|
||||
//-------------------------------------------------------------------
|
||||
void rtl8101_eeprom_type(struct rtl8101_private *tp)
|
||||
{
|
||||
u16 magic = 0;
|
||||
|
||||
if (tp->mcfg == CFG_METHOD_DEFAULT)
|
||||
goto out_no_eeprom;
|
||||
|
||||
if(RTL_R8(tp, 0xD2)&0x04) {
|
||||
//not support
|
||||
//tp->eeprom_type = EEPROM_TWSI;
|
||||
//tp->eeprom_len = 256;
|
||||
goto out_no_eeprom;
|
||||
} else if(RTL_R32(tp, RxConfig) & RxCfg_9356SEL) {
|
||||
tp->eeprom_type = EEPROM_TYPE_93C56;
|
||||
tp->eeprom_len = 256;
|
||||
} else {
|
||||
tp->eeprom_type = EEPROM_TYPE_93C46;
|
||||
tp->eeprom_len = 128;
|
||||
}
|
||||
|
||||
magic = rtl8101_eeprom_read_sc(tp, 0);
|
||||
|
||||
out_no_eeprom:
|
||||
if ((magic != 0x8129) && (magic != 0x8128)) {
|
||||
tp->eeprom_type = EEPROM_TYPE_NONE;
|
||||
tp->eeprom_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void rtl8101_eeprom_cleanup(struct rtl8101_private *tp)
|
||||
{
|
||||
u8 x;
|
||||
|
||||
x = RTL_R8(tp, Cfg9346);
|
||||
x &= ~(Cfg9346_EEDI | Cfg9346_EECS);
|
||||
|
||||
RTL_W8(tp, Cfg9346, x);
|
||||
|
||||
rtl8101_raise_clock(tp, &x);
|
||||
rtl8101_lower_clock(tp, &x);
|
||||
}
|
||||
|
||||
int rtl8101_eeprom_cmd_done(struct rtl8101_private *tp)
|
||||
{
|
||||
u8 x;
|
||||
int i;
|
||||
|
||||
rtl8101_stand_by(tp);
|
||||
|
||||
for (i = 0; i < 50000; i++) {
|
||||
x = RTL_R8(tp, Cfg9346);
|
||||
|
||||
if (x & Cfg9346_EEDO) {
|
||||
udelay(RTL_CLOCK_RATE * 2 * 3);
|
||||
return 0;
|
||||
}
|
||||
udelay(1);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
//rtl8101_eeprom_read_sc():
|
||||
// read one word from eeprom
|
||||
//-------------------------------------------------------------------
|
||||
u16 rtl8101_eeprom_read_sc(struct rtl8101_private *tp, u16 reg)
|
||||
{
|
||||
int addr_sz = 6;
|
||||
u8 x;
|
||||
u16 data;
|
||||
|
||||
if(tp->eeprom_type == EEPROM_TYPE_NONE) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tp->eeprom_type==EEPROM_TYPE_93C46)
|
||||
addr_sz = 6;
|
||||
else if (tp->eeprom_type==EEPROM_TYPE_93C56)
|
||||
addr_sz = 8;
|
||||
|
||||
x = Cfg9346_EEM1 | Cfg9346_EECS;
|
||||
RTL_W8(tp, Cfg9346, x);
|
||||
|
||||
rtl8101_shift_out_bits(tp, RTL_EEPROM_READ_OPCODE, 3);
|
||||
rtl8101_shift_out_bits(tp, reg, addr_sz);
|
||||
|
||||
data = rtl8101_shift_in_bits(tp);
|
||||
|
||||
rtl8101_eeprom_cleanup(tp);
|
||||
|
||||
RTL_W8(tp, Cfg9346, 0);
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
//rtl8101_eeprom_write_sc():
|
||||
// write one word to a specific address in the eeprom
|
||||
//-------------------------------------------------------------------
|
||||
void rtl8101_eeprom_write_sc(struct rtl8101_private *tp, u16 reg, u16 data)
|
||||
{
|
||||
u8 x;
|
||||
int addr_sz = 6;
|
||||
int w_dummy_addr = 4;
|
||||
|
||||
if(tp->eeprom_type == EEPROM_TYPE_NONE) {
|
||||
return ;
|
||||
}
|
||||
|
||||
if (tp->eeprom_type==EEPROM_TYPE_93C46) {
|
||||
addr_sz = 6;
|
||||
w_dummy_addr = 4;
|
||||
} else if (tp->eeprom_type==EEPROM_TYPE_93C56) {
|
||||
addr_sz = 8;
|
||||
w_dummy_addr = 6;
|
||||
}
|
||||
|
||||
x = Cfg9346_EEM1 | Cfg9346_EECS;
|
||||
RTL_W8(tp, Cfg9346, x);
|
||||
|
||||
rtl8101_shift_out_bits(tp, RTL_EEPROM_EWEN_OPCODE, 5);
|
||||
rtl8101_shift_out_bits(tp, reg, w_dummy_addr);
|
||||
rtl8101_stand_by(tp);
|
||||
|
||||
rtl8101_shift_out_bits(tp, RTL_EEPROM_ERASE_OPCODE, 3);
|
||||
rtl8101_shift_out_bits(tp, reg, addr_sz);
|
||||
if (rtl8101_eeprom_cmd_done(tp) < 0) {
|
||||
return;
|
||||
}
|
||||
rtl8101_stand_by(tp);
|
||||
|
||||
rtl8101_shift_out_bits(tp, RTL_EEPROM_WRITE_OPCODE, 3);
|
||||
rtl8101_shift_out_bits(tp, reg, addr_sz);
|
||||
rtl8101_shift_out_bits(tp, data, 16);
|
||||
if (rtl8101_eeprom_cmd_done(tp) < 0) {
|
||||
return;
|
||||
}
|
||||
rtl8101_stand_by(tp);
|
||||
|
||||
rtl8101_shift_out_bits(tp, RTL_EEPROM_EWDS_OPCODE, 5);
|
||||
rtl8101_shift_out_bits(tp, reg, w_dummy_addr);
|
||||
|
||||
rtl8101_eeprom_cleanup(tp);
|
||||
RTL_W8(tp, Cfg9346, 0);
|
||||
}
|
||||
|
||||
void rtl8101_raise_clock(struct rtl8101_private *tp, u8 *x)
|
||||
{
|
||||
*x = *x | Cfg9346_EESK;
|
||||
RTL_W8(tp, Cfg9346, *x);
|
||||
udelay(RTL_CLOCK_RATE);
|
||||
}
|
||||
|
||||
void rtl8101_lower_clock(struct rtl8101_private *tp, u8 *x)
|
||||
{
|
||||
|
||||
*x = *x & ~Cfg9346_EESK;
|
||||
RTL_W8(tp, Cfg9346, *x);
|
||||
udelay(RTL_CLOCK_RATE);
|
||||
}
|
||||
|
||||
void rtl8101_shift_out_bits(struct rtl8101_private *tp, int data, int count)
|
||||
{
|
||||
u8 x;
|
||||
int mask;
|
||||
|
||||
mask = 0x01 << (count - 1);
|
||||
x = RTL_R8(tp, Cfg9346);
|
||||
x &= ~(Cfg9346_EEDI | Cfg9346_EEDO);
|
||||
|
||||
do {
|
||||
if (data & mask)
|
||||
x |= Cfg9346_EEDI;
|
||||
else
|
||||
x &= ~Cfg9346_EEDI;
|
||||
|
||||
RTL_W8(tp, Cfg9346, x);
|
||||
udelay(RTL_CLOCK_RATE);
|
||||
rtl8101_raise_clock(tp, &x);
|
||||
rtl8101_lower_clock(tp, &x);
|
||||
mask = mask >> 1;
|
||||
} while(mask);
|
||||
|
||||
x &= ~Cfg9346_EEDI;
|
||||
RTL_W8(tp, Cfg9346, x);
|
||||
}
|
||||
|
||||
u16 rtl8101_shift_in_bits(struct rtl8101_private *tp)
|
||||
{
|
||||
u8 x;
|
||||
u16 d, i;
|
||||
|
||||
x = RTL_R8(tp, Cfg9346);
|
||||
x &= ~(Cfg9346_EEDI | Cfg9346_EEDO);
|
||||
|
||||
d = 0;
|
||||
|
||||
for (i = 0; i < 16; i++) {
|
||||
d = d << 1;
|
||||
rtl8101_raise_clock(tp, &x);
|
||||
|
||||
x = RTL_R8(tp, Cfg9346);
|
||||
x &= ~Cfg9346_EEDI;
|
||||
|
||||
if (x & Cfg9346_EEDO)
|
||||
d |= 1;
|
||||
|
||||
rtl8101_lower_clock(tp, &x);
|
||||
}
|
||||
|
||||
return d;
|
||||
}
|
||||
|
||||
void rtl8101_stand_by(struct rtl8101_private *tp)
|
||||
{
|
||||
u8 x;
|
||||
|
||||
x = RTL_R8(tp, Cfg9346);
|
||||
x &= ~(Cfg9346_EECS | Cfg9346_EESK);
|
||||
RTL_W8(tp, Cfg9346, x);
|
||||
udelay(RTL_CLOCK_RATE);
|
||||
|
||||
x |= Cfg9346_EECS;
|
||||
RTL_W8(tp, Cfg9346, x);
|
||||
}
|
||||
|
||||
void rtl8101_set_eeprom_sel_low(struct rtl8101_private *tp)
|
||||
{
|
||||
RTL_W8(tp, Cfg9346, Cfg9346_EEM1);
|
||||
RTL_W8(tp, Cfg9346, Cfg9346_EEM1 | Cfg9346_EESK);
|
||||
|
||||
udelay(20);
|
||||
|
||||
RTL_W8(tp, Cfg9346, Cfg9346_EEM1);
|
||||
}
|
56
src/rtl_eeprom.h
Normal file
56
src/rtl_eeprom.h
Normal file
@ -0,0 +1,56 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/*
|
||||
################################################################################
|
||||
#
|
||||
# r8101 is the Linux device driver released for Realtek Fast Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2022 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.
|
||||
***********************************************************************************/
|
||||
|
||||
//EEPROM opcodes
|
||||
#define RTL_EEPROM_READ_OPCODE 06
|
||||
#define RTL_EEPROM_WRITE_OPCODE 05
|
||||
#define RTL_EEPROM_ERASE_OPCODE 07
|
||||
#define RTL_EEPROM_EWEN_OPCODE 19
|
||||
#define RTL_EEPROM_EWDS_OPCODE 16
|
||||
|
||||
#define RTL_CLOCK_RATE 3
|
||||
|
||||
void rtl8101_eeprom_type(struct rtl8101_private *tp);
|
||||
void rtl8101_eeprom_cleanup(struct rtl8101_private *tp);
|
||||
u16 rtl8101_eeprom_read_sc(struct rtl8101_private *tp, u16 reg);
|
||||
void rtl8101_eeprom_write_sc(struct rtl8101_private *tp, u16 reg, u16 data);
|
||||
void rtl8101_shift_out_bits(struct rtl8101_private *tp, int data, int count);
|
||||
u16 rtl8101_shift_in_bits(struct rtl8101_private *tp);
|
||||
void rtl8101_raise_clock(struct rtl8101_private *tp, u8 *x);
|
||||
void rtl8101_lower_clock(struct rtl8101_private *tp, u8 *x);
|
||||
void rtl8101_stand_by(struct rtl8101_private *tp);
|
||||
void rtl8101_set_eeprom_sel_low(struct rtl8101_private *tp);
|
||||
|
||||
|
||||
|
419
src/rtl_ethtool.h
Normal file
419
src/rtl_ethtool.h
Normal file
@ -0,0 +1,419 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/*
|
||||
################################################################################
|
||||
#
|
||||
# r8101 is the Linux device driver released for Realtek Fast Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2022 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.
|
||||
***********************************************************************************/
|
||||
|
||||
/*****************************************************************************/
|
||||
/* 2.6.4 => 2.6.0 */
|
||||
#if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,25) || \
|
||||
( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) && \
|
||||
LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) ) )
|
||||
#define ETHTOOL_OPS_COMPAT
|
||||
#endif /* 2.6.4 => 2.6.0 */
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
|
||||
#undef ethtool_ops
|
||||
#define ethtool_ops _kc_ethtool_ops
|
||||
|
||||
struct _kc_ethtool_ops {
|
||||
int (*get_settings)(struct net_device *, struct ethtool_cmd *);
|
||||
int (*set_settings)(struct net_device *, struct ethtool_cmd *);
|
||||
void (*get_drvinfo)(struct net_device *, struct ethtool_drvinfo *);
|
||||
int (*get_regs_len)(struct net_device *);
|
||||
void (*get_regs)(struct net_device *, struct ethtool_regs *, void *);
|
||||
void (*get_wol)(struct net_device *, struct ethtool_wolinfo *);
|
||||
int (*set_wol)(struct net_device *, struct ethtool_wolinfo *);
|
||||
u32 (*get_msglevel)(struct net_device *);
|
||||
void (*set_msglevel)(struct net_device *, u32);
|
||||
int (*nway_reset)(struct net_device *);
|
||||
u32 (*get_link)(struct net_device *);
|
||||
int (*get_eeprom_len)(struct net_device *);
|
||||
int (*get_eeprom)(struct net_device *, struct ethtool_eeprom *, u8 *);
|
||||
int (*set_eeprom)(struct net_device *, struct ethtool_eeprom *, u8 *);
|
||||
int (*get_coalesce)(struct net_device *, struct ethtool_coalesce *);
|
||||
int (*set_coalesce)(struct net_device *, struct ethtool_coalesce *);
|
||||
void (*get_ringparam)(struct net_device *, struct ethtool_ringparam *);
|
||||
int (*set_ringparam)(struct net_device *, struct ethtool_ringparam *);
|
||||
void (*get_pauseparam)(struct net_device *,
|
||||
struct ethtool_pauseparam*);
|
||||
int (*set_pauseparam)(struct net_device *,
|
||||
struct ethtool_pauseparam*);
|
||||
u32 (*get_rx_csum)(struct net_device *);
|
||||
int (*set_rx_csum)(struct net_device *, u32);
|
||||
u32 (*get_tx_csum)(struct net_device *);
|
||||
int (*set_tx_csum)(struct net_device *, u32);
|
||||
u32 (*get_sg)(struct net_device *);
|
||||
int (*set_sg)(struct net_device *, u32);
|
||||
u32 (*get_tso)(struct net_device *);
|
||||
int (*set_tso)(struct net_device *, u32);
|
||||
int (*self_test_count)(struct net_device *);
|
||||
void (*self_test)(struct net_device *, struct ethtool_test *, u64 *);
|
||||
void (*get_strings)(struct net_device *, u32 stringset, u8 *);
|
||||
int (*phys_id)(struct net_device *, u32);
|
||||
int (*get_stats_count)(struct net_device *);
|
||||
void (*get_ethtool_stats)(struct net_device *, struct ethtool_stats *,
|
||||
u64 *);
|
||||
} *ethtool_ops = NULL;
|
||||
|
||||
#undef SET_ETHTOOL_OPS
|
||||
#define SET_ETHTOOL_OPS(netdev, ops) (ethtool_ops = (ops))
|
||||
|
||||
#endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
|
||||
|
||||
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,16,0)
|
||||
#ifndef SET_ETHTOOL_OPS
|
||||
#define SET_ETHTOOL_OPS(netdev,ops) \
|
||||
( (netdev)->ethtool_ops = (ops) )
|
||||
#endif //SET_ETHTOOL_OPS
|
||||
#endif //LINUX_VERSION_CODE >= KERNEL_VERSION(3,16,0)
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Installations with ethtool version without eeprom, adapter id, or statistics
|
||||
* support */
|
||||
|
||||
#ifndef ETH_GSTRING_LEN
|
||||
#define ETH_GSTRING_LEN 32
|
||||
#endif
|
||||
|
||||
#ifndef ETHTOOL_GSTATS
|
||||
#define ETHTOOL_GSTATS 0x1d
|
||||
#undef ethtool_drvinfo
|
||||
#define ethtool_drvinfo k_ethtool_drvinfo
|
||||
struct k_ethtool_drvinfo {
|
||||
u32 cmd;
|
||||
char driver[32];
|
||||
char version[32];
|
||||
char fw_version[32];
|
||||
char bus_info[32];
|
||||
char reserved1[32];
|
||||
char reserved2[16];
|
||||
u32 n_stats;
|
||||
u32 testinfo_len;
|
||||
u32 eedump_len;
|
||||
u32 regdump_len;
|
||||
};
|
||||
|
||||
struct ethtool_stats {
|
||||
u32 cmd;
|
||||
u32 n_stats;
|
||||
u64 data[0];
|
||||
};
|
||||
#endif /* ETHTOOL_GSTATS */
|
||||
|
||||
#ifndef ETHTOOL_PHYS_ID
|
||||
#define ETHTOOL_PHYS_ID 0x1c
|
||||
#endif /* ETHTOOL_PHYS_ID */
|
||||
|
||||
#ifndef ETHTOOL_GSTRINGS
|
||||
#define ETHTOOL_GSTRINGS 0x1b
|
||||
enum ethtool_stringset {
|
||||
ETH_SS_TEST = 0,
|
||||
ETH_SS_STATS,
|
||||
};
|
||||
struct ethtool_gstrings {
|
||||
u32 cmd; /* ETHTOOL_GSTRINGS */
|
||||
u32 string_set; /* string set id e.c. ETH_SS_TEST, etc*/
|
||||
u32 len; /* number of strings in the string set */
|
||||
u8 data[0];
|
||||
};
|
||||
#endif /* ETHTOOL_GSTRINGS */
|
||||
|
||||
#ifndef ETHTOOL_TEST
|
||||
#define ETHTOOL_TEST 0x1a
|
||||
enum ethtool_test_flags {
|
||||
ETH_TEST_FL_OFFLINE = (1 << 0),
|
||||
ETH_TEST_FL_FAILED = (1 << 1),
|
||||
};
|
||||
struct ethtool_test {
|
||||
u32 cmd;
|
||||
u32 flags;
|
||||
u32 reserved;
|
||||
u32 len;
|
||||
u64 data[0];
|
||||
};
|
||||
#endif /* ETHTOOL_TEST */
|
||||
|
||||
#ifndef ETHTOOL_GEEPROM
|
||||
#define ETHTOOL_GEEPROM 0xb
|
||||
#undef ETHTOOL_GREGS
|
||||
struct ethtool_eeprom {
|
||||
u32 cmd;
|
||||
u32 magic;
|
||||
u32 offset;
|
||||
u32 len;
|
||||
u8 data[0];
|
||||
};
|
||||
|
||||
struct ethtool_value {
|
||||
u32 cmd;
|
||||
u32 data;
|
||||
};
|
||||
#endif /* ETHTOOL_GEEPROM */
|
||||
|
||||
#ifndef ETHTOOL_GLINK
|
||||
#define ETHTOOL_GLINK 0xa
|
||||
#endif /* ETHTOOL_GLINK */
|
||||
|
||||
#ifndef ETHTOOL_GREGS
|
||||
#define ETHTOOL_GREGS 0x00000004 /* Get NIC registers */
|
||||
#define ethtool_regs _kc_ethtool_regs
|
||||
/* for passing big chunks of data */
|
||||
struct _kc_ethtool_regs {
|
||||
u32 cmd;
|
||||
u32 version; /* driver-specific, indicates different chips/revs */
|
||||
u32 len; /* bytes */
|
||||
u8 data[0];
|
||||
};
|
||||
#endif /* ETHTOOL_GREGS */
|
||||
|
||||
#ifndef ETHTOOL_GMSGLVL
|
||||
#define ETHTOOL_GMSGLVL 0x00000007 /* Get driver message level */
|
||||
#endif
|
||||
#ifndef ETHTOOL_SMSGLVL
|
||||
#define ETHTOOL_SMSGLVL 0x00000008 /* Set driver msg level, priv. */
|
||||
#endif
|
||||
#ifndef ETHTOOL_NWAY_RST
|
||||
#define ETHTOOL_NWAY_RST 0x00000009 /* Restart autonegotiation, priv */
|
||||
#endif
|
||||
#ifndef ETHTOOL_GLINK
|
||||
#define ETHTOOL_GLINK 0x0000000a /* Get link status */
|
||||
#endif
|
||||
#ifndef ETHTOOL_GEEPROM
|
||||
#define ETHTOOL_GEEPROM 0x0000000b /* Get EEPROM data */
|
||||
#endif
|
||||
#ifndef ETHTOOL_SEEPROM
|
||||
#define ETHTOOL_SEEPROM 0x0000000c /* Set EEPROM data */
|
||||
#endif
|
||||
#ifndef ETHTOOL_GCOALESCE
|
||||
#define ETHTOOL_GCOALESCE 0x0000000e /* Get coalesce config */
|
||||
/* for configuring coalescing parameters of chip */
|
||||
#define ethtool_coalesce _kc_ethtool_coalesce
|
||||
struct _kc_ethtool_coalesce {
|
||||
u32 cmd; /* ETHTOOL_{G,S}COALESCE */
|
||||
|
||||
/* How many usecs to delay an RX interrupt after
|
||||
* a packet arrives. If 0, only rx_max_coalesced_frames
|
||||
* is used.
|
||||
*/
|
||||
u32 rx_coalesce_usecs;
|
||||
|
||||
/* How many packets to delay an RX interrupt after
|
||||
* a packet arrives. If 0, only rx_coalesce_usecs is
|
||||
* used. It is illegal to set both usecs and max frames
|
||||
* to zero as this would cause RX interrupts to never be
|
||||
* generated.
|
||||
*/
|
||||
u32 rx_max_coalesced_frames;
|
||||
|
||||
/* Same as above two parameters, except that these values
|
||||
* apply while an IRQ is being serviced by the host. Not
|
||||
* all cards support this feature and the values are ignored
|
||||
* in that case.
|
||||
*/
|
||||
u32 rx_coalesce_usecs_irq;
|
||||
u32 rx_max_coalesced_frames_irq;
|
||||
|
||||
/* How many usecs to delay a TX interrupt after
|
||||
* a packet is sent. If 0, only tx_max_coalesced_frames
|
||||
* is used.
|
||||
*/
|
||||
u32 tx_coalesce_usecs;
|
||||
|
||||
/* How many packets to delay a TX interrupt after
|
||||
* a packet is sent. If 0, only tx_coalesce_usecs is
|
||||
* used. It is illegal to set both usecs and max frames
|
||||
* to zero as this would cause TX interrupts to never be
|
||||
* generated.
|
||||
*/
|
||||
u32 tx_max_coalesced_frames;
|
||||
|
||||
/* Same as above two parameters, except that these values
|
||||
* apply while an IRQ is being serviced by the host. Not
|
||||
* all cards support this feature and the values are ignored
|
||||
* in that case.
|
||||
*/
|
||||
u32 tx_coalesce_usecs_irq;
|
||||
u32 tx_max_coalesced_frames_irq;
|
||||
|
||||
/* How many usecs to delay in-memory statistics
|
||||
* block updates. Some drivers do not have an in-memory
|
||||
* statistic block, and in such cases this value is ignored.
|
||||
* This value must not be zero.
|
||||
*/
|
||||
u32 stats_block_coalesce_usecs;
|
||||
|
||||
/* Adaptive RX/TX coalescing is an algorithm implemented by
|
||||
* some drivers to improve latency under low packet rates and
|
||||
* improve throughput under high packet rates. Some drivers
|
||||
* only implement one of RX or TX adaptive coalescing. Anything
|
||||
* not implemented by the driver causes these values to be
|
||||
* silently ignored.
|
||||
*/
|
||||
u32 use_adaptive_rx_coalesce;
|
||||
u32 use_adaptive_tx_coalesce;
|
||||
|
||||
/* When the packet rate (measured in packets per second)
|
||||
* is below pkt_rate_low, the {rx,tx}_*_low parameters are
|
||||
* used.
|
||||
*/
|
||||
u32 pkt_rate_low;
|
||||
u32 rx_coalesce_usecs_low;
|
||||
u32 rx_max_coalesced_frames_low;
|
||||
u32 tx_coalesce_usecs_low;
|
||||
u32 tx_max_coalesced_frames_low;
|
||||
|
||||
/* When the packet rate is below pkt_rate_high but above
|
||||
* pkt_rate_low (both measured in packets per second) the
|
||||
* normal {rx,tx}_* coalescing parameters are used.
|
||||
*/
|
||||
|
||||
/* When the packet rate is (measured in packets per second)
|
||||
* is above pkt_rate_high, the {rx,tx}_*_high parameters are
|
||||
* used.
|
||||
*/
|
||||
u32 pkt_rate_high;
|
||||
u32 rx_coalesce_usecs_high;
|
||||
u32 rx_max_coalesced_frames_high;
|
||||
u32 tx_coalesce_usecs_high;
|
||||
u32 tx_max_coalesced_frames_high;
|
||||
|
||||
/* How often to do adaptive coalescing packet rate sampling,
|
||||
* measured in seconds. Must not be zero.
|
||||
*/
|
||||
u32 rate_sample_interval;
|
||||
};
|
||||
#endif /* ETHTOOL_GCOALESCE */
|
||||
|
||||
#ifndef ETHTOOL_SCOALESCE
|
||||
#define ETHTOOL_SCOALESCE 0x0000000f /* Set coalesce config. */
|
||||
#endif
|
||||
#ifndef ETHTOOL_GRINGPARAM
|
||||
#define ETHTOOL_GRINGPARAM 0x00000010 /* Get ring parameters */
|
||||
/* for configuring RX/TX ring parameters */
|
||||
#define ethtool_ringparam _kc_ethtool_ringparam
|
||||
struct _kc_ethtool_ringparam {
|
||||
u32 cmd; /* ETHTOOL_{G,S}RINGPARAM */
|
||||
|
||||
/* Read only attributes. These indicate the maximum number
|
||||
* of pending RX/TX ring entries the driver will allow the
|
||||
* user to set.
|
||||
*/
|
||||
u32 rx_max_pending;
|
||||
u32 rx_mini_max_pending;
|
||||
u32 rx_jumbo_max_pending;
|
||||
u32 tx_max_pending;
|
||||
|
||||
/* Values changeable by the user. The valid values are
|
||||
* in the range 1 to the "*_max_pending" counterpart above.
|
||||
*/
|
||||
u32 rx_pending;
|
||||
u32 rx_mini_pending;
|
||||
u32 rx_jumbo_pending;
|
||||
u32 tx_pending;
|
||||
};
|
||||
#endif /* ETHTOOL_GRINGPARAM */
|
||||
|
||||
#ifndef ETHTOOL_SRINGPARAM
|
||||
#define ETHTOOL_SRINGPARAM 0x00000011 /* Set ring parameters, priv. */
|
||||
#endif
|
||||
#ifndef ETHTOOL_GPAUSEPARAM
|
||||
#define ETHTOOL_GPAUSEPARAM 0x00000012 /* Get pause parameters */
|
||||
/* for configuring link flow control parameters */
|
||||
#define ethtool_pauseparam _kc_ethtool_pauseparam
|
||||
struct _kc_ethtool_pauseparam {
|
||||
u32 cmd; /* ETHTOOL_{G,S}PAUSEPARAM */
|
||||
|
||||
/* If the link is being auto-negotiated (via ethtool_cmd.autoneg
|
||||
* being true) the user may set 'autonet' here non-zero to have the
|
||||
* pause parameters be auto-negotiated too. In such a case, the
|
||||
* {rx,tx}_pause values below determine what capabilities are
|
||||
* advertised.
|
||||
*
|
||||
* If 'autoneg' is zero or the link is not being auto-negotiated,
|
||||
* then {rx,tx}_pause force the driver to use/not-use pause
|
||||
* flow control.
|
||||
*/
|
||||
u32 autoneg;
|
||||
u32 rx_pause;
|
||||
u32 tx_pause;
|
||||
};
|
||||
#endif /* ETHTOOL_GPAUSEPARAM */
|
||||
|
||||
#ifndef ETHTOOL_SPAUSEPARAM
|
||||
#define ETHTOOL_SPAUSEPARAM 0x00000013 /* Set pause parameters. */
|
||||
#endif
|
||||
#ifndef ETHTOOL_GRXCSUM
|
||||
#define ETHTOOL_GRXCSUM 0x00000014 /* Get RX hw csum enable (ethtool_value) */
|
||||
#endif
|
||||
#ifndef ETHTOOL_SRXCSUM
|
||||
#define ETHTOOL_SRXCSUM 0x00000015 /* Set RX hw csum enable (ethtool_value) */
|
||||
#endif
|
||||
#ifndef ETHTOOL_GTXCSUM
|
||||
#define ETHTOOL_GTXCSUM 0x00000016 /* Get TX hw csum enable (ethtool_value) */
|
||||
#endif
|
||||
#ifndef ETHTOOL_STXCSUM
|
||||
#define ETHTOOL_STXCSUM 0x00000017 /* Set TX hw csum enable (ethtool_value) */
|
||||
#endif
|
||||
#ifndef ETHTOOL_GSG
|
||||
#define ETHTOOL_GSG 0x00000018 /* Get scatter-gather enable
|
||||
* (ethtool_value) */
|
||||
#endif
|
||||
#ifndef ETHTOOL_SSG
|
||||
#define ETHTOOL_SSG 0x00000019 /* Set scatter-gather enable
|
||||
* (ethtool_value). */
|
||||
#endif
|
||||
#ifndef ETHTOOL_TEST
|
||||
#define ETHTOOL_TEST 0x0000001a /* execute NIC self-test, priv. */
|
||||
#endif
|
||||
#ifndef ETHTOOL_GSTRINGS
|
||||
#define ETHTOOL_GSTRINGS 0x0000001b /* get specified string set */
|
||||
#endif
|
||||
#ifndef ETHTOOL_PHYS_ID
|
||||
#define ETHTOOL_PHYS_ID 0x0000001c /* identify the NIC */
|
||||
#endif
|
||||
#ifndef ETHTOOL_GSTATS
|
||||
#define ETHTOOL_GSTATS 0x0000001d /* get NIC-specific statistics */
|
||||
#endif
|
||||
#ifndef ETHTOOL_GTSO
|
||||
#define ETHTOOL_GTSO 0x0000001e /* Get TSO enable (ethtool_value) */
|
||||
#endif
|
||||
#ifndef ETHTOOL_STSO
|
||||
#define ETHTOOL_STSO 0x0000001f /* Set TSO enable (ethtool_value) */
|
||||
#endif
|
||||
|
||||
#ifndef ETHTOOL_BUSINFO_LEN
|
||||
#define ETHTOOL_BUSINFO_LEN 32
|
||||
#endif
|
||||
|
||||
/*****************************************************************************/
|
248
src/rtltool.c
Normal file
248
src/rtltool.c
Normal file
@ -0,0 +1,248 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-only
|
||||
/*
|
||||
################################################################################
|
||||
#
|
||||
# r8101 is the Linux device driver released for Realtek Fast Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2022 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 <asm/uaccess.h>
|
||||
#include "r8101.h"
|
||||
#include "rtltool.h"
|
||||
|
||||
int rtl8101_tool_ioctl(struct rtl8101_private *tp, struct ifreq *ifr)
|
||||
{
|
||||
struct rtltool_cmd my_cmd;
|
||||
unsigned long flags;
|
||||
int ret;
|
||||
|
||||
if (copy_from_user(&my_cmd, ifr->ifr_data, sizeof(struct rtltool_cmd))) {
|
||||
return -EFAULT;
|
||||
}
|
||||
|
||||
ret = 0;
|
||||
switch(my_cmd.cmd) {
|
||||
case RTLTOOL_READ_MAC:
|
||||
if(my_cmd.len==1) {
|
||||
my_cmd.data = readb(tp->mmio_addr+my_cmd.offset);
|
||||
} else if(my_cmd.len==2) {
|
||||
my_cmd.data = readw(tp->mmio_addr+(my_cmd.offset&~1));
|
||||
} else if(my_cmd.len==4) {
|
||||
my_cmd.data = readl(tp->mmio_addr+(my_cmd.offset&~3));
|
||||
} else {
|
||||
ret = -EOPNOTSUPP;
|
||||
break;
|
||||
}
|
||||
|
||||
if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(struct rtltool_cmd))) {
|
||||
ret = -EFAULT;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case RTLTOOL_WRITE_MAC:
|
||||
if(my_cmd.len==1) {
|
||||
writeb(my_cmd.data, tp->mmio_addr+my_cmd.offset);
|
||||
} else if(my_cmd.len==2) {
|
||||
writew(my_cmd.data, tp->mmio_addr+(my_cmd.offset&~1));
|
||||
} else if(my_cmd.len==4) {
|
||||
writel(my_cmd.data, tp->mmio_addr+(my_cmd.offset&~3));
|
||||
} else {
|
||||
ret = -EOPNOTSUPP;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case RTLTOOL_READ_PHY:
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
my_cmd.data = rtl8101_mdio_prot_read(tp, my_cmd.offset);
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
|
||||
if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(struct rtltool_cmd))) {
|
||||
ret = -EFAULT;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case RTLTOOL_WRITE_PHY:
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
rtl8101_mdio_prot_write(tp, my_cmd.offset, my_cmd.data);
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
break;
|
||||
|
||||
case RTLTOOL_READ_EPHY:
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
my_cmd.data = rtl8101_ephy_read(tp, my_cmd.offset);
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
|
||||
if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(struct rtltool_cmd))) {
|
||||
ret = -EFAULT;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case RTLTOOL_WRITE_EPHY:
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
rtl8101_ephy_write(tp, my_cmd.offset, my_cmd.data);
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
break;
|
||||
|
||||
case RTLTOOL_READ_ERI:
|
||||
my_cmd.data = 0;
|
||||
if (my_cmd.len==1 || my_cmd.len==2 || my_cmd.len==4) {
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
my_cmd.data = rtl8101_eri_read(tp, my_cmd.offset, my_cmd.len, ERIAR_ExGMAC);
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
} else {
|
||||
ret = -EOPNOTSUPP;
|
||||
break;
|
||||
}
|
||||
|
||||
if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
|
||||
ret = -EFAULT;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case RTLTOOL_WRITE_ERI:
|
||||
if (my_cmd.len==1 || my_cmd.len==2 || my_cmd.len==4) {
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
my_cmd.data = rtl8101_eri_write(tp, my_cmd.offset, my_cmd.len, my_cmd.data, ERIAR_ExGMAC);
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
} else {
|
||||
ret = -EOPNOTSUPP;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case RTLTOOL_READ_PCI:
|
||||
my_cmd.data = 0;
|
||||
if(my_cmd.len==1) {
|
||||
pci_read_config_byte(tp->pci_dev, my_cmd.offset, (u8 *)&my_cmd.data);
|
||||
} else if(my_cmd.len==2) {
|
||||
pci_read_config_word(tp->pci_dev, my_cmd.offset, (u16 *)&my_cmd.data);
|
||||
} else if(my_cmd.len==4) {
|
||||
pci_read_config_dword(tp->pci_dev, my_cmd.offset, &my_cmd.data);
|
||||
} else {
|
||||
ret = -EOPNOTSUPP;
|
||||
break;
|
||||
}
|
||||
|
||||
if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(struct rtltool_cmd))) {
|
||||
ret = -EFAULT;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case RTLTOOL_WRITE_PCI:
|
||||
if(my_cmd.len==1) {
|
||||
pci_write_config_byte(tp->pci_dev, my_cmd.offset, my_cmd.data);
|
||||
} else if(my_cmd.len==2) {
|
||||
pci_write_config_word(tp->pci_dev, my_cmd.offset, my_cmd.data);
|
||||
} else if(my_cmd.len==4) {
|
||||
pci_write_config_dword(tp->pci_dev, my_cmd.offset, my_cmd.data);
|
||||
} else {
|
||||
ret = -EOPNOTSUPP;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case RTL_ENABLE_PCI_DIAG:
|
||||
spin_lock_irqsave(&tp->lock, flags);;
|
||||
tp->rtk_enable_diag = 1;
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
|
||||
printk("enable rtk diag\n");
|
||||
break;
|
||||
|
||||
case RTL_DISABLE_PCI_DIAG:
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
tp->rtk_enable_diag = 0;
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
|
||||
printk("disable rtk diag\n");
|
||||
break;
|
||||
|
||||
case RTL_READ_MAC_OCP:
|
||||
if (my_cmd.offset % 2)
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
my_cmd.data = rtl8101_mac_ocp_read(tp, my_cmd.offset);
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
|
||||
if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
|
||||
ret = -EFAULT;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case RTL_WRITE_MAC_OCP:
|
||||
if ((my_cmd.offset % 2) || (my_cmd.len != 2))
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
rtl8101_mac_ocp_write(tp, my_cmd.offset, (u16)my_cmd.data);
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
break;
|
||||
|
||||
case RTL_DIRECT_READ_PHY_OCP:
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
my_cmd.data = rtl8101_mdio_prot_direct_read_phy_ocp(tp, my_cmd.offset);
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
|
||||
if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
|
||||
ret = -EFAULT;
|
||||
break;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case RTL_DIRECT_WRITE_PHY_OCP:
|
||||
spin_lock_irqsave(&tp->lock, flags);
|
||||
rtl8101_mdio_prot_direct_write_phy_ocp(tp, my_cmd.offset, my_cmd.data);
|
||||
spin_unlock_irqrestore(&tp->lock, flags);
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = -EOPNOTSUPP;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
86
src/rtltool.h
Normal file
86
src/rtltool.h
Normal file
@ -0,0 +1,86 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/*
|
||||
################################################################################
|
||||
#
|
||||
# r8101 is the Linux device driver released for Realtek Fast Ethernet
|
||||
# controllers with PCI-Express interface.
|
||||
#
|
||||
# Copyright(c) 2022 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.
|
||||
***********************************************************************************/
|
||||
|
||||
#ifndef _LINUX_RTLTOOL_H
|
||||
#define _LINUX_RTLTOOL_H
|
||||
|
||||
#define SIOCRTLTOOL SIOCDEVPRIVATE+1
|
||||
|
||||
enum rtl_cmd {
|
||||
RTLTOOL_READ_MAC=0,
|
||||
RTLTOOL_WRITE_MAC,
|
||||
RTLTOOL_READ_PHY,
|
||||
RTLTOOL_WRITE_PHY,
|
||||
RTLTOOL_READ_EPHY,
|
||||
RTLTOOL_WRITE_EPHY,
|
||||
RTLTOOL_READ_ERI,
|
||||
RTLTOOL_WRITE_ERI,
|
||||
RTLTOOL_READ_PCI,
|
||||
RTLTOOL_WRITE_PCI,
|
||||
RTLTOOL_READ_EEPROM,
|
||||
RTLTOOL_WRITE_EEPROM,
|
||||
|
||||
RTL_READ_OOB_MAC,
|
||||
RTL_WRITE_OOB_MAC,
|
||||
|
||||
RTL_ENABLE_PCI_DIAG,
|
||||
RTL_DISABLE_PCI_DIAG,
|
||||
|
||||
RTL_READ_MAC_OCP,
|
||||
RTL_WRITE_MAC_OCP,
|
||||
|
||||
RTL_DIRECT_READ_PHY_OCP,
|
||||
RTL_DIRECT_WRITE_PHY_OCP,
|
||||
|
||||
RTLTOOL_INVALID
|
||||
};
|
||||
|
||||
struct rtltool_cmd {
|
||||
__u32 cmd;
|
||||
__u32 offset;
|
||||
__u32 len;
|
||||
__u32 data;
|
||||
};
|
||||
|
||||
enum mode_access {
|
||||
MODE_NONE=0,
|
||||
MODE_READ,
|
||||
MODE_WRITE
|
||||
};
|
||||
|
||||
#ifdef __KERNEL__
|
||||
int rtl8101_tool_ioctl(struct rtl8101_private *tp, struct ifreq *ifr);
|
||||
#endif
|
||||
|
||||
#endif /* _LINUX_RTLTOOL_H */
|
Loading…
Reference in New Issue
Block a user