Deleted Added
full compact
if_rl.c (51657) if_rl.c (52426)
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

--- 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
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/pci/if_rl.c 51657 1999-09-25 17:29:02Z wpaul $
32 * $FreeBSD: head/sys/pci/if_rl.c 52426 1999-10-21 19:42:03Z wpaul $
33 */
34
35/*
36 * RealTek 8129/8139 PCI NIC driver
37 *
38 * Supports several extremely cheap PCI 10/100 adapters based on
39 * the RealTek chipset. Datasheets can be obtained from
40 * www.realtek.com.tw.

--- 86 unchanged lines hidden (view full) ---

127 * uniprocessor systems though.
128 */
129#define RL_USEIOSPACE
130
131#include <pci/if_rlreg.h>
132
133#ifndef lint
134static const char rcsid[] =
33 */
34
35/*
36 * RealTek 8129/8139 PCI NIC driver
37 *
38 * Supports several extremely cheap PCI 10/100 adapters based on
39 * the RealTek chipset. Datasheets can be obtained from
40 * www.realtek.com.tw.

--- 86 unchanged lines hidden (view full) ---

127 * uniprocessor systems though.
128 */
129#define RL_USEIOSPACE
130
131#include <pci/if_rlreg.h>
132
133#ifndef lint
134static const char rcsid[] =
135 "$FreeBSD: head/sys/pci/if_rl.c 51657 1999-09-25 17:29:02Z wpaul $";
135 "$FreeBSD: head/sys/pci/if_rl.c 52426 1999-10-21 19:42:03Z wpaul $";
136#endif
137
138/*
139 * Various supported device vendors/types and their names.
140 */
141static struct rl_type rl_devs[] = {
142 { RT_VENDORID, RT_DEVICEID_8129,
143 "RealTek 8129 10/100BaseTX" },

--- 839 unchanged lines hidden (view full) ---

983
984 bus_generic_detach(dev);
985 device_delete_child(dev, sc->rl_miibus);
986
987 bus_teardown_intr(dev, sc->rl_irq, sc->rl_intrhand);
988 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->rl_res);
989 bus_release_resource(dev, RL_RES, RL_RID, sc->rl_res);
990
136#endif
137
138/*
139 * Various supported device vendors/types and their names.
140 */
141static struct rl_type rl_devs[] = {
142 { RT_VENDORID, RT_DEVICEID_8129,
143 "RealTek 8129 10/100BaseTX" },

--- 839 unchanged lines hidden (view full) ---

983
984 bus_generic_detach(dev);
985 device_delete_child(dev, sc->rl_miibus);
986
987 bus_teardown_intr(dev, sc->rl_irq, sc->rl_intrhand);
988 bus_release_resource(dev, SYS_RES_IRQ, 0, sc->rl_res);
989 bus_release_resource(dev, RL_RES, RL_RID, sc->rl_res);
990
991 free(sc->rl_cdata.rl_rx_buf, M_DEVBUF);
991 contigfree(sc->rl_cdata.rl_rx_buf, RL_RXBUFLEN + 32, M_DEVBUF);
992
993 splx(s);
994
995 return(0);
996}
997
998/*
999 * Initialize the transmit descriptors.

--- 120 unchanged lines hidden (view full) ---

1120 wrap = (sc->rl_cdata.rl_rx_buf + RL_RXBUFLEN) - rxbufpos;
1121
1122 if (total_len > wrap) {
1123 m = m_devget(rxbufpos - RL_ETHER_ALIGN,
1124 wrap + RL_ETHER_ALIGN, 0, ifp, NULL);
1125 if (m == NULL) {
1126 ifp->if_ierrors++;
1127 printf("rl%d: out of mbufs, tried to "
992
993 splx(s);
994
995 return(0);
996}
997
998/*
999 * Initialize the transmit descriptors.

--- 120 unchanged lines hidden (view full) ---

1120 wrap = (sc->rl_cdata.rl_rx_buf + RL_RXBUFLEN) - rxbufpos;
1121
1122 if (total_len > wrap) {
1123 m = m_devget(rxbufpos - RL_ETHER_ALIGN,
1124 wrap + RL_ETHER_ALIGN, 0, ifp, NULL);
1125 if (m == NULL) {
1126 ifp->if_ierrors++;
1127 printf("rl%d: out of mbufs, tried to "
1128 "copy %d bytes\n", sc->rl_unit, wrap);
1129 }
1130 else {
1128 "copy %d bytes\n", sc->rl_unit, wrap);
1129 } else {
1131 m_adj(m, RL_ETHER_ALIGN);
1132 m_copyback(m, wrap, total_len - wrap,
1133 sc->rl_cdata.rl_rx_buf);
1130 m_adj(m, RL_ETHER_ALIGN);
1131 m_copyback(m, wrap, total_len - wrap,
1132 sc->rl_cdata.rl_rx_buf);
1133 m_pullup(m, MHLEN - RL_ETHER_ALIGN);
1134 }
1135 cur_rx = (total_len - wrap + ETHER_CRC_LEN);
1136 } else {
1137 m = m_devget(rxbufpos - RL_ETHER_ALIGN,
1138 total_len + RL_ETHER_ALIGN, 0, ifp, NULL);
1139 if (m == NULL) {
1140 ifp->if_ierrors++;
1141 printf("rl%d: out of mbufs, tried to "
1134 }
1135 cur_rx = (total_len - wrap + ETHER_CRC_LEN);
1136 } else {
1137 m = m_devget(rxbufpos - RL_ETHER_ALIGN,
1138 total_len + RL_ETHER_ALIGN, 0, ifp, NULL);
1139 if (m == NULL) {
1140 ifp->if_ierrors++;
1141 printf("rl%d: out of mbufs, tried to "
1142 "copy %d bytes\n", sc->rl_unit, total_len);
1142 "copy %d bytes\n", sc->rl_unit, total_len);
1143 } else
1144 m_adj(m, RL_ETHER_ALIGN);
1145 cur_rx += total_len + 4 + ETHER_CRC_LEN;
1146 }
1147
1148 /*
1149 * Round up to 32-bit boundary.
1150 */

--- 60 unchanged lines hidden (view full) ---

1211
1212 if (RL_LAST_TXMBUF(sc) != NULL) {
1213 m_freem(RL_LAST_TXMBUF(sc));
1214 RL_LAST_TXMBUF(sc) = NULL;
1215 }
1216 if (txstat & RL_TXSTAT_TX_OK)
1217 ifp->if_opackets++;
1218 else {
1143 } else
1144 m_adj(m, RL_ETHER_ALIGN);
1145 cur_rx += total_len + 4 + ETHER_CRC_LEN;
1146 }
1147
1148 /*
1149 * Round up to 32-bit boundary.
1150 */

--- 60 unchanged lines hidden (view full) ---

1211
1212 if (RL_LAST_TXMBUF(sc) != NULL) {
1213 m_freem(RL_LAST_TXMBUF(sc));
1214 RL_LAST_TXMBUF(sc) = NULL;
1215 }
1216 if (txstat & RL_TXSTAT_TX_OK)
1217 ifp->if_opackets++;
1218 else {
1219 int oldthresh;
1219 ifp->if_oerrors++;
1220 if ((txstat & RL_TXSTAT_TXABRT) ||
1221 (txstat & RL_TXSTAT_OUTOFWIN))
1222 CSR_WRITE_4(sc, RL_TXCFG, RL_TXCFG_CONFIG);
1220 ifp->if_oerrors++;
1221 if ((txstat & RL_TXSTAT_TXABRT) ||
1222 (txstat & RL_TXSTAT_OUTOFWIN))
1223 CSR_WRITE_4(sc, RL_TXCFG, RL_TXCFG_CONFIG);
1224 oldthresh = sc->rl_txthresh;
1225 /* error recovery */
1226 rl_reset(sc);
1227 rl_init(sc);
1228 /*
1229 * If there was a transmit underrun,
1230 * bump the TX threshold.
1231 */
1232 if (txstat & RL_TXSTAT_TX_UNDERRUN)
1233 sc->rl_txthresh = oldthresh + 32;
1234 return;
1223 }
1224 RL_INC(sc->rl_cdata.last_tx);
1225 ifp->if_flags &= ~IFF_OACTIVE;
1226 } while (sc->rl_cdata.last_tx != sc->rl_cdata.cur_tx);
1227
1228 return;
1229}
1230

--- 54 unchanged lines hidden (view full) ---

1285 rl_init(sc);
1286 }
1287
1288 }
1289
1290 /* Re-enable interrupts. */
1291 CSR_WRITE_2(sc, RL_IMR, RL_INTRS);
1292
1235 }
1236 RL_INC(sc->rl_cdata.last_tx);
1237 ifp->if_flags &= ~IFF_OACTIVE;
1238 } while (sc->rl_cdata.last_tx != sc->rl_cdata.cur_tx);
1239
1240 return;
1241}
1242

--- 54 unchanged lines hidden (view full) ---

1297 rl_init(sc);
1298 }
1299
1300 }
1301
1302 /* Re-enable interrupts. */
1303 CSR_WRITE_2(sc, RL_IMR, RL_INTRS);
1304
1293 if (ifp->if_snd.ifq_head != NULL) {
1305 if (ifp->if_snd.ifq_head != NULL)
1294 rl_start(ifp);
1306 rl_start(ifp);
1295 }
1296
1297 return;
1298}
1299
1300/*
1301 * Encapsulate an mbuf chain in a descriptor by coupling the mbuf data
1302 * pointers to the fragment pointers.
1303 */

--- 18 unchanged lines hidden (view full) ---

1322 MCLGET(m_new, M_DONTWAIT);
1323 if (!(m_new->m_flags & M_EXT)) {
1324 m_freem(m_new);
1325 printf("rl%d: no memory for tx list",
1326 sc->rl_unit);
1327 return(1);
1328 }
1329 }
1307
1308 return;
1309}
1310
1311/*
1312 * Encapsulate an mbuf chain in a descriptor by coupling the mbuf data
1313 * pointers to the fragment pointers.
1314 */

