orinoco: Handle suspend/restore in core driver
Each device does almost exactly the same things on suspend and resume when upping and downing the interface. So move this logic into a common routine. Signed-off-by: David Kilroy <kilroyd@googlemail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
This commit is contained in:
committed by
John W. Linville
parent
ef96b5c9ed
commit
6415f7df10
@@ -50,15 +50,7 @@ airport_suspend(struct macio_dev *mdev, pm_message_t state)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = __orinoco_down(priv);
|
orinoco_down(priv);
|
||||||
if (err)
|
|
||||||
printk(KERN_WARNING "%s: PBOOK_SLEEP_NOW: Error %d downing interface\n",
|
|
||||||
dev->name, err);
|
|
||||||
|
|
||||||
netif_device_detach(dev);
|
|
||||||
|
|
||||||
priv->hw_unavailable++;
|
|
||||||
|
|
||||||
orinoco_unlock(priv, &flags);
|
orinoco_unlock(priv, &flags);
|
||||||
|
|
||||||
disable_irq(card->irq);
|
disable_irq(card->irq);
|
||||||
@@ -85,30 +77,11 @@ airport_resume(struct macio_dev *mdev)
|
|||||||
|
|
||||||
enable_irq(card->irq);
|
enable_irq(card->irq);
|
||||||
|
|
||||||
err = orinoco_reinit_firmware(priv);
|
|
||||||
if (err) {
|
|
||||||
printk(KERN_ERR "%s: Error %d re-initializing firmware on PBOOK_WAKE\n",
|
|
||||||
dev->name, err);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
spin_lock_irqsave(&priv->lock, flags);
|
spin_lock_irqsave(&priv->lock, flags);
|
||||||
|
err = orinoco_up(priv);
|
||||||
netif_device_attach(dev);
|
|
||||||
|
|
||||||
priv->hw_unavailable--;
|
|
||||||
|
|
||||||
if (priv->open && (!priv->hw_unavailable)) {
|
|
||||||
err = __orinoco_up(priv);
|
|
||||||
if (err)
|
|
||||||
printk(KERN_ERR "%s: Error %d restarting card on PBOOK_WAKE\n",
|
|
||||||
dev->name, err);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
spin_unlock_irqrestore(&priv->lock, flags);
|
spin_unlock_irqrestore(&priv->lock, flags);
|
||||||
|
|
||||||
return 0;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@@ -211,6 +211,8 @@ struct orinoco_rx_data {
|
|||||||
/********************************************************************/
|
/********************************************************************/
|
||||||
|
|
||||||
static void __orinoco_set_multicast_list(struct net_device *dev);
|
static void __orinoco_set_multicast_list(struct net_device *dev);
|
||||||
|
static int __orinoco_up(struct orinoco_private *priv);
|
||||||
|
static int __orinoco_down(struct orinoco_private *priv);
|
||||||
|
|
||||||
/********************************************************************/
|
/********************************************************************/
|
||||||
/* Internal helper functions */
|
/* Internal helper functions */
|
||||||
@@ -1514,7 +1516,7 @@ static void __orinoco_ev_infdrop(struct net_device *dev, hermes_t *hw)
|
|||||||
/* Internal hardware control routines */
|
/* Internal hardware control routines */
|
||||||
/********************************************************************/
|
/********************************************************************/
|
||||||
|
|
||||||
int __orinoco_up(struct orinoco_private *priv)
|
static int __orinoco_up(struct orinoco_private *priv)
|
||||||
{
|
{
|
||||||
struct net_device *dev = priv->ndev;
|
struct net_device *dev = priv->ndev;
|
||||||
struct hermes *hw = &priv->hw;
|
struct hermes *hw = &priv->hw;
|
||||||
@@ -1542,9 +1544,8 @@ int __orinoco_up(struct orinoco_private *priv)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(__orinoco_up);
|
|
||||||
|
|
||||||
int __orinoco_down(struct orinoco_private *priv)
|
static int __orinoco_down(struct orinoco_private *priv)
|
||||||
{
|
{
|
||||||
struct net_device *dev = priv->ndev;
|
struct net_device *dev = priv->ndev;
|
||||||
struct hermes *hw = &priv->hw;
|
struct hermes *hw = &priv->hw;
|
||||||
@@ -1574,9 +1575,8 @@ int __orinoco_down(struct orinoco_private *priv)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(__orinoco_down);
|
|
||||||
|
|
||||||
int orinoco_reinit_firmware(struct orinoco_private *priv)
|
static int orinoco_reinit_firmware(struct orinoco_private *priv)
|
||||||
{
|
{
|
||||||
struct hermes *hw = &priv->hw;
|
struct hermes *hw = &priv->hw;
|
||||||
int err;
|
int err;
|
||||||
@@ -1592,7 +1592,6 @@ int orinoco_reinit_firmware(struct orinoco_private *priv)
|
|||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(orinoco_reinit_firmware);
|
|
||||||
|
|
||||||
int __orinoco_program_rids(struct net_device *dev)
|
int __orinoco_program_rids(struct net_device *dev)
|
||||||
{
|
{
|
||||||
@@ -2389,6 +2388,56 @@ void free_orinocodev(struct orinoco_private *priv)
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL(free_orinocodev);
|
EXPORT_SYMBOL(free_orinocodev);
|
||||||
|
|
||||||
|
int orinoco_up(struct orinoco_private *priv)
|
||||||
|
{
|
||||||
|
struct net_device *dev = priv->ndev;
|
||||||
|
unsigned long flags;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
spin_lock_irqsave(&priv->lock, flags);
|
||||||
|
|
||||||
|
err = orinoco_reinit_firmware(priv);
|
||||||
|
if (err) {
|
||||||
|
printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
|
||||||
|
dev->name, err);
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
netif_device_attach(dev);
|
||||||
|
priv->hw_unavailable--;
|
||||||
|
|
||||||
|
if (priv->open && !priv->hw_unavailable) {
|
||||||
|
err = __orinoco_up(priv);
|
||||||
|
if (err)
|
||||||
|
printk(KERN_ERR "%s: Error %d restarting card\n",
|
||||||
|
dev->name, err);
|
||||||
|
}
|
||||||
|
|
||||||
|
exit:
|
||||||
|
spin_unlock_irqrestore(&priv->lock, flags);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(orinoco_up);
|
||||||
|
|
||||||
|
void orinoco_down(struct orinoco_private *priv)
|
||||||
|
{
|
||||||
|
struct net_device *dev = priv->ndev;
|
||||||
|
unsigned long flags;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
spin_lock_irqsave(&priv->lock, flags);
|
||||||
|
err = __orinoco_down(priv);
|
||||||
|
if (err)
|
||||||
|
printk(KERN_WARNING "%s: Error %d downing interface\n",
|
||||||
|
dev->name, err);
|
||||||
|
|
||||||
|
netif_device_detach(dev);
|
||||||
|
priv->hw_unavailable++;
|
||||||
|
spin_unlock_irqrestore(&priv->lock, flags);
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL(orinoco_down);
|
||||||
|
|
||||||
static void orinoco_get_drvinfo(struct net_device *dev,
|
static void orinoco_get_drvinfo(struct net_device *dev,
|
||||||
struct ethtool_drvinfo *info)
|
struct ethtool_drvinfo *info)
|
||||||
{
|
{
|
||||||
|
@@ -197,9 +197,8 @@ extern int orinoco_if_add(struct orinoco_private *priv,
|
|||||||
unsigned long base_addr,
|
unsigned long base_addr,
|
||||||
unsigned int irq);
|
unsigned int irq);
|
||||||
extern void orinoco_if_del(struct orinoco_private *priv);
|
extern void orinoco_if_del(struct orinoco_private *priv);
|
||||||
extern int __orinoco_up(struct orinoco_private *priv);
|
extern int orinoco_up(struct orinoco_private *priv);
|
||||||
extern int __orinoco_down(struct orinoco_private *priv);
|
extern void orinoco_down(struct orinoco_private *priv);
|
||||||
extern int orinoco_reinit_firmware(struct orinoco_private *priv);
|
|
||||||
extern irqreturn_t orinoco_interrupt(int irq, void *dev_id);
|
extern irqreturn_t orinoco_interrupt(int irq, void *dev_id);
|
||||||
|
|
||||||
/********************************************************************/
|
/********************************************************************/
|
||||||
|
@@ -349,26 +349,12 @@ static int orinoco_cs_suspend(struct pcmcia_device *link)
|
|||||||
{
|
{
|
||||||
struct orinoco_private *priv = link->priv;
|
struct orinoco_private *priv = link->priv;
|
||||||
struct orinoco_pccard *card = priv->card;
|
struct orinoco_pccard *card = priv->card;
|
||||||
struct net_device *dev = priv->ndev;
|
|
||||||
int err = 0;
|
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
/* This is probably racy, but I can't think of
|
/* This is probably racy, but I can't think of
|
||||||
a better way, short of rewriting the PCMCIA
|
a better way, short of rewriting the PCMCIA
|
||||||
layer to not suck :-( */
|
layer to not suck :-( */
|
||||||
if (!test_bit(0, &card->hard_reset_in_progress)) {
|
if (!test_bit(0, &card->hard_reset_in_progress))
|
||||||
spin_lock_irqsave(&priv->lock, flags);
|
orinoco_down(priv);
|
||||||
|
|
||||||
err = __orinoco_down(priv);
|
|
||||||
if (err)
|
|
||||||
printk(KERN_WARNING "%s: Error %d downing interface\n",
|
|
||||||
dev->name, err);
|
|
||||||
|
|
||||||
netif_device_detach(dev);
|
|
||||||
priv->hw_unavailable++;
|
|
||||||
|
|
||||||
spin_unlock_irqrestore(&priv->lock, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -377,32 +363,10 @@ static int orinoco_cs_resume(struct pcmcia_device *link)
|
|||||||
{
|
{
|
||||||
struct orinoco_private *priv = link->priv;
|
struct orinoco_private *priv = link->priv;
|
||||||
struct orinoco_pccard *card = priv->card;
|
struct orinoco_pccard *card = priv->card;
|
||||||
struct net_device *dev = priv->ndev;
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
if (!test_bit(0, &card->hard_reset_in_progress)) {
|
if (!test_bit(0, &card->hard_reset_in_progress))
|
||||||
err = orinoco_reinit_firmware(priv);
|
err = orinoco_up(priv);
|
||||||
if (err) {
|
|
||||||
printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
|
|
||||||
dev->name, err);
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
spin_lock_irqsave(&priv->lock, flags);
|
|
||||||
|
|
||||||
netif_device_attach(dev);
|
|
||||||
priv->hw_unavailable--;
|
|
||||||
|
|
||||||
if (priv->open && !priv->hw_unavailable) {
|
|
||||||
err = __orinoco_up(priv);
|
|
||||||
if (err)
|
|
||||||
printk(KERN_ERR "%s: Error %d restarting card\n",
|
|
||||||
dev->name, err);
|
|
||||||
}
|
|
||||||
|
|
||||||
spin_unlock_irqrestore(&priv->lock, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
@@ -22,28 +22,8 @@ struct orinoco_pci_card {
|
|||||||
static int orinoco_pci_suspend(struct pci_dev *pdev, pm_message_t state)
|
static int orinoco_pci_suspend(struct pci_dev *pdev, pm_message_t state)
|
||||||
{
|
{
|
||||||
struct orinoco_private *priv = pci_get_drvdata(pdev);
|
struct orinoco_private *priv = pci_get_drvdata(pdev);
|
||||||
struct net_device *dev = priv->ndev;
|
|
||||||
unsigned long flags;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = orinoco_lock(priv, &flags);
|
|
||||||
if (err) {
|
|
||||||
printk(KERN_ERR "%s: cannot lock hardware for suspend\n",
|
|
||||||
dev->name);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = __orinoco_down(priv);
|
|
||||||
if (err)
|
|
||||||
printk(KERN_WARNING "%s: error %d bringing interface down "
|
|
||||||
"for suspend\n", dev->name, err);
|
|
||||||
|
|
||||||
netif_device_detach(dev);
|
|
||||||
|
|
||||||
priv->hw_unavailable++;
|
|
||||||
|
|
||||||
orinoco_unlock(priv, &flags);
|
|
||||||
|
|
||||||
|
orinoco_down(priv);
|
||||||
free_irq(pdev->irq, priv);
|
free_irq(pdev->irq, priv);
|
||||||
pci_save_state(pdev);
|
pci_save_state(pdev);
|
||||||
pci_disable_device(pdev);
|
pci_disable_device(pdev);
|
||||||
@@ -56,7 +36,6 @@ static int orinoco_pci_resume(struct pci_dev *pdev)
|
|||||||
{
|
{
|
||||||
struct orinoco_private *priv = pci_get_drvdata(pdev);
|
struct orinoco_private *priv = pci_get_drvdata(pdev);
|
||||||
struct net_device *dev = priv->ndev;
|
struct net_device *dev = priv->ndev;
|
||||||
unsigned long flags;
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
pci_set_power_state(pdev, 0);
|
pci_set_power_state(pdev, 0);
|
||||||
@@ -77,29 +56,9 @@ static int orinoco_pci_resume(struct pci_dev *pdev)
|
|||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = orinoco_reinit_firmware(priv);
|
err = orinoco_up(priv);
|
||||||
if (err) {
|
|
||||||
printk(KERN_ERR "%s: error %d re-initializing firmware "
|
|
||||||
"on resume\n", dev->name, err);
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
spin_lock_irqsave(&priv->lock, flags);
|
return err;
|
||||||
|
|
||||||
netif_device_attach(dev);
|
|
||||||
|
|
||||||
priv->hw_unavailable--;
|
|
||||||
|
|
||||||
if (priv->open && (!priv->hw_unavailable)) {
|
|
||||||
err = __orinoco_up(priv);
|
|
||||||
if (err)
|
|
||||||
printk(KERN_ERR "%s: Error %d restarting card on resume\n",
|
|
||||||
dev->name, err);
|
|
||||||
}
|
|
||||||
|
|
||||||
spin_unlock_irqrestore(&priv->lock, flags);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#define orinoco_pci_suspend NULL
|
#define orinoco_pci_suspend NULL
|
||||||
|
@@ -421,22 +421,10 @@ static int
|
|||||||
spectrum_cs_suspend(struct pcmcia_device *link)
|
spectrum_cs_suspend(struct pcmcia_device *link)
|
||||||
{
|
{
|
||||||
struct orinoco_private *priv = link->priv;
|
struct orinoco_private *priv = link->priv;
|
||||||
struct net_device *dev = priv->ndev;
|
|
||||||
unsigned long flags;
|
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
/* Mark the device as stopped, to block IO until later */
|
/* Mark the device as stopped, to block IO until later */
|
||||||
spin_lock_irqsave(&priv->lock, flags);
|
orinoco_down(priv);
|
||||||
|
|
||||||
err = __orinoco_down(priv);
|
|
||||||
if (err)
|
|
||||||
printk(KERN_WARNING "%s: Error %d downing interface\n",
|
|
||||||
dev->name, err);
|
|
||||||
|
|
||||||
netif_device_detach(dev);
|
|
||||||
priv->hw_unavailable++;
|
|
||||||
|
|
||||||
spin_unlock_irqrestore(&priv->lock, flags);
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -445,32 +433,9 @@ static int
|
|||||||
spectrum_cs_resume(struct pcmcia_device *link)
|
spectrum_cs_resume(struct pcmcia_device *link)
|
||||||
{
|
{
|
||||||
struct orinoco_private *priv = link->priv;
|
struct orinoco_private *priv = link->priv;
|
||||||
struct net_device *dev = priv->ndev;
|
int err = orinoco_up(priv);
|
||||||
unsigned long flags;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
err = orinoco_reinit_firmware(priv);
|
return err;
|
||||||
if (err) {
|
|
||||||
printk(KERN_ERR "%s: Error %d re-initializing firmware\n",
|
|
||||||
dev->name, err);
|
|
||||||
return -EIO;
|
|
||||||
}
|
|
||||||
|
|
||||||
spin_lock_irqsave(&priv->lock, flags);
|
|
||||||
|
|
||||||
netif_device_attach(dev);
|
|
||||||
priv->hw_unavailable--;
|
|
||||||
|
|
||||||
if (priv->open && !priv->hw_unavailable) {
|
|
||||||
err = __orinoco_up(priv);
|
|
||||||
if (err)
|
|
||||||
printk(KERN_ERR "%s: Error %d restarting card\n",
|
|
||||||
dev->name, err);
|
|
||||||
}
|
|
||||||
|
|
||||||
spin_unlock_irqrestore(&priv->lock, flags);
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user