aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync/** $Id$ */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync/** @file
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync * DevE1000Phy - Intel 82540EM Ethernet Controller Internal PHY Emulation, Header.
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync/*
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsync * Copyright (C) 2007-2010 Oracle Corporation
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync *
dbcf44d4b4f08f03eae2903053ed8c5264b0c23fvboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
dbcf44d4b4f08f03eae2903053ed8c5264b0c23fvboxsync * available from http://www.virtualbox.org. This file is free software;
dbcf44d4b4f08f03eae2903053ed8c5264b0c23fvboxsync * you can redistribute it and/or modify it under the terms of the GNU
dbcf44d4b4f08f03eae2903053ed8c5264b0c23fvboxsync * General Public License (GPL) as published by the Free Software
dbcf44d4b4f08f03eae2903053ed8c5264b0c23fvboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
dbcf44d4b4f08f03eae2903053ed8c5264b0c23fvboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
dbcf44d4b4f08f03eae2903053ed8c5264b0c23fvboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#include <VBox/types.h>
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define PHY_EPID_M881000 0xC50
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define PHY_EPID_M881011 0xC24
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define PCTRL_SPDSELM 0x0040
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define PCTRL_DUPMOD 0x0100
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define PCTRL_ANEG 0x1000
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define PCTRL_SPDSELL 0x2000
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define PCTRL_RESET 0x8000
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define PSTATUS_LNKSTAT 0x0004
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync
e38e985e81603c3b6d0e4d42015d6a3fd4332c6evboxsync/*
e38e985e81603c3b6d0e4d42015d6a3fd4332c6evboxsync * Speed: 1000 Mb/s
e38e985e81603c3b6d0e4d42015d6a3fd4332c6evboxsync * Duplex: full
e38e985e81603c3b6d0e4d42015d6a3fd4332c6evboxsync * Page received
e38e985e81603c3b6d0e4d42015d6a3fd4332c6evboxsync * Resolved
e38e985e81603c3b6d0e4d42015d6a3fd4332c6evboxsync * Link up
e38e985e81603c3b6d0e4d42015d6a3fd4332c6evboxsync * Receive Pause Enable
e38e985e81603c3b6d0e4d42015d6a3fd4332c6evboxsync */
e38e985e81603c3b6d0e4d42015d6a3fd4332c6evboxsync#define PSSTAT_LINK 0xBC08
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsyncnamespace Phy
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync{
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /**
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync * Indices of memory-mapped registers in register table
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync enum enmRegIdx
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync {
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync PCTRL_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync PSTATUS_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync PID_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync EPID_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync ANA_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync LPA_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync ANE_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync NPT_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync LPN_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync GCON_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync GSTATUS_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync EPSTATUS_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync PSCON_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync PSSTAT_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync PINTE_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync PINTS_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync EPSCON1_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync PREC_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync EPSCON2_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync R30PS_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync R30AW_IDX,
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync NUM_OF_PHY_REGS
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync };
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /**
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync * Emulation state of PHY.
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync struct Phy_st
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync {
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /** Network controller instance this PHY is attached to. */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync int iInstance;
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /** Register storage. */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync uint16_t au16Regs[NUM_OF_PHY_REGS];
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /** Current state of serial MDIO interface. */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync uint16_t u16State;
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /** Current state of serial MDIO interface. */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync uint16_t u16Acc;
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /** Number of bits remaining to be shifted into/out of accumulator. */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync uint16_t u16Cnt;
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /** PHY register offset selected for MDIO operation. */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync uint16_t u16RegAdr;
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync };
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync}
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define MDIO_IDLE 0
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define MDIO_ST 1
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define MDIO_OP_ADR 2
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define MDIO_TA_RD 3
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define MDIO_TA_WR 4
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define MDIO_READ 5
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define MDIO_WRITE 6
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define MDIO_READ_OP 2
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync#define MDIO_WRITE_OP 1
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsynctypedef struct Phy::Phy_st PHY;
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsynctypedef PHY *PPHY;
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync/* Interface *****************************************************************/
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsyncnamespace Phy {
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /** Initialize PHY. */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync void init(PPHY pPhy, int iNICInstance, uint16_t u16EPid);
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /** Read PHY register at specified address. */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync uint16_t readRegister(PPHY pPhy, uint32_t u32Address);
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /** Write to PHY register at specified address. */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync void writeRegister(PPHY pPhy, uint32_t u32Address, uint16_t u16Value);
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /** Read the value on MDIO pin. */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync bool readMDIO(PPHY pPhy);
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /** Set the value of MDIO pin. */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync void writeMDIO(PPHY pPhy, bool fPin);
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /** Hardware reset. */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync void hardReset(PPHY pPhy);
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /** Query link status. */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync bool isLinkUp(PPHY pPhy);
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /** Set link status. */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync void setLinkStatus(PPHY pPhy, bool fLinkIsUp);
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /** Save PHY state. */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync int saveState(PSSMHANDLE pSSMHandle, PPHY pPhy);
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync /** Restore previously saved PHY state. */
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync int loadState(PSSMHANDLE pSSMHandle, PPHY pPhy);
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync}
aaf6eb788dab09bc8c3c8576c60fabc60037a483vboxsync