[haiku-commits] r42754 - in haiku/trunk/src/add-ons/kernel/drivers/network: . jmicron2x0/dev/jme jmicron2x0/dev/mii vt612x/dev/mii vt612x/dev/vge

  • From: zharik@xxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 14 Sep 2011 20:11:04 +0200 (CEST)

Author: siarzhuk
Date: 2011-09-14 20:11:04 +0200 (Wed, 14 Sep 2011)
New Revision: 42754
Changeset: https://dev.haiku-os.org/changeset/42754

Modified:
   haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile
   haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/jme/if_jme.c
   haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/jme/if_jmereg.h
   haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/jme/if_jmevar.h
   haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/mii/jmphy.c
   haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/mii/jmphyreg.h
   haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/mii/ciphy.c
   haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/mii/ciphyreg.h
   haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/mii/ukphy.c
   haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/mii/ukphy_subr.c
   haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/vge/Jamfile
   haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/vge/glue.c
   haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/vge/if_vge.c
   haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/vge/if_vgereg.h
   haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/vge/if_vgevar.h
Log:
Updating vt612x and jmicron2x0 drivers to FreeBSD Release 8.2 sources.



Modified: haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile
===================================================================
--- haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile      2011-09-14 
17:58:37 UTC (rev 42753)
+++ haiku/trunk/src/add-ons/kernel/drivers/network/Jamfile      2011-09-14 
18:11:04 UTC (rev 42754)
@@ -14,7 +14,6 @@
 # FreeBSD 7 drivers
 SubInclude HAIKU_TOP src add-ons kernel drivers network broadcom440x ;
 SubInclude HAIKU_TOP src add-ons kernel drivers network broadcom570x ;
-SubInclude HAIKU_TOP src add-ons kernel drivers network jmicron2x0 ;
 SubInclude HAIKU_TOP src add-ons kernel drivers network marvell_yukon ;
 SubInclude HAIKU_TOP src add-ons kernel drivers network nforce ;
 SubInclude HAIKU_TOP src add-ons kernel drivers network pcnet ;
@@ -23,7 +22,6 @@
 SubInclude HAIKU_TOP src add-ons kernel drivers network attansic_l2 ;
 SubInclude HAIKU_TOP src add-ons kernel drivers network ar81xx ;
 SubInclude HAIKU_TOP src add-ons kernel drivers network rtl81xx ;
-SubInclude HAIKU_TOP src add-ons kernel drivers network vt612x ;
 
 SubIncludeGPL HAIKU_TOP src add-ons kernel drivers network bcm440x ;
 SubIncludeGPL HAIKU_TOP src add-ons kernel drivers network bcm570x ;
@@ -31,10 +29,12 @@
 # FreeBSD 8 drivers
 SubInclude HAIKU_TOP src add-ons kernel drivers network 3com ;
 SubInclude HAIKU_TOP src add-ons kernel drivers network atheros813x ;
+SubInclude HAIKU_TOP src add-ons kernel drivers network dec21xxx ;
 SubInclude HAIKU_TOP src add-ons kernel drivers network ipro100 ;
 SubInclude HAIKU_TOP src add-ons kernel drivers network ipro1000 ;
-SubInclude HAIKU_TOP src add-ons kernel drivers network dec21xxx ;
+SubInclude HAIKU_TOP src add-ons kernel drivers network jmicron2x0 ;
 SubInclude HAIKU_TOP src add-ons kernel drivers network rtl8139 ;
+SubInclude HAIKU_TOP src add-ons kernel drivers network vt612x ;
 
 SubInclude HAIKU_TOP src add-ons kernel drivers network wlan ;
 SubInclude HAIKU_TOP src add-ons kernel drivers network wwan ;

Modified: 
haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/jme/if_jme.c
===================================================================
--- haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/jme/if_jme.c  
2011-09-14 17:58:37 UTC (rev 42753)
+++ haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/jme/if_jme.c  
2011-09-14 18:11:04 UTC (rev 42754)
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/jme/if_jme.c,v 1.10 2008/12/04 02:16:53 
yongari Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/jme/if_jme.c,v 1.11.2.8.2.1 2010/12/21 
17:09:25 kensmith Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -201,13 +201,6 @@
 
 static struct resource_spec jme_irq_spec_msi[] = {
        { SYS_RES_IRQ,          1,              RF_ACTIVE },
-       { SYS_RES_IRQ,          2,              RF_ACTIVE },
-       { SYS_RES_IRQ,          3,              RF_ACTIVE },
-       { SYS_RES_IRQ,          4,              RF_ACTIVE },
-       { SYS_RES_IRQ,          5,              RF_ACTIVE },
-       { SYS_RES_IRQ,          6,              RF_ACTIVE },
-       { SYS_RES_IRQ,          7,              RF_ACTIVE },
-       { SYS_RES_IRQ,          8,              RF_ACTIVE },
        { -1,                   0,              0 }
 };
 
@@ -224,13 +217,8 @@
        sc = device_get_softc(dev);
 
        /* For FPGA version, PHY address 0 should be ignored. */
-       if ((sc->jme_flags & JME_FLAG_FPGA) != 0) {
-               if (phy == 0)
-                       return (0);
-       } else {
-               if (sc->jme_phyaddr != phy)
-                       return (0);
-       }
+       if ((sc->jme_flags & JME_FLAG_FPGA) != 0 && phy == 0)
+               return (0);
 
        CSR_WRITE_4(sc, JME_SMI, SMI_OP_READ | SMI_OP_EXECUTE |
            SMI_PHY_ADDR(phy) | SMI_REG_ADDR(reg));
