orinoco_plx.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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 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. *
  34. * Here's the general details on how the PLX9052 adapter works:
  35. *
  36. * - Two PCI I/O address spaces, one 0x80 long which contains the
  37. * PLX9052 registers, and one that's 0x40 long mapped to the PCMCIA
  38. * slot I/O address space.
  39. *
  40. * - One PCI memory address space, mapped to the PCMCIA attribute space
  41. * (containing the CIS).
  42. *
  43. * Using the later, you can read through the CIS data to make sure the
  44. * card is compatible with the driver. Keep in mind that the PCMCIA
  45. * spec specifies the CIS as the lower 8 bits of each word read from
  46. * the CIS, so to read the bytes of the CIS, read every other byte
  47. * (0,2,4,...). Passing that test, you need to enable the I/O address
  48. * space on the PCMCIA card via the PCMCIA COR register. This is the
  49. * first byte following the CIS. In my case (which may not have any
  50. * relation to what's on the PRISM2 cards), COR was at offset 0x800
  51. * within the PCI memory space. Write 0x41 to the COR register to
  52. * enable I/O mode and to select level triggered interrupts. To
  53. * confirm you actually succeeded, read the COR register back and make
  54. * sure it actually got set to 0x41, in case you have an unexpected
  55. * card inserted.
  56. *
  57. * Following that, you can treat the second PCI I/O address space (the
  58. * one that's not 0x80 in length) as the PCMCIA I/O space.
  59. *
  60. * Note that in the Eumitcom's source for their drivers, they register
  61. * the interrupt as edge triggered when registering it with the
  62. * Windows kernel. I don't recall how to register edge triggered on
  63. * Linux (if it can be done at all). But in some experimentation, I
  64. * don't see much operational difference between using either
  65. * interrupt mode. Don't mess with the interrupt mode in the COR
  66. * register though, as the PLX9052 wants level triggers with the way
  67. * the serial EEPROM configures it on the WL11000.
  68. *
  69. * There's some other little quirks related to timing that I bumped
  70. * into, but I don't recall right now. Also, there's two variants of
  71. * the WL11000 I've seen, revision A1 and T2. These seem to differ
  72. * slightly in the timings configured in the wait-state generator in
  73. * the PLX9052. There have also been some comments from Eumitcom that
  74. * cards shouldn't be hot swapped, apparently due to risk of cooking
  75. * the PLX9052. I'm unsure why they believe this, as I can't see
  76. * anything in the design that would really cause a problem, except
  77. * for crashing drivers not written to expect it. And having developed
  78. * drivers for the WL11000, I'd say it's quite tricky to write code
  79. * that will successfully deal with a hot unplug. Very odd things
  80. * happen on the I/O side of things. But anyway, be warned. Despite
  81. * that, I've hot-swapped a number of times during debugging and
  82. * driver development for various reasons (stuck WAIT# line after the
  83. * radio card's firmware locks up).
  84. */
  85. #define DRIVER_NAME "orinoco_plx"
  86. #define PFX DRIVER_NAME ": "
  87. #include <linux/module.h>
  88. #include <linux/kernel.h>
  89. #include <linux/init.h>
  90. #include <linux/delay.h>
  91. #include <linux/pci.h>
  92. #include <pcmcia/cisreg.h>
  93. #include "orinoco.h"
  94. #include "orinoco_pci.h"
  95. #define COR_OFFSET (0x3e0) /* COR attribute offset of Prism2 PC card */
  96. #define COR_VALUE (COR_LEVEL_REQ | COR_FUNC_ENA) /* Enable PC card with interrupt in level trigger */
  97. #define COR_RESET (0x80) /* reset bit in the COR register */
  98. #define PLX_RESET_TIME (500) /* milliseconds */
  99. #define PLX_INTCSR 0x4c /* Interrupt Control & Status Register */
  100. #define PLX_INTCSR_INTEN (1 << 6) /* Interrupt Enable bit */
  101. /*
  102. * Do a soft reset of the card using the Configuration Option Register
  103. */
  104. static int orinoco_plx_cor_reset(struct orinoco_private *priv)
  105. {
  106. struct hermes *hw = &priv->hw;
  107. struct orinoco_pci_card *card = priv->card;
  108. unsigned long timeout;
  109. u16 reg;
  110. iowrite8(COR_VALUE | COR_RESET, card->attr_io + COR_OFFSET);
  111. mdelay(1);
  112. iowrite8(COR_VALUE, card->attr_io + COR_OFFSET);
  113. mdelay(1);
  114. /* Just in case, wait more until the card is no longer busy */
  115. timeout = jiffies + msecs_to_jiffies(PLX_RESET_TIME);
  116. reg = hermes_read_regn(hw, CMD);
  117. while (time_before(jiffies, timeout) && (reg & HERMES_CMD_BUSY)) {
  118. mdelay(1);
  119. reg = hermes_read_regn(hw, CMD);
  120. }
  121. /* Still busy? */
  122. if (reg & HERMES_CMD_BUSY) {
  123. printk(KERN_ERR PFX "Busy timeout\n");
  124. return -ETIMEDOUT;
  125. }
  126. return 0;
  127. }
  128. static int orinoco_plx_hw_init(struct orinoco_pci_card *card)
  129. {
  130. int i;
  131. u32 csr_reg;
  132. static const u8 cis_magic[] = {
  133. 0x01, 0x03, 0x00, 0x00, 0xff, 0x17, 0x04, 0x67
  134. };
  135. printk(KERN_DEBUG PFX "CIS: ");
  136. for (i = 0; i < 16; i++)
  137. printk("%02X:", ioread8(card->attr_io + (i << 1)));
  138. printk("\n");
  139. /* Verify whether a supported PC card is present */
  140. /* FIXME: we probably need to be smarted about this */
  141. for (i = 0; i < sizeof(cis_magic); i++) {
  142. if (cis_magic[i] != ioread8(card->attr_io + (i << 1))) {
  143. printk(KERN_ERR PFX "The CIS value of Prism2 PC "
  144. "card is unexpected\n");
  145. return -ENODEV;
  146. }
  147. }
  148. /* bjoern: We need to tell the card to enable interrupts, in
  149. case the serial eprom didn't do this already. See the
  150. PLX9052 data book, p8-1 and 8-24 for reference. */
  151. csr_reg = ioread32(card->bridge_io + PLX_INTCSR);
  152. if (!(csr_reg & PLX_INTCSR_INTEN)) {
  153. csr_reg |= PLX_INTCSR_INTEN;
  154. iowrite32(csr_reg, card->bridge_io + PLX_INTCSR);
  155. csr_reg = ioread32(card->bridge_io + PLX_INTCSR);
  156. if (!(csr_reg & PLX_INTCSR_INTEN)) {
  157. printk(KERN_ERR PFX "Cannot enable interrupts\n");
  158. return -EIO;
  159. }
  160. }
  161. return 0;
  162. }
  163. static int orinoco_plx_init_one(struct pci_dev *pdev,
  164. const struct pci_device_id *ent)
  165. {
  166. int err;
  167. struct orinoco_private *priv;
  168. struct orinoco_pci_card *card;
  169. void __iomem *hermes_io, *attr_io, *bridge_io;
  170. err = pci_enable_device(pdev);
  171. if (err) {
  172. printk(KERN_ERR PFX "Cannot enable PCI device\n");
  173. return err;
  174. }
  175. err = pci_request_regions(pdev, DRIVER_NAME);
  176. if (err) {
  177. printk(KERN_ERR PFX "Cannot obtain PCI resources\n");
  178. goto fail_resources;
  179. }
  180. bridge_io = pci_iomap(pdev, 1, 0);
  181. if (!bridge_io) {
  182. printk(KERN_ERR PFX "Cannot map bridge registers\n");
  183. err = -EIO;
  184. goto fail_map_bridge;
  185. }
  186. attr_io = pci_iomap(pdev, 2, 0);
  187. if (!attr_io) {
  188. printk(KERN_ERR PFX "Cannot map PCMCIA attributes\n");
  189. err = -EIO;
  190. goto fail_map_attr;
  191. }
  192. hermes_io = pci_iomap(pdev, 3, 0);
  193. if (!hermes_io) {
  194. printk(KERN_ERR PFX "Cannot map chipset registers\n");
  195. err = -EIO;
  196. goto fail_map_hermes;
  197. }
  198. /* Allocate network device */
  199. priv = alloc_orinocodev(sizeof(*card), &pdev->dev,
  200. orinoco_plx_cor_reset, NULL);
  201. if (!priv) {
  202. printk(KERN_ERR PFX "Cannot allocate network device\n");
  203. err = -ENOMEM;
  204. goto fail_alloc;
  205. }
  206. card = priv->card;
  207. card->bridge_io = bridge_io;
  208. card->attr_io = attr_io;
  209. hermes_struct_init(&priv->hw, hermes_io, HERMES_16BIT_REGSPACING);
  210. err = request_irq(pdev->irq, orinoco_interrupt, IRQF_SHARED,
  211. DRIVER_NAME, priv);
  212. if (err) {
  213. printk(KERN_ERR PFX "Cannot allocate IRQ %d\n", pdev->irq);
  214. err = -EBUSY;
  215. goto fail_irq;
  216. }
  217. err = orinoco_plx_hw_init(card);
  218. if (err) {
  219. printk(KERN_ERR PFX "Hardware initialization failed\n");
  220. goto fail;
  221. }
  222. err = orinoco_plx_cor_reset(priv);
  223. if (err) {
  224. printk(KERN_ERR PFX "Initial reset failed\n");
  225. goto fail;
  226. }
  227. err = orinoco_init(priv);
  228. if (err) {
  229. printk(KERN_ERR PFX "orinoco_init() failed\n");
  230. goto fail;
  231. }
  232. err = orinoco_if_add(priv, 0, 0, NULL);
  233. if (err) {
  234. printk(KERN_ERR PFX "orinoco_if_add() failed\n");
  235. goto fail_wiphy;
  236. }
  237. pci_set_drvdata(pdev, priv);
  238. return 0;
  239. fail_wiphy:
  240. wiphy_unregister(priv_to_wiphy(priv));
  241. fail:
  242. free_irq(pdev->irq, priv);
  243. fail_irq:
  244. free_orinocodev(priv);
  245. fail_alloc:
  246. pci_iounmap(pdev, hermes_io);
  247. fail_map_hermes:
  248. pci_iounmap(pdev, attr_io);
  249. fail_map_attr:
  250. pci_iounmap(pdev, bridge_io);
  251. fail_map_bridge:
  252. pci_release_regions(pdev);
  253. fail_resources:
  254. pci_disable_device(pdev);
  255. return err;
  256. }
  257. static void orinoco_plx_remove_one(struct pci_dev *pdev)
  258. {
  259. struct orinoco_private *priv = pci_get_drvdata(pdev);
  260. struct orinoco_pci_card *card = priv->card;
  261. orinoco_if_del(priv);
  262. wiphy_unregister(priv_to_wiphy(priv));
  263. free_irq(pdev->irq, priv);
  264. free_orinocodev(priv);
  265. pci_iounmap(pdev, priv->hw.iobase);
  266. pci_iounmap(pdev, card->attr_io);
  267. pci_iounmap(pdev, card->bridge_io);
  268. pci_release_regions(pdev);
  269. pci_disable_device(pdev);
  270. }
  271. static const struct pci_device_id orinoco_plx_id_table[] = {
  272. {0x111a, 0x1023, PCI_ANY_ID, PCI_ANY_ID,}, /* Siemens SpeedStream SS1023 */
  273. {0x1385, 0x4100, PCI_ANY_ID, PCI_ANY_ID,}, /* Netgear MA301 */
  274. {0x15e8, 0x0130, PCI_ANY_ID, PCI_ANY_ID,}, /* Correga - does this work? */
  275. {0x1638, 0x1100, PCI_ANY_ID, PCI_ANY_ID,}, /* SMC EZConnect SMC2602W,
  276. Eumitcom PCI WL11000,
  277. Addtron AWA-100 */
  278. {0x16ab, 0x1100, PCI_ANY_ID, PCI_ANY_ID,}, /* Global Sun Tech GL24110P */
  279. {0x16ab, 0x1101, PCI_ANY_ID, PCI_ANY_ID,}, /* Reported working, but unknown */
  280. {0x16ab, 0x1102, PCI_ANY_ID, PCI_ANY_ID,}, /* Linksys WDT11 */
  281. {0x16ec, 0x3685, PCI_ANY_ID, PCI_ANY_ID,}, /* USR 2415 */
  282. {0xec80, 0xec00, PCI_ANY_ID, PCI_ANY_ID,}, /* Belkin F5D6000 tested by
  283. Brendan W. McAdams <rit AT jacked-in.org> */
  284. {0x10b7, 0x7770, PCI_ANY_ID, PCI_ANY_ID,}, /* 3Com AirConnect PCI tested by
  285. Damien Persohn <damien AT persohn.net> */
  286. {0,},
  287. };
  288. MODULE_DEVICE_TABLE(pci, orinoco_plx_id_table);
  289. static struct pci_driver orinoco_plx_driver = {
  290. .name = DRIVER_NAME,
  291. .id_table = orinoco_plx_id_table,
  292. .probe = orinoco_plx_init_one,
  293. .remove = orinoco_plx_remove_one,
  294. .suspend = orinoco_pci_suspend,
  295. .resume = orinoco_pci_resume,
  296. };
  297. static char version[] __initdata = DRIVER_NAME " " DRIVER_VERSION
  298. " (Pavel Roskin <proski@gnu.org>,"
  299. " David Gibson <hermes@gibson.dropbear.id.au>,"
  300. " Daniel Barlow <dan@telent.net>)";
  301. MODULE_AUTHOR("Daniel Barlow <dan@telent.net>");
  302. MODULE_DESCRIPTION("Driver for wireless LAN cards using the PLX9052 PCI bridge");
  303. MODULE_LICENSE("Dual MPL/GPL");
  304. static int __init orinoco_plx_init(void)
  305. {
  306. printk(KERN_DEBUG "%s\n", version);
  307. return pci_register_driver(&orinoco_plx_driver);
  308. }
  309. static void __exit orinoco_plx_exit(void)
  310. {
  311. pci_unregister_driver(&orinoco_plx_driver);
  312. }
  313. module_init(orinoco_plx_init);
  314. module_exit(orinoco_plx_exit);
  315. /*
  316. * Local variables:
  317. * c-indent-level: 8
  318. * c-basic-offset: 8
  319. * tab-width: 8
  320. * End:
  321. */