orinoco_plx.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. /* orinoco_plx.c
  2. *
  3. * Driver for Prism II devices which would usually be driven by orinoco_cs,
  4. * but are connected to the PCI bus by a PLX9052.
  5. *
  6. * Current maintainers (as of 29 September 2003) are:
  7. * Pavel Roskin <proski AT gnu.org>
  8. * and David Gibson <hermes AT gibson.dropbear.id.au>
  9. *
  10. * (C) Copyright David Gibson, IBM Corp. 2001-2003.
  11. * Copyright (C) 2001 Daniel Barlow
  12. *
  13. * The contents of this file are subject to the Mozilla Public License
  14. * Version 1.1 (the "License"); you may not use this file except in
  15. * compliance with the License. You may obtain a copy of the License
  16. * at http://www.mozilla.org/MPL/
  17. *
  18. * Software distributed under the License is distributed on an "AS IS"
  19. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
  20. * the License for the specific language governing rights and
  21. * limitations under the License.
  22. *
  23. * Alternatively, the contents of this file may be used under the
  24. * terms of the GNU General Public License version 2 (the "GPL"), in
  25. * which case the provisions of the GPL are applicable instead of the
  26. * above. If you wish to allow the use of your version of this file
  27. * only under the terms of the GPL and not to allow others to use your
  28. * version of this file under the MPL, indicate your decision by
  29. * deleting the provisions above and replace them with the notice and
  30. * other provisions required by the GPL. If you do not delete the
  31. * provisions above, a recipient may use your version of this file
  32. * under either the MPL or the GPL.
  33. * Caution: this is experimental and probably buggy. For success and
  34. * failure reports for different cards and adaptors, see
  35. * orinoco_plx_pci_id_table near the end of the file. If you have a
  36. * card we don't have the PCI id for, and looks like it should work,
  37. * drop me mail with the id and "it works"/"it doesn't work".
  38. *
  39. * Note: if everything gets detected fine but it doesn't actually send
  40. * or receive packets, your first port of call should probably be to
  41. * try newer firmware in the card. Especially if you're doing Ad-Hoc
  42. * modes.
  43. *
  44. * The actual driving is done by orinoco.c, this is just resource
  45. * allocation stuff. The explanation below is courtesy of Ryan Niemi
  46. * on the linux-wlan-ng list at
  47. * http://archives.neohapsis.com/archives/dev/linux-wlan/2001-q1/0026.html
  48. *
  49. * The PLX9052-based cards (WL11000 and several others) are a
  50. * different beast than the usual PCMCIA-based PRISM2 configuration
  51. * expected by wlan-ng. Here's the general details on how the WL11000
  52. * PCI adapter works:
  53. *
  54. * - Two PCI I/O address spaces, one 0x80 long which contains the
  55. * PLX9052 registers, and one that's 0x40 long mapped to the PCMCIA
  56. * slot I/O address space.
  57. *
  58. * - One PCI memory address space, mapped to the PCMCIA memory space
  59. * (containing the CIS).
  60. *
  61. * After identifying the I/O and memory space, you can read through
  62. * the memory space to confirm the CIS's device ID or manufacturer ID
  63. * to make sure it's the expected card. qKeep in mind that the PCMCIA
  64. * spec specifies the CIS as the lower 8 bits of each word read from
  65. * the CIS, so to read the bytes of the CIS, read every other byte
  66. * (0,2,4,...). Passing that test, you need to enable the I/O address
  67. * space on the PCMCIA card via the PCMCIA COR register. This is the
  68. * first byte following the CIS. In my case (which may not have any
  69. * relation to what's on the PRISM2 cards), COR was at offset 0x800
  70. * within the PCI memory space. Write 0x41 to the COR register to
  71. * enable I/O mode and to select level triggered interrupts. To
  72. * confirm you actually succeeded, read the COR register back and make
  73. * sure it actually got set to 0x41, incase you have an unexpected
  74. * card inserted.
  75. *
  76. * Following that, you can treat the second PCI I/O address space (the
  77. * one that's not 0x80 in length) as the PCMCIA I/O space.
  78. *
  79. * Note that in the Eumitcom's source for their drivers, they register
  80. * the interrupt as edge triggered when registering it with the
  81. * Windows kernel. I don't recall how to register edge triggered on
  82. * Linux (if it can be done at all). But in some experimentation, I
  83. * don't see much operational difference between using either
  84. * interrupt mode. Don't mess with the interrupt mode in the COR
  85. * register though, as the PLX9052 wants level triggers with the way
  86. * the serial EEPROM configures it on the WL11000.
  87. *
  88. * There's some other little quirks related to timing that I bumped
  89. * into, but I don't recall right now. Also, there's two variants of
  90. * the WL11000 I've seen, revision A1 and T2. These seem to differ
  91. * slightly in the timings configured in the wait-state generator in
  92. * the PLX9052. There have also been some comments from Eumitcom that
  93. * cards shouldn't be hot swapped, apparently due to risk of cooking
  94. * the PLX9052. I'm unsure why they believe this, as I can't see
  95. * anything in the design that would really cause a problem, except
  96. * for crashing drivers not written to expect it. And having developed
  97. * drivers for the WL11000, I'd say it's quite tricky to write code
  98. * that will successfully deal with a hot unplug. Very odd things
  99. * happen on the I/O side of things. But anyway, be warned. Despite
  100. * that, I've hot-swapped a number of times during debugging and
  101. * driver development for various reasons (stuck WAIT# line after the
  102. * radio card's firmware locks up).
  103. *
  104. * Hope this is enough info for someone to add PLX9052 support to the
  105. * wlan-ng card. In the case of the WL11000, the PCI ID's are
  106. * 0x1639/0x0200, with matching subsystem ID's. Other PLX9052-based
  107. * manufacturers other than Eumitcom (or on cards other than the
  108. * WL11000) may have different PCI ID's.
  109. *
  110. * If anyone needs any more specific info, let me know. I haven't had
  111. * time to implement support myself yet, and with the way things are
  112. * going, might not have time for a while..
  113. */
  114. #define DRIVER_NAME "orinoco_plx"
  115. #define PFX DRIVER_NAME ": "
  116. #include <linux/config.h>
  117. #include <linux/module.h>
  118. #include <linux/kernel.h>
  119. #include <linux/init.h>
  120. #include <linux/delay.h>
  121. #include <linux/pci.h>
  122. #include <pcmcia/cisreg.h>
  123. #include "orinoco.h"
  124. #define COR_OFFSET (0x3e0) /* COR attribute offset of Prism2 PC card */
  125. #define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
  126. #define COR_RESET (0x80) /* reset bit in the COR register */
  127. #define PLX_RESET_TIME (500) /* milliseconds */
  128. #define PLX_INTCSR 0x4c /* Interrupt Control & Status Register */
  129. #define PLX_INTCSR_INTEN (1<<6) /* Interrupt Enable bit */
  130. static const u8 cis_magic[] = {
  131. 0x01, 0x03, 0x00, 0x00, 0xff, 0x17, 0x04, 0x67
  132. };
  133. /* Orinoco PLX specific data */
  134. struct orinoco_plx_card {
  135. void __iomem *attr_mem;
  136. };
  137. /*
  138. * Do a soft reset of the card using the Configuration Option Register
  139. */
  140. static int orinoco_plx_cor_reset(struct orinoco_private *priv)
  141. {
  142. hermes_t *hw = &priv->hw;
  143. struct orinoco_plx_card *card = priv->card;
  144. u8 __iomem *attr_mem = card->attr_mem;
  145. unsigned long timeout;
  146. u16 reg;
  147. writeb(COR_VALUE | COR_RESET, attr_mem + COR_OFFSET);
  148. mdelay(1);
  149. writeb(COR_VALUE, attr_mem + COR_OFFSET);
  150. mdelay(1);
  151. /* Just in case, wait more until the card is no longer busy */
  152. timeout = jiffies + (PLX_RESET_TIME * HZ / 1000);
  153. reg = hermes_read_regn(hw, CMD);
  154. while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
  155. mdelay(1);
  156. reg = hermes_read_regn(hw, CMD);
  157. }
  158. /* Did we timeout ? */
  159. if (reg & HERMES_CMD_BUSY) {
  160. printk(KERN_ERR PFX "Busy timeout\n");
  161. return -ETIMEDOUT;
  162. }
  163. return 0;
  164. }
  165. static int orinoco_plx_init_one(struct pci_dev *pdev,
  166. const struct pci_device_id *ent)
  167. {
  168. int err = 0;
  169. u8 __iomem *attr_mem = NULL;
  170. u32 csr_reg, plx_addr;
  171. struct orinoco_private *priv = NULL;
  172. struct orinoco_plx_card *card;
  173. unsigned long pccard_ioaddr = 0;
  174. unsigned long pccard_iolen = 0;
  175. struct net_device *dev = NULL;
  176. void __iomem *mem;
  177. int i;
  178. err = pci_enable_device(pdev);
  179. if (err) {
  180. printk(KERN_ERR PFX "Cannot enable PCI device\n");
  181. return err;
  182. }
  183. err = pci_request_regions(pdev, DRIVER_NAME);
  184. if (err != 0) {
  185. printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
  186. goto fail_resources;
  187. }
  188. /* Resource 1 is mapped to PLX-specific registers */
  189. plx_addr = pci_resource_start(pdev, 1);
  190. /* Resource 2 is mapped to the PCMCIA attribute memory */
  191. attr_mem = ioremap(pci_resource_start(pdev, 2),
  192. pci_resource_len(pdev, 2));
  193. if (!attr_mem) {
  194. printk(KERN_ERR PFX "Cannot remap PCMCIA space\n");
  195. goto fail_map_attr;
  196. }
  197. /* Resource 3 is mapped to the PCMCIA I/O address space */
  198. pccard_ioaddr = pci_resource_start(pdev, 3);
  199. pccard_iolen = pci_resource_len(pdev, 3);
  200. mem = pci_iomap(pdev, 3, 0);
  201. if (!mem) {
  202. err = -ENOMEM;
  203. goto fail_map_io;
  204. }
  205. /* Allocate network device */
  206. dev = alloc_orinocodev(sizeof(*card), orinoco_plx_cor_reset);
  207. if (!dev) {
  208. printk(KERN_ERR PFX "Cannot allocate network device\n");
  209. err = -ENOMEM;
  210. goto fail_alloc;
  211. }
  212. priv = netdev_priv(dev);
  213. card = priv->card;
  214. card->attr_mem = attr_mem;
  215. dev->base_addr = pccard_ioaddr;
  216. SET_MODULE_OWNER(dev);
  217. SET_NETDEV_DEV(dev, &pdev->dev);
  218. hermes_struct_init(&priv->hw, mem, HERMES_16BIT_REGSPACING);
  219. printk(KERN_DEBUG PFX "Detected Orinoco/Prism2 PLX device "
  220. "at %s irq:%d, io addr:0x%lx\n", pci_name(pdev), pdev->irq,
  221. pccard_ioaddr);
  222. err = request_irq(pdev->irq, orinoco_interrupt, SA_SHIRQ,
  223. dev->name, dev);
  224. if (err) {
  225. printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
  226. err = -EBUSY;
  227. goto fail_irq;
  228. }
  229. dev->irq = pdev->irq;
  230. /* bjoern: We need to tell the card to enable interrupts, in
  231. case the serial eprom didn't do this already. See the
  232. PLX9052 data book, p8-1 and 8-24 for reference. */
  233. csr_reg = inl(plx_addr + PLX_INTCSR);
  234. if (!(csr_reg & PLX_INTCSR_INTEN)) {
  235. csr_reg |= PLX_INTCSR_INTEN;
  236. outl(csr_reg, plx_addr + PLX_INTCSR);
  237. csr_reg = inl(plx_addr + PLX_INTCSR);
  238. if (!(csr_reg & PLX_INTCSR_INTEN)) {
  239. printk(KERN_ERR PFX "Cannot enable interrupts\n");
  240. goto fail;
  241. }
  242. }
  243. err = orinoco_plx_cor_reset(priv);
  244. if (err) {
  245. printk(KERN_ERR PFX "Initial reset failed\n");
  246. goto fail;
  247. }
  248. printk(KERN_DEBUG PFX "CIS: ");
  249. for (i = 0; i < 16; i++) {
  250. printk("%02X:", readb(attr_mem + 2*i));
  251. }
  252. printk("\n");
  253. /* Verify whether a supported PC card is present */
  254. /* FIXME: we probably need to be smarted about this */
  255. for (i = 0; i < sizeof(cis_magic); i++) {
  256. if (cis_magic[i] != readb(attr_mem +2*i)) {
  257. printk(KERN_ERR PFX "The CIS value of Prism2 PC "
  258. "card is unexpected\n");
  259. err = -EIO;
  260. goto fail;
  261. }
  262. }
  263. err = register_netdev(dev);
  264. if (err) {
  265. printk(KERN_ERR PFX "Cannot register network device\n");
  266. goto fail;
  267. }
  268. pci_set_drvdata(pdev, dev);
  269. return 0;
  270. fail:
  271. free_irq(pdev->irq, dev);
  272. fail_irq:
  273. pci_set_drvdata(pdev, NULL);
  274. free_orinocodev(dev);
  275. fail_alloc:
  276. pci_iounmap(pdev, mem);
  277. fail_map_io:
  278. iounmap(attr_mem);
  279. fail_map_attr:
  280. pci_release_regions(pdev);
  281. fail_resources:
  282. pci_disable_device(pdev);
  283. return err;
  284. }
  285. static void __devexit orinoco_plx_remove_one(struct pci_dev *pdev)
  286. {
  287. struct net_device *dev = pci_get_drvdata(pdev);
  288. struct orinoco_private *priv = netdev_priv(dev);
  289. struct orinoco_plx_card *card = priv->card;
  290. u8 __iomem *attr_mem = card->attr_mem;
  291. BUG_ON(! dev);
  292. unregister_netdev(dev);
  293. free_irq(dev->irq, dev);
  294. pci_set_drvdata(pdev, NULL);
  295. free_orinocodev(dev);
  296. pci_iounmap(pdev, priv->hw.iobase);
  297. iounmap(attr_mem);
  298. pci_release_regions(pdev);
  299. pci_disable_device(pdev);
  300. }
  301. static struct pci_device_id orinoco_plx_pci_id_table[] = {
  302. {0x111a, 0x1023, PCI_ANY_ID, PCI_ANY_ID,}, /* Siemens SpeedStream SS1023 */
  303. {0x1385, 0x4100, PCI_ANY_ID, PCI_ANY_ID,}, /* Netgear MA301 */
  304. {0x15e8, 0x0130, PCI_ANY_ID, PCI_ANY_ID,}, /* Correga - does this work? */
  305. {0x1638, 0x1100, PCI_ANY_ID, PCI_ANY_ID,}, /* SMC EZConnect SMC2602W,
  306. Eumitcom PCI WL11000,
  307. Addtron AWA-100 */
  308. {0x16ab, 0x1100, PCI_ANY_ID, PCI_ANY_ID,}, /* Global Sun Tech GL24110P */
  309. {0x16ab, 0x1101, PCI_ANY_ID, PCI_ANY_ID,}, /* Reported working, but unknown */
  310. {0x16ab, 0x1102, PCI_ANY_ID, PCI_ANY_ID,}, /* Linksys WDT11 */
  311. {0x16ec, 0x3685, PCI_ANY_ID, PCI_ANY_ID,}, /* USR 2415 */
  312. {0xec80, 0xec00, PCI_ANY_ID, PCI_ANY_ID,}, /* Belkin F5D6000 tested by
  313. Brendan W. McAdams <rit AT jacked-in.org> */
  314. {0x10b7, 0x7770, PCI_ANY_ID, PCI_ANY_ID,}, /* 3Com AirConnect PCI tested by
  315. Damien Persohn <damien AT persohn.net> */
  316. {0,},
  317. };
  318. MODULE_DEVICE_TABLE(pci, orinoco_plx_pci_id_table);
  319. static struct pci_driver orinoco_plx_driver = {
  320. .name = DRIVER_NAME,
  321. .id_table = orinoco_plx_pci_id_table,
  322. .probe = orinoco_plx_init_one,
  323. .remove = __devexit_p(orinoco_plx_remove_one),
  324. };
  325. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  326. " (Pavel Roskin <proski@gnu.org>,"
  327. " David Gibson <hermes@gibson.dropbear.id.au>,"
  328. " Daniel Barlow <dan@telent.net>)";
  329. MODULE_AUTHOR("Daniel Barlow <dan@telent.net>");
  330. MODULE_DESCRIPTION("Driver for wireless LAN cards using the PLX9052 PCI bridge");
  331. MODULE_LICENSE("Dual MPL/GPL");
  332. static int __init orinoco_plx_init(void)
  333. {
  334. printk(KERN_DEBUG "%s\n", version);
  335. return pci_module_init(&orinoco_plx_driver);
  336. }
  337. static void __exit orinoco_plx_exit(void)
  338. {
  339. pci_unregister_driver(&orinoco_plx_driver);
  340. ssleep(1);
  341. }
  342. module_init(orinoco_plx_init);
  343. module_exit(orinoco_plx_exit);
  344. /*
  345. * Local variables:
  346. * c-indent-level: 8
  347. * c-basic-offset: 8
  348. * tab-width: 8
  349. * End:
  350. */