From 5da42ff99adc8a7dcf599f8351bdcc65afa45a95 Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Tue, 15 Mar 2022 17:08:57 +0800 Subject: [PATCH 01/11] README.md: add matrix group Signed-off-by: Tianling Shen (cherry picked from commit dcf2a06a0696e1bfc96410f27eceeb0406b7b46b) --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 0558804284..71b6762e00 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ For a list of supported devices see the [OpenWrt Hardware Database](https://open ### Support Community - Support Chat: group [@ctcgfw_openwrt_discuss](https://t.me/ctcgfw_openwrt_discuss) on [Telegram](https://telegram.org/). + - Support Chat: group [#immortalwrt](https://matrix.to/#/#immortalwrt:matrix.org) on [Matrix](https://matrix.org/). ## License ImmortalWrt is licensed under [GPL-3.0-only](https://spdx.org/licenses/GPL-3.0-only.html). From 3338a5e835f4b5cd1194804be3a8c75e3e5af797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Tue, 1 Mar 2022 18:46:27 +0100 Subject: [PATCH 02/11] base-files: call "sync" after initial setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OpenWrt uses a lot of (b)ash scripts for initial setup. This isn't the best solution as they almost never consider syncing files / data. Still this is what we have and we need to try living with it. Without proper syncing OpenWrt can easily get into an inconsistent state on power cut. It's because: 1. Actual (flash) inode and data writes are not synchronized 2. Data writeback can take up to 30 seconds (dirty_expire_centisecs) 3. ubifs adds extra 5 seconds (dirty_writeback_centisecs) "delay" Some possible cases (examples) for new files: 1. Power cut during 5 seconds after write() can result in all data loss 2. Power cut happening between 5 and 35 seconds after write() can result in empty file (inode flushed after 5 seconds, data flush queued) Above affects e.g. uci-defaults. After executing some migration script it may get deleted (whited out) without generated data getting actually written. Power cut will result in missing data and deleted file. There are three ways of dealing with that: 1. Rewriting all user-space init to proper C with syncs 2. Trying bash hacks (like creating tmp files & moving them) 3. Adding sync and hoping for no power cut during critical section This change introduces the last solution that is the simplest. It reduces time during which things may go wrong from ~35 seconds to probably less than a second. Of course it applies only to IO operations performed before /etc/init.d/boot . It's probably the stage when the most new files get created. All later changes are usually done using smarter C apps (e.g. busybox or uci) that creates tmp files and uses rename() that is expected to be atomic. Signed-off-by: Rafał Miłecki Acked-by: Hauke Mehrtens Acked-by: Sergey Ryazanov (cherry picked from commit 9851d4b6ce6e89d164a04803817625a9041b060a) --- package/base-files/files/etc/init.d/boot | 1 + 1 file changed, 1 insertion(+) diff --git a/package/base-files/files/etc/init.d/boot b/package/base-files/files/etc/init.d/boot index da50e9e548..c076c6c5bf 100755 --- a/package/base-files/files/etc/init.d/boot +++ b/package/base-files/files/etc/init.d/boot @@ -48,6 +48,7 @@ boot() { /bin/config_generate uci_apply_defaults + sync # temporary hack until configd exists /sbin/reload_config From 71ca95a20cfeaa99994bc9dd88dc0960b19dd200 Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Tue, 15 Mar 2022 20:36:09 +0800 Subject: [PATCH 03/11] base-files: tweak banner Signed-off-by: Tianling Shen (cherry picked from commit be0ac56b63e45a57ae6b92d2c89507ce8312b04a) --- package/base-files/files/etc/banner | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/package/base-files/files/etc/banner b/package/base-files/files/etc/banner index 336f3ef443..1b6469c8cb 100644 --- a/package/base-files/files/etc/banner +++ b/package/base-files/files/etc/banner @@ -3,8 +3,7 @@ | |/ \ / \ / _ \_ __ \ __\__ \ | | | | Y Y \ Y Y ( <_> ) | \/| | / __ \| |__ |___|__|_| /__|_| /\____/|__| |__| (____ /____/ - \/ \/ \/ - BE FREE AND UNAFRAID + \/ \/ BE FREE AND UNAFRAID \/ ----------------------------------------------------- %D %V, %C ----------------------------------------------------- From ed3beac0cf669a9cf41b31265bf69d7ed0da819d Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Wed, 16 Mar 2022 17:36:17 +0800 Subject: [PATCH 04/11] Revert "toolchain/musl: Remove extra format attribute patch" This reverts commit c6bce01efebabc4f5481a1cf5cfb6175555831c7. Signed-off-by: Tianling Shen --- ...ribute-to-some-function-declarations.patch | 197 ++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 toolchain/musl/patches/400-Add-format-attribute-to-some-function-declarations.patch diff --git a/toolchain/musl/patches/400-Add-format-attribute-to-some-function-declarations.patch b/toolchain/musl/patches/400-Add-format-attribute-to-some-function-declarations.patch new file mode 100644 index 0000000000..06aeb34ced --- /dev/null +++ b/toolchain/musl/patches/400-Add-format-attribute-to-some-function-declarations.patch @@ -0,0 +1,197 @@ +From e6683d001a95d7c3d4d992496f00f77e01fcd268 Mon Sep 17 00:00:00 2001 +From: Hauke Mehrtens +Date: Sun, 22 Nov 2015 15:04:23 +0100 +Subject: [PATCH v2] Add format attribute to some function declarations + +GCC and Clang are able to check the format arguments given to a +function and warn the user if there is a error in the format arguments +or if there is a potential uncontrolled format string security problem +in the code. GCC does this automatically for some functions like +printf(), but it is also possible to annotate other functions in a way +that it will check them too. This feature is used by glibc for many +functions. This patch adds the attribute to the some functions of musl +expect for these functions where gcc automatically adds it. + +GCC automatically adds checks for these functions: printf, fprintf, +sprintf, scanf, fscanf, sscanf, strftime, vprintf, vfprintf and +vsprintf. + +The documentation from gcc is here: +https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html + +The documentation from Clang is here: +http://clang.llvm.org/docs/AttributeReference.html#format-gnu-format + +Signed-off-by: Hauke Mehrtens +--- + include/err.h | 26 +++++++++++++++++--------- + include/monetary.h | 12 ++++++++++-- + include/stdio.h | 29 ++++++++++++++++++++--------- + include/syslog.h | 12 ++++++++++-- + 4 files changed, 57 insertions(+), 22 deletions(-) + +--- a/include/err.h ++++ b/include/err.h +@@ -8,15 +8,23 @@ + extern "C" { + #endif + +-void warn(const char *, ...); +-void vwarn(const char *, va_list); +-void warnx(const char *, ...); +-void vwarnx(const char *, va_list); ++#if __GNUC__ >= 3 ++#define __fp(x, y) __attribute__ ((__format__ (__printf__, x, y))) ++#else ++#define __fp(x, y) ++#endif ++ ++void warn(const char *, ...) __fp(1, 2); ++void vwarn(const char *, va_list) __fp(1, 0); ++void warnx(const char *, ...) __fp(1, 2); ++void vwarnx(const char *, va_list) __fp(1, 0); ++ ++_Noreturn void err(int, const char *, ...) __fp(2, 3); ++_Noreturn void verr(int, const char *, va_list) __fp(2, 0); ++_Noreturn void errx(int, const char *, ...) __fp(2, 3); ++_Noreturn void verrx(int, const char *, va_list) __fp(2, 0); + +-_Noreturn void err(int, const char *, ...); +-_Noreturn void verr(int, const char *, va_list); +-_Noreturn void errx(int, const char *, ...); +-_Noreturn void verrx(int, const char *, va_list); ++#undef __fp + + #ifdef __cplusplus + } +--- a/include/monetary.h ++++ b/include/monetary.h +@@ -13,8 +13,16 @@ extern "C" { + + #include + +-ssize_t strfmon(char *__restrict, size_t, const char *__restrict, ...); +-ssize_t strfmon_l(char *__restrict, size_t, locale_t, const char *__restrict, ...); ++#if __GNUC__ >= 3 ++#define __fsfm(x, y) __attribute__ ((__format__ (__strfmon__, x, y))) ++#else ++#define __fsfm(x, y) ++#endif ++ ++ssize_t strfmon(char *__restrict, size_t, const char *__restrict, ...) __fsfm(3, 4); ++ssize_t strfmon_l(char *__restrict, size_t, locale_t, const char *__restrict, ...) __fsfm(4, 5); ++ ++#undef __fsfm + + #ifdef __cplusplus + } +--- a/include/stdio.h ++++ b/include/stdio.h +@@ -25,6 +25,14 @@ extern "C" { + + #include + ++#if __GNUC__ >= 3 ++#define __fp(x, y) __attribute__ ((__format__ (__printf__, x, y))) ++#define __fs(x, y) __attribute__ ((__format__ (__scanf__, x, y))) ++#else ++#define __fp(x, y) ++#define __fs(x, y) ++#endif ++ + #ifdef __cplusplus + #define NULL 0L + #else +@@ -107,19 +115,19 @@ int puts(const char *); + int printf(const char *__restrict, ...); + int fprintf(FILE *__restrict, const char *__restrict, ...); + int sprintf(char *__restrict, const char *__restrict, ...); +-int snprintf(char *__restrict, size_t, const char *__restrict, ...); ++int snprintf(char *__restrict, size_t, const char *__restrict, ...) __fp(3, 4); + + int vprintf(const char *__restrict, __isoc_va_list); + int vfprintf(FILE *__restrict, const char *__restrict, __isoc_va_list); + int vsprintf(char *__restrict, const char *__restrict, __isoc_va_list); +-int vsnprintf(char *__restrict, size_t, const char *__restrict, __isoc_va_list); ++int vsnprintf(char *__restrict, size_t, const char *__restrict, __isoc_va_list) __fp(3, 0); + + int scanf(const char *__restrict, ...); + int fscanf(FILE *__restrict, const char *__restrict, ...); + int sscanf(const char *__restrict, const char *__restrict, ...); +-int vscanf(const char *__restrict, __isoc_va_list); +-int vfscanf(FILE *__restrict, const char *__restrict, __isoc_va_list); +-int vsscanf(const char *__restrict, const char *__restrict, __isoc_va_list); ++int vscanf(const char *__restrict, __isoc_va_list) __fs(1, 0); ++int vfscanf(FILE *__restrict, const char *__restrict, __isoc_va_list) __fs(2, 0); ++int vsscanf(const char *__restrict, const char *__restrict, __isoc_va_list) __fs(2, 0); + + void perror(const char *); + +@@ -140,8 +148,8 @@ int pclose(FILE *); + int fileno(FILE *); + int fseeko(FILE *, off_t, int); + off_t ftello(FILE *); +-int dprintf(int, const char *__restrict, ...); +-int vdprintf(int, const char *__restrict, __isoc_va_list); ++int dprintf(int, const char *__restrict, ...) __fp(2, 3); ++int vdprintf(int, const char *__restrict, __isoc_va_list) __fp(2, 0); + void flockfile(FILE *); + int ftrylockfile(FILE *); + void funlockfile(FILE *); +@@ -180,8 +188,8 @@ int fileno_unlocked(FILE *); + int getw(FILE *); + int putw(int, FILE *); + char *fgetln(FILE *, size_t *); +-int asprintf(char **, const char *, ...); +-int vasprintf(char **, const char *, __isoc_va_list); ++int asprintf(char **, const char *, ...) __fp(2, 3); ++int vasprintf(char **, const char *, __isoc_va_list) __fp(2, 0); + #endif + + #ifdef _GNU_SOURCE +@@ -203,6 +211,9 @@ typedef struct _IO_cookie_io_functions_t + FILE *fopencookie(void *, const char *, cookie_io_functions_t); + #endif + ++#undef __fp ++#undef __fs ++ + #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) + #define tmpfile64 tmpfile + #define fopen64 fopen +--- a/include/syslog.h ++++ b/include/syslog.h +@@ -56,16 +56,22 @@ extern "C" { + #define LOG_NOWAIT 0x10 + #define LOG_PERROR 0x20 + ++#if __GNUC__ >= 3 ++#define __fp(x, y) __attribute__ ((__format__ (__printf__, x, y))) ++#else ++#define __fp(x, y) ++#endif ++ + void closelog (void); + void openlog (const char *, int, int); + int setlogmask (int); +-void syslog (int, const char *, ...); ++void syslog (int, const char *, ...) __fp(2, 3); + + #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) + #define _PATH_LOG "/dev/log" + #define __NEED_va_list + #include +-void vsyslog (int, const char *, va_list); ++void vsyslog (int, const char *, va_list) __fp(2, 0); + #if defined(SYSLOG_NAMES) + #define INTERNAL_NOPRI 0x10 + #define INTERNAL_MARK (LOG_NFACILITIES<<3) +@@ -93,6 +99,8 @@ typedef struct { + #endif + #endif + ++#undef __fp ++ + #ifdef __cplusplus + } + #endif From e465b69a4e682b9d310a77cbec3b18701f59b84d Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Wed, 16 Mar 2022 17:36:31 +0800 Subject: [PATCH 05/11] Revert "toolchain/musl: remove several GNU headers" This reverts commit c710efe18064e8e33f1f1348d19dd89e25c5bf0c. Signed-off-by: Tianling Shen --- toolchain/musl/include/bits/wordsize.h | 1 + toolchain/musl/include/features.h | 56 +++ toolchain/musl/include/sgidefs.h | 73 ++++ toolchain/musl/include/sys/cdefs.h | 378 ++++++++++++++++++ toolchain/musl/include/sys/glibc-types.h | 35 ++ .../musl/patches/100-add_glob_onlydir.patch | 11 + 6 files changed, 554 insertions(+) create mode 100644 toolchain/musl/include/bits/wordsize.h create mode 100644 toolchain/musl/include/features.h create mode 100644 toolchain/musl/include/sgidefs.h create mode 100644 toolchain/musl/include/sys/cdefs.h create mode 100644 toolchain/musl/include/sys/glibc-types.h create mode 100644 toolchain/musl/patches/100-add_glob_onlydir.patch diff --git a/toolchain/musl/include/bits/wordsize.h b/toolchain/musl/include/bits/wordsize.h new file mode 100644 index 0000000000..2d4cbe8317 --- /dev/null +++ b/toolchain/musl/include/bits/wordsize.h @@ -0,0 +1 @@ +#include diff --git a/toolchain/musl/include/features.h b/toolchain/musl/include/features.h new file mode 100644 index 0000000000..e801e2299a --- /dev/null +++ b/toolchain/musl/include/features.h @@ -0,0 +1,56 @@ +#ifndef _FEATURES_H +#define _FEATURES_H + +#if defined(_ALL_SOURCE) && !defined(_GNU_SOURCE) +#define _GNU_SOURCE 1 +#endif + +#if defined(_DEFAULT_SOURCE) && !defined(_BSD_SOURCE) +#define _BSD_SOURCE 1 +#endif + +#if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) \ + && !defined(_XOPEN_SOURCE) && !defined(_GNU_SOURCE) \ + && !defined(_BSD_SOURCE) && !defined(__STRICT_ANSI__) +#define _BSD_SOURCE 1 +#define _XOPEN_SOURCE 700 +#endif + +#if __STDC_VERSION__ >= 199901L +#define __restrict restrict +#elif !defined(__GNUC__) +#define __restrict +#endif + +#if __STDC_VERSION__ >= 199901L || defined(__cplusplus) +#define __inline inline +#elif !defined(__GNUC__) +#define __inline +#endif + +#if __STDC_VERSION__ >= 201112L +#elif defined(__GNUC__) +#define _Noreturn __attribute__((__noreturn__)) +#else +#define _Noreturn +#endif + +#define __REDIR(x,y) __typeof__(x) x __asm__(#y) + +/* Convenience macros to test the versions of glibc and gcc. + Use them like this: + #if __GNUC_PREREQ (2,8) + ... code requiring gcc 2.8 or later ... + #endif + Note - they won't work for gcc1 or glibc1, since the _MINOR macros + were not defined then. */ +#if defined __GNUC__ && defined __GNUC_MINOR__ +# define __GNUC_PREREQ(maj, min) \ + ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) +#else +# define __GNUC_PREREQ(maj, min) 0 +#endif + +#include + +#endif diff --git a/toolchain/musl/include/sgidefs.h b/toolchain/musl/include/sgidefs.h new file mode 100644 index 0000000000..74509fdbd0 --- /dev/null +++ b/toolchain/musl/include/sgidefs.h @@ -0,0 +1,73 @@ +/* Copyright (C) 1996, 1997, 1998, 2003, 2004 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Ralf Baechle . + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#ifndef _SGIDEFS_H +#define _SGIDEFS_H 1 + +/* + * A crude hack to stop + */ +#undef __ASM_SGIDEFS_H +#define __ASM_SGIDEFS_H + +/* + * And remove any damage it might have already done + */ +#undef _MIPS_ISA_MIPS1 +#undef _MIPS_ISA_MIPS2 +#undef _MIPS_ISA_MIPS3 +#undef _MIPS_ISA_MIPS4 +#undef _MIPS_ISA_MIPS5 +#undef _MIPS_ISA_MIPS32 +#undef _MIPS_ISA_MIPS64 + +#undef _MIPS_SIM_ABI32 +#undef _MIPS_SIM_NABI32 +#undef _MIPS_SIM_ABI64 + +/* + * Definitions for the ISA level + */ +#define _MIPS_ISA_MIPS1 1 +#define _MIPS_ISA_MIPS2 2 +#define _MIPS_ISA_MIPS3 3 +#define _MIPS_ISA_MIPS4 4 +#define _MIPS_ISA_MIPS5 5 +#define _MIPS_ISA_MIPS32 6 +#define _MIPS_ISA_MIPS64 7 + +/* + * Subprogram calling convention + */ +#ifndef _ABIO32 +# define _ABIO32 1 +#endif +#define _MIPS_SIM_ABI32 _ABIO32 + +#ifndef _ABIN32 +# define _ABIN32 2 +#endif +#define _MIPS_SIM_NABI32 _ABIN32 + +#ifndef _ABI64 +# define _ABI64 3 +#endif +#define _MIPS_SIM_ABI64 _ABI64 + +#endif /* sgidefs.h */ diff --git a/toolchain/musl/include/sys/cdefs.h b/toolchain/musl/include/sys/cdefs.h new file mode 100644 index 0000000000..e9866700d0 --- /dev/null +++ b/toolchain/musl/include/sys/cdefs.h @@ -0,0 +1,378 @@ +/* Copyright (C) 1992-2002, 2004, 2005, 2006, 2007, 2009, 2011, 2012 + Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _SYS_CDEFS_H +#define _SYS_CDEFS_H 1 + +/* We are almost always included from features.h. */ +#ifndef _FEATURES_H +# include +#endif + +/* The GNU libc does not support any K&R compilers or the traditional mode + of ISO C compilers anymore. Check for some of the combinations not + anymore supported. */ +#if defined __GNUC__ && !defined __STDC__ +# error "You need a ISO C conforming compiler to use the glibc headers" +#endif + +/* Some user header file might have defined this before. */ +#undef __P +#undef __PMT + +#ifdef __GNUC__ + +/* All functions, except those with callbacks or those that + synchronize memory, are leaf functions. */ +# if __GNUC_PREREQ (4, 6) && !defined _LIBC +# define __LEAF , __leaf__ +# define __LEAF_ATTR __attribute__ ((__leaf__)) +# else +# define __LEAF +# define __LEAF_ATTR +# endif + +/* GCC can always grok prototypes. For C++ programs we add throw() + to help it optimize the function calls. But this works only with + gcc 2.8.x and egcs. For gcc 3.2 and up we even mark C functions + as non-throwing using a function attribute since programs can use + the -fexceptions options for C code as well. */ +# if !defined __cplusplus && __GNUC_PREREQ (3, 3) +# define __THROW __attribute__ ((__nothrow__ __LEAF)) +# define __THROWNL __attribute__ ((__nothrow__)) +# define __NTH(fct) __attribute__ ((__nothrow__ __LEAF)) fct +# else +# if defined __cplusplus && __GNUC_PREREQ (2,8) +# define __THROW throw () +# define __THROWNL throw () +# define __NTH(fct) __LEAF_ATTR fct throw () +# else +# define __THROW +# define __THROWNL +# define __NTH(fct) fct +# endif +# endif + +#else /* Not GCC. */ + +# define __inline /* No inline functions. */ + +# define __THROW +# define __THROWNL +# define __NTH(fct) fct + +#endif /* GCC. */ + +/* These two macros are not used in glibc anymore. They are kept here + only because some other projects expect the macros to be defined. */ +#define __P(args) args +#define __PMT(args) args + +/* For these things, GCC behaves the ANSI way normally, + and the non-ANSI way under -traditional. */ + +#define __CONCAT(x,y) x ## y +#define __STRING(x) #x + +/* This is not a typedef so `const __ptr_t' does the right thing. */ +#define __ptr_t void * +#define __long_double_t long double + + +/* C++ needs to know that types and declarations are C, not C++. */ +#ifdef __cplusplus +# define __BEGIN_DECLS extern "C" { +# define __END_DECLS } +#else +# define __BEGIN_DECLS +# define __END_DECLS +#endif + + +/* The standard library needs the functions from the ISO C90 standard + in the std namespace. At the same time we want to be safe for + future changes and we include the ISO C99 code in the non-standard + namespace __c99. The C++ wrapper header take case of adding the + definitions to the global namespace. */ +#if defined __cplusplus && defined _GLIBCPP_USE_NAMESPACES +# define __BEGIN_NAMESPACE_STD namespace std { +# define __END_NAMESPACE_STD } +# define __USING_NAMESPACE_STD(name) using std::name; +# define __BEGIN_NAMESPACE_C99 namespace __c99 { +# define __END_NAMESPACE_C99 } +# define __USING_NAMESPACE_C99(name) using __c99::name; +#else +/* For compatibility we do not add the declarations into any + namespace. They will end up in the global namespace which is what + old code expects. */ +# define __BEGIN_NAMESPACE_STD +# define __END_NAMESPACE_STD +# define __USING_NAMESPACE_STD(name) +# define __BEGIN_NAMESPACE_C99 +# define __END_NAMESPACE_C99 +# define __USING_NAMESPACE_C99(name) +#endif + + +/* Support for bounded pointers. */ +#ifndef __BOUNDED_POINTERS__ +# define __bounded /* nothing */ +# define __unbounded /* nothing */ +# define __ptrvalue /* nothing */ +#endif + + +/* Fortify support. */ +#define __bos(ptr) __builtin_object_size (ptr, __USE_FORTIFY_LEVEL > 1) +#define __bos0(ptr) __builtin_object_size (ptr, 0) +#define __fortify_function __extern_always_inline __attribute_artificial__ + +#if __GNUC_PREREQ (4,3) +# define __warndecl(name, msg) \ + extern void name (void) __attribute__((__warning__ (msg))) +# define __warnattr(msg) __attribute__((__warning__ (msg))) +# define __errordecl(name, msg) \ + extern void name (void) __attribute__((__error__ (msg))) +#else +# define __warndecl(name, msg) extern void name (void) +# define __warnattr(msg) +# define __errordecl(name, msg) extern void name (void) +#endif + +/* Support for flexible arrays. */ +#if __GNUC_PREREQ (2,97) +/* GCC 2.97 supports C99 flexible array members. */ +# define __flexarr [] +#else +# ifdef __GNUC__ +# define __flexarr [0] +# else +# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L +# define __flexarr [] +# else +/* Some other non-C99 compiler. Approximate with [1]. */ +# define __flexarr [1] +# endif +# endif +#endif + + +/* __asm__ ("xyz") is used throughout the headers to rename functions + at the assembly language level. This is wrapped by the __REDIRECT + macro, in order to support compilers that can do this some other + way. When compilers don't support asm-names at all, we have to do + preprocessor tricks instead (which don't have exactly the right + semantics, but it's the best we can do). + + Example: + int __REDIRECT(setpgrp, (__pid_t pid, __pid_t pgrp), setpgid); */ + +#if defined __GNUC__ && __GNUC__ >= 2 + +# define __REDIRECT(name, proto, alias) name proto __asm__ (__ASMNAME (#alias)) +# ifdef __cplusplus +# define __REDIRECT_NTH(name, proto, alias) \ + name proto __THROW __asm__ (__ASMNAME (#alias)) +# define __REDIRECT_NTHNL(name, proto, alias) \ + name proto __THROWNL __asm__ (__ASMNAME (#alias)) +# else +# define __REDIRECT_NTH(name, proto, alias) \ + name proto __asm__ (__ASMNAME (#alias)) __THROW +# define __REDIRECT_NTHNL(name, proto, alias) \ + name proto __asm__ (__ASMNAME (#alias)) __THROWNL +# endif +# define __ASMNAME(cname) __ASMNAME2 (__USER_LABEL_PREFIX__, cname) +# define __ASMNAME2(prefix, cname) __STRING (prefix) cname + +/* +#elif __SOME_OTHER_COMPILER__ + +# define __REDIRECT(name, proto, alias) name proto; \ + _Pragma("let " #name " = " #alias) +*/ +#endif + +/* GCC has various useful declarations that can be made with the + `__attribute__' syntax. All of the ways we use this do fine if + they are omitted for compilers that don't understand it. */ +#if !defined __GNUC__ || __GNUC__ < 2 +# define __attribute__(xyz) /* Ignore */ +#endif + +/* At some point during the gcc 2.96 development the `malloc' attribute + for functions was introduced. We don't want to use it unconditionally + (although this would be possible) since it generates warnings. */ +#if __GNUC_PREREQ (2,96) +# define __attribute_malloc__ __attribute__ ((__malloc__)) +#else +# define __attribute_malloc__ /* Ignore */ +#endif + +/* At some point during the gcc 2.96 development the `pure' attribute + for functions was introduced. We don't want to use it unconditionally + (although this would be possible) since it generates warnings. */ +#if __GNUC_PREREQ (2,96) +# define __attribute_pure__ __attribute__ ((__pure__)) +#else +# define __attribute_pure__ /* Ignore */ +#endif + +/* This declaration tells the compiler that the value is constant. */ +#if __GNUC_PREREQ (2,5) +# define __attribute_const__ __attribute__ ((__const__)) +#else +# define __attribute_const__ /* Ignore */ +#endif + +/* At some point during the gcc 3.1 development the `used' attribute + for functions was introduced. We don't want to use it unconditionally + (although this would be possible) since it generates warnings. */ +#if __GNUC_PREREQ (3,1) +# define __attribute_used__ __attribute__ ((__used__)) +# define __attribute_noinline__ __attribute__ ((__noinline__)) +#else +# define __attribute_used__ __attribute__ ((__unused__)) +# define __attribute_noinline__ /* Ignore */ +#endif + +/* gcc allows marking deprecated functions. */ +#if __GNUC_PREREQ (3,2) +# define __attribute_deprecated__ __attribute__ ((__deprecated__)) +#else +# define __attribute_deprecated__ /* Ignore */ +#endif + +/* At some point during the gcc 2.8 development the `format_arg' attribute + for functions was introduced. We don't want to use it unconditionally + (although this would be possible) since it generates warnings. + If several `format_arg' attributes are given for the same function, in + gcc-3.0 and older, all but the last one are ignored. In newer gccs, + all designated arguments are considered. */ +#if __GNUC_PREREQ (2,8) +# define __attribute_format_arg__(x) __attribute__ ((__format_arg__ (x))) +#else +# define __attribute_format_arg__(x) /* Ignore */ +#endif + +/* At some point during the gcc 2.97 development the `strfmon' format + attribute for functions was introduced. We don't want to use it + unconditionally (although this would be possible) since it + generates warnings. */ +#if __GNUC_PREREQ (2,97) +# define __attribute_format_strfmon__(a,b) \ + __attribute__ ((__format__ (__strfmon__, a, b))) +#else +# define __attribute_format_strfmon__(a,b) /* Ignore */ +#endif + +/* The nonull function attribute allows to mark pointer parameters which + must not be NULL. */ +#if __GNUC_PREREQ (3,3) +# define __nonnull(params) __attribute__ ((__nonnull__ params)) +#else +# define __nonnull(params) +#endif + +/* If fortification mode, we warn about unused results of certain + function calls which can lead to problems. */ +#if __GNUC_PREREQ (3,4) +# define __attribute_warn_unused_result__ \ + __attribute__ ((__warn_unused_result__)) +# if __USE_FORTIFY_LEVEL > 0 +# define __wur __attribute_warn_unused_result__ +# endif +#else +# define __attribute_warn_unused_result__ /* empty */ +#endif +#ifndef __wur +# define __wur /* Ignore */ +#endif + +/* Forces a function to be always inlined. */ +#if __GNUC_PREREQ (3,2) +# define __always_inline __inline __attribute__ ((__always_inline__)) +#else +# define __always_inline __inline +#endif + +/* Associate error messages with the source location of the call site rather + than with the source location inside the function. */ +#if __GNUC_PREREQ (4,3) +# define __attribute_artificial__ __attribute__ ((__artificial__)) +#else +# define __attribute_artificial__ /* Ignore */ +#endif + +/* GCC 4.3 and above with -std=c99 or -std=gnu99 implements ISO C99 + inline semantics, unless -fgnu89-inline is used. */ +#if !defined __cplusplus || __GNUC_PREREQ (4,3) +# if defined __GNUC_STDC_INLINE__ || defined __cplusplus +# define __extern_inline extern __inline __attribute__ ((__gnu_inline__)) +# define __extern_always_inline \ + extern __always_inline __attribute__ ((__gnu_inline__)) +# else +# define __extern_inline extern __inline +# define __extern_always_inline extern __always_inline +# endif +#endif + +/* GCC 4.3 and above allow passing all anonymous arguments of an + __extern_always_inline function to some other vararg function. */ +#if __GNUC_PREREQ (4,3) +# define __va_arg_pack() __builtin_va_arg_pack () +# define __va_arg_pack_len() __builtin_va_arg_pack_len () +#endif + +/* It is possible to compile containing GCC extensions even if GCC is + run in pedantic mode if the uses are carefully marked using the + `__extension__' keyword. But this is not generally available before + version 2.8. */ +#if !__GNUC_PREREQ (2,8) +# define __extension__ /* Ignore */ +#endif + +/* __restrict is known in EGCS 1.2 and above. */ +#if !__GNUC_PREREQ (2,92) +# define __restrict /* Ignore */ +#endif + +/* ISO C99 also allows to declare arrays as non-overlapping. The syntax is + array_name[restrict] + GCC 3.1 supports this. */ +#if __GNUC_PREREQ (3,1) && !defined __GNUG__ +# define __restrict_arr __restrict +#else +# ifdef __GNUC__ +# define __restrict_arr /* Not supported in old GCC. */ +# else +# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L +# define __restrict_arr restrict +# else +/* Some other non-C99 compiler. */ +# define __restrict_arr /* Not supported. */ +# endif +# endif +#endif + +#if __GNUC__ >= 3 +# define __glibc_unlikely(cond) __builtin_expect((cond), 0) +#else +# define __glibc_unlikely(cond) (cond) +#endif + +#endif /* sys/cdefs.h */ diff --git a/toolchain/musl/include/sys/glibc-types.h b/toolchain/musl/include/sys/glibc-types.h new file mode 100644 index 0000000000..fa0684ced2 --- /dev/null +++ b/toolchain/musl/include/sys/glibc-types.h @@ -0,0 +1,35 @@ +#ifndef __MUSL_GLIBC_TYPES_H +#define __MUSL_GLIBC_TYPES_H + +#include + +/* Convenience types. */ +typedef unsigned char __u_char; +typedef unsigned short int __u_short; +typedef unsigned int __u_int; +typedef unsigned long int __u_long; + +/* Fixed-size types, underlying types depend on word size and compiler. */ +typedef signed char __int8_t; +typedef unsigned char __uint8_t; +typedef signed short int __int16_t; +typedef unsigned short int __uint16_t; +typedef signed int __int32_t; +typedef unsigned int __uint32_t; +#if __WORDSIZE == 64 +typedef signed long int __int64_t; +typedef unsigned long int __uint64_t; +#else +__extension__ typedef signed long long int __int64_t; +__extension__ typedef unsigned long long int __uint64_t; +#endif + +#define __off64_t off_t +#define __loff_t off_t +typedef char *__caddr_t; +#define __locale_t locale_t + +#define __gid_t gid_t +#define __uid_t uid_t + +#endif diff --git a/toolchain/musl/patches/100-add_glob_onlydir.patch b/toolchain/musl/patches/100-add_glob_onlydir.patch new file mode 100644 index 0000000000..a784e770df --- /dev/null +++ b/toolchain/musl/patches/100-add_glob_onlydir.patch @@ -0,0 +1,11 @@ +--- a/include/glob.h ++++ b/include/glob.h +@@ -34,6 +34,8 @@ void globfree(glob_t *); + #define GLOB_TILDE 0x1000 + #define GLOB_TILDE_CHECK 0x4000 + ++#define GLOB_ONLYDIR 0x100 ++ + #define GLOB_NOSPACE 1 + #define GLOB_ABORTED 2 + #define GLOB_NOMATCH 3 From d44eb0095e8784fb8b704bfd2f68d9e57d9bcec2 Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Wed, 16 Mar 2022 17:36:36 +0800 Subject: [PATCH 06/11] Revert "toolchain/musl: update to 1.2.2" This reverts commit 93a955b8a6711e72ffdbdeeabac38d6826f6f569. Signed-off-by: Tianling Shen --- toolchain/musl/common.mk | 6 +- toolchain/musl/include/features.h | 10 +-- .../patches/110-read_timezone_from_fs.patch | 4 +- .../patches/200-add_libssp_nonshared.patch | 8 +- toolchain/musl/patches/300-relative.patch | 2 +- ...ist-unlink-in-pthread_exit-after-all.patch | 51 +++++++++++ ...hreads_minus_1-as-relaxed-atomic-for.patch | 69 ++++++++++++++ ...own-size-of-some-libc-struct-members.patch | 25 ++++++ ...pping-for-processes-that-return-to-s.patch | 90 +++++++++++++++++++ ...00-nftw-support-common-gnu-extension.patch | 12 +-- .../700-wcsnrtombs-cve-2020-28928.diff | 63 +++++++++++++ .../musl/patches/901-crypt_size_hack.patch | 2 +- 12 files changed, 316 insertions(+), 26 deletions(-) create mode 100644 toolchain/musl/patches/500-0001-reorder-thread-list-unlink-in-pthread_exit-after-all.patch create mode 100644 toolchain/musl/patches/500-0002-don-t-use-libc.threads_minus_1-as-relaxed-atomic-for.patch create mode 100644 toolchain/musl/patches/500-0003-cut-down-size-of-some-libc-struct-members.patch create mode 100644 toolchain/musl/patches/500-0004-restore-lock-skipping-for-processes-that-return-to-s.patch create mode 100644 toolchain/musl/patches/700-wcsnrtombs-cve-2020-28928.diff diff --git a/toolchain/musl/common.mk b/toolchain/musl/common.mk index 0f42a9eb60..68098f5c6a 100644 --- a/toolchain/musl/common.mk +++ b/toolchain/musl/common.mk @@ -8,12 +8,12 @@ include $(TOPDIR)/rules.mk include $(INCLUDE_DIR)/target.mk PKG_NAME:=musl -PKG_VERSION:=1.2.2 -PKG_RELEASE:=1 +PKG_VERSION:=1.1.24 +PKG_RELEASE:=3 PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz PKG_SOURCE_URL:=https://musl.libc.org/releases/ -PKG_HASH:=9b969322012d796dc23dda27a35866034fa67d8fb67e0e2c45c913c3d43219dd +PKG_HASH:=1370c9a812b2cf2a7d92802510cca0058cc37e66a7bedd70051f0a34015022a3 LIBC_SO_VERSION:=$(PKG_VERSION) PATCH_DIR:=$(PATH_PREFIX)/patches diff --git a/toolchain/musl/include/features.h b/toolchain/musl/include/features.h index e801e2299a..edb8cc72d4 100644 --- a/toolchain/musl/include/features.h +++ b/toolchain/musl/include/features.h @@ -1,14 +1,10 @@ #ifndef _FEATURES_H #define _FEATURES_H -#if defined(_ALL_SOURCE) && !defined(_GNU_SOURCE) +#ifdef _ALL_SOURCE #define _GNU_SOURCE 1 #endif -#if defined(_DEFAULT_SOURCE) && !defined(_BSD_SOURCE) -#define _BSD_SOURCE 1 -#endif - #if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) \ && !defined(_XOPEN_SOURCE) && !defined(_GNU_SOURCE) \ && !defined(_BSD_SOURCE) && !defined(__STRICT_ANSI__) @@ -24,8 +20,6 @@ #if __STDC_VERSION__ >= 199901L || defined(__cplusplus) #define __inline inline -#elif !defined(__GNUC__) -#define __inline #endif #if __STDC_VERSION__ >= 201112L @@ -35,8 +29,6 @@ #define _Noreturn #endif -#define __REDIR(x,y) __typeof__(x) x __asm__(#y) - /* Convenience macros to test the versions of glibc and gcc. Use them like this: #if __GNUC_PREREQ (2,8) diff --git a/toolchain/musl/patches/110-read_timezone_from_fs.patch b/toolchain/musl/patches/110-read_timezone_from_fs.patch index a1f54db551..f92781f7ed 100644 --- a/toolchain/musl/patches/110-read_timezone_from_fs.patch +++ b/toolchain/musl/patches/110-read_timezone_from_fs.patch @@ -1,6 +1,6 @@ --- a/src/time/__tz.c +++ b/src/time/__tz.c -@@ -31,6 +31,9 @@ static int r0[5], r1[5]; +@@ -25,6 +25,9 @@ static int r0[5], r1[5]; static const unsigned char *zi, *trans, *index, *types, *abbrevs, *abbrevs_end; static size_t map_size; @@ -10,7 +10,7 @@ static char old_tz_buf[32]; static char *old_tz = old_tz_buf; static size_t old_tz_size = sizeof old_tz_buf; -@@ -132,6 +135,15 @@ static void do_tzset() +@@ -125,6 +128,15 @@ static void do_tzset() "/usr/share/zoneinfo/\0/share/zoneinfo/\0/etc/zoneinfo/\0"; s = getenv("TZ"); diff --git a/toolchain/musl/patches/200-add_libssp_nonshared.patch b/toolchain/musl/patches/200-add_libssp_nonshared.patch index 26a9bfebea..05bd2fe54a 100644 --- a/toolchain/musl/patches/200-add_libssp_nonshared.patch +++ b/toolchain/musl/patches/200-add_libssp_nonshared.patch @@ -7,7 +7,7 @@ Signed-off-by: Steven Barth --- a/Makefile +++ b/Makefile -@@ -67,7 +67,7 @@ CRT_LIBS = $(addprefix lib/,$(notdir $(C +@@ -66,7 +66,7 @@ CRT_LIBS = $(addprefix lib/,$(notdir $(C STATIC_LIBS = lib/libc.a SHARED_LIBS = lib/libc.so TOOL_LIBS = lib/musl-gcc.specs @@ -16,7 +16,7 @@ Signed-off-by: Steven Barth ALL_TOOLS = obj/musl-gcc WRAPCC_GCC = gcc -@@ -88,7 +88,7 @@ else +@@ -86,7 +86,7 @@ else all: $(ALL_LIBS) $(ALL_TOOLS) @@ -25,7 +25,7 @@ Signed-off-by: Steven Barth $(ALL_LIBS) $(ALL_TOOLS) $(ALL_OBJS) $(ALL_OBJS:%.o=%.lo) $(GENH) $(GENH_INT): | $(OBJ_DIRS) -@@ -115,6 +115,8 @@ obj/crt/rcrt1.o: $(srcdir)/ldso/dlstart. +@@ -113,6 +113,8 @@ obj/crt/rcrt1.o: $(srcdir)/ldso/dlstart. obj/crt/Scrt1.o obj/crt/rcrt1.o: CFLAGS_ALL += -fPIC @@ -34,7 +34,7 @@ Signed-off-by: Steven Barth OPTIMIZE_SRCS = $(wildcard $(OPTIMIZE_GLOBS:%=$(srcdir)/src/%)) $(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.o) $(OPTIMIZE_SRCS:$(srcdir)/%.c=obj/%.lo): CFLAGS += -O3 -@@ -167,6 +169,11 @@ lib/libc.a: $(AOBJS) +@@ -165,6 +167,11 @@ lib/libc.a: $(AOBJS) $(AR) rc $@ $(AOBJS) $(RANLIB) $@ diff --git a/toolchain/musl/patches/300-relative.patch b/toolchain/musl/patches/300-relative.patch index 7e1eb7d6bc..e34e60a09d 100644 --- a/toolchain/musl/patches/300-relative.patch +++ b/toolchain/musl/patches/300-relative.patch @@ -1,6 +1,6 @@ --- a/Makefile +++ b/Makefile -@@ -217,7 +217,7 @@ $(DESTDIR)$(includedir)/%: $(srcdir)/inc +@@ -215,7 +215,7 @@ $(DESTDIR)$(includedir)/%: $(srcdir)/inc $(INSTALL) -D -m 644 $< $@ $(DESTDIR)$(LDSO_PATHNAME): $(DESTDIR)$(libdir)/libc.so diff --git a/toolchain/musl/patches/500-0001-reorder-thread-list-unlink-in-pthread_exit-after-all.patch b/toolchain/musl/patches/500-0001-reorder-thread-list-unlink-in-pthread_exit-after-all.patch new file mode 100644 index 0000000000..d47f2f4108 --- /dev/null +++ b/toolchain/musl/patches/500-0001-reorder-thread-list-unlink-in-pthread_exit-after-all.patch @@ -0,0 +1,51 @@ +From 4d5aa20a94a2d3fae3e69289dc23ecafbd0c16c4 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Fri, 22 May 2020 17:35:14 -0400 +Subject: [PATCH 1/4] reorder thread list unlink in pthread_exit after all + locks + +since the backend for LOCK() skips locking if single-threaded, it's +unsafe to make the process appear single-threaded before the last use +of lock. + +this fixes potential unsynchronized access to a linked list via +__dl_thread_cleanup. +--- + src/thread/pthread_create.c | 19 +++++++++++-------- + 1 file changed, 11 insertions(+), 8 deletions(-) + +--- a/src/thread/pthread_create.c ++++ b/src/thread/pthread_create.c +@@ -90,14 +90,7 @@ _Noreturn void __pthread_exit(void *resu + exit(0); + } + +- /* At this point we are committed to thread termination. Unlink +- * the thread from the list. This change will not be visible +- * until the lock is released, which only happens after SYS_exit +- * has been called, via the exit futex address pointing at the lock. */ +- libc.threads_minus_1--; +- self->next->prev = self->prev; +- self->prev->next = self->next; +- self->prev = self->next = self; ++ /* At this point we are committed to thread termination. */ + + /* Process robust list in userspace to handle non-pshared mutexes + * and the detached thread case where the robust list head will +@@ -121,6 +114,16 @@ _Noreturn void __pthread_exit(void *resu + __do_orphaned_stdio_locks(); + __dl_thread_cleanup(); + ++ /* Last, unlink thread from the list. This change will not be visible ++ * until the lock is released, which only happens after SYS_exit ++ * has been called, via the exit futex address pointing at the lock. ++ * This needs to happen after any possible calls to LOCK() that might ++ * skip locking if libc.threads_minus_1 is zero. */ ++ libc.threads_minus_1--; ++ self->next->prev = self->prev; ++ self->prev->next = self->next; ++ self->prev = self->next = self; ++ + /* This atomic potentially competes with a concurrent pthread_detach + * call; the loser is responsible for freeing thread resources. */ + int state = a_cas(&self->detach_state, DT_JOINABLE, DT_EXITING); diff --git a/toolchain/musl/patches/500-0002-don-t-use-libc.threads_minus_1-as-relaxed-atomic-for.patch b/toolchain/musl/patches/500-0002-don-t-use-libc.threads_minus_1-as-relaxed-atomic-for.patch new file mode 100644 index 0000000000..4ca51b0be0 --- /dev/null +++ b/toolchain/musl/patches/500-0002-don-t-use-libc.threads_minus_1-as-relaxed-atomic-for.patch @@ -0,0 +1,69 @@ +From e01b5939b38aea5ecbe41670643199825874b26c Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Thu, 21 May 2020 23:32:45 -0400 +Subject: [PATCH 2/4] don't use libc.threads_minus_1 as relaxed atomic for + skipping locks + +after all but the last thread exits, the next thread to observe +libc.threads_minus_1==0 and conclude that it can skip locking fails to +synchronize with any changes to memory that were made by the +last-exiting thread. this can produce data races. + +on some archs, at least x86, memory synchronization is unlikely to be +a problem; however, with the inline locks in malloc, skipping the lock +also eliminated the compiler barrier, and caused code that needed to +re-check chunk in-use bits after obtaining the lock to reuse a stale +value, possibly from before the process became single-threaded. this +in turn produced corruption of the heap state. + +some uses of libc.threads_minus_1 remain, especially for allocation of +new TLS in the dynamic linker; otherwise, it could be removed +entirely. it's made non-volatile to reflect that the remaining +accesses are only made under lock on the thread list. + +instead of libc.threads_minus_1, libc.threaded is now used for +skipping locks. the difference is that libc.threaded is permanently +true once an additional thread has been created. this will produce +some performance regression in processes that are mostly +single-threaded but occasionally creating threads. in the future it +may be possible to bring back the full lock-skipping, but more care +needs to be taken to produce a safe design. +--- + src/internal/libc.h | 2 +- + src/malloc/malloc.c | 2 +- + src/thread/__lock.c | 2 +- + 3 files changed, 3 insertions(+), 3 deletions(-) + +--- a/src/internal/libc.h ++++ b/src/internal/libc.h +@@ -21,7 +21,7 @@ struct __libc { + int can_do_threads; + int threaded; + int secure; +- volatile int threads_minus_1; ++ int threads_minus_1; + size_t *auxv; + struct tls_module *tls_head; + size_t tls_size, tls_align, tls_cnt; +--- a/src/malloc/malloc.c ++++ b/src/malloc/malloc.c +@@ -26,7 +26,7 @@ int __malloc_replaced; + + static inline void lock(volatile int *lk) + { +- if (libc.threads_minus_1) ++ if (libc.threaded) + while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1); + } + +--- a/src/thread/__lock.c ++++ b/src/thread/__lock.c +@@ -18,7 +18,7 @@ + + void __lock(volatile int *l) + { +- if (!libc.threads_minus_1) return; ++ if (!libc.threaded) return; + /* fast path: INT_MIN for the lock, +1 for the congestion */ + int current = a_cas(l, 0, INT_MIN + 1); + if (!current) return; diff --git a/toolchain/musl/patches/500-0003-cut-down-size-of-some-libc-struct-members.patch b/toolchain/musl/patches/500-0003-cut-down-size-of-some-libc-struct-members.patch new file mode 100644 index 0000000000..6650434397 --- /dev/null +++ b/toolchain/musl/patches/500-0003-cut-down-size-of-some-libc-struct-members.patch @@ -0,0 +1,25 @@ +From f12888e9eb9eed60cc266b899dcafecb4752964a Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Fri, 22 May 2020 17:25:38 -0400 +Subject: [PATCH 3/4] cut down size of some libc struct members + +these are all flags that can be single-byte values. +--- + src/internal/libc.h | 6 +++--- + 1 file changed, 3 insertions(+), 3 deletions(-) + +--- a/src/internal/libc.h ++++ b/src/internal/libc.h +@@ -18,9 +18,9 @@ struct tls_module { + }; + + struct __libc { +- int can_do_threads; +- int threaded; +- int secure; ++ char can_do_threads; ++ char threaded; ++ char secure; + int threads_minus_1; + size_t *auxv; + struct tls_module *tls_head; diff --git a/toolchain/musl/patches/500-0004-restore-lock-skipping-for-processes-that-return-to-s.patch b/toolchain/musl/patches/500-0004-restore-lock-skipping-for-processes-that-return-to-s.patch new file mode 100644 index 0000000000..83a6d0247a --- /dev/null +++ b/toolchain/musl/patches/500-0004-restore-lock-skipping-for-processes-that-return-to-s.patch @@ -0,0 +1,90 @@ +From 8d81ba8c0bc6fe31136cb15c9c82ef4c24965040 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Fri, 22 May 2020 17:45:47 -0400 +Subject: [PATCH 4/4] restore lock-skipping for processes that return to + single-threaded state + +the design used here relies on the barrier provided by the first lock +operation after the process returns to single-threaded state to +synchronize with actions by the last thread that exited. by storing +the intent to change modes in the same object used to detect whether +locking is needed, it's possible to avoid an extra (possibly costly) +memory load after the lock is taken. +--- + src/internal/libc.h | 1 + + src/malloc/malloc.c | 5 ++++- + src/thread/__lock.c | 4 +++- + src/thread/pthread_create.c | 8 ++++---- + 4 files changed, 12 insertions(+), 6 deletions(-) + +--- a/src/internal/libc.h ++++ b/src/internal/libc.h +@@ -21,6 +21,7 @@ struct __libc { + char can_do_threads; + char threaded; + char secure; ++ volatile signed char need_locks; + int threads_minus_1; + size_t *auxv; + struct tls_module *tls_head; +--- a/src/malloc/malloc.c ++++ b/src/malloc/malloc.c +@@ -26,8 +26,11 @@ int __malloc_replaced; + + static inline void lock(volatile int *lk) + { +- if (libc.threaded) ++ int need_locks = libc.need_locks; ++ if (need_locks) { + while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1); ++ if (need_locks < 0) libc.need_locks = 0; ++ } + } + + static inline void unlock(volatile int *lk) +--- a/src/thread/__lock.c ++++ b/src/thread/__lock.c +@@ -18,9 +18,11 @@ + + void __lock(volatile int *l) + { +- if (!libc.threaded) return; ++ int need_locks = libc.need_locks; ++ if (!need_locks) return; + /* fast path: INT_MIN for the lock, +1 for the congestion */ + int current = a_cas(l, 0, INT_MIN + 1); ++ if (need_locks < 0) libc.need_locks = 0; + if (!current) return; + /* A first spin loop, for medium congestion. */ + for (unsigned i = 0; i < 10; ++i) { +--- a/src/thread/pthread_create.c ++++ b/src/thread/pthread_create.c +@@ -118,8 +118,8 @@ _Noreturn void __pthread_exit(void *resu + * until the lock is released, which only happens after SYS_exit + * has been called, via the exit futex address pointing at the lock. + * This needs to happen after any possible calls to LOCK() that might +- * skip locking if libc.threads_minus_1 is zero. */ +- libc.threads_minus_1--; ++ * skip locking if process appears single-threaded. */ ++ if (!--libc.threads_minus_1) libc.need_locks = -1; + self->next->prev = self->prev; + self->prev->next = self->next; + self->prev = self->next = self; +@@ -339,7 +339,7 @@ int __pthread_create(pthread_t *restrict + ~(1UL<<((SIGCANCEL-1)%(8*sizeof(long)))); + + __tl_lock(); +- libc.threads_minus_1++; ++ if (!libc.threads_minus_1++) libc.need_locks = 1; + ret = __clone((c11 ? start_c11 : start), stack, flags, args, &new->tid, TP_ADJ(new), &__thread_list_lock); + + /* All clone failures translate to EAGAIN. If explicit scheduling +@@ -363,7 +363,7 @@ int __pthread_create(pthread_t *restrict + new->next->prev = new; + new->prev->next = new; + } else { +- libc.threads_minus_1--; ++ if (!--libc.threads_minus_1) libc.need_locks = 0; + } + __tl_unlock(); + __restore_sigs(&set); diff --git a/toolchain/musl/patches/600-nftw-support-common-gnu-extension.patch b/toolchain/musl/patches/600-nftw-support-common-gnu-extension.patch index 2a7436cf84..81c96ad76c 100644 --- a/toolchain/musl/patches/600-nftw-support-common-gnu-extension.patch +++ b/toolchain/musl/patches/600-nftw-support-common-gnu-extension.patch @@ -32,9 +32,9 @@ Signed-off-by: Tony Ambardar +#define _GNU_SOURCE #include #include - #include -@@ -72,8 +73,20 @@ static int do_nftw(char *path, int (*fn) - if (!fd_limit) close(dfd); + #include +@@ -63,8 +64,20 @@ static int do_nftw(char *path, int (*fn) + lev.base = k; } - if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) @@ -56,7 +56,7 @@ Signed-off-by: Tony Ambardar for (; h; h = h->chain) if (h->dev == st.st_dev && h->ino == st.st_ino) -@@ -101,7 +114,10 @@ static int do_nftw(char *path, int (*fn) +@@ -88,7 +101,10 @@ static int do_nftw(char *path, int (*fn) strcpy(path+j+1, de->d_name); if ((r=do_nftw(path, fn, fd_limit-1, flags, &new))) { closedir(d); @@ -68,7 +68,7 @@ Signed-off-by: Tony Ambardar } } closedir(d); -@@ -112,8 +128,16 @@ static int do_nftw(char *path, int (*fn) +@@ -98,8 +114,16 @@ static int do_nftw(char *path, int (*fn) } path[l] = 0; @@ -87,7 +87,7 @@ Signed-off-by: Tony Ambardar return 0; } -@@ -139,4 +163,5 @@ int nftw(const char *path, int (*fn)(con +@@ -125,4 +149,5 @@ int nftw(const char *path, int (*fn)(con return r; } diff --git a/toolchain/musl/patches/700-wcsnrtombs-cve-2020-28928.diff b/toolchain/musl/patches/700-wcsnrtombs-cve-2020-28928.diff new file mode 100644 index 0000000000..5840dc1aac --- /dev/null +++ b/toolchain/musl/patches/700-wcsnrtombs-cve-2020-28928.diff @@ -0,0 +1,63 @@ +--- a/src/multibyte/wcsnrtombs.c ++++ b/src/multibyte/wcsnrtombs.c +@@ -1,41 +1,33 @@ + #include ++#include ++#include + + size_t wcsnrtombs(char *restrict dst, const wchar_t **restrict wcs, size_t wn, size_t n, mbstate_t *restrict st) + { +- size_t l, cnt=0, n2; +- char *s, buf[256]; + const wchar_t *ws = *wcs; +- const wchar_t *tmp_ws; +- +- if (!dst) s = buf, n = sizeof buf; +- else s = dst; +- +- while ( ws && n && ( (n2=wn)>=n || n2>32 ) ) { +- if (n2>=n) n2=n; +- tmp_ws = ws; +- l = wcsrtombs(s, &ws, n2, 0); +- if (!(l+1)) { +- cnt = l; +- n = 0; ++ size_t cnt = 0; ++ if (!dst) n=0; ++ while (ws && wn) { ++ char tmp[MB_LEN_MAX]; ++ size_t l = wcrtomb(nn) break; ++ memcpy(dst, tmp, l); ++ } ++ dst += l; + n -= l; + } +- wn = ws ? wn - (ws - tmp_ws) : 0; +- cnt += l; +- } +- if (ws) while (n && wn) { +- l = wcrtomb(s, *ws, 0); +- if ((l+1)<=1) { +- if (!l) ws = 0; +- else cnt = l; ++ if (!*ws) { ++ ws = 0; + break; + } +- ws++; wn--; +- /* safe - this loop runs fewer than sizeof(buf) times */ +- s+=l; n-=l; ++ ws++; ++ wn--; + cnt += l; + } + if (dst) *wcs = ws; diff --git a/toolchain/musl/patches/901-crypt_size_hack.patch b/toolchain/musl/patches/901-crypt_size_hack.patch index 667894a24f..75f196abca 100644 --- a/toolchain/musl/patches/901-crypt_size_hack.patch +++ b/toolchain/musl/patches/901-crypt_size_hack.patch @@ -43,7 +43,7 @@ typedef uint32_t BF_word; typedef int32_t BF_word_signed; -@@ -804,3 +815,4 @@ char *__crypt_blowfish(const char *key, +@@ -796,3 +807,4 @@ char *__crypt_blowfish(const char *key, return "*"; } From 9938878b162cb389a9c191bcf328d286bc6adadc Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Wed, 16 Mar 2022 18:27:04 +0800 Subject: [PATCH 07/11] tools/llvm-bpf: drop unused package Signed-off-by: Tianling Shen --- tools/Makefile | 1 - tools/llvm-bpf/Makefile | 36 ------------------------------------ 2 files changed, 37 deletions(-) delete mode 100644 tools/llvm-bpf/Makefile diff --git a/tools/Makefile b/tools/Makefile index 43d90ddfe9..0fd94866be 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -37,7 +37,6 @@ tools-$(CONFIG_TARGET_orion_generic) += wrt350nv2-builder upslug2 tools-$(CONFIG_TARGET_tegra) += cbootimage cbootimage-configs tools-$(CONFIG_USES_MINOR) += kernel2minor tools-$(CONFIG_USE_SPARSE) += sparse -tools-$(CONFIG_BUILD_LLVM_BPF) += llvm-bpf # builddir dependencies $(curdir)/autoconf/compile := $(curdir)/m4/compile diff --git a/tools/llvm-bpf/Makefile b/tools/llvm-bpf/Makefile deleted file mode 100644 index a5ba2a4cb7..0000000000 --- a/tools/llvm-bpf/Makefile +++ /dev/null @@ -1,36 +0,0 @@ -# -# Copyright (C) 2006-2016 OpenWrt.org -# -# This is free software, licensed under the GNU General Public License v2. -# See /LICENSE for more information. -# -include $(TOPDIR)/rules.mk - -PKG_NAME:=llvm-project -PKG_VERSION:=13.0.0 -PKG_RELEASE:=1 - -PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).src.tar.xz -PKG_SOURCE_URL:=https://github.com/llvm/llvm-project/releases/download/llvmorg-$(PKG_VERSION) -PKG_HASH:=6075ad30f1ac0e15f07c1bf062c1e1268c241d674f11bd32cdf0e040c71f2bf3 - -HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/$(PKG_NAME)-$(PKG_VERSION).src - -HOST_BUILD_PARALLEL:=1 - -CMAKE_BINARY_SUBDIR := build -CMAKE_SOURCE_SUBDIR := llvm - -include $(INCLUDE_DIR)/host-build.mk -include $(INCLUDE_DIR)/cmake.mk - -CMAKE_HOST_OPTIONS += \ - -DLLVM_ENABLE_BINDINGS=OFF \ - -DLLVM_INCLUDE_DOCS=OFF \ - -DLLVM_INCLUDE_EXAMPLES=OFF \ - -DLLVM_INCLUDE_TESTS=OFF \ - -DLLVM_ENABLE_PROJECTS="clang;lld" \ - -DLLVM_TARGETS_TO_BUILD=BPF \ - -DCLANG_BUILD_EXAMPLES=OFF - -$(eval $(call HostBuild)) From a77acbd16d958fb942626c1762af4391c923a0fb Mon Sep 17 00:00:00 2001 From: Lech Perczak Date: Sat, 12 Mar 2022 01:50:53 +0100 Subject: [PATCH 08/11] uqmi: set CID during 'query-data-status' operation Modems used in ZTE mobile broadband routers require to query the data session status using the same CID as one used to establish the session, otherwise they will report the session as "disconnected" despite reporting correct PDH in previous step. Without this change, IPv6 connection on these modems doesn't establish properly. In IPv4 this bug is present as well, but for some reason querying of IPv4 status works using temporary CID, this however seems noncompliant with QMI specifications, so fix it as well. Signed-off-by: Lech Perczak --- package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh b/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh index 5ee61b94e0..bf56862430 100755 --- a/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh +++ b/package/network/utils/uqmi/files/lib/netifd/proto/qmi.sh @@ -271,7 +271,7 @@ proto_qmi_setup() { fi # Check data connection state - connstat=$(uqmi -s -d "$device" --get-data-status) + connstat=$(uqmi -s -d "$device" --set-client-id wds,"$cid_4" --get-data-status) [ "$connstat" == '"connected"' ] || { echo "No data link!" uqmi -s -d "$device" --set-client-id wds,"$cid_4" --release-client-id wds > /dev/null 2>&1 @@ -308,7 +308,7 @@ proto_qmi_setup() { fi # Check data connection state - connstat=$(uqmi -s -d "$device" --get-data-status) + connstat=$(uqmi -s -d "$device" --set-client-id wds,"$cid_6" --get-data-status) [ "$connstat" == '"connected"' ] || { echo "No data link!" uqmi -s -d "$device" --set-client-id wds,"$cid_6" --release-client-id wds > /dev/null 2>&1 From a75b0a9c1b6f32fdecb02ed4cfc6c36a251c950e Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Wed, 9 Mar 2022 22:31:14 -0800 Subject: [PATCH 09/11] argp-standalone: fix compilation with Alpine Linux This package is a C89 one. Add the proper CFLAG to fix compilation. Signed-off-by: Rosen Penev --- package/libs/argp-standalone/Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/package/libs/argp-standalone/Makefile b/package/libs/argp-standalone/Makefile index 8fad739d85..f431aacbdc 100644 --- a/package/libs/argp-standalone/Makefile +++ b/package/libs/argp-standalone/Makefile @@ -33,8 +33,10 @@ define Package/argp-standalone/description endef MAKE_FLAGS += \ - CFLAGS="$(TARGET_CFLAGS) $(FPIC)" + CFLAGS="$(TARGET_CFLAGS) $(FPIC) -std=gnu89" +HOST_MAKE_FLAGS += \ + CFLAGS="$(HOST_CFLAGS) $(FPIC) -std=gnu89" define Build/InstallDev $(INSTALL_DIR) $(1)/usr/include From fd505eab88aaa0e4e544ec6c9d789d762cd1c34f Mon Sep 17 00:00:00 2001 From: Martin Schiller Date: Wed, 16 Mar 2022 15:04:56 +0100 Subject: [PATCH 10/11] openssl: bump to 1.1.1n This is a bugfix release. Changelog: *) Fixed a bug in the BN_mod_sqrt() function that can cause it to loop forever for non-prime moduli. (CVE-2022-0778) *) Add ciphersuites based on DHE_PSK (RFC 4279) and ECDHE_PSK (RFC 5489) to the list of ciphersuites providing Perfect Forward Secrecy as required by SECLEVEL >= 3. Signed-off-by: Martin Schiller --- package/libs/openssl/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/package/libs/openssl/Makefile b/package/libs/openssl/Makefile index d0af1c2ad5..4f1dd5931c 100644 --- a/package/libs/openssl/Makefile +++ b/package/libs/openssl/Makefile @@ -9,9 +9,9 @@ include $(TOPDIR)/rules.mk PKG_NAME:=openssl PKG_BASE:=1.1.1 -PKG_BUGFIX:=m +PKG_BUGFIX:=n PKG_VERSION:=$(PKG_BASE)$(PKG_BUGFIX) -PKG_RELEASE:=3 +PKG_RELEASE:=1 PKG_USE_MIPS16:=0 PKG_BUILD_PARALLEL:=1 @@ -27,7 +27,7 @@ PKG_SOURCE_URL:= \ ftp://ftp.pca.dfn.de/pub/tools/net/openssl/source/ \ ftp://ftp.pca.dfn.de/pub/tools/net/openssl/source/old/$(PKG_BASE)/ -PKG_HASH:=f89199be8b23ca45fc7cb9f1d8d3ee67312318286ad030f5316aca6462db6c96 +PKG_HASH:=40dceb51a4f6a5275bde0e6bf20ef4b91bfc32ed57c0552e2e8e15463372b17a PKG_LICENSE:=OpenSSL PKG_LICENSE_FILES:=LICENSE From 43f88fbf6ce95c4f2cd7fb3ff719c8ea5edbf573 Mon Sep 17 00:00:00 2001 From: Tianling Shen Date: Thu, 17 Mar 2022 15:27:45 +0800 Subject: [PATCH 11/11] r8125: bump to 9.008.00 Signed-off-by: Tianling Shen (cherry picked from commit d469e513ccde8f163ad64eba9e488c35ad4a143d) --- package/kernel/r8125/Makefile | 18 +- package/kernel/r8125/src/Makefile | 2 +- package/kernel/r8125/src/Makefile_linux24x | 2 +- package/kernel/r8125/src/r8125.h | 42 +- package/kernel/r8125/src/r8125_dash.h | 2 +- package/kernel/r8125/src/r8125_firmware.c | 2 +- package/kernel/r8125/src/r8125_firmware.h | 2 +- package/kernel/r8125/src/r8125_n.c | 459 +++++++++++++++------ package/kernel/r8125/src/r8125_ptp.c | 2 +- package/kernel/r8125/src/r8125_ptp.h | 2 +- package/kernel/r8125/src/r8125_realwow.h | 2 +- package/kernel/r8125/src/r8125_rss.c | 2 +- package/kernel/r8125/src/r8125_rss.h | 2 +- package/kernel/r8125/src/rtl_eeprom.c | 2 +- package/kernel/r8125/src/rtl_eeprom.h | 2 +- package/kernel/r8125/src/rtltool.c | 2 +- package/kernel/r8125/src/rtltool.h | 2 +- 17 files changed, 383 insertions(+), 164 deletions(-) diff --git a/package/kernel/r8125/Makefile b/package/kernel/r8125/Makefile index 3694528e7d..a4014c08ac 100644 --- a/package/kernel/r8125/Makefile +++ b/package/kernel/r8125/Makefile @@ -7,11 +7,9 @@ include $(TOPDIR)/rules.mk include $(INCLUDE_DIR)/kernel.mk PKG_NAME:=r8125 -PKG_VERSION:=9.007.01 +PKG_VERSION:=9.008.00 PKG_RELEASE:=$(AUTORELEASE) -PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION) - include $(INCLUDE_DIR)/package.mk define KernelPackage/r8125 @@ -27,20 +25,8 @@ define Package/r8125/description This package contains a driver for Realtek r8125 chipsets. endef -R8125_MAKEOPTS= -C $(PKG_BUILD_DIR) \ - PATH="$(TARGET_PATH)" \ - ARCH="$(LINUX_KARCH)" \ - CROSS_COMPILE="$(TARGET_CROSS)" \ - TARGET="$(HAL_TARGET)" \ - TOOLPREFIX="$(KERNEL_CROSS)" \ - TOOLPATH="$(KERNEL_CROSS)" \ - KERNELPATH="$(LINUX_DIR)" \ - KERNELDIR="$(LINUX_DIR)" \ - LDOPTS=" " \ - DOMULTI=1 - define Build/Compile - $(MAKE) $(R8125_MAKEOPTS) modules + +$(KERNEL_MAKE) M=$(PKG_BUILD_DIR) modules endef $(eval $(call KernelPackage,r8125)) diff --git a/package/kernel/r8125/src/Makefile b/package/kernel/r8125/src/Makefile index e64f995af4..a6958b86cc 100644 --- a/package/kernel/r8125/src/Makefile +++ b/package/kernel/r8125/src/Makefile @@ -4,7 +4,7 @@ # 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. +# 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 diff --git a/package/kernel/r8125/src/Makefile_linux24x b/package/kernel/r8125/src/Makefile_linux24x index d043fb00ca..50aef8d4c0 100644 --- a/package/kernel/r8125/src/Makefile_linux24x +++ b/package/kernel/r8125/src/Makefile_linux24x @@ -4,7 +4,7 @@ # 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. +# 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 diff --git a/package/kernel/r8125/src/r8125.h b/package/kernel/r8125/src/r8125.h index 8b4085c40b..6db55e6936 100644 --- a/package/kernel/r8125/src/r8125.h +++ b/package/kernel/r8125/src/r8125.h @@ -5,7 +5,7 @@ # 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. +# 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 @@ -363,12 +363,12 @@ do { \ #define RSS_SUFFIX "" #endif -#define RTL8125_VERSION "9.007.01" NAPI_SUFFIX DASH_SUFFIX REALWOW_SUFFIX PTP_SUFFIX RSS_SUFFIX +#define RTL8125_VERSION "9.008.00" NAPI_SUFFIX DASH_SUFFIX REALWOW_SUFFIX PTP_SUFFIX RSS_SUFFIX #define MODULENAME "r8125" #define PFX MODULENAME ": " #define GPL_CLAIM "\ -r8125 Copyright (C) 2021 Realtek NIC software team \n \ +r8125 Copyright (C) 2022 Realtek NIC software team \n \ This program comes with ABSOLUTELY NO WARRANTY; for details, please see . \n \ This is free software, and you are welcome to redistribute it under certain conditions; see . \n" @@ -413,7 +413,7 @@ This is free software, and you are welcome to redistribute it under certain cond #endif #define Reserved2_data 7 -#define RX_DMA_BURST 7 /* Maximum PCI burst, '6' is 1024 */ +#define RX_DMA_BURST 7 /* Maximum PCI burst, '7' is unlimited */ #define TX_DMA_BURST_unlimited 7 #define TX_DMA_BURST_1024 6 #define TX_DMA_BURST_512 5 @@ -456,12 +456,17 @@ This is free software, and you are welcome to redistribute it under certain cond #define RTL8125_LINK_TIMEOUT (1 * HZ) #define RTL8125_ESD_TIMEOUT (2 * HZ) -#define NUM_TX_DESC 1024 /* Number of Tx descriptor registers */ -#define NUM_RX_DESC 1024 /* Number of Rx descriptor registers */ +#define MAX_NUM_TX_DESC 1024 /* Maximum number of Tx descriptor registers */ +#define MAX_NUM_RX_DESC 1024 /* Maximum number of Rx descriptor registers */ + +#define MIN_NUM_TX_DESC 256 /* Minimum number of Tx descriptor registers */ +#define MIN_NUM_RX_DESC 256 /* Minimum number of Rx descriptor registers */ + +#define NUM_TX_DESC MAX_NUM_TX_DESC /* Number of Tx descriptor registers */ +#define NUM_RX_DESC MAX_NUM_RX_DESC /* Number of Rx descriptor registers */ #define RX_BUF_SIZE 0x05F3 /* 0x05F3 = 1522bye + 1 */ -#define R8125_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) -#define R8125_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) + #define R8125_MAX_TX_QUEUES (2) #define R8125_MAX_RX_QUEUES (4) #define R8125_MAX_QUEUES R8125_MAX_RX_QUEUES @@ -545,6 +550,9 @@ This is free software, and you are welcome to redistribute it under certain cond #define RTK_LPA_ADVERTISE_5000FULL 0x40 #define RTK_LPA_ADVERTISE_10000FULL 0x800 +#define RTK_EEE_ADVERTISE_2500FULL 0x01 +#define RTK_LPA_EEE_ADVERTISE_2500FULL 0x01 + /* Tx NO CLOSE */ #define MAX_TX_NO_CLOSE_DESC_PTR_V2 0x10000 #define TX_NO_CLOSE_SW_PTR_MASK_V2 0x1FFFF @@ -1745,9 +1753,10 @@ struct rtl8125_tx_ring { u32 index; u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */ u32 dirty_tx; + u32 num_tx_desc; /* Number of Tx descriptor registers */ struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ dma_addr_t TxPhyAddr; - struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ + struct ring_info tx_skb[MAX_NUM_TX_DESC]; /* Tx data buffers */ u32 NextHwDesCloPtr; u32 BeginHwDesCloPtr; @@ -1763,10 +1772,11 @@ struct rtl8125_rx_ring { u32 index; u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ u32 dirty_rx; + u32 num_rx_desc; /* Number of Rx descriptor registers */ struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ - u64 RxDescPhyAddr[NUM_RX_DESC]; /* Rx desc physical address*/ + u64 RxDescPhyAddr[MAX_NUM_RX_DESC]; /* Rx desc physical address*/ dma_addr_t RxPhyAddr; - struct sk_buff *Rx_skbuff[NUM_RX_DESC]; /* Rx data buffers */ + struct sk_buff *Rx_skbuff[MAX_NUM_RX_DESC]; /* Rx data buffers */ u16 rdsar_reg; /* Receive Descriptor Start Address */ }; @@ -2031,8 +2041,8 @@ struct rtl8125_private { //struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ //dma_addr_t TxPhyAddr; //dma_addr_t RxPhyAddr; - //struct sk_buff *Rx_skbuff[NUM_RX_DESC]; /* Rx data buffers */ - //struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ + //struct sk_buff *Rx_skbuff[MAX_NUM_RX_DESC]; /* Rx data buffers */ + //struct ring_info tx_skb[MAX_NUM_TX_DESC]; /* Tx data buffers */ unsigned rx_buf_sz; u16 HwSuppNumTxQueues; u16 HwSuppNumRxQueues; @@ -2118,12 +2128,17 @@ struct rtl8125_private { u16 sw_ram_code_ver; u16 hw_ram_code_ver; + u8 RequireRduNonStopPatch; + u8 rtk_enable_diag; u8 ShortPacketSwChecksum; u8 UseSwPaddingShortPkt; + void *ShortPacketEmptyBuffer; + dma_addr_t ShortPacketEmptyBufferPhy; + u8 RequireAdcBiasPatch; u16 AdcBiasPatchIoffset; @@ -2278,7 +2293,6 @@ struct rtl8125_private { #endif u8 InitRxDescType; u16 RxDescLength; //V1 16 Byte V2 32 Bytes - u32 RxDescRingLength; u8 HwSuppPtpVer; u8 EnablePtp; diff --git a/package/kernel/r8125/src/r8125_dash.h b/package/kernel/r8125/src/r8125_dash.h index f86d4255aa..6819370dfc 100644 --- a/package/kernel/r8125/src/r8125_dash.h +++ b/package/kernel/r8125/src/r8125_dash.h @@ -5,7 +5,7 @@ # 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. +# 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 diff --git a/package/kernel/r8125/src/r8125_firmware.c b/package/kernel/r8125/src/r8125_firmware.c index ac4ea626b9..61b92d11cf 100644 --- a/package/kernel/r8125/src/r8125_firmware.c +++ b/package/kernel/r8125/src/r8125_firmware.c @@ -5,7 +5,7 @@ # 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. +# 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 diff --git a/package/kernel/r8125/src/r8125_firmware.h b/package/kernel/r8125/src/r8125_firmware.h index 1961be5d55..df97bf9b14 100644 --- a/package/kernel/r8125/src/r8125_firmware.h +++ b/package/kernel/r8125/src/r8125_firmware.h @@ -5,7 +5,7 @@ # 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. +# 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 diff --git a/package/kernel/r8125/src/r8125_n.c b/package/kernel/r8125/src/r8125_n.c index ec117a766a..abfaf4773f 100644 --- a/package/kernel/r8125/src/r8125_n.c +++ b/package/kernel/r8125/src/r8125_n.c @@ -5,7 +5,7 @@ # 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. +# 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 @@ -344,6 +344,7 @@ static struct net_device_stats *rtl8125_get_stats(struct net_device *dev); static int rtl8125_rx_interrupt(struct net_device *, struct rtl8125_private *, struct rtl8125_rx_ring *, napi_budget); static int rtl8125_tx_interrupt(struct rtl8125_tx_ring *ring, int budget); static int rtl8125_tx_interrupt_with_vector(struct rtl8125_private *tp, const int message_id, int budget); +static void rtl8125_wait_for_quiescence(struct net_device *dev); static int rtl8125_change_mtu(struct net_device *dev, int new_mtu); static void rtl8125_down(struct net_device *dev); @@ -725,7 +726,7 @@ static int proc_get_driver_variable(struct seq_file *m, void *v) seq_printf(m, "chipset\t%d\n", tp->chipset); seq_printf(m, "chipset_name\t%s\n", rtl_chip_info[tp->chipset].name); seq_printf(m, "mtu\t%d\n", dev->mtu); - seq_printf(m, "NUM_RX_DESC\t0x%x\n", NUM_RX_DESC); + seq_printf(m, "NUM_RX_DESC\t0x%x\n", tp->rx_ring[0].num_rx_desc); seq_printf(m, "cur_rx0\t0x%x\n", tp->rx_ring[0].cur_rx); seq_printf(m, "dirty_rx0\t0x%x\n", tp->rx_ring[0].dirty_rx); seq_printf(m, "cur_rx1\t0x%x\n", tp->rx_ring[1].cur_rx); @@ -734,7 +735,7 @@ static int proc_get_driver_variable(struct seq_file *m, void *v) seq_printf(m, "dirty_rx2\t0x%x\n", tp->rx_ring[2].dirty_rx); seq_printf(m, "cur_rx3\t0x%x\n", tp->rx_ring[3].cur_rx); seq_printf(m, "dirty_rx3\t0x%x\n", tp->rx_ring[3].dirty_rx); - seq_printf(m, "NUM_TX_DESC\t0x%x\n", NUM_TX_DESC); + seq_printf(m, "NUM_TX_DESC\t0x%x\n", tp->tx_ring[0].num_tx_desc); seq_printf(m, "cur_tx0\t0x%x\n", tp->tx_ring[0].cur_tx); seq_printf(m, "dirty_tx0\t0x%x\n", tp->tx_ring[0].dirty_tx); seq_printf(m, "cur_tx1\t0x%x\n", tp->tx_ring[1].cur_tx); @@ -773,6 +774,7 @@ static int proc_get_driver_variable(struct seq_file *m, void *v) seq_printf(m, "rtk_enable_diag\t0x%x\n", tp->rtk_enable_diag); seq_printf(m, "ShortPacketSwChecksum\t0x%x\n", tp->ShortPacketSwChecksum); seq_printf(m, "UseSwPaddingShortPkt\t0x%x\n", tp->UseSwPaddingShortPkt); + seq_printf(m, "RequireRduNonStopPatch\t0x%x\n", tp->RequireRduNonStopPatch); seq_printf(m, "RequireAdcBiasPatch\t0x%x\n", tp->RequireAdcBiasPatch); seq_printf(m, "AdcBiasPatchIoffset\t0x%x\n", tp->AdcBiasPatchIoffset); seq_printf(m, "RequireAdjustUpsTxLinkPulseTiming\t0x%x\n", tp->RequireAdjustUpsTxLinkPulseTiming); @@ -1166,6 +1168,7 @@ static int proc_get_driver_variable(char *page, char **start, "rtk_enable_diag\t0x%x\n" "ShortPacketSwChecksum\t0x%x\n" "UseSwPaddingShortPkt\t0x%x\n" + "RequireRduNonStopPatch\t0x%x\n" "RequireAdcBiasPatch\t0x%x\n" "AdcBiasPatchIoffset\t0x%x\n" "RequireAdjustUpsTxLinkPulseTiming\t0x%x\n" @@ -1233,7 +1236,7 @@ static int proc_get_driver_variable(char *page, char **start, tp->chipset, rtl_chip_info[tp->chipset].name, dev->mtu, - NUM_RX_DESC, + tp->rx_ring[0].num_rx_desc, tp->rx_ring[0].cur_rx, tp->rx_ring[0].dirty_rx, tp->rx_ring[1].cur_rx, @@ -1242,7 +1245,7 @@ static int proc_get_driver_variable(char *page, char **start, tp->rx_ring[2].dirty_rx, tp->rx_ring[3].cur_rx, tp->rx_ring[3].dirty_rx, - NUM_TX_DESC, + tp->tx_ring[0].num_tx_desc, tp->tx_ring[0].cur_tx, tp->tx_ring[0].dirty_tx, tp->tx_ring[1].cur_tx, @@ -1281,6 +1284,7 @@ static int proc_get_driver_variable(char *page, char **start, tp->rtk_enable_diag, tp->ShortPacketSwChecksum, tp->UseSwPaddingShortPkt, + tp->RequireRduNonStopPatch, tp->RequireAdcBiasPatch, tp->AdcBiasPatchIoffset, tp->RequireAdjustUpsTxLinkPulseTiming, @@ -3205,6 +3209,13 @@ rtl8125_hw_set_timer_int_8125(struct rtl8125_private *tp, { switch (tp->HwSuppIntMitiVer) { case 4: +#ifdef ENABLE_LIB_SUPPORT + if (message_id < R8125_MAX_RX_QUEUES_VEC_V3) + timer_intmiti_val = 0; +#else + if (tp->EnableRss && (message_id < R8125_MAX_RX_QUEUES_VEC_V3)) + timer_intmiti_val = 0; +#endif //ENABLE_LIB_SUPPORT if (message_id < R8125_MAX_RX_QUEUES_VEC_V3) //ROK RTL_W8(tp,INT_MITI_V2_0_RX + 8 * message_id, timer_intmiti_val); else if (message_id == 16) //TOK @@ -4682,6 +4693,8 @@ rtl8125_rx_desc_opts2(struct rtl8125_private *tp, return desc->opts2; } +#ifdef CONFIG_R8125_VLAN + static void rtl8125_clear_rx_desc_opts2(struct rtl8125_private *tp, struct RxDesc *desc) @@ -4692,8 +4705,6 @@ rtl8125_clear_rx_desc_opts2(struct rtl8125_private *tp, desc->opts2 = 0; } -#ifdef CONFIG_R8125_VLAN - static inline u32 rtl8125_tx_vlan_tag(struct rtl8125_private *tp, struct sk_buff *skb) @@ -5189,7 +5200,7 @@ static const char rtl8125_gstrings[][ETH_GSTRING_LEN] = { "tdu", "rdu", }; -#endif //#LINUX_VERSION_CODE > KERNEL_VERSION(2,4,22) +#endif //LINUX_VERSION_CODE > KERNEL_VERSION(2,4,22) #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) #if LINUX_VERSION_CODE > KERNEL_VERSION(2,4,22) @@ -5197,7 +5208,7 @@ static int rtl8125_get_stats_count(struct net_device *dev) { return ARRAY_SIZE(rtl8125_gstrings); } -#endif //#LINUX_VERSION_CODE > KERNEL_VERSION(2,4,22) +#endif //LINUX_VERSION_CODE > KERNEL_VERSION(2,4,22) #else static int rtl8125_get_sset_count(struct net_device *dev, int sset) { @@ -5210,6 +5221,66 @@ static int rtl8125_get_sset_count(struct net_device *dev, int sset) } #endif +static void +rtl8125_set_ring_size(struct rtl8125_private *tp, u32 rx, u32 tx) +{ + int i; + + for (i = 0; i < tp->num_rx_rings; i++) + tp->rx_ring[i].num_rx_desc = rx; + + for (i = 0; i < tp->num_tx_rings; i++) + tp->tx_ring[i].num_tx_desc = tx; +} + +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) +static void rtl8125_get_ringparam(struct net_device *dev, + struct ethtool_ringparam *ring) +{ + struct rtl8125_private *tp = netdev_priv(dev); + + ring->rx_max_pending = MAX_NUM_TX_DESC; + ring->tx_max_pending = MAX_NUM_RX_DESC;; + ring->rx_pending = tp->rx_ring[0].num_rx_desc; + ring->tx_pending = tp->tx_ring[0].num_tx_desc; +} + +static int rtl8125_set_ringparam(struct net_device *dev, + struct ethtool_ringparam *ring) +{ + struct rtl8125_private *tp = netdev_priv(dev); + u32 new_rx_count, new_tx_count; + int rc = 0; + + if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) + return -EINVAL; + + new_tx_count = clamp_t(u32, ring->tx_pending, + MIN_NUM_TX_DESC, MAX_NUM_TX_DESC); + + new_rx_count = clamp_t(u32, ring->rx_pending, + MIN_NUM_RX_DESC, MAX_NUM_RX_DESC); + + if ((new_rx_count == tp->rx_ring[0].num_rx_desc) && + (new_tx_count == tp->tx_ring[0].num_tx_desc)) { + /* nothing to do */ + return 0; + } + + if (netif_running(dev)) { + rtl8125_wait_for_quiescence(dev); + rtl8125_close(dev); + } + + rtl8125_set_ring_size(tp, new_rx_count, new_tx_count); + + if (netif_running(dev)) + rc = rtl8125_open(dev); + + return rc; +} +#endif //LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + #if LINUX_VERSION_CODE > KERNEL_VERSION(2,4,22) static void rtl8125_get_ethtool_stats(struct net_device *dev, @@ -5282,7 +5353,7 @@ rtl8125_get_strings(struct net_device *dev, break; } } -#endif //#LINUX_VERSION_CODE > KERNEL_VERSION(2,4,22) +#endif //LINUX_VERSION_CODE > KERNEL_VERSION(2,4,22) static int rtl_get_eeprom_len(struct net_device *dev) { @@ -5413,7 +5484,10 @@ static int rtl8125_enable_eee(struct rtl8125_private *tp) SetMcuAccessRegBit(tp, 0xEB62, (BIT_2|BIT_1)); SetEthPhyOcpBit(tp, 0xA432, BIT_4); - SetEthPhyOcpBit(tp, 0xA5D0, eee_adv_t); + ClearAndSetEthPhyOcpBit(tp, + 0xA5D0, + MDIO_EEE_100TX | MDIO_EEE_1000T, + eee_adv_t); ClearEthPhyOcpBit(tp, 0xA6D4, BIT_0); ClearEthPhyOcpBit(tp, 0xA6D8, BIT_4); @@ -5427,7 +5501,10 @@ static int rtl8125_enable_eee(struct rtl8125_private *tp) SetMcuAccessRegBit(tp, 0xE040, (BIT_1|BIT_0)); - SetEthPhyOcpBit(tp, 0xA5D0, eee_adv_t); + ClearAndSetEthPhyOcpBit(tp, + 0xA5D0, + MDIO_EEE_100TX | MDIO_EEE_1000T, + eee_adv_t); if (eee->advertised & SUPPORTED_2500baseX_Full) SetEthPhyOcpBit(tp, 0xA6D4, BIT_0); else @@ -5587,10 +5664,16 @@ rtl_ethtool_get_eee(struct net_device *net, struct ethtool_eee *edata) /* Get advertisement EEE */ val = mdio_direct_read_phy_ocp(tp, 0xA5D0); adv = mmd_eee_adv_to_ethtool_adv_t(val); + val = mdio_direct_read_phy_ocp(tp, 0xA6D4); + if (val & RTK_EEE_ADVERTISE_2500FULL) + adv |= ADVERTISED_2500baseX_Full; /* Get LP advertisement EEE */ val = mdio_direct_read_phy_ocp(tp, 0xA5D2); lp = mmd_eee_adv_to_ethtool_adv_t(val); + val = mdio_direct_read_phy_ocp(tp, 0xA6D0); + if (val & RTK_LPA_EEE_ADVERTISE_2500FULL) + lp |= ADVERTISED_2500baseX_Full; /* Get EEE Tx LPI timer*/ tx_lpi_timer = RTL_R16(tp, EEE_TXIDLE_TIMER_8125); @@ -5691,17 +5774,21 @@ static const struct ethtool_ops rtl8125_ethtool_ops = { .get_drvinfo = rtl8125_get_drvinfo, .get_regs_len = rtl8125_get_regs_len, .get_link = ethtool_op_get_link, +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) + .get_ringparam = rtl8125_get_ringparam, + .set_ringparam = rtl8125_set_ringparam, +#endif //LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) #if LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0) .get_settings = rtl8125_get_settings, .set_settings = rtl8125_set_settings, #else .get_link_ksettings = rtl8125_get_settings, .set_link_ksettings = rtl8125_set_settings, -#endif +#endif //LINUX_VERSION_CODE < KERNEL_VERSION(4,6,0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) .get_pauseparam = rtl8125_get_pauseparam, .set_pauseparam = rtl8125_set_pauseparam, -#endif +#endif //LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) .get_msglevel = rtl8125_get_msglevel, .set_msglevel = rtl8125_set_msglevel, #if LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) @@ -5714,8 +5801,8 @@ static const struct ethtool_ops rtl8125_ethtool_ops = { #ifdef NETIF_F_TSO .get_tso = ethtool_op_get_tso, .set_tso = ethtool_op_set_tso, -#endif -#endif +#endif //NETIF_F_TSO +#endif //LINUX_VERSION_CODE < KERNEL_VERSION(3,3,0) .get_regs = rtl8125_get_regs, .get_wol = rtl8125_get_wol, .set_wol = rtl8125_set_wol, @@ -5724,12 +5811,12 @@ static const struct ethtool_ops rtl8125_ethtool_ops = { .get_stats_count = rtl8125_get_stats_count, #else .get_sset_count = rtl8125_get_sset_count, -#endif +#endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,33) .get_ethtool_stats = rtl8125_get_ethtool_stats, #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) #ifdef ETHTOOL_GPERMADDR .get_perm_addr = ethtool_op_get_perm_addr, -#endif +#endif //ETHTOOL_GPERMADDR #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) .get_eeprom = rtl_get_eeprom, .get_eeprom_len = rtl_get_eeprom_len, @@ -5740,7 +5827,7 @@ static const struct ethtool_ops rtl8125_ethtool_ops = { .get_rxfh_key_size = rtl8125_get_rxfh_key_size, .get_rxfh = rtl8125_get_rxfh, .set_rxfh = rtl8125_set_rxfh, -#endif +#endif //ENABLE_RSS_SUPPORT #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,5,0) #ifdef ENABLE_PTP_SUPPORT .get_ts_info = rtl8125_get_ts_info, @@ -6174,38 +6261,92 @@ rtl8125_set_mac_mcu_8125a_2(struct net_device *dev) { struct rtl8125_private *tp = netdev_priv(dev); static const u16 mcu_patch_code_8125a_2[] = { - 0xE010, 0xE026, 0xE036, 0xE05C, 0xE05E, 0xE060, 0xE0C9, 0xE0D2, 0xE0D4, - 0xE0DF, 0xE0EA, 0xE0FB, 0xE101, 0xE106, 0xE10B, 0xE10D, 0x9996, 0x49D1, - 0xF005, 0x49D4, 0xF10A, 0x49D8, 0xF108, 0xC00F, 0x7100, 0x209C, 0x249C, - 0xC009, 0x9900, 0xE004, 0xC006, 0x1900, 0x9900, 0xC602, 0xBE00, 0x5A48, - 0xE0C2, 0x0004, 0xE10A, 0xC60F, 0x73C4, 0x49B3, 0xF106, 0x73C2, 0xC608, - 0xB406, 0xC609, 0xFF80, 0xC605, 0xB406, 0xC605, 0xFF80, 0x0544, 0x0568, - 0xE906, 0xCDE8, 0xC724, 0xC624, 0x9EE2, 0x1E01, 0x9EE0, 0x76E0, 0x49E0, - 0xF1FE, 0x76E6, 0x486D, 0x4868, 0x9EE4, 0x1E03, 0x9EE0, 0x76E0, 0x49E0, - 0xF1FE, 0xC615, 0x9EE2, 0x1E01, 0x9EE0, 0x76E0, 0x49E0, 0xF1FE, 0x76E6, - 0x486F, 0x9EE4, 0x1E03, 0x9EE0, 0x76E0, 0x49E0, 0xF1FE, 0x7196, 0xC702, - 0xBF00, 0x5A44, 0xEB0E, 0x0070, 0x00C3, 0xC602, 0xBE00, 0x0000, 0xC602, - 0xBE00, 0x0EBA, 0x1501, 0xF02A, 0x1500, 0xF15D, 0xC661, 0x75C8, 0x49D5, - 0xF00A, 0x49D6, 0xF008, 0x49D7, 0xF006, 0x49D8, 0xF004, 0x75D2, 0x49D9, - 0xF150, 0xC553, 0x77A0, 0x75C8, 0x4855, 0x4856, 0x4857, 0x4858, 0x48DA, + 0xE010, 0xE012, 0xE022, 0xE024, 0xE029, 0xE02B, 0xE094, 0xE09D, 0xE09F, + 0xE0AA, 0xE0B5, 0xE0C6, 0xE0CC, 0xE0D1, 0xE0D6, 0xE0D8, 0xC602, 0xBE00, + 0x0000, 0xC60F, 0x73C4, 0x49B3, 0xF106, 0x73C2, 0xC608, 0xB406, 0xC609, + 0xFF80, 0xC605, 0xB406, 0xC605, 0xFF80, 0x0544, 0x0568, 0xE906, 0xCDE8, + 0xC602, 0xBE00, 0x0000, 0x48C1, 0x48C2, 0x9C46, 0xC402, 0xBC00, 0x0A12, + 0xC602, 0xBE00, 0x0EBA, 0x1501, 0xF02A, 0x1500, 0xF15D, 0xC661, 0x75C8, + 0x49D5, 0xF00A, 0x49D6, 0xF008, 0x49D7, 0xF006, 0x49D8, 0xF004, 0x75D2, + 0x49D9, 0xF150, 0xC553, 0x77A0, 0x75C8, 0x4855, 0x4856, 0x4857, 0x4858, + 0x48DA, 0x48DB, 0x49FE, 0xF002, 0x485A, 0x49FF, 0xF002, 0x485B, 0x9DC8, + 0x75D2, 0x4859, 0x9DD2, 0xC643, 0x75C0, 0x49D4, 0xF033, 0x49D0, 0xF137, + 0xE030, 0xC63A, 0x75C8, 0x49D5, 0xF00E, 0x49D6, 0xF00C, 0x49D7, 0xF00A, + 0x49D8, 0xF008, 0x75D2, 0x49D9, 0xF005, 0xC62E, 0x75C0, 0x49D7, 0xF125, + 0xC528, 0x77A0, 0xC627, 0x75C8, 0x4855, 0x4856, 0x4857, 0x4858, 0x48DA, 0x48DB, 0x49FE, 0xF002, 0x485A, 0x49FF, 0xF002, 0x485B, 0x9DC8, 0x75D2, - 0x4859, 0x9DD2, 0xC643, 0x75C0, 0x49D4, 0xF033, 0x49D0, 0xF137, 0xE030, - 0xC63A, 0x75C8, 0x49D5, 0xF00E, 0x49D6, 0xF00C, 0x49D7, 0xF00A, 0x49D8, - 0xF008, 0x75D2, 0x49D9, 0xF005, 0xC62E, 0x75C0, 0x49D7, 0xF125, 0xC528, - 0x77A0, 0xC627, 0x75C8, 0x4855, 0x4856, 0x4857, 0x4858, 0x48DA, 0x48DB, - 0x49FE, 0xF002, 0x485A, 0x49FF, 0xF002, 0x485B, 0x9DC8, 0x75D2, 0x4859, - 0x9DD2, 0xC616, 0x75C0, 0x4857, 0x9DC0, 0xC613, 0x75C0, 0x49DA, 0xF003, - 0x49D0, 0xF107, 0xC60B, 0xC50E, 0x48D9, 0x9DC0, 0x4859, 0x9DC0, 0xC608, - 0xC702, 0xBF00, 0x3AE0, 0xE860, 0xB400, 0xB5D4, 0xE908, 0xE86C, 0x1200, - 0xC409, 0x6780, 0x48F1, 0x8F80, 0xC404, 0xC602, 0xBE00, 0x10AA, 0xC010, - 0xEA7C, 0xC602, 0xBE00, 0x0000, 0x740A, 0x4846, 0x4847, 0x9C0A, 0xC607, - 0x74C0, 0x48C6, 0x9CC0, 0xC602, 0xBE00, 0x13FE, 0xE054, 0x72CA, 0x4826, - 0x4827, 0x9ACA, 0xC607, 0x72C0, 0x48A6, 0x9AC0, 0xC602, 0xBE00, 0x07DC, - 0xE054, 0xC60F, 0x74C4, 0x49CC, 0xF109, 0xC60C, 0x74CA, 0x48C7, 0x9CCA, - 0xC609, 0x74C0, 0x4846, 0x9CC0, 0xC602, 0xBE00, 0x2480, 0xE092, 0xE0C0, - 0xE054, 0x7420, 0x48C0, 0x9C20, 0x7444, 0xC602, 0xBE00, 0x12F8, 0x1BFF, - 0x46EB, 0x1BFF, 0xC102, 0xB900, 0x0D5A, 0x1BFF, 0x46EB, 0x1BFF, 0xC102, - 0xB900, 0x0E2A, 0xC602, 0xBE00, 0x0000, 0xC602, 0xBE00, 0x0000 + 0x4859, 0x9DD2, 0xC616, 0x75C0, 0x4857, 0x9DC0, 0xC613, 0x75C0, 0x49DA, + 0xF003, 0x49D0, 0xF107, 0xC60B, 0xC50E, 0x48D9, 0x9DC0, 0x4859, 0x9DC0, + 0xC608, 0xC702, 0xBF00, 0x3AE0, 0xE860, 0xB400, 0xB5D4, 0xE908, 0xE86C, + 0x1200, 0xC409, 0x6780, 0x48F1, 0x8F80, 0xC404, 0xC602, 0xBE00, 0x10AA, + 0xC010, 0xEA7C, 0xC602, 0xBE00, 0x0000, 0x740A, 0x4846, 0x4847, 0x9C0A, + 0xC607, 0x74C0, 0x48C6, 0x9CC0, 0xC602, 0xBE00, 0x13FE, 0xE054, 0x72CA, + 0x4826, 0x4827, 0x9ACA, 0xC607, 0x72C0, 0x48A6, 0x9AC0, 0xC602, 0xBE00, + 0x07DC, 0xE054, 0xC60F, 0x74C4, 0x49CC, 0xF109, 0xC60C, 0x74CA, 0x48C7, + 0x9CCA, 0xC609, 0x74C0, 0x4846, 0x9CC0, 0xC602, 0xBE00, 0x2480, 0xE092, + 0xE0C0, 0xE054, 0x7420, 0x48C0, 0x9C20, 0x7444, 0xC602, 0xBE00, 0x12F8, + 0x1BFF, 0x46EB, 0x1BFF, 0xC102, 0xB900, 0x0D5A, 0x1BFF, 0x46EB, 0x1BFF, + 0xC102, 0xB900, 0x0E2A, 0xC602, 0xBE00, 0x0000, 0xC602, 0xBE00, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x6486, + 0x0B15, 0x090E, 0x1139 }; rtl8125_hw_disable_mac_mcu_bps(dev); @@ -6215,13 +6356,14 @@ rtl8125_set_mac_mcu_8125a_2(struct net_device *dev) rtl8125_mac_ocp_write(tp, 0xFC26, 0x8000); rtl8125_mac_ocp_write(tp, 0xFC2A, 0x0540); + rtl8125_mac_ocp_write(tp, 0xFC2E, 0x0A06); rtl8125_mac_ocp_write(tp, 0xFC30, 0x0EB8); rtl8125_mac_ocp_write(tp, 0xFC32, 0x3A5C); rtl8125_mac_ocp_write(tp, 0xFC34, 0x10A8); rtl8125_mac_ocp_write(tp, 0xFC40, 0x0D54); rtl8125_mac_ocp_write(tp, 0xFC42, 0x0E24); - rtl8125_mac_ocp_write(tp, 0xFC48, 0x3072); + rtl8125_mac_ocp_write(tp, 0xFC48, 0x307A); } static void @@ -6235,8 +6377,8 @@ rtl8125_set_mac_mcu_8125b_2(struct net_device *dev) { struct rtl8125_private *tp = netdev_priv(dev); static const u16 mcu_patch_code_8125b_2[] = { - 0xE010, 0xE01B, 0xE026, 0xE037, 0xE03D, 0xE057, 0xE05B, 0xE05F, 0xE061, - 0xE063, 0xE065, 0xE067, 0xE069, 0xE06B, 0xE06D, 0xE06F, 0x740A, 0x4846, + 0xE010, 0xE01B, 0xE026, 0xE037, 0xE03D, 0xE057, 0xE05B, 0xE060, 0xE062, + 0xE064, 0xE066, 0xE068, 0xE06A, 0xE06C, 0xE06E, 0xE070, 0x740A, 0x4846, 0x4847, 0x9C0A, 0xC607, 0x74C0, 0x48C6, 0x9CC0, 0xC602, 0xBE00, 0x13F0, 0xE054, 0x72CA, 0x4826, 0x4827, 0x9ACA, 0xC607, 0x72C0, 0x48A6, 0x9AC0, 0xC602, 0xBE00, 0x081C, 0xE054, 0xC60F, 0x74C4, 0x49CC, 0xF109, 0xC60C, @@ -6246,10 +6388,10 @@ rtl8125_set_mac_mcu_8125b_2(struct net_device *dev) 0x3168, 0x3ADA, 0x31AB, 0x1A00, 0x9AC0, 0x1300, 0xF1FB, 0x7620, 0x236E, 0x276F, 0x1A3C, 0x22A1, 0x41B5, 0x9EE2, 0x76E4, 0x486F, 0x9EE4, 0xC602, 0xBE00, 0x4A26, 0x733A, 0x49BB, 0xC602, 0xBE00, 0x47A2, 0x48C1, 0x48C2, - 0xC5C3, 0xBD00, 0x0A52, 0xC602, 0xBE00, 0x0000, 0xC602, 0xBE00, 0x0000, - 0xC602, 0xBE00, 0x0000, 0xC602, 0xBE00, 0x0000, 0xC602, 0xBE00, 0x0000, - 0xC602, 0xBE00, 0x0000, 0xC602, 0xBE00, 0x0000, 0xC602, 0xBE00, 0x0000, - 0xC602, 0xBE00, 0x0000 + 0x9C46, 0xC402, 0xBC00, 0x0A52, 0xC602, 0xBE00, 0x0000, 0xC602, 0xBE00, + 0x0000, 0xC602, 0xBE00, 0x0000, 0xC602, 0xBE00, 0x0000, 0xC602, 0xBE00, + 0x0000, 0xC602, 0xBE00, 0x0000, 0xC602, 0xBE00, 0x0000, 0xC602, 0xBE00, + 0x0000, 0xC602, 0xBE00, 0x0000 }; rtl8125_hw_disable_mac_mcu_bps(dev); @@ -6264,9 +6406,9 @@ rtl8125_set_mac_mcu_8125b_2(struct net_device *dev) rtl8125_mac_ocp_write(tp, 0xFC2E, 0x12DA); rtl8125_mac_ocp_write(tp, 0xFC30, 0x4A20); rtl8125_mac_ocp_write(tp, 0xFC32, 0x47A0); - //rtl8125_mac_ocp_write(tp, 0xFC34, 0x0A46); + rtl8125_mac_ocp_write(tp, 0xFC34, 0x0A46); - rtl8125_mac_ocp_write(tp, 0xFC48, 0x003F); + rtl8125_mac_ocp_write(tp, 0xFC48, 0x007F); } static void @@ -6499,12 +6641,16 @@ rtl8125_hw_ephy_config(struct net_device *dev) case CFG_METHOD_5: case CFG_METHOD_7: rtl8125_ephy_write(tp, 0x0B, 0xA908); + rtl8125_ephy_write(tp, 0x1E, 0x20EB); rtl8125_ephy_write(tp, 0x22, 0x0023); - rtl8125_ephy_write(tp, 0x1E, 0x28EB); + rtl8125_ephy_write(tp, 0x02, 0x60C2); + rtl8125_ephy_write(tp, 0x29, 0xFF00); rtl8125_ephy_write(tp, 0x4B, 0xA908); - rtl8125_ephy_write(tp, 0x62, 0x0023); rtl8125_ephy_write(tp, 0x5E, 0x28EB); + rtl8125_ephy_write(tp, 0x62, 0x0023); + rtl8125_ephy_write(tp, 0x42, 0x60C2); + rtl8125_ephy_write(tp, 0x69, 0xFF00); break; } } @@ -10547,12 +10693,12 @@ rtl8125_init_software_variable(struct net_device *dev) tp->EnableRss = 1; } #endif - if (tp->EnableRss) - rtl8125_init_rss(tp); #endif rtl8125_setup_mqs_reg(tp); + rtl8125_set_ring_size(tp, NUM_RX_DESC, NUM_TX_DESC); + switch (tp->mcfg) { case CFG_METHOD_4: case CFG_METHOD_5: @@ -10565,19 +10711,6 @@ rtl8125_init_software_variable(struct net_device *dev) tp->EnablePtp = 1; #endif - tp->InitRxDescType = RX_DESC_RING_TYPE_1; - if (tp->EnableRss || tp->EnablePtp) - tp->InitRxDescType = RX_DESC_RING_TYPE_3; - - tp->RxDescLength = RX_DESC_LEN_TYPE_1; - if (tp->InitRxDescType == RX_DESC_RING_TYPE_3) - tp->RxDescLength = RX_DESC_LEN_TYPE_3; - tp->RxDescRingLength = NUM_RX_DESC * tp->RxDescLength; - - tp->rtl8125_rx_config = rtl_chip_info[tp->chipset].RCR_Cfg; - if (tp->InitRxDescType == RX_DESC_RING_TYPE_3) - tp->rtl8125_rx_config |= EnableRxDescV3; - //init interrupt switch (tp->mcfg) { case CFG_METHOD_4: @@ -10649,6 +10782,31 @@ rtl8125_init_software_variable(struct net_device *dev) timer_count_v2 = (timer_count / 0x100); +#ifndef ENABLE_LIB_SUPPORT + switch (tp->mcfg) { + case CFG_METHOD_4: + case CFG_METHOD_5: + case CFG_METHOD_7: + if (tp->HwSuppIsrVer == 2) { + tp->RequireRduNonStopPatch = 1; + tp->EnableRss = 0; + } + break; + } +#endif + + tp->InitRxDescType = RX_DESC_RING_TYPE_1; + if (tp->EnableRss || tp->EnablePtp) + tp->InitRxDescType = RX_DESC_RING_TYPE_3; + + tp->RxDescLength = RX_DESC_LEN_TYPE_1; + if (tp->InitRxDescType == RX_DESC_RING_TYPE_3) + tp->RxDescLength = RX_DESC_LEN_TYPE_3; + + tp->rtl8125_rx_config = rtl_chip_info[tp->chipset].RCR_Cfg; + if (tp->InitRxDescType == RX_DESC_RING_TYPE_3) + tp->rtl8125_rx_config |= EnableRxDescV3; + tp->NicCustLedValue = RTL_R16(tp, CustomLED); tp->wol_opts = rtl8125_get_hw_wol(tp); @@ -10689,6 +10847,11 @@ rtl8125_init_software_variable(struct net_device *dev) } tp->ptp_master_mode = enable_ptp_master_mode; + +#ifdef ENABLE_RSS_SUPPORT + if (tp->EnableRss) + rtl8125_init_rss(tp); +#endif } static void @@ -12113,12 +12276,12 @@ static int rtl8125_poll(napi_ptr napi, napi_budget budget) unsigned int work_done = 0; int i; - for (i = 0; i < tp->num_rx_rings; i++) - work_done += rtl8125_rx_interrupt(dev, tp, &tp->rx_ring[i], budget); - for (i = 0; i < tp->num_tx_rings; i++) rtl8125_tx_interrupt(&tp->tx_ring[i], budget); + for (i = 0; i < tp->num_rx_rings; i++) + work_done += rtl8125_rx_interrupt(dev, tp, &tp->rx_ring[i], budget); + RTL_NAPI_QUOTA_UPDATE(dev, work_done, budget); if (work_done < work_to_do) { @@ -12156,10 +12319,10 @@ static int rtl8125_poll_msix_ring(napi_ptr napi, napi_budget budget) unsigned int work_done = 0; const int message_id = r8125napi->index; - work_done += rtl8125_rx_interrupt(dev, tp, &tp->rx_ring[message_id], budget); - rtl8125_tx_interrupt_with_vector(tp, message_id, budget); + work_done += rtl8125_rx_interrupt(dev, tp, &tp->rx_ring[message_id], budget); + RTL_NAPI_QUOTA_UPDATE(dev, work_done, budget); if (work_done < work_to_do) { @@ -12682,8 +12845,10 @@ static int rtl8125_alloc_tx_desc(struct rtl8125_private *tp) for (i = 0; i < tp->num_tx_rings; i++) { ring = &tp->tx_ring[i]; - ring->TxDescArray = dma_alloc_coherent(&pdev->dev, R8125_TX_RING_BYTES, - &ring->TxPhyAddr, GFP_KERNEL); + ring->TxDescArray = dma_alloc_coherent(&pdev->dev, + (ring->num_tx_desc * sizeof(struct TxDesc)), + &ring->TxPhyAddr, + GFP_KERNEL); if (!ring->TxDescArray) return -1; @@ -12700,8 +12865,10 @@ static int rtl8125_alloc_rx_desc(struct rtl8125_private *tp) for (i = 0; i < tp->num_rx_rings; i++) { ring = &tp->rx_ring[i]; - ring->RxDescArray = dma_alloc_coherent(&pdev->dev, tp->RxDescRingLength, - &ring->RxPhyAddr, GFP_KERNEL); + ring->RxDescArray = dma_alloc_coherent(&pdev->dev, + (ring->num_rx_desc * tp->RxDescLength), + &ring->RxPhyAddr, + GFP_KERNEL); if (!ring->RxDescArray) return -1; @@ -12710,6 +12877,24 @@ static int rtl8125_alloc_rx_desc(struct rtl8125_private *tp) return 0; } +static int rtl8125_alloc_patch_mem(struct rtl8125_private *tp) +{ + struct pci_dev *pdev = tp->pci_dev; + + if (tp->RequireRduNonStopPatch) { + tp->ShortPacketEmptyBuffer = dma_alloc_coherent(&pdev->dev, + SHORT_PACKET_PADDING_BUF_SIZE, + &tp->ShortPacketEmptyBufferPhy, + GFP_KERNEL); + if (!tp->ShortPacketEmptyBuffer) + return -1; + + memset(tp->ShortPacketEmptyBuffer, 0x0, SHORT_PACKET_PADDING_BUF_SIZE); + } + + return 0; +} + static void rtl8125_free_tx_desc(struct rtl8125_private *tp) { struct rtl8125_tx_ring *ring; @@ -12719,7 +12904,9 @@ static void rtl8125_free_tx_desc(struct rtl8125_private *tp) for (i = 0; i < tp->num_tx_rings; i++) { ring = &tp->tx_ring[i]; if (ring->TxDescArray) { - dma_free_coherent(&pdev->dev, R8125_TX_RING_BYTES, ring->TxDescArray, + dma_free_coherent(&pdev->dev, + (ring->num_tx_desc * sizeof(struct TxDesc)), + ring->TxDescArray, ring->TxPhyAddr); ring->TxDescArray = NULL; } @@ -12735,18 +12922,35 @@ static void rtl8125_free_rx_desc(struct rtl8125_private *tp) for (i = 0; i < tp->num_rx_rings; i++) { ring = &tp->rx_ring[i]; if (ring->RxDescArray) { - dma_free_coherent(&pdev->dev, tp->RxDescRingLength, ring->RxDescArray, + dma_free_coherent(&pdev->dev, + (ring->num_rx_desc * tp->RxDescLength), + ring->RxDescArray, ring->RxPhyAddr); ring->RxDescArray = NULL; } } } +static void rtl8125_free_patch_mem(struct rtl8125_private *tp) +{ + struct pci_dev *pdev = tp->pci_dev; + + if (tp->ShortPacketEmptyBuffer) { + dma_free_coherent(&pdev->dev, + SHORT_PACKET_PADDING_BUF_SIZE, + tp->ShortPacketEmptyBuffer, + tp->ShortPacketEmptyBufferPhy); + tp->ShortPacketEmptyBuffer = NULL; + } +} + static void rtl8125_free_alloc_resources(struct rtl8125_private *tp) { rtl8125_free_rx_desc(tp); rtl8125_free_tx_desc(tp); + + rtl8125_free_patch_mem(tp); } #ifdef ENABLE_USE_FIRMWARE_FILE @@ -12798,6 +13002,10 @@ int rtl8125_open(struct net_device *dev) if (retval < 0) goto err_free_all_allocated_mem; + retval = rtl8125_alloc_patch_mem(tp); + if (retval < 0) + goto err_free_all_allocated_mem; + retval = rtl8125_alloc_irq(tp); if (retval < 0) goto err_free_all_allocated_mem; @@ -13192,6 +13400,12 @@ rtl8125_hw_config(struct net_device *dev) rtl8125_hw_clear_int_miti(dev); + if (tp->RequireRduNonStopPatch && + tp->ShortPacketEmptyBuffer) { + RTL_W32(tp, RSS_INDIRECTION_TBL_8125_V2, ((u64)tp->ShortPacketEmptyBufferPhy & DMA_BIT_MASK(32))); + RTL_W32(tp, RSS_INDIRECTION_TBL_8125_V2 + 4, ((u64)tp->ShortPacketEmptyBufferPhy >> 32)); + } + if (tp->use_timer_interrrupt && (tp->HwCurrIsrVer == 2) && (tp->HwSuppIntMitiVer == 4) && @@ -13490,7 +13704,7 @@ _rtl8125_rx_clear(struct rtl8125_private *tp, struct rtl8125_rx_ring *ring) { int i; - for (i = 0; i < NUM_RX_DESC; i++) { + for (i = 0; i < ring->num_rx_desc; i++) { if (ring->Rx_skbuff[i]) { rtl8125_free_rx_skb(tp, ring, @@ -13522,7 +13736,7 @@ rtl8125_rx_fill(struct rtl8125_private *tp, u32 cur; for (cur = start; end - cur > 0; cur++) { - int ret, i = cur % NUM_RX_DESC; + int ret, i = cur % ring->num_rx_desc; if (ring->Rx_skbuff[i]) continue; @@ -13582,9 +13796,9 @@ rtl8125_tx_desc_init(struct rtl8125_private *tp) for (i = 0; i < tp->num_tx_rings; i++) { struct rtl8125_tx_ring *ring = &tp->tx_ring[i]; - memset(ring->TxDescArray, 0x0, R8125_TX_RING_BYTES); + memset(ring->TxDescArray, 0x0, (ring->num_tx_desc * sizeof(struct TxDesc))); - ring->TxDescArray[NUM_TX_DESC - 1].opts1 = cpu_to_le32(RingEnd); + ring->TxDescArray[ring->num_tx_desc - 1].opts1 = cpu_to_le32(RingEnd); } } @@ -13595,7 +13809,8 @@ rtl8125_rx_desc_init(struct rtl8125_private *tp) for (i = 0; i < tp->num_rx_rings; i++) { struct rtl8125_rx_ring *ring = &tp->rx_ring[i]; - memset(ring->RxDescArray, 0x0, tp->RxDescRingLength); + memset(ring->RxDescArray, 0x0, + (ring->num_rx_desc * tp->RxDescLength)); } } @@ -13612,17 +13827,17 @@ rtl8125_init_ring(struct net_device *dev) for (i = 0; i < tp->num_tx_rings; i++) { struct rtl8125_tx_ring *ring = &tp->tx_ring[i]; - memset(ring->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info)); + memset(ring->tx_skb, 0x0, sizeof(ring->tx_skb)); } for (i = 0; i < tp->num_rx_rings; i++) { struct rtl8125_rx_ring *ring = &tp->rx_ring[i]; - memset(ring->Rx_skbuff, 0x0, NUM_RX_DESC * sizeof(struct sk_buff *)); - if (rtl8125_rx_fill(tp, ring, dev, 0, NUM_RX_DESC, 0) != NUM_RX_DESC) + memset(ring->Rx_skbuff, 0x0, sizeof(ring->Rx_skbuff)); + if (rtl8125_rx_fill(tp, ring, dev, 0, ring->num_rx_desc, 0) != ring->num_rx_desc) goto err_out; - rtl8125_mark_as_last_descriptor(tp, rtl8125_get_rxdesc(tp, ring->RxDescArray, NUM_RX_DESC - 1)); + rtl8125_mark_as_last_descriptor(tp, rtl8125_get_rxdesc(tp, ring->RxDescArray, ring->num_rx_desc - 1)); } return 0; @@ -13659,7 +13874,7 @@ rtl8125_tx_clear_range(struct rtl8125_private *tp, #endif for (i = 0; i < n; i++) { - unsigned int entry = (start + i) % NUM_TX_DESC; + unsigned int entry = (start + i) % ring->num_tx_desc; struct ring_info *tx_skb = ring->tx_skb + entry; unsigned int len = tx_skb->len; @@ -13684,7 +13899,7 @@ rtl8125_tx_clear(struct rtl8125_private *tp) for (i = 0; i < tp->num_tx_rings; i++) { struct rtl8125_tx_ring *ring = &tp->tx_ring[i]; - rtl8125_tx_clear_range(tp, ring, ring->dirty_tx, NUM_TX_DESC); + rtl8125_tx_clear_range(tp, ring, ring->dirty_tx, ring->num_tx_desc); ring->cur_tx = ring->dirty_tx = 0; } } @@ -13976,11 +14191,14 @@ rtl8125_tx_timeout(struct net_device *dev) } static u32 -rtl8125_get_txd_opts1(u32 opts1, u32 len, unsigned int entry) +rtl8125_get_txd_opts1(struct rtl8125_tx_ring *ring, + u32 opts1, + u32 len, + unsigned int entry) { u32 status = opts1 | len; - if (entry == NUM_TX_DESC - 1) + if (entry == ring->num_tx_desc - 1) status |= RingEnd; return status; @@ -14006,7 +14224,7 @@ rtl8125_xmit_frags(struct rtl8125_private *tp, u32 status, len; void *addr; - entry = (entry + 1) % NUM_TX_DESC; + entry = (entry + 1) % ring->num_tx_desc; txd = ring->TxDescArray + entry; #if LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0) @@ -14032,7 +14250,7 @@ rtl8125_xmit_frags(struct rtl8125_private *tp, } /* anti gcc 2.95.3 bugware (sic) */ - status = rtl8125_get_txd_opts1(opts[0], len, entry); + status = rtl8125_get_txd_opts1(ring, opts[0], len, entry); txd->addr = cpu_to_le64(mapping); @@ -14045,7 +14263,7 @@ rtl8125_xmit_frags(struct rtl8125_private *tp, //second txd addr += len; len = 1; - entry = (entry + 1) % NUM_TX_DESC; + entry = (entry + 1) % ring->num_tx_desc; txd = ring->TxDescArray + entry; cur_frag += 1; @@ -14062,7 +14280,7 @@ rtl8125_xmit_frags(struct rtl8125_private *tp, } /* anti gcc 2.95.3 bugware (sic) */ - status = rtl8125_get_txd_opts1(opts[0], len, entry); + status = rtl8125_get_txd_opts1(ring, opts[0], len, entry); if (cur_frag == (nr_frags - 1) || LsoPatchEnabled == TRUE) { //ring->tx_skb[entry].skb = skb; status |= LastFrag; @@ -14376,7 +14594,7 @@ rtl8125_tso_csum(struct sk_buff *skb, static bool rtl8125_tx_slots_avail(struct rtl8125_private *tp, struct rtl8125_tx_ring *ring) { - unsigned int slots_avail = READ_ONCE(ring->dirty_tx) + NUM_TX_DESC + unsigned int slots_avail = READ_ONCE(ring->dirty_tx) + ring->num_tx_desc - READ_ONCE(ring->cur_tx); /* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */ @@ -14400,7 +14618,7 @@ rtl8125_start_xmit(struct sk_buff *skb, struct rtl8125_tx_ring *ring; bool stop_queue; - assert(queue_mapping < tp->num_tx_queues); + assert(queue_mapping < tp->num_tx_rings); ring = &tp->tx_ring[queue_mapping]; @@ -14414,7 +14632,7 @@ rtl8125_start_xmit(struct sk_buff *skb, goto err_stop; } - entry = ring->cur_tx % NUM_TX_DESC; + entry = ring->cur_tx % ring->num_tx_desc; txd = ring->TxDescArray + entry; if (!EnableTxNoClose) { @@ -14448,7 +14666,7 @@ rtl8125_start_xmit(struct sk_buff *skb, opts[0] |= FirstFrag | LastFrag; } - opts[0] = rtl8125_get_txd_opts1(opts[0], len, entry); + opts[0] = rtl8125_get_txd_opts1(ring, opts[0], len, entry); mapping = dma_map_single(tp_to_dev(tp), skb->data, len, DMA_TO_DEVICE); if (unlikely(dma_mapping_error(tp_to_dev(tp), mapping))) { if (unlikely(net_ratelimit())) @@ -14559,7 +14777,7 @@ rtl8125_tx_interrupt(struct rtl8125_tx_ring *ring, int budget) } while (tx_left > 0) { - unsigned int entry = dirty_tx % NUM_TX_DESC; + unsigned int entry = dirty_tx % ring->num_tx_desc; struct ring_info *tx_skb = ring->tx_skb + entry; if (!EnableTxNoClose && @@ -14767,14 +14985,14 @@ rtl8125_rx_interrupt(struct net_device *dev, assert(dev != NULL); assert(tp != NULL); - if ((ring->RxDescArray == NULL)) + if (ring->RxDescArray == NULL) goto rx_out; rx_quota = RTL_RX_QUOTA(budget); cur_rx = ring->cur_rx; - entry = cur_rx % NUM_RX_DESC; + entry = cur_rx % ring->num_rx_desc; desc = rtl8125_get_rxdesc(tp, ring->RxDescArray, entry); - rx_left = NUM_RX_DESC + ring->dirty_rx - cur_rx; + rx_left = ring->num_rx_desc + ring->dirty_rx - cur_rx; rx_left = rtl8125_rx_quota(rx_left, (u32)rx_quota); for (; rx_left > 0; rx_left--) { @@ -14834,7 +15052,7 @@ process_pkt: unsigned int entry_next; struct sk_buff *skb_next; - entry_next = (cur_rx + 1) % NUM_RX_DESC; + entry_next = (cur_rx + 1) % ring->num_rx_desc; desc_next = (struct RxDescV3 *)rtl8125_get_rxdesc(tp, ring->RxDescArray, entry_next); rmb(); status_next = le32_to_cpu(desc_next->RxDescNormalDDWord4.opts1); @@ -14910,7 +15128,7 @@ process_pkt: } cur_rx++; - entry = cur_rx % NUM_RX_DESC; + entry = cur_rx % ring->num_rx_desc; desc = rtl8125_get_rxdesc(tp, ring->RxDescArray, entry); #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,37) prefetch(desc); @@ -14932,7 +15150,7 @@ process_pkt: * after refill ? * - how do others driver handle this condition (Uh oh...). */ - if ((ring->dirty_rx + NUM_RX_DESC == ring->cur_rx) && netif_msg_intr(tp)) + if ((ring->dirty_rx + ring->num_rx_desc == ring->cur_rx) && netif_msg_intr(tp)) printk(KERN_EMERG "%s: Rx buffers exhausted\n", dev->name); rx_out: @@ -14972,7 +15190,7 @@ static irqreturn_t rtl8125_interrupt(int irq, void *dev_instance) if (!status) break; - if ((status == 0xFFFFFFFF)) + if (status == 0xFFFFFFFF) break; if (!(status & (tp->intr_mask | tp->timer_intr_mask))) @@ -15038,14 +15256,15 @@ static irqreturn_t rtl8125_interrupt(int irq, void *dev_instance) if (status & tp->intr_mask) tp->keep_intr_cnt = RTK_KEEP_INTERRUPT_COUNT; + for (i = 0; i < tp->num_tx_rings; i++) + rtl8125_tx_interrupt(&tp->tx_ring[i], ~(u32)0); + #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) rtl8125_rx_interrupt(dev, tp, &tp->rx_ring[0], &budget); #else rtl8125_rx_interrupt(dev, tp, &tp->rx_ring[0], budget); #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) - for (i = 0; i < tp->num_tx_rings; i++) - rtl8125_tx_interrupt(&tp->tx_ring[i], ~(u32)0); #ifdef ENABLE_DASH_SUPPORT if (tp->DASH) { struct net_device *dev = tp->dev; @@ -15101,6 +15320,8 @@ static irqreturn_t rtl8125_interrupt_msix(int irq, void *dev_instance) printk(KERN_INFO "%s: interrupt message id %d in poll_msix\n", dev->name, message_id); #else + rtl8125_tx_interrupt_with_vector(tp, message_id, ~(u32)0); + if (message_id < tp->num_rx_rings) { #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) rtl8125_rx_interrupt(dev, tp, &tp->rx_ring[message_id], &budget); @@ -15109,8 +15330,6 @@ static irqreturn_t rtl8125_interrupt_msix(int irq, void *dev_instance) #endif //LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) } - rtl8125_tx_interrupt_with_vector(tp, message_id, ~(u32)0); - rtl8125_enable_hw_interrupt_v2(tp, message_id); #endif diff --git a/package/kernel/r8125/src/r8125_ptp.c b/package/kernel/r8125/src/r8125_ptp.c index e1102b76d8..6010a1809c 100644 --- a/package/kernel/r8125/src/r8125_ptp.c +++ b/package/kernel/r8125/src/r8125_ptp.c @@ -5,7 +5,7 @@ # 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. +# 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 diff --git a/package/kernel/r8125/src/r8125_ptp.h b/package/kernel/r8125/src/r8125_ptp.h index a324ff3827..7a1fe83b9a 100644 --- a/package/kernel/r8125/src/r8125_ptp.h +++ b/package/kernel/r8125/src/r8125_ptp.h @@ -5,7 +5,7 @@ # 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. +# 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 diff --git a/package/kernel/r8125/src/r8125_realwow.h b/package/kernel/r8125/src/r8125_realwow.h index 352e3270fa..e5e9b46d61 100644 --- a/package/kernel/r8125/src/r8125_realwow.h +++ b/package/kernel/r8125/src/r8125_realwow.h @@ -5,7 +5,7 @@ # 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. +# 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 diff --git a/package/kernel/r8125/src/r8125_rss.c b/package/kernel/r8125/src/r8125_rss.c index 78e53f5148..1f55c4477e 100644 --- a/package/kernel/r8125/src/r8125_rss.c +++ b/package/kernel/r8125/src/r8125_rss.c @@ -5,7 +5,7 @@ # 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. +# 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 diff --git a/package/kernel/r8125/src/r8125_rss.h b/package/kernel/r8125/src/r8125_rss.h index 90e2809027..8864139509 100644 --- a/package/kernel/r8125/src/r8125_rss.h +++ b/package/kernel/r8125/src/r8125_rss.h @@ -5,7 +5,7 @@ # 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. +# 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 diff --git a/package/kernel/r8125/src/rtl_eeprom.c b/package/kernel/r8125/src/rtl_eeprom.c index 866ae5f337..03660ddaf1 100644 --- a/package/kernel/r8125/src/rtl_eeprom.c +++ b/package/kernel/r8125/src/rtl_eeprom.c @@ -5,7 +5,7 @@ # 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. +# 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 diff --git a/package/kernel/r8125/src/rtl_eeprom.h b/package/kernel/r8125/src/rtl_eeprom.h index b0c4a050bd..8faed17cf2 100644 --- a/package/kernel/r8125/src/rtl_eeprom.h +++ b/package/kernel/r8125/src/rtl_eeprom.h @@ -5,7 +5,7 @@ # 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. +# 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 diff --git a/package/kernel/r8125/src/rtltool.c b/package/kernel/r8125/src/rtltool.c index ace717bde3..69ff20e8a2 100644 --- a/package/kernel/r8125/src/rtltool.c +++ b/package/kernel/r8125/src/rtltool.c @@ -5,7 +5,7 @@ # 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. +# 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 diff --git a/package/kernel/r8125/src/rtltool.h b/package/kernel/r8125/src/rtltool.h index fc8a10ca80..a54f8e6abd 100644 --- a/package/kernel/r8125/src/rtltool.h +++ b/package/kernel/r8125/src/rtltool.h @@ -5,7 +5,7 @@ # 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. +# 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