if_nfe.c (170595) | if_nfe.c (171559) |
---|---|
1/* $OpenBSD: if_nfe.c,v 1.54 2006/04/07 12:38:12 jsg Exp $ */ 2 3/*- 4 * Copyright (c) 2006 Shigeaki Tagashira <shigeaki@se.hiroshima-u.ac.jp> 5 * Copyright (c) 2006 Damien Bergamini <damien.bergamini@free.fr> 6 * Copyright (c) 2005, 2006 Jonathan Gray <jsg@openbsd.org> 7 * 8 * Permission to use, copy, modify, and distribute this software for any --- 7 unchanged lines hidden (view full) --- 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 */ 20 21/* Driver for NVIDIA nForce MCP Fast Ethernet and Gigabit Ethernet */ 22 23#include <sys/cdefs.h> | 1/* $OpenBSD: if_nfe.c,v 1.54 2006/04/07 12:38:12 jsg Exp $ */ 2 3/*- 4 * Copyright (c) 2006 Shigeaki Tagashira <shigeaki@se.hiroshima-u.ac.jp> 5 * Copyright (c) 2006 Damien Bergamini <damien.bergamini@free.fr> 6 * Copyright (c) 2005, 2006 Jonathan Gray <jsg@openbsd.org> 7 * 8 * Permission to use, copy, modify, and distribute this software for any --- 7 unchanged lines hidden (view full) --- 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 */ 20 21/* Driver for NVIDIA nForce MCP Fast Ethernet and Gigabit Ethernet */ 22 23#include <sys/cdefs.h> |
24__FBSDID("$FreeBSD: head/sys/dev/nfe/if_nfe.c 170595 2007-06-12 02:35:01Z yongari $"); | 24__FBSDID("$FreeBSD: head/sys/dev/nfe/if_nfe.c 171559 2007-07-24 01:11:00Z yongari $"); |
25 26#ifdef HAVE_KERNEL_OPTION_HEADERS 27#include "opt_device_polling.h" 28#endif 29 30#include <sys/param.h> 31#include <sys/endian.h> 32#include <sys/systm.h> --- 70 unchanged lines hidden (view full) --- 103static void nfe_setmulti(struct nfe_softc *); 104static void nfe_tx_task(void *, int); 105static void nfe_start(struct ifnet *); 106static void nfe_watchdog(struct ifnet *); 107static void nfe_init(void *); 108static void nfe_init_locked(void *); 109static void nfe_stop(struct ifnet *); 110static int nfe_alloc_rx_ring(struct nfe_softc *, struct nfe_rx_ring *); | 25 26#ifdef HAVE_KERNEL_OPTION_HEADERS 27#include "opt_device_polling.h" 28#endif 29 30#include <sys/param.h> 31#include <sys/endian.h> 32#include <sys/systm.h> --- 70 unchanged lines hidden (view full) --- 103static void nfe_setmulti(struct nfe_softc *); 104static void nfe_tx_task(void *, int); 105static void nfe_start(struct ifnet *); 106static void nfe_watchdog(struct ifnet *); 107static void nfe_init(void *); 108static void nfe_init_locked(void *); 109static void nfe_stop(struct ifnet *); 110static int nfe_alloc_rx_ring(struct nfe_softc *, struct nfe_rx_ring *); |
111static int nfe_alloc_jrx_ring(struct nfe_softc *, struct nfe_jrx_ring *); | 111static void nfe_alloc_jrx_ring(struct nfe_softc *, struct nfe_jrx_ring *); |
112static int nfe_init_rx_ring(struct nfe_softc *, struct nfe_rx_ring *); 113static int nfe_init_jrx_ring(struct nfe_softc *, struct nfe_jrx_ring *); 114static void nfe_free_rx_ring(struct nfe_softc *, struct nfe_rx_ring *); 115static void nfe_free_jrx_ring(struct nfe_softc *, struct nfe_jrx_ring *); 116static int nfe_alloc_tx_ring(struct nfe_softc *, struct nfe_tx_ring *); 117static void nfe_init_tx_ring(struct nfe_softc *, struct nfe_tx_ring *); 118static void nfe_free_tx_ring(struct nfe_softc *, struct nfe_tx_ring *); 119static int nfe_ifmedia_upd(struct ifnet *); --- 26 unchanged lines hidden (view full) --- 146#define NFE_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->nfe_mtx, MA_OWNED) 147 148#define NFE_JLIST_LOCK(_sc) mtx_lock(&(_sc)->nfe_jlist_mtx) 149#define NFE_JLIST_UNLOCK(_sc) mtx_unlock(&(_sc)->nfe_jlist_mtx) 150 151/* Tunables. */ 152static int msi_disable = 0; 153static int msix_disable = 0; | 112static int nfe_init_rx_ring(struct nfe_softc *, struct nfe_rx_ring *); 113static int nfe_init_jrx_ring(struct nfe_softc *, struct nfe_jrx_ring *); 114static void nfe_free_rx_ring(struct nfe_softc *, struct nfe_rx_ring *); 115static void nfe_free_jrx_ring(struct nfe_softc *, struct nfe_jrx_ring *); 116static int nfe_alloc_tx_ring(struct nfe_softc *, struct nfe_tx_ring *); 117static void nfe_init_tx_ring(struct nfe_softc *, struct nfe_tx_ring *); 118static void nfe_free_tx_ring(struct nfe_softc *, struct nfe_tx_ring *); 119static int nfe_ifmedia_upd(struct ifnet *); --- 26 unchanged lines hidden (view full) --- 146#define NFE_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->nfe_mtx, MA_OWNED) 147 148#define NFE_JLIST_LOCK(_sc) mtx_lock(&(_sc)->nfe_jlist_mtx) 149#define NFE_JLIST_UNLOCK(_sc) mtx_unlock(&(_sc)->nfe_jlist_mtx) 150 151/* Tunables. */ 152static int msi_disable = 0; 153static int msix_disable = 0; |
154static int jumbo_disable = 0; |
|
154TUNABLE_INT("hw.nfe.msi_disable", &msi_disable); 155TUNABLE_INT("hw.nfe.msix_disable", &msix_disable); | 155TUNABLE_INT("hw.nfe.msi_disable", &msi_disable); 156TUNABLE_INT("hw.nfe.msix_disable", &msix_disable); |
157TUNABLE_INT("hw.nfe.jumbo_disable", &jumbo_disable); |
|
156 157static device_method_t nfe_methods[] = { 158 /* Device interface */ 159 DEVMETHOD(device_probe, nfe_probe), 160 DEVMETHOD(device_attach, nfe_attach), 161 DEVMETHOD(device_detach, nfe_detach), 162 DEVMETHOD(device_suspend, nfe_suspend), 163 DEVMETHOD(device_resume, nfe_resume), --- 344 unchanged lines hidden (view full) --- 508 * Allocate Tx and Rx rings. 509 */ 510 if ((error = nfe_alloc_tx_ring(sc, &sc->txq)) != 0) 511 goto fail; 512 513 if ((error = nfe_alloc_rx_ring(sc, &sc->rxq)) != 0) 514 goto fail; 515 | 158 159static device_method_t nfe_methods[] = { 160 /* Device interface */ 161 DEVMETHOD(device_probe, nfe_probe), 162 DEVMETHOD(device_attach, nfe_attach), 163 DEVMETHOD(device_detach, nfe_detach), 164 DEVMETHOD(device_suspend, nfe_suspend), 165 DEVMETHOD(device_resume, nfe_resume), --- 344 unchanged lines hidden (view full) --- 510 * Allocate Tx and Rx rings. 511 */ 512 if ((error = nfe_alloc_tx_ring(sc, &sc->txq)) != 0) 513 goto fail; 514 515 if ((error = nfe_alloc_rx_ring(sc, &sc->rxq)) != 0) 516 goto fail; 517 |
516 if ((error = nfe_alloc_jrx_ring(sc, &sc->jrxq)) != 0) 517 goto fail; | 518 nfe_alloc_jrx_ring(sc, &sc->jrxq); |
518 519 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 520 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 521 OID_AUTO, "process_limit", CTLTYPE_INT | CTLFLAG_RW, 522 &sc->nfe_process_limit, 0, sysctl_hw_nfe_proc_limit, "I", 523 "max number of Rx events to process"); 524 525 sc->nfe_process_limit = NFE_PROC_DEFAULT; --- 609 unchanged lines hidden (view full) --- 1135 } 1136 } 1137 1138fail: 1139 return (error); 1140} 1141 1142 | 519 520 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev), 521 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), 522 OID_AUTO, "process_limit", CTLTYPE_INT | CTLFLAG_RW, 523 &sc->nfe_process_limit, 0, sysctl_hw_nfe_proc_limit, "I", 524 "max number of Rx events to process"); 525 526 sc->nfe_process_limit = NFE_PROC_DEFAULT; --- 609 unchanged lines hidden (view full) --- 1136 } 1137 } 1138 1139fail: 1140 return (error); 1141} 1142 1143 |
1143static int | 1144static void |
1144nfe_alloc_jrx_ring(struct nfe_softc *sc, struct nfe_jrx_ring *ring) 1145{ 1146 struct nfe_dmamap_arg ctx; 1147 struct nfe_rx_data *data; 1148 void *desc; 1149 struct nfe_jpool_entry *entry; 1150 uint8_t *ptr; 1151 int i, error, descsize; 1152 1153 if ((sc->nfe_flags & NFE_JUMBO_SUP) == 0) | 1145nfe_alloc_jrx_ring(struct nfe_softc *sc, struct nfe_jrx_ring *ring) 1146{ 1147 struct nfe_dmamap_arg ctx; 1148 struct nfe_rx_data *data; 1149 void *desc; 1150 struct nfe_jpool_entry *entry; 1151 uint8_t *ptr; 1152 int i, error, descsize; 1153 1154 if ((sc->nfe_flags & NFE_JUMBO_SUP) == 0) |
1154 return (0); | 1155 return; 1156 if (jumbo_disable != 0) { 1157 device_printf(sc->nfe_dev, "disabling jumbo frame support\n"); 1158 sc->nfe_jumbo_disable = 1; 1159 return; 1160 } |
1155 1156 if (sc->nfe_flags & NFE_40BIT_ADDR) { 1157 desc = ring->jdesc64; 1158 descsize = sizeof (struct nfe_desc64); 1159 } else { 1160 desc = ring->jdesc32; 1161 descsize = sizeof (struct nfe_desc32); 1162 } --- 133 unchanged lines hidden (view full) --- 1296 error = ENOMEM; 1297 goto fail; 1298 } 1299 entry->slot = i; 1300 SLIST_INSERT_HEAD(&sc->nfe_jfree_listhead, entry, 1301 jpool_entries); 1302 } 1303 | 1161 1162 if (sc->nfe_flags & NFE_40BIT_ADDR) { 1163 desc = ring->jdesc64; 1164 descsize = sizeof (struct nfe_desc64); 1165 } else { 1166 desc = ring->jdesc32; 1167 descsize = sizeof (struct nfe_desc32); 1168 } --- 133 unchanged lines hidden (view full) --- 1302 error = ENOMEM; 1303 goto fail; 1304 } 1305 entry->slot = i; 1306 SLIST_INSERT_HEAD(&sc->nfe_jfree_listhead, entry, 1307 jpool_entries); 1308 } 1309 |
1304 return (0); | 1310 return; |
1305 1306fail: | 1311 1312fail: |
1313 /* 1314 * Running without jumbo frame support is ok for most cases 1315 * so don't fail on creating dma tag/map for jumbo frame. 1316 */ |
|
1307 nfe_free_jrx_ring(sc, ring); | 1317 nfe_free_jrx_ring(sc, ring); |
1308 return (error); | 1318 device_printf(sc->nfe_dev, "disabling jumbo frame support due to " 1319 "resource shortage\n"); 1320 sc->nfe_jumbo_disable = 1; |
1309} 1310 1311 1312static int 1313nfe_init_rx_ring(struct nfe_softc *sc, struct nfe_rx_ring *ring) 1314{ 1315 void *desc; 1316 size_t descsize; --- 349 unchanged lines hidden (view full) --- 1666 1667 NFE_LOCK(sc); 1668 1669 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { 1670 NFE_UNLOCK(sc); 1671 return; 1672 } 1673 | 1321} 1322 1323 1324static int 1325nfe_init_rx_ring(struct nfe_softc *sc, struct nfe_rx_ring *ring) 1326{ 1327 void *desc; 1328 size_t descsize; --- 349 unchanged lines hidden (view full) --- 1678 1679 NFE_LOCK(sc); 1680 1681 if (!(ifp->if_drv_flags & IFF_DRV_RUNNING)) { 1682 NFE_UNLOCK(sc); 1683 return; 1684 } 1685 |
1674 nfe_rxeof(sc, count); | 1686 if (sc->nfe_framesize > MCLBYTES - ETHER_HDR_LEN) 1687 nfe_jrxeof(sc, count); 1688 else 1689 nfe_rxeof(sc, count); |
1675 nfe_txeof(sc); 1676 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) 1677 taskqueue_enqueue_fast(taskqueue_fast, &sc->nfe_tx_task); 1678 1679 if (cmd == POLL_AND_CHECK_STATUS) { 1680 if ((r = NFE_READ(sc, sc->nfe_irq_status)) == 0) { 1681 NFE_UNLOCK(sc); 1682 return; --- 58 unchanged lines hidden (view full) --- 1741 ifr = (struct ifreq *) data; 1742 error = 0; 1743 init = 0; 1744 switch (cmd) { 1745 case SIOCSIFMTU: 1746 if (ifr->ifr_mtu < ETHERMIN || ifr->ifr_mtu > NFE_JUMBO_MTU) 1747 error = EINVAL; 1748 else if (ifp->if_mtu != ifr->ifr_mtu) { | 1690 nfe_txeof(sc); 1691 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) 1692 taskqueue_enqueue_fast(taskqueue_fast, &sc->nfe_tx_task); 1693 1694 if (cmd == POLL_AND_CHECK_STATUS) { 1695 if ((r = NFE_READ(sc, sc->nfe_irq_status)) == 0) { 1696 NFE_UNLOCK(sc); 1697 return; --- 58 unchanged lines hidden (view full) --- 1756 ifr = (struct ifreq *) data; 1757 error = 0; 1758 init = 0; 1759 switch (cmd) { 1760 case SIOCSIFMTU: 1761 if (ifr->ifr_mtu < ETHERMIN || ifr->ifr_mtu > NFE_JUMBO_MTU) 1762 error = EINVAL; 1763 else if (ifp->if_mtu != ifr->ifr_mtu) { |
1749 if ((sc->nfe_flags & NFE_JUMBO_SUP) == 0 && | 1764 if ((((sc->nfe_flags & NFE_JUMBO_SUP) == 0) || 1765 (sc->nfe_jumbo_disable != 0)) && |
1750 ifr->ifr_mtu > ETHERMTU) 1751 error = EINVAL; 1752 else { 1753 NFE_LOCK(sc); 1754 ifp->if_mtu = ifr->ifr_mtu; 1755 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) 1756 nfe_init_locked(sc); 1757 NFE_UNLOCK(sc); --- 1445 unchanged lines hidden --- | 1766 ifr->ifr_mtu > ETHERMTU) 1767 error = EINVAL; 1768 else { 1769 NFE_LOCK(sc); 1770 ifp->if_mtu = ifr->ifr_mtu; 1771 if ((ifp->if_drv_flags & IFF_DRV_RUNNING) != 0) 1772 nfe_init_locked(sc); 1773 NFE_UNLOCK(sc); --- 1445 unchanged lines hidden --- |