orinoco_pci.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. /* orinoco_pci.c
  2. *
  3. * Driver for Prism 2.5/3 devices that have a direct PCI interface
  4. * (i.e. these are not PCMCIA cards in a PCMCIA-to-PCI bridge).
  5. * The card contains only one PCI region, which contains all the usual
  6. * hermes registers, as well as the COR register.
  7. *
  8. * Current maintainers are:
  9. * Pavel Roskin <proski AT gnu.org>
  10. * and David Gibson <hermes AT gibson.dropbear.id.au>
  11. *
  12. * Some of this code is borrowed from orinoco_plx.c
  13. * Copyright (C) 2001 Daniel Barlow <dan AT telent.net>
  14. * Some of this code is "inspired" by linux-wlan-ng-0.1.10, but nothing
  15. * has been copied from it. linux-wlan-ng-0.1.10 is originally :
  16. * Copyright (C) 1999 AbsoluteValue Systems, Inc. All Rights Reserved.
  17. * This file originally written by:
  18. * Copyright (C) 2001 Jean Tourrilhes <jt AT hpl.hp.com>
  19. * And is now maintained by:
  20. * (C) Copyright David Gibson, IBM Corp. 2002-2003.
  21. *
  22. * The contents of this file are subject to the Mozilla Public License
  23. * Version 1.1 (the "License"); you may not use this file except in
  24. * compliance with the License. You may obtain a copy of the License
  25. * at http://www.mozilla.org/MPL/
  26. *
  27. * Software distributed under the License is distributed on an "AS IS"
  28. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  29. * the License for the specific language governing rights and
  30. * limitations under the License.
  31. *
  32. * Alternatively, the contents of this file may be used under the
  33. * terms of the GNU General Public License version 2 (the "GPL"), in
  34. * which case the provisions of the GPL are applicable instead of the
  35. * above. If you wish to allow the use of your version of this file
  36. * only under the terms of the GPL and not to allow others to use your
  37. * version of this file under the MPL, indicate your decision by
  38. * deleting the provisions above and replace them with the notice and
  39. * other provisions required by the GPL. If you do not delete the
  40. * provisions above, a recipient may use your version of this file
  41. * under either the MPL or the GPL.
  42. */
  43. #define DRIVER_NAME "orinoco_pci"
  44. #define PFX DRIVER_NAME ": "
  45. #include <linux/config.h>
  46. #include <linux/module.h>
  47. #include <linux/kernel.h>
  48. #include <linux/init.h>
  49. #include <linux/delay.h>
  50. #include <linux/pci.h>
  51. #include "orinoco.h"
  52. #include "orinoco_pci.h"
  53. /* Offset of the COR register of the PCI card */
  54. #define HERMES_PCI_COR (0x26)
  55. /* Bitmask to reset the card */
  56. #define HERMES_PCI_COR_MASK (0x0080)
  57. /* Magic timeouts for doing the reset.
  58. * Those times are straight from wlan-ng, and it is claimed that they
  59. * are necessary. Alan will kill me. Take your time and grab a coffee. */
  60. #define HERMES_PCI_COR_ONT (250) /* ms */
  61. #define HERMES_PCI_COR_OFFT (500) /* ms */
  62. #define HERMES_PCI_COR_BUSYT (500) /* ms */
  63. /*
  64. * Do a soft reset of the card using the Configuration Option Register
  65. * We need this to get going...
  66. * This is the part of the code that is strongly inspired from wlan-ng
  67. *
  68. * Note : This code is done with irq enabled. This mean that many
  69. * interrupts will occur while we are there. This is why we use the
  70. * jiffies to regulate time instead of a straight mdelay(). Usually we
  71. * need only around 245 iteration of the loop to do 250 ms delay.
  72. *
  73. * Note bis : Don't try to access HERMES_CMD during the reset phase.
  74. * It just won't work !
  75. */
  76. static int orinoco_pci_cor_reset(struct orinoco_private *priv)
  77. {
  78. hermes_t *hw = &priv->hw;
  79. unsigned long timeout;
  80. u16 reg;
  81. /* Assert the reset until the card notices */
  82. hermes_write_regn(hw, PCI_COR, HERMES_PCI_COR_MASK);
  83. mdelay(HERMES_PCI_COR_ONT);
  84. /* Give time for the card to recover from this hard effort */
  85. hermes_write_regn(hw, PCI_COR, 0x0000);
  86. mdelay(HERMES_PCI_COR_OFFT);
  87. /* The card is ready when it's no longer busy */
  88. timeout = jiffies + (HERMES_PCI_COR_BUSYT * HZ / 1000);
  89. reg = hermes_read_regn(hw, CMD);
  90. while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
  91. mdelay(1);
  92. reg = hermes_read_regn(hw, CMD);
  93. }
  94. /* Still busy? */
  95. if (reg & HERMES_CMD_BUSY) {
  96. printk(KERN_ERR PFX "Busy timeout\n");
  97. return -ETIMEDOUT;
  98. }
  99. return 0;
  100. }
  101. static int orinoco_pci_init_one(struct pci_dev *pdev,
  102. const struct pci_device_id *ent)
  103. {
  104. int err;
  105. struct orinoco_private *priv;
  106. struct orinoco_pci_card *card;
  107. struct net_device *dev;
  108. void __iomem *hermes_io;
  109. err = pci_enable_device(pdev);
  110. if (err) {
  111. printk(KERN_ERR PFX "Cannot enable PCI device\n");
  112. return err;
  113. }
  114. err = pci_request_regions(pdev, DRIVER_NAME);
  115. if (err) {
  116. printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
  117. goto fail_resources;
  118. }
  119. hermes_io = pci_iomap(pdev, 0, 0);
  120. if (!hermes_io) {
  121. printk(KERN_ERR PFX "Cannot remap chipset registers\n");
  122. err = -EIO;
  123. goto fail_map_hermes;
  124. }
  125. /* Allocate network device */
  126. dev = alloc_orinocodev(sizeof(*card), orinoco_pci_cor_reset);
  127. if (!dev) {
  128. printk(KERN_ERR PFX "Cannot allocate network device\n");
  129. err = -ENOMEM;
  130. goto fail_alloc;
  131. }
  132. priv = netdev_priv(dev);
  133. card = priv->card;
  134. SET_MODULE_OWNER(dev);
  135. SET_NETDEV_DEV(dev, &pdev->dev);
  136. hermes_struct_init(&priv->hw, hermes_io, HERMES_32BIT_REGSPACING);
  137. err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
  138. dev->name, dev);
  139. if (err) {
  140. printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
  141. err = -EBUSY;
  142. goto fail_irq;
  143. }
  144. orinoco_pci_setup_netdev(dev, pdev, 0);
  145. err = orinoco_pci_cor_reset(priv);
  146. if (err) {
  147. printk(KERN_ERR PFX "Initial reset failed\n");
  148. goto fail;
  149. }
  150. err = register_netdev(dev);
  151. if (err) {
  152. printk(KERN_ERR PFX "Cannot register network device\n");
  153. goto fail;
  154. }
  155. pci_set_drvdata(pdev, dev);
  156. return 0;
  157. fail:
  158. free_irq(pdev->irq, dev);
  159. fail_irq:
  160. pci_set_drvdata(pdev, NULL);
  161. free_orinocodev(dev);
  162. fail_alloc:
  163. pci_iounmap(pdev, hermes_io);
  164. fail_map_hermes:
  165. pci_release_regions(pdev);
  166. fail_resources:
  167. pci_disable_device(pdev);
  168. return err;
  169. }
  170. static void __devexit orinoco_pci_remove_one(struct pci_dev *pdev)
  171. {
  172. struct net_device *dev = pci_get_drvdata(pdev);
  173. struct orinoco_private *priv = netdev_priv(dev);
  174. unregister_netdev(dev);
  175. free_irq(dev->irq, dev);
  176. pci_set_drvdata(pdev, NULL);
  177. free_orinocodev(dev);
  178. pci_iounmap(pdev, priv->hw.iobase);
  179. pci_release_regions(pdev);
  180. pci_disable_device(pdev);
  181. }
  182. static struct pci_device_id orinoco_pci_id_table[] = {
  183. /* Intersil Prism 3 */
  184. {0x1260, 0x3872, PCI_ANY_ID, PCI_ANY_ID,},
  185. /* Intersil Prism 2.5 */
  186. {0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID,},
  187. /* Samsung MagicLAN SWL-2210P */
  188. {0x167d, 0xa000, PCI_ANY_ID, PCI_ANY_ID,},
  189. {0,},
  190. };
  191. MODULE_DEVICE_TABLE(pci, orinoco_pci_id_table);
  192. static struct pci_driver orinoco_pci_driver = {
  193. .name = DRIVER_NAME,
  194. .id_table = orinoco_pci_id_table,
  195. .probe = orinoco_pci_init_one,
  196. .remove = __devexit_p(orinoco_pci_remove_one),
  197. .suspend = orinoco_pci_suspend,
  198. .resume = orinoco_pci_resume,
  199. };
  200. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  201. " (Pavel Roskin <proski@gnu.org>,"
  202. " David Gibson <hermes@gibson.dropbear.id.au> &"
  203. " Jean Tourrilhes <jt@hpl.hp.com>)";
  204. MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
  205. MODULE_DESCRIPTION("Driver for wireless LAN cards using direct PCI interface");
  206. MODULE_LICENSE("Dual MPL/GPL");
  207. static int __init orinoco_pci_init(void)
  208. {
  209. printk(KERN_DEBUG "%s\n", version);
  210. return pci_module_init(&orinoco_pci_driver);
  211. }
  212. static void __exit orinoco_pci_exit(void)
  213. {
  214. pci_unregister_driver(&orinoco_pci_driver);
  215. }
  216. module_init(orinoco_pci_init);
  217. module_exit(orinoco_pci_exit);
  218. /*
  219. * Local variables:
  220. * c-indent-level: 8
  221. * c-basic-offset: 8
  222. * tab-width: 8
  223. * End:
  224. */