8139too: wrong I/O size

Daniel Kobras daniel.kobras@student.uni-tuebingen.de
Sun Feb 20 12:02:24 2000


Hi Jeff!

I found out why 8139too (as in 2.3.46) refused to load on my machine: 
You define RTL_IO_SIZE to 256 while my card only registers a window of 128
byte. As the larger size apparently works for you, I suspect there are
different configs floating around. Defining RTL_IO_SIZE to 128 is one way
to fix it, the patch below maybe is a bit cleaner.

Regards,

Daniel.

--[snip]--

--- 8139too.c.orig	Sun Feb 20 16:22:26 2000
+++ 8139too.c	Sun Feb 20 16:52:14 2000
@@ -154,8 +154,6 @@
 	HAS_LNK_CHNG = 0x040000,
 };
 
-#define RTL_IO_SIZE 256
-
 #define RTL8139_CAPS  HAS_CHIP_XCVR|HAS_LNK_CHNG
 
 typedef enum {
@@ -243,6 +241,8 @@
 	PARA7c = 0x7c,		/* Magic transceiver parameter register. */
 };
 
+#define RTL_IO_WIDTH	0x7f
+
 enum ChipCmdBits {
 	CmdReset = 0x10,
 	CmdRxEnb = 0x08,
@@ -437,8 +437,8 @@
 	void *ioaddr = NULL;
 	u8 tmp8;
 	int rc;
-	u32 pio_start, pio_end, pio_flags;
-	u32 mmio_start, mmio_end, mmio_flags;
+	u32 pio_start, pio_end, pio_size, pio_flags;
+	u32 mmio_start, mmio_end, mmio_size, mmio_flags;
 
 	DPRINTK ("ENTER\n");
 
@@ -449,12 +449,20 @@
 
 	pio_start = pci_resource_start (pdev, 0);
 	pio_end = pci_resource_end (pdev, 0);
+	pio_size = pio_end - pio_start + 1;
 	pio_flags = pci_resource_flags (pdev, 0);
 
 	mmio_start = pci_resource_start (pdev, 1);
 	mmio_end = pci_resource_end (pdev, 1);
+	mmio_size = mmio_end - mmio_start + 1;
 	mmio_flags = pci_resource_flags (pdev, 1);
 
+	/* make sure IO window is large enough */
+	if (pio_size <= RTL_IO_WIDTH || mmio_size <= RTL_IO_WIDTH) {
+		printk (KERN_ERR PFX "I/O window too small, aborting\n");
+		return -ENODEV;
+	}
+	
 	/* make sure PCI base addr 0 is PIO */
 	if (pio_start == 0 || pio_end <= pio_start ||
 	    (!(pio_flags & IORESOURCE_IO))) {
@@ -470,14 +478,14 @@
 	}
 
 	/* make sure our PIO region in PCI space is available */
-	if (!request_region (pio_start, RTL_IO_SIZE, RTL8139_MODULE_NAME)) {
+	if (!request_region (pio_start, pio_size, RTL8139_MODULE_NAME)) {
 		printk (KERN_ERR PFX "no I/O resource available, aborting\n");
 		return -EBUSY;
 	}
 	
 	/* make sure our MMIO region in PCI space is available */
-	if (!request_mem_region (mmio_start, RTL_IO_SIZE, RTL8139_MODULE_NAME)) {
-		release_region (pio_start, RTL_IO_SIZE);
+	if (!request_mem_region (mmio_start, mmio_size, RTL8139_MODULE_NAME)) {
+		release_region (pio_start, pio_size);
 		printk (KERN_ERR PFX "no mem resource available, aborting\n");
 		return -EBUSY;
 	}
@@ -487,7 +495,7 @@
 	pci_set_master (pdev);
 
 	/* ioremap MMIO region */
-	ioaddr = ioremap (mmio_start, RTL_IO_SIZE);
+	ioaddr = ioremap (mmio_start, mmio_size);
 	if (ioaddr == NULL) {
 		printk (KERN_ERR PFX "cannot remap MMIO, aborting\n");
 		rc = -EIO;
@@ -523,8 +531,8 @@
 err_out:
 	if (ioaddr)
 		iounmap (ioaddr);
-	release_region (pio_start, RTL_IO_SIZE);
-	release_mem_region (mmio_start, RTL_IO_SIZE);
+	release_region (pio_start, pio_size);
+	release_mem_region (mmio_start, mmio_size);
 	DPRINTK ("EXIT, returning %d\n", rc);
 	return rc;
 }
@@ -641,8 +649,12 @@
 	unregister_netdev (dev);
 
 	iounmap (np->mmio_addr);
-	release_region (pci_resource_start (pdev, 0), RTL_IO_SIZE);
-	release_mem_region (pci_resource_start (pdev, 1), RTL_IO_SIZE);
+	release_region (pci_resource_start (pdev, 0), 
+	                pci_resource_end (pdev, 0) - 
+	                pci_resource_start (pdev, 0) + 1);
+	release_mem_region (pci_resource_start (pdev, 1), 
+	                    pci_resource_end (pdev, 1) -
+	                    pci_resource_start (pdev, 1) + 1);
 
 #ifndef RTL8139_NDEBUG
 	/* poison memory before freeing */
@@ -1865,6 +1877,8 @@
 		printk (KERN_INFO RTL8139_DRIVER_NAME
 			" loaded (%d device%s registered)\n",
 			rc, rc > 1 ? "s" : "");
+	} else {
+		pci_unregister_driver (&rtl8139_pci_driver);
 	}
 
 	DPRINTK ("EXIT\n");


 | To unsubscribe, send mail to Majordomo@cesdis.gsfc.nasa.gov, and within the
 |  body of the mail, include only the text:
 |   unsubscribe this-list-name youraddress@wherever.org
 | You will be unsubscribed as speedily as possible.