hostap_cs.c 23.5 KB
Newer Older
J
Jouni Malinen 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
#define PRISM2_PCCARD

#include <linux/module.h>
#include <linux/init.h>
#include <linux/if.h>
#include <linux/wait.h>
#include <linux/timer.h>
#include <linux/skbuff.h>
#include <linux/netdevice.h>
#include <linux/workqueue.h>
#include <linux/wireless.h>
#include <net/iw_handler.h>

#include <pcmcia/cs_types.h>
#include <pcmcia/cs.h>
#include <pcmcia/cistpl.h>
#include <pcmcia/cisreg.h>
#include <pcmcia/ds.h>

#include <asm/io.h>

#include "hostap_wlan.h"


static dev_info_t dev_info = "hostap_cs";

MODULE_AUTHOR("Jouni Malinen");
MODULE_DESCRIPTION("Support for Intersil Prism2-based 802.11 wireless LAN "
		   "cards (PC Card).");
MODULE_SUPPORTED_DEVICE("Intersil Prism2-based WLAN cards (PC Card)");
MODULE_LICENSE("GPL");


static int ignore_cis_vcc;
module_param(ignore_cis_vcc, int, 0444);
MODULE_PARM_DESC(ignore_cis_vcc, "Ignore broken CIS VCC entry");


39 40 41
/* struct local_info::hw_priv */
struct hostap_cs_priv {
	dev_node_t node;
42
	struct pcmcia_device *link;
43 44 45 46
	int sandisk_connectplus;
};


J
Jouni Malinen 已提交
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
#ifdef PRISM2_IO_DEBUG

static inline void hfa384x_outb_debug(struct net_device *dev, int a, u8 v)
{
	struct hostap_interface *iface;
	local_info_t *local;
	unsigned long flags;

	iface = netdev_priv(dev);
	local = iface->local;
	spin_lock_irqsave(&local->lock, flags);
	prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTB, a, v);
	outb(v, dev->base_addr + a);
	spin_unlock_irqrestore(&local->lock, flags);
}

static inline u8 hfa384x_inb_debug(struct net_device *dev, int a)
{
	struct hostap_interface *iface;
	local_info_t *local;
	unsigned long flags;
	u8 v;

	iface = netdev_priv(dev);
	local = iface->local;
	spin_lock_irqsave(&local->lock, flags);
	v = inb(dev->base_addr + a);
	prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INB, a, v);
	spin_unlock_irqrestore(&local->lock, flags);
	return v;
}

static inline void hfa384x_outw_debug(struct net_device *dev, int a, u16 v)
{
	struct hostap_interface *iface;
	local_info_t *local;
	unsigned long flags;

	iface = netdev_priv(dev);
	local = iface->local;
	spin_lock_irqsave(&local->lock, flags);
	prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTW, a, v);
	outw(v, dev->base_addr + a);
	spin_unlock_irqrestore(&local->lock, flags);
}

static inline u16 hfa384x_inw_debug(struct net_device *dev, int a)
{
	struct hostap_interface *iface;
	local_info_t *local;
	unsigned long flags;
	u16 v;

	iface = netdev_priv(dev);
	local = iface->local;
	spin_lock_irqsave(&local->lock, flags);
	v = inw(dev->base_addr + a);
	prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INW, a, v);
	spin_unlock_irqrestore(&local->lock, flags);
	return v;
}

static inline void hfa384x_outsw_debug(struct net_device *dev, int a,
				       u8 *buf, int wc)
{
	struct hostap_interface *iface;
	local_info_t *local;
	unsigned long flags;

	iface = netdev_priv(dev);
	local = iface->local;
	spin_lock_irqsave(&local->lock, flags);
	prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_OUTSW, a, wc);
	outsw(dev->base_addr + a, buf, wc);
	spin_unlock_irqrestore(&local->lock, flags);
}

static inline void hfa384x_insw_debug(struct net_device *dev, int a,
				      u8 *buf, int wc)
{
	struct hostap_interface *iface;
	local_info_t *local;
	unsigned long flags;

	iface = netdev_priv(dev);
	local = iface->local;
	spin_lock_irqsave(&local->lock, flags);
	prism2_io_debug_add(dev, PRISM2_IO_DEBUG_CMD_INSW, a, wc);
	insw(dev->base_addr + a, buf, wc);
	spin_unlock_irqrestore(&local->lock, flags);
}

#define HFA384X_OUTB(v,a) hfa384x_outb_debug(dev, (a), (v))
#define HFA384X_INB(a) hfa384x_inb_debug(dev, (a))
#define HFA384X_OUTW(v,a) hfa384x_outw_debug(dev, (a), (v))
#define HFA384X_INW(a) hfa384x_inw_debug(dev, (a))
#define HFA384X_OUTSW(a, buf, wc) hfa384x_outsw_debug(dev, (a), (buf), (wc))
#define HFA384X_INSW(a, buf, wc) hfa384x_insw_debug(dev, (a), (buf), (wc))

