Skip to content

Commit

Permalink
Try to fix missing connection in monterey with disableMSI on
Browse files Browse the repository at this point in the history
  • Loading branch information
Benau committed Apr 5, 2022
1 parent 549d404 commit fcd42d6
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
2 changes: 2 additions & 0 deletions RealtekRTL8111/RealtekRTL8111-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
<string>com.insanelymac.${PRODUCT_NAME:rfc1034identifier}</string>
<key>Driver Parameters</key>
<dict>
<key>disableMSI</key>
<false/>
<key>disableASPM</key>
<true/>
<key>enableCSO6</key>
Expand Down
61 changes: 53 additions & 8 deletions RealtekRTL8111/RealtekRTL8111.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ bool RTL8111::init(OSDictionary *properties)
mediumDict = NULL;
txQueue = NULL;
interruptSource = NULL;
interruptSimulationSource = NULL;
timerSource = NULL;
netif = NULL;
netStats = NULL;
Expand All @@ -65,7 +66,8 @@ bool RTL8111::init(OSDictionary *properties)
promiscusMode = false;
multicastMode = false;
linkUp = false;


disableMSI = false;
rxPoll = false;
polling = false;

Expand Down Expand Up @@ -117,6 +119,10 @@ void RTL8111::free()
workLoop->removeEventSource(timerSource);
RELEASE(timerSource);
}
if (interruptSimulationSource) {
workLoop->removeEventSource(interruptSimulationSource);
RELEASE(interruptSimulationSource);
}
workLoop->release();
workLoop = NULL;
}
Expand Down Expand Up @@ -244,6 +250,10 @@ void RTL8111::stop(IOService *provider)
workLoop->removeEventSource(timerSource);
RELEASE(timerSource);
}
if (interruptSimulationSource) {
workLoop->removeEventSource(interruptSimulationSource);
RELEASE(interruptSimulationSource);
}
workLoop->release();
workLoop = NULL;
}
Expand Down Expand Up @@ -353,7 +363,8 @@ IOReturn RTL8111::enable(IONetworkInterface *netif)
enableRTL8111();

/* We have to enable the interrupt because we are using a msi interrupt. */
interruptSource->enable();
if (interruptSource)
interruptSource->enable();

rxPacketHead = rxPacketTail = NULL;
rxPacketSize = 0;
Expand All @@ -365,7 +376,9 @@ IOReturn RTL8111::enable(IONetworkInterface *netif)

if (!revisionC)
timerSource->setTimeoutMS(kTimeoutMS);

if (interruptSimulationSource)
interruptSimulationSource->setTimeoutMS(1);

result = kIOReturnSuccess;

DebugLog("enable() <===\n");
Expand All @@ -390,11 +403,13 @@ IOReturn RTL8111::disable(IONetworkInterface *netif)
isEnabled = false;

timerSource->cancelTimeout();
if (interruptSimulationSource)
interruptSimulationSource->cancelTimeout();

needsUpdate = false;
txDescDoneCount = txDescDoneLast = 0;

/* Disable interrupt as we are using msi. */
interruptSource->disable();

disableRTL8111();

Expand Down Expand Up @@ -1095,6 +1110,7 @@ void RTL8111::getParams()
OSDictionary *params;
OSNumber *intrMit;
OSBoolean *poll;
OSBoolean *noMSI;
OSBoolean *tso4;
OSBoolean *tso6;
OSBoolean *csoV6;
Expand All @@ -1111,7 +1127,12 @@ void RTL8111::getParams()
disableASPM = (noASPM) ? noASPM->getValue() : false;

DebugLog("[RealtekRTL8111]: PCIe ASPM support %s.\n", disableASPM ? offName : onName);

noMSI = OSDynamicCast(OSBoolean, params->getObject(kDisableMSIName));
disableMSI = (noMSI) ? noMSI->getValue() : false;

IOLog("[RealtekRTL8111]: Using msi %s.\n", disableMSI ? offName : onName);

poll = OSDynamicCast(OSBoolean, params->getObject(kEnableRxPollName));
rxPoll = (poll) ? poll->getValue() : false;

