orinoco_pci.c 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /* orinoco_pci.c
  2. *
  3. * Driver for Prism II devices that have a direct PCI interface
  4. * (i.e., not in a Pcmcia or PLX bridge)
  5. *
  6. * Specifically here we're talking about the Linksys WMP11
  7. *
  8. * Current maintainers (as of 29 September 2003) 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. /*
  44. * Theory of operation...
  45. * -------------------
  46. * Maybe you had a look in orinoco_plx. Well, this is totally different...
  47. *
  48. * The card contains only one PCI region, which contains all the usual
  49. * hermes registers.
  50. *
  51. * The driver will memory map this region in normal memory. Because
  52. * the hermes registers are mapped in normal memory and not in ISA I/O
  53. * post space, we can't use the usual inw/outw macros and we need to
  54. * use readw/writew.
  55. * This slight difference force us to compile our own version of
  56. * hermes.c with the register access macro changed. That's a bit
  57. * hackish but works fine.
  58. *
  59. * Note that the PCI region is pretty big (4K). That's much more than
  60. * the usual set of hermes register (0x0 -> 0x3E). I've got a strong
  61. * suspicion that the whole memory space of the adapter is in fact in
  62. * this region. Accessing directly the adapter memory instead of going
  63. * through the usual register would speed up significantely the
  64. * operations...
  65. *
  66. * Finally, the card looks like this :
  67. -----------------------
  68. Bus 0, device 14, function 0:
  69. Network controller: PCI device 1260:3873 (Harris Semiconductor) (rev 1).
  70. IRQ 11.
  71. Master Capable. Latency=248.
  72. Prefetchable 32 bit memory at 0xffbcc000 [0xffbccfff].
  73. -----------------------
  74. 00:0e.0 Network controller: Harris Semiconductor: Unknown device 3873 (rev 01)
  75. Subsystem: Unknown device 1737:3874
  76. Control: I/O+ Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- ParErr- Stepping- SERR- FastB2B-
  77. Status: Cap+ 66Mhz- UDF- FastB2B+ ParErr- DEVSEL=medium >TAbort- <TAbort- <MAbort- >SERR- <PERR-
  78. Latency: 248 set, cache line size 08
  79. Interrupt: pin A routed to IRQ 11
  80. Region 0: Memory at ffbcc000 (32-bit, prefetchable) [size=4K]
  81. Capabilities: [dc] Power Management version 2
  82. Flags: PMEClk- AuxPwr- DSI- D1+ D2+ PME+
  83. Status: D0 PME-Enable- DSel=0 DScale=0 PME-
  84. -----------------------
  85. *
  86. * That's all..
  87. *
  88. * Jean II
  89. */
  90. #define DRIVER_NAME "orinoco_pci"
  91. #define PFX DRIVER_NAME ": "
  92. #include <linux/config.h>
  93. #include <linux/module.h>
  94. #include <linux/kernel.h>
  95. #include <linux/init.h>
  96. #include <linux/delay.h>
  97. #include <linux/pci.h>
  98. #include "orinoco.h"
  99. #include "orinoco_pci.h"
  100. /* All the magic there is from wlan-ng */
  101. /* Magic offset of the reset register of the PCI card */
  102. #define HERMES_PCI_COR (0x26)
  103. /* Magic bitmask to reset the card */
  104. #define HERMES_PCI_COR_MASK (0x0080)
  105. /* Magic timeouts for doing the reset.
  106. * Those times are straight from wlan-ng, and it is claimed that they
  107. * are necessary. Alan will kill me. Take your time and grab a coffee. */
  108. #define HERMES_PCI_COR_ONT (250) /* ms */
  109. #define HERMES_PCI_COR_OFFT (500) /* ms */
  110. #define HERMES_PCI_COR_BUSYT (500) /* ms */
  111. /*
  112. * Do a soft reset of the PCI card using the Configuration Option Register
  113. * We need this to get going...
  114. * This is the part of the code that is strongly inspired from wlan-ng
  115. *
  116. * Note : This code is done with irq enabled. This mean that many
  117. * interrupts will occur while we are there. This is why we use the
  118. * jiffies to regulate time instead of a straight mdelay(). Usually we
  119. * need only around 245 iteration of the loop to do 250 ms delay.
  120. *
  121. * Note bis : Don't try to access HERMES_CMD during the reset phase.
  122. * It just won't work !
  123. */
  124. static int orinoco_pci_cor_reset(struct orinoco_private *priv)
  125. {
  126. hermes_t *hw = &priv->hw;
  127. unsigned long timeout;
  128. u16 reg;
  129. /* Assert the reset until the card notice */
  130. hermes_write_regn(hw, PCI_COR, HERMES_PCI_COR_MASK);
  131. mdelay(HERMES_PCI_COR_ONT);
  132. /* Give time for the card to recover from this hard effort */
  133. hermes_write_regn(hw, PCI_COR, 0x0000);
  134. mdelay(HERMES_PCI_COR_OFFT);
  135. /* The card is ready when it's no longer busy */
  136. timeout = jiffies + (HERMES_PCI_COR_BUSYT * HZ / 1000);
  137. reg = hermes_read_regn(hw, CMD);
  138. while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
  139. mdelay(1);
  140. reg = hermes_read_regn(hw, CMD);
  141. }
  142. /* Still busy? */
  143. if (reg & HERMES_CMD_BUSY) {
  144. printk(KERN_ERR PFX "Busy timeout\n");
  145. return -ETIMEDOUT;
  146. }
  147. return 0;
  148. }
  149. static int orinoco_pci_init_one(struct pci_dev *pdev,
  150. const struct pci_device_id *ent)
  151. {
  152. int err;
  153. struct orinoco_private *priv;
  154. struct orinoco_pci_card *card;
  155. struct net_device *dev;
  156. void __iomem *hermes_io;
  157. err = pci_enable_device(pdev);
  158. if (err) {
  159. printk(KERN_ERR PFX "Cannot enable PCI device\n");
  160. return err;
  161. }
  162. err = pci_request_regions(pdev, DRIVER_NAME);
  163. if (err) {
  164. printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
  165. goto fail_resources;
  166. }
  167. hermes_io = pci_iomap(pdev, 0, 0);
  168. if (!hermes_io) {
  169. printk(KERN_ERR PFX "Cannot remap chipset registers\n");
  170. err = -EIO;
  171. goto fail_map_hermes;
  172. }
  173. /* Allocate network device */
  174. dev = alloc_orinocodev(sizeof(*card), orinoco_pci_cor_reset);
  175. if (!dev) {
  176. printk(KERN_ERR PFX "Cannot allocate network device\n");
  177. err = -ENOMEM;
  178. goto fail_alloc;
  179. }
  180. priv = netdev_priv(dev);
  181. card = priv->card;
  182. SET_MODULE_OWNER(dev);
  183. SET_NETDEV_DEV(dev, &pdev->dev);
  184. hermes_struct_init(&priv->hw, hermes_io, HERMES_32BIT_REGSPACING);
  185. err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
  186. dev->name, dev);
  187. if (err) {
  188. printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
  189. err = -EBUSY;
  190. goto fail_irq;
  191. }
  192. orinoco_pci_setup_netdev(dev, pdev, 0);
  193. err = orinoco_pci_cor_reset(priv);
  194. if (err) {
  195. printk(KERN_ERR PFX "Initial reset failed\n");
  196. goto fail;
  197. }
  198. err = register_netdev(dev);
  199. if (err) {
  200. printk(KERN_ERR PFX "Cannot register network device\n");
  201. goto fail;
  202. }
  203. pci_set_drvdata(pdev, dev);
  204. return 0;
  205. fail:
  206. free_irq(pdev->irq, dev);
  207. fail_irq:
  208. pci_set_drvdata(pdev, NULL);
  209. free_orinocodev(dev);
  210. fail_alloc:
  211. pci_iounmap(pdev, hermes_io);
  212. fail_map_hermes:
  213. pci_release_regions(pdev);
  214. fail_resources:
  215. pci_disable_device(pdev);
  216. return err;
  217. }
  218. static void __devexit orinoco_pci_remove_one(struct pci_dev *pdev)
  219. {
  220. struct net_device *dev = pci_get_drvdata(pdev);
  221. struct orinoco_private *priv = netdev_priv(dev);
  222. unregister_netdev(dev);
  223. free_irq(dev->irq, dev);
  224. pci_set_drvdata(pdev, NULL);
  225. free_orinocodev(dev);
  226. pci_iounmap(pdev, priv->hw.iobase);
  227. pci_release_regions(pdev);
  228. pci_disable_device(pdev);
  229. }
  230. static struct pci_device_id orinoco_pci_id_table[] = {
  231. /* Intersil Prism 3 */
  232. {0x1260, 0x3872, PCI_ANY_ID, PCI_ANY_ID,},
  233. /* Intersil Prism 2.5 */
  234. {0x1260, 0x3873, PCI_ANY_ID, PCI_ANY_ID,},
  235. /* Samsung MagicLAN SWL-2210P */
  236. {0x167d, 0xa000, PCI_ANY_ID, PCI_ANY_ID,},
  237. {0,},
  238. };
  239. MODULE_DEVICE_TABLE(pci, orinoco_pci_id_table);
  240. static struct pci_driver orinoco_pci_driver = {
  241. .name = DRIVER_NAME,
  242. .id_table = orinoco_pci_id_table,
  243. .probe = orinoco_pci_init_one,
  244. .remove = __devexit_p(orinoco_pci_remove_one),
  245. .suspend = orinoco_pci_suspend,
  246. .resume = orinoco_pci_resume,
  247. };
  248. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  249. " (Pavel Roskin <proski@gnu.org>,"
  250. " David Gibson <hermes@gibson.dropbear.id.au> &"
  251. " Jean Tourrilhes <jt@hpl.hp.com>)";
  252. MODULE_AUTHOR("Pavel Roskin <proski@gnu.org> & David Gibson <hermes@gibson.dropbear.id.au>");
  253. MODULE_DESCRIPTION("Driver for wireless LAN cards using direct PCI interface");
  254. MODULE_LICENSE("Dual MPL/GPL");
  255. static int __init orinoco_pci_init(void)
  256. {
  257. printk(KERN_DEBUG "%s\n", version);
  258. return pci_module_init(&orinoco_pci_driver);
  259. }
  260. static void __exit orinoco_pci_exit(void)
  261. {
  262. pci_unregister_driver(&orinoco_pci_driver);
  263. }
  264. module_init(orinoco_pci_init);
  265. module_exit(orinoco_pci_exit);
  266. /*
  267. * Local variables:
  268. * c-indent-level: 8
  269. * c-basic-offset: 8
  270. * tab-width: 8
  271. * End:
  272. */