Deleted Added
full compact
if_re.c (217832) if_re.c (217857)
1/*-
2 * Copyright (c) 1997, 1998-2003
3 * Bill Paul <wpaul@windriver.com>. 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-2003
3 * Bill Paul <wpaul@windriver.com>. 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/re/if_re.c 217832 2011-01-25 19:05:46Z yongari $");
34__FBSDID("$FreeBSD: head/sys/dev/re/if_re.c 217857 2011-01-25 22:18:00Z yongari $");
35
36/*
37 * RealTek 8139C+/8169/8169S/8110S/8168/8111/8101E PCI NIC driver
38 *
39 * Written by Bill Paul <wpaul@windriver.com>
40 * Senior Networking Software Engineer
41 * Wind River Systems
42 */

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

154MODULE_DEPEND(re, miibus, 1, 1, 1);
155
156/* "device miibus" required. See GENERIC if you get errors here. */
157#include "miibus_if.h"
158
159/* Tunables. */
160static int msi_disable = 0;
161TUNABLE_INT("hw.re.msi_disable", &msi_disable);
35
36/*
37 * RealTek 8139C+/8169/8169S/8110S/8168/8111/8101E PCI NIC driver
38 *
39 * Written by Bill Paul <wpaul@windriver.com>
40 * Senior Networking Software Engineer
41 * Wind River Systems
42 */

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

154MODULE_DEPEND(re, miibus, 1, 1, 1);
155
156/* "device miibus" required. See GENERIC if you get errors here. */
157#include "miibus_if.h"
158
159/* Tunables. */
160static int msi_disable = 0;
161TUNABLE_INT("hw.re.msi_disable", &msi_disable);
162static int msix_disable = 0;
163TUNABLE_INT("hw.re.msix_disable", &msix_disable);
162static int prefer_iomap = 0;
163TUNABLE_INT("hw.re.prefer_iomap", &prefer_iomap);
164
165#define RE_CSUM_FEATURES (CSUM_IP | CSUM_TCP | CSUM_UDP)
166
167/*
168 * Various supported device vendors/types and their names.
169 */

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

1171 u_char eaddr[ETHER_ADDR_LEN];
1172 u_int16_t as[ETHER_ADDR_LEN / 2];
1173 struct rl_softc *sc;
1174 struct ifnet *ifp;
1175 struct rl_hwrev *hw_rev;
1176 int hwrev;
1177 u_int16_t devid, re_did = 0;
1178 int error = 0, i, phy, rid;
164static int prefer_iomap = 0;
165TUNABLE_INT("hw.re.prefer_iomap", &prefer_iomap);
166
167#define RE_CSUM_FEATURES (CSUM_IP | CSUM_TCP | CSUM_UDP)
168
169/*
170 * Various supported device vendors/types and their names.
171 */

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

1173 u_char eaddr[ETHER_ADDR_LEN];
1174 u_int16_t as[ETHER_ADDR_LEN / 2];
1175 struct rl_softc *sc;
1176 struct ifnet *ifp;
1177 struct rl_hwrev *hw_rev;
1178 int hwrev;
1179 u_int16_t devid, re_did = 0;
1180 int error = 0, i, phy, rid;
1179 int msic, reg;
1181 int msic, msixc, reg;
1180 uint8_t cfg;
1181
1182 sc = device_get_softc(dev);
1183 sc->rl_dev = dev;
1184
1185 mtx_init(&sc->rl_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
1186 MTX_DEF);
1187 callout_init_mtx(&sc->rl_stat_callout, &sc->rl_mtx, 0);

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

1221 device_printf(dev, "couldn't map ports/memory\n");
1222 error = ENXIO;
1223 goto fail;
1224 }
1225
1226 sc->rl_btag = rman_get_bustag(sc->rl_res);
1227 sc->rl_bhandle = rman_get_bushandle(sc->rl_res);
1228
1182 uint8_t cfg;
1183
1184 sc = device_get_softc(dev);
1185 sc->rl_dev = dev;
1186
1187 mtx_init(&sc->rl_mtx, device_get_nameunit(dev), MTX_NETWORK_LOCK,
1188 MTX_DEF);
1189 callout_init_mtx(&sc->rl_stat_callout, &sc->rl_mtx, 0);

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

