Skip to contentSkip to conversation

VIA "Velocity" Gigabit ethernet driver

PATCH In review Alan Cox 3 participants 5 messages May 26, 2004 – May 31, 2004

Subsystems (2)
lore
Share & tools
lore

Alan Cox

author
#0 lore raw

A cleaned up and 2.6 ported VIA velocity driver is now available on ftp://people/redhat.com/alan/Kernel/. This is an initial clean up and port to 2.6. It isn't by any means polished yet. Please send test results and patches to me (I don't currently read linux-kernel).

It should work on both 32 and 64bit little endian, it won't work on big endian boxes yet.

Alan

#1 lore raw

PATCH 1/1 : was Re: VIA "Velocity" Gigabit ethernet driver

Quoted 2 lines · On Wed, 26 May 2004 13:40:18 -0400 Alan Cox <[email protected]> wrote:

It should work on both 32 and 64bit little endian, it won't work on big endian boxes yet.

64-bit eh? :-)

velocity.h renamed from velocity.h.~1~ +2 -2
@@ -1628,8 +1628,8 @@
 	enum chip_type chip_id;
 
 	struct mac_regs * mac_regs;
-	u32 memaddr;
-	u32 ioaddr;
+	unsigned long memaddr;
+	unsigned long ioaddr;
 	u32 io_size;
 
 	u8 rev_id;
author
#2 lore raw

Re: [PATCH]: was Re: VIA "Velocity" Gigabit ethernet driver

Quoted 4 lines · David S. Miller
Quoted 2 lines

It should work on both 32 and 64bit little endian, it won't work on big endian boxes yet.

64-bit eh? :-)

Works on athlon64 .. will apply

#3 lore raw
In reply to Alan Cox

Alan Cox <[email protected]> :

Quoted 4 lines

A cleaned up and 2.6 ported VIA velocity driver is now available on ftp://people/redhat.com/alan/Kernel/. This is an initial clean up and port to 2.6. It isn't by any means polished yet. Please send test results and patches to me (I don't currently read linux-kernel).

Some polish attached. I'll probably do the rx_copybreak thing as well as some pci_dma_sync_single_for_{cpu/device} if nobody beats me.

Apparently there's no documentation available for the chipset, right ?

--
Ueimor

- missing pci_disable_device() in the pci probe/remove functions;
- ioremap can fail;
- let's propagate the error codes instead of overriding these;
- velocity_free_info() removed.

Non void velocity_get_pci_info() probably deserves an explanation but I do not have one :o)

 net/via-velocity.h         |    0 
 drivers/net/via-velocity.c |   81 ++++++++++++++++++---------------------------
 2 files changed, 34 insertions(+), 47 deletions(-)
