Skip to content

Commit

Permalink
Version 2.4.2d0 - Reworked auto-negotiation to fix issue with 100 MBi…
Browse files Browse the repository at this point in the history
…t/s.
  • Loading branch information
Mieze committed Apr 23, 2021
1 parent 39209e2 commit 8fd431a
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 120 deletions.
4 changes: 2 additions & 2 deletions RealtekRTL8111.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = "$(MODULE_VERSION)";
MODULE_NAME = com.insanelymac.RealtekRTL8111;
MODULE_VERSION = 2.4.0;
MODULE_VERSION = 2.4.2d0;
PRODUCT_BUNDLE_IDENTIFIER = "com.insanelymac.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = RealtekRTL8111;
RUN_CLANG_STATIC_ANALYZER = YES;
Expand Down Expand Up @@ -285,7 +285,7 @@
MACOSX_DEPLOYMENT_TARGET = 10.14;
MARKETING_VERSION = "$(MODULE_VERSION)";
MODULE_NAME = com.insanelymac.RealtekRTL8111;
MODULE_VERSION = 2.4.0;
MODULE_VERSION = 2.4.2d0;
PRODUCT_BUNDLE_IDENTIFIER = "com.insanelymac.${PRODUCT_NAME:rfc1034identifier}";
PRODUCT_NAME = RealtekRTL8111;
SDKROOT = macosx;
Expand Down
Binary file not shown.
2 changes: 0 additions & 2 deletions RealtekRTL8111/RealtekRTL8111-Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
<true/>
<key>enableCSO6</key>
<true/>
<key>enableEEE</key>
<true/>
<key>enableTSO4</key>
<true/>
<key>enableTSO6</key>
Expand Down
50 changes: 16 additions & 34 deletions RealtekRTL8111/RealtekRTL8111.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,12 @@ bool RTL8111::init(OSDictionary *properties)

mtu = ETH_DATA_LEN;
powerState = 0;
speed = SPEED_1000;
speed = 0;
duplex = DUPLEX_FULL;
autoneg = AUTONEG_ENABLE;
flowCtl = kFlowControlOff;
linuxData.eee_adv_t = 0;
linuxData.eee_enabled = 1;
eeeCap = 0;
linuxData.aspm = 0;
linuxData.s0_magic_packet = 0;
Expand Down Expand Up @@ -348,7 +349,7 @@ IOReturn RTL8111::enable(IONetworkInterface *netif)
DebugLog("[RealtekRTL8111]: No medium selected. Falling back to autonegotiation.\n");
selectedMedium = mediumTable[MEDIUM_INDEX_AUTO];
}
selectMedium(selectedMedium);
setCurrentMedium(selectedMedium);
enableRTL8111();

/* We have to enable the interrupt because we are using a msi interrupt. */
Expand Down Expand Up @@ -936,94 +937,84 @@ IOReturn RTL8111::selectMedium(const IONetworkMedium *medium)
DebugLog("selectMedium() ===>\n");

