Skip to content

Commit eb58134

Browse files
Dave JonesJeff Garzik
authored andcommitted
8139too: Make PIO/MMIO a runtime decision through a module parameter.
This is needed to support devices that only work with PIO without penalising devices that work fine with MMIO in distro kernels. It also allows us to eventually use PIO as a fallback when setting up MMIO fails. Signed-off-by: Dave Jones <davej@redhat.com> Signed-off-by: Jeff Garzik <jgarzik@redhat.com>
1 parent 7239016 commit eb58134

File tree

1 file changed

+64
-64
lines changed

1 file changed

+64
-64
lines changed

drivers/net/8139too.c

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
#include <linux/compiler.h>
9999
#include <linux/pci.h>
100100
#include <linux/init.h>
101-
#include <linux/ioport.h>
102101
#include <linux/netdevice.h>
103102
#include <linux/etherdevice.h>
104103
#include <linux/rtnetlink.h>
@@ -120,11 +119,6 @@
120119
NETIF_MSG_LINK)
121120

122121

123-
/* enable PIO instead of MMIO, if CONFIG_8139TOO_PIO is selected */
124-
#ifdef CONFIG_8139TOO_PIO
125-
#define USE_IO_OPS 1
126-
#endif
127-
128122
/* define to 1, 2 or 3 to enable copious debugging info */
129123
#define RTL8139_DEBUG 0
130124

@@ -156,6 +150,13 @@
156150
static int media[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
157151
static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
158152

153+
/* Whether to use MMIO or PIO. Default to MMIO. */
154+
#ifdef CONFIG_8139TOO_PIO
155+
static int use_io = 1;
156+
#else
157+
static int use_io = 0;
158+
#endif
159+
159160
/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast).
160161
The RTL chips use a 64 element hash table based on the Ethernet CRC. */
161162
static int multicast_filter_limit = 32;
@@ -614,6 +615,8 @@ MODULE_DESCRIPTION ("RealTek RTL-8139 Fast Ethernet driver");
614615
MODULE_LICENSE("GPL");
615616
MODULE_VERSION(DRV_VERSION);
616617

618+
module_param(use_io, int, 0);
619+
MODULE_PARM_DESC(use_io, "Force use of I/O access mode. 0=MMIO 1=PIO");
617620
module_param(multicast_filter_limit, int, 0);
618621
module_param_array(media, int, NULL, 0);
619622
module_param_array(full_duplex, int, NULL, 0);
@@ -709,13 +712,8 @@ static void __rtl8139_cleanup_dev (struct net_device *dev)
709712
assert (tp->pci_dev != NULL);
710713
pdev = tp->pci_dev;
711714

712-
#ifdef USE_IO_OPS
713-
if (tp->mmio_addr)
714-
ioport_unmap (tp->mmio_addr);
715-
#else
716715
if (tp->mmio_addr)
717716
pci_iounmap (pdev, tp->mmio_addr);
718-
#endif /* USE_IO_OPS */
719717

