Commit 4e37e73e authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

USB: convert the drivers/usb/net files to the new USB driver model.

Note the cdc-ether.c driver does NOT work properly now, someone who 
understands the interface mess in that driver needs to fix it up.
parent 20c741ec
......@@ -761,28 +761,29 @@ static int catc_stop(struct net_device *netdev)
* USB probe, disconnect.
*/
static void *catc_probe(struct usb_device *usbdev, unsigned int ifnum, const struct usb_device_id *id)
static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id)
{
struct usb_device *usbdev = interface_to_usbdev(intf);
struct net_device *netdev;
struct catc *catc;
u8 broadcast[6];
int i, pktsz;
if (usb_set_interface(usbdev, ifnum, 1)) {
if (usb_set_interface(usbdev, intf->altsetting->bInterfaceNumber, 1)) {
err("Can't set altsetting 1.");
return NULL;
return -EIO;
}
catc = kmalloc(sizeof(struct catc), GFP_KERNEL);
if (!catc)
return NULL;
return -ENOMEM;
memset(catc, 0, sizeof(struct catc));
netdev = init_etherdev(0, 0);
if (!netdev) {
kfree(catc);
return NULL;
return -EIO;
}
netdev->open = catc_open;
......@@ -818,7 +819,7 @@ static void *catc_probe(struct usb_device *usbdev, unsigned int ifnum, const str
if (catc->irq_urb) usb_free_urb(catc->irq_urb);
kfree(netdev);
kfree(catc);
return NULL;
return -ENOMEM;
}
/* The F5U011 has the same vendor/product as the netmate but a device version of 0x130 */
......@@ -907,24 +908,29 @@ static void *catc_probe(struct usb_device *usbdev, unsigned int ifnum, const str
f5u011_rxmode(catc, catc->rxmode);
}
dbg("Init done.");
printk(KERN_INFO "%s: %s USB Ethernet at usb-%s-%s/%d, ",
printk(KERN_INFO "%s: %s USB Ethernet at usb-%s-%s, ",
netdev->name, (catc->is_f5u011) ? "Belkin F5U011" : "CATC EL1210A NetMate",
usbdev->bus->bus_name, usbdev->devpath, ifnum);
usbdev->bus->bus_name, usbdev->devpath);
for (i = 0; i < 5; i++) printk("%2.2x:", netdev->dev_addr[i]);
printk("%2.2x.\n", netdev->dev_addr[i]);
return catc;
dev_set_drvdata (&intf->dev, catc);
return 0;
}
static void catc_disconnect(struct usb_device *usbdev, void *dev_ptr)
static void catc_disconnect(struct usb_interface *intf)
{
struct catc *catc = dev_ptr;
unregister_netdev(catc->netdev);
usb_free_urb(catc->ctrl_urb);
usb_free_urb(catc->tx_urb);
usb_free_urb(catc->rx_urb);
usb_free_urb(catc->irq_urb);
kfree(catc->netdev);
kfree(catc);
struct catc *catc = dev_get_drvdata (&intf->dev);
dev_set_drvdata (&intf->dev, NULL);
if (catc) {
unregister_netdev(catc->netdev);
usb_free_urb(catc->ctrl_urb);
usb_free_urb(catc->tx_urb);
usb_free_urb(catc->rx_urb);
usb_free_urb(catc->irq_urb);
kfree(catc->netdev);
kfree(catc);
}
}
/*
......
......@@ -1123,9 +1123,10 @@ static struct usb_driver CDCEther_driver ;
// claims interfaces if they are for an Ethernet CDC /////////////////////////
//////////////////////////////////////////////////////////////////////////////
static void * CDCEther_probe( struct usb_device *usb, unsigned int ifnum,
const struct usb_device_id *id)
static int CDCEther_probe( struct usb_interface *intf,
const struct usb_device_id *id)
{
struct usb_device *usb = interface_to_usbdev(intf);
struct net_device *net;
ether_dev_t *ether_dev;
int rc;
......@@ -1135,7 +1136,7 @@ static void * CDCEther_probe( struct usb_device *usb, unsigned int ifnum,
if ( check_for_claimed_interfaces( usb->actconfig ) ) {
// Someone has already put there grubby paws on this device.
// We don't want it now...
return NULL;
return -ENODEV;
}
// We might be finding a device we can use.
......@@ -1144,7 +1145,7 @@ static void * CDCEther_probe( struct usb_device *usb, unsigned int ifnum,
// we are going to need later.
if(!(ether_dev = kmalloc(sizeof(ether_dev_t), GFP_KERNEL))) {
err("out of memory allocating device structure");
return NULL;
return -ENOMEM;
}
// Zero everything out.
......@@ -1153,20 +1154,20 @@ static void * CDCEther_probe( struct usb_device *usb, unsigned int ifnum,
ether_dev->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
if (!ether_dev->rx_urb) {
kfree(ether_dev);
return NULL;
return -ENOMEM;
}
ether_dev->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
if (!ether_dev->tx_urb) {
usb_free_urb(ether_dev->rx_urb);
kfree(ether_dev);
return NULL;
return -ENOMEM;
}
ether_dev->intr_urb = usb_alloc_urb(0, GFP_KERNEL);
if (!ether_dev->intr_urb) {
usb_free_urb(ether_dev->tx_urb);
usb_free_urb(ether_dev->rx_urb);
kfree(ether_dev);
return NULL;
return -ENOMEM;
}
// Let's see if we can find a configuration we can use.
......@@ -1261,8 +1262,12 @@ static void * CDCEther_probe( struct usb_device *usb, unsigned int ifnum,
// TODO - last minute HACK
ether_dev->comm_ep_in = 5;
/* FIXME!!! This driver needs to be fixed to work with the new USB interface logic
* this is not the correct thing to be doing here, we need to set the interface
* driver specific data field.
*/
// Okay, we are finally done...
return NULL;
return 0;
// bailing out with our tail between our knees
error_all:
......@@ -1270,7 +1275,7 @@ static void * CDCEther_probe( struct usb_device *usb, unsigned int ifnum,
usb_free_urb(ether_dev->rx_urb);
usb_free_urb(ether_dev->intr_urb);
kfree( ether_dev );
return NULL;
return -EIO;
}
......@@ -1280,9 +1285,12 @@ static void * CDCEther_probe( struct usb_device *usb, unsigned int ifnum,
// (Whichever happens first assuming the driver suceeded at its probe) ///////
//////////////////////////////////////////////////////////////////////////////
static void CDCEther_disconnect( struct usb_device *usb, void *ptr )
static void CDCEther_disconnect( struct usb_interface *intf )
{
ether_dev_t *ether_dev = ptr;
ether_dev_t *ether_dev = dev_get_drvdata (&intf->dev);
struct usb_device *usb;
dev_set_drvdata (&intf->dev, NULL);
// Sanity check!!!
if ( !ether_dev || !ether_dev->usb ) {
......@@ -1294,6 +1302,8 @@ static void CDCEther_disconnect( struct usb_device *usb, void *ptr )
// Make sure we fail the sanity check if we try this again.
ether_dev->usb = NULL;
usb = interface_to_usbdev(intf);
// It is possible that this function is called before
// the "close" function.
// This tells the close function we are already disconnected
......
......@@ -114,12 +114,11 @@ MODULE_AUTHOR("Michael Zappe <zapman@interlan.net>, Stephane Alnet <stephane@u-p
MODULE_DESCRIPTION("KL5USB101 USB Ethernet driver");
MODULE_LICENSE("GPL");
static void *kaweth_probe(
struct usb_device *dev, /* the device */
unsigned ifnum, /* what interface */
const struct usb_device_id *id /* from id_table */
static int kaweth_probe(
struct usb_interface *intf,
const struct usb_device_id *id /* from id_table */
);
static void kaweth_disconnect(struct usb_device *dev, void *ptr);
static void kaweth_disconnect(struct usb_interface *intf);
int kaweth_internal_control_msg(struct usb_device *usb_dev, unsigned int pipe,
struct usb_ctrlrequest *cmd, void *data,
int len, int timeout);
......@@ -847,12 +846,12 @@ static void kaweth_tx_timeout(struct net_device *net)
/****************************************************************
* kaweth_probe
****************************************************************/
static void *kaweth_probe(
struct usb_device *dev, /* the device */
unsigned ifnum, /* what interface */
const struct usb_device_id *id /* from id_table */
static int kaweth_probe(
struct usb_interface *intf,
const struct usb_device_id *id /* from id_table */
)
{
struct usb_device *dev = interface_to_usbdev(intf);
struct kaweth_device *kaweth;
struct net_device *netdev;
const eth_addr_t bcast_addr = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
......@@ -871,7 +870,7 @@ static void *kaweth_probe(
(int)dev->descriptor.bDescriptorType);
if(!(kaweth = kmalloc(sizeof(struct kaweth_device), GFP_KERNEL)))
return NULL;
return -ENOMEM;
memset(kaweth, 0, sizeof(struct kaweth_device));
......@@ -902,7 +901,7 @@ static void *kaweth_probe(
kaweth_err("Error downloading firmware (%d)", result);
free_page((unsigned long)kaweth->firmware_buf);
kfree(kaweth);
return NULL;
return -EIO;
}
if ((result = kaweth_download_firmware(kaweth,
......@@ -913,7 +912,7 @@ static void *kaweth_probe(
kaweth_err("Error downloading firmware fix (%d)", result);
free_page((unsigned long)kaweth->firmware_buf);
kfree(kaweth);
return NULL;
return -EIO;
}
if ((result = kaweth_download_firmware(kaweth,
......@@ -924,7 +923,7 @@ static void *kaweth_probe(
kaweth_err("Error downloading trigger code (%d)", result);
free_page((unsigned long)kaweth->firmware_buf);
kfree(kaweth);
return NULL;
return -EIO;
}
if ((result = kaweth_download_firmware(kaweth,
......@@ -935,7 +934,7 @@ static void *kaweth_probe(
kaweth_err("Error downloading trigger code fix (%d)", result);
free_page((unsigned long)kaweth->firmware_buf);
kfree(kaweth);
return NULL;
return -EIO;
}
......@@ -943,14 +942,14 @@ static void *kaweth_probe(
kaweth_err("Error triggering firmware (%d)", result);
free_page((unsigned long)kaweth->firmware_buf);
kfree(kaweth);
return NULL;
return -EIO;
}
/* Device will now disappear for a moment... */
kaweth_info("Firmware loaded. I'll be back...");
free_page((unsigned long)kaweth->firmware_buf);
kfree(kaweth);
return NULL;
return -EIO;
}
result = kaweth_read_configuration(kaweth);
......@@ -958,7 +957,7 @@ static void *kaweth_probe(
if(result < 0) {
kaweth_err("Error reading configuration (%d), no net device created", result);
kfree(kaweth);
return NULL;
return -EIO;
}
kaweth_info("Statistics collection: %x", kaweth->configuration.statistics_mask);
......@@ -977,17 +976,17 @@ static void *kaweth_probe(
sizeof(bcast_addr))) {
kaweth_err("Firmware not functioning properly, no net device created");
kfree(kaweth);
return NULL;
return -EIO;
}
if(kaweth_set_urb_size(kaweth, KAWETH_BUF_SIZE) < 0) {
kaweth_dbg("Error setting URB size");
return kaweth;
goto err_no_netdev;
}
if(kaweth_set_sofs_wait(kaweth, KAWETH_SOFS_TO_WAIT) < 0) {
kaweth_err("Error setting SOFS wait");
return kaweth;
goto err_no_netdev;
}
result = kaweth_set_receive_filter(kaweth,
......@@ -998,14 +997,14 @@ static void *kaweth_probe(
if(result < 0) {
kaweth_err("Error setting receive filter");
kfree(kaweth);
return NULL;
return -EIO;
}
kaweth_dbg("Initializing net device.");
if(!(netdev = kmalloc(sizeof(struct net_device), GFP_KERNEL))) {
kfree(kaweth);
return NULL;
return -ENOMEM;
}
kaweth->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
......@@ -1050,27 +1049,30 @@ static void *kaweth_probe(
kaweth_dbg("Kaweth probe returning.");
return kaweth;
dev_set_drvdata (&intf->dev, kaweth);
return 0;
err_tx_and_rx:
usb_free_urb(kaweth->rx_urb);
err_only_tx:
usb_free_urb(kaweth->tx_urb);
err_no_urb:
kfree(kaweth);
kfree(netdev);
return NULL;
err_no_netdev:
kfree(kaweth);
return -EIO;
}
/****************************************************************
* kaweth_disconnect
****************************************************************/
static void kaweth_disconnect(struct usb_device *dev, void *ptr)
static void kaweth_disconnect(struct usb_interface *intf)
{
struct kaweth_device *kaweth = ptr;
struct kaweth_device *kaweth = dev_get_drvdata (&intf->dev);
kaweth_info("Unregistering");
dev_set_drvdata (&intf->dev, NULL);
if (!kaweth) {
kaweth_warn("unregistering non-existant device");
return;
......
......@@ -1045,20 +1045,21 @@ static inline void setup_pegasus_II(pegasus_t * pegasus)
set_register(pegasus, Reg81, 2);
}
static void *pegasus_probe(struct usb_device *dev, unsigned int ifnum,
const struct usb_device_id *id)
static int pegasus_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
struct usb_device *dev = interface_to_usbdev(intf);
struct net_device *net;
pegasus_t *pegasus;
int dev_index = id - pegasus_ids;
if (usb_set_configuration(dev, dev->config[0].bConfigurationValue)) {
err("usb_set_configuration() failed");
return NULL;
return -ENODEV;
}
if (!(pegasus = kmalloc(sizeof(struct pegasus), GFP_KERNEL))) {
err("out of memory allocating device structure");
return NULL;
return -ENOMEM;
}
usb_get_dev(dev);
......@@ -1068,14 +1069,14 @@ static void *pegasus_probe(struct usb_device *dev, unsigned int ifnum,
if (!alloc_urbs(pegasus)) {
kfree(pegasus);
return NULL;
return -ENOMEM;
}
net = init_etherdev(NULL, 0);
if (!net) {
free_all_urbs(pegasus);
kfree(pegasus);
return NULL;
return -ENODEV;
}
init_MUTEX(&pegasus->sem);
......@@ -1122,13 +1123,18 @@ static void *pegasus_probe(struct usb_device *dev, unsigned int ifnum,
}
exit:
up(&pegasus->sem);
return pegasus;
if (pegasus) {
dev_set_drvdata (&intf->dev, pegasus);
return 0;
}
return -EIO;
}
static void pegasus_disconnect(struct usb_device *dev, void *ptr)
static void pegasus_disconnect(struct usb_interface *intf)
{
struct pegasus *pegasus = ptr;
struct pegasus *pegasus = dev_get_drvdata (&intf->dev);
dev_set_drvdata (&intf->dev, NULL);
if (!pegasus) {
warn("unregistering non-existant device");
return;
......@@ -1136,7 +1142,7 @@ static void pegasus_disconnect(struct usb_device *dev, void *ptr)
pegasus->flags |= PEGASUS_UNPLUG;
unregister_netdev(pegasus->net);
usb_put_dev(dev);
usb_put_dev(interface_to_usbdev(intf));
unlink_all_urbs(pegasus);
free_all_urbs(pegasus);
free_skb_pool(pegasus);
......
......@@ -109,9 +109,9 @@ unsigned long multicast_filter_limit = 32;
static void fill_skb_pool(rtl8150_t *);
static void free_skb_pool(rtl8150_t *);
static inline struct sk_buff *pull_skb(rtl8150_t *);
static void rtl8150_disconnect(struct usb_device *dev, void *ptr);
static void *rtl8150_probe(struct usb_device *dev, unsigned int ifnum,
const struct usb_device_id *id);
static void rtl8150_disconnect(struct usb_interface *intf);
static int rtl8150_probe(struct usb_interface *intf,
const struct usb_device_id *id);
static struct usb_driver rtl8150_driver = {
.name = "rtl8150",
......@@ -723,20 +723,21 @@ static int rtl8150_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
return res;
}
static void *rtl8150_probe(struct usb_device *udev, unsigned int ifnum,
const struct usb_device_id *id)
static int rtl8150_probe(struct usb_interface *intf,
const struct usb_device_id *id)
{
struct usb_device *udev = interface_to_usbdev(intf);
rtl8150_t *dev;
struct net_device *netdev;
if (usb_set_configuration(udev, udev->config[0].bConfigurationValue)) {
err("usb_set_configuration() failed");
return NULL;
return -EIO;
}
dev = kmalloc(sizeof(rtl8150_t), GFP_KERNEL);
if (!dev) {
err("Out of memory");
return NULL;
return -ENOMEM;
} else
memset(dev, 0, sizeof(rtl8150_t));
......@@ -744,7 +745,7 @@ static void *rtl8150_probe(struct usb_device *udev, unsigned int ifnum,
if (!netdev) {
kfree(dev);
err("Oh boy, out of memory again?!?");
return NULL;
return -ENOMEM;
}
init_MUTEX(&dev->sem);
......@@ -781,31 +782,35 @@ static void *rtl8150_probe(struct usb_device *udev, unsigned int ifnum,
info("%s: rtl8150 is detected", netdev->name);
up(&dev->sem);
return dev;
dev_set_drvdata (&intf->dev, dev);
return 0;
err:
unregister_netdev(dev->netdev);
up(&dev->sem);
kfree(netdev);
kfree(dev);
return NULL;
return -EIO;
}
static void rtl8150_disconnect(struct usb_device *udev, void *ptr)
static void rtl8150_disconnect(struct usb_interface *intf)
{
rtl8150_t *dev;
rtl8150_t *dev = dev_get_drvdata (&intf->dev);
dev = ptr;
set_bit(RTL8150_UNPLUG, &dev->flags);
unregister_netdev(dev->netdev);
unlink_all_urbs(dev);
free_all_urbs(dev);
free_skb_pool(dev);
if (dev->rx_skb)
dev_kfree_skb(dev->rx_skb);
kfree(dev->netdev);
kfree(dev);
dev->netdev = NULL;
dev = NULL;
dev_set_drvdata (&intf->dev, NULL);
if (dev) {
set_bit(RTL8150_UNPLUG, &dev->flags);
unregister_netdev(dev->netdev);
unlink_all_urbs(dev);
free_all_urbs(dev);
free_skb_pool(dev);
if (dev->rx_skb)
dev_kfree_skb(dev->rx_skb);
kfree(dev->netdev);
kfree(dev);
dev->netdev = NULL;
dev = NULL;
}
}
int __init usb_rtl8150_init(void)
......
......@@ -1941,12 +1941,20 @@ static void usbnet_bh (unsigned long param)
// precondition: never called in_interrupt
static void usbnet_disconnect (struct usb_device *udev, void *ptr)
static void usbnet_disconnect (struct usb_interface *intf)
{
struct usbnet *dev = (struct usbnet *) ptr;
struct usbnet *dev;
struct usb_device *xdev;
dev = dev_get_drvdata (&intf->dev);
dev_set_drvdata (&intf->dev, NULL);
if (!dev)
return;
xdev = interface_to_usbdev (intf);
devinfo (dev, "unregister usbnet usb-%s-%s, %s",
udev->bus->bus_name, udev->devpath,
xdev->bus->bus_name, xdev->devpath,
dev->driver_info->description);
unregister_netdev (&dev->net);
......@@ -1960,7 +1968,7 @@ static void usbnet_disconnect (struct usb_device *udev, void *ptr)
flush_scheduled_tasks ();
kfree (dev);
usb_put_dev (udev);
usb_put_dev (xdev);
}
......@@ -1968,46 +1976,38 @@ static void usbnet_disconnect (struct usb_device *udev, void *ptr)
// precondition: never called in_interrupt
static void *
usbnet_probe (struct usb_device *udev, unsigned ifnum,
const struct usb_device_id *prod)
int
usbnet_probe (struct usb_interface *udev, const struct usb_device_id *prod)
{
struct usbnet *dev;
struct net_device *net;
struct usb_interface_descriptor *interface;
struct driver_info *info;
int altnum = 0;
struct usb_device *xdev;
info = (struct driver_info *) prod->driver_info;
// sanity check; expect dedicated interface/devices for now.
interface = &udev->actconfig->interface [ifnum].altsetting [altnum];
if (udev->descriptor.bNumConfigurations != 1
|| udev->config[0].bNumInterfaces != 1
// || interface->bInterfaceClass != USB_CLASS_VENDOR_SPEC
) {
dbg ("Bogus config info");
return 0;
}
xdev = interface_to_usbdev (udev);
interface = &udev->altsetting [udev->act_altsetting];
// more sanity (unless the device is broken)
if (!(info->flags & FLAG_NO_SETINT)) {
if (usb_set_interface (udev, ifnum, altnum) < 0) {
if (usb_set_interface (xdev, interface->bInterfaceNumber,
interface->bAlternateSetting) < 0) {
err ("set_interface failed");
return 0;
return -EIO;
}
}
// set up our own records
if (!(dev = kmalloc (sizeof *dev, GFP_KERNEL))) {
dbg ("can't kmalloc dev");
return 0;
return -ENOMEM;
}
memset (dev, 0, sizeof *dev);
init_MUTEX_LOCKED (&dev->mutex);
usb_get_dev (udev);
dev->udev = udev;
usb_get_dev (xdev);
dev->udev = xdev;
dev->driver_info = info;
dev->msg_level = msg_level;
INIT_LIST_HEAD (&dev->dev_list);
......@@ -2040,10 +2040,11 @@ usbnet_probe (struct usb_device *udev, unsigned ifnum,
register_netdev (&dev->net);
devinfo (dev, "register usbnet usb-%s-%s, %s",
udev->bus->bus_name, udev->devpath,
xdev->bus->bus_name, xdev->devpath,
dev->driver_info->description);
// ok, it's ready to go.
dev_set_drvdata (&udev->dev, net);
mutex_lock (&usbnet_mutex);
list_add (&dev->dev_list, &usbnet_list);
mutex_unlock (&dev->mutex);
......@@ -2052,7 +2053,7 @@ usbnet_probe (struct usb_device *udev, unsigned ifnum,
netif_device_attach (&dev->net);
mutex_unlock (&usbnet_mutex);
return dev;
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment