if_vr.c (155671) | if_vr.c (162315) |
---|---|
1/*- 2 * Copyright (c) 1997, 1998 3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 1997, 1998 3 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 17 unchanged lines hidden (view full) --- 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 30 * THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/dev/vr/if_vr.c 155671 2006-02-14 12:44:56Z glebius $"); | 34__FBSDID("$FreeBSD: head/sys/dev/vr/if_vr.c 162315 2006-09-15 10:40:54Z glebius $"); |
35 36/* 37 * VIA Rhine fast ethernet PCI NIC driver 38 * 39 * Supports various network adapters based on the VIA Rhine 40 * and Rhine II PCI controllers, including the D-Link DFE530TX. 41 * Datasheets are available at http://www.via.com.tw. 42 * --- 555 unchanged lines hidden (view full) --- 598 599 for (i = 0; i < VR_TIMEOUT; i++) { 600 DELAY(10); 601 if (!(CSR_READ_2(sc, VR_COMMAND) & VR_CMD_RESET)) 602 break; 603 } 604 if (i == VR_TIMEOUT) { 605 if (sc->vr_revid < REV_ID_VT3065_A) | 35 36/* 37 * VIA Rhine fast ethernet PCI NIC driver 38 * 39 * Supports various network adapters based on the VIA Rhine 40 * and Rhine II PCI controllers, including the D-Link DFE530TX. 41 * Datasheets are available at http://www.via.com.tw. 42 * --- 555 unchanged lines hidden (view full) --- 598 599 for (i = 0; i < VR_TIMEOUT; i++) { 600 DELAY(10); 601 if (!(CSR_READ_2(sc, VR_COMMAND) & VR_CMD_RESET)) 602 break; 603 } 604 if (i == VR_TIMEOUT) { 605 if (sc->vr_revid < REV_ID_VT3065_A) |
606 if_printf(sc->vr_ifp, "reset never completed!\n"); | 606 device_printf(sc->vr_dev, "reset never completed!\n"); |
607 else { 608 /* Use newer force reset command */ | 607 else { 608 /* Use newer force reset command */ |
609 if_printf(sc->vr_ifp, "Using force reset command.\n"); | 609 device_printf(sc->vr_dev, "Using force reset command.\n"); |
610 VR_SETBIT(sc, VR_MISC_CR1, VR_MISCCR1_FORSRST); 611 } 612 } 613 614 /* Wait a little while for the chip to get its brains in order. */ 615 DELAY(1000); 616} 617 --- 28 unchanged lines hidden (view full) --- 646{ 647 int i; 648 u_char eaddr[ETHER_ADDR_LEN]; 649 struct vr_softc *sc; 650 struct ifnet *ifp; 651 int unit, error = 0, rid; 652 653 sc = device_get_softc(dev); | 610 VR_SETBIT(sc, VR_MISC_CR1, VR_MISCCR1_FORSRST); 611 } 612 } 613 614 /* Wait a little while for the chip to get its brains in order. */ 615 DELAY(1000); 616} 617 --- 28 unchanged lines hidden (view full) --- 646{ 647 int i; 648 u_char eaddr[ETHER_ADDR_LEN]; 649 struct vr_softc *sc; 650 struct ifnet *ifp; 651 int unit, error = 0, rid; 652 653 sc = device_get_softc(dev); |
654 sc->vr_dev = dev; |
|
654 unit = device_get_unit(dev); 655 656 mtx_init(&sc->vr_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, 657 MTX_DEF); 658 callout_init_mtx(&sc->vr_stat_callout, &sc->vr_mtx, 0); 659 660 /* 661 * Map control/status registers. --- 306 unchanged lines hidden (view full) --- 968 /* 969 * If an error occurs, update stats, clear the 970 * status word and leave the mbuf cluster in place: 971 * it should simply get re-used next time this descriptor 972 * comes up in the ring. 973 */ 974 if (rxstat & VR_RXSTAT_RXERR) { 975 ifp->if_ierrors++; | 655 unit = device_get_unit(dev); 656 657 mtx_init(&sc->vr_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK, 658 MTX_DEF); 659 callout_init_mtx(&sc->vr_stat_callout, &sc->vr_mtx, 0); 660 661 /* 662 * Map control/status registers. --- 306 unchanged lines hidden (view full) --- 969 /* 970 * If an error occurs, update stats, clear the 971 * status word and leave the mbuf cluster in place: 972 * it should simply get re-used next time this descriptor 973 * comes up in the ring. 974 */ 975 if (rxstat & VR_RXSTAT_RXERR) { 976 ifp->if_ierrors++; |
976 if_printf(ifp, "rx error (%02x):", rxstat & 0x000000ff); | 977 device_printf(sc->vr_dev, 978 "rx error (%02x):", rxstat & 0x000000ff); |
977 if (rxstat & VR_RXSTAT_CRCERR) 978 printf(" crc error"); 979 if (rxstat & VR_RXSTAT_FRAMEALIGNERR) 980 printf(" frame alignment error\n"); 981 if (rxstat & VR_RXSTAT_FIFOOFLOW) 982 printf(" FIFO overflow"); 983 if (rxstat & VR_RXSTAT_GIANT) 984 printf(" received giant packet"); --- 52 unchanged lines hidden (view full) --- 1037 /* Wait for receiver to stop */ 1038 for (i = 0x400; 1039 i && (CSR_READ_2(sc, VR_COMMAND) & VR_CMD_RX_ON); 1040 i--) { 1041 ; 1042 } 1043 1044 if (!i) { | 979 if (rxstat & VR_RXSTAT_CRCERR) 980 printf(" crc error"); 981 if (rxstat & VR_RXSTAT_FRAMEALIGNERR) 982 printf(" frame alignment error\n"); 983 if (rxstat & VR_RXSTAT_FIFOOFLOW) 984 printf(" FIFO overflow"); 985 if (rxstat & VR_RXSTAT_GIANT) 986 printf(" received giant packet"); --- 52 unchanged lines hidden (view full) --- 1039 /* Wait for receiver to stop */ 1040 for (i = 0x400; 1041 i && (CSR_READ_2(sc, VR_COMMAND) & VR_CMD_RX_ON); 1042 i--) { 1043 ; 1044 } 1045 1046 if (!i) { |
1045 if_printf(ifp, "rx shutdown error!\n"); | 1047 device_printf(sc->vr_dev, "rx shutdown error!\n"); |
1046 sc->vr_flags |= VR_F_RESTART; 1047 return; 1048 } 1049 1050 vr_rxeof(sc); 1051 1052 CSR_WRITE_4(sc, VR_RXADDR, vtophys(sc->vr_cdata.vr_rx_head->vr_ptr)); 1053 VR_SETBIT16(sc, VR_COMMAND, VR_CMD_RX_ON); --- 25 unchanged lines hidden (view full) --- 1079 1080 if ((txstat & VR_TXSTAT_ABRT) || 1081 (txstat & VR_TXSTAT_UDF)) { 1082 for (i = 0x400; 1083 i && (CSR_READ_2(sc, VR_COMMAND) & VR_CMD_TX_ON); 1084 i--) 1085 ; /* Wait for chip to shutdown */ 1086 if (!i) { | 1048 sc->vr_flags |= VR_F_RESTART; 1049 return; 1050 } 1051 1052 vr_rxeof(sc); 1053 1054 CSR_WRITE_4(sc, VR_RXADDR, vtophys(sc->vr_cdata.vr_rx_head->vr_ptr)); 1055 VR_SETBIT16(sc, VR_COMMAND, VR_CMD_RX_ON); --- 25 unchanged lines hidden (view full) --- 1081 1082 if ((txstat & VR_TXSTAT_ABRT) || 1083 (txstat & VR_TXSTAT_UDF)) { 1084 for (i = 0x400; 1085 i && (CSR_READ_2(sc, VR_COMMAND) & VR_CMD_TX_ON); 1086 i--) 1087 ; /* Wait for chip to shutdown */ 1088 if (!i) { |
1087 if_printf(ifp, "tx shutdown timeout\n"); | 1089 device_printf(sc->vr_dev, "tx shutdown timeout\n"); |
1088 sc->vr_flags |= VR_F_RESTART; 1089 break; 1090 } 1091 VR_TXOWN(cur_tx) = VR_TXSTAT_OWN; 1092 CSR_WRITE_4(sc, VR_TXADDR, vtophys(cur_tx->vr_ptr)); 1093 break; 1094 } 1095 --- 26 unchanged lines hidden (view full) --- 1122vr_tick(void *xsc) 1123{ 1124 struct vr_softc *sc = xsc; 1125 struct mii_data *mii; 1126 1127 VR_LOCK_ASSERT(sc); 1128 1129 if (sc->vr_flags & VR_F_RESTART) { | 1090 sc->vr_flags |= VR_F_RESTART; 1091 break; 1092 } 1093 VR_TXOWN(cur_tx) = VR_TXSTAT_OWN; 1094 CSR_WRITE_4(sc, VR_TXADDR, vtophys(cur_tx->vr_ptr)); 1095 break; 1096 } 1097 --- 26 unchanged lines hidden (view full) --- 1124vr_tick(void *xsc) 1125{ 1126 struct vr_softc *sc = xsc; 1127 struct mii_data *mii; 1128 1129 VR_LOCK_ASSERT(sc); 1130 1131 if (sc->vr_flags & VR_F_RESTART) { |
1130 if_printf(sc->vr_ifp, "restarting\n"); | 1132 device_printf(sc->vr_dev, "restarting\n"); |
1131 vr_stop(sc); 1132 vr_reset(sc); 1133 vr_init_locked(sc); 1134 sc->vr_flags &= ~VR_F_RESTART; 1135 } 1136 1137 mii = device_get_softc(sc->vr_miibus); 1138 mii_tick(mii); --- 117 unchanged lines hidden (view full) --- 1256 1257 if ((status & VR_INTRS) == 0) 1258 break; 1259 1260 if (status & VR_ISR_RX_OK) 1261 vr_rxeof(sc); 1262 1263 if (status & VR_ISR_RX_DROPPED) { | 1133 vr_stop(sc); 1134 vr_reset(sc); 1135 vr_init_locked(sc); 1136 sc->vr_flags &= ~VR_F_RESTART; 1137 } 1138 1139 mii = device_get_softc(sc->vr_miibus); 1140 mii_tick(mii); --- 117 unchanged lines hidden (view full) --- 1258 1259 if ((status & VR_INTRS) == 0) 1260 break; 1261 1262 if (status & VR_ISR_RX_OK) 1263 vr_rxeof(sc); 1264 1265 if (status & VR_ISR_RX_DROPPED) { |
1264 if_printf(ifp, "rx packet lost\n"); | 1266 device_printf(sc->vr_dev, "rx packet lost\n"); |
1265 ifp->if_ierrors++; 1266 } 1267 1268 if ((status & VR_ISR_RX_ERR) || (status & VR_ISR_RX_NOBUF) || 1269 (status & VR_ISR_RX_NOBUF) || (status & VR_ISR_RX_OFLOW)) { | 1267 ifp->if_ierrors++; 1268 } 1269 1270 if ((status & VR_ISR_RX_ERR) || (status & VR_ISR_RX_NOBUF) || 1271 (status & VR_ISR_RX_NOBUF) || (status & VR_ISR_RX_OFLOW)) { |
1270 if_printf(ifp, "receive error (%04x)", status); | 1272 device_printf(sc->vr_dev, "receive error (%04x)", status); |
1271 if (status & VR_ISR_RX_NOBUF) 1272 printf(" no buffers"); 1273 if (status & VR_ISR_RX_OFLOW) 1274 printf(" overflow"); 1275 if (status & VR_ISR_RX_DROPPED) 1276 printf(" packet lost"); 1277 printf("\n"); 1278 vr_rxeoc(sc); --- 185 unchanged lines hidden (view full) --- 1464 VR_CLRBIT(sc, VR_RXCFG, VR_RXCFG_RX_THRESH); 1465 VR_SETBIT(sc, VR_RXCFG, VR_RXTHRESH_128BYTES); 1466 1467 VR_CLRBIT(sc, VR_TXCFG, VR_TXCFG_TX_THRESH); 1468 VR_SETBIT(sc, VR_TXCFG, VR_TXTHRESH_STORENFWD); 1469 1470 /* Init circular RX list. */ 1471 if (vr_list_rx_init(sc) == ENOBUFS) { | 1273 if (status & VR_ISR_RX_NOBUF) 1274 printf(" no buffers"); 1275 if (status & VR_ISR_RX_OFLOW) 1276 printf(" overflow"); 1277 if (status & VR_ISR_RX_DROPPED) 1278 printf(" packet lost"); 1279 printf("\n"); 1280 vr_rxeoc(sc); --- 185 unchanged lines hidden (view full) --- 1466 VR_CLRBIT(sc, VR_RXCFG, VR_RXCFG_RX_THRESH); 1467 VR_SETBIT(sc, VR_RXCFG, VR_RXTHRESH_128BYTES); 1468 1469 VR_CLRBIT(sc, VR_TXCFG, VR_TXCFG_TX_THRESH); 1470 VR_SETBIT(sc, VR_TXCFG, VR_TXTHRESH_STORENFWD); 1471 1472 /* Init circular RX list. */ 1473 if (vr_list_rx_init(sc) == ENOBUFS) { |
1472 if_printf(ifp, | 1474 device_printf(sc->vr_dev, |
1473 "initialization failed: no memory for rx buffers\n"); 1474 vr_stop(sc); 1475 return; 1476 } 1477 1478 /* Init tx descriptors. */ 1479 vr_list_tx_init(sc); 1480 --- 228 unchanged lines hidden --- | 1475 "initialization failed: no memory for rx buffers\n"); 1476 vr_stop(sc); 1477 return; 1478 } 1479 1480 /* Init tx descriptors. */ 1481 vr_list_tx_init(sc); 1482 --- 228 unchanged lines hidden --- |