720718
/* it's ok to call this even if we have no regions to free */
721719
pci_release_regions (pdev);
@@ -790,32 +788,32 @@ static int __devinit rtl8139_init_board (struct pci_dev *pdev,
790788
DPRINTK("PIO region size == 0x%02X\n", pio_len);
791789
DPRINTK("MMIO region size == 0x%02lX\n", mmio_len);
792790

793-
#ifdef USE_IO_OPS
794-
/* make sure PCI base addr 0 is PIO */
795-
if (!(pio_flags & IORESOURCE_IO)) {
796-
dev_err(&pdev->dev, "region #0 not a PIO resource, aborting\n");
797-
rc = -ENODEV;
798-
goto err_out;
799-
}
800-
/* check for weird/broken PCI region reporting */
801-
if (pio_len < RTL_MIN_IO_SIZE) {
802-
dev_err(&pdev->dev, "Invalid PCI I/O region size(s), aborting\n");
803-
rc = -ENODEV;
804-
goto err_out;
805-
}
806-
#else
807-
/* make sure PCI base addr 1 is MMIO */
808-
if (!(mmio_flags & IORESOURCE_MEM)) {
809-
dev_err(&pdev->dev, "region #1 not an MMIO resource, aborting\n");
810-
rc = -ENODEV;
811-
goto err_out;
812-
}
813-
if (mmio_len < RTL_MIN_IO_SIZE) {
814-
dev_err(&pdev->dev, "Invalid PCI mem region size(s), aborting\n");
815-
rc = -ENODEV;
816-
goto err_out;
791+
if (use_io) {
792+
/* make sure PCI base addr 0 is PIO */
793+
if (!(pio_flags & IORESOURCE_IO)) {
794+
dev_err(&pdev->dev, "region #0 not a PIO resource, aborting\n");
795+
rc = -ENODEV;
796+
goto err_out;
797+
}
798+
/* check for weird/broken PCI region reporting */
799+
if (pio_len < RTL_MIN_IO_SIZE) {
800+
dev_err(&pdev->dev, "Invalid PCI I/O region size(s), aborting\n");
801+
rc = -ENODEV;
802+
goto err_out;
803+
}
804+
} else {
805+
/* make sure PCI base addr 1 is MMIO */
806+
if (!(mmio_flags & IORESOURCE_MEM)) {
807+
dev_err(&pdev->dev, "region #1 not an MMIO resource, aborting\n");
808+
rc = -ENODEV;
809+
goto err_out;
810+
}
811+
if (mmio_len < RTL_MIN_IO_SIZE) {
812+
dev_err(&pdev->dev, "Invalid PCI mem region size(s), aborting\n");
813+
rc = -ENODEV;
814+
goto err_out;
815+
}
817816
}
818-
#endif
819817

820818
rc = pci_request_regions (pdev, DRV_NAME);
821819
if (rc)
@@ -825,28 +823,27 @@ static int __devinit rtl8139_init_board (struct pci_dev *pdev,
825823
/* enable PCI bus-mastering */
826824
pci_set_master (pdev);
827825

828-
#ifdef USE_IO_OPS
829-
ioaddr = ioport_map(pio_start, pio_len);
830-
if (!ioaddr) {
831-
dev_err(&pdev->dev, "cannot map PIO, aborting\n");
832-
rc = -EIO;
833-
goto err_out;
834-
}
835-
dev->base_addr = pio_start;
836-
tp->mmio_addr = ioaddr;
837-
tp->regs_len = pio_len;
838-
#else
839-
/* ioremap MMIO region */
840-
ioaddr = pci_iomap(pdev, 1, 0);
841-
if (ioaddr == NULL) {
842-
dev_err(&pdev->dev, "cannot remap MMIO, aborting\n");
843-
rc = -EIO;
844-
goto err_out;
826+
if (use_io) {
827+
ioaddr = pci_iomap(pdev, 0, 0);
828+
if (!ioaddr) {
829+
dev_err(&pdev->dev, "cannot map PIO, aborting\n");
830+
rc = -EIO;
831+
goto err_out;
832+
}
833+
dev->base_addr = pio_start;
834+
tp->regs_len = pio_len;
835+
} else {
836+
/* ioremap MMIO region */
837+
ioaddr = pci_iomap(pdev, 1, 0);
838+
if (ioaddr == NULL) {
839+
dev_err(&pdev->dev, "cannot remap MMIO, aborting\n");
840+
rc = -EIO;
841+
goto err_out;
842+
}
843+
dev->base_addr = (long) ioaddr;
844+
tp->regs_len = mmio_len;
845845
}
846-
dev->base_addr = (long) ioaddr;
847846
tp->mmio_addr = ioaddr;
848-
tp->regs_len = mmio_len;
849-
#endif /* USE_IO_OPS */
850847

851848
/* Bring old chips out of low-power mode. */
852849
RTL_W8 (HltClk, 'R');
@@ -2381,28 +2378,31 @@ static void rtl8139_set_msglevel(struct net_device *dev, u32 datum)
23812378
np->msg_enable = datum;
23822379
}
23832380

2384-
/* TODO: we are too slack to do reg dumping for pio, for now */
2385-
#ifdef CONFIG_8139TOO_PIO
2386-
#define rtl8139_get_regs_len NULL
2387-
#define rtl8139_get_regs NULL
2388-
#else
23892381
static int rtl8139_get_regs_len(struct net_device *dev)
23902382
{
2391-
struct rtl8139_private *np = netdev_priv(dev);
2383+
struct rtl8139_private *np;
2384+
/* TODO: we are too slack to do reg dumping for pio, for now */
2385+
if (use_io)
2386+
return 0;
2387+
np = netdev_priv(dev);
23922388
return np->regs_len;
23932389
}
23942390

23952391
static void rtl8139_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *regbuf)
23962392
{
2397-
struct rtl8139_private *np = netdev_priv(dev);
2393+
struct rtl8139_private *np;
2394+
2395+
/* TODO: we are too slack to do reg dumping for pio, for now */
2396+
if (use_io)
2397+
return;
2398+
np = netdev_priv(dev);
23982399

23992400
regs->version = RTL_REGS_VER;
24002401

24012402
spin_lock_irq(&np->lock);
24022403
memcpy_fromio(regbuf, np->mmio_addr, regs->len);
24032404
spin_unlock_irq(&np->lock);
24042405
}
2405-
#endif /* CONFIG_8139TOO_MMIO */
24062406

24072407
static int rtl8139_get_sset_count(struct net_device *dev, int sset)
24082408
{

0 commit comments

Comments
 (0)