#else /* PRISM2_IO_DEBUG */

#define HFA384X_OUTB(v,a) outb((v), dev->base_addr + (a))
#define HFA384X_INB(a) inb(dev->base_addr + (a))
#define HFA384X_OUTW(v,a) outw((v), dev->base_addr + (a))
#define HFA384X_INW(a) inw(dev->base_addr + (a))
#define HFA384X_INSW(a, buf, wc) insw(dev->base_addr + (a), buf, wc)
#define HFA384X_OUTSW(a, buf, wc) outsw(dev->base_addr + (a), buf, wc)

#endif /* PRISM2_IO_DEBUG */


static int hfa384x_from_bap(struct net_device *dev, u16 bap, void *buf,
			    int len)
{
	u16 d_off;
	u16 *pos;

	d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
	pos = (u16 *) buf;

	if (len / 2)
		HFA384X_INSW(d_off, buf, len / 2);
	pos += len / 2;

	if (len & 1)
		*((char *) pos) = HFA384X_INB(d_off);

	return 0;
}


static int hfa384x_to_bap(struct net_device *dev, u16 bap, void *buf, int len)
{
	u16 d_off;
	u16 *pos;

	d_off = (bap == 1) ? HFA384X_DATA1_OFF : HFA384X_DATA0_OFF;
	pos = (u16 *) buf;

	if (len / 2)
		HFA384X_OUTSW(d_off, buf, len / 2);
	pos += len / 2;

	if (len & 1)
		HFA384X_OUTB(*((char *) pos), d_off);

	return 0;
}


/* FIX: This might change at some point.. */
#include "hostap_hw.c"



202
static void prism2_detach(struct pcmcia_device *p_dev);
J
Jouni Malinen 已提交
203
static void prism2_release(u_long arg);
204
static int prism2_config(struct pcmcia_device *link);
J
Jouni Malinen 已提交
205 206 207 208


static int prism2_pccard_card_present(local_info_t *local)
{
209
	struct hostap_cs_priv *hw_priv = local->hw_priv;
210
	if (hw_priv != NULL && hw_priv->link != NULL && pcmcia_dev_present(hw_priv->link))
J
Jouni Malinen 已提交
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228
		return 1;
	return 0;
}


/*
 * SanDisk CompactFlash WLAN Flashcard - Product Manual v1.0
 * Document No. 20-10-00058, January 2004
 * http://www.sandisk.com/pdf/industrial/ProdManualCFWLANv1.0.pdf
 */
#define SANDISK_WLAN_ACTIVATION_OFF 0x40
#define SANDISK_HCR_OFF 0x42


static void sandisk_set_iobase(local_info_t *local)
{
	int res;
	conf_reg_t reg;
229
	struct hostap_cs_priv *hw_priv = local->hw_priv;
J
Jouni Malinen 已提交
230 231 232 233

	reg.Function = 0;
	reg.Action = CS_WRITE;
	reg.Offset = 0x10; /* 0x3f0 IO base 1 */
234
	reg.Value = hw_priv->link->io.BasePort1 & 0x00ff;
235
	res = pcmcia_access_configuration_register(hw_priv->link,
236
						   &reg);
D
Dominik Brodowski 已提交
237
	if (res != 0) {
J
Jouni Malinen 已提交
238 239 240 241 242 243 244 245
		printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 0 -"
		       " res=%d\n", res);
	}
	udelay(10);

	reg.Function = 0;
	reg.Action = CS_WRITE;
	reg.Offset = 0x12; /* 0x3f2 IO base 2 */
246
	reg.Value = (hw_priv->link->io.BasePort1 & 0xff00) >> 8;
247
	res = pcmcia_access_configuration_register(hw_priv->link,
248
						   &reg);
D
Dominik Brodowski 已提交
249
	if (res != 0) {
J
Jouni Malinen 已提交
250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274
		printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 1 -"
		       " res=%d\n", res);
	}
}


static void sandisk_write_hcr(local_info_t *local, int hcr)
{
	struct net_device *dev = local->dev;
	int i;

	HFA384X_OUTB(0x80, SANDISK_WLAN_ACTIVATION_OFF);
	udelay(50);
	for (i = 0; i < 10; i++) {
		HFA384X_OUTB(hcr, SANDISK_HCR_OFF);
	}
	udelay(55);
	HFA384X_OUTB(0x45, SANDISK_WLAN_ACTIVATION_OFF);
}