if (medium) {
autoneg = AUTONEG_DISABLE;
flowCtl = kFlowControlOff;
linuxData.eee_adv_t = 0;
linuxData.eee_enabled = 0;

switch (medium->getIndex()) {
case MEDIUM_INDEX_AUTO:
autoneg = AUTONEG_ENABLE;
speed = 0;
duplex = DUPLEX_FULL;
flowCtl = kFlowControlOn;
linuxData.eee_adv_t = eeeCap;
linuxData.eee_enabled = 1;
break;

case MEDIUM_INDEX_10HD:
autoneg = AUTONEG_DISABLE;
speed = SPEED_10;
duplex = DUPLEX_HALF;
break;

case MEDIUM_INDEX_10FD:
autoneg = AUTONEG_ENABLE;
speed = SPEED_10;
duplex = DUPLEX_FULL;
break;

case MEDIUM_INDEX_100HD:
autoneg = AUTONEG_DISABLE;
speed = SPEED_100;
duplex = DUPLEX_HALF;
break;

case MEDIUM_INDEX_100FD:
autoneg = AUTONEG_ENABLE;
speed = SPEED_100;
duplex = DUPLEX_FULL;
break;

case MEDIUM_INDEX_100FDFC:
autoneg = AUTONEG_ENABLE;
speed = SPEED_100;
duplex = DUPLEX_FULL;
flowCtl = kFlowControlOn;
break;

case MEDIUM_INDEX_1000FD:
autoneg = AUTONEG_ENABLE;
speed = SPEED_1000;
duplex = DUPLEX_FULL;
break;

case MEDIUM_INDEX_1000FDFC:
autoneg = AUTONEG_ENABLE;
speed = SPEED_1000;
duplex = DUPLEX_FULL;
flowCtl = kFlowControlOn;
break;

case MEDIUM_INDEX_100FDEEE:
autoneg = AUTONEG_ENABLE;
speed = SPEED_100;
duplex = DUPLEX_FULL;
linuxData.eee_adv_t = eeeCap;
linuxData.eee_enabled = 1;
break;

case MEDIUM_INDEX_100FDFCEEE:
autoneg = AUTONEG_ENABLE;
speed = SPEED_100;
duplex = DUPLEX_FULL;
flowCtl = kFlowControlOn;
linuxData.eee_adv_t = eeeCap;
linuxData.eee_enabled = 1;
break;

case MEDIUM_INDEX_1000FDEEE:
autoneg = AUTONEG_ENABLE;
speed = SPEED_1000;
duplex = DUPLEX_FULL;
linuxData.eee_adv_t = eeeCap;
linuxData.eee_enabled = 1;
break;

case MEDIUM_INDEX_1000FDFCEEE:
autoneg = AUTONEG_ENABLE;
speed = SPEED_1000;
duplex = DUPLEX_FULL;
flowCtl = kFlowControlOn;
linuxData.eee_adv_t = eeeCap;
linuxData.eee_enabled = 1;
break;
}
setPhyMedium();
setCurrentMedium(medium);
restartRTL8111();
}

