switch (hw->phy_id) { case M88E1000_E_PHY_ID: case M88E1000_I_PHY_ID: case M88E1011_I_PHY_ID: case M88E1111_I_PHY_ID: case M88E1118_E_PHY_ID:
hw->phy_type = e1000_phy_m88; break; case IGP01E1000_I_PHY_ID: if (hw->mac_type == e1000_82541 ||
hw->mac_type == e1000_82541_rev_2 ||
hw->mac_type == e1000_82547 ||
hw->mac_type == e1000_82547_rev_2)
hw->phy_type = e1000_phy_igp; break; case RTL8211B_PHY_ID:
hw->phy_type = e1000_phy_8211; break; case RTL8201N_PHY_ID:
hw->phy_type = e1000_phy_8201; break; default: /* Should never have loaded on this device */
hw->phy_type = e1000_phy_undefined; return -E1000_ERR_PHY_TYPE;
}
/** *e1000_set_mac_type-Setthemactypememberinthehwstruct. *@hw:Structcontainingvariablesaccessedbysharedcode
*/
s32 e1000_set_mac_type(struct e1000_hw *hw)
{ switch (hw->device_id) { case E1000_DEV_ID_82542: switch (hw->revision_id) { case E1000_82542_2_0_REV_ID:
hw->mac_type = e1000_82542_rev2_0; break; case E1000_82542_2_1_REV_ID:
hw->mac_type = e1000_82542_rev2_1; break; default: /* Invalid 82542 revision ID */ return -E1000_ERR_MAC_TYPE;
} break; case E1000_DEV_ID_82543GC_FIBER: case E1000_DEV_ID_82543GC_COPPER:
hw->mac_type = e1000_82543; break; case E1000_DEV_ID_82544EI_COPPER: case E1000_DEV_ID_82544EI_FIBER: case E1000_DEV_ID_82544GC_COPPER: case E1000_DEV_ID_82544GC_LOM:
hw->mac_type = e1000_82544; break; case E1000_DEV_ID_82540EM: case E1000_DEV_ID_82540EM_LOM: case E1000_DEV_ID_82540EP: case E1000_DEV_ID_82540EP_LOM: case E1000_DEV_ID_82540EP_LP:
hw->mac_type = e1000_82540; break; case E1000_DEV_ID_82545EM_COPPER: case E1000_DEV_ID_82545EM_FIBER:
hw->mac_type = e1000_82545; break; case E1000_DEV_ID_82545GM_COPPER: case E1000_DEV_ID_82545GM_FIBER: case E1000_DEV_ID_82545GM_SERDES:
hw->mac_type = e1000_82545_rev_3; break; case E1000_DEV_ID_82546EB_COPPER: case E1000_DEV_ID_82546EB_FIBER: case E1000_DEV_ID_82546EB_QUAD_COPPER:
hw->mac_type = e1000_82546; break; case E1000_DEV_ID_82546GB_COPPER: case E1000_DEV_ID_82546GB_FIBER: case E1000_DEV_ID_82546GB_SERDES: case E1000_DEV_ID_82546GB_PCIE: case E1000_DEV_ID_82546GB_QUAD_COPPER: case E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3:
hw->mac_type = e1000_82546_rev_3; break; case E1000_DEV_ID_82541EI: case E1000_DEV_ID_82541EI_MOBILE: case E1000_DEV_ID_82541ER_LOM:
hw->mac_type = e1000_82541; break; case E1000_DEV_ID_82541ER: case E1000_DEV_ID_82541GI: case E1000_DEV_ID_82541GI_LF: case E1000_DEV_ID_82541GI_MOBILE:
hw->mac_type = e1000_82541_rev_2; break; case E1000_DEV_ID_82547EI: case E1000_DEV_ID_82547EI_MOBILE:
hw->mac_type = e1000_82547; break; case E1000_DEV_ID_82547GI:
hw->mac_type = e1000_82547_rev_2; break; case E1000_DEV_ID_INTEL_CE4100_GBE:
hw->mac_type = e1000_ce4100; break; default: /* Should never have loaded on this device */ return -E1000_ERR_MAC_TYPE;
}
switch (hw->mac_type) { case e1000_82541: case e1000_82547: case e1000_82541_rev_2: case e1000_82547_rev_2:
hw->asf_firmware_present = true; break; default: break;
}
/* The 82543 chip does not count tx_carrier_errors properly in *FDmode
*/ if (hw->mac_type == e1000_82543)
hw->bad_tx_carr_stats_fd = true;
if (hw->mac_type > e1000_82544)
hw->has_smbus = true;
/* For 82542 (rev 2.0), disable MWI before issuing a device reset */ if (hw->mac_type == e1000_82542_rev2_0) {
e_dbg("Disabling MWI on 82542 rev 2.0\n");
e1000_pci_clear_mwi(hw);
}
/* Clear interrupt mask to stop board from generating interrupts */
e_dbg("Masking off all interrupts\n");
ew32(IMC, 0xffffffff);
/* Disable the Transmit and Receive units. Then delay to allow *anypendingtransactionstocompletebeforewehittheMACwith *theglobalreset.
*/
ew32(RCTL, 0);
ew32(TCTL, E1000_TCTL_PSP);
E1000_WRITE_FLUSH();
/* The tbi_compatibility_on Flag must be cleared when Rctl is cleared. */
hw->tbi_compatibility_on = false;
/* Delay to allow any outstanding PCI transactions to complete before *resettingthedevice
*/
msleep(10);
ctrl = er32(CTRL);
/* Must reset the PHY before resetting the MAC */ if ((hw->mac_type == e1000_82541) || (hw->mac_type == e1000_82547)) {
ew32(CTRL, (ctrl | E1000_CTRL_PHY_RST));
E1000_WRITE_FLUSH();
msleep(5);
}
/* Issue a global reset to the MAC. This will reset the chip's *transmit,receive,DMA,andlinkunits.Itwillnoteffect *thecurrentPCIconfiguration.Theglobalresetbitisself- *clearing,andshouldclearwithinamicrosecond.
*/
e_dbg("Issuing a global reset to MAC\n");
switch (hw->mac_type) { case e1000_82544: case e1000_82540: case e1000_82545: case e1000_82546: case e1000_82541: case e1000_82541_rev_2: /* These controllers can't ack the 64-bit write when issuing the *reset,souseIO-mappingasaworkaroundtoissuethereset
*/
E1000_WRITE_REG_IO(hw, CTRL, (ctrl | E1000_CTRL_RST)); break; case e1000_82545_rev_3: case e1000_82546_rev_3: /* Reset is performed on a shadow of the control register */
ew32(CTRL_DUP, (ctrl | E1000_CTRL_RST)); break; case e1000_ce4100: default:
ew32(CTRL, (ctrl | E1000_CTRL_RST)); break;
}
/* After MAC reset, force reload of EEPROM to restore power-on settings *todevice.LatercontrollersreloadtheEEPROMautomatically,so *justwaitforreloadtocomplete.
*/ switch (hw->mac_type) { case e1000_82542_rev2_0: case e1000_82542_rev2_1: case e1000_82543: case e1000_82544: /* Wait for reset to complete */
udelay(10);
ctrl_ext = er32(CTRL_EXT);
ctrl_ext |= E1000_CTRL_EXT_EE_RST;
ew32(CTRL_EXT, ctrl_ext);
E1000_WRITE_FLUSH(); /* Wait for EEPROM reload */
msleep(2); break; case e1000_82541: case e1000_82541_rev_2: case e1000_82547: case e1000_82547_rev_2: /* Wait for EEPROM reload */
msleep(20); break; default: /* Auto read done will delay 5ms or poll based on mac type */
ret_val = e1000_get_auto_rd_done(hw); if (ret_val) return ret_val; break;
}
/* Clear interrupt mask to stop board from generating interrupts */
e_dbg("Masking off all interrupts\n");
ew32(IMC, 0xffffffff);
/* Clear any pending interrupt events. */
er32(ICR);
/* If MWI was previously enabled, reenable it. */ if (hw->mac_type == e1000_82542_rev2_0) { if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
e1000_pci_set_mwi(hw);
}
/* Initialize Identification LED */
ret_val = e1000_id_led_init(hw); if (ret_val) {
e_dbg("Error Initializing Identification LED\n"); return ret_val;
}
/* Set the media type and TBI compatibility */
e1000_set_media_type(hw);
/* Disabling VLAN filtering. */
e_dbg("Initializing the IEEE VLAN\n"); if (hw->mac_type < e1000_82545_rev_3)
ew32(VET, 0);
e1000_clear_vfta(hw);
/* For 82542 (rev 2.0), disable MWI and put the receiver into reset */ if (hw->mac_type == e1000_82542_rev2_0) {
e_dbg("Disabling MWI on 82542 rev 2.0\n");
e1000_pci_clear_mwi(hw);
ew32(RCTL, E1000_RCTL_RST);
E1000_WRITE_FLUSH();
msleep(5);
}
/* Setup the receive address. This involves initializing all of the *ReceiveAddressRegisters(RARs0-15).
*/
e1000_init_rx_addrs(hw);
/* For 82542 (rev 2.0), take the receiver out of reset and enable MWI */ if (hw->mac_type == e1000_82542_rev2_0) {
ew32(RCTL, 0);
E1000_WRITE_FLUSH();
msleep(1); if (hw->pci_cmd_word & PCI_COMMAND_INVALIDATE)
e1000_pci_set_mwi(hw);
}
/* Zero out the Multicast HASH table */
e_dbg("Zeroing the MTA\n");
mta_size = E1000_MC_TBL_SIZE; for (i = 0; i < mta_size; i++) {
E1000_WRITE_REG_ARRAY(hw, MTA, i, 0); /* use write flush to prevent Memory Write Block (MWB) from *occurringwhenaccessingourregisterspace
*/
E1000_WRITE_FLUSH();
}
/* Set the PCI priority bit correctly in the CTRL register. This *determinesiftheadaptergivesprioritytoreceives,orifit *givesequalprioritytotransmitsandreceives.Validonlyon *82542and82543silicon.
*/ if (hw->dma_fairness && hw->mac_type <= e1000_82543) {
ctrl = er32(CTRL);
ew32(CTRL, ctrl | E1000_CTRL_PRIOR);
}
switch (hw->mac_type) { case e1000_82545_rev_3: case e1000_82546_rev_3: break; default: /* Workaround for PCI-X problem when BIOS sets MMRBC *incorrectly.
*/ if (hw->bus_type == e1000_bus_type_pcix &&
e1000_pcix_get_mmrbc(hw) > 2048)
e1000_pcix_set_mmrbc(hw, 2048); break;
}
/* Call a subroutine to configure the link and setup flow control. */
ret_val = e1000_setup_link(hw);
/* Set the transmit descriptor write-back policy */ if (hw->mac_type > e1000_82544) {
ctrl = er32(TXDCTL);
ctrl =
(ctrl & ~E1000_TXDCTL_WTHRESH) |
E1000_TXDCTL_FULL_TX_DESC_WB;
ew32(TXDCTL, ctrl);
}
/* Clear all of the statistics registers (clear on read). It is *importantthatwedothisafterwehavetriedtoestablishlink *becausethesymbolerrorcountwillincrementwildlyifthere *isnolink.
*/
e1000_clear_hw_cntrs(hw);
if (hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER ||
hw->device_id == E1000_DEV_ID_82546GB_QUAD_COPPER_KSP3) {
ctrl_ext = er32(CTRL_EXT); /* Relaxed ordering must be disabled to avoid a parity *errorcrashinaPCIslot.
*/
ctrl_ext |= E1000_CTRL_EXT_RO_DIS;
ew32(CTRL_EXT, ctrl_ext);
}
/* Read and store word 0x0F of the EEPROM. This word contains bits *thatdeterminethehardware'sdefaultPAUSE(flowcontrol)mode, *abitthatdetermineswhethertheHWdefaultstoenablingor *disablingauto-negotiation,andthedirectionofthe *SWdefinedpins.IfthereisnoSWover-rideoftheflow *controlsetting,thenthevariablehw->fcwill *beinitializedbasedonavalueintheEEPROM.
*/ if (hw->fc == E1000_FC_DEFAULT) {
ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data); if (ret_val) {
e_dbg("EEPROM Read Error\n"); return -E1000_ERR_EEPROM;
} if ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) == 0)
hw->fc = E1000_FC_NONE; elseif ((eeprom_data & EEPROM_WORD0F_PAUSE_MASK) ==
EEPROM_WORD0F_ASM_DIR)
hw->fc = E1000_FC_TX_PAUSE; else
hw->fc = E1000_FC_FULL;
}
/* We want to save off the original Flow Control configuration just *incasewegetdisconnectedandthenreconnectedintoadifferent *huborswitchwithdifferentFlowControlcapabilities.
*/ if (hw->mac_type == e1000_82542_rev2_0)
hw->fc &= (~E1000_FC_TX_PAUSE);
e_dbg("After fix-ups FlowControl is now = %x\n", hw->fc);
/* Take the 4 bits from EEPROM word 0x0F that determine the initial *polarityvaluefortheSWcontrolledpins,andsetupthe *ExtendedDeviceControlregwiththatinfo. *ThisisneededbecauseoneoftheSWcontrolledpinsisusedfor *signaldetection.Sothisshouldbedonebeforee1000_setup_pcs_link() *ore1000_phy_setup()iscalled.
*/ if (hw->mac_type == e1000_82543) {
ret_val = e1000_read_eeprom(hw, EEPROM_INIT_CONTROL2_REG, 1, &eeprom_data); if (ret_val) {
e_dbg("EEPROM Read Error\n"); return -E1000_ERR_EEPROM;
}
ctrl_ext = ((eeprom_data & EEPROM_WORD0F_SWPDIO_EXT) <<
SWDPIO__EXT_SHIFT);
ew32(CTRL_EXT, ctrl_ext);
}
/* Call the necessary subroutine to configure the link. */
ret_val = (hw->media_type == e1000_media_type_copper) ?
e1000_setup_copper_link(hw) : e1000_setup_fiber_serdes_link(hw);
/* Initialize the flow control address, type, and PAUSE timer *registerstotheirdefaultvalues.Thisisdoneevenifflow *controlisdisabled,becauseitdoesnothurtanythingto *initializetheseregisters.
*/
e_dbg("Initializing the Flow Control address, type and timer regs\n");
/* Set the flow control receive threshold registers. Normally, *theseregisterswillbesettoadefaultthresholdthatmaybe *adjustedlaterbythedriver'sruntimecode.However,ifthe *abilitytotransmitpauseframesinnotenabled,thenthese *registerswillbesetto0.
*/ if (!(hw->fc & E1000_FC_TX_PAUSE)) {
ew32(FCRTL, 0);
ew32(FCRTH, 0);
} else { /* We need to set up the Receive Threshold high and low water *marksaswellas(optionally)enablingthetransmissionof *XONframes.
*/ if (hw->fc_send_xon) {
ew32(FCRTL, (hw->fc_low_water | E1000_FCRTL_XONE));
ew32(FCRTH, hw->fc_high_water);
} else {
ew32(FCRTL, hw->fc_low_water);
ew32(FCRTH, hw->fc_high_water);
}
} return ret_val;
}
/* On adapters with a MAC newer than 82544, SWDP 1 will be *setwhentheopticsdetectasignal.Onolderadapters,itwillbe *clearedwhenthereisasignal.Thisappliestofibermediaonly. *Ifwe'reonserdesmedia,adjusttheoutputamplitudetovalue *setintheEEPROM.
*/
ctrl = er32(CTRL); if (hw->media_type == e1000_media_type_fiber)
signal = (hw->mac_type > e1000_82544) ? E1000_CTRL_SWDPIN1 : 0;
ret_val = e1000_adjust_serdes_amplitude(hw); if (ret_val) return ret_val;
/* Take the link out of reset */
ctrl &= ~(E1000_CTRL_LRST);
/* Adjust VCO speed to improve BER performance */
ret_val = e1000_set_vco_speed(hw); if (ret_val) return ret_val;
e1000_config_collision_dist(hw);
/* Check for a software override of the flow control settings, and setup *thedeviceaccordingly.Ifauto-negotiationisenabled,then *softwarewillhavetosetthe"PAUSE"bitstothecorrectvaluein *theTranmsitConfigWordRegister(TXCW)andre-start *auto-negotiation.However,ifauto-negotiationisdisabled,then *softwarewillhavetomanuallyconfigurethetwoflowcontrolenable *bitsintheCTRLregister. * *Thepossiblevaluesofthe"fc"parameterare: *0:Flowcontroliscompletelydisabled *1:Rxflowcontrolisenabled(wecanreceivepauseframes,but *notsendpauseframes). *2:Txflowcontrolisenabled(wecansendpauseframesbutwedo *notsupportreceivingpauseframes). *3:BothRxandTXflowcontrol(symmetric)areenabled.
*/ switch (hw->fc) { case E1000_FC_NONE: /* Flow ctrl is completely disabled by a software over-ride */
txcw = (E1000_TXCW_ANE | E1000_TXCW_FD); break; case E1000_FC_RX_PAUSE: /* Rx Flow control is enabled and Tx Flow control is disabled by *asoftwareover-ride.Sincetherereallyisn'tawayto *advertisethatwearecapableofRxPauseONLY,wewill *advertisethatwesupportbothsymmetricandasymmetricRx *PAUSE.Later,wewilldisabletheadapter'sabilitytosend *PAUSEframes.
*/
txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); break; case E1000_FC_TX_PAUSE: /* Tx Flow control is enabled, and Rx Flow control is disabled, *byasoftwareover-ride.
*/
txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_ASM_DIR); break; case E1000_FC_FULL: /* Flow control (both Rx and Tx) is enabled by a software *over-ride.
*/
txcw = (E1000_TXCW_ANE | E1000_TXCW_FD | E1000_TXCW_PAUSE_MASK); break; default:
e_dbg("Flow control param set incorrectly\n"); return -E1000_ERR_CONFIG;
}
/* Since auto-negotiation is enabled, take the link out of reset (the *linkwillbeinreset,becausewepreviouslyresetthechip).This *willrestartauto-negotiation.Ifauto-negotiationissuccessful *thenthelink-upstatusbitwillbesetandtheflowcontrolenable *bits(RFCEandTFCE)willbesetaccordingtotheirnegotiatedvalue.
*/
e_dbg("Auto-negotiation enabled\n");
/* If we have a signal (the cable is plugged in) then poll for a *"Link-Up"indicationintheDeviceStatusRegister.Time-outifa *linkisn'tseenin500millisecondsseconds(Auto-negotiationshould *completeinlessthan500millisecondseveniftheotherendisdoing *itinSW).Forinternalserdes,wejustassumeasignalispresent, *thenpoll.
*/ if (hw->media_type == e1000_media_type_internal_serdes ||
(er32(CTRL) & E1000_CTRL_SWDPIN1) == signal) {
e_dbg("Looking for Link\n"); for (i = 0; i < (LINK_UP_TIMEOUT / 10); i++) {
msleep(10);
status = er32(STATUS); if (status & E1000_STATUS_LU) break;
} if (i == (LINK_UP_TIMEOUT / 10)) {
e_dbg("Never got a valid link from auto-neg!!!\n");
hw->autoneg_failed = 1; /* AutoNeg failed to achieve a link, so we'll call *e1000_check_for_link.Thisroutinewillforcethe *linkupifwedetectasignal.Thiswillallowusto *communicatewithnon-autonegotiatinglinkpartners.
*/
ret_val = e1000_check_for_link(hw); if (ret_val) {
e_dbg("Error while checking for link\n"); return ret_val;
}
hw->autoneg_failed = 0;
} else {
hw->autoneg_failed = 0;
e_dbg("Valid Link Found\n");
}
} else {
e_dbg("No Signal Detected\n");
} return E1000_SUCCESS;
}
ctrl = er32(CTRL); /* With 82543, we need to force speed and duplex on the MAC equal to *whatthePHYspeedandduplexconfigurationis.Inaddition,weneed *toperformahardwareresetonthePHYtotakeitoutofreset.
*/ if (hw->mac_type > e1000_82543) {
ctrl |= E1000_CTRL_SLU;
ctrl &= ~(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
ew32(CTRL, ctrl);
} else {
ctrl |=
(E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX | E1000_CTRL_SLU);
ew32(CTRL, ctrl);
ret_val = e1000_phy_hw_reset(hw); if (ret_val) return ret_val;
}
/* Make sure we have a valid PHY */
ret_val = e1000_detect_gig_phy(hw); if (ret_val) {
e_dbg("Error, did not detect valid phy.\n"); return ret_val;
}
e_dbg("Phy ID = %x\n", hw->phy_id);
/* Set PHY to class A mode (if necessary) */
ret_val = e1000_set_phy_mode(hw); if (ret_val) return ret_val;
/* Enable CRS on TX. This must be set for half-duplex operation. */
ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); if (ret_val) return ret_val;
if (hw->phy_revision < M88E1011_I_REV_4) { /* Force TX_CLK in the Extended PHY Specific Control Register *to25MHzclock.
*/
ret_val =
e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
&phy_data); if (ret_val) return ret_val;
phy_data |= M88E1000_EPSCR_TX_CLK_25;
if ((hw->phy_revision == E1000_REVISION_2) &&
(hw->phy_id == M88E1111_I_PHY_ID)) { /* Vidalia Phy, set the downshift counter to 5x */
phy_data &= ~(M88EC018_EPSCR_DOWNSHIFT_COUNTER_MASK);
phy_data |= M88EC018_EPSCR_DOWNSHIFT_COUNTER_5X;
ret_val = e1000_write_phy_reg(hw,
M88E1000_EXT_PHY_SPEC_CTRL,
phy_data); if (ret_val) return ret_val;
} else { /* Configure Master and Slave downshift values */
phy_data &= ~(M88E1000_EPSCR_MASTER_DOWNSHIFT_MASK |
M88E1000_EPSCR_SLAVE_DOWNSHIFT_MASK);
phy_data |= (M88E1000_EPSCR_MASTER_DOWNSHIFT_1X |
M88E1000_EPSCR_SLAVE_DOWNSHIFT_1X);
ret_val = e1000_write_phy_reg(hw,
M88E1000_EXT_PHY_SPEC_CTRL,
phy_data); if (ret_val) return ret_val;
}
}
/* SW Reset the PHY so all changes take effect */
ret_val = e1000_phy_reset(hw); if (ret_val) {
e_dbg("Error Resetting the PHY\n"); return ret_val;
}
/* Perform some bounds checking on the hw->autoneg_advertised *parameter.Ifthisvariableiszero,thensetittothedefault.
*/
hw->autoneg_advertised &= AUTONEG_ADVERTISE_SPEED_DEFAULT;
/* If autoneg_advertised is zero, we assume it was not defaulted *bythecallingcodesowesettoadvertisefullcapability.
*/ if (hw->autoneg_advertised == 0)
hw->autoneg_advertised = AUTONEG_ADVERTISE_SPEED_DEFAULT;
/* IFE/RTL8201N PHY only supports 10/100 */ if (hw->phy_type == e1000_phy_8201)
hw->autoneg_advertised &= AUTONEG_ADVERTISE_10_100_ALL;
e_dbg("Reconfiguring auto-neg advertisement params\n");
ret_val = e1000_phy_setup_autoneg(hw); if (ret_val) {
e_dbg("Error Setting up Auto-Negotiation\n"); return ret_val;
}
e_dbg("Restarting Auto-Neg\n");
/* Restart auto-negotiation by setting the Auto Neg Enable bit and *theAutoNegRestartbitinthePHYcontrolregister.
*/
ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); if (ret_val) return ret_val;
/* Does the user want to wait for Auto-Neg to complete here, or *checkatalatertime(forexample,callbackroutine).
*/ if (hw->wait_autoneg_complete) {
ret_val = e1000_wait_autoneg(hw); if (ret_val) {
e_dbg
("Error while waiting for autoneg to complete\n"); return ret_val;
}
}
/* Check if it is a valid PHY and set PHY mode if necessary. */
ret_val = e1000_copper_link_preconfig(hw); if (ret_val) return ret_val;
if (hw->phy_type == e1000_phy_igp) {
ret_val = e1000_copper_link_igp_setup(hw); if (ret_val) return ret_val;
} elseif (hw->phy_type == e1000_phy_m88) {
ret_val = e1000_copper_link_mgp_setup(hw); if (ret_val) return ret_val;
} else {
ret_val = gbe_dhg_phy_setup(hw); if (ret_val) {
e_dbg("gbe_dhg_phy_setup failed!\n"); return ret_val;
}
}
if (hw->autoneg) { /* Setup autoneg and flow control advertisement *andperformautonegotiation
*/
ret_val = e1000_copper_link_autoneg(hw); if (ret_val) return ret_val;
} else { /* PHY will be set to 10H, 10F, 100H,or 100F *dependingonvaluefromforced_speed_duplex.
*/
e_dbg("Forcing speed and duplex\n");
ret_val = e1000_phy_force_speed_duplex(hw); if (ret_val) {
e_dbg("Error Forcing Speed and Duplex\n"); return ret_val;
}
}
/* Check link status. Wait up to 100 microseconds for link to become *valid.
*/ for (i = 0; i < 10; i++) {
ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); if (ret_val) return ret_val;
ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); if (ret_val) return ret_val;
if (phy_data & MII_SR_LINK_STATUS) { /* Config the MAC and PHY after link is up */
ret_val = e1000_copper_link_postconfig(hw); if (ret_val) return ret_val;
e_dbg("Valid link established!!!\n"); return E1000_SUCCESS;
}
udelay(10);
}
e_dbg("Unable to establish link!!!\n"); return E1000_SUCCESS;
}
/* Read the MII Auto-Neg Advertisement Register (Address 4). */
ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV, &mii_autoneg_adv_reg); if (ret_val) return ret_val;
/* Read the MII 1000Base-T Control Register (Address 9). */
ret_val = e1000_read_phy_reg(hw, PHY_1000T_CTRL, &mii_1000t_ctrl_reg); if (ret_val) return ret_val; elseif (hw->phy_type == e1000_phy_8201)
mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
/* Need to parse both autoneg_advertised and fc and set up *theappropriatePHYregisters.Firstwewillparsefor *autoneg_advertisedsoftwareoverride.Sincewecanadvertise *aplethoraofcombinations,weneedtocheckeachbit *individually.
*/
/* First we clear all the 10/100 mb speed bits in the Auto-Neg *AdvertisementRegister(Address4)andthe1000mbspeedbitsin *the1000Base-TControlRegister(Address9).
*/
mii_autoneg_adv_reg &= ~REG4_SPEED_MASK;
mii_1000t_ctrl_reg &= ~REG9_SPEED_MASK;
/* Do we want to advertise 10 Mb Half Duplex? */ if (hw->autoneg_advertised & ADVERTISE_10_HALF) {
e_dbg("Advertise 10mb Half duplex\n");
mii_autoneg_adv_reg |= NWAY_AR_10T_HD_CAPS;
}
/* Do we want to advertise 10 Mb Full Duplex? */ if (hw->autoneg_advertised & ADVERTISE_10_FULL) {
e_dbg("Advertise 10mb Full duplex\n");
mii_autoneg_adv_reg |= NWAY_AR_10T_FD_CAPS;
}
/* Do we want to advertise 100 Mb Half Duplex? */ if (hw->autoneg_advertised & ADVERTISE_100_HALF) {
e_dbg("Advertise 100mb Half duplex\n");
mii_autoneg_adv_reg |= NWAY_AR_100TX_HD_CAPS;
}
/* Do we want to advertise 100 Mb Full Duplex? */ if (hw->autoneg_advertised & ADVERTISE_100_FULL) {
e_dbg("Advertise 100mb Full duplex\n");
mii_autoneg_adv_reg |= NWAY_AR_100TX_FD_CAPS;
}
/* We do not allow the Phy to advertise 1000 Mb Half Duplex */ if (hw->autoneg_advertised & ADVERTISE_1000_HALF) {
e_dbg
("Advertise 1000mb Half duplex requested, request denied!\n");
}
/* Do we want to advertise 1000 Mb Full Duplex? */ if (hw->autoneg_advertised & ADVERTISE_1000_FULL) {
e_dbg("Advertise 1000mb Full duplex\n");
mii_1000t_ctrl_reg |= CR_1000T_FD_CAPS;
}
/* Check for a software override of the flow control settings, and *setupthePHYadvertisementregistersaccordingly.If *auto-negotiationisenabled,thensoftwarewillhavetosetthe *"PAUSE"bitstothecorrectvalueintheAuto-Negotiation *AdvertisementRegister(PHY_AUTONEG_ADV)andre-start *auto-negotiation. * *Thepossiblevaluesofthe"fc"parameterare: *0:Flowcontroliscompletelydisabled *1:Rxflowcontrolisenabled(wecanreceivepauseframes *butnotsendpauseframes). *2:Txflowcontrolisenabled(wecansendpauseframes *butwedonotsupportreceivingpauseframes). *3:BothRxandTXflowcontrol(symmetric)areenabled. *other:Nosoftwareoverride.Theflowcontrolconfiguration *intheEEPROMisused.
*/ switch (hw->fc) { case E1000_FC_NONE: /* 0 */ /* Flow control (RX & TX) is completely disabled by a *softwareover-ride.
*/
mii_autoneg_adv_reg &= ~(NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); break; case E1000_FC_RX_PAUSE: /* 1 */ /* RX Flow control is enabled, and TX Flow control is *disabled,byasoftwareover-ride.
*/ /* Since there really isn't a way to advertise that we are *capableofRXPauseONLY,wewilladvertisethatwe *supportbothsymmetricandasymmetricRXPAUSE.Later *(ine1000_config_fc_after_link_up)wewilldisablethe *hw'sabilitytosendPAUSEframes.
*/
mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); break; case E1000_FC_TX_PAUSE: /* 2 */ /* TX Flow control is enabled, and RX Flow control is *disabled,byasoftwareover-ride.
*/
mii_autoneg_adv_reg |= NWAY_AR_ASM_DIR;
mii_autoneg_adv_reg &= ~NWAY_AR_PAUSE; break; case E1000_FC_FULL: /* 3 */ /* Flow control (both RX and TX) is enabled by a software *over-ride.
*/
mii_autoneg_adv_reg |= (NWAY_AR_ASM_DIR | NWAY_AR_PAUSE); break; default:
e_dbg("Flow control param set incorrectly\n"); return -E1000_ERR_CONFIG;
}
ret_val = e1000_write_phy_reg(hw, PHY_AUTONEG_ADV, mii_autoneg_adv_reg); if (ret_val) return ret_val;
/* Turn off Flow control if we are forcing speed and duplex. */
hw->fc = E1000_FC_NONE;
e_dbg("hw->fc = %d\n", hw->fc);
/* Read the Device Control Register. */
ctrl = er32(CTRL);
/* Set the bits to Force Speed and Duplex in the Device Ctrl Reg. */
ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
ctrl &= ~(DEVICE_SPEED_MASK);
/* Clear the Auto Speed Detect Enable bit. */
ctrl &= ~E1000_CTRL_ASDE;
/* Read the MII Control Register. */
ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &mii_ctrl_reg); if (ret_val) return ret_val;
/* We need to disable autoneg in order to force link and duplex. */
mii_ctrl_reg &= ~MII_CR_AUTO_NEG_EN;
/* Are we forcing Full or Half Duplex? */ if (hw->forced_speed_duplex == e1000_100_full ||
hw->forced_speed_duplex == e1000_10_full) { /* We want to force full duplex so we SET the full duplex bits *intheDeviceandMIIControlRegisters.
*/
ctrl |= E1000_CTRL_FD;
mii_ctrl_reg |= MII_CR_FULL_DUPLEX;
e_dbg("Full Duplex\n");
} else { /* We want to force half duplex so we CLEAR the full duplex bits *intheDeviceandMIIControlRegisters.
*/
ctrl &= ~E1000_CTRL_FD;
mii_ctrl_reg &= ~MII_CR_FULL_DUPLEX;
e_dbg("Half Duplex\n");
}
/* Are we forcing 100Mbps??? */ if (hw->forced_speed_duplex == e1000_100_full ||
hw->forced_speed_duplex == e1000_100_half) { /* Set the 100Mb bit and turn off the 1000Mb and 10Mb bits. */
ctrl |= E1000_CTRL_SPD_100;
mii_ctrl_reg |= MII_CR_SPEED_100;
mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_10);
e_dbg("Forcing 100mb ");
} else { /* Set the 10Mb bit and turn off the 1000Mb and 100Mb bits. */
ctrl &= ~(E1000_CTRL_SPD_1000 | E1000_CTRL_SPD_100);
mii_ctrl_reg |= MII_CR_SPEED_10;
mii_ctrl_reg &= ~(MII_CR_SPEED_1000 | MII_CR_SPEED_100);
e_dbg("Forcing 10mb ");
}
e1000_config_collision_dist(hw);
/* Write the configured values back to the Device Control Reg. */
ew32(CTRL, ctrl);
if (hw->phy_type == e1000_phy_m88) {
ret_val =
e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); if (ret_val) return ret_val;
/* Clear Auto-Crossover to force MDI manually. M88E1000 requires *MDIforcedwheneverspeedareduplexareforced.
*/
phy_data &= ~M88E1000_PSCR_AUTO_X_MODE;
ret_val =
e1000_write_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, phy_data); if (ret_val) return ret_val;
e_dbg("M88E1000 PSCR: %x\n", phy_data);
/* Need to reset the PHY or these changes will be ignored */
mii_ctrl_reg |= MII_CR_RESET;
/* Disable MDI-X support for 10/100 */
} else { /* Clear Auto-Crossover to force MDI manually. IGP requires MDI *forcedwheneverspeedorduplexareforced.
*/
ret_val =
e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, &phy_data); if (ret_val) return ret_val;
ret_val =
e1000_write_phy_reg(hw, IGP01E1000_PHY_PORT_CTRL, phy_data); if (ret_val) return ret_val;
}
/* Write back the modified PHY MII control register. */
ret_val = e1000_write_phy_reg(hw, PHY_CTRL, mii_ctrl_reg); if (ret_val) return ret_val;
udelay(1);
/* The wait_autoneg_complete flag may be a little misleading here. *Sinceweareforcingspeedandduplex,Auto-Negisnotenabled. *Butwedowanttodelayforaperiodwhileforcingonlysowe *don'tgeneratefalseNoLinkmessages.Sowewillwaithere *onlyiftheuserhassetwait_autoneg_completeto1,whichis *thedefault.
*/ if (hw->wait_autoneg_complete) { /* We will wait for autoneg to complete. */
e_dbg("Waiting for forced speed/duplex link.\n");
mii_status_reg = 0;
/* Wait for autoneg to complete or 4.5 seconds to expire */ for (i = PHY_FORCE_TIME; i > 0; i--) { /* Read the MII Status Register and wait for Auto-Neg *Completebittobeset.
*/
ret_val =
e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); if (ret_val) return ret_val;
ret_val =
e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); if (ret_val) return ret_val;
if (mii_status_reg & MII_SR_LINK_STATUS) break;
msleep(100);
} if ((i == 0) && (hw->phy_type == e1000_phy_m88)) { /* We didn't get link. Reset the DSP and wait again *forlink.
*/
ret_val = e1000_phy_reset_dsp(hw); if (ret_val) {
e_dbg("Error Resetting PHY DSP\n"); return ret_val;
}
} /* This loop will early-out if the link condition has been *met
*/ for (i = PHY_FORCE_TIME; i > 0; i--) { if (mii_status_reg & MII_SR_LINK_STATUS) break;
msleep(100); /* Read the MII Status Register and wait for Auto-Neg *Completebittobeset.
*/
ret_val =
e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); if (ret_val) return ret_val;
if (hw->phy_type == e1000_phy_m88) { /* Because we reset the PHY above, we need to re-force TX_CLK in *theExtendedPHYSpecificControlRegisterto25MHzclock. *Thisvaluedefaultsbacktoa2.5MHzclockwhenthePHYis *reset.
*/
ret_val =
e1000_read_phy_reg(hw, M88E1000_EXT_PHY_SPEC_CTRL,
&phy_data); if (ret_val) return ret_val;
/* In addition, because of the s/w reset above, we need to *enableCRSonTx.Thismustbesetforbothfullandhalf *duplexoperation.
*/
ret_val =
e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); if (ret_val) return ret_val;
/* 82544 or newer MAC, Auto Speed Detection takes care of *MACspeed/duplexconfiguration.
*/ if ((hw->mac_type >= e1000_82544) && (hw->mac_type != e1000_ce4100)) return E1000_SUCCESS;
/* Read the Device Control Register and set the bits to Force Speed *andDuplex.
*/
ctrl = er32(CTRL);
ctrl |= (E1000_CTRL_FRCSPD | E1000_CTRL_FRCDPX);
ctrl &= ~(E1000_CTRL_SPD_SEL | E1000_CTRL_ILOS);
switch (hw->phy_type) { case e1000_phy_8201:
ret_val = e1000_read_phy_reg(hw, PHY_CTRL, &phy_data); if (ret_val) return ret_val;
e1000_config_collision_dist(hw); break; default: /* Set up duplex in the Device Control and Transmit Control *registersdependingonnegotiatedvalues.
*/
ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
&phy_data); if (ret_val) return ret_val;
/* Set up speed in the Device Control register depending on *negotiatedvalues.
*/ if ((phy_data & M88E1000_PSSR_SPEED) == M88E1000_PSSR_1000MBS)
ctrl |= E1000_CTRL_SPD_1000; elseif ((phy_data & M88E1000_PSSR_SPEED) ==
M88E1000_PSSR_100MBS)
ctrl |= E1000_CTRL_SPD_100;
}
/* Write the configured values back to the Device Control Reg. */
ew32(CTRL, ctrl); return E1000_SUCCESS;
}
/* Get the current configuration of the Device Control Register */
ctrl = er32(CTRL);
/* Because we didn't get link via the internal auto-negotiation *mechanism(weeitherforcedlinkorwegotlinkviaPHY *auto-neg),wehavetomanuallyenable/disabletransmitan *receiveflowcontrol. * *The"Case"statementbelowenables/disableflowcontrol *accordingtothe"hw->fc"parameter. * *Thepossiblevaluesofthe"fc"parameterare: *0:Flowcontroliscompletelydisabled *1:Rxflowcontrolisenabled(wecanreceivepause *framesbutnotsendpauseframes). *2:Txflowcontrolisenabled(wecansendpauseframes *butwedonotreceivepauseframes). *3:BothRxandTXflowcontrol(symmetric)isenabled. *other:Noothervaluesshouldbepossibleatthispoint.
*/
switch (hw->fc) { case E1000_FC_NONE:
ctrl &= (~(E1000_CTRL_TFCE | E1000_CTRL_RFCE)); break; case E1000_FC_RX_PAUSE:
ctrl &= (~E1000_CTRL_TFCE);
ctrl |= E1000_CTRL_RFCE; break; case E1000_FC_TX_PAUSE:
ctrl &= (~E1000_CTRL_RFCE);
ctrl |= E1000_CTRL_TFCE; break; case E1000_FC_FULL:
ctrl |= (E1000_CTRL_TFCE | E1000_CTRL_RFCE); break; default:
e_dbg("Flow control param set incorrectly\n"); return -E1000_ERR_CONFIG;
}
/* Disable TX Flow Control for 82542 (rev 2.0) */ if (hw->mac_type == e1000_82542_rev2_0)
ctrl &= (~E1000_CTRL_TFCE);
/* Check for the case where we have fiber media and auto-neg failed *sowehadtoforcelink.Inthiscase,weneedtoforcethe *configurationoftheMACtomatchthe"fc"parameter.
*/ if (((hw->media_type == e1000_media_type_fiber) &&
(hw->autoneg_failed)) ||
((hw->media_type == e1000_media_type_internal_serdes) &&
(hw->autoneg_failed)) ||
((hw->media_type == e1000_media_type_copper) &&
(!hw->autoneg))) {
ret_val = e1000_force_mac_fc(hw); if (ret_val) {
e_dbg("Error forcing flow control settings\n"); return ret_val;
}
}
/* Check for the case where we have copper media and auto-neg is *enabled.Inthiscase,weneedtocheckandseeifAuto-Neg *hascompleted,andifso,howthePHYandlinkpartnerhas *flowcontrolconfigured.
*/ if ((hw->media_type == e1000_media_type_copper) && hw->autoneg) { /* Read the MII Status Register and check to see if AutoNeg *hascompleted.Wereadthistwicebecausethisreghas *some"sticky"(latched)bits.
*/
ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); if (ret_val) return ret_val;
ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); if (ret_val) return ret_val;
if (mii_status_reg & MII_SR_AUTONEG_COMPLETE) { /* The AutoNeg process has completed, so we now need to *readboththeAutoNegotiationAdvertisementRegister *(Address4)andtheAuto_NegotiationBasePage *AbilityRegister(Address5)todeterminehowflow *controlwasnegotiated.
*/
ret_val = e1000_read_phy_reg(hw, PHY_AUTONEG_ADV,
&mii_nway_adv_reg); if (ret_val) return ret_val;
ret_val = e1000_read_phy_reg(hw, PHY_LP_ABILITY,
&mii_nway_lp_ability_reg); if (ret_val) return ret_val;
/* Two bits in the Auto Negotiation Advertisement *Register(Address4)andtwobitsintheAuto *NegotiationBasePageAbilityRegister(Address5) *determineflowcontrolforboththePHYandthelink *partner.Thefollowingtable,takenoutoftheIEEE *802.3ab/D6.0datedMarch25,1999,describesthese *PAUSEresolutionbitsandhowflowcontrolis *determinedbaseduponthesesettings. *NOTE:DC=Don'tCare * *LOCALDEVICE|LINKPARTNER *PAUSE|ASM_DIR|PAUSE|ASM_DIR|NICResolution *-------|---------|-------|---------|------------------ *0|0|DC|DC|E1000_FC_NONE *0|1|0|DC|E1000_FC_NONE *0|1|1|0|E1000_FC_NONE *0|1|1|1|E1000_FC_TX_PAUSE *1|0|0|DC|E1000_FC_NONE *1|DC|1|DC|E1000_FC_FULL *1|1|0|0|E1000_FC_NONE *1|1|0|1|E1000_FC_RX_PAUSE *
*/ /* Are both PAUSE bits set to 1? If so, this implies *SymmetricFlowControlisenabledatbothends.The *ASM_DIRbitsareirrelevantperthespec. * *ForSymmetricFlowControl: * *LOCALDEVICE|LINKPARTNER *PAUSE|ASM_DIR|PAUSE|ASM_DIR|Result *-------|---------|-------|---------|------------------ *1|DC|1|DC|E1000_FC_FULL *
*/ if ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE)) { /* Now we need to check if the user selected Rx *ONLYofpauseframes.Inthiscase,wehad *toadvertiseFULLflowcontrolbecausewe *couldnotadvertiseRxONLY.Hence,wemust *nowchecktoseeifweneedtoturnOFFthe *TRANSMISSIONofPAUSEframes.
*/ if (hw->original_fc == E1000_FC_FULL) {
hw->fc = E1000_FC_FULL;
e_dbg("Flow Control = FULL.\n");
} else {
hw->fc = E1000_FC_RX_PAUSE;
e_dbg
("Flow Control = RX PAUSE frames only.\n");
}
} /* For receiving PAUSE frames ONLY. * *LOCALDEVICE|LINKPARTNER *PAUSE|ASM_DIR|PAUSE|ASM_DIR|Result *-------|---------|-------|---------|------------------ *0|1|1|1|E1000_FC_TX_PAUSE *
*/ elseif (!(mii_nway_adv_reg & NWAY_AR_PAUSE) &&
(mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
(mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
hw->fc = E1000_FC_TX_PAUSE;
e_dbg
("Flow Control = TX PAUSE frames only.\n");
} /* For transmitting PAUSE frames ONLY. * *LOCALDEVICE|LINKPARTNER *PAUSE|ASM_DIR|PAUSE|ASM_DIR|Result *-------|---------|-------|---------|------------------ *1|1|0|1|E1000_FC_RX_PAUSE *
*/ elseif ((mii_nway_adv_reg & NWAY_AR_PAUSE) &&
(mii_nway_adv_reg & NWAY_AR_ASM_DIR) &&
!(mii_nway_lp_ability_reg & NWAY_LPAR_PAUSE) &&
(mii_nway_lp_ability_reg & NWAY_LPAR_ASM_DIR)) {
hw->fc = E1000_FC_RX_PAUSE;
e_dbg
("Flow Control = RX PAUSE frames only.\n");
} /* Per the IEEE spec, at this point flow control should *bedisabled.However,wewanttoconsiderthatwe *couldbeconnectedtoalegacyswitchthatdoesn't *advertisedesiredflowcontrol,butcanbeforcedon *thelinkpartner.Soifweadvertisednoflow *control,thatiswhatwewillresolveto.Ifwe *advertisedsomekindofreceivecapability(RxPause *OnlyorFullFlowControl)andthelinkpartner *advertisednone,wewillconfigureourselvesto *enableRxFlowControlonly.Wecandothissafely *fortworeasons:Ifthelinkpartnerreally *didn'twantflowcontrolenabled,andweenableRx, *noharmdonesincewewon'tbereceivinganyPAUSE *framesanyway.Iftheintentonthelinkpartnerwas *tohaveflowcontrolenabled,thenbyusenablingRx *only,wecanatleastreceivepauseframesand *processthem.Thisisagoodideabecauseinmost *cases,sincewearepredominantlyaserverNIC,more *timesthannotwewillbeaskedtodelaytransmission *ofpacketsthanaskingourlinkpartnertopause *transmissionofframes.
*/ elseif ((hw->original_fc == E1000_FC_NONE ||
hw->original_fc == E1000_FC_TX_PAUSE) ||
hw->fc_strict_ieee) {
hw->fc = E1000_FC_NONE;
e_dbg("Flow Control = NONE.\n");
} else {
hw->fc = E1000_FC_RX_PAUSE;
e_dbg
("Flow Control = RX PAUSE frames only.\n");
}
/* Now we need to do one last check... If we auto- *negotiatedtoHALFDUPLEX,flowcontrolshouldnotbe *enabledperIEEE802.3spec.
*/
ret_val =
e1000_get_speed_and_duplex(hw, &speed, &duplex); if (ret_val) {
e_dbg
("Error getting link speed and duplex\n"); return ret_val;
}
if (duplex == HALF_DUPLEX)
hw->fc = E1000_FC_NONE;
/* Now we call a subroutine to actually force the MAC *controllertousethecorrectflowcontrolsettings.
*/
ret_val = e1000_force_mac_fc(hw); if (ret_val) {
e_dbg
("Error forcing flow control settings\n"); return ret_val;
}
} else {
e_dbg
("Copper PHY and Auto Neg has not completed.\n");
}
} return E1000_SUCCESS;
}
ctrl = er32(CTRL);
status = er32(STATUS);
rxcw = er32(RXCW);
/* If we don't have link (auto-negotiation failed or link partner *cannotauto-negotiate),andourlinkpartnerisnottryingto *auto-negotiatewithus(wearereceivingidlesordata), *weneedtoforcelinkup.Wealsoneedtogiveauto-negotiation *timetocomplete.
*/ /* (ctrl & E1000_CTRL_SWDPIN1) == 1 == have signal */ if ((!(status & E1000_STATUS_LU)) && (!(rxcw & E1000_RXCW_C))) { if (hw->autoneg_failed == 0) {
hw->autoneg_failed = 1; goto out;
}
e_dbg("NOT RXing /C/, disable AutoNeg and force link.\n");
/* Disable auto-negotiation in the TXCW register */
ew32(TXCW, (hw->txcw & ~E1000_TXCW_ANE));
/* Force link-up and also force full-duplex. */
ctrl = er32(CTRL);
ctrl |= (E1000_CTRL_SLU | E1000_CTRL_FD);
ew32(CTRL, ctrl);
/* Configure Flow Control after forcing link up. */
ret_val = e1000_config_fc_after_link_up(hw); if (ret_val) {
e_dbg("Error configuring flow control\n"); goto out;
}
} elseif ((ctrl & E1000_CTRL_SLU) && (rxcw & E1000_RXCW_C)) { /* If we are forcing link and we are receiving /C/ ordered *sets,re-enableauto-negotiationintheTXCWregister *anddisableforcedlinkintheDeviceControlregister *inanattempttoauto-negotiatewithourlinkpartner.
*/
e_dbg("RXing /C/, enable AutoNeg and stop forcing link.\n");
ew32(TXCW, hw->txcw);
ew32(CTRL, (ctrl & ~E1000_CTRL_SLU));
hw->serdes_has_link = true;
} elseif (!(E1000_TXCW_ANE & er32(TXCW))) { /* If we force link for non-auto-negotiation switch, check *linkstatusbasedonMACsynchronizationforinternal *serdesmediatype.
*/ /* SYNCH bit and IV bit are sticky. */
udelay(10);
rxcw = er32(RXCW); if (rxcw & E1000_RXCW_SYNCH) { if (!(rxcw & E1000_RXCW_IV)) {
hw->serdes_has_link = true;
e_dbg("SERDES: Link up - forced.\n");
}
} else {
hw->serdes_has_link = false;
e_dbg("SERDES: Link down - force failed.\n");
}
}
if (E1000_TXCW_ANE & er32(TXCW)) {
status = er32(STATUS); if (status & E1000_STATUS_LU) { /* SYNCH bit and IV bit are sticky, so reread rxcw. */
udelay(10);
rxcw = er32(RXCW); if (rxcw & E1000_RXCW_SYNCH) { if (!(rxcw & E1000_RXCW_IV)) {
hw->serdes_has_link = true;
e_dbg("SERDES: Link up - autoneg " "completed successfully.\n");
} else {
hw->serdes_has_link = false;
e_dbg("SERDES: Link down - invalid" "codewords detected in autoneg.\n");
}
} else {
hw->serdes_has_link = false;
e_dbg("SERDES: Link down - no sync.\n");
}
} else {
hw->serdes_has_link = false;
e_dbg("SERDES: Link down - autoneg failed\n");
}
}
/* On adapters with a MAC newer than 82544, SW Definable pin 1 will be *setwhentheopticsdetectasignal.Onolderadapters,itwillbe *clearedwhenthereisasignal.Thisappliestofibermediaonly.
*/ if ((hw->media_type == e1000_media_type_fiber) ||
(hw->media_type == e1000_media_type_internal_serdes)) {
er32(RXCW);
if (hw->media_type == e1000_media_type_fiber) { if (status & E1000_STATUS_LU)
hw->get_link_status = false;
}
}
/* If we have a copper PHY then we only want to go out to the PHY *registerstoseeifAuto-Neghascompletedand/orifourlink *statushaschanged.Theget_link_statusflagwillbesetifwe *receiveaLinkStatusChangeinterruptorwehaveRxSequence *Errors.
*/ if ((hw->media_type == e1000_media_type_copper) && hw->get_link_status) { /* First we want to see if the MII Status Register reports *link.Ifso,thenwewanttogetthecurrentspeed/duplex *ofthePHY. *Readtheregistertwicesincethelinkbitissticky.
*/
ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); if (ret_val) return ret_val;
ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); if (ret_val) return ret_val;
if (phy_data & MII_SR_LINK_STATUS) {
hw->get_link_status = false; /* Check if there was DownShift, must be checked *immediatelyafterlink-up
*/
e1000_check_downshift(hw);
/* If we are on 82544 or 82543 silicon and speed/duplex *areforcedto10Hor10F,thenwewillimplementthe *polarityreversalworkaround.Wedisableinterrupts *first,anduponreturning,placethedevices *interruptstatetoitspreviousvalueexceptforthe *linkstatuschangeinterruptwhichwill *happenduetotheexecutionofthisworkaround.
*/
} else { /* No link detected */
e1000_config_dsp_after_link_change(hw, false); return0;
}
/* If we are forcing speed/duplex, then we simply return since *wehavealreadydeterminedwhetherwehavelinkornot.
*/ if (!hw->autoneg) return -E1000_ERR_CONFIG;
/* optimize the dsp settings for the igp phy */
e1000_config_dsp_after_link_change(hw, true);
/* We have a M88E1000 PHY and Auto-Neg is enabled. If we *haveSionboardthatis82544ornewer,Auto *SpeedDetectiontakescareofMACspeed/duplex *configuration.SoweonlyneedtoconfigureCollision *DistanceintheMAC.Otherwise,weneedtoforce *speed/duplexontheMACtothecurrentPHYspeed/duplex *settings.
*/ if ((hw->mac_type >= e1000_82544) &&
(hw->mac_type != e1000_ce4100))
e1000_config_collision_dist(hw); else {
ret_val = e1000_config_mac_to_phy(hw); if (ret_val) {
e_dbg
("Error configuring MAC to PHY settings\n"); return ret_val;
}
}
/* Configure Flow Control now that Auto-Neg has completed. *First,weneedtorestorethedesiredflowcontrolsettings *becausewemayhavehadtore-autonegwithadifferentlink *partner.
*/
ret_val = e1000_config_fc_after_link_up(hw); if (ret_val) {
e_dbg("Error configuring flow control\n"); return ret_val;
}
/* At this point we know that we are on copper and we have *auto-negotiatedlink.Theseareconditionsforcheckingthe *linkpartnercapabilityregister.Weusethelinkspeedto *determineifTBIcompatibilityneedstobeturnedonoroff. *Ifthelinkisnotatgigabitspeed,thenTBIcompatibility *isnotneeded.Ifweareatgigabitspeed,weturnonTBI *compatibility.
*/ if (hw->tbi_compatibility_en) {
u16 speed, duplex;
if (ret_val) {
e_dbg
("Error getting link speed and duplex\n"); return ret_val;
} if (speed != SPEED_1000) { /* If link speed is not set to gigabit speed, we *donotneedtoenableTBIcompatibility.
*/ if (hw->tbi_compatibility_on) { /* If we previously were in the mode, *turnitoff.
*/
rctl = er32(RCTL);
rctl &= ~E1000_RCTL_SBP;
ew32(RCTL, rctl);
hw->tbi_compatibility_on = false;
}
} else { /* If TBI compatibility is was previously off, *turniton.ForcompatibilitywithaTBIlink *partner,wewillstorebadpackets.Some *frameshaveanadditionalbyteontheendand *willlooklikeCRCerrorstothehardware.
*/ if (!hw->tbi_compatibility_on) {
hw->tbi_compatibility_on = true;
rctl = er32(RCTL);
rctl |= E1000_RCTL_SBP;
ew32(RCTL, rctl);
}
}
}
}
if ((hw->media_type == e1000_media_type_fiber) ||
(hw->media_type == e1000_media_type_internal_serdes))
e1000_check_for_serdes_link_generic(hw);
/* We will wait for autoneg to complete or 4.5 seconds to expire. */ for (i = PHY_AUTO_NEG_TIME; i > 0; i--) { /* Read the MII Status Register and wait for Auto-Neg *Completebittobeset.
*/
ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); if (ret_val) return ret_val;
ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &phy_data); if (ret_val) return ret_val; if (phy_data & MII_SR_AUTONEG_COMPLETE) return E1000_SUCCESS;
msleep(100);
} return E1000_SUCCESS;
}
/** *e1000_raise_mdi_clk-RaisestheManagementDataClock *@hw:Structcontainingvariablesaccessedbysharedcode *@ctrl:Devicecontrolregister'scurrentvalue
*/ staticvoid e1000_raise_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
{ /* Raise the clock input to the Management Data Clock (by setting the *MDCbit),andthendelay10microseconds.
*/
ew32(CTRL, (*ctrl | E1000_CTRL_MDC));
E1000_WRITE_FLUSH();
udelay(10);
}
/** *e1000_lower_mdi_clk-LowerstheManagementDataClock *@hw:Structcontainingvariablesaccessedbysharedcode *@ctrl:Devicecontrolregister'scurrentvalue
*/ staticvoid e1000_lower_mdi_clk(struct e1000_hw *hw, u32 *ctrl)
{ /* Lower the clock input to the Management Data Clock (by clearing the *MDCbit),andthendelay10microseconds.
*/
ew32(CTRL, (*ctrl & ~E1000_CTRL_MDC));
E1000_WRITE_FLUSH();
udelay(10);
}
/* We need to shift "count" number of bits out to the PHY. So, the value *inthe"data"parameterwillbeshiftedouttothePHYonebitata *time.Inordertodothis,"data"mustbebrokendownintobits.
*/
mask = 0x01;
mask <<= (count - 1);
ctrl = er32(CTRL);
/* Set MDIO_DIR and MDC_DIR direction bits to be used as output pins. */
ctrl |= (E1000_CTRL_MDIO_DIR | E1000_CTRL_MDC_DIR);
while (mask) { /* A "1" is shifted out to the PHY by setting the MDIO bit to *"1"andthenraisingandloweringtheManagementDataClock. *A"0"isshiftedouttothePHYbysettingtheMDIObitto *"0"andthenraisingandloweringtheclock.
*/ if (data & mask)
ctrl |= E1000_CTRL_MDIO; else
ctrl &= ~E1000_CTRL_MDIO;
/* In order to read a register from the PHY, we need to shift in a total *of18bitsfromthePHY.Thefirsttwobit(turnaround)timesare *usedtoavoidcontentionontheMDIOpinwhenareadoperationis *performed.Thesetwobitsareignoredbyusandthrownaway.Bitsare *"shiftedin"byraisingtheinputtotheManagementDataClock *(settingtheMDCbit),andthenreadingthevalueoftheMDIObit.
*/
ctrl = er32(CTRL);
/* Clear MDIO_DIR (SWDPIO1) to indicate this bit is to be used as *input.
*/
ctrl &= ~E1000_CTRL_MDIO_DIR;
ctrl &= ~E1000_CTRL_MDIO;
ew32(CTRL, ctrl);
E1000_WRITE_FLUSH();
/* Raise and Lower the clock before reading in the data. This accounts *fortheturnaroundbits.Thefirstclockoccurredwhenweclockedout *thelastbitoftheRegisterAddress.
*/
e1000_raise_mdi_clk(hw, &ctrl);
e1000_lower_mdi_clk(hw, &ctrl);
for (data = 0, i = 0; i < 16; i++) {
data = data << 1;
e1000_raise_mdi_clk(hw, &ctrl);
ctrl = er32(CTRL); /* Check to see if we shifted in a "1". */ if (ctrl & E1000_CTRL_MDIO)
data |= 1;
e1000_lower_mdi_clk(hw, &ctrl);
}
if (reg_addr > MAX_PHY_REG_ADDRESS) {
e_dbg("PHY Address %d is out of range\n", reg_addr); return -E1000_ERR_PARAM;
}
if (hw->mac_type > e1000_82543) { /* Set up Op-code, Phy Address, and register address in the MDI *Controlregister.TheMACwilltakecareofinterfacingwith *thePHYtoretrievethedesireddata.
*/ if (hw->mac_type == e1000_ce4100) {
mdic = ((reg_addr << E1000_MDIC_REG_SHIFT) |
(phy_addr << E1000_MDIC_PHY_SHIFT) |
(INTEL_CE_GBE_MDIC_OP_READ) |
(INTEL_CE_GBE_MDIC_GO));
writel(mdic, E1000_MDIO_CMD);
/* Poll the ready bit to see if the MDI read *completed
*/ for (i = 0; i < 64; i++) {
udelay(50);
mdic = readl(E1000_MDIO_CMD); if (!(mdic & INTEL_CE_GBE_MDIC_GO)) break;
}
if (mdic & INTEL_CE_GBE_MDIC_GO) {
e_dbg("MDI Read did not complete\n"); return -E1000_ERR_PHY;
}
/* Poll the ready bit to see if the MDI read *completed
*/ for (i = 0; i < 64; i++) {
udelay(50);
mdic = er32(MDIC); if (mdic & E1000_MDIC_READY) break;
} if (!(mdic & E1000_MDIC_READY)) {
e_dbg("MDI Read did not complete\n"); return -E1000_ERR_PHY;
} if (mdic & E1000_MDIC_ERROR) {
e_dbg("MDI Error\n"); return -E1000_ERR_PHY;
}
*phy_data = (u16)mdic;
}
} else { /* We must first send a preamble through the MDIO pin to signal *thebeginningofanMIIinstruction.Thisisdonebysending *32consecutive"1"bits.
*/
e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
/* Now combine the next few fields that are required for a read *operation.Weusethismethodinsteadofcallingthe *e1000_shift_out_mdi_bitsroutinefivedifferenttimes.The *formatofaMIIreadinstructionconsistsofashiftoutof *14bitsandisdefinedasfollows: *<Preamble><SOF><OpCode><PhyAddr><RegAddr> *followedbyashiftinof18bits.Thisfirsttwobits *shiftedinareTurnAroundbitsusedtoavoidcontentionon *theMDIOpinwhenaREADoperationisperformed.Thesetwo *bitsarethrownawayfollowedbyashiftinof16bitswhich *containsthedesireddata.
*/
mdic = ((reg_addr) | (phy_addr << 5) |
(PHY_OP_READ << 10) | (PHY_SOF << 12));
e1000_shift_out_mdi_bits(hw, mdic, 14);
/* Now that we've shifted out the read command to the MII, we *needto"shiftin"the16-bitvalue(18totalbits)ofthe *requestedPHYregisteraddress.
*/
*phy_data = e1000_shift_in_mdi_bits(hw);
} return E1000_SUCCESS;
}
if (reg_addr > MAX_PHY_REG_ADDRESS) {
e_dbg("PHY Address %d is out of range\n", reg_addr); return -E1000_ERR_PARAM;
}
if (hw->mac_type > e1000_82543) { /* Set up Op-code, Phy Address, register address, and data *intendedforthePHYregisterintheMDIControlregister. *TheMACwilltakecareofinterfacingwiththePHYtosend *thedesireddata.
*/ if (hw->mac_type == e1000_ce4100) {
mdic = (((u32)phy_data) |
(reg_addr << E1000_MDIC_REG_SHIFT) |
(phy_addr << E1000_MDIC_PHY_SHIFT) |
(INTEL_CE_GBE_MDIC_OP_WRITE) |
(INTEL_CE_GBE_MDIC_GO));
writel(mdic, E1000_MDIO_CMD);
/* Poll the ready bit to see if the MDI read *completed
*/ for (i = 0; i < 640; i++) {
udelay(5);
mdic = readl(E1000_MDIO_CMD); if (!(mdic & INTEL_CE_GBE_MDIC_GO)) break;
} if (mdic & INTEL_CE_GBE_MDIC_GO) {
e_dbg("MDI Write did not complete\n"); return -E1000_ERR_PHY;
}
} else {
mdic = (((u32)phy_data) |
(reg_addr << E1000_MDIC_REG_SHIFT) |
(phy_addr << E1000_MDIC_PHY_SHIFT) |
(E1000_MDIC_OP_WRITE));
ew32(MDIC, mdic);
/* Poll the ready bit to see if the MDI read *completed
*/ for (i = 0; i < 641; i++) {
udelay(5);
mdic = er32(MDIC); if (mdic & E1000_MDIC_READY) break;
} if (!(mdic & E1000_MDIC_READY)) {
e_dbg("MDI Write did not complete\n"); return -E1000_ERR_PHY;
}
}
} else { /* We'll need to use the SW defined pins to shift the write *commandouttothePHY.WefirstsendapreambletothePHY *tosignalthebeginningoftheMIIinstruction.Thisisdone *bysending32consecutive"1"bits.
*/
e1000_shift_out_mdi_bits(hw, PHY_PREAMBLE, PHY_PREAMBLE_SIZE);
/* Now combine the remaining required fields that will indicate *awriteoperation.Weusethismethodinsteadofcallingthe *e1000_shift_out_mdi_bitsroutineforeachfieldinthe *command.TheformatofaMIIwriteinstructionisasfollows: *<Preamble><SOF><OpCode><PhyAddr><RegAddr><Turnaround><Data>.
*/
mdic = ((PHY_TURNAROUND) | (reg_addr << 2) | (phy_addr << 7) |
(PHY_OP_WRITE << 12) | (PHY_SOF << 14));
mdic <<= 16;
mdic |= (u32)phy_data;
/* Read the PHY ID Registers to identify which PHY is onboard. */
ret_val = e1000_read_phy_reg(hw, PHY_ID1, &phy_id_high); if (ret_val) return ret_val;
switch (hw->mac_type) { case e1000_82543: if (hw->phy_id == M88E1000_E_PHY_ID)
match = true; break; case e1000_82544: if (hw->phy_id == M88E1000_I_PHY_ID)
match = true; break; case e1000_82540: case e1000_82545: case e1000_82545_rev_3: case e1000_82546: case e1000_82546_rev_3: if (hw->phy_id == M88E1011_I_PHY_ID)
match = true; break; case e1000_ce4100: if ((hw->phy_id == RTL8211B_PHY_ID) ||
(hw->phy_id == RTL8201N_PHY_ID) ||
(hw->phy_id == M88E1118_E_PHY_ID))
match = true; break; case e1000_82541: case e1000_82541_rev_2: case e1000_82547: case e1000_82547_rev_2: if (hw->phy_id == IGP01E1000_I_PHY_ID)
match = true; break; default:
e_dbg("Invalid MAC type %d\n", hw->mac_type); return -E1000_ERR_CONFIG;
}
phy_init_status = e1000_set_phy_type(hw);
if ((match) && (phy_init_status == E1000_SUCCESS)) {
e_dbg("PHY ID 0x%X detected\n", hw->phy_id); return E1000_SUCCESS;
}
e_dbg("Invalid PHY ID 0x%X\n", hw->phy_id); return -E1000_ERR_PHY;
}
/* The downshift status is checked only once, after link is established, *anditstoredinthehw->speed_downgradedparameter.
*/
phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
/* IGP01E1000 does not need to support it. */
phy_info->extended_10bt_distance = e1000_10bt_ext_dist_enable_normal;
/* The downshift status is checked only once, after link is established, *anditstoredinthehw->speed_downgradedparameter.
*/
phy_info->downshift = (e1000_downshift) hw->speed_downgraded;
ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_CTRL, &phy_data); if (ret_val) return ret_val;
switch (hw->mac_type) { case e1000_82542_rev2_0: case e1000_82542_rev2_1: case e1000_82543: case e1000_82544:
eeprom->type = e1000_eeprom_microwire;
eeprom->word_size = 64;
eeprom->opcode_bits = 3;
eeprom->address_bits = 6;
eeprom->delay_usec = 50; break; case e1000_82540: case e1000_82545: case e1000_82545_rev_3: case e1000_82546: case e1000_82546_rev_3:
eeprom->type = e1000_eeprom_microwire;
eeprom->opcode_bits = 3;
eeprom->delay_usec = 50; if (eecd & E1000_EECD_SIZE) {
eeprom->word_size = 256;
eeprom->address_bits = 8;
} else {
eeprom->word_size = 64;
eeprom->address_bits = 6;
} break; case e1000_82541: case e1000_82541_rev_2: case e1000_82547: case e1000_82547_rev_2: if (eecd & E1000_EECD_TYPE) {
eeprom->type = e1000_eeprom_spi;
eeprom->opcode_bits = 8;
eeprom->delay_usec = 1; if (eecd & E1000_EECD_ADDR_BITS) {
eeprom->page_size = 32;
eeprom->address_bits = 16;
} else {
eeprom->page_size = 8;
eeprom->address_bits = 8;
}
} else {
eeprom->type = e1000_eeprom_microwire;
eeprom->opcode_bits = 3;
eeprom->delay_usec = 50; if (eecd & E1000_EECD_ADDR_BITS) {
eeprom->word_size = 256;
eeprom->address_bits = 8;
} else {
eeprom->word_size = 64;
eeprom->address_bits = 6;
}
} break; default: break;
}
if (eeprom->type == e1000_eeprom_spi) { /* eeprom_size will be an enum [0..8] that maps to eeprom sizes *128Bto32KB(incrementedbypowersof2).
*/ /* Set to default value for initial eeprom read. */
eeprom->word_size = 64;
ret_val = e1000_read_eeprom(hw, EEPROM_CFG, 1, &eeprom_size); if (ret_val) return ret_val;
eeprom_size =
FIELD_GET(EEPROM_SIZE_MASK, eeprom_size); /* 256B eeprom size was not supported in earlier hardware, so we *bumpeeprom_sizeuponetoensurethat"1"(whichmapsto *256B)isnevertheresultusedintheshiftinglogicbelow.
*/ if (eeprom_size)
eeprom_size++;
/* We need to shift "count" bits out to the EEPROM. So, value in the *"data"parameterwillbeshiftedouttotheEEPROMonebitatatime. *Inordertodothis,"data"mustbebrokendownintobits.
*/
mask = 0x01 << (count - 1);
eecd = er32(EECD); if (eeprom->type == e1000_eeprom_microwire)
eecd &= ~E1000_EECD_DO; elseif (eeprom->type == e1000_eeprom_spi)
eecd |= E1000_EECD_DO;
do { /* A "1" is shifted out to the EEPROM by setting bit "DI" to a *"1",andthenraisingandthenloweringtheclock(theSKbit *controlstheclockinputtotheEEPROM).A"0"isshifted *outtotheEEPROMbysetting"DI"to"0"andthenraisingand *thenloweringtheclock.
*/
eecd &= ~E1000_EECD_DI;
/* In order to read a register from the EEPROM, we need to shift 'count' *bitsinfromtheEEPROM.Bitsare"shiftedin"byraisingtheclock *inputtotheEEPROM(settingtheSKbit),andthenreadingthevalue *ofthe"DO"bit.Duringthis"shiftingin"processthe"DI"bit *shouldalwaysbeclear.
*/
eecd = er32(EECD);
eecd &= ~(E1000_EECD_DO | E1000_EECD_DI);
data = 0;
for (i = 0; i < count; i++) {
data = data << 1;
e1000_raise_ee_clk(hw, &eecd);
eecd = er32(EECD);
eecd &= ~(E1000_EECD_DI); if (eecd & E1000_EECD_DO)
data |= 1;
/* Read "Status Register" repeatedly until the LSB is cleared. The *EEPROMwillsignalthatthecommandhasbeencompletedbyclearing *bit0oftheinternalstatusregister.Ifit'snotclearedwithin *5milliseconds,thenerrorout.
*/
retry_count = 0; do {
e1000_shift_out_ee_bits(hw, EEPROM_RDSR_OPCODE_SPI,
hw->eeprom.opcode_bits);
spi_stat_reg = (u8)e1000_shift_in_ee_bits(hw, 8); if (!(spi_stat_reg & EEPROM_STATUS_RDY_SPI)) break;
udelay(5);
retry_count += 5;
e1000_standby_eeprom(hw);
} while (retry_count < EEPROM_MAX_RETRY_SPI);
/* ATMEL SPI write time could vary from 0-20mSec on 3.3V devices (and *only0-5mSecon5Vdevices)
*/ if (retry_count >= EEPROM_MAX_RETRY_SPI) {
e_dbg("SPI EEPROM Status error\n"); return -E1000_ERR_EEPROM;
}
/* A check for invalid values: offset too large, too many words, and *notenoughwords.
*/ if ((offset >= eeprom->word_size) ||
(words > eeprom->word_size - offset) ||
(words == 0)) {
e_dbg("\"words\" parameter out of bounds. Words = %d," "size = %d\n", offset, eeprom->word_size); return -E1000_ERR_EEPROM;
}
/* EEPROM's that don't use EERD to read require us to bit-bang the SPI *directly.Inthiscase,weneedtoacquiretheEEPROMsothat *FWorotherportsoftwaredoesnotinterrupt.
*/ /* Prepare the EEPROM for bit-bang reading */ if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) return -E1000_ERR_EEPROM;
/* Set up the SPI or Microwire EEPROM for bit-bang reading. We have *acquiredtheEEPROMatthispoint,soanyreturnsshouldreleaseit
*/ if (eeprom->type == e1000_eeprom_spi) {
u16 word_in;
u8 read_opcode = EEPROM_READ_OPCODE_SPI;
if (e1000_spi_eeprom_ready(hw)) {
e1000_release_eeprom(hw); return -E1000_ERR_EEPROM;
}
e1000_standby_eeprom(hw);
/* Some SPI eeproms use the 8th address bit embedded in the *opcode
*/ if ((eeprom->address_bits == 8) && (offset >= 128))
read_opcode |= EEPROM_A8_OPCODE_SPI;
/* Read the data. The address of the eeprom internally *incrementswitheachbyte(spi)beingread,savingonthe *overheadofeepromsetupandtear-down.Theaddresscounter *willrolloverifreadingbeyondthesizeoftheeeprom,thus *allowingtheentirememorytobereadstartingfromany *offset.
*/ for (i = 0; i < words; i++) {
word_in = e1000_shift_in_ee_bits(hw, 16);
data[i] = (word_in >> 8) | (word_in << 8);
}
} elseif (eeprom->type == e1000_eeprom_microwire) { for (i = 0; i < words; i++) { /* Send the READ command (opcode + addr) */
e1000_shift_out_ee_bits(hw,
EEPROM_READ_OPCODE_MICROWIRE,
eeprom->opcode_bits);
e1000_shift_out_ee_bits(hw, (u16)(offset + i),
eeprom->address_bits);
/* Read the data. For microwire, each word requires the *overheadofeepromsetupandtear-down.
*/
data[i] = e1000_shift_in_ee_bits(hw, 16);
e1000_standby_eeprom(hw);
cond_resched();
}
}
/* End this read operation */
e1000_release_eeprom(hw);
for (i = 0; i < (EEPROM_CHECKSUM_REG + 1); i++) { if (e1000_read_eeprom(hw, i, 1, &eeprom_data) < 0) {
e_dbg("EEPROM Read Error\n"); return -E1000_ERR_EEPROM;
}
checksum += eeprom_data;
}
#ifdef CONFIG_PARISC /* This is a signature and not a checksum on HP c8000 */ if ((hw->subsystem_vendor_id == 0x103C) && (eeprom_data == 0x16d6)) return E1000_SUCCESS;
/* A check for invalid values: offset too large, too many words, and *notenoughwords.
*/ if ((offset >= eeprom->word_size) ||
(words > eeprom->word_size - offset) ||
(words == 0)) {
e_dbg("\"words\" parameter out of bounds\n"); return -E1000_ERR_EEPROM;
}
/* Prepare the EEPROM for writing */ if (e1000_acquire_eeprom(hw) != E1000_SUCCESS) return -E1000_ERR_EEPROM;
if (eeprom->type == e1000_eeprom_microwire) {
status = e1000_write_eeprom_microwire(hw, offset, words, data);
} else {
status = e1000_write_eeprom_spi(hw, offset, words, data);
msleep(10);
}
while (widx < words) {
u8 write_opcode = EEPROM_WRITE_OPCODE_SPI;
if (e1000_spi_eeprom_ready(hw)) return -E1000_ERR_EEPROM;
e1000_standby_eeprom(hw);
cond_resched();
/* Send the WRITE ENABLE command (8 bit opcode ) */
e1000_shift_out_ee_bits(hw, EEPROM_WREN_OPCODE_SPI,
eeprom->opcode_bits);
e1000_standby_eeprom(hw);
/* Some SPI eeproms use the 8th address bit embedded in the *opcode
*/ if ((eeprom->address_bits == 8) && (offset >= 128))
write_opcode |= EEPROM_A8_OPCODE_SPI;
/* Send the data */
e1000_shift_out_ee_bits(hw, data[words_written], 16);
/* Toggle the CS line. This in effect tells the EEPROM to *executethepreviouscommand.
*/
e1000_standby_eeprom(hw);
/* Read DO repeatedly until it is high (equal to '1'). The *EEPROMwillsignalthatthecommandhasbeencompletedby *raisingtheDOsignal.IfDOdoesnotgohighin10 *milliseconds,thenerrorout.
*/ for (i = 0; i < 200; i++) {
eecd = er32(EECD); if (eecd & E1000_EECD_DO) break;
udelay(50);
} if (i == 200) {
e_dbg("EEPROM Write did not complete\n"); return -E1000_ERR_EEPROM;
}
/* Recover from write */
e1000_standby_eeprom(hw);
cond_resched();
words_written++;
}
/* Send the write disable command to the EEPROM (3-bit opcode plus *6/8-bitdummyaddressbeginningwith10).It'slessworktoinclude *the10ofthedummyaddressaspartoftheopcodethanitistoshift *itoverthecorrectnumberofbitsfortheaddress.Thistakesthe *EEPROMoutofwrite/erasemode.
*/
e1000_shift_out_ee_bits(hw, EEPROM_EWDS_OPCODE_MICROWIRE,
(u16)(eeprom->opcode_bits + 2));
/* Setup the receive address. */
e_dbg("Programming MAC Address into RAR[0]\n");
e1000_rar_set(hw, hw->mac_addr, 0);
rar_num = E1000_RAR_ENTRIES;
/* Zero out the following 14 receive addresses. RAR[15] is for *manageability
*/
e_dbg("Clearing RAR[1-14]\n"); for (i = 1; i < rar_num; i++) {
E1000_WRITE_REG_ARRAY(hw, RA, (i << 1), 0);
E1000_WRITE_FLUSH();
E1000_WRITE_REG_ARRAY(hw, RA, ((i << 1) + 1), 0);
E1000_WRITE_FLUSH();
}
}
for (i = 0; i < 4; i++) {
temp = (eeprom_data >> (i << 2)) & led_mask; switch (temp) { case ID_LED_ON1_DEF2: case ID_LED_ON1_ON2: case ID_LED_ON1_OFF2:
hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
hw->ledctl_mode1 |= ledctl_on << (i << 3); break; case ID_LED_OFF1_DEF2: case ID_LED_OFF1_ON2: case ID_LED_OFF1_OFF2:
hw->ledctl_mode1 &= ~(ledctl_mask << (i << 3));
hw->ledctl_mode1 |= ledctl_off << (i << 3); break; default: /* Do nothing */ break;
} switch (temp) { case ID_LED_DEF1_ON2: case ID_LED_ON1_ON2: case ID_LED_OFF1_ON2:
hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
hw->ledctl_mode2 |= ledctl_on << (i << 3); break; case ID_LED_DEF1_OFF2: case ID_LED_ON1_OFF2: case ID_LED_OFF1_OFF2:
hw->ledctl_mode2 &= ~(ledctl_mask << (i << 3));
hw->ledctl_mode2 |= ledctl_off << (i << 3); break; default: /* Do nothing */ break;
}
} return E1000_SUCCESS;
}
switch (hw->mac_type) { case e1000_82542_rev2_0: case e1000_82542_rev2_1: case e1000_82543: case e1000_82544: /* No cleanup necessary */ break; case e1000_82541: case e1000_82547: case e1000_82541_rev_2: case e1000_82547_rev_2: /* Turn on PHY Smart Power Down (if previously enabled) */
ret_val = e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
hw->phy_spd_default); if (ret_val) return ret_val;
fallthrough; default: /* Restore LEDCTL settings */
ew32(LEDCTL, hw->ledctl_default); break;
}
switch (hw->mac_type) { case e1000_82542_rev2_0: case e1000_82542_rev2_1: case e1000_82543: /* Set SW Defineable Pin 0 to turn on the LED */
ctrl |= E1000_CTRL_SWDPIN0;
ctrl |= E1000_CTRL_SWDPIO0; break; case e1000_82544: if (hw->media_type == e1000_media_type_fiber) { /* Set SW Defineable Pin 0 to turn on the LED */
ctrl |= E1000_CTRL_SWDPIN0;
ctrl |= E1000_CTRL_SWDPIO0;
} else { /* Clear SW Defineable Pin 0 to turn on the LED */
ctrl &= ~E1000_CTRL_SWDPIN0;
ctrl |= E1000_CTRL_SWDPIO0;
} break; default: if (hw->media_type == e1000_media_type_fiber) { /* Clear SW Defineable Pin 0 to turn on the LED */
ctrl &= ~E1000_CTRL_SWDPIN0;
ctrl |= E1000_CTRL_SWDPIO0;
} elseif (hw->media_type == e1000_media_type_copper) {
ew32(LEDCTL, hw->ledctl_mode2); return E1000_SUCCESS;
} break;
}
switch (hw->mac_type) { case e1000_82542_rev2_0: case e1000_82542_rev2_1: case e1000_82543: /* Clear SW Defineable Pin 0 to turn off the LED */
ctrl &= ~E1000_CTRL_SWDPIN0;
ctrl |= E1000_CTRL_SWDPIO0; break; case e1000_82544: if (hw->media_type == e1000_media_type_fiber) { /* Clear SW Defineable Pin 0 to turn off the LED */
ctrl &= ~E1000_CTRL_SWDPIN0;
ctrl |= E1000_CTRL_SWDPIO0;
} else { /* Set SW Defineable Pin 0 to turn off the LED */
ctrl |= E1000_CTRL_SWDPIN0;
ctrl |= E1000_CTRL_SWDPIO0;
} break; default: if (hw->media_type == e1000_media_type_fiber) { /* Set SW Defineable Pin 0 to turn off the LED */
ctrl |= E1000_CTRL_SWDPIN0;
ctrl |= E1000_CTRL_SWDPIO0;
} elseif (hw->media_type == e1000_media_type_copper) {
ew32(LEDCTL, hw->ledctl_mode1); return E1000_SUCCESS;
} break;
}
/* Use old method for Phy older than IGP */ if (hw->phy_type == e1000_phy_m88) {
ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
&phy_data); if (ret_val) return ret_val;
cable_length = FIELD_GET(M88E1000_PSSR_CABLE_LENGTH, phy_data);
/* Convert the enum value to ranged values */ switch (cable_length) { case e1000_cable_length_50:
*min_length = 0;
*max_length = e1000_igp_cable_length_50; break; case e1000_cable_length_50_80:
*min_length = e1000_igp_cable_length_50;
*max_length = e1000_igp_cable_length_80; break; case e1000_cable_length_80_110:
*min_length = e1000_igp_cable_length_80;
*max_length = e1000_igp_cable_length_110; break; case e1000_cable_length_110_140:
*min_length = e1000_igp_cable_length_110;
*max_length = e1000_igp_cable_length_140; break; case e1000_cable_length_140:
*min_length = e1000_igp_cable_length_140;
*max_length = e1000_igp_cable_length_170; break; default: return -E1000_ERR_PHY;
}
} elseif (hw->phy_type == e1000_phy_igp) { /* For IGP PHY */
u16 cur_agc_value;
u16 min_agc_value = IGP01E1000_AGC_LENGTH_TABLE_SIZE; staticconst u16 agc_reg_array[IGP01E1000_PHY_CHANNEL_NUM] = {
IGP01E1000_PHY_AGC_A,
IGP01E1000_PHY_AGC_B,
IGP01E1000_PHY_AGC_C,
IGP01E1000_PHY_AGC_D
}; /* Read the AGC registers for all channels */ for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
ret_val =
e1000_read_phy_reg(hw, agc_reg_array[i], &phy_data); if (ret_val) return ret_val;
/* Remove the minimal AGC result for length < 50m */ if (agc_value <
IGP01E1000_PHY_CHANNEL_NUM * e1000_igp_cable_length_50) {
agc_value -= min_agc_value;
/* Get the average length of the remaining 3 channels */
agc_value /= (IGP01E1000_PHY_CHANNEL_NUM - 1);
} else { /* Get the average length of all the 4 channels. */
agc_value /= IGP01E1000_PHY_CHANNEL_NUM;
}
/* Set the range of the calculated length. */
*min_length = ((e1000_igp_cable_length_table[agc_value] -
IGP01E1000_AGC_RANGE) > 0) ?
(e1000_igp_cable_length_table[agc_value] -
IGP01E1000_AGC_RANGE) : 0;
*max_length = e1000_igp_cable_length_table[agc_value] +
IGP01E1000_AGC_RANGE;
}
if (hw->phy_type == e1000_phy_m88) { /* return the Polarity bit in the Status register. */
ret_val = e1000_read_phy_reg(hw, M88E1000_PHY_SPEC_STATUS,
&phy_data); if (ret_val) return ret_val;
*polarity = FIELD_GET(M88E1000_PSSR_REV_POLARITY, phy_data) ?
e1000_rev_polarity_reversed : e1000_rev_polarity_normal;
} elseif (hw->phy_type == e1000_phy_igp) { /* Read the Status register to check the speed */
ret_val = e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_STATUS,
&phy_data); if (ret_val) return ret_val;
/* If speed is 1000 Mbps, must read the *IGP01E1000_PHY_PCS_INIT_REGtofindthepolaritystatus
*/ if ((phy_data & IGP01E1000_PSSR_SPEED_MASK) ==
IGP01E1000_PSSR_SPEED_1000MBPS) { /* Read the GIG initialization PCS register (0x00B4) */
ret_val =
e1000_read_phy_reg(hw, IGP01E1000_PHY_PCS_INIT_REG,
&phy_data); if (ret_val) return ret_val;
/* Check the polarity bits */
*polarity = (phy_data & IGP01E1000_PHY_POLARITY_MASK) ?
e1000_rev_polarity_reversed :
e1000_rev_polarity_normal;
} else { /* For 10 Mbps, read the polarity bit in the status *register.(for100Mbpsthisbitisalways0)
*/
*polarity =
(phy_data & IGP01E1000_PSSR_POLARITY_REVERSED) ?
e1000_rev_polarity_reversed :
e1000_rev_polarity_normal;
}
} return E1000_SUCCESS;
}
ret_val = e1000_get_cable_length(hw, &min_length, &max_length); if (ret_val) return ret_val;
if (hw->dsp_config_state != e1000_dsp_config_enabled) return0;
if (min_length >= e1000_igp_cable_length_50) { for (i = 0; i < IGP01E1000_PHY_CHANNEL_NUM; i++) {
ret_val = e1000_read_phy_reg(hw, dsp_reg_array[i],
&phy_data); if (ret_val) return ret_val;
if (hw->phy_type != e1000_phy_igp) return E1000_SUCCESS;
if (link_up) {
ret_val = e1000_get_speed_and_duplex(hw, &speed, &duplex); if (ret_val) {
e_dbg("Error getting link speed and duplex\n"); return ret_val;
}
if (speed == SPEED_1000) {
ret_val = e1000_1000Mb_check_cable_length(hw); if (ret_val) return ret_val;
}
} else { if (hw->dsp_config_state == e1000_dsp_config_activated) { /* Save off the current value of register 0x2F5B to be *restoredattheendoftheroutines.
*/
ret_val =
e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
if (hw->ffe_config_state == e1000_ffe_config_active) { /* Save off the current value of register 0x2F5B to be *restoredattheendoftheroutines.
*/
ret_val =
e1000_read_phy_reg(hw, 0x2F5B, &phy_saved_data);
if (hw->phy_type != e1000_phy_igp) return E1000_SUCCESS;
/* During driver activity LPLU should not be used or it will attain link *fromthelowestspeedsstartingfrom10Mbps.Thecapabilityisused *forDxtransitionsandstates
*/ if (hw->mac_type == e1000_82541_rev_2 ||
hw->mac_type == e1000_82547_rev_2) {
ret_val =
e1000_read_phy_reg(hw, IGP01E1000_GMII_FIFO, &phy_data); if (ret_val) return ret_val;
}
if (!active) { if (hw->mac_type == e1000_82541_rev_2 ||
hw->mac_type == e1000_82547_rev_2) {
phy_data &= ~IGP01E1000_GMII_FLEX_SPD;
ret_val =
e1000_write_phy_reg(hw, IGP01E1000_GMII_FIFO,
phy_data); if (ret_val) return ret_val;
}
/* LPLU and SmartSpeed are mutually exclusive. LPLU is used *duringDxstateswherethepowerconservationismost *important.Duringdriveractivityweshouldenable *SmartSpeed,soperformanceismaintained.
*/ if (hw->smart_speed == e1000_smart_speed_on) {
ret_val =
e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
&phy_data); if (ret_val) return ret_val;
/* When LPLU is enabled we should disable SmartSpeed */
ret_val =
e1000_read_phy_reg(hw, IGP01E1000_PHY_PORT_CONFIG,
&phy_data); if (ret_val) return ret_val;
/* Polarity reversal workaround for forced 10F/10H links. */
/* Disable the transmitter on the PHY */
ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); if (ret_val) return ret_val;
ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFFF); if (ret_val) return ret_val;
ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); if (ret_val) return ret_val;
/* This loop will early-out if the NO link condition has been met. */ for (i = PHY_FORCE_TIME; i > 0; i--) { /* Read the MII Status Register and wait for Link Status bit *tobeclear.
*/
ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); if (ret_val) return ret_val;
ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); if (ret_val) return ret_val;
if ((mii_status_reg & ~MII_SR_LINK_STATUS) == 0) break;
msleep(100);
}
/* Recommended delay time after link has been lost */
msleep(1000);
/* Now we will re-enable th transmitter on the PHY */
ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0019); if (ret_val) return ret_val;
msleep(50);
ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFFF0); if (ret_val) return ret_val;
msleep(50);
ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0xFF00); if (ret_val) return ret_val;
msleep(50);
ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_GEN_CONTROL, 0x0000); if (ret_val) return ret_val;
ret_val = e1000_write_phy_reg(hw, M88E1000_PHY_PAGE_SELECT, 0x0000); if (ret_val) return ret_val;
/* This loop will early-out if the link condition has been met. */ for (i = PHY_FORCE_TIME; i > 0; i--) { /* Read the MII Status Register and wait for Link Status bit *tobeset.
*/
ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); if (ret_val) return ret_val;
ret_val = e1000_read_phy_reg(hw, PHY_STATUS, &mii_status_reg); if (ret_val) return ret_val;
if (mii_status_reg & MII_SR_LINK_STATUS) break;
msleep(100);
} return E1000_SUCCESS;
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.194Bemerkung:
(vorverarbeitet am 2026-10-03)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.