static int sandisk_enable_wireless(struct net_device *dev)
{
	int res, ret = 0;
	conf_reg_t reg;
275
	struct hostap_interface *iface = netdev_priv(dev);
J
Jouni Malinen 已提交
276 277 278 279
	local_info_t *local = iface->local;
	tuple_t tuple;
	cisparse_t *parse = NULL;
	u_char buf[64];
280
	struct hostap_cs_priv *hw_priv = local->hw_priv;
J
Jouni Malinen 已提交
281

282
	if (hw_priv->link->io.NumPorts1 < 0x42) {
J
Jouni Malinen 已提交
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
		/* Not enough ports to be SanDisk multi-function card */
		ret = -ENODEV;
		goto done;
	}

	parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL);
	if (parse == NULL) {
		ret = -ENOMEM;
		goto done;
	}

	tuple.Attributes = TUPLE_RETURN_COMMON;
	tuple.TupleData = buf;
	tuple.TupleDataMax = sizeof(buf);
	tuple.TupleOffset = 0;
298 299

	if (hw_priv->link->manf_id != 0xd601 || hw_priv->link->card_id != 0x0101) {
J
Jouni Malinen 已提交
300 301 302 303 304 305
		/* No SanDisk manfid found */
		ret = -ENODEV;
		goto done;
	}

	tuple.DesiredTuple = CISTPL_LONGLINK_MFC;
306 307 308
	if (pcmcia_get_first_tuple(hw_priv->link, &tuple) ||
	    pcmcia_get_tuple_data(hw_priv->link, &tuple) ||
	    pcmcia_parse_tuple(hw_priv->link, &tuple, parse) ||
J
Jouni Malinen 已提交
309 310 311 312 313 314 315 316
		parse->longlink_mfc.nfn < 2) {
		/* No multi-function links found */
		ret = -ENODEV;
		goto done;
	}

	printk(KERN_DEBUG "%s: Multi-function SanDisk ConnectPlus detected"
	       " - using vendor-specific initialization\n", dev->name);
317
	hw_priv->sandisk_connectplus = 1;
J
Jouni Malinen 已提交
318 319 320 321 322

	reg.Function = 0;
	reg.Action = CS_WRITE;
	reg.Offset = CISREG_COR;
	reg.Value = COR_SOFT_RESET;
323
	res = pcmcia_access_configuration_register(hw_priv->link,
324
						   &reg);
D
Dominik Brodowski 已提交
325
	if (res != 0) {
J
Jouni Malinen 已提交
326 327 328 329 330 331 332 333 334 335 336 337 338 339
		printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
		       dev->name, res);
		goto done;
	}
	mdelay(5);

	reg.Function = 0;
	reg.Action = CS_WRITE;
	reg.Offset = CISREG_COR;
	/*
	 * Do not enable interrupts here to avoid some bogus events. Interrupts
	 * will be enabled during the first cor_sreset call.
	 */
	reg.Value = COR_LEVEL_REQ | 0x8 | COR_ADDR_DECODE | COR_FUNC_ENA;
340
	res = pcmcia_access_configuration_register(hw_priv->link,
341
						   &reg);
D
Dominik Brodowski 已提交
342
	if (res != 0) {
J
Jouni Malinen 已提交
343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
		printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
		       dev->name, res);
		goto done;
	}
	mdelay(5);

	sandisk_set_iobase(local);

	HFA384X_OUTB(0xc5, SANDISK_WLAN_ACTIVATION_OFF);
	udelay(10);
	HFA384X_OUTB(0x4b, SANDISK_WLAN_ACTIVATION_OFF);
	udelay(10);

done:
	kfree(parse);
	return ret;
}


static void prism2_pccard_cor_sreset(local_info_t *local)
{
	int res;
	conf_reg_t reg;
366
	struct hostap_cs_priv *hw_priv = local->hw_priv;
J
Jouni Malinen 已提交
367 368 369 370 371 372 373 374

	if (!prism2_pccard_card_present(local))
	       return;

	reg.Function = 0;
	reg.Action = CS_READ;
	reg.Offset = CISREG_COR;
	reg.Value = 0;
375
	res = pcmcia_access_configuration_register(hw_priv->link,
376
						   &reg);
D
Dominik Brodowski 已提交
377
	if (res != 0) {
J
Jouni Malinen 已提交
378 379 380 381 382 383 384 385 386
		printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 1 (%d)\n",
		       res);
		return;
	}
	printk(KERN_DEBUG "prism2_pccard_cor_sreset: original COR %02x\n",
	       reg.Value);

	reg.Action = CS_WRITE;
	reg.Value |= COR_SOFT_RESET;
