├── .DS_Store ├── RealtekRTL8111 ├── .DS_Store ├── RealtekRxPool.hpp ├── RealtekRTL8111-V2-Prefix.pch ├── Info.plist ├── if_ether.h ├── RealtekRxPool.cpp ├── r8168_dash.h ├── linux.h ├── mii.h ├── RealtekRTL8111.hpp ├── RealtekRTL8111VTD.cpp ├── gpl.txt ├── APPLE_LICENSE ├── RealtekRTL8111Setup.cpp └── ethertool.h ├── RealtekRTL8111.xcodeproj ├── xcuserdata │ └── laura.xcuserdatad │ │ ├── xcdebugger │ │ └── Breakpoints.xcbkptlist │ │ └── xcschemes │ │ ├── xcschememanagement.plist │ │ ├── RealtekRTL8111.xcscheme │ │ └── RealtekRTL8111-V2.xcscheme └── project.xcworkspace │ ├── contents.xcworkspacedata │ ├── xcuserdata │ └── laura.xcuserdatad │ │ ├── UserInterfaceState.xcuserstate │ │ └── WorkspaceSettings.xcsettings │ └── xcshareddata │ └── RealtekRTL8111.xccheckout ├── .github └── FUNDING.yml └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mieze/RTL8111_driver_for_OS_X/HEAD/.DS_Store -------------------------------------------------------------------------------- /RealtekRTL8111/.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mieze/RTL8111_driver_for_OS_X/HEAD/RealtekRTL8111/.DS_Store -------------------------------------------------------------------------------- /RealtekRTL8111.xcodeproj/xcuserdata/laura.xcuserdatad/xcdebugger/Breakpoints.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /RealtekRTL8111.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /RealtekRTL8111.xcodeproj/project.xcworkspace/xcuserdata/laura.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Mieze/RTL8111_driver_for_OS_X/HEAD/RealtekRTL8111.xcodeproj/project.xcworkspace/xcuserdata/laura.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /RealtekRTL8111.xcodeproj/project.xcworkspace/xcuserdata/laura.xcuserdatad/WorkspaceSettings.xcsettings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | BuildLocationStyle 6 | UseAppPreferences 7 | CustomBuildLocationType 8 | RelativeToDerivedData 9 | DerivedDataLocationStyle 10 | Default 11 | HasAskedToTakeAutomaticSnapshotBeforeSignificantChanges 12 | 13 | IssueFilterStyle 14 | ShowActiveSchemeOnly 15 | LiveSourceIssuesEnabled 16 | 17 | SnapshotAutomaticallyBeforeSignificantChanges 18 | 19 | SnapshotLocationStyle 20 | Default 21 | 22 | 23 | -------------------------------------------------------------------------------- /RealtekRTL8111.xcodeproj/xcuserdata/laura.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | RealtekRTL8111-V2.xcscheme 8 | 9 | orderHint 10 | 1 11 | 12 | RealtekRTL8111.xcscheme 13 | 14 | orderHint 15 | 0 16 | 17 | 18 | SuppressBuildableAutocreation 19 | 20 | D34D36B41AD2F62B00EEEC08 21 | 22 | primary 23 | 24 | 25 | D37BD67E16C605F500C255A2 26 | 27 | primary 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry 12 | polar: # Replace with a single Polar username 13 | buy_me_a_coffee: mieze 14 | thanks_dev: # Replace with a single thanks.dev username 15 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 16 | -------------------------------------------------------------------------------- /RealtekRTL8111/RealtekRxPool.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // RealtekRxPool.hpp 3 | // RealtekRTL8111 4 | // 5 | // Created by Laura Müller on 26.11.25. 6 | // Copyright © 2025 Laura Müller. All rights reserved. 7 | // 8 | 9 | #ifndef RealtekRxPool_hpp 10 | #define RealtekRxPool_hpp 11 | 12 | #define kRefillDelayTime 5000UL 13 | 14 | class RealtekRxPool : public OSObject 15 | { 16 | OSDeclareDefaultStructors(RealtekRxPool); 17 | 18 | public: 19 | virtual bool init() APPLE_KEXT_OVERRIDE; 20 | 21 | virtual void free() APPLE_KEXT_OVERRIDE; 22 | 23 | virtual bool initWithCapacity(UInt32 mbufCapacity, 24 | UInt32 clustCapacity); 25 | 26 | static RealtekRxPool * withCapacity(UInt32 mbufCapacity, 27 | UInt32 clustCapacity); 28 | 29 | virtual mbuf_t getPacket(UInt32 size, mbuf_how_t how); 30 | 31 | 32 | mbuf_t replaceOrCopyPacket(mbuf_t *mp, 33 | UInt32 len, 34 | bool * replaced); 35 | 36 | protected: 37 | void refillPool(); 38 | 39 | static void refillThread(thread_call_param_t param0); 40 | 41 | thread_call_t refillCE; 42 | UInt64 refillDelay; 43 | mbuf_t cPktHead; 44 | mbuf_t cPktTail; 45 | mbuf_t mPktHead; 46 | mbuf_t mPktTail; 47 | UInt32 cCapacity; 48 | UInt32 cRefillTresh; 49 | SInt32 cPktNum; 50 | UInt32 mCapacity; 51 | UInt32 mRefillTresh; 52 | SInt32 mPktNum; 53 | UInt32 maxCopySize; 54 | bool refillScheduled; 55 | }; 56 | 57 | #endif /* RealtekRxPool_hpp */ 58 | -------------------------------------------------------------------------------- /RealtekRTL8111.xcodeproj/project.xcworkspace/xcshareddata/RealtekRTL8111.xccheckout: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDESourceControlProjectFavoriteDictionaryKey 6 | 7 | IDESourceControlProjectIdentifier 8 | 34068AF1-2078-4FAC-BC27-415F1104EFA0 9 | IDESourceControlProjectName 10 | RealtekRTL8111 11 | IDESourceControlProjectOriginsDictionary 12 | 13 | 52FD44A8D7C2885B44C325DC0C12115B6E4CC996 14 | https://github.com/Mieze/RTL8111_driver_for_OS_X.git 15 | 16 | IDESourceControlProjectPath 17 | RealtekRTL8111.xcodeproj 18 | IDESourceControlProjectRelativeInstallPathDictionary 19 | 20 | 52FD44A8D7C2885B44C325DC0C12115B6E4CC996 21 | ../.. 22 | 23 | IDESourceControlProjectURL 24 | https://github.com/Mieze/RTL8111_driver_for_OS_X.git 25 | IDESourceControlProjectVersion 26 | 111 27 | IDESourceControlProjectWCCIdentifier 28 | 52FD44A8D7C2885B44C325DC0C12115B6E4CC996 29 | IDESourceControlProjectWCConfigurations 30 | 31 | 32 | IDESourceControlRepositoryExtensionIdentifierKey 33 | public.vcs.git 34 | IDESourceControlWCCIdentifierKey 35 | 52FD44A8D7C2885B44C325DC0C12115B6E4CC996 36 | IDESourceControlWCCName 37 | RealtekRTL8111 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /RealtekRTL8111/RealtekRTL8111-V2-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'RealtekRTL8111' target in the 'RealtekRTL8111' project 3 | // 4 | 5 | #ifndef RealtekRTL8111_Prefix_pch 6 | #define RealtekRTL8111_Prefix_pch 7 | 8 | // Include any system framework and library headers here that should be included in all compilation units. 9 | // You will also need to set the Prefix Header build setting of one or more of your targets to reference this file. 10 | 11 | #define __PRIVATE_SPI__ 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif // __cplusplus 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif // __cplusplus 39 | 40 | #ifdef __cplusplus 41 | 42 | typedef u_int32_t ifnet_ctl_cmd_t; 43 | 44 | #include 45 | #include 46 | 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | #include 53 | #include 54 | #include 55 | #include 56 | #include 57 | #include 58 | #include 59 | #include 60 | #include 61 | 62 | #endif // __cplusplus 63 | 64 | #endif /* RealtekRTL8111_Prefix_pch */ 65 | -------------------------------------------------------------------------------- /RealtekRTL8111/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | com.insanelymac.${PRODUCT_NAME:rfc1034identifier} 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | KEXT 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | $MODULE_VERSION 23 | CFBundleShortVersionString 24 | $MARKETING_VERSION 25 | IOKitPersonalities 26 | 27 | RTL8111 PCIe Adapter 28 | 29 | CFBundleIdentifier 30 | com.insanelymac.${PRODUCT_NAME:rfc1034identifier} 31 | Driver Parameters 32 | 33 | disableASPM 34 | 35 | enableCSO6 36 | 37 | enableEEE 38 | 39 | enableTSO4 40 | 41 | enableTSO6 42 | 43 | fallbackMAC 44 | 45 | 46 | DriverVersion 47 | $MODULE_VERSION 48 | IOClass 49 | RTL8111 50 | IOPCIMatch 51 | 0x816810ec 0x81681186 0x250210ec 0x260010ec 52 | IOProbeScore 53 | 1000 54 | IOProviderClass 55 | IOPCIDevice 56 | Model 57 | RTL8111 58 | Vendor 59 | Realtek 60 | 61 | 62 | NSHumanReadableCopyright 63 | Copyright © 2013-2025 Laura Müller. All rights reserved. 64 | OSBundleLibraries 65 | 66 | com.apple.iokit.IONetworkingFamily 67 | 1.5.0 68 | com.apple.iokit.IOPCIFamily 69 | 1.7 70 | com.apple.kpi.bsd 71 | 8.10.0 72 | com.apple.kpi.iokit 73 | 8.10.0 74 | com.apple.kpi.libkern 75 | 8.10.0 76 | com.apple.kpi.mach 77 | 8.10.0 78 | 79 | OSBundleRequired 80 | Network-Root 81 | 82 | 83 | -------------------------------------------------------------------------------- /RealtekRTL8111.xcodeproj/xcuserdata/laura.xcuserdatad/xcschemes/RealtekRTL8111.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 50 | 51 | 52 | 53 | 59 | 60 | 62 | 63 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /RealtekRTL8111.xcodeproj/xcuserdata/laura.xcuserdatad/xcschemes/RealtekRTL8111-V2.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 50 | 51 | 52 | 53 | 59 | 60 | 62 | 63 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /RealtekRTL8111/if_ether.h: -------------------------------------------------------------------------------- 1 | /* if_ether.h -- Definitions from the linux kernel source needed by the linux code. 2 | * 3 | * Copyright (c) 2013 Laura Müller 4 | * All rights reserved. 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation; either version 2 of the License, or (at your option) 9 | * any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | * more details. 15 | * 16 | * Driver for Realtek RTL8111x PCIe ethernet controllers. 17 | * 18 | * This driver is based on Realtek's r8168 Linux driver (8.041.0). 19 | */ 20 | 21 | #ifndef RTL8111Ethernet_if_ether_h 22 | #define RTL8111Ethernet_if_ether_h 23 | 24 | /* 25 | * INET An implementation of the TCP/IP protocol suite for the LINUX 26 | * operating system. INET is implemented using the BSD Socket 27 | * interface as the means of communication with the user level. 28 | * 29 | * Global definitions for the Ethernet IEEE 802.3 interface. 30 | * 31 | * Version: @(#)if_ether.h 1.0.1a 02/08/94 32 | * 33 | * Author: Fred N. van Kempen, 34 | * Donald Becker, 35 | * Alan Cox, 36 | * Steve Whitehouse, 37 | * 38 | * This program is free software; you can redistribute it and/or 39 | * modify it under the terms of the GNU General Public License 40 | * as published by the Free Software Foundation; either version 41 | * 2 of the License, or (at your option) any later version. 42 | */ 43 | 44 | #ifndef _LINUX_IF_ETHER_H 45 | #define _LINUX_IF_ETHER_H 46 | /* 47 | #include 48 | */ 49 | /* 50 | * IEEE 802.3 Ethernet magic constants. The frame sizes omit the preamble 51 | * and FCS/CRC (frame check sequence). 52 | */ 53 | 54 | #define ETH_ALEN 6 /* Octets in one ethernet addr */ 55 | #define ETH_HLEN 14 /* Total octets in header. */ 56 | #define ETH_ZLEN 60 /* Min. octets in frame sans FCS */ 57 | #define ETH_DATA_LEN 1500 /* Max. octets in payload */ 58 | #define ETH_FRAME_LEN 1514 /* Max. octets in frame sans FCS */ 59 | #define ETH_FCS_LEN 4 /* Octets in the FCS */ 60 | 61 | /* 62 | * These are the defined Ethernet Protocol ID's. 63 | */ 64 | 65 | #define ETH_P_LOOP 0x0060 /* Ethernet Loopback packet */ 66 | #define ETH_P_PUP 0x0200 /* Xerox PUP packet */ 67 | #define ETH_P_PUPAT 0x0201 /* Xerox PUP Addr Trans packet */ 68 | #define ETH_P_IP 0x0800 /* Internet Protocol packet */ 69 | #define ETH_P_X25 0x0805 /* CCITT X.25 */ 70 | #define ETH_P_ARP 0x0806 /* Address Resolution packet */ 71 | #define ETH_P_BPQ 0x08FF /* G8BPQ AX.25 Ethernet Packet [ NOT AN OFFICIALLY REGISTERED ID ] */ 72 | #define ETH_P_IEEEPUP 0x0a00 /* Xerox IEEE802.3 PUP packet */ 73 | #define ETH_P_IEEEPUPAT 0x0a01 /* Xerox IEEE802.3 PUP Addr Trans packet */ 74 | #define ETH_P_DEC 0x6000 /* DEC Assigned proto */ 75 | #define ETH_P_DNA_DL 0x6001 /* DEC DNA Dump/Load */ 76 | #define ETH_P_DNA_RC 0x6002 /* DEC DNA Remote Console */ 77 | #define ETH_P_DNA_RT 0x6003 /* DEC DNA Routing */ 78 | #define ETH_P_LAT 0x6004 /* DEC LAT */ 79 | #define ETH_P_DIAG 0x6005 /* DEC Diagnostics */ 80 | #define ETH_P_CUST 0x6006 /* DEC Customer use */ 81 | #define ETH_P_SCA 0x6007 /* DEC Systems Comms Arch */ 82 | #define ETH_P_TEB 0x6558 /* Trans Ether Bridging */ 83 | #define ETH_P_RARP 0x8035 /* Reverse Addr Res packet */ 84 | #define ETH_P_ATALK 0x809B /* Appletalk DDP */ 85 | #define ETH_P_AARP 0x80F3 /* Appletalk AARP */ 86 | #define ETH_P_8021Q 0x8100 /* 802.1Q VLAN Extended Header */ 87 | #define ETH_P_IPX 0x8137 /* IPX over DIX */ 88 | #define ETH_P_IPV6 0x86DD /* IPv6 over bluebook */ 89 | #define ETH_P_PAUSE 0x8808 /* IEEE Pause frames. See 802.3 31B */ 90 | #define ETH_P_SLOW 0x8809 /* Slow Protocol. See 802.3ad 43B */ 91 | #define ETH_P_WCCP 0x883E /* Web-cache coordination protocol 92 | * defined in draft-wilson-wrec-wccp-v2-00.txt */ 93 | #define ETH_P_PPP_DISC 0x8863 /* PPPoE discovery messages */ 94 | #define ETH_P_PPP_SES 0x8864 /* PPPoE session messages */ 95 | #define ETH_P_MPLS_UC 0x8847 /* MPLS Unicast traffic */ 96 | #define ETH_P_MPLS_MC 0x8848 /* MPLS Multicast traffic */ 97 | #define ETH_P_ATMMPOA 0x884c /* MultiProtocol Over ATM */ 98 | #define ETH_P_LINK_CTL 0x886c /* HPNA, wlan link local tunnel */ 99 | #define ETH_P_ATMFATE 0x8884 /* Frame-based ATM Transport 100 | * over Ethernet 101 | */ 102 | #define ETH_P_PAE 0x888E /* Port Access Entity (IEEE 802.1X) */ 103 | #define ETH_P_AOE 0x88A2 /* ATA over Ethernet */ 104 | #define ETH_P_TIPC 0x88CA /* TIPC */ 105 | #define ETH_P_1588 0x88F7 /* IEEE 1588 Timesync */ 106 | #define ETH_P_FCOE 0x8906 /* Fibre Channel over Ethernet */ 107 | #define ETH_P_FIP 0x8914 /* FCoE Initialization Protocol */ 108 | #define ETH_P_EDSA 0xDADA /* Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ 109 | 110 | /* 111 | * Non DIX types. Won't clash for 1500 types. 112 | */ 113 | 114 | #define ETH_P_802_3 0x0001 /* Dummy type for 802.3 frames */ 115 | #define ETH_P_AX25 0x0002 /* Dummy protocol id for AX.25 */ 116 | #define ETH_P_ALL 0x0003 /* Every packet (be careful!!!) */ 117 | #define ETH_P_802_2 0x0004 /* 802.2 frames */ 118 | #define ETH_P_SNAP 0x0005 /* Internal only */ 119 | #define ETH_P_DDCMP 0x0006 /* DEC DDCMP: Internal only */ 120 | #define ETH_P_WAN_PPP 0x0007 /* Dummy type for WAN PPP frames*/ 121 | #define ETH_P_PPP_MP 0x0008 /* Dummy type for PPP MP frames */ 122 | #define ETH_P_LOCALTALK 0x0009 /* Localtalk pseudo type */ 123 | #define ETH_P_CAN 0x000C /* Controller Area Network */ 124 | #define ETH_P_PPPTALK 0x0010 /* Dummy type for Atalk over PPP*/ 125 | #define ETH_P_TR_802_2 0x0011 /* 802.2 frames */ 126 | #define ETH_P_MOBITEX 0x0015 /* Mobitex (kaz@cafe.net) */ 127 | #define ETH_P_CONTROL 0x0016 /* Card specific control frames */ 128 | #define ETH_P_IRDA 0x0017 /* Linux-IrDA */ 129 | #define ETH_P_ECONET 0x0018 /* Acorn Econet */ 130 | #define ETH_P_HDLC 0x0019 /* HDLC frames */ 131 | #define ETH_P_ARCNET 0x001A /* 1A for ArcNet :-) */ 132 | #define ETH_P_DSA 0x001B /* Distributed Switch Arch. */ 133 | #define ETH_P_TRAILER 0x001C /* Trailer switch tagging */ 134 | #define ETH_P_PHONET 0x00F5 /* Nokia Phonet frames */ 135 | #define ETH_P_IEEE802154 0x00F6 /* IEEE802.15.4 frame */ 136 | #define ETH_P_CAIF 0x00F7 /* ST-Ericsson CAIF protocol */ 137 | 138 | /* 139 | * This is an Ethernet frame header. 140 | */ 141 | 142 | struct ethhdr { 143 | unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ 144 | unsigned char h_source[ETH_ALEN]; /* source ether addr */ 145 | __be16 h_proto; /* packet type ID field */ 146 | } __attribute__((packed)); 147 | 148 | #ifdef __KERNEL__ 149 | #include 150 | 151 | static inline struct ethhdr *eth_hdr(const struct sk_buff *skb) 152 | { 153 | return (struct ethhdr *)skb_mac_header(skb); 154 | } 155 | 156 | int eth_header_parse(const struct sk_buff *skb, unsigned char *haddr); 157 | 158 | int mac_pton(const char *s, u8 *mac); 159 | extern ssize_t sysfs_format_mac(char *buf, const unsigned char *addr, int len); 160 | 161 | #endif 162 | 163 | #endif /* _LINUX_IF_ETHER_H */ 164 | 165 | #endif 166 | -------------------------------------------------------------------------------- /RealtekRTL8111/RealtekRxPool.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // RealtekRxPool.cpp 3 | // RealtekRTL8111 4 | // 5 | // Created by Laura Müller on 26.11.25. 6 | // Copyright © 2025 Laura Müller. All rights reserved. 7 | // 8 | 9 | #include "RealtekRxPool.hpp" 10 | 11 | OSDefineMetaClassAndStructors(RealtekRxPool, OSObject); 12 | 13 | #define super OSObject 14 | 15 | bool RealtekRxPool::init() 16 | { 17 | return true; 18 | } 19 | 20 | void RealtekRxPool::free() 21 | { 22 | if (refillCE) { 23 | thread_call_cancel(refillCE); 24 | IOSleep(1); 25 | thread_call_free(refillCE); 26 | refillCE = NULL; 27 | } 28 | if (cPktHead) { 29 | mbuf_freem_list(cPktHead); 30 | cPktHead = cPktTail = NULL; 31 | cPktNum = 0; 32 | } 33 | if (mPktHead) { 34 | mbuf_freem_list(mPktHead); 35 | mPktHead = mPktTail = NULL; 36 | mPktNum = 0; 37 | } 38 | super::free(); 39 | } 40 | 41 | bool RealtekRxPool::initWithCapacity(UInt32 mbufCapacity, 42 | UInt32 clustCapacity) 43 | { 44 | mbuf_t m; 45 | void *data; 46 | UInt32 i; 47 | errno_t err; 48 | unsigned int chunks; 49 | bool result = false; 50 | 51 | if ((mbufCapacity > 0) && (clustCapacity > 0)) { 52 | cPktHead = cPktTail = NULL; 53 | mPktHead = mPktTail = NULL; 54 | cCapacity = clustCapacity; 55 | cRefillTresh = cCapacity - (cCapacity >> 1); 56 | mCapacity = mbufCapacity; 57 | mRefillTresh = mCapacity - (mCapacity >> 1); 58 | cPktNum = 0; 59 | mPktNum = 0; 60 | maxCopySize = mbuf_get_mhlen(); 61 | refillScheduled = false; 62 | 63 | nanoseconds_to_absolutetime(kRefillDelayTime, &refillDelay); 64 | 65 | refillCE = thread_call_allocate_with_options((thread_call_func_t) &refillThread, (void *) this, THREAD_CALL_PRIORITY_KERNEL, 0); 66 | 67 | if (!refillCE) { 68 | goto done; 69 | } 70 | for (i = 0; i < mbufCapacity; i++) { 71 | chunks = 1; 72 | err = mbuf_allocpacket(MBUF_WAITOK, maxCopySize, &chunks, &m); 73 | 74 | if (err) 75 | goto fail_mbuf; 76 | 77 | if (mPktHead) { 78 | mbuf_setnextpkt(mPktTail, m); 79 | mPktTail = m; 80 | mPktNum++; 81 | } else { 82 | mPktHead = mPktTail = m; 83 | mPktNum = 1; 84 | } 85 | data = mbuf_datastart(m); 86 | mbuf_setdata(m, data, 0); 87 | } 88 | for (i = 0; i < clustCapacity; i++) { 89 | chunks = 1; 90 | err = mbuf_allocpacket(MBUF_WAITOK, PAGE_SIZE, &chunks, &m); 91 | 92 | if (err) 93 | goto fail_cluster; 94 | 95 | if (cPktHead) { 96 | mbuf_setnextpkt(cPktTail, m); 97 | cPktTail = m; 98 | cPktNum++; 99 | } else { 100 | cPktHead = cPktTail = m; 101 | cPktNum = 1; 102 | } 103 | data = mbuf_datastart(m); 104 | mbuf_setdata(m, data, 0); 105 | } 106 | result = true; 107 | } 108 | done: 109 | return result; 110 | 111 | fail_cluster: 112 | if (cPktHead) { 113 | mbuf_freem_list(cPktHead); 114 | cPktHead = cPktTail = NULL; 115 | cPktNum = 0; 116 | } 117 | 118 | fail_mbuf: 119 | if (mPktHead) { 120 | mbuf_freem_list(mPktHead); 121 | mPktHead = mPktTail = NULL; 122 | mPktNum = 0; 123 | } 124 | goto done; 125 | } 126 | 127 | RealtekRxPool * 128 | RealtekRxPool::withCapacity(UInt32 mbufCapacity, 129 | UInt32 clustCapacity) 130 | { 131 | RealtekRxPool *pool = new RealtekRxPool; 132 | 133 | if (pool && !pool->initWithCapacity(mbufCapacity, 134 | clustCapacity)) { 135 | pool->release(); 136 | pool = NULL; 137 | } 138 | return pool; 139 | } 140 | 141 | mbuf_t RealtekRxPool::getPacket(UInt32 size, mbuf_how_t how) 142 | { 143 | mbuf_t m = NULL; 144 | void * data; 145 | errno_t err; 146 | unsigned int chunks = 1; 147 | 148 | if (size > maxCopySize) { 149 | err = mbuf_allocpacket(how, PAGE_SIZE, &chunks, &m); 150 | 151 | if (!err) { 152 | data = mbuf_datastart(m); 153 | mbuf_setdata(m, data, 0); 154 | 155 | } else if (cPktNum > 1) { 156 | OSDecrementAtomic(&cPktNum); 157 | 158 | m = cPktHead; 159 | cPktHead = mbuf_nextpkt(cPktHead); 160 | mbuf_setnextpkt(m, NULL); 161 | 162 | if ((cPktNum < cRefillTresh) && !refillScheduled) { 163 | refillScheduled = true; 164 | thread_call_enter_delayed(refillCE, refillDelay); 165 | } 166 | } 167 | } else { 168 | err = mbuf_allocpacket(how, maxCopySize, &chunks, &m); 169 | 170 | if (!err) { 171 | data = mbuf_datastart(m); 172 | mbuf_setdata(m, data, 0); 173 | 174 | } else if (mPktNum > 1) { 175 | OSDecrementAtomic(&mPktNum); 176 | 177 | m = mPktHead; 178 | mPktHead = mbuf_nextpkt(mPktHead); 179 | mbuf_setnextpkt(m, NULL); 180 | 181 | if ((mPktNum < mRefillTresh) && !refillScheduled) { 182 | refillScheduled = true; 183 | thread_call_enter_delayed(refillCE, refillDelay); 184 | } 185 | } 186 | } 187 | return m; 188 | } 189 | 190 | void RealtekRxPool::refillPool() 191 | { 192 | mbuf_t m; 193 | void * data; 194 | errno_t err; 195 | unsigned int chunks; 196 | 197 | while (mPktNum < mCapacity) { 198 | chunks = 1; 199 | err = mbuf_allocpacket(MBUF_DONTWAIT, maxCopySize, &chunks, &m); 200 | 201 | if (!err) { 202 | data = mbuf_datastart(m); 203 | mbuf_setdata(m, data, 0); 204 | 205 | mbuf_setnextpkt(mPktTail, m); 206 | mPktTail = m; 207 | OSIncrementAtomic(&mPktNum); 208 | } else { 209 | goto done; 210 | } 211 | } 212 | while (cPktNum < cCapacity) { 213 | chunks = 1; 214 | err = mbuf_allocpacket(MBUF_DONTWAIT, PAGE_SIZE, &chunks, &m); 215 | 216 | if (!err) { 217 | data = mbuf_datastart(m); 218 | mbuf_setdata(m, data, 0); 219 | 220 | mbuf_setnextpkt(cPktTail, m); 221 | cPktTail = m; 222 | OSIncrementAtomic(&cPktNum); 223 | } else { 224 | goto done; 225 | } 226 | } 227 | 228 | done: 229 | refillScheduled = false; 230 | } 231 | 232 | void RealtekRxPool::refillThread(thread_call_param_t param0) 233 | { 234 | ((RealtekRxPool *) param0)->refillPool(); 235 | } 236 | 237 | /* 238 | * This is an exact copy of IONetworkController's method 239 | * replaceOrCopyPacket(), except that it tries to get new 240 | * packets form one of our pool. 241 | */ 242 | mbuf_t RealtekRxPool::replaceOrCopyPacket(mbuf_t *mp, 243 | UInt32 len, 244 | bool * replaced) 245 | { 246 | mbuf_t m = NULL; 247 | 248 | if ((mp != NULL) && (replaced != NULL)) { 249 | /* 250 | * Packet needs to be replaced. Try to alloc one 251 | * get or get one from the cluster buffer pool. 252 | */ 253 | if (len > maxCopySize) { 254 | m = *mp; 255 | if ((*mp = getPacket(len, MBUF_DONTWAIT)) == 0) { 256 | *mp = m; 257 | m = 0; 258 | } 259 | *replaced = true; 260 | } else { 261 | /* 262 | * Packet should be copied. Try to get 263 | * one from the mbuf buffer pool. 264 | */ 265 | m = getPacket(len, MBUF_DONTWAIT); 266 | 267 | if (m) { 268 | mbuf_copy_pkthdr(m, *mp); 269 | mbuf_pkthdr_setheader(m, NULL); 270 | bcopy(mbuf_data(*mp), mbuf_data(m), len); 271 | } 272 | *replaced = false; 273 | } 274 | } 275 | return m; 276 | } 277 | -------------------------------------------------------------------------------- /RealtekRTL8111/r8168_dash.h: -------------------------------------------------------------------------------- 1 | /* 2 | ################################################################################ 3 | # 4 | # r8168 is the Linux device driver released for Realtek Gigabit Ethernet 5 | # controllers with PCI-Express interface. 6 | # 7 | # Copyright(c) 2019 Realtek Semiconductor Corp. All rights reserved. 8 | # 9 | # This program is free software; you can redistribute it and/or modify it 10 | # under the terms of the GNU General Public License as published by the Free 11 | # Software Foundation; either version 2 of the License, or (at your option) 12 | # any later version. 13 | # 14 | # This program is distributed in the hope that it will be useful, but WITHOUT 15 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 16 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 17 | # more details. 18 | # 19 | # You should have received a copy of the GNU General Public License along with 20 | # this program; if not, see . 21 | # 22 | # Author: 23 | # Realtek NIC software team 24 | # No. 2, Innovation Road II, Hsinchu Science Park, Hsinchu 300, Taiwan 25 | # 26 | ################################################################################ 27 | */ 28 | 29 | /************************************************************************************ 30 | * This product is covered by one or more of the following patents: 31 | * US6,570,884, US6,115,776, and US6,327,625. 32 | ***********************************************************************************/ 33 | 34 | #ifndef _LINUX_R8168_DASH_H 35 | #define _LINUX_R8168_DASH_H 36 | 37 | #define SIOCDEVPRIVATE_RTLDASH SIOCDEVPRIVATE+2 38 | 39 | enum rtl_dash_cmd { 40 | RTL_DASH_ARP_NS_OFFLOAD = 0, 41 | RTL_DASH_SET_OOB_IPMAC, 42 | RTL_DASH_NOTIFY_OOB, 43 | 44 | RTL_DASH_SEND_BUFFER_DATA_TO_DASH_FW, 45 | RTL_DASH_CHECK_SEND_BUFFER_TO_DASH_FW_COMPLETE, 46 | RTL_DASH_GET_RCV_FROM_FW_BUFFER_DATA, 47 | RTL_DASH_OOB_REQ, 48 | RTL_DASH_OOB_ACK, 49 | RTL_DASH_DETACH_OOB_REQ, 50 | RTL_DASH_DETACH_OOB_ACK, 51 | 52 | RTL_FW_SET_IPV4 = 0x10, 53 | RTL_FW_GET_IPV4, 54 | RTL_FW_SET_IPV6, 55 | RTL_FW_GET_IPV6, 56 | RTL_FW_SET_EXT_SNMP, 57 | RTL_FW_GET_EXT_SNMP, 58 | RTL_FW_SET_WAKEUP_PATTERN, 59 | RTL_FW_GET_WAKEUP_PATTERN, 60 | RTL_FW_DEL_WAKEUP_PATTERN, 61 | 62 | RTLT_DASH_COMMAND_INVALID, 63 | }; 64 | 65 | struct rtl_dash_ip_mac { 66 | struct sockaddr ifru_addr; 67 | struct sockaddr ifru_netmask; 68 | struct sockaddr ifru_hwaddr; 69 | }; 70 | 71 | struct rtl_dash_ioctl_struct { 72 | __u32 cmd; 73 | __u32 offset; 74 | __u32 len; 75 | union { 76 | __u32 data; 77 | void *data_buffer; 78 | }; 79 | }; 80 | 81 | struct settings_ipv4 { 82 | __u32 IPv4addr; 83 | __u32 IPv4mask; 84 | __u32 IPv4Gateway; 85 | }; 86 | 87 | struct settings_ipv6 { 88 | __u32 reserved; 89 | __u32 prefixLen; 90 | __u16 IPv6addr[8]; 91 | __u16 IPv6Gateway[8]; 92 | }; 93 | 94 | struct settings_ext_snmp { 95 | __u16 index; 96 | __u16 oid_get_len; 97 | __u8 oid_for_get[24]; 98 | __u8 reserved0[26]; 99 | __u16 value_len; 100 | __u8 value[256]; 101 | __u8 supported; 102 | __u8 reserved1[27]; 103 | }; 104 | 105 | struct wakeup_pattern { 106 | __u8 index; 107 | __u8 valid; 108 | __u8 start; 109 | __u8 length; 110 | __u8 name[36]; 111 | __u8 mask[16]; 112 | __u8 pattern[128]; 113 | __u32 reserved[2]; 114 | }; 115 | 116 | typedef struct _RX_DASH_FROM_FW_DESC { 117 | u16 length; 118 | u8 statusLowByte; 119 | u8 statusHighByte; 120 | u32 resv; 121 | u64 BufferAddress; 122 | } 123 | RX_DASH_FROM_FW_DESC, *PRX_DASH_FROM_FW_DESC; 124 | 125 | typedef struct _TX_DASH_SEND_FW_DESC { 126 | u16 length; 127 | u8 statusLowByte; 128 | u8 statusHighByte; 129 | u32 resv; 130 | u64 BufferAddress; 131 | } 132 | TX_DASH_SEND_FW_DESC, *PTX_DASH_SEND_FW_DESC; 133 | 134 | typedef struct _OSOOBHdr { 135 | u32 len; 136 | u8 type; 137 | u8 flag; 138 | u8 hostReqV; 139 | u8 res; 140 | } 141 | OSOOBHdr, *POSOOBHdr; 142 | 143 | typedef struct _RX_DASH_BUFFER_TYPE_2 { 144 | OSOOBHdr oobhdr; 145 | u8 RxDataBuffer[0]; 146 | } 147 | RX_DASH_BUFFER_TYPE_2, *PRX_DASH_BUFFER_TYPE_2; 148 | 149 | #define ALIGN_8 (0x7) 150 | #define ALIGN_16 (0xf) 151 | #define ALIGN_32 (0x1f) 152 | #define ALIGN_64 (0x3f) 153 | #define ALIGN_256 (0xff) 154 | #define ALIGN_4096 (0xfff) 155 | 156 | #define OCP_REG_CONFIG0 (0x10) 157 | #define OCP_REG_CONFIG0_REV_F (0xB8) 158 | #define OCP_REG_DASH_POLL (0x30) 159 | #define OCP_REG_HOST_REQ (0x34) 160 | #define OCP_REG_DASH_REQ (0x35) 161 | #define OCP_REG_CR (0x36) 162 | #define OCP_REG_DMEMSTA (0x38) 163 | #define OCP_REG_GPHYAR (0x60) 164 | 165 | 166 | #define OCP_REG_CONFIG0_DASHEN BIT_15 167 | #define OCP_REG_CONFIG0_OOBRESET BIT_14 168 | #define OCP_REG_CONFIG0_APRDY BIT_13 169 | #define OCP_REG_CONFIG0_FIRMWARERDY BIT_12 170 | #define OCP_REG_CONFIG0_DRIVERRDY BIT_11 171 | #define OCP_REG_CONFIG0_OOB_WDT BIT_9 172 | #define OCP_REG_CONFIG0_DRV_WAIT_OOB BIT_8 173 | #define OCP_REG_CONFIG0_TLSEN BIT_7 174 | 175 | #define HW_DASH_SUPPORT_DASH(_M) ((_M)->HwSuppDashVer > 0 ) 176 | #define HW_DASH_SUPPORT_TYPE_1(_M) ((_M)->HwSuppDashVer == 1 ) 177 | #define HW_DASH_SUPPORT_TYPE_2(_M) ((_M)->HwSuppDashVer == 2 ) 178 | #define HW_DASH_SUPPORT_TYPE_3(_M) ((_M)->HwSuppDashVer == 3 ) 179 | 180 | #define RECV_FROM_FW_BUF_SIZE (1520) 181 | #define SEND_TO_FW_BUF_SIZE (1520) 182 | 183 | #define RX_DASH_FROM_FW_OWN BIT_15 184 | #define TX_DASH_SEND_FW_OWN BIT_15 185 | #define TX_DASH_SEND_FW_OWN_HIGHBYTE BIT_7 186 | 187 | #define TXS_CC3_0 (BIT_0|BIT_1|BIT_2|BIT_3) 188 | #define TXS_EXC BIT_4 189 | #define TXS_LNKF BIT_5 190 | #define TXS_OWC BIT_6 191 | #define TXS_TES BIT_7 192 | #define TXS_UNF BIT_9 193 | #define TXS_LGSEN BIT_11 194 | #define TXS_LS BIT_12 195 | #define TXS_FS BIT_13 196 | #define TXS_EOR BIT_14 197 | #define TXS_OWN BIT_15 198 | 199 | #define TPPool_HRDY 0x20 200 | 201 | #define HostReqReg (0xC0) 202 | #define SystemMasterDescStartAddrLow (0xF0) 203 | #define SystemMasterDescStartAddrHigh (0xF4) 204 | #define SystemSlaveDescStartAddrLow (0xF8) 205 | #define SystemSlaveDescStartAddrHigh (0xFC) 206 | 207 | //DASH Request Type 208 | #define WSMANREG 0x01 209 | #define OSPUSHDATA 0x02 210 | 211 | #define RXS_OWN BIT_15 212 | #define RXS_EOR BIT_14 213 | #define RXS_FS BIT_13 214 | #define RXS_LS BIT_12 215 | 216 | #define ISRIMR_DP_DASH_OK BIT_15 217 | #define ISRIMR_DP_HOST_OK BIT_13 218 | #define ISRIMR_DP_REQSYS_OK BIT_11 219 | 220 | #define ISRIMR_DASH_INTR_EN BIT_12 221 | #define ISRIMR_DASH_INTR_CMAC_RESET BIT_15 222 | 223 | #define ISRIMR_DASH_TYPE2_ROK BIT_0 224 | #define ISRIMR_DASH_TYPE2_RDU BIT_1 225 | #define ISRIMR_DASH_TYPE2_TOK BIT_2 226 | #define ISRIMR_DASH_TYPE2_TDU BIT_3 227 | #define ISRIMR_DASH_TYPE2_TX_FIFO_FULL BIT_4 228 | #define ISRIMR_DASH_TYPE2_TX_DISABLE_IDLE BIT_5 229 | #define ISRIMR_DASH_TYPE2_RX_DISABLE_IDLE BIT_6 230 | 231 | #define CMAC_OOB_STOP 0x25 232 | #define CMAC_OOB_INIT 0x26 233 | #define CMAC_OOB_RESET 0x2a 234 | 235 | #define NO_BASE_ADDRESS 0x00000000 236 | #define RTL8168FP_OOBMAC_BASE 0xBAF70000 237 | #define RTL8168FP_CMAC_IOBASE 0xBAF20000 238 | #define RTL8168FP_KVM_BASE 0xBAF80400 239 | #define CMAC_SYNC_REG 0x20 240 | #define CMAC_RXDESC_OFFSET 0x90 //RX: 0x90 - 0x98 241 | #define CMAC_TXDESC_OFFSET 0x98 //TX: 0x98 - 0x9F 242 | 243 | #if DISABLED_CODE 244 | 245 | /* cmac write/read MMIO register */ 246 | #define RTL_CMAC_W8(reg, val8) writeb ((val8), tp->cmac_ioaddr + (reg)) 247 | #define RTL_CMAC_W16(reg, val16) writew ((val16), tp->cmac_ioaddr + (reg)) 248 | #define RTL_CMAC_W32(reg, val32) writel ((val32), tp->cmac_ioaddr + (reg)) 249 | #define RTL_CMAC_R8(reg) readb (tp->cmac_ioaddr + (reg)) 250 | #define RTL_CMAC_R16(reg) readw (tp->cmac_ioaddr + (reg)) 251 | #define RTL_CMAC_R32(reg) ((unsigned long) readl (tp->cmac_ioaddr + (reg))) 252 | 253 | #endif /* DISABLED_CODE */ 254 | 255 | int rtl8168_dash_ioctl(struct net_device *dev, struct ifreq *ifr); 256 | void HandleDashInterrupt(struct net_device *dev); 257 | int AllocateDashShareMemory(struct net_device *dev); 258 | void FreeAllocatedDashShareMemory(struct net_device *dev); 259 | void DashHwInit(struct net_device *dev); 260 | 261 | 262 | #endif /* _LINUX_R8168_DASH_H */ 263 | -------------------------------------------------------------------------------- /RealtekRTL8111/linux.h: -------------------------------------------------------------------------------- 1 | /* linux.h -- Definitions to make the linux code compile under OS X. 2 | * 3 | * Copyright (c) 2013 Laura Müller 4 | * All rights reserved. 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation; either version 2 of the License, or (at your option) 9 | * any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | * more details. 15 | * 16 | * Driver for Realtek RTL8111x PCIe ethernet controllers. 17 | * 18 | * This driver is based on Realtek's r8168 Linux driver (8.041.0). 19 | */ 20 | 21 | #ifndef RealtekRTL8111_linux_h 22 | #define RealtekRTL8111_linux_h 23 | 24 | #include 25 | 26 | /******************************************************************************/ 27 | #pragma mark - 28 | #pragma mark Debugging 29 | #pragma mark - 30 | /******************************************************************************/ 31 | 32 | #if defined(RTL8168_DEBUG) 33 | 34 | // Levels 1 to 6 are used, in order of verbosity. 35 | // 5 or above will usually produce a LOT of log output for every packet. 36 | #define dprintk(format,args...) \ 37 | do \ 38 | { \ 39 | IOLog("[RealtekRTL8111] " format, ##args); \ 40 | } while (0) 41 | 42 | #define dev_dbg(dev,format,args...) \ 43 | IOLog("[RealtekRTL8111] " format, ##args); 44 | 45 | #else // Disable debugging. 46 | 47 | #define dprintk(args...) 48 | 49 | #endif // Disable debugging. 50 | 51 | #define printk(args...) IOLog(args) 52 | /******************************************************************************/ 53 | #pragma mark - 54 | #pragma mark Bits and Bytes 55 | #pragma mark - 56 | /******************************************************************************/ 57 | 58 | #define HZ 1000 // Milliseconds. 59 | 60 | #if defined(__LITTLE_ENDIAN__) 61 | #define __LITTLE_ENDIAN 1234 62 | #define __LITTLE_ENDIAN_BITFIELD 63 | 64 | #elif defined(__BIG_ENDIAN__) 65 | #define __BIG_ENDIAN 4321 66 | #define __BIG_ENDIAN_BITFIELD 67 | 68 | #endif // ENDIAN 69 | 70 | #define u8 UInt8 71 | #define u16 UInt16 72 | #define u32 UInt32 73 | #define u64 UInt64 74 | #define s32 SInt32 75 | #define __be16 SInt16 76 | #define __be32 SInt32 77 | #define __be64 SInt64 78 | #define __le16 SInt16 79 | #define __le32 SInt32 80 | #define __le64 SInt64 81 | #define __s8 SInt8 82 | #define __s16 SInt16 83 | #define __s32 SInt32 84 | #define __s64 SInt64 85 | #define __u8 UInt8 86 | #define __u16 UInt16 87 | #define __u32 UInt32 88 | #define __u64 UInt64 89 | 90 | #define ALIGN_MASK(x, mask) (((x) + (mask)) & ~(mask)) 91 | #define ALIGN(x, a) ALIGN_MASK(x, (typeof(x))(a) - 1) 92 | 93 | #define cpu_to_le16(x) OSSwapHostToLittleInt16(x) 94 | #define cpu_to_le32(x) OSSwapHostToLittleInt32(x) 95 | #define cpu_to_le64(x) OSSwapHostToLittleInt64(x) 96 | #define le16_to_cpu(x) OSSwapLittleToHostInt16(x) 97 | #define le32_to_cpu(x) OSSwapLittleToHostInt32(x) 98 | #define le64_to_cpu(x) OSSwapLittleToHostInt64(x) 99 | 100 | #define cpu_to_be16(x) OSSwapHostToBigInt16(x) 101 | #define cpu_to_be32(x) OSSwapHostToBigInt32(x) 102 | #define cpu_to_be64(x) OSSwapHostToBigInt64(x) 103 | #define be16_to_cpu(x) OSSwapBigToHostInt16(x) 104 | #define be32_to_cpu(x) OSSwapBigToHostInt32(x) 105 | #define be64_to_cpu(x) OSSwapBigToHostInt64(x) 106 | 107 | #define le16_to_cpus(x) ((*x) = OSSwapLittleToHostInt16((*x))) 108 | #define le32_to_cpus(x) ((*x) = OSSwapLittleToHostInt32((*x))) 109 | #define le64_to_cpus(x) ((*x) = OSSwapLittleToHostInt64((*x))) 110 | 111 | #define container_of(ptr, type, member) ({ \ 112 | const typeof( ((type *)0)->member ) *__mptr = (ptr); \ 113 | (type *)( (char *)__mptr - offsetof(type,member) );}) 114 | 115 | #define BITS_PER_LONG LONG_BIT 116 | #define BIT(nr) (1UL << (nr)) 117 | #define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG)) 118 | #define BIT_WORD(nr) ((nr) / BITS_PER_LONG) 119 | #define BITS_PER_BYTE 8 120 | #define BITS_TO_LONGS(bits) (((bits)+BITS_PER_LONG-1)/BITS_PER_LONG) 121 | 122 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) 123 | 124 | #define min_t(type,x,y) \ 125 | ({ type __x = (x); type __y = (y); __x < __y ? __x: __y; }) 126 | 127 | #define max_t(type, x, y) \ 128 | ({ type __x = (x); type __y = (y); __x > __y ? __x: __y; }) 129 | 130 | #if 0 131 | enum bool_t 132 | { 133 | false = 0, 134 | true = 1 135 | }; 136 | typedef enum bool_t bool; 137 | #endif 138 | 139 | #define dma_addr_t IOPhysicalAddress64 140 | 141 | #define likely(x) __builtin_expect(!!(x), 1) 142 | #define unlikely(x) __builtin_expect(!!(x), 0) 143 | 144 | static inline int atomic_dec_and_test(volatile SInt32 * addr) 145 | { 146 | return ((OSDecrementAtomic(addr) == 1) ? 1 : 0); 147 | } 148 | 149 | static inline int atomic_inc_and_test(volatile SInt32 * addr) 150 | { 151 | return ((OSIncrementAtomic(addr) == -1) ? 1 : 0); 152 | } 153 | 154 | #define atomic_inc(v) OSIncrementAtomic(v) 155 | #define atomic_dec(v) OSDecrementAtomic(v) 156 | 157 | static inline int 158 | test_bit(int nr, const volatile unsigned long *addr) 159 | { 160 | return (OSAddAtomic(0, addr) & (1 << nr)) != 0; 161 | } 162 | 163 | static inline void 164 | set_bit(unsigned int nr, volatile unsigned long *addr) 165 | { 166 | OSTestAndSet(nr, (volatile UInt8 *)addr); 167 | } 168 | 169 | static inline void 170 | clear_bit(unsigned int nr, volatile unsigned long *addr) 171 | { 172 | OSTestAndClear(nr, (volatile UInt8 *)addr); 173 | } 174 | 175 | static inline int 176 | test_and_clear_bit(unsigned int nr, volatile unsigned long *addr) 177 | { 178 | return !OSTestAndClear(nr, (volatile UInt8 *)addr); 179 | } 180 | 181 | static inline int 182 | test_and_set_bit(unsigned int nr, volatile unsigned long *addr) 183 | { 184 | return OSTestAndSet(nr, (volatile UInt8 *)addr); 185 | } 186 | 187 | /******************************************************************************/ 188 | #pragma mark - 189 | #pragma mark Read/Write Registers 190 | #pragma mark - 191 | /******************************************************************************/ 192 | 193 | OS_INLINE 194 | void 195 | _OSWriteInt8( 196 | volatile void * base, 197 | uintptr_t byteOffset, 198 | uint16_t data 199 | ) 200 | { 201 | *(volatile uint8_t *)((uintptr_t)base + byteOffset) = data; 202 | } 203 | 204 | OS_INLINE 205 | uint8_t 206 | _OSReadInt8( 207 | const volatile void * base, 208 | uintptr_t byteOffset 209 | ) 210 | { 211 | return *(volatile uint8_t *)((uintptr_t)base + byteOffset); 212 | } 213 | 214 | #define OSWriteLittleInt8(base, byteOffset, data) \ 215 | _OSWriteInt8((base), (byteOffset), (data)) 216 | #define OSReadLittleInt8(base, byteOffset) \ 217 | _OSReadInt8((base), (byteOffset)) 218 | 219 | #define RTL_W8(reg, val8) _OSWriteInt8((ioaddr), (reg), (val8)) 220 | #define RTL_W16(reg, val16) OSWriteLittleInt16((ioaddr), (reg), (val16)) 221 | #define RTL_W32(reg, val32) OSWriteLittleInt32((ioaddr), (reg), (val32)) 222 | #define RTL_R8(reg) _OSReadInt8((ioaddr), (reg)) 223 | #define RTL_R16(reg) OSReadLittleInt16((ioaddr), (reg)) 224 | #define RTL_R32(reg) OSReadLittleInt32((ioaddr), (reg)) 225 | 226 | #define wmb() asm volatile("sfence" : : : "memory") 227 | 228 | /******************************************************************************/ 229 | #pragma mark - 230 | #pragma mark Locks 231 | #pragma mark - 232 | /******************************************************************************/ 233 | 234 | #define spinlock_t IOSimpleLock * 235 | #define atomic_t volatile SInt32 236 | 237 | 238 | #define spin_lock_init(slock) \ 239 | do \ 240 | { \ 241 | if (*slock == NULL) \ 242 | { \ 243 | *(slock) = IOSimpleLockAlloc(); \ 244 | } \ 245 | } while (0) 246 | 247 | #define spin_lock(lock) 248 | 249 | #define spin_unlock(lock) 250 | 251 | #define spin_lock_irqsave(lock,flags) 252 | 253 | #define spin_trylock_irqsave(lock,flags) 254 | 255 | #define spin_unlock_irqrestore(lock,flags) 256 | 257 | #define usec_delay(x) IODelay(x) 258 | #define msec_delay(x) IOSleep(x) 259 | #define udelay(x) IODelay(x) 260 | #define mdelay(x) IODelay(1000*(x)) 261 | #define msleep(x) IOSleep(x) 262 | 263 | enum 264 | { 265 | GFP_KERNEL, 266 | GFP_ATOMIC, 267 | }; 268 | 269 | #define __iomem volatile 270 | #define __devinit 271 | 272 | #define LINUX_VERSION_CODE 30000 273 | #define KERNEL_VERSION(x,y,z) (x*10000+100*y+z) 274 | 275 | #define irqreturn_t int 276 | 277 | #define WARN_ON_ONCE(x) 278 | 279 | #define net_device rtl8168_private 280 | #define netdev_priv(x) ((struct rtl8168_private *)x) 281 | 282 | #define DISABLED_CODE 0 283 | 284 | struct pci_dev { 285 | UInt16 vendor; 286 | UInt16 device; 287 | UInt16 subsystem_vendor; 288 | UInt16 subsystem_device; 289 | }; 290 | 291 | #define BMCR_SPEED10 0x0000 292 | 293 | /* The additional bytes required by VLAN 294 | * (in addition to the Ethernet header) 295 | */ 296 | #define VLAN_HLEN 4 297 | 298 | /** 299 | * is_zero_ether_addr - Determine if give Ethernet address is all zeros. 300 | * @addr: Pointer to a six-byte array containing the Ethernet address 301 | * 302 | * Return true if the address is all zeroes. 303 | * 304 | * Please note: addr must be aligned to u16. 305 | */ 306 | static inline bool is_zero_ether_addr(const u8 *addr) 307 | { 308 | #if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) 309 | return ((*(const u32 *)addr) | (*(const u16 *)(addr + 4))) == 0; 310 | #else 311 | return (*(const u16 *)(addr + 0) | 312 | *(const u16 *)(addr + 2) | 313 | *(const u16 *)(addr + 4)) == 0; 314 | #endif 315 | } 316 | 317 | /** 318 | * is_multicast_ether_addr - Determine if the Ethernet address is a multicast. 319 | * @addr: Pointer to a six-byte array containing the Ethernet address 320 | * 321 | * Return true if the address is a multicast address. 322 | * By definition the broadcast address is also a multicast address. 323 | */ 324 | static inline bool is_multicast_ether_addr(const u8 *addr) 325 | { 326 | return 0x01 & addr[0]; 327 | } 328 | 329 | /** 330 | * is_valid_ether_addr - Determine if the given Ethernet address is valid 331 | * @addr: Pointer to a six-byte array containing the Ethernet address 332 | * 333 | * Check that the Ethernet address (MAC) is not 00:00:00:00:00:00, is not 334 | * a multicast address, and is not FF:FF:FF:FF:FF:FF. 335 | * 336 | * Return true if the address is valid. 337 | * 338 | * Please note: addr must be aligned to u16. 339 | */ 340 | static inline bool is_valid_ether_addr(const u8 *addr) 341 | { 342 | /* FF:FF:FF:FF:FF:FF is a multicast address so we don't need to 343 | * explicitly check for it here. */ 344 | return !is_multicast_ether_addr(addr) && !is_zero_ether_addr(addr); 345 | } 346 | 347 | #endif 348 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | RTL8111 Driver for OS X 2 | ======================= 3 | 4 | OS X open source driver for the Realtek RTL8111/8168 family 5 | 6 | *** Please note that this driver isn't maintained by Realtek! *** 7 | 8 | Due to the lack of an OS X driver that makes use of the advanced features of the Realtek RTL81111/8168 series I started a new project with the aim to create a state of the art driver that gets the most out of those NICs which can be found on virtually any cheap board on the market today. Based on Realtek's Linux driver (version 8.035.0) I have written a driver that is optimized for performance while making efficient use of system resources and keeping the CPU usage down under heavy load. 9 | 10 | **Key Features of the Driver** 11 | - Supports Realtek RTL8111/8168 B/C/D/E/F/G/H found on recent boards. 12 | - Support for multisegment packets relieving the network stack of unnecessary copy operations when assembling packets for transmission. 13 | - No-copy receive and transmit. Only small packets are copied on reception because creating a copy is more efficient than allocating a new buffer. 14 | TCP, UDP and IPv4 checksum offload (receive and transmit). 15 | - TCP segmentation offload over IPv4 and IPv6. 16 | - Support for TCP/IPv6 and UDP/IPv6 checksum offload. 17 | - Fully optimized for Mountain Lion (64bit architecture) but should work with Lion too. Snow Leopard requies some changes. 18 | - Supports Wake on LAN. 19 | - Support for Energy Efficient Ethernet (EEE) which can be disabled by setting enableEEE to NO in the drivers Info.plist without rebuild. The default is YES. 20 | - The driver is published under GPLv2. 21 | 22 | **Limitations** 23 | - As checksum offload doesn't work with jumbo frames on older versions of the RTL8111, jumbo frames are only supported on chiset 16 (RTL8111E-VL) and above. 24 | - No support for 32bit kernels. 25 | 26 | **Installation** 27 | 28 | Before you install the driver you have to remove any installed driver for RTL8111/8168. 29 | 30 | - Use OpenCore or Clover to inject the driver. 31 | 32 | - Reboot 33 | 34 | - Open System Preferences again, select Network and check if the new network interface has been created automatically or create it manually now. 35 | 36 | - Configure the interface. 37 | 38 | **Current status** 39 | 40 | The driver has been successfully tested under 10.8.2 - 26.1 with serveral versions of the RTL8111 and is known to work stable on these devices but you'll have to consider that there are more than 30 different revisions of the RTL8111. The RTL8111B/8168B chips have been reported to work since version 1.0.2 too. 41 | 42 | **A word on AppleVTD** 43 | 44 | Although RealtekRTL8111 supports AppleVTD since version 2.5.0d0, there is no guarantee that your mainboard also does. In case you are unsure if you need AppleVTD, leave it disabled and you'll be on the safe side. When you enable AppleVTD and experience one of the following issues, it's most likely that your board doesn't support AppleVTD: 45 | - Kernel Panics. 46 | - The machine suddenly reboots, freezes and/or the fans speed up. 47 | - No network connection at all. 48 | - The link status keeps going up and down. 49 | - Very low connection throughput. 50 | 51 | **What can you do to resolve the issue?** 52 | - Check your board's DMAR table and see if there are any reserved memory regions in it. 53 | - If there are reserved memory regions, you might want to patch your DMAR removing these regions. If it resolves the issue, congratulations! Be careful, because the board's manufacturer did add these regions with intention. Removing them may produce unexpected results too, like the problems described above. 54 | - Otherwise you have to keep AppleVTD disabled, because it is incompatible with your board and there is no way to make it compatible. 55 | - Users with CPUs from AMD can't use AppleVTD. You should continue using version 2.4.2 as support for AppleVTD is the only difference between 2.5.0 and 2.4.2. 56 | 57 | **Support** 58 | 59 | Please refer to the driver's thread on insanelymac.com 60 | 61 | https://www.insanelymac.com/forum/topic/287161-new-driver-for-realtek-rtl8111/ 62 | 63 | in case you have further questions, need support or want to submit a problem report. 64 | 65 | **Contributions** 66 | 67 | If you find my projects useful, please consider to buy me a cup of coffee: https://buymeacoffee.com/mieze 68 | 69 | Thank you for your support! Your contribution helps me to continue development. 70 | 71 | **Changelog** 72 | 73 | - Version 2.5.0d2 (2025-02-05) 74 | - Added support for AppleVTD and restructured resource allocation. 75 | - Cleaned up source code. 76 | - Adopted MacKernelSDK. 77 | - Version 2.3.0 (2020-08-14) 78 | - Reworked medium section and EEE support to resolve problems with connection establishment and stability. 79 | - Added option to supply a fallback MAC. 80 | - Updated Linux sources to 8.047.04 and added support for new family members 81 | - Requires 10.14 or newer. 82 | - Version 2.2.2 (2018-01-21) 83 | - Force ASPM state to disabled/enabled according to the config parameter setting. 84 | - Requires 10.12 or newer. 85 | - Version 2.2.1 (2016-03-12): 86 | - Updated underlying linux sources from Realtek to 8.041.00. 87 | - Added support for RTL8111H. 88 | - Implemented Apple’s polled receive driver model (RXPOLL). 89 | - Requires 10.11 or newer. Support for older versions of OS X has been dropped. 90 | - Version 2.2.0d0 (2016-02-06): 91 | - Improved media selection and reporting (flow control and EEE). 92 | - Updated Linux sources to 8.041.000. 93 | - Version 2.0.0 (2015-07-14): 94 | - Replaced Apple headers with those from IONetworkingFamily-85.2 to fix compatibility issues with Mountain Lion. 95 | - Version 2.0.0 (2015-06-21): 96 | - Uses Apple's private driver interface introduced with 10.8. 97 | - Supports packet scheduling with QFQ. 98 | - Please note that 2.0.0 is identical to 2.0.0d2. Only the version number has changed. 99 | - Version 1.2.3 (2014-08-23): 100 | - Reworked TSO4 and added support for TSO6. 101 | - Version 1.2.2 (2014-08-14): 102 | - Added an option to disable ASPM (default disabled) as it seems to result in unstable operation of some chipsets. 103 | - Resolved a problem with Link Aggregation after reboot. 104 | - Added a workaround for the Multicast filter bug of chipset 17 (RTL8111F) which prevented Bonjour from working properly. 105 | - Version 1.0.1 (2013-03-31): 106 | - Improved behavior when rx checksum offload isn't working properly. 107 | - Adds the chipset's model name to IORegistry so that it will show up in System Profiler. 108 | - Version 1.0.2 (2013-04-22): 109 | - Added support for rx checksum offload of TCP and UDP over IPv6. 110 | - Version 1.0.3 (2013-04-25): 111 | - The issue after a reboot from Windows has been eliminated. 112 | - Version 1.0.4 (2013-05-04) 113 | - Moved setLinkStatus(kIONetworkLinkValid) from start() to enable(). Cleaned up getDescCommand(). 114 | - Version 1.1.0 (2013-06-08): 115 | - Support for TCP/IPv6 and UDP/IPv6 checksum offload added (can be disabled in Info.plist). 116 | - Maximum size of the scatter-gather-list has been increased from 24 to 40 segments to resolve performance issues with TSO4 when offloading large packets which are highly fragmented. 117 | - TSO4 can be disabled in Info.plist without rebuild. 118 | - Statistics gathering has been improved to deliver more detailed information (resource shortages, transmitter resets, transmitter interrupt count). 119 | - The interrupt mitigate settings has been changed to improve performance with SMB and to reduce CPU load. 120 | - Configuration option added to allow for user defined interrupt mitigate settings without rebuild (see above). 121 | - Version 1.1.1 (2013-06-29): 122 | - Remove ethernet CRC from received packets to fix rx checksum offload. 123 | - Version 1.1.2 (2013-08-03): 124 | - Improved SMB performance in certain configurations. 125 | - Faster browsing of large shares. 126 | - Version 1.1.3 (2013-11-29): 127 | - Improved transmit queue handling made it possible to reduce CPU load during packet transmission. 128 | - Improved deadlock detection logic in order to avoid false positives due to lost interrupts. 129 | - Version 1.2.0 (2014-04-23): 130 | - Updated underlying linux sources from Realtek to 8.037.00. Improved interrupt mitigate to use a less aggressive value for 10/100 MBit connections. 131 | 132 | **Troubleshooting** 133 | - Make sure you have followed the installation instructions especially when you have issues with certain domains while the others are working fine. 134 | - Use the debug version to collect log data when trying to track down problems. The kernel log messages can be found in /var/log/system.log. For Sierra and above use "log show --predicate "processID == 0" --debug" in order to retrieve kernel logs. Include the log data when asking for support or giving feedback. I'm an engineer, not a clairvoyant. 135 | - Check your BIOS settings. You might want to disable Network Boot and the UEFI Network Stack as these can interfere with the driver. 136 | - Double check that you have removed any other Realtek kext from your system because they could prevent the driver from working properly. 137 | - Verify your bootloader configuration, in particular the kernel flags. Avoid using npci=0x2000 or npci=0x3000. 138 | - In Terminal run netstat -s in order to display network statistics. Carefully examine the data for any unusual activity like a high number of packets with bad IP header checksums, etc. 139 | - In case auto-configuration of the link layer connection doesn't work it might be necessary to select the medium manually in System Preferences under Network for the interface. 140 | - Use Wireshark to create a packet dump in order to collect diagnostic information. 141 | - Keep in mind that there are many manufacturers of network equipment. Although Ethernet is an IEEE standard different implementations may show different behavior causing incompatibilities. In case you are having trouble try a different switch or a different cable. 142 | 143 | **Help - I'm getting kernel panics!** 144 | 145 | Well, before you start complaining about bugs after you upgraded macOS and ask me to publish a driver update, you should first try to resolve the issue on your own by cleaning the system caches. 146 | As the driver uses macOS's private network driver interface, which is supposed to be used by Apple provided drivers only, you might run into problems after an OS update because the linker may fail to recognize that IONetworking.kext has been updated and that the driver needs to be linked against the new version (Apple provided drivers avoid this problem because they are always updated together with IONetworking.kext). As a result, the linking process produces garbage and the driver may call arbitrary code when trying to call functions from IONetworking.kext. This usually results in unpredicted behavior or a kernel panic. In order to recover from such a situation, you should clean the System Caches forcing the linker to recreate it's caches: 147 | 1. Delete all the files in /System/Library/Caches and it's subdirectories but leave the directories and the symbolic links intact. This is very important! 148 | 2. Reboot. 149 | 3. Recreate the kernel cache. 150 | 4. Reboot again. 151 | 152 | **FAQ** 153 | - How can I retrieve the kernel logs? 154 | - In Terminal type "grep kernel /var/log/system.log". 155 | - I want to disable Energy Efficient Ethernet (EEE) but I don't know how? 156 | - Take a look at the driver's Info.plist file. There you will find an option named enableEEE. Change its value from to . Don't forget to recreate the kernel cache after changing the value. 157 | - WoL from S5 doesn't work with this driver but under Windows it's working. Is this a driver bug? 158 | - No it isn't, the driver is working as it should because OS X doesn't support WoL from S5. 159 | 160 | **Known Issues** 161 | - There are still performance problems with regard to SMB in certain configurations. My tests indicate that Apple's Broadcom driver shows the same behavior with those configurations. Obviously it's a more general problem that is not limited to my driver. 162 | - WoL refuses to work on some machines. 163 | - Old systems with 3 and 4 series chipsets exhibit performance issues in recent versions of macOS because there is no optimized power management for these systems in macOS anymore as Apple dropped support for the underlying hardware a long time ago. In case you are affected, please upgrade your hardware or find an alternative solution because I have no plans for a workaround. Sorry, but I don't think that it's worth the effort. 164 | 165 | **Building from Source** 166 | 167 | I'm always using the latest version of XCode for development. You can get a free copy of XCode after becoming a member of the Apple developer program. The free membership is sufficient in order to get access to development tools and documentation. 168 | 169 | -------------------------------------------------------------------------------- /RealtekRTL8111/mii.h: -------------------------------------------------------------------------------- 1 | /* mii.h -- Definitions from the linux kernel source needed by the linux code. 2 | * 3 | * Copyright (c) 2013 Laura Müller 4 | * All rights reserved. 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation; either version 2 of the License, or (at your option) 9 | * any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | * more details. 15 | * 16 | * Driver for Realtek RTL8111x PCIe ethernet controllers. 17 | * 18 | * This driver is based on Realtek's r8168 Linux driver (8.041.0). 19 | */ 20 | 21 | #ifndef RTL8111Ethernet_mii_h 22 | #define RTL8111Ethernet_mii_h 23 | 24 | /* 25 | * linux/mii.h: definitions for MII-compatible transceivers 26 | * Originally drivers/net/sunhme.h. 27 | * 28 | * Copyright (C) 1996, 1999, 2001 David S. Miller (davem@redhat.com) 29 | */ 30 | 31 | #ifndef __LINUX_MII_H__ 32 | #define __LINUX_MII_H__ 33 | /* 34 | #include 35 | */ 36 | /* Generic MII registers. */ 37 | 38 | #define MII_BMCR 0x00 /* Basic mode control register */ 39 | #define MII_BMSR 0x01 /* Basic mode status register */ 40 | #define MII_PHYSID1 0x02 /* PHYS ID 1 */ 41 | #define MII_PHYSID2 0x03 /* PHYS ID 2 */ 42 | #define MII_ADVERTISE 0x04 /* Advertisement control reg */ 43 | #define MII_LPA 0x05 /* Link partner ability reg */ 44 | #define MII_EXPANSION 0x06 /* Expansion register */ 45 | #define MII_CTRL1000 0x09 /* 1000BASE-T control */ 46 | #define MII_STAT1000 0x0a /* 1000BASE-T status */ 47 | #define MII_ESTATUS 0x0f /* Extended Status */ 48 | #define MII_DCOUNTER 0x12 /* Disconnect counter */ 49 | #define MII_FCSCOUNTER 0x13 /* False carrier counter */ 50 | #define MII_NWAYTEST 0x14 /* N-way auto-neg test reg */ 51 | #define MII_RERRCOUNTER 0x15 /* Receive error counter */ 52 | #define MII_SREVISION 0x16 /* Silicon revision */ 53 | #define MII_RESV1 0x17 /* Reserved... */ 54 | #define MII_LBRERROR 0x18 /* Lpback, rx, bypass error */ 55 | #define MII_PHYADDR 0x19 /* PHY address */ 56 | #define MII_RESV2 0x1a /* Reserved... */ 57 | #define MII_TPISTATUS 0x1b /* TPI status for 10mbps */ 58 | #define MII_NCONFIG 0x1c /* Network interface config */ 59 | 60 | /* Basic mode control register. */ 61 | #define BMCR_RESV 0x003f /* Unused... */ 62 | #define BMCR_SPEED1000 0x0040 /* MSB of Speed (1000) */ 63 | #define BMCR_CTST 0x0080 /* Collision test */ 64 | #define BMCR_FULLDPLX 0x0100 /* Full duplex */ 65 | #define BMCR_ANRESTART 0x0200 /* Auto negotiation restart */ 66 | #define BMCR_ISOLATE 0x0400 /* Disconnect DP83840 from MII */ 67 | #define BMCR_PDOWN 0x0800 /* Powerdown the DP83840 */ 68 | #define BMCR_ANENABLE 0x1000 /* Enable auto negotiation */ 69 | #define BMCR_SPEED100 0x2000 /* Select 100Mbps */ 70 | #define BMCR_LOOPBACK 0x4000 /* TXD loopback bits */ 71 | #define BMCR_RESET 0x8000 /* Reset the DP83840 */ 72 | 73 | /* Basic mode status register. */ 74 | #define BMSR_ERCAP 0x0001 /* Ext-reg capability */ 75 | #define BMSR_JCD 0x0002 /* Jabber detected */ 76 | #define BMSR_LSTATUS 0x0004 /* Link status */ 77 | #define BMSR_ANEGCAPABLE 0x0008 /* Able to do auto-negotiation */ 78 | #define BMSR_RFAULT 0x0010 /* Remote fault detected */ 79 | #define BMSR_ANEGCOMPLETE 0x0020 /* Auto-negotiation complete */ 80 | #define BMSR_RESV 0x00c0 /* Unused... */ 81 | #define BMSR_ESTATEN 0x0100 /* Extended Status in R15 */ 82 | #define BMSR_100HALF2 0x0200 /* Can do 100BASE-T2 HDX */ 83 | #define BMSR_100FULL2 0x0400 /* Can do 100BASE-T2 FDX */ 84 | #define BMSR_10HALF 0x0800 /* Can do 10mbps, half-duplex */ 85 | #define BMSR_10FULL 0x1000 /* Can do 10mbps, full-duplex */ 86 | #define BMSR_100HALF 0x2000 /* Can do 100mbps, half-duplex */ 87 | #define BMSR_100FULL 0x4000 /* Can do 100mbps, full-duplex */ 88 | #define BMSR_100BASE4 0x8000 /* Can do 100mbps, 4k packets */ 89 | 90 | /* Advertisement control register. */ 91 | #define ADVERTISE_SLCT 0x001f /* Selector bits */ 92 | #define ADVERTISE_CSMA 0x0001 /* Only selector supported */ 93 | #define ADVERTISE_10HALF 0x0020 /* Try for 10mbps half-duplex */ 94 | #define ADVERTISE_1000XFULL 0x0020 /* Try for 1000BASE-X full-duplex */ 95 | #define ADVERTISE_10FULL 0x0040 /* Try for 10mbps full-duplex */ 96 | #define ADVERTISE_1000XHALF 0x0040 /* Try for 1000BASE-X half-duplex */ 97 | #define ADVERTISE_100HALF 0x0080 /* Try for 100mbps half-duplex */ 98 | #define ADVERTISE_1000XPAUSE 0x0080 /* Try for 1000BASE-X pause */ 99 | #define ADVERTISE_100FULL 0x0100 /* Try for 100mbps full-duplex */ 100 | #define ADVERTISE_1000XPSE_ASYM 0x0100 /* Try for 1000BASE-X asym pause */ 101 | #define ADVERTISE_100BASE4 0x0200 /* Try for 100mbps 4k packets */ 102 | #define ADVERTISE_PAUSE_CAP 0x0400 /* Try for pause */ 103 | #define ADVERTISE_PAUSE_ASYM 0x0800 /* Try for asymetric pause */ 104 | #define ADVERTISE_RESV 0x1000 /* Unused... */ 105 | #define ADVERTISE_RFAULT 0x2000 /* Say we can detect faults */ 106 | #define ADVERTISE_LPACK 0x4000 /* Ack link partners response */ 107 | #define ADVERTISE_NPAGE 0x8000 /* Next page bit */ 108 | 109 | #define ADVERTISE_FULL (ADVERTISE_100FULL | ADVERTISE_10FULL | \ 110 | ADVERTISE_CSMA) 111 | #define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \ 112 | ADVERTISE_100HALF | ADVERTISE_100FULL) 113 | 114 | /* Link partner ability register. */ 115 | #define LPA_SLCT 0x001f /* Same as advertise selector */ 116 | #define LPA_10HALF 0x0020 /* Can do 10mbps half-duplex */ 117 | #define LPA_1000XFULL 0x0020 /* Can do 1000BASE-X full-duplex */ 118 | #define LPA_10FULL 0x0040 /* Can do 10mbps full-duplex */ 119 | #define LPA_1000XHALF 0x0040 /* Can do 1000BASE-X half-duplex */ 120 | #define LPA_100HALF 0x0080 /* Can do 100mbps half-duplex */ 121 | #define LPA_1000XPAUSE 0x0080 /* Can do 1000BASE-X pause */ 122 | #define LPA_100FULL 0x0100 /* Can do 100mbps full-duplex */ 123 | #define LPA_1000XPAUSE_ASYM 0x0100 /* Can do 1000BASE-X pause asym*/ 124 | #define LPA_100BASE4 0x0200 /* Can do 100mbps 4k packets */ 125 | #define LPA_PAUSE_CAP 0x0400 /* Can pause */ 126 | #define LPA_PAUSE_ASYM 0x0800 /* Can pause asymetrically */ 127 | #define LPA_RESV 0x1000 /* Unused... */ 128 | #define LPA_RFAULT 0x2000 /* Link partner faulted */ 129 | #define LPA_LPACK 0x4000 /* Link partner acked us */ 130 | #define LPA_NPAGE 0x8000 /* Next page bit */ 131 | 132 | #define LPA_DUPLEX (LPA_10FULL | LPA_100FULL) 133 | #define LPA_100 (LPA_100FULL | LPA_100HALF | LPA_100BASE4) 134 | 135 | /* Expansion register for auto-negotiation. */ 136 | #define EXPANSION_NWAY 0x0001 /* Can do N-way auto-nego */ 137 | #define EXPANSION_LCWP 0x0002 /* Got new RX page code word */ 138 | #define EXPANSION_ENABLENPAGE 0x0004 /* This enables npage words */ 139 | #define EXPANSION_NPCAPABLE 0x0008 /* Link partner supports npage */ 140 | #define EXPANSION_MFAULTS 0x0010 /* Multiple faults detected */ 141 | #define EXPANSION_RESV 0xffe0 /* Unused... */ 142 | 143 | #define ESTATUS_1000_TFULL 0x2000 /* Can do 1000BT Full */ 144 | #define ESTATUS_1000_THALF 0x1000 /* Can do 1000BT Half */ 145 | 146 | /* N-way test register. */ 147 | #define NWAYTEST_RESV1 0x00ff /* Unused... */ 148 | #define NWAYTEST_LOOPBACK 0x0100 /* Enable loopback for N-way */ 149 | #define NWAYTEST_RESV2 0xfe00 /* Unused... */ 150 | 151 | /* 1000BASE-T Control register */ 152 | #define ADVERTISE_1000FULL 0x0200 /* Advertise 1000BASE-T full duplex */ 153 | #define ADVERTISE_1000HALF 0x0100 /* Advertise 1000BASE-T half duplex */ 154 | 155 | /* 1000BASE-T Status register */ 156 | #define LPA_1000LOCALRXOK 0x2000 /* Link partner local receiver status */ 157 | #define LPA_1000REMRXOK 0x1000 /* Link partner remote receiver status */ 158 | #define LPA_1000FULL 0x0800 /* Link partner 1000BASE-T full duplex */ 159 | #define LPA_1000HALF 0x0400 /* Link partner 1000BASE-T half duplex */ 160 | 161 | /* Flow control flags */ 162 | #define FLOW_CTRL_TX 0x01 163 | #define FLOW_CTRL_RX 0x02 164 | 165 | /* This structure is used in all SIOCxMIIxxx ioctl calls */ 166 | struct mii_ioctl_data { 167 | __u16 phy_id; 168 | __u16 reg_num; 169 | __u16 val_in; 170 | __u16 val_out; 171 | }; 172 | 173 | #ifdef __KERNEL__ 174 | 175 | #include 176 | 177 | struct ethtool_cmd; 178 | 179 | struct mii_if_info { 180 | int phy_id; 181 | int advertising; 182 | int phy_id_mask; 183 | int reg_num_mask; 184 | 185 | unsigned int full_duplex : 1; /* is full duplex? */ 186 | unsigned int force_media : 1; /* is autoneg. disabled? */ 187 | unsigned int supports_gmii : 1; /* are GMII registers supported? */ 188 | 189 | struct net_device *dev; 190 | int (*mdio_read) (struct net_device *dev, int phy_id, int location); 191 | void (*mdio_write) (struct net_device *dev, int phy_id, int location, int val); 192 | }; 193 | 194 | extern int mii_link_ok (struct mii_if_info *mii); 195 | extern int mii_nway_restart (struct mii_if_info *mii); 196 | extern int mii_ethtool_gset(struct mii_if_info *mii, struct ethtool_cmd *ecmd); 197 | extern int mii_ethtool_sset(struct mii_if_info *mii, struct ethtool_cmd *ecmd); 198 | extern int mii_check_gmii_support(struct mii_if_info *mii); 199 | extern void mii_check_link (struct mii_if_info *mii); 200 | extern unsigned int mii_check_media (struct mii_if_info *mii, 201 | unsigned int ok_to_print, 202 | unsigned int init_media); 203 | extern int generic_mii_ioctl(struct mii_if_info *mii_if, 204 | struct mii_ioctl_data *mii_data, int cmd, 205 | unsigned int *duplex_changed); 206 | 207 | 208 | static inline struct mii_ioctl_data *if_mii(struct ifreq *rq) 209 | { 210 | return (struct mii_ioctl_data *) &rq->ifr_ifru; 211 | } 212 | 213 | 214 | /** 215 | * mii_nway_result 216 | * @negotiated: value of MII ANAR and'd with ANLPAR 217 | * 218 | * Given a set of MII abilities, check each bit and returns the 219 | * currently supported media, in the priority order defined by 220 | * IEEE 802.3u. We use LPA_xxx constants but note this is not the 221 | * value of LPA solely, as described above. 222 | * 223 | * The one exception to IEEE 802.3u is that 100baseT4 is placed 224 | * between 100T-full and 100T-half. If your phy does not support 225 | * 100T4 this is fine. If your phy places 100T4 elsewhere in the 226 | * priority order, you will need to roll your own function. 227 | */ 228 | static inline unsigned int mii_nway_result (unsigned int negotiated) 229 | { 230 | unsigned int ret; 231 | 232 | if (negotiated & LPA_100FULL) 233 | ret = LPA_100FULL; 234 | else if (negotiated & LPA_100BASE4) 235 | ret = LPA_100BASE4; 236 | else if (negotiated & LPA_100HALF) 237 | ret = LPA_100HALF; 238 | else if (negotiated & LPA_10FULL) 239 | ret = LPA_10FULL; 240 | else 241 | ret = LPA_10HALF; 242 | 243 | return ret; 244 | } 245 | 246 | /** 247 | * mii_duplex 248 | * @duplex_lock: Non-zero if duplex is locked at full 249 | * @negotiated: value of MII ANAR and'd with ANLPAR 250 | * 251 | * A small helper function for a common case. Returns one 252 | * if the media is operating or locked at full duplex, and 253 | * returns zero otherwise. 254 | */ 255 | static inline unsigned int mii_duplex (unsigned int duplex_lock, 256 | unsigned int negotiated) 257 | { 258 | if (duplex_lock) 259 | return 1; 260 | if (mii_nway_result(negotiated) & LPA_DUPLEX) 261 | return 1; 262 | return 0; 263 | } 264 | 265 | /** 266 | * mii_advertise_flowctrl - get flow control advertisement flags 267 | * @cap: Flow control capabilities (FLOW_CTRL_RX, FLOW_CTRL_TX or both) 268 | */ 269 | static inline u16 mii_advertise_flowctrl(int cap) 270 | { 271 | u16 adv = 0; 272 | 273 | if (cap & FLOW_CTRL_RX) 274 | adv = ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; 275 | if (cap & FLOW_CTRL_TX) 276 | adv ^= ADVERTISE_PAUSE_ASYM; 277 | 278 | return adv; 279 | } 280 | 281 | /** 282 | * mii_resolve_flowctrl_fdx 283 | * @lcladv: value of MII ADVERTISE register 284 | * @rmtadv: value of MII LPA register 285 | * 286 | * Resolve full duplex flow control as per IEEE 802.3-2005 table 28B-3 287 | */ 288 | static inline u8 mii_resolve_flowctrl_fdx(u16 lcladv, u16 rmtadv) 289 | { 290 | u8 cap = 0; 291 | 292 | if (lcladv & rmtadv & ADVERTISE_PAUSE_CAP) { 293 | cap = FLOW_CTRL_TX | FLOW_CTRL_RX; 294 | } else if (lcladv & rmtadv & ADVERTISE_PAUSE_ASYM) { 295 | if (lcladv & ADVERTISE_PAUSE_CAP) 296 | cap = FLOW_CTRL_RX; 297 | else if (rmtadv & ADVERTISE_PAUSE_CAP) 298 | cap = FLOW_CTRL_TX; 299 | } 300 | 301 | return cap; 302 | } 303 | 304 | #endif /* __KERNEL__ */ 305 | #endif /* __LINUX_MII_H__ */ 306 | 307 | #endif 308 | -------------------------------------------------------------------------------- /RealtekRTL8111/RealtekRTL8111.hpp: -------------------------------------------------------------------------------- 1 | /* RealtekRTL8111.hpp -- RTL8111 driver class definition. 2 | * 3 | * Copyright (c) 2013-2025 Laura Müller 4 | * All rights reserved. 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation; either version 2 of the License, or (at your option) 9 | * any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | * more details. 15 | * 16 | * Driver for Realtek RTL8111x PCIe ethernet controllers. 17 | * 18 | * This driver is based on Realtek's r8168 Linux driver (8.041.0). 19 | */ 20 | 21 | #include "RealtekRTL8111Linux-804704.hpp" 22 | #include "RealtekRxPool.hpp" 23 | 24 | #ifdef DEBUG 25 | #define DebugLog(args...) IOLog(args) 26 | #else 27 | #define DebugLog(args...) 28 | #endif 29 | 30 | #define RELEASE(x) if(x){(x)->release();(x)=NULL;} 31 | 32 | #define WriteReg8(reg, val8) _OSWriteInt8((baseAddr), (reg), (val8)) 33 | #define WriteReg16(reg, val16) OSWriteLittleInt16((baseAddr), (reg), (val16)) 34 | #define WriteReg32(reg, val32) OSWriteLittleInt32((baseAddr), (reg), (val32)) 35 | #define ReadReg8(reg) _OSReadInt8((baseAddr), (reg)) 36 | #define ReadReg16(reg) OSReadLittleInt16((baseAddr), (reg)) 37 | #define ReadReg32(reg) OSReadLittleInt32((baseAddr), (reg)) 38 | 39 | #define super IOEthernetController 40 | 41 | enum 42 | { 43 | MEDIUM_INDEX_AUTO = 0, 44 | MEDIUM_INDEX_10HD, 45 | MEDIUM_INDEX_10FD, 46 | MEDIUM_INDEX_100HD, 47 | MEDIUM_INDEX_100FD, 48 | MEDIUM_INDEX_100FDFC, 49 | MEDIUM_INDEX_1000FD, 50 | MEDIUM_INDEX_1000FDFC, 51 | MEDIUM_INDEX_100FDEEE, 52 | MEDIUM_INDEX_100FDFCEEE, 53 | MEDIUM_INDEX_1000FDEEE, 54 | MEDIUM_INDEX_1000FDFCEEE, 55 | MEDIUM_INDEX_COUNT 56 | }; 57 | 58 | #define MBit 1000000 59 | 60 | enum { 61 | kSpeed1000MBit = 1000*MBit, 62 | kSpeed100MBit = 100*MBit, 63 | kSpeed10MBit = 10*MBit, 64 | }; 65 | 66 | enum { 67 | kFlowControlOff = 0, 68 | kFlowControlOn = 0x01 69 | }; 70 | 71 | enum { 72 | kEEEMode100 = 0x0002, 73 | kEEEMode1000 = 0x0004 74 | }; 75 | 76 | enum { 77 | kEEETypeNo = 0, 78 | kEEETypeYes = 1, 79 | kEEETypeCount 80 | }; 81 | 82 | /* RTL8111's dma descriptor. */ 83 | typedef union RtlDmaDesc { 84 | struct { 85 | UInt32 opts1; 86 | UInt32 opts2; 87 | UInt64 addr; 88 | } cmd; 89 | struct { 90 | UInt64 blen; 91 | UInt64 addr; 92 | } buf; 93 | } RtlDmaDesc; 94 | 95 | /* RTL8111's statistics dump data structure */ 96 | typedef struct RtlStatData { 97 | UInt64 txPackets; 98 | UInt64 rxPackets; 99 | UInt64 txErrors; 100 | UInt32 rxErrors; 101 | UInt16 rxMissed; 102 | UInt16 alignErrors; 103 | UInt32 txOneCollision; 104 | UInt32 txMultiCollision; 105 | UInt64 rxUnicast; 106 | UInt64 rxBroadcast; 107 | UInt32 rxMulticast; 108 | UInt16 txAborted; 109 | UInt16 txUnderun; 110 | } RtlStatData; 111 | 112 | #define kTransmitQueueCapacity 1024 113 | 114 | /* With up to 32 segments we should be on the save side. */ 115 | #define kMaxSegs 32 116 | 117 | /* The number of descriptors must be a power of 2. */ 118 | #define kNumTxDesc 512 /* Number of Tx descriptors */ 119 | #define kNumRxDesc 512 /* Number of Rx descriptors */ 120 | #define kTxLastDesc (kNumTxDesc - 1) 121 | #define kRxLastDesc (kNumRxDesc - 1) 122 | #define kTxDescMask (kNumTxDesc - 1) 123 | #define kRxDescMask (kNumRxDesc - 1) 124 | #define kTxDescSize (kNumTxDesc * sizeof(union RtlDmaDesc)) 125 | #define kRxDescSize (kNumRxDesc * sizeof(union RtlDmaDesc)) 126 | #define kRxBufArraySize (kNumRxDesc * sizeof(rtlRxBufferInfo)) 127 | #define kTxBufArraySize (kNumTxDesc * sizeof(mbuf_t)) 128 | 129 | /* Numbers of IOMemoryDescriptors and IORanges for tx */ 130 | #define kNumTxMemDesc (kNumTxDesc / 2) 131 | #define kTxMemDescMask (kNumTxMemDesc - 1) 132 | #define kNumTxRanges (kNumTxDesc + kMaxSegs) 133 | #define kTxRangeMask kTxDescMask 134 | #define kTxMapMemSize sizeof(struct rtlTxMapInfo) 135 | 136 | /* Numbers of IOMemoryDescriptors and batch size for rx */ 137 | #define kRxMemBaseShift 4 138 | #define kNumRxMemDesc (kNumRxDesc >> kRxMemBaseShift) 139 | #define kRxMapMemSize (sizeof(struct rtlRxMapInfo)) 140 | #define kRxMemBatchSize (kNumRxDesc / kNumRxMemDesc) 141 | #define kRxMemDescMask (kRxMemBatchSize - 1) 142 | #define kRxMemBaseMask ~kRxMemDescMask 143 | 144 | 145 | /* This is the receive buffer size (must be large enough to hold a packet). */ 146 | #define kRxBufferSize PAGE_SIZE 147 | #define kMCFilterLimit 32 148 | #define kMaxMtu 9000 149 | #define kMaxPacketSize (kMaxMtu + ETH_HLEN + ETH_FCS_LEN) 150 | #define kJumboFrameSupport CFG_METHOD_16 151 | 152 | /* RealtekRxPool capacities */ 153 | #define kRxPoolClstCap 100 /* mbufs with 4k cluster*/ 154 | #define kRxPoolMbufCap 50 /* mbufs without clusters */ 155 | 156 | /* statitics timer period in ms. */ 157 | #define kTimeoutMS 1000 158 | 159 | /* Treshhold value in ns for the modified interrupt sequence. */ 160 | #define kFastIntrTreshhold 200000 161 | 162 | /* Treshhold value to wake a stalled queue */ 163 | #define kTxQueueWakeTreshhold (kNumTxDesc / 8) 164 | 165 | /* transmitter deadlock treshhold in seconds. */ 166 | #define kTxDeadlockTreshhold 3 167 | #define kTxCheckTreshhold (kTxDeadlockTreshhold - 1) 168 | 169 | /* IPv4 specific stuff */ 170 | #define kMinL4HdrOffsetV4 34 171 | 172 | /* IPv6 specific stuff */ 173 | #define kMinL4HdrOffsetV6 54 174 | 175 | /* This definitions should have been in IOPCIDevice.h. */ 176 | enum 177 | { 178 | kIOPCIPMCapability = 2, 179 | kIOPCIPMControl = 4, 180 | }; 181 | 182 | enum 183 | { 184 | kIOPCIELinkCapability = 12, 185 | kIOPCIELinkControl = 16, 186 | }; 187 | 188 | enum 189 | { 190 | kIOPCIELinkCtlASPM = 0x0003, /* ASPM Control */ 191 | kIOPCIELinkCtlL0s = 0x0001, /* L0s Enable */ 192 | kIOPCIELinkCtlL1 = 0x0002, /* L1 Enable */ 193 | kIOPCIELinkCtlCcc = 0x0040, /* Common Clock Configuration */ 194 | kIOPCIELinkCtlClkReqEn = 0x100, /* Enable clkreq */ 195 | }; 196 | 197 | enum 198 | { 199 | kPowerStateOff = 0, 200 | kPowerStateOn, 201 | kPowerStateCount 202 | }; 203 | 204 | #define kParamName "Driver Parameters" 205 | #define kEnableEeeName "enableEEE" 206 | #define kEnableCSO6Name "enableCSO6" 207 | #define kEnableTSO4Name "enableTSO4" 208 | #define kEnableTSO6Name "enableTSO6" 209 | #define kDisableASPMName "disableASPM" 210 | #define kDriverVersionName "DriverVersion" 211 | #define kFallbackName "fallbackMAC" 212 | #define kNameLenght 64 213 | 214 | #define kChipsetName "Chipset" 215 | 216 | /* 217 | * Indicates if a tx IOMemoryDescriptor is in the prepared 218 | * (active) or completed state (inactive). 219 | */ 220 | enum 221 | { 222 | kIOMemoryInactive = 0, 223 | kIOMemoryActive = 1 224 | }; 225 | 226 | typedef struct rtlTxMapInfo { 227 | UInt16 txNextMem2Use; 228 | UInt16 txNextMem2Free; 229 | SInt16 txNumFreeMem; 230 | IOMemoryDescriptor *txMemIO[kNumTxMemDesc]; 231 | IOAddressRange txMemRange[kNumTxRanges]; 232 | IOAddressRange txSCRange[kMaxSegs]; 233 | } rtlTxMapInfo; 234 | 235 | typedef struct rtlRxMapInfo { 236 | IOMemoryDescriptor *rxMemIO[kNumRxMemDesc]; 237 | IOAddressRange rxMemRange[kNumRxDesc]; 238 | } rtlRxMapInfo; 239 | 240 | typedef struct rtlRxBufferInfo { 241 | mbuf_t mbuf; 242 | IOPhysicalAddress64 phyAddr; 243 | } rtlRxBufferInfo; 244 | 245 | /** 246 | * Known kernel versions 247 | */ 248 | enum KernelVersion { 249 | Tiger = 8, 250 | Leopard = 9, 251 | SnowLeopard = 10, 252 | Lion = 11, 253 | MountainLion = 12, 254 | Mavericks = 13, 255 | Yosemite = 14, 256 | ElCapitan = 15, 257 | Sierra = 16, 258 | HighSierra = 17, 259 | Mojave = 18, 260 | Catalina = 19, 261 | BigSur = 20, 262 | Monterey = 21, 263 | Ventura = 22, 264 | Sonoma = 23, 265 | Sequoia = 24, 266 | Tahoe = 25, 267 | }; 268 | 269 | /** 270 | * Kernel version major 271 | */ 272 | extern const int version_major; 273 | 274 | extern const struct RTLChipInfo rtl_chip_info[]; 275 | 276 | class RTL8111 : public super 277 | { 278 | 279 | OSDeclareDefaultStructors(RTL8111) 280 | 281 | public: 282 | /* IOService (or its superclass) methods. */ 283 | virtual bool start(IOService *provider) override; 284 | virtual void stop(IOService *provider) override; 285 | virtual bool init(OSDictionary *properties) override; 286 | virtual void free() override; 287 | 288 | /* Power Management Support */ 289 | virtual IOReturn registerWithPolicyMaker(IOService *policyMaker) override; 290 | virtual IOReturn setPowerState(unsigned long powerStateOrdinal, IOService *policyMaker ) override; 291 | virtual void systemWillShutdown(IOOptionBits specifier) override; 292 | 293 | /* IONetworkController methods. */ 294 | virtual IOReturn enable(IONetworkInterface *netif) override; 295 | virtual IOReturn disable(IONetworkInterface *netif) override; 296 | 297 | virtual IOReturn outputStart(IONetworkInterface *interface, IOOptionBits options) override; 298 | virtual IOReturn setInputPacketPollingEnable(IONetworkInterface *interface, bool enabled) override; 299 | virtual void pollInputPackets(IONetworkInterface *interface, uint32_t maxCount, IOMbufQueue *pollQueue, void *context) override; 300 | 301 | virtual void getPacketBufferConstraints(IOPacketBufferConstraints *constraints) const override; 302 | 303 | virtual IOOutputQueue* createOutputQueue() override; 304 | 305 | virtual const OSString* newVendorString() const override; 306 | virtual const OSString* newModelString() const override; 307 | 308 | virtual IOReturn selectMedium(const IONetworkMedium *medium) override; 309 | virtual bool configureInterface(IONetworkInterface *interface) override; 310 | 311 | virtual bool createWorkLoop() override; 312 | virtual IOWorkLoop* getWorkLoop() const override; 313 | 314 | /* Methods inherited from IOEthernetController. */ 315 | virtual IOReturn getHardwareAddress(IOEthernetAddress *addr) override; 316 | virtual IOReturn setHardwareAddress(const IOEthernetAddress *addr) override; 317 | virtual IOReturn setPromiscuousMode(bool active) override; 318 | virtual IOReturn setMulticastMode(bool active) override; 319 | virtual IOReturn setMulticastList(IOEthernetAddress *addrs, UInt32 count) override; 320 | virtual IOReturn getChecksumSupport(UInt32 *checksumMask, UInt32 checksumFamily, bool isOutput) override; 321 | virtual IOReturn setWakeOnMagicPacket(bool active) override; 322 | virtual IOReturn getPacketFilters(const OSSymbol *group, UInt32 *filters) const override; 323 | 324 | virtual UInt32 getFeatures() const override; 325 | virtual IOReturn getMaxPacketSize(UInt32 * maxSize) const override; 326 | virtual IOReturn setMaxPacketSize(UInt32 maxSize) override; 327 | 328 | private: 329 | bool initPCIConfigSpace(IOPCIDevice *provider); 330 | static IOReturn setPowerStateWakeAction(OSObject *owner, void *arg1, void *arg2, void *arg3, void *arg4); 331 | static IOReturn setPowerStateSleepAction(OSObject *owner, void *arg1, void *arg2, void *arg3, void *arg4); 332 | void getParams(); 333 | bool setupMediumDict(); 334 | bool initEventSources(IOService *provider); 335 | void pciErrorInterrupt(); 336 | void txInterrupt(); 337 | 338 | UInt32 txMapPacket(mbuf_t packet, IOPhysicalSegment *vector, UInt32 maxSegs); 339 | void txUnmapPacket(); 340 | 341 | void interruptOccurredPoll(OSObject *client, IOInterruptEventSource *src, int count); 342 | void interruptOccurredVTD(OSObject *client, IOInterruptEventSource *src, int count); 343 | 344 | UInt32 rxInterrupt(IONetworkInterface *interface, uint32_t maxCount, IOMbufQueue *pollQueue, void *context); 345 | UInt32 rxInterruptVTD(IONetworkInterface *interface, uint32_t maxCount, IOMbufQueue *pollQueue, void *context); 346 | 347 | UInt16 rxMapBuffers(UInt16 index, UInt16 count); 348 | 349 | bool setupRxResources(); 350 | bool setupTxResources(); 351 | bool setupStatResources(); 352 | void freeRxResources(); 353 | void freeTxResources(); 354 | void freeStatResources(); 355 | void clearDescriptors(); 356 | void checkLinkStatus(); 357 | void updateStatitics(); 358 | void setLinkUp(); 359 | void setLinkDown(); 360 | bool checkForDeadlock(); 361 | 362 | bool setupRxMap(); 363 | void freeRxMap(); 364 | bool setupTxMap(); 365 | void freeTxMap(); 366 | 367 | /* Jumbo frame support methods */ 368 | void discardPacketFragment(); 369 | 370 | /* Hardware initialization methods. */ 371 | bool initRTL8111(); 372 | void enableRTL8111(); 373 | void disableRTL8111(); 374 | void setupRTL8111(UInt16 newIntrMitigate, bool enableInterrupts); 375 | void setOffset79(UInt8 setting); 376 | void restartRTL8111(); 377 | void setPhyMedium(); 378 | UInt8 csiFun0ReadByte(UInt32 addr); 379 | void csiFun0WriteByte(UInt32 addr, UInt8 value); 380 | void enablePCIOffset99(); 381 | void disablePCIOffset99(); 382 | void initPCIOffset99(); 383 | void setPCI99_180ExitDriverPara(); 384 | void hardwareD3Para(); 385 | void sleepRxEnable(); 386 | UInt16 getEEEMode(); 387 | void exitOOB(); 388 | 389 | /* Hardware specific methods */ 390 | inline void getChecksumCommand(UInt32 *cmd1, UInt32 *cmd2, mbuf_csum_request_flags_t checksums); 391 | inline void getTso4Command(UInt32 *cmd1, UInt32 *cmd2, UInt32 mssValue, mbuf_tso_request_flags_t tsoFlags); 392 | inline void getTso6Command(UInt32 *cmd1, UInt32 *cmd2, UInt32 mssValue, mbuf_tso_request_flags_t tsoFlags); 393 | void getChecksumResult(mbuf_t m, UInt32 status1, UInt32 status2); 394 | 395 | /* RTL8111C specific methods */ 396 | void timerActionRTL8111C(IOTimerEventSource *timer); 397 | 398 | /* RTL8111B/8168B specific methods */ 399 | void timerActionRTL8111B(IOTimerEventSource *timer); 400 | 401 | private: 402 | IOWorkLoop *workLoop; 403 | IOCommandGate *commandGate; 404 | IOPCIDevice *pciDevice; 405 | OSDictionary *mediumDict; 406 | IONetworkMedium *mediumTable[MEDIUM_INDEX_COUNT]; 407 | IOBasicOutputQueue *txQueue; 408 | 409 | IOInterruptEventSource *interruptSource; 410 | IOTimerEventSource *timerSource; 411 | IOEthernetInterface *netif; 412 | IOMemoryMap *baseMap; 413 | IOMapper *mapper; 414 | volatile void *baseAddr; 415 | 416 | /* transmitter data */ 417 | mbuf_t txNext2FreeMbuf; 418 | IOBufferMemoryDescriptor *txBufDesc; 419 | IOPhysicalAddress64 txPhyAddr; 420 | IODMACommand *txDescDmaCmd; 421 | RtlDmaDesc *txDescArray; 422 | IOMbufNaturalMemoryCursor *txMbufCursor; 423 | mbuf_t *txMbufArray; 424 | void *txBufArrayMem; 425 | rtlTxMapInfo *txMapInfo; 426 | void *txMapMem; 427 | UInt64 txDescDoneCount; 428 | UInt64 txDescDoneLast; 429 | UInt32 txNextDescIndex; 430 | UInt32 txDirtyDescIndex; 431 | SInt32 txNumFreeDesc; 432 | 433 | /* receiver data */ 434 | IOBufferMemoryDescriptor *rxBufDesc; 435 | IOPhysicalAddress64 rxPhyAddr; 436 | IODMACommand *rxDescDmaCmd; 437 | RtlDmaDesc *rxDescArray; 438 | RealtekRxPool *rxPool; 439 | rtlRxBufferInfo *rxBufArray; 440 | void *rxBufArrayMem; 441 | void *rxMapMem; 442 | rtlRxMapInfo *rxMapInfo; 443 | mbuf_t rxPacketHead; 444 | mbuf_t rxPacketTail; 445 | UInt32 rxPacketSize; 446 | UInt64 multicastFilter; 447 | UInt32 rxConfigReg; 448 | UInt32 rxConfigMask; 449 | UInt16 rxNextDescIndex; 450 | UInt16 rxMapNextIndex; 451 | 452 | /* power management data */ 453 | unsigned long powerState; 454 | 455 | /* statistics data */ 456 | UInt32 deadlockWarn; 457 | IONetworkStats *netStats; 458 | IOEthernetStats *etherStats; 459 | IOBufferMemoryDescriptor *statBufDesc; 460 | IOPhysicalAddress64 statPhyAddr; 461 | IODMACommand *statDescDmaCmd; 462 | struct RtlStatData *statData; 463 | 464 | UInt32 mtu; 465 | UInt32 speed; 466 | UInt32 duplex; 467 | UInt16 flowCtl; 468 | UInt16 autoneg; 469 | UInt16 eeeCap; 470 | UInt16 eeeMode; 471 | struct pci_dev pciDeviceData; 472 | struct rtl8168_private linuxData; 473 | struct IOEthernetAddress currMacAddr; 474 | struct IOEthernetAddress origMacAddr; 475 | struct IOEthernetAddress fallBackMacAddr; 476 | 477 | UInt64 lastIntrTime; 478 | UInt16 intrMask; 479 | UInt16 intrMitigateValue; 480 | 481 | UInt16 intrMaskRxTx; 482 | UInt16 intrMaskPoll; 483 | 484 | IONetworkPacketPollingParameters pollParams; 485 | 486 | bool polling; 487 | 488 | /* flags */ 489 | bool isEnabled; 490 | bool promiscusMode; 491 | bool multicastMode; 492 | bool linkUp; 493 | 494 | bool needsUpdate; 495 | bool wolCapable; 496 | bool wolActive; 497 | bool revisionC; 498 | bool enableTSO4; 499 | bool enableTSO6; 500 | bool enableCSO6; 501 | bool disableASPM; 502 | bool useAppleVTD; 503 | 504 | UInt8 pciPMCtrlOffset; 505 | }; 506 | -------------------------------------------------------------------------------- /RealtekRTL8111/RealtekRTL8111VTD.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // RealtekRTL8111VTD.cpp 3 | // RealtekRTL8111 4 | // 5 | // Created by Laura Müller on 26.11.25. 6 | // Copyright © 2025 Laura Müller. All rights reserved. 7 | // 8 | 9 | #include "RealtekRTL8111.hpp" 10 | 11 | #ifndef MIN 12 | #define MIN(a,b) (((a)<(b))?(a):(b)) 13 | #endif /* MIN */ 14 | 15 | #define next_page(x) trunc_page(x + PAGE_SIZE) 16 | 17 | #pragma mark --- initialisation methods for AppleVTD support --- 18 | 19 | bool RTL8111::setupRxMap() 20 | { 21 | IOMemoryDescriptor *md; 22 | IOPhysicalAddress pa; 23 | IOByteCount offset; 24 | UInt64 word1; 25 | UInt32 end; 26 | UInt32 i, n, idx; 27 | bool result = false; 28 | 29 | /* Alloc ixgbeRxBufferInfo. */ 30 | rxMapMem = IOMallocZero(kRxMapMemSize); 31 | 32 | if (!rxMapMem) { 33 | IOLog("Couldn't alloc rx map.\n"); 34 | goto done; 35 | } 36 | rxMapInfo = (rtlRxMapInfo *)rxMapMem; 37 | 38 | /* Setup Ranges for IOMemoryDescriptors. */ 39 | for (i = 0; i < kNumRxDesc; i++) { 40 | rxMapInfo->rxMemRange[i].address = (IOVirtualAddress)mbuf_datastart(rxBufArray[i].mbuf); 41 | rxMapInfo->rxMemRange[i].length = PAGE_SIZE; 42 | } 43 | 44 | /* Alloc IOMemoryDescriptors. */ 45 | for (i = 0, idx = 0; i < kNumRxMemDesc; i++, idx += kRxMemBatchSize) { 46 | md = IOMemoryDescriptor::withOptions(&rxMapInfo->rxMemRange[idx], kRxMemBatchSize, 0, kernel_task, (kIOMemoryTypeVirtual | kIODirectionIn | kIOMemoryAsReference), mapper); 47 | 48 | if (!md) { 49 | IOLog("Couldn't alloc IOMemoryDescriptor.\n"); 50 | goto error_rx_desc; 51 | } 52 | if (md->prepare() != kIOReturnSuccess) { 53 | IOLog("IOMemoryDescriptor::prepare() failed.\n"); 54 | goto error_prep; 55 | } 56 | rxMapInfo->rxMemIO[i] = md; 57 | offset = 0; 58 | end = idx + kRxMemBatchSize; 59 | word1 = (kRxBufferSize | DescOwn); 60 | 61 | for (n = idx; n < end; n++) { 62 | if (n == kRxLastDesc) 63 | word1 |= RingEnd; 64 | 65 | pa = md->getPhysicalSegment(offset, NULL); 66 | rxBufArray[n].phyAddr = pa; 67 | 68 | rxDescArray[i].buf.blen = OSSwapHostToLittleInt64(word1); 69 | rxDescArray[i].buf.addr = OSSwapHostToLittleInt64(rxBufArray[i].phyAddr); 70 | 71 | offset += PAGE_SIZE; 72 | } 73 | } 74 | result = true; 75 | 76 | done: 77 | return result; 78 | 79 | error_prep: 80 | md->complete(); 81 | RELEASE(md); 82 | 83 | error_rx_desc: 84 | if (rxMapMem) { 85 | for (i = 0; i < kNumRxMemDesc; i++) { 86 | md = rxMapInfo->rxMemIO[i]; 87 | 88 | if (md) { 89 | md->complete(); 90 | md->release(); 91 | } 92 | rxMapInfo->rxMemIO[i] = NULL; 93 | } 94 | IOFree(rxMapMem, kRxMapMemSize); 95 | rxMapMem = NULL; 96 | } 97 | goto done; 98 | } 99 | 100 | void RTL8111::freeRxMap() 101 | { 102 | IOMemoryDescriptor *md; 103 | UInt32 i; 104 | 105 | if (rxMapMem) { 106 | for (i = 0; i < kNumRxMemDesc; i++) { 107 | md = rxMapInfo->rxMemIO[i]; 108 | 109 | if (md) { 110 | md->complete(); 111 | md->release(); 112 | } 113 | rxMapInfo->rxMemIO[i] = NULL; 114 | } 115 | IOFree(rxMapMem, kRxMapMemSize); 116 | rxMapMem = NULL; 117 | } 118 | } 119 | 120 | bool RTL8111::setupTxMap() 121 | { 122 | bool result = false; 123 | 124 | txMapMem = IOMallocZero(kTxMapMemSize); 125 | 126 | if (!txMapMem) { 127 | IOLog("Couldn't alloc memory for tx map.\n"); 128 | goto done; 129 | } 130 | txMapInfo = (rtlTxMapInfo *)txMapMem; 131 | 132 | txMapInfo->txNextMem2Use = 0; 133 | txMapInfo->txNextMem2Free = 0; 134 | txMapInfo->txNumFreeMem = kNumTxMemDesc; 135 | 136 | result = true; 137 | 138 | done: 139 | return result; 140 | } 141 | 142 | void RTL8111::freeTxMap() 143 | { 144 | UInt32 i; 145 | 146 | if (txMapMem) { 147 | for (i = 0; i < kNumTxMemDesc; i++) { 148 | if (txMapInfo->txMemIO[i]) { 149 | txMapInfo->txMemIO[i]->complete(); 150 | txMapInfo->txMemIO[i]->release(); 151 | txMapInfo->txMemIO[i] = NULL; 152 | } 153 | } 154 | IOFree(txMapMem, kTxMapMemSize); 155 | txMapMem = NULL; 156 | } 157 | } 158 | 159 | #pragma mark --- interrupt methods for AppleVTD support --- 160 | 161 | void RTL8111::interruptOccurredVTD(OSObject *client, IOInterruptEventSource *src, int count) 162 | { 163 | UInt32 packets; 164 | UInt16 status; 165 | 166 | WriteReg16(IntrMask, 0x0000); 167 | status = ReadReg16(IntrStatus); 168 | 169 | /* hotplug/major error/no more work/shared irq */ 170 | if ((status == 0xFFFF) || !status) 171 | goto done; 172 | 173 | if (status & SYSErr) { 174 | pciErrorInterrupt(); 175 | goto done; 176 | } 177 | if (!polling) { 178 | /* Rx interrupt */ 179 | if (status & (RxOK | RxDescUnavail | RxFIFOOver)) { 180 | packets = rxInterruptVTD(netif, kNumRxDesc, NULL, NULL); 181 | 182 | if (packets) 183 | netif->flushInputQueue(); 184 | } 185 | /* Tx interrupt */ 186 | if (status & (TxOK | TxErr | TxDescUnavail)) 187 | txInterrupt(); 188 | } 189 | if (status & LinkChg) 190 | checkLinkStatus(); 191 | 192 | done: 193 | WriteReg16(IntrStatus, status); 194 | WriteReg16(IntrMask, intrMask); 195 | } 196 | 197 | 198 | #pragma mark --- tx methods for AppleVTD support --- 199 | 200 | /* 201 | * Map a tx packet for read DMA access by the NIC. 202 | * The packet is split up into physical contiguous segments 203 | * and an IOMemoryDescriptor is used to map all segments for 204 | * DMA access. 205 | */ 206 | UInt32 RTL8111::txMapPacket(mbuf_t packet, 207 | IOPhysicalSegment *vector, 208 | UInt32 maxSegs) 209 | { 210 | IOMemoryDescriptor *md = NULL; 211 | IOAddressRange *srcRange; 212 | IOAddressRange *dstRange; 213 | mbuf_t m; 214 | IOVirtualAddress d; 215 | IOByteCount offset; 216 | UInt64 len, l; 217 | UInt32 segIndex = 0; 218 | UInt32 i; 219 | UInt16 saveMem; 220 | bool result = false; 221 | 222 | if (packet && vector && maxSegs) { 223 | srcRange = txMapInfo->txSCRange; 224 | m = packet; 225 | 226 | /* 227 | * Split up the packet into virtual contiguos segments. 228 | */ 229 | if (mbuf_next(m) == 0) { 230 | d = (IOVirtualAddress)mbuf_data(m); 231 | len = mbuf_len(m); 232 | 233 | if ( trunc_page(d) == trunc_page(d + len - 1) ) { 234 | srcRange[0].address = d; 235 | srcRange[0].length = len; 236 | segIndex = 1; 237 | goto map; 238 | } 239 | } 240 | do { 241 | d = (IOVirtualAddress)mbuf_data(m); 242 | 243 | for (len = mbuf_len(m); len; d += l, len -= l) { 244 | l = MIN(len, PAGE_SIZE); 245 | l = MIN(next_page(d), d + l) - d; 246 | 247 | if (segIndex < maxSegs) { 248 | srcRange[segIndex].address = d; 249 | srcRange[segIndex].length = l; 250 | } else { 251 | segIndex = 0; 252 | goto done; 253 | } 254 | segIndex++; 255 | } 256 | m = mbuf_next(m); 257 | } while (m); 258 | map: 259 | /* 260 | * Get IORanges, fill in the virtual segments and grab 261 | * an IOMemoryDescriptor to map the packet. 262 | */ 263 | if (txMapInfo->txNumFreeMem > 1) { 264 | dstRange = &txMapInfo->txMemRange[txNextDescIndex]; 265 | 266 | for (i = 0; i < segIndex; i++) { 267 | dstRange[i].address = (srcRange[i].address & ~PAGE_MASK); 268 | dstRange[i].length = PAGE_SIZE; 269 | srcRange[i].address &= PAGE_MASK; 270 | } 271 | OSAddAtomic16(-1, &txMapInfo->txNumFreeMem); 272 | saveMem = txMapInfo->txNextMem2Use++; 273 | txMapInfo->txNextMem2Use &= kTxMemDescMask; 274 | md = txMapInfo->txMemIO[saveMem]; 275 | 276 | if (md) { 277 | result = md->initWithOptions(dstRange, segIndex, 0, kernel_task, (kIOMemoryTypeVirtual | kIODirectionOut | kIOMemoryAsReference), mapper); 278 | } else { 279 | md = IOMemoryDescriptor::withAddressRanges(dstRange, segIndex, (kIOMemoryTypeVirtual | kIODirectionOut | kIOMemoryAsReference), kernel_task); 280 | 281 | if (!md) { 282 | DebugLog("Couldn't alloc IOMemoryDescriptor for tx packet."); 283 | goto error_map; 284 | } 285 | txMapInfo->txMemIO[saveMem] = md; 286 | result = true; 287 | } 288 | if (!result) { 289 | DebugLog("Failed to init IOMemoryDescriptor for tx packet."); 290 | goto error_map; 291 | } 292 | if (md->prepare() != kIOReturnSuccess) { 293 | DebugLog("Failed to prepare() tx packet."); 294 | goto error_map; 295 | } 296 | md->setTag(kIOMemoryActive); 297 | offset = 0; 298 | 299 | /* 300 | * Get the physical segments and fill in the vector. 301 | */ 302 | for (i = 0; i < segIndex; i++) { 303 | vector[i].location = md->getPhysicalSegment(offset, NULL) + srcRange[i].address; 304 | vector[i].length = srcRange[i].length; 305 | 306 | //DebugLog("Phy. Segment %u addr: %llx, len: %llu\n", i, vector[i].location, vector[i].length); 307 | offset += PAGE_SIZE; 308 | } 309 | } 310 | } 311 | 312 | done: 313 | return segIndex; 314 | 315 | error_map: 316 | txMapInfo->txNextMem2Use = saveMem; 317 | OSAddAtomic16(1, &txMapInfo->txNumFreeMem); 318 | 319 | segIndex = 0; 320 | goto done; 321 | } 322 | 323 | /* 324 | * Unmap a tx packet. Complete the IOMemoryDecriptor and free it 325 | * for reuse. 326 | */ 327 | void RTL8111::txUnmapPacket() 328 | { 329 | IOMemoryDescriptor *md = txMapInfo->txMemIO[txMapInfo->txNextMem2Free]; 330 | 331 | md->complete(); 332 | md->setTag(kIOMemoryInactive); 333 | 334 | ++(txMapInfo->txNextMem2Free) &= kTxMemDescMask; 335 | OSAddAtomic16(1, &txMapInfo->txNumFreeMem); 336 | } 337 | 338 | #pragma mark --- rx methods for AppleVTD support --- 339 | 340 | /* 341 | * Unmap a batch of rx buffers, replace them with new ones and map them. 342 | * @ring The ring to map for 343 | * @index The index of the first buffer in a batch to map. 344 | * @count Number of batches to map. 345 | * @result The index of the next batch to map. 346 | */ 347 | UInt16 RTL8111::rxMapBuffers(UInt16 index, UInt16 count) 348 | { 349 | IOPhysicalAddress pa; 350 | IOMemoryDescriptor *md; 351 | UInt64 length; 352 | IOByteCount offset; 353 | UInt32 batch = count; 354 | UInt16 end, i; 355 | bool result; 356 | 357 | while (batch--) { 358 | /* 359 | * Get the coresponding IOMemoryDescriptor and complete 360 | * the mapping; 361 | */ 362 | md = rxMapInfo->rxMemIO[index >> kRxMemBaseShift]; 363 | md->complete(); 364 | 365 | /* 366 | * Update IORanges with the addresses of the replaced buffers. 367 | */ 368 | for (i = index, end = index + kRxMemBatchSize; i < end; i++) { 369 | if (rxBufArray[i].phyAddr == 0) { 370 | rxMapInfo->rxMemRange[i].address = (IOVirtualAddress)mbuf_datastart(rxBufArray[i].mbuf); 371 | } 372 | } 373 | /* 374 | * Prepare IOMemoryDescriptor with updated buffer addresses. 375 | */ 376 | result = md->initWithOptions(&rxMapInfo->rxMemRange[index], kRxMemBatchSize, 0, kernel_task, kIOMemoryTypeVirtual | kIODirectionIn | kIOMemoryAsReference, mapper); 377 | 378 | if (!result) { 379 | IOLog("Failed to reinit rx IOMemoryDescriptor.\n"); 380 | goto done; 381 | } 382 | if (md->prepare() != kIOReturnSuccess) { 383 | IOLog("Failed to prepare rx IOMemoryDescriptor.\n"); 384 | goto done; 385 | } 386 | /* 387 | * Get physical addresses of the buffers and update buffer info, 388 | * as well as the descriptor ring with new addresses. 389 | */ 390 | length = (kRxBufferSize | DescOwn); 391 | offset = 0; 392 | 393 | for (i = index, end = index + kRxMemBatchSize; i < end; i++) { 394 | if (i == kRxLastDesc) 395 | length |= RingEnd; 396 | 397 | pa = md->getPhysicalSegment(offset, NULL); 398 | rxBufArray[i].phyAddr = pa; 399 | 400 | rxDescArray[i].buf.addr = OSSwapHostToLittleInt64(pa); 401 | rxDescArray[i].buf.blen = OSSwapHostToLittleInt64(length); 402 | 403 | //DebugLog("rxDescArray[%u]: 0x%x %llu\n", i, (unsigned int)length, pa); 404 | offset += PAGE_SIZE; 405 | } 406 | wmb(); 407 | 408 | next_batch: 409 | /* 410 | * Update indices after every batch. 411 | */ 412 | index = (index + kRxMemBatchSize) & kRxDescMask; 413 | rxMapNextIndex = index; 414 | } 415 | 416 | done: 417 | return index; 418 | } 419 | 420 | UInt32 RTL8111::rxInterruptVTD(IONetworkInterface *interface, uint32_t maxCount, IOMbufQueue *pollQueue, void *context) 421 | { 422 | RtlDmaDesc *desc = &rxDescArray[rxNextDescIndex]; 423 | mbuf_t bufPkt, newPkt; 424 | UInt32 goodPkts = 0; 425 | UInt32 numMap = 0; 426 | UInt32 descStatus1, descStatus2; 427 | UInt32 pktSize; 428 | bool replaced; 429 | 430 | while (!((descStatus1 = OSSwapLittleToHostInt32(desc->cmd.opts1)) & DescOwn) && (goodPkts < maxCount)) { 431 | descStatus2 = OSSwapLittleToHostInt32(desc->cmd.opts2); 432 | pktSize = (descStatus1 & 0x1fff) - kIOEthernetCRCSize; 433 | bufPkt = rxBufArray[rxNextDescIndex].mbuf; 434 | //DebugLog("rxInterrupt(): descStatus1=0x%x, descStatus2=0x%x, pktSize=%u\n", descStatus1, descStatus2, pktSize); 435 | 436 | newPkt = rxPool->replaceOrCopyPacket(&bufPkt, pktSize, &replaced); 437 | 438 | if (!newPkt) { 439 | /* Allocation of a new packet failed so that we must leave the original packet in place. */ 440 | DebugLog("replaceOrCopyPacket() failed.\n"); 441 | etherStats->dot3RxExtraEntry.resourceErrors++; 442 | goto nextDesc; 443 | } 444 | 445 | /* If the packet was replaced we have to update the descriptor's buffer address. */ 446 | if (replaced) { 447 | if (mbuf_next(bufPkt) != NULL) { 448 | DebugLog("Failed to get physical address.\n"); 449 | etherStats->dot3RxExtraEntry.resourceErrors++; 450 | mbuf_freem_list(bufPkt); 451 | goto nextDesc; 452 | } 453 | rxBufArray[rxNextDescIndex].mbuf = bufPkt; 454 | rxBufArray[rxNextDescIndex].phyAddr = 0; 455 | } 456 | /* Set the length of the buffer. */ 457 | mbuf_setlen(newPkt, pktSize); 458 | 459 | if (descStatus1 & LastFrag) { 460 | if (rxPacketHead) { 461 | /* This is the last buffer of a jumbo frame. */ 462 | mbuf_setflags_mask(newPkt, 0, MBUF_PKTHDR); 463 | mbuf_setnext(rxPacketTail, newPkt); 464 | 465 | rxPacketSize += pktSize; 466 | rxPacketTail = newPkt; 467 | } else { 468 | /* 469 | * We've got a complete packet in one buffer. 470 | * It can be enqueued directly. 471 | */ 472 | rxPacketHead = newPkt; 473 | rxPacketSize = pktSize; 474 | } 475 | getChecksumResult(newPkt, descStatus1, descStatus2); 476 | 477 | /* Also get the VLAN tag if there is any. */ 478 | if (descStatus2 & RxVlanTag) 479 | setVlanTag(rxPacketHead, OSSwapInt16(descStatus2 & 0xffff)); 480 | 481 | mbuf_pkthdr_setlen(rxPacketHead, rxPacketSize); 482 | interface->enqueueInputPacket(rxPacketHead, pollQueue); 483 | 484 | rxPacketHead = rxPacketTail = NULL; 485 | rxPacketSize = 0; 486 | 487 | goodPkts++; 488 | } else { 489 | if (rxPacketHead) { 490 | /* We are in the middle of a jumbo frame. */ 491 | mbuf_setflags_mask(newPkt, 0, MBUF_PKTHDR); 492 | mbuf_setnext(rxPacketTail, newPkt); 493 | 494 | rxPacketTail = newPkt; 495 | rxPacketSize += pktSize; 496 | } else { 497 | /* This is the first buffer of a jumbo frame. */ 498 | rxPacketHead = rxPacketTail = newPkt; 499 | rxPacketSize = pktSize; 500 | } 501 | } 502 | 503 | nextDesc: 504 | /* 505 | * If a batch has been completed, increment the number of 506 | * batches, which need to be mapped. 507 | */ 508 | if ((rxNextDescIndex & kRxMemDescMask) == kRxMemDescMask) 509 | numMap++; 510 | 511 | /* Get the next descriptor to process. */ 512 | ++rxNextDescIndex &= kRxDescMask; 513 | desc = &rxDescArray[rxNextDescIndex]; 514 | } 515 | if (numMap) { 516 | //DebugLog("rxMapNextIndex: %u, numMap: %u\n", rxMapNextIndex, numMap); 517 | rxMapBuffers(rxMapNextIndex, numMap); 518 | } 519 | return goodPkts; 520 | } 521 | -------------------------------------------------------------------------------- /RealtekRTL8111/gpl.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 2, June 1991 3 | 4 | Copyright (C) 1989, 1991 Free Software Foundation, Inc. 5 | 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 6 | Everyone is permitted to copy and distribute verbatim copies 7 | of this license document, but changing it is not allowed. 8 | 9 | Preamble 10 | 11 | The licenses for most software are designed to take away your 12 | freedom to share and change it. By contrast, the GNU General Public 13 | License is intended to guarantee your freedom to share and change free 14 | software--to make sure the software is free for all its users. This 15 | General Public License applies to most of the Free Software 16 | Foundation's software and to any other program whose authors commit to 17 | using it. (Some other Free Software Foundation software is covered by 18 | the GNU Library General Public License instead.) You can apply it to 19 | your programs, too. 20 | 21 | When we speak of free software, we are referring to freedom, not 22 | price. Our General Public Licenses are designed to make sure that you 23 | have the freedom to distribute copies of free software (and charge for 24 | this service if you wish), that you receive source code or can get it 25 | if you want it, that you can change the software or use pieces of it 26 | in new free programs; and that you know you can do these things. 27 | 28 | To protect your rights, we need to make restrictions that forbid 29 | anyone to deny you these rights or to ask you to surrender the rights. 30 | These restrictions translate to certain responsibilities for you if you 31 | distribute copies of the software, or if you modify it. 32 | 33 | For example, if you distribute copies of such a program, whether 34 | gratis or for a fee, you must give the recipients all the rights that 35 | you have. You must make sure that they, too, receive or can get the 36 | source code. And you must show them these terms so they know their 37 | rights. 38 | 39 | We protect your rights with two steps: (1) copyright the software, and 40 | (2) offer you this license which gives you legal permission to copy, 41 | distribute and/or modify the software. 42 | 43 | Also, for each author's protection and ours, we want to make certain 44 | that everyone understands that there is no warranty for this free 45 | software. If the software is modified by someone else and passed on, we 46 | want its recipients to know that what they have is not the original, so 47 | that any problems introduced by others will not reflect on the original 48 | authors' reputations. 49 | 50 | Finally, any free program is threatened constantly by software 51 | patents. We wish to avoid the danger that redistributors of a free 52 | program will individually obtain patent licenses, in effect making the 53 | program proprietary. To prevent this, we have made it clear that any 54 | patent must be licensed for everyone's free use or not licensed at all. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | GNU GENERAL PUBLIC LICENSE 60 | TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 61 | 62 | 0. This License applies to any program or other work which contains 63 | a notice placed by the copyright holder saying it may be distributed 64 | under the terms of this General Public License. The "Program", below, 65 | refers to any such program or work, and a "work based on the Program" 66 | means either the Program or any derivative work under copyright law: 67 | that is to say, a work containing the Program or a portion of it, 68 | either verbatim or with modifications and/or translated into another 69 | language. (Hereinafter, translation is included without limitation in 70 | the term "modification".) Each licensee is addressed as "you". 71 | 72 | Activities other than copying, distribution and modification are not 73 | covered by this License; they are outside its scope. The act of 74 | running the Program is not restricted, and the output from the Program 75 | is covered only if its contents constitute a work based on the 76 | Program (independent of having been made by running the Program). 77 | Whether that is true depends on what the Program does. 78 | 79 | 1. You may copy and distribute verbatim copies of the Program's 80 | source code as you receive it, in any medium, provided that you 81 | conspicuously and appropriately publish on each copy an appropriate 82 | copyright notice and disclaimer of warranty; keep intact all the 83 | notices that refer to this License and to the absence of any warranty; 84 | and give any other recipients of the Program a copy of this License 85 | along with the Program. 86 | 87 | You may charge a fee for the physical act of transferring a copy, and 88 | you may at your option offer warranty protection in exchange for a fee. 89 | 90 | 2. You may modify your copy or copies of the Program or any portion 91 | of it, thus forming a work based on the Program, and copy and 92 | distribute such modifications or work under the terms of Section 1 93 | above, provided that you also meet all of these conditions: 94 | 95 | a) You must cause the modified files to carry prominent notices 96 | stating that you changed the files and the date of any change. 97 | 98 | b) You must cause any work that you distribute or publish, that in 99 | whole or in part contains or is derived from the Program or any 100 | part thereof, to be licensed as a whole at no charge to all third 101 | parties under the terms of this License. 102 | 103 | c) If the modified program normally reads commands interactively 104 | when run, you must cause it, when started running for such 105 | interactive use in the most ordinary way, to print or display an 106 | announcement including an appropriate copyright notice and a 107 | notice that there is no warranty (or else, saying that you provide 108 | a warranty) and that users may redistribute the program under 109 | these conditions, and telling the user how to view a copy of this 110 | License. (Exception: if the Program itself is interactive but 111 | does not normally print such an announcement, your work based on 112 | the Program is not required to print an announcement.) 113 | 114 | These requirements apply to the modified work as a whole. If 115 | identifiable sections of that work are not derived from the Program, 116 | and can be reasonably considered independent and separate works in 117 | themselves, then this License, and its terms, do not apply to those 118 | sections when you distribute them as separate works. But when you 119 | distribute the same sections as part of a whole which is a work based 120 | on the Program, the distribution of the whole must be on the terms of 121 | this License, whose permissions for other licensees extend to the 122 | entire whole, and thus to each and every part regardless of who wrote it. 123 | 124 | Thus, it is not the intent of this section to claim rights or contest 125 | your rights to work written entirely by you; rather, the intent is to 126 | exercise the right to control the distribution of derivative or 127 | collective works based on the Program. 128 | 129 | In addition, mere aggregation of another work not based on the Program 130 | with the Program (or with a work based on the Program) on a volume of 131 | a storage or distribution medium does not bring the other work under 132 | the scope of this License. 133 | 134 | 3. You may copy and distribute the Program (or a work based on it, 135 | under Section 2) in object code or executable form under the terms of 136 | Sections 1 and 2 above provided that you also do one of the following: 137 | 138 | a) Accompany it with the complete corresponding machine-readable 139 | source code, which must be distributed under the terms of Sections 140 | 1 and 2 above on a medium customarily used for software interchange; or, 141 | 142 | b) Accompany it with a written offer, valid for at least three 143 | years, to give any third party, for a charge no more than your 144 | cost of physically performing source distribution, a complete 145 | machine-readable copy of the corresponding source code, to be 146 | distributed under the terms of Sections 1 and 2 above on a medium 147 | customarily used for software interchange; or, 148 | 149 | c) Accompany it with the information you received as to the offer 150 | to distribute corresponding source code. (This alternative is 151 | allowed only for noncommercial distribution and only if you 152 | received the program in object code or executable form with such 153 | an offer, in accord with Subsection b above.) 154 | 155 | The source code for a work means the preferred form of the work for 156 | making modifications to it. For an executable work, complete source 157 | code means all the source code for all modules it contains, plus any 158 | associated interface definition files, plus the scripts used to 159 | control compilation and installation of the executable. However, as a 160 | special exception, the source code distributed need not include 161 | anything that is normally distributed (in either source or binary 162 | form) with the major components (compiler, kernel, and so on) of the 163 | operating system on which the executable runs, unless that component 164 | itself accompanies the executable. 165 | 166 | If distribution of executable or object code is made by offering 167 | access to copy from a designated place, then offering equivalent 168 | access to copy the source code from the same place counts as 169 | distribution of the source code, even though third parties are not 170 | compelled to copy the source along with the object code. 171 | 172 | 4. You may not copy, modify, sublicense, or distribute the Program 173 | except as expressly provided under this License. Any attempt 174 | otherwise to copy, modify, sublicense or distribute the Program is 175 | void, and will automatically terminate your rights under this License. 176 | However, parties who have received copies, or rights, from you under 177 | this License will not have their licenses terminated so long as such 178 | parties remain in full compliance. 179 | 180 | 5. You are not required to accept this License, since you have not 181 | signed it. However, nothing else grants you permission to modify or 182 | distribute the Program or its derivative works. These actions are 183 | prohibited by law if you do not accept this License. Therefore, by 184 | modifying or distributing the Program (or any work based on the 185 | Program), you indicate your acceptance of this License to do so, and 186 | all its terms and conditions for copying, distributing or modifying 187 | the Program or works based on it. 188 | 189 | 6. Each time you redistribute the Program (or any work based on the 190 | Program), the recipient automatically receives a license from the 191 | original licensor to copy, distribute or modify the Program subject to 192 | these terms and conditions. You may not impose any further 193 | restrictions on the recipients' exercise of the rights granted herein. 194 | You are not responsible for enforcing compliance by third parties to 195 | this License. 196 | 197 | 7. If, as a consequence of a court judgment or allegation of patent 198 | infringement or for any other reason (not limited to patent issues), 199 | conditions are imposed on you (whether by court order, agreement or 200 | otherwise) that contradict the conditions of this License, they do not 201 | excuse you from the conditions of this License. If you cannot 202 | distribute so as to satisfy simultaneously your obligations under this 203 | License and any other pertinent obligations, then as a consequence you 204 | may not distribute the Program at all. For example, if a patent 205 | license would not permit royalty-free redistribution of the Program by 206 | all those who receive copies directly or indirectly through you, then 207 | the only way you could satisfy both it and this License would be to 208 | refrain entirely from distribution of the Program. 209 | 210 | If any portion of this section is held invalid or unenforceable under 211 | any particular circumstance, the balance of the section is intended to 212 | apply and the section as a whole is intended to apply in other 213 | circumstances. 214 | 215 | It is not the purpose of this section to induce you to infringe any 216 | patents or other property right claims or to contest validity of any 217 | such claims; this section has the sole purpose of protecting the 218 | integrity of the free software distribution system, which is 219 | implemented by public license practices. Many people have made 220 | generous contributions to the wide range of software distributed 221 | through that system in reliance on consistent application of that 222 | system; it is up to the author/donor to decide if he or she is willing 223 | to distribute software through any other system and a licensee cannot 224 | impose that choice. 225 | 226 | This section is intended to make thoroughly clear what is believed to 227 | be a consequence of the rest of this License. 228 | 229 | 8. If the distribution and/or use of the Program is restricted in 230 | certain countries either by patents or by copyrighted interfaces, the 231 | original copyright holder who places the Program under this License 232 | may add an explicit geographical distribution limitation excluding 233 | those countries, so that distribution is permitted only in or among 234 | countries not thus excluded. In such case, this License incorporates 235 | the limitation as if written in the body of this License. 236 | 237 | 9. The Free Software Foundation may publish revised and/or new versions 238 | of the General Public License from time to time. Such new versions will 239 | be similar in spirit to the present version, but may differ in detail to 240 | address new problems or concerns. 241 | 242 | Each version is given a distinguishing version number. If the Program 243 | specifies a version number of this License which applies to it and "any 244 | later version", you have the option of following the terms and conditions 245 | either of that version or of any later version published by the Free 246 | Software Foundation. If the Program does not specify a version number of 247 | this License, you may choose any version ever published by the Free Software 248 | Foundation. 249 | 250 | 10. If you wish to incorporate parts of the Program into other free 251 | programs whose distribution conditions are different, write to the author 252 | to ask for permission. For software which is copyrighted by the Free 253 | Software Foundation, write to the Free Software Foundation; we sometimes 254 | make exceptions for this. Our decision will be guided by the two goals 255 | of preserving the free status of all derivatives of our free software and 256 | of promoting the sharing and reuse of software generally. 257 | 258 | NO WARRANTY 259 | 260 | 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY 261 | FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN 262 | OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 263 | PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED 264 | OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 265 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS 266 | TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE 267 | PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, 268 | REPAIR OR CORRECTION. 269 | 270 | 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 271 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR 272 | REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 273 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING 274 | OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED 275 | TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY 276 | YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER 277 | PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE 278 | POSSIBILITY OF SUCH DAMAGES. 279 | 280 | END OF TERMS AND CONDITIONS 281 | 282 | How to Apply These Terms to Your New Programs 283 | 284 | If you develop a new program, and you want it to be of the greatest 285 | possible use to the public, the best way to achieve this is to make it 286 | free software which everyone can redistribute and change under these terms. 287 | 288 | To do so, attach the following notices to the program. It is safest 289 | to attach them to the start of each source file to most effectively 290 | convey the exclusion of warranty; and each file should have at least 291 | the "copyright" line and a pointer to where the full notice is found. 292 | 293 | 294 | Copyright (C) 295 | 296 | This program is free software; you can redistribute it and/or modify 297 | it under the terms of the GNU General Public License as published by 298 | the Free Software Foundation; either version 2 of the License, or 299 | (at your option) any later version. 300 | 301 | This program is distributed in the hope that it will be useful, 302 | but WITHOUT ANY WARRANTY; without even the implied warranty of 303 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 304 | GNU General Public License for more details. 305 | 306 | You should have received a copy of the GNU General Public License 307 | along with this program; if not, write to the Free Software 308 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 309 | 310 | 311 | Also add information on how to contact you by electronic and paper mail. 312 | 313 | If the program is interactive, make it output a short notice like this 314 | when it starts in an interactive mode: 315 | 316 | Gnomovision version 69, Copyright (C) year name of author 317 | Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 318 | This is free software, and you are welcome to redistribute it 319 | under certain conditions; type `show c' for details. 320 | 321 | The hypothetical commands `show w' and `show c' should show the appropriate 322 | parts of the General Public License. Of course, the commands you use may 323 | be called something other than `show w' and `show c'; they could even be 324 | mouse-clicks or menu items--whatever suits your program. 325 | 326 | You should also get your employer (if you work as a programmer) or your 327 | school, if any, to sign a "copyright disclaimer" for the program, if 328 | necessary. Here is a sample; alter the names: 329 | 330 | Yoyodyne, Inc., hereby disclaims all copyright interest in the program 331 | `Gnomovision' (which makes passes at compilers) written by James Hacker. 332 | 333 | , 1 April 1989 334 | Ty Coon, President of Vice 335 | 336 | This General Public License does not permit incorporating your program into 337 | proprietary programs. If your program is a subroutine library, you may 338 | consider it more useful to permit linking proprietary applications with the 339 | library. If this is what you want to do, use the GNU Library General 340 | Public License instead of this License. -------------------------------------------------------------------------------- /RealtekRTL8111/APPLE_LICENSE: -------------------------------------------------------------------------------- 1 | APPLE PUBLIC SOURCE LICENSE 2 | Version 2.0 - August 6, 2003 3 | 4 | Please read this License carefully before downloading this software. By 5 | downloading or using this software, you are agreeing to be bound by the terms 6 | of this License. If you do not or cannot agree to the terms of this License, 7 | please do not download or use the software. 8 | 9 | Apple Note: In January 2007, Apple changed its corporate name from "Apple 10 | Computer, Inc." to "Apple Inc." This change has been reflected below and 11 | copyright years updated, but no other changes have been made to the APSL 2.0. 12 | 13 | 1. General; Definitions. This License applies to any program or other 14 | work which Apple Inc. ("Apple") makes publicly available and which contains a 15 | notice placed by Apple identifying such program or work as "Original Code" and 16 | stating that it is subject to the terms of this Apple Public Source License 17 | version 2.0 ("License"). As used in this License: 18 | 19 | 1.1 "Applicable Patent Rights" mean: (a) in the case where Apple is the 20 | grantor of rights, (i) claims of patents that are now or hereafter acquired, 21 | owned by or assigned to Apple and (ii) that cover subject matter contained in 22 | the Original Code, but only to the extent necessary to use, reproduce and/or 23 | distribute the Original Code without infringement; and (b) in the case where 24 | You are the grantor of rights, (i) claims of patents that are now or hereafter 25 | acquired, owned by or assigned to You and (ii) that cover subject matter in 26 | Your Modifications, taken alone or in combination with Original Code. 27 | 28 | 1.2 "Contributor" means any person or entity that creates or contributes to 29 | the creation of Modifications. 30 | 31 | 1.3 "Covered Code" means the Original Code, Modifications, the combination 32 | of Original Code and any Modifications, and/or any respective portions thereof. 33 | 34 | 1.4 "Externally Deploy" means: (a) to sublicense, distribute or otherwise 35 | make Covered Code available, directly or indirectly, to anyone other than You; 36 | and/or (b) to use Covered Code, alone or as part of a Larger Work, in any way 37 | to provide a service, including but not limited to delivery of content, through 38 | electronic communication with a client other than You. 39 | 40 | 1.5 "Larger Work" means a work which combines Covered Code or portions 41 | thereof with code not governed by the terms of this License. 42 | 43 | 1.6 "Modifications" mean any addition to, deletion from, and/or change to, 44 | the substance and/or structure of the Original Code, any previous 45 | Modifications, the combination of Original Code and any previous Modifications, 46 | and/or any respective portions thereof. When code is released as a series of 47 | files, a Modification is: (a) any addition to or deletion from the contents of 48 | a file containing Covered Code; and/or (b) any new file or other representation 49 | of computer program statements that contains any part of Covered Code. 50 | 51 | 1.7 "Original Code" means (a) the Source Code of a program or other work as 52 | originally made available by Apple under this License, including the Source 53 | Code of any updates or upgrades to such programs or works made available by 54 | Apple under this License, and that has been expressly identified by Apple as 55 | such in the header file(s) of such work; and (b) the object code compiled from 56 | such Source Code and originally made available by Apple under this License 57 | 58 | 1.8 "Source Code" means the human readable form of a program or other work 59 | that is suitable for making modifications to it, including all modules it 60 | contains, plus any associated interface definition files, scripts used to 61 | control compilation and installation of an executable (object code). 62 | 63 | 1.9 "You" or "Your" means an individual or a legal entity exercising rights 64 | under this License. For legal entities, "You" or "Your" includes any entity 65 | which controls, is controlled by, or is under common control with, You, where 66 | "control" means (a) the power, direct or indirect, to cause the direction or 67 | management of such entity, whether by contract or otherwise, or (b) ownership 68 | of fifty percent (50%) or more of the outstanding shares or beneficial 69 | ownership of such entity. 70 | 71 | 2. Permitted Uses; Conditions & Restrictions. Subject to the terms and 72 | conditions of this License, Apple hereby grants You, effective on the date You 73 | accept this License and download the Original Code, a world-wide, royalty-free, 74 | non-exclusive license, to the extent of Apple's Applicable Patent Rights and 75 | copyrights covering the Original Code, to do the following: 76 | 77 | 2.1 Unmodified Code. You may use, reproduce, display, perform, internally 78 | distribute within Your organization, and Externally Deploy verbatim, unmodified 79 | copies of the Original Code, for commercial or non-commercial purposes, 80 | provided that in each instance: 81 | 82 | (a) You must retain and reproduce in all copies of Original Code the 83 | copyright and other proprietary notices and disclaimers of Apple as they appear 84 | in the Original Code, and keep intact all notices in the Original Code that 85 | refer to this License; and 86 | 87 | (b) You must include a copy of this License with every copy of Source Code 88 | of Covered Code and documentation You distribute or Externally Deploy, and You 89 | may not offer or impose any terms on such Source Code that alter or restrict 90 | this License or the recipients' rights hereunder, except as permitted under 91 | Section 6. 92 | 93 | 2.2 Modified Code. You may modify Covered Code and use, reproduce, 94 | display, perform, internally distribute within Your organization, and 95 | Externally Deploy Your Modifications and Covered Code, for commercial or 96 | non-commercial purposes, provided that in each instance You also meet all of 97 | these conditions: 98 | 99 | (a) You must satisfy all the conditions of Section 2.1 with respect to the 100 | Source Code of the Covered Code; 101 | 102 | (b) You must duplicate, to the extent it does not already exist, the notice 103 | in Exhibit A in each file of the Source Code of all Your Modifications, and 104 | cause the modified files to carry prominent notices stating that You changed 105 | the files and the date of any change; and 106 | 107 | (c) If You Externally Deploy Your Modifications, You must make Source Code 108 | of all Your Externally Deployed Modifications either available to those to whom 109 | You have Externally Deployed Your Modifications, or publicly available. Source 110 | Code of Your Externally Deployed Modifications must be released under the terms 111 | set forth in this License, including the license grants set forth in Section 3 112 | below, for as long as you Externally Deploy the Covered Code or twelve (12) 113 | months from the date of initial External Deployment, whichever is longer. You 114 | should preferably distribute the Source Code of Your Externally Deployed 115 | Modifications electronically (e.g. download from a web site). 116 | 117 | 2.3 Distribution of Executable Versions. In addition, if You Externally 118 | Deploy Covered Code (Original Code and/or Modifications) in object code, 119 | executable form only, You must include a prominent notice, in the code itself 120 | as well as in related documentation, stating that Source Code of the Covered 121 | Code is available under the terms of this License with information on how and 122 | where to obtain such Source Code. 123 | 124 | 2.4 Third Party Rights. You expressly acknowledge and agree that although 125 | Apple and each Contributor grants the licenses to their respective portions of 126 | the Covered Code set forth herein, no assurances are provided by Apple or any 127 | Contributor that the Covered Code does not infringe the patent or other 128 | intellectual property rights of any other entity. Apple and each Contributor 129 | disclaim any liability to You for claims brought by any other entity based on 130 | infringement of intellectual property rights or otherwise. As a condition to 131 | exercising the rights and licenses granted hereunder, You hereby assume sole 132 | responsibility to secure any other intellectual property rights needed, if any. 133 | For example, if a third party patent license is required to allow You to 134 | distribute the Covered Code, it is Your responsibility to acquire that license 135 | before distributing the Covered Code. 136 | 137 | 3. Your Grants. In consideration of, and as a condition to, the licenses 138 | granted to You under this License, You hereby grant to any person or entity 139 | receiving or distributing Covered Code under this License a non-exclusive, 140 | royalty-free, perpetual, irrevocable license, under Your Applicable Patent 141 | Rights and other intellectual property rights (other than patent) owned or 142 | controlled by You, to use, reproduce, display, perform, modify, sublicense, 143 | distribute and Externally Deploy Your Modifications of the same scope and 144 | extent as Apple's licenses under Sections 2.1 and 2.2 above. 145 | 146 | 4. Larger Works. You may create a Larger Work by combining Covered Code 147 | with other code not governed by the terms of this License and distribute the 148 | Larger Work as a single product. In each such instance, You must make sure the 149 | requirements of this License are fulfilled for the Covered Code or any portion 150 | thereof. 151 | 152 | 5. Limitations on Patent License. Except as expressly stated in Section 153 | 2, no other patent rights, express or implied, are granted by Apple herein. 154 | Modifications and/or Larger Works may require additional patent licenses from 155 | Apple which Apple may grant in its sole discretion. 156 | 157 | 6. Additional Terms. You may choose to offer, and to charge a fee for, 158 | warranty, support, indemnity or liability obligations and/or other rights 159 | consistent with the scope of the license granted herein ("Additional Terms") to 160 | one or more recipients of Covered Code. However, You may do so only on Your own 161 | behalf and as Your sole responsibility, and not on behalf of Apple or any 162 | Contributor. You must obtain the recipient's agreement that any such Additional 163 | Terms are offered by You alone, and You hereby agree to indemnify, defend and 164 | hold Apple and every Contributor harmless for any liability incurred by or 165 | claims asserted against Apple or such Contributor by reason of any such 166 | Additional Terms. 167 | 168 | 7. Versions of the License. Apple may publish revised and/or new versions 169 | of this License from time to time. Each version will be given a distinguishing 170 | version number. Once Original Code has been published under a particular 171 | version of this License, You may continue to use it under the terms of that 172 | version. You may also choose to use such Original Code under the terms of any 173 | subsequent version of this License published by Apple. No one other than Apple 174 | has the right to modify the terms applicable to Covered Code created under this 175 | License. 176 | 177 | 8. NO WARRANTY OR SUPPORT. The Covered Code may contain in whole or in 178 | part pre-release, untested, or not fully tested works. The Covered Code may 179 | contain errors that could cause failures or loss of data, and may be incomplete 180 | or contain inaccuracies. You expressly acknowledge and agree that use of the 181 | Covered Code, or any portion thereof, is at Your sole and entire risk. THE 182 | COVERED CODE IS PROVIDED "AS IS" AND WITHOUT WARRANTY, UPGRADES OR SUPPORT OF 183 | ANY KIND AND APPLE AND APPLE'S LICENSOR(S) (COLLECTIVELY REFERRED TO AS "APPLE" 184 | FOR THE PURPOSES OF SECTIONS 8 AND 9) AND ALL CONTRIBUTORS EXPRESSLY DISCLAIM 185 | ALL WARRANTIES AND/OR CONDITIONS, EXPRESS OR IMPLIED, INCLUDING, BUT NOT 186 | LIMITED TO, THE IMPLIED WARRANTIES AND/OR CONDITIONS OF MERCHANTABILITY, OF 187 | SATISFACTORY QUALITY, OF FITNESS FOR A PARTICULAR PURPOSE, OF ACCURACY, OF 188 | QUIET ENJOYMENT, AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. APPLE AND EACH 189 | CONTRIBUTOR DOES NOT WARRANT AGAINST INTERFERENCE WITH YOUR ENJOYMENT OF THE 190 | COVERED CODE, THAT THE FUNCTIONS CONTAINED IN THE COVERED CODE WILL MEET YOUR 191 | REQUIREMENTS, THAT THE OPERATION OF THE COVERED CODE WILL BE UNINTERRUPTED OR 192 | ERROR-FREE, OR THAT DEFECTS IN THE COVERED CODE WILL BE CORRECTED. NO ORAL OR 193 | WRITTEN INFORMATION OR ADVICE GIVEN BY APPLE, AN APPLE AUTHORIZED 194 | REPRESENTATIVE OR ANY CONTRIBUTOR SHALL CREATE A WARRANTY. You acknowledge 195 | that the Covered Code is not intended for use in the operation of nuclear 196 | facilities, aircraft navigation, communication systems, or air traffic control 197 | machines in which case the failure of the Covered Code could lead to death, 198 | personal injury, or severe physical or environmental damage. 199 | 200 | 9. LIMITATION OF LIABILITY. TO THE EXTENT NOT PROHIBITED BY LAW, IN NO 201 | EVENT SHALL APPLE OR ANY CONTRIBUTOR BE LIABLE FOR ANY INCIDENTAL, SPECIAL, 202 | INDIRECT OR CONSEQUENTIAL DAMAGES ARISING OUT OF OR RELATING TO THIS LICENSE OR 203 | YOUR USE OR INABILITY TO USE THE COVERED CODE, OR ANY PORTION THEREOF, WHETHER 204 | UNDER A THEORY OF CONTRACT, WARRANTY, TORT (INCLUDING NEGLIGENCE), PRODUCTS 205 | LIABILITY OR OTHERWISE, EVEN IF APPLE OR SUCH CONTRIBUTOR HAS BEEN ADVISED OF 206 | THE POSSIBILITY OF SUCH DAMAGES AND NOTWITHSTANDING THE FAILURE OF ESSENTIAL 207 | PURPOSE OF ANY REMEDY. SOME JURISDICTIONS DO NOT ALLOW THE LIMITATION OF 208 | LIABILITY OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS LIMITATION MAY NOT 209 | APPLY TO YOU. In no event shall Apple's total liability to You for all damages 210 | (other than as may be required by applicable law) under this License exceed the 211 | amount of fifty dollars ($50.00). 212 | 213 | 10. Trademarks. This License does not grant any rights to use the 214 | trademarks or trade names "Apple", "Mac", "Mac OS", "QuickTime", "QuickTime 215 | Streaming Server" or any other trademarks, service marks, logos or trade names 216 | belonging to Apple (collectively "Apple Marks") or to any trademark, service 217 | mark, logo or trade name belonging to any Contributor. You agree not to use 218 | any Apple Marks in or as part of the name of products derived from the Original 219 | Code or to endorse or promote products derived from the Original Code other 220 | than as expressly permitted by and in strict compliance at all times with 221 | Apple's third party trademark usage guidelines which are posted at 222 | http://www.apple.com/legal/guidelinesfor3rdparties.html. 223 | 224 | 11. Ownership. Subject to the licenses granted under this License, each 225 | Contributor retains all rights, title and interest in and to any Modifications 226 | made by such Contributor. Apple retains all rights, title and interest in and 227 | to the Original Code and any Modifications made by or on behalf of Apple 228 | ("Apple Modifications"), and such Apple Modifications will not be automatically 229 | subject to this License. Apple may, at its sole discretion, choose to license 230 | such Apple Modifications under this License, or on different terms from those 231 | contained in this License or may choose not to license them at all. 232 | 233 | 12. Termination. 234 | 235 | 12.1 Termination. This License and the rights granted hereunder will 236 | terminate: 237 | 238 | (a) automatically without notice from Apple if You fail to comply with any 239 | term(s) of this License and fail to cure such breach within 30 days of becoming 240 | aware of such breach; 241 | (b) immediately in the event of the circumstances described in Section 242 | 13.5(b); or 243 | (c) automatically without notice from Apple if You, at any time during the 244 | term of this License, commence an action for patent infringement against Apple; 245 | provided that Apple did not first commence an action for patent infringement 246 | against You in that instance. 247 | 248 | 12.2 Effect of Termination. Upon termination, You agree to immediately stop 249 | any further use, reproduction, modification, sublicensing and distribution of 250 | the Covered Code. All sublicenses to the Covered Code which have been properly 251 | granted prior to termination shall survive any termination of this License. 252 | Provisions which, by their nature, should remain in effect beyond the 253 | termination of this License shall survive, including but not limited to 254 | Sections 3, 5, 8, 9, 10, 11, 12.2 and 13. No party will be liable to any other 255 | for compensation, indemnity or damages of any sort solely as a result of 256 | terminating this License in accordance with its terms, and termination of this 257 | License will be without prejudice to any other right or remedy of any party. 258 | 259 | 13. Miscellaneous. 260 | 261 | 13.1 Government End Users. The Covered Code is a "commercial item" as 262 | defined in FAR 2.101. Government software and technical data rights in the 263 | Covered Code include only those rights customarily provided to the public as 264 | defined in this License. This customary commercial license in technical data 265 | and software is provided in accordance with FAR 12.211 (Technical Data) and 266 | 12.212 (Computer Software) and, for Department of Defense purchases, DFAR 267 | 252.227-7015 (Technical Data -- Commercial Items) and 227.7202-3 (Rights in 268 | Commercial Computer Software or Computer Software Documentation). Accordingly, 269 | all U.S. Government End Users acquire Covered Code with only those rights set 270 | forth herein. 271 | 272 | 13.2 Relationship of Parties. This License will not be construed as 273 | creating an agency, partnership, joint venture or any other form of legal 274 | association between or among You, Apple or any Contributor, and You will not 275 | represent to the contrary, whether expressly, by implication, appearance or 276 | otherwise. 277 | 278 | 13.3 Independent Development. Nothing in this License will impair Apple's 279 | right to acquire, license, develop, have others develop for it, market and/or 280 | distribute technology or products that perform the same or similar functions 281 | as, or otherwise compete with, Modifications, Larger Works, technology or 282 | products that You may develop, produce, market or distribute. 283 | 284 | 13.4 Waiver; Construction. Failure by Apple or any Contributor to enforce 285 | any provision of this License will not be deemed a waiver of future enforcement 286 | of that or any other provision. Any law or regulation which provides that the 287 | language of a contract shall be construed against the drafter will not apply to 288 | this License. 289 | 290 | 13.5 Severability. (a) If for any reason a court of competent jurisdiction 291 | finds any provision of this License, or portion thereof, to be unenforceable, 292 | that provision of the License will be enforced to the maximum extent 293 | permissible so as to effect the economic benefits and intent of the parties, 294 | and the remainder of this License will continue in full force and effect. (b) 295 | Notwithstanding the foregoing, if applicable law prohibits or restricts You 296 | from fully and/or specifically complying with Sections 2 and/or 3 or prevents 297 | the enforceability of either of those Sections, this License will immediately 298 | terminate and You must immediately discontinue any use of the Covered Code and 299 | destroy all copies of it that are in your possession or control. 300 | 301 | 13.6 Dispute Resolution. Any litigation or other dispute resolution between 302 | You and Apple relating to this License shall take place in the Northern 303 | District of California, and You and Apple hereby consent to the personal 304 | jurisdiction of, and venue in, the state and federal courts within that 305 | District with respect to this License. The application of the United Nations 306 | Convention on Contracts for the International Sale of Goods is expressly 307 | excluded. 308 | 309 | 13.7 Entire Agreement; Governing Law. This License constitutes the entire 310 | agreement between the parties with respect to the subject matter hereof. This 311 | License shall be governed by the laws of the United States and the State of 312 | California, except that body of California law concerning conflicts of law. 313 | 314 | Where You are located in the province of Quebec, Canada, the following clause 315 | applies: The parties hereby confirm that they have requested that this License 316 | and all related documents be drafted in English. Les parties ont exigé que le 317 | présent contrat et tous les documents connexes soient rédigés en anglais. 318 | 319 | EXHIBIT A. 320 | 321 | "Portions Copyright (c) 1999-2007 Apple Inc. All Rights Reserved. 322 | 323 | This file contains Original Code and/or Modifications of Original Code as 324 | defined in and that are subject to the Apple Public Source License Version 2.0 325 | (the 'License'). You may not use this file except in compliance with the 326 | License. Please obtain a copy of the License at 327 | http://www.opensource.apple.com/apsl/ and read it before using this file. 328 | 329 | The Original Code and all software distributed under the License are 330 | distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS 331 | OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING WITHOUT 332 | LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 333 | PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. Please see the License for the 334 | specific language governing rights and limitations under the License." 335 | 336 | -------------------------------------------------------------------------------- /RealtekRTL8111/RealtekRTL8111Setup.cpp: -------------------------------------------------------------------------------- 1 | // 2 | // RealtekRTL8111Setup.cpp 3 | // RealtekRTL8111 4 | // 5 | // Created by Laura Müller on 26.01.25. 6 | // Copyright © 2025 Laura Müller. All rights reserved. 7 | // 8 | 9 | #include "RealtekRTL8111.hpp" 10 | 11 | #pragma mark --- data structure initialization methods --- 12 | 13 | static const char *onName = "enabled"; 14 | static const char *offName = "disabled"; 15 | 16 | void RTL8111::getParams() 17 | { 18 | OSDictionary *params; 19 | OSIterator *iterator; 20 | OSBoolean *enableEEE; 21 | OSBoolean *tso4; 22 | OSBoolean *tso6; 23 | OSBoolean *csoV6; 24 | OSBoolean *noASPM; 25 | OSString *versionString; 26 | OSString *fbAddr; 27 | 28 | if (version_major >= Tahoe) { 29 | params = serviceMatching("AppleVTD"); 30 | 31 | if (params) { 32 | iterator = IOService::getMatchingServices(params); 33 | 34 | if (iterator) { 35 | IOMapper *mp = OSDynamicCast(IOMapper, iterator->getNextObject()); 36 | 37 | if (mp) { 38 | IOLog("AppleVTD is enabled."); 39 | useAppleVTD = true; 40 | } 41 | iterator->release(); 42 | } 43 | params->release(); 44 | } 45 | } 46 | versionString = OSDynamicCast(OSString, getProperty(kDriverVersionName)); 47 | 48 | params = OSDynamicCast(OSDictionary, getProperty(kParamName)); 49 | 50 | if (params) { 51 | noASPM = OSDynamicCast(OSBoolean, params->getObject(kDisableASPMName)); 52 | disableASPM = (noASPM != NULL) ? noASPM->getValue() : false; 53 | 54 | DebugLog("PCIe ASPM support %s.\n", disableASPM ? offName : onName); 55 | 56 | enableEEE = OSDynamicCast(OSBoolean, params->getObject(kEnableEeeName)); 57 | 58 | if (enableEEE != NULL) 59 | linuxData.eee_enabled = (enableEEE->getValue()) ? 1 : 0; 60 | else 61 | linuxData.eee_enabled = 0; 62 | 63 | IOLog("EEE support %s.\n", linuxData.eee_enabled ? onName : offName); 64 | 65 | tso4 = OSDynamicCast(OSBoolean, params->getObject(kEnableTSO4Name)); 66 | enableTSO4 = (tso4 != NULL) ? tso4->getValue() : false; 67 | 68 | IOLog("TCP/IPv4 segmentation offload %s.\n", enableTSO4 ? onName : offName); 69 | 70 | tso6 = OSDynamicCast(OSBoolean, params->getObject(kEnableTSO6Name)); 71 | enableTSO6 = (tso6 != NULL) ? tso6->getValue() : false; 72 | 73 | IOLog("TCP/IPv6 segmentation offload %s.\n", enableTSO6 ? onName : offName); 74 | 75 | csoV6 = OSDynamicCast(OSBoolean, params->getObject(kEnableCSO6Name)); 76 | enableCSO6 = (csoV6 != NULL) ? csoV6->getValue() : false; 77 | 78 | IOLog("TCP/IPv6 checksum offload %s.\n", enableCSO6 ? onName : offName); 79 | 80 | fbAddr = OSDynamicCast(OSString, params->getObject(kFallbackName)); 81 | 82 | if (fbAddr) { 83 | const char *s = fbAddr->getCStringNoCopy(); 84 | UInt8 *addr = fallBackMacAddr.bytes; 85 | 86 | if (fbAddr->getLength()) { 87 | sscanf(s, "%2hhx:%2hhx:%2hhx:%2hhx:%2hhx:%2hhx", &addr[0], &addr[1], &addr[2], &addr[3], &addr[4], &addr[5]); 88 | 89 | IOLog("Fallback MAC: %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n", 90 | fallBackMacAddr.bytes[0], fallBackMacAddr.bytes[1], 91 | fallBackMacAddr.bytes[2], fallBackMacAddr.bytes[3], 92 | fallBackMacAddr.bytes[4], fallBackMacAddr.bytes[5]); 93 | } 94 | } 95 | } else { 96 | disableASPM = true; 97 | linuxData.eee_enabled = 1; 98 | enableTSO4 = true; 99 | enableTSO6 = true; 100 | intrMitigateValue = 0x5f51; 101 | } 102 | if (versionString) 103 | IOLog("Version %s using interrupt mitigate value 0x%x. Please don't support tonymacx86.com!\n", versionString->getCStringNoCopy(), intrMitigateValue); 104 | else 105 | IOLog("Using interrupt mitigate value 0x%x. Please don't support tonymacx86.com!\n", intrMitigateValue); 106 | } 107 | 108 | static IOMediumType mediumTypeArray[MEDIUM_INDEX_COUNT] = { 109 | kIOMediumEthernetAuto, 110 | (kIOMediumEthernet10BaseT | IFM_HDX), 111 | (kIOMediumEthernet10BaseT | IFM_FDX), 112 | (kIOMediumEthernet100BaseTX | IFM_HDX), 113 | (kIOMediumEthernet100BaseTX | IFM_FDX), 114 | (kIOMediumEthernet100BaseTX | IFM_FDX | IFM_FLOW), 115 | (kIOMediumEthernet1000BaseT | IFM_FDX), 116 | (kIOMediumEthernet1000BaseT | IFM_FDX | IFM_FLOW), 117 | (kIOMediumEthernet100BaseTX | IFM_FDX | IFM_EEE), 118 | (kIOMediumEthernet100BaseTX | IFM_FDX | IFM_FLOW | IFM_EEE), 119 | (kIOMediumEthernet1000BaseT | IFM_FDX | IFM_EEE), 120 | (kIOMediumEthernet1000BaseT | IFM_FDX | IFM_FLOW | IFM_EEE) 121 | }; 122 | 123 | static UInt32 mediumSpeedArray[MEDIUM_INDEX_COUNT] = { 124 | 0, 125 | 10 * MBit, 126 | 10 * MBit, 127 | 100 * MBit, 128 | 100 * MBit, 129 | 100 * MBit, 130 | 1000 * MBit, 131 | 1000 * MBit, 132 | 100 * MBit, 133 | 100 * MBit, 134 | 1000 * MBit, 135 | 1000 * MBit 136 | }; 137 | 138 | bool RTL8111::setupMediumDict() 139 | { 140 | IONetworkMedium *medium; 141 | UInt32 i, n; 142 | bool result = false; 143 | 144 | n = eeeCap ? MEDIUM_INDEX_COUNT : MEDIUM_INDEX_COUNT - 4; 145 | mediumDict = OSDictionary::withCapacity(n + 1); 146 | 147 | if (mediumDict) { 148 | for (i = MEDIUM_INDEX_AUTO; i < n; i++) { 149 | medium = IONetworkMedium::medium(mediumTypeArray[i], mediumSpeedArray[i], 0, i); 150 | 151 | if (!medium) 152 | goto error1; 153 | 154 | result = IONetworkMedium::addMedium(mediumDict, medium); 155 | medium->release(); 156 | 157 | if (!result) 158 | goto error1; 159 | 160 | mediumTable[i] = medium; 161 | } 162 | } 163 | result = publishMediumDictionary(mediumDict); 164 | 165 | if (!result) 166 | goto error1; 167 | 168 | done: 169 | return result; 170 | 171 | error1: 172 | IOLog("Error creating medium dictionary.\n"); 173 | mediumDict->release(); 174 | 175 | for (i = MEDIUM_INDEX_AUTO; i < MEDIUM_INDEX_COUNT; i++) 176 | mediumTable[i] = NULL; 177 | 178 | goto done; 179 | } 180 | 181 | bool RTL8111::initEventSources(IOService *provider) 182 | { 183 | int msiIndex = -1; 184 | int intrIndex = 0; 185 | int intrType = 0; 186 | bool result = false; 187 | 188 | txQueue = reinterpret_cast(getOutputQueue()); 189 | 190 | if (txQueue == NULL) { 191 | IOLog("Failed to get output queue.\n"); 192 | goto done; 193 | } 194 | txQueue->retain(); 195 | 196 | while (pciDevice->getInterruptType(intrIndex, &intrType) == kIOReturnSuccess) { 197 | if (intrType & kIOInterruptTypePCIMessaged){ 198 | msiIndex = intrIndex; 199 | break; 200 | } 201 | intrIndex++; 202 | } 203 | if (msiIndex != -1) { 204 | DebugLog("MSI interrupt index: %d\n", msiIndex); 205 | 206 | if (useAppleVTD) { 207 | interruptSource = IOInterruptEventSource::interruptEventSource(this, OSMemberFunctionCast(IOInterruptEventSource::Action, this, &RTL8111::interruptOccurredVTD), provider, msiIndex); 208 | } else { 209 | interruptSource = IOInterruptEventSource::interruptEventSource(this, OSMemberFunctionCast(IOInterruptEventSource::Action, this, &RTL8111::interruptOccurredPoll), provider, msiIndex); 210 | } 211 | } 212 | if (!interruptSource) { 213 | IOLog("Error: MSI index was not found or MSI interrupt could not be enabled.\n"); 214 | goto error1; 215 | } 216 | workLoop->addEventSource(interruptSource); 217 | 218 | if (revisionC) 219 | timerSource = IOTimerEventSource::timerEventSource(this, OSMemberFunctionCast(IOTimerEventSource::Action, this, &RTL8111::timerActionRTL8111C)); 220 | else 221 | timerSource = IOTimerEventSource::timerEventSource(this, OSMemberFunctionCast(IOTimerEventSource::Action, this, &RTL8111::timerActionRTL8111B)); 222 | 223 | if (!timerSource) { 224 | IOLog("Failed to create IOTimerEventSource.\n"); 225 | goto error2; 226 | } 227 | workLoop->addEventSource(timerSource); 228 | 229 | result = true; 230 | 231 | done: 232 | return result; 233 | 234 | error2: 235 | workLoop->removeEventSource(interruptSource); 236 | RELEASE(interruptSource); 237 | 238 | error1: 239 | IOLog("Error initializing event sources.\n"); 240 | txQueue->release(); 241 | txQueue = NULL; 242 | goto done; 243 | } 244 | 245 | bool RTL8111::setupRxResources() 246 | { 247 | IOPhysicalAddress64 pa = 0; 248 | IODMACommand::Segment64 seg; 249 | mbuf_t m; 250 | UInt64 offset = 0; 251 | UInt64 word1; 252 | UInt32 numSegs = 1; 253 | UInt32 i; 254 | bool result = false; 255 | 256 | /* Alloc rx mbuf_t array. */ 257 | rxBufArrayMem = IOMallocZero(kRxBufArraySize); 258 | 259 | if (!rxBufArrayMem) { 260 | IOLog("Couldn't alloc receive buffer array.\n"); 261 | goto done; 262 | } 263 | rxBufArray = (rtlRxBufferInfo *)rxBufArrayMem; 264 | 265 | /* Create receiver descriptor array. */ 266 | rxBufDesc = IOBufferMemoryDescriptor::inTaskWithPhysicalMask(kernel_task, (kIODirectionInOut | kIOMemoryPhysicallyContiguous | kIOMemoryHostPhysicallyContiguous | kIOMapInhibitCache), kRxDescSize, 0xFFFFFFFFFFFFFF00ULL); 267 | 268 | if (!rxBufDesc) { 269 | IOLog("Couldn't alloc rxBufDesc.\n"); 270 | goto error_buff; 271 | } 272 | if (rxBufDesc->prepare() != kIOReturnSuccess) { 273 | IOLog("rxBufDesc->prepare() failed.\n"); 274 | goto error_prep; 275 | } 276 | rxDescArray = (RtlDmaDesc *)rxBufDesc->getBytesNoCopy(); 277 | 278 | rxDescDmaCmd = IODMACommand::withSpecification(kIODMACommandOutputHost64, 64, 0, IODMACommand::kMapped, 0, 1, mapper, NULL); 279 | 280 | if (!rxDescDmaCmd) { 281 | IOLog("Couldn't alloc rxDescDmaCmd.\n"); 282 | goto error_dma; 283 | } 284 | 285 | if (rxDescDmaCmd->setMemoryDescriptor(rxBufDesc) != kIOReturnSuccess) { 286 | IOLog("setMemoryDescriptor() failed.\n"); 287 | goto error_set_desc; 288 | } 289 | 290 | if (rxDescDmaCmd->gen64IOVMSegments(&offset, &seg, &numSegs) != kIOReturnSuccess) { 291 | IOLog("gen64IOVMSegments() failed.\n"); 292 | goto error_rx_buf; 293 | } 294 | /* And the rx ring's physical address too. */ 295 | rxPhyAddr = seg.fIOVMAddr; 296 | 297 | /* Initialize rxDescArray. */ 298 | bzero(rxDescArray, kRxDescSize); 299 | rxDescArray[kRxLastDesc].cmd.opts1 = OSSwapHostToLittleInt32(RingEnd); 300 | 301 | for (i = 0; i < kNumRxDesc; i++) { 302 | rxBufArray[i].mbuf = NULL; 303 | } 304 | rxNextDescIndex = 0; 305 | rxMapNextIndex = 0; 306 | 307 | rxPool = RealtekRxPool::withCapacity(kRxPoolMbufCap, kRxPoolClstCap); 308 | 309 | if (!rxPool) { 310 | IOLog("Couldn't alloc receive buffer pool.\n"); 311 | goto error_rx_buf; 312 | } 313 | 314 | /* Alloc receive buffers. */ 315 | for (i = 0; i < kNumRxDesc; i++) { 316 | m = rxPool->getPacket(kRxBufferSize, MBUF_WAITOK); 317 | 318 | if (!m) { 319 | IOLog("Couldn't get receive buffer from pool.\n"); 320 | goto error_buf; 321 | } 322 | rxBufArray[i].mbuf = m; 323 | 324 | if (!useAppleVTD) { 325 | word1 = (kRxBufferSize | DescOwn); 326 | 327 | if (i == kRxLastDesc) 328 | word1 |= RingEnd; 329 | 330 | pa = mbuf_data_to_physical(mbuf_datastart(m)); 331 | rxBufArray[i].phyAddr = pa; 332 | 333 | rxDescArray[i].buf.blen = OSSwapHostToLittleInt64(word1); 334 | rxDescArray[i].buf.addr = OSSwapHostToLittleInt64(pa); 335 | } 336 | } 337 | if (useAppleVTD) 338 | result = setupRxMap(); 339 | else 340 | result = true; 341 | 342 | done: 343 | return result; 344 | 345 | error_buf: 346 | for (i = 0; i < kNumRxDesc; i++) { 347 | if (rxBufArray[i].mbuf) { 348 | mbuf_freem_list(rxBufArray[i].mbuf); 349 | rxBufArray[i].mbuf = NULL; 350 | rxBufArray[i].phyAddr = 0; 351 | } 352 | } 353 | RELEASE(rxPool); 354 | 355 | error_rx_buf: 356 | rxDescDmaCmd->clearMemoryDescriptor(); 357 | 358 | error_set_desc: 359 | RELEASE(rxDescDmaCmd); 360 | 361 | error_dma: 362 | rxBufDesc->complete(); 363 | 364 | error_prep: 365 | RELEASE(rxBufDesc); 366 | 367 | error_buff: 368 | IOFree(rxBufArrayMem, kRxBufArraySize); 369 | rxBufArrayMem = NULL; 370 | rxBufArray = NULL; 371 | 372 | goto done; 373 | } 374 | 375 | bool RTL8111::setupTxResources() 376 | { 377 | IODMACommand::Segment64 seg; 378 | UInt64 offset = 0; 379 | UInt32 numSegs = 1; 380 | UInt32 i; 381 | bool result = false; 382 | 383 | /* Alloc tx mbuf_t array. */ 384 | txBufArrayMem = IOMallocZero(kTxBufArraySize); 385 | 386 | if (!txBufArrayMem) { 387 | IOLog("Couldn't alloc transmit buffer array.\n"); 388 | goto done; 389 | } 390 | txMbufArray = (mbuf_t *)txBufArrayMem; 391 | 392 | /* Create transmitter descriptor array. */ 393 | txBufDesc = IOBufferMemoryDescriptor::inTaskWithPhysicalMask(kernel_task, (kIODirectionInOut | kIOMemoryPhysicallyContiguous | kIOMemoryHostPhysicallyContiguous | kIOMapInhibitCache), kTxDescSize, 0xFFFFFFFFFFFFFF00ULL); 394 | 395 | if (!txBufDesc) { 396 | IOLog("Couldn't alloc txBufDesc.\n"); 397 | goto error_buff; 398 | } 399 | if (txBufDesc->prepare() != kIOReturnSuccess) { 400 | IOLog("txBufDesc->prepare() failed.\n"); 401 | goto error_prep; 402 | } 403 | txDescArray = (RtlDmaDesc *)txBufDesc->getBytesNoCopy(); 404 | 405 | txDescDmaCmd = IODMACommand::withSpecification(kIODMACommandOutputHost64, 64, 0, IODMACommand::kMapped, 0, 1, mapper, NULL); 406 | 407 | if (!txDescDmaCmd) { 408 | IOLog("Couldn't alloc txDescDmaCmd.\n"); 409 | goto error_dma; 410 | } 411 | 412 | if (txDescDmaCmd->setMemoryDescriptor(txBufDesc) != kIOReturnSuccess) { 413 | IOLog("setMemoryDescriptor() failed.\n"); 414 | goto error_set_desc; 415 | } 416 | 417 | if (txDescDmaCmd->gen64IOVMSegments(&offset, &seg, &numSegs) != kIOReturnSuccess) { 418 | IOLog("gen64IOVMSegments() failed.\n"); 419 | goto error_segm; 420 | } 421 | /* Now get tx ring's physical address. */ 422 | txPhyAddr = seg.fIOVMAddr; 423 | 424 | /* Initialize txDescArray. */ 425 | bzero(txDescArray, kTxDescSize); 426 | txDescArray[kTxLastDesc].cmd.opts1 = OSSwapHostToLittleInt32(RingEnd); 427 | 428 | for (i = 0; i < kNumTxDesc; i++) { 429 | txMbufArray[i] = NULL; 430 | } 431 | txNextDescIndex = txDirtyDescIndex = 0; 432 | txNumFreeDesc = kNumTxDesc; 433 | 434 | if (useAppleVTD) { 435 | result = setupTxMap(); 436 | 437 | if (!result) 438 | goto error_segm; 439 | } else { 440 | txMbufCursor = IOMbufNaturalMemoryCursor::withSpecification(0x4000, kMaxSegs); 441 | 442 | if (!txMbufCursor) { 443 | IOLog("Couldn't create txMbufCursor.\n"); 444 | goto error_segm; 445 | } 446 | result = true; 447 | } 448 | 449 | done: 450 | return result; 451 | 452 | error_segm: 453 | txDescDmaCmd->clearMemoryDescriptor(); 454 | 455 | error_set_desc: 456 | RELEASE(txDescDmaCmd); 457 | 458 | error_dma: 459 | txBufDesc->complete(); 460 | 461 | error_prep: 462 | RELEASE(txBufDesc); 463 | 464 | error_buff: 465 | IOFree(txBufArrayMem, kTxBufArraySize); 466 | txBufArrayMem = NULL; 467 | txMbufArray = NULL; 468 | 469 | goto done; 470 | } 471 | 472 | bool RTL8111::setupStatResources() 473 | { 474 | IODMACommand::Segment64 seg; 475 | UInt64 offset = 0; 476 | UInt32 numSegs = 1; 477 | bool result = false; 478 | 479 | /* Create statistics dump buffer. */ 480 | statBufDesc = IOBufferMemoryDescriptor::inTaskWithPhysicalMask(kernel_task, (kIODirectionIn | kIOMemoryPhysicallyContiguous | kIOMemoryHostPhysicallyContiguous | kIOMapInhibitCache), sizeof(RtlStatData), 0xFFFFFFFFFFFFFF00ULL); 481 | 482 | if (!statBufDesc) { 483 | IOLog("Couldn't alloc statBufDesc.\n"); 484 | goto done; 485 | } 486 | 487 | if (statBufDesc->prepare() != kIOReturnSuccess) { 488 | IOLog("statBufDesc->prepare() failed.\n"); 489 | goto error_prep; 490 | } 491 | statData = (RtlStatData *)statBufDesc->getBytesNoCopy(); 492 | 493 | statDescDmaCmd = IODMACommand::withSpecification(kIODMACommandOutputHost64, 64, 0, IODMACommand::kMapped, 0, 1); 494 | 495 | if (!statDescDmaCmd) { 496 | IOLog("Couldn't alloc statDescDmaCmd.\n"); 497 | goto error_dma; 498 | } 499 | 500 | if (statDescDmaCmd->setMemoryDescriptor(statBufDesc) != kIOReturnSuccess) { 501 | IOLog("setMemoryDescriptor() failed.\n"); 502 | goto error_set_desc; 503 | } 504 | 505 | if (statDescDmaCmd->gen64IOVMSegments(&offset, &seg, &numSegs) != kIOReturnSuccess) { 506 | IOLog("gen64IOVMSegments() failed.\n"); 507 | goto error_segm; 508 | } 509 | /* And the rx ring's physical address too. */ 510 | statPhyAddr = seg.fIOVMAddr; 511 | 512 | /* Initialize statData. */ 513 | bzero(statData, sizeof(RtlStatData)); 514 | 515 | result = true; 516 | 517 | done: 518 | return result; 519 | 520 | error_segm: 521 | statDescDmaCmd->clearMemoryDescriptor(); 522 | 523 | error_set_desc: 524 | RELEASE(statDescDmaCmd); 525 | 526 | error_dma: 527 | statBufDesc->complete(); 528 | 529 | error_prep: 530 | RELEASE(statBufDesc); 531 | goto done; 532 | } 533 | 534 | void RTL8111::freeRxResources() 535 | { 536 | UInt32 i; 537 | 538 | if (useAppleVTD) 539 | freeRxMap(); 540 | 541 | if (rxDescDmaCmd) { 542 | rxDescDmaCmd->complete(); 543 | rxDescDmaCmd->clearMemoryDescriptor(); 544 | rxDescDmaCmd->release(); 545 | rxDescDmaCmd = NULL; 546 | } 547 | if (rxBufDesc) { 548 | rxBufDesc->complete(); 549 | rxBufDesc->release(); 550 | rxBufDesc = NULL; 551 | rxPhyAddr = (IOPhysicalAddress64)NULL; 552 | } 553 | RELEASE(rxPool); 554 | 555 | if (rxBufArrayMem) { 556 | for (i = 0; i < kNumRxDesc; i++) { 557 | if (rxBufArray[i].mbuf) { 558 | mbuf_freem_list(rxBufArray[i].mbuf); 559 | rxBufArray[i].mbuf = NULL; 560 | } 561 | } 562 | IOFree(rxBufArrayMem, kRxBufArraySize); 563 | rxBufArrayMem = NULL; 564 | rxBufArray = NULL; 565 | } 566 | } 567 | 568 | void RTL8111::freeTxResources() 569 | { 570 | if (useAppleVTD) 571 | freeTxMap(); 572 | else 573 | RELEASE(txMbufCursor); 574 | 575 | if (txDescDmaCmd) { 576 | txDescDmaCmd->complete(); 577 | txDescDmaCmd->clearMemoryDescriptor(); 578 | txDescDmaCmd->release(); 579 | txDescDmaCmd = NULL; 580 | } 581 | if (txBufDesc) { 582 | txBufDesc->complete(); 583 | txBufDesc->release(); 584 | txBufDesc = NULL; 585 | txPhyAddr = (IOPhysicalAddress64)NULL; 586 | } 587 | if (txBufArrayMem) { 588 | IOFree(txBufArrayMem, kTxBufArraySize); 589 | txBufArrayMem = NULL; 590 | txMbufArray = NULL; 591 | } 592 | } 593 | 594 | void RTL8111::freeStatResources() 595 | { 596 | if (statDescDmaCmd) { 597 | statDescDmaCmd->complete(); 598 | statDescDmaCmd->clearMemoryDescriptor(); 599 | statDescDmaCmd->release(); 600 | statDescDmaCmd = NULL; 601 | } 602 | if (statBufDesc) { 603 | statBufDesc->complete(); 604 | statBufDesc->release(); 605 | statBufDesc = NULL; 606 | statPhyAddr = (IOPhysicalAddress64)NULL; 607 | } 608 | } 609 | 610 | void RTL8111::clearDescriptors() 611 | { 612 | IOMemoryDescriptor *md; 613 | mbuf_t m; 614 | UInt64 word1; 615 | UInt32 lastIndex = kTxLastDesc; 616 | UInt32 i; 617 | 618 | DebugLog("clearDescriptors() ===>\n"); 619 | 620 | if (useAppleVTD && txMapInfo) { 621 | for (i = 0; i < kNumTxMemDesc; i++) { 622 | md = txMapInfo->txMemIO[i]; 623 | 624 | if (md && (md->getTag() == kIOMemoryActive)) { 625 | md->complete(); 626 | md->setTag(kIOMemoryInactive); 627 | } 628 | } 629 | txMapInfo->txNextMem2Use = txMapInfo->txNextMem2Free = 0; 630 | txMapInfo->txNumFreeMem = kNumTxMemDesc; 631 | } 632 | for (i = 0; i < kNumTxDesc; i++) { 633 | txDescArray[i].cmd.opts1 = OSSwapHostToLittleInt32((i != lastIndex) ? 0 : RingEnd); 634 | m = txMbufArray[i]; 635 | 636 | if (m) { 637 | mbuf_freem_list(m); 638 | txMbufArray[i] = NULL; 639 | } 640 | } 641 | txDirtyDescIndex = txNextDescIndex = 0; 642 | txNumFreeDesc = kNumTxDesc; 643 | 644 | if (useAppleVTD) 645 | rxMapBuffers(0, kNumRxMemDesc); 646 | 647 | for (i = 0; i < kNumRxDesc; i++) { 648 | word1 = (kRxBufferSize | DescOwn); 649 | 650 | if (i == kRxLastDesc) 651 | word1 |= RingEnd; 652 | 653 | rxDescArray[i].buf.blen = OSSwapHostToLittleInt64(word1); 654 | rxDescArray[i].buf.addr = OSSwapHostToLittleInt64(rxBufArray[i].phyAddr); 655 | } 656 | rxNextDescIndex = 0; 657 | rxMapNextIndex = 0; 658 | deadlockWarn = 0; 659 | 660 | /* Free packet fragments which haven't been upstreamed yet. */ 661 | discardPacketFragment(); 662 | 663 | DebugLog("clearDescriptors() <===\n"); 664 | } 665 | 666 | void RTL8111::discardPacketFragment() 667 | { 668 | /* 669 | * In case there is a packet fragment which hasn't been enqueued yet 670 | * we have to free it in order to prevent a memory leak. 671 | */ 672 | if (rxPacketHead) 673 | mbuf_freem_list(rxPacketHead); 674 | 675 | rxPacketHead = rxPacketTail = NULL; 676 | rxPacketSize = 0; 677 | } 678 | -------------------------------------------------------------------------------- /RealtekRTL8111/ethertool.h: -------------------------------------------------------------------------------- 1 | /* ethertool.h -- Definitions from the linux kernel source needed by the linux code. 2 | * 3 | * Copyright (c) 2013 Laura Müller 4 | * All rights reserved. 5 | * 6 | * This program is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU General Public License as published by the Free 8 | * Software Foundation; either version 2 of the License, or (at your option) 9 | * any later version. 10 | * 11 | * This program is distributed in the hope that it will be useful, but WITHOUT 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 14 | * more details. 15 | * 16 | * Driver for Realtek RTL8111x PCIe ethernet controllers. 17 | * 18 | * This driver is based on Realtek's r8168 Linux driver (8.041.0). 19 | */ 20 | 21 | #ifndef RTL8111Ethernet_ethertool_h 22 | #define RTL8111Ethernet_ethertool_h 23 | 24 | /* 25 | * ethtool.h: Defines for Linux ethtool. 26 | * 27 | * Copyright (C) 1998 David S. Miller (davem@redhat.com) 28 | * Copyright 2001 Jeff Garzik 29 | * Portions Copyright 2001 Sun Microsystems (thockin@sun.com) 30 | * Portions Copyright 2002 Intel (eli.kupermann@intel.com, 31 | * christopher.leech@intel.com, 32 | * scott.feldman@intel.com) 33 | * Portions Copyright (C) Sun Microsystems 2008 34 | */ 35 | 36 | #ifndef _LINUX_ETHTOOL_H 37 | #define _LINUX_ETHTOOL_H 38 | 39 | #include "if_ether.h" 40 | 41 | /* 42 | #ifdef __KERNEL__ 43 | #include 44 | #endif 45 | #include 46 | #include 47 | */ 48 | /* This should work for both 32 and 64 bit userland. */ 49 | struct ethtool_cmd { 50 | __u32 cmd; 51 | __u32 supported; /* Features this interface supports */ 52 | __u32 advertising; /* Features this interface advertises */ 53 | __u16 speed; /* The forced speed (lower bits) in 54 | * Mbps. Please use 55 | * ethtool_cmd_speed()/_set() to 56 | * access it */ 57 | __u8 duplex; /* Duplex, half or full */ 58 | __u8 port; /* Which connector port */ 59 | __u8 phy_address; 60 | __u8 transceiver; /* Which transceiver to use */ 61 | __u8 autoneg; /* Enable or disable autonegotiation */ 62 | __u8 mdio_support; 63 | __u32 maxtxpkt; /* Tx pkts before generating tx int */ 64 | __u32 maxrxpkt; /* Rx pkts before generating rx int */ 65 | __u16 speed_hi; /* The forced speed (upper 66 | * bits) in Mbps. Please use 67 | * ethtool_cmd_speed()/_set() to 68 | * access it */ 69 | __u8 eth_tp_mdix; 70 | __u8 reserved2; 71 | __u32 lp_advertising; /* Features the link partner advertises */ 72 | __u32 reserved[2]; 73 | }; 74 | 75 | static inline void ethtool_cmd_speed_set(struct ethtool_cmd *ep, 76 | __u32 speed) 77 | { 78 | 79 | ep->speed = (__u16)speed; 80 | ep->speed_hi = (__u16)(speed >> 16); 81 | } 82 | 83 | static inline __u32 ethtool_cmd_speed(const struct ethtool_cmd *ep) 84 | { 85 | return (ep->speed_hi << 16) | ep->speed; 86 | } 87 | 88 | #define ETHTOOL_FWVERS_LEN 32 89 | #define ETHTOOL_BUSINFO_LEN 32 90 | /* these strings are set to whatever the driver author decides... */ 91 | struct ethtool_drvinfo { 92 | __u32 cmd; 93 | char driver[32]; /* driver short name, "tulip", "eepro100" */ 94 | char version[32]; /* driver version string */ 95 | char fw_version[ETHTOOL_FWVERS_LEN]; /* firmware version string */ 96 | char bus_info[ETHTOOL_BUSINFO_LEN]; /* Bus info for this IF. */ 97 | /* For PCI devices, use pci_name(pci_dev). */ 98 | char reserved1[32]; 99 | char reserved2[12]; 100 | /* 101 | * Some struct members below are filled in 102 | * using ops->get_sset_count(). Obtaining 103 | * this info from ethtool_drvinfo is now 104 | * deprecated; Use ETHTOOL_GSSET_INFO 105 | * instead. 106 | */ 107 | __u32 n_priv_flags; /* number of flags valid in ETHTOOL_GPFLAGS */ 108 | __u32 n_stats; /* number of u64's from ETHTOOL_GSTATS */ 109 | __u32 testinfo_len; 110 | __u32 eedump_len; /* Size of data from ETHTOOL_GEEPROM (bytes) */ 111 | __u32 regdump_len; /* Size of data from ETHTOOL_GREGS (bytes) */ 112 | }; 113 | 114 | #define SOPASS_MAX 6 115 | /* wake-on-lan settings */ 116 | struct ethtool_wolinfo { 117 | __u32 cmd; 118 | __u32 supported; 119 | __u32 wolopts; 120 | __u8 sopass[SOPASS_MAX]; /* SecureOn(tm) password */ 121 | }; 122 | 123 | /* for passing single values */ 124 | struct ethtool_value { 125 | __u32 cmd; 126 | __u32 data; 127 | }; 128 | 129 | /* for passing big chunks of data */ 130 | struct ethtool_regs { 131 | __u32 cmd; 132 | __u32 version; /* driver-specific, indicates different chips/revs */ 133 | __u32 len; /* bytes */ 134 | __u8 data[0]; 135 | }; 136 | 137 | /* for passing EEPROM chunks */ 138 | struct ethtool_eeprom { 139 | __u32 cmd; 140 | __u32 magic; 141 | __u32 offset; /* in bytes */ 142 | __u32 len; /* in bytes */ 143 | __u8 data[0]; 144 | }; 145 | 146 | /* for configuring coalescing parameters of chip */ 147 | struct ethtool_coalesce { 148 | __u32 cmd; /* ETHTOOL_{G,S}COALESCE */ 149 | 150 | /* How many usecs to delay an RX interrupt after 151 | * a packet arrives. If 0, only rx_max_coalesced_frames 152 | * is used. 153 | */ 154 | __u32 rx_coalesce_usecs; 155 | 156 | /* How many packets to delay an RX interrupt after 157 | * a packet arrives. If 0, only rx_coalesce_usecs is 158 | * used. It is illegal to set both usecs and max frames 159 | * to zero as this would cause RX interrupts to never be 160 | * generated. 161 | */ 162 | __u32 rx_max_coalesced_frames; 163 | 164 | /* Same as above two parameters, except that these values 165 | * apply while an IRQ is being serviced by the host. Not 166 | * all cards support this feature and the values are ignored 167 | * in that case. 168 | */ 169 | __u32 rx_coalesce_usecs_irq; 170 | __u32 rx_max_coalesced_frames_irq; 171 | 172 | /* How many usecs to delay a TX interrupt after 173 | * a packet is sent. If 0, only tx_max_coalesced_frames 174 | * is used. 175 | */ 176 | __u32 tx_coalesce_usecs; 177 | 178 | /* How many packets to delay a TX interrupt after 179 | * a packet is sent. If 0, only tx_coalesce_usecs is 180 | * used. It is illegal to set both usecs and max frames 181 | * to zero as this would cause TX interrupts to never be 182 | * generated. 183 | */ 184 | __u32 tx_max_coalesced_frames; 185 | 186 | /* Same as above two parameters, except that these values 187 | * apply while an IRQ is being serviced by the host. Not 188 | * all cards support this feature and the values are ignored 189 | * in that case. 190 | */ 191 | __u32 tx_coalesce_usecs_irq; 192 | __u32 tx_max_coalesced_frames_irq; 193 | 194 | /* How many usecs to delay in-memory statistics 195 | * block updates. Some drivers do not have an in-memory 196 | * statistic block, and in such cases this value is ignored. 197 | * This value must not be zero. 198 | */ 199 | __u32 stats_block_coalesce_usecs; 200 | 201 | /* Adaptive RX/TX coalescing is an algorithm implemented by 202 | * some drivers to improve latency under low packet rates and 203 | * improve throughput under high packet rates. Some drivers 204 | * only implement one of RX or TX adaptive coalescing. Anything 205 | * not implemented by the driver causes these values to be 206 | * silently ignored. 207 | */ 208 | __u32 use_adaptive_rx_coalesce; 209 | __u32 use_adaptive_tx_coalesce; 210 | 211 | /* When the packet rate (measured in packets per second) 212 | * is below pkt_rate_low, the {rx,tx}_*_low parameters are 213 | * used. 214 | */ 215 | __u32 pkt_rate_low; 216 | __u32 rx_coalesce_usecs_low; 217 | __u32 rx_max_coalesced_frames_low; 218 | __u32 tx_coalesce_usecs_low; 219 | __u32 tx_max_coalesced_frames_low; 220 | 221 | /* When the packet rate is below pkt_rate_high but above 222 | * pkt_rate_low (both measured in packets per second) the 223 | * normal {rx,tx}_* coalescing parameters are used. 224 | */ 225 | 226 | /* When the packet rate is (measured in packets per second) 227 | * is above pkt_rate_high, the {rx,tx}_*_high parameters are 228 | * used. 229 | */ 230 | __u32 pkt_rate_high; 231 | __u32 rx_coalesce_usecs_high; 232 | __u32 rx_max_coalesced_frames_high; 233 | __u32 tx_coalesce_usecs_high; 234 | __u32 tx_max_coalesced_frames_high; 235 | 236 | /* How often to do adaptive coalescing packet rate sampling, 237 | * measured in seconds. Must not be zero. 238 | */ 239 | __u32 rate_sample_interval; 240 | }; 241 | 242 | /* for configuring RX/TX ring parameters */ 243 | struct ethtool_ringparam { 244 | __u32 cmd; /* ETHTOOL_{G,S}RINGPARAM */ 245 | 246 | /* Read only attributes. These indicate the maximum number 247 | * of pending RX/TX ring entries the driver will allow the 248 | * user to set. 249 | */ 250 | __u32 rx_max_pending; 251 | __u32 rx_mini_max_pending; 252 | __u32 rx_jumbo_max_pending; 253 | __u32 tx_max_pending; 254 | 255 | /* Values changeable by the user. The valid values are 256 | * in the range 1 to the "*_max_pending" counterpart above. 257 | */ 258 | __u32 rx_pending; 259 | __u32 rx_mini_pending; 260 | __u32 rx_jumbo_pending; 261 | __u32 tx_pending; 262 | }; 263 | 264 | /** 265 | * struct ethtool_channels - configuring number of network channel 266 | * @cmd: ETHTOOL_{G,S}CHANNELS 267 | * @max_rx: Read only. Maximum number of receive channel the driver support. 268 | * @max_tx: Read only. Maximum number of transmit channel the driver support. 269 | * @max_other: Read only. Maximum number of other channel the driver support. 270 | * @max_combined: Read only. Maximum number of combined channel the driver 271 | * support. Set of queues RX, TX or other. 272 | * @rx_count: Valid values are in the range 1 to the max_rx. 273 | * @tx_count: Valid values are in the range 1 to the max_tx. 274 | * @other_count: Valid values are in the range 1 to the max_other. 275 | * @combined_count: Valid values are in the range 1 to the max_combined. 276 | * 277 | * This can be used to configure RX, TX and other channels. 278 | */ 279 | 280 | struct ethtool_channels { 281 | __u32 cmd; 282 | __u32 max_rx; 283 | __u32 max_tx; 284 | __u32 max_other; 285 | __u32 max_combined; 286 | __u32 rx_count; 287 | __u32 tx_count; 288 | __u32 other_count; 289 | __u32 combined_count; 290 | }; 291 | 292 | /* for configuring link flow control parameters */ 293 | struct ethtool_pauseparam { 294 | __u32 cmd; /* ETHTOOL_{G,S}PAUSEPARAM */ 295 | 296 | /* If the link is being auto-negotiated (via ethtool_cmd.autoneg 297 | * being true) the user may set 'autoneg' here non-zero to have the 298 | * pause parameters be auto-negotiated too. In such a case, the 299 | * {rx,tx}_pause values below determine what capabilities are 300 | * advertised. 301 | * 302 | * If 'autoneg' is zero or the link is not being auto-negotiated, 303 | * then {rx,tx}_pause force the driver to use/not-use pause 304 | * flow control. 305 | */ 306 | __u32 autoneg; 307 | __u32 rx_pause; 308 | __u32 tx_pause; 309 | }; 310 | 311 | #define ETH_GSTRING_LEN 32 312 | enum ethtool_stringset { 313 | ETH_SS_TEST = 0, 314 | ETH_SS_STATS, 315 | ETH_SS_PRIV_FLAGS, 316 | ETH_SS_NTUPLE_FILTERS, 317 | ETH_SS_FEATURES, 318 | }; 319 | 320 | /* for passing string sets for data tagging */ 321 | struct ethtool_gstrings { 322 | __u32 cmd; /* ETHTOOL_GSTRINGS */ 323 | __u32 string_set; /* string set id e.c. ETH_SS_TEST, etc*/ 324 | __u32 len; /* number of strings in the string set */ 325 | __u8 data[0]; 326 | }; 327 | 328 | struct ethtool_sset_info { 329 | __u32 cmd; /* ETHTOOL_GSSET_INFO */ 330 | __u32 reserved; 331 | __u64 sset_mask; /* input: each bit selects an sset to query */ 332 | /* output: each bit a returned sset */ 333 | __u32 data[0]; /* ETH_SS_xxx count, in order, based on bits 334 | in sset_mask. One bit implies one 335 | __u32, two bits implies two 336 | __u32's, etc. */ 337 | }; 338 | 339 | enum ethtool_test_flags { 340 | ETH_TEST_FL_OFFLINE = (1 << 0), /* online / offline */ 341 | ETH_TEST_FL_FAILED = (1 << 1), /* test passed / failed */ 342 | }; 343 | 344 | /* for requesting NIC test and getting results*/ 345 | struct ethtool_test { 346 | __u32 cmd; /* ETHTOOL_TEST */ 347 | __u32 flags; /* ETH_TEST_FL_xxx */ 348 | __u32 reserved; 349 | __u32 len; /* result length, in number of u64 elements */ 350 | __u64 data[0]; 351 | }; 352 | 353 | /* for dumping NIC-specific statistics */ 354 | struct ethtool_stats { 355 | __u32 cmd; /* ETHTOOL_GSTATS */ 356 | __u32 n_stats; /* number of u64's being returned */ 357 | __u64 data[0]; 358 | }; 359 | 360 | struct ethtool_perm_addr { 361 | __u32 cmd; /* ETHTOOL_GPERMADDR */ 362 | __u32 size; 363 | __u8 data[0]; 364 | }; 365 | 366 | /* boolean flags controlling per-interface behavior characteristics. 367 | * When reading, the flag indicates whether or not a certain behavior 368 | * is enabled/present. When writing, the flag indicates whether 369 | * or not the driver should turn on (set) or off (clear) a behavior. 370 | * 371 | * Some behaviors may read-only (unconditionally absent or present). 372 | * If such is the case, return EINVAL in the set-flags operation if the 373 | * flag differs from the read-only value. 374 | */ 375 | enum ethtool_flags { 376 | ETH_FLAG_TXVLAN = (1 << 7), /* TX VLAN offload enabled */ 377 | ETH_FLAG_RXVLAN = (1 << 8), /* RX VLAN offload enabled */ 378 | ETH_FLAG_LRO = (1 << 15), /* LRO is enabled */ 379 | ETH_FLAG_NTUPLE = (1 << 27), /* N-tuple filters enabled */ 380 | ETH_FLAG_RXHASH = (1 << 28), 381 | }; 382 | 383 | /* The following structures are for supporting RX network flow 384 | * classification and RX n-tuple configuration. Note, all multibyte 385 | * fields, e.g., ip4src, ip4dst, psrc, pdst, spi, etc. are expected to 386 | * be in network byte order. 387 | */ 388 | 389 | /** 390 | * struct ethtool_tcpip4_spec - flow specification for TCP/IPv4 etc. 391 | * @ip4src: Source host 392 | * @ip4dst: Destination host 393 | * @psrc: Source port 394 | * @pdst: Destination port 395 | * @tos: Type-of-service 396 | * 397 | * This can be used to specify a TCP/IPv4, UDP/IPv4 or SCTP/IPv4 flow. 398 | */ 399 | struct ethtool_tcpip4_spec { 400 | __be32 ip4src; 401 | __be32 ip4dst; 402 | __be16 psrc; 403 | __be16 pdst; 404 | __u8 tos; 405 | }; 406 | 407 | /** 408 | * struct ethtool_ah_espip4_spec - flow specification for IPsec/IPv4 409 | * @ip4src: Source host 410 | * @ip4dst: Destination host 411 | * @spi: Security parameters index 412 | * @tos: Type-of-service 413 | * 414 | * This can be used to specify an IPsec transport or tunnel over IPv4. 415 | */ 416 | struct ethtool_ah_espip4_spec { 417 | __be32 ip4src; 418 | __be32 ip4dst; 419 | __be32 spi; 420 | __u8 tos; 421 | }; 422 | 423 | #define ETH_RX_NFC_IP4 1 424 | 425 | /** 426 | * struct ethtool_usrip4_spec - general flow specification for IPv4 427 | * @ip4src: Source host 428 | * @ip4dst: Destination host 429 | * @l4_4_bytes: First 4 bytes of transport (layer 4) header 430 | * @tos: Type-of-service 431 | * @ip_ver: Value must be %ETH_RX_NFC_IP4; mask must be 0 432 | * @proto: Transport protocol number; mask must be 0 433 | */ 434 | struct ethtool_usrip4_spec { 435 | __be32 ip4src; 436 | __be32 ip4dst; 437 | __be32 l4_4_bytes; 438 | __u8 tos; 439 | __u8 ip_ver; 440 | __u8 proto; 441 | }; 442 | 443 | union ethtool_flow_union { 444 | struct ethtool_tcpip4_spec tcp_ip4_spec; 445 | struct ethtool_tcpip4_spec udp_ip4_spec; 446 | struct ethtool_tcpip4_spec sctp_ip4_spec; 447 | struct ethtool_ah_espip4_spec ah_ip4_spec; 448 | struct ethtool_ah_espip4_spec esp_ip4_spec; 449 | struct ethtool_usrip4_spec usr_ip4_spec; 450 | struct ethhdr ether_spec; 451 | __u8 hdata[60]; 452 | }; 453 | 454 | struct ethtool_flow_ext { 455 | __be16 vlan_etype; 456 | __be16 vlan_tci; 457 | __be32 data[2]; 458 | }; 459 | 460 | /** 461 | * struct ethtool_rx_flow_spec - specification for RX flow filter 462 | * @flow_type: Type of match to perform, e.g. %TCP_V4_FLOW 463 | * @h_u: Flow fields to match (dependent on @flow_type) 464 | * @h_ext: Additional fields to match 465 | * @m_u: Masks for flow field bits to be matched 466 | * @m_ext: Masks for additional field bits to be matched 467 | * Note, all additional fields must be ignored unless @flow_type 468 | * includes the %FLOW_EXT flag. 469 | * @ring_cookie: RX ring/queue index to deliver to, or %RX_CLS_FLOW_DISC 470 | * if packets should be discarded 471 | * @location: Index of filter in hardware table 472 | */ 473 | struct ethtool_rx_flow_spec { 474 | __u32 flow_type; 475 | union ethtool_flow_union h_u; 476 | struct ethtool_flow_ext h_ext; 477 | union ethtool_flow_union m_u; 478 | struct ethtool_flow_ext m_ext; 479 | __u64 ring_cookie; 480 | __u32 location; 481 | }; 482 | 483 | /** 484 | * struct ethtool_rxnfc - command to get or set RX flow classification rules 485 | * @cmd: Specific command number - %ETHTOOL_GRXFH, %ETHTOOL_SRXFH, 486 | * %ETHTOOL_GRXRINGS, %ETHTOOL_GRXCLSRLCNT, %ETHTOOL_GRXCLSRULE, 487 | * %ETHTOOL_GRXCLSRLALL, %ETHTOOL_SRXCLSRLDEL or %ETHTOOL_SRXCLSRLINS 488 | * @flow_type: Type of flow to be affected, e.g. %TCP_V4_FLOW 489 | * @data: Command-dependent value 490 | * @fs: Flow filter specification 491 | * @rule_cnt: Number of rules to be affected 492 | * @rule_locs: Array of valid rule indices 493 | * 494 | * For %ETHTOOL_GRXFH and %ETHTOOL_SRXFH, @data is a bitmask indicating 495 | * the fields included in the flow hash, e.g. %RXH_IP_SRC. The following 496 | * structure fields must not be used. 497 | * 498 | * For %ETHTOOL_GRXRINGS, @data is set to the number of RX rings/queues 499 | * on return. 500 | * 501 | * For %ETHTOOL_GRXCLSRLCNT, @rule_cnt is set to the number of defined 502 | * rules on return. 503 | * 504 | * For %ETHTOOL_GRXCLSRULE, @fs.@location specifies the index of an 505 | * existing filter rule on entry and @fs contains the rule on return. 506 | * 507 | * For %ETHTOOL_GRXCLSRLALL, @rule_cnt specifies the array size of the 508 | * user buffer for @rule_locs on entry. On return, @data is the size 509 | * of the filter table and @rule_locs contains the indices of the 510 | * defined rules. 511 | * 512 | * For %ETHTOOL_SRXCLSRLINS, @fs specifies the filter rule to add or 513 | * update. @fs.@location specifies the index to use and must not be 514 | * ignored. 515 | * 516 | * For %ETHTOOL_SRXCLSRLDEL, @fs.@location specifies the index of an 517 | * existing filter rule on entry. 518 | * 519 | * Implementation of indexed classification rules generally requires a 520 | * TCAM. 521 | */ 522 | struct ethtool_rxnfc { 523 | __u32 cmd; 524 | __u32 flow_type; 525 | __u64 data; 526 | struct ethtool_rx_flow_spec fs; 527 | __u32 rule_cnt; 528 | __u32 rule_locs[0]; 529 | }; 530 | 531 | #ifdef __KERNEL__ 532 | #ifdef CONFIG_COMPAT 533 | 534 | struct compat_ethtool_rx_flow_spec { 535 | u32 flow_type; 536 | union ethtool_flow_union h_u; 537 | struct ethtool_flow_ext h_ext; 538 | union ethtool_flow_union m_u; 539 | struct ethtool_flow_ext m_ext; 540 | compat_u64 ring_cookie; 541 | u32 location; 542 | }; 543 | 544 | struct compat_ethtool_rxnfc { 545 | u32 cmd; 546 | u32 flow_type; 547 | compat_u64 data; 548 | struct compat_ethtool_rx_flow_spec fs; 549 | u32 rule_cnt; 550 | u32 rule_locs[0]; 551 | }; 552 | 553 | #endif /* CONFIG_COMPAT */ 554 | #endif /* __KERNEL__ */ 555 | 556 | /** 557 | * struct ethtool_rxfh_indir - command to get or set RX flow hash indirection 558 | * @cmd: Specific command number - %ETHTOOL_GRXFHINDIR or %ETHTOOL_SRXFHINDIR 559 | * @size: On entry, the array size of the user buffer. On return from 560 | * %ETHTOOL_GRXFHINDIR, the array size of the hardware indirection table. 561 | * @ring_index: RX ring/queue index for each hash value 562 | */ 563 | struct ethtool_rxfh_indir { 564 | __u32 cmd; 565 | __u32 size; 566 | __u32 ring_index[0]; 567 | }; 568 | 569 | /** 570 | * struct ethtool_rx_ntuple_flow_spec - specification for RX flow filter 571 | * @flow_type: Type of match to perform, e.g. %TCP_V4_FLOW 572 | * @h_u: Flow field values to match (dependent on @flow_type) 573 | * @m_u: Masks for flow field value bits to be ignored 574 | * @vlan_tag: VLAN tag to match 575 | * @vlan_tag_mask: Mask for VLAN tag bits to be ignored 576 | * @data: Driver-dependent data to match 577 | * @data_mask: Mask for driver-dependent data bits to be ignored 578 | * @action: RX ring/queue index to deliver to (non-negative) or other action 579 | * (negative, e.g. %ETHTOOL_RXNTUPLE_ACTION_DROP) 580 | * 581 | * For flow types %TCP_V4_FLOW, %UDP_V4_FLOW and %SCTP_V4_FLOW, where 582 | * a field value and mask are both zero this is treated as if all mask 583 | * bits are set i.e. the field is ignored. 584 | */ 585 | struct ethtool_rx_ntuple_flow_spec { 586 | __u32 flow_type; 587 | union { 588 | struct ethtool_tcpip4_spec tcp_ip4_spec; 589 | struct ethtool_tcpip4_spec udp_ip4_spec; 590 | struct ethtool_tcpip4_spec sctp_ip4_spec; 591 | struct ethtool_ah_espip4_spec ah_ip4_spec; 592 | struct ethtool_ah_espip4_spec esp_ip4_spec; 593 | struct ethtool_usrip4_spec usr_ip4_spec; 594 | struct ethhdr ether_spec; 595 | __u8 hdata[72]; 596 | } h_u, m_u; 597 | 598 | __u16 vlan_tag; 599 | __u16 vlan_tag_mask; 600 | __u64 data; 601 | __u64 data_mask; 602 | 603 | __s32 action; 604 | #define ETHTOOL_RXNTUPLE_ACTION_DROP (-1) /* drop packet */ 605 | #define ETHTOOL_RXNTUPLE_ACTION_CLEAR (-2) /* clear filter */ 606 | }; 607 | 608 | /** 609 | * struct ethtool_rx_ntuple - command to set or clear RX flow filter 610 | * @cmd: Command number - %ETHTOOL_SRXNTUPLE 611 | * @fs: Flow filter specification 612 | */ 613 | struct ethtool_rx_ntuple { 614 | __u32 cmd; 615 | struct ethtool_rx_ntuple_flow_spec fs; 616 | }; 617 | 618 | #define ETHTOOL_FLASH_MAX_FILENAME 128 619 | enum ethtool_flash_op_type { 620 | ETHTOOL_FLASH_ALL_REGIONS = 0, 621 | }; 622 | 623 | /* for passing firmware flashing related parameters */ 624 | struct ethtool_flash { 625 | __u32 cmd; 626 | __u32 region; 627 | char data[ETHTOOL_FLASH_MAX_FILENAME]; 628 | }; 629 | 630 | /** 631 | * struct ethtool_dump - used for retrieving, setting device dump 632 | * @cmd: Command number - %ETHTOOL_GET_DUMP_FLAG, %ETHTOOL_GET_DUMP_DATA, or 633 | * %ETHTOOL_SET_DUMP 634 | * @version: FW version of the dump, filled in by driver 635 | * @flag: driver dependent flag for dump setting, filled in by driver during 636 | * get and filled in by ethtool for set operation 637 | * @len: length of dump data, used as the length of the user buffer on entry to 638 | * %ETHTOOL_GET_DUMP_DATA and this is returned as dump length by driver 639 | * for %ETHTOOL_GET_DUMP_FLAG command 640 | * @data: data collected for get dump data operation 641 | */ 642 | struct ethtool_dump { 643 | __u32 cmd; 644 | __u32 version; 645 | __u32 flag; 646 | __u32 len; 647 | __u8 data[0]; 648 | }; 649 | 650 | /* for returning and changing feature sets */ 651 | 652 | /** 653 | * struct ethtool_get_features_block - block with state of 32 features 654 | * @available: mask of changeable features 655 | * @requested: mask of features requested to be enabled if possible 656 | * @active: mask of currently enabled features 657 | * @never_changed: mask of features not changeable for any device 658 | */ 659 | struct ethtool_get_features_block { 660 | __u32 available; 661 | __u32 requested; 662 | __u32 active; 663 | __u32 never_changed; 664 | }; 665 | 666 | /** 667 | * struct ethtool_gfeatures - command to get state of device's features 668 | * @cmd: command number = %ETHTOOL_GFEATURES 669 | * @size: in: number of elements in the features[] array; 670 | * out: number of elements in features[] needed to hold all features 671 | * @features: state of features 672 | */ 673 | struct ethtool_gfeatures { 674 | __u32 cmd; 675 | __u32 size; 676 | struct ethtool_get_features_block features[0]; 677 | }; 678 | 679 | /** 680 | * struct ethtool_set_features_block - block with request for 32 features 681 | * @valid: mask of features to be changed 682 | * @requested: values of features to be changed 683 | */ 684 | struct ethtool_set_features_block { 685 | __u32 valid; 686 | __u32 requested; 687 | }; 688 | 689 | /** 690 | * struct ethtool_sfeatures - command to request change in device's features 691 | * @cmd: command number = %ETHTOOL_SFEATURES 692 | * @size: array size of the features[] array 693 | * @features: feature change masks 694 | */ 695 | struct ethtool_sfeatures { 696 | __u32 cmd; 697 | __u32 size; 698 | struct ethtool_set_features_block features[0]; 699 | }; 700 | 701 | /* 702 | * %ETHTOOL_SFEATURES changes features present in features[].valid to the 703 | * values of corresponding bits in features[].requested. Bits in .requested 704 | * not set in .valid or not changeable are ignored. 705 | * 706 | * Returns %EINVAL when .valid contains undefined or never-changeable bits 707 | * or size is not equal to required number of features words (32-bit blocks). 708 | * Returns >= 0 if request was completed; bits set in the value mean: 709 | * %ETHTOOL_F_UNSUPPORTED - there were bits set in .valid that are not 710 | * changeable (not present in %ETHTOOL_GFEATURES' features[].available) 711 | * those bits were ignored. 712 | * %ETHTOOL_F_WISH - some or all changes requested were recorded but the 713 | * resulting state of bits masked by .valid is not equal to .requested. 714 | * Probably there are other device-specific constraints on some features 715 | * in the set. When %ETHTOOL_F_UNSUPPORTED is set, .valid is considered 716 | * here as though ignored bits were cleared. 717 | * %ETHTOOL_F_COMPAT - some or all changes requested were made by calling 718 | * compatibility functions. Requested offload state cannot be properly 719 | * managed by kernel. 720 | * 721 | * Meaning of bits in the masks are obtained by %ETHTOOL_GSSET_INFO (number of 722 | * bits in the arrays - always multiple of 32) and %ETHTOOL_GSTRINGS commands 723 | * for ETH_SS_FEATURES string set. First entry in the table corresponds to least 724 | * significant bit in features[0] fields. Empty strings mark undefined features. 725 | */ 726 | enum ethtool_sfeatures_retval_bits { 727 | ETHTOOL_F_UNSUPPORTED__BIT, 728 | ETHTOOL_F_WISH__BIT, 729 | ETHTOOL_F_COMPAT__BIT, 730 | }; 731 | 732 | #define ETHTOOL_F_UNSUPPORTED (1 << ETHTOOL_F_UNSUPPORTED__BIT) 733 | #define ETHTOOL_F_WISH (1 << ETHTOOL_F_WISH__BIT) 734 | #define ETHTOOL_F_COMPAT (1 << ETHTOOL_F_COMPAT__BIT) 735 | 736 | #ifdef __KERNEL__ 737 | 738 | #include 739 | 740 | /* needed by dev_disable_lro() */ 741 | extern int __ethtool_set_flags(struct net_device *dev, u32 flags); 742 | 743 | struct ethtool_rx_ntuple_flow_spec_container { 744 | struct ethtool_rx_ntuple_flow_spec fs; 745 | struct list_head list; 746 | }; 747 | 748 | struct ethtool_rx_ntuple_list { 749 | #define ETHTOOL_MAX_NTUPLE_LIST_ENTRY 1024 750 | #define ETHTOOL_MAX_NTUPLE_STRING_PER_ENTRY 14 751 | struct list_head list; 752 | unsigned int count; 753 | }; 754 | 755 | /** 756 | * enum ethtool_phys_id_state - indicator state for physical identification 757 | * @ETHTOOL_ID_INACTIVE: Physical ID indicator should be deactivated 758 | * @ETHTOOL_ID_ACTIVE: Physical ID indicator should be activated 759 | * @ETHTOOL_ID_ON: LED should be turned on (used iff %ETHTOOL_ID_ACTIVE 760 | * is not supported) 761 | * @ETHTOOL_ID_OFF: LED should be turned off (used iff %ETHTOOL_ID_ACTIVE 762 | * is not supported) 763 | */ 764 | enum ethtool_phys_id_state { 765 | ETHTOOL_ID_INACTIVE, 766 | ETHTOOL_ID_ACTIVE, 767 | ETHTOOL_ID_ON, 768 | ETHTOOL_ID_OFF 769 | }; 770 | 771 | struct net_device; 772 | 773 | /* Some generic methods drivers may use in their ethtool_ops */ 774 | u32 ethtool_op_get_link(struct net_device *dev); 775 | u32 ethtool_op_get_tx_csum(struct net_device *dev); 776 | int ethtool_op_set_tx_csum(struct net_device *dev, u32 data); 777 | int ethtool_op_set_tx_hw_csum(struct net_device *dev, u32 data); 778 | int ethtool_op_set_tx_ipv6_csum(struct net_device *dev, u32 data); 779 | u32 ethtool_op_get_sg(struct net_device *dev); 780 | int ethtool_op_set_sg(struct net_device *dev, u32 data); 781 | u32 ethtool_op_get_tso(struct net_device *dev); 782 | int ethtool_op_set_tso(struct net_device *dev, u32 data); 783 | u32 ethtool_op_get_ufo(struct net_device *dev); 784 | int ethtool_op_set_ufo(struct net_device *dev, u32 data); 785 | u32 ethtool_op_get_flags(struct net_device *dev); 786 | int ethtool_op_set_flags(struct net_device *dev, u32 data, u32 supported); 787 | void ethtool_ntuple_flush(struct net_device *dev); 788 | bool ethtool_invalid_flags(struct net_device *dev, u32 data, u32 supported); 789 | 790 | /** 791 | * struct ethtool_ops - optional netdev operations 792 | * @get_settings: Get various device settings including Ethernet link 793 | * settings. The @cmd parameter is expected to have been cleared 794 | * before get_settings is called. Returns a negative error code or 795 | * zero. 796 | * @set_settings: Set various device settings including Ethernet link 797 | * settings. Returns a negative error code or zero. 798 | * @get_drvinfo: Report driver/device information. Should only set the 799 | * @driver, @version, @fw_version and @bus_info fields. If not 800 | * implemented, the @driver and @bus_info fields will be filled in 801 | * according to the netdev's parent device. 802 | * @get_regs_len: Get buffer length required for @get_regs 803 | * @get_regs: Get device registers 804 | * @get_wol: Report whether Wake-on-Lan is enabled 805 | * @set_wol: Turn Wake-on-Lan on or off. Returns a negative error code 806 | * or zero. 807 | * @get_msglevel: Report driver message level. This should be the value 808 | * of the @msg_enable field used by netif logging functions. 809 | * @set_msglevel: Set driver message level 810 | * @nway_reset: Restart autonegotiation. Returns a negative error code 811 | * or zero. 812 | * @get_link: Report whether physical link is up. Will only be called if 813 | * the netdev is up. Should usually be set to ethtool_op_get_link(), 814 | * which uses netif_carrier_ok(). 815 | * @get_eeprom: Read data from the device EEPROM. 816 | * Should fill in the magic field. Don't need to check len for zero 817 | * or wraparound. Fill in the data argument with the eeprom values 818 | * from offset to offset + len. Update len to the amount read. 819 | * Returns an error or zero. 820 | * @set_eeprom: Write data to the device EEPROM. 821 | * Should validate the magic field. Don't need to check len for zero 822 | * or wraparound. Update len to the amount written. Returns an error 823 | * or zero. 824 | * @get_coalesce: Get interrupt coalescing parameters. Returns a negative 825 | * error code or zero. 826 | * @set_coalesce: Set interrupt coalescing parameters. Returns a negative 827 | * error code or zero. 828 | * @get_ringparam: Report ring sizes 829 | * @set_ringparam: Set ring sizes. Returns a negative error code or zero. 830 | * @get_pauseparam: Report pause parameters 831 | * @set_pauseparam: Set pause parameters. Returns a negative error code 832 | * or zero. 833 | * @get_rx_csum: Deprecated in favour of the netdev feature %NETIF_F_RXCSUM. 834 | * Report whether receive checksums are turned on or off. 835 | * @set_rx_csum: Deprecated in favour of generic netdev features. Turn 836 | * receive checksum on or off. Returns a negative error code or zero. 837 | * @get_tx_csum: Deprecated as redundant. Report whether transmit checksums 838 | * are turned on or off. 839 | * @set_tx_csum: Deprecated in favour of generic netdev features. Turn 840 | * transmit checksums on or off. Returns a negative error code or zero. 841 | * @get_sg: Deprecated as redundant. Report whether scatter-gather is 842 | * enabled. 843 | * @set_sg: Deprecated in favour of generic netdev features. Turn 844 | * scatter-gather on or off. Returns a negative error code or zero. 845 | * @get_tso: Deprecated as redundant. Report whether TCP segmentation 846 | * offload is enabled. 847 | * @set_tso: Deprecated in favour of generic netdev features. Turn TCP 848 | * segmentation offload on or off. Returns a negative error code or zero. 849 | * @self_test: Run specified self-tests 850 | * @get_strings: Return a set of strings that describe the requested objects 851 | * @set_phys_id: Identify the physical devices, e.g. by flashing an LED 852 | * attached to it. The implementation may update the indicator 853 | * asynchronously or synchronously, but in either case it must return 854 | * quickly. It is initially called with the argument %ETHTOOL_ID_ACTIVE, 855 | * and must either activate asynchronous updates and return zero, return 856 | * a negative error or return a positive frequency for synchronous 857 | * indication (e.g. 1 for one on/off cycle per second). If it returns 858 | * a frequency then it will be called again at intervals with the 859 | * argument %ETHTOOL_ID_ON or %ETHTOOL_ID_OFF and should set the state of 860 | * the indicator accordingly. Finally, it is called with the argument 861 | * %ETHTOOL_ID_INACTIVE and must deactivate the indicator. Returns a 862 | * negative error code or zero. 863 | * @get_ethtool_stats: Return extended statistics about the device. 864 | * This is only useful if the device maintains statistics not 865 | * included in &struct rtnl_link_stats64. 866 | * @begin: Function to be called before any other operation. Returns a 867 | * negative error code or zero. 868 | * @complete: Function to be called after any other operation except 869 | * @begin. Will be called even if the other operation failed. 870 | * @get_ufo: Deprecated as redundant. Report whether UDP fragmentation 871 | * offload is enabled. 872 | * @set_ufo: Deprecated in favour of generic netdev features. Turn UDP 873 | * fragmentation offload on or off. Returns a negative error code or zero. 874 | * @get_flags: Deprecated as redundant. Report features included in 875 | * &enum ethtool_flags that are enabled. 876 | * @set_flags: Deprecated in favour of generic netdev features. Turn 877 | * features included in &enum ethtool_flags on or off. Returns a 878 | * negative error code or zero. 879 | * @get_priv_flags: Report driver-specific feature flags. 880 | * @set_priv_flags: Set driver-specific feature flags. Returns a negative 881 | * error code or zero. 882 | * @get_sset_count: Get number of strings that @get_strings will write. 883 | * @get_rxnfc: Get RX flow classification rules. Returns a negative 884 | * error code or zero. 885 | * @set_rxnfc: Set RX flow classification rules. Returns a negative 886 | * error code or zero. 887 | * @flash_device: Write a firmware image to device's flash memory. 888 | * Returns a negative error code or zero. 889 | * @reset: Reset (part of) the device, as specified by a bitmask of 890 | * flags from &enum ethtool_reset_flags. Returns a negative 891 | * error code or zero. 892 | * @set_rx_ntuple: Set an RX n-tuple rule. Returns a negative error code 893 | * or zero. 894 | * @get_rx_ntuple: Deprecated. 895 | * @get_rxfh_indir: Get the contents of the RX flow hash indirection table. 896 | * Returns a negative error code or zero. 897 | * @set_rxfh_indir: Set the contents of the RX flow hash indirection table. 898 | * Returns a negative error code or zero. 899 | * @get_channels: Get number of channels. 900 | * @set_channels: Set number of channels. Returns a negative error code or 901 | * zero. 902 | * @get_dump_flag: Get dump flag indicating current dump length, version, 903 | * and flag of the device. 904 | * @get_dump_data: Get dump data. 905 | * @set_dump: Set dump specific flags to the device. 906 | * 907 | * All operations are optional (i.e. the function pointer may be set 908 | * to %NULL) and callers must take this into account. Callers must 909 | * hold the RTNL, except that for @get_drvinfo the caller may or may 910 | * not hold the RTNL. 911 | * 912 | * See the structures used by these operations for further documentation. 913 | * 914 | * See &struct net_device and &struct net_device_ops for documentation 915 | * of the generic netdev features interface. 916 | */ 917 | struct ethtool_ops { 918 | int (*get_settings)(struct net_device *, struct ethtool_cmd *); 919 | int (*set_settings)(struct net_device *, struct ethtool_cmd *); 920 | void (*get_drvinfo)(struct net_device *, struct ethtool_drvinfo *); 921 | int (*get_regs_len)(struct net_device *); 922 | void (*get_regs)(struct net_device *, struct ethtool_regs *, void *); 923 | void (*get_wol)(struct net_device *, struct ethtool_wolinfo *); 924 | int (*set_wol)(struct net_device *, struct ethtool_wolinfo *); 925 | u32 (*get_msglevel)(struct net_device *); 926 | void (*set_msglevel)(struct net_device *, u32); 927 | int (*nway_reset)(struct net_device *); 928 | u32 (*get_link)(struct net_device *); 929 | int (*get_eeprom_len)(struct net_device *); 930 | int (*get_eeprom)(struct net_device *, 931 | struct ethtool_eeprom *, u8 *); 932 | int (*set_eeprom)(struct net_device *, 933 | struct ethtool_eeprom *, u8 *); 934 | int (*get_coalesce)(struct net_device *, struct ethtool_coalesce *); 935 | int (*set_coalesce)(struct net_device *, struct ethtool_coalesce *); 936 | void (*get_ringparam)(struct net_device *, 937 | struct ethtool_ringparam *); 938 | int (*set_ringparam)(struct net_device *, 939 | struct ethtool_ringparam *); 940 | void (*get_pauseparam)(struct net_device *, 941 | struct ethtool_pauseparam*); 942 | int (*set_pauseparam)(struct net_device *, 943 | struct ethtool_pauseparam*); 944 | u32 (*get_rx_csum)(struct net_device *); 945 | int (*set_rx_csum)(struct net_device *, u32); 946 | u32 (*get_tx_csum)(struct net_device *); 947 | int (*set_tx_csum)(struct net_device *, u32); 948 | u32 (*get_sg)(struct net_device *); 949 | int (*set_sg)(struct net_device *, u32); 950 | u32 (*get_tso)(struct net_device *); 951 | int (*set_tso)(struct net_device *, u32); 952 | void (*self_test)(struct net_device *, struct ethtool_test *, u64 *); 953 | void (*get_strings)(struct net_device *, u32 stringset, u8 *); 954 | int (*set_phys_id)(struct net_device *, enum ethtool_phys_id_state); 955 | void (*get_ethtool_stats)(struct net_device *, 956 | struct ethtool_stats *, u64 *); 957 | int (*begin)(struct net_device *); 958 | void (*complete)(struct net_device *); 959 | u32 (*get_ufo)(struct net_device *); 960 | int (*set_ufo)(struct net_device *, u32); 961 | u32 (*get_flags)(struct net_device *); 962 | int (*set_flags)(struct net_device *, u32); 963 | u32 (*get_priv_flags)(struct net_device *); 964 | int (*set_priv_flags)(struct net_device *, u32); 965 | int (*get_sset_count)(struct net_device *, int); 966 | int (*get_rxnfc)(struct net_device *, 967 | struct ethtool_rxnfc *, void *); 968 | int (*set_rxnfc)(struct net_device *, struct ethtool_rxnfc *); 969 | int (*flash_device)(struct net_device *, struct ethtool_flash *); 970 | int (*reset)(struct net_device *, u32 *); 971 | int (*set_rx_ntuple)(struct net_device *, 972 | struct ethtool_rx_ntuple *); 973 | int (*get_rx_ntuple)(struct net_device *, u32 stringset, void *); 974 | int (*get_rxfh_indir)(struct net_device *, 975 | struct ethtool_rxfh_indir *); 976 | int (*set_rxfh_indir)(struct net_device *, 977 | const struct ethtool_rxfh_indir *); 978 | void (*get_channels)(struct net_device *, struct ethtool_channels *); 979 | int (*set_channels)(struct net_device *, struct ethtool_channels *); 980 | int (*get_dump_flag)(struct net_device *, struct ethtool_dump *); 981 | int (*get_dump_data)(struct net_device *, 982 | struct ethtool_dump *, void *); 983 | int (*set_dump)(struct net_device *, struct ethtool_dump *); 984 | 985 | }; 986 | #endif /* __KERNEL__ */ 987 | 988 | /* CMDs currently supported */ 989 | #define ETHTOOL_GSET 0x00000001 /* Get settings. */ 990 | #define ETHTOOL_SSET 0x00000002 /* Set settings. */ 991 | #define ETHTOOL_GDRVINFO 0x00000003 /* Get driver info. */ 992 | #define ETHTOOL_GREGS 0x00000004 /* Get NIC registers. */ 993 | #define ETHTOOL_GWOL 0x00000005 /* Get wake-on-lan options. */ 994 | #define ETHTOOL_SWOL 0x00000006 /* Set wake-on-lan options. */ 995 | #define ETHTOOL_GMSGLVL 0x00000007 /* Get driver message level */ 996 | #define ETHTOOL_SMSGLVL 0x00000008 /* Set driver msg level. */ 997 | #define ETHTOOL_NWAY_RST 0x00000009 /* Restart autonegotiation. */ 998 | /* Get link status for host, i.e. whether the interface *and* the 999 | * physical port (if there is one) are up (ethtool_value). */ 1000 | #define ETHTOOL_GLINK 0x0000000a 1001 | #define ETHTOOL_GEEPROM 0x0000000b /* Get EEPROM data */ 1002 | #define ETHTOOL_SEEPROM 0x0000000c /* Set EEPROM data. */ 1003 | #define ETHTOOL_GCOALESCE 0x0000000e /* Get coalesce config */ 1004 | #define ETHTOOL_SCOALESCE 0x0000000f /* Set coalesce config. */ 1005 | #define ETHTOOL_GRINGPARAM 0x00000010 /* Get ring parameters */ 1006 | #define ETHTOOL_SRINGPARAM 0x00000011 /* Set ring parameters. */ 1007 | #define ETHTOOL_GPAUSEPARAM 0x00000012 /* Get pause parameters */ 1008 | #define ETHTOOL_SPAUSEPARAM 0x00000013 /* Set pause parameters. */ 1009 | #define ETHTOOL_GRXCSUM 0x00000014 /* Get RX hw csum enable (ethtool_value) */ 1010 | #define ETHTOOL_SRXCSUM 0x00000015 /* Set RX hw csum enable (ethtool_value) */ 1011 | #define ETHTOOL_GTXCSUM 0x00000016 /* Get TX hw csum enable (ethtool_value) */ 1012 | #define ETHTOOL_STXCSUM 0x00000017 /* Set TX hw csum enable (ethtool_value) */ 1013 | #define ETHTOOL_GSG 0x00000018 /* Get scatter-gather enable 1014 | * (ethtool_value) */ 1015 | #define ETHTOOL_SSG 0x00000019 /* Set scatter-gather enable 1016 | * (ethtool_value). */ 1017 | #define ETHTOOL_TEST 0x0000001a /* execute NIC self-test. */ 1018 | #define ETHTOOL_GSTRINGS 0x0000001b /* get specified string set */ 1019 | #define ETHTOOL_PHYS_ID 0x0000001c /* identify the NIC */ 1020 | #define ETHTOOL_GSTATS 0x0000001d /* get NIC-specific statistics */ 1021 | #define ETHTOOL_GTSO 0x0000001e /* Get TSO enable (ethtool_value) */ 1022 | #define ETHTOOL_STSO 0x0000001f /* Set TSO enable (ethtool_value) */ 1023 | #define ETHTOOL_GPERMADDR 0x00000020 /* Get permanent hardware address */ 1024 | #define ETHTOOL_GUFO 0x00000021 /* Get UFO enable (ethtool_value) */ 1025 | #define ETHTOOL_SUFO 0x00000022 /* Set UFO enable (ethtool_value) */ 1026 | #define ETHTOOL_GGSO 0x00000023 /* Get GSO enable (ethtool_value) */ 1027 | #define ETHTOOL_SGSO 0x00000024 /* Set GSO enable (ethtool_value) */ 1028 | #define ETHTOOL_GFLAGS 0x00000025 /* Get flags bitmap(ethtool_value) */ 1029 | #define ETHTOOL_SFLAGS 0x00000026 /* Set flags bitmap(ethtool_value) */ 1030 | #define ETHTOOL_GPFLAGS 0x00000027 /* Get driver-private flags bitmap */ 1031 | #define ETHTOOL_SPFLAGS 0x00000028 /* Set driver-private flags bitmap */ 1032 | 1033 | #define ETHTOOL_GRXFH 0x00000029 /* Get RX flow hash configuration */ 1034 | #define ETHTOOL_SRXFH 0x0000002a /* Set RX flow hash configuration */ 1035 | #define ETHTOOL_GGRO 0x0000002b /* Get GRO enable (ethtool_value) */ 1036 | #define ETHTOOL_SGRO 0x0000002c /* Set GRO enable (ethtool_value) */ 1037 | #define ETHTOOL_GRXRINGS 0x0000002d /* Get RX rings available for LB */ 1038 | #define ETHTOOL_GRXCLSRLCNT 0x0000002e /* Get RX class rule count */ 1039 | #define ETHTOOL_GRXCLSRULE 0x0000002f /* Get RX classification rule */ 1040 | #define ETHTOOL_GRXCLSRLALL 0x00000030 /* Get all RX classification rule */ 1041 | #define ETHTOOL_SRXCLSRLDEL 0x00000031 /* Delete RX classification rule */ 1042 | #define ETHTOOL_SRXCLSRLINS 0x00000032 /* Insert RX classification rule */ 1043 | #define ETHTOOL_FLASHDEV 0x00000033 /* Flash firmware to device */ 1044 | #define ETHTOOL_RESET 0x00000034 /* Reset hardware */ 1045 | #define ETHTOOL_SRXNTUPLE 0x00000035 /* Add an n-tuple filter to device */ 1046 | #define ETHTOOL_GRXNTUPLE 0x00000036 /* Get n-tuple filters from device */ 1047 | #define ETHTOOL_GSSET_INFO 0x00000037 /* Get string set info */ 1048 | #define ETHTOOL_GRXFHINDIR 0x00000038 /* Get RX flow hash indir'n table */ 1049 | #define ETHTOOL_SRXFHINDIR 0x00000039 /* Set RX flow hash indir'n table */ 1050 | 1051 | #define ETHTOOL_GFEATURES 0x0000003a /* Get device offload settings */ 1052 | #define ETHTOOL_SFEATURES 0x0000003b /* Change device offload settings */ 1053 | #define ETHTOOL_GCHANNELS 0x0000003c /* Get no of channels */ 1054 | #define ETHTOOL_SCHANNELS 0x0000003d /* Set no of channels */ 1055 | #define ETHTOOL_SET_DUMP 0x0000003e /* Set dump settings */ 1056 | #define ETHTOOL_GET_DUMP_FLAG 0x0000003f /* Get dump settings */ 1057 | #define ETHTOOL_GET_DUMP_DATA 0x00000040 /* Get dump data */ 1058 | 1059 | /* compatibility with older code */ 1060 | #define SPARC_ETH_GSET ETHTOOL_GSET 1061 | #define SPARC_ETH_SSET ETHTOOL_SSET 1062 | 1063 | /* Indicates what features are supported by the interface. */ 1064 | #define SUPPORTED_10baseT_Half (1 << 0) 1065 | #define SUPPORTED_10baseT_Full (1 << 1) 1066 | #define SUPPORTED_100baseT_Half (1 << 2) 1067 | #define SUPPORTED_100baseT_Full (1 << 3) 1068 | #define SUPPORTED_1000baseT_Half (1 << 4) 1069 | #define SUPPORTED_1000baseT_Full (1 << 5) 1070 | #define SUPPORTED_Autoneg (1 << 6) 1071 | #define SUPPORTED_TP (1 << 7) 1072 | #define SUPPORTED_AUI (1 << 8) 1073 | #define SUPPORTED_MII (1 << 9) 1074 | #define SUPPORTED_FIBRE (1 << 10) 1075 | #define SUPPORTED_BNC (1 << 11) 1076 | #define SUPPORTED_10000baseT_Full (1 << 12) 1077 | #define SUPPORTED_Pause (1 << 13) 1078 | #define SUPPORTED_Asym_Pause (1 << 14) 1079 | #define SUPPORTED_2500baseX_Full (1 << 15) 1080 | #define SUPPORTED_Backplane (1 << 16) 1081 | #define SUPPORTED_1000baseKX_Full (1 << 17) 1082 | #define SUPPORTED_10000baseKX4_Full (1 << 18) 1083 | #define SUPPORTED_10000baseKR_Full (1 << 19) 1084 | #define SUPPORTED_10000baseR_FEC (1 << 20) 1085 | #define SUPPORTED_20000baseMLD2_Full (1 << 21) 1086 | #define SUPPORTED_20000baseKR2_Full (1 << 22) 1087 | 1088 | /* Indicates what features are advertised by the interface. */ 1089 | #define ADVERTISED_10baseT_Half (1 << 0) 1090 | #define ADVERTISED_10baseT_Full (1 << 1) 1091 | #define ADVERTISED_100baseT_Half (1 << 2) 1092 | #define ADVERTISED_100baseT_Full (1 << 3) 1093 | #define ADVERTISED_1000baseT_Half (1 << 4) 1094 | #define ADVERTISED_1000baseT_Full (1 << 5) 1095 | #define ADVERTISED_Autoneg (1 << 6) 1096 | #define ADVERTISED_TP (1 << 7) 1097 | #define ADVERTISED_AUI (1 << 8) 1098 | #define ADVERTISED_MII (1 << 9) 1099 | #define ADVERTISED_FIBRE (1 << 10) 1100 | #define ADVERTISED_BNC (1 << 11) 1101 | #define ADVERTISED_10000baseT_Full (1 << 12) 1102 | #define ADVERTISED_Pause (1 << 13) 1103 | #define ADVERTISED_Asym_Pause (1 << 14) 1104 | #define ADVERTISED_2500baseX_Full (1 << 15) 1105 | #define ADVERTISED_Backplane (1 << 16) 1106 | #define ADVERTISED_1000baseKX_Full (1 << 17) 1107 | #define ADVERTISED_10000baseKX4_Full (1 << 18) 1108 | #define ADVERTISED_10000baseKR_Full (1 << 19) 1109 | #define ADVERTISED_10000baseR_FEC (1 << 20) 1110 | #define ADVERTISED_20000baseMLD2_Full (1 << 21) 1111 | #define ADVERTISED_20000baseKR2_Full (1 << 22) 1112 | 1113 | /* The following are all involved in forcing a particular link 1114 | * mode for the device for setting things. When getting the 1115 | * devices settings, these indicate the current mode and whether 1116 | * it was forced up into this mode or autonegotiated. 1117 | */ 1118 | 1119 | /* The forced speed, 10Mb, 100Mb, gigabit, 2.5Gb, 10GbE. */ 1120 | #define SPEED_10 10 1121 | #define SPEED_100 100 1122 | #define SPEED_1000 1000 1123 | #define SPEED_2500 2500 1124 | #define SPEED_10000 10000 1125 | 1126 | /* Duplex, half or full. */ 1127 | #define DUPLEX_HALF 0x00 1128 | #define DUPLEX_FULL 0x01 1129 | 1130 | /* Which connector port. */ 1131 | #define PORT_TP 0x00 1132 | #define PORT_AUI 0x01 1133 | #define PORT_MII 0x02 1134 | #define PORT_FIBRE 0x03 1135 | #define PORT_BNC 0x04 1136 | #define PORT_DA 0x05 1137 | #define PORT_NONE 0xef 1138 | #define PORT_OTHER 0xff 1139 | 1140 | /* Which transceiver to use. */ 1141 | #define XCVR_INTERNAL 0x00 1142 | #define XCVR_EXTERNAL 0x01 1143 | #define XCVR_DUMMY1 0x02 1144 | #define XCVR_DUMMY2 0x03 1145 | #define XCVR_DUMMY3 0x04 1146 | 1147 | /* Enable or disable autonegotiation. If this is set to enable, 1148 | * the forced link modes above are completely ignored. 1149 | */ 1150 | #define AUTONEG_DISABLE 0x00 1151 | #define AUTONEG_ENABLE 0x01 1152 | 1153 | /* Mode MDI or MDI-X */ 1154 | #define ETH_TP_MDI_INVALID 0x00 1155 | #define ETH_TP_MDI 0x01 1156 | #define ETH_TP_MDI_X 0x02 1157 | 1158 | /* Wake-On-Lan options. */ 1159 | #define WAKE_PHY (1 << 0) 1160 | #define WAKE_UCAST (1 << 1) 1161 | #define WAKE_MCAST (1 << 2) 1162 | #define WAKE_BCAST (1 << 3) 1163 | #define WAKE_ARP (1 << 4) 1164 | #define WAKE_MAGIC (1 << 5) 1165 | #define WAKE_MAGICSECURE (1 << 6) /* only meaningful if WAKE_MAGIC */ 1166 | 1167 | /* L2-L4 network traffic flow types */ 1168 | #define TCP_V4_FLOW 0x01 /* hash or spec (tcp_ip4_spec) */ 1169 | #define UDP_V4_FLOW 0x02 /* hash or spec (udp_ip4_spec) */ 1170 | #define SCTP_V4_FLOW 0x03 /* hash or spec (sctp_ip4_spec) */ 1171 | #define AH_ESP_V4_FLOW 0x04 /* hash only */ 1172 | #define TCP_V6_FLOW 0x05 /* hash only */ 1173 | #define UDP_V6_FLOW 0x06 /* hash only */ 1174 | #define SCTP_V6_FLOW 0x07 /* hash only */ 1175 | #define AH_ESP_V6_FLOW 0x08 /* hash only */ 1176 | #define AH_V4_FLOW 0x09 /* hash or spec (ah_ip4_spec) */ 1177 | #define ESP_V4_FLOW 0x0a /* hash or spec (esp_ip4_spec) */ 1178 | #define AH_V6_FLOW 0x0b /* hash only */ 1179 | #define ESP_V6_FLOW 0x0c /* hash only */ 1180 | #define IP_USER_FLOW 0x0d /* spec only (usr_ip4_spec) */ 1181 | #define IPV4_FLOW 0x10 /* hash only */ 1182 | #define IPV6_FLOW 0x11 /* hash only */ 1183 | #define ETHER_FLOW 0x12 /* spec only (ether_spec) */ 1184 | /* Flag to enable additional fields in struct ethtool_rx_flow_spec */ 1185 | #define FLOW_EXT 0x80000000 1186 | 1187 | /* L3-L4 network traffic flow hash options */ 1188 | #define RXH_L2DA (1 << 1) 1189 | #define RXH_VLAN (1 << 2) 1190 | #define RXH_L3_PROTO (1 << 3) 1191 | #define RXH_IP_SRC (1 << 4) 1192 | #define RXH_IP_DST (1 << 5) 1193 | #define RXH_L4_B_0_1 (1 << 6) /* src port in case of TCP/UDP/SCTP */ 1194 | #define RXH_L4_B_2_3 (1 << 7) /* dst port in case of TCP/UDP/SCTP */ 1195 | #define RXH_DISCARD (1 << 31) 1196 | 1197 | #define RX_CLS_FLOW_DISC 0xffffffffffffffffULL 1198 | 1199 | /* Reset flags */ 1200 | /* The reset() operation must clear the flags for the components which 1201 | * were actually reset. On successful return, the flags indicate the 1202 | * components which were not reset, either because they do not exist 1203 | * in the hardware or because they cannot be reset independently. The 1204 | * driver must never reset any components that were not requested. 1205 | */ 1206 | enum ethtool_reset_flags { 1207 | /* These flags represent components dedicated to the interface 1208 | * the command is addressed to. Shift any flag left by 1209 | * ETH_RESET_SHARED_SHIFT to reset a shared component of the 1210 | * same type. 1211 | */ 1212 | ETH_RESET_MGMT = 1 << 0, /* Management processor */ 1213 | ETH_RESET_IRQ = 1 << 1, /* Interrupt requester */ 1214 | ETH_RESET_DMA = 1 << 2, /* DMA engine */ 1215 | ETH_RESET_FILTER = 1 << 3, /* Filtering/flow direction */ 1216 | ETH_RESET_OFFLOAD = 1 << 4, /* Protocol offload */ 1217 | ETH_RESET_MAC = 1 << 5, /* Media access controller */ 1218 | ETH_RESET_PHY = 1 << 6, /* Transceiver/PHY */ 1219 | ETH_RESET_RAM = 1 << 7, /* RAM shared between 1220 | * multiple components */ 1221 | 1222 | ETH_RESET_DEDICATED = 0x0000ffff, /* All components dedicated to 1223 | * this interface */ 1224 | ETH_RESET_ALL = 0xffffffff, /* All components used by this 1225 | * interface, even if shared */ 1226 | }; 1227 | #define ETH_RESET_SHARED_SHIFT 16 1228 | 1229 | #endif /* _LINUX_ETHTOOL_H */ 1230 | 1231 | #endif 1232 | --------------------------------------------------------------------------------