Expand Down Expand Up @@ -1154,6 +1175,7 @@ void RTL8111::getParams()
}
} else {
disableASPM = true;
disableMSI = false;
rxPoll = true;
enableTSO4 = true;
enableTSO6 = true;
Expand Down Expand Up @@ -1261,21 +1283,35 @@ bool RTL8111::initEventSources(IOService *provider)
}
intrIndex++;
}
if (msiIndex != -1) {
if (msiIndex != -1 && !disableMSI) {
DebugLog("[RealtekRTL8111]: MSI interrupt index: %d\n", msiIndex);

if (rxPoll) {
interruptSource = IOInterruptEventSource::interruptEventSource(this, OSMemberFunctionCast(IOInterruptEventSource::Action, this, &RTL8111::interruptOccurredPoll), provider, msiIndex);
} else {
interruptSource = IOInterruptEventSource::interruptEventSource(this, OSMemberFunctionCast(IOInterruptEventSource::Action, this, &RTL8111::interruptOccurred), provider, msiIndex);
}
if (interruptSource)
workLoop->addEventSource(interruptSource);
}
if (!interruptSource) {

if (!interruptSource && !disableMSI) {
IOLog("[RealtekRTL8111]: Error: MSI index was not found or MSI interrupt could not be enabled.\n");
goto error1;
}
workLoop->addEventSource(interruptSource);


if (disableMSI) {
DebugLog("[RealtekRTL8111]: Using MSI interrupt simulation.\n");

interruptSimulationSource = IOTimerEventSource::timerEventSource(this, OSMemberFunctionCast(IOTimerEventSource::Action, this, &RTL8111::interruptSimulation));
if (!interruptSimulationSource) {
IOLog("[RealtekRTL8111]: Error: MSI interrupt simulation could not be enabled.\n");
goto error1;
}
interruptSimulationSource->setTimeoutMS(1);
workLoop->addEventSource(interruptSimulationSource);
}

if (revisionC)
timerSource = IOTimerEventSource::timerEventSource(this, OSMemberFunctionCast(IOTimerEventSource::Action, this, &RTL8111::timerActionRTL8111C));
else
Expand Down Expand Up @@ -2406,6 +2442,15 @@ void RTL8111::updateStatitics()
}
}

void RTL8111::interruptSimulation(IOTimerEventSource *timer)
{
if (rxPoll)
interruptOccurredPoll(NULL, NULL, 0);
else
interruptOccurred(NULL, NULL, 0);
interruptSimulationSource->setTimeoutMS(1);
}

#pragma mark --- RTL8111C specific methods ---

void RTL8111::timerActionRTL8111C(IOTimerEventSource *timer)
Expand Down
5 changes: 5 additions & 0 deletions RealtekRTL8111/RealtekRTL8111.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ enum
#define kEnableTSO4Name "enableTSO4"
#define kEnableTSO6Name "enableTSO6"
#define kIntrMitigateName "intrMitigate"
#define kDisableMSIName "disableMSI"
#define kDisableASPMName "disableASPM"
#define kDriverVersionName "Driver_Version"
#define kFallbackName "fallbackMAC"
Expand Down Expand Up @@ -248,6 +249,8 @@ class RTL8111 : public super
bool setupMediumDict();
bool initEventSources(IOService *provider);
void interruptOccurred(OSObject *client, IOInterruptEventSource *src, int count);
void interruptSimulation(IOTimerEventSource *timer);

void pciErrorInterrupt();
void txInterrupt();

Expand Down Expand Up @@ -307,6 +310,7 @@ class RTL8111 : public super

IOInterruptEventSource *interruptSource;
IOTimerEventSource *timerSource;
IOTimerEventSource *interruptSimulationSource;
IOEthernetInterface *netif;
IOMemoryMap *baseMap;
volatile void *baseAddr;
Expand Down Expand Up @@ -369,6 +373,7 @@ class RTL8111 : public super

IONetworkPacketPollingParameters pollParams;

bool disableMSI;
bool rxPoll;
bool polling;

Expand Down

0 comments on commit fcd42d6

Please sign in to comment.