387
	res = pcmcia_access_configuration_register(hw_priv->link,
388
						   &reg);
D
Dominik Brodowski 已提交
389
	if (res != 0) {
J
Jouni Malinen 已提交
390 391 392 393 394
		printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 2 (%d)\n",
		       res);
		return;
	}

395
	mdelay(hw_priv->sandisk_connectplus ? 5 : 2);
J
Jouni Malinen 已提交
396 397

	reg.Value &= ~COR_SOFT_RESET;
398
	if (hw_priv->sandisk_connectplus)
J
Jouni Malinen 已提交
399
		reg.Value |= COR_IREQ_ENA;
400
	res = pcmcia_access_configuration_register(hw_priv->link,
401
						   &reg);
D
Dominik Brodowski 已提交
402
	if (res != 0) {
J
Jouni Malinen 已提交
403 404 405 406 407
		printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 3 (%d)\n",
		       res);
		return;
	}

408
	mdelay(hw_priv->sandisk_connectplus ? 5 : 2);
J
Jouni Malinen 已提交
409

410
	if (hw_priv->sandisk_connectplus)
J
Jouni Malinen 已提交
411 412 413 414 415 416 417 418 419
		sandisk_set_iobase(local);
}


static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
{
	int res;
	conf_reg_t reg;
	int old_cor;
420
	struct hostap_cs_priv *hw_priv = local->hw_priv;
J
Jouni Malinen 已提交
421 422 423 424

	if (!prism2_pccard_card_present(local))
	       return;

425
	if (hw_priv->sandisk_connectplus) {
J
Jouni Malinen 已提交
426 427 428 429 430 431 432 433
		sandisk_write_hcr(local, hcr);
		return;
	}

	reg.Function = 0;
	reg.Action = CS_READ;
	reg.Offset = CISREG_COR;
	reg.Value = 0;
434
	res = pcmcia_access_configuration_register(hw_priv->link,
435
						   &reg);
D
Dominik Brodowski 已提交
436
	if (res != 0) {
J
Jouni Malinen 已提交
437 438 439 440 441 442 443 444 445 446
		printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 "
		       "(%d)\n", res);
		return;
	}
	printk(KERN_DEBUG "prism2_pccard_genesis_sreset: original COR %02x\n",
	       reg.Value);
	old_cor = reg.Value;

	reg.Action = CS_WRITE;
	reg.Value |= COR_SOFT_RESET;
447
	res = pcmcia_access_configuration_register(hw_priv->link,
448
						   &reg);
D
Dominik Brodowski 已提交
449
	if (res != 0) {
J
Jouni Malinen 已提交
450 451 452 453 454 455 456 457 458 459 460
		printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 "
		       "(%d)\n", res);
		return;
	}

	mdelay(10);

	/* Setup Genesis mode */
	reg.Action = CS_WRITE;
	reg.Value = hcr;
	reg.Offset = CISREG_CCSR;
461
	res = pcmcia_access_configuration_register(hw_priv->link,
462
						   &reg);
D
Dominik Brodowski 已提交
463
	if (res != 0) {
J
Jouni Malinen 已提交
464 465 466 467 468 469 470 471 472
		printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 "
		       "(%d)\n", res);
		return;
	}
	mdelay(10);

	reg.Action = CS_WRITE;
	reg.Offset = CISREG_COR;
	reg.Value = old_cor & ~COR_SOFT_RESET;
473
	res = pcmcia_access_configuration_register(hw_priv->link,
474
						   &reg);
D
Dominik Brodowski 已提交
475
	if (res != 0) {
J
Jouni Malinen 已提交
476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495
		printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 "
		       "(%d)\n", res);
		return;
	}

	mdelay(10);
}


static struct prism2_helper_functions prism2_pccard_funcs =
{
	.card_present	= prism2_pccard_card_present,
	.cor_sreset	= prism2_pccard_cor_sreset,
	.genesis_reset	= prism2_pccard_genesis_reset,
	.hw_type	= HOSTAP_HW_PCCARD,
};


/* allocate local data and register with CardServices
 * initialize dev_link structure, but do not configure the card yet */
496
static int hostap_cs_probe(struct pcmcia_device *p_dev)
J
Jouni Malinen 已提交
497
{
498 499
	int ret;

J
Jouni Malinen 已提交
500
	PDEBUG(DEBUG_HW, "%s: setting Vcc=33 (constant)\n", dev_info);
501
	p_dev->conf.IntType = INT_MEMORY_AND_IO;
502

503 504
	ret = prism2_config(p_dev);
	if (ret) {
505
		PDEBUG(DEBUG_EXTRA, "prism2_config() failed\n");
506
	}
507

508
	return ret;
J
Jouni Malinen 已提交
509 510 511
}


