Commit 41fb9c44 authored by Russell King's avatar Russell King Committed by Dale Farnsworth

[PATCH] PCMCIA net device unplugging ordering fix

This is a rather old patch which re-orders the teardown of PCMCIA
network devices.  Current device drivers remove the IO mappings,
interrupts, and free any PCMCIA windows before they unregister
themselves from the network layer.

This patch ensures that we first unregister from the network layer
before performing any teardown of resources or windows.

Note: the only card which has been tested in this patch is pcnet_cs.
parent 6103d1db
......@@ -360,7 +360,10 @@ static void tc574_detach(dev_link_t *link)
for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
if (*linkp == link) break;
if (*linkp == NULL)
return;
return;
if (link->dev)
unregister_netdev(dev);
if (link->state & DEV_CONFIG)
tc574_release(link);
......@@ -370,8 +373,6 @@ static void tc574_detach(dev_link_t *link)
/* Unlink device structure, free bits */
*linkp = link->next;
if (link->dev)
unregister_netdev(dev);
free_netdev(dev);
} /* tc574_detach */
......@@ -580,10 +581,8 @@ static int tc574_event(event_t event, int priority,
switch (event) {
case CS_EVENT_CARD_REMOVAL:
link->state &= ~DEV_PRESENT;
if (link->state & DEV_CONFIG) {
if (link->state & DEV_CONFIG)
netif_device_detach(dev);
tc574_release(link);
}
break;
case CS_EVENT_CARD_INSERTION:
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
......
......@@ -276,6 +276,9 @@ static void tc589_detach(dev_link_t *link)
if (*linkp == NULL)
return;
if (link->dev)
unregister_netdev(dev);
if (link->state & DEV_CONFIG)
tc589_release(link);
......@@ -284,8 +287,6 @@ static void tc589_detach(dev_link_t *link)
/* Unlink device structure, free bits */
*linkp = link->next;
if (link->dev)
unregister_netdev(dev);
free_netdev(dev);
} /* tc589_detach */
......@@ -456,10 +457,8 @@ static int tc589_event(event_t event, int priority,
switch (event) {
case CS_EVENT_CARD_REMOVAL:
link->state &= ~DEV_PRESENT;
if (link->state & DEV_CONFIG) {
if (link->state & DEV_CONFIG)
netif_device_detach(dev);
tc589_release(link);
}
break;
case CS_EVENT_CARD_INSERTION:
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
......
......@@ -231,6 +231,9 @@ static void axnet_detach(dev_link_t *link)
if (*linkp == NULL)
return;
if (link->dev)
unregister_netdev(dev);
if (link->state & DEV_CONFIG)
axnet_release(link);
......@@ -239,8 +242,6 @@ static void axnet_detach(dev_link_t *link)
/* Unlink device structure, free bits */
*linkp = link->next;
if (link->dev)
unregister_netdev(dev);
free_netdev(dev);
} /* axnet_detach */
......@@ -525,10 +526,8 @@ static int axnet_event(event_t event, int priority,
switch (event) {
case CS_EVENT_CARD_REMOVAL:
link->state &= ~DEV_PRESENT;
if (link->state & DEV_CONFIG) {
if (link->state & DEV_CONFIG)
netif_device_detach(dev);
axnet_release(link);
}
break;
case CS_EVENT_CARD_INSERTION:
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
......
......@@ -262,6 +262,19 @@ static void com20020_detach(dev_link_t *link)
dev = info->dev;
if (link->dev) {
DEBUG(1,"unregister...\n");
unregister_netdev(dev);
/*
* this is necessary because we register our IRQ separately
* from card services.
*/
if (dev->irq)
free_irq(dev->irq, dev);
}
if (link->state & DEV_CONFIG)
com20020_release(link);
......@@ -276,21 +289,6 @@ static void com20020_detach(dev_link_t *link)
dev = info->dev;
if (dev)
{
if (link->dev)
{
DEBUG(1,"unregister...\n");
unregister_netdev(dev);
/*
* this is necessary because we register our IRQ separately
* from card services.
*/
if (dev->irq)
free_irq(dev->irq, dev);
/* ...but I/O ports are done automatically by card services */
}
DEBUG(1,"kfree...\n");
free_netdev(dev);
}
......@@ -461,10 +459,8 @@ static int com20020_event(event_t event, int priority,
switch (event) {
case CS_EVENT_CARD_REMOVAL:
link->state &= ~DEV_PRESENT;
if (link->state & DEV_CONFIG) {
if (link->state & DEV_CONFIG)
netif_device_detach(dev);
link->state |= DEV_RELEASE_PENDING;
}
break;
case CS_EVENT_CARD_INSERTION:
link->state |= DEV_PRESENT;
......
......@@ -332,6 +332,9 @@ static void fmvj18x_detach(dev_link_t *link)
if (*linkp == NULL)
return;
if (link->dev)
unregister_netdev(dev);
if (link->state & DEV_CONFIG)
fmvj18x_release(link);
......@@ -341,8 +344,6 @@ static void fmvj18x_detach(dev_link_t *link)
/* Unlink device structure, free pieces */
*linkp = link->next;
if (link->dev)
unregister_netdev(dev);
free_netdev(dev);
} /* fmvj18x_detach */
......@@ -741,10 +742,8 @@ static int fmvj18x_event(event_t event, int priority,
switch (event) {
case CS_EVENT_CARD_REMOVAL:
link->state &= ~DEV_PRESENT;
if (link->state & DEV_CONFIG) {
if (link->state & DEV_CONFIG)
netif_device_detach(dev);
fmvj18x_release(link);
}
break;
case CS_EVENT_CARD_INSERTION:
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
......
......@@ -446,7 +446,6 @@ static int ibmtr_event(event_t event, int priority,
struct tok_info *priv = netdev_priv(dev);
priv->sram_virt |= 1;
netif_device_detach(dev);
ibmtr_release(link);
}
break;
case CS_EVENT_CARD_INSERTION:
......
......@@ -551,6 +551,9 @@ static void nmclan_detach(dev_link_t *link)
if (*linkp == NULL)
return;
if (link->dev)
unregister_netdev(dev);
if (link->state & DEV_CONFIG)
nmclan_release(link);
......@@ -559,8 +562,6 @@ static void nmclan_detach(dev_link_t *link)
/* Unlink device structure, free bits */
*linkp = link->next;
if (link->dev)
unregister_netdev(dev);
free_netdev(dev);
} /* nmclan_detach */
......@@ -834,10 +835,8 @@ static int nmclan_event(event_t event, int priority,
switch (event) {
case CS_EVENT_CARD_REMOVAL:
link->state &= ~DEV_PRESENT;
if (link->state & DEV_CONFIG) {
if (link->state & DEV_CONFIG)
netif_device_detach(dev);
nmclan_release(link);
}
break;
case CS_EVENT_CARD_INSERTION:
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
......
......@@ -326,6 +326,9 @@ static void pcnet_detach(dev_link_t *link)
if (*linkp == NULL)
return;
if (link->dev)
unregister_netdev(dev);
if (link->state & DEV_CONFIG)
pcnet_release(link);
......@@ -334,8 +337,6 @@ static void pcnet_detach(dev_link_t *link)
/* Unlink device structure, free bits */
*linkp = link->next;
if (link->dev)
unregister_netdev(dev);
free_netdev(dev);
} /* pcnet_detach */
......@@ -806,10 +807,8 @@ static int pcnet_event(event_t event, int priority,
switch (event) {
case CS_EVENT_CARD_REMOVAL:
link->state &= ~DEV_PRESENT;
if (link->state & DEV_CONFIG) {
if (link->state & DEV_CONFIG)
netif_device_detach(dev);
pcnet_release(link);
}
break;
case CS_EVENT_CARD_INSERTION:
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
......
......@@ -411,6 +411,9 @@ static void smc91c92_detach(dev_link_t *link)
if (*linkp == NULL)
return;
if (link->dev)
unregister_netdev(dev);
if (link->state & DEV_CONFIG)
smc91c92_release(link);
......@@ -419,8 +422,6 @@ static void smc91c92_detach(dev_link_t *link)
/* Unlink device structure, free bits */
*linkp = link->next;
if (link->dev)
unregister_netdev(dev);
free_netdev(dev);
} /* smc91c92_detach */
......@@ -1112,10 +1113,8 @@ static int smc91c92_event(event_t event, int priority,
switch (event) {
case CS_EVENT_CARD_REMOVAL:
link->state &= ~DEV_PRESENT;
if (link->state & DEV_CONFIG) {
if (link->state & DEV_CONFIG)
netif_device_detach(dev);
smc91c92_release(link);
}
break;
case CS_EVENT_CARD_INSERTION:
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
......
......@@ -668,6 +668,9 @@ xirc2ps_detach(dev_link_t * link)
return;
}
if (link->dev)
unregister_netdev(dev);
/*
* If the device is currently configured and active, we won't
* actually delete it yet. Instead, it is marked so that when
......@@ -683,8 +686,6 @@ xirc2ps_detach(dev_link_t * link)
/* Unlink device structure, free it */
*linkp = link->next;
if (link->dev)
unregister_netdev(dev);
free_netdev(dev);
} /* xirc2ps_detach */
......@@ -1203,10 +1204,8 @@ xirc2ps_event(event_t event, int priority,
break;
case CS_EVENT_CARD_REMOVAL:
link->state &= ~DEV_PRESENT;
if (link->state & DEV_CONFIG) {
if (link->state & DEV_CONFIG)
netif_device_detach(dev);
xirc2ps_release(link);
}
break;
case CS_EVENT_CARD_INSERTION:
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
......
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