Deleted Added
full compact
if_npe.c (207554) if_npe.c (213893)
1/*-
2 * Copyright (c) 2006-2008 Sam Leffler. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 9 unchanged lines hidden (view full) ---

18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2006-2008 Sam Leffler. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 9 unchanged lines hidden (view full) ---

18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25#include <sys/cdefs.h>
26__FBSDID("$FreeBSD: head/sys/arm/xscale/ixp425/if_npe.c 207554 2010-05-03 07:32:50Z sobomax $");
26__FBSDID("$FreeBSD: head/sys/arm/xscale/ixp425/if_npe.c 213893 2010-10-15 14:52:11Z marius $");
27
28/*
29 * Intel XScale NPE Ethernet driver.
30 *
31 * This driver handles the two ports present on the IXP425.
32 * Packet processing is done by the Network Processing Engines
33 * (NPE's) that work together with a MAC and PHY. The MAC
34 * is also mapped to the XScale cpu; the PHY is accessed via

--- 97 unchanged lines hidden (view full) ---

132 struct npedma txdma;
133 struct npebuf *tx_free; /* list of free tx buffers */
134 struct npedma rxdma;
135 bus_addr_t buf_phys; /* XXX for returning a value */
136 int rx_qid; /* rx qid */
137 int rx_freeqid; /* rx free buffers qid */
138 int tx_qid; /* tx qid */
139 int tx_doneqid; /* tx completed qid */
27
28/*
29 * Intel XScale NPE Ethernet driver.
30 *
31 * This driver handles the two ports present on the IXP425.
32 * Packet processing is done by the Network Processing Engines
33 * (NPE's) that work together with a MAC and PHY. The MAC
34 * is also mapped to the XScale cpu; the PHY is accessed via

--- 97 unchanged lines hidden (view full) ---

132 struct npedma txdma;
133 struct npebuf *tx_free; /* list of free tx buffers */
134 struct npedma rxdma;
135 bus_addr_t buf_phys; /* XXX for returning a value */
136 int rx_qid; /* rx qid */
137 int rx_freeqid; /* rx free buffers qid */
138 int tx_qid; /* tx qid */
139 int tx_doneqid; /* tx completed qid */
140 int sc_phy; /* PHY id */
141 struct ifmib_iso_8802_3 mibdata;
142 bus_dma_tag_t sc_stats_tag; /* bus dma tag for stats block */
143 struct npestats *sc_stats;
144 bus_dmamap_t sc_stats_map;
145 bus_addr_t sc_stats_phys; /* phys addr of sc_stats */
146 struct npestats sc_totals; /* accumulated sc_stats */
147};
148

--- 514 unchanged lines hidden (view full) ---

663 /* configure MAC to generate MDC clock */
664 WR4(sc, NPE_MAC_CORE_CNTRL, NPE_CORE_MDC_EN);
665}
666
667static int
668npe_activate(device_t dev)
669{
670 struct npe_softc *sc = device_get_softc(dev);
140 struct ifmib_iso_8802_3 mibdata;
141 bus_dma_tag_t sc_stats_tag; /* bus dma tag for stats block */
142 struct npestats *sc_stats;
143 bus_dmamap_t sc_stats_map;
144 bus_addr_t sc_stats_phys; /* phys addr of sc_stats */
145 struct npestats sc_totals; /* accumulated sc_stats */
146};
147

--- 514 unchanged lines hidden (view full) ---

