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