DebugLog("selectMedium() <===\n");
Expand Down Expand Up @@ -1103,7 +1094,6 @@ void RTL8111::getParams()
{
OSDictionary *params;
OSNumber *intrMit;
OSBoolean *enableEEE;
OSBoolean *poll;
OSBoolean *tso4;
OSBoolean *tso6;
Expand All @@ -1122,15 +1112,6 @@ void RTL8111::getParams()

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

enableEEE = OSDynamicCast(OSBoolean, params->getObject(kEnableEeeName));

if (enableEEE)
linuxData.eee_enabled = (enableEEE->getValue()) ? 1 : 0;
else
linuxData.eee_enabled = 0;

IOLog("[RealtekRTL8111]: EEE support %s.\n", linuxData.eee_enabled ? onName : offName);

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

Expand Down Expand Up @@ -1173,7 +1154,6 @@ void RTL8111::getParams()
}
} else {
disableASPM = true;
linuxData.eee_enabled = 1;
rxPoll = true;
enableTSO4 = true;
enableTSO6 = true;
Expand Down Expand Up @@ -1822,6 +1802,8 @@ void RTL8111::checkLinkStatus()
UInt16 newIntrMitigate = 0x5f51;
UInt8 currLinkState;

DebugLog("Link change interrupt: Check link status.\n");

if (tp->mcfg == CFG_METHOD_11)
rtl8168dp_10mbps_gphy_para(tp);

Expand Down Expand Up @@ -2235,9 +2217,9 @@ void RTL8111::getChecksumResult(mbuf_t m, UInt32 status1, UInt32 status2)
static const char *speed1GName = "1-Gigabit";
static const char *speed100MName = "100-Megabit";
static const char *speed10MName = "10-Megabit";
static const char *duplexFullName = "Full-duplex";
static const char *duplexHalfName = "Half-duplex";
static const char *offFlowName = "No flow-control";
static const char *duplexFullName = "full-duplex";
static const char *duplexHalfName = "half-duplex";
static const char *offFlowName = "no flow-control";
static const char *onFlowName = "flow-control";

static const char* eeeNames[kEEETypeCount] = {
Expand Down
1 change: 0 additions & 1 deletion RealtekRTL8111/RealtekRTL8111.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ enum
};

#define kParamName "Driver Parameters"
#define kEnableEeeName "enableEEE"
#define kEnableCSO6Name "enableCSO6"
#define kEnableTSO4Name "enableTSO4"
#define kEnableTSO6Name "enableTSO6"
Expand Down
116 changes: 35 additions & 81 deletions RealtekRTL8111/RealtekRTL8111Hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,10 @@ bool RTL8111::initRTL8111()
tp->HwPkgDet = (tp->HwPkgDet >> 3) & 0x0F;
break;
}
/*
if (HW_DASH_SUPPORT_TYPE_3(tp) && tp->HwPkgDet == 0x06)
tp->eee_enabled = 0;
*/
switch (tp->mcfg) {
case CFG_METHOD_21:
case CFG_METHOD_22:
Expand Down Expand Up @@ -1587,9 +1587,11 @@ void RTL8111::setPhyMedium()
struct rtl8168_private *tp = &linuxData;
int autoNego = 0;
int gigaCtrl = 0;
int force = 0;
int use_default = 0;

if ((speed != SPEED_1000) && (speed != SPEED_100) && (speed != SPEED_10)) {
duplex = DUPLEX_FULL;
autoneg = AUTONEG_ENABLE;
}
if (tp->mcfg == CFG_METHOD_29 || tp->mcfg == CFG_METHOD_30 ||
tp->mcfg == CFG_METHOD_31 || tp->mcfg == CFG_METHOD_32) {
/* Disable Giga Lite. */
Expand All @@ -1602,94 +1604,46 @@ void RTL8111::setPhyMedium()
rtl8168_mdio_write(tp, 0x1F, 0x0A40);
rtl8168_mdio_write(tp, 0x1F, 0x0000);
}
if ((speed != SPEED_1000) && (speed != SPEED_100) && (speed != SPEED_10)) {
speed = SPEED_1000;
duplex = DUPLEX_FULL;
autoneg = AUTONEG_ENABLE;
use_default = 1;
}
autoNego = rtl8168_mdio_read(tp, MII_ADVERTISE);
autoNego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL | ADVERTISE_100HALF | ADVERTISE_100FULL | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);

gigaCtrl = rtl8168_mdio_read(tp, MII_CTRL1000);
gigaCtrl &= ~(ADVERTISE_1000HALF | ADVERTISE_1000FULL);

