if_sf.c (81714) | if_sf.c (81737) |
---|---|
1/* 2 * Copyright (c) 1997, 1998, 1999 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 --- 15 unchanged lines hidden (view full) --- 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 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 * | 1/* 2 * Copyright (c) 1997, 1998, 1999 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 --- 15 unchanged lines hidden (view full) --- 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 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 * $FreeBSD: head/sys/dev/sf/if_sf.c 81714 2001-08-15 17:46:57Z wpaul $ | 32 * $FreeBSD: head/sys/dev/sf/if_sf.c 81737 2001-08-16 00:32:20Z wpaul $ |
33 */ 34 35/* 36 * Adaptec AIC-6915 "Starfire" PCI fast ethernet driver for FreeBSD. 37 * Programming manual is available from: 38 * ftp.adaptec.com:/pub/BBS/userguides/aic6915_pg.pdf. 39 * 40 * Written by Bill Paul <wpaul@ctr.columbia.edu> --- 75 unchanged lines hidden (view full) --- 116#define SF_USEIOSPACE 117 118#include <pci/if_sfreg.h> 119 120MODULE_DEPEND(sf, miibus, 1, 1, 1); 121 122#ifndef lint 123static const char rcsid[] = | 33 */ 34 35/* 36 * Adaptec AIC-6915 "Starfire" PCI fast ethernet driver for FreeBSD. 37 * Programming manual is available from: 38 * ftp.adaptec.com:/pub/BBS/userguides/aic6915_pg.pdf. 39 * 40 * Written by Bill Paul <wpaul@ctr.columbia.edu> --- 75 unchanged lines hidden (view full) --- 116#define SF_USEIOSPACE 117 118#include <pci/if_sfreg.h> 119 120MODULE_DEPEND(sf, miibus, 1, 1, 1); 121 122#ifndef lint 123static const char rcsid[] = |
124 "$FreeBSD: head/sys/dev/sf/if_sf.c 81714 2001-08-15 17:46:57Z wpaul $"; | 124 "$FreeBSD: head/sys/dev/sf/if_sf.c 81737 2001-08-16 00:32:20Z wpaul $"; |
125#endif 126 127static struct sf_type sf_devs[] = { 128 { AD_VENDORID, AD_DEVICEID_STARFIRE, 129 "Adaptec AIC-6915 10/100BaseTX" }, 130 { 0, 0, NULL } 131}; 132 --- 32 unchanged lines hidden (view full) --- 165static u_int32_t sf_calchash __P((caddr_t)); 166 167static int sf_miibus_readreg __P((device_t, int, int)); 168static int sf_miibus_writereg __P((device_t, int, int, int)); 169static void sf_miibus_statchg __P((device_t)); 170 171static u_int32_t csr_read_4 __P((struct sf_softc *, int)); 172static void csr_write_4 __P((struct sf_softc *, int, u_int32_t)); | 125#endif 126 127static struct sf_type sf_devs[] = { 128 { AD_VENDORID, AD_DEVICEID_STARFIRE, 129 "Adaptec AIC-6915 10/100BaseTX" }, 130 { 0, 0, NULL } 131}; 132 --- 32 unchanged lines hidden (view full) --- 165static u_int32_t sf_calchash __P((caddr_t)); 166 167static int sf_miibus_readreg __P((device_t, int, int)); 168static int sf_miibus_writereg __P((device_t, int, int, int)); 169static void sf_miibus_statchg __P((device_t)); 170 171static u_int32_t csr_read_4 __P((struct sf_softc *, int)); 172static void csr_write_4 __P((struct sf_softc *, int, u_int32_t)); |
173static void sf_txthresh_adjust __P((struct sf_softc *)); |
|
173 174#ifdef SF_USEIOSPACE 175#define SF_RES SYS_RES_IOPORT 176#define SF_RID SF_PCI_LOIO 177#else 178#define SF_RES SYS_RES_MEMORY 179#define SF_RID SF_PCI_LOMEM 180#endif --- 853 unchanged lines hidden (view full) --- 1034 1035 txcons = csr_read_4(sc, SF_CQ_CONSIDX); 1036 cmpprodidx = SF_IDX_HI(csr_read_4(sc, SF_CQ_PRODIDX)); 1037 cmpconsidx = SF_IDX_HI(txcons); 1038 1039 while (cmpconsidx != cmpprodidx) { 1040 cur_cmp = &sc->sf_ldata->sf_tx_clist[cmpconsidx]; 1041 cur_tx = &sc->sf_ldata->sf_tx_dlist[cur_cmp->sf_index >> 7]; | 174 175#ifdef SF_USEIOSPACE 176#define SF_RES SYS_RES_IOPORT 177#define SF_RID SF_PCI_LOIO 178#else 179#define SF_RES SYS_RES_MEMORY 180#define SF_RID SF_PCI_LOMEM 181#endif --- 853 unchanged lines hidden (view full) --- 1035 1036 txcons = csr_read_4(sc, SF_CQ_CONSIDX); 1037 cmpprodidx = SF_IDX_HI(csr_read_4(sc, SF_CQ_PRODIDX)); 1038 cmpconsidx = SF_IDX_HI(txcons); 1039 1040 while (cmpconsidx != cmpprodidx) { 1041 cur_cmp = &sc->sf_ldata->sf_tx_clist[cmpconsidx]; 1042 cur_tx = &sc->sf_ldata->sf_tx_dlist[cur_cmp->sf_index >> 7]; |
1042 SF_INC(cmpconsidx, SF_TX_CLIST_CNT); | |
1043 1044 if (cur_cmp->sf_txstat & SF_TXSTAT_TX_OK) 1045 ifp->if_opackets++; | 1043 1044 if (cur_cmp->sf_txstat & SF_TXSTAT_TX_OK) 1045 ifp->if_opackets++; |
1046 else | 1046 else { 1047 if (cur_cmp->sf_txstat & SF_TXSTAT_TX_UNDERRUN) 1048 sf_txthresh_adjust(sc); |
1047 ifp->if_oerrors++; | 1049 ifp->if_oerrors++; |
1050 } |
|
1048 1049 sc->sf_tx_cnt--; 1050 if (cur_tx->sf_mbuf != NULL) { 1051 m_freem(cur_tx->sf_mbuf); 1052 cur_tx->sf_mbuf = NULL; | 1051 1052 sc->sf_tx_cnt--; 1053 if (cur_tx->sf_mbuf != NULL) { 1054 m_freem(cur_tx->sf_mbuf); 1055 cur_tx->sf_mbuf = NULL; |
1053 } | 1056 } else 1057 break; 1058 SF_INC(cmpconsidx, SF_TX_CLIST_CNT); |
1054 } 1055 1056 ifp->if_timer = 0; 1057 ifp->if_flags &= ~IFF_OACTIVE; 1058 1059 csr_write_4(sc, SF_CQ_CONSIDX, 1060 (txcons & ~SF_CQ_CONSIDX_TXQ) | 1061 ((cmpconsidx << 16) & 0xFFFF0000)); 1062 1063 return; 1064} 1065 | 1059 } 1060 1061 ifp->if_timer = 0; 1062 ifp->if_flags &= ~IFF_OACTIVE; 1063 1064 csr_write_4(sc, SF_CQ_CONSIDX, 1065 (txcons & ~SF_CQ_CONSIDX_TXQ) | 1066 ((cmpconsidx << 16) & 0xFFFF0000)); 1067 1068 return; 1069} 1070 |
1071static void sf_txthresh_adjust(sc) 1072 struct sf_softc *sc; 1073{ 1074 u_int32_t txfctl; 1075 u_int8_t txthresh; 1076 1077 txfctl = csr_read_4(sc, SF_TX_FRAMCTL); 1078 txthresh = txfctl & SF_TXFRMCTL_TXTHRESH; 1079 if (txthresh < 0xFF) { 1080 txthresh++; 1081 txfctl &= ~SF_TXFRMCTL_TXTHRESH; 1082 txfctl |= txthresh; 1083#ifdef DIAGNOSTIC 1084 printf("sf%d: tx underrun, increasing " 1085 "tx threshold to %d bytes\n", 1086 sc->sf_unit, txthresh * 4); 1087#endif 1088 csr_write_4(sc, SF_TX_FRAMCTL, txfctl); 1089 } 1090 1091 return; 1092} 1093 |
|
1066static void sf_intr(arg) 1067 void *arg; 1068{ 1069 struct sf_softc *sc; 1070 struct ifnet *ifp; 1071 u_int32_t status; 1072 1073 sc = arg; --- 17 unchanged lines hidden (view full) --- 1091 if (!(status & SF_INTRS)) 1092 break; 1093 1094 if (status & SF_ISR_RXDQ1_DMADONE) 1095 sf_rxeof(sc); 1096 1097 if (status & SF_ISR_TX_TXDONE || 1098 status & SF_ISR_TX_DMADONE || | 1094static void sf_intr(arg) 1095 void *arg; 1096{ 1097 struct sf_softc *sc; 1098 struct ifnet *ifp; 1099 u_int32_t status; 1100 1101 sc = arg; --- 17 unchanged lines hidden (view full) --- 1119 if (!(status & SF_INTRS)) 1120 break; 1121 1122 if (status & SF_ISR_RXDQ1_DMADONE) 1123 sf_rxeof(sc); 1124 1125 if (status & SF_ISR_TX_TXDONE || 1126 status & SF_ISR_TX_DMADONE || |
1099 status & SF_ISR_TX_QUEUEDONE || 1100 status & SF_ISR_TX_LOFIFO) | 1127 status & SF_ISR_TX_QUEUEDONE) |
1101 sf_txeof(sc); 1102 | 1128 sf_txeof(sc); 1129 |
1130 if (status & SF_ISR_TX_LOFIFO) 1131 sf_txthresh_adjust(sc); 1132 |
|
1103 if (status & SF_ISR_ABNORMALINTR) { 1104 if (status & SF_ISR_STATSOFLOW) { 1105 untimeout(sf_stats_update, sc, 1106 sc->sf_stat_ch); 1107 sf_stats_update(sc); 1108 } else 1109 sf_init(sc); 1110 } --- 202 unchanged lines hidden (view full) --- 1313 return; 1314 } 1315 1316 if (ifp->if_flags & IFF_OACTIVE) { 1317 SF_UNLOCK(sc); 1318 return; 1319 } 1320 | 1133 if (status & SF_ISR_ABNORMALINTR) { 1134 if (status & SF_ISR_STATSOFLOW) { 1135 untimeout(sf_stats_update, sc, 1136 sc->sf_stat_ch); 1137 sf_stats_update(sc); 1138 } else 1139 sf_init(sc); 1140 } --- 202 unchanged lines hidden (view full) --- 1343 return; 1344 } 1345 1346 if (ifp->if_flags & IFF_OACTIVE) { 1347 SF_UNLOCK(sc); 1348 return; 1349 } 1350 |
1351 if (sc->sf_tx_cnt) 1352 sf_txeof(sc); 1353 |
|
1321 txprod = csr_read_4(sc, SF_TXDQ_PRODIDX); 1322 i = SF_IDX_HI(txprod) >> 4; 1323 | 1354 txprod = csr_read_4(sc, SF_TXDQ_PRODIDX); 1355 i = SF_IDX_HI(txprod) >> 4; 1356 |
1357 if (sc->sf_ldata->sf_tx_dlist[i].sf_mbuf != NULL) { 1358 printf("sf%d: TX ring full, resetting\n", sc->sf_unit); 1359 sf_init(sc); 1360 txprod = csr_read_4(sc, SF_TXDQ_PRODIDX); 1361 i = SF_IDX_HI(txprod) >> 4; 1362 } 1363 |
|
1324 while(sc->sf_ldata->sf_tx_dlist[i].sf_mbuf == NULL) { | 1364 while(sc->sf_ldata->sf_tx_dlist[i].sf_mbuf == NULL) { |
1325 if (sc->sf_tx_cnt == (SF_TX_DLIST_CNT - 2)) { | 1365 if (sc->sf_tx_cnt >= (SF_TX_DLIST_CNT - 5)) { |
1326 ifp->if_flags |= IFF_OACTIVE; 1327 cur_tx = NULL; 1328 break; 1329 } 1330 IF_DEQUEUE(&ifp->if_snd, m_head); 1331 if (m_head == NULL) 1332 break; 1333 --- 167 unchanged lines hidden --- | 1366 ifp->if_flags |= IFF_OACTIVE; 1367 cur_tx = NULL; 1368 break; 1369 } 1370 IF_DEQUEUE(&ifp->if_snd, m_head); 1371 if (m_head == NULL) 1372 break; 1373 --- 167 unchanged lines hidden --- |