1223 device_printf(dev, "couldn't map ports/memory\n");
1224 error = ENXIO;
1225 goto fail;
1226 }
1227
1228 sc->rl_btag = rman_get_bustag(sc->rl_res);
1229 sc->rl_bhandle = rman_get_bushandle(sc->rl_res);
1230
1229 msic = 0;
1230 if (pci_find_extcap(dev, PCIY_EXPRESS, &reg) == 0) {
1231 msic = pci_msi_count(dev);
1232 msixc = pci_msix_count(dev);
1233 if (pci_find_extcap(dev, PCIY_EXPRESS, &reg) == 0)
1231 sc->rl_flags |= RL_FLAG_PCIE;
1234 sc->rl_flags |= RL_FLAG_PCIE;
1232 msic = pci_msi_count(dev);
1233 if (bootverbose)
1234 device_printf(dev, "MSI count : %d\n", msic);
1235 if (bootverbose) {
1236 device_printf(dev, "MSI count : %d\n", msic);
1237 device_printf(dev, "MSI-X count : %d\n", msixc);
1235 }
1238 }
1236 if (msic > 0 && msi_disable == 0) {
1239 if (msix_disable > 0)
1240 msixc = 0;
1241 if (msi_disable > 0)
1242 msic = 0;
1243 /* Prefer MSI-X to MSI. */
1244 if (msixc > 0) {
1245 msixc = 1;
1246 rid = PCIR_BAR(4);
1247 sc->rl_res_pba = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
1248 &rid, RF_ACTIVE);
1249 if (sc->rl_res_pba == NULL) {
1250 device_printf(sc->rl_dev,
1251 "could not allocate MSI-X PBA resource\n");
1252 }
1253 if (sc->rl_res_pba != NULL &&
1254 pci_alloc_msix(dev, &msixc) == 0) {
1255 if (msixc == 1) {
1256 device_printf(dev, "Using %d MSI-X message\n",
1257 msixc);
1258 sc->rl_flags |= RL_FLAG_MSIX;
1259 } else
1260 pci_release_msi(dev);
1261 }
1262 if ((sc->rl_flags & RL_FLAG_MSIX) == 0) {
1263 if (sc->rl_res_pba != NULL)
1264 bus_release_resource(dev, SYS_RES_MEMORY, rid,
1265 sc->rl_res_pba);
1266 sc->rl_res_pba = NULL;
1267 msixc = 0;
1268 }
1269 }
1270 /* Prefer MSI to INTx. */
1271 if (msixc == 0 && msic > 0) {
1237 msic = 1;
1238 if (pci_alloc_msi(dev, &msic) == 0) {
1239 if (msic == RL_MSI_MESSAGES) {
1272 msic = 1;
1273 if (pci_alloc_msi(dev, &msic) == 0) {
1274 if (msic == RL_MSI_MESSAGES) {
1240 device_printf(dev, "Using %d MSI messages\n",
1275 device_printf(dev, "Using %d MSI message\n",
1241 msic);
1242 sc->rl_flags |= RL_FLAG_MSI;
1243 /* Explicitly set MSI enable bit. */
1244 CSR_WRITE_1(sc, RL_EECMD, RL_EE_MODE);
1245 cfg = CSR_READ_1(sc, RL_CFG2);
1246 cfg |= RL_CFG2_MSI;
1247 CSR_WRITE_1(sc, RL_CFG2, cfg);
1248 CSR_WRITE_1(sc, RL_EECMD, RL_EEMODE_OFF);
1249 } else
1250 pci_release_msi(dev);
1251 }
1276 msic);
1277 sc->rl_flags |= RL_FLAG_MSI;
1278 /* Explicitly set MSI enable bit. */
1279 CSR_WRITE_1(sc, RL_EECMD, RL_EE_MODE);
1280 cfg = CSR_READ_1(sc, RL_CFG2);
1281 cfg |= RL_CFG2_MSI;
1282 CSR_WRITE_1(sc, RL_CFG2, cfg);
1283 CSR_WRITE_1(sc, RL_EECMD, RL_EEMODE_OFF);
1284 } else
1285 pci_release_msi(dev);
1286 }
1287 if ((sc->rl_flags & RL_FLAG_MSI) == 0)
1288 msic = 0;
1252 }
1253
1254 /* Allocate interrupt */
1289 }
1290
1291 /* Allocate interrupt */
1255 if ((sc->rl_flags & RL_FLAG_MSI) == 0) {
1292 if ((sc->rl_flags & (RL_FLAG_MSI | RL_FLAG_MSIX)) == 0) {
1256 rid = 0;
1257 sc->rl_irq[0] = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
1258 RF_SHAREABLE | RF_ACTIVE);
1259 if (sc->rl_irq[0] == NULL) {
1260 device_printf(dev, "couldn't allocate IRQ resources\n");
1261 error = ENXIO;
1262 goto fail;
1263 }

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

1534 "attach aborted due to hardware diag failure\n");
1535 ether_ifdetach(ifp);
1536 goto fail;
1537 }
1538 }
1539#endif
1540
1541 /* Hook interrupt last to avoid having to lock softc */
1293 rid = 0;
1294 sc->rl_irq[0] = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
1295 RF_SHAREABLE | RF_ACTIVE);
1296 if (sc->rl_irq[0] == NULL) {
1297 device_printf(dev, "couldn't allocate IRQ resources\n");
1298 error = ENXIO;
1299 goto fail;
1300 }

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

