Commit 966b66c7 authored by Alexander Viro's avatar Alexander Viro Committed by Stephen Hemminger

[netdrvr pcnet_cs] alloc_ei_netdev-associated cleanups

Create __alloc_ei_netdev() helper, which takes a size argument for
allocation of driver-private structures.

Use __alloc_ei_netdev in pcnet_cs, for embedded priv struct.
parent 34a933e8
......@@ -1044,11 +1044,11 @@ static void __ethdev_init(struct net_device *dev)
*
* Allocate 8390-specific net_device.
*/
struct net_device *alloc_ei_netdev(void)
struct net_device *__alloc_ei_netdev(int size)
{
struct net_device *dev;
dev = alloc_netdev(sizeof(struct ei_device), "eth%d", __ethdev_init);
dev = alloc_netdev(sizeof(struct ei_device) + size, "eth%d", __ethdev_init);
if (dev)
ei_device_init(dev->priv);
......@@ -1158,7 +1158,7 @@ EXPORT_SYMBOL(ei_interrupt);
EXPORT_SYMBOL(ei_tx_timeout);
EXPORT_SYMBOL(ethdev_init);
EXPORT_SYMBOL(NS8390_init);
EXPORT_SYMBOL(alloc_ei_netdev);
EXPORT_SYMBOL(__alloc_ei_netdev);
#if defined(MODULE)
......
......@@ -44,7 +44,11 @@ extern void NS8390_init(struct net_device *dev, int startp);
extern int ei_open(struct net_device *dev);
extern int ei_close(struct net_device *dev);
extern irqreturn_t ei_interrupt(int irq, void *dev_id, struct pt_regs *regs);
extern struct net_device *alloc_ei_netdev(void);
extern struct net_device *__alloc_ei_netdev(int size);
static inline struct net_device *alloc_ei_netdev(void)
{
return __alloc_ei_netdev(0);
}
/* You have one of these per-board */
struct ei_device {
......
......@@ -224,7 +224,6 @@ static hw_info_t dl10019_info = { 0, 0, 0, 0, IS_DL10019|HAS_MII };
static hw_info_t dl10022_info = { 0, 0, 0, 0, IS_DL10022|HAS_MII };
typedef struct pcnet_dev_t {
struct net_device dev; /* so &dev == &pcnet_dev_t */
dev_link_t link;
dev_node_t node;
u_int flags;
......@@ -237,16 +236,10 @@ typedef struct pcnet_dev_t {
u_long mii_reset;
} pcnet_dev_t;
/*======================================================================
We never need to do anything when a pcnet device is "initialized"
by the net software, because we only register already-found cards.
======================================================================*/
static int pcnet_init(struct net_device *dev)
static inline pcnet_dev_t *PRIV(struct net_device *dev)
{
return 0;
char *p = netdev_priv(dev);
return (pcnet_dev_t *)(p + sizeof(struct ei_device));
}
/*======================================================================
......@@ -268,11 +261,11 @@ static dev_link_t *pcnet_attach(void)
DEBUG(0, "pcnet_attach()\n");
/* Create new ethernet device */
info = kmalloc(sizeof(*info), GFP_KERNEL);
if (!info) return NULL;
memset(info, 0, sizeof(*info));
link = &info->link; dev = &info->dev;
link->priv = info;
dev = __alloc_ei_netdev(sizeof(pcnet_dev_t));
if (!dev) return NULL;
info = PRIV(dev);
link = &info->link;
link->priv = dev;
link->irq.Attributes = IRQ_TYPE_EXCLUSIVE;
link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID;
......@@ -284,9 +277,7 @@ static dev_link_t *pcnet_attach(void)
link->conf.Attributes = CONF_ENABLE_IRQ;
link->conf.IntType = INT_MEMORY_AND_IO;
ethdev_init(dev);
SET_MODULE_OWNER(dev);
dev->init = &pcnet_init;
dev->open = &pcnet_open;
dev->stop = &pcnet_close;
dev->set_config = &set_config;
......@@ -324,7 +315,7 @@ static dev_link_t *pcnet_attach(void)
static void pcnet_detach(dev_link_t *link)
{
pcnet_dev_t *info = link->priv;
struct net_device *dev = link->priv;
dev_link_t **linkp;
DEBUG(0, "pcnet_detach(0x%p)\n", link);
......@@ -343,12 +334,9 @@ static void pcnet_detach(dev_link_t *link)
/* Unlink device structure, free bits */
*linkp = link->next;
if (link->dev) {
unregister_netdev(&info->dev);
free_netdev(&info->dev);
} else
kfree(info);
if (link->dev)
unregister_netdev(dev);
free_netdev(dev);
} /* pcnet_detach */
/*======================================================================
......@@ -580,8 +568,8 @@ static int try_io_port(dev_link_t *link)
static void pcnet_config(dev_link_t *link)
{
client_handle_t handle = link->handle;
pcnet_dev_t *info = link->priv;
struct net_device *dev = &info->dev;
struct net_device *dev = link->priv;
pcnet_dev_t *info = PRIV(dev);
tuple_t tuple;
cisparse_t parse;
int i, last_ret, last_fn, start_pg, stop_pg, cm_offset;
......@@ -783,7 +771,7 @@ static void pcnet_config(dev_link_t *link)
static void pcnet_release(dev_link_t *link)
{
pcnet_dev_t *info = link->priv;
pcnet_dev_t *info = PRIV(link->priv);
DEBUG(0, "pcnet_release(0x%p)\n", link);
......@@ -811,7 +799,7 @@ static int pcnet_event(event_t event, int priority,
event_callback_args_t *args)
{
dev_link_t *link = args->client_data;
pcnet_dev_t *info = link->priv;
struct net_device *dev = link->priv;
DEBUG(2, "pcnet_event(0x%06x)\n", event);
......@@ -819,7 +807,7 @@ static int pcnet_event(event_t event, int priority,
case CS_EVENT_CARD_REMOVAL:
link->state &= ~DEV_PRESENT;
if (link->state & DEV_CONFIG) {
netif_device_detach(&info->dev);
netif_device_detach(dev);
pcnet_release(link);
}
break;
......@@ -833,7 +821,7 @@ static int pcnet_event(event_t event, int priority,
case CS_EVENT_RESET_PHYSICAL:
if (link->state & DEV_CONFIG) {
if (link->open)
netif_device_detach(&info->dev);
netif_device_detach(dev);
CardServices(ReleaseConfiguration, link->handle);
}
break;
......@@ -844,9 +832,9 @@ static int pcnet_event(event_t event, int priority,
if (link->state & DEV_CONFIG) {
CardServices(RequestConfiguration, link->handle, &link->conf);
if (link->open) {
pcnet_reset_8390(&info->dev);
NS8390_init(&info->dev, 1);
netif_device_attach(&info->dev);
pcnet_reset_8390(dev);
NS8390_init(dev, 1);
netif_device_attach(dev);
}
}
break;
......@@ -1026,7 +1014,7 @@ static void write_asic(ioaddr_t ioaddr, int location, short asic_data)
static void set_misc_reg(struct net_device *dev)
{
ioaddr_t nic_base = dev->base_addr;
pcnet_dev_t *info = (pcnet_dev_t *)dev;
pcnet_dev_t *info = PRIV(dev);
u_char tmp;
if (info->flags & HAS_MISC_REG) {
......@@ -1056,7 +1044,7 @@ static void set_misc_reg(struct net_device *dev)
static void mii_phy_probe(struct net_device *dev)
{
pcnet_dev_t *info = (pcnet_dev_t *)dev;
pcnet_dev_t *info = PRIV(dev);
ioaddr_t mii_addr = dev->base_addr + DLINK_GPIO;
int i;
u_int tmp, phyid;
......@@ -1080,7 +1068,7 @@ static void mii_phy_probe(struct net_device *dev)
static int pcnet_open(struct net_device *dev)
{
pcnet_dev_t *info = (pcnet_dev_t *)dev;
pcnet_dev_t *info = PRIV(dev);
dev_link_t *link = &info->link;
DEBUG(2, "pcnet_open('%s')\n", dev->name);
......@@ -1097,7 +1085,7 @@ static int pcnet_open(struct net_device *dev)
info->link_status = 0x00;
init_timer(&info->watchdog);
info->watchdog.function = &ei_watchdog;
info->watchdog.data = (u_long)info;
info->watchdog.data = (u_long)dev;
info->watchdog.expires = jiffies + HZ;
add_timer(&info->watchdog);
......@@ -1108,7 +1096,7 @@ static int pcnet_open(struct net_device *dev)
static int pcnet_close(struct net_device *dev)
{
pcnet_dev_t *info = (pcnet_dev_t *)dev;
pcnet_dev_t *info = PRIV(dev);
dev_link_t *link = &info->link;
DEBUG(2, "pcnet_close('%s')\n", dev->name);
......@@ -1159,7 +1147,7 @@ static void pcnet_reset_8390(struct net_device *dev)
static int set_config(struct net_device *dev, struct ifmap *map)
{
pcnet_dev_t *info = (pcnet_dev_t *)dev;
pcnet_dev_t *info = PRIV(dev);
if ((map->port != (u_char)(-1)) && (map->port != dev->if_port)) {
if (!(info->flags & HAS_MISC_REG))
return -EOPNOTSUPP;
......@@ -1177,7 +1165,8 @@ static int set_config(struct net_device *dev, struct ifmap *map)
static irqreturn_t ei_irq_wrapper(int irq, void *dev_id, struct pt_regs *regs)
{
pcnet_dev_t *info = dev_id;
struct net_device *dev = dev_id;
pcnet_dev_t *info = PRIV(dev);
info->stale = 0;
ei_interrupt(irq, dev_id, regs);
/* FIXME! Was it really ours? */
......@@ -1186,8 +1175,8 @@ static irqreturn_t ei_irq_wrapper(int irq, void *dev_id, struct pt_regs *regs)
static void ei_watchdog(u_long arg)
{
pcnet_dev_t *info = (pcnet_dev_t *)(arg);
struct net_device *dev = &info->dev;
struct net_device *dev = (struct net_device *)arg;
pcnet_dev_t *info = PRIV(dev);
ioaddr_t nic_base = dev->base_addr;
ioaddr_t mii_addr = nic_base + DLINK_GPIO;
u_short link;
......@@ -1290,7 +1279,7 @@ static struct ethtool_ops netdev_ethtool_ops = {
static int ei_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
{
pcnet_dev_t *info = (pcnet_dev_t *)dev;
pcnet_dev_t *info = PRIV(dev);
u16 *data = (u16 *)&rq->ifr_data;
ioaddr_t mii_addr = dev->base_addr + DLINK_GPIO;
switch (cmd) {
......@@ -1401,7 +1390,7 @@ static void dma_block_output(struct net_device *dev, int count,
const u_char *buf, const int start_page)
{
ioaddr_t nic_base = dev->base_addr;
pcnet_dev_t *info = (pcnet_dev_t *)dev;
pcnet_dev_t *info = PRIV(dev);
#ifdef PCMCIA_DEBUG
int retries = 0;
#endif
......@@ -1587,7 +1576,7 @@ static int setup_shmem_window(dev_link_t *link, int start_pg,
int stop_pg, int cm_offset)
{
struct net_device *dev = link->priv;
pcnet_dev_t *info = link->priv;
pcnet_dev_t *info = PRIV(dev);
win_req_t req;
memreq_t mem;
int i, window_size, offset, last_ret, last_fn;
......
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