Skip to content

Commit

Permalink
Update HW part according new e1000e sources (#3)
Browse files Browse the repository at this point in the history
Update hardware routines according new e1000e sources
Fixed WoL on I219 family devices
Use Random RSS key hash generation instead of static
Fix IRQ mask for Cannon-Point devices
Adjusted debug log
  • Loading branch information
savvamitrofanov committed Jan 4, 2021
1 parent f4c3a43 commit a2078d8
Show file tree
Hide file tree
Showing 7 changed files with 1,885 additions and 1,556 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Expand Up @@ -19,6 +19,10 @@ IntelMausi Changelog
* I219-V18
* I219-LM19
* I219-V19
- Fixed WoL on I219 family devices
- Use Random RSS key hash generation instead of static
- Fix IRQ mask for Cannon-Point devices
- Adjusted debug log

#### v1.0.4
- Added MacKernelSDK with Xcode 12 compatibility
Expand Down
1,046 changes: 526 additions & 520 deletions IntelMausiEthernet/IntelMausiEthernet.cpp

Large diffs are not rendered by default.

174 changes: 89 additions & 85 deletions IntelMausiEthernet/IntelMausiEthernet.h
Expand Up @@ -29,7 +29,7 @@ extern "C" {
#define DebugLog(args...)
#endif

#define RELEASE(x) if(x){(x)->release();(x)=NULL;}
#define RELEASE(x) if(x){(x)->release();(x)=NULL;}

#define intelWriteMem8(reg, val8) _OSWriteInt8((baseAddr), (reg), (val8))
#define intelWriteMem16(reg, val16) OSWriteLittleInt16((baseAddr), (reg), (val16))
Expand All @@ -39,14 +39,17 @@ extern "C" {
#define intelReadMem32(reg) OSReadLittleInt32((baseAddr), (reg))
#define intelFlush() OSReadLittleInt32((baseAddr), (E1000_STATUS))

/* RSS keys are 40 or 52 bytes long */
#define INTEL_RSS_KEY_LEN 52

#define super IOEthernetController

enum
{
MEDIUM_INDEX_AUTO = 0,
MEDIUM_INDEX_10HD,
MEDIUM_INDEX_10FD,
MEDIUM_INDEX_100HD,
MEDIUM_INDEX_AUTO = 0,
MEDIUM_INDEX_10HD,
MEDIUM_INDEX_10FD,
MEDIUM_INDEX_100HD,
MEDIUM_INDEX_100FD,
MEDIUM_INDEX_100FDFC,
MEDIUM_INDEX_1000FD,
Expand All @@ -55,7 +58,7 @@ enum
MEDIUM_INDEX_1000FDFCEEE,
MEDIUM_INDEX_100FDEEE,
MEDIUM_INDEX_100FDFCEEE,
MEDIUM_INDEX_COUNT
MEDIUM_INDEX_COUNT
};

#define MBit 1000000
Expand Down Expand Up @@ -164,20 +167,20 @@ enum {

/* mask to determine if packets should be dropped due to frame errors */
#define E1000_RXDLGC_ERR_FRAME_ERR_MASK ( \
E1000_RXDLGC_ERR_CE | \
E1000_RXDLGC_ERR_SE | \
E1000_RXDLGC_ERR_SEQ | \
E1000_RXDLGC_ERR_CXE | \
E1000_RXDLGC_ERR_CE | \
E1000_RXDLGC_ERR_SE | \
E1000_RXDLGC_ERR_SEQ | \
E1000_RXDLGC_ERR_CXE | \
E1000_RXDLGC_ERR_RXE)

#define E1000_TX_FLAGS_CSUM 0x00000001
#define E1000_TX_FLAGS_VLAN 0x00000002
#define E1000_TX_FLAGS_TSO 0x00000004
#define E1000_TX_FLAGS_IPV4 0x00000008
#define E1000_TX_FLAGS_NO_FCS 0x00000010
#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
#define E1000_TX_FLAGS_VLAN_SHIFT 16
#define E1000_TX_FLAGS_CSUM 0x00000001
#define E1000_TX_FLAGS_VLAN 0x00000002
#define E1000_TX_FLAGS_TSO 0x00000004
#define E1000_TX_FLAGS_IPV4 0x00000008
#define E1000_TX_FLAGS_NO_FCS 0x00000010
#define E1000_TX_FLAGS_HWTSTAMP 0x00000020
#define E1000_TX_FLAGS_VLAN_MASK 0xffff0000
#define E1000_TX_FLAGS_VLAN_SHIFT 16

#define E1000_TXD_OPTS_IXSM 0x00000100
#define E1000_TXD_OPTS_TXSM 0x00000200
Expand Down Expand Up @@ -299,22 +302,22 @@ struct IntelAddrData {

class IntelMausi : public super
{
OSDeclareDefaultStructors(IntelMausi)

OSDeclareDefaultStructors(IntelMausi)

public:
/* IOService (or its superclass) methods. */
virtual bool start(IOService *provider) APPLE_KEXT_OVERRIDE;
virtual void stop(IOService *provider) APPLE_KEXT_OVERRIDE;
virtual bool init(OSDictionary *properties) APPLE_KEXT_OVERRIDE;
virtual void free() APPLE_KEXT_OVERRIDE;
/* Power Management Support */
virtual IOReturn registerWithPolicyMaker(IOService *policyMaker) APPLE_KEXT_OVERRIDE;
/* IOService (or its superclass) methods. */
virtual bool start(IOService *provider) APPLE_KEXT_OVERRIDE;
virtual void stop(IOService *provider) APPLE_KEXT_OVERRIDE;
virtual bool init(OSDictionary *properties) APPLE_KEXT_OVERRIDE;
virtual void free() APPLE_KEXT_OVERRIDE;

/* Power Management Support */
virtual IOReturn registerWithPolicyMaker(IOService *policyMaker) APPLE_KEXT_OVERRIDE;
virtual IOReturn setPowerState(unsigned long powerStateOrdinal, IOService *policyMaker) APPLE_KEXT_OVERRIDE;
virtual void systemWillShutdown(IOOptionBits specifier) APPLE_KEXT_OVERRIDE;
/* IONetworkController methods. */
virtual void systemWillShutdown(IOOptionBits specifier) APPLE_KEXT_OVERRIDE;

/* IONetworkController methods. */
virtual IOReturn enable(IONetworkInterface *netif) APPLE_KEXT_OVERRIDE;
virtual IOReturn disable(IONetworkInterface *netif) APPLE_KEXT_OVERRIDE;
virtual IOReturn enable(IOKernelDebugger *debugger) APPLE_KEXT_OVERRIDE;
Expand All @@ -330,31 +333,31 @@ class IntelMausi : public super
#else
virtual UInt32 outputPacket(mbuf_t m, void *param) APPLE_KEXT_OVERRIDE;
#endif /* __PRIVATE_SPI__ */
virtual void getPacketBufferConstraints(IOPacketBufferConstraints *constraints) const APPLE_KEXT_OVERRIDE;
virtual IOOutputQueue* createOutputQueue() APPLE_KEXT_OVERRIDE;
virtual const OSString* newVendorString() const APPLE_KEXT_OVERRIDE;
virtual const OSString* newModelString() const APPLE_KEXT_OVERRIDE;
virtual IOReturn selectMedium(const IONetworkMedium *medium) APPLE_KEXT_OVERRIDE;
virtual bool configureInterface(IONetworkInterface *interface) APPLE_KEXT_OVERRIDE;
virtual bool createWorkLoop() APPLE_KEXT_OVERRIDE;
virtual IOWorkLoop* getWorkLoop() const APPLE_KEXT_OVERRIDE;
/* Methods inherited from IOEthernetController. */
virtual IOReturn getHardwareAddress(IOEthernetAddress *addr) APPLE_KEXT_OVERRIDE;
virtual IOReturn setHardwareAddress(const IOEthernetAddress *addr) APPLE_KEXT_OVERRIDE;
virtual IOReturn setPromiscuousMode(bool active) APPLE_KEXT_OVERRIDE;
virtual IOReturn setMulticastMode(bool active) APPLE_KEXT_OVERRIDE;
virtual IOReturn setMulticastList(IOEthernetAddress *addrs, UInt32 count) APPLE_KEXT_OVERRIDE;
virtual IOReturn getChecksumSupport(UInt32 *checksumMask, UInt32 checksumFamily, bool isOutput) APPLE_KEXT_OVERRIDE;
virtual IOReturn getMinPacketSize(UInt32 *minSize) const APPLE_KEXT_OVERRIDE;

virtual void getPacketBufferConstraints(IOPacketBufferConstraints *constraints) const APPLE_KEXT_OVERRIDE;

virtual IOOutputQueue* createOutputQueue() APPLE_KEXT_OVERRIDE;

virtual const OSString* newVendorString() const APPLE_KEXT_OVERRIDE;
virtual const OSString* newModelString() const APPLE_KEXT_OVERRIDE;

virtual IOReturn selectMedium(const IONetworkMedium *medium) APPLE_KEXT_OVERRIDE;
virtual bool configureInterface(IONetworkInterface *interface) APPLE_KEXT_OVERRIDE;

virtual bool createWorkLoop() APPLE_KEXT_OVERRIDE;
virtual IOWorkLoop* getWorkLoop() const APPLE_KEXT_OVERRIDE;

/* Methods inherited from IOEthernetController. */
virtual IOReturn getHardwareAddress(IOEthernetAddress *addr) APPLE_KEXT_OVERRIDE;
virtual IOReturn setHardwareAddress(const IOEthernetAddress *addr) APPLE_KEXT_OVERRIDE;
virtual IOReturn setPromiscuousMode(bool active) APPLE_KEXT_OVERRIDE;
virtual IOReturn setMulticastMode(bool active) APPLE_KEXT_OVERRIDE;
virtual IOReturn setMulticastList(IOEthernetAddress *addrs, UInt32 count) APPLE_KEXT_OVERRIDE;
virtual IOReturn getChecksumSupport(UInt32 *checksumMask, UInt32 checksumFamily, bool isOutput) APPLE_KEXT_OVERRIDE;
virtual IOReturn getMinPacketSize(UInt32 *minSize) const APPLE_KEXT_OVERRIDE;
virtual IOReturn setWakeOnMagicPacket(bool active) APPLE_KEXT_OVERRIDE;
virtual IOReturn getPacketFilters(const OSSymbol *group, UInt32 *filters) const APPLE_KEXT_OVERRIDE;

virtual UInt32 getFeatures() const APPLE_KEXT_OVERRIDE;
virtual IOReturn getMaxPacketSize(UInt32 * maxSize) const APPLE_KEXT_OVERRIDE;
virtual IOReturn setMaxPacketSize(UInt32 maxSize) APPLE_KEXT_OVERRIDE;
Expand Down Expand Up @@ -390,17 +393,15 @@ class IntelMausi : public super
void setLinkUp();
void setLinkDown();
bool checkForDeadlock();

/* Jumbo frame support methods */
void discardPacketFragment(bool extended = false);

/* Hardware specific methods */
bool intelIdentifyChip();
bool intelStart();
void intelEEPROMChecks(struct e1000_adapter *adapter);
void intelInitTxRing();
void intelInitRxRing();
void intelEnableIRQ(UInt32 newMask);
void intelEnableIRQ(struct e1000_adapter *adapter);
void intelDisableIRQ();
void intelUpdateTxDescTail(UInt32 index);
void intelUpdateRxDescTail(UInt32 index);
Expand All @@ -420,6 +421,7 @@ class IntelMausi : public super
void intelUpdateAdaptive(struct e1000_hw *hw);
void intelVlanStripDisable(struct e1000_adapter *adapter);
void intelVlanStripEnable(struct e1000_adapter *adapter);
void intelRssKeyFill(void *buffer, size_t len);
void intelSetupRssHash(struct e1000_adapter *adapter);

void intelRestart();
Expand All @@ -434,33 +436,33 @@ class IntelMausi : public super
void intelSetupAdvForMedium(const IONetworkMedium *medium);
void intelFlushLPIC();
void setMaxLatency(UInt32 linkSpeed);

UInt16 intelSupportsEEE(struct e1000_adapter *adapter);
SInt32 intelEnableEEE(struct e1000_hw *hw, UInt16 mode);

inline void intelGetChecksumResult(mbuf_t m, UInt32 status);

void getAddressList(struct IntelAddrData *addr);

/* timer action */
void timerAction(IOTimerEventSource *timer);

private:
IOWorkLoop *workLoop;
IOWorkLoop *workLoop;
IOCommandGate *commandGate;
IOPCIDevice *pciDevice;
OSDictionary *mediumDict;
IONetworkMedium *mediumTable[MEDIUM_INDEX_COUNT];
IOBasicOutputQueue *txQueue;
IOInterruptEventSource *interruptSource;
IOTimerEventSource *timerSource;
IOEthernetInterface *netif;
IOMemoryMap *baseMap;
IOPCIDevice *pciDevice;
OSDictionary *mediumDict;
IONetworkMedium *mediumTable[MEDIUM_INDEX_COUNT];
IOBasicOutputQueue *txQueue;

IOInterruptEventSource *interruptSource;
IOTimerEventSource *timerSource;
IOEthernetInterface *netif;
IOMemoryMap *baseMap;
volatile void *baseAddr;
IOMemoryMap *flashMap;
IOMemoryMap *flashMap;
volatile void *flashAddr;

/* transmitter data */
IODMACommand *txDescDmaCmd;
IOBufferMemoryDescriptor *txBufDesc;
Expand All @@ -475,32 +477,31 @@ class IntelMausi : public super
UInt16 txNextDescIndex;
UInt16 txDirtyIndex;
UInt16 txCleanBarrierIndex;

/* receiver data */
IODMACommand *rxDescDmaCmd;
IOBufferMemoryDescriptor *rxBufDesc;
IOPhysicalAddress64 rxPhyAddr;
union e1000_rx_desc_extended *rxDescArray;
IOMbufNaturalMemoryCursor *rxMbufCursor;
IOMbufNaturalMemoryCursor *rxMbufCursor;
mbuf_t rxPacketHead;
mbuf_t rxPacketTail;
UInt32 rxPacketSize;
IOEthernetAddress *mcAddrList;
UInt32 mcListCount;
UInt16 rxNextDescIndex;
UInt16 rxCleanedCount;

/* power management data */
unsigned long powerState;

/* statistics data */
UInt32 deadlockWarn;
IONetworkStats *netStats;
IOEthernetStats *etherStats;
IOEthernetStats *etherStats;

UInt32 chip;
UInt32 chipType;
UInt32 intrMask;
UInt32 intrThrValue10;
UInt32 intrThrValue100;
UInt32 intrThrValue1000;
Expand All @@ -519,14 +520,17 @@ class IntelMausi : public super
UInt8 pcieCapOffset;
UInt8 pciPMCtrlOffset;

UInt8 rssHashKey[INTEL_RSS_KEY_LEN];

#ifdef __PRIVATE_SPI__
IONetworkPacketPollingParameters pollParams;
#endif /* __PRIVATE_SPI__ */

/* flags */
bool isRssSet;
bool isEnabled;
bool promiscusMode;
bool multicastMode;
bool promiscusMode;
bool multicastMode;
bool linkUp;

#ifdef __PRIVATE_SPI__
Expand All @@ -540,7 +544,7 @@ class IntelMausi : public super
bool wolActive;
bool enableCSO6;
bool enableWoM;

/* mbuf_t arrays */
struct intelTxBufferInfo txBufArray[kNumTxDesc];
struct intelRxBufferInfo rxBufArray[kNumRxDesc];
Expand Down
2 changes: 1 addition & 1 deletion IntelMausiEthernet/IntelMausiEthernetV2-Prefix.pch
Expand Up @@ -28,7 +28,7 @@ extern "C" {
#include <sys/appleapiopts.h>
#include <sys/errno.h>
#include <sys/kpi_mbuf.h>

#ifdef __cplusplus
}
#endif // __cplusplus
Expand Down

0 comments on commit a2078d8

Please sign in to comment.