├── LICENSE
├── README.md
├── build-script
└── build-r8125.sh
└── r8125
├── Makefile
├── Makefile_linux24x
├── copy_to_vmkdriver.sh
├── kcompat.c
├── kcompat.h
├── kcompat_esx.h
├── kcompat_ethtool.c
├── 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 9.011.00-10 for ESXi 6.7 U3
2 | * Major rewrite by IRON Software GmbH / ksh@ironsoftware.de
3 |
4 | This source code is based on realtek official source, VMware-ESXI-67U3-ODP and VMware-TOOLS-10.2.0-ODP.
5 | - Log in with root, make a folder name 'build' on /, make folder toolchain and vsphere in /build.
6 | - Copy and extract gcc-4.8.0, binutils-2.22, glibc-2.3.4-2.41 to /build/toolchain/src
7 | - Compile the toolchain, dest path is /build/toolchain/lin64
8 | - Extract and copy vmkdrivers-gpl from 67U3-ODP to /build/vsphere
9 | - Copy build-r8125.sh to /build/vsphere/vmkdrivers-gpl/
10 | - Copy r8125 folder to /build/vsphere/vmkdrivers-gpl/vmkdrivers/src_9/drivers/net
11 | - Run build-r8125.sh
12 |
13 | Just do these steps for development:
14 | - cd /tmp; vmkload_mod -u r8125; sha1sum r8125; \
15 | - vmkload_mod ./r8125 enable_tso=1 enable_tx_csum=1 eee_enable=0 hwoptimize=1 tx_no_close_enable=1 enable_double_vlan=0 use_dac=0
16 |
17 | Install bundle
18 | - esxcli software vib install -f -v $PWD/net-r8125-9.011.00-10.vib
19 |
20 |
--------------------------------------------------------------------------------
/build-script/build-r8125.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | set -e
3 |
4 | # clean start
5 | rm -rf BLD/build/vmkdriver-r8125
6 |
7 | VERSION="9.011.00"
8 |
9 |
10 | # Use gcc version 4.4.3-2
11 | # Below is the internal VMWare location. Please change as required for your
12 | # installed location.
13 | CC=/build/toolchain/lin64/gcc-4.8.0/bin/x86_64-linux-gcc
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 | # ENABLE_USE_FIRMWARE_FILE
20 | CONFIG_FLAGS="-DENABLE_TX_NO_CLOSE -DCONFIG_R8125_VLAN \
21 | -DDISABLE_PM_SUPPORT -DRTL8125_DEBUG -DCONFIG_SOC_LAN -DENABLE_S0_MAGIC_PACKET -DENABLE_S5WOL \
22 | -DCONFIG_NET_POLL_CONTROLLER -DDENABLE_RSS_SUPPORT \
23 | " # -DCONFIG_R8125_NAPI -DENABLE_PAUSE -DENABLE_PTP_SUPPORT " # -DCONFIG_SOC_LAN -DCONFIG_ESD -DENABLE_PAGE_REUSE -DENABLE_RX_PACKET_FRAGMENT
24 | # -DENABLE_DASH_SUPPORT -DENABLE_PTP_SUPPORT -DCONFIG_HW_HACK -DRTL_USE_NEW_INTR_API
25 |
26 | # PR# 976913 requested that OSS binaries be stripped of debug
27 | LD_OPTS=--strip-debug
28 | SYS_ROOT=/nowhere
29 |
30 | COMP_FLAGS="--sysroot=$SYS_ROOT -fwrapv -pipe -fno-strict-aliasing -Wno-unused-but-set-variable -fno-working-directory \
31 | -g -ggdb3 -O3 -mcmodel=smallhigh -Wall -Werror -Wstrict-prototypes -fno-strict-aliasing -freg-struct-return -falign-jumps=1 \
32 | -falign-functions=4 -falign-loops=1 -m64 -mno-red-zone -mpreferred-stack-boundary=4 -minline-all-stringops -mno-mmx -mno-3dnow \
33 | -mno-sse -mno-sse2 -mcld -finline-limit=2000 -fno-common -ffreestanding -nostdinc -fomit-frame-pointer -nostdlib \
34 | --sysroot=$SYS_ROOT -Wno-error -Wdeclaration-after-statement -Wno-pointer-sign -Wno-strict-prototypes -Wno-enum-compare \
35 | -Wno-switch -Wno-declaration-after-statement -Wno-declaration-after-statement -Wno-declaration-after-statement"
36 |
37 | I_SYSTEM=/build/toolchain/lin64/gcc-4.8.0/lib/gcc/x86_64-linux/4.8.0/include
38 | INCLUDES="-isystem $I_SYSTEM -Ivmkdrivers/src_9/drivers/net/r8125 -IBLD/build/HEADERS/vmkdrivers-vmkernel/vmkernel64/release \
39 | -IBLD/build/version -Ivmkdrivers/src_92/include -Ivmkdrivers/src_92/include/vmklinux_92 \
40 | -IBLD/build/HEADERS/92-vmkdrivers-asm-x64/vmkernel64/release -Ivmkdrivers/src_92/drivers/net \
41 | -IBLD/build/HEADERS/vmkapi-v2_3_0_0-all-public-bincomp/generic/release \
42 | -IBLD/build/HEADERS/vmkapi-current-all-public-bincomp/generic/release -include vmkdrivers/src_92/include/linux/autoconf.h"
43 |
44 | DFLAGS="-DLINUX -D__KERNEL__ -DMODULE -DMODVERSIONS -DEXPORT_SYMTAB \
45 | -D_LINUX -D__VMWARE__ -D__VMKERNEL_MODULE__ -D__VMKERNEL__ -D__VMKLNX__ -D__VMK_GCC_BUG_ALIGNMENT_PADDING__ \
46 | -DCONFIG_COMPAT -DCONFIG_DCB -DCONFIG_FCOE -DCONFIG_INET_LRO -DCONFIG_NETDEVICES_MULTIQUEUE -DCONFIG_PCI_IOV \
47 | -DCONFIG_PCI_MSI -DCONFIG_PROC_FS -DCPU=x86-64 -DESX3_NETWORKING_NOT_DONE_YET -DGPLED_CODE -DHAVE_DCBNL_OPS_GETAPP \
48 | -DHAVE_IPLINK_VF_CONFIG -DKBUILD_MODNAME=\"r8125\" -DLINUX_MODULE_AUX_HEAP_NAME=vmklnx_r8125 -DLINUX_MODULE_HEAP_INITIAL=1024*100 \
49 | -DLINUX_MODULE_HEAP_MAX=64*1024*1024 -DLINUX_MODULE_HEAP_NAME=vmklnx_r8125 -DLINUX_MODULE_SKB_HEAP \
50 | -DLINUX_MODULE_SKB_HEAP_INITIAL=512*1024 -DLINUX_MODULE_SKB_HEAP_MAX=128*1024*1024 -DLINUX_MODULE_VERSION=\"${VERSION}\" \
51 | -DMODULE -DNET_DRIVER -DNO_FLOATING_POINT -DVMKERNEL -DVMKERNEL_MODULE -DVMKLINUX_MODULE_HEAP_ANY_MEM \
52 | -DVMK_DEVKIT_HAS_API_VMKAPI_BASE -DVMK_DEVKIT_HAS_API_VMKAPI_DEVICE -DVMK_DEVKIT_HAS_API_VMKAPI_ISCSI \
53 | -DVMK_DEVKIT_HAS_API_VMKAPI_NET -DVMK_DEVKIT_HAS_API_VMKAPI_RDMA -DVMK_DEVKIT_HAS_API_VMKAPI_SCSI \
54 | -DVMK_DEVKIT_HAS_API_VMKAPI_SOCKETS -DVMK_DEVKIT_IS_DDK -DVMK_DEVKIT_USES_BINARY_COMPATIBLE_APIS \
55 | -DVMK_DEVKIT_USES_PUBLIC_APIS -DVMNIX -DVMX86_RELEASE -DVMX86_SERVER"
56 |
57 |
58 | # Use GNU grep 2.5.1
59 | GREP=grep
60 | # Use GNU sed 4.5.1
61 | SED=sed
62 | # Use GNU xargs 4.2.27
63 | XARGS=xargs
64 | # Use mkdir from GNU coreutils 5.97
65 | MKDIR=mkdir
66 |
67 | # Create output directories
68 | $GREP -v -e "SED" build-r8125.sh \
69 | | $GREP -o -e "-o [^ ]*\." \
70 | | $SED -e 's?-o \(.*\)/[^/]*\.?\1?' \
71 | | $GREP -v -e "\*" \
72 | | $XARGS $MKDIR -p
73 |
74 |
75 | # copy from src
76 | /build/r8125/r8125-${VERSION}/src/copy_to_vmkdriver.sh
77 |
78 | echo "[i] Building"
79 | # Compiler flags assume being compiled natively on a x86-64 machine
80 | $CC $CONFIG_FLAGS $COMP_FLAGS $DFLAGS $INCLUDES -c \
81 | -o BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_9/drivers/net/r8125/r8125_n.o \
82 | vmkdrivers/src_9/drivers/net/r8125/r8125_n.c
83 |
84 | $CC $CONFIG_FLAGS $COMP_FLAGS $DFLAGS $INCLUDES -c \
85 | -o BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_9/drivers/net/r8125/rtl_eeprom.o \
86 | vmkdrivers/src_9/drivers/net/r8125/rtl_eeprom.c
87 |
88 | $CC $CONFIG_FLAGS $COMP_FLAGS $DFLAGS $INCLUDES -c \
89 | -o BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_9/drivers/net/r8125/rtltool.o \
90 | vmkdrivers/src_9/drivers/net/r8125/rtltool.c
91 |
92 | $CC $CONFIG_FLAGS $COMP_FLAGS $DFLAGS $INCLUDES -c \
93 | -o BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_9/drivers/net/r8125/kcompat.o \
94 | vmkdrivers/src_9/drivers/net/r8125/kcompat.c
95 |
96 | $CC $CONFIG_FLAGS $COMP_FLAGS $DFLAGS $INCLUDES -c \
97 | -o BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_92/common/vmklinux_module.o \
98 | vmkdrivers/src_92/common/vmklinux_module.c
99 |
100 | $LD $LD_OPTS -r -o BLD/build/vmkdriver-r8125/release/vmkernel64/r8125 \
101 | --whole-archive BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_9/drivers/net/r8125/r8125_n.o \
102 | BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_9/drivers/net/r8125/rtl_eeprom.o \
103 | BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_9/drivers/net/r8125/rtltool.o \
104 | BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_9/drivers/net/r8125/kcompat.o \
105 | BLD/build/vmkdriver-r8125/release/vmkernel64/SUBDIRS/vmkdrivers/src_92/common/vmklinux_module.o
106 |
107 | echo "[i] Build finished"
108 |
109 | # copy asset
110 | cp /build/vmkdrivers-gpl/BLD/build/vmkdriver-r8125/release/vmkernel64/r8125 .
111 | cp r8125 /build/compile-vib-tutorial/vib-r8125-${VERSION}/payloads/net-8125/usr/lib/vmware/vmkmod/
112 | sha1sum r8125
113 |
114 | echo "esxcli system module set -e true -m r8125;"
115 | echo "cd /tmp; vmkload_mod -u r8125; sha1sum r8125; \
116 | vmkload_mod ./r8125 enable_tso=1 enable_tx_csum=1 eee_enable=0 hwoptimize=1 tx_no_close_enable=1 enable_double_vlan=0 use_dac=0"
117 |
118 |
--------------------------------------------------------------------------------
/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) 2022 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 | ENABLE_DOUBLE_VLAN = n
53 | ENABLE_PAGE_REUSE = n
54 | ENABLE_RX_PACKET_FRAGMENT = n
55 |
56 | ifneq ($(KERNELRELEASE),)
57 | obj-m := r8125.o
58 | r8125-objs := r8125_n.o rtl_eeprom.o rtltool.o
59 | ifeq ($(CONFIG_SOC_LAN), y)
60 | EXTRA_CFLAGS += -DCONFIG_SOC_LAN
61 | endif
62 | ifeq ($(ENABLE_REALWOW_SUPPORT), y)
63 | r8125-objs += r8125_realwow.o
64 | EXTRA_CFLAGS += -DENABLE_REALWOW_SUPPORT
65 | endif
66 | ifeq ($(ENABLE_DASH_SUPPORT), y)
67 | r8125-objs += r8125_dash.o
68 | EXTRA_CFLAGS += -DENABLE_DASH_SUPPORT
69 | endif
70 | ifeq ($(ENABLE_DASH_PRINTER_SUPPORT), y)
71 | r8125-objs += r8125_dash.o
72 | EXTRA_CFLAGS += -DENABLE_DASH_SUPPORT -DENABLE_DASH_PRINTER_SUPPORT
73 | endif
74 | EXTRA_CFLAGS += -DCONFIG_R8125_NAPI
75 | EXTRA_CFLAGS += -DCONFIG_R8125_VLAN
76 | ifeq ($(CONFIG_DOWN_SPEED_100), y)
77 | EXTRA_CFLAGS += -DCONFIG_DOWN_SPEED_100
78 | endif
79 | ifeq ($(CONFIG_ASPM), y)
80 | EXTRA_CFLAGS += -DCONFIG_ASPM
81 | endif
82 | ifeq ($(ENABLE_S5WOL), y)
83 | EXTRA_CFLAGS += -DENABLE_S5WOL
84 | endif
85 | ifeq ($(ENABLE_S5_KEEP_CURR_MAC), y)
86 | EXTRA_CFLAGS += -DENABLE_S5_KEEP_CURR_MAC
87 | endif
88 | ifeq ($(ENABLE_EEE), y)
89 | EXTRA_CFLAGS += -DENABLE_EEE
90 | endif
91 | ifeq ($(ENABLE_S0_MAGIC_PACKET), y)
92 | EXTRA_CFLAGS += -DENABLE_S0_MAGIC_PACKET
93 | endif
94 | ifeq ($(ENABLE_TX_NO_CLOSE), y)
95 | EXTRA_CFLAGS += -DENABLE_TX_NO_CLOSE
96 | endif
97 | ifeq ($(ENABLE_MULTIPLE_TX_QUEUE), y)
98 | EXTRA_CFLAGS += -DENABLE_MULTIPLE_TX_QUEUE
99 | endif
100 | ifeq ($(ENABLE_PTP_SUPPORT), y)
101 | r8125-objs += r8125_ptp.o
102 | EXTRA_CFLAGS += -DENABLE_PTP_SUPPORT
103 | endif
104 | ifeq ($(ENABLE_PTP_MASTER_MODE), y)
105 | EXTRA_CFLAGS += -DENABLE_PTP_MASTER_MODE
106 | endif
107 | ifeq ($(ENABLE_RSS_SUPPORT), y)
108 | r8125-objs += r8125_rss.o
109 | EXTRA_CFLAGS += -DENABLE_RSS_SUPPORT
110 | endif
111 | ifeq ($(ENABLE_LIB_SUPPORT), y)
112 | r8125-objs += r8125_lib.o
113 | EXTRA_CFLAGS += -DENABLE_LIB_SUPPORT
114 | endif
115 | ifeq ($(ENABLE_USE_FIRMWARE_FILE), y)
116 | r8125-objs += r8125_firmware.o
117 | EXTRA_CFLAGS += -DENABLE_USE_FIRMWARE_FILE
118 | endif
119 | ifeq ($(DISABLE_PM_SUPPORT), y)
120 | EXTRA_CFLAGS += -DDISABLE_PM_SUPPORT
121 | endif
122 | ifeq ($(DISABLE_MULTI_MSIX_VECTOR), y)
123 | EXTRA_CFLAGS += -DDISABLE_MULTI_MSIX_VECTOR
124 | endif
125 | ifeq ($(ENABLE_DOUBLE_VLAN), y)
126 | EXTRA_CFLAGS += -DENABLE_DOUBLE_VLAN
127 | endif
128 | ifeq ($(ENABLE_PAGE_REUSE), y)
129 | EXTRA_CFLAGS += -DENABLE_PAGE_REUSE
130 | endif
131 | ifeq ($(ENABLE_RX_PACKET_FRAGMENT), y)
132 | EXTRA_CFLAGS += -DENABLE_RX_PACKET_FRAGMENT
133 | endif
134 | else
135 | BASEDIR := /lib/modules/$(shell uname -r)
136 | KERNELDIR ?= $(BASEDIR)/build
137 | PWD :=$(shell pwd)
138 | DRIVERDIR := $(shell find $(BASEDIR)/kernel/drivers/net/ethernet -name realtek -type d)
139 | ifeq ($(DRIVERDIR),)
140 | DRIVERDIR := $(shell find $(BASEDIR)/kernel/drivers/net -name realtek -type d)
141 | endif
142 | ifeq ($(DRIVERDIR),)
143 | DRIVERDIR := $(BASEDIR)/kernel/drivers/net
144 | endif
145 | RTKDIR := $(subst $(BASEDIR)/,,$(DRIVERDIR))
146 |
147 | KERNEL_GCC_VERSION := $(shell cat /proc/version | sed -n 's/.*gcc version \([[:digit:]]\.[[:digit:]]\.[[:digit:]]\).*/\1/p')
148 | CCVERSION = $(shell $(CC) -dumpversion)
149 |
150 | KVER = $(shell uname -r)
151 | KMAJ = $(shell echo $(KVER) | \
152 | sed -e 's/^\([0-9][0-9]*\)\.[0-9][0-9]*\.[0-9][0-9]*.*/\1/')
153 | KMIN = $(shell echo $(KVER) | \
154 | sed -e 's/^[0-9][0-9]*\.\([0-9][0-9]*\)\.[0-9][0-9]*.*/\1/')
155 | KREV = $(shell echo $(KVER) | \
156 | sed -e 's/^[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\).*/\1/')
157 |
158 | kver_ge = $(shell \
159 | echo test | awk '{if($(KMAJ) < $(1)) {print 0} else { \
160 | if($(KMAJ) > $(1)) {print 1} else { \
161 | if($(KMIN) < $(2)) {print 0} else { \
162 | if($(KMIN) > $(2)) {print 1} else { \
163 | if($(KREV) < $(3)) {print 0} else { print 1 } \
164 | }}}}}' \
165 | )
166 |
167 | .PHONY: all
168 | all: print_vars clean modules install
169 |
170 | print_vars:
171 | @echo
172 | @echo "CC: " $(CC)
173 | @echo "CCVERSION: " $(CCVERSION)
174 | @echo "KERNEL_GCC_VERSION: " $(KERNEL_GCC_VERSION)
175 | @echo "KVER: " $(KVER)
176 | @echo "KMAJ: " $(KMAJ)
177 | @echo "KMIN: " $(KMIN)
178 | @echo "KREV: " $(KREV)
179 | @echo "BASEDIR: " $(BASEDIR)
180 | @echo "DRIVERDIR: " $(DRIVERDIR)
181 | @echo "PWD: " $(PWD)
182 | @echo "RTKDIR: " $(RTKDIR)
183 | @echo
184 |
185 | .PHONY:modules
186 | modules:
187 | #ifeq ($(call kver_ge,5,0,0),1)
188 | $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
189 | #else
190 | # $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) modules
191 | #endif
192 |
193 | .PHONY:clean
194 | clean:
195 | #ifeq ($(call kver_ge,5,0,0),1)
196 | $(MAKE) -C $(KERNELDIR) M=$(PWD) clean
197 | #else
198 | # $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) clean
199 | #endif
200 |
201 | .PHONY:install
202 | install:
203 | #ifeq ($(call kver_ge,5,0,0),1)
204 | $(MAKE) -C $(KERNELDIR) M=$(PWD) INSTALL_MOD_DIR=$(RTKDIR) modules_install
205 | #else
206 | # $(MAKE) -C $(KERNELDIR) SUBDIRS=$(PWD) INSTALL_MOD_DIR=$(RTKDIR) modules_install
207 | #endif
208 |
209 | endif
210 |
--------------------------------------------------------------------------------
/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) 2022 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/copy_to_vmkdriver.sh:
--------------------------------------------------------------------------------
1 | rsync -avP "$(dirname $0)/" /build/vsphere/vmkdrivers-gpl/vmkdrivers/src_9/drivers/net/r8125/
2 |
--------------------------------------------------------------------------------
/r8125/kcompat.c:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 |
3 | Intel(R) Gigabit Ethernet Linux driver
4 | Copyright(c) 2007-2013 Intel Corporation.
5 |
6 | This program is free software; you can redistribute it and/or modify it
7 | under the terms and conditions of the GNU General Public License,
8 | version 2, as published by the Free Software Foundation.
9 |
10 | This program is distributed in the hope it will be useful, but WITHOUT
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 | more details.
14 |
15 | You should have received a copy of the GNU General Public License along with
16 | this program; if not, write to the Free Software Foundation, Inc.,
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 |
19 | The full GNU General Public License is included in this distribution in
20 | the file called "COPYING".
21 |
22 | Contact Information:
23 | e1000-devel Mailing List
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 |
26 | *******************************************************************************/
27 |
28 | #include "r8125.h"
29 | #include "kcompat.h"
30 |
31 | /*****************************************************************************/
32 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,8) )
33 | /* From lib/vsprintf.c */
34 | #include
35 |
36 | static int skip_atoi(const char **s)
37 | {
38 | int i=0;
39 |
40 | while (isdigit(**s))
41 | i = i*10 + *((*s)++) - '0';
42 | return i;
43 | }
44 |
45 | #define _kc_ZEROPAD 1 /* pad with zero */
46 | #define _kc_SIGN 2 /* unsigned/signed long */
47 | #define _kc_PLUS 4 /* show plus */
48 | #define _kc_SPACE 8 /* space if plus */
49 | #define _kc_LEFT 16 /* left justified */
50 | #define _kc_SPECIAL 32 /* 0x */
51 | #define _kc_LARGE 64 /* use 'ABCDEF' instead of 'abcdef' */
52 |
53 | static char * number(char * buf, char * end, long long num, int base, int size, int precision, int type)
54 | {
55 | char c,sign,tmp[66];
56 | const char *digits;
57 | const char small_digits[] = "0123456789abcdefghijklmnopqrstuvwxyz";
58 | const char large_digits[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
59 | int i;
60 |
61 | digits = (type & _kc_LARGE) ? large_digits : small_digits;
62 | if (type & _kc_LEFT)
63 | type &= ~_kc_ZEROPAD;
64 | if (base < 2 || base > 36)
65 | return 0;
66 | c = (type & _kc_ZEROPAD) ? '0' : ' ';
67 | sign = 0;
68 | if (type & _kc_SIGN) {
69 | if (num < 0) {
70 | sign = '-';
71 | num = -num;
72 | size--;
73 | } else if (type & _kc_PLUS) {
74 | sign = '+';
75 | size--;
76 | } else if (type & _kc_SPACE) {
77 | sign = ' ';
78 | size--;
79 | }
80 | }
81 | if (type & _kc_SPECIAL) {
82 | if (base == 16)
83 | size -= 2;
84 | else if (base == 8)
85 | size--;
86 | }
87 | i = 0;
88 | if (num == 0)
89 | tmp[i++]='0';
90 | else while (num != 0)
91 | tmp[i++] = digits[do_div(num,base)];
92 | if (i > precision)
93 | precision = i;
94 | size -= precision;
95 | if (!(type&(_kc_ZEROPAD+_kc_LEFT))) {
96 | while(size-->0) {
97 | if (buf <= end)
98 | *buf = ' ';
99 | ++buf;
100 | }
101 | }
102 | if (sign) {
103 | if (buf <= end)
104 | *buf = sign;
105 | ++buf;
106 | }
107 | if (type & _kc_SPECIAL) {
108 | if (base==8) {
109 | if (buf <= end)
110 | *buf = '0';
111 | ++buf;
112 | } else if (base==16) {
113 | if (buf <= end)
114 | *buf = '0';
115 | ++buf;
116 | if (buf <= end)
117 | *buf = digits[33];
118 | ++buf;
119 | }
120 | }
121 | if (!(type & _kc_LEFT)) {
122 | while (size-- > 0) {
123 | if (buf <= end)
124 | *buf = c;
125 | ++buf;
126 | }
127 | }
128 | while (i < precision--) {
129 | if (buf <= end)
130 | *buf = '0';
131 | ++buf;
132 | }
133 | while (i-- > 0) {
134 | if (buf <= end)
135 | *buf = tmp[i];
136 | ++buf;
137 | }
138 | while (size-- > 0) {
139 | if (buf <= end)
140 | *buf = ' ';
141 | ++buf;
142 | }
143 | return buf;
144 | }
145 |
146 | int _kc_vsnprintf(char *buf, size_t size, const char *fmt, va_list args)
147 | {
148 | int len;
149 | unsigned long long num;
150 | int i, base;
151 | char *str, *end, c;
152 | const char *s;
153 |
154 | int flags; /* flags to number() */
155 |
156 | int field_width; /* width of output field */
157 | int precision; /* min. # of digits for integers; max
158 | number of chars for from string */
159 | int qualifier; /* 'h', 'l', or 'L' for integer fields */
160 | /* 'z' support added 23/7/1999 S.H. */
161 | /* 'z' changed to 'Z' --davidm 1/25/99 */
162 |
163 | str = buf;
164 | end = buf + size - 1;
165 |
166 | if (end < buf - 1) {
167 | end = ((void *) -1);
168 | size = end - buf + 1;
169 | }
170 |
171 | for (; *fmt ; ++fmt) {
172 | if (*fmt != '%') {
173 | if (str <= end)
174 | *str = *fmt;
175 | ++str;
176 | continue;
177 | }
178 |
179 | /* process flags */
180 | flags = 0;
181 | repeat:
182 | ++fmt; /* this also skips first '%' */
183 | switch (*fmt) {
184 | case '-': flags |= _kc_LEFT; goto repeat;
185 | case '+': flags |= _kc_PLUS; goto repeat;
186 | case ' ': flags |= _kc_SPACE; goto repeat;
187 | case '#': flags |= _kc_SPECIAL; goto repeat;
188 | case '0': flags |= _kc_ZEROPAD; goto repeat;
189 | }
190 |
191 | /* get field width */
192 | field_width = -1;
193 | if (isdigit(*fmt))
194 | field_width = skip_atoi(&fmt);
195 | else if (*fmt == '*') {
196 | ++fmt;
197 | /* it's the next argument */
198 | field_width = va_arg(args, int);
199 | if (field_width < 0) {
200 | field_width = -field_width;
201 | flags |= _kc_LEFT;
202 | }
203 | }
204 |
205 | /* get the precision */
206 | precision = -1;
207 | if (*fmt == '.') {
208 | ++fmt;
209 | if (isdigit(*fmt))
210 | precision = skip_atoi(&fmt);
211 | else if (*fmt == '*') {
212 | ++fmt;
213 | /* it's the next argument */
214 | precision = va_arg(args, int);
215 | }
216 | if (precision < 0)
217 | precision = 0;
218 | }
219 |
220 | /* get the conversion qualifier */
221 | qualifier = -1;
222 | if (*fmt == 'h' || *fmt == 'l' || *fmt == 'L' || *fmt =='Z') {
223 | qualifier = *fmt;
224 | ++fmt;
225 | }
226 |
227 | /* default base */
228 | base = 10;
229 |
230 | switch (*fmt) {
231 | case 'c':
232 | if (!(flags & _kc_LEFT)) {
233 | while (--field_width > 0) {
234 | if (str <= end)
235 | *str = ' ';
236 | ++str;
237 | }
238 | }
239 | c = (unsigned char) va_arg(args, int);
240 | if (str <= end)
241 | *str = c;
242 | ++str;
243 | while (--field_width > 0) {
244 | if (str <= end)
245 | *str = ' ';
246 | ++str;
247 | }
248 | continue;
249 |
250 | case 's':
251 | s = va_arg(args, char *);
252 | if (!s)
253 | s = "";
254 |
255 | len = strnlen(s, precision);
256 |
257 | if (!(flags & _kc_LEFT)) {
258 | while (len < field_width--) {
259 | if (str <= end)
260 | *str = ' ';
261 | ++str;
262 | }
263 | }
264 | for (i = 0; i < len; ++i) {
265 | if (str <= end)
266 | *str = *s;
267 | ++str; ++s;
268 | }
269 | while (len < field_width--) {
270 | if (str <= end)
271 | *str = ' ';
272 | ++str;
273 | }
274 | continue;
275 |
276 | case 'p':
277 | if (field_width == -1) {
278 | field_width = 2*sizeof(void *);
279 | flags |= _kc_ZEROPAD;
280 | }
281 | str = number(str, end,
282 | (unsigned long) va_arg(args, void *),
283 | 16, field_width, precision, flags);
284 | continue;
285 |
286 |
287 | case 'n':
288 | /* FIXME:
289 | * What does C99 say about the overflow case here? */
290 | if (qualifier == 'l') {
291 | long * ip = va_arg(args, long *);
292 | *ip = (str - buf);
293 | } else if (qualifier == 'Z') {
294 | size_t * ip = va_arg(args, size_t *);
295 | *ip = (str - buf);
296 | } else {
297 | int * ip = va_arg(args, int *);
298 | *ip = (str - buf);
299 | }
300 | continue;
301 |
302 | case '%':
303 | if (str <= end)
304 | *str = '%';
305 | ++str;
306 | continue;
307 |
308 | /* integer number formats - set up the flags and "break" */
309 | case 'o':
310 | base = 8;
311 | break;
312 |
313 | case 'X':
314 | flags |= _kc_LARGE;
315 | case 'x':
316 | base = 16;
317 | break;
318 |
319 | case 'd':
320 | case 'i':
321 | flags |= _kc_SIGN;
322 | case 'u':
323 | break;
324 |
325 | default:
326 | if (str <= end)
327 | *str = '%';
328 | ++str;
329 | if (*fmt) {
330 | if (str <= end)
331 | *str = *fmt;
332 | ++str;
333 | } else {
334 | --fmt;
335 | }
336 | continue;
337 | }
338 | if (qualifier == 'L')
339 | num = va_arg(args, long long);
340 | else if (qualifier == 'l') {
341 | num = va_arg(args, unsigned long);
342 | if (flags & _kc_SIGN)
343 | num = (signed long) num;
344 | } else if (qualifier == 'Z') {
345 | num = va_arg(args, size_t);
346 | } else if (qualifier == 'h') {
347 | num = (unsigned short) va_arg(args, int);
348 | if (flags & _kc_SIGN)
349 | num = (signed short) num;
350 | } else {
351 | num = va_arg(args, unsigned int);
352 | if (flags & _kc_SIGN)
353 | num = (signed int) num;
354 | }
355 | str = number(str, end, num, base,
356 | field_width, precision, flags);
357 | }
358 | if (str <= end)
359 | *str = '\0';
360 | else if (size > 0)
361 | /* don't write out a null byte if the buf size is zero */
362 | *end = '\0';
363 | /* the trailing null byte doesn't count towards the total
364 | * ++str;
365 | */
366 | return str-buf;
367 | }
368 |
369 | int _kc_snprintf(char * buf, size_t size, const char *fmt, ...)
370 | {
371 | va_list args;
372 | int i;
373 |
374 | va_start(args, fmt);
375 | i = _kc_vsnprintf(buf,size,fmt,args);
376 | va_end(args);
377 | return i;
378 | }
379 | #endif /* < 2.4.8 */
380 |
381 | /*****************************************************************************/
382 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,13) )
383 |
384 | /**************************************/
385 | /* PCI DMA MAPPING */
386 |
387 | #if defined(CONFIG_HIGHMEM)
388 |
389 | #ifndef PCI_DRAM_OFFSET
390 | #define PCI_DRAM_OFFSET 0
391 | #endif
392 |
393 | u64
394 | _kc_pci_map_page(struct pci_dev *dev, struct page *page, unsigned long offset,
395 | size_t size, int direction)
396 | {
397 | return (((u64) (page - mem_map) << PAGE_SHIFT) + offset +
398 | PCI_DRAM_OFFSET);
399 | }
400 |
401 | #else /* CONFIG_HIGHMEM */
402 |
403 | u64
404 | _kc_pci_map_page(struct pci_dev *dev, struct page *page, unsigned long offset,
405 | size_t size, int direction)
406 | {
407 | return pci_map_single(dev, (void *)page_address(page) + offset, size,
408 | direction);
409 | }
410 |
411 | #endif /* CONFIG_HIGHMEM */
412 |
413 | void
414 | _kc_pci_unmap_page(struct pci_dev *dev, u64 dma_addr, size_t size,
415 | int direction)
416 | {
417 | return pci_unmap_single(dev, dma_addr, size, direction);
418 | }
419 |
420 | #endif /* 2.4.13 => 2.4.3 */
421 |
422 | /*****************************************************************************/
423 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,3) )
424 |
425 | /**************************************/
426 | /* PCI DRIVER API */
427 |
428 | int
429 | _kc_pci_set_dma_mask(struct pci_dev *dev, dma_addr_t mask)
430 | {
431 | if (!pci_dma_supported(dev, mask))
432 | return -EIO;
433 | dev->dma_mask = mask;
434 | return 0;
435 | }
436 |
437 | int
438 | _kc_pci_request_regions(struct pci_dev *dev, char *res_name)
439 | {
440 | int i;
441 |
442 | for (i = 0; i < 6; i++) {
443 | if (pci_resource_len(dev, i) == 0)
444 | continue;
445 |
446 | if (pci_resource_flags(dev, i) & IORESOURCE_IO) {
447 | if (!request_region(pci_resource_start(dev, i), pci_resource_len(dev, i), res_name)) {
448 | pci_release_regions(dev);
449 | return -EBUSY;
450 | }
451 | } else if (pci_resource_flags(dev, i) & IORESOURCE_MEM) {
452 | if (!request_mem_region(pci_resource_start(dev, i), pci_resource_len(dev, i), res_name)) {
453 | pci_release_regions(dev);
454 | return -EBUSY;
455 | }
456 | }
457 | }
458 | return 0;
459 | }
460 |
461 | void
462 | _kc_pci_release_regions(struct pci_dev *dev)
463 | {
464 | int i;
465 |
466 | for (i = 0; i < 6; i++) {
467 | if (pci_resource_len(dev, i) == 0)
468 | continue;
469 |
470 | if (pci_resource_flags(dev, i) & IORESOURCE_IO)
471 | release_region(pci_resource_start(dev, i), pci_resource_len(dev, i));
472 |
473 | else if (pci_resource_flags(dev, i) & IORESOURCE_MEM)
474 | release_mem_region(pci_resource_start(dev, i), pci_resource_len(dev, i));
475 | }
476 | }
477 |
478 | /**************************************/
479 | /* NETWORK DRIVER API */
480 |
481 | struct net_device *
482 | _kc_alloc_etherdev(int sizeof_priv)
483 | {
484 | struct net_device *dev;
485 | int alloc_size;
486 |
487 | alloc_size = sizeof(*dev) + sizeof_priv + IFNAMSIZ + 31;
488 | dev = kzalloc(alloc_size, GFP_KERNEL);
489 | if (!dev)
490 | return NULL;
491 |
492 | if (sizeof_priv)
493 | dev->priv = (void *) (((unsigned long)(dev + 1) + 31) & ~31);
494 | dev->name[0] = '\0';
495 | ether_setup(dev);
496 |
497 | return dev;
498 | }
499 |
500 | int
501 | _kc_is_valid_ether_addr(u8 *addr)
502 | {
503 | const char zaddr[6] = { 0, };
504 |
505 | return !(addr[0] & 1) && memcmp(addr, zaddr, 6);
506 | }
507 |
508 | #endif /* 2.4.3 => 2.4.0 */
509 |
510 | /*****************************************************************************/
511 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6) )
512 |
513 | int
514 | _kc_pci_set_power_state(struct pci_dev *dev, int state)
515 | {
516 | return 0;
517 | }
518 |
519 | int
520 | _kc_pci_enable_wake(struct pci_dev *pdev, u32 state, int enable)
521 | {
522 | return 0;
523 | }
524 |
525 | #endif /* 2.4.6 => 2.4.3 */
526 |
527 | /*****************************************************************************/
528 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) )
529 | void _kc_skb_fill_page_desc(struct sk_buff *skb, int i, struct page *page,
530 | int off, int size)
531 | {
532 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
533 | frag->page = page;
534 | frag->page_offset = off;
535 | frag->size = size;
536 | skb_shinfo(skb)->nr_frags = i + 1;
537 | }
538 |
539 | #ifndef __VMKLNX__
540 | /*
541 | * Original Copyright:
542 | * find_next_bit.c: fallback find next bit implementation
543 | *
544 | * Copyright (C) 2004 Red Hat, Inc. All Rights Reserved.
545 | * Written by David Howells (dhowells@redhat.com)
546 | */
547 |
548 | /**
549 | * find_next_bit - find the next set bit in a memory region
550 | * @addr: The address to base the search on
551 | * @offset: The bitnumber to start searching at
552 | * @size: The maximum size to search
553 | */
554 | unsigned long find_next_bit(const unsigned long *addr, unsigned long size,
555 | unsigned long offset)
556 | {
557 | const unsigned long *p = addr + BITOP_WORD(offset);
558 | unsigned long result = offset & ~(BITS_PER_LONG-1);
559 | unsigned long tmp;
560 |
561 | if (offset >= size)
562 | return size;
563 | size -= result;
564 | offset %= BITS_PER_LONG;
565 | if (offset) {
566 | tmp = *(p++);
567 | tmp &= (~0UL << offset);
568 | if (size < BITS_PER_LONG)
569 | goto found_first;
570 | if (tmp)
571 | goto found_middle;
572 | size -= BITS_PER_LONG;
573 | result += BITS_PER_LONG;
574 | }
575 | while (size & ~(BITS_PER_LONG-1)) {
576 | if ((tmp = *(p++)))
577 | goto found_middle;
578 | result += BITS_PER_LONG;
579 | size -= BITS_PER_LONG;
580 | }
581 | if (!size)
582 | return result;
583 | tmp = *p;
584 |
585 | found_first:
586 | tmp &= (~0UL >> (BITS_PER_LONG - size));
587 | if (tmp == 0UL) /* Are any bits set? */
588 | return result + size; /* Nope. */
589 | found_middle:
590 | return result + ffs(tmp);
591 | }
592 | #endif /* __VMKLNX__ */
593 |
594 | size_t _kc_strlcpy(char *dest, const char *src, size_t size)
595 | {
596 | size_t ret = strlen(src);
597 |
598 | if (size) {
599 | size_t len = (ret >= size) ? size - 1 : ret;
600 | memcpy(dest, src, len);
601 | dest[len] = '\0';
602 | }
603 | return ret;
604 | }
605 |
606 | #ifndef do_div
607 | #if BITS_PER_LONG == 32
608 | uint32_t __attribute__((weak)) _kc__div64_32(uint64_t *n, uint32_t base)
609 | {
610 | uint64_t rem = *n;
611 | uint64_t b = base;
612 | uint64_t res, d = 1;
613 | uint32_t high = rem >> 32;
614 |
615 | /* Reduce the thing a bit first */
616 | res = 0;
617 | if (high >= base) {
618 | high /= base;
619 | res = (uint64_t) high << 32;
620 | rem -= (uint64_t) (high*base) << 32;
621 | }
622 |
623 | while ((int64_t)b > 0 && b < rem) {
624 | b = b+b;
625 | d = d+d;
626 | }
627 |
628 | do {
629 | if (rem >= b) {
630 | rem -= b;
631 | res += d;
632 | }
633 | b >>= 1;
634 | d >>= 1;
635 | } while (d);
636 |
637 | *n = res;
638 | return rem;
639 | }
640 | #endif /* BITS_PER_LONG == 32 */
641 | #endif /* do_div */
642 | #endif /* 2.6.0 => 2.4.6 */
643 |
644 | /*****************************************************************************/
645 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,4) )
646 | int _kc_scnprintf(char * buf, size_t size, const char *fmt, ...)
647 | {
648 | va_list args;
649 | int i;
650 |
651 | va_start(args, fmt);
652 | i = vsnprintf(buf, size, fmt, args);
653 | va_end(args);
654 | return (i >= size) ? (size - 1) : i;
655 | }
656 | #endif /* < 2.6.4 */
657 |
658 | /*****************************************************************************/
659 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,10) )
660 | DECLARE_BITMAP(_kcompat_node_online_map, MAX_NUMNODES) = {1};
661 | #endif /* < 2.6.10 */
662 |
663 | /*****************************************************************************/
664 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13) )
665 | char *_kc_kstrdup(const char *s, unsigned int gfp)
666 | {
667 | size_t len;
668 | char *buf;
669 |
670 | if (!s)
671 | return NULL;
672 |
673 | len = strlen(s) + 1;
674 | buf = kmalloc(len, gfp);
675 | if (buf)
676 | memcpy(buf, s, len);
677 | return buf;
678 | }
679 | #endif /* < 2.6.13 */
680 |
681 | /*****************************************************************************/
682 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14) )
683 | void *_kc_kzalloc(size_t size, int flags)
684 | {
685 | void *ret = kmalloc(size, flags);
686 | if (ret)
687 | memset(ret, 0, size);
688 | return ret;
689 | }
690 | #endif /* <= 2.6.13 */
691 |
692 | /*****************************************************************************/
693 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) )
694 | int _kc_skb_pad(struct sk_buff *skb, int pad)
695 | {
696 | int ntail;
697 |
698 | /* If the skbuff is non linear tailroom is always zero.. */
699 | if(!skb_cloned(skb) && skb_tailroom(skb) >= pad) {
700 | memset(skb->data+skb->len, 0, pad);
701 | return 0;
702 | }
703 |
704 | ntail = skb->data_len + pad - (skb->end - skb->tail);
705 | if (likely(skb_cloned(skb) || ntail > 0)) {
706 | if (pskb_expand_head(skb, 0, ntail, GFP_ATOMIC));
707 | goto free_skb;
708 | }
709 |
710 | #ifdef MAX_SKB_FRAGS
711 | if (skb_is_nonlinear(skb) &&
712 | !__pskb_pull_tail(skb, skb->data_len))
713 | goto free_skb;
714 |
715 | #endif
716 | memset(skb->data + skb->len, 0, pad);
717 | return 0;
718 |
719 | free_skb:
720 | kfree_skb(skb);
721 | return -ENOMEM;
722 | }
723 |
724 | #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE >= RHEL_RELEASE_VERSION(5,4)))
725 | int _kc_pci_save_state(struct pci_dev *pdev)
726 | {
727 | struct net_device *netdev = pci_get_drvdata(pdev);
728 | struct adapter_struct *adapter = netdev_priv(netdev);
729 | int size = PCI_CONFIG_SPACE_LEN, i;
730 | u16 pcie_cap_offset, pcie_link_status;
731 |
732 | #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0) )
733 | /* no ->dev for 2.4 kernels */
734 | WARN_ON(pdev->dev.driver_data == NULL);
735 | #endif
736 | pcie_cap_offset = pci_find_capability(pdev, PCI_CAP_ID_EXP);
737 | if (pcie_cap_offset) {
738 | if (!pci_read_config_word(pdev,
739 | pcie_cap_offset + PCIE_LINK_STATUS,
740 | &pcie_link_status))
741 | size = PCIE_CONFIG_SPACE_LEN;
742 | }
743 | pci_config_space_ich8lan();
744 | #ifdef HAVE_PCI_ERS
745 | if (adapter->config_space == NULL)
746 | #else
747 | WARN_ON(adapter->config_space != NULL);
748 | #endif
749 | adapter->config_space = kmalloc(size, GFP_KERNEL);
750 | if (!adapter->config_space) {
751 | printk(KERN_ERR "Out of memory in pci_save_state\n");
752 | return -ENOMEM;
753 | }
754 | for (i = 0; i < (size / 4); i++)
755 | pci_read_config_dword(pdev, i * 4, &adapter->config_space[i]);
756 | return 0;
757 | }
758 |
759 | void _kc_pci_restore_state(struct pci_dev *pdev)
760 | {
761 | struct net_device *netdev = pci_get_drvdata(pdev);
762 | struct adapter_struct *adapter = netdev_priv(netdev);
763 | int size = PCI_CONFIG_SPACE_LEN, i;
764 | u16 pcie_cap_offset;
765 | u16 pcie_link_status;
766 |
767 | if (adapter->config_space != NULL) {
768 | pcie_cap_offset = pci_find_capability(pdev, PCI_CAP_ID_EXP);
769 | if (pcie_cap_offset &&
770 | !pci_read_config_word(pdev,
771 | pcie_cap_offset + PCIE_LINK_STATUS,
772 | &pcie_link_status))
773 | size = PCIE_CONFIG_SPACE_LEN;
774 |
775 | pci_config_space_ich8lan();
776 | for (i = 0; i < (size / 4); i++)
777 | pci_write_config_dword(pdev, i * 4, adapter->config_space[i]);
778 | #ifndef HAVE_PCI_ERS
779 | kfree(adapter->config_space);
780 | adapter->config_space = NULL;
781 | #endif
782 | }
783 | }
784 | #endif /* !(RHEL_RELEASE_CODE >= RHEL 5.4) */
785 |
786 | #ifdef HAVE_PCI_ERS
787 | void _kc_free_netdev(struct net_device *netdev)
788 | {
789 | struct adapter_struct *adapter = netdev_priv(netdev);
790 |
791 | if (adapter->config_space != NULL)
792 | kfree(adapter->config_space);
793 | #ifdef CONFIG_SYSFS
794 | if (netdev->reg_state == NETREG_UNINITIALIZED) {
795 | kfree((char *)netdev - netdev->padded);
796 | } else {
797 | BUG_ON(netdev->reg_state != NETREG_UNREGISTERED);
798 | netdev->reg_state = NETREG_RELEASED;
799 | class_device_put(&netdev->class_dev);
800 | }
801 | #else
802 | kfree((char *)netdev - netdev->padded);
803 | #endif
804 | }
805 | #endif
806 |
807 | void *_kc_kmemdup(const void *src, size_t len, unsigned gfp)
808 | {
809 | void *p;
810 |
811 | p = kzalloc(len, gfp);
812 | if (p)
813 | memcpy(p, src, len);
814 | return p;
815 | }
816 | #endif /* <= 2.6.19 */
817 |
818 | /*****************************************************************************/
819 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,21) )
820 | struct pci_dev *_kc_netdev_to_pdev(struct net_device *netdev)
821 | {
822 | return ((struct adapter_struct *)netdev_priv(netdev))->pdev;
823 | }
824 | #endif /* < 2.6.21 */
825 |
826 | /*****************************************************************************/
827 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22) )
828 | /* hexdump code taken from lib/hexdump.c */
829 | static void _kc_hex_dump_to_buffer(const void *buf, size_t len, int rowsize,
830 | int groupsize, unsigned char *linebuf,
831 | size_t linebuflen, bool ascii)
832 | {
833 | const u8 *ptr = buf;
834 | u8 ch;
835 | int j, lx = 0;
836 | int ascii_column;
837 |
838 | if (rowsize != 16 && rowsize != 32)
839 | rowsize = 16;
840 |
841 | if (!len)
842 | goto nil;
843 | if (len > rowsize) /* limit to one line at a time */
844 | len = rowsize;
845 | if ((len % groupsize) != 0) /* no mixed size output */
846 | groupsize = 1;
847 |
848 | switch (groupsize) {
849 | case 8: {
850 | const u64 *ptr8 = buf;
851 | int ngroups = len / groupsize;
852 |
853 | for (j = 0; j < ngroups; j++)
854 | lx += scnprintf((char *)(linebuf + lx), linebuflen - lx,
855 | "%s%16.16llx", j ? " " : "",
856 | (unsigned long long)*(ptr8 + j));
857 | ascii_column = 17 * ngroups + 2;
858 | break;
859 | }
860 |
861 | case 4: {
862 | const u32 *ptr4 = buf;
863 | int ngroups = len / groupsize;
864 |
865 | for (j = 0; j < ngroups; j++)
866 | lx += scnprintf((char *)(linebuf + lx), linebuflen - lx,
867 | "%s%8.8x", j ? " " : "", *(ptr4 + j));
868 | ascii_column = 9 * ngroups + 2;
869 | break;
870 | }
871 |
872 | case 2: {
873 | const u16 *ptr2 = buf;
874 | int ngroups = len / groupsize;
875 |
876 | for (j = 0; j < ngroups; j++)
877 | lx += scnprintf((char *)(linebuf + lx), linebuflen - lx,
878 | "%s%4.4x", j ? " " : "", *(ptr2 + j));
879 | ascii_column = 5 * ngroups + 2;
880 | break;
881 | }
882 |
883 | default:
884 | for (j = 0; (j < len) && (lx + 3) <= linebuflen; j++) {
885 | ch = ptr[j];
886 | linebuf[lx++] = hex_asc(ch >> 4);
887 | linebuf[lx++] = hex_asc(ch & 0x0f);
888 | linebuf[lx++] = ' ';
889 | }
890 | if (j)
891 | lx--;
892 |
893 | ascii_column = 3 * rowsize + 2;
894 | break;
895 | }
896 | if (!ascii)
897 | goto nil;
898 |
899 | while (lx < (linebuflen - 1) && lx < (ascii_column - 1))
900 | linebuf[lx++] = ' ';
901 | for (j = 0; (j < len) && (lx + 2) < linebuflen; j++)
902 | linebuf[lx++] = (isascii(ptr[j]) && isprint(ptr[j])) ? ptr[j]
903 | : '.';
904 | nil:
905 | linebuf[lx++] = '\0';
906 | }
907 |
908 | void _kc_print_hex_dump(const char *level,
909 | const char *prefix_str, int prefix_type,
910 | int rowsize, int groupsize,
911 | const void *buf, size_t len, bool ascii)
912 | {
913 | const u8 *ptr = buf;
914 | int i, linelen, remaining = len;
915 | unsigned char linebuf[200];
916 |
917 | if (rowsize != 16 && rowsize != 32)
918 | rowsize = 16;
919 |
920 | for (i = 0; i < len; i += rowsize) {
921 | linelen = min(remaining, rowsize);
922 | remaining -= rowsize;
923 | _kc_hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
924 | linebuf, sizeof(linebuf), ascii);
925 |
926 | switch (prefix_type) {
927 | case DUMP_PREFIX_ADDRESS:
928 | printk("%s%s%*p: %s\n", level, prefix_str,
929 | (int)(2 * sizeof(void *)), ptr + i, linebuf);
930 | break;
931 | case DUMP_PREFIX_OFFSET:
932 | printk("%s%s%.8x: %s\n", level, prefix_str, i, linebuf);
933 | break;
934 | default:
935 | printk("%s%s%s\n", level, prefix_str, linebuf);
936 | break;
937 | }
938 | }
939 | }
940 |
941 | #endif /* < 2.6.22 */
942 |
943 | /*****************************************************************************/
944 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24) )
945 | #endif /* <= 2.6.24 */
946 |
947 | /*****************************************************************************/
948 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26) )
949 | #endif /* < 2.6.26 */
950 |
951 | /*****************************************************************************/
952 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27) )
953 | #ifdef HAVE_TX_MQ
954 | #endif /* HAVE_TX_MQ */
955 |
956 | #ifndef __WARN_printf
957 | void __kc_warn_slowpath(const char *file, int line, const char *fmt, ...)
958 | {
959 | va_list args;
960 |
961 | printk(KERN_WARNING "------------[ cut here ]------------\n");
962 | printk(KERN_WARNING "WARNING: at %s:%d %s()\n", file, line);
963 | va_start(args, fmt);
964 | vprintk(fmt, args);
965 | va_end(args);
966 |
967 | dump_stack();
968 | }
969 | #endif /* __WARN_printf */
970 | #endif /* < 2.6.27 */
971 |
972 | /*****************************************************************************/
973 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,28) )
974 |
975 | //PCIe MSIX backport
976 | int _kc_pci_enable_msix_range(struct pci_dev *dev, struct msix_entry *entries,
977 | int minvec, int maxvec)
978 | {
979 | int nvec = maxvec;
980 | int rc;
981 |
982 | if (maxvec < minvec)
983 | return -ERANGE;
984 |
985 | do {
986 | rc = pci_enable_msix(dev, entries, nvec);
987 | if (rc < 0) {
988 | return rc;
989 | } else if (rc > 0) {
990 | if (rc < minvec)
991 | return -ENOSPC;
992 | nvec = rc;
993 | }
994 | } while (rc);
995 |
996 | return nvec;
997 | }
998 |
999 | int
1000 | _kc_pci_prepare_to_sleep(struct pci_dev *dev)
1001 | {
1002 | pci_power_t target_state;
1003 | int error;
1004 |
1005 | target_state = pci_choose_state(dev, PMSG_SUSPEND);
1006 |
1007 | pci_enable_wake(dev, target_state, true);
1008 |
1009 | error = pci_set_power_state(dev, target_state);
1010 |
1011 | if (error)
1012 | pci_enable_wake(dev, target_state, false);
1013 |
1014 | return error;
1015 | }
1016 |
1017 | int
1018 | _kc_pci_wake_from_d3(struct pci_dev *dev, bool enable)
1019 | {
1020 | int err;
1021 |
1022 | err = pci_enable_wake(dev, PCI_D3cold, enable);
1023 | if (err)
1024 | goto out;
1025 |
1026 | err = pci_enable_wake(dev, PCI_D3hot, enable);
1027 |
1028 | out:
1029 | return err;
1030 | }
1031 | #endif /* < 2.6.28 */
1032 |
1033 | /*****************************************************************************/
1034 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,29) )
1035 | static void __kc_pci_set_master(struct pci_dev *pdev, bool enable)
1036 | {
1037 | u16 old_cmd, cmd;
1038 |
1039 | pci_read_config_word(pdev, PCI_COMMAND, &old_cmd);
1040 | if (enable)
1041 | cmd = old_cmd | PCI_COMMAND_MASTER;
1042 | else
1043 | cmd = old_cmd & ~PCI_COMMAND_MASTER;
1044 | if (cmd != old_cmd) {
1045 | dev_dbg(pci_dev_to_dev(pdev), "%s bus mastering\n",
1046 | enable ? "enabling" : "disabling");
1047 | pci_write_config_word(pdev, PCI_COMMAND, cmd);
1048 | }
1049 | #if ( LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,7) )
1050 | pdev->is_busmaster = enable;
1051 | #endif
1052 | }
1053 |
1054 | void _kc_pci_clear_master(struct pci_dev *dev)
1055 | {
1056 | __kc_pci_set_master(dev, false);
1057 | }
1058 | #endif /* < 2.6.29 */
1059 |
1060 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,34) )
1061 | #if (RHEL_RELEASE_CODE < RHEL_RELEASE_VERSION(6,0))
1062 | int _kc_pci_num_vf(struct pci_dev *dev)
1063 | {
1064 | int num_vf = 0;
1065 | #ifndef __VMKLNX__
1066 | #endif
1067 | return num_vf;
1068 | }
1069 | #endif /* RHEL_RELEASE_CODE */
1070 | #endif /* < 2.6.34 */
1071 |
1072 |
1073 | /*****************************************************************************/
1074 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36) )
1075 | static const u32 _kc_flags_dup_features =
1076 | (ETH_FLAG_LRO | ETH_FLAG_NTUPLE | ETH_FLAG_RXHASH);
1077 |
1078 | u32 _kc_ethtool_op_get_flags(struct net_device *dev)
1079 | {
1080 | return dev->features & _kc_flags_dup_features;
1081 | }
1082 |
1083 | int _kc_ethtool_op_set_flags(struct net_device *dev, u32 data, u32 supported)
1084 | {
1085 | if (data & ~supported)
1086 | return -EINVAL;
1087 |
1088 | dev->features = ((dev->features & ~_kc_flags_dup_features) |
1089 | (data & _kc_flags_dup_features));
1090 | return 0;
1091 | }
1092 | #endif /* < 2.6.36 */
1093 |
1094 | /******************************************************************************/
1095 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(2,6,39) )
1096 | #if (!(RHEL_RELEASE_CODE && RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(6,0)))
1097 |
1098 |
1099 |
1100 | #endif /* !(RHEL_RELEASE_CODE > RHEL_RELEASE_VERSION(6,0)) */
1101 | #endif /* < 2.6.39 */
1102 |
1103 | /******************************************************************************/
1104 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,4,0) )
1105 | void _kc_skb_add_rx_frag(struct sk_buff *skb, int i, struct page *page,
1106 | int off, int size, unsigned int truesize)
1107 | {
1108 | skb_fill_page_desc(skb, i, page, off, size);
1109 | skb->len += size;
1110 | skb->data_len += size;
1111 | #ifndef __VMKLNX__
1112 | skb->truesize += truesize;
1113 | #endif
1114 | }
1115 |
1116 | int _kc_simple_open(struct inode *inode, struct file *file)
1117 | {
1118 | if (inode->i_private)
1119 | file->private_data = inode->i_private;
1120 |
1121 | return 0;
1122 | }
1123 |
1124 | #endif /* < 3.4.0 */
1125 |
1126 | /******************************************************************************/
1127 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,7,0) )
1128 | #if !(SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(11,3,0))
1129 | static inline int __kc_pcie_cap_version(struct pci_dev *dev)
1130 | {
1131 | int pos;
1132 | u16 reg16;
1133 |
1134 | pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
1135 | if (!pos)
1136 | return 0;
1137 | pci_read_config_word(dev, pos + PCI_EXP_FLAGS, ®16);
1138 | return reg16 & PCI_EXP_FLAGS_VERS;
1139 | }
1140 |
1141 | static inline bool __kc_pcie_cap_has_devctl(const struct pci_dev __always_unused *dev)
1142 | {
1143 | return true;
1144 | }
1145 |
1146 | static inline bool __kc_pcie_cap_has_lnkctl(struct pci_dev *dev)
1147 | {
1148 | int type = pci_pcie_type(dev);
1149 |
1150 | return __kc_pcie_cap_version(dev) > 1 ||
1151 | type == PCI_EXP_TYPE_ROOT_PORT ||
1152 | type == PCI_EXP_TYPE_ENDPOINT ||
1153 | type == PCI_EXP_TYPE_LEG_END;
1154 | }
1155 |
1156 | static inline bool __kc_pcie_cap_has_sltctl(struct pci_dev *dev)
1157 | {
1158 | int type = pci_pcie_type(dev);
1159 | int pos;
1160 | u16 pcie_flags_reg;
1161 |
1162 | pos = pci_find_capability(dev, PCI_CAP_ID_EXP);
1163 | if (!pos)
1164 | return 0;
1165 | pci_read_config_word(dev, pos + PCI_EXP_FLAGS, &pcie_flags_reg);
1166 |
1167 | return __kc_pcie_cap_version(dev) > 1 ||
1168 | type == PCI_EXP_TYPE_ROOT_PORT ||
1169 | (type == PCI_EXP_TYPE_DOWNSTREAM &&
1170 | pcie_flags_reg & PCI_EXP_FLAGS_SLOT);
1171 | }
1172 |
1173 | static inline bool __kc_pcie_cap_has_rtctl(struct pci_dev *dev)
1174 | {
1175 | int type = pci_pcie_type(dev);
1176 |
1177 | return __kc_pcie_cap_version(dev) > 1 ||
1178 | type == PCI_EXP_TYPE_ROOT_PORT ||
1179 | type == PCI_EXP_TYPE_RC_EC;
1180 | }
1181 |
1182 | static bool __kc_pcie_capability_reg_implemented(struct pci_dev *dev, int pos)
1183 | {
1184 | if (!pci_is_pcie(dev))
1185 | return false;
1186 |
1187 | switch (pos) {
1188 | case PCI_EXP_FLAGS_TYPE:
1189 | return true;
1190 | case PCI_EXP_DEVCAP:
1191 | case PCI_EXP_DEVCTL:
1192 | case PCI_EXP_DEVSTA:
1193 | return __kc_pcie_cap_has_devctl(dev);
1194 | case PCI_EXP_LNKCAP:
1195 | case PCI_EXP_LNKCTL:
1196 | case PCI_EXP_LNKSTA:
1197 | return __kc_pcie_cap_has_lnkctl(dev);
1198 | case PCI_EXP_SLTCAP:
1199 | case PCI_EXP_SLTCTL:
1200 | case PCI_EXP_SLTSTA:
1201 | return __kc_pcie_cap_has_sltctl(dev);
1202 | case PCI_EXP_RTCTL:
1203 | case PCI_EXP_RTCAP:
1204 | case PCI_EXP_RTSTA:
1205 | return __kc_pcie_cap_has_rtctl(dev);
1206 | case PCI_EXP_DEVCAP2:
1207 | case PCI_EXP_DEVCTL2:
1208 | case PCI_EXP_LNKCAP2:
1209 | case PCI_EXP_LNKCTL2:
1210 | case PCI_EXP_LNKSTA2:
1211 | return __kc_pcie_cap_version(dev) > 1;
1212 | default:
1213 | return false;
1214 | }
1215 | }
1216 |
1217 | /*
1218 | * Note that these accessor functions are only for the "PCI Express
1219 | * Capability" (see PCIe spec r3.0, sec 7.8). They do not apply to the
1220 | * other "PCI Express Extended Capabilities" (AER, VC, ACS, MFVC, etc.)
1221 | */
1222 | int __kc_pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val)
1223 | {
1224 | int ret;
1225 |
1226 | *val = 0;
1227 | if (pos & 1)
1228 | return -EINVAL;
1229 |
1230 | if (__kc_pcie_capability_reg_implemented(dev, pos)) {
1231 | ret = pci_read_config_word(dev, pci_pcie_cap(dev) + pos, val);
1232 | /*
1233 | * Reset *val to 0 if pci_read_config_word() fails, it may
1234 | * have been written as 0xFFFF if hardware error happens
1235 | * during pci_read_config_word().
1236 | */
1237 | if (ret)
1238 | *val = 0;
1239 | return ret;
1240 | }
1241 |
1242 | /*
1243 | * For Functions that do not implement the Slot Capabilities,
1244 | * Slot Status, and Slot Control registers, these spaces must
1245 | * be hardwired to 0b, with the exception of the Presence Detect
1246 | * State bit in the Slot Status register of Downstream Ports,
1247 | * which must be hardwired to 1b. (PCIe Base Spec 3.0, sec 7.8)
1248 | */
1249 | if (pci_is_pcie(dev) && pos == PCI_EXP_SLTSTA &&
1250 | pci_pcie_type(dev) == PCI_EXP_TYPE_DOWNSTREAM) {
1251 | *val = PCI_EXP_SLTSTA_PDS;
1252 | }
1253 |
1254 | return 0;
1255 | }
1256 |
1257 | int __kc_pcie_capability_write_word(struct pci_dev *dev, int pos, u16 val)
1258 | {
1259 | if (pos & 1)
1260 | return -EINVAL;
1261 |
1262 | if (!__kc_pcie_capability_reg_implemented(dev, pos))
1263 | return 0;
1264 |
1265 | return pci_write_config_word(dev, pci_pcie_cap(dev) + pos, val);
1266 | }
1267 |
1268 | int __kc_pcie_capability_clear_and_set_word(struct pci_dev *dev, int pos,
1269 | u16 clear, u16 set)
1270 | {
1271 | int ret;
1272 | u16 val;
1273 |
1274 | ret = __kc_pcie_capability_read_word(dev, pos, &val);
1275 | if (!ret) {
1276 | val &= ~clear;
1277 | val |= set;
1278 | ret = __kc_pcie_capability_write_word(dev, pos, val);
1279 | }
1280 |
1281 | return ret;
1282 | }
1283 | #endif /* !(SLE_VERSION_CODE && SLE_VERSION_CODE >= SLE_VERSION(11,3,0)) */
1284 | #endif /* < 3.7.0 */
1285 |
1286 | /******************************************************************************/
1287 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,9,0) )
1288 | #endif /* 3.9.0 */
1289 |
1290 | /*****************************************************************************/
1291 | #if ( LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) )
1292 | #endif /* 3.10.0 */
1293 |
--------------------------------------------------------------------------------
/r8125/kcompat_esx.h:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 |
3 | Intel(R) Gigabit Ethernet Linux driver
4 | Copyright(c) 2007-2013 Intel Corporation.
5 |
6 | This program is free software; you can redistribute it and/or modify it
7 | under the terms and conditions of the GNU General Public License,
8 | version 2, as published by the Free Software Foundation.
9 |
10 | This program is distributed in the hope it will be useful, but WITHOUT
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 | more details.
14 |
15 | You should have received a copy of the GNU General Public License along with
16 | this program; if not, write to the Free Software Foundation, Inc.,
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 |
19 | The full GNU General Public License is included in this distribution in
20 | the file called "COPYING".
21 |
22 | Contact Information:
23 | e1000-devel Mailing List
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 |
26 | *******************************************************************************/
27 |
28 | /*
29 | *
30 | * VMware ESX compatibility layer
31 | *
32 | */
33 |
34 | #include "vmkapi.h"
35 |
36 | #define ESX40_PRODUCT_VER "4.0.0"
37 | #define ESX41_PRODUCT_VER "4.1.0"
38 | #define ESX50_PRODUCT_VER "5.0.0"
39 | #define ESX51_PRODUCT_VER "5.1.0"
40 |
41 | /* disable features that VMware ESX does not support */
42 |
43 | #ifndef CONFIG_PM
44 | #undef device_init_wakeup
45 | #define device_init_wakeup(dev, val) \
46 | ((dev)->power.can_wakeup = !!val)
47 | #undef device_set_wakeup_enable
48 | #define device_set_wakeup_enable(dev, val) do { } while (0)
49 | #endif /* CONFIG_PM */
50 |
51 | #define cpu_to_be16(x) __constant_htons(x)
52 |
53 | #define vmalloc_node(a,b) vmalloc(a)
54 |
55 | #define skb_record_rx_queue(a, b) \
56 | vmknetddi_queueops_set_skb_queueid((a), \
57 | VMKNETDDI_QUEUEOPS_MK_RX_QUEUEID((b)));
58 |
59 |
60 | #define skb_trim _kc_skb_trim
61 | static inline void _kc_skb_trim(struct sk_buff *skb, unsigned int len)
62 | {
63 | if (skb->len > len) {
64 | if (unlikely(skb->data_len)) {
65 | WARN_ON(1);
66 | return;
67 | }
68 | skb->len = len;
69 | skb->tail = skb->data + len;
70 | }
71 | }
72 |
73 | /* Alternate __VMKLNX__ DMA memory allocation stuff */
74 | #define alloc_page(A) __get_free_pages(A, 0)
75 | #define pci_map_page(A,B,C,D,E) (page_to_phys(B) + (C))
76 | #define pci_unmap_page(A,B,C,D)
77 | #define pci_unmap_single(A,B,C,D)
78 | #define put_page(A) free_pages(A, 0)
79 |
80 | /* multiqueue netdev magic */
81 | #define egress_subqueue_count real_num_tx_queues
82 |
83 | /*
84 | * A couple of quick hacks for working with esx40
85 | */
86 | #define vmknetddi_queueops_queue_features_t unsigned int
87 | #define HAVE_NETDEV_NAPI_LIST
88 | #define vmk_set_module_version(x,y) 1
89 | #define VMKNETDDI_REGISTER_QUEUEOPS(ndev, ops) \
90 | do { \
91 | ndev->netqueue_ops = ops; \
92 | } while (0)
93 |
94 | #ifdef NETIF_F_SW_LRO
95 | #define NETIF_F_LRO NETIF_F_SW_LRO
96 | #endif
97 |
98 | #define dca3_get_tag(d, c) dca_get_tag(c)
99 | #define dca_unregister_notify(x)
100 | #define dca_register_notify(x)
101 |
102 | #define USE_REBOOT_NOTIFIER
103 | #define device_set_wakeup_enable(d, w) device_init_wakeup(d, w);
104 |
105 |
106 | #define nr_cpu_ids smp_num_cpus
107 | #define ESX_ALLOC_PERCPU( type ) \
108 | kmalloc(sizeof(type) * nr_cpu_ids, GFP_KERNEL)
109 | #define ESX_FREE_PERCPU( ptr ) kfree(ptr)
110 | #define ESX_PER_CPU_PTR( ptr, cpu, type ) (((cpu) < nr_cpu_ids)? \
111 | ((typeof(ptr))((char*)(ptr) + (cpu) * sizeof(type))):NULL)
112 | #define __percpu
113 |
--------------------------------------------------------------------------------
/r8125/kcompat_ethtool.c:
--------------------------------------------------------------------------------
1 | /*******************************************************************************
2 |
3 | Intel(R) Gigabit Ethernet Linux driver
4 | Copyright(c) 2007-2013 Intel Corporation.
5 |
6 | This program is free software; you can redistribute it and/or modify it
7 | under the terms and conditions of the GNU General Public License,
8 | version 2, as published by the Free Software Foundation.
9 |
10 | This program is distributed in the hope it will be useful, but WITHOUT
11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 | more details.
14 |
15 | You should have received a copy of the GNU General Public License along with
16 | this program; if not, write to the Free Software Foundation, Inc.,
17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18 |
19 | The full GNU General Public License is included in this distribution in
20 | the file called "COPYING".
21 |
22 | Contact Information:
23 | e1000-devel Mailing List
24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 |
26 | *******************************************************************************/
27 |
28 | /*
29 | * net/core/ethtool.c - Ethtool ioctl handler
30 | * Copyright (c) 2003 Matthew Wilcox
31 | *
32 | * This file is where we call all the ethtool_ops commands to get
33 | * the information ethtool needs. We fall back to calling do_ioctl()
34 | * for drivers which haven't been converted to ethtool_ops yet.
35 | *
36 | * It's GPL, stupid.
37 | *
38 | * Modification by sfeldma@pobox.com to work as backward compat
39 | * solution for pre-ethtool_ops kernels.
40 | * - copied struct ethtool_ops from ethtool.h
41 | * - defined SET_ETHTOOL_OPS
42 | * - put in some #ifndef NETIF_F_xxx wrappers
43 | * - changes refs to dev->ethtool_ops to ethtool_ops
44 | * - changed dev_ethtool to ethtool_ioctl
45 | * - remove EXPORT_SYMBOL()s
46 | * - added _kc_ prefix in built-in ethtool_op_xxx ops.
47 | */
48 |
49 | #include
50 | #include
51 | #include
52 | #include
53 | #include
54 | #include
55 | #include
56 |
57 | #include "kcompat.h"
58 |
59 | #undef SUPPORTED_10000baseT_Full
60 | #define SUPPORTED_10000baseT_Full (1 << 12)
61 | #undef ADVERTISED_10000baseT_Full
62 | #define ADVERTISED_10000baseT_Full (1 << 12)
63 | #undef SPEED_10000
64 | #define SPEED_10000 10000
65 |
66 | #undef ethtool_ops
67 | #define ethtool_ops _kc_ethtool_ops
68 |
69 | struct _kc_ethtool_ops {
70 | int (*get_settings)(struct net_device *, struct ethtool_cmd *);
71 | int (*set_settings)(struct net_device *, struct ethtool_cmd *);
72 | void (*get_drvinfo)(struct net_device *, struct ethtool_drvinfo *);
73 | int (*get_regs_len)(struct net_device *);
74 | void (*get_regs)(struct net_device *, struct ethtool_regs *, void *);
75 | void (*get_wol)(struct net_device *, struct ethtool_wolinfo *);
76 | int (*set_wol)(struct net_device *, struct ethtool_wolinfo *);
77 | u32 (*get_msglevel)(struct net_device *);
78 | void (*set_msglevel)(struct net_device *, u32);
79 | int (*nway_reset)(struct net_device *);
80 | u32 (*get_link)(struct net_device *);
81 | int (*get_eeprom_len)(struct net_device *);
82 | int (*get_eeprom)(struct net_device *, struct ethtool_eeprom *, u8 *);
83 | int (*set_eeprom)(struct net_device *, struct ethtool_eeprom *, u8 *);
84 | int (*get_coalesce)(struct net_device *, struct ethtool_coalesce *);
85 | int (*set_coalesce)(struct net_device *, struct ethtool_coalesce *);
86 | void (*get_ringparam)(struct net_device *, struct ethtool_ringparam *);
87 | int (*set_ringparam)(struct net_device *, struct ethtool_ringparam *);
88 | void (*get_pauseparam)(struct net_device *,
89 | struct ethtool_pauseparam*);
90 | int (*set_pauseparam)(struct net_device *,
91 | struct ethtool_pauseparam*);
92 | u32 (*get_rx_csum)(struct net_device *);
93 | int (*set_rx_csum)(struct net_device *, u32);
94 | u32 (*get_tx_csum)(struct net_device *);
95 | int (*set_tx_csum)(struct net_device *, u32);
96 | u32 (*get_sg)(struct net_device *);
97 | int (*set_sg)(struct net_device *, u32);
98 | u32 (*get_tso)(struct net_device *);
99 | int (*set_tso)(struct net_device *, u32);
100 | int (*self_test_count)(struct net_device *);
101 | void (*self_test)(struct net_device *, struct ethtool_test *, u64 *);
102 | void (*get_strings)(struct net_device *, u32 stringset, u8 *);
103 | int (*phys_id)(struct net_device *, u32);
104 | int (*get_stats_count)(struct net_device *);
105 | void (*get_ethtool_stats)(struct net_device *, struct ethtool_stats *,
106 | u64 *);
107 | } *ethtool_ops = NULL;
108 |
109 | #undef SET_ETHTOOL_OPS
110 | #define SET_ETHTOOL_OPS(netdev, ops) (ethtool_ops = (ops))
111 |
112 | /*
113 | * Some useful ethtool_ops methods that are device independent. If we find that
114 | * all drivers want to do the same thing here, we can turn these into dev_()
115 | * function calls.
116 | */
117 |
118 | #undef ethtool_op_get_link
119 | #define ethtool_op_get_link _kc_ethtool_op_get_link
120 | u32 _kc_ethtool_op_get_link(struct net_device *dev)
121 | {
122 | return netif_carrier_ok(dev) ? 1 : 0;
123 | }
124 |
125 | #undef ethtool_op_get_tx_csum
126 | #define ethtool_op_get_tx_csum _kc_ethtool_op_get_tx_csum
127 | u32 _kc_ethtool_op_get_tx_csum(struct net_device *dev)
128 | {
129 | #ifdef NETIF_F_IP_CSUM
130 | return (dev->features & NETIF_F_IP_CSUM) != 0;
131 | #else
132 | return 0;
133 | #endif
134 | }
135 |
136 | #undef ethtool_op_set_tx_csum
137 | #define ethtool_op_set_tx_csum _kc_ethtool_op_set_tx_csum
138 | int _kc_ethtool_op_set_tx_csum(struct net_device *dev, u32 data)
139 | {
140 | #ifdef NETIF_F_IP_CSUM
141 | if (data)
142 | #ifdef NETIF_F_IPV6_CSUM
143 | dev->features |= (NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
144 | else
145 | dev->features &= ~(NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM);
146 | #else
147 | dev->features |= NETIF_F_IP_CSUM;
148 | else
149 | dev->features &= ~NETIF_F_IP_CSUM;
150 | #endif
151 | #endif
152 |
153 | return 0;
154 | }
155 |
156 | #undef ethtool_op_get_sg
157 | #define ethtool_op_get_sg _kc_ethtool_op_get_sg
158 | u32 _kc_ethtool_op_get_sg(struct net_device *dev)
159 | {
160 | #ifdef NETIF_F_SG
161 | return (dev->features & NETIF_F_SG) != 0;
162 | #else
163 | return 0;
164 | #endif
165 | }
166 |
167 | #undef ethtool_op_set_sg
168 | #define ethtool_op_set_sg _kc_ethtool_op_set_sg
169 | int _kc_ethtool_op_set_sg(struct net_device *dev, u32 data)
170 | {
171 | #ifdef NETIF_F_SG
172 | if (data)
173 | dev->features |= NETIF_F_SG;
174 | else
175 | dev->features &= ~NETIF_F_SG;
176 | #endif
177 |
178 | return 0;
179 | }
180 |
181 | #undef ethtool_op_get_tso
182 | #define ethtool_op_get_tso _kc_ethtool_op_get_tso
183 | u32 _kc_ethtool_op_get_tso(struct net_device *dev)
184 | {
185 | #ifdef NETIF_F_TSO
186 | return (dev->features & NETIF_F_TSO) != 0;
187 | #else
188 | return 0;
189 | #endif
190 | }
191 |
192 | #undef ethtool_op_set_tso
193 | #define ethtool_op_set_tso _kc_ethtool_op_set_tso
194 | int _kc_ethtool_op_set_tso(struct net_device *dev, u32 data)
195 | {
196 | #ifdef NETIF_F_TSO
197 | if (data)
198 | dev->features |= NETIF_F_TSO;
199 | else
200 | dev->features &= ~NETIF_F_TSO;
201 | #endif
202 |
203 | return 0;
204 | }
205 |
206 | /* Handlers for each ethtool command */
207 |
208 | static int ethtool_get_settings(struct net_device *dev, void *useraddr)
209 | {
210 | struct ethtool_cmd cmd = { ETHTOOL_GSET };
211 | int err;
212 |
213 | if (!ethtool_ops->get_settings)
214 | return -EOPNOTSUPP;
215 |
216 | err = ethtool_ops->get_settings(dev, &cmd);
217 | if (err < 0)
218 | return err;
219 |
220 | if (copy_to_user(useraddr, &cmd, sizeof(cmd)))
221 | return -EFAULT;
222 | return 0;
223 | }
224 |
225 | static int ethtool_set_settings(struct net_device *dev, void *useraddr)
226 | {
227 | struct ethtool_cmd cmd;
228 |
229 | if (!ethtool_ops->set_settings)
230 | return -EOPNOTSUPP;
231 |
232 | if (copy_from_user(&cmd, useraddr, sizeof(cmd)))
233 | return -EFAULT;
234 |
235 | return ethtool_ops->set_settings(dev, &cmd);
236 | }
237 |
238 | static int ethtool_get_drvinfo(struct net_device *dev, void *useraddr)
239 | {
240 | struct ethtool_drvinfo info;
241 | struct ethtool_ops *ops = ethtool_ops;
242 |
243 | if (!ops->get_drvinfo)
244 | return -EOPNOTSUPP;
245 |
246 | memset(&info, 0, sizeof(info));
247 | info.cmd = ETHTOOL_GDRVINFO;
248 | ops->get_drvinfo(dev, &info);
249 |
250 | if (ops->self_test_count)
251 | info.testinfo_len = ops->self_test_count(dev);
252 | if (ops->get_stats_count)
253 | info.n_stats = ops->get_stats_count(dev);
254 | if (ops->get_regs_len)
255 | info.regdump_len = ops->get_regs_len(dev);
256 | if (ops->get_eeprom_len)
257 | info.eedump_len = ops->get_eeprom_len(dev);
258 |
259 | if (copy_to_user(useraddr, &info, sizeof(info)))
260 | return -EFAULT;
261 | return 0;
262 | }
263 |
264 | static int ethtool_get_regs(struct net_device *dev, char *useraddr)
265 | {
266 | struct ethtool_regs regs;
267 | struct ethtool_ops *ops = ethtool_ops;
268 | void *regbuf;
269 | int reglen, ret;
270 |
271 | if (!ops->get_regs || !ops->get_regs_len)
272 | return -EOPNOTSUPP;
273 |
274 | if (copy_from_user(®s, useraddr, sizeof(regs)))
275 | return -EFAULT;
276 |
277 | reglen = ops->get_regs_len(dev);
278 | if (regs.len > reglen)
279 | regs.len = reglen;
280 |
281 | regbuf = kmalloc(reglen, GFP_USER);
282 | if (!regbuf)
283 | return -ENOMEM;
284 |
285 | ops->get_regs(dev, ®s, regbuf);
286 |
287 | ret = -EFAULT;
288 | if (copy_to_user(useraddr, ®s, sizeof(regs)))
289 | goto out;
290 | useraddr += offsetof(struct ethtool_regs, data);
291 | if (copy_to_user(useraddr, regbuf, reglen))
292 | goto out;
293 | ret = 0;
294 |
295 | out:
296 | kfree(regbuf);
297 | return ret;
298 | }
299 |
300 | static int ethtool_get_wol(struct net_device *dev, char *useraddr)
301 | {
302 | struct ethtool_wolinfo wol = { ETHTOOL_GWOL };
303 |
304 | if (!ethtool_ops->get_wol)
305 | return -EOPNOTSUPP;
306 |
307 | ethtool_ops->get_wol(dev, &wol);
308 |
309 | if (copy_to_user(useraddr, &wol, sizeof(wol)))
310 | return -EFAULT;
311 | return 0;
312 | }
313 |
314 | static int ethtool_set_wol(struct net_device *dev, char *useraddr)
315 | {
316 | struct ethtool_wolinfo wol;
317 |
318 | if (!ethtool_ops->set_wol)
319 | return -EOPNOTSUPP;
320 |
321 | if (copy_from_user(&wol, useraddr, sizeof(wol)))
322 | return -EFAULT;
323 |
324 | return ethtool_ops->set_wol(dev, &wol);
325 | }
326 |
327 | static int ethtool_get_msglevel(struct net_device *dev, char *useraddr)
328 | {
329 | struct ethtool_value edata = { ETHTOOL_GMSGLVL };
330 |
331 | if (!ethtool_ops->get_msglevel)
332 | return -EOPNOTSUPP;
333 |
334 | edata.data = ethtool_ops->get_msglevel(dev);
335 |
336 | if (copy_to_user(useraddr, &edata, sizeof(edata)))
337 | return -EFAULT;
338 | return 0;
339 | }
340 |
341 | static int ethtool_set_msglevel(struct net_device *dev, char *useraddr)
342 | {
343 | struct ethtool_value edata;
344 |
345 | if (!ethtool_ops->set_msglevel)
346 | return -EOPNOTSUPP;
347 |
348 | if (copy_from_user(&edata, useraddr, sizeof(edata)))
349 | return -EFAULT;
350 |
351 | ethtool_ops->set_msglevel(dev, edata.data);
352 | return 0;
353 | }
354 |
355 | static int ethtool_nway_reset(struct net_device *dev)
356 | {
357 | if (!ethtool_ops->nway_reset)
358 | return -EOPNOTSUPP;
359 |
360 | return ethtool_ops->nway_reset(dev);
361 | }
362 |
363 | static int ethtool_get_link(struct net_device *dev, void *useraddr)
364 | {
365 | struct ethtool_value edata = { ETHTOOL_GLINK };
366 |
367 | if (!ethtool_ops->get_link)
368 | return -EOPNOTSUPP;
369 |
370 | edata.data = ethtool_ops->get_link(dev);
371 |
372 | if (copy_to_user(useraddr, &edata, sizeof(edata)))
373 | return -EFAULT;
374 | return 0;
375 | }
376 |
377 | static int ethtool_get_eeprom(struct net_device *dev, void *useraddr)
378 | {
379 | struct ethtool_eeprom eeprom;
380 | struct ethtool_ops *ops = ethtool_ops;
381 | u8 *data;
382 | int ret;
383 |
384 | if (!ops->get_eeprom || !ops->get_eeprom_len)
385 | return -EOPNOTSUPP;
386 |
387 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
388 | return -EFAULT;
389 |
390 | /* Check for wrap and zero */
391 | if (eeprom.offset + eeprom.len <= eeprom.offset)
392 | return -EINVAL;
393 |
394 | /* Check for exceeding total eeprom len */
395 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
396 | return -EINVAL;
397 |
398 | data = kmalloc(eeprom.len, GFP_USER);
399 | if (!data)
400 | return -ENOMEM;
401 |
402 | ret = -EFAULT;
403 | if (copy_from_user(data, useraddr + sizeof(eeprom), eeprom.len))
404 | goto out;
405 |
406 | ret = ops->get_eeprom(dev, &eeprom, data);
407 | if (ret)
408 | goto out;
409 |
410 | ret = -EFAULT;
411 | if (copy_to_user(useraddr, &eeprom, sizeof(eeprom)))
412 | goto out;
413 | if (copy_to_user(useraddr + sizeof(eeprom), data, eeprom.len))
414 | goto out;
415 | ret = 0;
416 |
417 | out:
418 | kfree(data);
419 | return ret;
420 | }
421 |
422 | static int ethtool_set_eeprom(struct net_device *dev, void *useraddr)
423 | {
424 | struct ethtool_eeprom eeprom;
425 | struct ethtool_ops *ops = ethtool_ops;
426 | u8 *data;
427 | int ret;
428 |
429 | if (!ops->set_eeprom || !ops->get_eeprom_len)
430 | return -EOPNOTSUPP;
431 |
432 | if (copy_from_user(&eeprom, useraddr, sizeof(eeprom)))
433 | return -EFAULT;
434 |
435 | /* Check for wrap and zero */
436 | if (eeprom.offset + eeprom.len <= eeprom.offset)
437 | return -EINVAL;
438 |
439 | /* Check for exceeding total eeprom len */
440 | if (eeprom.offset + eeprom.len > ops->get_eeprom_len(dev))
441 | return -EINVAL;
442 |
443 | data = kmalloc(eeprom.len, GFP_USER);
444 | if (!data)
445 | return -ENOMEM;
446 |
447 | ret = -EFAULT;
448 | if (copy_from_user(data, useraddr + sizeof(eeprom), eeprom.len))
449 | goto out;
450 |
451 | ret = ops->set_eeprom(dev, &eeprom, data);
452 | if (ret)
453 | goto out;
454 |
455 | if (copy_to_user(useraddr + sizeof(eeprom), data, eeprom.len))
456 | ret = -EFAULT;
457 |
458 | out:
459 | kfree(data);
460 | return ret;
461 | }
462 |
463 | static int ethtool_get_coalesce(struct net_device *dev, void *useraddr)
464 | {
465 | struct ethtool_coalesce coalesce = { ETHTOOL_GCOALESCE };
466 |
467 | if (!ethtool_ops->get_coalesce)
468 | return -EOPNOTSUPP;
469 |
470 | ethtool_ops->get_coalesce(dev, &coalesce);
471 |
472 | if (copy_to_user(useraddr, &coalesce, sizeof(coalesce)))
473 | return -EFAULT;
474 | return 0;
475 | }
476 |
477 | static int ethtool_set_coalesce(struct net_device *dev, void *useraddr)
478 | {
479 | struct ethtool_coalesce coalesce;
480 |
481 | if (!ethtool_ops->get_coalesce)
482 | return -EOPNOTSUPP;
483 |
484 | if (copy_from_user(&coalesce, useraddr, sizeof(coalesce)))
485 | return -EFAULT;
486 |
487 | return ethtool_ops->set_coalesce(dev, &coalesce);
488 | }
489 |
490 | static int ethtool_get_ringparam(struct net_device *dev, void *useraddr)
491 | {
492 | struct ethtool_ringparam ringparam = { ETHTOOL_GRINGPARAM };
493 |
494 | if (!ethtool_ops->get_ringparam)
495 | return -EOPNOTSUPP;
496 |
497 | ethtool_ops->get_ringparam(dev, &ringparam);
498 |
499 | if (copy_to_user(useraddr, &ringparam, sizeof(ringparam)))
500 | return -EFAULT;
501 | return 0;
502 | }
503 |
504 | static int ethtool_set_ringparam(struct net_device *dev, void *useraddr)
505 | {
506 | struct ethtool_ringparam ringparam;
507 |
508 | if (!ethtool_ops->get_ringparam)
509 | return -EOPNOTSUPP;
510 |
511 | if (copy_from_user(&ringparam, useraddr, sizeof(ringparam)))
512 | return -EFAULT;
513 |
514 | return ethtool_ops->set_ringparam(dev, &ringparam);
515 | }
516 |
517 | static int ethtool_get_pauseparam(struct net_device *dev, void *useraddr)
518 | {
519 | struct ethtool_pauseparam pauseparam = { ETHTOOL_GPAUSEPARAM };
520 |
521 | if (!ethtool_ops->get_pauseparam)
522 | return -EOPNOTSUPP;
523 |
524 | ethtool_ops->get_pauseparam(dev, &pauseparam);
525 |
526 | if (copy_to_user(useraddr, &pauseparam, sizeof(pauseparam)))
527 | return -EFAULT;
528 | return 0;
529 | }
530 |
531 | static int ethtool_set_pauseparam(struct net_device *dev, void *useraddr)
532 | {
533 | struct ethtool_pauseparam pauseparam;
534 |
535 | if (!ethtool_ops->get_pauseparam)
536 | return -EOPNOTSUPP;
537 |
538 | if (copy_from_user(&pauseparam, useraddr, sizeof(pauseparam)))
539 | return -EFAULT;
540 |
541 | return ethtool_ops->set_pauseparam(dev, &pauseparam);
542 | }
543 |
544 | static int ethtool_get_rx_csum(struct net_device *dev, char *useraddr)
545 | {
546 | struct ethtool_value edata = { ETHTOOL_GRXCSUM };
547 |
548 | if (!ethtool_ops->get_rx_csum)
549 | return -EOPNOTSUPP;
550 |
551 | edata.data = ethtool_ops->get_rx_csum(dev);
552 |
553 | if (copy_to_user(useraddr, &edata, sizeof(edata)))
554 | return -EFAULT;
555 | return 0;
556 | }
557 |
558 | static int ethtool_set_rx_csum(struct net_device *dev, char *useraddr)
559 | {
560 | struct ethtool_value edata;
561 |
562 | if (!ethtool_ops->set_rx_csum)
563 | return -EOPNOTSUPP;
564 |
565 | if (copy_from_user(&edata, useraddr, sizeof(edata)))
566 | return -EFAULT;
567 |
568 | ethtool_ops->set_rx_csum(dev, edata.data);
569 | return 0;
570 | }
571 |
572 | static int ethtool_get_tx_csum(struct net_device *dev, char *useraddr)
573 | {
574 | struct ethtool_value edata = { ETHTOOL_GTXCSUM };
575 |
576 | if (!ethtool_ops->get_tx_csum)
577 | return -EOPNOTSUPP;
578 |
579 | edata.data = ethtool_ops->get_tx_csum(dev);
580 |
581 | if (copy_to_user(useraddr, &edata, sizeof(edata)))
582 | return -EFAULT;
583 | return 0;
584 | }
585 |
586 | static int ethtool_set_tx_csum(struct net_device *dev, char *useraddr)
587 | {
588 | struct ethtool_value edata;
589 |
590 | if (!ethtool_ops->set_tx_csum)
591 | return -EOPNOTSUPP;
592 |
593 | if (copy_from_user(&edata, useraddr, sizeof(edata)))
594 | return -EFAULT;
595 |
596 | return ethtool_ops->set_tx_csum(dev, edata.data);
597 | }
598 |
599 | static int ethtool_get_sg(struct net_device *dev, char *useraddr)
600 | {
601 | struct ethtool_value edata = { ETHTOOL_GSG };
602 |
603 | if (!ethtool_ops->get_sg)
604 | return -EOPNOTSUPP;
605 |
606 | edata.data = ethtool_ops->get_sg(dev);
607 |
608 | if (copy_to_user(useraddr, &edata, sizeof(edata)))
609 | return -EFAULT;
610 | return 0;
611 | }
612 |
613 | static int ethtool_set_sg(struct net_device *dev, char *useraddr)
614 | {
615 | struct ethtool_value edata;
616 |
617 | if (!ethtool_ops->set_sg)
618 | return -EOPNOTSUPP;
619 |
620 | if (copy_from_user(&edata, useraddr, sizeof(edata)))
621 | return -EFAULT;
622 |
623 | return ethtool_ops->set_sg(dev, edata.data);
624 | }
625 |
626 | static int ethtool_get_tso(struct net_device *dev, char *useraddr)
627 | {
628 | struct ethtool_value edata = { ETHTOOL_GTSO };
629 |
630 | if (!ethtool_ops->get_tso)
631 | return -EOPNOTSUPP;
632 |
633 | edata.data = ethtool_ops->get_tso(dev);
634 |
635 | if (copy_to_user(useraddr, &edata, sizeof(edata)))
636 | return -EFAULT;
637 | return 0;
638 | }
639 |
640 | static int ethtool_set_tso(struct net_device *dev, char *useraddr)
641 | {
642 | struct ethtool_value edata;
643 |
644 | if (!ethtool_ops->set_tso)
645 | return -EOPNOTSUPP;
646 |
647 | if (copy_from_user(&edata, useraddr, sizeof(edata)))
648 | return -EFAULT;
649 |
650 | return ethtool_ops->set_tso(dev, edata.data);
651 | }
652 |
653 | static int ethtool_self_test(struct net_device *dev, char *useraddr)
654 | {
655 | struct ethtool_test test;
656 | struct ethtool_ops *ops = ethtool_ops;
657 | u64 *data;
658 | int ret;
659 |
660 | if (!ops->self_test || !ops->self_test_count)
661 | return -EOPNOTSUPP;
662 |
663 | if (copy_from_user(&test, useraddr, sizeof(test)))
664 | return -EFAULT;
665 |
666 | test.len = ops->self_test_count(dev);
667 | data = kmalloc(test.len * sizeof(u64), GFP_USER);
668 | if (!data)
669 | return -ENOMEM;
670 |
671 | ops->self_test(dev, &test, data);
672 |
673 | ret = -EFAULT;
674 | if (copy_to_user(useraddr, &test, sizeof(test)))
675 | goto out;
676 | useraddr += sizeof(test);
677 | if (copy_to_user(useraddr, data, test.len * sizeof(u64)))
678 | goto out;
679 | ret = 0;
680 |
681 | out:
682 | kfree(data);
683 | return ret;
684 | }
685 |
686 | static int ethtool_get_strings(struct net_device *dev, void *useraddr)
687 | {
688 | struct ethtool_gstrings gstrings;
689 | struct ethtool_ops *ops = ethtool_ops;
690 | u8 *data;
691 | int ret;
692 |
693 | if (!ops->get_strings)
694 | return -EOPNOTSUPP;
695 |
696 | if (copy_from_user(&gstrings, useraddr, sizeof(gstrings)))
697 | return -EFAULT;
698 |
699 | switch (gstrings.string_set) {
700 | case ETH_SS_TEST:
701 | if (!ops->self_test_count)
702 | return -EOPNOTSUPP;
703 | gstrings.len = ops->self_test_count(dev);
704 | break;
705 | case ETH_SS_STATS:
706 | if (!ops->get_stats_count)
707 | return -EOPNOTSUPP;
708 | gstrings.len = ops->get_stats_count(dev);
709 | break;
710 | default:
711 | return -EINVAL;
712 | }
713 |
714 | data = kmalloc(gstrings.len * ETH_GSTRING_LEN, GFP_USER);
715 | if (!data)
716 | return -ENOMEM;
717 |
718 | ops->get_strings(dev, gstrings.string_set, data);
719 |
720 | ret = -EFAULT;
721 | if (copy_to_user(useraddr, &gstrings, sizeof(gstrings)))
722 | goto out;
723 | useraddr += sizeof(gstrings);
724 | if (copy_to_user(useraddr, data, gstrings.len * ETH_GSTRING_LEN))
725 | goto out;
726 | ret = 0;
727 |
728 | out:
729 | kfree(data);
730 | return ret;
731 | }
732 |
733 | static int ethtool_phys_id(struct net_device *dev, void *useraddr)
734 | {
735 | struct ethtool_value id;
736 |
737 | if (!ethtool_ops->phys_id)
738 | return -EOPNOTSUPP;
739 |
740 | if (copy_from_user(&id, useraddr, sizeof(id)))
741 | return -EFAULT;
742 |
743 | return ethtool_ops->phys_id(dev, id.data);
744 | }
745 |
746 | static int ethtool_get_stats(struct net_device *dev, void *useraddr)
747 | {
748 | struct ethtool_stats stats;
749 | struct ethtool_ops *ops = ethtool_ops;
750 | u64 *data;
751 | int ret;
752 |
753 | if (!ops->get_ethtool_stats || !ops->get_stats_count)
754 | return -EOPNOTSUPP;
755 |
756 | if (copy_from_user(&stats, useraddr, sizeof(stats)))
757 | return -EFAULT;
758 |
759 | stats.n_stats = ops->get_stats_count(dev);
760 | data = kmalloc(stats.n_stats * sizeof(u64), GFP_USER);
761 | if (!data)
762 | return -ENOMEM;
763 |
764 | ops->get_ethtool_stats(dev, &stats, data);
765 |
766 | ret = -EFAULT;
767 | if (copy_to_user(useraddr, &stats, sizeof(stats)))
768 | goto out;
769 | useraddr += sizeof(stats);
770 | if (copy_to_user(useraddr, data, stats.n_stats * sizeof(u64)))
771 | goto out;
772 | ret = 0;
773 |
774 | out:
775 | kfree(data);
776 | return ret;
777 | }
778 |
779 | /* The main entry point in this file. Called from net/core/dev.c */
780 |
781 | #define ETHTOOL_OPS_COMPAT
782 | int ethtool_ioctl(struct ifreq *ifr)
783 | {
784 | struct net_device *dev = __dev_get_by_name(ifr->ifr_name);
785 | void *useraddr = (void *) ifr->ifr_data;
786 | u32 ethcmd;
787 |
788 | /*
789 | * XXX: This can be pushed down into the ethtool_* handlers that
790 | * need it. Keep existing behavior for the moment.
791 | */
792 | if (!capable(CAP_NET_ADMIN))
793 | return -EPERM;
794 |
795 | if (!dev || !netif_device_present(dev))
796 | return -ENODEV;
797 |
798 | if (copy_from_user(ðcmd, useraddr, sizeof (ethcmd)))
799 | return -EFAULT;
800 |
801 | switch (ethcmd) {
802 | case ETHTOOL_GSET:
803 | return ethtool_get_settings(dev, useraddr);
804 | case ETHTOOL_SSET:
805 | return ethtool_set_settings(dev, useraddr);
806 | case ETHTOOL_GDRVINFO:
807 | return ethtool_get_drvinfo(dev, useraddr);
808 | case ETHTOOL_GREGS:
809 | return ethtool_get_regs(dev, useraddr);
810 | case ETHTOOL_GWOL:
811 | return ethtool_get_wol(dev, useraddr);
812 | case ETHTOOL_SWOL:
813 | return ethtool_set_wol(dev, useraddr);
814 | case ETHTOOL_GMSGLVL:
815 | return ethtool_get_msglevel(dev, useraddr);
816 | case ETHTOOL_SMSGLVL:
817 | return ethtool_set_msglevel(dev, useraddr);
818 | case ETHTOOL_NWAY_RST:
819 | return ethtool_nway_reset(dev);
820 | case ETHTOOL_GLINK:
821 | return ethtool_get_link(dev, useraddr);
822 | case ETHTOOL_GEEPROM:
823 | return ethtool_get_eeprom(dev, useraddr);
824 | case ETHTOOL_SEEPROM:
825 | return ethtool_set_eeprom(dev, useraddr);
826 | case ETHTOOL_GCOALESCE:
827 | return ethtool_get_coalesce(dev, useraddr);
828 | case ETHTOOL_SCOALESCE:
829 | return ethtool_set_coalesce(dev, useraddr);
830 | case ETHTOOL_GRINGPARAM:
831 | return ethtool_get_ringparam(dev, useraddr);
832 | case ETHTOOL_SRINGPARAM:
833 | return ethtool_set_ringparam(dev, useraddr);
834 | case ETHTOOL_GPAUSEPARAM:
835 | return ethtool_get_pauseparam(dev, useraddr);
836 | case ETHTOOL_SPAUSEPARAM:
837 | return ethtool_set_pauseparam(dev, useraddr);
838 | case ETHTOOL_GRXCSUM:
839 | return ethtool_get_rx_csum(dev, useraddr);
840 | case ETHTOOL_SRXCSUM:
841 | return ethtool_set_rx_csum(dev, useraddr);
842 | case ETHTOOL_GTXCSUM:
843 | return ethtool_get_tx_csum(dev, useraddr);
844 | case ETHTOOL_STXCSUM:
845 | return ethtool_set_tx_csum(dev, useraddr);
846 | case ETHTOOL_GSG:
847 | return ethtool_get_sg(dev, useraddr);
848 | case ETHTOOL_SSG:
849 | return ethtool_set_sg(dev, useraddr);
850 | case ETHTOOL_GTSO:
851 | return ethtool_get_tso(dev, useraddr);
852 | case ETHTOOL_STSO:
853 | return ethtool_set_tso(dev, useraddr);
854 | case ETHTOOL_TEST:
855 | return ethtool_self_test(dev, useraddr);
856 | case ETHTOOL_GSTRINGS:
857 | return ethtool_get_strings(dev, useraddr);
858 | case ETHTOOL_PHYS_ID:
859 | return ethtool_phys_id(dev, useraddr);
860 | case ETHTOOL_GSTATS:
861 | return ethtool_get_stats(dev, useraddr);
862 | default:
863 | return -EOPNOTSUPP;
864 | }
865 |
866 | return -EOPNOTSUPP;
867 | }
868 |
869 | #define mii_if_info _kc_mii_if_info
870 | struct _kc_mii_if_info {
871 | int phy_id;
872 | int advertising;
873 | int phy_id_mask;
874 | int reg_num_mask;
875 |
876 | unsigned int full_duplex : 1; /* is full duplex? */
877 | unsigned int force_media : 1; /* is autoneg. disabled? */
878 |
879 | struct net_device *dev;
880 | int (*mdio_read) (struct net_device *dev, int phy_id, int location);
881 | void (*mdio_write) (struct net_device *dev, int phy_id, int location, int val);
882 | };
883 |
884 | struct ethtool_cmd;
885 | struct mii_ioctl_data;
886 |
887 | #undef mii_link_ok
888 | #define mii_link_ok _kc_mii_link_ok
889 | #undef mii_nway_restart
890 | #define mii_nway_restart _kc_mii_nway_restart
891 | #undef mii_ethtool_gset
892 | #define mii_ethtool_gset _kc_mii_ethtool_gset
893 | #undef mii_ethtool_sset
894 | #define mii_ethtool_sset _kc_mii_ethtool_sset
895 | #undef mii_check_link
896 | #define mii_check_link _kc_mii_check_link
897 | extern int _kc_mii_link_ok (struct mii_if_info *mii);
898 | extern int _kc_mii_nway_restart (struct mii_if_info *mii);
899 | extern int _kc_mii_ethtool_gset(struct mii_if_info *mii,
900 | struct ethtool_cmd *ecmd);
901 | extern int _kc_mii_ethtool_sset(struct mii_if_info *mii,
902 | struct ethtool_cmd *ecmd);
903 | extern void _kc_mii_check_link (struct mii_if_info *mii);
904 | #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,4,6) )
905 | #undef generic_mii_ioctl
906 | #define generic_mii_ioctl _kc_generic_mii_ioctl
907 | extern int _kc_generic_mii_ioctl(struct mii_if_info *mii_if,
908 | struct mii_ioctl_data *mii_data, int cmd,
909 | unsigned int *duplex_changed);
910 | #endif /* > 2.4.6 */
911 |
912 |
913 | struct _kc_pci_dev_ext {
914 | struct pci_dev *dev;
915 | void *pci_drvdata;
916 | struct pci_driver *driver;
917 | };
918 |
919 | struct _kc_net_dev_ext {
920 | struct net_device *dev;
921 | unsigned int carrier;
922 | };
923 |
924 |
925 | /**************************************/
926 | /* mii support */
927 |
928 | int _kc_mii_ethtool_gset(struct mii_if_info *mii, struct ethtool_cmd *ecmd)
929 | {
930 | struct net_device *dev = mii->dev;
931 | u32 advert, bmcr, lpa, nego;
932 |
933 | ecmd->supported =
934 | (SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
935 | SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
936 | SUPPORTED_Autoneg | SUPPORTED_TP | SUPPORTED_MII);
937 |
938 | /* only supports twisted-pair */
939 | ecmd->port = PORT_MII;
940 |
941 | /* only supports internal transceiver */
942 | ecmd->transceiver = XCVR_INTERNAL;
943 |
944 | /* this isn't fully supported at higher layers */
945 | ecmd->phy_address = mii->phy_id;
946 |
947 | ecmd->advertising = ADVERTISED_TP | ADVERTISED_MII;
948 | advert = mii->mdio_read(dev, mii->phy_id, MII_ADVERTISE);
949 | if (advert & ADVERTISE_10HALF)
950 | ecmd->advertising |= ADVERTISED_10baseT_Half;
951 | if (advert & ADVERTISE_10FULL)
952 | ecmd->advertising |= ADVERTISED_10baseT_Full;
953 | if (advert & ADVERTISE_100HALF)
954 | ecmd->advertising |= ADVERTISED_100baseT_Half;
955 | if (advert & ADVERTISE_100FULL)
956 | ecmd->advertising |= ADVERTISED_100baseT_Full;
957 |
958 | bmcr = mii->mdio_read(dev, mii->phy_id, MII_BMCR);
959 | lpa = mii->mdio_read(dev, mii->phy_id, MII_LPA);
960 | if (bmcr & BMCR_ANENABLE) {
961 | ecmd->advertising |= ADVERTISED_Autoneg;
962 | ecmd->autoneg = AUTONEG_ENABLE;
963 |
964 | nego = mii_nway_result(advert & lpa);
965 | if (nego == LPA_100FULL || nego == LPA_100HALF)
966 | ecmd->speed = SPEED_100;
967 | else
968 | ecmd->speed = SPEED_10;
969 | if (nego == LPA_100FULL || nego == LPA_10FULL) {
970 | ecmd->duplex = DUPLEX_FULL;
971 | mii->full_duplex = 1;
972 | } else {
973 | ecmd->duplex = DUPLEX_HALF;
974 | mii->full_duplex = 0;
975 | }
976 | } else {
977 | ecmd->autoneg = AUTONEG_DISABLE;
978 |
979 | ecmd->speed = (bmcr & BMCR_SPEED100) ? SPEED_100 : SPEED_10;
980 | ecmd->duplex = (bmcr & BMCR_FULLDPLX) ? DUPLEX_FULL : DUPLEX_HALF;
981 | }
982 |
983 | /* ignore maxtxpkt, maxrxpkt for now */
984 |
985 | return 0;
986 | }
987 |
988 | int _kc_mii_ethtool_sset(struct mii_if_info *mii, struct ethtool_cmd *ecmd)
989 | {
990 | struct net_device *dev = mii->dev;
991 |
992 | if (ecmd->speed != SPEED_10 && ecmd->speed != SPEED_100)
993 | return -EINVAL;
994 | if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
995 | return -EINVAL;
996 | if (ecmd->port != PORT_MII)
997 | return -EINVAL;
998 | if (ecmd->transceiver != XCVR_INTERNAL)
999 | return -EINVAL;
1000 | if (ecmd->phy_address != mii->phy_id)
1001 | return -EINVAL;
1002 | if (ecmd->autoneg != AUTONEG_DISABLE && ecmd->autoneg != AUTONEG_ENABLE)
1003 | return -EINVAL;
1004 |
1005 | /* ignore supported, maxtxpkt, maxrxpkt */
1006 |
1007 | if (ecmd->autoneg == AUTONEG_ENABLE) {
1008 | u32 bmcr, advert, tmp;
1009 |
1010 | if ((ecmd->advertising & (ADVERTISED_10baseT_Half |
1011 | ADVERTISED_10baseT_Full |
1012 | ADVERTISED_100baseT_Half |
1013 | ADVERTISED_100baseT_Full)) == 0)
1014 | return -EINVAL;
1015 |
1016 | /* advertise only what has been requested */
1017 | advert = mii->mdio_read(dev, mii->phy_id, MII_ADVERTISE);
1018 | tmp = advert & ~(ADVERTISE_ALL | ADVERTISE_100BASE4);
1019 | if (ADVERTISED_10baseT_Half)
1020 | tmp |= ADVERTISE_10HALF;
1021 | if (ADVERTISED_10baseT_Full)
1022 | tmp |= ADVERTISE_10FULL;
1023 | if (ADVERTISED_100baseT_Half)
1024 | tmp |= ADVERTISE_100HALF;
1025 | if (ADVERTISED_100baseT_Full)
1026 | tmp |= ADVERTISE_100FULL;
1027 | if (advert != tmp) {
1028 | mii->mdio_write(dev, mii->phy_id, MII_ADVERTISE, tmp);
1029 | mii->advertising = tmp;
1030 | }
1031 |
1032 | /* turn on autonegotiation, and force a renegotiate */
1033 | bmcr = mii->mdio_read(dev, mii->phy_id, MII_BMCR);
1034 | bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
1035 | mii->mdio_write(dev, mii->phy_id, MII_BMCR, bmcr);
1036 |
1037 | mii->force_media = 0;
1038 | } else {
1039 | u32 bmcr, tmp;
1040 |
1041 | /* turn off auto negotiation, set speed and duplexity */
1042 | bmcr = mii->mdio_read(dev, mii->phy_id, MII_BMCR);
1043 | tmp = bmcr & ~(BMCR_ANENABLE | BMCR_SPEED100 | BMCR_FULLDPLX);
1044 | if (ecmd->speed == SPEED_100)
1045 | tmp |= BMCR_SPEED100;
1046 | if (ecmd->duplex == DUPLEX_FULL) {
1047 | tmp |= BMCR_FULLDPLX;
1048 | mii->full_duplex = 1;
1049 | } else
1050 | mii->full_duplex = 0;
1051 | if (bmcr != tmp)
1052 | mii->mdio_write(dev, mii->phy_id, MII_BMCR, tmp);
1053 |
1054 | mii->force_media = 1;
1055 | }
1056 | return 0;
1057 | }
1058 |
1059 | int _kc_mii_link_ok (struct mii_if_info *mii)
1060 | {
1061 | /* first, a dummy read, needed to latch some MII phys */
1062 | mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR);
1063 | if (mii->mdio_read(mii->dev, mii->phy_id, MII_BMSR) & BMSR_LSTATUS)
1064 | return 1;
1065 | return 0;
1066 | }
1067 |
1068 | int _kc_mii_nway_restart (struct mii_if_info *mii)
1069 | {
1070 | int bmcr;
1071 | int r = -EINVAL;
1072 |
1073 | /* if autoneg is off, it's an error */
1074 | bmcr = mii->mdio_read(mii->dev, mii->phy_id, MII_BMCR);
1075 |
1076 | if (bmcr & BMCR_ANENABLE) {
1077 | bmcr |= BMCR_ANRESTART;
1078 | mii->mdio_write(mii->dev, mii->phy_id, MII_BMCR, bmcr);
1079 | r = 0;
1080 | }
1081 |
1082 | return r;
1083 | }
1084 |
1085 | void _kc_mii_check_link (struct mii_if_info *mii)
1086 | {
1087 | int cur_link = mii_link_ok(mii);
1088 | int prev_link = netif_carrier_ok(mii->dev);
1089 |
1090 | if (cur_link && !prev_link)
1091 | netif_carrier_on(mii->dev);
1092 | else if (prev_link && !cur_link)
1093 | netif_carrier_off(mii->dev);
1094 | }
1095 |
1096 | #if ( LINUX_VERSION_CODE > KERNEL_VERSION(2,4,6) )
1097 | int _kc_generic_mii_ioctl(struct mii_if_info *mii_if,
1098 | struct mii_ioctl_data *mii_data, int cmd,
1099 | unsigned int *duplex_chg_out)
1100 | {
1101 | int rc = 0;
1102 | unsigned int duplex_changed = 0;
1103 |
1104 | if (duplex_chg_out)
1105 | *duplex_chg_out = 0;
1106 |
1107 | mii_data->phy_id &= mii_if->phy_id_mask;
1108 | mii_data->reg_num &= mii_if->reg_num_mask;
1109 |
1110 | switch(cmd) {
1111 | case SIOCDEVPRIVATE: /* binary compat, remove in 2.5 */
1112 | case SIOCGMIIPHY:
1113 | mii_data->phy_id = mii_if->phy_id;
1114 | /* fall through */
1115 |
1116 | case SIOCDEVPRIVATE + 1:/* binary compat, remove in 2.5 */
1117 | case SIOCGMIIREG:
1118 | mii_data->val_out =
1119 | mii_if->mdio_read(mii_if->dev, mii_data->phy_id,
1120 | mii_data->reg_num);
1121 | break;
1122 |
1123 | case SIOCDEVPRIVATE + 2:/* binary compat, remove in 2.5 */
1124 | case SIOCSMIIREG: {
1125 | u16 val = mii_data->val_in;
1126 |
1127 | if (!capable(CAP_NET_ADMIN))
1128 | return -EPERM;
1129 |
1130 | if (mii_data->phy_id == mii_if->phy_id) {
1131 | switch(mii_data->reg_num) {
1132 | case MII_BMCR: {
1133 | unsigned int new_duplex = 0;
1134 | if (val & (BMCR_RESET|BMCR_ANENABLE))
1135 | mii_if->force_media = 0;
1136 | else
1137 | mii_if->force_media = 1;
1138 | if (mii_if->force_media &&
1139 | (val & BMCR_FULLDPLX))
1140 | new_duplex = 1;
1141 | if (mii_if->full_duplex != new_duplex) {
1142 | duplex_changed = 1;
1143 | mii_if->full_duplex = new_duplex;
1144 | }
1145 | break;
1146 | }
1147 | case MII_ADVERTISE:
1148 | mii_if->advertising = val;
1149 | break;
1150 | default:
1151 | /* do nothing */
1152 | break;
1153 | }
1154 | }
1155 |
1156 | mii_if->mdio_write(mii_if->dev, mii_data->phy_id,
1157 | mii_data->reg_num, val);
1158 | break;
1159 | }
1160 |
1161 | default:
1162 | rc = -EOPNOTSUPP;
1163 | break;
1164 | }
1165 |
1166 | if ((rc == 0) && (duplex_chg_out) && (duplex_changed))
1167 | *duplex_chg_out = 1;
1168 |
1169 | return rc;
1170 | }
1171 | #endif /* > 2.4.6 */
1172 |
1173 |
--------------------------------------------------------------------------------
/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) 2022 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) 2022 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) 2022 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) 2022 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) 2022 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) 2022 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) 2022 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) 2022 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) 2022 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) 2022 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) 2022 Realtek Semiconductor Corp. All rights reserved.
9 | #
10 | # This program is free software; you can redistribute it and/or modify it
11 | # under the terms of the GNU General Public License as published by the Free
12 | # Software Foundation; either version 2 of the License, or (at your option)
13 | # any later version.
14 | #
15 | # This program is distributed in the hope that it will be useful, but WITHOUT
16 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 | # more details.
19 | #
20 | # You should have received a copy of the GNU General Public License along with
21 | # this program; if not, see .
22 | #
23 | # Author:
24 | # Realtek NIC software team
25 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan
26 | #
27 | ################################################################################
28 | */
29 |
30 | /************************************************************************************
31 | * This product is covered by one or more of the following patents:
32 | * US6,570,884, US6,115,776, and US6,327,625.
33 | ***********************************************************************************/
34 |
35 | #include
36 | #include
37 | #include
38 | #include
39 | #include
40 | #include
41 | #include
42 | #include
43 | #include "r8125.h"
44 | #include "rtl_eeprom.h"
45 | #include "rtltool.h"
46 |
47 | int rtl8125_tool_ioctl(struct rtl8125_private *tp, struct ifreq *ifr)
48 | {
49 | struct rtltool_cmd my_cmd;
50 | int ret;
51 |
52 | if (copy_from_user(&my_cmd, ifr->ifr_data, sizeof(my_cmd)))
53 | return -EFAULT;
54 |
55 | ret = 0;
56 | switch (my_cmd.cmd) {
57 | case RTLTOOL_READ_MAC:
58 | if (my_cmd.len==1)
59 | my_cmd.data = readb(tp->mmio_addr+my_cmd.offset);
60 | else if (my_cmd.len==2)
61 | my_cmd.data = readw(tp->mmio_addr+(my_cmd.offset&~1));
62 | else if (my_cmd.len==4)
63 | my_cmd.data = readl(tp->mmio_addr+(my_cmd.offset&~3));
64 | else {
65 | ret = -EOPNOTSUPP;
66 | break;
67 | }
68 |
69 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
70 | ret = -EFAULT;
71 | break;
72 | }
73 | break;
74 |
75 | case RTLTOOL_WRITE_MAC:
76 | if (my_cmd.len==1)
77 | writeb(my_cmd.data, tp->mmio_addr+my_cmd.offset);
78 | else if (my_cmd.len==2)
79 | writew(my_cmd.data, tp->mmio_addr+(my_cmd.offset&~1));
80 | else if (my_cmd.len==4)
81 | writel(my_cmd.data, tp->mmio_addr+(my_cmd.offset&~3));
82 | else {
83 | ret = -EOPNOTSUPP;
84 | break;
85 | }
86 |
87 | break;
88 |
89 | case RTLTOOL_READ_PHY:
90 | my_cmd.data = rtl8125_mdio_prot_read(tp, my_cmd.offset);
91 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
92 | ret = -EFAULT;
93 | break;
94 | }
95 |
96 | break;
97 |
98 | case RTLTOOL_WRITE_PHY:
99 | rtl8125_mdio_prot_write(tp, my_cmd.offset, my_cmd.data);
100 | break;
101 |
102 | case RTLTOOL_READ_EPHY:
103 | my_cmd.data = rtl8125_ephy_read(tp, my_cmd.offset);
104 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
105 | ret = -EFAULT;
106 | break;
107 | }
108 |
109 | break;
110 |
111 | case RTLTOOL_WRITE_EPHY:
112 | rtl8125_ephy_write(tp, my_cmd.offset, my_cmd.data);
113 | break;
114 |
115 | case RTLTOOL_READ_ERI:
116 | my_cmd.data = 0;
117 | if (my_cmd.len==1 || my_cmd.len==2 || my_cmd.len==4) {
118 | my_cmd.data = rtl8125_eri_read(tp, my_cmd.offset, my_cmd.len, ERIAR_ExGMAC);
119 | } else {
120 | ret = -EOPNOTSUPP;
121 | break;
122 | }
123 |
124 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
125 | ret = -EFAULT;
126 | break;
127 | }
128 |
129 | break;
130 |
131 | case RTLTOOL_WRITE_ERI:
132 | if (my_cmd.len==1 || my_cmd.len==2 || my_cmd.len==4) {
133 | rtl8125_eri_write(tp, my_cmd.offset, my_cmd.len, my_cmd.data, ERIAR_ExGMAC);
134 | } else {
135 | ret = -EOPNOTSUPP;
136 | break;
137 | }
138 | break;
139 |
140 | case RTLTOOL_READ_PCI:
141 | my_cmd.data = 0;
142 | if (my_cmd.len==1)
143 | pci_read_config_byte(tp->pci_dev, my_cmd.offset,
144 | (u8 *)&my_cmd.data);
145 | else if (my_cmd.len==2)
146 | pci_read_config_word(tp->pci_dev, my_cmd.offset,
147 | (u16 *)&my_cmd.data);
148 | else if (my_cmd.len==4)
149 | pci_read_config_dword(tp->pci_dev, my_cmd.offset,
150 | &my_cmd.data);
151 | else {
152 | ret = -EOPNOTSUPP;
153 | break;
154 | }
155 |
156 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
157 | ret = -EFAULT;
158 | break;
159 | }
160 | break;
161 |
162 | case RTLTOOL_WRITE_PCI:
163 | if (my_cmd.len==1)
164 | pci_write_config_byte(tp->pci_dev, my_cmd.offset,
165 | my_cmd.data);
166 | else if (my_cmd.len==2)
167 | pci_write_config_word(tp->pci_dev, my_cmd.offset,
168 | my_cmd.data);
169 | else if (my_cmd.len==4)
170 | pci_write_config_dword(tp->pci_dev, my_cmd.offset,
171 | my_cmd.data);
172 | else {
173 | ret = -EOPNOTSUPP;
174 | break;
175 | }
176 |
177 | break;
178 |
179 | case RTLTOOL_READ_EEPROM:
180 | my_cmd.data = rtl8125_eeprom_read_sc(tp, my_cmd.offset);
181 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
182 | ret = -EFAULT;
183 | break;
184 | }
185 |
186 | break;
187 |
188 | case RTLTOOL_WRITE_EEPROM:
189 | rtl8125_eeprom_write_sc(tp, my_cmd.offset, my_cmd.data);
190 | break;
191 |
192 | case RTL_READ_OOB_MAC:
193 | rtl8125_oob_mutex_lock(tp);
194 | my_cmd.data = rtl8125_ocp_read(tp, my_cmd.offset, 4);
195 | rtl8125_oob_mutex_unlock(tp);
196 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
197 | ret = -EFAULT;
198 | break;
199 | }
200 | break;
201 |
202 | case RTL_WRITE_OOB_MAC:
203 | if (my_cmd.len == 0 || my_cmd.len > 4)
204 | return -EOPNOTSUPP;
205 |
206 | rtl8125_oob_mutex_lock(tp);
207 | rtl8125_ocp_write(tp, my_cmd.offset, my_cmd.len, my_cmd.data);
208 | rtl8125_oob_mutex_unlock(tp);
209 | break;
210 |
211 | case RTL_ENABLE_PCI_DIAG:
212 | tp->rtk_enable_diag = 1;
213 |
214 | dprintk("enable rtk diag\n");
215 | break;
216 |
217 | case RTL_DISABLE_PCI_DIAG:
218 | tp->rtk_enable_diag = 0;
219 |
220 | dprintk("disable rtk diag\n");
221 | break;
222 |
223 | case RTL_READ_MAC_OCP:
224 | if (my_cmd.offset % 2)
225 | return -EOPNOTSUPP;
226 |
227 | my_cmd.data = rtl8125_mac_ocp_read(tp, my_cmd.offset);
228 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
229 | ret = -EFAULT;
230 | break;
231 | }
232 | break;
233 |
234 | case RTL_WRITE_MAC_OCP:
235 | if ((my_cmd.offset % 2) || (my_cmd.len != 2))
236 | return -EOPNOTSUPP;
237 |
238 | rtl8125_mac_ocp_write(tp, my_cmd.offset, (u16)my_cmd.data);
239 | break;
240 |
241 | case RTL_DIRECT_READ_PHY_OCP:
242 | my_cmd.data = rtl8125_mdio_prot_direct_read_phy_ocp(tp, my_cmd.offset);
243 | if (copy_to_user(ifr->ifr_data, &my_cmd, sizeof(my_cmd))) {
244 | ret = -EFAULT;
245 | break;
246 | }
247 |
248 | break;
249 |
250 | case RTL_DIRECT_WRITE_PHY_OCP:
251 | rtl8125_mdio_prot_direct_write_phy_ocp(tp, my_cmd.offset, my_cmd.data);
252 | break;
253 |
254 | default:
255 | ret = -EOPNOTSUPP;
256 | break;
257 | }
258 |
259 | return ret;
260 | }
261 |
--------------------------------------------------------------------------------
/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) 2022 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 |
--------------------------------------------------------------------------------