Deleted Added
full compact
if_nge.c (146734) if_nge.c (147256)
1/*-
2 * Copyright (c) 2001 Wind River Systems
3 * Copyright (c) 1997, 1998, 1999, 2000, 2001
4 * Bill Paul <wpaul@bsdi.com>. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 2001 Wind River Systems
3 * Copyright (c) 1997, 1998, 1999, 2000, 2001
4 * Bill Paul <wpaul@bsdi.com>. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

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

27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
31 * THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34#include <sys/cdefs.h>
35__FBSDID("$FreeBSD: head/sys/dev/nge/if_nge.c 146734 2005-05-29 04:42:30Z nyan $");
35__FBSDID("$FreeBSD: head/sys/dev/nge/if_nge.c 147256 2005-06-10 16:49:24Z brooks $");
36
37/*
38 * National Semiconductor DP83820/DP83821 gigabit ethernet driver
39 * for FreeBSD. Datasheets are available from:
40 *
41 * http://www.national.com/ds/DP/DP83820.pdf
42 * http://www.national.com/ds/DP/DP83821.pdf
43 *

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

667 struct nge_softc *sc;
668{
669 struct ifnet *ifp;
670 struct ifmultiaddr *ifma;
671 u_int32_t h = 0, i, filtsave;
672 int bit, index;
673
674 NGE_LOCK_ASSERT(sc);
36
37/*
38 * National Semiconductor DP83820/DP83821 gigabit ethernet driver
39 * for FreeBSD. Datasheets are available from:
40 *
41 * http://www.national.com/ds/DP/DP83820.pdf
42 * http://www.national.com/ds/DP/DP83821.pdf
43 *

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

667 struct nge_softc *sc;
668{
669 struct ifnet *ifp;
670 struct ifmultiaddr *ifma;
671 u_int32_t h = 0, i, filtsave;
672 int bit, index;
673
674 NGE_LOCK_ASSERT(sc);
675 ifp = &sc->arpcom.ac_if;
675 ifp = sc->nge_ifp;
676
677 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
678 NGE_CLRBIT(sc, NGE_RXFILT_CTL,
679 NGE_RXFILTCTL_MCHASH|NGE_RXFILTCTL_UCHASH);
680 NGE_SETBIT(sc, NGE_RXFILT_CTL, NGE_RXFILTCTL_ALLMULTI);
681 return;
682 }
683

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

829 /*
830 * Get station address from the EEPROM.
831 */
832 nge_read_eeprom(sc, (caddr_t)&eaddr[4], NGE_EE_NODEADDR, 1, 0);
833 nge_read_eeprom(sc, (caddr_t)&eaddr[2], NGE_EE_NODEADDR + 1, 1, 0);
834 nge_read_eeprom(sc, (caddr_t)&eaddr[0], NGE_EE_NODEADDR + 2, 1, 0);
835
836 sc->nge_unit = unit;
676
677 if (ifp->if_flags & IFF_ALLMULTI || ifp->if_flags & IFF_PROMISC) {
678 NGE_CLRBIT(sc, NGE_RXFILT_CTL,
679 NGE_RXFILTCTL_MCHASH|NGE_RXFILTCTL_UCHASH);
680 NGE_SETBIT(sc, NGE_RXFILT_CTL, NGE_RXFILTCTL_ALLMULTI);
681 return;
682 }
683

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