512
static void prism2_detach(struct pcmcia_device *link)
J
Jouni Malinen 已提交
513 514 515
{
	PDEBUG(DEBUG_FLOW, "prism2_detach\n");

516
	prism2_release((u_long)link);
J
Jouni Malinen 已提交
517 518 519

	/* release net devices */
	if (link->priv) {
520
		struct hostap_cs_priv *hw_priv;
521 522 523 524
		struct net_device *dev;
		struct hostap_interface *iface;
		dev = link->priv;
		iface = netdev_priv(dev);
525
		hw_priv = iface->local->hw_priv;
526
		prism2_free_local_data(dev);
527
		kfree(hw_priv);
J
Jouni Malinen 已提交
528 529 530 531 532 533 534 535 536 537
	}
}


#define CS_CHECK(fn, ret) \
do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)


/* run after a CARD_INSERTION event is received to configure the PCMCIA
 * socket and make the device available to the system */
538 539 540

static int prism2_config_check(struct pcmcia_device *p_dev,
			       cistpl_cftable_entry_t *cfg,
541
			       cistpl_cftable_entry_t *dflt,
542
			       unsigned int vcc,
543 544 545 546 547 548
			       void *priv_data)
{
	if (cfg->index == 0)
		return -ENODEV;

	PDEBUG(DEBUG_EXTRA, "Checking CFTABLE_ENTRY 0x%02X "
549
	       "(default 0x%02X)\n", cfg->index, dflt->index);
550 551 552 553 554 555 556 557 558 559

	/* Does this card need audio output? */
	if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
		p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
		p_dev->conf.Status = CCSR_AUDIO_ENA;
	}

	/* Use power settings for Vcc and Vpp if present */
	/*  Note that the CIS values need to be rescaled */
	if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
560
		if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] /
561 562 563 564 565
		    10000 && !ignore_cis_vcc) {
			PDEBUG(DEBUG_EXTRA, "  Vcc mismatch - skipping"
			       " this entry\n");
			return -ENODEV;
		}
566
	} else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
567
		if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] /
568 569 570 571 572 573 574 575 576
		    10000 && !ignore_cis_vcc) {
			PDEBUG(DEBUG_EXTRA, "  Vcc (default) mismatch "
			       "- skipping this entry\n");
			return -ENODEV;
		}
	}

	if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
		p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
577 578
	else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
		p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
579 580

	/* Do we need to allocate an interrupt? */
581
	if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
582 583 584 585 586 587 588 589 590 591 592
		p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
	else if (!(p_dev->conf.Attributes & CONF_ENABLE_IRQ)) {
		/* At least Compaq WL200 does not have IRQInfo1 set,
		 * but it does not work without interrupts.. */
		printk(KERN_WARNING "Config has no IRQ info, but trying to "
		       "enable IRQ anyway..\n");
		p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
	}

	/* IO window settings */
	PDEBUG(DEBUG_EXTRA, "IO window settings: cfg->io.nwin=%d "
593 594
	       "dflt->io.nwin=%d\n",
	       cfg->io.nwin, dflt->io.nwin);
595
	p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
596 597
	if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
		cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620
		p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
		PDEBUG(DEBUG_EXTRA, "io->flags = 0x%04X, "
		       "io.base=0x%04x, len=%d\n", io->flags,
		       io->win[0].base, io->win[0].len);
		if (!(io->flags & CISTPL_IO_8BIT))
			p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
		if (!(io->flags & CISTPL_IO_16BIT))
			p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
		p_dev->io.IOAddrLines = io->flags &
			CISTPL_IO_LINES_MASK;
		p_dev->io.BasePort1 = io->win[0].base;
		p_dev->io.NumPorts1 = io->win[0].len;
		if (io->nwin > 1) {
			p_dev->io.Attributes2 = p_dev->io.Attributes1;
			p_dev->io.BasePort2 = io->win[1].base;
			p_dev->io.NumPorts2 = io->win[1].len;
		}
	}

	/* This reserves IO space but doesn't actually enable it */
	return pcmcia_request_io(p_dev, &p_dev->io);
}

