Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 1 | #define PRISM2_PCCARD |
| 2 | |
| 3 | #include <linux/config.h> |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 4 | #include <linux/module.h> |
| 5 | #include <linux/init.h> |
| 6 | #include <linux/if.h> |
| 7 | #include <linux/wait.h> |
| 8 | #include <linux/timer.h> |
| 9 | #include <linux/skbuff.h> |
| 10 | #include <linux/netdevice.h> |
| 11 | #include <linux/workqueue.h> |
| 12 | #include <linux/wireless.h> |
| 13 | #include <net/iw_handler.h> |
| 14 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 15 | #include <pcmcia/cs_types.h> |
| 16 | #include <pcmcia/cs.h> |
| 17 | #include <pcmcia/cistpl.h> |
| 18 | #include <pcmcia/cisreg.h> |
| 19 | #include <pcmcia/ds.h> |
| 20 | |
| 21 | #include <asm/io.h> |
| 22 | |
| 23 | #include "hostap_wlan.h" |
| 24 | |
| 25 | |
| 26 | static char *version = PRISM2_VERSION " (Jouni Malinen <jkmaline@cc.hut.fi>)"; |
| 27 | static dev_info_t dev_info = "hostap_cs"; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 28 | |
| 29 | MODULE_AUTHOR("Jouni Malinen"); |
| 30 | MODULE_DESCRIPTION("Support for Intersil Prism2-based 802.11 wireless LAN " |
| 31 | "cards (PC Card)."); |
| 32 | MODULE_SUPPORTED_DEVICE("Intersil Prism2-based WLAN cards (PC Card)"); |
| 33 | MODULE_LICENSE("GPL"); |
Jouni Malinen | f06ac31 | 2005-07-30 12:50:00 -0700 | [diff] [blame] | 34 | MODULE_VERSION(PRISM2_VERSION); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 35 | |
| 36 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 37 | static int ignore_cis_vcc; |
| 38 | module_param(ignore_cis_vcc, int, 0444); |
| 39 | MODULE_PARM_DESC(ignore_cis_vcc, "Ignore broken CIS VCC entry"); |
| 40 | |
| 41 | |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 42 | /* struct local_info::hw_priv */ |
| 43 | struct hostap_cs_priv { |
| 44 | dev_node_t node; |
| 45 | dev_link_t *link; |
| 46 | int sandisk_connectplus; |
| 47 | }; |
| 48 | |
| 49 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 50 | #ifdef PRISM2_IO_DEBUG |
| 51 | |
| 52 | static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v) |
| 53 | { |
| 54 | struct hostap_interface *iface; |
| 55 | local_info_t *local; |
| 56 | unsigned long flags; |
| 57 | |
| 58 | iface = netdev_priv(dev); |
| 59 | local = iface->local; |
| 60 | spin_lock_irqsave(&local->lock, flags); |
| 61 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v); |
| 62 | outb(v, dev->base_addr + a); |
| 63 | spin_unlock_irqrestore(&local->lock, flags); |
| 64 | } |
| 65 | |
| 66 | static inline u8 hfa384x_inb_debug(struct net_device *dev, int a) |
| 67 | { |
| 68 | struct hostap_interface *iface; |
| 69 | local_info_t *local; |
| 70 | unsigned long flags; |
| 71 | u8 v; |
| 72 | |
| 73 | iface = netdev_priv(dev); |
| 74 | local = iface->local; |
| 75 | spin_lock_irqsave(&local->lock, flags); |
| 76 | v = inb(dev->base_addr + a); |
| 77 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INB, a, v); |
| 78 | spin_unlock_irqrestore(&local->lock, flags); |
| 79 | return v; |
| 80 | } |
| 81 | |
| 82 | static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v) |
| 83 | { |
| 84 | struct hostap_interface *iface; |
| 85 | local_info_t *local; |
| 86 | unsigned long flags; |
| 87 | |
| 88 | iface = netdev_priv(dev); |
| 89 | local = iface->local; |
| 90 | spin_lock_irqsave(&local->lock, flags); |
| 91 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v); |
| 92 | outw(v, dev->base_addr + a); |
| 93 | spin_unlock_irqrestore(&local->lock, flags); |
| 94 | } |
| 95 | |
| 96 | static inline u16 hfa384x_inw_debug(struct net_device *dev, int a) |
| 97 | { |
| 98 | struct hostap_interface *iface; |
| 99 | local_info_t *local; |
| 100 | unsigned long flags; |
| 101 | u16 v; |
| 102 | |
| 103 | iface = netdev_priv(dev); |
| 104 | local = iface->local; |
| 105 | spin_lock_irqsave(&local->lock, flags); |
| 106 | v = inw(dev->base_addr + a); |
| 107 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INW, a, v); |
| 108 | spin_unlock_irqrestore(&local->lock, flags); |
| 109 | return v; |
| 110 | } |
| 111 | |
| 112 | static inline void hfa384x_outsw_debug(struct net_device *dev, int a, |
| 113 | u8 *buf, int wc) |
| 114 | { |
| 115 | struct hostap_interface *iface; |
| 116 | local_info_t *local; |
| 117 | unsigned long flags; |
| 118 | |
| 119 | iface = netdev_priv(dev); |
| 120 | local = iface->local; |
| 121 | spin_lock_irqsave(&local->lock, flags); |
| 122 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTSW, a, wc); |
| 123 | outsw(dev->base_addr + a, buf, wc); |
| 124 | spin_unlock_irqrestore(&local->lock, flags); |
| 125 | } |
| 126 | |
| 127 | static inline void hfa384x_insw_debug(struct net_device *dev, int a, |
| 128 | u8 *buf, int wc) |
| 129 | { |
| 130 | struct hostap_interface *iface; |
| 131 | local_info_t *local; |
| 132 | unsigned long flags; |
| 133 | |
| 134 | iface = netdev_priv(dev); |
| 135 | local = iface->local; |
| 136 | spin_lock_irqsave(&local->lock, flags); |
| 137 | prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INSW, a, wc); |
| 138 | insw(dev->base_addr + a, buf, wc); |
| 139 | spin_unlock_irqrestore(&local->lock, flags); |
| 140 | } |
| 141 | |
| 142 | #define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v)) |
| 143 | #define HFA384X_INB(a) hfa384x_inb_debug(dev, (a)) |
| 144 | #define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v)) |
| 145 | #define HFA384X_INW(a) hfa384x_inw_debug(dev, (a)) |
| 146 | #define HFA384X_OUTSW(a, buf, wc) hfa384x_outsw_debug(dev, (a), (buf), (wc)) |
| 147 | #define HFA384X_INSW(a, buf, wc) hfa384x_insw_debug(dev, (a), (buf), (wc)) |
| 148 | |
| 149 | #else /* PRISM2_IO_DEBUG */ |
| 150 | |
| 151 | #define HFA384X_OUTB(v,a) outb((v), dev->base_addr + (a)) |
| 152 | #define HFA384X_INB(a) inb(dev->base_addr + (a)) |
| 153 | #define HFA384X_OUTW(v,a) outw((v), dev->base_addr + (a)) |
| 154 | #define HFA384X_INW(a) inw(dev->base_addr + (a)) |
| 155 | #define HFA384X_INSW(a, buf, wc) insw(dev->base_addr + (a), buf, wc) |
| 156 | #define HFA384X_OUTSW(a, buf, wc) outsw(dev->base_addr + (a), buf, wc) |
| 157 | |
| 158 | #endif /* PRISM2_IO_DEBUG */ |
| 159 | |
| 160 | |
| 161 | static int hfa384x_from_bap(struct net_device *dev, u16 bap, void *buf, |
| 162 | int len) |
| 163 | { |
| 164 | u16 d_off; |
| 165 | u16 *pos; |
| 166 | |
| 167 | d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF; |
| 168 | pos = (u16 *) buf; |
| 169 | |
| 170 | if (len / 2) |
| 171 | HFA384X_INSW(d_off, buf, len / 2); |
| 172 | pos += len / 2; |
| 173 | |
| 174 | if (len & 1) |
| 175 | *((char *) pos) = HFA384X_INB(d_off); |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | |
| 181 | static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len) |
| 182 | { |
| 183 | u16 d_off; |
| 184 | u16 *pos; |
| 185 | |
| 186 | d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF; |
| 187 | pos = (u16 *) buf; |
| 188 | |
| 189 | if (len / 2) |
| 190 | HFA384X_OUTSW(d_off, buf, len / 2); |
| 191 | pos += len / 2; |
| 192 | |
| 193 | if (len & 1) |
| 194 | HFA384X_OUTB(*((char *) pos), d_off); |
| 195 | |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | |
| 200 | /* FIX: This might change at some point.. */ |
| 201 | #include "hostap_hw.c" |
| 202 | |
| 203 | |
| 204 | |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 205 | static void prism2_detach(struct pcmcia_device *p_dev); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 206 | static void prism2_release(u_long arg); |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 207 | static int prism2_config(dev_link_t *link); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 208 | |
| 209 | |
| 210 | static int prism2_pccard_card_present(local_info_t *local) |
| 211 | { |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 212 | struct hostap_cs_priv *hw_priv = local->hw_priv; |
Kalle Valo | a8eef8a | 2005-08-28 22:46:57 +0300 | [diff] [blame] | 213 | if (hw_priv != NULL && hw_priv->link != NULL && |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 214 | ((hw_priv->link->state & (DEV_PRESENT | DEV_CONFIG)) == |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 215 | (DEV_PRESENT | DEV_CONFIG))) |
| 216 | return 1; |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | |
| 221 | /* |
| 222 | * SanDisk CompactFlash WLAN Flashcard - Product Manual v1.0 |
| 223 | * Document No. 20-10-00058, January 2004 |
| 224 | * http://www.sandisk.com/pdf/industrial/ProdManualCFWLANv1.0.pdf |
| 225 | */ |
| 226 | #define SANDISK_WLAN_ACTIVATION_OFF 0x40 |
| 227 | #define SANDISK_HCR_OFF 0x42 |
| 228 | |
| 229 | |
| 230 | static void sandisk_set_iobase(local_info_t *local) |
| 231 | { |
| 232 | int res; |
| 233 | conf_reg_t reg; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 234 | struct hostap_cs_priv *hw_priv = local->hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 235 | |
| 236 | reg.Function = 0; |
| 237 | reg.Action = CS_WRITE; |
| 238 | reg.Offset = 0x10; /* 0x3f0 IO base 1 */ |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 239 | reg.Value = hw_priv->link->io.BasePort1 & 0x00ff; |
| 240 | res = pcmcia_access_configuration_register(hw_priv->link->handle, |
| 241 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 242 | if (res != CS_SUCCESS) { |
| 243 | printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 0 -" |
| 244 | " res=%d\n", res); |
| 245 | } |
| 246 | udelay(10); |
| 247 | |
| 248 | reg.Function = 0; |
| 249 | reg.Action = CS_WRITE; |
| 250 | reg.Offset = 0x12; /* 0x3f2 IO base 2 */ |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 251 | reg.Value = (hw_priv->link->io.BasePort1 & 0xff00) >> 8; |
| 252 | res = pcmcia_access_configuration_register(hw_priv->link->handle, |
| 253 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 254 | if (res != CS_SUCCESS) { |
| 255 | printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 1 -" |
| 256 | " res=%d\n", res); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | |
| 261 | static void sandisk_write_hcr(local_info_t *local, int hcr) |
| 262 | { |
| 263 | struct net_device *dev = local->dev; |
| 264 | int i; |
| 265 | |
| 266 | HFA384X_OUTB(0x80, SANDISK_WLAN_ACTIVATION_OFF); |
| 267 | udelay(50); |
| 268 | for (i = 0; i < 10; i++) { |
| 269 | HFA384X_OUTB(hcr, SANDISK_HCR_OFF); |
| 270 | } |
| 271 | udelay(55); |
| 272 | HFA384X_OUTB(0x45, SANDISK_WLAN_ACTIVATION_OFF); |
| 273 | } |
| 274 | |
| 275 | |
| 276 | static int sandisk_enable_wireless(struct net_device *dev) |
| 277 | { |
| 278 | int res, ret = 0; |
| 279 | conf_reg_t reg; |
| 280 | struct hostap_interface *iface = dev->priv; |
| 281 | local_info_t *local = iface->local; |
| 282 | tuple_t tuple; |
| 283 | cisparse_t *parse = NULL; |
| 284 | u_char buf[64]; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 285 | struct hostap_cs_priv *hw_priv = local->hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 286 | |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 287 | if (hw_priv->link->io.NumPorts1 < 0x42) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 288 | /* Not enough ports to be SanDisk multi-function card */ |
| 289 | ret = -ENODEV; |
| 290 | goto done; |
| 291 | } |
| 292 | |
| 293 | parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL); |
| 294 | if (parse == NULL) { |
| 295 | ret = -ENOMEM; |
| 296 | goto done; |
| 297 | } |
| 298 | |
| 299 | tuple.DesiredTuple = CISTPL_MANFID; |
| 300 | tuple.Attributes = TUPLE_RETURN_COMMON; |
| 301 | tuple.TupleData = buf; |
| 302 | tuple.TupleDataMax = sizeof(buf); |
| 303 | tuple.TupleOffset = 0; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 304 | if (pcmcia_get_first_tuple(hw_priv->link->handle, &tuple) || |
| 305 | pcmcia_get_tuple_data(hw_priv->link->handle, &tuple) || |
| 306 | pcmcia_parse_tuple(hw_priv->link->handle, &tuple, parse) || |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 307 | parse->manfid.manf != 0xd601 || parse->manfid.card != 0x0101) { |
| 308 | /* No SanDisk manfid found */ |
| 309 | ret = -ENODEV; |
| 310 | goto done; |
| 311 | } |
| 312 | |
| 313 | tuple.DesiredTuple = CISTPL_LONGLINK_MFC; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 314 | if (pcmcia_get_first_tuple(hw_priv->link->handle, &tuple) || |
| 315 | pcmcia_get_tuple_data(hw_priv->link->handle, &tuple) || |
| 316 | pcmcia_parse_tuple(hw_priv->link->handle, &tuple, parse) || |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 317 | parse->longlink_mfc.nfn < 2) { |
| 318 | /* No multi-function links found */ |
| 319 | ret = -ENODEV; |
| 320 | goto done; |
| 321 | } |
| 322 | |
| 323 | printk(KERN_DEBUG "%s: Multi-function SanDisk ConnectPlus detected" |
| 324 | " - using vendor-specific initialization\n", dev->name); |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 325 | hw_priv->sandisk_connectplus = 1; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 326 | |
| 327 | reg.Function = 0; |
| 328 | reg.Action = CS_WRITE; |
| 329 | reg.Offset = CISREG_COR; |
| 330 | reg.Value = COR_SOFT_RESET; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 331 | res = pcmcia_access_configuration_register(hw_priv->link->handle, |
| 332 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 333 | if (res != CS_SUCCESS) { |
| 334 | printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n", |
| 335 | dev->name, res); |
| 336 | goto done; |
| 337 | } |
| 338 | mdelay(5); |
| 339 | |
| 340 | reg.Function = 0; |
| 341 | reg.Action = CS_WRITE; |
| 342 | reg.Offset = CISREG_COR; |
| 343 | /* |
| 344 | * Do not enable interrupts here to avoid some bogus events. Interrupts |
| 345 | * will be enabled during the first cor_sreset call. |
| 346 | */ |
| 347 | reg.Value = COR_LEVEL_REQ | 0x8 | COR_ADDR_DECODE | COR_FUNC_ENA; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 348 | res = pcmcia_access_configuration_register(hw_priv->link->handle, |
| 349 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 350 | if (res != CS_SUCCESS) { |
| 351 | printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n", |
| 352 | dev->name, res); |
| 353 | goto done; |
| 354 | } |
| 355 | mdelay(5); |
| 356 | |
| 357 | sandisk_set_iobase(local); |
| 358 | |
| 359 | HFA384X_OUTB(0xc5, SANDISK_WLAN_ACTIVATION_OFF); |
| 360 | udelay(10); |
| 361 | HFA384X_OUTB(0x4b, SANDISK_WLAN_ACTIVATION_OFF); |
| 362 | udelay(10); |
| 363 | |
| 364 | done: |
| 365 | kfree(parse); |
| 366 | return ret; |
| 367 | } |
| 368 | |
| 369 | |
| 370 | static void prism2_pccard_cor_sreset(local_info_t *local) |
| 371 | { |
| 372 | int res; |
| 373 | conf_reg_t reg; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 374 | struct hostap_cs_priv *hw_priv = local->hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 375 | |
| 376 | if (!prism2_pccard_card_present(local)) |
| 377 | return; |
| 378 | |
| 379 | reg.Function = 0; |
| 380 | reg.Action = CS_READ; |
| 381 | reg.Offset = CISREG_COR; |
| 382 | reg.Value = 0; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 383 | res = pcmcia_access_configuration_register(hw_priv->link->handle, |
| 384 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 385 | if (res != CS_SUCCESS) { |
| 386 | printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 1 (%d)\n", |
| 387 | res); |
| 388 | return; |
| 389 | } |
| 390 | printk(KERN_DEBUG "prism2_pccard_cor_sreset: original COR %02x\n", |
| 391 | reg.Value); |
| 392 | |
| 393 | reg.Action = CS_WRITE; |
| 394 | reg.Value |= COR_SOFT_RESET; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 395 | res = pcmcia_access_configuration_register(hw_priv->link->handle, |
| 396 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 397 | if (res != CS_SUCCESS) { |
| 398 | printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 2 (%d)\n", |
| 399 | res); |
| 400 | return; |
| 401 | } |
| 402 | |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 403 | mdelay(hw_priv->sandisk_connectplus ? 5 : 2); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 404 | |
| 405 | reg.Value &= ~COR_SOFT_RESET; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 406 | if (hw_priv->sandisk_connectplus) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 407 | reg.Value |= COR_IREQ_ENA; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 408 | res = pcmcia_access_configuration_register(hw_priv->link->handle, |
| 409 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 410 | if (res != CS_SUCCESS) { |
| 411 | printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 3 (%d)\n", |
| 412 | res); |
| 413 | return; |
| 414 | } |
| 415 | |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 416 | mdelay(hw_priv->sandisk_connectplus ? 5 : 2); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 417 | |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 418 | if (hw_priv->sandisk_connectplus) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 419 | sandisk_set_iobase(local); |
| 420 | } |
| 421 | |
| 422 | |
| 423 | static void prism2_pccard_genesis_reset(local_info_t *local, int hcr) |
| 424 | { |
| 425 | int res; |
| 426 | conf_reg_t reg; |
| 427 | int old_cor; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 428 | struct hostap_cs_priv *hw_priv = local->hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 429 | |
| 430 | if (!prism2_pccard_card_present(local)) |
| 431 | return; |
| 432 | |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 433 | if (hw_priv->sandisk_connectplus) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 434 | sandisk_write_hcr(local, hcr); |
| 435 | return; |
| 436 | } |
| 437 | |
| 438 | reg.Function = 0; |
| 439 | reg.Action = CS_READ; |
| 440 | reg.Offset = CISREG_COR; |
| 441 | reg.Value = 0; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 442 | res = pcmcia_access_configuration_register(hw_priv->link->handle, |
| 443 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 444 | if (res != CS_SUCCESS) { |
| 445 | printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 " |
| 446 | "(%d)\n", res); |
| 447 | return; |
| 448 | } |
| 449 | printk(KERN_DEBUG "prism2_pccard_genesis_sreset: original COR %02x\n", |
| 450 | reg.Value); |
| 451 | old_cor = reg.Value; |
| 452 | |
| 453 | reg.Action = CS_WRITE; |
| 454 | reg.Value |= COR_SOFT_RESET; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 455 | res = pcmcia_access_configuration_register(hw_priv->link->handle, |
| 456 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 457 | if (res != CS_SUCCESS) { |
| 458 | printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 " |
| 459 | "(%d)\n", res); |
| 460 | return; |
| 461 | } |
| 462 | |
| 463 | mdelay(10); |
| 464 | |
| 465 | /* Setup Genesis mode */ |
| 466 | reg.Action = CS_WRITE; |
| 467 | reg.Value = hcr; |
| 468 | reg.Offset = CISREG_CCSR; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 469 | res = pcmcia_access_configuration_register(hw_priv->link->handle, |
| 470 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 471 | if (res != CS_SUCCESS) { |
| 472 | printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 " |
| 473 | "(%d)\n", res); |
| 474 | return; |
| 475 | } |
| 476 | mdelay(10); |
| 477 | |
| 478 | reg.Action = CS_WRITE; |
| 479 | reg.Offset = CISREG_COR; |
| 480 | reg.Value = old_cor & ~COR_SOFT_RESET; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 481 | res = pcmcia_access_configuration_register(hw_priv->link->handle, |
| 482 | ®); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 483 | if (res != CS_SUCCESS) { |
| 484 | printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 " |
| 485 | "(%d)\n", res); |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | mdelay(10); |
| 490 | } |
| 491 | |
| 492 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 493 | static struct prism2_helper_functions prism2_pccard_funcs = |
| 494 | { |
| 495 | .card_present = prism2_pccard_card_present, |
| 496 | .cor_sreset = prism2_pccard_cor_sreset, |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 497 | .genesis_reset = prism2_pccard_genesis_reset, |
| 498 | .hw_type = HOSTAP_HW_PCCARD, |
| 499 | }; |
| 500 | |
| 501 | |
| 502 | /* allocate local data and register with CardServices |
| 503 | * initialize dev_link structure, but do not configure the card yet */ |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 504 | static int prism2_attach(struct pcmcia_device *p_dev) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 505 | { |
| 506 | dev_link_t *link; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 507 | |
| 508 | link = kmalloc(sizeof(dev_link_t), GFP_KERNEL); |
| 509 | if (link == NULL) |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 510 | return -ENOMEM; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 511 | |
| 512 | memset(link, 0, sizeof(dev_link_t)); |
| 513 | |
| 514 | PDEBUG(DEBUG_HW, "%s: setting Vcc=33 (constant)\n", dev_info); |
| 515 | link->conf.Vcc = 33; |
| 516 | link->conf.IntType = INT_MEMORY_AND_IO; |
| 517 | |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 518 | link->handle = p_dev; |
| 519 | p_dev->instance = link; |
| 520 | |
| 521 | link->state |= DEV_PRESENT | DEV_CONFIG_PENDING; |
| 522 | if (prism2_config(link)) |
| 523 | PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n"); |
| 524 | |
| 525 | return 0; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 529 | static void prism2_detach(struct pcmcia_device *p_dev) |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 530 | { |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 531 | dev_link_t *link = dev_to_instance(p_dev); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 532 | |
| 533 | PDEBUG(DEBUG_FLOW, "prism2_detach\n"); |
| 534 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 535 | if (link->state & DEV_CONFIG) { |
| 536 | prism2_release((u_long)link); |
| 537 | } |
| 538 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 539 | /* release net devices */ |
| 540 | if (link->priv) { |
Jouni Malinen | c355184 | 2005-10-02 17:19:00 -0700 | [diff] [blame] | 541 | struct hostap_cs_priv *hw_priv; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 542 | struct net_device *dev; |
| 543 | struct hostap_interface *iface; |
| 544 | dev = link->priv; |
| 545 | iface = netdev_priv(dev); |
Jouni Malinen | c355184 | 2005-10-02 17:19:00 -0700 | [diff] [blame] | 546 | hw_priv = iface->local->hw_priv; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 547 | prism2_free_local_data(dev); |
Jouni Malinen | c355184 | 2005-10-02 17:19:00 -0700 | [diff] [blame] | 548 | kfree(hw_priv); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 549 | } |
| 550 | kfree(link); |
| 551 | } |
| 552 | |
| 553 | |
| 554 | #define CS_CHECK(fn, ret) \ |
| 555 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) |
| 556 | |
| 557 | #define CFG_CHECK2(fn, retf) \ |
| 558 | do { int ret = (retf); \ |
| 559 | if (ret != 0) { \ |
| 560 | PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", ret); \ |
| 561 | cs_error(link->handle, fn, ret); \ |
| 562 | goto next_entry; \ |
| 563 | } \ |
| 564 | } while (0) |
| 565 | |
| 566 | |
| 567 | /* run after a CARD_INSERTION event is received to configure the PCMCIA |
| 568 | * socket and make the device available to the system */ |
| 569 | static int prism2_config(dev_link_t *link) |
| 570 | { |
| 571 | struct net_device *dev; |
| 572 | struct hostap_interface *iface; |
| 573 | local_info_t *local; |
| 574 | int ret = 1; |
| 575 | tuple_t tuple; |
| 576 | cisparse_t *parse; |
| 577 | int last_fn, last_ret; |
| 578 | u_char buf[64]; |
| 579 | config_info_t conf; |
| 580 | cistpl_cftable_entry_t dflt = { 0 }; |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 581 | struct hostap_cs_priv *hw_priv; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 582 | |
| 583 | PDEBUG(DEBUG_FLOW, "prism2_config()\n"); |
| 584 | |
| 585 | parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL); |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 586 | hw_priv = kmalloc(sizeof(*hw_priv), GFP_KERNEL); |
| 587 | if (parse == NULL || hw_priv == NULL) { |
| 588 | kfree(parse); |
| 589 | kfree(hw_priv); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 590 | ret = -ENOMEM; |
| 591 | goto failed; |
| 592 | } |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 593 | memset(hw_priv, 0, sizeof(*hw_priv)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 594 | |
| 595 | tuple.DesiredTuple = CISTPL_CONFIG; |
| 596 | tuple.Attributes = 0; |
| 597 | tuple.TupleData = buf; |
| 598 | tuple.TupleDataMax = sizeof(buf); |
| 599 | tuple.TupleOffset = 0; |
| 600 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link->handle, &tuple)); |
| 601 | CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link->handle, &tuple)); |
| 602 | CS_CHECK(ParseTuple, pcmcia_parse_tuple(link->handle, &tuple, parse)); |
| 603 | link->conf.ConfigBase = parse->config.base; |
| 604 | link->conf.Present = parse->config.rmask[0]; |
| 605 | |
| 606 | CS_CHECK(GetConfigurationInfo, |
| 607 | pcmcia_get_configuration_info(link->handle, &conf)); |
| 608 | PDEBUG(DEBUG_HW, "%s: %s Vcc=%d (from config)\n", dev_info, |
| 609 | ignore_cis_vcc ? "ignoring" : "setting", conf.Vcc); |
| 610 | link->conf.Vcc = conf.Vcc; |
| 611 | |
| 612 | /* Look for an appropriate configuration table entry in the CIS */ |
| 613 | tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY; |
| 614 | CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link->handle, &tuple)); |
| 615 | for (;;) { |
| 616 | cistpl_cftable_entry_t *cfg = &(parse->cftable_entry); |
| 617 | CFG_CHECK2(GetTupleData, |
| 618 | pcmcia_get_tuple_data(link->handle, &tuple)); |
| 619 | CFG_CHECK2(ParseTuple, |
| 620 | pcmcia_parse_tuple(link->handle, &tuple, parse)); |
| 621 | |
| 622 | if (cfg->flags & CISTPL_CFTABLE_DEFAULT) |
| 623 | dflt = *cfg; |
| 624 | if (cfg->index == 0) |
| 625 | goto next_entry; |
| 626 | link->conf.ConfigIndex = cfg->index; |
| 627 | PDEBUG(DEBUG_EXTRA, "Checking CFTABLE_ENTRY 0x%02X " |
| 628 | "(default 0x%02X)\n", cfg->index, dflt.index); |
Jeff Garzik | 74fae82 | 2005-07-31 13:08:32 -0400 | [diff] [blame] | 629 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 630 | /* Does this card need audio output? */ |
| 631 | if (cfg->flags & CISTPL_CFTABLE_AUDIO) { |
| 632 | link->conf.Attributes |= CONF_ENABLE_SPKR; |
| 633 | link->conf.Status = CCSR_AUDIO_ENA; |
| 634 | } |
Jeff Garzik | 74fae82 | 2005-07-31 13:08:32 -0400 | [diff] [blame] | 635 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 636 | /* Use power settings for Vcc and Vpp if present */ |
| 637 | /* Note that the CIS values need to be rescaled */ |
| 638 | if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) { |
| 639 | if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / |
| 640 | 10000 && !ignore_cis_vcc) { |
| 641 | PDEBUG(DEBUG_EXTRA, " Vcc mismatch - skipping" |
| 642 | " this entry\n"); |
| 643 | goto next_entry; |
| 644 | } |
| 645 | } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) { |
| 646 | if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / |
| 647 | 10000 && !ignore_cis_vcc) { |
| 648 | PDEBUG(DEBUG_EXTRA, " Vcc (default) mismatch " |
| 649 | "- skipping this entry\n"); |
| 650 | goto next_entry; |
| 651 | } |
| 652 | } |
| 653 | |
| 654 | if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) |
| 655 | link->conf.Vpp1 = link->conf.Vpp2 = |
| 656 | cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000; |
| 657 | else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) |
| 658 | link->conf.Vpp1 = link->conf.Vpp2 = |
| 659 | dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000; |
| 660 | |
| 661 | /* Do we need to allocate an interrupt? */ |
| 662 | if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) |
| 663 | link->conf.Attributes |= CONF_ENABLE_IRQ; |
| 664 | else if (!(link->conf.Attributes & CONF_ENABLE_IRQ)) { |
| 665 | /* At least Compaq WL200 does not have IRQInfo1 set, |
| 666 | * but it does not work without interrupts.. */ |
| 667 | printk("Config has no IRQ info, but trying to enable " |
| 668 | "IRQ anyway..\n"); |
| 669 | link->conf.Attributes |= CONF_ENABLE_IRQ; |
| 670 | } |
| 671 | |
| 672 | /* IO window settings */ |
| 673 | PDEBUG(DEBUG_EXTRA, "IO window settings: cfg->io.nwin=%d " |
| 674 | "dflt.io.nwin=%d\n", |
| 675 | cfg->io.nwin, dflt.io.nwin); |
| 676 | link->io.NumPorts1 = link->io.NumPorts2 = 0; |
| 677 | if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) { |
| 678 | cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io; |
| 679 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO; |
| 680 | PDEBUG(DEBUG_EXTRA, "io->flags = 0x%04X, " |
| 681 | "io.base=0x%04x, len=%d\n", io->flags, |
| 682 | io->win[0].base, io->win[0].len); |
| 683 | if (!(io->flags & CISTPL_IO_8BIT)) |
| 684 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_16; |
| 685 | if (!(io->flags & CISTPL_IO_16BIT)) |
| 686 | link->io.Attributes1 = IO_DATA_PATH_WIDTH_8; |
| 687 | link->io.IOAddrLines = io->flags & |
| 688 | CISTPL_IO_LINES_MASK; |
| 689 | link->io.BasePort1 = io->win[0].base; |
| 690 | link->io.NumPorts1 = io->win[0].len; |
| 691 | if (io->nwin > 1) { |
| 692 | link->io.Attributes2 = link->io.Attributes1; |
| 693 | link->io.BasePort2 = io->win[1].base; |
| 694 | link->io.NumPorts2 = io->win[1].len; |
| 695 | } |
| 696 | } |
| 697 | |
| 698 | /* This reserves IO space but doesn't actually enable it */ |
| 699 | CFG_CHECK2(RequestIO, |
| 700 | pcmcia_request_io(link->handle, &link->io)); |
| 701 | |
| 702 | /* This configuration table entry is OK */ |
| 703 | break; |
| 704 | |
| 705 | next_entry: |
| 706 | CS_CHECK(GetNextTuple, |
| 707 | pcmcia_get_next_tuple(link->handle, &tuple)); |
| 708 | } |
| 709 | |
| 710 | /* Need to allocate net_device before requesting IRQ handler */ |
Dave Hansen | 0cd545d | 2005-07-30 12:49:58 -0700 | [diff] [blame] | 711 | dev = prism2_init_local_data(&prism2_pccard_funcs, 0, |
| 712 | &handle_to_dev(link->handle)); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 713 | if (dev == NULL) |
| 714 | goto failed; |
| 715 | link->priv = dev; |
| 716 | |
Jouni Malinen | fbff868 | 2005-08-28 17:53:32 -0700 | [diff] [blame] | 717 | iface = netdev_priv(dev); |
| 718 | local = iface->local; |
| 719 | local->hw_priv = hw_priv; |
| 720 | hw_priv->link = link; |
| 721 | strcpy(hw_priv->node.dev_name, dev->name); |
| 722 | link->dev = &hw_priv->node; |
| 723 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 724 | /* |
| 725 | * Allocate an interrupt line. Note that this does not assign a |
| 726 | * handler to the interrupt, unless the 'Handler' member of the |
| 727 | * irq structure is initialized. |
| 728 | */ |
| 729 | if (link->conf.Attributes & CONF_ENABLE_IRQ) { |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 730 | link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT; |
Jar | 0ef79ee | 2005-07-30 12:49:57 -0700 | [diff] [blame] | 731 | link->irq.IRQInfo1 = IRQ_LEVEL_ID; |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 732 | link->irq.Handler = prism2_interrupt; |
| 733 | link->irq.Instance = dev; |
| 734 | CS_CHECK(RequestIRQ, |
| 735 | pcmcia_request_irq(link->handle, &link->irq)); |
| 736 | } |
| 737 | |
| 738 | /* |
| 739 | * This actually configures the PCMCIA socket -- setting up |
| 740 | * the I/O windows and the interrupt mapping, and putting the |
| 741 | * card and host interface into "Memory and IO" mode. |
| 742 | */ |
| 743 | CS_CHECK(RequestConfiguration, |
| 744 | pcmcia_request_configuration(link->handle, &link->conf)); |
| 745 | |
| 746 | dev->irq = link->irq.AssignedIRQ; |
| 747 | dev->base_addr = link->io.BasePort1; |
| 748 | |
| 749 | /* Finally, report what we've done */ |
| 750 | printk(KERN_INFO "%s: index 0x%02x: Vcc %d.%d", |
| 751 | dev_info, link->conf.ConfigIndex, |
| 752 | link->conf.Vcc / 10, link->conf.Vcc % 10); |
| 753 | if (link->conf.Vpp1) |
| 754 | printk(", Vpp %d.%d", link->conf.Vpp1 / 10, |
| 755 | link->conf.Vpp1 % 10); |
| 756 | if (link->conf.Attributes & CONF_ENABLE_IRQ) |
| 757 | printk(", irq %d", link->irq.AssignedIRQ); |
| 758 | if (link->io.NumPorts1) |
| 759 | printk(", io 0x%04x-0x%04x", link->io.BasePort1, |
| 760 | link->io.BasePort1+link->io.NumPorts1-1); |
| 761 | if (link->io.NumPorts2) |
| 762 | printk(" & 0x%04x-0x%04x", link->io.BasePort2, |
| 763 | link->io.BasePort2+link->io.NumPorts2-1); |
| 764 | printk("\n"); |
| 765 | |
| 766 | link->state |= DEV_CONFIG; |
| 767 | link->state &= ~DEV_CONFIG_PENDING; |
| 768 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 769 | local->shutdown = 0; |
| 770 | |
| 771 | sandisk_enable_wireless(dev); |
| 772 | |
| 773 | ret = prism2_hw_config(dev, 1); |
| 774 | if (!ret) { |
| 775 | ret = hostap_hw_ready(dev); |
| 776 | if (ret == 0 && local->ddev) |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 777 | strcpy(hw_priv->node.dev_name, local->ddev->name); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 778 | } |
| 779 | kfree(parse); |
| 780 | return ret; |
| 781 | |
| 782 | cs_failed: |
| 783 | cs_error(link->handle, last_fn, last_ret); |
| 784 | |
| 785 | failed: |
| 786 | kfree(parse); |
Jouni Malinen | 67e0e47 | 2005-08-14 19:08:41 -0700 | [diff] [blame] | 787 | kfree(hw_priv); |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 788 | prism2_release((u_long)link); |
| 789 | return ret; |
| 790 | } |
| 791 | |
| 792 | |
| 793 | static void prism2_release(u_long arg) |
| 794 | { |
| 795 | dev_link_t *link = (dev_link_t *)arg; |
| 796 | |
| 797 | PDEBUG(DEBUG_FLOW, "prism2_release\n"); |
| 798 | |
| 799 | if (link->priv) { |
| 800 | struct net_device *dev = link->priv; |
| 801 | struct hostap_interface *iface; |
| 802 | |
| 803 | iface = netdev_priv(dev); |
| 804 | if (link->state & DEV_CONFIG) |
| 805 | prism2_hw_shutdown(dev, 0); |
| 806 | iface->local->shutdown = 1; |
| 807 | } |
| 808 | |
| 809 | if (link->win) |
| 810 | pcmcia_release_window(link->win); |
| 811 | pcmcia_release_configuration(link->handle); |
| 812 | if (link->io.NumPorts1) |
| 813 | pcmcia_release_io(link->handle, &link->io); |
| 814 | if (link->irq.AssignedIRQ) |
| 815 | pcmcia_release_irq(link->handle, &link->irq); |
| 816 | |
| 817 | link->state &= ~DEV_CONFIG; |
| 818 | |
| 819 | PDEBUG(DEBUG_FLOW, "release - done\n"); |
| 820 | } |
| 821 | |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 822 | static int hostap_cs_suspend(struct pcmcia_device *p_dev) |
| 823 | { |
| 824 | dev_link_t *link = dev_to_instance(p_dev); |
| 825 | struct net_device *dev = (struct net_device *) link->priv; |
| 826 | int dev_open = 0; |
| 827 | |
| 828 | PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info); |
| 829 | |
| 830 | link->state |= DEV_SUSPEND; |
| 831 | |
| 832 | if (link->state & DEV_CONFIG) { |
| 833 | struct hostap_interface *iface = netdev_priv(dev); |
| 834 | if (iface && iface->local) |
| 835 | dev_open = iface->local->num_dev_open > 0; |
| 836 | if (dev_open) { |
| 837 | netif_stop_queue(dev); |
| 838 | netif_device_detach(dev); |
| 839 | } |
| 840 | prism2_suspend(dev); |
| 841 | pcmcia_release_configuration(link->handle); |
| 842 | } |
| 843 | |
| 844 | return 0; |
| 845 | } |
| 846 | |
| 847 | static int hostap_cs_resume(struct pcmcia_device *p_dev) |
| 848 | { |
| 849 | dev_link_t *link = dev_to_instance(p_dev); |
| 850 | struct net_device *dev = (struct net_device *) link->priv; |
| 851 | int dev_open = 0; |
| 852 | |
| 853 | PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info); |
| 854 | |
| 855 | link->state &= ~DEV_SUSPEND; |
| 856 | if (link->state & DEV_CONFIG) { |
| 857 | struct hostap_interface *iface = netdev_priv(dev); |
| 858 | if (iface && iface->local) |
| 859 | dev_open = iface->local->num_dev_open > 0; |
| 860 | |
| 861 | pcmcia_request_configuration(link->handle, &link->conf); |
| 862 | |
| 863 | prism2_hw_shutdown(dev, 1); |
| 864 | prism2_hw_config(dev, dev_open ? 0 : 1); |
| 865 | if (dev_open) { |
| 866 | netif_device_attach(dev); |
| 867 | netif_start_queue(dev); |
| 868 | } |
| 869 | } |
| 870 | |
| 871 | return 0; |
| 872 | } |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 873 | |
Henrik Brix Andersen | 093853c | 2005-07-30 12:49:59 -0700 | [diff] [blame] | 874 | static struct pcmcia_device_id hostap_cs_ids[] = { |
| 875 | PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100), |
| 876 | PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300), |
| 877 | PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777), |
| 878 | PCMCIA_DEVICE_MANF_CARD(0x0126, 0x8000), |
| 879 | PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002), |
| 880 | PCMCIA_DEVICE_MANF_CARD(0x0156, 0x0002), |
| 881 | PCMCIA_DEVICE_MANF_CARD(0x0250, 0x0002), |
Richard Purdie | 1e4adbd | 2005-08-04 00:16:27 +0100 | [diff] [blame] | 882 | PCMCIA_DEVICE_MANF_CARD(0x026f, 0x030b), |
Henrik Brix Andersen | 093853c | 2005-07-30 12:49:59 -0700 | [diff] [blame] | 883 | PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1612), |
| 884 | PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613), |
| 885 | PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002), |
| 886 | PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002), |
| 887 | PCMCIA_DEVICE_MANF_CARD(0x02d2, 0x0001), |
| 888 | PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x0001), |
| 889 | PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300), |
| 890 | PCMCIA_DEVICE_MANF_CARD(0xc00f, 0x0000), |
| 891 | PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002), |
| 892 | PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005), |
| 893 | PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0010), |
| 894 | PCMCIA_MFC_DEVICE_PROD_ID12(0, "SanDisk", "ConnectPlus", |
| 895 | 0x7a954bd9, 0x74be00c6), |
| 896 | PCMCIA_DEVICE_PROD_ID1234( |
| 897 | "Intersil", "PRISM 2_5 PCMCIA ADAPTER", "ISL37300P", |
| 898 | "Eval-RevA", |
| 899 | 0x4b801a17, 0x6345a0bf, 0xc9049a39, 0xc23adc0e), |
| 900 | PCMCIA_DEVICE_PROD_ID123( |
| 901 | "Addtron", "AWP-100 Wireless PCMCIA", "Version 01.02", |
| 902 | 0xe6ec52ce, 0x08649af2, 0x4b74baa0), |
| 903 | PCMCIA_DEVICE_PROD_ID123( |
| 904 | "D", "Link DWL-650 11Mbps WLAN Card", "Version 01.02", |
| 905 | 0x71b18589, 0xb6f1b0ab, 0x4b74baa0), |
| 906 | PCMCIA_DEVICE_PROD_ID123( |
| 907 | "Instant Wireless ", " Network PC CARD", "Version 01.02", |
| 908 | 0x11d901af, 0x6e9bd926, 0x4b74baa0), |
| 909 | PCMCIA_DEVICE_PROD_ID123( |
| 910 | "SMC", "SMC2632W", "Version 01.02", |
| 911 | 0xc4f8b18b, 0x474a1f2a, 0x4b74baa0), |
Richard Purdie | 1e4adbd | 2005-08-04 00:16:27 +0100 | [diff] [blame] | 912 | PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-CF-S11G", |
Jouni Malinen | 6c5b90d | 2005-08-28 10:51:36 -0700 | [diff] [blame] | 913 | 0x2decece3, 0x82067c18), |
Henrik Brix Andersen | 093853c | 2005-07-30 12:49:59 -0700 | [diff] [blame] | 914 | PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card", |
| 915 | 0x54f7c49c, 0x15a75e5b), |
| 916 | PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE", |
| 917 | 0x74c5e40d, 0xdb472a18), |
| 918 | PCMCIA_DEVICE_PROD_ID12("Linksys", "Wireless CompactFlash Card", |
| 919 | 0x0733cc81, 0x0c52f395), |
| 920 | PCMCIA_DEVICE_PROD_ID12( |
| 921 | "ZoomAir 11Mbps High", "Rate wireless Networking", |
| 922 | 0x273fe3db, 0x32a1eaee), |
| 923 | PCMCIA_DEVICE_NULL |
| 924 | }; |
| 925 | MODULE_DEVICE_TABLE(pcmcia, hostap_cs_ids); |
| 926 | |
| 927 | |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 928 | static struct pcmcia_driver hostap_driver = { |
| 929 | .drv = { |
| 930 | .name = "hostap_cs", |
| 931 | }, |
Dominik Brodowski | f8cfa61 | 2005-11-14 21:25:51 +0100 | [diff] [blame] | 932 | .probe = prism2_attach, |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 933 | .remove = prism2_detach, |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 934 | .owner = THIS_MODULE, |
Henrik Brix Andersen | 093853c | 2005-07-30 12:49:59 -0700 | [diff] [blame] | 935 | .id_table = hostap_cs_ids, |
Dominik Brodowski | 98e4c28 | 2005-11-14 21:21:18 +0100 | [diff] [blame] | 936 | .suspend = hostap_cs_suspend, |
| 937 | .resume = hostap_cs_resume, |
Jouni Malinen | ff1d276 | 2005-05-12 22:54:16 -0400 | [diff] [blame] | 938 | }; |
| 939 | |
| 940 | static int __init init_prism2_pccard(void) |
| 941 | { |
| 942 | printk(KERN_INFO "%s: %s\n", dev_info, version); |
| 943 | return pcmcia_register_driver(&hostap_driver); |
| 944 | } |
| 945 | |
| 946 | static void __exit exit_prism2_pccard(void) |
| 947 | { |
| 948 | pcmcia_unregister_driver(&hostap_driver); |
| 949 | printk(KERN_INFO "%s: Driver unloaded\n", dev_info); |
| 950 | } |
| 951 | |
| 952 | |
| 953 | module_init(init_prism2_pccard); |
| 954 | module_exit(exit_prism2_pccard); |