829 /*
830 * Get station address from the EEPROM.
831 */
832 nge_read_eeprom(sc, (caddr_t)&eaddr[4], NGE_EE_NODEADDR, 1, 0);
833 nge_read_eeprom(sc, (caddr_t)&eaddr[2], NGE_EE_NODEADDR + 1, 1, 0);
834 nge_read_eeprom(sc, (caddr_t)&eaddr[0], NGE_EE_NODEADDR + 2, 1, 0);
835
836 sc->nge_unit = unit;
837 bcopy(eaddr, (char *)&sc->arpcom.ac_enaddr, ETHER_ADDR_LEN);
838
837
838 /* XXX: leaked on error */
839 sc->nge_ldata = contigmalloc(sizeof(struct nge_list_data), M_DEVBUF,
840 M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
841
842 if (sc->nge_ldata == NULL) {
843 printf("nge%d: no memory for list buffers!\n", unit);
844 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->nge_irq);
845 bus_release_resource(dev, NGE_RES, NGE_RID, sc->nge_res);
846 error = ENXIO;
847 goto fail;
848 }
839 sc->nge_ldata = contigmalloc(sizeof(struct nge_list_data), M_DEVBUF,
840 M_NOWAIT, 0, 0xffffffff, PAGE_SIZE, 0);
841
842 if (sc->nge_ldata == NULL) {
843 printf("nge%d: no memory for list buffers!\n", unit);
844 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->nge_irq);
845 bus_release_resource(dev, NGE_RES, NGE_RID, sc->nge_res);
846 error = ENXIO;
847 goto fail;
848 }
849 bzero(sc->nge_ldata, sizeof(struct nge_list_data));
850
849
851 ifp = &sc->arpcom.ac_if;
850 ifp = sc->nge_ifp = if_alloc(IFT_ETHER);
851 if (ifp == NULL) {
852 printf("nge%d: can not if_alloc()\n", unit);
853 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->nge_irq);
854 bus_release_resource(dev, NGE_RES, NGE_RID, sc->nge_res);
855 error = ENOSPC;
856 goto fail;
857 }
852 ifp->if_softc = sc;
853 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
854 ifp->if_mtu = ETHERMTU;
855 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
856 ifp->if_ioctl = nge_ioctl;
857 ifp->if_start = nge_start;
858 ifp->if_watchdog = nge_watchdog;
859 ifp->if_init = nge_init;

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

919 callout_init(&sc->nge_stat_ch, CALLOUT_MPSAFE);
920
921 /*
922 * Hookup IRQ last.
923 */
924 error = bus_setup_intr(dev, sc->nge_irq, INTR_TYPE_NET | INTR_MPSAFE,
925 nge_intr, sc, &sc->nge_intrhand);
926 if (error) {
858 ifp->if_softc = sc;
859 if_initname(ifp, device_get_name(dev), device_get_unit(dev));
860 ifp->if_mtu = ETHERMTU;
861 ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
862 ifp->if_ioctl = nge_ioctl;
863 ifp->if_start = nge_start;
864 ifp->if_watchdog = nge_watchdog;
865 ifp->if_init = nge_init;

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

925 callout_init(&sc->nge_stat_ch, CALLOUT_MPSAFE);
926
927 /*
928 * Hookup IRQ last.
929 */
930 error = bus_setup_intr(dev, sc->nge_irq, INTR_TYPE_NET | INTR_MPSAFE,
931 nge_intr, sc, &sc->nge_intrhand);
932 if (error) {
933 /* XXX: resource leaks */
927 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->nge_irq);
928 bus_release_resource(dev, NGE_RES, NGE_RID, sc->nge_res);
929 printf("nge%d: couldn't set up irq\n", unit);
930 }
931
932fail:
933
934 if (error)

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

939static int
940nge_detach(dev)
941 device_t dev;
942{
943 struct nge_softc *sc;
944 struct ifnet *ifp;
945
946 sc = device_get_softc(dev);
934 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->nge_irq);
935 bus_release_resource(dev, NGE_RES, NGE_RID, sc->nge_res);
936 printf("nge%d: couldn't set up irq\n", unit);
937 }
938
939fail:
940
941 if (error)

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

946static int
947nge_detach(dev)
948 device_t dev;
949{
950 struct nge_softc *sc;
951 struct ifnet *ifp;
952
953 sc = device_get_softc(dev);
947 ifp = &sc->arpcom.ac_if;
954 ifp = sc->nge_ifp;
948
949 NGE_LOCK(sc);
950 nge_reset(sc);
951 nge_stop(sc);
952 NGE_UNLOCK(sc);
953 ether_ifdetach(ifp);
955
956 NGE_LOCK(sc);
957 nge_reset(sc);
958 nge_stop(sc);
959 NGE_UNLOCK(sc);
960 ether_ifdetach(ifp);
961 if_free(ifp);
954
955 bus_generic_detach(dev);
956 if (!sc->nge_tbi) {
957 device_delete_child(dev, sc->nge_miibus);
958 }
959 bus_teardown_intr(dev, sc->nge_irq, sc->nge_intrhand);
960 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->nge_irq);
961 bus_release_resource(dev, NGE_RES, NGE_RID, sc->nge_res);

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

