Skip to content

Commit

Permalink
Version 1.1.0d12 - Fixed auto-negotiation to work properly with all s…
Browse files Browse the repository at this point in the history
…upported link rates.
  • Loading branch information
Mieze committed Apr 24, 2021
1 parent 224443e commit d8c62c6
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 86 deletions.
4 changes: 2 additions & 2 deletions LucyRTL8125Ethernet.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
INFOPLIST_FILE = LucyRTL8125Ethernet/Info.plist;
MARKETING_VERSION = $MODULE_VERSION;
MODULE_NAME = com.insanelymac.LucyRTL8125Ethernet;
MODULE_VERSION = 1.1.0d11;
MODULE_VERSION = 1.1.0d12;
PRODUCT_BUNDLE_IDENTIFIER = com.insanelymac.LucyRTL8125Ethernet;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand All @@ -346,7 +346,7 @@
INFOPLIST_FILE = LucyRTL8125Ethernet/Info.plist;
MARKETING_VERSION = $MODULE_VERSION;
MODULE_NAME = com.insanelymac.LucyRTL8125Ethernet;
MODULE_VERSION = 1.1.0d11;
MODULE_VERSION = 1.1.0d12;
PRODUCT_BUNDLE_IDENTIFIER = com.insanelymac.LucyRTL8125Ethernet;
PRODUCT_NAME = "$(TARGET_NAME)";
PROVISIONING_PROFILE_SPECIFIER = "";
Expand Down
29 changes: 8 additions & 21 deletions LucyRTL8125Ethernet/LucyRTL8125Ethernet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ bool LucyRTL8125::init(OSDictionary *properties)

mtu = ETH_DATA_LEN;
powerState = 0;
speed = SPEED_1000;
speed = 0;
duplex = DUPLEX_FULL;
autoneg = AUTONEG_ENABLE;
flowCtl = kFlowControlOff;
Expand Down Expand Up @@ -819,6 +819,7 @@ IOReturn LucyRTL8125::selectMedium(const IONetworkMedium *medium)
DebugLog("selectMedium() ===>\n");

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

Expand All @@ -831,87 +832,74 @@ IOReturn LucyRTL8125::selectMedium(const IONetworkMedium *medium)
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;
break;

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

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

case MEDIUM_INDEX_1000FDFCEEE:
autoneg = AUTONEG_ENABLE;
speed = SPEED_1000;
duplex = DUPLEX_FULL;
flowCtl = kFlowControlOn;
linuxData.eee_adv_t = eeeCap;
break;

case MEDIUM_INDEX_2500FD:
autoneg = AUTONEG_ENABLE;
speed = SPEED_2500;
duplex = DUPLEX_FULL;
break;

case MEDIUM_INDEX_2500FDFC:
autoneg = AUTONEG_ENABLE;
speed = SPEED_2500;
duplex = DUPLEX_FULL;
flowCtl = kFlowControlOn;
Expand Down Expand Up @@ -1735,7 +1723,6 @@ void LucyRTL8125::checkLinkStatus()
/* Stop watchdog and statistics updates. */
timerSource->cancelTimeout();
setLinkDown();

}
}

