Commit b52e3b4d authored by Stephen Hemminger's avatar Stephen Hemminger Committed by Greg Kroah-Hartman

[PATCH] kaweth: use alloc_etherdev to allocate device private

Change other usb network driver to use alloc_etherdev to allocate the
private data structure. And use netdev_priv to find it.
Signed-off-by: default avatarStephen Hemminger <shemminger@osdl.org>
Signed-off-by: default avatarOliver Neukum <oliver@neukum.name>
Signed-off-by: default avatarGreg Kroah-Hartman <greg@kroah.com>
parent ac23b6c4
......@@ -651,7 +651,7 @@ static void kaweth_usb_receive(struct urb *urb, struct pt_regs *regs)
****************************************************************/
static int kaweth_open(struct net_device *net)
{
struct kaweth_device *kaweth = (struct kaweth_device *)net->priv;
struct kaweth_device *kaweth = netdev_priv(net);
int res;
kaweth_dbg("Opening network device.");
......@@ -689,7 +689,7 @@ static int kaweth_open(struct net_device *net)
****************************************************************/
static int kaweth_close(struct net_device *net)
{
struct kaweth_device *kaweth = net->priv;
struct kaweth_device *kaweth = netdev_priv(net);
netif_stop_queue(net);
......@@ -740,7 +740,7 @@ static void kaweth_usb_transmit_complete(struct urb *urb, struct pt_regs *regs)
****************************************************************/
static int kaweth_start_xmit(struct sk_buff *skb, struct net_device *net)
{
struct kaweth_device *kaweth = net->priv;
struct kaweth_device *kaweth = netdev_priv(net);
__le16 *private_header;
int res;
......@@ -811,7 +811,7 @@ static int kaweth_start_xmit(struct sk_buff *skb, struct net_device *net)
****************************************************************/
static void kaweth_set_rx_mode(struct net_device *net)
{
struct kaweth_device *kaweth = net->priv;
struct kaweth_device *kaweth = netdev_priv(net);
__u16 packet_filter_bitmap = KAWETH_PACKET_FILTER_DIRECTED |
KAWETH_PACKET_FILTER_BROADCAST |
......@@ -868,7 +868,8 @@ static void kaweth_async_set_rx_mode(struct kaweth_device *kaweth)
****************************************************************/
static struct net_device_stats *kaweth_netdev_stats(struct net_device *dev)
{
return &((struct kaweth_device *)dev->priv)->stats;
struct kaweth_device *kaweth = netdev_priv(dev);
return &kaweth->stats;
}
/****************************************************************
......@@ -876,7 +877,7 @@ static struct net_device_stats *kaweth_netdev_stats(struct net_device *dev)
****************************************************************/
static void kaweth_tx_timeout(struct net_device *net)
{
struct kaweth_device *kaweth = net->priv;
struct kaweth_device *kaweth = netdev_priv(net);
kaweth_warn("%s: Tx timed out. Resetting.", net->name);
kaweth->stats.tx_errors++;
......@@ -911,12 +912,14 @@ static int kaweth_probe(
(int)dev->descriptor.bLength,
(int)dev->descriptor.bDescriptorType);
if(!(kaweth = kmalloc(sizeof(struct kaweth_device), GFP_KERNEL)))
netdev = alloc_etherdev(sizeof(*kaweth));
if (!netdev)
return -ENOMEM;
memset(kaweth, 0, sizeof(struct kaweth_device));
kaweth = netdev_priv(dev);
kaweth->dev = dev;
kaweth->net = netdev;
spin_lock_init(&kaweth->device_lock);
init_waitqueue_head(&kaweth->term_wait);
......@@ -941,9 +944,7 @@ static int kaweth_probe(
100,
2)) < 0) {
kaweth_err("Error downloading firmware (%d)", result);
free_page((unsigned long)kaweth->firmware_buf);
kfree(kaweth);
return -EIO;
goto err_fw;
}
if ((result = kaweth_download_firmware(kaweth,
......@@ -952,9 +953,7 @@ static int kaweth_probe(
100,
3)) < 0) {
kaweth_err("Error downloading firmware fix (%d)", result);
free_page((unsigned long)kaweth->firmware_buf);
kfree(kaweth);
return -EIO;
goto err_fw;
}
if ((result = kaweth_download_firmware(kaweth,
......@@ -963,9 +962,8 @@ static int kaweth_probe(
126,
2)) < 0) {
kaweth_err("Error downloading trigger code (%d)", result);
free_page((unsigned long)kaweth->firmware_buf);
kfree(kaweth);
return -EIO;
goto err_fw;
}
if ((result = kaweth_download_firmware(kaweth,
......@@ -974,23 +972,20 @@ static int kaweth_probe(
126,
3)) < 0) {
kaweth_err("Error downloading trigger code fix (%d)", result);
free_page((unsigned long)kaweth->firmware_buf);
kfree(kaweth);
return -EIO;
goto err_fw;
}
if ((result = kaweth_trigger_firmware(kaweth, 126)) < 0) {
kaweth_err("Error triggering firmware (%d)", result);
free_page((unsigned long)kaweth->firmware_buf);
kfree(kaweth);
return -EIO;
goto err_fw;
}
/* Device will now disappear for a moment... */
kaweth_info("Firmware loaded. I'll be back...");
err_fw:
free_page((unsigned long)kaweth->firmware_buf);
kfree(kaweth);
free_netdev(netdev);
return -EIO;
}
......@@ -998,8 +993,7 @@ static int kaweth_probe(
if(result < 0) {
kaweth_err("Error reading configuration (%d), no net device created", result);
kfree(kaweth);
return -EIO;
goto err_free_netdev;
}
kaweth_info("Statistics collection: %x", kaweth->configuration.statistics_mask);
......@@ -1017,18 +1011,17 @@ static int kaweth_probe(
&bcast_addr,
sizeof(bcast_addr))) {
kaweth_err("Firmware not functioning properly, no net device created");
kfree(kaweth);
return -EIO;
goto err_free_netdev;
}
if(kaweth_set_urb_size(kaweth, KAWETH_BUF_SIZE) < 0) {
kaweth_dbg("Error setting URB size");
goto err_no_netdev;
goto err_free_netdev;
}
if(kaweth_set_sofs_wait(kaweth, KAWETH_SOFS_TO_WAIT) < 0) {
kaweth_err("Error setting SOFS wait");
goto err_no_netdev;
goto err_free_netdev;
}
result = kaweth_set_receive_filter(kaweth,
......@@ -1038,20 +1031,14 @@ static int kaweth_probe(
if(result < 0) {
kaweth_err("Error setting receive filter");
kfree(kaweth);
return -EIO;
goto err_free_netdev;
}
kaweth_dbg("Initializing net device.");
if (!(netdev = alloc_etherdev(0))) {
kfree(kaweth);
return -ENOMEM;
}
kaweth->tx_urb = usb_alloc_urb(0, GFP_KERNEL);
if (!kaweth->tx_urb)
goto err_no_urb;
goto err_free_netdev;
kaweth->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
if (!kaweth->rx_urb)
goto err_only_tx;
......@@ -1072,26 +1059,23 @@ static int kaweth_probe(
if (!kaweth->rx_buf)
goto err_all_but_rxbuf;
kaweth->net = netdev;
memcpy(kaweth->net->broadcast, &bcast_addr, sizeof(bcast_addr));
memcpy(kaweth->net->dev_addr,
&kaweth->configuration.hw_addr,
memcpy(netdev->broadcast, &bcast_addr, sizeof(bcast_addr));
memcpy(netdev->dev_addr, &kaweth->configuration.hw_addr,
sizeof(kaweth->configuration.hw_addr));
kaweth->net->priv = kaweth;
kaweth->net->open = kaweth_open;
kaweth->net->stop = kaweth_close;
netdev->open = kaweth_open;
netdev->stop = kaweth_close;
kaweth->net->watchdog_timeo = KAWETH_TX_TIMEOUT;
kaweth->net->tx_timeout = kaweth_tx_timeout;
netdev->watchdog_timeo = KAWETH_TX_TIMEOUT;
netdev->tx_timeout = kaweth_tx_timeout;
kaweth->net->hard_start_xmit = kaweth_start_xmit;
kaweth->net->set_multicast_list = kaweth_set_rx_mode;
kaweth->net->get_stats = kaweth_netdev_stats;
kaweth->net->mtu = le16_to_cpu(kaweth->configuration.segment_size);
SET_ETHTOOL_OPS(kaweth->net, &ops);
netdev->hard_start_xmit = kaweth_start_xmit;
netdev->set_multicast_list = kaweth_set_rx_mode;
netdev->get_stats = kaweth_netdev_stats;
netdev->mtu = le16_to_cpu(kaweth->configuration.segment_size);
SET_ETHTOOL_OPS(netdev, &ops);
memset(&kaweth->stats, 0, sizeof(kaweth->stats));
/* kaweth is zeroed as part of alloc_netdev */
INIT_WORK(&kaweth->lowmem_work, kaweth_resubmit_tl, (void *)kaweth);
......@@ -1128,10 +1112,9 @@ static int kaweth_probe(
usb_free_urb(kaweth->rx_urb);
err_only_tx:
usb_free_urb(kaweth->tx_urb);
err_no_urb:
err_free_netdev:
free_netdev(netdev);
err_no_netdev:
kfree(kaweth);
return -EIO;
}
......@@ -1141,6 +1124,7 @@ static int kaweth_probe(
static void kaweth_disconnect(struct usb_interface *intf)
{
struct kaweth_device *kaweth = usb_get_intfdata(intf);
struct net_device *netdev;
kaweth_info("Unregistering");
......@@ -1149,7 +1133,7 @@ static void kaweth_disconnect(struct usb_interface *intf)
kaweth_warn("unregistering non-existant device");
return;
}
netdev = kaweth->net;
kaweth->removed = 1;
usb_kill_urb(kaweth->irq_urb);
usb_kill_urb(kaweth->rx_urb);
......@@ -1163,26 +1147,17 @@ static void kaweth_disconnect(struct usb_interface *intf)
spin_unlock(&kaweth->device_lock);
}
if(kaweth->net) {
if(kaweth->net->flags & IFF_UP) {
kaweth_dbg("Closing net device");
dev_close(kaweth->net);
}
kaweth_dbg("Unregistering net device");
unregister_netdev(kaweth->net);
free_netdev(kaweth->net);
}
unregister_netdev(netdev);
usb_free_urb(kaweth->rx_urb);
usb_free_urb(kaweth->tx_urb);
usb_free_urb(kaweth->irq_urb);
usb_buffer_free(kaweth->dev, KAWETH_BUF_SIZE, (void *)kaweth->rx_buf, kaweth->rxbufferhandle);
usb_buffer_free(kaweth->dev, INTBUFFERSIZE, (void *)kaweth->intbuffer, kaweth->intbufferhandle);
kfree(kaweth);
free_netdev(netdev);
}
......
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