1571 "attach aborted due to hardware diag failure\n");
1572 ether_ifdetach(ifp);
1573 goto fail;
1574 }
1575 }
1576#endif
1577
1578 /* Hook interrupt last to avoid having to lock softc */
1542 if ((sc->rl_flags & RL_FLAG_MSI) == 0)
1579 if ((sc->rl_flags & (RL_FLAG_MSI | RL_FLAG_MSIX)) == 0)
1543 error = bus_setup_intr(dev, sc->rl_irq[0],
1544 INTR_TYPE_NET | INTR_MPSAFE, re_intr, NULL, sc,
1545 &sc->rl_intrhand[0]);
1546 else {
1547 for (i = 0; i < RL_MSI_MESSAGES; i++) {
1548 error = bus_setup_intr(dev, sc->rl_irq[i],
1549 INTR_TYPE_NET | INTR_MPSAFE, re_intr, NULL, sc,
1550 &sc->rl_intrhand[i]);

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

1626 if (sc->rl_intrhand[i] != NULL) {
1627 bus_teardown_intr(dev, sc->rl_irq[i],
1628 sc->rl_intrhand[i]);
1629 sc->rl_intrhand[i] = NULL;
1630 }
1631 }
1632 if (ifp != NULL)
1633 if_free(ifp);
1580 error = bus_setup_intr(dev, sc->rl_irq[0],
1581 INTR_TYPE_NET | INTR_MPSAFE, re_intr, NULL, sc,
1582 &sc->rl_intrhand[0]);
1583 else {
1584 for (i = 0; i < RL_MSI_MESSAGES; i++) {
1585 error = bus_setup_intr(dev, sc->rl_irq[i],
1586 INTR_TYPE_NET | INTR_MPSAFE, re_intr, NULL, sc,
1587 &sc->rl_intrhand[i]);

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

1663 if (sc->rl_intrhand[i] != NULL) {
1664 bus_teardown_intr(dev, sc->rl_irq[i],
1665 sc->rl_intrhand[i]);
1666 sc->rl_intrhand[i] = NULL;
1667 }
1668 }
1669 if (ifp != NULL)
1670 if_free(ifp);
1634 if ((sc->rl_flags & RL_FLAG_MSI) == 0) {
1671 if ((sc->rl_flags & (RL_FLAG_MSI | RL_FLAG_MSIX)) == 0) {
1635 if (sc->rl_irq[0] != NULL) {
1636 bus_release_resource(dev, SYS_RES_IRQ, 0,
1637 sc->rl_irq[0]);
1638 sc->rl_irq[0] = NULL;
1639 }
1640 } else {
1641 for (i = 0, rid = 1; i < RL_MSI_MESSAGES; i++, rid++) {
1642 if (sc->rl_irq[i] != NULL) {
1643 bus_release_resource(dev, SYS_RES_IRQ, rid,
1644 sc->rl_irq[i]);
1645 sc->rl_irq[i] = NULL;
1646 }
1647 }
1648 pci_release_msi(dev);
1649 }
1672 if (sc->rl_irq[0] != NULL) {
1673 bus_release_resource(dev, SYS_RES_IRQ, 0,
1674 sc->rl_irq[0]);
1675 sc->rl_irq[0] = NULL;
1676 }
1677 } else {
1678 for (i = 0, rid = 1; i < RL_MSI_MESSAGES; i++, rid++) {
1679 if (sc->rl_irq[i] != NULL) {
1680 bus_release_resource(dev, SYS_RES_IRQ, rid,
1681 sc->rl_irq[i]);
1682 sc->rl_irq[i] = NULL;
1683 }
1684 }
1685 pci_release_msi(dev);
1686 }
1687 if (sc->rl_res_pba) {
1688 rid = PCIR_BAR(4);
1689 bus_release_resource(dev, SYS_RES_MEMORY, rid, sc->rl_res_pba);
1690 }
1650 if (sc->rl_res)
1651 bus_release_resource(dev, sc->rl_res_type, sc->rl_res_id,
1652 sc->rl_res);
1653
1654 /* Unload and free the RX DMA ring memory and map */
1655
1656 if (sc->rl_ldata.rl_rx_list_tag) {
1657 if (sc->rl_ldata.rl_rx_list_map)

--- 1930 unchanged lines hidden ---
1691 if (sc->rl_res)
1692 bus_release_resource(dev, sc->rl_res_type, sc->rl_res_id,
1693 sc->rl_res);
1694
1695 /* Unload and free the RX DMA ring memory and map */
1696
1697 if (sc->rl_ldata.rl_rx_list_tag) {
1698 if (sc->rl_ldata.rl_rx_list_map)

--- 1930 unchanged lines hidden ---