662 /* configure MAC to generate MDC clock */
663 WR4(sc, NPE_MAC_CORE_CNTRL, NPE_CORE_MDC_EN);
664}
665
666static int
667npe_activate(device_t dev)
668{
669 struct npe_softc *sc = device_get_softc(dev);
671 int error, i, macbase, miibase;
670 int error, i, macbase, miibase, phy;
672
673 /*
674 * Setup NEP ID, MAC, and MII bindings. We allow override
675 * via hints to handle unexpected board configs.
676 */
677 if (!override_npeid(dev, "npeid", &sc->sc_npeid))
678 sc->sc_npeid = unit2npeid(device_get_unit(dev));
679 sc->sc_npe = ixpnpe_attach(dev, sc->sc_npeid);

--- 8 unchanged lines hidden (view full) ---

688 device_printf(sc->sc_dev, "MAC at 0x%x\n", macbase);
689 if (bus_space_map(sc->sc_iot, macbase, IXP425_REG_SIZE, 0, &sc->sc_ioh)) {
690 device_printf(dev, "cannot map mac registers 0x%x:0x%x\n",
691 macbase, IXP425_REG_SIZE);
692 return ENOMEM;
693 }
694
695 /* PHY */
671
672 /*
673 * Setup NEP ID, MAC, and MII bindings. We allow override
674 * via hints to handle unexpected board configs.
675 */
676 if (!override_npeid(dev, "npeid", &sc->sc_npeid))
677 sc->sc_npeid = unit2npeid(device_get_unit(dev));
678 sc->sc_npe = ixpnpe_attach(dev, sc->sc_npeid);

--- 8 unchanged lines hidden (view full) ---

687 device_printf(sc->sc_dev, "MAC at 0x%x\n", macbase);
688 if (bus_space_map(sc->sc_iot, macbase, IXP425_REG_SIZE, 0, &sc->sc_ioh)) {
689 device_printf(dev, "cannot map mac registers 0x%x:0x%x\n",
690 macbase, IXP425_REG_SIZE);
691 return ENOMEM;
692 }
693
694 /* PHY */
696 if (!override_unit(dev, "phy", &sc->sc_phy, 0, MII_NPHY-1))
697 sc->sc_phy = npeconfig[sc->sc_npeid].phy;
695 if (!override_unit(dev, "phy", &phy, 0, MII_NPHY - 1))
696 phy = npeconfig[sc->sc_npeid].phy;
698 if (!override_addr(dev, "mii", &miibase))
699 miibase = npeconfig[sc->sc_npeid].miibase;
700 device_printf(sc->sc_dev, "MII at 0x%x\n", miibase);
701 if (miibase != macbase) {
702 /*
703 * PHY is mapped through a different MAC, setup an
704 * additional mapping for frobbing the PHY registers.
705 */

--- 10 unchanged lines hidden (view full) ---

716 * Load NPE firmware and start it running.
717 */
718 error = ixpnpe_init(sc->sc_npe);
719 if (error != 0) {
720 device_printf(dev, "cannot init NPE (error %d)\n", error);
721 return error;
722 }
723
697 if (!override_addr(dev, "mii", &miibase))
698 miibase = npeconfig[sc->sc_npeid].miibase;
699 device_printf(sc->sc_dev, "MII at 0x%x\n", miibase);
700 if (miibase != macbase) {
701 /*
702 * PHY is mapped through a different MAC, setup an
703 * additional mapping for frobbing the PHY registers.
704 */

--- 10 unchanged lines hidden (view full) ---

715 * Load NPE firmware and start it running.
716 */
717 error = ixpnpe_init(sc->sc_npe);
718 if (error != 0) {
719 device_printf(dev, "cannot init NPE (error %d)\n", error);
720 return error;
721 }
722
724 /* probe for PHY */
725 if (mii_phy_probe(dev, &sc->sc_mii, npe_ifmedia_update, npe_ifmedia_status)) {
726 device_printf(dev, "cannot find PHY %d.\n", sc->sc_phy);
727 return ENXIO;
723 /* attach PHY */
724 error = mii_attach(dev, &sc->sc_mii, sc->sc_ifp, npe_ifmedia_update,
725 npe_ifmedia_status, BMSR_DEFCAPMASK, phy, MII_OFFSET_ANY, 0);
726 if (error != 0) {
727 device_printf(dev, "attaching PHYs failed\n");
728 return error;
728 }
729
730 error = npe_dma_setup(sc, &sc->txdma, "tx", npe_txbuf, NPE_MAXSEG);
731 if (error != 0)
732 return error;
733 error = npe_dma_setup(sc, &sc->rxdma, "rx", npe_rxbuf, 1);
734 if (error != 0)
735 return error;

--- 959 unchanged lines hidden (view full) ---

1695}
1696
1697static int
1698npe_miibus_readreg(device_t dev, int phy, int reg)
1699{
1700 struct npe_softc *sc = device_get_softc(dev);
1701 uint32_t v;
1702
729 }
730
731 error = npe_dma_setup(sc, &sc->txdma, "tx", npe_txbuf, NPE_MAXSEG);
732 if (error != 0)
733 return error;
734 error = npe_dma_setup(sc, &sc->rxdma, "rx", npe_rxbuf, 1);
735 if (error != 0)
736 return error;

--- 959 unchanged lines hidden (view full) ---

1696}
1697
1698static int
1699npe_miibus_readreg(device_t dev, int phy, int reg)
1700{
1701 struct npe_softc *sc = device_get_softc(dev);
1702 uint32_t v;
1703
1703 if (phy != sc->sc_phy) /* XXX no auto-detect */
1704 return 0xffff;
1705 v = (phy << NPE_MII_ADDR_SHL) | (reg << NPE_MII_REG_SHL) | NPE_MII_GO;
1706 npe_mii_mdio_write(sc, NPE_MAC_MDIO_CMD, v);
1707 if (npe_mii_mdio_wait(sc))
1708 v = npe_mii_mdio_read(sc, NPE_MAC_MDIO_STS);
1709 else
1710 v = 0xffff | NPE_MII_READ_FAIL;
1711 return (v & NPE_MII_READ_FAIL) ? 0xffff : (v & 0xffff);
1712}
1713
1714static int
1715npe_miibus_writereg(device_t dev, int phy, int reg, int data)
1716{
1717 struct npe_softc *sc = device_get_softc(dev);
1718 uint32_t v;
1719
1704 v = (phy << NPE_MII_ADDR_SHL) | (reg << NPE_MII_REG_SHL) | NPE_MII_GO;
1705 npe_mii_mdio_write(sc, NPE_MAC_MDIO_CMD, v);
1706 if (npe_mii_mdio_wait(sc))
1707 v = npe_mii_mdio_read(sc, NPE_MAC_MDIO_STS);
1708 else
1709 v = 0xffff | NPE_MII_READ_FAIL;
1710 return (v & NPE_MII_READ_FAIL) ? 0xffff : (v & 0xffff);
1711}
1712
1713static int
1714npe_miibus_writereg(device_t dev, int phy, int reg, int data)
1715{
1716 struct npe_softc *sc = device_get_softc(dev);
1717 uint32_t v;
1718
1720 if (phy != sc->sc_phy) /* XXX */
1721 return (0);
1722 v = (phy << NPE_MII_ADDR_SHL) | (reg << NPE_MII_REG_SHL)
1723 | data | NPE_MII_WRITE
1724 | NPE_MII_GO;
1725 npe_mii_mdio_write(sc, NPE_MAC_MDIO_CMD, v);
1726 /* XXX complain about timeout */
1727 (void) npe_mii_mdio_wait(sc);
1728 return (0);
1729}

--- 50 unchanged lines hidden ---
1719 v = (phy << NPE_MII_ADDR_SHL) | (reg << NPE_MII_REG_SHL)
1720 | data | NPE_MII_WRITE
1721 | NPE_MII_GO;
1722 npe_mii_mdio_write(sc, NPE_MAC_MDIO_CMD, v);
1723 /* XXX complain about timeout */
1724 (void) npe_mii_mdio_wait(sc);
1725 return (0);
1726}

--- 50 unchanged lines hidden ---