if (tp->HwHasWrRamCodeToMicroP == TRUE) {
if ((tp->eee_enabled) && (linuxData.eee_adv_t != 0)) {
rtl8168_enable_EEE(tp);
DebugLog("Enable EEE support.\n");
if (autoneg == AUTONEG_ENABLE) {
/* The default medium has been selected. */
gigaCtrl |= ADVERTISE_1000FULL;
autoNego |= ADVERTISE_100HALF | ADVERTISE_100FULL | ADVERTISE_10HALF | ADVERTISE_10FULL;
} else if (speed == SPEED_1000) {
gigaCtrl |= ADVERTISE_1000FULL;
} else if (speed == SPEED_100) {
if (duplex == DUPLEX_HALF) {
autoNego |= ADVERTISE_100HALF;
} else {
rtl8168_disable_EEE(tp);
DebugLog("Disable EEE support.\n");
autoNego |= ADVERTISE_100FULL;
}
}
if (autoneg == AUTONEG_ENABLE) {
/* n-way force */
if (speed == SPEED_1000) {
if (use_default) {
/* The default medium has been selected. */
gigaCtrl |= ADVERTISE_1000HALF | ADVERTISE_1000FULL;
autoNego |= ADVERTISE_100HALF | ADVERTISE_100FULL | ADVERTISE_10HALF | ADVERTISE_10FULL;
} else {
if (duplex == DUPLEX_HALF) {
gigaCtrl |= ADVERTISE_1000HALF;
} else {
gigaCtrl |= ADVERTISE_1000FULL;
}
}
} else if (speed == SPEED_100) {
if (duplex == DUPLEX_HALF) {
autoNego |= ADVERTISE_100HALF;
} else {
autoNego |= ADVERTISE_100FULL;
}
} else { /* speed == SPEED_10 */
if (duplex == DUPLEX_HALF) {
autoNego |= ADVERTISE_10HALF;
} else {
autoNego |= ADVERTISE_10FULL;
}
} else { /* speed == SPEED_10 */
if (duplex == DUPLEX_HALF) {
autoNego |= ADVERTISE_10HALF;
} else {
autoNego |= ADVERTISE_10FULL;
}
}
/* Set flow control support. */
if (flowCtl == kFlowControlOn)
autoNego |= ADVERTISE_PAUSE_CAP|ADVERTISE_PAUSE_ASYM;

/* Set flow control support. */
if (flowCtl == kFlowControlOn)
autoNego |= ADVERTISE_PAUSE_CAP|ADVERTISE_PAUSE_ASYM;

tp->phy_auto_nego_reg = autoNego;
tp->phy_1000_ctrl_reg = gigaCtrl;

/* Setup EEE advertisement. */
if (eeeCap) {
if ((tp->mcfg >= CFG_METHOD_14) && (tp->mcfg < CFG_METHOD_21)) {
rtl8168_mdio_write(&linuxData, 0x0D, 0x0007);
rtl8168_mdio_write(&linuxData, 0x0E, 0x003C);
rtl8168_mdio_write(&linuxData, 0x0D, 0x4007);
rtl8168_mdio_write(&linuxData, 0x0E, linuxData.eee_adv_t);
rtl8168_mdio_write(tp, 0x1F, 0x0000);
}
}
rtl8168_mdio_write(tp, 0x1f, 0x0000);
rtl8168_mdio_write(tp, MII_ADVERTISE, autoNego);
rtl8168_mdio_write(tp, MII_CTRL1000, gigaCtrl);
rtl8168_mdio_write(tp, 0x1f, 0x0000);
rtl8168_mdio_write(tp, MII_BMCR, BMCR_RESET | BMCR_ANENABLE | BMCR_ANRESTART);
mdelay(20);
} else {
/* true force */
if ((speed == SPEED_10) && (duplex == DUPLEX_HALF)) {
force = BMCR_SPEED10;
} else if ((speed == SPEED_10) && (duplex == DUPLEX_FULL)) {
force = BMCR_SPEED10 | BMCR_FULLDPLX;
} else if ((speed == SPEED_100) && (duplex == DUPLEX_HALF)) {
force = BMCR_SPEED100;
} else if ((speed == SPEED_100) && (duplex == DUPLEX_FULL)) {
force = BMCR_SPEED100 | BMCR_FULLDPLX;
}
tp->phy_auto_nego_reg = autoNego;
tp->phy_1000_ctrl_reg = gigaCtrl;

rtl8168_mdio_write(tp, 0x1f, 0x0000);
rtl8168_mdio_write(tp, MII_BMCR, force);
}
tp->autoneg = autoneg;
rtl8168_mdio_write(tp, 0x1f, 0x0000);
rtl8168_mdio_write(tp, MII_ADVERTISE, autoNego);
rtl8168_mdio_write(tp, MII_CTRL1000, gigaCtrl);
rtl8168_mdio_write(tp, 0x1f, 0x0000);
rtl8168_mdio_write(tp, MII_BMCR, BMCR_RESET | BMCR_ANENABLE | BMCR_ANRESTART);
mdelay(20);

tp->autoneg = AUTONEG_ENABLE;
tp->speed = speed;
tp->duplex = duplex;

Expand Down

0 comments on commit 8fd431a

Please sign in to comment.