--- 18 unchanged lines hidden (view full) ---

1333 MCLGET(m_new, M_DONTWAIT);
1334 if (!(m_new->m_flags & M_EXT)) {
1335 m_freem(m_new);
1336 printf("rl%d: no memory for tx list",
1337 sc->rl_unit);
1338 return(1);
1339 }
1340 }
1330 m_copydata(m_head, 0, m_head->m_pkthdr.len,
1331 mtod(m_new, caddr_t));
1341 m_copydata(m_head, 0, m_head->m_pkthdr.len, mtod(m_new, caddr_t));
1332 m_new->m_pkthdr.len = m_new->m_len = m_head->m_pkthdr.len;
1333 m_freem(m_head);
1334 m_head = m_new;
1335
1336 /* Pad frames to at least 60 bytes. */
1337 if (m_head->m_pkthdr.len < RL_MIN_FRAMELEN) {
1338 m_head->m_pkthdr.len +=
1342 m_new->m_pkthdr.len = m_new->m_len = m_head->m_pkthdr.len;
1343 m_freem(m_head);
1344 m_head = m_new;
1345
1346 /* Pad frames to at least 60 bytes. */
1347 if (m_head->m_pkthdr.len < RL_MIN_FRAMELEN) {
1348 m_head->m_pkthdr.len +=
1339 (RL_MIN_FRAMELEN - m_head->m_pkthdr.len);
1349 (RL_MIN_FRAMELEN - m_head->m_pkthdr.len);
1340 m_head->m_len = m_head->m_pkthdr.len;
1341 }
1342
1343 RL_CUR_TXMBUF(sc) = m_head;
1344
1345 return(0);
1346}
1347

--- 24 unchanged lines hidden (view full) ---

1372 bpf_mtap(ifp, RL_CUR_TXMBUF(sc));
1373
1374 /*
1375 * Transmit the frame.
1376 */
1377 CSR_WRITE_4(sc, RL_CUR_TXADDR(sc),
1378 vtophys(mtod(RL_CUR_TXMBUF(sc), caddr_t)));
1379 CSR_WRITE_4(sc, RL_CUR_TXSTAT(sc),
1350 m_head->m_len = m_head->m_pkthdr.len;
1351 }
1352
1353 RL_CUR_TXMBUF(sc) = m_head;
1354
1355 return(0);
1356}
1357

--- 24 unchanged lines hidden (view full) ---

1382 bpf_mtap(ifp, RL_CUR_TXMBUF(sc));
1383
1384 /*
1385 * Transmit the frame.
1386 */
1387 CSR_WRITE_4(sc, RL_CUR_TXADDR(sc),
1388 vtophys(mtod(RL_CUR_TXMBUF(sc), caddr_t)));
1389 CSR_WRITE_4(sc, RL_CUR_TXSTAT(sc),
1380 RL_TX_EARLYTHRESH | RL_CUR_TXMBUF(sc)->m_pkthdr.len);
1390 RL_TXTHRESH(sc->rl_txthresh) |
1391 RL_CUR_TXMBUF(sc)->m_pkthdr.len);
1381
1382 RL_INC(sc->rl_cdata.cur_tx);
1383 }
1384
1385 /*
1386 * We broke out of the loop because all our TX slots are
1387 * full. Mark the NIC as busy until it drains some of the
1388 * packets from the queue.

--- 78 unchanged lines hidden (view full) ---

1467 */
1468 rl_setmulti(sc);
1469
1470 /*
1471 * Enable interrupts.
1472 */
1473 CSR_WRITE_2(sc, RL_IMR, RL_INTRS);
1474
1392
1393 RL_INC(sc->rl_cdata.cur_tx);
1394 }
1395
1396 /*
1397 * We broke out of the loop because all our TX slots are
1398 * full. Mark the NIC as busy until it drains some of the
1399 * packets from the queue.

--- 78 unchanged lines hidden (view full) ---

1478 */
1479 rl_setmulti(sc);
1480
1481 /*
1482 * Enable interrupts.
1483 */
1484 CSR_WRITE_2(sc, RL_IMR, RL_INTRS);
1485
1486 /* Set initial TX threshold */
1487 sc->rl_txthresh = RL_TX_THRESH_INIT;
1488
1475 /* Start RX/TX process. */
1476 CSR_WRITE_4(sc, RL_MISSEDPKT, 0);
1477
1478 /* Enable receiver and transmitter. */
1479 CSR_WRITE_1(sc, RL_COMMAND, RL_CMD_TX_ENB|RL_CMD_RX_ENB);
1480
1481 mii_mediachg(mii);
1482

--- 161 unchanged lines hidden ---
1489 /* Start RX/TX process. */
1490 CSR_WRITE_4(sc, RL_MISSEDPKT, 0);
1491
1492 /* Enable receiver and transmitter. */
1493 CSR_WRITE_1(sc, RL_COMMAND, RL_CMD_TX_ENB|RL_CMD_RX_ENB);
1494
1495 mii_mediachg(mii);
1496

--- 161 unchanged lines hidden ---