1101{
1102 struct mbuf *m;
1103 struct ifnet *ifp;
1104 struct nge_desc *cur_rx;
1105 int i, total_len = 0;
1106 u_int32_t rxstat;
1107
1108 NGE_LOCK_ASSERT(sc);
962
963 bus_generic_detach(dev);
964 if (!sc->nge_tbi) {
965 device_delete_child(dev, sc->nge_miibus);
966 }
967 bus_teardown_intr(dev, sc->nge_irq, sc->nge_intrhand);
968 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->nge_irq);
969 bus_release_resource(dev, NGE_RES, NGE_RID, sc->nge_res);

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

1109{
1110 struct mbuf *m;
1111 struct ifnet *ifp;
1112 struct nge_desc *cur_rx;
1113 int i, total_len = 0;
1114 u_int32_t rxstat;
1115
1116 NGE_LOCK_ASSERT(sc);
1109 ifp = &sc->arpcom.ac_if;
1117 ifp = sc->nge_ifp;
1110 i = sc->nge_cdata.nge_rx_prod;
1111
1112 while(NGE_OWNDESC(&sc->nge_ldata->nge_rx_list[i])) {
1113 u_int32_t extsts;
1114
1115#ifdef DEVICE_POLLING
1116 if (ifp->if_flags & IFF_POLLING) {
1117 if (sc->rxcycles <= 0)

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

1242nge_txeof(sc)
1243 struct nge_softc *sc;
1244{
1245 struct nge_desc *cur_tx;
1246 struct ifnet *ifp;
1247 u_int32_t idx;
1248
1249 NGE_LOCK_ASSERT(sc);
1118 i = sc->nge_cdata.nge_rx_prod;
1119
1120 while(NGE_OWNDESC(&sc->nge_ldata->nge_rx_list[i])) {
1121 u_int32_t extsts;
1122
1123#ifdef DEVICE_POLLING
1124 if (ifp->if_flags & IFF_POLLING) {
1125 if (sc->rxcycles <= 0)

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

1250nge_txeof(sc)
1251 struct nge_softc *sc;
1252{
1253 struct nge_desc *cur_tx;
1254 struct ifnet *ifp;
1255 u_int32_t idx;
1256
1257 NGE_LOCK_ASSERT(sc);
1250 ifp = &sc->arpcom.ac_if;
1258 ifp = sc->nge_ifp;
1251
1252 /*
1253 * Go through our tx list and free mbufs for those
1254 * frames that have been transmitted.
1255 */
1256 idx = sc->nge_cdata.nge_tx_cons;
1257 while (idx != sc->nge_cdata.nge_tx_prod) {
1258 cur_tx = &sc->nge_ldata->nge_tx_list[idx];

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

1312static void
1313nge_tick_locked(sc)
1314 struct nge_softc *sc;
1315{
1316 struct mii_data *mii;
1317 struct ifnet *ifp;
1318
1319 NGE_LOCK_ASSERT(sc);
1259
1260 /*
1261 * Go through our tx list and free mbufs for those
1262 * frames that have been transmitted.
1263 */
1264 idx = sc->nge_cdata.nge_tx_cons;
1265 while (idx != sc->nge_cdata.nge_tx_prod) {
1266 cur_tx = &sc->nge_ldata->nge_tx_list[idx];

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

1320static void
1321nge_tick_locked(sc)
1322 struct nge_softc *sc;
1323{
1324 struct mii_data *mii;
1325 struct ifnet *ifp;
1326
1327 NGE_LOCK_ASSERT(sc);
1320 ifp = &sc->arpcom.ac_if;
1328 ifp = sc->nge_ifp;
1321
1322 if (sc->nge_tbi) {
1323 if (!sc->nge_link) {
1324 if (CSR_READ_4(sc, NGE_TBI_BMSR)
1325 & NGE_TBIBMSR_ANEG_DONE) {
1326 if (bootverbose)
1327 printf("nge%d: gigabit link up\n",
1328 sc->nge_unit);

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

1411nge_intr(arg)
1412 void *arg;
1413{
1414 struct nge_softc *sc;
1415 struct ifnet *ifp;
1416 u_int32_t status;
1417
1418 sc = arg;
1329
1330 if (sc->nge_tbi) {
1331 if (!sc->nge_link) {
1332 if (CSR_READ_4(sc, NGE_TBI_BMSR)
1333 & NGE_TBIBMSR_ANEG_DONE) {
1334 if (bootverbose)
1335 printf("nge%d: gigabit link up\n",
1336 sc->nge_unit);

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

1419nge_intr(arg)
1420 void *arg;
1421{
1422 struct nge_softc *sc;
1423 struct ifnet *ifp;
1424 u_int32_t status;
1425
1426 sc = arg;
1419 ifp = &sc->arpcom.ac_if;
1427 ifp = sc->nge_ifp;
1420
1421 NGE_LOCK(sc);
1422#ifdef DEVICE_POLLING
1423 if (ifp->if_flags & IFF_POLLING) {
1424 NGE_UNLOCK(sc);
1425 return;
1426 }
1427 if ((ifp->if_capenable & IFCAP_POLLING) &&

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

1558 if (m_head->m_pkthdr.csum_flags & CSUM_TCP)
1559 sc->nge_ldata->nge_tx_list[*txidx].nge_extsts |=
1560 NGE_TXEXTSTS_TCPCSUM;
1561 if (m_head->m_pkthdr.csum_flags & CSUM_UDP)
1562 sc->nge_ldata->nge_tx_list[*txidx].nge_extsts |=
1563 NGE_TXEXTSTS_UDPCSUM;
1564 }
1565
1428
1429 NGE_LOCK(sc);
1430#ifdef DEVICE_POLLING
1431 if (ifp->if_flags & IFF_POLLING) {
1432 NGE_UNLOCK(sc);
1433 return;
1434 }
1435 if ((ifp->if_capenable & IFCAP_POLLING) &&

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

1566 if (m_head->m_pkthdr.csum_flags & CSUM_TCP)
1567 sc->nge_ldata->nge_tx_list[*txidx].nge_extsts |=
1568 NGE_TXEXTSTS_TCPCSUM;
1569 if (m_head->m_pkthdr.csum_flags & CSUM_UDP)
1570 sc->nge_ldata->nge_tx_list[*txidx].nge_extsts |=
1571 NGE_TXEXTSTS_UDPCSUM;
1572 }
1573
1566 mtag = VLAN_OUTPUT_TAG(&sc->arpcom.ac_if, m_head);
1574 mtag = VLAN_OUTPUT_TAG(sc->nge_ifp, m_head);
1567 if (mtag != NULL) {
1568 sc->nge_ldata->nge_tx_list[cur].nge_extsts |=
1569 (NGE_TXEXTSTS_VLANPKT|htons(VLAN_TAG_VALUE(mtag)));
1570 }
1571
1572 sc->nge_ldata->nge_tx_list[cur].nge_mbuf = m_head;
1573 sc->nge_ldata->nge_tx_list[cur].nge_ctl &= ~NGE_CMDSTS_MORE;
1574 sc->nge_ldata->nge_tx_list[*txidx].nge_ctl |= NGE_CMDSTS_OWN;

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

1656 nge_init_locked(sc);
1657 NGE_UNLOCK(sc);
1658}
1659
1660static void
1661nge_init_locked(sc)
1662 struct nge_softc *sc;
1663{
1575 if (mtag != NULL) {
1576 sc->nge_ldata->nge_tx_list[cur].nge_extsts |=
1577 (NGE_TXEXTSTS_VLANPKT|htons(VLAN_TAG_VALUE(mtag)));
1578 }
1579
1580 sc->nge_ldata->nge_tx_list[cur].nge_mbuf = m_head;
1581 sc->nge_ldata->nge_tx_list[cur].nge_ctl &= ~NGE_CMDSTS_MORE;
1582 sc->nge_ldata->nge_tx_list[*txidx].nge_ctl |= NGE_CMDSTS_OWN;

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

1664 nge_init_locked(sc);
1665 NGE_UNLOCK(sc);
1666}
1667
1668static void
1669nge_init_locked(sc)
1670 struct nge_softc *sc;
1671{
1664 struct ifnet *ifp = &sc->arpcom.ac_if;
1672 struct ifnet *ifp = sc->nge_ifp;
1665 struct mii_data *mii;
1666
1667 NGE_LOCK_ASSERT(sc);
1668
1669 if (ifp->if_flags & IFF_RUNNING)
1670 return;
1671
1672 /*

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

1678 mii = NULL;
1679 } else {
1680 mii = device_get_softc(sc->nge_miibus);
1681 }
1682
1683 /* Set MAC address */
1684 CSR_WRITE_4(sc, NGE_RXFILT_CTL, NGE_FILTADDR_PAR0);
1685 CSR_WRITE_4(sc, NGE_RXFILT_DATA,
1673 struct mii_data *mii;
1674
1675 NGE_LOCK_ASSERT(sc);
1676
1677 if (ifp->if_flags & IFF_RUNNING)
1678 return;
1679
1680 /*

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

1686 mii = NULL;
1687 } else {
1688 mii = device_get_softc(sc->nge_miibus);
1689 }
1690
1691 /* Set MAC address */
1692 CSR_WRITE_4(sc, NGE_RXFILT_CTL, NGE_FILTADDR_PAR0);
1693 CSR_WRITE_4(sc, NGE_RXFILT_DATA,
1686 ((u_int16_t *)sc->arpcom.ac_enaddr)[0]);
1694 ((u_int16_t *)IFP2ENADDR(sc->nge_ifp))[0]);
1687 CSR_WRITE_4(sc, NGE_RXFILT_CTL, NGE_FILTADDR_PAR1);
1688 CSR_WRITE_4(sc, NGE_RXFILT_DATA,
1695 CSR_WRITE_4(sc, NGE_RXFILT_CTL, NGE_FILTADDR_PAR1);
1696 CSR_WRITE_4(sc, NGE_RXFILT_DATA,
1689 ((u_int16_t *)sc->arpcom.ac_enaddr)[1]);
1697 ((u_int16_t *)IFP2ENADDR(sc->nge_ifp))[1]);
1690 CSR_WRITE_4(sc, NGE_RXFILT_CTL, NGE_FILTADDR_PAR2);
1691 CSR_WRITE_4(sc, NGE_RXFILT_DATA,
1698 CSR_WRITE_4(sc, NGE_RXFILT_CTL, NGE_FILTADDR_PAR2);
1699 CSR_WRITE_4(sc, NGE_RXFILT_DATA,
1692 ((u_int16_t *)sc->arpcom.ac_enaddr)[2]);
1700 ((u_int16_t *)IFP2ENADDR(sc->nge_ifp))[2]);
1693
1694 /* Init circular RX list. */
1695 if (nge_list_rx_init(sc) == ENOBUFS) {
1696 printf("nge%d: initialization failed: no "
1697 "memory for rx buffers\n", sc->nge_unit);
1698 nge_stop(sc);
1699 return;
1700 }

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

2078nge_stop(sc)
2079 struct nge_softc *sc;
2080{
2081 register int i;
2082 struct ifnet *ifp;
2083 struct mii_data *mii;
2084
2085 NGE_LOCK_ASSERT(sc);
1701
1702 /* Init circular RX list. */
1703 if (nge_list_rx_init(sc) == ENOBUFS) {
1704 printf("nge%d: initialization failed: no "
1705 "memory for rx buffers\n", sc->nge_unit);
1706 nge_stop(sc);
1707 return;
1708 }

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

2086nge_stop(sc)
2087 struct nge_softc *sc;
2088{
2089 register int i;
2090 struct ifnet *ifp;
2091 struct mii_data *mii;
2092
2093 NGE_LOCK_ASSERT(sc);
2086 ifp = &sc->arpcom.ac_if;
2094 ifp = sc->nge_ifp;
2087 ifp->if_timer = 0;
2088 if (sc->nge_tbi) {
2089 mii = NULL;
2090 } else {
2091 mii = device_get_softc(sc->nge_miibus);
2092 }
2093
2094 callout_stop(&sc->nge_stat_ch);

--- 64 unchanged lines hidden ---
2095 ifp->if_timer = 0;
2096 if (sc->nge_tbi) {
2097 mii = NULL;
2098 } else {
2099 mii = device_get_softc(sc->nge_miibus);
2100 }
2101
2102 callout_stop(&sc->nge_stat_ch);

--- 64 unchanged lines hidden ---