drivers/net/via-velocity.c renamed from drivers/net/via-velocity.c~via-velocity-00 +34 -47
diff -puN drivers/net/via-velocity.c~via-velocity-00 drivers/net/via-velocity.c
@@ -244,7 +244,6 @@ VELOCITY_PARAM(int_works, "Number of pac
 
 static int velocity_found1(struct pci_dev *pdev, const struct pci_device_id *ent);
 static void velocity_init_info(struct pci_dev *pdev, struct velocity_info *vptr, struct velocity_info_tbl *info);
-static void velocity_free_info(struct velocity_info *vptr);
 static int velocity_get_pci_info(struct velocity_info *, struct pci_dev *pdev);
 static void velocity_print_info(struct velocity_info *vptr);
 static int velocity_open(struct net_device *dev);
@@ -341,11 +340,13 @@ static void __devexit velocity_remove1(s
 {
 	struct net_device *dev = pci_get_drvdata(pdev);
 	struct velocity_info *vptr = dev->priv;
+
 	unregister_netdev(dev);
-	velocity_free_info(vptr);
+	iounmap(vptr->mac_regs);
 	pci_release_regions(pdev);
+	pci_disable_device(pdev);
+	pci_set_drvdata(pdev, NULL);
 	free_netdev(dev);
-
 }
 
 /**
@@ -674,6 +675,7 @@ static int velocity_found1(struct pci_de
 	struct velocity_info_tbl *info = (struct velocity_info_tbl *) ent->driver_data;
 	struct velocity_info *vptr;
 	struct mac_regs * regs;
+	int ret = -ENOMEM;
 
 	if (velocity_nics++ >= MAX_UNITS) {
 		printk(KERN_NOTICE VELOCITY_NAME ": already found %d NICs.\n", 
@@ -685,7 +687,7 @@ static int velocity_found1(struct pci_de
 
 	if (dev == NULL) {
 		printk(KERN_ERR VELOCITY_NAME ": allocate net device failed.\n");
-		return -ENODEV;
+		goto out;
 	}
 	
 	/* Chain it all together */
@@ -710,28 +712,28 @@ static int velocity_found1(struct pci_de
 	dev->priv = vptr;
 	dev->irq = pdev->irq;
 
-	if (pci_enable_device(pdev)) {
-		velocity_free_info(vptr);
-		free_netdev(dev);
-		return -ENODEV;
-	}
+	ret = pci_enable_device(pdev);
+	if (ret < 0) 
+		goto err_free_dev;
 
-	if (velocity_get_pci_info(vptr, pdev) < 0) {
+	ret = velocity_get_pci_info(vptr, pdev);
+	if (ret < 0) {
 		printk(KERN_ERR VELOCITY_NAME ": Failed to find PCI device.\n");
-		velocity_free_info(vptr);
-		free_netdev(dev);
-		return -ENODEV;
+		goto err_disable;
 	}
 
-	if ((i = pci_request_regions(pdev, VELOCITY_NAME)) < 0) {
+	ret = pci_request_regions(pdev, VELOCITY_NAME);
+	if (ret < 0) {
 		printk(KERN_ERR VELOCITY_NAME ": Failed to find PCI device.\n");
-		vptr->ioaddr = 0;
-		velocity_free_info(vptr);
-		free_netdev(dev);
-		return i;
+		goto err_disable;
 	}
 
 	regs = ioremap(vptr->memaddr, vptr->io_size);
+	if (regs == NULL) {
+		ret = -EIO;
+		goto err_release_res;
+	}
+
 	vptr->mac_regs = regs;
 
 	mac_wol_reset(regs);
@@ -778,14 +780,9 @@ static int velocity_found1(struct pci_de
 		dev->features |= NETIF_F_HW_CSUM;
 	}
 
-	i = register_netdev (dev);
-	if (i)
-	{
-		pci_release_regions(pdev);
-		velocity_free_info(vptr);
-		free_netdev(dev);
-		return i;
-	}
+	ret = register_netdev(dev);
+	if (ret < 0)
+		goto err_iounmap;
 
 	velocity_print_info(vptr);
 	pci_set_drvdata(pdev, dev);
@@ -793,8 +790,18 @@ static int velocity_found1(struct pci_de
 	/* and leave the chip powered down */
 	
 	pci_set_power_state(pdev, 3);
+out:
+	return ret;
 
-	return 0;
+err_iounmap:
+	iounmap(regs);
+err_release_res:
+	pci_release_regions(pdev);
+err_disable:
+	pci_disable_device(pdev);
+err_free_dev:
+	free_netdev(dev);
+	goto out;
 }
 
 /**
@@ -864,26 +871,6 @@ static int velocity_get_pci_info(struct 
 }
 
 /**
- *	velocity_free_info	-	free velocity data
- *	@vptr: velocity
- *
- *	Free up the data structures for the velocity hardware
- *	that we are unloading. Relies on the PCI layer threading/locking
- *	rather than its own locks. Must not be called until the device
- *	is unplugged from the network layer
- */
- 
-static void velocity_free_info(struct velocity_info *vptr)
-{
-	ASSERT(vptr);
-	if (vptr->mac_regs)
-		iounmap(vptr->mac_regs);
-	if (vptr->pdev) {
-		pci_set_drvdata(vptr->pdev, NULL);
-	}
-}
-
-/**
  *	velocity_init_rings	-	set up DMA rings
  *	@vptr: Velocity to set up
  *

diff -puN drivers/net/via-velocity.h~via-velocity-00 drivers/net/via-velocity.h

_

1 - velocity_init_rings: no need to build an aligned memory buffer by hand

    as pci_alloc_consistent() does this part of the job;
2 - velocity_info.{pool/pool_dma} are not needed any more (see 1);
3 - vptr->{td_rings/td_pool_dma} init: 178 cols is a bit high...;
4 - velocity_free_rings(): let's balance the 64 bytes reduction of the
    Rx/Tx desc pool (see 1);
5 - velocity_free_rings(): vptr->tx_bufs == 0 can not happen;
6 - velocity_init_rd_ring(): fix leak when it has been called from dev->open()
    and fails;
7 - velocity_free_rd_ring(): ok, this one is a bit cosmetic but I could not
    resist when I noticed that vptr->rd_info was tested against NULL two
    times in the same function. The hunk can be safely removed if this is
    frowned upon;
8 - velocity_open(): fix leak and power down the device if something fails
    and it has been enabled;

9 - velocity_change_mtu: stop returning with spinlock_irq taken when memory
allocation fails.

 drivers/net/via-velocity.c |  144 +++++++++++++++++++++++++++++----------------
 drivers/net/via-velocity.h |    2 
 2 files changed, 94 insertions(+), 52 deletions(-)
drivers/net/via-velocity.c renamed from drivers/net/via-velocity.c~via-velocity-01 +94 -50

263 lines not on this page · raw message

drivers/net/via-velocity.h renamed from drivers/net/via-velocity.h~via-velocity-01 +0 -2
diff -puN drivers/net/via-velocity.h~via-velocity-01 drivers/net/via-velocity.h
@@ -1751,8 +1751,6 @@ struct velocity_info {
 	u32 pci_state[16];
 #endif
 
-	void *pool;
-	dma_addr_t pool_dma;
 	dma_addr_t rd_pool_dma;
 	dma_addr_t td_pool_dma[TX_QUEUE_NO];
 

_

author
#4 lore raw
Quoted 4 lines · Francois Romieu

Some polish attached. I'll probably do the rx_copybreak thing as well as some pci_dma_sync_single_for_{cpu/device} if nobody beats me.

Apparently there's no documentation available for the chipset, right ?

I have some documentation but its not what I would call complete. The docs are marked NDA etc etc but identical to the ones you'll find included with the current driver zip (the .exe is also a zip) on viaarena ;)