621
static int prism2_config(struct pcmcia_device *link)
J
Jouni Malinen 已提交
622 623 624 625 626 627
{
	struct net_device *dev;
	struct hostap_interface *iface;
	local_info_t *local;
	int ret = 1;
	int last_fn, last_ret;
628
	struct hostap_cs_priv *hw_priv;
J
Jouni Malinen 已提交
629 630 631

	PDEBUG(DEBUG_FLOW, "prism2_config()\n");

632
	hw_priv = kzalloc(sizeof(*hw_priv), GFP_KERNEL);
633
	if (hw_priv == NULL) {
J
Jouni Malinen 已提交
634 635 636 637 638
		ret = -ENOMEM;
		goto failed;
	}

	/* Look for an appropriate configuration table entry in the CIS */
639
	last_ret = pcmcia_loop_config(link, prism2_config_check, NULL);
640 641 642 643 644 645 646
	if (last_ret) {
		if (!ignore_cis_vcc)
			printk(KERN_ERR "GetNextTuple(): No matching "
			       "CIS configuration.  Maybe you need the "
			       "ignore_cis_vcc=1 parameter.\n");
		cs_error(link, RequestIO, last_ret);
		goto failed;
J
Jouni Malinen 已提交
647 648 649
	}

	/* Need to allocate net_device before requesting IRQ handler */
D
Dave Hansen 已提交
650
	dev = prism2_init_local_data(&prism2_pccard_funcs, 0,
651
				     &handle_to_dev(link));
J
Jouni Malinen 已提交
652 653 654 655
	if (dev == NULL)
		goto failed;
	link->priv = dev;

656 657 658 659 660
	iface = netdev_priv(dev);
	local = iface->local;
	local->hw_priv = hw_priv;
	hw_priv->link = link;
	strcpy(hw_priv->node.dev_name, dev->name);
661
	link->dev_node = &hw_priv->node;
662

J
Jouni Malinen 已提交
663 664 665 666 667 668 669
	/*
	 * Allocate an interrupt line.  Note that this does not assign a
	 * handler to the interrupt, unless the 'Handler' member of the
	 * irq structure is initialized.
	 */
	if (link->conf.Attributes & CONF_ENABLE_IRQ) {
		link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
J
Jar 已提交
670
		link->irq.IRQInfo1 = IRQ_LEVEL_ID;
J
Jouni Malinen 已提交
671 672 673
		link->irq.Handler = prism2_interrupt;
		link->irq.Instance = dev;
		CS_CHECK(RequestIRQ,
674
			 pcmcia_request_irq(link, &link->irq));
J
Jouni Malinen 已提交
675 676 677 678 679 680 681 682
	}

	/*
	 * This actually configures the PCMCIA socket -- setting up
	 * the I/O windows and the interrupt mapping, and putting the
	 * card and host interface into "Memory and IO" mode.
	 */
	CS_CHECK(RequestConfiguration,
683
		 pcmcia_request_configuration(link, &link->conf));
J
Jouni Malinen 已提交
684 685 686 687 688

	dev->irq = link->irq.AssignedIRQ;
	dev->base_addr = link->io.BasePort1;

	/* Finally, report what we've done */
689 690 691 692 693
	printk(KERN_INFO "%s: index 0x%02x: ",
	       dev_info, link->conf.ConfigIndex);
	if (link->conf.Vpp)
		printk(", Vpp %d.%d", link->conf.Vpp / 10,
		       link->conf.Vpp % 10);
J
Jouni Malinen 已提交
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711
	if (link->conf.Attributes & CONF_ENABLE_IRQ)
		printk(", irq %d", link->irq.AssignedIRQ);
	if (link->io.NumPorts1)
		printk(", io 0x%04x-0x%04x", link->io.BasePort1,
		       link->io.BasePort1+link->io.NumPorts1-1);
	if (link->io.NumPorts2)
		printk(" & 0x%04x-0x%04x", link->io.BasePort2,
		       link->io.BasePort2+link->io.NumPorts2-1);
	printk("\n");

	local->shutdown = 0;

	sandisk_enable_wireless(dev);

	ret = prism2_hw_config(dev, 1);
	if (!ret) {
		ret = hostap_hw_ready(dev);
		if (ret == 0 && local->ddev)
712
			strcpy(hw_priv->node.dev_name, local->ddev->name);
J
Jouni Malinen 已提交
713 714 715 716
	}
	return ret;

 cs_failed:
717
	cs_error(link, last_fn, last_ret);
J
Jouni Malinen 已提交
718 719

 failed:
720
	kfree(hw_priv);
J
Jouni Malinen 已提交
721 722 723 724 725 726 727
	prism2_release((u_long)link);
	return ret;
}


static void prism2_release(u_long arg)
{
728
	struct pcmcia_device *link = (struct pcmcia_device *)arg;
J
Jouni Malinen 已提交
729 730 731 732 733 734 735 736

	PDEBUG(DEBUG_FLOW, "prism2_release\n");

	if (link->priv) {
		struct net_device *dev = link->priv;
		struct hostap_interface *iface;

		iface = netdev_priv(dev);
737
		prism2_hw_shutdown(dev, 0);
J
Jouni Malinen 已提交
738 739 740
		iface->local->shutdown = 1;
	}

741
	pcmcia_disable_device(link);
J
Jouni Malinen 已提交
742 743 744
	PDEBUG(DEBUG_FLOW, "release - done\n");
}

