if_my.c (266270) | if_my.c (271827) |
---|---|
1/*- 2 * Written by: yen_cw@myson.com.tw 3 * Copyright (c) 2002 Myson Technology Inc. 4 * 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: --- 14 unchanged lines hidden (view full) --- 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * Myson fast ethernet PCI NIC driver, available at: http://www.myson.com.tw/ 28 */ 29 30#include <sys/cdefs.h> | 1/*- 2 * Written by: yen_cw@myson.com.tw 3 * Copyright (c) 2002 Myson Technology Inc. 4 * 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: --- 14 unchanged lines hidden (view full) --- 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 * SUCH DAMAGE. 26 * 27 * Myson fast ethernet PCI NIC driver, available at: http://www.myson.com.tw/ 28 */ 29 30#include <sys/cdefs.h> |
31__FBSDID("$FreeBSD: head/sys/dev/my/if_my.c 266270 2014-05-16 21:19:17Z brueffer $"); | 31__FBSDID("$FreeBSD: head/sys/dev/my/if_my.c 271827 2014-09-18 20:59:59Z glebius $"); |
32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/sockio.h> 36#include <sys/mbuf.h> 37#include <sys/malloc.h> 38#include <sys/kernel.h> 39#include <sys/socket.h> --- 1076 unchanged lines hidden (view full) --- 1116 MY_LOCK_ASSERT(sc); 1117 ifp = sc->my_ifp; 1118 while (!((rxstat = sc->my_cdata.my_rx_head->my_ptr->my_status) 1119 & MY_OWNByNIC)) { 1120 cur_rx = sc->my_cdata.my_rx_head; 1121 sc->my_cdata.my_rx_head = cur_rx->my_nextdesc; 1122 1123 if (rxstat & MY_ES) { /* error summary: give up this rx pkt */ | 32 33#include <sys/param.h> 34#include <sys/systm.h> 35#include <sys/sockio.h> 36#include <sys/mbuf.h> 37#include <sys/malloc.h> 38#include <sys/kernel.h> 39#include <sys/socket.h> --- 1076 unchanged lines hidden (view full) --- 1116 MY_LOCK_ASSERT(sc); 1117 ifp = sc->my_ifp; 1118 while (!((rxstat = sc->my_cdata.my_rx_head->my_ptr->my_status) 1119 & MY_OWNByNIC)) { 1120 cur_rx = sc->my_cdata.my_rx_head; 1121 sc->my_cdata.my_rx_head = cur_rx->my_nextdesc; 1122 1123 if (rxstat & MY_ES) { /* error summary: give up this rx pkt */ |
1124 ifp->if_ierrors++; | 1124 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
1125 cur_rx->my_ptr->my_status = MY_OWNByNIC; 1126 continue; 1127 } 1128 /* No errors; receive the packet. */ 1129 total_len = (rxstat & MY_FLNGMASK) >> MY_FLNGShift; 1130 total_len -= ETHER_CRC_LEN; 1131 1132 if (total_len < MINCLSIZE) { 1133 m = m_devget(mtod(cur_rx->my_mbuf, char *), 1134 total_len, 0, ifp, NULL); 1135 cur_rx->my_ptr->my_status = MY_OWNByNIC; 1136 if (m == NULL) { | 1125 cur_rx->my_ptr->my_status = MY_OWNByNIC; 1126 continue; 1127 } 1128 /* No errors; receive the packet. */ 1129 total_len = (rxstat & MY_FLNGMASK) >> MY_FLNGShift; 1130 total_len -= ETHER_CRC_LEN; 1131 1132 if (total_len < MINCLSIZE) { 1133 m = m_devget(mtod(cur_rx->my_mbuf, char *), 1134 total_len, 0, ifp, NULL); 1135 cur_rx->my_ptr->my_status = MY_OWNByNIC; 1136 if (m == NULL) { |
1137 ifp->if_ierrors++; | 1137 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
1138 continue; 1139 } 1140 } else { 1141 m = cur_rx->my_mbuf; 1142 /* 1143 * Try to conjure up a new mbuf cluster. If that 1144 * fails, it means we have an out of memory condition 1145 * and should leave the buffer in place and continue. 1146 * This will result in a lost packet, but there's 1147 * little else we can do in this situation. 1148 */ 1149 if (my_newbuf(sc, cur_rx) == ENOBUFS) { | 1138 continue; 1139 } 1140 } else { 1141 m = cur_rx->my_mbuf; 1142 /* 1143 * Try to conjure up a new mbuf cluster. If that 1144 * fails, it means we have an out of memory condition 1145 * and should leave the buffer in place and continue. 1146 * This will result in a lost packet, but there's 1147 * little else we can do in this situation. 1148 */ 1149 if (my_newbuf(sc, cur_rx) == ENOBUFS) { |
1150 ifp->if_ierrors++; | 1150 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
1151 cur_rx->my_ptr->my_status = MY_OWNByNIC; 1152 continue; 1153 } 1154 m->m_pkthdr.rcvif = ifp; 1155 m->m_pkthdr.len = m->m_len = total_len; 1156 } | 1151 cur_rx->my_ptr->my_status = MY_OWNByNIC; 1152 continue; 1153 } 1154 m->m_pkthdr.rcvif = ifp; 1155 m->m_pkthdr.len = m->m_len = total_len; 1156 } |
1157 ifp->if_ipackets++; | 1157 if_inc_counter(ifp, IFCOUNTER_IPACKETS, 1); |
1158 eh = mtod(m, struct ether_header *); 1159#if NBPFILTER > 0 1160 /* 1161 * Handle BPF listeners. Let the BPF user see the packet, but 1162 * don't pass it up to the ether_input() layer unless it's a 1163 * broadcast packet, multicast packet, matches our ethernet 1164 * address or the interface is in promiscuous mode. 1165 */ --- 41 unchanged lines hidden (view full) --- 1207 u_int32_t txstat; 1208 1209 cur_tx = sc->my_cdata.my_tx_head; 1210 txstat = MY_TXSTATUS(cur_tx); 1211 if ((txstat & MY_OWNByNIC) || txstat == MY_UNSENT) 1212 break; 1213 if (!(CSR_READ_4(sc, MY_TCRRCR) & MY_Enhanced)) { 1214 if (txstat & MY_TXERR) { | 1158 eh = mtod(m, struct ether_header *); 1159#if NBPFILTER > 0 1160 /* 1161 * Handle BPF listeners. Let the BPF user see the packet, but 1162 * don't pass it up to the ether_input() layer unless it's a 1163 * broadcast packet, multicast packet, matches our ethernet 1164 * address or the interface is in promiscuous mode. 1165 */ --- 41 unchanged lines hidden (view full) --- 1207 u_int32_t txstat; 1208 1209 cur_tx = sc->my_cdata.my_tx_head; 1210 txstat = MY_TXSTATUS(cur_tx); 1211 if ((txstat & MY_OWNByNIC) || txstat == MY_UNSENT) 1212 break; 1213 if (!(CSR_READ_4(sc, MY_TCRRCR) & MY_Enhanced)) { 1214 if (txstat & MY_TXERR) { |
1215 ifp->if_oerrors++; | 1215 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); |
1216 if (txstat & MY_EC) /* excessive collision */ | 1216 if (txstat & MY_EC) /* excessive collision */ |
1217 ifp->if_collisions++; | 1217 if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1); |
1218 if (txstat & MY_LC) /* late collision */ | 1218 if (txstat & MY_LC) /* late collision */ |
1219 ifp->if_collisions++; | 1219 if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1); |
1220 } | 1220 } |
1221 ifp->if_collisions += (txstat & MY_NCRMASK) >> 1222 MY_NCRShift; | 1221 if_inc_counter(ifp, IFCOUNTER_COLLISIONS, 1222 (txstat & MY_NCRMASK) >> MY_NCRShift); |
1223 } | 1223 } |
1224 ifp->if_opackets++; | 1224 if_inc_counter(ifp, IFCOUNTER_OPACKETS, 1); |
1225 m_freem(cur_tx->my_mbuf); 1226 cur_tx->my_mbuf = NULL; 1227 if (sc->my_cdata.my_tx_head == sc->my_cdata.my_tx_tail) { 1228 sc->my_cdata.my_tx_head = NULL; 1229 sc->my_cdata.my_tx_tail = NULL; 1230 break; 1231 } 1232 sc->my_cdata.my_tx_head = cur_tx->my_nextdesc; 1233 } 1234 if (CSR_READ_4(sc, MY_TCRRCR) & MY_Enhanced) { | 1225 m_freem(cur_tx->my_mbuf); 1226 cur_tx->my_mbuf = NULL; 1227 if (sc->my_cdata.my_tx_head == sc->my_cdata.my_tx_tail) { 1228 sc->my_cdata.my_tx_head = NULL; 1229 sc->my_cdata.my_tx_tail = NULL; 1230 break; 1231 } 1232 sc->my_cdata.my_tx_head = cur_tx->my_nextdesc; 1233 } 1234 if (CSR_READ_4(sc, MY_TCRRCR) & MY_Enhanced) { |
1235 ifp->if_collisions += (CSR_READ_4(sc, MY_TSR) & MY_NCRMask); | 1235 if_inc_counter(ifp, IFCOUNTER_COLLISIONS, (CSR_READ_4(sc, MY_TSR) & MY_NCRMask)); |
1236 } 1237 return; 1238} 1239 1240/* 1241 * TX 'end of channel' interrupt handler. 1242 */ 1243static void --- 44 unchanged lines hidden (view full) --- 1288 else 1289 break; 1290 1291 if (status & MY_RI) /* receive interrupt */ 1292 my_rxeof(sc); 1293 1294 if ((status & MY_RBU) || (status & MY_RxErr)) { 1295 /* rx buffer unavailable or rx error */ | 1236 } 1237 return; 1238} 1239 1240/* 1241 * TX 'end of channel' interrupt handler. 1242 */ 1243static void --- 44 unchanged lines hidden (view full) --- 1288 else 1289 break; 1290 1291 if (status & MY_RI) /* receive interrupt */ 1292 my_rxeof(sc); 1293 1294 if ((status & MY_RBU) || (status & MY_RxErr)) { 1295 /* rx buffer unavailable or rx error */ |
1296 ifp->if_ierrors++; | 1296 if_inc_counter(ifp, IFCOUNTER_IERRORS, 1); |
1297#ifdef foo 1298 my_stop(sc); 1299 my_reset(sc); 1300 my_init_locked(sc); 1301#endif 1302 } 1303 if (status & MY_TI) /* tx interrupt */ 1304 my_txeof(sc); --- 391 unchanged lines hidden (view full) --- 1696 1697 sc = arg; 1698 MY_LOCK_ASSERT(sc); 1699 callout_reset(&sc->my_watchdog, hz, my_watchdog, sc); 1700 if (sc->my_timer == 0 || --sc->my_timer > 0) 1701 return; 1702 1703 ifp = sc->my_ifp; | 1297#ifdef foo 1298 my_stop(sc); 1299 my_reset(sc); 1300 my_init_locked(sc); 1301#endif 1302 } 1303 if (status & MY_TI) /* tx interrupt */ 1304 my_txeof(sc); --- 391 unchanged lines hidden (view full) --- 1696 1697 sc = arg; 1698 MY_LOCK_ASSERT(sc); 1699 callout_reset(&sc->my_watchdog, hz, my_watchdog, sc); 1700 if (sc->my_timer == 0 || --sc->my_timer > 0) 1701 return; 1702 1703 ifp = sc->my_ifp; |
1704 ifp->if_oerrors++; | 1704 if_inc_counter(ifp, IFCOUNTER_OERRORS, 1); |
1705 if_printf(ifp, "watchdog timeout\n"); 1706 if (!(my_phy_readreg(sc, PHY_BMSR) & PHY_BMSR_LINKSTAT)) 1707 if_printf(ifp, "no carrier - transceiver cable problem?\n"); 1708 my_stop(sc); 1709 my_reset(sc); 1710 my_init_locked(sc); 1711 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) 1712 my_start_locked(ifp); --- 64 unchanged lines hidden --- | 1705 if_printf(ifp, "watchdog timeout\n"); 1706 if (!(my_phy_readreg(sc, PHY_BMSR) & PHY_BMSR_LINKSTAT)) 1707 if_printf(ifp, "no carrier - transceiver cable problem?\n"); 1708 my_stop(sc); 1709 my_reset(sc); 1710 my_init_locked(sc); 1711 if (!IFQ_DRV_IS_EMPTY(&ifp->if_snd)) 1712 my_start_locked(ifp); --- 64 unchanged lines hidden --- |