@@ -260,13 +248,8 @@
        sc = device_get_softc(dev);
 
        /* For FPGA version, PHY address 0 should be ignored. */
-       if ((sc->jme_flags & JME_FLAG_FPGA) != 0) {
-               if (phy == 0)
-                       return (0);
-       } else {
-               if (sc->jme_phyaddr != phy)
-                       return (0);
-       }
+       if ((sc->jme_flags & JME_FLAG_FPGA) != 0 && phy == 0)
+               return (0);
 
        CSR_WRITE_4(sc, JME_SMI, SMI_OP_WRITE | SMI_OP_EXECUTE |
            ((val << SMI_DATA_SHIFT) & SMI_DATA_MASK) |
@@ -306,6 +289,10 @@
 
        sc = ifp->if_softc;
        JME_LOCK(sc);
+       if ((ifp->if_flags & IFF_UP) == 0) {
+               JME_UNLOCK(sc);
+               return;
+       }
        mii = device_get_softc(sc->jme_miibus);
 
        mii_pollstat(mii);
@@ -461,7 +448,7 @@
                    "generating fake ethernet address.\n");
                par0 = arc4random();
                /* Set OUI to JMicron. */
-               sc->jme_eaddr[0] = 0x00;
+               sc->jme_eaddr[0] = 0x02;        /* U/L bit set. */
                sc->jme_eaddr[1] = 0x1B;
                sc->jme_eaddr[2] = 0x8C;
                sc->jme_eaddr[3] = (par0 >> 16) & 0xff;
@@ -592,11 +579,16 @@
                device_printf(dev, "MSI count : %d\n", msic);
        }
 