745
static int hostap_cs_suspend(struct pcmcia_device *link)
746 747 748
{
	struct net_device *dev = (struct net_device *) link->priv;
	int dev_open = 0;
749
	struct hostap_interface *iface = NULL;
J
Jouni Malinen 已提交
750

751 752 753 754
	if (!dev)
		return -ENODEV;

	iface = netdev_priv(dev);
755

756 757 758 759 760 761
	PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_SUSPEND\n", dev_info);
	if (iface && iface->local)
		dev_open = iface->local->num_dev_open > 0;
	if (dev_open) {
		netif_stop_queue(dev);
		netif_device_detach(dev);
762
	}
763
	prism2_suspend(dev);
764 765 766 767

	return 0;
}

768
static int hostap_cs_resume(struct pcmcia_device *link)
J
Jouni Malinen 已提交
769 770
{
	struct net_device *dev = (struct net_device *) link->priv;
771
	int dev_open = 0;
772 773
	struct hostap_interface *iface = NULL;

774 775 776 777
	if (!dev)
		return -ENODEV;

	iface = netdev_priv(dev);
778

779 780
	PDEBUG(DEBUG_EXTRA, "%s: CS_EVENT_PM_RESUME\n", dev_info);

781 782
	if (iface && iface->local)
		dev_open = iface->local->num_dev_open > 0;
783

784 785 786 787 788
	prism2_hw_shutdown(dev, 1);
	prism2_hw_config(dev, dev_open ? 0 : 1);
	if (dev_open) {
		netif_device_attach(dev);
		netif_start_queue(dev);
789
	}
J
Jouni Malinen 已提交
790

791 792 793
	return 0;
}

H
Henrik Brix Andersen 已提交
794 795 796 797 798 799
static struct pcmcia_device_id hostap_cs_ids[] = {
	PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7100),
	PCMCIA_DEVICE_MANF_CARD(0x000b, 0x7300),
	PCMCIA_DEVICE_MANF_CARD(0x0101, 0x0777),
	PCMCIA_DEVICE_MANF_CARD(0x0126, 0x8000),
	PCMCIA_DEVICE_MANF_CARD(0x0138, 0x0002),
800
	PCMCIA_DEVICE_MANF_CARD(0x01bf, 0x3301),
H
Henrik Brix Andersen 已提交
801
	PCMCIA_DEVICE_MANF_CARD(0x0250, 0x0002),
R
Richard Purdie 已提交
802
	PCMCIA_DEVICE_MANF_CARD(0x026f, 0x030b),
H
Henrik Brix Andersen 已提交
803 804 805 806 807 808 809
	PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1612),
	PCMCIA_DEVICE_MANF_CARD(0x0274, 0x1613),
	PCMCIA_DEVICE_MANF_CARD(0x028a, 0x0002),
	PCMCIA_DEVICE_MANF_CARD(0x02aa, 0x0002),
	PCMCIA_DEVICE_MANF_CARD(0x02d2, 0x0001),
	PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x0001),
	PCMCIA_DEVICE_MANF_CARD(0x50c2, 0x7300),
810
/*	PCMCIA_DEVICE_MANF_CARD(0xc00f, 0x0000),    conflict with pcnet_cs */
811
	PCMCIA_DEVICE_MANF_CARD(0xc250, 0x0002),
H
Henrik Brix Andersen 已提交
812 813 814
	PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0002),
	PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0005),
	PCMCIA_DEVICE_MANF_CARD(0xd601, 0x0010),
815
	PCMCIA_DEVICE_MANF_CARD(0x0126, 0x0002),
816 817
	PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0xd601, 0x0005, "ADLINK 345 CF",
					 0x2d858104),
818 819 820 821
	PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0x0156, 0x0002, "INTERSIL",
					 0x74c5e40d),
	PCMCIA_DEVICE_MANF_CARD_PROD_ID1(0x0156, 0x0002, "Intersil",
					 0x4b801a17),
H
Henrik Brix Andersen 已提交
822 823
	PCMCIA_MFC_DEVICE_PROD_ID12(0, "SanDisk", "ConnectPlus",
				    0x7a954bd9, 0x74be00c6),
824
	PCMCIA_DEVICE_PROD_ID123(
H
Henrik Brix Andersen 已提交
825
		"Intersil", "PRISM 2_5 PCMCIA ADAPTER",	"ISL37300P",
826
		0x4b801a17, 0x6345a0bf, 0xc9049a39),
827
	/* D-Link DWL-650 Rev. P1; manfid 0x000b, 0x7110 */
