Commit ec47df58 authored by Alexander Viro's avatar Alexander Viro Committed by Stephen Hemminger

[wan hdlc] kill embedding of struct net_device

Now we can kill the embedding of net_device into hdlc_device.  Indeed,
all instances of hdlc_device are created by alloc_hdlcdev() and nothing
uses hdlc->netdev directly.  So we can
        * remove hdlc->netdev
        * have alloc_hdlcdev() implemented via alloc_netdev() with the rest
of hdlc_device as private part of net_device.
        * replace free_hdlcdev() with free_netdev().
        * have dev_to_hdlc(dev) simply return netdev_priv(dev).
parent 705ddf60
...@@ -287,7 +287,7 @@ static void c101_destroy_card(card_t *card) ...@@ -287,7 +287,7 @@ static void c101_destroy_card(card_t *card)
release_mem_region(card->phy_winbase, C101_MAPPED_RAM_SIZE); release_mem_region(card->phy_winbase, C101_MAPPED_RAM_SIZE);
} }
free_hdlcdev(card->dev); free_netdev(card->dev);
kfree(card); kfree(card);
} }
......
...@@ -699,7 +699,7 @@ static void dscc4_free1(struct pci_dev *pdev) ...@@ -699,7 +699,7 @@ static void dscc4_free1(struct pci_dev *pdev)
pci_set_drvdata(pdev, NULL); pci_set_drvdata(pdev, NULL);
for (i = 0; i < dev_per_card; i++) for (i = 0; i < dev_per_card; i++)
free_hdlcdev(root[i].dev); free_netdev(root[i].dev);
kfree(root); kfree(root);
kfree(ppriv); kfree(ppriv);
} }
...@@ -885,7 +885,7 @@ static int dscc4_found1(struct pci_dev *pdev, unsigned long ioaddr) ...@@ -885,7 +885,7 @@ static int dscc4_found1(struct pci_dev *pdev, unsigned long ioaddr)
root[i].dev = alloc_hdlcdev(root + i); root[i].dev = alloc_hdlcdev(root + i);
if (!root[i].dev) { if (!root[i].dev) {
while (i--) while (i--)
free_hdlcdev(root[i].dev); free_netdev(root[i].dev);
goto err_free_dev; goto err_free_dev;
} }
} }
...@@ -953,7 +953,7 @@ static int dscc4_found1(struct pci_dev *pdev, unsigned long ioaddr) ...@@ -953,7 +953,7 @@ static int dscc4_found1(struct pci_dev *pdev, unsigned long ioaddr)
kfree(ppriv); kfree(ppriv);
err_free_dev2: err_free_dev2:
for (i = 0; i < dev_per_card; i++) for (i = 0; i < dev_per_card; i++)
free_hdlcdev(root[i].dev); free_netdev(root[i].dev);
err_free_dev: err_free_dev:
kfree(root); kfree(root);
err_out: err_out:
......
...@@ -1465,7 +1465,7 @@ fst_init_card ( struct fst_card_info *card ) ...@@ -1465,7 +1465,7 @@ fst_init_card ( struct fst_card_info *card )
printk_err ("Cannot register HDLC device for port %d" printk_err ("Cannot register HDLC device for port %d"
" (errno %d)\n", i, -err ); " (errno %d)\n", i, -err );
for (j = i; j < card->nports; j++) { for (j = i; j < card->nports; j++) {
free_hdlcdev(card->ports[j].dev); free_netdev(card->ports[j].dev);
card->ports[j].dev = NULL; card->ports[j].dev = NULL;
} }
card->nports = i; card->nports = i;
...@@ -1534,7 +1534,7 @@ fst_add_one ( struct pci_dev *pdev, const struct pci_device_id *ent ) ...@@ -1534,7 +1534,7 @@ fst_add_one ( struct pci_dev *pdev, const struct pci_device_id *ent )
hdlc_device *hdlc; hdlc_device *hdlc;
if (!dev) { if (!dev) {
while (i--) while (i--)
free_hdlcdev(card->ports[i].dev); free_netdev(card->ports[i].dev);
printk_err ("FarSync: out of memory\n"); printk_err ("FarSync: out of memory\n");
goto error_free_card; goto error_free_card;
} }
...@@ -1651,7 +1651,7 @@ fst_add_one ( struct pci_dev *pdev, const struct pci_device_id *ent ) ...@@ -1651,7 +1651,7 @@ fst_add_one ( struct pci_dev *pdev, const struct pci_device_id *ent )
error_free_ports: error_free_ports:
for (i = 0; i < card->nports; i++) for (i = 0; i < card->nports; i++)
free_hdlcdev(card->ports[i].dev); free_netdev(card->ports[i].dev);
error_free_card: error_free_card:
kfree ( card ); kfree ( card );
return err; return err;
...@@ -1686,7 +1686,7 @@ fst_remove_one ( struct pci_dev *pdev ) ...@@ -1686,7 +1686,7 @@ fst_remove_one ( struct pci_dev *pdev )
release_region ( card->pci_conf, 0x80 ); release_region ( card->pci_conf, 0x80 );
for (i = 0; i < card->nports; i++) for (i = 0; i < card->nports; i++)
free_hdlcdev(card->ports[i].dev); free_netdev(card->ports[i].dev);
kfree ( card ); kfree ( card );
} }
......
...@@ -226,14 +226,33 @@ int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) ...@@ -226,14 +226,33 @@ int hdlc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
} }
} }
static void hdlc_setup(struct net_device *dev)
{
hdlc_device *hdlc = dev_to_hdlc(dev);
dev->get_stats = hdlc_get_stats;
dev->change_mtu = hdlc_change_mtu;
dev->mtu = HDLC_MAX_MTU;
dev->type = ARPHRD_RAWHDLC;
dev->hard_header_len = 16;
dev->flags = IFF_POINTOPOINT | IFF_NOARP;
hdlc->proto.id = -1;
hdlc->proto.detach = NULL;
hdlc->carrier = 1;
hdlc->open = 0;
spin_lock_init(&hdlc->state_lock);
}
struct net_device *alloc_hdlcdev(void *priv) struct net_device *alloc_hdlcdev(void *priv)
{ {
void *p = kmalloc(sizeof(hdlc_device), GFP_KERNEL); struct net_device *dev;
if (p) { dev = alloc_netdev(sizeof(hdlc_device), "hdlc%d", hdlc_setup);
memset(p, 0, sizeof(hdlc_device)); if (dev)
dev_to_hdlc(p)->priv = priv; dev_to_hdlc(dev)->priv = priv;
} return dev;
return p;
} }
int register_hdlc_device(struct net_device *dev) int register_hdlc_device(struct net_device *dev)
......
...@@ -325,9 +325,9 @@ static void n2_destroy_card(card_t *card) ...@@ -325,9 +325,9 @@ static void n2_destroy_card(card_t *card)
if (card->io) if (card->io)
release_region(card->io, N2_IOPORTS); release_region(card->io, N2_IOPORTS);
if (card->ports[0].dev) if (card->ports[0].dev)
free_hdlcdev(card->ports[0].dev); free_netdev(card->ports[0].dev);
if (card->ports[1].dev) if (card->ports[1].dev)
free_hdlcdev(card->ports[1].dev); free_netdev(card->ports[1].dev);
kfree(card); kfree(card);
} }
......
...@@ -3406,7 +3406,7 @@ static void cpc_init_card(pc300_t * card) ...@@ -3406,7 +3406,7 @@ static void cpc_init_card(pc300_t * card)
} else { } else {
printk ("Dev%d on card(0x%08lx): unable to allocate i/f name.\n", printk ("Dev%d on card(0x%08lx): unable to allocate i/f name.\n",
i + 1, card->hw.ramphys); i + 1, card->hw.ramphys);
free_hdlcdev(dev); free_netdev(dev);
continue; continue;
} }
} }
...@@ -3653,7 +3653,7 @@ static void __devexit cpc_remove_one(struct pci_dev *pdev) ...@@ -3653,7 +3653,7 @@ static void __devexit cpc_remove_one(struct pci_dev *pdev)
} }
for (i = 0; i < card->hw.nchan; i++) for (i = 0; i < card->hw.nchan; i++)
if (card->chan[i].d.dev); if (card->chan[i].d.dev);
free_hdlcdev(card->chan[i].d.dev); free_netdev(card->chan[i].d.dev);
if (card->hw.irq) if (card->hw.irq)
free_irq(card->hw.irq, card); free_irq(card->hw.irq, card);
kfree(card); kfree(card);
......
...@@ -557,7 +557,7 @@ static void wanxl_pci_remove_one(struct pci_dev *pdev) ...@@ -557,7 +557,7 @@ static void wanxl_pci_remove_one(struct pci_dev *pdev)
for (i = 0; i < card->n_ports; i++) for (i = 0; i < card->n_ports; i++)
if (card->__ports[i].dev) if (card->__ports[i].dev)
free_hdlcdev(card->__ports[i].dev); free_netdev(card->__ports[i].dev);
pci_set_drvdata(pdev, NULL); pci_set_drvdata(pdev, NULL);
kfree(card); kfree(card);
......
...@@ -96,7 +96,6 @@ typedef struct pvc_device_struct { ...@@ -96,7 +96,6 @@ typedef struct pvc_device_struct {
typedef struct hdlc_device_struct { typedef struct hdlc_device_struct {
/* To be initialized by hardware driver */ /* To be initialized by hardware driver */
struct net_device netdev; /* master net device - must be first */
struct net_device_stats stats; struct net_device_stats stats;
/* used by HDLC layer to take control over HDLC device from hw driver*/ /* used by HDLC layer to take control over HDLC device from hw driver*/
...@@ -191,15 +190,9 @@ void unregister_hdlc_device(struct net_device *dev); ...@@ -191,15 +190,9 @@ void unregister_hdlc_device(struct net_device *dev);
struct net_device *alloc_hdlcdev(void *priv); struct net_device *alloc_hdlcdev(void *priv);
static inline void free_hdlcdev(struct net_device *dev)
{
kfree(dev);
}
static __inline__ hdlc_device* dev_to_hdlc(struct net_device *dev) static __inline__ hdlc_device* dev_to_hdlc(struct net_device *dev)
{ {
return (hdlc_device*)dev; return netdev_priv(dev);
} }
......
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