Expand Down Expand Up @@ -1947,9 +1934,9 @@ static const char *speed25GName = "2.5 Gigabit";
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 Expand Up @@ -2138,7 +2125,7 @@ void LucyRTL8125::updateStatitics()
etherStats->dot3TxExtraEntry.underruns = OSSwapLittleToHostInt16(statData->txUnderun);
}
/* Some chips are unable to dump the tally counter while the receiver is disabled. */
if (ReadReg8(ChipCmd) & CmdRxEnb) {
if (linkUp && (ReadReg8(ChipCmd) & CmdRxEnb)) {
WriteReg32(CounterAddrHigh, (statPhyAddr >> 32));
cmd = (statPhyAddr & 0x00000000ffffffff);
WriteReg32(CounterAddrLow, cmd);
Expand All @@ -2149,15 +2136,15 @@ void LucyRTL8125::updateStatitics()

void LucyRTL8125::timerActionRTL8125(IOTimerEventSource *timer)
{
updateStatitics();

if (!linkUp) {
DebugLog("Timer fired while link down.\n");
goto done;
}
/* Check for tx deadlock. */
if (checkForDeadlock())
goto done;

updateStatitics();
timerSource->setTimeoutMS(kTimeoutMS);

done:
Expand Down
105 changes: 42 additions & 63 deletions LucyRTL8125Ethernet/LucyRTL8125Hardware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,6 @@ bool LucyRTL8125::initRTL8125()
/* Set wake on LAN support. */
wolCapable = (tp->wol_enabled == WOL_ENABLED);

//rtl8125_link_option((u8*)&autoneg_mode, (u32*)&speed_mode, (u8*)&duplex_mode, (u32*)&advertising_mode);
/*
tp->autoneg = autoneg_mode;
tp->speed = speed_mode;
tp->duplex = duplex_mode;
tp->advertising = advertising_mode;
*/
//tp->eee_enabled = eee_enable;
tp->eee_adv_t = MDIO_EEE_1000T | MDIO_EEE_100TX;

Expand Down Expand Up @@ -869,13 +862,11 @@ void LucyRTL8125::setPhyMedium()
int auto_nego = 0;
int giga_ctrl = 0;
int ctrl_2500 = 0;
int use_default = 0;

if (speed != SPEED_2500 && (speed != SPEED_1000) &&
(speed != SPEED_100) && (speed != SPEED_10)) {
duplex = DUPLEX_FULL;
autoneg = AUTONEG_ENABLE;
use_default = 1;
}
/* Enable or disable EEE support according to selected medium. */
if ((linuxData.eee_adv_t != 0) && (autoneg == AUTONEG_ENABLE)) {
Expand All @@ -891,70 +882,58 @@ void LucyRTL8125::setPhyMedium()

giga_ctrl = rtl8125_mdio_read(tp, MII_CTRL1000);
giga_ctrl &= ~(ADVERTISE_1000HALF | ADVERTISE_1000FULL);

ctrl_2500 = mdio_direct_read_phy_ocp(tp, 0xA5D4);
ctrl_2500 &= ~(RTK_ADVERTISE_2500FULL);

auto_nego = rtl8125_mdio_read(tp, MII_ADVERTISE);
auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL |
ADVERTISE_100HALF | ADVERTISE_100FULL |
ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);

if (autoneg == AUTONEG_ENABLE) {
/*n-way force*/
auto_nego = rtl8125_mdio_read(tp, MII_ADVERTISE);
auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL |
ADVERTISE_100HALF | ADVERTISE_100FULL |
ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);

if (use_default) {
/* The default medium has been selected. */
speed = SPEED_1000;

auto_nego |= (ADVERTISE_10HALF | ADVERTISE_10FULL | ADVERTISE_100HALF | ADVERTISE_100FULL);
/* The default medium has been selected. */
auto_nego |= (ADVERTISE_10HALF | ADVERTISE_10FULL | ADVERTISE_100HALF | ADVERTISE_100FULL);
giga_ctrl |= ADVERTISE_1000FULL;
ctrl_2500 |= RTK_ADVERTISE_2500FULL;
} else if (speed == SPEED_2500) {
ctrl_2500 |= RTK_ADVERTISE_2500FULL;
} else if (speed == SPEED_1000) {
if (duplex == DUPLEX_HALF) {
giga_ctrl |= ADVERTISE_1000HALF;
} else {
giga_ctrl |= ADVERTISE_1000FULL;
//ctrl_2500 |= RTK_ADVERTISE_2500FULL;
} else if (speed == SPEED_2500) {
ctrl_2500 |= RTK_ADVERTISE_2500FULL;
} else if (speed == SPEED_1000) {
if (duplex == DUPLEX_HALF) {
giga_ctrl |= ADVERTISE_1000HALF;
} else {
giga_ctrl |= ADVERTISE_1000FULL;
}
} else if (speed == SPEED_100) {
if (duplex == DUPLEX_HALF) {
auto_nego |= ADVERTISE_100HALF;
} else {
auto_nego |= ADVERTISE_100FULL;
}
} else { /* speed == SPEED_10 */
if (duplex == DUPLEX_HALF) {
auto_nego |= ADVERTISE_10HALF;
} else {
auto_nego |= ADVERTISE_10FULL;
}
}

/* Set flow control support. */
if (flowCtl == kFlowControlOn)
auto_nego |= (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
} else if (speed == SPEED_100) {
if (duplex == DUPLEX_HALF) {
auto_nego |= ADVERTISE_100HALF;
} else {
auto_nego |= ADVERTISE_100FULL;
}
} else { /* speed == SPEED_10 */
if (duplex == DUPLEX_HALF) {
auto_nego |= ADVERTISE_10HALF;
} else {
auto_nego |= ADVERTISE_10FULL;
}
}
/* Set flow control support. */
if (flowCtl == kFlowControlOn)
auto_nego |= (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);

tp->phy_auto_nego_reg = auto_nego;
tp->phy_1000_ctrl_reg = giga_ctrl;
tp->phy_auto_nego_reg = auto_nego;
tp->phy_1000_ctrl_reg = giga_ctrl;

tp->phy_2500_ctrl_reg = ctrl_2500;
tp->phy_2500_ctrl_reg = ctrl_2500;

rtl8125_mdio_write(tp, 0x1f, 0x0000);
rtl8125_mdio_write(tp, MII_ADVERTISE, auto_nego);
rtl8125_mdio_write(tp, MII_CTRL1000, giga_ctrl);
mdio_direct_write_phy_ocp(tp, 0xA5D4, ctrl_2500);
rtl8125_phy_restart_nway(tp);
mdelay(20);
} else {
/*true force*/
if (speed == SPEED_10 || speed == SPEED_100 ||
(speed == SPEED_1000 && duplex == DUPLEX_FULL &&
tp->HwSuppGigaForceMode)) {
rtl8125_phy_setup_force_mode(tp, speed, duplex);
}
}
rtl8125_mdio_write(tp, 0x1f, 0x0000);
rtl8125_mdio_write(tp, MII_ADVERTISE, auto_nego);
rtl8125_mdio_write(tp, MII_CTRL1000, giga_ctrl);
mdio_direct_write_phy_ocp(tp, 0xA5D4, ctrl_2500);
rtl8125_phy_restart_nway(tp);
mdelay(20);

tp->autoneg = autoneg;
tp->autoneg = AUTONEG_ENABLE;
tp->speed = speed;
tp->duplex = duplex;
}
Expand Down

0 comments on commit d8c62c6

Please sign in to comment.