828
	PCMCIA_DEVICE_PROD_ID123(
829
		"D-Link", "DWL-650 Wireless PC Card RevP", "ISL37101P-10",
830
		0x1a424a1c, 0x6ea57632, 0xdd97a26b),
H
Henrik Brix Andersen 已提交
831 832 833 834 835 836 837 838 839 840 841 842
	PCMCIA_DEVICE_PROD_ID123(
		"Addtron", "AWP-100 Wireless PCMCIA", "Version 01.02",
		0xe6ec52ce, 0x08649af2, 0x4b74baa0),
	PCMCIA_DEVICE_PROD_ID123(
		"D", "Link DWL-650 11Mbps WLAN Card", "Version 01.02",
		0x71b18589, 0xb6f1b0ab, 0x4b74baa0),
	PCMCIA_DEVICE_PROD_ID123(
		"Instant Wireless ", " Network PC CARD", "Version 01.02",
		0x11d901af, 0x6e9bd926, 0x4b74baa0),
	PCMCIA_DEVICE_PROD_ID123(
		"SMC", "SMC2632W", "Version 01.02",
		0xc4f8b18b, 0x474a1f2a, 0x4b74baa0),
R
Richard Purdie 已提交
843
	PCMCIA_DEVICE_PROD_ID12("BUFFALO", "WLI-CF-S11G", 
844
				0x2decece3, 0x82067c18),
H
Henrik Brix Andersen 已提交
845 846 847 848 849 850 851 852 853
	PCMCIA_DEVICE_PROD_ID12("Compaq", "WL200_11Mbps_Wireless_PCI_Card",
				0x54f7c49c, 0x15a75e5b),
	PCMCIA_DEVICE_PROD_ID12("INTERSIL", "HFA384x/IEEE",
				0x74c5e40d, 0xdb472a18),
	PCMCIA_DEVICE_PROD_ID12("Linksys", "Wireless CompactFlash Card",
				0x0733cc81, 0x0c52f395),
	PCMCIA_DEVICE_PROD_ID12(
		"ZoomAir 11Mbps High", "Rate wireless Networking",
		0x273fe3db, 0x32a1eaee),
854 855 856 857 858 859
	PCMCIA_DEVICE_PROD_ID123(
		"Pretec", "CompactWLAN Card 802.11b", "2.5",
		0x1cadd3e5, 0xe697636c, 0x7a5bfcf1),
	PCMCIA_DEVICE_PROD_ID123(
		"U.S. Robotics", "IEEE 802.11b PC-CARD", "Version 01.02",
		0xc7b8df9d, 0x1700d087, 0x4b74baa0),
860 861 862 863 864 865 866
	PCMCIA_DEVICE_PROD_ID123(
		"Allied Telesyn", "AT-WCL452 Wireless PCMCIA Radio",
		"Ver. 1.00",
		0x5cd01705, 0x4271660f, 0x9d08ee12),
	PCMCIA_DEVICE_PROD_ID123(
		"corega", "WL PCCL-11", "ISL37300P",
		0xa21501a, 0x59868926, 0xc9049a39),
867
	PCMCIA_DEVICE_PROD_ID123(
868
		"The Linksys Group, Inc.", "Wireless Network CF Card", "ISL37300P",
869
		0xa5f472c2, 0x9c05598d, 0xc9049a39),
870 871 872
	PCMCIA_DEVICE_PROD_ID123(
		"Wireless LAN" , "11Mbps PC Card", "Version 01.02",
		0x4b8870ff, 0x70e946d1, 0x4b74baa0),
H
Henrik Brix Andersen 已提交
873 874 875 876 877
	PCMCIA_DEVICE_NULL
};
MODULE_DEVICE_TABLE(pcmcia, hostap_cs_ids);


J
Jouni Malinen 已提交
878 879 880 881
static struct pcmcia_driver hostap_driver = {
	.drv		= {
		.name	= "hostap_cs",
	},
882
	.probe		= hostap_cs_probe,
883
	.remove		= prism2_detach,
J
Jouni Malinen 已提交
884
	.owner		= THIS_MODULE,
H
Henrik Brix Andersen 已提交
885
	.id_table	= hostap_cs_ids,
886 887
	.suspend	= hostap_cs_suspend,
	.resume		= hostap_cs_resume,
J
Jouni Malinen 已提交
888 889 890 891 892 893 894 895 896 897 898 899 900 901 902
};

static int __init init_prism2_pccard(void)
{
	return pcmcia_register_driver(&hostap_driver);
}

static void __exit exit_prism2_pccard(void)
{
	pcmcia_unregister_driver(&hostap_driver);
}


module_init(init_prism2_pccard);
module_exit(exit_prism2_pccard);