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