+       /* Use 1 MSI/MSI-X. */
+       if (msixc > 1)
+               msixc = 1;
+       if (msic > 1)
+               msic = 1;
        /* Prefer MSIX over MSI. */
        if (msix_disable == 0 || msi_disable == 0) {
-               if (msix_disable == 0 && msixc == JME_MSIX_MESSAGES &&
+               if (msix_disable == 0 && msixc > 0 &&
                    pci_alloc_msix(dev, &msixc) == 0) {
-                       if (msic == JME_MSIX_MESSAGES) {
+                       if (msixc == 1) {
                                device_printf(dev, "Using %d MSIX messages.\n",
                                    msixc);
                                sc->jme_flags |= JME_FLAG_MSIX;
@@ -605,9 +597,8 @@
                                pci_release_msi(dev);
                }
                if (msi_disable == 0 && (sc->jme_flags & JME_FLAG_MSIX) == 0 &&
-                   msic == JME_MSI_MESSAGES &&
-                   pci_alloc_msi(dev, &msic) == 0) {
-                       if (msic == JME_MSI_MESSAGES) {
+                   msic > 0 && pci_alloc_msi(dev, &msic) == 0) {
+                       if (msic == 1) {
                                device_printf(dev, "Using %d MSI messages.\n",
                                    msic);
                                sc->jme_flags |= JME_FLAG_MSI;
@@ -747,9 +738,11 @@
        ifp->if_capenable = ifp->if_capabilities;
 
        /* Set up MII bus. */
-       if ((error = mii_phy_probe(dev, &sc->jme_miibus, jme_mediachange,
-           jme_mediastatus)) != 0) {
-               device_printf(dev, "no PHY found!\n");
+       error = mii_attach(dev, &sc->jme_miibus, ifp, jme_mediachange,
+           jme_mediastatus, BMSR_DEFCAPMASK, sc->jme_phyaddr, MII_OFFSET_ANY,
+           MIIF_DOPAUSE);
+       if (error != 0) {
+               device_printf(dev, "attaching PHYs failed\n");
                goto fail;
        }
 
@@ -779,7 +772,7 @@
 
        /* VLAN capability setup */
        ifp->if_capabilities |= IFCAP_VLAN_MTU | IFCAP_VLAN_HWTAGGING |
-           IFCAP_VLAN_HWCSUM;
+           IFCAP_VLAN_HWCSUM | IFCAP_VLAN_HWTSO;
        ifp->if_capenable = ifp->if_capabilities;
 
        /* Tell the upper layer(s) we support long frames. */
@@ -798,13 +791,7 @@
        taskqueue_start_threads(&sc->jme_tq, 1, PI_NET, "%s taskq",
            device_get_nameunit(sc->jme_dev));
 
-       if ((sc->jme_flags & JME_FLAG_MSIX) != 0)
-               msic = JME_MSIX_MESSAGES;
-       else if ((sc->jme_flags & JME_FLAG_MSI) != 0)
-               msic = JME_MSI_MESSAGES;
-       else
-               msic = 1;
-       for (i = 0; i < msic; i++) {
+       for (i = 0; i < 1; i++) {
                error = bus_setup_intr(dev, sc->jme_irq[i],
                    INTR_TYPE_NET | INTR_MPSAFE, jme_intr, NULL, sc,
                    &sc->jme_intrhand[i]);
@@ -832,7 +819,7 @@
 {
        struct jme_softc *sc;
        struct ifnet *ifp;
-       int i, msic;
+       int i;
 
        sc = device_get_softc(dev);
 
@@ -867,14 +854,7 @@
                sc->jme_ifp = NULL;
        }
 
-       msic = 1;
-       if ((sc->jme_flags & JME_FLAG_MSIX) != 0)
-               msic = JME_MSIX_MESSAGES;
-       else if ((sc->jme_flags & JME_FLAG_MSI) != 0)
-               msic = JME_MSI_MESSAGES;
-       else
-               msic = 1;
-       for (i = 0; i < msic; i++) {
+       for (i = 0; i < 1; i++) {
                if (sc->jme_intrhand[i] != NULL) {
                        bus_teardown_intr(dev, sc->jme_irq[i],
                            sc->jme_intrhand[i]);
@@ -1585,8 +1565,10 @@
                    pmc + PCIR_POWER_STATUS, pmstat, 2);
        }
        ifp = sc->jme_ifp;
-       if ((ifp->if_flags & IFF_UP) != 0)
+       if ((ifp->if_flags & IFF_UP) != 0) {
+               ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
                jme_init_locked(sc);
+       }
 
        JME_UNLOCK(sc);
 
@@ -1659,11 +1641,12 @@
                        *m_head = NULL;
                        return (ENOBUFS);
                }
-               tcp = (struct tcphdr *)(mtod(m, char *) + poff);
                /*
                 * Reset IP checksum and recompute TCP pseudo
                 * checksum that NDIS specification requires.
                 */
+               ip = (struct ip *)(mtod(m, char *) + ip_off);
+               tcp = (struct tcphdr *)(mtod(m, char *) + poff);
                ip->ip_sum = 0;
                if (poff + (tcp->th_off << 2) == m->m_pkthdr.len) {
                        tcp->th_sum = in_pseudo(ip->ip_src.s_addr,
@@ -1861,6 +1844,7 @@
        if ((sc->jme_flags & JME_FLAG_LINK) == 0) {
                if_printf(sc->jme_ifp, "watchdog timeout (missed link)\n");
                ifp->if_oerrors++;
+               ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
                jme_init_locked(sc);
                return;
        }
@@ -1875,6 +1859,7 @@
 
        if_printf(sc->jme_ifp, "watchdog timeout\n");
        ifp->if_oerrors++;
+       ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
        jme_init_locked(sc);
        if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd))
                taskqueue_enqueue(sc->jme_tq, &sc->jme_tx_task);
@@ -1917,8 +1902,10 @@
                                VLAN_CAPABILITIES(ifp);
                        }
                        ifp->if_mtu = ifr->ifr_mtu;
-                       if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
+                       if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) {
+                               ifp->if_drv_flags &= ~IFF_DRV_RUNNING;
                                jme_init_locked(sc);
+                       }
                        JME_UNLOCK(sc);
                }
                break;
@@ -1990,6 +1977,9 @@
                if ((mask & IFCAP_VLAN_HWCSUM) != 0 &&
                    (ifp->if_capabilities & IFCAP_VLAN_HWCSUM) != 0)
                        ifp->if_capenable ^= IFCAP_VLAN_HWCSUM;
+               if ((mask & IFCAP_VLAN_HWTSO) != 0 &&
+                   (ifp->if_capabilities & IFCAP_VLAN_HWTSO) != 0)
+                       ifp->if_capenable ^= IFCAP_VLAN_HWTSO;
                if ((mask & IFCAP_VLAN_HWTAGGING) != 0 &&
                    (IFCAP_VLAN_HWTAGGING & ifp->if_capabilities) != 0) {
                        ifp->if_capenable ^= IFCAP_VLAN_HWTAGGING;
@@ -2034,12 +2024,10 @@
                txmac &= ~(TXMAC_COLL_ENB | TXMAC_CARRIER_SENSE |
                    TXMAC_BACKOFF | TXMAC_CARRIER_EXT |
                    TXMAC_FRAME_BURST);
-#ifdef notyet
                if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_TXPAUSE) != 0)
                        txpause |= TXPFC_PAUSE_ENB;
                if ((IFM_OPTIONS(mii->mii_media_active) & IFM_ETH_RXPAUSE) != 0)
                        rxmac |= RXMAC_FC_ENB;
-#endif
                /* Disable retry transmit timer/retry limit. */
                CSR_WRITE_4(sc, JME_TXTRHD, CSR_READ_4(sc, JME_TXTRHD) &
                    ~(TXTRHD_RT_PERIOD_ENB | TXTRHD_RT_LIMIT_ENB));
@@ -2642,6 +2630,8 @@
        ifp = sc->jme_ifp;
        mii = device_get_softc(sc->jme_miibus);
 
+       if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0)
+               return;
        /*
         * Cancel any pending I/O.
         */
@@ -3122,7 +3112,7 @@
        rxcfg |= RXMAC_MULTICAST;
        bzero(mchash, sizeof(mchash));
 
-       IF_ADDR_LOCK(ifp);
+       if_maddr_rlock(ifp);
        TAILQ_FOREACH(ifma, &sc->jme_ifp->if_multiaddrs, ifma_link) {
                if (ifma->ifma_addr->sa_family != AF_LINK)
                        continue;
@@ -3135,7 +3125,7 @@
                /* Set the corresponding bit in the hash table. */
                mchash[crc >> 5] |= 1 << (crc & 0x1f);
        }
-       IF_ADDR_UNLOCK(ifp);
+       if_maddr_runlock(ifp);
 
        CSR_WRITE_4(sc, JME_MAR0, mchash[0]);
        CSR_WRITE_4(sc, JME_MAR1, mchash[1]);

Modified: 
haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/jme/if_jmereg.h
===================================================================
--- 
haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/jme/if_jmereg.h   
    2011-09-14 17:58:37 UTC (rev 42753)
+++ 
haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/jme/if_jmereg.h   
    2011-09-14 18:11:04 UTC (rev 42754)
@@ -24,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/jme/if_jmereg.h,v 1.6 2008/12/04 02:16:53 yongari Exp 
$
+ * $FreeBSD: src/sys/dev/jme/if_jmereg.h,v 1.6.2.2.2.1 2010/12/21 17:09:25 
kensmith Exp $
  */
 
 #ifndef        _IF_JMEREG_H
@@ -275,8 +275,8 @@
 #define        RXCSR_RXQ2              2
 #define        RXCSR_RXQ3              3
 #define        RXCSR_DESC_RT_CNT(x)    \
-       ((((x) / 4) << RXCSR_DESC_RT_CNT_SHIFT) & RXCSR_DESC_RT_CNT_MASK)
-#define        RXCSR_DESC_RT_CNT_DEFAULT       32
+       (((x) << RXCSR_DESC_RT_CNT_SHIFT) & RXCSR_DESC_RT_CNT_MASK)
+#define        RXCSR_DESC_RT_CNT_DEFAULT       0
 
 /* Rx queue descriptor base address. 16bytes alignment needed. */
 #define        JME_RXDBA_LO            0x0024

Modified: 
haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/jme/if_jmevar.h
===================================================================
--- 
haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/jme/if_jmevar.h   
    2011-09-14 17:58:37 UTC (rev 42753)
+++ 
haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/jme/if_jmevar.h   
    2011-09-14 18:11:04 UTC (rev 42754)
@@ -24,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/jme/if_jmevar.h,v 1.3 2008/12/04 02:16:53 yongari Exp 
$
+ * $FreeBSD: src/sys/dev/jme/if_jmevar.h,v 1.3.2.1.6.1 2010/12/21 17:09:25 
kensmith Exp $
  */
 
 #ifndef        _IF_JMEVAR_H

Modified: 
haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/mii/jmphy.c
===================================================================
--- haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/mii/jmphy.c   
2011-09-14 17:58:37 UTC (rev 42753)
+++ haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/mii/jmphy.c   
2011-09-14 18:11:04 UTC (rev 42754)
@@ -26,7 +26,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/mii/jmphy.c,v 1.1 2008/05/27 01:16:40 yongari 
Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/mii/jmphy.c,v 1.1.6.5.2.1 2010/12/21 17:09:25 
kensmith Exp $");
 
 /*
  * Driver for the JMicron JMP211 10/100/1000, JMP202 10/100 PHY.
@@ -50,11 +50,11 @@
 
 #include "miibus_if.h"
 
-static int     jmphy_probe(device_t);
-static int     jmphy_attach(device_t);
+static int     jmphy_probe(device_t);
+static int     jmphy_attach(device_t);
 static void    jmphy_reset(struct mii_softc *);
 static uint16_t        jmphy_anar(struct ifmedia_entry *);
-static int     jmphy_auto(struct mii_softc *, struct ifmedia_entry *);
+static int     jmphy_setmedia(struct mii_softc *, struct ifmedia_entry *);
 
 struct jmphy_softc {
        struct mii_softc mii_sc;
@@ -109,16 +109,15 @@
        sc = &jsc->mii_sc;
        ma = device_get_ivars(dev);
        sc->mii_dev = device_get_parent(dev);
-       mii = device_get_softc(sc->mii_dev);
+       mii = ma->mii_data;
        LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
 
-       sc->mii_inst = mii->mii_instance;
+       sc->mii_flags = miibus_get_flags(dev);
+       sc->mii_inst = mii->mii_instance++;
        sc->mii_phy = ma->mii_phyno;
        sc->mii_service = jmphy_service;
        sc->mii_pdata = mii;
 
-       mii->mii_instance++;
-
        jsc->mii_oui = MII_OUI(ma->mii_id1, ma->mii_id2);
        jsc->mii_model = MII_MODEL(ma->mii_id2);
        jsc->mii_rev = MII_REV(ma->mii_id2);
@@ -136,53 +135,31 @@
        printf("\n");
 
        MIIBUS_MEDIAINIT(sc->mii_dev);
-       return(0);
+       return (0);
 }
 
 static int
 jmphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
 {
        struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
-       uint16_t bmcr;
 
        switch (cmd) {
        case MII_POLLSTAT:
-               /*
-                * If we're not polling our PHY instance, just return.
-                */
-               if (IFM_INST(ife->ifm_media) != sc->mii_inst)
-                       return (0);
                break;
 
        case MII_MEDIACHG:
                /*
-                * If the media indicates a different PHY instance,
-                * isolate ourselves.
-                */
-               if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
-                       bmcr = PHY_READ(sc, MII_BMCR);
-                       PHY_WRITE(sc, MII_BMCR, bmcr | BMCR_ISO);
-                       return (0);
-               }
-
-               /*
                 * If the interface is not up, don't do anything.
                 */
                if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
                        break;
 
-               if (jmphy_auto(sc, ife) != EJUSTRETURN)
+               if (jmphy_setmedia(sc, ife) != EJUSTRETURN)
                        return (EINVAL);
                break;
 
        case MII_TICK:
                /*
-                * If we're not currently selected, just return.
-                */
-               if (IFM_INST(ife->ifm_media) != sc->mii_inst)
-                       return (0);
-
-               /*
                 * Is the interface even up?
                 */
                if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
@@ -209,7 +186,7 @@
                        return (0);
 
                sc->mii_ticks = 0;
-               jmphy_auto(sc, ife);
+               (void)jmphy_setmedia(sc, ife);
                break;
        }
 
@@ -274,16 +251,14 @@
        }
 
        if ((ssr & JMPHY_SSR_DUPLEX) != 0)
-               mii->mii_media_active |= IFM_FDX;
+               mii->mii_media_active |= IFM_FDX | mii_phy_flowstatus(sc);
        else
                mii->mii_media_active |= IFM_HDX;
-       /* XXX Flow-control. */
-#ifdef notyet
+
        if (IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T) {
                if ((PHY_READ(sc, MII_100T2SR) & GTSR_MS_RES) != 0)
                        mii->mii_media_active |= IFM_ETH_MASTER;
        }
-#endif
 }
 
 static void
@@ -332,7 +307,7 @@
 }
 
 static int
-jmphy_auto(struct mii_softc *sc, struct ifmedia_entry *ife)
+jmphy_setmedia(struct mii_softc *sc, struct ifmedia_entry *ife)
 {
        uint16_t anar, bmcr, gig;
 
@@ -359,17 +334,18 @@
                bmcr |= BMCR_LOOP;
 
        anar = jmphy_anar(ife);
-       /* XXX Always advertise pause capability. */
-       anar |= (3 << 10);
+       if (((IFM_SUBTYPE(ife->ifm_media) == IFM_AUTO ||
+           (ife->ifm_media & IFM_FDX) != 0) &&
+           (ife->ifm_media & IFM_FLOW) != 0) ||
+           (sc->mii_flags & MIIF_FORCEPAUSE) != 0)
+               anar |= ANAR_PAUSE_TOWARDS;
 
        if ((sc->mii_flags & MIIF_HAVE_GTCR) != 0) {
-#ifdef notyet
-               struct mii_data *mii;
-
-               mii = sc->mii_pdata;
-               if ((mii->mii_media.ifm_media & IFM_ETH_MASTER) != 0)
-                       gig |= GTCR_MAN_MS | GTCR_MAN_ADV;
-#endif
+               if (IFM_SUBTYPE(ife->ifm_media) == IFM_1000_T) {
+                       gig |= GTCR_MAN_MS;
+                       if ((ife->ifm_media & IFM_ETH_MASTER) != 0)
+                               gig |= GTCR_ADV_MS;
+               }
                PHY_WRITE(sc, MII_100T2CR, gig);
        }
        PHY_WRITE(sc, MII_ANAR, anar | ANAR_CSMA);

Modified: 
haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/mii/jmphyreg.h
===================================================================
--- 
haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/mii/jmphyreg.h    
    2011-09-14 17:58:37 UTC (rev 42753)
+++ 
haiku/trunk/src/add-ons/kernel/drivers/network/jmicron2x0/dev/mii/jmphyreg.h    
    2011-09-14 18:11:04 UTC (rev 42754)
@@ -24,7 +24,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/mii/jmphyreg.h,v 1.1 2008/05/27 01:16:40 yongari Exp $
+ * $FreeBSD: src/sys/dev/mii/jmphyreg.h,v 1.1.6.1.6.1 2010/12/21 17:09:25 
kensmith Exp $
  */
 
 #ifndef        _DEV_MII_JMPHYREG_H_

Modified: haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/mii/ciphy.c
===================================================================
--- haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/mii/ciphy.c       
2011-09-14 17:58:37 UTC (rev 42753)
+++ haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/mii/ciphy.c       
2011-09-14 18:11:04 UTC (rev 42754)
@@ -28,15 +28,13 @@
  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD: src/sys/dev/mii/ciphy.c,v 1.2 2005/01/06 01:42:55 imp Exp $
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/mii/ciphy.c,v 1.2 2005/01/06 01:42:55 imp Exp 
$");
+__FBSDID("$FreeBSD: src/sys/dev/mii/ciphy.c,v 1.17.2.5.2.1 2010/12/21 17:09:25 
kensmith Exp $");
 
 /*
- * Driver for the Cicada CS8201 10/100/1000 copper PHY.
+ * Driver for the Cicada/Vitesse CS/VSC8xxx 10/100/1000 copper PHY.
  */
 
 #include <sys/param.h>
@@ -46,8 +44,6 @@
 #include <sys/socket.h>
 #include <sys/bus.h>
 
-#include <machine/clock.h>
-
 #include <net/if.h>
 #include <net/if_arp.h>
 #include <net/if_media.h>
@@ -61,9 +57,7 @@
 #include "miibus_if.h"
 
 #include <machine/bus.h>
-/*
-#include <dev/vge/if_vgereg.h>
-*/
+
 static int ciphy_probe(device_t);
 static int ciphy_attach(device_t);
 
@@ -91,40 +85,26 @@
 static void    ciphy_reset(struct mii_softc *);
 static void    ciphy_fixup(struct mii_softc *);
 
+static const struct mii_phydesc ciphys[] = {
+       MII_PHY_DESC(CICADA, CS8201),
+       MII_PHY_DESC(CICADA, CS8201A),
+       MII_PHY_DESC(CICADA, CS8201B),
+       MII_PHY_DESC(CICADA, CS8204),
+       MII_PHY_DESC(CICADA, VSC8211),
+       MII_PHY_DESC(CICADA, CS8244),
+       MII_PHY_DESC(VITESSE, VSC8601),
+       MII_PHY_END
+};
+
 static int
-ciphy_probe(dev)
-       device_t                dev;
+ciphy_probe(device_t dev)
 {
-       struct mii_attach_args *ma;
 
-       ma = device_get_ivars(dev);
-
-device_printf(dev, "OUI: %x\n", MII_OUI(ma->mii_id1, ma->mii_id2));
-device_printf(dev, "MODEL: %x\n", MII_MODEL(ma->mii_id2));
-       if (MII_OUI(ma->mii_id1, ma->mii_id2) == MII_OUI_CICADA &&
-           MII_MODEL(ma->mii_id2) == MII_MODEL_CICADA_CS8201) {
-               device_set_desc(dev, MII_STR_CICADA_CS8201);
-               return(0);
-       }
-
-       if (MII_OUI(ma->mii_id1, ma->mii_id2) == MII_OUI_CICADA &&
-           MII_MODEL(ma->mii_id2) == MII_MODEL_CICADA_CS8201A) {
-               device_set_desc(dev, MII_STR_CICADA_CS8201A);
-               return(0);
-       }
-
-       if (MII_OUI(ma->mii_id1, ma->mii_id2) == MII_OUI_CICADA &&
-           MII_MODEL(ma->mii_id2) == MII_MODEL_CICADA_CS8201B) {
-               device_set_desc(dev, MII_STR_CICADA_CS8201B);
-               return(0);
-       }
-
-       return(ENXIO);
+       return (mii_phy_dev_probe(dev, ciphys, BUS_PROBE_DEFAULT));
 }
 
 static int
-ciphy_attach(dev)
-       device_t                dev;
+ciphy_attach(device_t dev)
 {
        struct mii_softc *sc;
        struct mii_attach_args *ma;
@@ -133,21 +113,20 @@
        sc = device_get_softc(dev);
        ma = device_get_ivars(dev);
        sc->mii_dev = device_get_parent(dev);
-       mii = device_get_softc(sc->mii_dev);
+       mii = ma->mii_data;
        LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
 
-       sc->mii_inst = mii->mii_instance;
+       sc->mii_flags = miibus_get_flags(dev);
+       sc->mii_inst = mii->mii_instance++;
        sc->mii_phy = ma->mii_phyno;
        sc->mii_service = ciphy_service;
        sc->mii_pdata = mii;
 
        sc->mii_flags |= MIIF_NOISOLATE;
-       mii->mii_instance++;
 
        ciphy_reset(sc);
 
-       sc->mii_capabilities =
-           PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
+       sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
        if (sc->mii_capabilities & BMSR_EXTSTAT)
                sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
        device_printf(dev, " ");
@@ -155,39 +134,21 @@
        printf("\n");
 
        MIIBUS_MEDIAINIT(sc->mii_dev);
-       return(0);
+       return (0);
 }
 
 static int
-ciphy_service(sc, mii, cmd)
-       struct mii_softc *sc;
-       struct mii_data *mii;
-       int cmd;
+ciphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
 {
        struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
        int reg, speed, gig;
 
        switch (cmd) {
        case MII_POLLSTAT:
-               /*
-                * If we're not polling our PHY instance, just return.
-                */
-               if (IFM_INST(ife->ifm_media) != sc->mii_inst)
-                       return (0);
                break;
 
        case MII_MEDIACHG:
                /*
-                * If the media indicates a different PHY instance,
-                * isolate ourselves.
-                */
-               if (IFM_INST(ife->ifm_media) != sc->mii_inst) {
-                       reg = PHY_READ(sc, MII_BMCR);
-                       PHY_WRITE(sc, MII_BMCR, reg | BMCR_ISO);
-                       return (0);
-               }
-
-               /*
                 * If the interface is not up, don't do anything.
                 */
                if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
@@ -204,7 +165,7 @@
                        if (PHY_READ(sc, CIPHY_MII_BMCR) & CIPHY_BMCR_AUTOEN)
                                return (0);
 #endif
-                       (void) mii_phy_auto(sc);
+                       (void)mii_phy_auto(sc);
                        break;
                case IFM_1000_T:
                        speed = CIPHY_S1000;
@@ -226,33 +187,20 @@
                        PHY_WRITE(sc, CIPHY_MII_BMCR, speed);
                        PHY_WRITE(sc, CIPHY_MII_ANAR, CIPHY_SEL_TYPE);
 
-                       if (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T) 
+                       if (IFM_SUBTYPE(ife->ifm_media) != IFM_1000_T)
                                break;
 
+                       gig |= CIPHY_1000CTL_MSE;
+                       if ((ife->ifm_media & IFM_ETH_MASTER) != 0 ||
+                           (mii->mii_ifp->if_flags & IFF_LINK0) != 0)
+                               gig |= CIPHY_1000CTL_MSC;
                        PHY_WRITE(sc, CIPHY_MII_1000CTL, gig);
                        PHY_WRITE(sc, CIPHY_MII_BMCR,
-                           speed|CIPHY_BMCR_AUTOEN|CIPHY_BMCR_STARTNEG);
-
-                       /*
-                        * When setting the link manually, one side must
-                        * be the master and the other the slave. However
-                        * ifmedia doesn't give us a good way to specify
-                        * this, so we fake it by using one of the LINK
-                        * flags. If LINK0 is set, we program the PHY to
-                        * be a master, otherwise it's a slave.
-                        */
-                       if ((mii->mii_ifp->if_flags & IFF_LINK0)) {
-                               PHY_WRITE(sc, CIPHY_MII_1000CTL,
-                                   gig|CIPHY_1000CTL_MSE|CIPHY_1000CTL_MSC);
-                       } else {
-                               PHY_WRITE(sc, CIPHY_MII_1000CTL,
-                                   gig|CIPHY_1000CTL_MSE);
-                       }
+                           speed | CIPHY_BMCR_AUTOEN | CIPHY_BMCR_STARTNEG);
                        break;
                case IFM_NONE:
-                       PHY_WRITE(sc, MII_BMCR, BMCR_ISO|BMCR_PDOWN);
+                       PHY_WRITE(sc, MII_BMCR, BMCR_ISO | BMCR_PDOWN);
                        break;
-               case IFM_100_T4:
                default:
                        return (EINVAL);
                }
@@ -260,12 +208,6 @@
 
        case MII_TICK:
                /*
-                * If we're not currently selected, just return.
-                */
-               if (IFM_INST(ife->ifm_media) != sc->mii_inst)
-                       return (0);
-
-               /*
                 * Is the interface even up?
                 */
                if ((mii->mii_ifp->if_flags & IFF_UP) == 0)
@@ -286,15 +228,18 @@
                if (reg & BMSR_LINK)
                        break;
 
+               /* Announce link loss right after it happens. */
+               if (++sc->mii_ticks == 0)
+                       break;
                /*
-                * Only retry autonegotiation every 5 seconds.
+                * Only retry autonegotiation every mii_anegticks seconds.
                 */
-               if (++sc->mii_ticks <= 5/*10*/)
+               if (sc->mii_ticks <= sc->mii_anegticks)
                        break;
-               
+
                sc->mii_ticks = 0;
                mii_phy_auto(sc);
-               return (0);
+               break;
        }
 
        /* Update the media status. */
@@ -304,7 +249,7 @@
         * Callback if something changed. Note that we need to poke
         * apply fixups for certain PHY revs.
         */
-       if (sc->mii_media_active != mii->mii_media_active || 
+       if (sc->mii_media_active != mii->mii_media_active ||
            sc->mii_media_status != mii->mii_media_status ||
            cmd == MII_MEDIACHG) {
                ciphy_fixup(sc);
@@ -314,8 +259,7 @@
 }
 
 static void
-ciphy_status(sc)
-       struct mii_softc *sc;
+ciphy_status(struct mii_softc *sc)
 {
        struct mii_data *mii = sc->mii_pdata;
        int bmsr, bmcr;
@@ -360,17 +304,20 @@
 
        if (bmsr & CIPHY_AUXCSR_FDX)
                mii->mii_media_active |= IFM_FDX;
+       else
+               mii->mii_media_active |= IFM_HDX;
 
-       return;
+       if ((IFM_SUBTYPE(mii->mii_media_active) == IFM_1000_T) &&
+          (PHY_READ(sc, CIPHY_MII_1000STS) & CIPHY_1000STS_MSR) != 0)
+               mii->mii_media_active |= IFM_ETH_MASTER;
 }
 
 static void
 ciphy_reset(struct mii_softc *sc)
 {
+
        mii_phy_reset(sc);
        DELAY(1000);
-
-       return;
 }
 
 #define PHY_SETBIT(x, y, z) \
@@ -383,12 +330,30 @@
 {
        uint16_t                model;
        uint16_t                status, speed;
+       uint16_t                val;
 
        model = MII_MODEL(PHY_READ(sc, CIPHY_MII_PHYIDR2));
        status = PHY_READ(sc, CIPHY_MII_AUXCSR);
        speed = status & CIPHY_AUXCSR_SPEED;
 
+       if (strcmp(device_get_name(device_get_parent(sc->mii_dev)),
+           "nfe") == 0) {
+               /* need to set for 2.5V RGMII for NVIDIA adapters */
+               val = PHY_READ(sc, CIPHY_MII_ECTL1);
+               val &= ~(CIPHY_ECTL1_IOVOL | CIPHY_ECTL1_INTSEL);
+               val |= (CIPHY_IOVOL_2500MV | CIPHY_INTSEL_RGMII);
+               PHY_WRITE(sc, CIPHY_MII_ECTL1, val);
+               /* From Linux. */
+               val = PHY_READ(sc, CIPHY_MII_AUXCSR);
+               val |= CIPHY_AUXCSR_MDPPS;
+               PHY_WRITE(sc, CIPHY_MII_AUXCSR, val);
+               val = PHY_READ(sc, CIPHY_MII_10BTCSR);
+               val |= CIPHY_10BTCSR_ECHO;
+               PHY_WRITE(sc, CIPHY_MII_10BTCSR, val);
+       }
+
        switch (model) {
+       case MII_MODEL_CICADA_CS8204:
        case MII_MODEL_CICADA_CS8201:
 
                /* Turn off "aux mode" (whatever that means) */
@@ -425,11 +390,13 @@
                }
 
                break;
+       case MII_MODEL_CICADA_VSC8211:
+       case MII_MODEL_CICADA_CS8244:
+       case MII_MODEL_VITESSE_VSC8601:
+               break;
        default:
                device_printf(sc->mii_dev, "unknown CICADA PHY model %x\n",
                    model);
                break;
        }
-
-       return;
 }

Modified: 
haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/mii/ciphyreg.h
===================================================================
--- haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/mii/ciphyreg.h    
2011-09-14 17:58:37 UTC (rev 42753)
+++ haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/mii/ciphyreg.h    
2011-09-14 18:11:04 UTC (rev 42754)
@@ -29,7 +29,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
- * $FreeBSD: src/sys/dev/mii/ciphyreg.h,v 1.2 2005/01/06 01:42:55 imp Exp $
+ * $FreeBSD: src/sys/dev/mii/ciphyreg.h,v 1.3.10.1.6.1 2010/12/21 17:09:25 
kensmith Exp $
  */
 
 #ifndef _DEV_MII_CIPHYREG_H_
@@ -251,7 +251,17 @@
 /* Extended PHY control register #1 */
 #define CIPHY_MII_ECTL1                0x17
 #define CIPHY_ECTL1_ACTIPHY    0x0020  /* Enable ActiPHY power saving */
+#define CIPHY_ECTL1_IOVOL      0x0e00  /* MAC interface and I/O voltage select 
*/
+#define CIPHY_ECTL1_INTSEL     0xf000  /* select MAC interface */
 
+#define CIPHY_IOVOL_3300MV     0x0000  /* 3.3V for I/O pins */
+#define CIPHY_IOVOL_2500MV     0x0200  /* 2.5V for I/O pins */
+
+#define CIPHY_INTSEL_GMII      0x0000  /* GMII/MII */
+#define CIPHY_INTSEL_RGMII     0x1000
+#define CIPHY_INTSEL_TBI       0x2000
+#define CIPHY_INTSEL_RTBI      0x3000
+
 /* Extended PHY control register #2 */
 #define CIPHY_MII_ECTL2                0x18
 #define CIPHY_ECTL2_ERATE      0xE000  /* 10/1000 edge rate control */

Modified: haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/mii/ukphy.c
===================================================================
--- haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/mii/ukphy.c       
2011-09-14 17:58:37 UTC (rev 42753)
+++ haiku/trunk/src/add-ons/kernel/drivers/network/vt612x/dev/mii/ukphy.c       
2011-09-14 18:11:04 UTC (rev 42754)
@@ -16,13 +16,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the NetBSD
- *     Foundation, Inc. and its contributors.
- * 4. Neither the name of The NetBSD Foundation nor the names of its
- *    contributors may be used to endorse or promote products derived
- *    from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
@@ -48,11 +41,6 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by Manuel Bouyer.
- * 4. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
  *
  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
@@ -67,7 +55,7 @@
  */
 
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/mii/ukphy.c,v 1.20 2007/01/20 00:52:29 marius 
Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/mii/ukphy.c,v 1.20.10.6.2.1 2010/12/21 
17:09:25 kensmith Exp $");
 
 /*
  * driver for generic unknown PHYs
@@ -134,7 +122,7 @@
        sc = device_get_softc(dev);
        ma = device_get_ivars(dev);
        sc->mii_dev = device_get_parent(dev);
-       mii = device_get_softc(sc->mii_dev);
+       mii = ma->mii_data;
        LIST_INSERT_HEAD(&mii->mii_phys, sc, mii_list);
 
        if (bootverbose)
@@ -142,17 +130,17 @@
                    MII_OUI(ma->mii_id1, ma->mii_id2),
                    MII_MODEL(ma->mii_id2), MII_REV(ma->mii_id2));
 
-       sc->mii_inst = mii->mii_instance;
+       sc->mii_flags = miibus_get_flags(dev);
+       sc->mii_inst = mii->mii_instance++;
        sc->mii_phy = ma->mii_phyno;
        sc->mii_service = ukphy_service;
        sc->mii_pdata = mii;
 
-       mii->mii_instance++;
+       sc->mii_flags |= MIIF_NOMANPAUSE;
 
        mii_phy_reset(sc);
 
-       sc->mii_capabilities =
-           PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
+       sc->mii_capabilities = PHY_READ(sc, MII_BMSR) & ma->mii_capmask;
        if (sc->mii_capabilities & BMSR_EXTSTAT)
                sc->mii_extcapabilities = PHY_READ(sc, MII_EXTSR);
        device_printf(dev, " ");
@@ -168,30 +156,13 @@
 static int
 ukphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd)
 {
-       struct ifmedia_entry *ife = mii->mii_media.ifm_cur;
-       int reg;
 
        switch (cmd) {
        case MII_POLLSTAT:
-               /*
-                * If we're not polling our PHY instance, just return.
-                */
-               if (IFM_INST(ife->ifm_media) != sc->mii_inst)
-                       return (0);
                break;
 
        case MII_MEDIACHG:
                /*
-                * If the media indicates a different PHY instance,

[... truncated: 4189 lines follow ...]

Other related posts:

  • » [haiku-commits] r42754 - in haiku/trunk/src/add-ons/kernel/drivers/network: . jmicron2x0/dev/jme jmicron2x0/dev/mii vt612x/dev/mii vt612x/dev/vge - zharik