├── LICENSE
├── README.md
├── build-script
└── build-r8125.sh
└── r8125
├── Makefile
├── Makefile_linux24x
├── r8125.h
├── r8125_dash.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
/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 | # Realtek RTL8125 NIC driver for ESXi 6.7
2 |
3 | This source code is based on realtek official source, VMware-ESXI-67U3-ODP and VMware-TOOLS-10.2.0-ODP.
4 |
5 | Just do these steps:
6 | - Prepare the building environment, I did it on CentOS 7
7 | - Log in with root, make a folder name 'build' on /, make folder toolchain and vsphere in /build.
8 | - Copy and extract gcc-4.8.0, binutils-2.22, glibc-2.3.4-2.41 to /build/toolchain/src
9 | - Compile the toolchain, dest path is /build/toolchain/lin64
10 | - Extract and copy vmkdrivers-gpl from 67U3-ODP to /build/vsphere
11 | - Copy build-r8125.sh to /build/vsphere/vmkdrivers-gpl/
12 | - Copy r8125 folder to /build/vsphere/vmkdrivers-gpl/vmkdrivers/src_9/drivers/net
13 | - Run build-r8125.sh
14 |
--------------------------------------------------------------------------------
/build-script/build-r8125.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 |
3 | rm -rf BLD/build/vmkdriver-r8125
4 |
5 | # Use gcc version 4.4.3-2
6 | # Below is the internal VMWare location. Please change as required for your
7 | # installed location.
8 | CC=/build/toolchain/lin64/gcc-4.8.0/bin/x86_64-linux-gcc
9 |
10 | CC_OPTS=""
11 | #"-DLINUX -D__KERNEL__ -DMODULE -DMODVERSIONS -DEXPORT_SYMTAB"
12 | #-DCONFIG_R8125_NAPI -DCONFIG_R8125_VLAN -DENABLE_EEE -DENABLE_TX_NO_CLOSE"
13 |
14 | # Use ld from binutils-2.20.1-1
15 | # Below is the internal VMWare location. Please change as required for your
16 | # installed location.
17 | LD=/build/toolchain/lin64/binutils-2.22/bin/x86_64-linux-ld
18 |
19 | # PR# 976913 requested that OSS binaries be stripped of debug
20 | LD_OPTS=--strip-debug
21 |
22 | SYS_ROOT=/nowhere
23 |
24 | I_SYSTEM=/build/toolchain/lin64/gcc-4.8.0/lib/gcc/x86_64-linux/4.8.0/include
25 |
26 | # Use GNU grep 2.5.1
27 | GREP=grep
28 | # Use GNU sed 4.5.1
29 | SED=sed
30 | # Use GNU xargs 4.2.27
31 | XARGS=xargs
32 | # Use mkdir from GNU coreutils 5.97
33 | MKDIR=mkdir
34 |
35 | # Create output directories
36 | $GREP -v -e "SED" build-r8125.sh \
37 | | $GREP -o -e "-o [^ ]*\." \
38 | | $SED -e 's?-o \(.*\)/[^/]*\.?\1?' \
39 | | $GREP -v -e "\*" \
40 | | $XARGS $MKDIR -p
41 |
42 |
43 | # Compiler flags assume being compiled natively on a x86-64 machine
44 |
45 | $CC -DLINUX -D__KERNEL__ -DMODULE -DMODVERSIONS -DEXPORT_SYMTAB -DENABLE_TX_NO_CLOSE -DCONFIG_R8125_NAPI -DCONFIG_R8125_VLAN --sysroot=$SYS_ROOT -fwrapv -pipe -fno-strict-aliasing -Wno-unused-but-set-variable -fno-working-directory -g -ggdb3 -O2 -mcmodel=smallhigh -Wall -Werror -Wstrict-prototypes -fno-strict-aliasing -freg-struct-return -falign-jumps=1 -falign-functions=4 -falign-loops=1 -m64 -mno-red-zone -mpreferred-stack-boundary=4 -minline-all-stringops -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mcld -finline-limit=2000 -fno-common -ffreestanding -nostdinc -fomit-frame-pointer -nostdlib --sysroot=$SYS_ROOT -Wno-error -Wdeclaration-after-statement -Wno-pointer-sign -Wno-strict-prototypes -Wno-enum-compare -Wno-switch -Wno-declaration-after-statement -Wno-declaration-after-statement -Wno-declaration-after-statement -DCONFIG_COMPAT -DCONFIG_DCB -DCONFIG_FCOE -DCONFIG_INET_LRO -DCONFIG_NETDEVICES_MULTIQUEUE -DCONFIG_PCI_IOV -DCONFIG_PCI_MSI -DCONFIG_PROC_FS -DCPU=x86-64 -DESX3_NETWORKING_NOT_DONE_YET -DGPLED_CODE -DHAVE_DCBNL_OPS_GETAPP -DHAVE_IPLINK_VF_CONFIG -DKBUILD_MODNAME=\"r8125\" -DLINUX_MODULE_AUX_HEAP_NAME=vmklnx_r8125 -DLINUX_MODULE_HEAP_INITIAL=1024*100 -DLINUX_MODULE_HEAP_MAX=64*1024*1024 -DLINUX_MODULE_HEAP_NAME=vmklnx_r8125 -DLINUX_MODULE_SKB_HEAP -DLINUX_MODULE_SKB_HEAP_INITIAL=512*1024 -DLINUX_MODULE_SKB_HEAP_MAX=128*1024*1024 -DLINUX_MODULE_VERSION=\"9.007.01\" -DMODULE -DNET_DRIVER -DNO_FLOATING_POINT -DVMKERNEL -DVMKERNEL_MODULE -DVMKLINUX_MODULE_HEAP_ANY_MEM -DVMK_DEVKIT_HAS_API_VMKAPI_BASE -DVMK_DEVKIT_HAS_API_VMKAPI_DEVICE -DVMK_DEVKIT_HAS_API_VMKAPI_ISCSI -DVMK_DEVKIT_HAS_API_VMKAPI_NET -DVMK_DEVKIT_HAS_API_VMKAPI_RDMA -DVMK_DEVKIT_HAS_API_VMKAPI_SCSI -DVMK_DEVKIT_HAS_API_VMKAPI_SOCKETS -DVMK_DEVKIT_IS_DDK -DVMK_DEVKIT_USES_BINARY_COMPATIBLE_APIS -DVMK_DEVKIT_USES_PUBLIC_APIS -DVMNIX -DVMX86_RELEASE -DVMX86_SERVER -D_LINUX -D__KERNEL__ -D__VMKERNEL_MODULE__ -D__VMKERNEL__ -D__VMKLNX__ -D__VMK_GCC_BUG_ALIGNMENT_PADDING__ -D__VMWARE__ -isystem $I_SYSTEM -Ivmkdrivers/src_9/drivers/net/r8125 -IBLD/build/HEADERS/vmkdrivers-vmkernel/vmkernel64/release -IBLD/build/version -Ivmkdrivers/src_92/include -Ivmkdrivers/src_92/include/vmklinux_92 -IBLD/build/HEADERS/92-vmkdrivers-asm-x64/vmkernel64/release -Ivmkdrivers/src_92/drivers/net -IBLD/build/HEADERS/vmkapi-v2_3_0_0-all-public-bincomp/generic/release -IBLD/build/HEADERS/vmkapi-current-all-public-bincomp/generic/release -include vmkdrivers/src_92/include/linux/autoconf.h -c -o BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_9/drivers/net/r8125/r8125_n.o vmkdrivers/src_9/drivers/net/r8125/r8125_n.c
46 | $CC -DLINUX -D__KERNEL__ -DMODULE -DMODVERSIONS -DEXPORT_SYMTAB -DENABLE_TX_NO_CLOSE -DCONFIG_R8125_NAPI -DCONFIG_R8125_VLAN --sysroot=$SYS_ROOT -fwrapv -pipe -fno-strict-aliasing -Wno-unused-but-set-variable -fno-working-directory -g -ggdb3 -O2 -mcmodel=smallhigh -Wall -Werror -Wstrict-prototypes -fno-strict-aliasing -freg-struct-return -falign-jumps=1 -falign-functions=4 -falign-loops=1 -m64 -mno-red-zone -mpreferred-stack-boundary=4 -minline-all-stringops -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mcld -finline-limit=2000 -fno-common -ffreestanding -nostdinc -fomit-frame-pointer -nostdlib --sysroot=$SYS_ROOT -Wno-error -Wdeclaration-after-statement -Wno-pointer-sign -Wno-strict-prototypes -Wno-enum-compare -Wno-switch -Wno-declaration-after-statement -Wno-declaration-after-statement -Wno-declaration-after-statement -DCONFIG_COMPAT -DCONFIG_DCB -DCONFIG_FCOE -DCONFIG_INET_LRO -DCONFIG_NETDEVICES_MULTIQUEUE -DCONFIG_PCI_IOV -DCONFIG_PCI_MSI -DCONFIG_PROC_FS -DCPU=x86-64 -DESX3_NETWORKING_NOT_DONE_YET -DGPLED_CODE -DHAVE_DCBNL_OPS_GETAPP -DHAVE_IPLINK_VF_CONFIG -DKBUILD_MODNAME=\"r8125\" -DLINUX_MODULE_AUX_HEAP_NAME=vmklnx_r8125 -DLINUX_MODULE_HEAP_INITIAL=1024*100 -DLINUX_MODULE_HEAP_MAX=64*1024*1024 -DLINUX_MODULE_HEAP_NAME=vmklnx_r8125 -DLINUX_MODULE_SKB_HEAP -DLINUX_MODULE_SKB_HEAP_INITIAL=512*1024 -DLINUX_MODULE_SKB_HEAP_MAX=128*1024*1024 -DLINUX_MODULE_VERSION=\"9.007.01\" -DMODULE -DNET_DRIVER -DNO_FLOATING_POINT -DVMKERNEL -DVMKERNEL_MODULE -DVMKLINUX_MODULE_HEAP_ANY_MEM -DVMK_DEVKIT_HAS_API_VMKAPI_BASE -DVMK_DEVKIT_HAS_API_VMKAPI_DEVICE -DVMK_DEVKIT_HAS_API_VMKAPI_ISCSI -DVMK_DEVKIT_HAS_API_VMKAPI_NET -DVMK_DEVKIT_HAS_API_VMKAPI_RDMA -DVMK_DEVKIT_HAS_API_VMKAPI_SCSI -DVMK_DEVKIT_HAS_API_VMKAPI_SOCKETS -DVMK_DEVKIT_IS_DDK -DVMK_DEVKIT_USES_BINARY_COMPATIBLE_APIS -DVMK_DEVKIT_USES_PUBLIC_APIS -DVMNIX -DVMX86_RELEASE -DVMX86_SERVER -D_LINUX -D__KERNEL__ -D__VMKERNEL_MODULE__ -D__VMKERNEL__ -D__VMKLNX__ -D__VMK_GCC_BUG_ALIGNMENT_PADDING__ -D__VMWARE__ -isystem $I_SYSTEM -Ivmkdrivers/src_9/drivers/net/r8125 -IBLD/build/HEADERS/vmkdrivers-vmkernel/vmkernel64/release -IBLD/build/version -Ivmkdrivers/src_92/include -Ivmkdrivers/src_92/include/vmklinux_92 -IBLD/build/HEADERS/92-vmkdrivers-asm-x64/vmkernel64/release -Ivmkdrivers/src_92/drivers/net -IBLD/build/HEADERS/vmkapi-v2_3_0_0-all-public-bincomp/generic/release -IBLD/build/HEADERS/vmkapi-current-all-public-bincomp/generic/release -include vmkdrivers/src_92/include/linux/autoconf.h -c -o BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_9/drivers/net/r8125/rtl_eeprom.o vmkdrivers/src_9/drivers/net/r8125/rtl_eeprom.c
47 | $CC -DLINUX -D__KERNEL__ -DMODULE -DMODVERSIONS -DEXPORT_SYMTAB -DENABLE_TX_NO_CLOSE -DCONFIG_R8125_NAPI -DCONFIG_R8125_VLAN --sysroot=$SYS_ROOT -fwrapv -pipe -fno-strict-aliasing -Wno-unused-but-set-variable -fno-working-directory -g -ggdb3 -O2 -mcmodel=smallhigh -Wall -Werror -Wstrict-prototypes -fno-strict-aliasing -freg-struct-return -falign-jumps=1 -falign-functions=4 -falign-loops=1 -m64 -mno-red-zone -mpreferred-stack-boundary=4 -minline-all-stringops -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mcld -finline-limit=2000 -fno-common -ffreestanding -nostdinc -fomit-frame-pointer -nostdlib --sysroot=$SYS_ROOT -Wno-error -Wdeclaration-after-statement -Wno-pointer-sign -Wno-strict-prototypes -Wno-enum-compare -Wno-switch -Wno-declaration-after-statement -Wno-declaration-after-statement -Wno-declaration-after-statement -DCONFIG_COMPAT -DCONFIG_DCB -DCONFIG_FCOE -DCONFIG_INET_LRO -DCONFIG_NETDEVICES_MULTIQUEUE -DCONFIG_PCI_IOV -DCONFIG_PCI_MSI -DCONFIG_PROC_FS -DCPU=x86-64 -DESX3_NETWORKING_NOT_DONE_YET -DGPLED_CODE -DHAVE_DCBNL_OPS_GETAPP -DHAVE_IPLINK_VF_CONFIG -DKBUILD_MODNAME=\"r8125\" -DLINUX_MODULE_AUX_HEAP_NAME=vmklnx_r8125 -DLINUX_MODULE_HEAP_INITIAL=1024*100 -DLINUX_MODULE_HEAP_MAX=64*1024*1024 -DLINUX_MODULE_HEAP_NAME=vmklnx_r8125 -DLINUX_MODULE_SKB_HEAP -DLINUX_MODULE_SKB_HEAP_INITIAL=512*1024 -DLINUX_MODULE_SKB_HEAP_MAX=128*1024*1024 -DLINUX_MODULE_VERSION=\"9.007.01\" -DMODULE -DNET_DRIVER -DNO_FLOATING_POINT -DVMKERNEL -DVMKERNEL_MODULE -DVMKLINUX_MODULE_HEAP_ANY_MEM -DVMK_DEVKIT_HAS_API_VMKAPI_BASE -DVMK_DEVKIT_HAS_API_VMKAPI_DEVICE -DVMK_DEVKIT_HAS_API_VMKAPI_ISCSI -DVMK_DEVKIT_HAS_API_VMKAPI_NET -DVMK_DEVKIT_HAS_API_VMKAPI_RDMA -DVMK_DEVKIT_HAS_API_VMKAPI_SCSI -DVMK_DEVKIT_HAS_API_VMKAPI_SOCKETS -DVMK_DEVKIT_IS_DDK -DVMK_DEVKIT_USES_BINARY_COMPATIBLE_APIS -DVMK_DEVKIT_USES_PUBLIC_APIS -DVMNIX -DVMX86_RELEASE -DVMX86_SERVER -D_LINUX -D__KERNEL__ -D__VMKERNEL_MODULE__ -D__VMKERNEL__ -D__VMKLNX__ -D__VMK_GCC_BUG_ALIGNMENT_PADDING__ -D__VMWARE__ -isystem $I_SYSTEM -Ivmkdrivers/src_9/drivers/net/r8125 -IBLD/build/HEADERS/vmkdrivers-vmkernel/vmkernel64/release -IBLD/build/version -Ivmkdrivers/src_92/include -Ivmkdrivers/src_92/include/vmklinux_92 -IBLD/build/HEADERS/92-vmkdrivers-asm-x64/vmkernel64/release -Ivmkdrivers/src_92/drivers/net -IBLD/build/HEADERS/vmkapi-v2_3_0_0-all-public-bincomp/generic/release -IBLD/build/HEADERS/vmkapi-current-all-public-bincomp/generic/release -include vmkdrivers/src_92/include/linux/autoconf.h -c -o BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_9/drivers/net/r8125/rtltool.o vmkdrivers/src_9/drivers/net/r8125/rtltool.c
48 | $CC -DLINUX -D__KERNEL__ -DMODULE -DMODVERSIONS -DEXPORT_SYMTAB --sysroot=$SYS_ROOT -fwrapv -pipe -fno-strict-aliasing -Wno-unused-but-set-variable -fno-working-directory -g -ggdb3 -O2 -mcmodel=smallhigh -Wall -Werror -Wstrict-prototypes -fno-strict-aliasing -freg-struct-return -falign-jumps=1 -falign-functions=4 -falign-loops=1 -m64 -mno-red-zone -mpreferred-stack-boundary=4 -minline-all-stringops -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mcld -finline-limit=2000 -fno-common -ffreestanding -nostdinc -fomit-frame-pointer -nostdlib --sysroot=$SYS_ROOT -Wno-error -Wdeclaration-after-statement -Wno-pointer-sign -Wno-strict-prototypes -Wno-enum-compare -Wno-switch -Wno-declaration-after-statement -Wno-declaration-after-statement -Wno-declaration-after-statement -DCONFIG_COMPAT -DCONFIG_DCB -DCONFIG_FCOE -DCONFIG_INET_LRO -DCONFIG_NETDEVICES_MULTIQUEUE -DCONFIG_PCI_IOV -DCONFIG_PCI_MSI -DCONFIG_PROC_FS -DCPU=x86-64 -DESX3_NETWORKING_NOT_DONE_YET -DGPLED_CODE -DHAVE_DCBNL_OPS_GETAPP -DHAVE_IPLINK_VF_CONFIG -DKBUILD_MODNAME=\"r8125\" -DLINUX_MODULE_AUX_HEAP_NAME=vmklnx_r8125 -DLINUX_MODULE_HEAP_INITIAL=1024*100 -DLINUX_MODULE_HEAP_MAX=64*1024*1024 -DLINUX_MODULE_HEAP_NAME=vmklnx_r8125 -DLINUX_MODULE_SKB_HEAP -DLINUX_MODULE_SKB_HEAP_INITIAL=512*1024 -DLINUX_MODULE_SKB_HEAP_MAX=128*1024*1024 -DLINUX_MODULE_VERSION=\"6.7U3\" -DMODULE -DNET_DRIVER -DNO_FLOATING_POINT -DVMKERNEL -DVMKERNEL_MODULE -DVMKLINUX_MODULE_HEAP_ANY_MEM -DVMK_DEVKIT_HAS_API_VMKAPI_BASE -DVMK_DEVKIT_HAS_API_VMKAPI_DEVICE -DVMK_DEVKIT_HAS_API_VMKAPI_ISCSI -DVMK_DEVKIT_HAS_API_VMKAPI_NET -DVMK_DEVKIT_HAS_API_VMKAPI_RDMA -DVMK_DEVKIT_HAS_API_VMKAPI_SCSI -DVMK_DEVKIT_HAS_API_VMKAPI_SOCKETS -DVMK_DEVKIT_IS_DDK -DVMK_DEVKIT_USES_BINARY_COMPATIBLE_APIS -DVMK_DEVKIT_USES_PUBLIC_APIS -DVMNIX -DVMX86_RELEASE -DVMX86_SERVER -D_LINUX -D__KERNEL__ -D__VMKERNEL_MODULE__ -D__VMKERNEL__ -D__VMKLNX__ -D__VMK_GCC_BUG_ALIGNMENT_PADDING__ -D__VMWARE__ -isystem $I_SYSTEM -Ivmkdrivers/src_9/drivers/net/r8125 -IBLD/build/HEADERS/vmkdrivers-vmkernel/vmkernel64/release -IBLD/build/version -Ivmkdrivers/src_92/include -Ivmkdrivers/src_92/include/vmklinux_92 -IBLD/build/HEADERS/92-vmkdrivers-asm-x64/vmkernel64/release -Ivmkdrivers/src_92/drivers/net -IBLD/build/HEADERS/vmkapi-v2_3_0_0-all-public-bincomp/generic/release -IBLD/build/HEADERS/vmkapi-current-all-public-bincomp/generic/release -include vmkdrivers/src_92/include/linux/autoconf.h -c -o BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_92/common/vmklinux_module.o vmkdrivers/src_92/common/vmklinux_module.c
49 | $LD $LD_OPTS -r -o BLD/build/vmkdriver-r8125/release/vmkernel64/r8125 --whole-archive BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_9/drivers/net/r8125/r8125_n.o BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_9/drivers/net/r8125/rtl_eeprom.o BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_9/drivers/net/r8125/rtltool.o BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_92/common/vmklinux_module.o
50 |
51 | cp /build/vmkdrivers-gpl/BLD/build/vmkdriver-r8125/release/vmkernel64/r8125 ./
52 |
--------------------------------------------------------------------------------
/r8125/Makefile:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: GPL-2.0-only
2 | ################################################################################
3 | #
4 | # r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
5 | # controllers with PCI-Express interface.
6 | #
7 | # Copyright(c) 2021 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_REALWOW_SUPPORT = n
35 | ENABLE_DASH_SUPPORT = n
36 | ENABLE_DASH_PRINTER_SUPPORT = n
37 | CONFIG_DOWN_SPEED_100 = n
38 | CONFIG_ASPM = y
39 | ENABLE_S5WOL = y
40 | ENABLE_S5_KEEP_CURR_MAC = n
41 | ENABLE_EEE = y
42 | ENABLE_S0_MAGIC_PACKET = n
43 | ENABLE_TX_NO_CLOSE = y
44 | ENABLE_MULTIPLE_TX_QUEUE = n
45 | ENABLE_PTP_SUPPORT = n
46 | ENABLE_PTP_MASTER_MODE = n
47 | ENABLE_RSS_SUPPORT = n
48 | ENABLE_LIB_SUPPORT = n
49 | ENABLE_USE_FIRMWARE_FILE = n
50 | DISABLE_PM_SUPPORT = n
51 | DISABLE_MULTI_MSIX_VECTOR = n
52 |
53 | ifneq ($(KERNELRELEASE),)
54 | obj-m := r8125.o
55 | r8125-objs := r8125_n.o rtl_eeprom.o rtltool.o
56 | ifeq ($(CONFIG_SOC_LAN), y)
57 | EXTRA_CFLAGS += -DCONFIG_SOC_LAN
58 | endif
59 | ifeq ($(ENABLE_REALWOW_SUPPORT), y)
60 | r8125-objs += r8125_realwow.o
61 | EXTRA_CFLAGS += -DENABLE_REALWOW_SUPPORT
62 | endif
63 | ifeq ($(ENABLE_DASH_SUPPORT), y)
64 | r8125-objs += r8125_dash.o
65 | EXTRA_CFLAGS += -DENABLE_DASH_SUPPORT
66 | endif
67 | ifeq ($(ENABLE_DASH_PRINTER_SUPPORT), y)
68 | r8125-objs += r8125_dash.o
69 | EXTRA_CFLAGS += -DENABLE_DASH_SUPPORT -DENABLE_DASH_PRINTER_SUPPORT
70 | endif
71 | EXTRA_CFLAGS += -DCONFIG_R8125_NAPI
72 | EXTRA_CFLAGS += -DCONFIG_R8125_VLAN
73 | ifeq ($(CONFIG_DOWN_SPEED_100), y)
74 | EXTRA_CFLAGS += -DCONFIG_DOWN_SPEED_100
75 | endif
76 | ifeq ($(CONFIG_ASPM), y)
77 | EXTRA_CFLAGS += -DCONFIG_ASPM
78 | endif
79 | ifeq ($(ENABLE_S5WOL), y)
80 | EXTRA_CFLAGS += -DENABLE_S5WOL
81 | endif
82 | ifeq ($(ENABLE_S5_KEEP_CURR_MAC), y)
83 | EXTRA_CFLAGS += -DENABLE_S5_KEEP_CURR_MAC
84 | endif
85 | ifeq ($(ENABLE_EEE), y)
86 | EXTRA_CFLAGS += -DENABLE_EEE
87 | endif
88 | ifeq ($(ENABLE_S0_MAGIC_PACKET), y)
89 | EXTRA_CFLAGS += -DENABLE_S0_MAGIC_PACKET
90 | endif
91 | ifeq ($(ENABLE_TX_NO_CLOSE), y)
92 | EXTRA_CFLAGS += -DENABLE_TX_NO_CLOSE
93 | endif
94 | ifeq ($(ENABLE_MULTIPLE_TX_QUEUE), y)
95 | EXTRA_CFLAGS += -DENABLE_MULTIPLE_TX_QUEUE
96 | endif
97 | ifeq ($(ENABLE_PTP_SUPPORT), y)
98 | r8125-objs += r8125_ptp.o
99 | EXTRA_CFLAGS += -DENABLE_PTP_SUPPORT
100 | endif
101 | ifeq ($(ENABLE_PTP_MASTER_MODE), y)
102 | EXTRA_CFLAGS += -DENABLE_PTP_MASTER_MODE
103 | endif
104 | ifeq ($(ENABLE_RSS_SUPPORT), y)
105 | r8125-objs += r8125_rss.o
106 | EXTRA_CFLAGS += -DENABLE_RSS_SUPPORT
107 | endif
108 | ifeq ($(ENABLE_LIB_SUPPORT), y)
109 | r8125-objs += r8125_lib.o
110 | EXTRA_CFLAGS += -DENABLE_LIB_SUPPORT
111 | endif
112 | ifeq ($(ENABLE_USE_FIRMWARE_FILE), y)
113 | r8125-objs += r8125_firmware.o
114 | EXTRA_CFLAGS += -DENABLE_USE_FIRMWARE_FILE
115 | endif
116 | ifeq ($(DISABLE_PM_SUPPORT), y)
117 | EXTRA_CFLAGS += -DDISABLE_PM_SUPPORT
118 | endif
119 | ifeq ($(DISABLE_MULTI_MSIX_VECTOR), y)
120 | EXTRA_CFLAGS += -DDISABLE_MULTI_MSIX_VECTOR
121 | endif
122 | else
123 | BASEDIR := /lib/modules/$(shell uname -r)
124 | KERNELDIR ?= $(BASEDIR)/build
125 | PWD :=$(shell pwd)
126 | DRIVERDIR := $(shell find $(BASEDIR)/kernel/drivers/net/ethernet -name realtek -type d)
127 | ifeq ($(DRIVERDIR),)
128 | DRIVERDIR := $(shell find $(BASEDIR)/kernel/drivers/net -name realtek -type d)
129 | endif
130 | ifeq ($(DRIVERDIR),)
131 | DRIVERDIR := $(BASEDIR)/kernel/drivers/net
132 | endif
133 | RTKDIR := $(subst $(BASEDIR)/,,$(DRIVERDIR))
134 |
135 | KERNEL_GCC_VERSION := $(shell cat /proc/version | sed -n 's/.*gcc version \([[:digit:]]\.[[:digit:]]\.[[:digit:]]\).*/\1/p')
136 | CCVERSION = $(shell $(CC) -dumpversion)
137 |
138 | KVER = $(shell uname -r)
139 | KMAJ = $(shell echo $(KVER) | \
140 | sed -e 's/^\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*.*/\1/')
141 | KMIN = $(shell echo $(KVER) | \
142 | sed -e 's/^[0-9][0-9]*\.\([0-9][0-9]*\)\.[0-9][0-9]*.*/\1/')
143 | KREV = $(shell echo $(KVER) | \
144 | sed -e 's/^[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/')
145 |
146 | kver_ge = $(shell \
147 | echo test | awk '{if($(KMAJ) < $(1)) {print 0} else { \
148 | if($(KMAJ) > $(1)) {print 1} else { \
149 | if($(KMIN) < $(2)) {print 0} else { \
150 | if($(KMIN) > $(2)) {print 1} else { \
151 | if($(KREV) < $(3)) {print 0} else { print 1 } \
152 | }}}}}' \
153 | )
154 |
155 | .PHONY: all
156 | all: print_vars clean modules install
157 |
158 | print_vars:
159 | @echo
160 | @echo "CC: " $(CC)
161 | @echo "CCVERSION: " $(CCVERSION)
162 | @echo "KERNEL_GCC_VERSION: " $(KERNEL_GCC_VERSION)
163 | @echo "KVER: " $(KVER)
164 | @echo "KMAJ: " $(KMAJ)
165 | @echo "KMIN: " $(KMIN)
166 | @echo "KREV: " $(KREV)
167 | @echo "BASEDIR: " $(BASEDIR)
168 | @echo "DRIVERDIR: " $(DRIVERDIR)
169 | @echo "PWD: " $(PWD)
170 | @echo "RTKDIR: " $(RTKDIR)
171 | @echo
172 |
173 | .PHONY:modules
174 | modules:
175 | #ifeq ($(call kver_ge,5,0,0),1)
176 | $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
177 | #else
178 | # $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) modules
179 | #endif
180 |
181 | .PHONY:clean
182 | clean:
183 | #ifeq ($(call kver_ge,5,0,0),1)
184 | $(MAKE) -C $(KERNELDIR) M=$(PWD) clean
185 | #else
186 | # $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) clean
187 | #endif
188 |
189 | .PHONY:install
190 | install:
191 | #ifeq ($(call kver_ge,5,0,0),1)
192 | $(MAKE) -C $(KERNELDIR) M=$(PWD) INSTALL_MOD_DIR=$(RTKDIR) modules_install
193 | #else
194 | # $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) INSTALL_MOD_DIR=$(RTKDIR) modules_install
195 | #endif
196 |
197 | endif
198 |
--------------------------------------------------------------------------------
/r8125/Makefile_linux24x:
--------------------------------------------------------------------------------
1 | # SPDX-License-Identifier: GPL-2.0-only
2 | ################################################################################
3 | #
4 | # r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
5 | # controllers with PCI-Express interface.
6 | #
7 | # Copyright(c) 2021 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/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.5Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2021 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 |
168 |
169 | #define OCP_REG_CONFIG0_DASHEN BIT_15
170 | #define OCP_REG_CONFIG0_OOBRESET BIT_14
171 | #define OCP_REG_CONFIG0_APRDY BIT_13
172 | #define OCP_REG_CONFIG0_FIRMWARERDY BIT_12
173 | #define OCP_REG_CONFIG0_DRIVERRDY BIT_11
174 | #define OCP_REG_CONFIG0_OOB_WDT BIT_9
175 | #define OCP_REG_CONFIG0_DRV_WAIT_OOB BIT_8
176 | #define OCP_REG_CONFIG0_TLSEN BIT_7
177 |
178 | #define HW_DASH_SUPPORT_DASH(_M) ((_M)->HwSuppDashVer > 0 )
179 | #define HW_DASH_SUPPORT_TYPE_1(_M) ((_M)->HwSuppDashVer == 1 )
180 | #define HW_DASH_SUPPORT_TYPE_2(_M) ((_M)->HwSuppDashVer == 2 )
181 | #define HW_DASH_SUPPORT_TYPE_3(_M) ((_M)->HwSuppDashVer == 3 )
182 |
183 | #define RECV_FROM_FW_BUF_SIZE (1520)
184 | #define SEND_TO_FW_BUF_SIZE (1520)
185 |
186 | #define RX_DASH_FROM_FW_OWN BIT_15
187 | #define TX_DASH_SEND_FW_OWN BIT_15
188 | #define TX_DASH_SEND_FW_OWN_HIGHBYTE BIT_7
189 |
190 | #define TXS_CC3_0 (BIT_0|BIT_1|BIT_2|BIT_3)
191 | #define TXS_EXC BIT_4
192 | #define TXS_LNKF BIT_5
193 | #define TXS_OWC BIT_6
194 | #define TXS_TES BIT_7
195 | #define TXS_UNF BIT_9
196 | #define TXS_LGSEN BIT_11
197 | #define TXS_LS BIT_12
198 | #define TXS_FS BIT_13
199 | #define TXS_EOR BIT_14
200 | #define TXS_OWN BIT_15
201 |
202 | #define TPPool_HRDY 0x20
203 |
204 | #define HostReqReg (0xC0)
205 | #define SystemMasterDescStartAddrLow (0xF0)
206 | #define SystemMasterDescStartAddrHigh (0xF4)
207 | #define SystemSlaveDescStartAddrLow (0xF8)
208 | #define SystemSlaveDescStartAddrHigh (0xFC)
209 |
210 | //DASH Request Type
211 | #define WSMANREG 0x01
212 | #define OSPUSHDATA 0x02
213 |
214 | #define RXS_OWN BIT_15
215 | #define RXS_EOR BIT_14
216 | #define RXS_FS BIT_13
217 | #define RXS_LS BIT_12
218 |
219 | #define ISRIMR_DP_DASH_OK BIT_15
220 | #define ISRIMR_DP_HOST_OK BIT_13
221 | #define ISRIMR_DP_REQSYS_OK BIT_11
222 |
223 | #define ISRIMR_DASH_INTR_EN BIT_12
224 | #define ISRIMR_DASH_INTR_CMAC_RESET BIT_15
225 |
226 | #define ISRIMR_DASH_TYPE2_ROK BIT_0
227 | #define ISRIMR_DASH_TYPE2_RDU BIT_1
228 | #define ISRIMR_DASH_TYPE2_TOK BIT_2
229 | #define ISRIMR_DASH_TYPE2_TDU BIT_3
230 | #define ISRIMR_DASH_TYPE2_TX_FIFO_FULL BIT_4
231 | #define ISRIMR_DASH_TYPE2_TX_DISABLE_IDLE BIT_5
232 | #define ISRIMR_DASH_TYPE2_RX_DISABLE_IDLE BIT_6
233 |
234 | #define CMAC_OOB_STOP 0x25
235 | #define CMAC_OOB_INIT 0x26
236 | #define CMAC_OOB_RESET 0x2a
237 |
238 | #define NO_BASE_ADDRESS 0x00000000
239 | #define RTL8168FP_OOBMAC_BASE 0xBAF70000
240 | #define RTL8168FP_CMAC_IOBASE 0xBAF20000
241 | #define RTL8168FP_KVM_BASE 0xBAF80400
242 | #define CMAC_SYNC_REG 0x20
243 | #define CMAC_RXDESC_OFFSET 0x90 //RX: 0x90 - 0x98
244 | #define CMAC_TXDESC_OFFSET 0x98 //TX: 0x98 - 0x9F
245 |
246 | /* cmac write/read MMIO register */
247 | #define RTL_CMAC_W8(tp, reg, val8) writeb ((val8), tp->cmac_ioaddr + (reg))
248 | #define RTL_CMAC_W16(tp, reg, val16) writew ((val16), tp->cmac_ioaddr + (reg))
249 | #define RTL_CMAC_W32(tp, reg, val32) writel ((val32), tp->cmac_ioaddr + (reg))
250 | #define RTL_CMAC_R8(tp, reg) readb (tp->cmac_ioaddr + (reg))
251 | #define RTL_CMAC_R16(tp, reg) readw (tp->cmac_ioaddr + (reg))
252 | #define RTL_CMAC_R32(tp, reg) ((unsigned long) readl (tp->cmac_ioaddr + (reg)))
253 |
254 | int rtl8125_dash_ioctl(struct net_device *dev, struct ifreq *ifr);
255 | void HandleDashInterrupt(struct net_device *dev);
256 | int AllocateDashShareMemory(struct net_device *dev);
257 | void FreeAllocatedDashShareMemory(struct net_device *dev);
258 | void DashHwInit(struct net_device *dev);
259 |
260 |
261 | #endif /* _LINUX_R8125_DASH_H */
262 |
--------------------------------------------------------------------------------
/r8125/r8125_firmware.c:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-2.0-only
2 | /*
3 | ################################################################################
4 | #
5 | # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2021 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 | mdelay(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/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.5Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2021 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/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.5Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2021 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 |
44 | #include "r8125.h"
45 | #include "r8125_ptp.h"
46 |
47 | #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,6,0)
48 | static inline struct timespec timespec64_to_timespec(const struct timespec64 ts64)
49 | {
50 | return *(const struct timespec *)&ts64;
51 | }
52 |
53 | static inline struct timespec64 timespec_to_timespec64(const struct timespec ts)
54 | {
55 | return *(const struct timespec64 *)&ts;
56 | }
57 | #endif
58 |
59 | static int _rtl8125_phc_gettime(struct rtl8125_private *tp, struct timespec64 *ts64)
60 | {
61 | //get local time
62 | RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_LATCHED_LOCAL_TIME | PTP_EXEC_CMD));
63 |
64 | /* nanoseconds */
65 | //0x6808[29:0]
66 | ts64->tv_nsec = (RTL_R32(tp, PTP_SOFT_CONFIG_Time_NS_8125) & 0x3fffffff) +
67 | tp->ptp_adjust;
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 | #if 0
96 | static int _rtl8125_phc_adjtime(struct rtl8125_private *tp, s64 delta)
97 | {
98 | struct timespec64 now, then = ns_to_timespec64(delta);
99 | u32 nsec;
100 | u64 sec;
101 |
102 | _rtl8125_phc_gettime(tp, &now);
103 | now = timespec64_add(now, then);
104 |
105 | nsec = now.tv_nsec & 0x3fffffff;
106 | sec = now.tv_sec & 0x0000ffffffffffff;
107 |
108 | /* nanoseconds */
109 | //0x6808[29:0]
110 | RTL_W32(tp, PTP_SOFT_CONFIG_Time_NS_8125, nsec);
111 |
112 | /* seconds */
113 | //0x680C[47:0]
114 | RTL_W32(tp, PTP_SOFT_CONFIG_Time_S_8125, sec);
115 | RTL_W16(tp, PTP_SOFT_CONFIG_Time_S_8125 + 4, (sec >> 32));
116 |
117 | //adjust local time
118 | //RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_DRIFT_LOCAL_TIME | PTP_EXEC_CMD));
119 | RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_SET_LOCAL_TIME | PTP_EXEC_CMD));
120 |
121 | return 0;
122 | }
123 | #endif
124 |
125 | static int rtl8125_phc_adjtime(struct ptp_clock_info *ptp, s64 delta)
126 | {
127 | struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
128 | unsigned long flags;
129 | //int ret = 0;
130 |
131 | //netif_info(tp, drv, tp->dev, "phc adjust time\n");
132 |
133 | spin_lock_irqsave(&tp->lock, flags);
134 | //ret = _rtl8125_phc_adjtime(tp, delta);
135 | tp->ptp_adjust += delta;
136 | spin_unlock_irqrestore(&tp->lock, flags);
137 |
138 | return 0;
139 | }
140 |
141 | /*
142 | 1ppm means every 125MHz plus 125Hz. It also means every 8ns minus 8ns*10^(-6)
143 |
144 | 1ns=2^30 sub_ns
145 |
146 | 8ns*10^(-6) = 8 * 2^30 sub_ns * 10^(-6) = 2^33 sub_ns * 10^(-6) = 8590 = 0x218E sub_ns
147 |
148 | 1ppb means every 125MHz plus 0.125Hz. It also means every 8ns minus 8ns*10^(-9)
149 |
150 | 1ns=2^30 sub_ns
151 |
152 | 8ns*10^(-9) = 8 * 2^30 sub_ns * 10^(-9) = 2^33 sub_ns * 10^(-9) = 8.59 sub_ns = 9 sub_ns
153 | */
154 | static int _rtl8125_phc_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
155 | {
156 | struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
157 | bool negative = false;
158 | u32 sub_ns;
159 |
160 | if (ppb < 0) {
161 | negative = true;
162 | ppb = -ppb;
163 | }
164 |
165 | sub_ns = ppb * 9;
166 | if (negative) {
167 | sub_ns = -sub_ns;
168 | sub_ns &= 0x3fffffff;
169 | sub_ns |= PTP_ADJUST_TIME_NS_NEGATIVE;
170 | } else
171 | sub_ns &= 0x3fffffff;
172 |
173 | /* nanoseconds */
174 | //0x6808[29:0]
175 | RTL_W32(tp, PTP_SOFT_CONFIG_Time_NS_8125, sub_ns);
176 |
177 | //adjust local time
178 | RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_DRIFT_LOCAL_TIME | PTP_EXEC_CMD));
179 | //RTL_W16(tp, PTP_TIME_CORRECT_CMD_8125, (PTP_CMD_SET_LOCAL_TIME | PTP_EXEC_CMD));
180 |
181 | return 0;
182 | }
183 |
184 | static int rtl8125_phc_adjfreq(struct ptp_clock_info *ptp, s32 delta)
185 | {
186 | //struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
187 |
188 | //netif_info(tp, drv, tp->dev, "phc adjust freq\n");
189 |
190 | if (delta > ptp->max_adj || delta < -ptp->max_adj)
191 | return -EINVAL;
192 |
193 | _rtl8125_phc_adjfreq(ptp, delta);
194 |
195 | return 0;
196 | }
197 |
198 | static int rtl8125_phc_gettime(struct ptp_clock_info *ptp, struct timespec64 *ts64)
199 | {
200 | struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
201 | unsigned long flags;
202 | int ret;
203 |
204 | //netif_info(tp, drv, tp->dev, "phc get ts\n");
205 |
206 | spin_lock_irqsave(&tp->lock, flags);
207 | ret = _rtl8125_phc_gettime(tp, ts64);
208 | spin_unlock_irqrestore(&tp->lock, flags);
209 |
210 | return ret;
211 | }
212 |
213 | static int rtl8125_phc_settime(struct ptp_clock_info *ptp,
214 | const struct timespec64 *ts64)
215 | {
216 | struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
217 | unsigned long flags;
218 | int ret;
219 |
220 | //netif_info(tp, drv, tp->dev, "phc set ts\n");
221 |
222 | spin_lock_irqsave(&tp->lock, flags);
223 | ret = _rtl8125_phc_settime(tp, ts64);
224 | tp->ptp_adjust = 0;
225 | spin_unlock_irqrestore(&tp->lock, flags);
226 |
227 | return ret;
228 | }
229 |
230 | static int rtl8125_phc_enable(struct ptp_clock_info *ptp,
231 | struct ptp_clock_request *rq, int on)
232 | {
233 | struct rtl8125_private *tp = container_of(ptp, struct rtl8125_private, ptp_clock_info);
234 | unsigned long flags;
235 | u16 ptp_ctrl;
236 |
237 | //netif_info(tp, drv, tp->dev, "phc enable type %x on %d\n", rq->type, on);
238 |
239 | switch (rq->type) {
240 | case PTP_CLK_REQ_PPS:
241 | spin_lock_irqsave(&tp->lock, flags);
242 | ptp_ctrl = RTL_R16(tp, PTP_CTRL_8125);
243 | ptp_ctrl &= ~BIT_15;
244 | if (on)
245 | ptp_ctrl |= BIT_14;
246 | else
247 | ptp_ctrl &= ~BIT_14;
248 | RTL_W16(tp, PTP_CTRL_8125, ptp_ctrl);
249 | spin_unlock_irqrestore(&tp->lock, flags);
250 | return 0;
251 | default:
252 | return -EOPNOTSUPP;
253 | }
254 | }
255 |
256 | int rtl8125_get_ts_info(struct net_device *netdev,
257 | struct ethtool_ts_info *info)
258 | {
259 | struct rtl8125_private *tp = netdev_priv(netdev);
260 |
261 | /* we always support timestamping disabled */
262 | info->rx_filters = BIT(HWTSTAMP_FILTER_NONE);
263 |
264 | if (tp->HwSuppPtpVer == 0)
265 | return ethtool_op_get_ts_info(netdev, info);
266 |
267 | info->so_timestamping = SOF_TIMESTAMPING_TX_SOFTWARE |
268 | SOF_TIMESTAMPING_RX_SOFTWARE |
269 | SOF_TIMESTAMPING_SOFTWARE |
270 | SOF_TIMESTAMPING_TX_HARDWARE |
271 | SOF_TIMESTAMPING_RX_HARDWARE |
272 | SOF_TIMESTAMPING_RAW_HARDWARE;
273 |
274 | if (tp->ptp_clock)
275 | info->phc_index = ptp_clock_index(tp->ptp_clock);
276 | else
277 | info->phc_index = -1;
278 |
279 | info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
280 |
281 | info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
282 | BIT(HWTSTAMP_FILTER_PTP_V2_EVENT) |
283 | BIT(HWTSTAMP_FILTER_PTP_V2_L4_EVENT) |
284 | BIT(HWTSTAMP_FILTER_PTP_V2_SYNC) |
285 | BIT(HWTSTAMP_FILTER_PTP_V2_L4_SYNC) |
286 | BIT(HWTSTAMP_FILTER_PTP_V2_DELAY_REQ) |
287 | BIT(HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ);
288 |
289 | return 0;
290 | }
291 |
292 | static const struct ptp_clock_info rtl_ptp_clock_info = {
293 | .owner = THIS_MODULE,
294 | .n_alarm = 0,
295 | .n_ext_ts = 0,
296 | .n_per_out = 0,
297 | .n_pins = 0,
298 | .pps = 1,
299 | .adjfreq = rtl8125_phc_adjfreq,
300 | .adjtime = rtl8125_phc_adjtime,
301 | .gettime64 = rtl8125_phc_gettime,
302 | .settime64 = rtl8125_phc_settime,
303 | .enable = rtl8125_phc_enable,
304 | };
305 |
306 | static int rtl8125_get_tx_ptp_pkt_tstamp(struct rtl8125_private *tp, struct timespec64 *ts64)
307 | {
308 | return _rtl8125_phc_gettime(tp, ts64);
309 | }
310 |
311 | static void rtl8125_ptp_tx_hwtstamp(struct rtl8125_private *tp)
312 | {
313 | struct sk_buff *skb = tp->ptp_tx_skb;
314 | struct skb_shared_hwtstamps shhwtstamps = {0};
315 | struct timespec64 ts64;
316 |
317 | RTL_W8(tp, PTP_ISR_8125, PTP_ISR_TOK | PTP_ISR_TER);
318 |
319 | rtl8125_get_tx_ptp_pkt_tstamp(tp, &ts64);
320 |
321 | /* Upper 32 bits contain s, lower 32 bits contain ns. */
322 | shhwtstamps.hwtstamp = ktime_set(ts64.tv_sec,
323 | ts64.tv_nsec);
324 |
325 | /* Clear the lock early before calling skb_tstamp_tx so that
326 | * applications are not woken up before the lock bit is clear. We use
327 | * a copy of the skb pointer to ensure other threads can't change it
328 | * while we're notifying the stack.
329 | */
330 | tp->ptp_tx_skb = NULL;
331 |
332 | /* Notify the stack and free the skb after we've unlocked */
333 | skb_tstamp_tx(skb, &shhwtstamps);
334 | dev_kfree_skb_any(skb);
335 | }
336 |
337 | #define RTL8125_PTP_TX_TIMEOUT (HZ * 15)
338 | static void rtl8125_ptp_tx_work(struct work_struct *work)
339 | {
340 | struct rtl8125_private *tp = container_of(work, struct rtl8125_private,
341 | ptp_tx_work);
342 | unsigned long flags;
343 |
344 | spin_lock_irqsave(&tp->lock, flags);
345 |
346 | if (!tp->ptp_tx_skb)
347 | goto Exit;
348 |
349 | if (time_is_before_jiffies(tp->ptp_tx_start +
350 | RTL8125_PTP_TX_TIMEOUT)) {
351 | dev_kfree_skb_any(tp->ptp_tx_skb);
352 | tp->ptp_tx_skb = NULL;
353 | tp->tx_hwtstamp_timeouts++;
354 | /* Clear the tx valid bit in TSYNCTXCTL register to enable
355 | * interrupt
356 | */
357 | RTL_W8(tp, PTP_ISR_8125, PTP_ISR_TOK | PTP_ISR_TER);
358 | goto Exit;
359 | }
360 |
361 | if (RTL_R8(tp, PTP_ISR_8125) & (PTP_ISR_TOK))
362 | rtl8125_ptp_tx_hwtstamp(tp);
363 | else
364 | /* reschedule to check later */
365 | schedule_work(&tp->ptp_tx_work);
366 |
367 | Exit:
368 | spin_unlock_irqrestore(&tp->lock, flags);
369 | }
370 |
371 | static int rtl8125_hwtstamp_enable(struct rtl8125_private *tp, bool enable)
372 | {
373 | RTL_W16(tp, PTP_CTRL_8125, 0);
374 | if (enable) {
375 | u16 ptp_ctrl;
376 | struct timespec64 ts64;
377 |
378 | //clear ptp isr
379 | RTL_W8(tp, PTP_ISR_8125, 0xff);
380 | //ptp source 0:gphy 1:mac
381 | rtl8125_mac_ocp_write(tp, 0xDC00, rtl8125_mac_ocp_read(tp, 0xDC00) | BIT_6);
382 | //enable ptp
383 | ptp_ctrl = (BIT_0 | BIT_3 | BIT_4 | BIT_6 | BIT_10 | BIT_12 | BIT_13);
384 | if (tp->ptp_master_mode) {
385 | ptp_ctrl &= ~BIT_13;
386 | ptp_ctrl |= BIT_1;
387 | }
388 | RTL_W16(tp, PTP_CTRL_8125, ptp_ctrl);
389 |
390 | //set system time
391 | /*
392 | if (ktime_to_timespec64_cond(ktime_get_real(), &ts64))
393 | _rtl8125_phc_settime(tp, timespec64_to_timespec(ts64));
394 | */
395 | ktime_get_real_ts64(&ts64);
396 | ts64.tv_nsec += tp->ptp_adjust;
397 | _rtl8125_phc_settime(tp, &ts64);
398 | tp->ptp_adjust = 0;
399 | }
400 |
401 | return 0;
402 | }
403 |
404 | static long rtl8125_ptp_create_clock(struct rtl8125_private *tp)
405 | {
406 | struct net_device *netdev = tp->dev;
407 | long err;
408 |
409 | if (!IS_ERR_OR_NULL(tp->ptp_clock))
410 | return 0;
411 |
412 | if (tp->HwSuppPtpVer == 0) {
413 | tp->ptp_clock = NULL;
414 | return -EOPNOTSUPP;
415 | }
416 |
417 | tp->ptp_clock_info = rtl_ptp_clock_info;
418 | snprintf(tp->ptp_clock_info.name, sizeof(tp->ptp_clock_info.name),
419 | "%pm", tp->dev->dev_addr);
420 | tp->ptp_clock_info.max_adj = 119304647;
421 | tp->ptp_clock = ptp_clock_register(&tp->ptp_clock_info, &tp->pci_dev->dev);
422 | if (IS_ERR(tp->ptp_clock)) {
423 | err = PTR_ERR(tp->ptp_clock);
424 | tp->ptp_clock = NULL;
425 | netif_err(tp, drv, tp->dev, "ptp_clock_register failed\n");
426 | return err;
427 | } else
428 | netif_info(tp, drv, tp->dev, "registered PHC device on %s\n", netdev->name);
429 |
430 | return 0;
431 | }
432 |
433 | void rtl8125_ptp_reset(struct rtl8125_private *tp)
434 | {
435 | if (!tp->ptp_clock)
436 | return;
437 |
438 | netif_info(tp, drv, tp->dev, "reset PHC clock\n");
439 |
440 | rtl8125_hwtstamp_enable(tp, false);
441 | }
442 |
443 | void rtl8125_ptp_init(struct rtl8125_private *tp)
444 | {
445 | /* obtain a PTP device, or re-use an existing device */
446 | if (rtl8125_ptp_create_clock(tp))
447 | return;
448 |
449 | /* we have a clock so we can initialize work now */
450 | INIT_WORK(&tp->ptp_tx_work, rtl8125_ptp_tx_work);
451 |
452 | tp->ptp_adjust = 0;
453 |
454 | /* reset the PTP related hardware bits */
455 | rtl8125_ptp_reset(tp);
456 |
457 | return;
458 | }
459 |
460 | void rtl8125_ptp_suspend(struct rtl8125_private *tp)
461 | {
462 | if (!tp->ptp_clock)
463 | return;
464 |
465 | netif_info(tp, drv, tp->dev, "suspend PHC clock\n");
466 |
467 | rtl8125_hwtstamp_enable(tp, false);
468 |
469 | /* ensure that we cancel any pending PTP Tx work item in progress */
470 | cancel_work_sync(&tp->ptp_tx_work);
471 | }
472 |
473 | void rtl8125_ptp_stop(struct rtl8125_private *tp)
474 | {
475 | struct net_device *netdev = tp->dev;
476 |
477 | netif_info(tp, drv, tp->dev, "stop PHC clock\n");
478 |
479 | /* first, suspend PTP activity */
480 | rtl8125_ptp_suspend(tp);
481 |
482 | /* disable the PTP clock device */
483 | if (tp->ptp_clock) {
484 | ptp_clock_unregister(tp->ptp_clock);
485 | tp->ptp_clock = NULL;
486 | netif_info(tp, drv, tp->dev, "removed PHC on %s\n",
487 | netdev->name);
488 | }
489 | }
490 |
491 | static int rtl8125_set_tstamp(struct net_device *netdev, struct ifreq *ifr)
492 | {
493 | struct rtl8125_private *tp = netdev_priv(netdev);
494 | struct hwtstamp_config config;
495 | bool hwtstamp = 0;
496 |
497 | //netif_info(tp, drv, tp->dev, "ptp set ts\n");
498 |
499 | if (copy_from_user(&config, ifr->ifr_data, sizeof(config)))
500 | return -EFAULT;
501 |
502 | if (config.flags)
503 | return -EINVAL;
504 |
505 | switch (config.tx_type) {
506 | case HWTSTAMP_TX_ON:
507 | hwtstamp = 1;
508 | case HWTSTAMP_TX_OFF:
509 | break;
510 | case HWTSTAMP_TX_ONESTEP_SYNC:
511 | default:
512 | return -ERANGE;
513 | }
514 |
515 | switch (config.rx_filter) {
516 | case HWTSTAMP_FILTER_PTP_V2_EVENT:
517 | case HWTSTAMP_FILTER_PTP_V2_L2_EVENT:
518 | case HWTSTAMP_FILTER_PTP_V2_L4_EVENT:
519 | case HWTSTAMP_FILTER_PTP_V2_SYNC:
520 | case HWTSTAMP_FILTER_PTP_V2_L2_SYNC:
521 | case HWTSTAMP_FILTER_PTP_V2_L4_SYNC:
522 | case HWTSTAMP_FILTER_PTP_V2_DELAY_REQ:
523 | case HWTSTAMP_FILTER_PTP_V2_L2_DELAY_REQ:
524 | case HWTSTAMP_FILTER_PTP_V2_L4_DELAY_REQ:
525 | config.rx_filter = HWTSTAMP_FILTER_PTP_V2_EVENT;
526 | hwtstamp = 1;
527 | case HWTSTAMP_FILTER_NONE:
528 | break;
529 | default:
530 | return -ERANGE;
531 | }
532 |
533 | if (tp->hwtstamp_config.tx_type != config.tx_type ||
534 | tp->hwtstamp_config.rx_filter != config.rx_filter) {
535 | tp->hwtstamp_config = config;
536 | rtl8125_hwtstamp_enable(tp, hwtstamp);
537 | }
538 |
539 | return copy_to_user(ifr->ifr_data, &config,
540 | sizeof(config)) ? -EFAULT : 0;
541 | }
542 |
543 | static int rtl8125_get_tstamp(struct net_device *netdev, struct ifreq *ifr)
544 | {
545 | struct rtl8125_private *tp = netdev_priv(netdev);
546 |
547 | //netif_info(tp, drv, tp->dev, "ptp get ts\n");
548 |
549 | return copy_to_user(ifr->ifr_data, &tp->hwtstamp_config,
550 | sizeof(tp->hwtstamp_config)) ? -EFAULT : 0;
551 | }
552 |
553 | int rtl8125_ptp_ioctl(struct net_device *netdev, struct ifreq *ifr, int cmd)
554 | {
555 | struct rtl8125_private *tp = netdev_priv(netdev);
556 | int ret;
557 | unsigned long flags;
558 |
559 | //netif_info(tp, drv, tp->dev, "ptp ioctl\n");
560 |
561 | ret = 0;
562 | switch (cmd) {
563 | #ifdef ENABLE_PTP_SUPPORT
564 | case SIOCSHWTSTAMP:
565 | spin_lock_irqsave(&tp->lock, flags);
566 | ret = rtl8125_set_tstamp(netdev, ifr);
567 | spin_unlock_irqrestore(&tp->lock, flags);
568 | break;
569 | case SIOCGHWTSTAMP:
570 | spin_lock_irqsave(&tp->lock, flags);
571 | ret = rtl8125_get_tstamp(netdev, ifr);
572 | spin_unlock_irqrestore(&tp->lock, flags);
573 | break;
574 | #endif
575 | default:
576 | ret = -EOPNOTSUPP;
577 | break;
578 | }
579 |
580 | return ret;
581 | }
582 |
583 | void rtl8125_rx_ptp_pktstamp(struct rtl8125_private *tp, struct sk_buff *skb,
584 | struct RxDescV3 *descv3)
585 | {
586 | time64_t tv_sec;
587 | long tv_nsec;
588 |
589 | tv_sec = le32_to_cpu(descv3->RxDescTimeStamp.TimeStampHigh) +
590 | ((u64)le32_to_cpu(descv3->RxDescPTPDDWord4.TimeStampHHigh) << 32);
591 | tv_nsec = le32_to_cpu(descv3->RxDescTimeStamp.TimeStampLow) + tp->ptp_adjust;
592 |
593 | skb_hwtstamps(skb)->hwtstamp = ktime_set(tv_sec, tv_nsec);
594 | }
595 |
--------------------------------------------------------------------------------
/r8125/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.5Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2021 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/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.5Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2021 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/r8125_rss.c:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-2.0-only
2 | /*
3 | ################################################################################
4 | #
5 | # r8168 is the Linux device driver released for Realtek Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2021 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_HALF_SUPP = (1 << 7),
45 | RSS_CTRL_UDP_IPV4_SUPP = (1 << 11),
46 | RSS_CTRL_UDP_IPV6_SUPP = (1 << 12),
47 | RSS_QUAD_CPU_EN = (1 << 16),
48 | RSS_HQ_Q_SUP_R = (1 << 31),
49 | };
50 |
51 | static int rtl8125_get_rss_hash_opts(struct rtl8125_private *tp,
52 | struct ethtool_rxnfc *cmd)
53 | {
54 | cmd->data = 0;
55 |
56 | /* Report default options for RSS */
57 | switch (cmd->flow_type) {
58 | case TCP_V4_FLOW:
59 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
60 | /* fallthrough */
61 | case UDP_V4_FLOW:
62 | if (tp->rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV4)
63 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
64 | /* fallthrough */
65 | case IPV4_FLOW:
66 | cmd->data |= RXH_IP_SRC | RXH_IP_DST;
67 | break;
68 | case TCP_V6_FLOW:
69 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
70 | /* fallthrough */
71 | case UDP_V6_FLOW:
72 | if (tp->rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV6)
73 | cmd->data |= RXH_L4_B_0_1 | RXH_L4_B_2_3;
74 | /* fallthrough */
75 | case IPV6_FLOW:
76 | cmd->data |= RXH_IP_SRC | RXH_IP_DST;
77 | break;
78 | default:
79 | return -EINVAL;
80 | }
81 |
82 | return 0;
83 | }
84 |
85 | int rtl8125_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
86 | u32 *rule_locs)
87 | {
88 | struct rtl8125_private *tp = netdev_priv(dev);
89 | int ret = -EOPNOTSUPP;
90 |
91 | netif_info(tp, drv, tp->dev, "rss get rxnfc\n");
92 |
93 | if (!(dev->features & NETIF_F_RXHASH))
94 | return ret;
95 |
96 | switch (cmd->cmd) {
97 | case ETHTOOL_GRXRINGS:
98 | cmd->data = rtl8125_tot_rx_rings(tp);
99 | ret = 0;
100 | break;
101 | case ETHTOOL_GRXFH:
102 | ret = rtl8125_get_rss_hash_opts(tp, cmd);
103 | break;
104 | default:
105 | break;
106 | }
107 |
108 | return ret;
109 | }
110 |
111 | u32 rtl8125_rss_indir_tbl_entries(struct rtl8125_private *tp)
112 | {
113 | return tp->HwSuppIndirTblEntries;
114 | }
115 |
116 | #define RSS_MASK_BITS_OFFSET (8)
117 | #define RSS_CPU_NUM_OFFSET (16)
118 | #define RTL8125_UDP_RSS_FLAGS (RTL_8125_RSS_FLAG_HASH_UDP_IPV4 | \
119 | RTL_8125_RSS_FLAG_HASH_UDP_IPV6)
120 | static int _rtl8125_set_rss_hash_opt(struct rtl8125_private *tp)
121 | {
122 | u32 rss_flags = tp->rss_flags;
123 | u32 hash_mask_len;
124 | u32 rss_ctrl;
125 |
126 | rss_ctrl = ilog2(rtl8125_tot_rx_rings(tp));
127 | rss_ctrl &= (BIT_0 | BIT_1 | BIT_2);
128 | rss_ctrl <<= RSS_CPU_NUM_OFFSET;
129 |
130 | /* Perform hash on these packet types */
131 | rss_ctrl |= RSS_CTRL_TCP_IPV4_SUPP
132 | | RSS_CTRL_IPV4_SUPP
133 | | RSS_CTRL_IPV6_SUPP
134 | | RSS_CTRL_TCP_IPV6_SUPP;
135 |
136 | if (rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV4)
137 | rss_ctrl |= RSS_CTRL_UDP_IPV4_SUPP;
138 |
139 | if (rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV6)
140 | rss_ctrl |= RSS_CTRL_UDP_IPV6_SUPP;
141 |
142 | hash_mask_len = ilog2(rtl8125_rss_indir_tbl_entries(tp));
143 | hash_mask_len &= (BIT_0 | BIT_1 | BIT_2);
144 | rss_ctrl |= hash_mask_len << RSS_MASK_BITS_OFFSET;
145 |
146 | RTL_W32(tp, RSS_CTRL_8125, rss_ctrl);
147 |
148 | return 0;
149 | }
150 |
151 | static int rtl8125_set_rss_hash_opt(struct rtl8125_private *tp,
152 | struct ethtool_rxnfc *nfc)
153 | {
154 | u32 rss_flags = tp->rss_flags;
155 |
156 | netif_info(tp, drv, tp->dev, "rss set hash\n");
157 |
158 | /*
159 | * RSS does not support anything other than hashing
160 | * to queues on src and dst IPs and ports
161 | */
162 | if (nfc->data & ~(RXH_IP_SRC | RXH_IP_DST |
163 | RXH_L4_B_0_1 | RXH_L4_B_2_3))
164 | return -EINVAL;
165 |
166 | switch (nfc->flow_type) {
167 | case TCP_V4_FLOW:
168 | case TCP_V6_FLOW:
169 | if (!(nfc->data & RXH_IP_SRC) ||
170 | !(nfc->data & RXH_IP_DST) ||
171 | !(nfc->data & RXH_L4_B_0_1) ||
172 | !(nfc->data & RXH_L4_B_2_3))
173 | return -EINVAL;
174 | break;
175 | case UDP_V4_FLOW:
176 | if (!(nfc->data & RXH_IP_SRC) ||
177 | !(nfc->data & RXH_IP_DST))
178 | return -EINVAL;
179 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
180 | case 0:
181 | rss_flags &= ~RTL_8125_RSS_FLAG_HASH_UDP_IPV4;
182 | break;
183 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
184 | rss_flags |= RTL_8125_RSS_FLAG_HASH_UDP_IPV4;
185 | break;
186 | default:
187 | return -EINVAL;
188 | }
189 | break;
190 | case UDP_V6_FLOW:
191 | if (!(nfc->data & RXH_IP_SRC) ||
192 | !(nfc->data & RXH_IP_DST))
193 | return -EINVAL;
194 | switch (nfc->data & (RXH_L4_B_0_1 | RXH_L4_B_2_3)) {
195 | case 0:
196 | rss_flags &= ~RTL_8125_RSS_FLAG_HASH_UDP_IPV6;
197 | break;
198 | case (RXH_L4_B_0_1 | RXH_L4_B_2_3):
199 | rss_flags |= RTL_8125_RSS_FLAG_HASH_UDP_IPV6;
200 | break;
201 | default:
202 | return -EINVAL;
203 | }
204 | break;
205 | case SCTP_V4_FLOW:
206 | case AH_ESP_V4_FLOW:
207 | case AH_V4_FLOW:
208 | case ESP_V4_FLOW:
209 | case SCTP_V6_FLOW:
210 | case AH_ESP_V6_FLOW:
211 | case AH_V6_FLOW:
212 | case ESP_V6_FLOW:
213 | case IP_USER_FLOW:
214 | case ETHER_FLOW:
215 | /* RSS is not supported for these protocols */
216 | if (nfc->data) {
217 | netif_err(tp, drv, tp->dev, "Command parameters not supported\n");
218 | return -EINVAL;
219 | }
220 | return 0;
221 | break;
222 | default:
223 | return -EINVAL;
224 | }
225 |
226 | /* if we changed something we need to update flags */
227 | if (rss_flags != tp->rss_flags) {
228 | u32 rss_ctrl = RTL_R32(tp, RSS_CTRL_8125);
229 |
230 | if ((rss_flags & RTL8125_UDP_RSS_FLAGS) &&
231 | !(tp->rss_flags & RTL8125_UDP_RSS_FLAGS))
232 | netdev_warn(tp->dev,
233 | "enabling UDP RSS: fragmented packets may "
234 | "arrive out of order to the stack above\n");
235 |
236 | tp->rss_flags = rss_flags;
237 |
238 | /* Perform hash on these packet types */
239 | rss_ctrl |= RSS_CTRL_TCP_IPV4_SUPP
240 | | RSS_CTRL_IPV4_SUPP
241 | | RSS_CTRL_IPV6_SUPP
242 | | RSS_CTRL_TCP_IPV6_SUPP;
243 |
244 | rss_ctrl &= ~(RSS_CTRL_UDP_IPV4_SUPP |
245 | RSS_CTRL_UDP_IPV6_SUPP);
246 |
247 | if (rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV4)
248 | rss_ctrl |= RSS_CTRL_UDP_IPV4_SUPP;
249 |
250 | if (rss_flags & RTL_8125_RSS_FLAG_HASH_UDP_IPV6)
251 | rss_ctrl |= RSS_CTRL_UDP_IPV6_SUPP;
252 |
253 | RTL_W32(tp, RSS_CTRL_8125, rss_ctrl);
254 | }
255 |
256 | return 0;
257 | }
258 |
259 | int rtl8125_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd)
260 | {
261 | struct rtl8125_private *tp = netdev_priv(dev);
262 | int ret = -EOPNOTSUPP;
263 |
264 | netif_info(tp, drv, tp->dev, "rss set rxnfc\n");
265 |
266 | if (!(dev->features & NETIF_F_RXHASH))
267 | return ret;
268 |
269 | switch (cmd->cmd) {
270 | case ETHTOOL_SRXFH:
271 | ret = rtl8125_set_rss_hash_opt(tp, cmd);
272 | break;
273 | default:
274 | break;
275 | }
276 |
277 | return ret;
278 | }
279 |
280 | static u32 _rtl8125_get_rxfh_key_size(struct rtl8125_private *tp)
281 | {
282 | return sizeof(tp->rss_key);
283 | }
284 |
285 | u32 rtl8125_get_rxfh_key_size(struct net_device *dev)
286 | {
287 | struct rtl8125_private *tp = netdev_priv(dev);
288 |
289 | netif_info(tp, drv, tp->dev, "rss get key size\n");
290 |
291 | if (!(dev->features & NETIF_F_RXHASH))
292 | return 0;
293 |
294 | return _rtl8125_get_rxfh_key_size(tp);
295 | }
296 |
297 | u32 rtl8125_rss_indir_size(struct net_device *dev)
298 | {
299 | struct rtl8125_private *tp = netdev_priv(dev);
300 |
301 | netif_info(tp, drv, tp->dev, "rss get indir tbl size\n");
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 | int rtl8125_get_rxfh(struct net_device *dev, u32 *indir, u8 *key,
318 | u8 *hfunc)
319 | {
320 | struct rtl8125_private *tp = netdev_priv(dev);
321 |
322 | netif_info(tp, drv, tp->dev, "rss get rxfh\n");
323 |
324 | if (!(dev->features & NETIF_F_RXHASH))
325 | return -EOPNOTSUPP;
326 |
327 | if (hfunc)
328 | *hfunc = ETH_RSS_HASH_TOP;
329 |
330 | if (indir)
331 | rtl8125_get_reta(tp, indir);
332 |
333 | if (key)
334 | memcpy(key, tp->rss_key, rtl8125_get_rxfh_key_size(dev));
335 |
336 | return 0;
337 | }
338 |
339 | static u32 rtl8125_rss_key_reg(struct rtl8125_private *tp)
340 | {
341 | return RSS_KEY_8125;
342 | }
343 |
344 | static u32 rtl8125_rss_indir_tbl_reg(struct rtl8125_private *tp)
345 | {
346 | return RSS_INDIRECTION_TBL_8125_V2;
347 | }
348 |
349 | static void rtl8125_store_reta(struct rtl8125_private *tp)
350 | {
351 | u16 indir_tbl_reg = rtl8125_rss_indir_tbl_reg(tp);
352 | u32 i, reta_entries = rtl8125_rss_indir_tbl_entries(tp);
353 | u32 reta = 0;
354 | u8 *indir_tbl = tp->rss_indir_tbl;
355 |
356 | /* Write redirection table to HW */
357 | for (i = 0; i < reta_entries; i++) {
358 | reta |= indir_tbl[i] << (i & 0x3) * 8;
359 | if ((i & 3) == 3) {
360 | RTL_W32(tp, indir_tbl_reg, reta);
361 |
362 | indir_tbl_reg += 4;
363 | reta = 0;
364 | }
365 | }
366 | }
367 |
368 | static void rtl8125_store_rss_key(struct rtl8125_private *tp)
369 | {
370 | const u16 rss_key_reg = rtl8125_rss_key_reg(tp);
371 | u32 i, rss_key_size = _rtl8125_get_rxfh_key_size(tp);
372 | u32 *rss_key = (u32*)tp->rss_key;
373 |
374 | /* Write redirection table to HW */
375 | for (i = 0; i < rss_key_size; i+=4)
376 | RTL_W32(tp, rss_key_reg + i, *rss_key++);
377 | }
378 |
379 | int rtl8125_set_rxfh(struct net_device *dev, const u32 *indir,
380 | const u8 *key, const u8 hfunc)
381 | {
382 | struct rtl8125_private *tp = netdev_priv(dev);
383 | int i;
384 | u32 reta_entries = rtl8125_rss_indir_tbl_entries(tp);
385 |
386 | netif_info(tp, drv, tp->dev, "rss set rxfh\n");
387 |
388 | /* We require at least one supported parameter to be changed and no
389 | * change in any of the unsupported parameters
390 | */
391 | if (hfunc != ETH_RSS_HASH_NO_CHANGE && hfunc != ETH_RSS_HASH_TOP)
392 | return -EOPNOTSUPP;
393 |
394 | /* Fill out the redirection table */
395 | if (indir) {
396 | int max_queues = tp->num_rx_rings;
397 |
398 | /* Verify user input. */
399 | for (i = 0; i < reta_entries; i++)
400 | if (indir[i] >= max_queues)
401 | return -EINVAL;
402 |
403 | for (i = 0; i < reta_entries; i++)
404 | tp->rss_indir_tbl[i] = indir[i];
405 | }
406 |
407 | /* Fill out the rss hash key */
408 | if (key)
409 | memcpy(tp->rss_key, key, rtl8125_get_rxfh_key_size(dev));
410 |
411 | rtl8125_store_reta(tp);
412 |
413 | rtl8125_store_rss_key(tp);
414 |
415 | return 0;
416 | }
417 |
418 | static u32 rtl8125_get_rx_desc_hash(struct rtl8125_private *tp,
419 | struct RxDescV3 *descv3)
420 | {
421 | return le32_to_cpu(descv3->RxDescNormalDDWord2.RSSResult);
422 | }
423 |
424 | #define RXS_8125B_RSS_UDP BIT(9)
425 | #define RXS_8125_RSS_IPV4 BIT(10)
426 | #define RXS_8125_RSS_IPV6 BIT(12)
427 | #define RXS_8125_RSS_TCP BIT(13)
428 | #define RTL8125_RXS_RSS_L3_TYPE_MASK (RXS_8125_RSS_IPV4 | RXS_8125_RSS_IPV6)
429 | #define RTL8125_RXS_RSS_L4_TYPE_MASK (RXS_8125_RSS_TCP | RXS_8125B_RSS_UDP)
430 | void rtl8125_rx_hash(struct rtl8125_private *tp,
431 | struct RxDescV3 *descv3,
432 | struct sk_buff *skb)
433 | {
434 | u16 rss_header_info;
435 |
436 | if (!(tp->dev->features & NETIF_F_RXHASH))
437 | return;
438 |
439 | rss_header_info = le16_to_cpu(descv3->RxDescNormalDDWord2.HeaderInfo);
440 |
441 | if (!(rss_header_info & RTL8125_RXS_RSS_L3_TYPE_MASK))
442 | return;
443 |
444 | skb_set_hash(skb, rtl8125_get_rx_desc_hash(tp, descv3),
445 | (RTL8125_RXS_RSS_L4_TYPE_MASK & rss_header_info) ?
446 | PKT_HASH_TYPE_L4 : PKT_HASH_TYPE_L3);
447 | }
448 |
449 | void rtl8125_disable_rss(struct rtl8125_private *tp)
450 | {
451 | RTL_W32(tp, RSS_CTRL_8125, 0x00);
452 | }
453 |
454 | void _rtl8125_config_rss(struct rtl8125_private *tp)
455 | {
456 | _rtl8125_set_rss_hash_opt(tp);
457 |
458 | rtl8125_store_reta(tp);
459 |
460 | rtl8125_store_rss_key(tp);
461 | }
462 |
463 | void rtl8125_config_rss(struct rtl8125_private *tp)
464 | {
465 | if (!tp->EnableRss) {
466 | rtl8125_disable_rss(tp);
467 | return;
468 | }
469 |
470 | _rtl8125_config_rss(tp);
471 | }
472 |
473 | void rtl8125_init_rss(struct rtl8125_private *tp)
474 | {
475 | int i;
476 |
477 | for (i = 0; i < rtl8125_rss_indir_tbl_entries(tp); i++)
478 | tp->rss_indir_tbl[i] = ethtool_rxfh_indir_default(i, tp->num_rx_rings);
479 |
480 | netdev_rss_key_fill(tp->rss_key, RTL8125_RSS_KEY_SIZE);
481 | }
482 |
--------------------------------------------------------------------------------
/r8125/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.5Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2021 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 |
51 | int rtl8125_get_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd,
52 | u32 *rule_locs);
53 | int rtl8125_set_rxnfc(struct net_device *dev, struct ethtool_rxnfc *cmd);
54 | u32 rtl8125_get_rxfh_key_size(struct net_device *netdev);
55 | u32 rtl8125_rss_indir_size(struct net_device *netdev);
56 | int rtl8125_get_rxfh(struct net_device *netdev, u32 *indir, u8 *key,
57 | u8 *hfunc);
58 | int rtl8125_set_rxfh(struct net_device *netdev, const u32 *indir,
59 | const u8 *key, const u8 hfunc);
60 | void rtl8125_rx_hash(struct rtl8125_private *tp,
61 | struct RxDescV3 *descv3,
62 | struct sk_buff *skb);
63 | void _rtl8125_config_rss(struct rtl8125_private *tp);
64 | void rtl8125_config_rss(struct rtl8125_private *tp);
65 | void rtl8125_init_rss(struct rtl8125_private *tp);
66 | u32 rtl8125_rss_indir_tbl_entries(struct rtl8125_private *tp);
67 | void rtl8125_disable_rss(struct rtl8125_private *tp);
68 |
69 | #endif /* _LINUX_rtl8125_RSS_H */
70 |
--------------------------------------------------------------------------------
/r8125/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.5Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2021 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 | 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 | udelay(RTL_CLOCK_RATE * 2 * 3);
108 | return 0;
109 | }
110 | udelay(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 |
130 | if (tp->eeprom_type==EEPROM_TYPE_93C46)
131 | addr_sz = 6;
132 | else if (tp->eeprom_type==EEPROM_TYPE_93C56)
133 | addr_sz = 8;
134 |
135 | x = Cfg9346_EEM1 | Cfg9346_EECS;
136 | RTL_W8(tp, Cfg9346, x);
137 |
138 | rtl8125_shift_out_bits(tp, RTL_EEPROM_READ_OPCODE, 3);
139 | rtl8125_shift_out_bits(tp, reg, addr_sz);
140 |
141 | data = rtl8125_shift_in_bits(tp);
142 |
143 | rtl8125_eeprom_cleanup(tp);
144 |
145 | RTL_W8(tp, Cfg9346, 0);
146 |
147 | return data;
148 | }
149 |
150 | //-------------------------------------------------------------------
151 | //rtl8125_eeprom_write_sc():
152 | // write one word to a specific address in the eeprom
153 | //-------------------------------------------------------------------
154 | void rtl8125_eeprom_write_sc(struct rtl8125_private *tp, u16 reg, u16 data)
155 | {
156 | u8 x;
157 | int addr_sz = 6;
158 | int w_dummy_addr = 4;
159 |
160 | if(tp->eeprom_type == EEPROM_TYPE_NONE) {
161 | return ;
162 | }
163 |
164 | if (tp->eeprom_type==EEPROM_TYPE_93C46) {
165 | addr_sz = 6;
166 | w_dummy_addr = 4;
167 | } else if (tp->eeprom_type==EEPROM_TYPE_93C56) {
168 | addr_sz = 8;
169 | w_dummy_addr = 6;
170 | }
171 |
172 | x = Cfg9346_EEM1 | Cfg9346_EECS;
173 | RTL_W8(tp, Cfg9346, x);
174 |
175 | rtl8125_shift_out_bits(tp, RTL_EEPROM_EWEN_OPCODE, 5);
176 | rtl8125_shift_out_bits(tp, reg, w_dummy_addr);
177 | rtl8125_stand_by(tp);
178 |
179 | rtl8125_shift_out_bits(tp, RTL_EEPROM_ERASE_OPCODE, 3);
180 | rtl8125_shift_out_bits(tp, reg, addr_sz);
181 | if (rtl8125_eeprom_cmd_done(tp) < 0) {
182 | return;
183 | }
184 | rtl8125_stand_by(tp);
185 |
186 | rtl8125_shift_out_bits(tp, RTL_EEPROM_WRITE_OPCODE, 3);
187 | rtl8125_shift_out_bits(tp, reg, addr_sz);
188 | rtl8125_shift_out_bits(tp, data, 16);
189 | if (rtl8125_eeprom_cmd_done(tp) < 0) {
190 | return;
191 | }
192 | rtl8125_stand_by(tp);
193 |
194 | rtl8125_shift_out_bits(tp, RTL_EEPROM_EWDS_OPCODE, 5);
195 | rtl8125_shift_out_bits(tp, reg, w_dummy_addr);
196 |
197 | rtl8125_eeprom_cleanup(tp);
198 | RTL_W8(tp, Cfg9346, 0);
199 | }
200 |
201 | void rtl8125_raise_clock(struct rtl8125_private *tp, u8 *x)
202 | {
203 | *x = *x | Cfg9346_EESK;
204 | RTL_W8(tp, Cfg9346, *x);
205 | udelay(RTL_CLOCK_RATE);
206 | }
207 |
208 | void rtl8125_lower_clock(struct rtl8125_private *tp, u8 *x)
209 | {
210 |
211 | *x = *x & ~Cfg9346_EESK;
212 | RTL_W8(tp, Cfg9346, *x);
213 | udelay(RTL_CLOCK_RATE);
214 | }
215 |
216 | void rtl8125_shift_out_bits(struct rtl8125_private *tp, int data, int count)
217 | {
218 | u8 x;
219 | int mask;
220 |
221 | mask = 0x01 << (count - 1);
222 | x = RTL_R8(tp, Cfg9346);
223 | x &= ~(Cfg9346_EEDI | Cfg9346_EEDO);
224 |
225 | do {
226 | if (data & mask)
227 | x |= Cfg9346_EEDI;
228 | else
229 | x &= ~Cfg9346_EEDI;
230 |
231 | RTL_W8(tp, Cfg9346, x);
232 | udelay(RTL_CLOCK_RATE);
233 | rtl8125_raise_clock(tp, &x);
234 | rtl8125_lower_clock(tp, &x);
235 | mask = mask >> 1;
236 | } while(mask);
237 |
238 | x &= ~Cfg9346_EEDI;
239 | RTL_W8(tp, Cfg9346, x);
240 | }
241 |
242 | u16 rtl8125_shift_in_bits(struct rtl8125_private *tp)
243 | {
244 | u8 x;
245 | u16 d, i;
246 |
247 | x = RTL_R8(tp, Cfg9346);
248 | x &= ~(Cfg9346_EEDI | Cfg9346_EEDO);
249 |
250 | d = 0;
251 |
252 | for (i = 0; i < 16; i++) {
253 | d = d << 1;
254 | rtl8125_raise_clock(tp, &x);
255 |
256 | x = RTL_R8(tp, Cfg9346);
257 | x &= ~Cfg9346_EEDI;
258 |
259 | if (x & Cfg9346_EEDO)
260 | d |= 1;
261 |
262 | rtl8125_lower_clock(tp, &x);
263 | }
264 |
265 | return d;
266 | }
267 |
268 | void rtl8125_stand_by(struct rtl8125_private *tp)
269 | {
270 | u8 x;
271 |
272 | x = RTL_R8(tp, Cfg9346);
273 | x &= ~(Cfg9346_EECS | Cfg9346_EESK);
274 | RTL_W8(tp, Cfg9346, x);
275 | udelay(RTL_CLOCK_RATE);
276 |
277 | x |= Cfg9346_EECS;
278 | RTL_W8(tp, Cfg9346, x);
279 | }
280 |
281 | void rtl8125_set_eeprom_sel_low(struct rtl8125_private *tp)
282 | {
283 | RTL_W8(tp, Cfg9346, Cfg9346_EEM1);
284 | RTL_W8(tp, Cfg9346, Cfg9346_EEM1 | Cfg9346_EESK);
285 |
286 | udelay(20);
287 |
288 | RTL_W8(tp, Cfg9346, Cfg9346_EEM1);
289 | }
290 |
--------------------------------------------------------------------------------
/r8125/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.5Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2021 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/rtltool.c:
--------------------------------------------------------------------------------
1 | // SPDX-License-Identifier: GPL-2.0-only
2 | /*
3 | ################################################################################
4 | #
5 | # r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2021 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 (!capable(CAP_NET_ADMIN))
59 | return -EPERM;
60 |
61 | if (my_cmd.len==1)
62 | my_cmd.data = readb(tp->mmio_addr+my_cmd.offset);
63 | else if (my_cmd.len==2)
64 | my_cmd.data = readw(tp->mmio_addr+(my_cmd.offset&~1));
65 | else if (my_cmd.len==4)
66 | my_cmd.data = readl(tp->mmio_addr+(my_cmd.offset&~3));
67 | else {
68 | ret = -EOPNOTSUPP;
69 | break;
70 | }
71 |
72 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
73 | ret = -EFAULT;
74 | break;
75 | }
76 | break;
77 |
78 | case RTLTOOL_WRITE_MAC:
79 | if (!capable(CAP_NET_ADMIN))
80 | return -EPERM;
81 |
82 | if (my_cmd.len==1)
83 | writeb(my_cmd.data, tp->mmio_addr+my_cmd.offset);
84 | else if (my_cmd.len==2)
85 | writew(my_cmd.data, tp->mmio_addr+(my_cmd.offset&~1));
86 | else if (my_cmd.len==4)
87 | writel(my_cmd.data, tp->mmio_addr+(my_cmd.offset&~3));
88 | else {
89 | ret = -EOPNOTSUPP;
90 | break;
91 | }
92 |
93 | break;
94 |
95 | case RTLTOOL_READ_PHY:
96 | if (!capable(CAP_NET_ADMIN))
97 | return -EPERM;
98 |
99 | my_cmd.data = rtl8125_mdio_prot_read(tp, my_cmd.offset);
100 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
101 | ret = -EFAULT;
102 | break;
103 | }
104 |
105 | break;
106 |
107 | case RTLTOOL_WRITE_PHY:
108 | if (!capable(CAP_NET_ADMIN))
109 | return -EPERM;
110 |
111 | rtl8125_mdio_prot_write(tp, my_cmd.offset, my_cmd.data);
112 | break;
113 |
114 | case RTLTOOL_READ_EPHY:
115 | if (!capable(CAP_NET_ADMIN))
116 | return -EPERM;
117 |
118 | my_cmd.data = rtl8125_ephy_read(tp, my_cmd.offset);
119 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
120 | ret = -EFAULT;
121 | break;
122 | }
123 |
124 | break;
125 |
126 | case RTLTOOL_WRITE_EPHY:
127 | if (!capable(CAP_NET_ADMIN))
128 | return -EPERM;
129 |
130 | rtl8125_ephy_write(tp, my_cmd.offset, my_cmd.data);
131 | break;
132 |
133 | case RTLTOOL_READ_ERI:
134 | my_cmd.data = 0;
135 | if (my_cmd.len==1 || my_cmd.len==2 || my_cmd.len==4) {
136 | my_cmd.data = rtl8125_eri_read(tp, my_cmd.offset, my_cmd.len, ERIAR_ExGMAC);
137 | } else {
138 | ret = -EOPNOTSUPP;
139 | break;
140 | }
141 |
142 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
143 | ret = -EFAULT;
144 | break;
145 | }
146 |
147 | break;
148 |
149 | case RTLTOOL_WRITE_ERI:
150 | if (!capable(CAP_NET_ADMIN))
151 | return -EPERM;
152 |
153 | if (!capable(CAP_NET_ADMIN))
154 | return -EPERM;
155 |
156 | if (my_cmd.len==1 || my_cmd.len==2 || my_cmd.len==4) {
157 | rtl8125_eri_write(tp, my_cmd.offset, my_cmd.len, my_cmd.data, ERIAR_ExGMAC);
158 | } else {
159 | ret = -EOPNOTSUPP;
160 | break;
161 | }
162 | break;
163 |
164 | case RTLTOOL_READ_PCI:
165 | if (!capable(CAP_NET_ADMIN))
166 | return -EPERM;
167 |
168 | my_cmd.data = 0;
169 | if (my_cmd.len==1)
170 | pci_read_config_byte(tp->pci_dev, my_cmd.offset,
171 | (u8 *)&my_cmd.data);
172 | else if (my_cmd.len==2)
173 | pci_read_config_word(tp->pci_dev, my_cmd.offset,
174 | (u16 *)&my_cmd.data);
175 | else if (my_cmd.len==4)
176 | pci_read_config_dword(tp->pci_dev, my_cmd.offset,
177 | &my_cmd.data);
178 | else {
179 | ret = -EOPNOTSUPP;
180 | break;
181 | }
182 |
183 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
184 | ret = -EFAULT;
185 | break;
186 | }
187 | break;
188 |
189 | case RTLTOOL_WRITE_PCI:
190 | if (!capable(CAP_NET_ADMIN))
191 | return -EPERM;
192 |
193 | if (my_cmd.len==1)
194 | pci_write_config_byte(tp->pci_dev, my_cmd.offset,
195 | my_cmd.data);
196 | else if (my_cmd.len==2)
197 | pci_write_config_word(tp->pci_dev, my_cmd.offset,
198 | my_cmd.data);
199 | else if (my_cmd.len==4)
200 | pci_write_config_dword(tp->pci_dev, my_cmd.offset,
201 | my_cmd.data);
202 | else {
203 | ret = -EOPNOTSUPP;
204 | break;
205 | }
206 |
207 | break;
208 |
209 | case RTLTOOL_READ_EEPROM:
210 | if (!capable(CAP_NET_ADMIN))
211 | return -EPERM;
212 |
213 | my_cmd.data = rtl8125_eeprom_read_sc(tp, my_cmd.offset);
214 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
215 | ret = -EFAULT;
216 | break;
217 | }
218 |
219 | break;
220 |
221 | case RTLTOOL_WRITE_EEPROM:
222 | if (!capable(CAP_NET_ADMIN))
223 | return -EPERM;
224 |
225 | rtl8125_eeprom_write_sc(tp, my_cmd.offset, my_cmd.data);
226 | break;
227 |
228 | case RTL_READ_OOB_MAC:
229 | if (!capable(CAP_NET_ADMIN))
230 | return -EPERM;
231 |
232 | rtl8125_oob_mutex_lock(tp);
233 | my_cmd.data = rtl8125_ocp_read(tp, my_cmd.offset, 4);
234 | rtl8125_oob_mutex_unlock(tp);
235 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
236 | ret = -EFAULT;
237 | break;
238 | }
239 | break;
240 |
241 | case RTL_WRITE_OOB_MAC:
242 | if (!capable(CAP_NET_ADMIN))
243 | return -EPERM;
244 |
245 | if (my_cmd.len == 0 || my_cmd.len > 4)
246 | return -EOPNOTSUPP;
247 |
248 | rtl8125_oob_mutex_lock(tp);
249 | rtl8125_ocp_write(tp, my_cmd.offset, my_cmd.len, my_cmd.data);
250 | rtl8125_oob_mutex_unlock(tp);
251 | break;
252 |
253 | case RTL_ENABLE_PCI_DIAG:
254 | if (!capable(CAP_NET_ADMIN))
255 | return -EPERM;
256 |
257 | tp->rtk_enable_diag = 1;
258 |
259 | dprintk("enable rtk diag\n");
260 | break;
261 |
262 | case RTL_DISABLE_PCI_DIAG:
263 | if (!capable(CAP_NET_ADMIN))
264 | return -EPERM;
265 |
266 | tp->rtk_enable_diag = 0;
267 |
268 | dprintk("disable rtk diag\n");
269 | break;
270 |
271 | case RTL_READ_MAC_OCP:
272 | if (!capable(CAP_NET_ADMIN))
273 | return -EPERM;
274 |
275 | if (my_cmd.offset % 2)
276 | return -EOPNOTSUPP;
277 |
278 | my_cmd.data = rtl8125_mac_ocp_read(tp, my_cmd.offset);
279 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
280 | ret = -EFAULT;
281 | break;
282 | }
283 | break;
284 |
285 | case RTL_WRITE_MAC_OCP:
286 | if (!capable(CAP_NET_ADMIN))
287 | return -EPERM;
288 |
289 | if ((my_cmd.offset % 2) || (my_cmd.len != 2))
290 | return -EOPNOTSUPP;
291 |
292 | rtl8125_mac_ocp_write(tp, my_cmd.offset, (u16)my_cmd.data);
293 | break;
294 |
295 | case RTL_DIRECT_READ_PHY_OCP:
296 | if (!capable(CAP_NET_ADMIN))
297 | return -EPERM;
298 |
299 | my_cmd.data = rtl8125_mdio_prot_direct_read_phy_ocp(tp, my_cmd.offset);
300 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
301 | ret = -EFAULT;
302 | break;
303 | }
304 |
305 | break;
306 |
307 | case RTL_DIRECT_WRITE_PHY_OCP:
308 | if (!capable(CAP_NET_ADMIN))
309 | return -EPERM;
310 |
311 | rtl8125_mdio_prot_direct_write_phy_ocp(tp, my_cmd.offset, my_cmd.data);
312 | break;
313 |
314 | default:
315 | ret = -EOPNOTSUPP;
316 | break;
317 | }
318 |
319 | return ret;
320 | }
321 |
--------------------------------------------------------------------------------
/r8125/rtltool.h:
--------------------------------------------------------------------------------
1 | /* SPDX-License-Identifier: GPL-2.0-only */
2 | /*
3 | ################################################################################
4 | #
5 | # r8125 is the Linux device driver released for Realtek 2.5Gigabit Ethernet
6 | # controllers with PCI-Express interface.
7 | #
8 | # Copyright(c) 2021 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 | RTLTOOL_INVALID
67 | };
68 |
69 | struct rtltool_cmd {
70 | __u32 cmd;
71 | __u32 offset;
72 | __u32 len;
73 | __u32 data;
74 | };
75 |
76 | enum mode_access {
77 | MODE_NONE=0,
78 | MODE_READ,
79 | MODE_WRITE
80 | };
81 |
82 | #ifdef __KERNEL__
83 | int rtl8125_tool_ioctl(struct rtl8125_private *tp, struct ifreq *ifr);
84 | #endif
85 |
86 | #endif /* _LINUX_RTLTOOL_H */
87 |
--------------------------------------------------------------------------------