Commit 0f65172c authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[netdrvr usb] use netdev_priv

Update catc, pegasus, rtl8150, and gadget/ether to use netdev_priv()
parent 7ecab9af
...@@ -1670,7 +1670,7 @@ eth_disconnect (struct usb_gadget *gadget) ...@@ -1670,7 +1670,7 @@ eth_disconnect (struct usb_gadget *gadget)
static int eth_change_mtu (struct net_device *net, int new_mtu) static int eth_change_mtu (struct net_device *net, int new_mtu)
{ {
struct eth_dev *dev = (struct eth_dev *) net->priv; struct eth_dev *dev = netdev_priv(net);
// FIXME if rndis, don't change while link's live // FIXME if rndis, don't change while link's live
...@@ -1685,12 +1685,12 @@ static int eth_change_mtu (struct net_device *net, int new_mtu) ...@@ -1685,12 +1685,12 @@ static int eth_change_mtu (struct net_device *net, int new_mtu)
static struct net_device_stats *eth_get_stats (struct net_device *net) static struct net_device_stats *eth_get_stats (struct net_device *net)
{ {
return &((struct eth_dev *) net->priv)->stats; return &((struct eth_dev *)netdev_priv(net))->stats;
} }
static int eth_ethtool_ioctl (struct net_device *net, void __user *useraddr) static int eth_ethtool_ioctl (struct net_device *net, void __user *useraddr)
{ {
struct eth_dev *dev = (struct eth_dev *) net->priv; struct eth_dev *dev = netdev_priv(net);
u32 cmd; u32 cmd;
if (get_user (cmd, (u32 __user *)useraddr)) if (get_user (cmd, (u32 __user *)useraddr))
...@@ -1997,7 +1997,7 @@ static void tx_complete (struct usb_ep *ep, struct usb_request *req) ...@@ -1997,7 +1997,7 @@ static void tx_complete (struct usb_ep *ep, struct usb_request *req)
static int eth_start_xmit (struct sk_buff *skb, struct net_device *net) static int eth_start_xmit (struct sk_buff *skb, struct net_device *net)
{ {
struct eth_dev *dev = (struct eth_dev *) net->priv; struct eth_dev *dev = netdev_priv(net);
int length = skb->len; int length = skb->len;
int retval; int retval;
struct usb_request *req = NULL; struct usb_request *req = NULL;
...@@ -2110,7 +2110,7 @@ static void rndis_control_ack_complete (struct usb_ep *ep, struct usb_request *r ...@@ -2110,7 +2110,7 @@ static void rndis_control_ack_complete (struct usb_ep *ep, struct usb_request *r
static int rndis_control_ack (struct net_device *net) static int rndis_control_ack (struct net_device *net)
{ {
struct eth_dev *dev = (struct eth_dev *) net->priv; struct eth_dev *dev = netdev_priv(net);
u32 length; u32 length;
struct usb_request *resp; struct usb_request *resp;
...@@ -2177,7 +2177,7 @@ static void eth_start (struct eth_dev *dev, int gfp_flags) ...@@ -2177,7 +2177,7 @@ static void eth_start (struct eth_dev *dev, int gfp_flags)
static int eth_open (struct net_device *net) static int eth_open (struct net_device *net)
{ {
struct eth_dev *dev = (struct eth_dev *) net->priv; struct eth_dev *dev = netdev_priv(net);
DEBUG (dev, "%s\n", __FUNCTION__); DEBUG (dev, "%s\n", __FUNCTION__);
if (netif_carrier_ok (dev->net)) if (netif_carrier_ok (dev->net))
...@@ -2187,7 +2187,7 @@ static int eth_open (struct net_device *net) ...@@ -2187,7 +2187,7 @@ static int eth_open (struct net_device *net)
static int eth_stop (struct net_device *net) static int eth_stop (struct net_device *net)
{ {
struct eth_dev *dev = (struct eth_dev *) net->priv; struct eth_dev *dev = netdev_priv(net);
VDEBUG (dev, "%s\n", __FUNCTION__); VDEBUG (dev, "%s\n", __FUNCTION__);
netif_stop_queue (net); netif_stop_queue (net);
...@@ -2474,7 +2474,7 @@ eth_bind (struct usb_gadget *gadget) ...@@ -2474,7 +2474,7 @@ eth_bind (struct usb_gadget *gadget)
net = alloc_etherdev (sizeof *dev); net = alloc_etherdev (sizeof *dev);
if (!net) if (!net)
return status; return status;
dev = net->priv; dev = netdev_priv(net);
spin_lock_init (&dev->lock); spin_lock_init (&dev->lock);
INIT_WORK (&dev->work, eth_work, dev); INIT_WORK (&dev->work, eth_work, dev);
INIT_LIST_HEAD (&dev->tx_reqs); INIT_LIST_HEAD (&dev->tx_reqs);
......
...@@ -411,7 +411,7 @@ static void catc_tx_done(struct urb *urb, struct pt_regs *regs) ...@@ -411,7 +411,7 @@ static void catc_tx_done(struct urb *urb, struct pt_regs *regs)
static int catc_hard_start_xmit(struct sk_buff *skb, struct net_device *netdev) static int catc_hard_start_xmit(struct sk_buff *skb, struct net_device *netdev)
{ {
struct catc *catc = netdev->priv; struct catc *catc = netdev_priv(netdev);
unsigned long flags; unsigned long flags;
char *tx_buf; char *tx_buf;
...@@ -442,7 +442,7 @@ static int catc_hard_start_xmit(struct sk_buff *skb, struct net_device *netdev) ...@@ -442,7 +442,7 @@ static int catc_hard_start_xmit(struct sk_buff *skb, struct net_device *netdev)
static void catc_tx_timeout(struct net_device *netdev) static void catc_tx_timeout(struct net_device *netdev)
{ {
struct catc *catc = netdev->priv; struct catc *catc = netdev_priv(netdev);
warn("Transmit timed out."); warn("Transmit timed out.");
catc->tx_urb->transfer_flags |= URB_ASYNC_UNLINK; catc->tx_urb->transfer_flags |= URB_ASYNC_UNLINK;
...@@ -604,7 +604,7 @@ static void catc_stats_timer(unsigned long data) ...@@ -604,7 +604,7 @@ static void catc_stats_timer(unsigned long data)
static struct net_device_stats *catc_get_stats(struct net_device *netdev) static struct net_device_stats *catc_get_stats(struct net_device *netdev)
{ {
struct catc *catc = netdev->priv; struct catc *catc = netdev_priv(netdev);
return &catc->stats; return &catc->stats;
} }
...@@ -622,7 +622,7 @@ static void catc_multicast(unsigned char *addr, u8 *multicast) ...@@ -622,7 +622,7 @@ static void catc_multicast(unsigned char *addr, u8 *multicast)
static void catc_set_multicast_list(struct net_device *netdev) static void catc_set_multicast_list(struct net_device *netdev)
{ {
struct catc *catc = netdev->priv; struct catc *catc = netdev_priv(netdev);
struct dev_mc_list *mc; struct dev_mc_list *mc;
u8 broadcast[6]; u8 broadcast[6];
u8 rx = RxEnable | RxPolarity | RxMultiCast; u8 rx = RxEnable | RxPolarity | RxMultiCast;
...@@ -669,7 +669,7 @@ static void catc_set_multicast_list(struct net_device *netdev) ...@@ -669,7 +669,7 @@ static void catc_set_multicast_list(struct net_device *netdev)
*/ */
static int netdev_ethtool_ioctl(struct net_device *dev, void __user *useraddr) static int netdev_ethtool_ioctl(struct net_device *dev, void __user *useraddr)
{ {
struct catc *catc = dev->priv; struct catc *catc = netdev_priv(dev);
u32 cmd; u32 cmd;
if (get_user(cmd, (u32 __user *)useraddr)) if (get_user(cmd, (u32 __user *)useraddr))
...@@ -739,7 +739,7 @@ static int catc_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) ...@@ -739,7 +739,7 @@ static int catc_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
static int catc_open(struct net_device *netdev) static int catc_open(struct net_device *netdev)
{ {
struct catc *catc = netdev->priv; struct catc *catc = netdev_priv(netdev);
int status; int status;
catc->irq_urb->dev = catc->usbdev; catc->irq_urb->dev = catc->usbdev;
...@@ -758,7 +758,7 @@ static int catc_open(struct net_device *netdev) ...@@ -758,7 +758,7 @@ static int catc_open(struct net_device *netdev)
static int catc_stop(struct net_device *netdev) static int catc_stop(struct net_device *netdev)
{ {
struct catc *catc = netdev->priv; struct catc *catc = netdev_priv(netdev);
netif_stop_queue(netdev); netif_stop_queue(netdev);
...@@ -791,17 +791,11 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id ...@@ -791,17 +791,11 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id
return -EIO; return -EIO;
} }
catc = kmalloc(sizeof(struct catc), GFP_KERNEL); netdev = alloc_etherdev(sizeof(struct catc));
if (!catc) if (!netdev)
return -ENOMEM; return -ENOMEM;
memset(catc, 0, sizeof(struct catc)); catc = netdev_priv(netdev);
netdev = alloc_etherdev(0);
if (!netdev) {
kfree(catc);
return -EIO;
}
netdev->open = catc_open; netdev->open = catc_open;
netdev->hard_start_xmit = catc_hard_start_xmit; netdev->hard_start_xmit = catc_hard_start_xmit;
...@@ -811,7 +805,6 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id ...@@ -811,7 +805,6 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id
netdev->watchdog_timeo = TX_TIMEOUT; netdev->watchdog_timeo = TX_TIMEOUT;
netdev->set_multicast_list = catc_set_multicast_list; netdev->set_multicast_list = catc_set_multicast_list;
netdev->do_ioctl = catc_ioctl; netdev->do_ioctl = catc_ioctl;
netdev->priv = catc;
catc->usbdev = usbdev; catc->usbdev = usbdev;
catc->netdev = netdev; catc->netdev = netdev;
...@@ -839,7 +832,6 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id ...@@ -839,7 +832,6 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id
if (catc->irq_urb) if (catc->irq_urb)
usb_free_urb(catc->irq_urb); usb_free_urb(catc->irq_urb);
free_netdev(netdev); free_netdev(netdev);
kfree(catc);
return -ENOMEM; return -ENOMEM;
} }
...@@ -944,7 +936,6 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id ...@@ -944,7 +936,6 @@ static int catc_probe(struct usb_interface *intf, const struct usb_device_id *id
usb_free_urb(catc->rx_urb); usb_free_urb(catc->rx_urb);
usb_free_urb(catc->irq_urb); usb_free_urb(catc->irq_urb);
free_netdev(netdev); free_netdev(netdev);
kfree(catc);
return -EIO; return -EIO;
} }
return 0; return 0;
...@@ -962,7 +953,6 @@ static void catc_disconnect(struct usb_interface *intf) ...@@ -962,7 +953,6 @@ static void catc_disconnect(struct usb_interface *intf)
usb_free_urb(catc->rx_urb); usb_free_urb(catc->rx_urb);
usb_free_urb(catc->irq_urb); usb_free_urb(catc->irq_urb);
free_netdev(catc->netdev); free_netdev(catc->netdev);
kfree(catc);
} }
} }
......
...@@ -308,7 +308,7 @@ static int read_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 * regd) ...@@ -308,7 +308,7 @@ static int read_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 * regd)
static int mdio_read(struct net_device *dev, int phy_id, int loc) static int mdio_read(struct net_device *dev, int phy_id, int loc)
{ {
pegasus_t *pegasus = (pegasus_t *) dev->priv; pegasus_t *pegasus = (pegasus_t *) netdev_priv(dev);
int res; int res;
read_mii_word(pegasus, phy_id, loc, (u16 *) & res); read_mii_word(pegasus, phy_id, loc, (u16 *) & res);
...@@ -338,7 +338,7 @@ static int write_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 regd) ...@@ -338,7 +338,7 @@ static int write_mii_word(pegasus_t * pegasus, __u8 phy, __u8 indx, __u16 regd)
static void mdio_write(struct net_device *dev, int phy_id, int loc, int val) static void mdio_write(struct net_device *dev, int phy_id, int loc, int val)
{ {
pegasus_t *pegasus = (pegasus_t *) dev->priv; pegasus_t *pegasus = (pegasus_t *) netdev_priv(dev);
write_mii_word(pegasus, phy_id, loc, val); write_mii_word(pegasus, phy_id, loc, val);
} }
...@@ -471,7 +471,7 @@ static int enable_net_traffic(struct net_device *dev, struct usb_device *usb) ...@@ -471,7 +471,7 @@ static int enable_net_traffic(struct net_device *dev, struct usb_device *usb)
{ {
__u16 linkpart; __u16 linkpart;
__u8 data[4]; __u8 data[4];
pegasus_t *pegasus = dev->priv; pegasus_t *pegasus = netdev_priv(dev);
read_mii_word(pegasus, pegasus->phy, MII_LPA, &linkpart); read_mii_word(pegasus, pegasus->phy, MII_LPA, &linkpart);
data[0] = 0xc9; data[0] = 0xc9;
...@@ -754,11 +754,7 @@ static void intr_callback(struct urb *urb, struct pt_regs *regs) ...@@ -754,11 +754,7 @@ static void intr_callback(struct urb *urb, struct pt_regs *regs)
static void pegasus_tx_timeout(struct net_device *net) static void pegasus_tx_timeout(struct net_device *net)
{ {
pegasus_t *pegasus = net->priv; pegasus_t *pegasus = netdev_priv(net);
if (!pegasus)
return;
warn("%s: Tx timed out.", net->name); warn("%s: Tx timed out.", net->name);
pegasus->tx_urb->transfer_flags |= URB_ASYNC_UNLINK; pegasus->tx_urb->transfer_flags |= URB_ASYNC_UNLINK;
usb_unlink_urb(pegasus->tx_urb); usb_unlink_urb(pegasus->tx_urb);
...@@ -767,7 +763,7 @@ static void pegasus_tx_timeout(struct net_device *net) ...@@ -767,7 +763,7 @@ static void pegasus_tx_timeout(struct net_device *net)
static int pegasus_start_xmit(struct sk_buff *skb, struct net_device *net) static int pegasus_start_xmit(struct sk_buff *skb, struct net_device *net)
{ {
pegasus_t *pegasus = net->priv; pegasus_t *pegasus = netdev_priv(net);
int count = ((skb->len + 2) & 0x3f) ? skb->len + 2 : skb->len + 3; int count = ((skb->len + 2) & 0x3f) ? skb->len + 2 : skb->len + 3;
int res; int res;
__u16 l16 = skb->len; __u16 l16 = skb->len;
...@@ -804,7 +800,7 @@ static int pegasus_start_xmit(struct sk_buff *skb, struct net_device *net) ...@@ -804,7 +800,7 @@ static int pegasus_start_xmit(struct sk_buff *skb, struct net_device *net)
static struct net_device_stats *pegasus_netdev_stats(struct net_device *dev) static struct net_device_stats *pegasus_netdev_stats(struct net_device *dev)
{ {
return &((pegasus_t *) dev->priv)->stats; return &((pegasus_t *) netdev_priv(dev))->stats;
} }
static inline void disable_net_traffic(pegasus_t * pegasus) static inline void disable_net_traffic(pegasus_t * pegasus)
...@@ -832,10 +828,9 @@ static inline void get_interrupt_interval(pegasus_t * pegasus) ...@@ -832,10 +828,9 @@ static inline void get_interrupt_interval(pegasus_t * pegasus)
static void set_carrier(struct net_device *net) static void set_carrier(struct net_device *net)
{ {
pegasus_t *pegasus; pegasus_t *pegasus = netdev_priv(net);
short tmp; short tmp;
pegasus = net->priv;
read_mii_word(pegasus, pegasus->phy, MII_BMSR, &tmp); read_mii_word(pegasus, pegasus->phy, MII_BMSR, &tmp);
if (tmp & BMSR_LSTATUS) if (tmp & BMSR_LSTATUS)
netif_carrier_on(net); netif_carrier_on(net);
...@@ -890,7 +885,7 @@ static int alloc_urbs(pegasus_t * pegasus) ...@@ -890,7 +885,7 @@ static int alloc_urbs(pegasus_t * pegasus)
static int pegasus_open(struct net_device *net) static int pegasus_open(struct net_device *net)
{ {
pegasus_t *pegasus = (pegasus_t *) net->priv; pegasus_t *pegasus = netdev_priv(net);
int res; int res;
if (pegasus->rx_skb == NULL) if (pegasus->rx_skb == NULL)
...@@ -933,7 +928,7 @@ static int pegasus_open(struct net_device *net) ...@@ -933,7 +928,7 @@ static int pegasus_open(struct net_device *net)
static int pegasus_close(struct net_device *net) static int pegasus_close(struct net_device *net)
{ {
pegasus_t *pegasus = net->priv; pegasus_t *pegasus = netdev_priv(net);
pegasus->flags &= ~PEGASUS_RUNNING; pegasus->flags &= ~PEGASUS_RUNNING;
netif_stop_queue(net); netif_stop_queue(net);
...@@ -949,7 +944,7 @@ static int pegasus_ethtool_ioctl(struct net_device *dev, void __user *useraddr) ...@@ -949,7 +944,7 @@ static int pegasus_ethtool_ioctl(struct net_device *dev, void __user *useraddr)
{ {
u32 ethcmd; u32 ethcmd;
pegasus_t *pegasus = dev->priv; pegasus_t *pegasus = netdev_priv(dev);
if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd))) if (copy_from_user(&ethcmd, useraddr, sizeof (ethcmd)))
return -EFAULT; return -EFAULT;
...@@ -1029,7 +1024,7 @@ static int pegasus_ethtool_ioctl(struct net_device *net, void __user *uaddr) ...@@ -1029,7 +1024,7 @@ static int pegasus_ethtool_ioctl(struct net_device *net, void __user *uaddr)
pegasus_t *pegasus; pegasus_t *pegasus;
int cmd; int cmd;
pegasus = net->priv; pegasus = netdev_priv(net);
if (get_user(cmd, (int __user *) uaddr)) if (get_user(cmd, (int __user *) uaddr))
return -EFAULT; return -EFAULT;
switch (cmd) { switch (cmd) {
...@@ -1108,7 +1103,7 @@ static int pegasus_ethtool_ioctl(struct net_device *net, void __user *uaddr) ...@@ -1108,7 +1103,7 @@ static int pegasus_ethtool_ioctl(struct net_device *net, void __user *uaddr)
static int pegasus_ioctl(struct net_device *net, struct ifreq *rq, int cmd) static int pegasus_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
{ {
__u16 *data = (__u16 *) & rq->ifr_ifru; __u16 *data = (__u16 *) & rq->ifr_ifru;
pegasus_t *pegasus = net->priv; pegasus_t *pegasus = netdev_priv(net);
int res; int res;
switch (cmd) { switch (cmd) {
...@@ -1135,7 +1130,7 @@ static int pegasus_ioctl(struct net_device *net, struct ifreq *rq, int cmd) ...@@ -1135,7 +1130,7 @@ static int pegasus_ioctl(struct net_device *net, struct ifreq *rq, int cmd)
static void pegasus_set_multicast(struct net_device *net) static void pegasus_set_multicast(struct net_device *net)
{ {
pegasus_t *pegasus = net->priv; pegasus_t *pegasus = netdev_priv(net);
if (net->flags & IFF_PROMISC) { if (net->flags & IFF_PROMISC) {
pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS; pegasus->eth_regs[EthCtrl2] |= RX_PROMISCUOUS;
...@@ -1211,11 +1206,13 @@ static int pegasus_probe(struct usb_interface *intf, ...@@ -1211,11 +1206,13 @@ static int pegasus_probe(struct usb_interface *intf,
int res = -ENOMEM; int res = -ENOMEM;
usb_get_dev(dev); usb_get_dev(dev);
if (!(pegasus = kmalloc(sizeof (struct pegasus), GFP_KERNEL))) { net = alloc_etherdev(sizeof(struct pegasus));
if (!net) {
err("out of memory allocating device structure"); err("out of memory allocating device structure");
goto out; goto out;
} }
pegasus = netdev_priv(net);
memset(pegasus, 0, sizeof (struct pegasus)); memset(pegasus, 0, sizeof (struct pegasus));
pegasus->dev_index = dev_index; pegasus->dev_index = dev_index;
init_waitqueue_head(&pegasus->ctrl_wait); init_waitqueue_head(&pegasus->ctrl_wait);
...@@ -1223,16 +1220,11 @@ static int pegasus_probe(struct usb_interface *intf, ...@@ -1223,16 +1220,11 @@ static int pegasus_probe(struct usb_interface *intf,
if (!alloc_urbs(pegasus)) if (!alloc_urbs(pegasus))
goto out1; goto out1;
net = alloc_etherdev(0);
if (!net)
goto out2;
tasklet_init(&pegasus->rx_tl, rx_fixup, (unsigned long) pegasus); tasklet_init(&pegasus->rx_tl, rx_fixup, (unsigned long) pegasus);
pegasus->usb = dev; pegasus->usb = dev;
pegasus->net = net; pegasus->net = net;
SET_MODULE_OWNER(net); SET_MODULE_OWNER(net);
net->priv = pegasus;
net->open = pegasus_open; net->open = pegasus_open;
net->stop = pegasus_close; net->stop = pegasus_close;
net->watchdog_timeo = PEGASUS_TX_TIMEOUT; net->watchdog_timeo = PEGASUS_TX_TIMEOUT;
...@@ -1254,7 +1246,7 @@ static int pegasus_probe(struct usb_interface *intf, ...@@ -1254,7 +1246,7 @@ static int pegasus_probe(struct usb_interface *intf,
if (reset_mac(pegasus)) { if (reset_mac(pegasus)) {
err("can't reset MAC"); err("can't reset MAC");
res = -EIO; res = -EIO;
goto out3; goto out2;
} }
set_ethernet_addr(pegasus); set_ethernet_addr(pegasus);
fill_skb_pool(pegasus); fill_skb_pool(pegasus);
...@@ -1271,19 +1263,17 @@ static int pegasus_probe(struct usb_interface *intf, ...@@ -1271,19 +1263,17 @@ static int pegasus_probe(struct usb_interface *intf,
SET_NETDEV_DEV(net, &intf->dev); SET_NETDEV_DEV(net, &intf->dev);
res = register_netdev(net); res = register_netdev(net);
if (res) if (res)
goto out4; goto out3;
printk("%s: %s\n", net->name, usb_dev_id[dev_index].name); printk("%s: %s\n", net->name, usb_dev_id[dev_index].name);
return 0; return 0;
out4: out3:
usb_set_intfdata(intf, NULL); usb_set_intfdata(intf, NULL);
free_skb_pool(pegasus); free_skb_pool(pegasus);
out3:
free_netdev(net);
out2: out2:
free_all_urbs(pegasus); free_all_urbs(pegasus);
out1: out1:
kfree(pegasus); free_netdev(net);
out: out:
usb_put_dev(dev); usb_put_dev(dev);
return res; return res;
...@@ -1307,7 +1297,6 @@ static void pegasus_disconnect(struct usb_interface *intf) ...@@ -1307,7 +1297,6 @@ static void pegasus_disconnect(struct usb_interface *intf)
if (pegasus->rx_skb) if (pegasus->rx_skb)
dev_kfree_skb(pegasus->rx_skb); dev_kfree_skb(pegasus->rx_skb);
free_netdev(pegasus->net); free_netdev(pegasus->net);
kfree(pegasus);
} }
static struct usb_driver pegasus_driver = { static struct usb_driver pegasus_driver = {
......
...@@ -304,15 +304,12 @@ static inline void set_ethernet_addr(rtl8150_t * dev) ...@@ -304,15 +304,12 @@ static inline void set_ethernet_addr(rtl8150_t * dev)
static int rtl8150_set_mac_address(struct net_device *netdev, void *p) static int rtl8150_set_mac_address(struct net_device *netdev, void *p)
{ {
struct sockaddr *addr = p; struct sockaddr *addr = p;
rtl8150_t *dev; rtl8150_t *dev = netdev_priv(netdev);
int i; int i;
if (netif_running(netdev)) if (netif_running(netdev))
return -EBUSY; return -EBUSY;
dev = netdev->priv;
if (dev == NULL) {
return -ENODEV;
}
memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
dbg("%s: Setting MAC address to ", netdev->name); dbg("%s: Setting MAC address to ", netdev->name);
for (i = 0; i < 5; i++) for (i = 0; i < 5; i++)
...@@ -651,16 +648,12 @@ static void disable_net_traffic(rtl8150_t * dev) ...@@ -651,16 +648,12 @@ static void disable_net_traffic(rtl8150_t * dev)
static struct net_device_stats *rtl8150_netdev_stats(struct net_device *dev) static struct net_device_stats *rtl8150_netdev_stats(struct net_device *dev)
{ {
return &((rtl8150_t *) dev->priv)->stats; return &((rtl8150_t *)netdev_priv(dev))->stats;
} }
static void rtl8150_tx_timeout(struct net_device *netdev) static void rtl8150_tx_timeout(struct net_device *netdev)
{ {
rtl8150_t *dev; rtl8150_t *dev = netdev_priv(netdev);
dev = netdev->priv;
if (!dev)
return;
warn("%s: Tx timeout.", netdev->name); warn("%s: Tx timeout.", netdev->name);
dev->tx_urb->transfer_flags |= URB_ASYNC_UNLINK; dev->tx_urb->transfer_flags |= URB_ASYNC_UNLINK;
usb_unlink_urb(dev->tx_urb); usb_unlink_urb(dev->tx_urb);
...@@ -669,9 +662,7 @@ static void rtl8150_tx_timeout(struct net_device *netdev) ...@@ -669,9 +662,7 @@ static void rtl8150_tx_timeout(struct net_device *netdev)
static void rtl8150_set_multicast(struct net_device *netdev) static void rtl8150_set_multicast(struct net_device *netdev)
{ {
rtl8150_t *dev; rtl8150_t *dev = netdev_priv(netdev);
dev = netdev->priv;
netif_stop_queue(netdev); netif_stop_queue(netdev);
if (netdev->flags & IFF_PROMISC) { if (netdev->flags & IFF_PROMISC) {
dev->rx_creg |= cpu_to_le16(0x0001); dev->rx_creg |= cpu_to_le16(0x0001);
...@@ -691,11 +682,10 @@ static void rtl8150_set_multicast(struct net_device *netdev) ...@@ -691,11 +682,10 @@ static void rtl8150_set_multicast(struct net_device *netdev)
static int rtl8150_start_xmit(struct sk_buff *skb, struct net_device *netdev) static int rtl8150_start_xmit(struct sk_buff *skb, struct net_device *netdev)
{ {
rtl8150_t *dev; rtl8150_t *dev = netdev_priv(netdev);
int count, res; int count, res;
netif_stop_queue(netdev); netif_stop_queue(netdev);
dev = netdev->priv;
count = (skb->len < 60) ? 60 : skb->len; count = (skb->len < 60) ? 60 : skb->len;
count = (count & 0x3f) ? count : count + 1; count = (count & 0x3f) ? count : count + 1;
dev->tx_skb = skb; dev->tx_skb = skb;
...@@ -717,7 +707,7 @@ static int rtl8150_start_xmit(struct sk_buff *skb, struct net_device *netdev) ...@@ -717,7 +707,7 @@ static int rtl8150_start_xmit(struct sk_buff *skb, struct net_device *netdev)
static void set_carrier(struct net_device *netdev) static void set_carrier(struct net_device *netdev)
{ {
rtl8150_t *dev = netdev->priv; rtl8150_t *dev = netdev_priv(netdev);
short tmp; short tmp;
get_registers(dev, CSCR, 2, &tmp); get_registers(dev, CSCR, 2, &tmp);
...@@ -729,13 +719,9 @@ static void set_carrier(struct net_device *netdev) ...@@ -729,13 +719,9 @@ static void set_carrier(struct net_device *netdev)
static int rtl8150_open(struct net_device *netdev) static int rtl8150_open(struct net_device *netdev)
{ {
rtl8150_t *dev; rtl8150_t *dev = netdev_priv(netdev);
int res; int res;
dev = netdev->priv;
if (dev == NULL) {
return -ENODEV;
}
if (dev->rx_skb == NULL) if (dev->rx_skb == NULL)
dev->rx_skb = pull_skb(dev); dev->rx_skb = pull_skb(dev);
if (!dev->rx_skb) if (!dev->rx_skb)
...@@ -761,13 +747,9 @@ static int rtl8150_open(struct net_device *netdev) ...@@ -761,13 +747,9 @@ static int rtl8150_open(struct net_device *netdev)
static int rtl8150_close(struct net_device *netdev) static int rtl8150_close(struct net_device *netdev)
{ {
rtl8150_t *dev; rtl8150_t *dev = netdev_priv(netdev);
int res = 0; int res = 0;
dev = netdev->priv;
if (!dev)
return -ENODEV;
netif_stop_queue(netdev); netif_stop_queue(netdev);
if (!test_bit(RTL8150_UNPLUG, &dev->flags)) if (!test_bit(RTL8150_UNPLUG, &dev->flags))
disable_net_traffic(dev); disable_net_traffic(dev);
...@@ -778,10 +760,9 @@ static int rtl8150_close(struct net_device *netdev) ...@@ -778,10 +760,9 @@ static int rtl8150_close(struct net_device *netdev)
static int rtl8150_ethtool_ioctl(struct net_device *netdev, void __user *uaddr) static int rtl8150_ethtool_ioctl(struct net_device *netdev, void __user *uaddr)
{ {
rtl8150_t *dev; rtl8150_t *dev = netdev_priv(netdev);
int cmd; int cmd;
dev = netdev->priv;
if (get_user(cmd, (int __user *) uaddr)) if (get_user(cmd, (int __user *) uaddr))
return -EFAULT; return -EFAULT;
...@@ -851,11 +832,10 @@ static int rtl8150_ethtool_ioctl(struct net_device *netdev, void __user *uaddr) ...@@ -851,11 +832,10 @@ static int rtl8150_ethtool_ioctl(struct net_device *netdev, void __user *uaddr)
static int rtl8150_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd) static int rtl8150_ioctl(struct net_device *netdev, struct ifreq *rq, int cmd)
{ {
rtl8150_t *dev; rtl8150_t *dev = netdev_priv(netdev);
u16 *data; u16 *data;
int res; int res;
dev = netdev->priv;
data = (u16 *) & rq->ifr_ifru; data = (u16 *) & rq->ifr_ifru;
res = 0; res = 0;
...@@ -887,23 +867,18 @@ static int rtl8150_probe(struct usb_interface *intf, ...@@ -887,23 +867,18 @@ static int rtl8150_probe(struct usb_interface *intf,
rtl8150_t *dev; rtl8150_t *dev;
struct net_device *netdev; struct net_device *netdev;
dev = kmalloc(sizeof(rtl8150_t), GFP_KERNEL); netdev = alloc_etherdev(sizeof(rtl8150_t));
if (!dev) { if (!netdev) {
err("Out of memory"); err("Out of memory");
return -ENOMEM; return -ENOMEM;
} else }
memset(dev, 0, sizeof(rtl8150_t));
dev = netdev_priv(netdev);
memset(dev, 0, sizeof(rtl8150_t));
dev->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL); dev->intr_buff = kmalloc(INTBUFSIZE, GFP_KERNEL);
if (!dev->intr_buff) { if (!dev->intr_buff) {
kfree(dev); free_netdev(netdev);
return -ENOMEM;
}
netdev = alloc_etherdev(0);
if (!netdev) {
kfree(dev->intr_buff);
kfree(dev);
err("Oh boy, out of memory again?!?");
return -ENOMEM; return -ENOMEM;
} }
...@@ -913,7 +888,6 @@ static int rtl8150_probe(struct usb_interface *intf, ...@@ -913,7 +888,6 @@ static int rtl8150_probe(struct usb_interface *intf,
dev->udev = udev; dev->udev = udev;
dev->netdev = netdev; dev->netdev = netdev;
SET_MODULE_OWNER(netdev); SET_MODULE_OWNER(netdev);
netdev->priv = dev;
netdev->open = rtl8150_open; netdev->open = rtl8150_open;
netdev->stop = rtl8150_close; netdev->stop = rtl8150_close;
netdev->do_ioctl = rtl8150_ioctl; netdev->do_ioctl = rtl8150_ioctl;
...@@ -954,7 +928,6 @@ static int rtl8150_probe(struct usb_interface *intf, ...@@ -954,7 +928,6 @@ static int rtl8150_probe(struct usb_interface *intf,
out: out:
kfree(dev->intr_buff); kfree(dev->intr_buff);
free_netdev(netdev); free_netdev(netdev);
kfree(dev);
return -EIO; return -EIO;
} }
...@@ -971,9 +944,8 @@ static void rtl8150_disconnect(struct usb_interface *intf) ...@@ -971,9 +944,8 @@ static void rtl8150_disconnect(struct usb_interface *intf)
free_skb_pool(dev); free_skb_pool(dev);
if (dev->rx_skb) if (dev->rx_skb)
dev_kfree_skb(dev->rx_skb); dev_kfree_skb(dev->rx_skb);
free_netdev(dev->netdev);
kfree(dev->intr_buff); kfree(dev->intr_buff);
kfree(dev); free_netdev(dev->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