if_ed.c (791) | if_ed.c (798) |
---|---|
1/* 2 * Device driver for National Semiconductor DS8390/WD83C690 based ethernet 3 * adapters. By David Greenman, 29-April-1993 4 * 5 * Copyright (C) 1993, David Greenman. This software may be used, modified, 6 * copied, distributed, and sold, in both source and binary form provided 7 * that the above copyright and these terms are retained. Under no 8 * circumstances is the author responsible for the proper functioning --- 6 unchanged lines hidden (view full) --- 15 * 16 * Thanks to Charles Hannum for proving to me with example code that the 17 * NE1000/2000 support could be added with minimal impact. Without 18 * this, I wouldn't have proceeded in this direction. 19 * 20 */ 21 22/* | 1/* 2 * Device driver for National Semiconductor DS8390/WD83C690 based ethernet 3 * adapters. By David Greenman, 29-April-1993 4 * 5 * Copyright (C) 1993, David Greenman. This software may be used, modified, 6 * copied, distributed, and sold, in both source and binary form provided 7 * that the above copyright and these terms are retained. Under no 8 * circumstances is the author responsible for the proper functioning --- 6 unchanged lines hidden (view full) --- 15 * 16 * Thanks to Charles Hannum for proving to me with example code that the 17 * NE1000/2000 support could be added with minimal impact. Without 18 * this, I wouldn't have proceeded in this direction. 19 * 20 */ 21 22/* |
23 * $Id: if_ed.c,v 2.14 1993/11/22 10:55:30 davidg Exp davidg $ | 23 * $Id: if_ed.c,v 1.23 1993/11/22 11:08:14 davidg Exp $ |
24 */ 25 26/* 27 * Modification history 28 * 29 * Revision 2.14 1993/11/22 10:55:30 davidg 30 * change all splnet's to splimp's 31 * --- 148 unchanged lines hidden (view full) --- 180 u_char txb_next_tx; /* pointer to next buffer ready to xmit */ 181 u_short txb_len[8]; /* buffered xmit buffer lengths */ 182 u_char tx_page_start; /* first page of TX buffer area */ 183 u_char rec_page_start; /* first page of RX ring-buffer */ 184 u_char rec_page_stop; /* last page of RX ring-buffer */ 185 u_char next_packet; /* pointer to next unread RX packet */ 186} ed_softc[NED]; 187 | 24 */ 25 26/* 27 * Modification history 28 * 29 * Revision 2.14 1993/11/22 10:55:30 davidg 30 * change all splnet's to splimp's 31 * --- 148 unchanged lines hidden (view full) --- 180 u_char txb_next_tx; /* pointer to next buffer ready to xmit */ 181 u_short txb_len[8]; /* buffered xmit buffer lengths */ 182 u_char tx_page_start; /* first page of TX buffer area */ 183 u_char rec_page_start; /* first page of RX ring-buffer */ 184 u_char rec_page_stop; /* last page of RX ring-buffer */ 185 u_char next_packet; /* pointer to next unread RX packet */ 186} ed_softc[NED]; 187 |
188int ed_attach(), ed_init(), edintr(), ed_ioctl(), ed_probe(), 189 ed_start(), ed_reset(), ed_watchdog(); | 188int ed_attach(struct isa_device *); 189void ed_init(int); 190void edintr(int); 191int ed_ioctl(struct ifnet *, int, caddr_t); 192int ed_probe(struct isa_device *); 193void ed_start(struct ifnet *); 194void ed_reset(int, int); 195void ed_watchdog(int); 196static void ed_get_packet(struct ed_softc *, char *, int /*u_short*/); 197static void ed_stop(int); |
190 | 198 |
191static void ed_stop(); 192 | |
193static inline void ed_rint(); 194static inline void ed_xmit(); 195static inline char *ed_ring_copy(); 196 197void ed_pio_readmem(), ed_pio_writemem(); 198u_short ed_pio_write_mbufs(); 199 200extern int ether_output(); --- 907 unchanged lines hidden (view full) --- 1108 (ifp->if_flags & IFF_ALTPHYS)) ? "tranceiver disabled" : ""); 1109 1110 /* 1111 * If BPF is in the kernel, call the attach for it 1112 */ 1113#if NBPFILTER > 0 1114 bpfattach(&sc->bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); 1115#endif | 199static inline void ed_rint(); 200static inline void ed_xmit(); 201static inline char *ed_ring_copy(); 202 203void ed_pio_readmem(), ed_pio_writemem(); 204u_short ed_pio_write_mbufs(); 205 206extern int ether_output(); --- 907 unchanged lines hidden (view full) --- 1114 (ifp->if_flags & IFF_ALTPHYS)) ? "tranceiver disabled" : ""); 1115 1116 /* 1117 * If BPF is in the kernel, call the attach for it 1118 */ 1119#if NBPFILTER > 0 1120 bpfattach(&sc->bpf, ifp, DLT_EN10MB, sizeof(struct ether_header)); 1121#endif |
1116 | 1122 return 1; |
1117} 1118 1119/* 1120 * Reset interface. 1121 */ | 1123} 1124 1125/* 1126 * Reset interface. 1127 */ |
1122int 1123ed_reset(unit) | 1128void 1129ed_reset(unit, uban) |
1124 int unit; | 1130 int unit; |
1131 int uban; /* XXX */ |
|
1125{ 1126 int s; 1127 1128 s = splimp(); 1129 1130 /* 1131 * Stop interface and re-initialize. 1132 */ --- 29 unchanged lines hidden (view full) --- 1162 while (((inb(sc->nic_addr + ED_P0_ISR) & ED_ISR_RST) == 0) && --n); 1163 1164} 1165 1166/* 1167 * Device timeout/watchdog routine. Entered if the device neglects to 1168 * generate an interrupt after a transmit has been started on it. 1169 */ | 1132{ 1133 int s; 1134 1135 s = splimp(); 1136 1137 /* 1138 * Stop interface and re-initialize. 1139 */ --- 29 unchanged lines hidden (view full) --- 1169 while (((inb(sc->nic_addr + ED_P0_ISR) & ED_ISR_RST) == 0) && --n); 1170 1171} 1172 1173/* 1174 * Device timeout/watchdog routine. Entered if the device neglects to 1175 * generate an interrupt after a transmit has been started on it. 1176 */ |
1170int | 1177void |
1171ed_watchdog(unit) 1172 int unit; 1173{ 1174 struct ed_softc *sc = &ed_softc[unit]; 1175 1176 log(LOG_ERR, "ed%d: device timeout\n", unit); 1177 ++sc->arpcom.ac_if.if_oerrors; 1178 | 1178ed_watchdog(unit) 1179 int unit; 1180{ 1181 struct ed_softc *sc = &ed_softc[unit]; 1182 1183 log(LOG_ERR, "ed%d: device timeout\n", unit); 1184 ++sc->arpcom.ac_if.if_oerrors; 1185 |
1179 ed_reset(unit); | 1186 ed_reset(unit, 0); |
1180} 1181 1182/* 1183 * Initialize device. 1184 */ | 1187} 1188 1189/* 1190 * Initialize device. 1191 */ |
1192void |
|
1185ed_init(unit) 1186 int unit; 1187{ 1188 struct ed_softc *sc = &ed_softc[unit]; 1189 struct ifnet *ifp = &sc->arpcom.ac_if; 1190 int i, s; 1191 u_char command; 1192 --- 212 unchanged lines hidden (view full) --- 1405 * Start output on interface. 1406 * We make two assumptions here: 1407 * 1) that the current priority is set to splimp _before_ this code 1408 * is called *and* is returned to the appropriate priority after 1409 * return 1410 * 2) that the IFF_OACTIVE flag is checked before this code is called 1411 * (i.e. that the output part of the interface is idle) 1412 */ | 1193ed_init(unit) 1194 int unit; 1195{ 1196 struct ed_softc *sc = &ed_softc[unit]; 1197 struct ifnet *ifp = &sc->arpcom.ac_if; 1198 int i, s; 1199 u_char command; 1200 --- 212 unchanged lines hidden (view full) --- 1413 * Start output on interface. 1414 * We make two assumptions here: 1415 * 1) that the current priority is set to splimp _before_ this code 1416 * is called *and* is returned to the appropriate priority after 1417 * return 1418 * 2) that the IFF_OACTIVE flag is checked before this code is called 1419 * (i.e. that the output part of the interface is idle) 1420 */ |
1413int | 1421void |
1414ed_start(ifp) 1415 struct ifnet *ifp; 1416{ 1417 struct ed_softc *sc = &ed_softc[ifp->if_unit]; 1418 struct mbuf *m0, *m; 1419 caddr_t buffer; 1420 int len; 1421 --- 239 unchanged lines hidden (view full) --- 1661 * Really BAD...probably indicates that the ring pointers 1662 * are corrupted. Also seen on early rev chips under 1663 * high load - the byte order of the length gets switched. 1664 */ 1665 log(LOG_ERR, 1666 "ed%d: NIC memory corrupt - invalid packet length %d\n", 1667 unit, len); 1668 ++sc->arpcom.ac_if.if_ierrors; | 1422ed_start(ifp) 1423 struct ifnet *ifp; 1424{ 1425 struct ed_softc *sc = &ed_softc[ifp->if_unit]; 1426 struct mbuf *m0, *m; 1427 caddr_t buffer; 1428 int len; 1429 --- 239 unchanged lines hidden (view full) --- 1669 * Really BAD...probably indicates that the ring pointers 1670 * are corrupted. Also seen on early rev chips under 1671 * high load - the byte order of the length gets switched. 1672 */ 1673 log(LOG_ERR, 1674 "ed%d: NIC memory corrupt - invalid packet length %d\n", 1675 unit, len); 1676 ++sc->arpcom.ac_if.if_ierrors; |
1669 ed_reset(unit); | 1677 ed_reset(unit, 0); |
1670 return; 1671 } 1672 1673 /* 1674 * Update next packet pointer 1675 */ 1676 sc->next_packet = packet_hdr.next_packet; 1677 --- 25 unchanged lines hidden (view full) --- 1703 outb(sc->nic_addr + ED_P0_CR, ED_CR_PAGE_1|ED_CR_RD2|ED_CR_STA); 1704 } 1705 } 1706} 1707 1708/* 1709 * Ethernet interface interrupt processor 1710 */ | 1678 return; 1679 } 1680 1681 /* 1682 * Update next packet pointer 1683 */ 1684 sc->next_packet = packet_hdr.next_packet; 1685 --- 25 unchanged lines hidden (view full) --- 1711 outb(sc->nic_addr + ED_P0_CR, ED_CR_PAGE_1|ED_CR_RD2|ED_CR_STA); 1712 } 1713 } 1714} 1715 1716/* 1717 * Ethernet interface interrupt processor 1718 */ |
1711int | 1719void |
1712edintr(unit) 1713 int unit; 1714{ 1715 struct ed_softc *sc = &ed_softc[unit]; 1716 u_char isr; 1717 1718 /* 1719 * Set NIC to page 0 registers --- 106 unchanged lines hidden (view full) --- 1826#ifdef DIAGNOSTIC 1827 log(LOG_WARNING, 1828 "ed%d: warning - receiver ring buffer overrun\n", 1829 unit); 1830#endif 1831 /* 1832 * Stop/reset/re-init NIC 1833 */ | 1720edintr(unit) 1721 int unit; 1722{ 1723 struct ed_softc *sc = &ed_softc[unit]; 1724 u_char isr; 1725 1726 /* 1727 * Set NIC to page 0 registers --- 106 unchanged lines hidden (view full) --- 1834#ifdef DIAGNOSTIC 1835 log(LOG_WARNING, 1836 "ed%d: warning - receiver ring buffer overrun\n", 1837 unit); 1838#endif 1839 /* 1840 * Stop/reset/re-init NIC 1841 */ |
1834 ed_reset(unit); | 1842 ed_reset(unit, 0); |
1835 } else { 1836 1837 /* 1838 * Receiver Error. One or more of: CRC error, frame 1839 * alignment error FIFO overrun, or missed packet. 1840 */ 1841 if (isr & ED_ISR_RXE) { 1842 ++sc->arpcom.ac_if.if_ierrors; --- 206 unchanged lines hidden (view full) --- 2049 (((caddr_t)(start)+(off))) - (sc)->mem_end \ 2050 + (sc)->mem_ring: \ 2051 ((caddr_t)(start)+(off)) )) 2052 2053/* 2054 * Retreive packet from shared memory and send to the next level up via 2055 * ether_input(). If there is a BPF listener, give a copy to BPF, too. 2056 */ | 1843 } else { 1844 1845 /* 1846 * Receiver Error. One or more of: CRC error, frame 1847 * alignment error FIFO overrun, or missed packet. 1848 */ 1849 if (isr & ED_ISR_RXE) { 1850 ++sc->arpcom.ac_if.if_ierrors; --- 206 unchanged lines hidden (view full) --- 2057 (((caddr_t)(start)+(off))) - (sc)->mem_end \ 2058 + (sc)->mem_ring: \ 2059 ((caddr_t)(start)+(off)) )) 2060 2061/* 2062 * Retreive packet from shared memory and send to the next level up via 2063 * ether_input(). If there is a BPF listener, give a copy to BPF, too. 2064 */ |
2065static void |
|
2057ed_get_packet(sc, buf, len) 2058 struct ed_softc *sc; 2059 char *buf; 2060 u_short len; 2061{ 2062 struct ether_header *eh; | 2066ed_get_packet(sc, buf, len) 2067 struct ed_softc *sc; 2068 char *buf; 2069 u_short len; 2070{ 2071 struct ether_header *eh; |
2063 struct mbuf *m, *head, *ed_ring_to_mbuf(); | 2072 struct mbuf *m, *head = 0, *ed_ring_to_mbuf(); |
2064 u_short off; 2065 int resid; 2066 u_short etype; 2067 struct trailer_header trailer_header; 2068 2069 /* Allocate a header mbuf */ 2070 MGETHDR(m, M_DONTWAIT, MT_DATA); 2071 if (m == 0) --- 304 unchanged lines hidden (view full) --- 2376 * Not waiting causes really bad things to happen - like the NIC 2377 * irrecoverably jamming the ISA bus. 2378 */ 2379 while (((inb(sc->nic_addr + ED_P0_ISR) & ED_ISR_RDC) != ED_ISR_RDC) && --maxwait); 2380 2381 if (!maxwait) { 2382 log(LOG_WARNING, "ed%d: remote transmit DMA failed to complete\n", 2383 sc->arpcom.ac_if.if_unit); | 2073 u_short off; 2074 int resid; 2075 u_short etype; 2076 struct trailer_header trailer_header; 2077 2078 /* Allocate a header mbuf */ 2079 MGETHDR(m, M_DONTWAIT, MT_DATA); 2080 if (m == 0) --- 304 unchanged lines hidden (view full) --- 2385 * Not waiting causes really bad things to happen - like the NIC 2386 * irrecoverably jamming the ISA bus. 2387 */ 2388 while (((inb(sc->nic_addr + ED_P0_ISR) & ED_ISR_RDC) != ED_ISR_RDC) && --maxwait); 2389 2390 if (!maxwait) { 2391 log(LOG_WARNING, "ed%d: remote transmit DMA failed to complete\n", 2392 sc->arpcom.ac_if.if_unit); |
2384 ed_reset(sc->arpcom.ac_if.if_unit); | 2393 ed_reset(sc->arpcom.ac_if.if_unit, 0); |
2385 } 2386 2387 return(len); 2388} 2389 2390/* 2391 * Given a source and destination address, copy 'amount' of a packet from 2392 * the ring buffer into a linear destination buffer. Takes into account --- 89 unchanged lines hidden --- | 2394 } 2395 2396 return(len); 2397} 2398 2399/* 2400 * Given a source and destination address, copy 'amount' of a packet from 2401 * the ring buffer into a linear destination buffer. Takes into account --- 89 unchanged lines hidden --- |