orinoco_pci.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* orinoco_pci.h
  2. *
  3. * Common code for all Orinoco drivers for PCI devices, including
  4. * both native PCI and PCMCIA-to-PCI bridges.
  5. *
  6. * Copyright (C) 2005, Pavel Roskin.
  7. * See orinoco.c for license.
  8. */
  9. #ifndef _ORINOCO_PCI_H
  10. #define _ORINOCO_PCI_H
  11. #include <linux/netdevice.h>
  12. /* Driver specific data */
  13. struct orinoco_pci_card {
  14. void __iomem *bridge_io;
  15. void __iomem *attr_io;
  16. };
  17. /* Set base address or memory range of the network device based on
  18. * the PCI device it's using. Specify BAR of the "main" resource.
  19. * To be used after request_irq(). */
  20. static inline void orinoco_pci_setup_netdev(struct net_device *dev,
  21. struct pci_dev *pdev, int bar)
  22. {
  23. char *range_type;
  24. unsigned long start = pci_resource_start(pdev, bar);
  25. unsigned long len = pci_resource_len(pdev, bar);
  26. unsigned long flags = pci_resource_flags(pdev, bar);
  27. unsigned long end = start + len - 1;
  28. dev->irq = pdev->irq;
  29. if (flags & IORESOURCE_IO) {
  30. dev->base_addr = start;
  31. range_type = "ports";
  32. } else {
  33. dev->mem_start = start;
  34. dev->mem_end = end;
  35. range_type = "memory";
  36. }
  37. printk(KERN_DEBUG PFX "%s: irq %d, %s 0x%lx-0x%lx\n",
  38. pci_name(pdev), pdev->irq, range_type, start, end);
  39. }
  40. static int orinoco_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  41. {
  42. struct net_device *dev = pci_get_drvdata(pdev);
  43. struct orinoco_private *priv = netdev_priv(dev);
  44. unsigned long flags;
  45. int err;
  46. err = orinoco_lock(priv, &flags);
  47. if (err) {
  48. printk(KERN_ERR "%s: cannot lock hardware for suspend\n",
  49. dev->name);
  50. return err;
  51. }
  52. err = __orinoco_down(dev);
  53. if (err)
  54. printk(KERN_WARNING "%s: error %d bringing interface down "
  55. "for suspend\n", dev->name, err);
  56. netif_device_detach(dev);
  57. priv->hw_unavailable++;
  58. orinoco_unlock(priv, &flags);
  59. free_irq(pdev->irq, dev);
  60. pci_save_state(pdev);
  61. pci_disable_device(pdev);
  62. pci_set_power_state(pdev, PCI_D3hot);
  63. return 0;
  64. }
  65. static int orinoco_pci_resume(struct pci_dev *pdev)
  66. {
  67. struct net_device *dev = pci_get_drvdata(pdev);
  68. struct orinoco_private *priv = netdev_priv(dev);
  69. unsigned long flags;
  70. int err;
  71. pci_set_power_state(pdev, 0);
  72. pci_enable_device(pdev);
  73. pci_restore_state(pdev);
  74. err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
  75. dev->name, dev);
  76. if (err) {
  77. printk(KERN_ERR "%s: cannot re-allocate IRQ on resume\n",
  78. dev->name);
  79. pci_disable_device(pdev);
  80. return -EBUSY;
  81. }
  82. err = orinoco_reinit_firmware(dev);
  83. if (err) {
  84. printk(KERN_ERR "%s: error %d re-initializing firmware "
  85. "on resume\n", dev->name, err);
  86. return err;
  87. }
  88. spin_lock_irqsave(&priv->lock, flags);
  89. netif_device_attach(dev);
  90. priv->hw_unavailable--;
  91. if (priv->open && (! priv->hw_unavailable)) {
  92. err = __orinoco_up(dev);
  93. if (err)
  94. printk(KERN_ERR "%s: Error %d restarting card on resume\n",
  95. dev->name, err);
  96. }
  97. spin_unlock_irqrestore(&priv->lock, flags);
  98. return 0;
  99. }
  100. #endif /* _ORINOCO_PCI_H */