├── .github
└── workflows
│ ├── ixgbe.yaml
│ └── r8125.yaml
├── .gitignore
├── LICENSE
├── README.md
└── r8125
├── Makefile
├── README
├── autorun.sh
└── src
├── Makefile
├── Makefile_linux24x
├── r8125.h
├── r8125_dash.h
├── r8125_fiber.c
├── r8125_fiber.h
├── r8125_firmware.c
├── r8125_firmware.h
├── r8125_n.c
├── r8125_ptp.c
├── r8125_ptp.h
├── r8125_realwow.h
├── r8125_rss.c
├── r8125_rss.h
├── rtl_eeprom.c
├── rtl_eeprom.h
├── rtltool.c
└── rtltool.h
/.github/workflows/ixgbe.yaml:
--------------------------------------------------------------------------------
1 | name: Build ixgbe driver for Proxmox
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | schedule:
8 | - cron: "0 0 * * MON"
9 |
10 | env:
11 | IXGBE_VERSION: 5.20.10
12 | PROXMOX_KERNEL_VERSIONS: /var/tmp/proxmox_kernel_versions
13 | APT_URL: https://gist.githubusercontent.com/csrutil/6d83b7dd62b5652697fe22271fbee482/raw/5149abcc3ca3ee48f95978949db528d6bf765daa/depends-ubuntu-2004
14 |
15 | jobs:
16 | build_ixgbe_Modules:
17 | runs-on: ubuntu-20.04
18 | steps:
19 | - name: Checkout
20 | uses: actions/checkout@main
21 |
22 | - name: Initialization Environment
23 | env:
24 | DEBIAN_FRONTEND: noninteractive
25 | run: |
26 | kernel_version() {
27 | ## curl "https://raw.githubusercontent.com/proxmox/pve-kernel/$1/debian/changelog" \
28 | curl "https://git.proxmox.com/?p=pve-kernel.git;a=blob_plain;f=debian/changelog;hb=refs/heads/$1" \
29 | | grep 'pve-kernel' \
30 | | grep -Eo '[0-9]([0-9]|\.|-)+' | sed 's/(^|$)//g' \
31 | | head -n 10
32 | }
33 |
34 | kernel_version master >> $PROXMOX_KERNEL_VERSIONS
35 |
36 | sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc
37 | echo "deb http://download.proxmox.com/debian/pve bullseye pve-no-subscription" | sudo tee /etc/apt/sources.list.d/pve.list
38 | sudo wget https://enterprise.proxmox.com/debian/proxmox-release-bullseye.gpg -O /etc/apt/trusted.gpg.d/proxmox-release-bullseye.gpg
39 | sudo -E apt -qq update
40 | sudo -E apt -qq install $(curl -fsSL $APT_URL) tree jq
41 | for version in $(cat $PROXMOX_KERNEL_VERSIONS); do
42 | sudo -E apt -qq install "pve-headers-$version-pve" || true
43 | done
44 | sudo -E apt -qq autoremove --purge
45 | sudo -E apt -qq clean
46 |
47 | - name: Compile
48 | run: |
49 | wget -O "/tmp/ixgbe-$IXGBE_VERSION.tar.gz" \
50 | "https://onboardcloud.dl.sourceforge.net/project/e1000/ixgbe%20stable/$IXGBE_VERSION/ixgbe-$IXGBE_VERSION.tar.gz"
51 |
52 | for version in $(cat $PROXMOX_KERNEL_VERSIONS); do
53 | if [[ -d "/lib/modules/$version-pve" ]]; then
54 | rm -rf "ixgbe-$IXGBE_VERSION"
55 |
56 | tar xvf "/tmp/ixgbe-$IXGBE_VERSION.tar.gz"
57 |
58 | cd "ixgbe-$IXGBE_VERSION/src"
59 |
60 | BUILD_KERNEL="$version-pve" make || true
61 |
62 | if [[ -f ixgbe.ko ]]; then
63 | name="ixgbe-$IXGBE_VERSION-$version.ko"
64 | mv ixgbe.ko $name
65 | curl -F "file=@$name" https://file.io/?expires=1w | jq -r '(.name, .link)' >> /var/tmp/links
66 | fi
67 | fi
68 | done
69 |
70 | cat /var/tmp/links
71 |
72 | curl \
73 | -H "Title: Build ixgbe driver for Proxmox" \
74 | -H "Priority: default" \
75 | -H "Tags: ixgbe" \
76 | -d "$(cat /var/tmp/links)" \
77 | ntfy.sh/csrutil_gh
78 |
--------------------------------------------------------------------------------
/.github/workflows/r8125.yaml:
--------------------------------------------------------------------------------
1 | name: Build Realtek r8125 driver for OpenWrt
2 |
3 | on:
4 | push:
5 | branches:
6 | - main
7 | # schedule:
8 | # - cron: "0 0 * * MON"
9 |
10 | env:
11 | RELEASE_URL: https://gist.githubusercontent.com/csrutil/a448f7d1e9d6f0b8487fabd45dfc759f/raw/26642dc5b5a35cc954e14c7cd5edea8f197dc30d/OpenWrt-NIC-Drivers-release.txt
12 | KMOD_VERSION: 9.015.00
13 | APT_URL: https://gist.githubusercontent.com/csrutil/6d83b7dd62b5652697fe22271fbee482/raw/3fe019895bf3425e1f40518b83dd81306c2291f8/depends-ubuntu-2004
14 |
15 | jobs:
16 | build_r8125_modules:
17 | runs-on: ubuntu-22.04
18 | continue-on-error: true
19 |
20 | strategy:
21 | fail-fast: false
22 | matrix:
23 | sdk_url:
24 | - https://downloads.openwrt.org/releases/19.07.10/targets/x86/64/openwrt-sdk-19.07.10-x86-64_gcc-7.5.0_musl.Linux-x86_64.tar.xz
25 | - https://downloads.openwrt.org/releases/21.02.7/targets/x86/64/openwrt-sdk-21.02.7-x86-64_gcc-8.4.0_musl.Linux-x86_64.tar.xz
26 | - https://downloads.openwrt.org/releases/22.03.6/targets/x86/64/openwrt-sdk-22.03.6-x86-64_gcc-11.2.0_musl.Linux-x86_64.tar.xz
27 | - https://downloads.openwrt.org/releases/23.05.4/targets/x86/64/openwrt-sdk-23.05.4-x86-64_gcc-12.3.0_musl.Linux-x86_64.tar.xz
28 | - https://downloads.openwrt.org/releases/24.10.0/targets/x86/64/openwrt-sdk-24.10.0-x86-64_gcc-13.3.0_musl.Linux-x86_64.tar.zst
29 | - https://downloads.openwrt.org/releases/24.10.1/targets/x86/64/openwrt-sdk-24.10.1-x86-64_gcc-13.3.0_musl.Linux-x86_64.tar.zst
30 |
31 | steps:
32 | - name: Checkout repository
33 | uses: actions/checkout@v3
34 |
35 | - name: Initialize Environment
36 | env:
37 | DEBIAN_FRONTEND: noninteractive
38 | run: |
39 | sudo rm -rf /etc/apt/sources.list.d/* /usr/share/dotnet /usr/local/lib/android /opt/ghc
40 | sudo apt-get update -qq
41 | sudo apt-get install -qq -y $(curl -fsSL $APT_URL) tree jq
42 | sudo apt-get autoremove --purge -qq
43 | sudo apt-get clean -qq
44 |
45 | - name: Download and Extract SDK
46 | run: |
47 | sdk=$(basename ${{ matrix.sdk_url }} | sed -E 's/\.tar\.(xz|zst)$//')
48 | wget ${{ matrix.sdk_url }}
49 | case ${{ matrix.sdk_url }} in
50 | *.tar.xz) tar -xvf $sdk.tar.xz ;;
51 | *.tar.zst) tar --zstd -xvf $sdk.tar.zst ;;
52 | esac
53 | mkdir -p $sdk/package
54 | cp -r r8125 $sdk/package/
55 |
56 | - name: Compile Driver
57 | run: |
58 | sdk=$(basename ${{ matrix.sdk_url }} | sed -E 's/\.tar\.(xz|zst)$//')
59 |
60 | cd $sdk
61 | echo 'CONFIG_PACKAGE_kmod-r8125=m' > .config
62 | make defconfig
63 | if ! make package/r8125/compile -j$(nproc); then
64 | make package/r8125/compile -j1 V=sc || echo "Compilation failed for ${{ matrix.sdk_url }}!"
65 | fi
66 |
67 | cd ${{ github.workspace }}
68 | mkdir -p artifact
69 | find . -name 'kmod-r8125*.ipk' -exec mv {} artifact/ \;
70 |
71 | echo "SDK=$sdk" >> $GITHUB_ENV
72 |
73 | - name: Upload Build Artifacts
74 | uses: actions/upload-artifact@v4
75 | with:
76 | name: kmod-r8125-${{ env.SDK }}
77 | path: ${{ github.workspace }}/artifact/**/*
78 | if-no-files-found: error
79 |
80 | collect_and_upload:
81 | needs: build_r8125_modules
82 | runs-on: ubuntu-latest
83 | steps:
84 | - name: Download Artifacts
85 | uses: actions/download-artifact@v4
86 | with:
87 | path: all_artifacts
88 | pattern: kmod-r8125-*
89 | merge-multiple: true
90 |
91 | - name: Merge All Artifacts
92 | run: |
93 | mkdir -p combined_artifact
94 | find all_artifacts -name '*.ipk' -exec mv {} combined_artifact/ \;
95 | cd combined_artifact && md5sum *.ipk > md5sum.txt
96 |
97 | - name: Upload Combined Artifact
98 | uses: actions/upload-artifact@v4
99 | with:
100 | name: ${{ env.KMOD_VERSION }}
101 | path: combined_artifact/**/*
102 |
103 | deploy:
104 | needs: collect_and_upload
105 | name: Create Release and Upload Artifacts
106 | runs-on: ubuntu-latest
107 |
108 | steps:
109 | - name: Download Combined Artifact
110 | uses: actions/download-artifact@v4
111 | with:
112 | name: ${{ env.KMOD_VERSION }}
113 |
114 | - name: Prepare Release
115 | run: |
116 | wget -O release.txt $RELEASE_URL
117 | echo -e "\nUpdated at $(date)" >> release.txt
118 |
119 | mkdir -p artifact
120 | mv *.ipk artifact/
121 | cd artifact && md5sum *.ipk > md5sum.txt
122 |
123 | - name: Upload to GitHub Release
124 | uses: softprops/action-gh-release@v1
125 | with:
126 | name: ${{ env.KMOD_VERSION }}
127 | tag_name: ${{ env.KMOD_VERSION }}
128 | body_path: release.txt
129 | files: artifact/**/*
130 | env:
131 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
132 |
133 | - name: Cleanup Old Releases
134 | uses: dev-drprasad/delete-older-releases@v0.3.1
135 | with:
136 | keep_latest: 2
137 | delete_tags: true
138 | env:
139 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
140 |
141 | - name: Delete Build Artifacts
142 | uses: geekyeggo/delete-artifact@v2
143 | with:
144 | name: |
145 | kmod-r8125-*
146 | ${{ env.KMOD_VERSION }}
147 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Object files
5 | *.o
6 | *.ko
7 | *.obj
8 | *.elf
9 |
10 | # Linker output
11 | *.ilk
12 | *.map
13 | *.exp
14 |
15 | # Precompiled Headers
16 | *.gch
17 | *.pch
18 |
19 | # Libraries
20 | *.lib
21 | *.a
22 | *.la
23 | *.lo
24 |
25 | # Shared objects (inc. Windows DLLs)
26 | *.dll
27 | *.so
28 | *.so.*
29 | *.dylib
30 |
31 | # Executables
32 | *.exe
33 | *.out
34 | *.app
35 | *.i*86
36 | *.x86_64
37 | *.hex
38 |
39 | # Debug files
40 | *.dSYM/
41 | *.su
42 | *.idb
43 | *.pdb
44 |
45 | # Kernel Module Compile Results
46 | *.mod*
47 | *.cmd
48 | .tmp_versions/
49 | modules.order
50 | Module.symvers
51 | Mkfile.old
52 | dkms.conf
53 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # RTL8125B OpenWrt Driver
2 |
3 | The repository is for building the Realtek 8125b driver for OpenWrt firmwares
4 |
5 | [](https://github.com/csrutil/realtek-r8125-openwrt/actions/workflows/r8125.yaml)
6 |
7 | ## Realtek RTL8125 / RTL8125B(S)(G)
8 |
9 | The latest version of the driver has the RSS feature enable by default🎉
10 |
11 | ```
12 | root@main:~# cat /proc/interrupts | grep 'CPU\|eth' | grep -v '0 0'
13 | CPU0 CPU1
14 | 48: 1 8359439 PCI-MSI 3407888-edge eth0-16
15 | 50: 4146137 4039293 PCI-MSI 3407890-edge eth0-18
16 | 53: 0 1 PCI-MSI 3407893-edge eth0-21
17 | 64: 9385347 0 PCI-MSI 3424256-edge eth1-0
18 | 65: 3943462 3345782 PCI-MSI 3424257-edge eth1-1
19 | 80: 1 9252867 PCI-MSI 3424272-edge eth1-16
20 | 82: 3606778 3428598 PCI-MSI 3424274-edge eth1-18
21 | 85: 0 1 PCI-MSI 3424277-edge eth1-21
22 |
23 | root@main:~# cat /proc/net/r8125/eth*/debug/driver_var | grep Rss
24 | EnableRss 0x1
25 | EnableRss 0x1
26 | ```
27 |
28 | ## Setup
29 |
30 | Attention⚠️, only support official firmware. If you are compiling your own firmware, please refer to the scripts in the action.
31 |
32 | First, download the corresponding ipk file according to your version, scp it to your device, and then run
33 |
34 | ```
35 | opkg -i kmod-r8125_4.14.275+9.011.01-x86-0_x86_64.ipk
36 | ```
37 |
38 | If you are using the 5.15 kernel, the r8196 driver should automatically drive your network card. If you want to force the use of the driver from this project, you can delete the r8196 driver.
39 |
40 | ## QA
41 |
42 | if you're not the right speed, please check this command.
43 |
44 | ```
45 | # https://forum.openwrt.org/t/realtek-8156b-2-5g-for-pi-4-and-openwrt-21-02-2/125102/11
46 | ethtool -s eth1 autoneg on advertise 0x80000000002f
47 | ```
48 |
49 | ## Donating 💸
50 |
51 | - Feel free to [Buy Me a Coffee](https://www.buymeacoffee.com/csrutil)
52 | - `XHV hvxyGJc7axz1hiQCiXVcrrLJbjhbkHHuuC4auW9oJTbCcWEg7x14VgmfWPkxEThLsSfq4Ss9uuTLqYGe8ugFqnQe6Daa2hj2L7`
53 |
54 | ## Credits
55 |
56 | - https://sourceforge.net/projects/e1000/files/igb%20stable/
57 | - [https://www.realtek.com/en/component/zoo/category/network-interface-controllers-10-100-1000m-gigabit-ethernet-usb-3-0-software](https://www.realtek.com/Download/Index?cate_id=194&menu_id=297)
58 |
--------------------------------------------------------------------------------
/r8125/Makefile:
--------------------------------------------------------------------------------
1 | include $(TOPDIR)/rules.mk
2 | include $(INCLUDE_DIR)/kernel.mk
3 |
4 | PKG_NAME:=r8125
5 | PKG_VERSION:=9.015.00
6 | PKG_RELEASE:=0
7 |
8 | PKG_BUILD_DIR:=$(KERNEL_BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
9 |
10 | include $(INCLUDE_DIR)/package.mk
11 |
12 | define KernelPackage/r8125
13 | TITLE:=Driver for Realtek r8125 chipsets
14 | SUBMENU:=Network Devices
15 | VERSION:=$(LINUX_VERSION)+$(PKG_VERSION)-$(BOARD)-$(PKG_RELEASE)
16 | FILES:= $(PKG_BUILD_DIR)/r8125.ko
17 | AUTOLOAD:=$(call AutoProbe,r8125)
18 | endef
19 |
20 | define Package/r8125/description
21 | This package contains a driver for Realtek r8125 chipsets.
22 | endef
23 |
24 | R8125_MAKEOPTS= -C $(PKG_BUILD_DIR) \
25 | PATH="$(TARGET_PATH)" \
26 | ARCH="$(LINUX_KARCH)" \
27 | CROSS_COMPILE="$(TARGET_CROSS)" \
28 | TARGET="$(HAL_TARGET)" \
29 | TOOLPREFIX="$(KERNEL_CROSS)" \
30 | TOOLPATH="$(KERNEL_CROSS)" \
31 | KERNELPATH="$(LINUX_DIR)" \
32 | KERNELDIR="$(LINUX_DIR)" \
33 | LDOPTS=" " \
34 | DOMULTI=1
35 |
36 | define Build/Compile
37 | $(MAKE) $(R8125_MAKEOPTS) modules
38 | endef
39 |
40 | $(eval $(call KernelPackage,r8125))
41 |
--------------------------------------------------------------------------------
/r8125/README:
--------------------------------------------------------------------------------
1 |
2 |
3 | This is the Linux device driver released for Realtek 2.5 Gigabit Ethernet controllers with PCI-Express interface.
4 |
5 |
6 |
7 | - Kernel source tree (supported Linux kernel 2.6.x and 2.4.x)
8 | - For linux kernel 2.4.x, this driver supports 2.4.20 and latter.
9 | - Compiler/binutils for kernel compilation
10 |
11 |
12 | Unpack the tarball :
13 | # tar vjxf r8125-9.aaa.bb.tar.bz2
14 |
15 | Change to the directory:
16 | # cd r8125-9.aaa.bb
17 |
18 | If you are running the target kernel, then you should be able to do :
19 |
20 | # ./autorun.sh (as root or with sudo)
21 |
22 | You can check whether the driver is loaded by using following commands.
23 |
24 | # lsmod | grep r8125
25 | # ifconfig -a
26 |
27 | If there is a device name, ethX, shown on the monitor, the linux
28 | driver is loaded. Then, you can use the following command to activate
29 | the ethX.
30 |
31 | # ifconfig ethX up
32 |
33 | ,where X=0,1,2,...
34 |
35 |
36 | 1. Set manually
37 | a. Set the IP address of your machine.
38 |
39 | # ifconfig ethX "the IP address of your machine"
40 |
41 | b. Set the IP address of DNS.
42 |
43 | Insert the following configuration in /etc/resolv.conf.
44 |
45 | nameserver "the IP address of DNS"
46 |
47 | c. Set the IP address of gateway.
48 |
49 | # route add default gw "the IP address of gateway"
50 |
51 | 2. Set by doing configurations in /etc/sysconfig/network-scripts
52 | /ifcfg-ethX for Redhat and Fedora, or /etc/sysconfig/network
53 | /ifcfg-ethX for SuSE. There are two examples to set network
54 | configurations.
55 |
56 | a. Fixed IP address:
57 | DEVICE=eth0
58 | BOOTPROTO=static
59 | ONBOOT=yes
60 | TYPE=ethernet
61 | NETMASK=255.255.255.0
62 | IPADDR=192.168.1.1
63 | GATEWAY=192.168.1.254
64 | BROADCAST=192.168.1.255
65 |
66 | b. DHCP:
67 | DEVICE=eth0
68 | BOOTPROTO=dhcp
69 | ONBOOT=yes
70 |
71 |
72 | There are two ways to modify the MAC address of the NIC.
73 | 1. Use ifconfig:
74 |
75 | # ifconfig ethX hw ether YY:YY:YY:YY:YY:YY
76 |
77 | ,where X is the device number assigned by Linux kernel, and
78 | YY:YY:YY:YY:YY:YY is the MAC address assigned by the user.
79 |
80 | 2. Use ip:
81 |
82 | # ip link set ethX address YY:YY:YY:YY:YY:YY
83 |
84 | ,where X is the device number assigned by Linux kernel, and
85 | YY:YY:YY:YY:YY:YY is the MAC address assigned by the user.
86 |
87 |
88 |
89 | 1. Force the link status when insert the driver.
90 |
91 | If the user is in the path ~/r8125, the link status can be forced
92 | to one of the 5 modes as following command.
93 |
94 | # insmod ./src/r8125.ko speed=SPEED_MODE duplex=DUPLEX_MODE autoneg=NWAY_OPTION
95 |
96 | ,where
97 | SPEED_MODE = 1000 for 1000Mbps
98 | = 100 for 100Mbps
99 | = 10 for 10Mbps
100 | DUPLEX_MODE = 0 for half-duplex
101 | = 1 for full-duplex
102 | NWAY_OPTION = 0 for auto-negotiation off (true force)
103 | = 1 for auto-negotiation on (nway force)
104 | For example:
105 |
106 | # insmod ./src/r8125.ko speed=100 duplex=0 autoneg=1
107 |
108 | will force PHY to operate in 100Mpbs Half-duplex(nway force).
109 |
110 | 2. Force the link status by using ethtool.
111 | a. Insert the driver first.
112 | b. Make sure that ethtool exists in /sbin.
113 | c. Force the link status as the following command.
114 |
115 | 2.5G before kernel v4.10
116 | # ethtool -s eth0 autoneg on advertise 0x802f
117 |
118 | 2.5G for kernel v4.10 and later
119 | # ethtool -s eth0 autoneg on advertise 0x80000000002f
120 |
121 | # ethtool -s eth0 autoneg on advertise 0x002f (1G)
122 | # ethtool -s eth0 autoneg on advertise 0x000f (100M full)
123 | # ethtool -s eth0 autoneg on advertise 0x0003 (10M full)
124 |
125 |
126 | Transmitting Jumbo Frames, whose packet size is bigger than 1500 bytes, please change mtu by the following command.
127 |
128 | # ifconfig ethX mtu MTU
129 |
130 | , where X=0,1,2,..., and MTU is configured by user.
131 |
132 | RTL8125 supports Jumbo Frame size up to 9 kBytes.
133 |
134 |
135 | Get/Set device EEE status
136 |
137 | Get EEE device status
138 | # ethtool --show-eee enp1s0
139 |
140 | Set EEE device status
141 | # ethtool --set-eee enp1s0 eee on tx-lpi on tx-timer 1546 advertise 0x0008 (100M full)
142 | # ethtool --set-eee enp1s0 eee on tx-lpi on tx-timer 1546 advertise 0x0020 (1G)
143 | # ethtool --set-eee enp1s0 eee on tx-lpi on tx-timer 1546 advertise 0x8000 (2.5G)
144 |
--------------------------------------------------------------------------------
/r8125/autorun.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | # SPDX-License-Identifier: GPL-2.0-only
3 |
4 | # invoke insmod with all arguments we got
5 | # and use a pathname, as insmod doesn't look in . by default
6 |
7 | TARGET_PATH=$(find /lib/modules/$(uname -r)/kernel/drivers/net/ethernet -name realtek -type d)
8 | if [ "$TARGET_PATH" = "" ]; then
9 | TARGET_PATH=$(find /lib/modules/$(uname -r)/kernel/drivers/net -name realtek -type d)
10 | fi
11 | if [ "$TARGET_PATH" = "" ]; then
12 | TARGET_PATH=/lib/modules/$(uname -r)/kernel/drivers/net
13 | fi
14 | echo
15 | echo "Check old driver and unload it."
16 | check=`lsmod | grep r8169`
17 | if [ "$check" != "" ]; then
18 | echo "rmmod r8169"
19 | /sbin/rmmod r8169
20 | fi
21 |
22 | check=`lsmod | grep r8125`
23 | if [ "$check" != "" ]; then
24 | echo "rmmod r8125"
25 | /sbin/rmmod r8125
26 | fi
27 |
28 | echo "Build the module and install"
29 | echo "-------------------------------" >> log.txt
30 | date 1>>log.txt
31 | make $@ all 1>>log.txt || exit 1
32 | module=`ls src/*.ko`
33 | module=${module#src/}
34 | module=${module%.ko}
35 |
36 | if [ "$module" = "" ]; then
37 | echo "No driver exists!!!"
38 | exit 1
39 | elif [ "$module" != "r8169" ]; then
40 | if test -e $TARGET_PATH/r8169.ko ; then
41 | echo "Backup r8169.ko"
42 | if test -e $TARGET_PATH/r8169.bak ; then
43 | i=0
44 | while test -e $TARGET_PATH/r8169.bak$i
45 | do
46 | i=$(($i+1))
47 | done
48 | echo "rename r8169.ko to r8169.bak$i"
49 | mv $TARGET_PATH/r8169.ko $TARGET_PATH/r8169.bak$i
50 | else
51 | echo "rename r8169.ko to r8169.bak"
52 | mv $TARGET_PATH/r8169.ko $TARGET_PATH/r8169.bak
53 | fi
54 | fi
55 | fi
56 |
57 | echo "DEPMOD $(uname -r)"
58 | depmod `uname -r`
59 | echo "load module $module"
60 | modprobe $module
61 |
62 | is_update_initramfs=n
63 | distrib_list="ubuntu debian"
64 |
65 | if [ -r /etc/debian_version ]; then
66 | is_update_initramfs=y
67 | elif [ -r /etc/lsb-release ]; then
68 | for distrib in $distrib_list
69 | do
70 | /bin/grep -i "$distrib" /etc/lsb-release 2>&1 /dev/null && \
71 | is_update_initramfs=y && break
72 | done
73 | fi
74 |
75 | if [ "$is_update_initramfs" = "y" ]; then
76 | if which update-initramfs >/dev/null ; then
77 | echo "Updating initramfs. Please wait."
78 | update-initramfs -u -k $(uname -r)
79 | else
80 | echo "update-initramfs: command not found"
81 | exit 1
82 | fi
83 | fi
84 |
85 | echo "Completed."
86 | exit 0
87 |
88 |
--------------------------------------------------------------------------------
/r8125/src/Makefile:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: GPL-2.0-only
2 | ################################################################################
3 | #
4 | # r8125 is the Linux device driver released for Realtek 2.5 Gigabit Ethernet
5 | # controllers with PCI-Express interface.
6 | #
7 | # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.
8 | #
9 | # This program is free software; you can redistribute it and/or modify it
10 | # under the terms of the GNU General Public License as published by the Free
11 | # Software Foundation; either version 2 of the License, or (at your option)
12 | # any later version.
13 | #
14 | # This program is distributed in the hope that it will be useful, but WITHOUT
15 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 | # more details.
18 | #
19 | # You should have received a copy of the GNU General Public License along with
20 | # this program; if not, see .
21 | #
22 | # Author:
23 | # Realtek NIC software team
24 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
25 | #
26 | ################################################################################
27 |
28 | ################################################################################
29 | # This product is covered by one or more of the following patents:
30 | # US6,570,884, US6,115,776, and US6,327,625.
31 | ################################################################################
32 |
33 | CONFIG_SOC_LAN = n
34 | ENABLE_FIBER_SUPPORT = n
35 | ENABLE_REALWOW_SUPPORT = n
36 | ENABLE_DASH_SUPPORT = n
37 | ENABLE_DASH_PRINTER_SUPPORT = n
38 | CONFIG_DOWN_SPEED_100 = n
39 | CONFIG_ASPM = n
40 | ENABLE_S5WOL = y
41 | ENABLE_S5_KEEP_CURR_MAC = n
42 | ENABLE_EEE = y
43 | ENABLE_S0_MAGIC_PACKET = n
44 | ENABLE_TX_NO_CLOSE = y
45 | ENABLE_MULTIPLE_TX_QUEUE = y
46 | ENABLE_PTP_SUPPORT = n
47 | ENABLE_PTP_MASTER_MODE = n
48 | ENABLE_RSS_SUPPORT = y
49 | ENABLE_LIB_SUPPORT = n
50 | ENABLE_USE_FIRMWARE_FILE = n
51 | DISABLE_WOL_SUPPORT = n
52 | DISABLE_MULTI_MSIX_VECTOR = n
53 | ENABLE_DOUBLE_VLAN = n
54 | ENABLE_PAGE_REUSE = n
55 | ENABLE_RX_PACKET_FRAGMENT = n
56 | ENABLE_GIGA_LITE = y
57 |
58 | ifneq ($(KERNELRELEASE),)
59 | obj-m := r8125.o
60 | r8125-objs := r8125_n.o rtl_eeprom.o rtltool.o
61 | ifeq ($(CONFIG_SOC_LAN), y)
62 | EXTRA_CFLAGS += -DCONFIG_SOC_LAN
63 | endif
64 | ifeq ($(ENABLE_FIBER_SUPPORT), y)
65 | r8125-objs += r8125_fiber.o
66 | EXTRA_CFLAGS += -DENABLE_FIBER_SUPPORT
67 | endif
68 | ifeq ($(ENABLE_REALWOW_SUPPORT), y)
69 | r8125-objs += r8125_realwow.o
70 | EXTRA_CFLAGS += -DENABLE_REALWOW_SUPPORT
71 | endif
72 | ifeq ($(ENABLE_DASH_SUPPORT), y)
73 | r8125-objs += r8125_dash.o
74 | EXTRA_CFLAGS += -DENABLE_DASH_SUPPORT
75 | endif
76 | ifeq ($(ENABLE_DASH_PRINTER_SUPPORT), y)
77 | r8125-objs += r8125_dash.o
78 | EXTRA_CFLAGS += -DENABLE_DASH_SUPPORT -DENABLE_DASH_PRINTER_SUPPORT
79 | endif
80 | EXTRA_CFLAGS += -DCONFIG_R8125_NAPI
81 | EXTRA_CFLAGS += -DCONFIG_R8125_VLAN
82 | ifeq ($(CONFIG_DOWN_SPEED_100), y)
83 | EXTRA_CFLAGS += -DCONFIG_DOWN_SPEED_100
84 | endif
85 | ifeq ($(CONFIG_ASPM), y)
86 | EXTRA_CFLAGS += -DCONFIG_ASPM
87 | endif
88 | ifeq ($(ENABLE_S5WOL), y)
89 | EXTRA_CFLAGS += -DENABLE_S5WOL
90 | endif
91 | ifeq ($(ENABLE_S5_KEEP_CURR_MAC), y)
92 | EXTRA_CFLAGS += -DENABLE_S5_KEEP_CURR_MAC
93 | endif
94 | ifeq ($(ENABLE_EEE), y)
95 | EXTRA_CFLAGS += -DENABLE_EEE
96 | endif
97 | ifeq ($(ENABLE_S0_MAGIC_PACKET), y)
98 | EXTRA_CFLAGS += -DENABLE_S0_MAGIC_PACKET
99 | endif
100 | ifeq ($(ENABLE_TX_NO_CLOSE), y)
101 | EXTRA_CFLAGS += -DENABLE_TX_NO_CLOSE
102 | endif
103 | ifeq ($(ENABLE_MULTIPLE_TX_QUEUE), y)
104 | EXTRA_CFLAGS += -DENABLE_MULTIPLE_TX_QUEUE
105 | endif
106 | ifeq ($(ENABLE_PTP_SUPPORT), y)
107 | r8125-objs += r8125_ptp.o
108 | EXTRA_CFLAGS += -DENABLE_PTP_SUPPORT
109 | endif
110 | ifeq ($(ENABLE_PTP_MASTER_MODE), y)
111 | EXTRA_CFLAGS += -DENABLE_PTP_MASTER_MODE
112 | endif
113 | ifeq ($(ENABLE_RSS_SUPPORT), y)
114 | r8125-objs += r8125_rss.o
115 | EXTRA_CFLAGS += -DENABLE_RSS_SUPPORT
116 | endif
117 | ifeq ($(ENABLE_LIB_SUPPORT), y)
118 | r8125-objs += r8125_lib.o
119 | EXTRA_CFLAGS += -DENABLE_LIB_SUPPORT
120 | endif
121 | ifeq ($(ENABLE_USE_FIRMWARE_FILE), y)
122 | r8125-objs += r8125_firmware.o
123 | EXTRA_CFLAGS += -DENABLE_USE_FIRMWARE_FILE
124 | endif
125 | ifeq ($(DISABLE_WOL_SUPPORT), y)
126 | EXTRA_CFLAGS += -DDISABLE_WOL_SUPPORT
127 | endif
128 | ifeq ($(DISABLE_MULTI_MSIX_VECTOR), y)
129 | EXTRA_CFLAGS += -DDISABLE_MULTI_MSIX_VECTOR
130 | endif
131 | ifeq ($(ENABLE_DOUBLE_VLAN), y)
132 | EXTRA_CFLAGS += -DENABLE_DOUBLE_VLAN
133 | endif
134 | ifeq ($(ENABLE_PAGE_REUSE), y)
135 | EXTRA_CFLAGS += -DENABLE_PAGE_REUSE
136 | endif
137 | ifeq ($(ENABLE_RX_PACKET_FRAGMENT), y)
138 | EXTRA_CFLAGS += -DENABLE_RX_PACKET_FRAGMENT
139 | endif
140 | ifeq ($(ENABLE_GIGA_LITE), y)
141 | EXTRA_CFLAGS += -DENABLE_GIGA_LITE
142 | endif
143 | else
144 | BASEDIR := /lib/modules/$(shell uname -r)
145 | KERNELDIR ?= $(BASEDIR)/build
146 | PWD :=$(shell pwd)
147 | DRIVERDIR := $(shell find $(BASEDIR)/kernel/drivers/net/ethernet -name realtek -type d)
148 | ifeq ($(DRIVERDIR),)
149 | DRIVERDIR := $(shell find $(BASEDIR)/kernel/drivers/net -name realtek -type d)
150 | endif
151 | ifeq ($(DRIVERDIR),)
152 | DRIVERDIR := $(BASEDIR)/kernel/drivers/net
153 | endif
154 | RTKDIR := $(subst $(BASEDIR)/,,$(DRIVERDIR))
155 |
156 | KERNEL_GCC_VERSION := $(shell cat /proc/version | sed -n 's/.*gcc version \([[:digit:]]\.[[:digit:]]\.[[:digit:]]\).*/\1/p')
157 | CCVERSION = $(shell $(CC) -dumpversion)
158 |
159 | KVER = $(shell uname -r)
160 | KMAJ = $(shell echo $(KVER) | \
161 | sed -e 's/^\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*.*/\1/')
162 | KMIN = $(shell echo $(KVER) | \
163 | sed -e 's/^[0-9][0-9]*\.\([0-9][0-9]*\)\.[0-9][0-9]*.*/\1/')
164 | KREV = $(shell echo $(KVER) | \
165 | sed -e 's/^[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/')
166 |
167 | kver_ge = $(shell \
168 | echo test | awk '{if($(KMAJ) < $(1)) {print 0} else { \
169 | if($(KMAJ) > $(1)) {print 1} else { \
170 | if($(KMIN) < $(2)) {print 0} else { \
171 | if($(KMIN) > $(2)) {print 1} else { \
172 | if($(KREV) < $(3)) {print 0} else { print 1 } \
173 | }}}}}' \
174 | )
175 |
176 | .PHONY: all
177 | all: print_vars clean modules install
178 |
179 | print_vars:
180 | @echo
181 | @echo "CC: " $(CC)
182 | @echo "CCVERSION: " $(CCVERSION)
183 | @echo "KERNEL_GCC_VERSION: " $(KERNEL_GCC_VERSION)
184 | @echo "KVER: " $(KVER)
185 | @echo "KMAJ: " $(KMAJ)
186 | @echo "KMIN: " $(KMIN)
187 | @echo "KREV: " $(KREV)
188 | @echo "BASEDIR: " $(BASEDIR)
189 | @echo "DRIVERDIR: " $(DRIVERDIR)
190 | @echo "PWD: " $(PWD)
191 | @echo "RTKDIR: " $(RTKDIR)
192 | @echo
193 |
194 | .PHONY:modules
195 | modules:
196 | #ifeq ($(call kver_ge,5,0,0),1)
197 | $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
198 | #else
199 | # $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) modules
200 | #endif
201 |
202 | .PHONY:clean
203 | clean:
204 | #ifeq ($(call kver_ge,5,0,0),1)
205 | $(MAKE) -C $(KERNELDIR) M=$(PWD) clean
206 | #else
207 | # $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) clean
208 | #endif
209 |
210 | .PHONY:install
211 | install:
212 | #ifeq ($(call kver_ge,5,0,0),1)
213 | $(MAKE) -C $(KERNELDIR) M=$(PWD) INSTALL_MOD_DIR=$(RTKDIR) modules_install
214 | #else
215 | # $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) INSTALL_MOD_DIR=$(RTKDIR) modules_install
216 | #endif
217 |
218 | endif
219 |
--------------------------------------------------------------------------------
/r8125/src/Makefile_linux24x:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: GPL-2.0-only
2 | ################################################################################
3 | #
4 | # r8125 is the Linux device driver released for Realtek 2.5 Gigabit Ethernet
5 | # controllers with PCI-Express interface.
6 | #
7 | # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.
8 | #
9 | # This program is free software; you can redistribute it and/or modify it
10 | # under the terms of the GNU General Public License as published by the Free
11 | # Software Foundation; either version 2 of the License, or (at your option)
12 | # any later version.
13 | #
14 | # This program is distributed in the hope that it will be useful, but WITHOUT
15 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 | # more details.
18 | #
19 | # You should have received a copy of the GNU General Public License along with
20 | # this program; if not, see .
21 | #
22 | # Author:
23 | # Realtek NIC software team
24 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
25 | #
26 | ################################################################################
27 |
28 | ################################################################################
29 | # This product is covered by one or more of the following patents:
30 | # US6,570,884, US6,115,776, and US6,327,625.
31 | ################################################################################
32 |
33 | CC := gcc
34 | LD := ld
35 | ARCH := $(shell uname -m | sed 's/i.86/i386/')
36 | KSRC := /lib/modules/$(shell uname -r)/build
37 | CONFIG_FILE := $(KSRC)/include/linux/autoconf.h
38 | KMISC := /lib/modules/$(shell uname -r)/kernel/drivers/net/
39 |
40 |
41 | ifeq ($(ARCH),x86_64)
42 | MODCFLAGS += -mcmodel=kernel -mno-red-zone
43 | endif
44 |
45 | #standard flags for module builds
46 | MODCFLAGS += -DLINUX -D__KERNEL__ -DMODULE -O2 -pipe -Wall
47 | MODCFLAGS += -I$(KSRC)/include -I.
48 | MODCFLAGS += -DMODVERSIONS -DEXPORT_SYMTAB -include $(KSRC)/include/linux/modversions.h
49 | SOURCE := r8125_n.c rtl_eeprom.c rtltool.c
50 | OBJS := $(SOURCE:.c=.o)
51 |
52 |
53 | SMP := $(shell $(CC) $(MODCFLAGS) -E -dM $(CONFIG_FILE) | \
54 | grep CONFIG_SMP | awk '{print $$3}')
55 |
56 | ifneq ($(SMP),1)
57 | SMP := 0
58 | endif
59 |
60 | ifeq ($(SMP),1)
61 | MODCFLAGS += -D__SMP__
62 | endif
63 |
64 | modules: $(OBJS)
65 | $(LD) -r $^ -o r8125.o
66 | strip --strip-debug r8125.o
67 |
68 | %.o: %.c
69 | $(CC) $(MODCFLAGS) -c $< -o $@
70 |
71 | clean:
72 | rm *.o -f
73 |
74 | install:
75 | install -m 744 -c r8125.o $(KMISC)
76 |
--------------------------------------------------------------------------------
/r8125/src/r8125_dash.h:
--------------------------------------------------------------------------------
1 | /* SPDX-License-Identifier: GPL-2.0-only */
2 | /*
3 | ################################################################################
4 | #
5 | # r8125 is the Linux device driver released for Realtek 2.5 Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.
9 | #
10 | # This program is free software; you can redistribute it and/or modify it
11 | # under the terms of the GNU General Public License as published by the Free
12 | # Software Foundation; either version 2 of the License, or (at your option)
13 | # any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful, but WITHOUT
16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 | # more details.
19 | #
20 | # You should have received a copy of the GNU General Public License along with
21 | # this program; if not, see .
22 | #
23 | # Author:
24 | # Realtek NIC software team
25 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
26 | #
27 | ################################################################################
28 | */
29 |
30 | /************************************************************************************
31 | * This product is covered by one or more of the following patents:
32 | * US6,570,884, US6,115,776, and US6,327,625.
33 | ***********************************************************************************/
34 |
35 | #ifndef _LINUX_R8125_DASH_H
36 | #define _LINUX_R8125_DASH_H
37 |
38 | #include
39 |
40 | #define SIOCDEVPRIVATE_RTLDASH SIOCDEVPRIVATE+2
41 |
42 | enum rtl_dash_cmd {
43 | RTL_DASH_ARP_NS_OFFLOAD = 0,
44 | RTL_DASH_SET_OOB_IPMAC,
45 | RTL_DASH_NOTIFY_OOB,
46 |
47 | RTL_DASH_SEND_BUFFER_DATA_TO_DASH_FW,
48 | RTL_DASH_CHECK_SEND_BUFFER_TO_DASH_FW_COMPLETE,
49 | RTL_DASH_GET_RCV_FROM_FW_BUFFER_DATA,
50 | RTL_DASH_OOB_REQ,
51 | RTL_DASH_OOB_ACK,
52 | RTL_DASH_DETACH_OOB_REQ,
53 | RTL_DASH_DETACH_OOB_ACK,
54 |
55 | RTL_FW_SET_IPV4 = 0x10,
56 | RTL_FW_GET_IPV4,
57 | RTL_FW_SET_IPV6,
58 | RTL_FW_GET_IPV6,
59 | RTL_FW_SET_EXT_SNMP,
60 | RTL_FW_GET_EXT_SNMP,
61 | RTL_FW_SET_WAKEUP_PATTERN,
62 | RTL_FW_GET_WAKEUP_PATTERN,
63 | RTL_FW_DEL_WAKEUP_PATTERN,
64 |
65 | RTLT_DASH_COMMAND_INVALID,
66 | };
67 |
68 | struct rtl_dash_ip_mac {
69 | struct sockaddr ifru_addr;
70 | struct sockaddr ifru_netmask;
71 | struct sockaddr ifru_hwaddr;
72 | };
73 |
74 | struct rtl_dash_ioctl_struct {
75 | __u32 cmd;
76 | __u32 offset;
77 | __u32 len;
78 | union {
79 | __u32 data;
80 | void *data_buffer;
81 | };
82 | };
83 |
84 | struct settings_ipv4 {
85 | __u32 IPv4addr;
86 | __u32 IPv4mask;
87 | __u32 IPv4Gateway;
88 | };
89 |
90 | struct settings_ipv6 {
91 | __u32 reserved;
92 | __u32 prefixLen;
93 | __u16 IPv6addr[8];
94 | __u16 IPv6Gateway[8];
95 | };
96 |
97 | struct settings_ext_snmp {
98 | __u16 index;
99 | __u16 oid_get_len;
100 | __u8 oid_for_get[24];
101 | __u8 reserved0[26];
102 | __u16 value_len;
103 | __u8 value[256];
104 | __u8 supported;
105 | __u8 reserved1[27];
106 | };
107 |
108 | struct wakeup_pattern {
109 | __u8 index;
110 | __u8 valid;
111 | __u8 start;
112 | __u8 length;
113 | __u8 name[36];
114 | __u8 mask[16];
115 | __u8 pattern[128];
116 | __u32 reserved[2];
117 | };
118 |
119 | typedef struct _RX_DASH_FROM_FW_DESC {
120 | u16 length;
121 | u8 statusLowByte;
122 | u8 statusHighByte;
123 | u32 resv;
124 | u64 BufferAddress;
125 | }
126 | RX_DASH_FROM_FW_DESC, *PRX_DASH_FROM_FW_DESC;
127 |
128 | typedef struct _TX_DASH_SEND_FW_DESC {
129 | u16 length;
130 | u8 statusLowByte;
131 | u8 statusHighByte;
132 | u32 resv;
133 | u64 BufferAddress;
134 | }
135 | TX_DASH_SEND_FW_DESC, *PTX_DASH_SEND_FW_DESC;
136 |
137 | typedef struct _OSOOBHdr {
138 | u32 len;
139 | u8 type;
140 | u8 flag;
141 | u8 hostReqV;
142 | u8 res;
143 | }
144 | OSOOBHdr, *POSOOBHdr;
145 |
146 | typedef struct _RX_DASH_BUFFER_TYPE_2 {
147 | OSOOBHdr oobhdr;
148 | u8 RxDataBuffer[0];
149 | }
150 | RX_DASH_BUFFER_TYPE_2, *PRX_DASH_BUFFER_TYPE_2;
151 |
152 | #define ALIGN_8 (0x7)
153 | #define ALIGN_16 (0xf)
154 | #define ALIGN_32 (0x1f)
155 | #define ALIGN_64 (0x3f)
156 | #define ALIGN_256 (0xff)
157 | #define ALIGN_4096 (0xfff)
158 |
159 | #define OCP_REG_CONFIG0 (0x10)
160 | #define OCP_REG_CONFIG0_REV_F (0xB8)
161 | #define OCP_REG_DASH_POLL (0x30)
162 | #define OCP_REG_HOST_REQ (0x34)
163 | #define OCP_REG_DASH_REQ (0x35)
164 | #define OCP_REG_CR (0x36)
165 | #define OCP_REG_DMEMSTA (0x38)
166 | #define OCP_REG_GPHYAR (0x60)
167 | #define OCP_REG_FIRMWARE_MAJOR_VERSION (0x120)
168 |
169 |
170 | #define OCP_REG_CONFIG0_DASHEN BIT_15
171 | #define OCP_REG_CONFIG0_OOBRESET BIT_14
172 | #define OCP_REG_CONFIG0_APRDY BIT_13
173 | #define OCP_REG_CONFIG0_FIRMWARERDY BIT_12
174 | #define OCP_REG_CONFIG0_DRIVERRDY BIT_11
175 | #define OCP_REG_CONFIG0_OOB_WDT BIT_9
176 | #define OCP_REG_CONFIG0_DRV_WAIT_OOB BIT_8
177 | #define OCP_REG_CONFIG0_TLSEN BIT_7
178 |
179 | #define HW_DASH_SUPPORT_DASH(_M) ((_M)->HwSuppDashVer > 0)
180 | #define HW_DASH_SUPPORT_TYPE_1(_M) ((_M)->HwSuppDashVer == 1)
181 | #define HW_DASH_SUPPORT_TYPE_2(_M) ((_M)->HwSuppDashVer == 2)
182 | #define HW_DASH_SUPPORT_TYPE_3(_M) ((_M)->HwSuppDashVer == 3)
183 | #define HW_DASH_SUPPORT_TYPE_4(_M) ((_M)->HwSuppDashVer == 4)
184 | #define HW_DASH_SUPPORT_CMAC(_M) (HW_DASH_SUPPORT_TYPE_2(_M) || HW_DASH_SUPPORT_TYPE_3(_M))
185 | #define HW_DASH_SUPPORT_IPC2(_M) (HW_DASH_SUPPORT_TYPE_4(_M))
186 | #define HW_DASH_SUPPORT_GET_FIRMWARE_VERSION(_M) (HW_DASH_SUPPORT_TYPE_2(_M) || \
187 | HW_DASH_SUPPORT_TYPE_3(_M) || \
188 | HW_DASH_SUPPORT_TYPE_4(_M))
189 |
190 | #define RECV_FROM_FW_BUF_SIZE (1520)
191 | #define SEND_TO_FW_BUF_SIZE (1520)
192 |
193 | #define RX_DASH_FROM_FW_OWN BIT_15
194 | #define TX_DASH_SEND_FW_OWN BIT_15
195 | #define TX_DASH_SEND_FW_OWN_HIGHBYTE BIT_7
196 |
197 | #define TXS_CC3_0 (BIT_0|BIT_1|BIT_2|BIT_3)
198 | #define TXS_EXC BIT_4
199 | #define TXS_LNKF BIT_5
200 | #define TXS_OWC BIT_6
201 | #define TXS_TES BIT_7
202 | #define TXS_UNF BIT_9
203 | #define TXS_LGSEN BIT_11
204 | #define TXS_LS BIT_12
205 | #define TXS_FS BIT_13
206 | #define TXS_EOR BIT_14
207 | #define TXS_OWN BIT_15
208 |
209 | #define TPPool_HRDY 0x20
210 |
211 | #define HostReqReg (0xC0)
212 | #define SystemMasterDescStartAddrLow (0xF0)
213 | #define SystemMasterDescStartAddrHigh (0xF4)
214 | #define SystemSlaveDescStartAddrLow (0xF8)
215 | #define SystemSlaveDescStartAddrHigh (0xFC)
216 |
217 | //DASH Request Type
218 | #define WSMANREG 0x01
219 | #define OSPUSHDATA 0x02
220 |
221 | #define RXS_OWN BIT_15
222 | #define RXS_EOR BIT_14
223 | #define RXS_FS BIT_13
224 | #define RXS_LS BIT_12
225 |
226 | #define ISRIMR_DP_DASH_OK BIT_15
227 | #define ISRIMR_DP_HOST_OK BIT_13
228 | #define ISRIMR_DP_REQSYS_OK BIT_11
229 |
230 | #define ISRIMR_DASH_INTR_EN BIT_12
231 | #define ISRIMR_DASH_INTR_CMAC_RESET BIT_15
232 |
233 | #define ISRIMR_DASH_TYPE2_ROK BIT_0
234 | #define ISRIMR_DASH_TYPE2_RDU BIT_1
235 | #define ISRIMR_DASH_TYPE2_TOK BIT_2
236 | #define ISRIMR_DASH_TYPE2_TDU BIT_3
237 | #define ISRIMR_DASH_TYPE2_TX_FIFO_FULL BIT_4
238 | #define ISRIMR_DASH_TYPE2_TX_DISABLE_IDLE BIT_5
239 | #define ISRIMR_DASH_TYPE2_RX_DISABLE_IDLE BIT_6
240 |
241 | #define CMAC_OOB_STOP 0x25
242 | #define CMAC_OOB_INIT 0x26
243 | #define CMAC_OOB_RESET 0x2a
244 |
245 | #define NO_BASE_ADDRESS 0x00000000
246 | #define RTL8168FP_OOBMAC_BASE 0xBAF70000
247 | #define RTL8168FP_CMAC_IOBASE 0xBAF20000
248 | #define RTL8168FP_KVM_BASE 0xBAF80400
249 | #define CMAC_SYNC_REG 0x20
250 | #define CMAC_RXDESC_OFFSET 0x90 //RX: 0x90 - 0x98
251 | #define CMAC_TXDESC_OFFSET 0x98 //TX: 0x98 - 0x9F
252 |
253 | /* cmac write/read MMIO register */
254 | #define RTL_CMAC_W8(tp, reg, val8) writeb ((val8), tp->cmac_ioaddr + (reg))
255 | #define RTL_CMAC_W16(tp, reg, val16) writew ((val16), tp->cmac_ioaddr + (reg))
256 | #define RTL_CMAC_W32(tp, reg, val32) writel ((val32), tp->cmac_ioaddr + (reg))
257 | #define RTL_CMAC_R8(tp, reg) readb (tp->cmac_ioaddr + (reg))
258 | #define RTL_CMAC_R16(tp, reg) readw (tp->cmac_ioaddr + (reg))
259 | #define RTL_CMAC_R32(tp, reg) ((unsigned long) readl (tp->cmac_ioaddr + (reg)))
260 |
261 | int rtl8125_dash_ioctl(struct net_device *dev, struct ifreq *ifr);
262 | void HandleDashInterrupt(struct net_device *dev);
263 | int AllocateDashShareMemory(struct net_device *dev);
264 | void FreeAllocatedDashShareMemory(struct net_device *dev);
265 | void DashHwInit(struct net_device *dev);
266 |
267 |
268 | #endif /* _LINUX_R8125_DASH_H */
269 |
--------------------------------------------------------------------------------
/r8125/src/r8125_fiber.c:
--------------------------------------------------------------------------------
1 | /*
2 | ################################################################################
3 | #
4 | # r8125 is the Linux device driver released for Realtek 2.5 Gigabit Ethernet
5 | # controllers with PCI-Express interface.
6 | #
7 | # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.
8 | #
9 | # This program is free software; you can redistribute it and/or modify it
10 | # under the terms of the GNU General Public License as published by the Free
11 | # Software Foundation; either version 2 of the License, or (at your option)
12 | # any later version.
13 | #
14 | # This program is distributed in the hope that it will be useful, but WITHOUT
15 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 | # more details.
18 | #
19 | # You should have received a copy of the GNU General Public License along with
20 | # this program; if not, see .
21 | #
22 | # Author:
23 | # Realtek NIC software team
24 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
25 | #
26 | ################################################################################
27 | */
28 |
29 | /************************************************************************************
30 | * This product is covered by one or more of the following patents:
31 | * US6,570,884, US6,115,776, and US6,327,625.
32 | ***********************************************************************************/
33 |
34 | #include
35 | #include
36 | #include
37 |
38 | #include "r8125.h"
39 | #include "r8125_fiber.h"
40 |
41 | static void
42 | rtl8125_fiber_set_mdc_gpio_c45(struct rtl8125_private *tp, bool pu)
43 | {
44 | if (pu)
45 | rtl8125_set_mac_ocp_bit(tp, 0xDC52, BIT_7);
46 | else
47 | rtl8125_clear_mac_ocp_bit(tp, 0xDC52, BIT_7);
48 |
49 | //RtPciCommittp);
50 | }
51 |
52 | static void
53 | rtl8125_fiber_set_mdc(struct rtl8125_private *tp, bool pu)
54 | {
55 | rtl8125_fiber_set_mdc_gpio_c45(tp, pu);
56 | }
57 |
58 | static void
59 | rtl8125_fiber_set_mdcDownUp(struct rtl8125_private *tp)
60 | {
61 | udelay(1);
62 | rtl8125_fiber_set_mdc(tp, 0);
63 | udelay(1);
64 | rtl8125_fiber_set_mdc(tp, 1);
65 | }
66 |
67 | static void
68 | rtl8125_fiber_set_mdio_bit_gpio_c45(struct rtl8125_private *tp, bool pu)
69 | {
70 | if (pu)
71 | rtl8125_set_mac_ocp_bit(tp, 0xDC52, BIT_2);
72 | else
73 | rtl8125_clear_mac_ocp_bit(tp, 0xDC52, BIT_2);
74 |
75 | //RtPciCommittp);
76 |
77 | rtl8125_fiber_set_mdcDownUp(tp);
78 | }
79 |
80 | static void
81 | rtl8125_fiber_set_mdio_bit(struct rtl8125_private *tp, bool pu)
82 | {
83 | rtl8125_fiber_set_mdio_bit_gpio_c45(tp, pu);
84 | }
85 |
86 | static u16
87 | rtl8125_fiber_get_mdio_bit_gpio_c45(struct rtl8125_private *tp)
88 | {
89 | rtl8125_fiber_set_mdcDownUp(tp);
90 |
91 | return !!(rtl8125_mac_ocp_read(tp, 0xDC58) & BIT(2));
92 | }
93 |
94 | static u16
95 | rtl8125_fiber_get_mdio_bit(struct rtl8125_private *tp)
96 | {
97 | return rtl8125_fiber_get_mdio_bit_gpio_c45(tp);
98 | }
99 |
100 | static void
101 | rtl8125_fiber_shift_bit_in(struct rtl8125_private *tp, u32 val, int count)
102 | {
103 | int i;
104 |
105 | for (i = (count - 1); i >= 0; i--)
106 | rtl8125_fiber_set_mdio_bit(tp, !!(val & BIT(i)));
107 | }
108 |
109 | static u16
110 | rtl8125_fiber_shift_bit_out(struct rtl8125_private *tp)
111 | {
112 | u16 data = 0;
113 | int i;
114 |
115 | for (i = 15; i >= 0; i--)
116 | data += (rtl8125_fiber_get_mdio_bit(tp) << i);
117 |
118 | return data;
119 | }
120 |
121 | static void
122 | rtl8125_fiber_dir_gpio_c45(struct rtl8125_private *tp, bool output_mode)
123 | {
124 | if (output_mode)
125 | rtl8125_set_mac_ocp_bit(tp, 0xDC4C, BIT_2);
126 | else
127 | rtl8125_clear_mac_ocp_bit(tp, 0xDC4C, BIT_2);
128 | }
129 |
130 | static void
131 | rtl8125_fiber_dir(struct rtl8125_private *tp, bool output_mode)
132 | {
133 | rtl8125_fiber_dir_gpio_c45(tp, output_mode);
134 | }
135 |
136 | //fiber
137 | #define R8125_FIBER_C22 (0)
138 | #define R8125_FIBER_C45 (1)
139 |
140 | // sfp opcodes
141 | #define R8125_FIBER_ST (1)
142 | #define R8125_FIBER_OP_W (1)
143 | #define R8125_FIBER_OP_R (2)
144 | #define R8125_FIBER_TA (2)
145 |
146 | // sfp C45 opcodes
147 | #define R8125_FIBER_MDIO_C45 (BIT(15))
148 | #define R8125_FIBER_C45_ST (R8125_FIBER_MDIO_C45 | 0)
149 | #define R8125_FIBER_C45_OP_ADDR (R8125_FIBER_MDIO_C45 | 0)
150 | #define R8125_FIBER_C45_OP_W (R8125_FIBER_MDIO_C45 | 1)
151 | #define R8125_FIBER_C45_OP_R (R8125_FIBER_MDIO_C45 | 3)
152 |
153 | static void
154 | rtl8125_fiber_cmd(struct rtl8125_private *tp, u32 cmd, u8 phy_addr,
155 | u32 reg)
156 | {
157 | /* change to output mode */
158 | rtl8125_fiber_dir(tp, 1);
159 |
160 | /* preamble 32bit of 1 */
161 | rtl8125_fiber_shift_bit_in(tp, UINT_MAX, 32);
162 |
163 | /* start bit */
164 | if (cmd & R8125_FIBER_MDIO_C45)
165 | rtl8125_fiber_shift_bit_in(tp, R8125_FIBER_C45_ST, 2);
166 | else
167 | rtl8125_fiber_shift_bit_in(tp, R8125_FIBER_ST, 2);
168 |
169 | /* opcode */
170 | rtl8125_fiber_shift_bit_in(tp, cmd, 2);
171 |
172 | /* phy address */
173 | rtl8125_fiber_shift_bit_in(tp, phy_addr, 5);
174 |
175 | /* phy reg */
176 | rtl8125_fiber_shift_bit_in(tp, reg, 5);
177 | }
178 |
179 | static u8
180 | rtl8125_fiber_cmdAddr(struct rtl8125_private *tp, u8 phy_addr, u32 reg)
181 | {
182 | u8 dev_addr = (reg >> 16) & 0x1F;
183 | u16 addr = (u16)reg;
184 |
185 | rtl8125_fiber_cmd(tp, R8125_FIBER_C45_OP_ADDR, phy_addr, dev_addr);
186 |
187 | /* turn-around(TA) */
188 | rtl8125_fiber_shift_bit_in(tp, R8125_FIBER_TA, 2);
189 |
190 | rtl8125_fiber_shift_bit_in(tp, addr, 16);
191 |
192 | rtl8125_fiber_dir(tp, 0);
193 |
194 | rtl8125_fiber_get_mdio_bit(tp);
195 |
196 | return dev_addr;
197 | }
198 |
199 | static void
200 | rtl8125_fiber_reset_gpio_c45(struct rtl8125_private *tp)
201 | {
202 | rtl8125_set_mac_ocp_bit(tp, 0xDC4C, (BIT_7 | BIT_2));
203 |
204 | /* init sfp interface */
205 | rtl8125_clear_mac_ocp_bit(tp, 0xDC52, BIT_7);
206 | rtl8125_set_mac_ocp_bit(tp, 0xDC52, BIT_2);
207 | }
208 |
209 | static void
210 | rtl8125_fiber_write_common(struct rtl8125_private *tp, u16 val)
211 | {
212 | /* turn-around(TA) */
213 | rtl8125_fiber_shift_bit_in(tp, R8125_FIBER_TA, 2);
214 |
215 | /* write phy data */
216 | rtl8125_fiber_shift_bit_in(tp, val, 16);
217 |
218 | /* change to input mode */
219 | rtl8125_fiber_dir(tp, 0);
220 |
221 | rtl8125_fiber_get_mdio_bit(tp);
222 | }
223 |
224 | static void
225 | rtl8125_fiber_mdio_write_gpio_c45(
226 | struct rtl8125_private *tp,
227 | u32 reg,
228 | u16 val,
229 | u8 phy_addr)
230 | {
231 | /* opcode write */
232 | reg = rtl8125_fiber_cmdAddr(tp, phy_addr, reg);
233 | rtl8125_fiber_cmd(tp, R8125_FIBER_C45_OP_W, phy_addr, reg);
234 |
235 | rtl8125_fiber_write_common(tp, val);
236 | }
237 |
238 | static u16
239 | rtl8125_fiber_read_common(struct rtl8125_private *tp)
240 | {
241 | u16 data = 0;
242 |
243 | /* change to input mode */
244 | rtl8125_fiber_dir(tp, 0);
245 |
246 | /* TA 0 */
247 | rtl8125_fiber_get_mdio_bit(tp);
248 |
249 | /* read phy data */
250 | data = rtl8125_fiber_shift_bit_out(tp);
251 |
252 | rtl8125_fiber_get_mdio_bit(tp);
253 |
254 | return data;
255 | }
256 |
257 | static u16
258 | rtl8125_fiber_mdio_read_gpio_c45(
259 | struct rtl8125_private *tp,
260 | u32 reg,
261 | u8 phy_addr)
262 | {
263 | reg = rtl8125_fiber_cmdAddr(tp, phy_addr, reg);
264 | rtl8125_fiber_cmd(tp, R8125_FIBER_C45_OP_R, phy_addr, reg);
265 |
266 | return rtl8125_fiber_read_common(tp);
267 | }
268 |
269 | void
270 | rtl8125_fiber_mdio_write(
271 | struct rtl8125_private *tp,
272 | u32 reg,
273 | u16 val)
274 | {
275 | switch(tp->HwFiberStat) {
276 | case FIBER_STAT_CONNECT_GPO_C45:
277 | return rtl8125_fiber_mdio_write_gpio_c45(tp, reg, val, 0);
278 | default:
279 | return;
280 | }
281 | }
282 |
283 | u16
284 | rtl8125_fiber_mdio_read(
285 | struct rtl8125_private *tp,
286 | u32 reg)
287 | {
288 | switch(tp->HwFiberStat) {
289 | case FIBER_STAT_CONNECT_GPO_C45:
290 | return rtl8125_fiber_mdio_read_gpio_c45(tp, reg, 0);
291 | default:
292 | return 0xffff;
293 | }
294 | }
295 |
296 | static void
297 | rtl8125_fiber_clear_and_set_phy_bit(struct rtl8125_private *tp, u32 addr, u16 clearmask, u16 setmask)
298 | {
299 | u16 PhyRegValue;
300 |
301 | PhyRegValue = rtl8125_fiber_mdio_read(tp, addr);
302 | PhyRegValue &= ~clearmask;
303 | PhyRegValue |= setmask;
304 | rtl8125_fiber_mdio_write(tp, addr, PhyRegValue);
305 | }
306 |
307 | static void
308 | rtl8125_fiber_clear_phy_bit(struct rtl8125_private *tp, u32 addr, u16 mask)
309 | {
310 | rtl8125_fiber_clear_and_set_phy_bit(tp, addr, mask, 0);
311 | }
312 |
313 | static void
314 | rtl8125_fiber_set_phy_bit(struct rtl8125_private *tp, u32 addr, u16 mask)
315 | {
316 | rtl8125_fiber_clear_and_set_phy_bit(tp, addr, 0, mask);
317 | }
318 |
319 | #define R8125_MAKE_C45_ADDR(_mmd, _addr) (_mmd << 16 | _addr)
320 |
321 | static void
322 | rtl8125_fiber_phy_reset_8221d(struct rtl8125_private *tp)
323 | {
324 | u16 PhyRegValue;
325 | u32 Timeout;
326 |
327 | rtl8125_fiber_set_phy_bit(tp, R8125_MAKE_C45_ADDR(0x01, 0x00), BIT_15);
328 |
329 | Timeout = 0;
330 | do {
331 | udelay(1000);
332 |
333 | PhyRegValue = rtl8125_fiber_mdio_read(tp, R8125_MAKE_C45_ADDR(0x01, 0x00));
334 |
335 | Timeout++;
336 | } while ((PhyRegValue & BIT_15) && (Timeout < 20));
337 | }
338 |
339 | static void
340 | rtl8125_fiber_phy_reset(struct rtl8125_private *tp)
341 | {
342 | switch (tp->HwFiberModeVer) {
343 | case FIBER_MODE_RTL8125D_RTL8221D:
344 | rtl8125_fiber_phy_reset_8221d(tp);
345 | break;
346 | }
347 | }
348 |
349 | static void
350 | rtl8125_hw_rtl8221d_phy_config(struct rtl8125_private *tp)
351 | {
352 | rtl8125_fiber_reset_gpio_c45(tp);
353 |
354 | rtl8125_fiber_clear_phy_bit(tp, R8125_MAKE_C45_ADDR(30, 0x75F3), BIT_0);
355 | rtl8125_fiber_clear_and_set_phy_bit(tp,
356 | R8125_MAKE_C45_ADDR(30, 0x697A),
357 | 0x003F,
358 | 0x0002);
359 |
360 |
361 | rtl8125_fiber_clear_phy_bit(tp, R8125_MAKE_C45_ADDR(0x07, 0x3C), (BIT_2 | BIT_1));
362 | rtl8125_fiber_clear_phy_bit(tp, R8125_MAKE_C45_ADDR(0x07, 0x3E), (BIT_1 | BIT_0));
363 |
364 |
365 | rtl8125_fiber_phy_reset(tp);
366 | }
367 |
368 | void
369 | rtl8125_hw_fiber_phy_config(struct rtl8125_private *tp)
370 | {
371 | switch (tp->HwFiberModeVer) {
372 | case FIBER_MODE_RTL8125D_RTL8221D:
373 | rtl8125_hw_rtl8221d_phy_config(tp);
374 | break;
375 | }
376 | }
377 |
378 | #define RTL8221D_PHY_ID_1 0x001C
379 | #define RTL8221D_PHY_ID_2 0xC849
380 | static u32
381 | rtl8125_fiber_get_connect_status_8221d(struct rtl8125_private *tp)
382 | {
383 | int i;
384 | int const checkcnt = 4;
385 |
386 | rtl8125_fiber_reset_gpio_c45(tp);
387 |
388 | for (i = 0; i < checkcnt; i++) {
389 | if (RTL8221D_PHY_ID_1 != rtl8125_fiber_mdio_read_gpio_c45(tp, R8125_MAKE_C45_ADDR(0x01, 0x02), 0) ||
390 | RTL8221D_PHY_ID_2 != rtl8125_fiber_mdio_read_gpio_c45(tp, R8125_MAKE_C45_ADDR(0x01, 0x03), 0))
391 | return FIBER_STAT_DISCONNECT;
392 | }
393 |
394 | return FIBER_STAT_CONNECT_GPO_C45;
395 | }
396 |
397 | static u32
398 | rtl8125_fiber_get_connect_status(struct rtl8125_private *tp)
399 | {
400 | switch (tp->HwFiberModeVer) {
401 | case FIBER_MODE_RTL8125D_RTL8221D:
402 | return rtl8125_fiber_get_connect_status_8221d(tp);
403 | default:
404 | return FIBER_STAT_NOT_CHECKED;
405 | }
406 | }
407 |
408 | void
409 | rtl8125_check_fiber_mode_support(struct rtl8125_private *tp)
410 | {
411 | switch(tp->mcfg) {
412 | case CFG_METHOD_10:
413 | case CFG_METHOD_11: {
414 | u8 tmp = (u8)rtl8125_mac_ocp_read(tp, 0xD006);
415 | if (tmp == 0x03)
416 | tp->HwFiberModeVer = FIBER_MODE_RTL8125D_RTL8221D;
417 | }
418 | break;
419 | }
420 |
421 | if (HW_FIBER_MODE_ENABLED(tp))
422 | tp->HwFiberStat = rtl8125_fiber_get_connect_status(tp);
423 | }
424 |
425 | unsigned int
426 | rtl8125_fiber_link_ok(struct net_device *dev)
427 | {
428 | struct rtl8125_private *tp = netdev_priv(dev);
429 | u16 status;
430 |
431 | switch (tp->HwFiberStat) {
432 | case FIBER_STAT_CONNECT_GPO_C45:
433 | status = rtl8125_fiber_mdio_read(tp, R8125_MAKE_C45_ADDR(30, 0x758D));
434 | if (status != USHRT_MAX && status & BIT_1)
435 | return 1;
436 | else
437 | return 0;
438 | break;
439 | default:
440 | return 0;
441 | }
442 | }
443 |
--------------------------------------------------------------------------------
/r8125/src/r8125_fiber.h:
--------------------------------------------------------------------------------
1 | /* SPDX-License-Identifier: GPL-2.0-only */
2 | /*
3 | ################################################################################
4 | #
5 | # r8125 is the Linux device driver released for Realtek 2.5 Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.
9 | #
10 | # This program is free software; you can redistribute it and/or modify it
11 | # under the terms of the GNU General Public License as published by the Free
12 | # Software Foundation; either version 2 of the License, or (at your option)
13 | # any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful, but WITHOUT
16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 | # more details.
19 | #
20 | # You should have received a copy of the GNU General Public License along with
21 | # this program; if not, see .
22 | #
23 | # Author:
24 | # Realtek NIC software team
25 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
26 | #
27 | ################################################################################
28 | */
29 |
30 | /************************************************************************************
31 | * This product is covered by one or more of the following patents:
32 | * US6,570,884, US6,115,776, and US6,327,625.
33 | ***********************************************************************************/
34 |
35 | #ifndef _LINUX_R8125_FIBER_H
36 | #define _LINUX_R8125_FIBER_H
37 |
38 | enum {
39 | FIBER_MODE_NIC_ONLY = 0,
40 | FIBER_MODE_RTL8125D_RTL8221D,
41 | FIBER_MODE_MAX
42 | };
43 |
44 | enum {
45 | FIBER_STAT_NOT_CHECKED = 0,
46 | FIBER_STAT_DISCONNECT,
47 | FIBER_STAT_CONNECT_GPO_C45,
48 | FIBER_STAT_MAX
49 | };
50 |
51 | #define HW_FIBER_MODE_ENABLED(_M) ((_M)->HwFiberModeVer > 0)
52 | #define HW_FIBER_STATUS_CONNECTED(_M) (((_M)->HwFiberStat == FIBER_STAT_CONNECT_GPO_C45))
53 | #define HW_FIBER_STATUS_DISCONNECTED(_M) ((_M)->HwFiberStat == FIBER_STAT_DISCONNECT)
54 |
55 | struct rtl8125_private;
56 |
57 | void rtl8125_hw_fiber_phy_config(struct rtl8125_private *tp);
58 | void rtl8125_check_fiber_mode_support(struct rtl8125_private *tp);
59 | void rtl8125_fiber_mdio_write( struct rtl8125_private *tp, u32 reg, u16 val);
60 | u16 rtl8125_fiber_mdio_read(struct rtl8125_private *tp, u32 reg);
61 | unsigned int rtl8125_fiber_link_ok(struct net_device *dev);
62 |
63 | #endif /* _LINUX_R8125_FIBER_H */
64 |
--------------------------------------------------------------------------------
/r8125/src/r8125_firmware.c:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-2.0-only
2 | /*
3 | ################################################################################
4 | #
5 | # r8125 is the Linux device driver released for Realtek 2.5 Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.
9 | #
10 | # This program is free software; you can redistribute it and/or modify it
11 | # under the terms of the GNU General Public License as published by the Free
12 | # Software Foundation; either version 2 of the License, or (at your option)
13 | # any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful, but WITHOUT
16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 | # more details.
19 | #
20 | # You should have received a copy of the GNU General Public License along with
21 | # this program; if not, see .
22 | #
23 | # Author:
24 | # Realtek NIC software team
25 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
26 | #
27 | ################################################################################
28 | */
29 |
30 | /************************************************************************************
31 | * This product is covered by one or more of the following patents:
32 | * US6,570,884, US6,115,776, and US6,327,625.
33 | ***********************************************************************************/
34 |
35 | #include
36 | #include
37 | #include
38 |
39 | #include "r8125_firmware.h"
40 |
41 | enum rtl_fw_opcode {
42 | PHY_READ = 0x0,
43 | PHY_DATA_OR = 0x1,
44 | PHY_DATA_AND = 0x2,
45 | PHY_BJMPN = 0x3,
46 | PHY_MDIO_CHG = 0x4,
47 | PHY_CLEAR_READCOUNT = 0x7,
48 | PHY_WRITE = 0x8,
49 | PHY_READCOUNT_EQ_SKIP = 0x9,
50 | PHY_COMP_EQ_SKIPN = 0xa,
51 | PHY_COMP_NEQ_SKIPN = 0xb,
52 | PHY_WRITE_PREVIOUS = 0xc,
53 | PHY_SKIPN = 0xd,
54 | PHY_DELAY_MS = 0xe,
55 | };
56 |
57 | struct fw_info {
58 | u32 magic;
59 | char version[RTL8125_VER_SIZE];
60 | __le32 fw_start;
61 | __le32 fw_len;
62 | u8 chksum;
63 | } __packed;
64 |
65 | #if LINUX_VERSION_CODE < KERNEL_VERSION(4,16,0)
66 | #define sizeof_field(TYPE, MEMBER) sizeof((((TYPE *)0)->MEMBER))
67 | #endif
68 | #define FW_OPCODE_SIZE sizeof_field(struct rtl8125_fw_phy_action, code[0])
69 |
70 | static bool rtl8125_fw_format_ok(struct rtl8125_fw *rtl_fw)
71 | {
72 | const struct firmware *fw = rtl_fw->fw;
73 | struct fw_info *fw_info = (struct fw_info *)fw->data;
74 | struct rtl8125_fw_phy_action *pa = &rtl_fw->phy_action;
75 |
76 | if (fw->size < FW_OPCODE_SIZE)
77 | return false;
78 |
79 | if (!fw_info->magic) {
80 | size_t i, size, start;
81 | u8 checksum = 0;
82 |
83 | if (fw->size < sizeof(*fw_info))
84 | return false;
85 |
86 | for (i = 0; i < fw->size; i++)
87 | checksum += fw->data[i];
88 | if (checksum != 0)
89 | return false;
90 |
91 | start = le32_to_cpu(fw_info->fw_start);
92 | if (start > fw->size)
93 | return false;
94 |
95 | size = le32_to_cpu(fw_info->fw_len);
96 | if (size > (fw->size - start) / FW_OPCODE_SIZE)
97 | return false;
98 |
99 | strscpy(rtl_fw->version, fw_info->version, RTL8125_VER_SIZE);
100 |
101 | pa->code = (__le32 *)(fw->data + start);
102 | pa->size = size;
103 | } else {
104 | if (fw->size % FW_OPCODE_SIZE)
105 | return false;
106 |
107 | strscpy(rtl_fw->version, rtl_fw->fw_name, RTL8125_VER_SIZE);
108 |
109 | pa->code = (__le32 *)fw->data;
110 | pa->size = fw->size / FW_OPCODE_SIZE;
111 | }
112 |
113 | return true;
114 | }
115 |
116 | static bool rtl8125_fw_data_ok(struct rtl8125_fw *rtl_fw)
117 | {
118 | struct rtl8125_fw_phy_action *pa = &rtl_fw->phy_action;
119 | size_t index;
120 |
121 | for (index = 0; index < pa->size; index++) {
122 | u32 action = le32_to_cpu(pa->code[index]);
123 | u32 val = action & 0x0000ffff;
124 | u32 regno = (action & 0x0fff0000) >> 16;
125 |
126 | switch (action >> 28) {
127 | case PHY_READ:
128 | case PHY_DATA_OR:
129 | case PHY_DATA_AND:
130 | case PHY_CLEAR_READCOUNT:
131 | case PHY_WRITE:
132 | case PHY_WRITE_PREVIOUS:
133 | case PHY_DELAY_MS:
134 | break;
135 |
136 | case PHY_MDIO_CHG:
137 | if (val > 1)
138 | goto out;
139 | break;
140 |
141 | case PHY_BJMPN:
142 | if (regno > index)
143 | goto out;
144 | break;
145 | case PHY_READCOUNT_EQ_SKIP:
146 | if (index + 2 >= pa->size)
147 | goto out;
148 | break;
149 | case PHY_COMP_EQ_SKIPN:
150 | case PHY_COMP_NEQ_SKIPN:
151 | case PHY_SKIPN:
152 | if (index + 1 + regno >= pa->size)
153 | goto out;
154 | break;
155 |
156 | default:
157 | dev_err(rtl_fw->dev, "Invalid action 0x%08x\n", action);
158 | return false;
159 | }
160 | }
161 |
162 | return true;
163 | out:
164 | dev_err(rtl_fw->dev, "Out of range of firmware\n");
165 | return false;
166 | }
167 |
168 | void rtl8125_fw_write_firmware(struct rtl8125_private *tp, struct rtl8125_fw *rtl_fw)
169 | {
170 | struct rtl8125_fw_phy_action *pa = &rtl_fw->phy_action;
171 | rtl8125_fw_write_t fw_write = rtl_fw->phy_write;
172 | rtl8125_fw_read_t fw_read = rtl_fw->phy_read;
173 | int predata = 0, count = 0;
174 | size_t index;
175 |
176 | for (index = 0; index < pa->size; index++) {
177 | u32 action = le32_to_cpu(pa->code[index]);
178 | u32 data = action & 0x0000ffff;
179 | u32 regno = (action & 0x0fff0000) >> 16;
180 | enum rtl_fw_opcode opcode = action >> 28;
181 |
182 | if (!action)
183 | break;
184 |
185 | switch (opcode) {
186 | case PHY_READ:
187 | predata = fw_read(tp, regno);
188 | count++;
189 | break;
190 | case PHY_DATA_OR:
191 | predata |= data;
192 | break;
193 | case PHY_DATA_AND:
194 | predata &= data;
195 | break;
196 | case PHY_BJMPN:
197 | index -= (regno + 1);
198 | break;
199 | case PHY_MDIO_CHG:
200 | if (data) {
201 | fw_write = rtl_fw->mac_mcu_write;
202 | fw_read = rtl_fw->mac_mcu_read;
203 | } else {
204 | fw_write = rtl_fw->phy_write;
205 | fw_read = rtl_fw->phy_read;
206 | }
207 |
208 | break;
209 | case PHY_CLEAR_READCOUNT:
210 | count = 0;
211 | break;
212 | case PHY_WRITE:
213 | fw_write(tp, regno, data);
214 | break;
215 | case PHY_READCOUNT_EQ_SKIP:
216 | if (count == data)
217 | index++;
218 | break;
219 | case PHY_COMP_EQ_SKIPN:
220 | if (predata == data)
221 | index += regno;
222 | break;
223 | case PHY_COMP_NEQ_SKIPN:
224 | if (predata != data)
225 | index += regno;
226 | break;
227 | case PHY_WRITE_PREVIOUS:
228 | fw_write(tp, regno, predata);
229 | break;
230 | case PHY_SKIPN:
231 | index += regno;
232 | break;
233 | case PHY_DELAY_MS:
234 | fsleep(1000 * data);
235 | break;
236 | }
237 | }
238 | }
239 |
240 | void rtl8125_fw_release_firmware(struct rtl8125_fw *rtl_fw)
241 | {
242 | release_firmware(rtl_fw->fw);
243 | }
244 |
245 | int rtl8125_fw_request_firmware(struct rtl8125_fw *rtl_fw)
246 | {
247 | int rc;
248 |
249 | rc = request_firmware(&rtl_fw->fw, rtl_fw->fw_name, rtl_fw->dev);
250 | if (rc < 0)
251 | goto out;
252 |
253 | if (!rtl8125_fw_format_ok(rtl_fw) || !rtl8125_fw_data_ok(rtl_fw)) {
254 | release_firmware(rtl_fw->fw);
255 | rc = -EINVAL;
256 | goto out;
257 | }
258 |
259 | return 0;
260 | out:
261 | dev_err(rtl_fw->dev, "Unable to load firmware %s (%d)\n",
262 | rtl_fw->fw_name, rc);
263 | return rc;
264 | }
265 |
--------------------------------------------------------------------------------
/r8125/src/r8125_firmware.h:
--------------------------------------------------------------------------------
1 | /* SPDX-License-Identifier: GPL-2.0-only */
2 | /*
3 | ################################################################################
4 | #
5 | # r8125 is the Linux device driver released for Realtek 2.5 Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.
9 | #
10 | # This program is free software; you can redistribute it and/or modify it
11 | # under the terms of the GNU General Public License as published by the Free
12 | # Software Foundation; either version 2 of the License, or (at your option)
13 | # any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful, but WITHOUT
16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 | # more details.
19 | #
20 | # You should have received a copy of the GNU General Public License along with
21 | # this program; if not, see .
22 | #
23 | # Author:
24 | # Realtek NIC software team
25 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
26 | #
27 | ################################################################################
28 | */
29 |
30 | /************************************************************************************
31 | * This product is covered by one or more of the following patents:
32 | * US6,570,884, US6,115,776, and US6,327,625.
33 | ***********************************************************************************/
34 |
35 | #ifndef _LINUX_rtl8125_FIRMWARE_H
36 | #define _LINUX_rtl8125_FIRMWARE_H
37 |
38 | #include
39 | #include
40 |
41 | struct rtl8125_private;
42 | typedef void (*rtl8125_fw_write_t)(struct rtl8125_private *tp, u16 reg, u16 val);
43 | typedef u32 (*rtl8125_fw_read_t)(struct rtl8125_private *tp, u16 reg);
44 |
45 | #define RTL8125_VER_SIZE 32
46 |
47 | struct rtl8125_fw {
48 | rtl8125_fw_write_t phy_write;
49 | rtl8125_fw_read_t phy_read;
50 | rtl8125_fw_write_t mac_mcu_write;
51 | rtl8125_fw_read_t mac_mcu_read;
52 | const struct firmware *fw;
53 | const char *fw_name;
54 | struct device *dev;
55 |
56 | char version[RTL8125_VER_SIZE];
57 |
58 | struct rtl8125_fw_phy_action {
59 | __le32 *code;
60 | size_t size;
61 | } phy_action;
62 | };
63 |
64 | int rtl8125_fw_request_firmware(struct rtl8125_fw *rtl_fw);
65 | void rtl8125_fw_release_firmware(struct rtl8125_fw *rtl_fw);
66 | void rtl8125_fw_write_firmware(struct rtl8125_private *tp, struct rtl8125_fw *rtl_fw);
67 |
68 | #endif /* _LINUX_rtl8125_FIRMWARE_H */
69 |
--------------------------------------------------------------------------------
/r8125/src/r8125_ptp.c:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-2.0-only
2 | /*
3 | ################################################################################
4 | #
5 | # r8125 is the Linux device driver released for Realtek 2.5 Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.
9 | #
10 | # This program is free software; you can redistribute it and/or modify it
11 | # under the terms of the GNU General Public License as published by the Free
12 | # Software Foundation; either version 2 of the License, or (at your option)
13 | # any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful, but WITHOUT
16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 | # more details.
19 | #
20 | # You should have received a copy of the GNU General Public License along with
21 | # this program; if not, see .
22 | #
23 | # Author:
24 | # Realtek NIC software team
25 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
26 | #
27 | ################################################################################
28 | */
29 |
30 | /************************************************************************************
31 | * This product is covered by one or more of the following patents:
32 | * US6,570,884, US6,115,776, and US6,327,625.
33 | ***********************************************************************************/
34 |
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include
44 |
45 | #include "r8125.h"
46 | #include "r8125_ptp.h"
47 |
48 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0)
49 | static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64)
50 | {
51 | return *(const struct timespec *)&ts64;
52 | }
53 |
54 | static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
55 | {
56 | return *(const struct timespec64 *)&ts;
57 | }
58 | #endif
59 |
60 | static int _rtl8125_phc_gettime(struct rtl8125_private *tp, struct timespec64 *ts64)
61 | {
62 | //get local time
63 | RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_LATCHED_LOCAL_TIME | PTP_EXEC_CMD));
64 |
65 | /* nanoseconds */
66 | //0x6808[29:0]
67 | ts64->tv_nsec = (RTL_R32(tp, PTP_SOFT_CONFIG_Time_NS_8125) & 0x3fffffff);
68 |
69 | /* seconds */
70 | //0x680C[47:0]
71 | ts64->tv_sec = RTL_R16(tp, PTP_SOFT_CONFIG_Time_S_8125 + 4);
72 | ts64->tv_sec <<= 32;
73 | ts64->tv_sec |= RTL_R32(tp, PTP_SOFT_CONFIG_Time_S_8125);
74 |
75 | return 0;
76 | }
77 |
78 | static int _rtl8125_phc_settime(struct rtl8125_private *tp, const struct timespec64 *ts64)
79 | {
80 | /* nanoseconds */
81 | //0x6808[29:0]
82 | RTL_W32(tp, PTP_SOFT_CONFIG_Time_NS_8125, (ts64->tv_nsec & 0x3fffffff));
83 |
84 | /* seconds */
85 | //0x680C[47:0]
86 | RTL_W32(tp, PTP_SOFT_CONFIG_Time_S_8125, ts64->tv_sec);
87 | RTL_W16(tp, PTP_SOFT_CONFIG_Time_S_8125 + 4, (ts64->tv_sec >> 32));
88 |
89 | //set local time
90 | RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_SET_LOCAL_TIME | PTP_EXEC_CMD));
91 |
92 | return 0;
93 | }
94 |
95 | static int _rtl8125_phc_adjtime(struct rtl8125_private *tp, s64 delta)
96 | {
97 | struct timespec64 d;
98 | bool negative = false;
99 | u64 tohw;
100 | u32 nsec;
101 | u64 sec;
102 |
103 | if (delta < 0) {
104 | negative = true;
105 | tohw = -delta;
106 | } else {
107 | tohw = delta;
108 | }
109 |
110 | d = ns_to_timespec64(tohw);
111 |
112 | nsec = d.tv_nsec;
113 | sec = d.tv_sec;
114 |
115 | if (negative) {
116 | nsec = -nsec;
117 | sec = -sec;
118 | }
119 |
120 | nsec &= 0x3fffffff;
121 | sec &= 0x0000ffffffffffff;
122 |
123 | if (negative) {
124 | nsec |= PTP_SOFT_CONFIG_TIME_NS_NEGATIVE;
125 | sec |= PTP_SOFT_CONFIG_TIME_S_NEGATIVE;
126 | }
127 |
128 | /* nanoseconds */
129 | //0x6808[29:0]
130 | RTL_W32(tp, PTP_SOFT_CONFIG_Time_NS_8125, nsec);
131 |
132 | /* seconds */
133 | //0x680C[47:0]
134 | RTL_W32(tp, PTP_SOFT_CONFIG_Time_S_8125, sec);
135 | RTL_W16(tp, PTP_SOFT_CONFIG_Time_S_8125 + 4, (sec >> 32));
136 |
137 | //adjust local time
138 | //RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_DRIFT_LOCAL_TIME | PTP_EXEC_CMD));
139 | RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_SET_LOCAL_TIME | PTP_EXEC_CMD));
140 |
141 | return 0;
142 | }
143 |
144 | static int rtl8125_phc_adjtime(struct ptp_clock_info *ptp, s64 delta)
145 | {
146 | struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
147 | int ret;
148 |
149 | //netif_info(tp, drv, tp->dev, "phc adjust time\n");
150 |
151 | rtnl_lock();
152 | ret = _rtl8125_phc_adjtime(tp, delta);
153 | rtnl_unlock();
154 |
155 | return ret;
156 | }
157 |
158 | /*
159 | 1ppm means every 125MHz plus 125Hz. It also means every 8ns minus 8ns*10^(-6)
160 |
161 | 1ns=2^30 sub_ns
162 |
163 | 8ns*10^(-6) = 8 * 2^30 sub_ns * 10^(-6) = 2^33 sub_ns * 10^(-6) = 8590 = 0x218E sub_ns
164 |
165 | 1ppb means every 125MHz plus 0.125Hz. It also means every 8ns minus 8ns*10^(-9)
166 |
167 | 1ns=2^30 sub_ns
168 |
169 | 8ns*10^(-9) = 8 * 2^30 sub_ns * 10^(-9) = 2^33 sub_ns * 10^(-9) = 8.59 sub_ns = 9 sub_ns
170 | */
171 | static int _rtl8125_phc_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
172 | {
173 | struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
174 | bool negative = false;
175 | u32 sub_ns;
176 |
177 | if (ppb < 0) {
178 | negative = true;
179 | ppb = -ppb;
180 | }
181 |
182 | sub_ns = ppb * 9;
183 | if (negative) {
184 | sub_ns = -sub_ns;
185 | sub_ns &= 0x3fffffff;
186 | sub_ns |= PTP_ADJUST_TIME_NS_NEGATIVE;
187 | } else
188 | sub_ns &= 0x3fffffff;
189 |
190 | /* nanoseconds */
191 | //0x6808[29:0]
192 | RTL_W32(tp, PTP_SOFT_CONFIG_Time_NS_8125, sub_ns);
193 |
194 | //adjust local time
195 | RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_DRIFT_LOCAL_TIME | PTP_EXEC_CMD));
196 | //RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_SET_LOCAL_TIME | PTP_EXEC_CMD));
197 |
198 | return 0;
199 | }
200 |
201 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(6,2,0)
202 | static int rtl8125_ptp_adjfine(struct ptp_clock_info *ptp, long scaled_ppm)
203 | {
204 | s32 ppb = scaled_ppm_to_ppb(scaled_ppm);
205 |
206 | if (ppb > ptp->max_adj || ppb < -ptp->max_adj)
207 | return -EINVAL;
208 |
209 | rtnl_lock();
210 | _rtl8125_phc_adjfreq(ptp, ppb);
211 | rtnl_unlock();
212 |
213 | return 0;
214 | }
215 | #else
216 | static int rtl8125_phc_adjfreq(struct ptp_clock_info *ptp, s32 delta)
217 | {
218 | //struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
219 |
220 | //netif_info(tp, drv, tp->dev, "phc adjust freq\n");
221 |
222 | if (delta > ptp->max_adj || delta < -ptp->max_adj)
223 | return -EINVAL;
224 |
225 | rtnl_lock();
226 | _rtl8125_phc_adjfreq(ptp, delta);
227 | rtnl_unlock();
228 |
229 | return 0;
230 | }
231 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(6,2,0) */
232 |
233 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,0,0)
234 | static int rtl8125_phc_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts64,
235 | struct ptp_system_timestamp *sts)
236 | {
237 | struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
238 | int ret;
239 |
240 | //netif_info(tp, drv, tp->dev, "phc get ts\n");
241 |
242 | rtnl_lock();
243 | ptp_read_system_prets(sts);
244 | ret = _rtl8125_phc_gettime(tp, ts64);
245 | ptp_read_system_postts(sts);
246 | rtnl_unlock();
247 |
248 | return ret;
249 | }
250 | #else
251 | static int rtl8125_phc_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts64)
252 | {
253 | struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
254 | int ret;
255 |
256 | //netif_info(tp, drv, tp->dev, "phc get ts\n");
257 |
258 | rtnl_lock();
259 | ret = _rtl8125_phc_gettime(tp, ts64);
260 | rtnl_unlock();
261 |
262 | return ret;
263 | }
264 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(5,0,0) */
265 |
266 | static int rtl8125_phc_settime(struct ptp_clock_info *ptp,
267 | const struct timespec64 *ts64)
268 | {
269 | struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
270 | int ret;
271 |
272 | //netif_info(tp, drv, tp->dev, "phc set ts\n");
273 |
274 | rtnl_lock();
275 | ret = _rtl8125_phc_settime(tp, ts64);
276 | rtnl_unlock();
277 |
278 | return ret;
279 | }
280 |
281 | static int rtl8125_phc_enable(struct ptp_clock_info *ptp,
282 | struct ptp_clock_request *rq, int on)
283 | {
284 | struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
285 | u16 ptp_ctrl;
286 |
287 | //netif_info(tp, drv, tp->dev, "phc enable type %x on %d\n", rq->type, on);
288 |
289 | switch (rq->type) {
290 | case PTP_CLK_REQ_PPS:
291 | rtnl_lock();
292 | ptp_ctrl = RTL_R16(tp, PTP_CTRL_8125);
293 | ptp_ctrl &= ~BIT_15;
294 | if (on)
295 | ptp_ctrl |= BIT_14;
296 | else
297 | ptp_ctrl &= ~BIT_14;
298 | RTL_W16(tp, PTP_CTRL_8125, ptp_ctrl);
299 | rtnl_unlock();
300 | return 0;
301 | default:
302 | return -EOPNOTSUPP;
303 | }
304 | }
305 |
306 | int rtl8125_get_ts_info(struct net_device *netdev,
307 | struct ethtool_ts_info *info)
308 | {
309 | struct rtl8125_private *tp = netdev_priv(netdev);
310 |
311 | /* we always support timestamping disabled */
312 | info->rx_filters = BIT(HWTSTAMP_FILTER_NONE);
313 |
314 | if (tp->HwSuppPtpVer == 0)
315 | return ethtool_op_get_ts_info(netdev, info);
316 |
317 | info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
318 | SOF_TIMESTAMPING_RX_SOFTWARE |
319 | SOF_TIMESTAMPING_SOFTWARE |
320 | SOF_TIMESTAMPING_TX_HARDWARE |
321 | SOF_TIMESTAMPING_RX_HARDWARE |
322 | SOF_TIMESTAMPING_RAW_HARDWARE;
323 |
324 | if (tp->ptp_clock)
325 | info->phc_index = ptp_clock_index(tp->ptp_clock);
326 | else
327 | info->phc_index = -1;
328 |
329 | info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
330 |
331 | info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
332 | BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
333 | BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
334 | BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
335 | BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
336 | BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
337 | BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
338 |
339 | return 0;
340 | }
341 |
342 | static const struct ptp_clock_info rtl_ptp_clock_info = {
343 | .owner = THIS_MODULE,
344 | .n_alarm = 0,
345 | .n_ext_ts = 0,
346 | .n_per_out = 0,
347 | .n_pins = 0,
348 | .pps = 1,
349 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(6,2,0)
350 | .adjfine = rtl8125_ptp_adjfine,
351 | #else
352 | .adjfreq = rtl8125_phc_adjfreq,
353 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(6,2,0) */
354 | .adjtime = rtl8125_phc_adjtime,
355 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,0,0)
356 | .gettimex64 = rtl8125_phc_gettime,
357 | #else
358 | .gettime64 = rtl8125_phc_gettime,
359 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(5,0,0) */
360 | .settime64 = rtl8125_phc_settime,
361 | .enable = rtl8125_phc_enable,
362 | };
363 |
364 | static int rtl8125_ptp_egresstime(struct rtl8125_private *tp, struct timespec64 *ts64, u32 regnum)
365 | {
366 | /* nanoseconds */
367 | //[29:0]
368 | ts64->tv_nsec = rtl8125_mac_ocp_read(tp, PTP_EGRESS_TIME_BASE_NS_8125 + regnum * 16 + 2);
369 | ts64->tv_nsec <<= 16;
370 | ts64->tv_nsec |= rtl8125_mac_ocp_read(tp, PTP_EGRESS_TIME_BASE_NS_8125 + regnum * 16);
371 | ts64->tv_nsec &= 0x3fffffff;
372 |
373 | /* seconds */
374 | //[47:0]
375 | ts64->tv_sec = rtl8125_mac_ocp_read(tp, PTP_EGRESS_TIME_BASE_S_8125 + regnum * 16 + 4);
376 | ts64->tv_sec <<= 16;
377 | ts64->tv_sec |= rtl8125_mac_ocp_read(tp, PTP_EGRESS_TIME_BASE_S_8125 + regnum * 16 + 2);
378 | ts64->tv_sec <<= 16;
379 | ts64->tv_sec |= rtl8125_mac_ocp_read(tp, PTP_EGRESS_TIME_BASE_S_8125 + regnum * 16);
380 | ts64->tv_sec &= 0x0000ffffffffffff;
381 |
382 | return 0;
383 | }
384 |
385 | static void rtl8125_ptp_tx_hwtstamp(struct rtl8125_private *tp)
386 | {
387 | struct sk_buff *skb = tp->ptp_tx_skb;
388 | struct skb_shared_hwtstamps shhwtstamps = {0};
389 | struct timespec64 ts64;
390 | u32 regnum;
391 |
392 | RTL_W8(tp, PTP_ISR_8125, PTP_ISR_TOK | PTP_ISR_TER);
393 |
394 | //IO 0x2302 bit 10~11 WR_PTR
395 | regnum = RTL_R16(tp, 0x2032) & 0x0C00;
396 | regnum >>= 10;
397 | regnum = (regnum + 3) % 4;
398 |
399 | rtnl_lock();
400 | rtl8125_ptp_egresstime(tp, &ts64, regnum);
401 | rtnl_unlock();
402 |
403 | /* Upper 32 bits contain s, lower 32 bits contain ns. */
404 | shhwtstamps.hwtstamp = ktime_set(ts64.tv_sec,
405 | ts64.tv_nsec);
406 |
407 | /* Clear the lock early before calling skb_tstamp_tx so that
408 | * applications are not woken up before the lock bit is clear. We use
409 | * a copy of the skb pointer to ensure other threads can't change it
410 | * while we're notifying the stack.
411 | */
412 | tp->ptp_tx_skb = NULL;
413 | clear_bit_unlock(__RTL8125_PTP_TX_IN_PROGRESS, &tp->state);
414 |
415 | /* Notify the stack and free the skb after we've unlocked */
416 | skb_tstamp_tx(skb, &shhwtstamps);
417 | dev_kfree_skb_any(skb);
418 | }
419 |
420 | #define RTL8125_PTP_TX_TIMEOUT (HZ * 15)
421 | static void rtl8125_ptp_tx_work(struct work_struct *work)
422 | {
423 | struct rtl8125_private *tp = container_of(work, struct rtl8125_private,
424 | ptp_tx_work);
425 |
426 | if (!tp->ptp_tx_skb)
427 | return;
428 |
429 | if (time_is_before_jiffies(tp->ptp_tx_start +
430 | RTL8125_PTP_TX_TIMEOUT)) {
431 | dev_kfree_skb_any(tp->ptp_tx_skb);
432 | tp->ptp_tx_skb = NULL;
433 | clear_bit_unlock(__RTL8125_PTP_TX_IN_PROGRESS, &tp->state);
434 | tp->tx_hwtstamp_timeouts++;
435 | /* Clear the tx valid bit in TSYNCTXCTL register to enable
436 | * interrupt
437 | */
438 | RTL_W8(tp, PTP_ISR_8125, PTP_ISR_TOK | PTP_ISR_TER);
439 | return;
440 | }
441 |
442 | if (RTL_R8(tp, PTP_ISR_8125) & (PTP_ISR_TOK))
443 | rtl8125_ptp_tx_hwtstamp(tp);
444 | else
445 | /* reschedule to check later */
446 | schedule_work(&tp->ptp_tx_work);
447 |
448 | }
449 |
450 | static int rtl8125_hwtstamp_enable(struct rtl8125_private *tp, bool enable)
451 | {
452 | RTL_W16(tp, PTP_CTRL_8125, 0);
453 | if (enable) {
454 | u16 ptp_ctrl;
455 | struct timespec64 ts64;
456 |
457 | //clear ptp isr
458 | RTL_W8(tp, PTP_ISR_8125, 0xff);
459 | //ptp source 0:gphy 1:mac
460 | rtl8125_mac_ocp_write(tp, 0xDC00, rtl8125_mac_ocp_read(tp, 0xDC00) | BIT_6);
461 | //enable ptp
462 | ptp_ctrl = (BIT_0 | BIT_3 | BIT_4 | BIT_6 | BIT_10 | BIT_12);
463 | if (tp->ptp_master_mode)
464 | ptp_ctrl |= BIT_1;
465 | RTL_W16(tp, PTP_CTRL_8125, ptp_ctrl);
466 |
467 | //set system time
468 | /*
469 | if (ktime_to_timespec64_cond(ktime_get_real(), &ts64))
470 | _rtl8125_phc_settime(tp, timespec64_to_timespec(ts64));
471 | */
472 | ktime_get_real_ts64(&ts64);
473 | _rtl8125_phc_settime(tp, &ts64);
474 | }
475 |
476 | return 0;
477 | }
478 |
479 | static long rtl8125_ptp_create_clock(struct rtl8125_private *tp)
480 | {
481 | struct net_device *netdev = tp->dev;
482 | long err;
483 |
484 | if (!IS_ERR_OR_NULL(tp->ptp_clock))
485 | return 0;
486 |
487 | if (tp->HwSuppPtpVer == 0) {
488 | tp->ptp_clock = NULL;
489 | return -EOPNOTSUPP;
490 | }
491 |
492 | tp->ptp_clock_info = rtl_ptp_clock_info;
493 | snprintf(tp->ptp_clock_info.name, sizeof(tp->ptp_clock_info.name),
494 | "%pm", tp->dev->dev_addr);
495 | tp->ptp_clock_info.max_adj = 119304647;
496 | tp->ptp_clock = ptp_clock_register(&tp->ptp_clock_info, &tp->pci_dev->dev);
497 | if (IS_ERR(tp->ptp_clock)) {
498 | err = PTR_ERR(tp->ptp_clock);
499 | tp->ptp_clock = NULL;
500 | netif_err(tp, drv, tp->dev, "ptp_clock_register failed\n");
501 | return err;
502 | } else
503 | netif_info(tp, drv, tp->dev, "registered PHC device on %s\n", netdev->name);
504 |
505 | return 0;
506 | }
507 |
508 | void rtl8125_ptp_reset(struct rtl8125_private *tp)
509 | {
510 | if (!tp->ptp_clock)
511 | return;
512 |
513 | netif_info(tp, drv, tp->dev, "reset PHC clock\n");
514 |
515 | rtl8125_hwtstamp_enable(tp, false);
516 | }
517 |
518 | void rtl8125_ptp_init(struct rtl8125_private *tp)
519 | {
520 | /* obtain a PTP device, or re-use an existing device */
521 | if (rtl8125_ptp_create_clock(tp))
522 | return;
523 |
524 | /* we have a clock so we can initialize work now */
525 | INIT_WORK(&tp->ptp_tx_work, rtl8125_ptp_tx_work);
526 |
527 | /* reset the PTP related hardware bits */
528 | rtl8125_ptp_reset(tp);
529 |
530 | return;
531 | }
532 |
533 | void rtl8125_ptp_suspend(struct rtl8125_private *tp)
534 | {
535 | if (!tp->ptp_clock)
536 | return;
537 |
538 | netif_info(tp, drv, tp->dev, "suspend PHC clock\n");
539 |
540 | rtl8125_hwtstamp_enable(tp, false);
541 |
542 | /* ensure that we cancel any pending PTP Tx work item in progress */
543 | cancel_work_sync(&tp->ptp_tx_work);
544 | }
545 |
546 | void rtl8125_ptp_stop(struct rtl8125_private *tp)
547 | {
548 | struct net_device *netdev = tp->dev;
549 |
550 | netif_info(tp, drv, tp->dev, "stop PHC clock\n");
551 |
552 | /* first, suspend PTP activity */
553 | rtl8125_ptp_suspend(tp);
554 |
555 | /* disable the PTP clock device */
556 | if (tp->ptp_clock) {
557 | ptp_clock_unregister(tp->ptp_clock);
558 | tp->ptp_clock = NULL;
559 | netif_info(tp, drv, tp->dev, "removed PHC on %s\n",
560 | netdev->name);
561 | }
562 | }
563 |
564 | static int rtl8125_set_tstamp(struct net_device *netdev, struct ifreq *ifr)
565 | {
566 | struct rtl8125_private *tp = netdev_priv(netdev);
567 | struct hwtstamp_config config;
568 | bool hwtstamp = 0;
569 |
570 | //netif_info(tp, drv, tp->dev, "ptp set ts\n");
571 |
572 | if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
573 | return -EFAULT;
574 |
575 | if (config.flags)
576 | return -EINVAL;
577 |
578 | switch (config.tx_type) {
579 | case HWTSTAMP_TX_ON:
580 | hwtstamp = 1;
581 | case HWTSTAMP_TX_OFF:
582 | break;
583 | case HWTSTAMP_TX_ONESTEP_SYNC:
584 | default:
585 | return -ERANGE;
586 | }
587 |
588 | switch (config.rx_filter) {
589 | case HWTSTAMP_FILTER_PTP_V2_EVENT:
590 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
591 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
592 | case HWTSTAMP_FILTER_PTP_V2_SYNC:
593 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
594 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
595 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
596 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
597 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
598 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
599 | hwtstamp = 1;
600 | case HWTSTAMP_FILTER_NONE:
601 | break;
602 | default:
603 | return -ERANGE;
604 | }
605 |
606 | if (tp->hwtstamp_config.tx_type != config.tx_type ||
607 | tp->hwtstamp_config.rx_filter != config.rx_filter) {
608 | tp->hwtstamp_config = config;
609 | rtl8125_hwtstamp_enable(tp, hwtstamp);
610 | }
611 |
612 | return copy_to_user(ifr->ifr_data, &config,
613 | sizeof(config)) ? -EFAULT : 0;
614 | }
615 |
616 | static int rtl8125_get_tstamp(struct net_device *netdev, struct ifreq *ifr)
617 | {
618 | struct rtl8125_private *tp = netdev_priv(netdev);
619 |
620 | //netif_info(tp, drv, tp->dev, "ptp get ts\n");
621 |
622 | return copy_to_user(ifr->ifr_data, &tp->hwtstamp_config,
623 | sizeof(tp->hwtstamp_config)) ? -EFAULT : 0;
624 | }
625 |
626 | int rtl8125_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
627 | {
628 | int ret;
629 |
630 | //netif_info(tp, drv, tp->dev, "ptp ioctl\n");
631 |
632 | switch (cmd) {
633 | #ifdef ENABLE_PTP_SUPPORT
634 | case SIOCSHWTSTAMP:
635 | ret = rtl8125_set_tstamp(netdev, ifr);
636 | break;
637 | case SIOCGHWTSTAMP:
638 | ret = rtl8125_get_tstamp(netdev, ifr);
639 | break;
640 | #endif
641 | default:
642 | ret = -EOPNOTSUPP;
643 | break;
644 | }
645 |
646 | return ret;
647 | }
648 |
649 | void rtl8125_rx_ptp_pktstamp(struct rtl8125_private *tp, struct sk_buff *skb,
650 | struct RxDescV3 *descv3)
651 | {
652 | time64_t tv_sec;
653 | long tv_nsec;
654 |
655 | tv_sec = le32_to_cpu(descv3->RxDescTimeStamp.TimeStampHigh) +
656 | ((u64)le32_to_cpu(descv3->RxDescPTPDDWord4.TimeStampHHigh) << 32);
657 | tv_nsec = le32_to_cpu(descv3->RxDescTimeStamp.TimeStampLow);
658 |
659 | skb_hwtstamps(skb)->hwtstamp = ktime_set(tv_sec, tv_nsec);
660 | }
661 |
--------------------------------------------------------------------------------
/r8125/src/r8125_ptp.h:
--------------------------------------------------------------------------------
1 | /* SPDX-License-Identifier: GPL-2.0-only */
2 | /*
3 | ################################################################################
4 | #
5 | # r8125 is the Linux device driver released for Realtek 2.5 Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.
9 | #
10 | # This program is free software; you can redistribute it and/or modify it
11 | # under the terms of the GNU General Public License as published by the Free
12 | # Software Foundation; either version 2 of the License, or (at your option)
13 | # any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful, but WITHOUT
16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 | # more details.
19 | #
20 | # You should have received a copy of the GNU General Public License along with
21 | # this program; if not, see .
22 | #
23 | # Author:
24 | # Realtek NIC software team
25 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
26 | #
27 | ################################################################################
28 | */
29 |
30 | /************************************************************************************
31 | * This product is covered by one or more of the following patents:
32 | * US6,570,884, US6,115,776, and US6,327,625.
33 | ***********************************************************************************/
34 |
35 | #ifndef _LINUX_rtl8125_PTP_H
36 | #define _LINUX_rtl8125_PTP_H
37 |
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 |
44 | struct rtl8125_ptp_info {
45 | s64 time_sec;
46 | u32 time_ns;
47 | u16 ts_info;
48 | };
49 |
50 | #ifndef _STRUCT_TIMESPEC
51 | #define _STRUCT_TIMESPEC
52 | struct timespec {
53 | __kernel_old_time_t tv_sec; /* seconds */
54 | long tv_nsec; /* nanoseconds */
55 | };
56 | #endif
57 |
58 | enum PTP_CMD_TYPE {
59 | PTP_CMD_SET_LOCAL_TIME = 0,
60 | PTP_CMD_DRIFT_LOCAL_TIME,
61 | PTP_CMD_LATCHED_LOCAL_TIME,
62 | };
63 |
64 |
65 | struct rtl8125_private;
66 | struct RxDescV3;
67 |
68 | int rtl8125_get_ts_info(struct net_device *netdev,
69 | struct ethtool_ts_info *info);
70 |
71 | void rtl8125_ptp_reset(struct rtl8125_private *tp);
72 | void rtl8125_ptp_init(struct rtl8125_private *tp);
73 | void rtl8125_ptp_suspend(struct rtl8125_private *tp);
74 | void rtl8125_ptp_stop(struct rtl8125_private *tp);
75 |
76 | int rtl8125_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd);
77 |
78 | void rtl8125_rx_ptp_pktstamp(struct rtl8125_private *tp, struct sk_buff *skb,
79 | struct RxDescV3 *descv3);
80 |
81 | #endif /* _LINUX_rtl8125_PTP_H */
82 |
--------------------------------------------------------------------------------
/r8125/src/r8125_realwow.h:
--------------------------------------------------------------------------------
1 | /* SPDX-License-Identifier: GPL-2.0-only */
2 | /*
3 | ################################################################################
4 | #
5 | # r8125 is the Linux device driver released for Realtek 2.5 Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.
9 | #
10 | # This program is free software; you can redistribute it and/or modify it
11 | # under the terms of the GNU General Public License as published by the Free
12 | # Software Foundation; either version 2 of the License, or (at your option)
13 | # any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful, but WITHOUT
16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 | # more details.
19 | #
20 | # You should have received a copy of the GNU General Public License along with
21 | # this program; if not, see .
22 | #
23 | # Author:
24 | # Realtek NIC software team
25 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
26 | #
27 | ################################################################################
28 | */
29 |
30 | /************************************************************************************
31 | * This product is covered by one or more of the following patents:
32 | * US6,570,884, US6,115,776, and US6,327,625.
33 | ***********************************************************************************/
34 |
35 | #ifndef _LINUX_R8125_REALWOW_H
36 | #define _LINUX_R8125_REALWOW_H
37 |
38 | #define SIOCDEVPRIVATE_RTLREALWOW SIOCDEVPRIVATE+3
39 |
40 | #define MAX_RealWoW_KCP_SIZE (100)
41 | #define MAX_RealWoW_Payload (64)
42 |
43 | #define KA_TX_PACKET_SIZE (100)
44 | #define KA_WAKEUP_PATTERN_SIZE (120)
45 |
46 | //HwSuppKeepAliveOffloadVer
47 | #define HW_SUPPORT_KCP_OFFLOAD(_M) ((_M)->HwSuppKCPOffloadVer > 0)
48 |
49 | enum rtl_realwow_cmd {
50 |
51 | RTL_REALWOW_SET_KCP_DISABLE=0,
52 | RTL_REALWOW_SET_KCP_INFO,
53 | RTL_REALWOW_SET_KCP_CONTENT,
54 |
55 | RTL_REALWOW_SET_KCP_ACKPKTINFO,
56 | RTL_REALWOW_SET_KCP_WPINFO,
57 | RTL_REALWOW_SET_KCPDHCP_TIMEOUT,
58 |
59 | RTLT_REALWOW_COMMAND_INVALID
60 | };
61 |
62 | struct rtl_realwow_ioctl_struct {
63 | __u32 cmd;
64 | __u32 offset;
65 | __u32 len;
66 | union {
67 | __u32 data;
68 | void *data_buffer;
69 | };
70 | };
71 |
72 | typedef struct _MP_KCPInfo {
73 | u8 DIPv4[4];
74 | u8 MacID[6];
75 | u16 UdpPort[2];
76 | u8 PKTLEN[2];
77 |
78 | u16 ackLostCnt;
79 | u8 KCP_WakePattern[MAX_RealWoW_Payload];
80 | u8 KCP_AckPacket[MAX_RealWoW_Payload];
81 | u32 KCP_interval;
82 | u8 KCP_WakePattern_Len;
83 | u8 KCP_AckPacket_Len;
84 | u8 KCP_TxPacket[2][KA_TX_PACKET_SIZE];
85 | } MP_KCP_INFO, *PMP_KCP_INFO;
86 |
87 | typedef struct _KCPInfo {
88 | u32 nId; // = id
89 | u8 DIPv4[4];
90 | u8 MacID[6];
91 | u16 UdpPort;
92 | u16 PKTLEN;
93 | } KCPInfo, *PKCPInfo;
94 |
95 | typedef struct _KCPContent {
96 | u32 id; // = id
97 | u32 mSec; // = msec
98 | u32 size; // =size
99 | u8 bPacket[MAX_RealWoW_KCP_SIZE]; // put packet here
100 | } KCPContent, *PKCPContent;
101 |
102 | typedef struct _RealWoWAckPktInfo {
103 | u16 ackLostCnt;
104 | u16 patterntSize;
105 | u8 pattern[MAX_RealWoW_Payload];
106 | } RealWoWAckPktInfo,*PRealWoWAckPktInfo;
107 |
108 | typedef struct _RealWoWWPInfo {
109 | u16 patterntSize;
110 | u8 pattern[MAX_RealWoW_Payload];
111 | } RealWoWWPInfo,*PRealWoWWPInfo;
112 |
113 | int rtl8125_realwow_ioctl(struct net_device *dev, struct ifreq *ifr);
114 | void rtl8125_realwow_hw_init(struct net_device *dev);
115 | void rtl8125_get_realwow_hw_version(struct net_device *dev);
116 | void rtl8125_set_realwow_d3_para(struct net_device *dev);
117 |
118 | #endif /* _LINUX_R8125_REALWOW_H */
119 |
--------------------------------------------------------------------------------
/r8125/src/r8125_rss.c:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-2.0-only
2 | /*
3 | ################################################################################
4 | #
5 | # r8125 is the Linux device driver released for Realtek 2.5 Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.
9 | #
10 | # This program is free software; you can redistribute it and/or modify it
11 | # under the terms of the GNU General Public License as published by the Free
12 | # Software Foundation; either version 2 of the License, or (at your option)
13 | # any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful, but WITHOUT
16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 | # more details.
19 | #
20 | # You should have received a copy of the GNU General Public License along with
21 | # this program; if not, see .
22 | #
23 | # Author:
24 | # Realtek NIC software team
25 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
26 | #
27 | ################################################################################
28 | */
29 |
30 | /************************************************************************************
31 | * This product is covered by one or more of the following patents:
32 | * US6,570,884, US6,115,776, and US6,327,625.
33 | ***********************************************************************************/
34 |
35 | #include
36 | #include "r8125.h"
37 |
38 | enum rtl8125_rss_register_content {
39 | /* RSS */
40 | RSS_CTRL_TCP_IPV4_SUPP = (1 << 0),
41 | RSS_CTRL_IPV4_SUPP = (1 << 1),
42 | RSS_CTRL_TCP_IPV6_SUPP = (1 << 2),
43 | RSS_CTRL_IPV6_SUPP = (1 << 3),
44 | RSS_CTRL_IPV6_EXT_SUPP = (1 << 4),
45 | RSS_CTRL_TCP_IPV6_EXT_SUPP = (1 << 5),
46 | RSS_HALF_SUPP = (1 << 7),
47 | RSS_CTRL_UDP_IPV4_SUPP = (1 << 11),
48 | RSS_CTRL_UDP_IPV6_SUPP = (1 << 12),
49 | RSS_CTRL_UDP_IPV6_EXT_SUPP = (1 << 13),
50 | RSS_QUAD_CPU_EN = (1 << 16),
51 | RSS_HQ_Q_SUP_R = (1 << 31),
52 | };
53 |
54 | static int rtl8125_get_rss_hash_opts(struct rtl8125_private *tp,
55 | struct ethtool_rxnfc *cmd)
56 | {
57 | cmd->data = 0;
58 |
59 | /* Report default options for RSS */
60 | switch (cmd->flow_type) {
61 | case TCP_V4_FLOW:
62 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
63 | fallthrough;
64 | case UDP_V4_FLOW:
65 | if (tp->rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV4)
66 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
67 | fallthrough;
68 | case IPV4_FLOW:
69 | cmd->data |= RXH_IP_SRC | RXH_IP_DST;
70 | break;
71 | case TCP_V6_FLOW:
72 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
73 | fallthrough;
74 | case UDP_V6_FLOW:
75 | if (tp->rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV6)
76 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
77 | fallthrough;
78 | case IPV6_FLOW:
79 | cmd->data |= RXH_IP_SRC | RXH_IP_DST;
80 | break;
81 | default:
82 | return -EINVAL;
83 | }
84 |
85 | return 0;
86 | }
87 |
88 | int rtl8125_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
89 | u32 *rule_locs)
90 | {
91 | struct rtl8125_private *tp = netdev_priv(dev);
92 | int ret = -EOPNOTSUPP;
93 |
94 | if (!(dev->features & NETIF_F_RXHASH))
95 | return ret;
96 |
97 | switch (cmd->cmd) {
98 | case ETHTOOL_GRXRINGS:
99 | cmd->data = rtl8125_tot_rx_rings(tp);
100 | ret = 0;
101 | break;
102 | case ETHTOOL_GRXFH:
103 | ret = rtl8125_get_rss_hash_opts(tp, cmd);
104 | break;
105 | default:
106 | break;
107 | }
108 |
109 | return ret;
110 | }
111 |
112 | u32 rtl8125_rss_indir_tbl_entries(struct rtl8125_private *tp)
113 | {
114 | return tp->HwSuppIndirTblEntries;
115 | }
116 |
117 | #define RSS_MASK_BITS_OFFSET (8)
118 | #define RSS_CPU_NUM_OFFSET (16)
119 | #define RTL8125_UDP_RSS_FLAGS (RTL_8125_RSS_FLAG_HASH_UDP_IPV4 | \
120 | RTL_8125_RSS_FLAG_HASH_UDP_IPV6)
121 | static int _rtl8125_set_rss_hash_opt(struct rtl8125_private *tp)
122 | {
123 | u32 rss_flags = tp->rss_flags;
124 | u32 hash_mask_len;
125 | u32 rss_ctrl;
126 |
127 | rss_ctrl = ilog2(rtl8125_tot_rx_rings(tp));
128 | rss_ctrl &= (BIT_0 | BIT_1 | BIT_2);
129 | rss_ctrl <<= RSS_CPU_NUM_OFFSET;
130 |
131 | /* Perform hash on these packet types */
132 | rss_ctrl |= RSS_CTRL_TCP_IPV4_SUPP
133 | | RSS_CTRL_IPV4_SUPP
134 | | RSS_CTRL_IPV6_SUPP
135 | | RSS_CTRL_IPV6_EXT_SUPP
136 | | RSS_CTRL_TCP_IPV6_SUPP
137 | | RSS_CTRL_TCP_IPV6_EXT_SUPP;
138 |
139 | if (rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV4)
140 | rss_ctrl |= RSS_CTRL_UDP_IPV4_SUPP;
141 |
142 | if (rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV6)
143 | rss_ctrl |= RSS_CTRL_UDP_IPV6_SUPP |
144 | RSS_CTRL_UDP_IPV6_EXT_SUPP;
145 |
146 | hash_mask_len = ilog2(rtl8125_rss_indir_tbl_entries(tp));
147 | hash_mask_len &= (BIT_0 | BIT_1 | BIT_2);
148 | rss_ctrl |= hash_mask_len << RSS_MASK_BITS_OFFSET;
149 |
150 | RTL_W32(tp, RSS_CTRL_8125, rss_ctrl);
151 |
152 | return 0;
153 | }
154 |
155 | static int rtl8125_set_rss_hash_opt(struct rtl8125_private *tp,
156 | struct ethtool_rxnfc *nfc)
157 | {
158 | u32 rss_flags = tp->rss_flags;
159 |
160 | /*
161 | * RSS does not support anything other than hashing
162 | * to queues on src and dst IPs and ports
163 | */
164 | if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
165 | RXH_L4_B_0_1 | RXH_L4_B_2_3))
166 | return -EINVAL;
167 |
168 | switch (nfc->flow_type) {
169 | case TCP_V4_FLOW:
170 | case TCP_V6_FLOW:
171 | if (!(nfc->data & RXH_IP_SRC) ||
172 | !(nfc->data & RXH_IP_DST) ||
173 | !(nfc->data & RXH_L4_B_0_1) ||
174 | !(nfc->data & RXH_L4_B_2_3))
175 | return -EINVAL;
176 | break;
177 | case UDP_V4_FLOW:
178 | if (!(nfc->data & RXH_IP_SRC) ||
179 | !(nfc->data & RXH_IP_DST))
180 | return -EINVAL;
181 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
182 | case 0:
183 | rss_flags &= ~RTL_8125_RSS_FLAG_HASH_UDP_IPV4;
184 | break;
185 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
186 | rss_flags |= RTL_8125_RSS_FLAG_HASH_UDP_IPV4;
187 | break;
188 | default:
189 | return -EINVAL;
190 | }
191 | break;
192 | case UDP_V6_FLOW:
193 | if (!(nfc->data & RXH_IP_SRC) ||
194 | !(nfc->data & RXH_IP_DST))
195 | return -EINVAL;
196 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
197 | case 0:
198 | rss_flags &= ~RTL_8125_RSS_FLAG_HASH_UDP_IPV6;
199 | break;
200 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
201 | rss_flags |= RTL_8125_RSS_FLAG_HASH_UDP_IPV6;
202 | break;
203 | default:
204 | return -EINVAL;
205 | }
206 | break;
207 | case SCTP_V4_FLOW:
208 | case AH_ESP_V4_FLOW:
209 | case AH_V4_FLOW:
210 | case ESP_V4_FLOW:
211 | case SCTP_V6_FLOW:
212 | case AH_ESP_V6_FLOW:
213 | case AH_V6_FLOW:
214 | case ESP_V6_FLOW:
215 | case IP_USER_FLOW:
216 | case ETHER_FLOW:
217 | /* RSS is not supported for these protocols */
218 | if (nfc->data) {
219 | netif_err(tp, drv, tp->dev, "Command parameters not supported\n");
220 | return -EINVAL;
221 | }
222 | return 0;
223 | break;
224 | default:
225 | return -EINVAL;
226 | }
227 |
228 | /* if we changed something we need to update flags */
229 | if (rss_flags != tp->rss_flags) {
230 | u32 rss_ctrl = RTL_R32(tp, RSS_CTRL_8125);
231 |
232 | if ((rss_flags & RTL8125_UDP_RSS_FLAGS) &&
233 | !(tp->rss_flags & RTL8125_UDP_RSS_FLAGS))
234 | netdev_warn(tp->dev,
235 | "enabling UDP RSS: fragmented packets may "
236 | "arrive out of order to the stack above\n");
237 |
238 | tp->rss_flags = rss_flags;
239 |
240 | /* Perform hash on these packet types */
241 | rss_ctrl |= RSS_CTRL_TCP_IPV4_SUPP
242 | | RSS_CTRL_IPV4_SUPP
243 | | RSS_CTRL_IPV6_SUPP
244 | | RSS_CTRL_IPV6_EXT_SUPP
245 | | RSS_CTRL_TCP_IPV6_SUPP
246 | | RSS_CTRL_TCP_IPV6_EXT_SUPP;
247 |
248 | rss_ctrl &= ~(RSS_CTRL_UDP_IPV4_SUPP |
249 | RSS_CTRL_UDP_IPV6_SUPP |
250 | RSS_CTRL_UDP_IPV6_EXT_SUPP);
251 |
252 | if (rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV4)
253 | rss_ctrl |= RSS_CTRL_UDP_IPV4_SUPP;
254 |
255 | if (rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV6)
256 | rss_ctrl |= RSS_CTRL_UDP_IPV6_SUPP |
257 | RSS_CTRL_UDP_IPV6_EXT_SUPP;
258 |
259 | RTL_W32(tp, RSS_CTRL_8125, rss_ctrl);
260 | }
261 |
262 | return 0;
263 | }
264 |
265 | int rtl8125_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
266 | {
267 | struct rtl8125_private *tp = netdev_priv(dev);
268 | int ret = -EOPNOTSUPP;
269 |
270 | if (!(dev->features & NETIF_F_RXHASH))
271 | return ret;
272 |
273 | switch (cmd->cmd) {
274 | case ETHTOOL_SRXFH:
275 | ret = rtl8125_set_rss_hash_opt(tp, cmd);
276 | break;
277 | default:
278 | break;
279 | }
280 |
281 | return ret;
282 | }
283 |
284 | static u32 _rtl8125_get_rxfh_key_size(struct rtl8125_private *tp)
285 | {
286 | return sizeof(tp->rss_key);
287 | }
288 |
289 | u32 rtl8125_get_rxfh_key_size(struct net_device *dev)
290 | {
291 | struct rtl8125_private *tp = netdev_priv(dev);
292 |
293 | if (!(dev->features & NETIF_F_RXHASH))
294 | return 0;
295 |
296 | return _rtl8125_get_rxfh_key_size(tp);
297 | }
298 |
299 | u32 rtl8125_rss_indir_size(struct net_device *dev)
300 | {
301 | struct rtl8125_private *tp = netdev_priv(dev);
302 |
303 | if (!(dev->features & NETIF_F_RXHASH))
304 | return 0;
305 |
306 | return rtl8125_rss_indir_tbl_entries(tp);
307 | }
308 |
309 | static void rtl8125_get_reta(struct rtl8125_private *tp, u32 *indir)
310 | {
311 | int i, reta_size = rtl8125_rss_indir_tbl_entries(tp);
312 |
313 | for (i = 0; i < reta_size; i++)
314 | indir[i] = tp->rss_indir_tbl[i];
315 | }
316 |
317 | static u32 rtl8125_rss_key_reg(struct rtl8125_private *tp)
318 | {
319 | return RSS_KEY_8125;
320 | }
321 |
322 | static u32 rtl8125_rss_indir_tbl_reg(struct rtl8125_private *tp)
323 | {
324 | return RSS_INDIRECTION_TBL_8125_V2;
325 | }
326 |
327 | static void rtl8125_store_reta(struct rtl8125_private *tp)
328 | {
329 | u16 indir_tbl_reg = rtl8125_rss_indir_tbl_reg(tp);
330 | u32 i, reta_entries = rtl8125_rss_indir_tbl_entries(tp);
331 | u32 reta = 0;
332 | u8 *indir_tbl = tp->rss_indir_tbl;
333 |
334 | /* Write redirection table to HW */
335 | for (i = 0; i < reta_entries; i++) {
336 | reta |= indir_tbl[i] << (i & 0x3) * 8;
337 | if ((i & 3) == 3) {
338 | RTL_W32(tp, indir_tbl_reg, reta);
339 |
340 | indir_tbl_reg += 4;
341 | reta = 0;
342 | }
343 | }
344 | }
345 |
346 | static void rtl8125_store_rss_key(struct rtl8125_private *tp)
347 | {
348 | const u16 rss_key_reg = rtl8125_rss_key_reg(tp);
349 | u32 i, rss_key_size = _rtl8125_get_rxfh_key_size(tp);
350 | u32 *rss_key = (u32*)tp->rss_key;
351 |
352 | /* Write redirection table to HW */
353 | for (i = 0; i < rss_key_size; i+=4)
354 | RTL_W32(tp, rss_key_reg + i, *rss_key++);
355 | }
356 |
357 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(6,8,0)
358 | int rtl8125_get_rxfh(struct net_device *dev, struct ethtool_rxfh_param *rxfh)
359 | {
360 | struct rtl8125_private *tp = netdev_priv(dev);
361 |
362 | if (!(dev->features & NETIF_F_RXHASH))
363 | return -EOPNOTSUPP;
364 |
365 | rxfh->hfunc = ETH_RSS_HASH_TOP;
366 |
367 | if (rxfh->indir)
368 | rtl8125_get_reta(tp, rxfh->indir);
369 |
370 | if (rxfh->key)
371 | memcpy(rxfh->key, tp->rss_key, RTL8125_RSS_KEY_SIZE);
372 |
373 | return 0;
374 | }
375 |
376 | int rtl8125_set_rxfh(struct net_device *dev, struct ethtool_rxfh_param *rxfh,
377 | struct netlink_ext_ack *extack)
378 | {
379 | struct rtl8125_private *tp = netdev_priv(dev);
380 | int i;
381 | u32 reta_entries = rtl8125_rss_indir_tbl_entries(tp);
382 |
383 | /* We require at least one supported parameter to be changed and no
384 | * change in any of the unsupported parameters
385 | */
386 | if (rxfh->hfunc != ETH_RSS_HASH_NO_CHANGE && rxfh->hfunc != ETH_RSS_HASH_TOP)
387 | return -EOPNOTSUPP;
388 |
389 | /* Fill out the redirection table */
390 | if (rxfh->indir) {
391 | int max_queues = tp->num_rx_rings;
392 |
393 | /* Verify user input. */
394 | for (i = 0; i < reta_entries; i++)
395 | if (rxfh->indir[i] >= max_queues)
396 | return -EINVAL;
397 |
398 | for (i = 0; i < reta_entries; i++)
399 | tp->rss_indir_tbl[i] = rxfh->indir[i];
400 | }
401 |
402 | /* Fill out the rss hash key */
403 | if (rxfh->key)
404 | memcpy(tp->rss_key, rxfh->key, RTL8125_RSS_KEY_SIZE);
405 |
406 | rtl8125_store_reta(tp);
407 |
408 | rtl8125_store_rss_key(tp);
409 |
410 | return 0;
411 | }
412 | #else
413 | int rtl8125_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
414 | u8 *hfunc)
415 | {
416 | struct rtl8125_private *tp = netdev_priv(dev);
417 |
418 | if (!(dev->features & NETIF_F_RXHASH))
419 | return -EOPNOTSUPP;
420 |
421 | if (hfunc)
422 | *hfunc = ETH_RSS_HASH_TOP;
423 |
424 | if (indir)
425 | rtl8125_get_reta(tp, indir);
426 |
427 | if (key)
428 | memcpy(key, tp->rss_key, RTL8125_RSS_KEY_SIZE);
429 |
430 | return 0;
431 | }
432 |
433 | int rtl8125_set_rxfh(struct net_device *dev, const u32 *indir,
434 | const u8 *key, const u8 hfunc)
435 | {
436 | struct rtl8125_private *tp = netdev_priv(dev);
437 | int i;
438 | u32 reta_entries = rtl8125_rss_indir_tbl_entries(tp);
439 |
440 | /* We require at least one supported parameter to be changed and no
441 | * change in any of the unsupported parameters
442 | */
443 | if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
444 | return -EOPNOTSUPP;
445 |
446 | /* Fill out the redirection table */
447 | if (indir) {
448 | int max_queues = tp->num_rx_rings;
449 |
450 | /* Verify user input. */
451 | for (i = 0; i < reta_entries; i++)
452 | if (indir[i] >= max_queues)
453 | return -EINVAL;
454 |
455 | for (i = 0; i < reta_entries; i++)
456 | tp->rss_indir_tbl[i] = indir[i];
457 | }
458 |
459 | /* Fill out the rss hash key */
460 | if (key)
461 | memcpy(tp->rss_key, key, RTL8125_RSS_KEY_SIZE);
462 |
463 | rtl8125_store_reta(tp);
464 |
465 | rtl8125_store_rss_key(tp);
466 |
467 | return 0;
468 | }
469 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(6,8,0) */
470 |
471 | static u32 rtl8125_get_rx_desc_hash(struct rtl8125_private *tp,
472 | struct RxDesc *desc)
473 | {
474 | switch (tp->InitRxDescType) {
475 | case RX_DESC_RING_TYPE_3:
476 | return le32_to_cpu(((struct RxDescV3 *)desc)->RxDescNormalDDWord2.RSSResult);
477 | case RX_DESC_RING_TYPE_4:
478 | return le32_to_cpu(((struct RxDescV4 *)desc)->RxDescNormalDDWord1.RSSResult);
479 | default:
480 | return 0;
481 | }
482 | }
483 |
484 | #define RXS_8125B_RSS_UDP BIT(9)
485 | #define RXS_8125_RSS_IPV4 BIT(10)
486 | #define RXS_8125_RSS_IPV6 BIT(12)
487 | #define RXS_8125_RSS_TCP BIT(13)
488 | #define RTL8125_RXS_RSS_L3_TYPE_MASK (RXS_8125_RSS_IPV4 | RXS_8125_RSS_IPV6)
489 | #define RTL8125_RXS_RSS_L4_TYPE_MASK (RXS_8125_RSS_TCP | RXS_8125B_RSS_UDP)
490 |
491 | #define RXS_8125B_RSS_UDP_V4 BIT(27)
492 | #define RXS_8125_RSS_IPV4_V4 BIT(28)
493 | #define RXS_8125_RSS_IPV6_V4 BIT(29)
494 | #define RXS_8125_RSS_TCP_V4 BIT(30)
495 | #define RTL8125_RXS_RSS_L3_TYPE_MASK_V4 (RXS_8125_RSS_IPV4_V4 | RXS_8125_RSS_IPV6_V4)
496 | #define RTL8125_RXS_RSS_L4_TYPE_MASK_V4 (RXS_8125_RSS_TCP_V4 | RXS_8125B_RSS_UDP_V4)
497 | static void rtl8125_rx_hash_v3(struct rtl8125_private *tp,
498 | struct RxDescV3 *descv3,
499 | struct sk_buff *skb)
500 | {
501 | u16 rss_header_info;
502 |
503 | if (!(tp->dev->features & NETIF_F_RXHASH))
504 | return;
505 |
506 | rss_header_info = le16_to_cpu(descv3->RxDescNormalDDWord2.HeaderInfo);
507 |
508 | if (!(rss_header_info & RTL8125_RXS_RSS_L3_TYPE_MASK))
509 | return;
510 |
511 | skb_set_hash(skb, rtl8125_get_rx_desc_hash(tp, (struct RxDesc *)descv3),
512 | (RTL8125_RXS_RSS_L4_TYPE_MASK & rss_header_info) ?
513 | PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
514 | }
515 |
516 | static void rtl8125_rx_hash_v4(struct rtl8125_private *tp,
517 | struct RxDescV4 *descv4,
518 | struct sk_buff *skb)
519 | {
520 | u32 rss_header_info;
521 |
522 | if (!(tp->dev->features & NETIF_F_RXHASH))
523 | return;
524 |
525 | rss_header_info = le32_to_cpu(descv4->RxDescNormalDDWord1.RSSInfo);
526 |
527 | if (!(rss_header_info & RTL8125_RXS_RSS_L3_TYPE_MASK_V4))
528 | return;
529 |
530 | skb_set_hash(skb, rtl8125_get_rx_desc_hash(tp, (struct RxDesc *)descv4),
531 | (RTL8125_RXS_RSS_L4_TYPE_MASK_V4 & rss_header_info) ?
532 | PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
533 | }
534 |
535 | void rtl8125_rx_hash(struct rtl8125_private *tp,
536 | struct RxDesc *desc,
537 | struct sk_buff *skb)
538 | {
539 | switch (tp->InitRxDescType) {
540 | case RX_DESC_RING_TYPE_3:
541 | rtl8125_rx_hash_v3(tp, (struct RxDescV3 *)desc, skb);
542 | break;
543 | case RX_DESC_RING_TYPE_4:
544 | rtl8125_rx_hash_v4(tp, (struct RxDescV4 *)desc, skb);
545 | break;
546 | default:
547 | return;
548 | }
549 | }
550 |
551 | void rtl8125_disable_rss(struct rtl8125_private *tp)
552 | {
553 | RTL_W32(tp, RSS_CTRL_8125, 0x00);
554 | }
555 |
556 | void _rtl8125_config_rss(struct rtl8125_private *tp)
557 | {
558 | _rtl8125_set_rss_hash_opt(tp);
559 |
560 | rtl8125_store_reta(tp);
561 |
562 | rtl8125_store_rss_key(tp);
563 | }
564 |
565 | void rtl8125_config_rss(struct rtl8125_private *tp)
566 | {
567 | if (!tp->EnableRss) {
568 | rtl8125_disable_rss(tp);
569 | return;
570 | }
571 |
572 | _rtl8125_config_rss(tp);
573 | }
574 |
575 | void rtl8125_init_rss(struct rtl8125_private *tp)
576 | {
577 | int i;
578 |
579 | for (i = 0; i < rtl8125_rss_indir_tbl_entries(tp); i++)
580 | tp->rss_indir_tbl[i] = ethtool_rxfh_indir_default(i, tp->num_rx_rings);
581 |
582 | netdev_rss_key_fill(tp->rss_key, RTL8125_RSS_KEY_SIZE);
583 | }
584 |
--------------------------------------------------------------------------------
/r8125/src/r8125_rss.h:
--------------------------------------------------------------------------------
1 | /* SPDX-License-Identifier: GPL-2.0-only */
2 | /*
3 | ################################################################################
4 | #
5 | # r8125 is the Linux device driver released for Realtek 2.5 Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.
9 | #
10 | # This program is free software; you can redistribute it and/or modify it
11 | # under the terms of the GNU General Public License as published by the Free
12 | # Software Foundation; either version 2 of the License, or (at your option)
13 | # any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful, but WITHOUT
16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 | # more details.
19 | #
20 | # You should have received a copy of the GNU General Public License along with
21 | # this program; if not, see .
22 | #
23 | # Author:
24 | # Realtek NIC software team
25 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
26 | #
27 | ################################################################################
28 | */
29 |
30 | /************************************************************************************
31 | * This product is covered by one or more of the following patents:
32 | * US6,570,884, US6,115,776, and US6,327,625.
33 | ***********************************************************************************/
34 |
35 | #ifndef _LINUX_rtl8125_RSS_H
36 | #define _LINUX_rtl8125_RSS_H
37 |
38 | #include
39 | #include
40 |
41 | #define RTL8125_RSS_KEY_SIZE 40 /* size of RSS Hash Key in bytes */
42 | #define RTL8125_MAX_INDIRECTION_TABLE_ENTRIES 128
43 |
44 | enum rtl8125_rss_flag {
45 | RTL_8125_RSS_FLAG_HASH_UDP_IPV4 = (1 << 0),
46 | RTL_8125_RSS_FLAG_HASH_UDP_IPV6 = (1 << 1),
47 | };
48 |
49 | struct rtl8125_private;
50 | struct RxDesc;
51 |
52 | int rtl8125_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
53 | u32 *rule_locs);
54 | int rtl8125_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd);
55 | u32 rtl8125_get_rxfh_key_size(struct net_device *netdev);
56 | u32 rtl8125_rss_indir_size(struct net_device *netdev);
57 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(6,8,0)
58 | int rtl8125_get_rxfh(struct net_device *dev, struct ethtool_rxfh_param *rxfh);
59 | int rtl8125_set_rxfh(struct net_device *dev, struct ethtool_rxfh_param *rxfh,
60 | struct netlink_ext_ack *extack);
61 | #else
62 | int rtl8125_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
63 | u8 *hfunc);
64 | int rtl8125_set_rxfh(struct net_device *netdev, const u32 *indir,
65 | const u8 *key, const u8 hfunc);
66 | #endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(6,8,0) */
67 | void rtl8125_rx_hash(struct rtl8125_private *tp,
68 | struct RxDesc *desc,
69 | struct sk_buff *skb);
70 | void _rtl8125_config_rss(struct rtl8125_private *tp);
71 | void rtl8125_config_rss(struct rtl8125_private *tp);
72 | void rtl8125_init_rss(struct rtl8125_private *tp);
73 | u32 rtl8125_rss_indir_tbl_entries(struct rtl8125_private *tp);
74 | void rtl8125_disable_rss(struct rtl8125_private *tp);
75 |
76 | #endif /* _LINUX_rtl8125_RSS_H */
77 |
--------------------------------------------------------------------------------
/r8125/src/rtl_eeprom.c:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-2.0-only
2 | /*
3 | ################################################################################
4 | #
5 | # r8125 is the Linux device driver released for Realtek 2.5 Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.
9 | #
10 | # This program is free software; you can redistribute it and/or modify it
11 | # under the terms of the GNU General Public License as published by the Free
12 | # Software Foundation; either version 2 of the License, or (at your option)
13 | # any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful, but WITHOUT
16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 | # more details.
19 | #
20 | # You should have received a copy of the GNU General Public License along with
21 | # this program; if not, see .
22 | #
23 | # Author:
24 | # Realtek NIC software team
25 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
26 | #
27 | ################################################################################
28 | */
29 |
30 | /************************************************************************************
31 | * This product is covered by one or more of the following patents:
32 | * US6,570,884, US6,115,776, and US6,327,625.
33 | ***********************************************************************************/
34 |
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 |
42 | #include
43 |
44 | #include "r8125.h"
45 | #include "rtl_eeprom.h"
46 |
47 | //-------------------------------------------------------------------
48 | //rtl8125_eeprom_type():
49 | // tell the eeprom type
50 | //return value:
51 | // 0: the eeprom type is 93C46
52 | // 1: the eeprom type is 93C56 or 93C66
53 | //-------------------------------------------------------------------
54 | void rtl8125_eeprom_type(struct rtl8125_private *tp)
55 | {
56 | u16 magic = 0;
57 |
58 | if (tp->mcfg == CFG_METHOD_DEFAULT)
59 | goto out_no_eeprom;
60 |
61 | if(RTL_R8(tp, 0xD2)&0x04) {
62 | //not support
63 | //tp->eeprom_type = EEPROM_TWSI;
64 | //tp->eeprom_len = 256;
65 | goto out_no_eeprom;
66 | } else if(RTL_R32(tp, RxConfig) & RxCfg_9356SEL) {
67 | tp->eeprom_type = EEPROM_TYPE_93C56;
68 | tp->eeprom_len = 256;
69 | } else {
70 | tp->eeprom_type = EEPROM_TYPE_93C46;
71 | tp->eeprom_len = 128;
72 | }
73 |
74 | magic = rtl8125_eeprom_read_sc(tp, 0);
75 |
76 | out_no_eeprom:
77 | if ((magic != 0x8129) && (magic != 0x8128)) {
78 | tp->eeprom_type = EEPROM_TYPE_NONE;
79 | tp->eeprom_len = 0;
80 | }
81 | }
82 |
83 | void rtl8125_eeprom_cleanup(struct rtl8125_private *tp)
84 | {
85 | u8 x;
86 |
87 | x = RTL_R8(tp, Cfg9346);
88 | x &= ~(Cfg9346_EEDI | Cfg9346_EECS);
89 |
90 | RTL_W8(tp, Cfg9346, x);
91 |
92 | rtl8125_raise_clock(tp, &x);
93 | rtl8125_lower_clock(tp, &x);
94 | }
95 |
96 | static int rtl8125_eeprom_cmd_done(struct rtl8125_private *tp)
97 | {
98 | u8 x;
99 | int i;
100 |
101 | rtl8125_stand_by(tp);
102 |
103 | for (i = 0; i < 50000; i++) {
104 | x = RTL_R8(tp, Cfg9346);
105 |
106 | if (x & Cfg9346_EEDO) {
107 | fsleep(RTL_CLOCK_RATE * 2 * 3);
108 | return 0;
109 | }
110 | fsleep(1);
111 | }
112 |
113 | return -1;
114 | }
115 |
116 | //-------------------------------------------------------------------
117 | //rtl8125_eeprom_read_sc():
118 | // read one word from eeprom
119 | //-------------------------------------------------------------------
120 | u16 rtl8125_eeprom_read_sc(struct rtl8125_private *tp, u16 reg)
121 | {
122 | int addr_sz = 6;
123 | u8 x;
124 | u16 data;
125 |
126 | if(tp->eeprom_type == EEPROM_TYPE_NONE)
127 | return -1;
128 |
129 | if (tp->eeprom_type==EEPROM_TYPE_93C46)
130 | addr_sz = 6;
131 | else if (tp->eeprom_type==EEPROM_TYPE_93C56)
132 | addr_sz = 8;
133 |
134 | x = Cfg9346_EEM1 | Cfg9346_EECS;
135 | RTL_W8(tp, Cfg9346, x);
136 |
137 | rtl8125_shift_out_bits(tp, RTL_EEPROM_READ_OPCODE, 3);
138 | rtl8125_shift_out_bits(tp, reg, addr_sz);
139 |
140 | data = rtl8125_shift_in_bits(tp);
141 |
142 | rtl8125_eeprom_cleanup(tp);
143 |
144 | RTL_W8(tp, Cfg9346, 0);
145 |
146 | return data;
147 | }
148 |
149 | //-------------------------------------------------------------------
150 | //rtl8125_eeprom_write_sc():
151 | // write one word to a specific address in the eeprom
152 | //-------------------------------------------------------------------
153 | void rtl8125_eeprom_write_sc(struct rtl8125_private *tp, u16 reg, u16 data)
154 | {
155 | u8 x;
156 | int addr_sz = 6;
157 | int w_dummy_addr = 4;
158 |
159 | if(tp->eeprom_type == EEPROM_TYPE_NONE)
160 | return;
161 |
162 | if (tp->eeprom_type==EEPROM_TYPE_93C46) {
163 | addr_sz = 6;
164 | w_dummy_addr = 4;
165 | } else if (tp->eeprom_type==EEPROM_TYPE_93C56) {
166 | addr_sz = 8;
167 | w_dummy_addr = 6;
168 | }
169 |
170 | x = Cfg9346_EEM1 | Cfg9346_EECS;
171 | RTL_W8(tp, Cfg9346, x);
172 |
173 | rtl8125_shift_out_bits(tp, RTL_EEPROM_EWEN_OPCODE, 5);
174 | rtl8125_shift_out_bits(tp, reg, w_dummy_addr);
175 | rtl8125_stand_by(tp);
176 |
177 | rtl8125_shift_out_bits(tp, RTL_EEPROM_ERASE_OPCODE, 3);
178 | rtl8125_shift_out_bits(tp, reg, addr_sz);
179 | if (rtl8125_eeprom_cmd_done(tp) < 0)
180 | return;
181 | rtl8125_stand_by(tp);
182 |
183 | rtl8125_shift_out_bits(tp, RTL_EEPROM_WRITE_OPCODE, 3);
184 | rtl8125_shift_out_bits(tp, reg, addr_sz);
185 | rtl8125_shift_out_bits(tp, data, 16);
186 | if (rtl8125_eeprom_cmd_done(tp) < 0)
187 | return;
188 | rtl8125_stand_by(tp);
189 |
190 | rtl8125_shift_out_bits(tp, RTL_EEPROM_EWDS_OPCODE, 5);
191 | rtl8125_shift_out_bits(tp, reg, w_dummy_addr);
192 |
193 | rtl8125_eeprom_cleanup(tp);
194 | RTL_W8(tp, Cfg9346, 0);
195 | }
196 |
197 | void rtl8125_raise_clock(struct rtl8125_private *tp, u8 *x)
198 | {
199 | *x = *x | Cfg9346_EESK;
200 | RTL_W8(tp, Cfg9346, *x);
201 | fsleep(RTL_CLOCK_RATE);
202 | }
203 |
204 | void rtl8125_lower_clock(struct rtl8125_private *tp, u8 *x)
205 | {
206 | *x = *x & ~Cfg9346_EESK;
207 | RTL_W8(tp, Cfg9346, *x);
208 | fsleep(RTL_CLOCK_RATE);
209 | }
210 |
211 | void rtl8125_shift_out_bits(struct rtl8125_private *tp, int data, int count)
212 | {
213 | u8 x;
214 | int mask;
215 |
216 | mask = 0x01 << (count - 1);
217 | x = RTL_R8(tp, Cfg9346);
218 | x &= ~(Cfg9346_EEDI | Cfg9346_EEDO);
219 |
220 | do {
221 | if (data & mask)
222 | x |= Cfg9346_EEDI;
223 | else
224 | x &= ~Cfg9346_EEDI;
225 |
226 | RTL_W8(tp, Cfg9346, x);
227 | fsleep(RTL_CLOCK_RATE);
228 | rtl8125_raise_clock(tp, &x);
229 | rtl8125_lower_clock(tp, &x);
230 | mask = mask >> 1;
231 | } while(mask);
232 |
233 | x &= ~Cfg9346_EEDI;
234 | RTL_W8(tp, Cfg9346, x);
235 | }
236 |
237 | u16 rtl8125_shift_in_bits(struct rtl8125_private *tp)
238 | {
239 | u8 x;
240 | u16 d, i;
241 |
242 | x = RTL_R8(tp, Cfg9346);
243 | x &= ~(Cfg9346_EEDI | Cfg9346_EEDO);
244 |
245 | d = 0;
246 |
247 | for (i = 0; i < 16; i++) {
248 | d = d << 1;
249 | rtl8125_raise_clock(tp, &x);
250 |
251 | x = RTL_R8(tp, Cfg9346);
252 | x &= ~Cfg9346_EEDI;
253 |
254 | if (x & Cfg9346_EEDO)
255 | d |= 1;
256 |
257 | rtl8125_lower_clock(tp, &x);
258 | }
259 |
260 | return d;
261 | }
262 |
263 | void rtl8125_stand_by(struct rtl8125_private *tp)
264 | {
265 | u8 x;
266 |
267 | x = RTL_R8(tp, Cfg9346);
268 | x &= ~(Cfg9346_EECS | Cfg9346_EESK);
269 | RTL_W8(tp, Cfg9346, x);
270 | fsleep(RTL_CLOCK_RATE);
271 |
272 | x |= Cfg9346_EECS;
273 | RTL_W8(tp, Cfg9346, x);
274 | }
275 |
276 | void rtl8125_set_eeprom_sel_low(struct rtl8125_private *tp)
277 | {
278 | RTL_W8(tp, Cfg9346, Cfg9346_EEM1);
279 | RTL_W8(tp, Cfg9346, Cfg9346_EEM1 | Cfg9346_EESK);
280 |
281 | fsleep(20);
282 |
283 | RTL_W8(tp, Cfg9346, Cfg9346_EEM1);
284 | }
285 |
--------------------------------------------------------------------------------
/r8125/src/rtl_eeprom.h:
--------------------------------------------------------------------------------
1 | /* SPDX-License-Identifier: GPL-2.0-only */
2 | /*
3 | ################################################################################
4 | #
5 | # r8125 is the Linux device driver released for Realtek 2.5 Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.
9 | #
10 | # This program is free software; you can redistribute it and/or modify it
11 | # under the terms of the GNU General Public License as published by the Free
12 | # Software Foundation; either version 2 of the License, or (at your option)
13 | # any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful, but WITHOUT
16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 | # more details.
19 | #
20 | # You should have received a copy of the GNU General Public License along with
21 | # this program; if not, see .
22 | #
23 | # Author:
24 | # Realtek NIC software team
25 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
26 | #
27 | ################################################################################
28 | */
29 |
30 | /************************************************************************************
31 | * This product is covered by one or more of the following patents:
32 | * US6,570,884, US6,115,776, and US6,327,625.
33 | ***********************************************************************************/
34 |
35 | //EEPROM opcodes
36 | #define RTL_EEPROM_READ_OPCODE 06
37 | #define RTL_EEPROM_WRITE_OPCODE 05
38 | #define RTL_EEPROM_ERASE_OPCODE 07
39 | #define RTL_EEPROM_EWEN_OPCODE 19
40 | #define RTL_EEPROM_EWDS_OPCODE 16
41 |
42 | #define RTL_CLOCK_RATE 3
43 |
44 | void rtl8125_eeprom_type(struct rtl8125_private *tp);
45 | void rtl8125_eeprom_cleanup(struct rtl8125_private *tp);
46 | u16 rtl8125_eeprom_read_sc(struct rtl8125_private *tp, u16 reg);
47 | void rtl8125_eeprom_write_sc(struct rtl8125_private *tp, u16 reg, u16 data);
48 | void rtl8125_shift_out_bits(struct rtl8125_private *tp, int data, int count);
49 | u16 rtl8125_shift_in_bits(struct rtl8125_private *tp);
50 | void rtl8125_raise_clock(struct rtl8125_private *tp, u8 *x);
51 | void rtl8125_lower_clock(struct rtl8125_private *tp, u8 *x);
52 | void rtl8125_stand_by(struct rtl8125_private *tp);
53 | void rtl8125_set_eeprom_sel_low(struct rtl8125_private *tp);
54 |
--------------------------------------------------------------------------------
/r8125/src/rtltool.c:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-2.0-only
2 | /*
3 | ################################################################################
4 | #
5 | # r8125 is the Linux device driver released for Realtek 2.5 Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.
9 | #
10 | # This program is free software; you can redistribute it and/or modify it
11 | # under the terms of the GNU General Public License as published by the Free
12 | # Software Foundation; either version 2 of the License, or (at your option)
13 | # any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful, but WITHOUT
16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 | # more details.
19 | #
20 | # You should have received a copy of the GNU General Public License along with
21 | # this program; if not, see .
22 | #
23 | # Author:
24 | # Realtek NIC software team
25 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
26 | #
27 | ################################################################################
28 | */
29 |
30 | /************************************************************************************
31 | * This product is covered by one or more of the following patents:
32 | * US6,570,884, US6,115,776, and US6,327,625.
33 | ***********************************************************************************/
34 |
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include "r8125.h"
44 | #include "rtl_eeprom.h"
45 | #include "rtltool.h"
46 |
47 | int rtl8125_tool_ioctl(struct rtl8125_private *tp, struct ifreq *ifr)
48 | {
49 | struct rtltool_cmd my_cmd;
50 | int ret;
51 |
52 | if (copy_from_user(&my_cmd, ifr->ifr_data, sizeof(my_cmd)))
53 | return -EFAULT;
54 |
55 | ret = 0;
56 | switch (my_cmd.cmd) {
57 | case RTLTOOL_READ_MAC:
58 | if ((my_cmd.offset + my_cmd.len) > pci_resource_len(tp->pci_dev, 2)) {
59 | ret = -EINVAL;
60 | break;
61 | }
62 |
63 | if (my_cmd.len==1)
64 | my_cmd.data = readb(tp->mmio_addr+my_cmd.offset);
65 | else if (my_cmd.len==2)
66 | my_cmd.data = readw(tp->mmio_addr+(my_cmd.offset&~1));
67 | else if (my_cmd.len==4)
68 | my_cmd.data = readl(tp->mmio_addr+(my_cmd.offset&~3));
69 | else {
70 | ret = -EOPNOTSUPP;
71 | break;
72 | }
73 |
74 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
75 | ret = -EFAULT;
76 | break;
77 | }
78 | break;
79 |
80 | case RTLTOOL_WRITE_MAC:
81 | if ((my_cmd.offset + my_cmd.len) > pci_resource_len(tp->pci_dev, 2)) {
82 | ret = -EINVAL;
83 | break;
84 | }
85 |
86 | if (my_cmd.len==1)
87 | writeb(my_cmd.data, tp->mmio_addr+my_cmd.offset);
88 | else if (my_cmd.len==2)
89 | writew(my_cmd.data, tp->mmio_addr+(my_cmd.offset&~1));
90 | else if (my_cmd.len==4)
91 | writel(my_cmd.data, tp->mmio_addr+(my_cmd.offset&~3));
92 | else {
93 | ret = -EOPNOTSUPP;
94 | break;
95 | }
96 |
97 | break;
98 |
99 | case RTLTOOL_READ_PHY:
100 | my_cmd.data = rtl8125_mdio_prot_read(tp, my_cmd.offset);
101 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
102 | ret = -EFAULT;
103 | break;
104 | }
105 |
106 | break;
107 |
108 | case RTLTOOL_WRITE_PHY:
109 | rtl8125_mdio_prot_write(tp, my_cmd.offset, my_cmd.data);
110 | break;
111 |
112 | case RTLTOOL_READ_EPHY:
113 | my_cmd.data = rtl8125_ephy_read(tp, my_cmd.offset);
114 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
115 | ret = -EFAULT;
116 | break;
117 | }
118 |
119 | break;
120 |
121 | case RTLTOOL_WRITE_EPHY:
122 | rtl8125_ephy_write(tp, my_cmd.offset, my_cmd.data);
123 | break;
124 |
125 | case RTLTOOL_READ_ERI:
126 | my_cmd.data = 0;
127 | if (my_cmd.len==1 || my_cmd.len==2 || my_cmd.len==4) {
128 | my_cmd.data = rtl8125_eri_read(tp, my_cmd.offset, my_cmd.len, ERIAR_ExGMAC);
129 | } else {
130 | ret = -EOPNOTSUPP;
131 | break;
132 | }
133 |
134 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
135 | ret = -EFAULT;
136 | break;
137 | }
138 |
139 | break;
140 |
141 | case RTLTOOL_WRITE_ERI:
142 | if (my_cmd.len==1 || my_cmd.len==2 || my_cmd.len==4) {
143 | rtl8125_eri_write(tp, my_cmd.offset, my_cmd.len, my_cmd.data, ERIAR_ExGMAC);
144 | } else {
145 | ret = -EOPNOTSUPP;
146 | break;
147 | }
148 | break;
149 |
150 | case RTLTOOL_READ_PCI:
151 | my_cmd.data = 0;
152 | if (my_cmd.len==1)
153 | pci_read_config_byte(tp->pci_dev, my_cmd.offset,
154 | (u8 *)&my_cmd.data);
155 | else if (my_cmd.len==2)
156 | pci_read_config_word(tp->pci_dev, my_cmd.offset,
157 | (u16 *)&my_cmd.data);
158 | else if (my_cmd.len==4)
159 | pci_read_config_dword(tp->pci_dev, my_cmd.offset,
160 | &my_cmd.data);
161 | else {
162 | ret = -EOPNOTSUPP;
163 | break;
164 | }
165 |
166 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
167 | ret = -EFAULT;
168 | break;
169 | }
170 | break;
171 |
172 | case RTLTOOL_WRITE_PCI:
173 | if (my_cmd.len==1)
174 | pci_write_config_byte(tp->pci_dev, my_cmd.offset,
175 | my_cmd.data);
176 | else if (my_cmd.len==2)
177 | pci_write_config_word(tp->pci_dev, my_cmd.offset,
178 | my_cmd.data);
179 | else if (my_cmd.len==4)
180 | pci_write_config_dword(tp->pci_dev, my_cmd.offset,
181 | my_cmd.data);
182 | else {
183 | ret = -EOPNOTSUPP;
184 | break;
185 | }
186 |
187 | break;
188 |
189 | case RTLTOOL_READ_EEPROM:
190 | my_cmd.data = rtl8125_eeprom_read_sc(tp, my_cmd.offset);
191 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
192 | ret = -EFAULT;
193 | break;
194 | }
195 |
196 | break;
197 |
198 | case RTLTOOL_WRITE_EEPROM:
199 | rtl8125_eeprom_write_sc(tp, my_cmd.offset, my_cmd.data);
200 | break;
201 |
202 | case RTL_READ_OOB_MAC:
203 | rtl8125_oob_mutex_lock(tp);
204 | my_cmd.data = rtl8125_ocp_read(tp, my_cmd.offset, 4);
205 | rtl8125_oob_mutex_unlock(tp);
206 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
207 | ret = -EFAULT;
208 | break;
209 | }
210 | break;
211 |
212 | case RTL_WRITE_OOB_MAC:
213 | if (my_cmd.len == 0 || my_cmd.len > 4)
214 | return -EOPNOTSUPP;
215 |
216 | rtl8125_oob_mutex_lock(tp);
217 | rtl8125_ocp_write(tp, my_cmd.offset, my_cmd.len, my_cmd.data);
218 | rtl8125_oob_mutex_unlock(tp);
219 | break;
220 |
221 | case RTL_ENABLE_PCI_DIAG:
222 | tp->rtk_enable_diag = 1;
223 |
224 | dprintk("enable rtk diag\n");
225 | break;
226 |
227 | case RTL_DISABLE_PCI_DIAG:
228 | tp->rtk_enable_diag = 0;
229 |
230 | dprintk("disable rtk diag\n");
231 | break;
232 |
233 | case RTL_READ_MAC_OCP:
234 | if (my_cmd.offset % 2)
235 | return -EOPNOTSUPP;
236 |
237 | my_cmd.data = rtl8125_mac_ocp_read(tp, my_cmd.offset);
238 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
239 | ret = -EFAULT;
240 | break;
241 | }
242 | break;
243 |
244 | case RTL_WRITE_MAC_OCP:
245 | if ((my_cmd.offset % 2) || (my_cmd.len != 2))
246 | return -EOPNOTSUPP;
247 |
248 | rtl8125_mac_ocp_write(tp, my_cmd.offset, (u16)my_cmd.data);
249 | break;
250 |
251 | case RTL_DIRECT_READ_PHY_OCP:
252 | my_cmd.data = rtl8125_mdio_prot_direct_read_phy_ocp(tp, my_cmd.offset);
253 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
254 | ret = -EFAULT;
255 | break;
256 | }
257 |
258 | break;
259 |
260 | case RTL_DIRECT_WRITE_PHY_OCP:
261 | rtl8125_mdio_prot_direct_write_phy_ocp(tp, my_cmd.offset, my_cmd.data);
262 | break;
263 |
264 | #ifdef ENABLE_FIBER_SUPPORT
265 | case RTL_READ_FIBER_PHY:
266 | if (!HW_FIBER_STATUS_CONNECTED(tp)) {
267 | ret = -EOPNOTSUPP;
268 | break;
269 | }
270 |
271 | my_cmd.data = rtl8125_fiber_mdio_read(tp, my_cmd.offset);
272 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
273 | ret = -EFAULT;
274 | break;
275 | }
276 |
277 | break;
278 |
279 | case RTL_WRITE_FIBER_PHY:
280 | if (!HW_FIBER_STATUS_CONNECTED(tp)) {
281 | ret = -EOPNOTSUPP;
282 | break;
283 | }
284 |
285 | rtl8125_fiber_mdio_write(tp, my_cmd.offset, my_cmd.data);
286 | break;
287 | #endif /* ENABLE_FIBER_SUPPORT */
288 |
289 | default:
290 | ret = -EOPNOTSUPP;
291 | break;
292 | }
293 |
294 | return ret;
295 | }
296 |
--------------------------------------------------------------------------------
/r8125/src/rtltool.h:
--------------------------------------------------------------------------------
1 | /* SPDX-License-Identifier: GPL-2.0-only */
2 | /*
3 | ################################################################################
4 | #
5 | # r8125 is the Linux device driver released for Realtek 2.5 Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2024 Realtek Semiconductor Corp. All rights reserved.
9 | #
10 | # This program is free software; you can redistribute it and/or modify it
11 | # under the terms of the GNU General Public License as published by the Free
12 | # Software Foundation; either version 2 of the License, or (at your option)
13 | # any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful, but WITHOUT
16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 | # more details.
19 | #
20 | # You should have received a copy of the GNU General Public License along with
21 | # this program; if not, see .
22 | #
23 | # Author:
24 | # Realtek NIC software team
25 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
26 | #
27 | ################################################################################
28 | */
29 |
30 | /************************************************************************************
31 | * This product is covered by one or more of the following patents:
32 | * US6,570,884, US6,115,776, and US6,327,625.
33 | ***********************************************************************************/
34 |
35 | #ifndef _LINUX_RTLTOOL_H
36 | #define _LINUX_RTLTOOL_H
37 |
38 | #define SIOCRTLTOOL SIOCDEVPRIVATE+1
39 |
40 | enum rtl_cmd {
41 | RTLTOOL_READ_MAC=0,
42 | RTLTOOL_WRITE_MAC,
43 | RTLTOOL_READ_PHY,
44 | RTLTOOL_WRITE_PHY,
45 | RTLTOOL_READ_EPHY,
46 | RTLTOOL_WRITE_EPHY,
47 | RTLTOOL_READ_ERI,
48 | RTLTOOL_WRITE_ERI,
49 | RTLTOOL_READ_PCI,
50 | RTLTOOL_WRITE_PCI,
51 | RTLTOOL_READ_EEPROM,
52 | RTLTOOL_WRITE_EEPROM,
53 |
54 | RTL_READ_OOB_MAC,
55 | RTL_WRITE_OOB_MAC,
56 |
57 | RTL_ENABLE_PCI_DIAG,
58 | RTL_DISABLE_PCI_DIAG,
59 |
60 | RTL_READ_MAC_OCP,
61 | RTL_WRITE_MAC_OCP,
62 |
63 | RTL_DIRECT_READ_PHY_OCP,
64 | RTL_DIRECT_WRITE_PHY_OCP,
65 |
66 | RTL_READ_FIBER_PHY,
67 | RTL_WRITE_FIBER_PHY,
68 |
69 | RTLTOOL_INVALID
70 | };
71 |
72 | struct rtltool_cmd {
73 | __u32 cmd;
74 | __u32 offset;
75 | __u32 len;
76 | __u32 data;
77 | };
78 |
79 | enum mode_access {
80 | MODE_NONE=0,
81 | MODE_READ,
82 | MODE_WRITE
83 | };
84 |
85 | #ifdef __KERNEL__
86 | int rtl8125_tool_ioctl(struct rtl8125_private *tp, struct ifreq *ifr);
87 | #endif
88 |
89 | #endif /* _LINUX_RTLTOOL_H */
90 |
--------------------------------------------------------------------------------