1/*
2 *	WaveLAN ISA driver
3 *
4 *		Jean II - HPLB '96
5 *
6 * Reorganisation and extension of the driver.
7 * Original copyright follows (also see the end of this file).
8 * See wavelan.p.h for details.
9 *
10 *
11 *
12 * AT&T GIS (nee NCR) WaveLAN card:
13 *	An Ethernet-like radio transceiver
14 *	controlled by an Intel 82586 coprocessor.
15 */
16
17#include "wavelan.p.h"		/* Private header */
18
19/************************* MISC SUBROUTINES **************************/
20/*
21 * Subroutines which won't fit in one of the following category
22 * (WaveLAN modem or i82586)
23 */
24
25/*------------------------------------------------------------------*/
26/*
27 * Wrapper for disabling interrupts and locking the driver.
28 * (note : inline, so optimised away)
29 */
30static inline void wv_splhi(net_local *		lp,
31			    unsigned long *	pflags)
32{
33	spin_lock_irqsave(&lp->spinlock, *pflags);
34	/* Note : above does the cli(); itself */
35}
36
37/*------------------------------------------------------------------*/
38/*
39 * Wrapper for re-enabling interrupts and un-locking the driver.
40 */
41static inline void wv_splx(net_local *		lp,
42			   unsigned long *	pflags)
43{
44	spin_unlock_irqrestore(&lp->spinlock, *pflags);
45}
46
47/*------------------------------------------------------------------*/
48/*
49 * Translate irq number to PSA irq parameter
50 */
51static u8 wv_irq_to_psa(int irq)
52{
53	if (irq < 0 || irq >= NELS(irqvals))
54		return 0;
55
56	return irqvals[irq];
57}
58
59/*------------------------------------------------------------------*/
60/*
61 * Translate PSA irq parameter to irq number
62 */
63static int __init wv_psa_to_irq(u8 irqval)
64{
65	int irq;
66
67	for (irq = 0; irq < NELS(irqvals); irq++)
68		if (irqvals[irq] == irqval)
69			return irq;
70
71	return -1;
72}
73
74#ifdef STRUCT_CHECK
75/*------------------------------------------------------------------*/
76/*
77 * Sanity routine to verify the sizes of the various WaveLAN interface
78 * structures.
79 */
80static char *wv_struct_check(void)
81{
82#define	SC(t,s,n)	if (sizeof(t) != s) return(n);
83
84	SC(psa_t, PSA_SIZE, "psa_t");
85	SC(mmw_t, MMW_SIZE, "mmw_t");
86	SC(mmr_t, MMR_SIZE, "mmr_t");
87	SC(ha_t, HA_SIZE, "ha_t");
88
89#undef	SC
90
91	return ((char *) NULL);
92}				/* wv_struct_check */
93#endif				/* STRUCT_CHECK */
94
95/********************* HOST ADAPTER SUBROUTINES *********************/
96/*
97 * Useful subroutines to manage the WaveLAN ISA interface
98 *
99 * One major difference with the PCMCIA hardware (except the port mapping)
100 * is that we have to keep the state of the Host Control Register
101 * because of the interrupt enable & bus size flags.
102 */
103
104/*------------------------------------------------------------------*/
105/*
106 * Read from card's Host Adaptor Status Register.
107 */
108static inline u16 hasr_read(unsigned long ioaddr)
109{
110	return (inw(HASR(ioaddr)));
111}				/* hasr_read */
112
113/*------------------------------------------------------------------*/
114/*
115 * Write to card's Host Adapter Command Register.
116 */
117static inline void hacr_write(unsigned long ioaddr, u16 hacr)
118{
119	outw(hacr, HACR(ioaddr));
120}				/* hacr_write */
121
122/*------------------------------------------------------------------*/
123/*
124 * Write to card's Host Adapter Command Register. Include a delay for
125 * those times when it is needed.
126 */
127static inline void hacr_write_slow(unsigned long ioaddr, u16 hacr)
128{
129	hacr_write(ioaddr, hacr);
130	/* delay might only be needed sometimes */
131	mdelay(1);
132}				/* hacr_write_slow */
133
134/*------------------------------------------------------------------*/
135/*
136 * Set the channel attention bit.
137 */
138static inline void set_chan_attn(unsigned long ioaddr, u16 hacr)
139{
140	hacr_write(ioaddr, hacr | HACR_CA);
141}				/* set_chan_attn */
142
143/*------------------------------------------------------------------*/
144/*
145 * Reset, and then set host adaptor into default mode.
146 */
147static inline void wv_hacr_reset(unsigned long ioaddr)
148{
149	hacr_write_slow(ioaddr, HACR_RESET);
150	hacr_write(ioaddr, HACR_DEFAULT);
151}				/* wv_hacr_reset */
152
153/*------------------------------------------------------------------*/
154/*
155 * Set the I/O transfer over the ISA bus to 8-bit mode
156 */
157static inline void wv_16_off(unsigned long ioaddr, u16 hacr)
158{
159	hacr &= ~HACR_16BITS;
160	hacr_write(ioaddr, hacr);
161}				/* wv_16_off */
162
163/*------------------------------------------------------------------*/
164/*
165 * Set the I/O transfer over the ISA bus to 8-bit mode
166 */
167static inline void wv_16_on(unsigned long ioaddr, u16 hacr)
168{
169	hacr |= HACR_16BITS;
170	hacr_write(ioaddr, hacr);
171}				/* wv_16_on */
172
173/*------------------------------------------------------------------*/
174/*
175 * Disable interrupts on the WaveLAN hardware.
176 * (called by wv_82586_stop())
177 */
178static inline void wv_ints_off(device * dev)
179{
180	net_local *lp = (net_local *) dev->priv;
181	unsigned long ioaddr = dev->base_addr;
182
183	lp->hacr &= ~HACR_INTRON;
184	hacr_write(ioaddr, lp->hacr);
185}				/* wv_ints_off */
186
187/*------------------------------------------------------------------*/
188/*
189 * Enable interrupts on the WaveLAN hardware.
190 * (called by wv_hw_reset())
191 */
192static inline void wv_ints_on(device * dev)
193{
194	net_local *lp = (net_local *) dev->priv;
195	unsigned long ioaddr = dev->base_addr;
196
197	lp->hacr |= HACR_INTRON;
198	hacr_write(ioaddr, lp->hacr);
199}				/* wv_ints_on */
200
201/******************* MODEM MANAGEMENT SUBROUTINES *******************/
202/*
203 * Useful subroutines to manage the modem of the WaveLAN
204 */
205
206/*------------------------------------------------------------------*/
207/*
208 * Read the Parameter Storage Area from the WaveLAN card's memory
209 */
210/*
211 * Read bytes from the PSA.
212 */
213static void psa_read(unsigned long ioaddr, u16 hacr, int o,	/* offset in PSA */
214		     u8 * b,	/* buffer to fill */
215		     int n)
216{				/* size to read */
217	wv_16_off(ioaddr, hacr);
218
219	while (n-- > 0) {
220		outw(o, PIOR2(ioaddr));
221		o++;
222		*b++ = inb(PIOP2(ioaddr));
223	}
224
225	wv_16_on(ioaddr, hacr);
226}				/* psa_read */
227
228/*------------------------------------------------------------------*/
229/*
230 * Write the Parameter Storage Area to the WaveLAN card's memory.
231 */
232static void psa_write(unsigned long ioaddr, u16 hacr, int o,	/* Offset in PSA */
233		      u8 * b,	/* Buffer in memory */
234		      int n)
235{				/* Length of buffer */
236	int count = 0;
237
238	wv_16_off(ioaddr, hacr);
239
240	while (n-- > 0) {
241		outw(o, PIOR2(ioaddr));
242		o++;
243
244		outb(*b, PIOP2(ioaddr));
245		b++;
246
247		/* Wait for the memory to finish its write cycle */
248		count = 0;
249		while ((count++ < 100) &&
250		       (hasr_read(ioaddr) & HASR_PSA_BUSY)) mdelay(1);
251	}
252
253	wv_16_on(ioaddr, hacr);
254}				/* psa_write */
255
256#ifdef SET_PSA_CRC
257/*------------------------------------------------------------------*/
258/*
259 * Calculate the PSA CRC
260 * Thanks to Valster, Nico <NVALSTER@wcnd.nl.lucent.com> for the code
261 * NOTE: By specifying a length including the CRC position the
262 * returned value should be zero. (i.e. a correct checksum in the PSA)
263 *
264 * The Windows drivers don't use the CRC, but the AP and the PtP tool
265 * depend on it.
266 */
267static inline u16 psa_crc(u8 * psa,	/* The PSA */
268			      int size)
269{				/* Number of short for CRC */
270	int byte_cnt;		/* Loop on the PSA */
271	u16 crc_bytes = 0;	/* Data in the PSA */
272	int bit_cnt;		/* Loop on the bits of the short */
273
274	for (byte_cnt = 0; byte_cnt < size; byte_cnt++) {
275		crc_bytes ^= psa[byte_cnt];	/* Its an xor */
276
277		for (bit_cnt = 1; bit_cnt < 9; bit_cnt++) {
278			if (crc_bytes & 0x0001)
279				crc_bytes = (crc_bytes >> 1) ^ 0xA001;
280			else
281				crc_bytes >>= 1;
282		}
283	}
284
285	return crc_bytes;
286}				/* psa_crc */
287#endif				/* SET_PSA_CRC */
288
289/*------------------------------------------------------------------*/
290/*
291 * update the checksum field in the Wavelan's PSA
292 */
293static void update_psa_checksum(device * dev, unsigned long ioaddr, u16 hacr)
294{
295#ifdef SET_PSA_CRC
296	psa_t psa;
297	u16 crc;
298
299	/* read the parameter storage area */
300	psa_read(ioaddr, hacr, 0, (unsigned char *) &psa, sizeof(psa));
301
302	/* update the checksum */
303	crc = psa_crc((unsigned char *) &psa,
304		      sizeof(psa) - sizeof(psa.psa_crc[0]) -
305		      sizeof(psa.psa_crc[1])
306		      - sizeof(psa.psa_crc_status));
307
308	psa.psa_crc[0] = crc & 0xFF;
309	psa.psa_crc[1] = (crc & 0xFF00) >> 8;
310
311	/* Write it ! */
312	psa_write(ioaddr, hacr, (char *) &psa.psa_crc - (char *) &psa,
313		  (unsigned char *) &psa.psa_crc, 2);
314
315#ifdef DEBUG_IOCTL_INFO
316	printk(KERN_DEBUG "%s: update_psa_checksum(): crc = 0x%02x%02x\n",
317	       dev->name, psa.psa_crc[0], psa.psa_crc[1]);
318
319	/* Check again (luxury !) */
320	crc = psa_crc((unsigned char *) &psa,
321		      sizeof(psa) - sizeof(psa.psa_crc_status));
322
323	if (crc != 0)
324		printk(KERN_WARNING
325		       "%s: update_psa_checksum(): CRC does not agree with PSA data (even after recalculating)\n",
326		       dev->name);
327#endif				/* DEBUG_IOCTL_INFO */
328#endif				/* SET_PSA_CRC */
329}				/* update_psa_checksum */
330
331/*------------------------------------------------------------------*/
332/*
333 * Write 1 byte to the MMC.
334 */
335static inline void mmc_out(unsigned long ioaddr, u16 o, u8 d)
336{
337	/* Wait for MMC to go idle */
338	while (inw(HASR(ioaddr)) & HASR_MMC_BUSY);
339
340	outw((u16) (((u16) d << 8) | (o << 1) | 1), MMCR(ioaddr));
341}
342
343/*------------------------------------------------------------------*/
344/*
345 * Routine to write bytes to the Modem Management Controller.
346 * We start at the end because it is the way it should be!
347 */
348static inline void mmc_write(unsigned long ioaddr, u8 o, u8 * b, int n)
349{
350	o += n;
351	b += n;
352
353	while (n-- > 0)
354		mmc_out(ioaddr, --o, *(--b));
355}				/* mmc_write */
356
357/*------------------------------------------------------------------*/
358/*
359 * Read a byte from the MMC.
360 * Optimised version for 1 byte, avoid using memory.
361 */
362static inline u8 mmc_in(unsigned long ioaddr, u16 o)
363{
364	while (inw(HASR(ioaddr)) & HASR_MMC_BUSY);
365	outw(o << 1, MMCR(ioaddr));
366
367	while (inw(HASR(ioaddr)) & HASR_MMC_BUSY);
368	return (u8) (inw(MMCR(ioaddr)) >> 8);
369}
370
371/*------------------------------------------------------------------*/
372/*
373 * Routine to read bytes from the Modem Management Controller.
374 * The implementation is complicated by a lack of address lines,
375 * which prevents decoding of the low-order bit.
376 * (code has just been moved in the above function)
377 * We start at the end because it is the way it should be!
378 */
379static inline void mmc_read(unsigned long ioaddr, u8 o, u8 * b, int n)
380{
381	o += n;
382	b += n;
383
384	while (n-- > 0)
385		*(--b) = mmc_in(ioaddr, --o);
386}				/* mmc_read */
387
388/*------------------------------------------------------------------*/
389/*
390 * Get the type of encryption available.
391 */
392static inline int mmc_encr(unsigned long ioaddr)
393{				/* I/O port of the card */
394	int temp;
395
396	temp = mmc_in(ioaddr, mmroff(0, mmr_des_avail));
397	if ((temp != MMR_DES_AVAIL_DES) && (temp != MMR_DES_AVAIL_AES))
398		return 0;
399	else
400		return temp;
401}
402
403/*------------------------------------------------------------------*/
404/*
405 * Wait for the frequency EEPROM to complete a command.
406 * I hope this one will be optimally inlined.
407 */
408static inline void fee_wait(unsigned long ioaddr,	/* I/O port of the card */
409			    int delay,	/* Base delay to wait for */
410			    int number)
411{				/* Number of time to wait */
412	int count = 0;		/* Wait only a limited time */
413
414	while ((count++ < number) &&
415	       (mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
416		MMR_FEE_STATUS_BUSY)) udelay(delay);
417}
418
419/*------------------------------------------------------------------*/
420/*
421 * Read bytes from the Frequency EEPROM (frequency select cards).
422 */
423static void fee_read(unsigned long ioaddr,	/* I/O port of the card */
424		     u16 o,	/* destination offset */
425		     u16 * b,	/* data buffer */
426		     int n)
427{				/* number of registers */
428	b += n;			/* Position at the end of the area */
429
430	/* Write the address */
431	mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n - 1);
432
433	/* Loop on all buffer */
434	while (n-- > 0) {
435		/* Write the read command */
436		mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
437			MMW_FEE_CTRL_READ);
438
439		/* Wait until EEPROM is ready (should be quick). */
440		fee_wait(ioaddr, 10, 100);
441
442		/* Read the value. */
443		*--b = ((mmc_in(ioaddr, mmroff(0, mmr_fee_data_h)) << 8) |
444			mmc_in(ioaddr, mmroff(0, mmr_fee_data_l)));
445	}
446}
447
448#ifdef WIRELESS_EXT		    /* if the wireless extension exists in the kernel */
449
450/*------------------------------------------------------------------*/
451/*
452 * Write bytes from the Frequency EEPROM (frequency select cards).
453 * This is a bit complicated, because the frequency EEPROM has to
454 * be unprotected and the write enabled.
455 * Jean II
456 */
457static void fee_write(unsigned long ioaddr,	/* I/O port of the card */
458		      u16 o,	/* destination offset */
459		      u16 * b,	/* data buffer */
460		      int n)
461{				/* number of registers */
462	b += n;			/* Position at the end of the area. */
463
464#ifdef EEPROM_IS_PROTECTED	    /* disabled */
465#ifdef DOESNT_SEEM_TO_WORK	    /* disabled */
466	/* Ask to read the protected register */
467	mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRREAD);
468
469	fee_wait(ioaddr, 10, 100);
470
471	/* Read the protected register. */
472	printk("Protected 2:  %02X-%02X\n",
473	       mmc_in(ioaddr, mmroff(0, mmr_fee_data_h)),
474	       mmc_in(ioaddr, mmroff(0, mmr_fee_data_l)));
475#endif				/* DOESNT_SEEM_TO_WORK */
476
477	/* Enable protected register. */
478	mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
479	mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PREN);
480
481	fee_wait(ioaddr, 10, 100);
482
483	/* Unprotect area. */
484	mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n);
485	mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
486#ifdef DOESNT_SEEM_TO_WORK	    /* disabled */
487	/* or use: */
488	mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRCLEAR);
489#endif				/* DOESNT_SEEM_TO_WORK */
490
491	fee_wait(ioaddr, 10, 100);
492#endif				/* EEPROM_IS_PROTECTED */
493
494	/* Write enable. */
495	mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_EN);
496	mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WREN);
497
498	fee_wait(ioaddr, 10, 100);
499
500	/* Write the EEPROM address. */
501	mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), o + n - 1);
502
503	/* Loop on all buffer */
504	while (n-- > 0) {
505		/* Write the value. */
506		mmc_out(ioaddr, mmwoff(0, mmw_fee_data_h), (*--b) >> 8);
507		mmc_out(ioaddr, mmwoff(0, mmw_fee_data_l), *b & 0xFF);
508
509		/* Write the write command. */
510		mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
511			MMW_FEE_CTRL_WRITE);
512
513		/* WaveLAN documentation says to wait at least 10 ms for EEBUSY = 0 */
514		mdelay(10);
515		fee_wait(ioaddr, 10, 100);
516	}
517
518	/* Write disable. */
519	mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), MMW_FEE_ADDR_DS);
520	mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_WDS);
521
522	fee_wait(ioaddr, 10, 100);
523
524#ifdef EEPROM_IS_PROTECTED	    /* disabled */
525	/* Reprotect EEPROM. */
526	mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x00);
527	mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl), MMW_FEE_CTRL_PRWRITE);
528
529	fee_wait(ioaddr, 10, 100);
530#endif				/* EEPROM_IS_PROTECTED */
531}
532#endif				/* WIRELESS_EXT */
533
534/************************ I82586 SUBROUTINES *************************/
535/*
536 * Useful subroutines to manage the Ethernet controller
537 */
538
539/*------------------------------------------------------------------*/
540/*
541 * Read bytes from the on-board RAM.
542 * Why does inlining this function make it fail?
543 */
544static /*inline */ void obram_read(unsigned long ioaddr,
545				   u16 o, u8 * b, int n)
546{
547	outw(o, PIOR1(ioaddr));
548	insw(PIOP1(ioaddr), (unsigned short *) b, (n + 1) >> 1);
549}
550
551/*------------------------------------------------------------------*/
552/*
553 * Write bytes to the on-board RAM.
554 */
555static inline void obram_write(unsigned long ioaddr, u16 o, u8 * b, int n)
556{
557	outw(o, PIOR1(ioaddr));
558	outsw(PIOP1(ioaddr), (unsigned short *) b, (n + 1) >> 1);
559}
560
561/*------------------------------------------------------------------*/
562/*
563 * Acknowledge the reading of the status issued by the i82586.
564 */
565static void wv_ack(device * dev)
566{
567	net_local *lp = (net_local *) dev->priv;
568	unsigned long ioaddr = dev->base_addr;
569	u16 scb_cs;
570	int i;
571
572	obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
573		   (unsigned char *) &scb_cs, sizeof(scb_cs));
574	scb_cs &= SCB_ST_INT;
575
576	if (scb_cs == 0)
577		return;
578
579	obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
580		    (unsigned char *) &scb_cs, sizeof(scb_cs));
581
582	set_chan_attn(ioaddr, lp->hacr);
583
584	for (i = 1000; i > 0; i--) {
585		obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
586			   (unsigned char *) &scb_cs, sizeof(scb_cs));
587		if (scb_cs == 0)
588			break;
589
590		udelay(10);
591	}
592	udelay(100);
593
594#ifdef DEBUG_CONFIG_ERROR
595	if (i <= 0)
596		printk(KERN_INFO
597		       "%s: wv_ack(): board not accepting command.\n",
598		       dev->name);
599#endif
600}
601
602/*------------------------------------------------------------------*/
603/*
604 * Set channel attention bit and busy wait until command has
605 * completed, then acknowledge completion of the command.
606 */
607static inline int wv_synchronous_cmd(device * dev, const char *str)
608{
609	net_local *lp = (net_local *) dev->priv;
610	unsigned long ioaddr = dev->base_addr;
611	u16 scb_cmd;
612	ach_t cb;
613	int i;
614
615	scb_cmd = SCB_CMD_CUC & SCB_CMD_CUC_GO;
616	obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
617		    (unsigned char *) &scb_cmd, sizeof(scb_cmd));
618
619	set_chan_attn(ioaddr, lp->hacr);
620
621	for (i = 1000; i > 0; i--) {
622		obram_read(ioaddr, OFFSET_CU, (unsigned char *) &cb,
623			   sizeof(cb));
624		if (cb.ac_status & AC_SFLD_C)
625			break;
626
627		udelay(10);
628	}
629	udelay(100);
630
631	if (i <= 0 || !(cb.ac_status & AC_SFLD_OK)) {
632#ifdef DEBUG_CONFIG_ERROR
633		printk(KERN_INFO "%s: %s failed; status = 0x%x\n",
634		       dev->name, str, cb.ac_status);
635#endif
636#ifdef DEBUG_I82586_SHOW
637		wv_scb_show(ioaddr);
638#endif
639		return -1;
640	}
641
642	/* Ack the status */
643	wv_ack(dev);
644
645	return 0;
646}
647
648/*------------------------------------------------------------------*/
649/*
650 * Configuration commands completion interrupt.
651 * Check if done, and if OK.
652 */
653static inline int
654wv_config_complete(device * dev, unsigned long ioaddr, net_local * lp)
655{
656	unsigned short mcs_addr;
657	unsigned short status;
658	int ret;
659
660#ifdef DEBUG_INTERRUPT_TRACE
661	printk(KERN_DEBUG "%s: ->wv_config_complete()\n", dev->name);
662#endif
663
664	mcs_addr = lp->tx_first_in_use + sizeof(ac_tx_t) + sizeof(ac_nop_t)
665	    + sizeof(tbd_t) + sizeof(ac_cfg_t) + sizeof(ac_ias_t);
666
667	/* Read the status of the last command (set mc list). */
668	obram_read(ioaddr, acoff(mcs_addr, ac_status),
669		   (unsigned char *) &status, sizeof(status));
670
671	/* If not completed -> exit */
672	if ((status & AC_SFLD_C) == 0)
673		ret = 0;	/* Not ready to be scrapped */
674	else {
675#ifdef DEBUG_CONFIG_ERROR
676		unsigned short cfg_addr;
677		unsigned short ias_addr;
678
679		/* Check mc_config command */
680		if ((status & AC_SFLD_OK) != AC_SFLD_OK)
681			printk(KERN_INFO
682			       "%s: wv_config_complete(): set_multicast_address failed; status = 0x%x\n",
683			       dev->name, status);
684
685		/* check ia-config command */
686		ias_addr = mcs_addr - sizeof(ac_ias_t);
687		obram_read(ioaddr, acoff(ias_addr, ac_status),
688			   (unsigned char *) &status, sizeof(status));
689		if ((status & AC_SFLD_OK) != AC_SFLD_OK)
690			printk(KERN_INFO
691			       "%s: wv_config_complete(): set_MAC_address failed; status = 0x%x\n",
692			       dev->name, status);
693
694		/* Check config command. */
695		cfg_addr = ias_addr - sizeof(ac_cfg_t);
696		obram_read(ioaddr, acoff(cfg_addr, ac_status),
697			   (unsigned char *) &status, sizeof(status));
698		if ((status & AC_SFLD_OK) != AC_SFLD_OK)
699			printk(KERN_INFO
700			       "%s: wv_config_complete(): configure failed; status = 0x%x\n",
701			       dev->name, status);
702#endif	/* DEBUG_CONFIG_ERROR */
703
704		ret = 1;	/* Ready to be scrapped */
705	}
706
707#ifdef DEBUG_INTERRUPT_TRACE
708	printk(KERN_DEBUG "%s: <-wv_config_complete() - %d\n", dev->name,
709	       ret);
710#endif
711	return ret;
712}
713
714/*------------------------------------------------------------------*/
715/*
716 * Command completion interrupt.
717 * Reclaim as many freed tx buffers as we can.
718 * (called in wavelan_interrupt()).
719 * Note : the spinlock is already grabbed for us.
720 */
721static int wv_complete(device * dev, unsigned long ioaddr, net_local * lp)
722{
723	int nreaped = 0;
724
725#ifdef DEBUG_INTERRUPT_TRACE
726	printk(KERN_DEBUG "%s: ->wv_complete()\n", dev->name);
727#endif
728
729	/* Loop on all the transmit buffers */
730	while (lp->tx_first_in_use != I82586NULL) {
731		unsigned short tx_status;
732
733		/* Read the first transmit buffer */
734		obram_read(ioaddr, acoff(lp->tx_first_in_use, ac_status),
735			   (unsigned char *) &tx_status,
736			   sizeof(tx_status));
737
738		/* If not completed -> exit */
739		if ((tx_status & AC_SFLD_C) == 0)
740			break;
741
742		/* Hack for reconfiguration */
743		if (tx_status == 0xFFFF)
744			if (!wv_config_complete(dev, ioaddr, lp))
745				break;	/* Not completed */
746
747		/* We now remove this buffer */
748		nreaped++;
749		--lp->tx_n_in_use;
750
751/*
752if (lp->tx_n_in_use > 0)
753	printk("%c", "0123456789abcdefghijk"[lp->tx_n_in_use]);
754*/
755
756		/* Was it the last one? */
757		if (lp->tx_n_in_use <= 0)
758			lp->tx_first_in_use = I82586NULL;
759		else {
760			/* Next one in the chain */
761			lp->tx_first_in_use += TXBLOCKZ;
762			if (lp->tx_first_in_use >=
763			    OFFSET_CU +
764			    NTXBLOCKS * TXBLOCKZ) lp->tx_first_in_use -=
765				    NTXBLOCKS * TXBLOCKZ;
766		}
767
768		/* Hack for reconfiguration */
769		if (tx_status == 0xFFFF)
770			continue;
771
772		/* Now, check status of the finished command */
773		if (tx_status & AC_SFLD_OK) {
774			int ncollisions;
775
776			lp->stats.tx_packets++;
777			ncollisions = tx_status & AC_SFLD_MAXCOL;
778			lp->stats.collisions += ncollisions;
779#ifdef DEBUG_TX_INFO
780			if (ncollisions > 0)
781				printk(KERN_DEBUG
782				       "%s: wv_complete(): tx completed after %d collisions.\n",
783				       dev->name, ncollisions);
784#endif
785		} else {
786			lp->stats.tx_errors++;
787			if (tx_status & AC_SFLD_S10) {
788				lp->stats.tx_carrier_errors++;
789#ifdef DEBUG_TX_FAIL
790				printk(KERN_DEBUG
791				       "%s: wv_complete(): tx error: no CS.\n",
792				       dev->name);
793#endif
794			}
795			if (tx_status & AC_SFLD_S9) {
796				lp->stats.tx_carrier_errors++;
797#ifdef DEBUG_TX_FAIL
798				printk(KERN_DEBUG
799				       "%s: wv_complete(): tx error: lost CTS.\n",
800				       dev->name);
801#endif
802			}
803			if (tx_status & AC_SFLD_S8) {
804				lp->stats.tx_fifo_errors++;
805#ifdef DEBUG_TX_FAIL
806				printk(KERN_DEBUG
807				       "%s: wv_complete(): tx error: slow DMA.\n",
808				       dev->name);
809#endif
810			}
811			if (tx_status & AC_SFLD_S6) {
812				lp->stats.tx_heartbeat_errors++;
813#ifdef DEBUG_TX_FAIL
814				printk(KERN_DEBUG
815				       "%s: wv_complete(): tx error: heart beat.\n",
816				       dev->name);
817#endif
818			}
819			if (tx_status & AC_SFLD_S5) {
820				lp->stats.tx_aborted_errors++;
821#ifdef DEBUG_TX_FAIL
822				printk(KERN_DEBUG
823				       "%s: wv_complete(): tx error: too many collisions.\n",
824				       dev->name);
825#endif
826			}
827		}
828
829#ifdef DEBUG_TX_INFO
830		printk(KERN_DEBUG
831		       "%s: wv_complete(): tx completed, tx_status 0x%04x\n",
832		       dev->name, tx_status);
833#endif
834	}
835
836#ifdef DEBUG_INTERRUPT_INFO
837	if (nreaped > 1)
838		printk(KERN_DEBUG "%s: wv_complete(): reaped %d\n",
839		       dev->name, nreaped);
840#endif
841
842	/*
843	 * Inform upper layers.
844	 */
845	if (lp->tx_n_in_use < NTXBLOCKS - 1) {
846		netif_wake_queue(dev);
847	}
848#ifdef DEBUG_INTERRUPT_TRACE
849	printk(KERN_DEBUG "%s: <-wv_complete()\n", dev->name);
850#endif
851	return nreaped;
852}
853
854/*------------------------------------------------------------------*/
855/*
856 * Reconfigure the i82586, or at least ask for it.
857 * Because wv_82586_config uses a transmission buffer, we must do it
858 * when we are sure that there is one left, so we do it now
859 * or in wavelan_packet_xmit() (I can't find any better place,
860 * wavelan_interrupt is not an option), so you may experience
861 * delays sometimes.
862 */
863static inline void wv_82586_reconfig(device * dev)
864{
865	net_local *lp = (net_local *) dev->priv;
866	unsigned long flags;
867
868	/* Arm the flag, will be cleard in wv_82586_config() */
869	lp->reconfig_82586 = 1;
870
871	/* Check if we can do it now ! */
872	if((netif_running(dev)) && !(netif_queue_stopped(dev))) {
873		wv_splhi(lp, &flags);
874		/* May fail */
875		wv_82586_config(dev);
876		wv_splx(lp, &flags);
877	}
878	else {
879#ifdef DEBUG_CONFIG_INFO
880		printk(KERN_DEBUG
881		       "%s: wv_82586_reconfig(): delayed (state = %lX)\n",
882			       dev->name, dev->state);
883#endif
884	}
885}
886
887/********************* DEBUG & INFO SUBROUTINES *********************/
888/*
889 * This routine is used in the code to show information for debugging.
890 * Most of the time, it dumps the contents of hardware structures.
891 */
892
893#ifdef DEBUG_PSA_SHOW
894/*------------------------------------------------------------------*/
895/*
896 * Print the formatted contents of the Parameter Storage Area.
897 */
898static void wv_psa_show(psa_t * p)
899{
900	printk(KERN_DEBUG "##### WaveLAN PSA contents: #####\n");
901	printk(KERN_DEBUG "psa_io_base_addr_1: 0x%02X %02X %02X %02X\n",
902	       p->psa_io_base_addr_1,
903	       p->psa_io_base_addr_2,
904	       p->psa_io_base_addr_3, p->psa_io_base_addr_4);
905	printk(KERN_DEBUG "psa_rem_boot_addr_1: 0x%02X %02X %02X\n",
906	       p->psa_rem_boot_addr_1,
907	       p->psa_rem_boot_addr_2, p->psa_rem_boot_addr_3);
908	printk(KERN_DEBUG "psa_holi_params: 0x%02x, ", p->psa_holi_params);
909	printk("psa_int_req_no: %d\n", p->psa_int_req_no);
910#ifdef DEBUG_SHOW_UNUSED
911	printk(KERN_DEBUG
912	       "psa_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
913	       p->psa_unused0[0], p->psa_unused0[1], p->psa_unused0[2],
914	       p->psa_unused0[3], p->psa_unused0[4], p->psa_unused0[5],
915	       p->psa_unused0[6]);
916#endif				/* DEBUG_SHOW_UNUSED */
917	printk(KERN_DEBUG
918	       "psa_univ_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
919	       p->psa_univ_mac_addr[0], p->psa_univ_mac_addr[1],
920	       p->psa_univ_mac_addr[2], p->psa_univ_mac_addr[3],
921	       p->psa_univ_mac_addr[4], p->psa_univ_mac_addr[5]);
922	printk(KERN_DEBUG
923	       "psa_local_mac_addr[]: %02x:%02x:%02x:%02x:%02x:%02x\n",
924	       p->psa_local_mac_addr[0], p->psa_local_mac_addr[1],
925	       p->psa_local_mac_addr[2], p->psa_local_mac_addr[3],
926	       p->psa_local_mac_addr[4], p->psa_local_mac_addr[5]);
927	printk(KERN_DEBUG "psa_univ_local_sel: %d, ",
928	       p->psa_univ_local_sel);
929	printk("psa_comp_number: %d, ", p->psa_comp_number);
930	printk("psa_thr_pre_set: 0x%02x\n", p->psa_thr_pre_set);
931	printk(KERN_DEBUG "psa_feature_select/decay_prm: 0x%02x, ",
932	       p->psa_feature_select);
933	printk("psa_subband/decay_update_prm: %d\n", p->psa_subband);
934	printk(KERN_DEBUG "psa_quality_thr: 0x%02x, ", p->psa_quality_thr);
935	printk("psa_mod_delay: 0x%02x\n", p->psa_mod_delay);
936	printk(KERN_DEBUG "psa_nwid: 0x%02x%02x, ", p->psa_nwid[0],
937	       p->psa_nwid[1]);
938	printk("psa_nwid_select: %d\n", p->psa_nwid_select);
939	printk(KERN_DEBUG "psa_encryption_select: %d, ",
940	       p->psa_encryption_select);
941	printk
942	    ("psa_encryption_key[]: %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n",
943	     p->psa_encryption_key[0], p->psa_encryption_key[1],
944	     p->psa_encryption_key[2], p->psa_encryption_key[3],
945	     p->psa_encryption_key[4], p->psa_encryption_key[5],
946	     p->psa_encryption_key[6], p->psa_encryption_key[7]);
947	printk(KERN_DEBUG "psa_databus_width: %d\n", p->psa_databus_width);
948	printk(KERN_DEBUG "psa_call_code/auto_squelch: 0x%02x, ",
949	       p->psa_call_code[0]);
950	printk
951	    ("psa_call_code[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
952	     p->psa_call_code[0], p->psa_call_code[1], p->psa_call_code[2],
953	     p->psa_call_code[3], p->psa_call_code[4], p->psa_call_code[5],
954	     p->psa_call_code[6], p->psa_call_code[7]);
955#ifdef DEBUG_SHOW_UNUSED
956	printk(KERN_DEBUG "psa_reserved[]: %02X:%02X:%02X:%02X\n",
957	       p->psa_reserved[0],
958	       p->psa_reserved[1], p->psa_reserved[2], p->psa_reserved[3]);
959#endif				/* DEBUG_SHOW_UNUSED */
960	printk(KERN_DEBUG "psa_conf_status: %d, ", p->psa_conf_status);
961	printk("psa_crc: 0x%02x%02x, ", p->psa_crc[0], p->psa_crc[1]);
962	printk("psa_crc_status: 0x%02x\n", p->psa_crc_status);
963}				/* wv_psa_show */
964#endif				/* DEBUG_PSA_SHOW */
965
966#ifdef DEBUG_MMC_SHOW
967/*------------------------------------------------------------------*/
968/*
969 * Print the formatted status of the Modem Management Controller.
970 * This function needs to be completed.
971 */
972static void wv_mmc_show(device * dev)
973{
974	unsigned long ioaddr = dev->base_addr;
975	net_local *lp = (net_local *) dev->priv;
976	mmr_t m;
977
978	/* Basic check */
979	if (hasr_read(ioaddr) & HASR_NO_CLK) {
980		printk(KERN_WARNING
981		       "%s: wv_mmc_show: modem not connected\n",
982		       dev->name);
983		return;
984	}
985
986	/* Read the mmc */
987	mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
988	mmc_read(ioaddr, 0, (u8 *) & m, sizeof(m));
989	mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
990
991#ifdef WIRELESS_EXT		    /* if wireless extension exists in the kernel */
992	/* Don't forget to update statistics */
993	lp->wstats.discard.nwid +=
994	    (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
995#endif				/* WIRELESS_EXT */
996
997	printk(KERN_DEBUG "##### WaveLAN modem status registers: #####\n");
998#ifdef DEBUG_SHOW_UNUSED
999	printk(KERN_DEBUG
1000	       "mmc_unused0[]: %02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X\n",
1001	       m.mmr_unused0[0], m.mmr_unused0[1], m.mmr_unused0[2],
1002	       m.mmr_unused0[3], m.mmr_unused0[4], m.mmr_unused0[5],
1003	       m.mmr_unused0[6], m.mmr_unused0[7]);
1004#endif				/* DEBUG_SHOW_UNUSED */
1005	printk(KERN_DEBUG "Encryption algorithm: %02X - Status: %02X\n",
1006	       m.mmr_des_avail, m.mmr_des_status);
1007#ifdef DEBUG_SHOW_UNUSED
1008	printk(KERN_DEBUG "mmc_unused1[]: %02X:%02X:%02X:%02X:%02X\n",
1009	       m.mmr_unused1[0],
1010	       m.mmr_unused1[1],
1011	       m.mmr_unused1[2], m.mmr_unused1[3], m.mmr_unused1[4]);
1012#endif				/* DEBUG_SHOW_UNUSED */
1013	printk(KERN_DEBUG "dce_status: 0x%x [%s%s%s%s]\n",
1014	       m.mmr_dce_status,
1015	       (m.
1016		mmr_dce_status & MMR_DCE_STATUS_RX_BUSY) ?
1017	       "energy detected," : "",
1018	       (m.
1019		mmr_dce_status & MMR_DCE_STATUS_LOOPT_IND) ?
1020	       "loop test indicated," : "",
1021	       (m.
1022		mmr_dce_status & MMR_DCE_STATUS_TX_BUSY) ?
1023	       "transmitter on," : "",
1024	       (m.
1025		mmr_dce_status & MMR_DCE_STATUS_JBR_EXPIRED) ?
1026	       "jabber timer expired," : "");
1027	printk(KERN_DEBUG "Dsp ID: %02X\n", m.mmr_dsp_id);
1028#ifdef DEBUG_SHOW_UNUSED
1029	printk(KERN_DEBUG "mmc_unused2[]: %02X:%02X\n",
1030	       m.mmr_unused2[0], m.mmr_unused2[1]);
1031#endif				/* DEBUG_SHOW_UNUSED */
1032	printk(KERN_DEBUG "# correct_nwid: %d, # wrong_nwid: %d\n",
1033	       (m.mmr_correct_nwid_h << 8) | m.mmr_correct_nwid_l,
1034	       (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l);
1035	printk(KERN_DEBUG "thr_pre_set: 0x%x [current signal %s]\n",
1036	       m.mmr_thr_pre_set & MMR_THR_PRE_SET,
1037	       (m.
1038		mmr_thr_pre_set & MMR_THR_PRE_SET_CUR) ? "above" :
1039	       "below");
1040	printk(KERN_DEBUG "signal_lvl: %d [%s], ",
1041	       m.mmr_signal_lvl & MMR_SIGNAL_LVL,
1042	       (m.
1043		mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) ? "new msg" :
1044	       "no new msg");
1045	printk("silence_lvl: %d [%s], ",
1046	       m.mmr_silence_lvl & MMR_SILENCE_LVL,
1047	       (m.
1048		mmr_silence_lvl & MMR_SILENCE_LVL_VALID) ? "update done" :
1049	       "no new update");
1050	printk("sgnl_qual: 0x%x [%s]\n", m.mmr_sgnl_qual & MMR_SGNL_QUAL,
1051	       (m.
1052		mmr_sgnl_qual & MMR_SGNL_QUAL_ANT) ? "Antenna 1" :
1053	       "Antenna 0");
1054#ifdef DEBUG_SHOW_UNUSED
1055	printk(KERN_DEBUG "netw_id_l: %x\n", m.mmr_netw_id_l);
1056#endif				/* DEBUG_SHOW_UNUSED */
1057}				/* wv_mmc_show */
1058#endif				/* DEBUG_MMC_SHOW */
1059
1060#ifdef DEBUG_I82586_SHOW
1061/*------------------------------------------------------------------*/
1062/*
1063 * Print the last block of the i82586 memory.
1064 */
1065static void wv_scb_show(unsigned long ioaddr)
1066{
1067	scb_t scb;
1068
1069	obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
1070		   sizeof(scb));
1071
1072	printk(KERN_DEBUG "##### WaveLAN system control block: #####\n");
1073
1074	printk(KERN_DEBUG "status: ");
1075	printk("stat 0x%x[%s%s%s%s] ",
1076	       (scb.
1077		scb_status & (SCB_ST_CX | SCB_ST_FR | SCB_ST_CNA |
1078			      SCB_ST_RNR)) >> 12,
1079	       (scb.
1080		scb_status & SCB_ST_CX) ? "command completion interrupt," :
1081	       "", (scb.scb_status & SCB_ST_FR) ? "frame received," : "",
1082	       (scb.
1083		scb_status & SCB_ST_CNA) ? "command unit not active," : "",
1084	       (scb.
1085		scb_status & SCB_ST_RNR) ? "receiving unit not ready," :
1086	       "");
1087	printk("cus 0x%x[%s%s%s] ", (scb.scb_status & SCB_ST_CUS) >> 8,
1088	       ((scb.scb_status & SCB_ST_CUS) ==
1089		SCB_ST_CUS_IDLE) ? "idle" : "",
1090	       ((scb.scb_status & SCB_ST_CUS) ==
1091		SCB_ST_CUS_SUSP) ? "suspended" : "",
1092	       ((scb.scb_status & SCB_ST_CUS) ==
1093		SCB_ST_CUS_ACTV) ? "active" : "");
1094	printk("rus 0x%x[%s%s%s%s]\n", (scb.scb_status & SCB_ST_RUS) >> 4,
1095	       ((scb.scb_status & SCB_ST_RUS) ==
1096		SCB_ST_RUS_IDLE) ? "idle" : "",
1097	       ((scb.scb_status & SCB_ST_RUS) ==
1098		SCB_ST_RUS_SUSP) ? "suspended" : "",
1099	       ((scb.scb_status & SCB_ST_RUS) ==
1100		SCB_ST_RUS_NRES) ? "no resources" : "",
1101	       ((scb.scb_status & SCB_ST_RUS) ==
1102		SCB_ST_RUS_RDY) ? "ready" : "");
1103
1104	printk(KERN_DEBUG "command: ");
1105	printk("ack 0x%x[%s%s%s%s] ",
1106	       (scb.
1107		scb_command & (SCB_CMD_ACK_CX | SCB_CMD_ACK_FR |
1108			       SCB_CMD_ACK_CNA | SCB_CMD_ACK_RNR)) >> 12,
1109	       (scb.
1110		scb_command & SCB_CMD_ACK_CX) ? "ack cmd completion," : "",
1111	       (scb.
1112		scb_command & SCB_CMD_ACK_FR) ? "ack frame received," : "",
1113	       (scb.
1114		scb_command & SCB_CMD_ACK_CNA) ? "ack CU not active," : "",
1115	       (scb.
1116		scb_command & SCB_CMD_ACK_RNR) ? "ack RU not ready," : "");
1117	printk("cuc 0x%x[%s%s%s%s%s] ",
1118	       (scb.scb_command & SCB_CMD_CUC) >> 8,
1119	       ((scb.scb_command & SCB_CMD_CUC) ==
1120		SCB_CMD_CUC_NOP) ? "nop" : "",
1121	       ((scb.scb_command & SCB_CMD_CUC) ==
1122		SCB_CMD_CUC_GO) ? "start cbl_offset" : "",
1123	       ((scb.scb_command & SCB_CMD_CUC) ==
1124		SCB_CMD_CUC_RES) ? "resume execution" : "",
1125	       ((scb.scb_command & SCB_CMD_CUC) ==
1126		SCB_CMD_CUC_SUS) ? "suspend execution" : "",
1127	       ((scb.scb_command & SCB_CMD_CUC) ==
1128		SCB_CMD_CUC_ABT) ? "abort execution" : "");
1129	printk("ruc 0x%x[%s%s%s%s%s]\n",
1130	       (scb.scb_command & SCB_CMD_RUC) >> 4,
1131	       ((scb.scb_command & SCB_CMD_RUC) ==
1132		SCB_CMD_RUC_NOP) ? "nop" : "",
1133	       ((scb.scb_command & SCB_CMD_RUC) ==
1134		SCB_CMD_RUC_GO) ? "start rfa_offset" : "",
1135	       ((scb.scb_command & SCB_CMD_RUC) ==
1136		SCB_CMD_RUC_RES) ? "resume reception" : "",
1137	       ((scb.scb_command & SCB_CMD_RUC) ==
1138		SCB_CMD_RUC_SUS) ? "suspend reception" : "",
1139	       ((scb.scb_command & SCB_CMD_RUC) ==
1140		SCB_CMD_RUC_ABT) ? "abort reception" : "");
1141
1142	printk(KERN_DEBUG "cbl_offset 0x%x ", scb.scb_cbl_offset);
1143	printk("rfa_offset 0x%x\n", scb.scb_rfa_offset);
1144
1145	printk(KERN_DEBUG "crcerrs %d ", scb.scb_crcerrs);
1146	printk("alnerrs %d ", scb.scb_alnerrs);
1147	printk("rscerrs %d ", scb.scb_rscerrs);
1148	printk("ovrnerrs %d\n", scb.scb_ovrnerrs);
1149}
1150
1151/*------------------------------------------------------------------*/
1152/*
1153 * Print the formatted status of the i82586's receive unit.
1154 */
1155static void wv_ru_show(device * dev)
1156{
1157	/* net_local *lp = (net_local *) dev->priv; */
1158
1159	printk(KERN_DEBUG
1160	       "##### WaveLAN i82586 receiver unit status: #####\n");
1161	printk(KERN_DEBUG "ru:");
1162	/*
1163	 * Not implemented yet
1164	 */
1165	printk("\n");
1166}				/* wv_ru_show */
1167
1168/*------------------------------------------------------------------*/
1169/*
1170 * Display info about one control block of the i82586 memory.
1171 */
1172static void wv_cu_show_one(device * dev, net_local * lp, int i, u16 p)
1173{
1174	unsigned long ioaddr;
1175	ac_tx_t actx;
1176
1177	ioaddr = dev->base_addr;
1178
1179	printk("%d: 0x%x:", i, p);
1180
1181	obram_read(ioaddr, p, (unsigned char *) &actx, sizeof(actx));
1182	printk(" status=0x%x,", actx.tx_h.ac_status);
1183	printk(" command=0x%x,", actx.tx_h.ac_command);
1184
1185	/*
1186	   {
1187	   tbd_t      tbd;
1188
1189	   obram_read(ioaddr, actx.tx_tbd_offset, (unsigned char *)&tbd, sizeof(tbd));
1190	   printk(" tbd_status=0x%x,", tbd.tbd_status);
1191	   }
1192	 */
1193
1194	printk("|");
1195}
1196
1197/*------------------------------------------------------------------*/
1198/*
1199 * Print status of the command unit of the i82586.
1200 */
1201static void wv_cu_show(device * dev)
1202{
1203	net_local *lp = (net_local *) dev->priv;
1204	unsigned int i;
1205	u16 p;
1206
1207	printk(KERN_DEBUG
1208	       "##### WaveLAN i82586 command unit status: #####\n");
1209
1210	printk(KERN_DEBUG);
1211	for (i = 0, p = lp->tx_first_in_use; i < NTXBLOCKS; i++) {
1212		wv_cu_show_one(dev, lp, i, p);
1213
1214		p += TXBLOCKZ;
1215		if (p >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
1216			p -= NTXBLOCKS * TXBLOCKZ;
1217	}
1218	printk("\n");
1219}
1220#endif				/* DEBUG_I82586_SHOW */
1221
1222#ifdef DEBUG_DEVICE_SHOW
1223/*------------------------------------------------------------------*/
1224/*
1225 * Print the formatted status of the WaveLAN PCMCIA device driver.
1226 */
1227static void wv_dev_show(device * dev)
1228{
1229	printk(KERN_DEBUG "dev:");
1230	printk(" state=%lX,", dev->state);
1231	printk(" trans_start=%ld,", dev->trans_start);
1232	printk(" flags=0x%x,", dev->flags);
1233	printk("\n");
1234}				/* wv_dev_show */
1235
1236/*------------------------------------------------------------------*/
1237/*
1238 * Print the formatted status of the WaveLAN PCMCIA device driver's
1239 * private information.
1240 */
1241static void wv_local_show(device * dev)
1242{
1243	net_local *lp;
1244
1245	lp = (net_local *) dev->priv;
1246
1247	printk(KERN_DEBUG "local:");
1248	printk(" tx_n_in_use=%d,", lp->tx_n_in_use);
1249	printk(" hacr=0x%x,", lp->hacr);
1250	printk(" rx_head=0x%x,", lp->rx_head);
1251	printk(" rx_last=0x%x,", lp->rx_last);
1252	printk(" tx_first_free=0x%x,", lp->tx_first_free);
1253	printk(" tx_first_in_use=0x%x,", lp->tx_first_in_use);
1254	printk("\n");
1255}				/* wv_local_show */
1256#endif				/* DEBUG_DEVICE_SHOW */
1257
1258#if defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO)
1259/*------------------------------------------------------------------*/
1260/*
1261 * Dump packet header (and content if necessary) on the screen
1262 */
1263static inline void wv_packet_info(u8 * p,	/* Packet to dump */
1264				  int length,	/* Length of the packet */
1265				  char *msg1,	/* Name of the device */
1266				  char *msg2)
1267{				/* Name of the function */
1268	int i;
1269	int maxi;
1270
1271	printk(KERN_DEBUG
1272	       "%s: %s(): dest %02X:%02X:%02X:%02X:%02X:%02X, length %d\n",
1273	       msg1, msg2, p[0], p[1], p[2], p[3], p[4], p[5], length);
1274	printk(KERN_DEBUG
1275	       "%s: %s(): src %02X:%02X:%02X:%02X:%02X:%02X, type 0x%02X%02X\n",
1276	       msg1, msg2, p[6], p[7], p[8], p[9], p[10], p[11], p[12],
1277	       p[13]);
1278
1279#ifdef DEBUG_PACKET_DUMP
1280
1281	printk(KERN_DEBUG "data=\"");
1282
1283	if ((maxi = length) > DEBUG_PACKET_DUMP)
1284		maxi = DEBUG_PACKET_DUMP;
1285	for (i = 14; i < maxi; i++)
1286		if (p[i] >= ' ' && p[i] <= '~')
1287			printk(" %c", p[i]);
1288		else
1289			printk("%02X", p[i]);
1290	if (maxi < length)
1291		printk("..");
1292	printk("\"\n");
1293	printk(KERN_DEBUG "\n");
1294#endif				/* DEBUG_PACKET_DUMP */
1295}
1296#endif				/* defined(DEBUG_RX_INFO) || defined(DEBUG_TX_INFO) */
1297
1298/*------------------------------------------------------------------*/
1299/*
1300 * This is the information which is displayed by the driver at startup.
1301 * There are lots of flags for configuring it to your liking.
1302 */
1303static inline void wv_init_info(device * dev)
1304{
1305	short ioaddr = dev->base_addr;
1306	net_local *lp = (net_local *) dev->priv;
1307	psa_t psa;
1308	int i;
1309
1310	/* Read the parameter storage area */
1311	psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa));
1312
1313#ifdef DEBUG_PSA_SHOW
1314	wv_psa_show(&psa);
1315#endif
1316#ifdef DEBUG_MMC_SHOW
1317	wv_mmc_show(dev);
1318#endif
1319#ifdef DEBUG_I82586_SHOW
1320	wv_cu_show(dev);
1321#endif
1322
1323#ifdef DEBUG_BASIC_SHOW
1324	/* Now, let's go for the basic stuff. */
1325	printk(KERN_NOTICE "%s: WaveLAN at %#x,", dev->name, ioaddr);
1326	for (i = 0; i < WAVELAN_ADDR_SIZE; i++)
1327		printk("%s%02X", (i == 0) ? " " : ":", dev->dev_addr[i]);
1328	printk(", IRQ %d", dev->irq);
1329
1330	/* Print current network ID. */
1331	if (psa.psa_nwid_select)
1332		printk(", nwid 0x%02X-%02X", psa.psa_nwid[0],
1333		       psa.psa_nwid[1]);
1334	else
1335		printk(", nwid off");
1336
1337	/* If 2.00 card */
1338	if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1339	      (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
1340		unsigned short freq;
1341
1342		/* Ask the EEPROM to read the frequency from the first area. */
1343		fee_read(ioaddr, 0x00, &freq, 1);
1344
1345		/* Print frequency */
1346		printk(", 2.00, %ld", (freq >> 6) + 2400L);
1347
1348		/* Hack! */
1349		if (freq & 0x20)
1350			printk(".5");
1351	} else {
1352		printk(", PC");
1353		switch (psa.psa_comp_number) {
1354		case PSA_COMP_PC_AT_915:
1355		case PSA_COMP_PC_AT_2400:
1356			printk("-AT");
1357			break;
1358		case PSA_COMP_PC_MC_915:
1359		case PSA_COMP_PC_MC_2400:
1360			printk("-MC");
1361			break;
1362		case PSA_COMP_PCMCIA_915:
1363			printk("MCIA");
1364			break;
1365		default:
1366			printk("?");
1367		}
1368		printk(", ");
1369		switch (psa.psa_subband) {
1370		case PSA_SUBBAND_915:
1371			printk("915");
1372			break;
1373		case PSA_SUBBAND_2425:
1374			printk("2425");
1375			break;
1376		case PSA_SUBBAND_2460:
1377			printk("2460");
1378			break;
1379		case PSA_SUBBAND_2484:
1380			printk("2484");
1381			break;
1382		case PSA_SUBBAND_2430_5:
1383			printk("2430.5");
1384			break;
1385		default:
1386			printk("?");
1387		}
1388	}
1389
1390	printk(" MHz\n");
1391#endif				/* DEBUG_BASIC_SHOW */
1392
1393#ifdef DEBUG_VERSION_SHOW
1394	/* Print version information */
1395	printk(KERN_NOTICE "%s", version);
1396#endif
1397}				/* wv_init_info */
1398
1399/********************* IOCTL, STATS & RECONFIG *********************/
1400/*
1401 * We found here routines that are called by Linux on different
1402 * occasions after the configuration and not for transmitting data
1403 * These may be called when the user use ifconfig, /proc/net/dev
1404 * or wireless extensions
1405 */
1406
1407/*------------------------------------------------------------------*/
1408/*
1409 * Get the current Ethernet statistics. This may be called with the
1410 * card open or closed.
1411 * Used when the user read /proc/net/dev
1412 */
1413static en_stats *wavelan_get_stats(device * dev)
1414{
1415#ifdef DEBUG_IOCTL_TRACE
1416	printk(KERN_DEBUG "%s: <>wavelan_get_stats()\n", dev->name);
1417#endif
1418
1419	return (&((net_local *) dev->priv)->stats);
1420}
1421
1422/*------------------------------------------------------------------*/
1423/*
1424 * Set or clear the multicast filter for this adaptor.
1425 * num_addrs == -1	Promiscuous mode, receive all packets
1426 * num_addrs == 0	Normal mode, clear multicast list
1427 * num_addrs > 0	Multicast mode, receive normal and MC packets,
1428 *			and do best-effort filtering.
1429 */
1430static void wavelan_set_multicast_list(device * dev)
1431{
1432	net_local *lp = (net_local *) dev->priv;
1433
1434#ifdef DEBUG_IOCTL_TRACE
1435	printk(KERN_DEBUG "%s: ->wavelan_set_multicast_list()\n",
1436	       dev->name);
1437#endif
1438
1439#ifdef DEBUG_IOCTL_INFO
1440	printk(KERN_DEBUG
1441	       "%s: wavelan_set_multicast_list(): setting Rx mode %02X to %d addresses.\n",
1442	       dev->name, dev->flags, dev->mc_count);
1443#endif
1444
1445	/* Are we asking for promiscuous mode,
1446	 * or all multicast addresses (we don't have that!)
1447	 * or too many multicast addresses for the hardware filter? */
1448	if ((dev->flags & IFF_PROMISC) ||
1449	    (dev->flags & IFF_ALLMULTI) ||
1450	    (dev->mc_count > I82586_MAX_MULTICAST_ADDRESSES)) {
1451		/*
1452		 * Enable promiscuous mode: receive all packets.
1453		 */
1454		if (!lp->promiscuous) {
1455			lp->promiscuous = 1;
1456			lp->mc_count = 0;
1457
1458			wv_82586_reconfig(dev);
1459
1460			/* Tell the kernel that we are doing a really bad job. */
1461			dev->flags |= IFF_PROMISC;
1462		}
1463	} else
1464		/* Are there multicast addresses to send? */
1465	if (dev->mc_list != (struct dev_mc_list *) NULL) {
1466		/*
1467		 * Disable promiscuous mode, but receive all packets
1468		 * in multicast list
1469		 */
1470#ifdef MULTICAST_AVOID
1471		if (lp->promiscuous || (dev->mc_count != lp->mc_count))
1472#endif
1473		{
1474			lp->promiscuous = 0;
1475			lp->mc_count = dev->mc_count;
1476
1477			wv_82586_reconfig(dev);
1478		}
1479	} else {
1480		/*
1481		 * Switch to normal mode: disable promiscuous mode and
1482		 * clear the multicast list.
1483		 */
1484		if (lp->promiscuous || lp->mc_count == 0) {
1485			lp->promiscuous = 0;
1486			lp->mc_count = 0;
1487
1488			wv_82586_reconfig(dev);
1489		}
1490	}
1491#ifdef DEBUG_IOCTL_TRACE
1492	printk(KERN_DEBUG "%s: <-wavelan_set_multicast_list()\n",
1493	       dev->name);
1494#endif
1495}
1496
1497/*------------------------------------------------------------------*/
1498/*
1499 * This function doesn't exist.
1500 * (Note : it was a nice way to test the reconfigure stuff...)
1501 */
1502#ifdef SET_MAC_ADDRESS
1503static int wavelan_set_mac_address(device * dev, void *addr)
1504{
1505	struct sockaddr *mac = addr;
1506
1507	/* Copy the address. */
1508	memcpy(dev->dev_addr, mac->sa_data, WAVELAN_ADDR_SIZE);
1509
1510	/* Reconfigure the beast. */
1511	wv_82586_reconfig(dev);
1512
1513	return 0;
1514}
1515#endif				/* SET_MAC_ADDRESS */
1516
1517#ifdef WIRELESS_EXT		    /* if wireless extensions exist in the kernel */
1518
1519/*------------------------------------------------------------------*/
1520/*
1521 * Frequency setting (for hardware capable of it)
1522 * It's a bit complicated and you don't really want to look into it.
1523 * (called in wavelan_ioctl)
1524 */
1525static inline int wv_set_frequency(unsigned long ioaddr,	/* I/O port of the card */
1526				   iw_freq * frequency)
1527{
1528	const int BAND_NUM = 10;	/* Number of bands */
1529	long freq = 0L;		/* offset to 2.4 GHz in .5 MHz */
1530#ifdef DEBUG_IOCTL_INFO
1531	int i;
1532#endif
1533
1534	/* Setting by frequency */
1535	/* Theoretically, you may set any frequency between
1536	 * the two limits with a 0.5 MHz precision. In practice,
1537	 * I don't want you to have trouble with local regulations.
1538	 */
1539	if ((frequency->e == 1) &&
1540	    (frequency->m >= (int) 2.412e8)
1541	    && (frequency->m <= (int) 2.487e8)) {
1542		freq = ((frequency->m / 10000) - 24000L) / 5;
1543	}
1544
1545	/* Setting by channel (same as wfreqsel) */
1546	/* Warning: each channel is 22 MHz wide, so some of the channels
1547	 * will interfere. */
1548	if ((frequency->e == 0) && (frequency->m < BAND_NUM)) {
1549		/* Get frequency offset. */
1550		freq = channel_bands[frequency->m] >> 1;
1551	}
1552
1553	/* Verify that the frequency is allowed. */
1554	if (freq != 0L) {
1555		u16 table[10];	/* Authorized frequency table */
1556
1557		/* Read the frequency table. */
1558		fee_read(ioaddr, 0x71, table, 10);
1559
1560#ifdef DEBUG_IOCTL_INFO
1561		printk(KERN_DEBUG "Frequency table: ");
1562		for (i = 0; i < 10; i++) {
1563			printk(" %04X", table[i]);
1564		}
1565		printk("\n");
1566#endif
1567
1568		/* Look in the table to see whether the frequency is allowed. */
1569		if (!(table[9 - ((freq - 24) / 16)] &
1570		      (1 << ((freq - 24) % 16)))) return -EINVAL;	/* not allowed */
1571	} else
1572		return -EINVAL;
1573
1574	/* if we get a usable frequency */
1575	if (freq != 0L) {
1576		unsigned short area[16];
1577		unsigned short dac[2];
1578		unsigned short area_verify[16];
1579		unsigned short dac_verify[2];
1580		/* Corresponding gain (in the power adjust value table)
1581		 * See AT&T WaveLAN Data Manual, REF 407-024689/E, page 3-8
1582		 * and WCIN062D.DOC, page 6.2.9. */
1583		unsigned short power_limit[] = { 40, 80, 120, 160, 0 };
1584		int power_band = 0;	/* Selected band */
1585		unsigned short power_adjust;	/* Correct value */
1586
1587		/* Search for the gain. */
1588		power_band = 0;
1589		while ((freq > power_limit[power_band]) &&
1590		       (power_limit[++power_band] != 0));
1591
1592		/* Read the first area. */
1593		fee_read(ioaddr, 0x00, area, 16);
1594
1595		/* Read the DAC. */
1596		fee_read(ioaddr, 0x60, dac, 2);
1597
1598		/* Read the new power adjust value. */
1599		fee_read(ioaddr, 0x6B - (power_band >> 1), &power_adjust,
1600			 1);
1601		if (power_band & 0x1)
1602			power_adjust >>= 8;
1603		else
1604			power_adjust &= 0xFF;
1605
1606#ifdef DEBUG_IOCTL_INFO
1607		printk(KERN_DEBUG "WaveLAN EEPROM Area 1: ");
1608		for (i = 0; i < 16; i++) {
1609			printk(" %04X", area[i]);
1610		}
1611		printk("\n");
1612
1613		printk(KERN_DEBUG "WaveLAN EEPROM DAC: %04X %04X\n",
1614		       dac[0], dac[1]);
1615#endif
1616
1617		/* Frequency offset (for info only) */
1618		area[0] = ((freq << 5) & 0xFFE0) | (area[0] & 0x1F);
1619
1620		/* Receiver Principle main divider coefficient */
1621		area[3] = (freq >> 1) + 2400L - 352L;
1622		area[2] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1623
1624		/* Transmitter Main divider coefficient */
1625		area[13] = (freq >> 1) + 2400L;
1626		area[12] = ((freq & 0x1) << 4) | (area[2] & 0xFFEF);
1627
1628		/* Other parts of the area are flags, bit streams or unused. */
1629
1630		/* Set the value in the DAC. */
1631		dac[1] = ((power_adjust >> 1) & 0x7F) | (dac[1] & 0xFF80);
1632		dac[0] = ((power_adjust & 0x1) << 4) | (dac[0] & 0xFFEF);
1633
1634		/* Write the first area. */
1635		fee_write(ioaddr, 0x00, area, 16);
1636
1637		/* Write the DAC. */
1638		fee_write(ioaddr, 0x60, dac, 2);
1639
1640		/* We now should verify here that the writing of the EEPROM went OK. */
1641
1642		/* Reread the first area. */
1643		fee_read(ioaddr, 0x00, area_verify, 16);
1644
1645		/* Reread the DAC. */
1646		fee_read(ioaddr, 0x60, dac_verify, 2);
1647
1648		/* Compare. */
1649		if (memcmp(area, area_verify, 16 * 2) ||
1650		    memcmp(dac, dac_verify, 2 * 2)) {
1651#ifdef DEBUG_IOCTL_ERROR
1652			printk(KERN_INFO
1653			       "WaveLAN: wv_set_frequency: unable to write new frequency to EEPROM(?).\n");
1654#endif
1655			return -EOPNOTSUPP;
1656		}
1657
1658		/* We must download the frequency parameters to the
1659		 * synthesizers (from the EEPROM - area 1)
1660		 * Note: as the EEPROM is automatically decremented, we set the end
1661		 * if the area... */
1662		mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x0F);
1663		mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
1664			MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1665
1666		/* Wait until the download is finished. */
1667		fee_wait(ioaddr, 100, 100);
1668
1669		/* We must now download the power adjust value (gain) to
1670		 * the synthesizers (from the EEPROM - area 7 - DAC). */
1671		mmc_out(ioaddr, mmwoff(0, mmw_fee_addr), 0x61);
1672		mmc_out(ioaddr, mmwoff(0, mmw_fee_ctrl),
1673			MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD);
1674
1675		/* Wait for the download to finish. */
1676		fee_wait(ioaddr, 100, 100);
1677
1678#ifdef DEBUG_IOCTL_INFO
1679		/* Verification of what we have done */
1680
1681		printk(KERN_DEBUG "WaveLAN EEPROM Area 1: ");
1682		for (i = 0; i < 16; i++) {
1683			printk(" %04X", area_verify[i]);
1684		}
1685		printk("\n");
1686
1687		printk(KERN_DEBUG "WaveLAN EEPROM DAC:  %04X %04X\n",
1688		       dac_verify[0], dac_verify[1]);
1689#endif
1690
1691		return 0;
1692	} else
1693		return -EINVAL;	/* Bah, never get there... */
1694}
1695
1696/*------------------------------------------------------------------*/
1697/*
1698 * Give the list of available frequencies.
1699 */
1700static inline int wv_frequency_list(unsigned long ioaddr,	/* I/O port of the card */
1701				    iw_freq * list,	/* List of frequencies to fill */
1702				    int max)
1703{				/* Maximum number of frequencies */
1704	u16 table[10];	/* Authorized frequency table */
1705	long freq = 0L;		/* offset to 2.4 GHz in .5 MHz + 12 MHz */
1706	int i;			/* index in the table */
1707	int c = 0;		/* Channel number */
1708
1709	/* Read the frequency table. */
1710	fee_read(ioaddr, 0x71 /* frequency table */ , table, 10);
1711
1712	/* Check all frequencies. */
1713	i = 0;
1714	for (freq = 0; freq < 150; freq++)
1715		/* Look in the table if the frequency is allowed */
1716		if (table[9 - (freq / 16)] & (1 << (freq % 16))) {
1717			/* Compute approximate channel number */
1718			while ((((channel_bands[c] >> 1) - 24) < freq) &&
1719			       (c < NELS(channel_bands)))
1720				c++;
1721			list[i].i = c;	/* Set the list index */
1722
1723			/* put in the list */
1724			list[i].m = (((freq + 24) * 5) + 24000L) * 10000;
1725			list[i++].e = 1;
1726
1727			/* Check number. */
1728			if (i >= max)
1729				return (i);
1730		}
1731
1732	return (i);
1733}
1734
1735#ifdef WIRELESS_SPY
1736/*------------------------------------------------------------------*/
1737/*
1738 * Gather wireless spy statistics:  for each packet, compare the source
1739 * address with our list, and if they match, get the statistics.
1740 * Sorry, but this function really needs the wireless extensions.
1741 */
1742static inline void wl_spy_gather(device * dev, u8 * mac,	/* MAC address */
1743				 u8 * stats)
1744{				/* Statistics to gather */
1745	net_local *lp = (net_local *) dev->priv;
1746	int i;
1747
1748	/* Check all addresses. */
1749	for (i = 0; i < lp->spy_number; i++)
1750		/* If match */
1751		if (!memcmp(mac, lp->spy_address[i], WAVELAN_ADDR_SIZE)) {
1752			/* Update statistics */
1753			lp->spy_stat[i].qual = stats[2] & MMR_SGNL_QUAL;
1754			lp->spy_stat[i].level = stats[0] & MMR_SIGNAL_LVL;
1755			lp->spy_stat[i].noise = stats[1] & MMR_SILENCE_LVL;
1756			lp->spy_stat[i].updated = 0x7;
1757		}
1758}
1759#endif				/* WIRELESS_SPY */
1760
1761#ifdef HISTOGRAM
1762/*------------------------------------------------------------------*/
1763/*
1764 * This function calculates a histogram of the signal level.
1765 * As the noise is quite constant, it's like doing it on the SNR.
1766 * We have defined a set of interval (lp->his_range), and each time
1767 * the level goes in that interval, we increment the count (lp->his_sum).
1768 * With this histogram you may detect if one WaveLAN is really weak,
1769 * or you may also calculate the mean and standard deviation of the level.
1770 */
1771static inline void wl_his_gather(device * dev, u8 * stats)
1772{				/* Statistics to gather */
1773	net_local *lp = (net_local *) dev->priv;
1774	u8 level = stats[0] & MMR_SIGNAL_LVL;
1775	int i;
1776
1777	/* Find the correct interval. */
1778	i = 0;
1779	while ((i < (lp->his_number - 1))
1780	       && (level >= lp->his_range[i++]));
1781
1782	/* Increment interval counter. */
1783	(lp->his_sum[i])++;
1784}
1785#endif				/* HISTOGRAM */
1786
1787/*------------------------------------------------------------------*/
1788/*
1789 * Perform ioctl for configuration and information.
1790 * It is here that the wireless extensions are treated (iwconfig).
1791 */
1792static int wavelan_ioctl(struct net_device *dev,	/* device on which the ioctl is applied */
1793			 struct ifreq *rq,	/* data passed */
1794			 int cmd)
1795{				/* ioctl number */
1796	unsigned long ioaddr = dev->base_addr;
1797	net_local *lp = (net_local *) dev->priv;	/* lp is not unused */
1798	struct iwreq *wrq = (struct iwreq *) rq;
1799	psa_t psa;
1800	mm_t m;
1801	unsigned long flags;
1802	int ret = 0;
1803	int err = 0;
1804
1805#ifdef DEBUG_IOCTL_TRACE
1806	printk(KERN_DEBUG "%s: ->wavelan_ioctl(cmd=0x%X)\n", dev->name,
1807	       cmd);
1808#endif
1809
1810	/* Disable interrupts and save flags. */
1811	wv_splhi(lp, &flags);
1812
1813	/* Look what is the request */
1814	switch (cmd) {
1815		/* --------------- WIRELESS EXTENSIONS --------------- */
1816
1817	case SIOCGIWNAME:
1818		strcpy(wrq->u.name, "WaveLAN");
1819		break;
1820
1821	case SIOCSIWNWID:
1822		/* Set NWID in WaveLAN. */
1823		if (!wrq->u.nwid.disabled) {
1824			/* Set NWID in psa */
1825			psa.psa_nwid[0] =
1826			    (wrq->u.nwid.value & 0xFF00) >> 8;
1827			psa.psa_nwid[1] = wrq->u.nwid.value & 0xFF;
1828			psa.psa_nwid_select = 0x01;
1829			psa_write(ioaddr, lp->hacr,
1830				  (char *) psa.psa_nwid - (char *) &psa,
1831				  (unsigned char *) psa.psa_nwid, 3);
1832
1833			/* Set NWID in mmc. */
1834			m.w.mmw_netw_id_l = psa.psa_nwid[1];
1835			m.w.mmw_netw_id_h = psa.psa_nwid[0];
1836			mmc_write(ioaddr,
1837				  (char *) &m.w.mmw_netw_id_l -
1838				  (char *) &m,
1839				  (unsigned char *) &m.w.mmw_netw_id_l, 2);
1840			mmc_out(ioaddr, mmwoff(0, mmw_loopt_sel), 0x00);
1841		} else {
1842			/* Disable NWID in the psa. */
1843			psa.psa_nwid_select = 0x00;
1844			psa_write(ioaddr, lp->hacr,
1845				  (char *) &psa.psa_nwid_select -
1846				  (char *) &psa,
1847				  (unsigned char *) &psa.psa_nwid_select,
1848				  1);
1849
1850			/* Disable NWID in the mmc (no filtering). */
1851			mmc_out(ioaddr, mmwoff(0, mmw_loopt_sel),
1852				MMW_LOOPT_SEL_DIS_NWID);
1853		}
1854		/* update the Wavelan checksum */
1855		update_psa_checksum(dev, ioaddr, lp->hacr);
1856		break;
1857
1858	case SIOCGIWNWID:
1859		/* Read the NWID. */
1860		psa_read(ioaddr, lp->hacr,
1861			 (char *) psa.psa_nwid - (char *) &psa,
1862			 (unsigned char *) psa.psa_nwid, 3);
1863		wrq->u.nwid.value =
1864		    (psa.psa_nwid[0] << 8) + psa.psa_nwid[1];
1865		wrq->u.nwid.disabled = !(psa.psa_nwid_select);
1866		wrq->u.nwid.fixed = 1;	/* Superfluous */
1867		break;
1868
1869	case SIOCSIWFREQ:
1870		/* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
1871		if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1872		      (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY)))
1873			ret = wv_set_frequency(ioaddr, &(wrq->u.freq));
1874		else
1875			ret = -EOPNOTSUPP;
1876		break;
1877
1878	case SIOCGIWFREQ:
1879		/* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable).
1880		 * Does it work for everybody, especially old cards? */
1881		if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
1882		      (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
1883			unsigned short freq;
1884
1885			/* Ask the EEPROM to read the frequency from the first area. */
1886			fee_read(ioaddr, 0x00, &freq, 1);
1887			wrq->u.freq.m = ((freq >> 5) * 5 + 24000L) * 10000;
1888			wrq->u.freq.e = 1;
1889		} else {
1890			psa_read(ioaddr, lp->hacr,
1891				 (char *) &psa.psa_subband - (char *) &psa,
1892				 (unsigned char *) &psa.psa_subband, 1);
1893
1894			if (psa.psa_subband <= 4) {
1895				wrq->u.freq.m =
1896				    fixed_bands[psa.psa_subband];
1897				wrq->u.freq.e = (psa.psa_subband != 0);
1898			} else
1899				ret = -EOPNOTSUPP;
1900		}
1901		break;
1902
1903	case SIOCSIWSENS:
1904		/* Set the level threshold. */
1905		/* We should complain loudly if wrq->u.sens.fixed = 0, because we
1906		 * can't set auto mode... */
1907		psa.psa_thr_pre_set = wrq->u.sens.value & 0x3F;
1908		psa_write(ioaddr, lp->hacr,
1909			  (char *) &psa.psa_thr_pre_set - (char *) &psa,
1910			  (unsigned char *) &psa.psa_thr_pre_set, 1);
1911		/* update the Wavelan checksum */
1912		update_psa_checksum(dev, ioaddr, lp->hacr);
1913		mmc_out(ioaddr, mmwoff(0, mmw_thr_pre_set),
1914			psa.psa_thr_pre_set);
1915		break;
1916
1917	case SIOCGIWSENS:
1918		/* Read the level threshold. */
1919		psa_read(ioaddr, lp->hacr,
1920			 (char *) &psa.psa_thr_pre_set - (char *) &psa,
1921			 (unsigned char *) &psa.psa_thr_pre_set, 1);
1922		wrq->u.sens.value = psa.psa_thr_pre_set & 0x3F;
1923		wrq->u.sens.fixed = 1;
1924		break;
1925
1926	case SIOCSIWENCODE:
1927		/* Set encryption key */
1928		if (!mmc_encr(ioaddr)) {
1929			ret = -EOPNOTSUPP;
1930			break;
1931		}
1932
1933		/* Basic checking... */
1934		if (wrq->u.encoding.pointer != (caddr_t) 0) {
1935			/* Check the size of the key */
1936			if (wrq->u.encoding.length != 8) {
1937				ret = -EINVAL;
1938				break;
1939			}
1940
1941			/* Copy the key in the driver */
1942			wv_splx(lp, &flags);
1943			err = copy_from_user(psa.psa_encryption_key,
1944					     wrq->u.encoding.pointer,
1945					     wrq->u.encoding.length);
1946			wv_splhi(lp, &flags);
1947			if (err) {
1948				ret = -EFAULT;
1949				break;
1950			}
1951
1952			psa.psa_encryption_select = 1;
1953			psa_write(ioaddr, lp->hacr,
1954				  (char *) &psa.psa_encryption_select -
1955				  (char *) &psa,
1956				  (unsigned char *) &psa.
1957				  psa_encryption_select, 8 + 1);
1958
1959			mmc_out(ioaddr, mmwoff(0, mmw_encr_enable),
1960				MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE);
1961			mmc_write(ioaddr, mmwoff(0, mmw_encr_key),
1962				  (unsigned char *) &psa.
1963				  psa_encryption_key, 8);
1964		}
1965
1966		if (wrq->u.encoding.flags & IW_ENCODE_DISABLED) {	/* disable encryption */
1967			psa.psa_encryption_select = 0;
1968			psa_write(ioaddr, lp->hacr,
1969				  (char *) &psa.psa_encryption_select -
1970				  (char *) &psa,
1971				  (unsigned char *) &psa.
1972				  psa_encryption_select, 1);
1973
1974			mmc_out(ioaddr, mmwoff(0, mmw_encr_enable), 0);
1975		}
1976		/* update the Wavelan checksum */
1977		update_psa_checksum(dev, ioaddr, lp->hacr);
1978		break;
1979
1980	case SIOCGIWENCODE:
1981		/* Read the encryption key */
1982		if (!mmc_encr(ioaddr)) {
1983			ret = -EOPNOTSUPP;
1984			break;
1985		}
1986
1987		/* only super-user can see encryption key */
1988		if (!capable(CAP_NET_ADMIN)) {
1989			ret = -EPERM;
1990			break;
1991		}
1992
1993		/* Basic checking... */
1994		if (wrq->u.encoding.pointer != (caddr_t) 0) {
1995			/* Verify the user buffer */
1996			ret =
1997			    verify_area(VERIFY_WRITE,
1998					wrq->u.encoding.pointer, 8);
1999			if (ret)
2000				break;
2001
2002			psa_read(ioaddr, lp->hacr,
2003				 (char *) &psa.psa_encryption_select -
2004				 (char *) &psa,
2005				 (unsigned char *) &psa.
2006				 psa_encryption_select, 1 + 8);
2007
2008			/* encryption is enabled ? */
2009			if (psa.psa_encryption_select)
2010				wrq->u.encoding.flags = IW_ENCODE_ENABLED;
2011			else
2012				wrq->u.encoding.flags = IW_ENCODE_DISABLED;
2013			wrq->u.encoding.flags |= mmc_encr(ioaddr);
2014
2015			/* Copy the key to the user buffer */
2016			wrq->u.encoding.length = 8;
2017			wv_splx(lp, &flags);
2018			if (copy_to_user(wrq->u.encoding.pointer,
2019					 psa.psa_encryption_key, 8))
2020				ret = -EFAULT;
2021			wv_splhi(lp, &flags);
2022		}
2023		break;
2024
2025	case SIOCGIWRANGE:
2026		/* basic checking */
2027		if (wrq->u.data.pointer != (caddr_t) 0) {
2028			struct iw_range range;
2029
2030			/* Set the length (very important for backward
2031			 * compatibility) */
2032			wrq->u.data.length = sizeof(struct iw_range);
2033
2034			/* Set all the info we don't care or don't know
2035			 * about to zero */
2036			memset(&range, 0, sizeof(range));
2037
2038			/* Set the Wireless Extension versions */
2039			range.we_version_compiled = WIRELESS_EXT;
2040			range.we_version_source = 9;
2041
2042			/* Set information in the range struct.  */
2043			range.throughput = 1.6 * 1000 * 1000;	/* don't argue on this ! */
2044			range.min_nwid = 0x0000;
2045			range.max_nwid = 0xFFFF;
2046
2047			/* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable). */
2048			if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
2049			      (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2050				range.num_channels = 10;
2051				range.num_frequency =
2052				    wv_frequency_list(ioaddr, range.freq,
2053						      IW_MAX_FREQUENCIES);
2054			} else
2055				range.num_channels = range.num_frequency =
2056				    0;
2057
2058			range.sensitivity = 0x3F;
2059			range.max_qual.qual = MMR_SGNL_QUAL;
2060			range.max_qual.level = MMR_SIGNAL_LVL;
2061			range.max_qual.noise = MMR_SILENCE_LVL;
2062			range.avg_qual.qual = MMR_SGNL_QUAL; /* Always max */
2063			/* Need to get better values for those two */
2064			range.avg_qual.level = 30;
2065			range.avg_qual.noise = 8;
2066
2067			range.num_bitrates = 1;
2068			range.bitrate[0] = 2000000;	/* 2 Mb/s */
2069
2070			/* Encryption supported ? */
2071			if (mmc_encr(ioaddr)) {
2072				range.encoding_size[0] = 8;	/* DES = 64 bits key */
2073				range.num_encoding_sizes = 1;
2074				range.max_encoding_tokens = 1;	/* Only one key possible */
2075			} else {
2076				range.num_encoding_sizes = 0;
2077				range.max_encoding_tokens = 0;
2078			}
2079
2080			/* Copy structure to the user buffer. */
2081			wv_splx(lp, &flags);
2082			if (copy_to_user(wrq->u.data.pointer,
2083					 &range,
2084					 sizeof(struct iw_range)))
2085				ret = -EFAULT;
2086			wv_splhi(lp, &flags);
2087		}
2088		break;
2089
2090	case SIOCGIWPRIV:
2091		/* Basic checking */
2092		if (wrq->u.data.pointer != (caddr_t) 0) {
2093			struct iw_priv_args priv[] = {
2094				/* { cmd,
2095				     set_args,
2096				     get_args,
2097				     name } */
2098				{ SIOCSIPQTHR,
2099				  IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
2100				  0,
2101				  "setqualthr" },
2102				{ SIOCGIPQTHR,
2103				  0,
2104				  IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 1,
2105				  "getqualthr" },
2106				{ SIOCSIPHISTO,
2107				  IW_PRIV_TYPE_BYTE | 16,
2108				  0,
2109				  "sethisto" },
2110				{ SIOCGIPHISTO,
2111				  0,
2112				  IW_PRIV_TYPE_INT | 16,
2113				 "gethisto" },
2114			};
2115
2116			/* Set the number of available ioctls. */
2117			wrq->u.data.length = 4;
2118
2119			/* Copy structure to the user buffer. */
2120			wv_splx(lp, &flags);
2121			if (copy_to_user(wrq->u.data.pointer,
2122					      (u8 *) priv,
2123					      sizeof(priv)))
2124				ret = -EFAULT;
2125			wv_splhi(lp, &flags);
2126		}
2127		break;
2128
2129#ifdef WIRELESS_SPY
2130	case SIOCSIWSPY:
2131		/* Set the spy list */
2132
2133		/* Check the number of addresses. */
2134		if (wrq->u.data.length > IW_MAX_SPY) {
2135			ret = -E2BIG;
2136			break;
2137		}
2138		lp->spy_number = wrq->u.data.length;
2139
2140		/* Are there are addresses to copy? */
2141		if (lp->spy_number > 0) {
2142			struct sockaddr address[IW_MAX_SPY];
2143			int i;
2144
2145			/* Copy addresses to the driver. */
2146			wv_splx(lp, &flags);
2147			err = copy_from_user(address,
2148					     wrq->u.data.pointer,
2149					     sizeof(struct sockaddr)
2150					     * lp->spy_number);
2151			wv_splhi(lp, &flags);
2152			if (err) {
2153				ret = -EFAULT;
2154				break;
2155			}
2156
2157			/* Copy addresses to the lp structure. */
2158			for (i = 0; i < lp->spy_number; i++) {
2159				memcpy(lp->spy_address[i],
2160				       address[i].sa_data,
2161				       WAVELAN_ADDR_SIZE);
2162			}
2163
2164			/* Reset structure. */
2165			memset(lp->spy_stat, 0x00,
2166			       sizeof(iw_qual) * IW_MAX_SPY);
2167
2168#ifdef DEBUG_IOCTL_INFO
2169			printk(KERN_DEBUG
2170			       "SetSpy:  set of new addresses is: \n");
2171			for (i = 0; i < wrq->u.data.length; i++)
2172				printk(KERN_DEBUG
2173				       "%02X:%02X:%02X:%02X:%02X:%02X \n",
2174				       lp->spy_address[i][0],
2175				       lp->spy_address[i][1],
2176				       lp->spy_address[i][2],
2177				       lp->spy_address[i][3],
2178				       lp->spy_address[i][4],
2179				       lp->spy_address[i][5]);
2180#endif				/* DEBUG_IOCTL_INFO */
2181		}
2182
2183		break;
2184
2185	case SIOCGIWSPY:
2186		/* Get the spy list and spy stats. */
2187
2188		/* Set the number of addresses */
2189		wrq->u.data.length = lp->spy_number;
2190
2191		/* Does the user want to have the addresses back? */
2192		if ((lp->spy_number > 0)
2193		    && (wrq->u.data.pointer != (caddr_t) 0)) {
2194			struct sockaddr address[IW_MAX_SPY];
2195			int i;
2196
2197			/* Copy addresses from the lp structure. */
2198			for (i = 0; i < lp->spy_number; i++) {
2199				memcpy(address[i].sa_data,
2200				       lp->spy_address[i],
2201				       WAVELAN_ADDR_SIZE);
2202				address[i].sa_family = AF_UNIX;
2203			}
2204
2205			/* Copy addresses to the user buffer. */
2206			wv_splx(lp, &flags);
2207			err = copy_to_user(wrq->u.data.pointer,
2208					   address,
2209					   sizeof(struct sockaddr)
2210					   * lp->spy_number);
2211
2212			/* Copy stats to the user buffer (just after). */
2213			err |= copy_to_user(wrq->u.data.pointer
2214					    + (sizeof(struct sockaddr)
2215					       * lp->spy_number),
2216					    lp->spy_stat,
2217					    sizeof(iw_qual) * lp->spy_number);
2218			wv_splhi(lp, &flags);
2219			if (err) {
2220				ret = -EFAULT;
2221				break;
2222			}
2223
2224			/* Reset updated flags. */
2225			for (i = 0; i < lp->spy_number; i++)
2226				lp->spy_stat[i].updated = 0x0;
2227		}
2228		/* if(pointer != NULL) */
2229		break;
2230#endif				/* WIRELESS_SPY */
2231
2232		/* ------------------ PRIVATE IOCTL ------------------ */
2233
2234	case SIOCSIPQTHR:
2235		if (!capable(CAP_NET_ADMIN)) {
2236			ret = -EPERM;
2237			break;
2238		}
2239		psa.psa_quality_thr = *(wrq->u.name) & 0x0F;
2240		psa_write(ioaddr, lp->hacr,
2241			  (char *) &psa.psa_quality_thr - (char *) &psa,
2242			  (unsigned char *) &psa.psa_quality_thr, 1);
2243		/* update the Wavelan checksum */
2244		update_psa_checksum(dev, ioaddr, lp->hacr);
2245		mmc_out(ioaddr, mmwoff(0, mmw_quality_thr),
2246			psa.psa_quality_thr);
2247		break;
2248
2249	case SIOCGIPQTHR:
2250		psa_read(ioaddr, lp->hacr,
2251			 (char *) &psa.psa_quality_thr - (char *) &psa,
2252			 (unsigned char *) &psa.psa_quality_thr, 1);
2253		*(wrq->u.name) = psa.psa_quality_thr & 0x0F;
2254		break;
2255
2256#ifdef HISTOGRAM
2257	case SIOCSIPHISTO:
2258		/* Verify that the user is root. */
2259		if (!capable(CAP_NET_ADMIN)) {
2260			ret = -EPERM;
2261			break;
2262		}
2263
2264		/* Check the number of intervals. */
2265		if (wrq->u.data.length > 16) {
2266			ret = -E2BIG;
2267			break;
2268		}
2269		lp->his_number = wrq->u.data.length;
2270
2271		/* Are there addresses to copy? */
2272		if (lp->his_number > 0) {
2273			/* Copy interval ranges to the driver */
2274			wv_splx(lp, &flags);
2275			err = copy_from_user(lp->his_range,
2276					     wrq->u.data.pointer,
2277					     sizeof(char) * lp->his_number);
2278			wv_splhi(lp, &flags);
2279			if (err) {
2280				ret = -EFAULT;
2281				break;
2282			}
2283
2284			/* Reset structure. */
2285			memset(lp->his_sum, 0x00, sizeof(long) * 16);
2286		}
2287		break;
2288
2289	case SIOCGIPHISTO:
2290		/* Set the number of intervals. */
2291		wrq->u.data.length = lp->his_number;
2292
2293		/* Give back the distribution statistics */
2294		if ((lp->his_number > 0)
2295		    && (wrq->u.data.pointer != (caddr_t) 0)) {
2296			/* Copy data to the user buffer. */
2297			wv_splx(lp, &flags);
2298			if (copy_to_user(wrq->u.data.pointer,
2299					 lp->his_sum,
2300					 sizeof(long) * lp->his_number);
2301				ret = -EFAULT;
2302			wv_splhi(lp, &flags);
2303
2304		}		/* if(pointer != NULL) */
2305		break;
2306#endif				/* HISTOGRAM */
2307
2308		/* ------------------- OTHER IOCTL ------------------- */
2309
2310	default:
2311		ret = -EOPNOTSUPP;
2312	}	/* switch (cmd) */
2313
2314	/* Enable interrupts and restore flags. */
2315	wv_splx(lp, &flags);
2316
2317#ifdef DEBUG_IOCTL_TRACE
2318	printk(KERN_DEBUG "%s: <-wavelan_ioctl()\n", dev->name);
2319#endif
2320	return ret;
2321}
2322
2323/*------------------------------------------------------------------*/
2324/*
2325 * Get wireless statistics.
2326 * Called by /proc/net/wireless
2327 */
2328static iw_stats *wavelan_get_wireless_stats(device * dev)
2329{
2330	unsigned long ioaddr = dev->base_addr;
2331	net_local *lp = (net_local *) dev->priv;
2332	mmr_t m;
2333	iw_stats *wstats;
2334	unsigned long flags;
2335
2336#ifdef DEBUG_IOCTL_TRACE
2337	printk(KERN_DEBUG "%s: ->wavelan_get_wireless_stats()\n",
2338	       dev->name);
2339#endif
2340
2341	/* Check */
2342	if (lp == (net_local *) NULL)
2343		return (iw_stats *) NULL;
2344
2345	/* Disable interrupts and save flags. */
2346	wv_splhi(lp, &flags);
2347
2348	wstats = &lp->wstats;
2349
2350	/* Get data from the mmc. */
2351	mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
2352
2353	mmc_read(ioaddr, mmroff(0, mmr_dce_status), &m.mmr_dce_status, 1);
2354	mmc_read(ioaddr, mmroff(0, mmr_wrong_nwid_l), &m.mmr_wrong_nwid_l,
2355		 2);
2356	mmc_read(ioaddr, mmroff(0, mmr_thr_pre_set), &m.mmr_thr_pre_set,
2357		 4);
2358
2359	mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
2360
2361	/* Copy data to wireless stuff. */
2362	wstats->status = m.mmr_dce_status & MMR_DCE_STATUS;
2363	wstats->qual.qual = m.mmr_sgnl_qual & MMR_SGNL_QUAL;
2364	wstats->qual.level = m.mmr_signal_lvl & MMR_SIGNAL_LVL;
2365	wstats->qual.noise = m.mmr_silence_lvl & MMR_SILENCE_LVL;
2366	wstats->qual.updated = (((m. mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 7)
2367			| ((m.mmr_signal_lvl & MMR_SIGNAL_LVL_VALID) >> 6)
2368			| ((m.mmr_silence_lvl & MMR_SILENCE_LVL_VALID) >> 5));
2369	wstats->discard.nwid += (m.mmr_wrong_nwid_h << 8) | m.mmr_wrong_nwid_l;
2370	wstats->discard.code = 0L;
2371	wstats->discard.misc = 0L;
2372
2373	/* Enable interrupts and restore flags. */
2374	wv_splx(lp, &flags);
2375
2376#ifdef DEBUG_IOCTL_TRACE
2377	printk(KERN_DEBUG "%s: <-wavelan_get_wireless_stats()\n",
2378	       dev->name);
2379#endif
2380	return &lp->wstats;
2381}
2382#endif				/* WIRELESS_EXT */
2383
2384/************************* PACKET RECEPTION *************************/
2385/*
2386 * This part deals with receiving the packets.
2387 * The interrupt handler gets an interrupt when a packet has been
2388 * successfully received and calls this part.
2389 */
2390
2391/*------------------------------------------------------------------*/
2392/*
2393 * This routine does the actual copying of data (including the Ethernet
2394 * header structure) from the WaveLAN card to an sk_buff chain that
2395 * will be passed up to the network interface layer. NOTE: we
2396 * currently don't handle trailer protocols (neither does the rest of
2397 * the network interface), so if that is needed, it will (at least in
2398 * part) be added here.  The contents of the receive ring buffer are
2399 * copied to a message chain that is then passed to the kernel.
2400 *
2401 * Note: if any errors occur, the packet is "dropped on the floor".
2402 * (called by wv_packet_rcv())
2403 */
2404static inline void
2405wv_packet_read(device * dev, u16 buf_off, int sksize)
2406{
2407	net_local *lp = (net_local *) dev->priv;
2408	unsigned long ioaddr = dev->base_addr;
2409	struct sk_buff *skb;
2410
2411#ifdef DEBUG_RX_TRACE
2412	printk(KERN_DEBUG "%s: ->wv_packet_read(0x%X, %d)\n",
2413	       dev->name, buf_off, sksize);
2414#endif
2415
2416	/* Allocate buffer for the data */
2417	if ((skb = dev_alloc_skb(sksize)) == (struct sk_buff *) NULL) {
2418#ifdef DEBUG_RX_ERROR
2419		printk(KERN_INFO
2420		       "%s: wv_packet_read(): could not alloc_skb(%d, GFP_ATOMIC).\n",
2421		       dev->name, sksize);
2422#endif
2423		lp->stats.rx_dropped++;
2424		return;
2425	}
2426
2427	skb->dev = dev;
2428
2429	/* Copy the packet to the buffer. */
2430	obram_read(ioaddr, buf_off, skb_put(skb, sksize), sksize);
2431	skb->protocol = eth_type_trans(skb, dev);
2432
2433#ifdef DEBUG_RX_INFO
2434	wv_packet_info(skb->mac.raw, sksize, dev->name, "wv_packet_read");
2435#endif				/* DEBUG_RX_INFO */
2436
2437	/* Statistics-gathering and associated stuff.
2438	 * It seem a bit messy with all the define, but it's really simple... */
2439#if defined(WIRELESS_SPY) || defined(HISTOGRAM)
2440	if (
2441#ifdef WIRELESS_SPY
2442		   (lp->spy_number > 0) ||
2443#endif				/* WIRELESS_SPY */
2444#ifdef HISTOGRAM
2445		   (lp->his_number > 0) ||
2446#endif				/* HISTOGRAM */
2447		   0) {
2448		u8 stats[3];	/* signal level, noise level, signal quality */
2449
2450		/* Read signal level, silence level and signal quality bytes. */
2451		/* Note: in the PCMCIA hardware, these are part of the frame.  It seems
2452		 * that for the ISA hardware, it's nowhere to be found in the frame,
2453		 * so I'm obliged to do this (it has a side effect on /proc/net/wireless).
2454		 * Any ideas?
2455		 */
2456		mmc_out(ioaddr, mmwoff(0, mmw_freeze), 1);
2457		mmc_read(ioaddr, mmroff(0, mmr_signal_lvl), stats, 3);
2458		mmc_out(ioaddr, mmwoff(0, mmw_freeze), 0);
2459
2460#ifdef DEBUG_RX_INFO
2461		printk(KERN_DEBUG
2462		       "%s: wv_packet_read(): Signal level %d/63, Silence level %d/63, signal quality %d/16\n",
2463		       dev->name, stats[0] & 0x3F, stats[1] & 0x3F,
2464		       stats[2] & 0x0F);
2465#endif
2466
2467		/* Spying stuff */
2468#ifdef WIRELESS_SPY
2469		wl_spy_gather(dev, skb->mac.raw + WAVELAN_ADDR_SIZE,
2470			      stats);
2471#endif				/* WIRELESS_SPY */
2472#ifdef HISTOGRAM
2473		wl_his_gather(dev, stats);
2474#endif				/* HISTOGRAM */
2475	}
2476#endif				/* defined(WIRELESS_SPY) || defined(HISTOGRAM) */
2477
2478	/*
2479	 * Hand the packet to the network module.
2480	 */
2481	netif_rx(skb);
2482
2483	/* Keep statistics up to date */
2484	dev->last_rx = jiffies;
2485	lp->stats.rx_packets++;
2486	lp->stats.rx_bytes += sksize;
2487
2488#ifdef DEBUG_RX_TRACE
2489	printk(KERN_DEBUG "%s: <-wv_packet_read()\n", dev->name);
2490#endif
2491}
2492
2493/*------------------------------------------------------------------*/
2494/*
2495 * Transfer as many packets as we can
2496 * from the device RAM.
2497 * (called in wavelan_interrupt()).
2498 * Note : the spinlock is already grabbed for us.
2499 */
2500static inline void wv_receive(device * dev)
2501{
2502	unsigned long ioaddr = dev->base_addr;
2503	net_local *lp = (net_local *) dev->priv;
2504	fd_t fd;
2505	rbd_t rbd;
2506	int nreaped = 0;
2507
2508#ifdef DEBUG_RX_TRACE
2509	printk(KERN_DEBUG "%s: ->wv_receive()\n", dev->name);
2510#endif
2511
2512	/* Loop on each received packet. */
2513	for (;;) {
2514		obram_read(ioaddr, lp->rx_head, (unsigned char *) &fd,
2515			   sizeof(fd));
2516
2517		/* Note about the status :
2518		 * It start up to be 0 (the value we set). Then, when the RU
2519		 * grab the buffer to prepare for reception, it sets the
2520		 * FD_STATUS_B flag. When the RU has finished receiving the
2521		 * frame, it clears FD_STATUS_B, set FD_STATUS_C to indicate
2522		 * completion and set the other flags to indicate the eventual
2523		 * errors. FD_STATUS_OK indicates that the reception was OK.
2524		 */
2525
2526		/* If the current frame is not complete, we have reached the end. */
2527		if ((fd.fd_status & FD_STATUS_C) != FD_STATUS_C)
2528			break;	/* This is how we exit the loop. */
2529
2530		nreaped++;
2531
2532		/* Check whether frame was correctly received. */
2533		if ((fd.fd_status & FD_STATUS_OK) == FD_STATUS_OK) {
2534			/* Does the frame contain a pointer to the data?  Let's check. */
2535			if (fd.fd_rbd_offset != I82586NULL) {
2536				/* Read the receive buffer descriptor */
2537				obram_read(ioaddr, fd.fd_rbd_offset,
2538					   (unsigned char *) &rbd,
2539					   sizeof(rbd));
2540
2541#ifdef DEBUG_RX_ERROR
2542				if ((rbd.rbd_status & RBD_STATUS_EOF) !=
2543				    RBD_STATUS_EOF) printk(KERN_INFO
2544							   "%s: wv_receive(): missing EOF flag.\n",
2545							   dev->name);
2546
2547				if ((rbd.rbd_status & RBD_STATUS_F) !=
2548				    RBD_STATUS_F) printk(KERN_INFO
2549							 "%s: wv_receive(): missing F flag.\n",
2550							 dev->name);
2551#endif				/* DEBUG_RX_ERROR */
2552
2553				/* Read the packet and transmit to Linux */
2554				wv_packet_read(dev, rbd.rbd_bufl,
2555					       rbd.
2556					       rbd_status &
2557					       RBD_STATUS_ACNT);
2558			}
2559#ifdef DEBUG_RX_ERROR
2560			else	/* if frame has no data */
2561				printk(KERN_INFO
2562				       "%s: wv_receive(): frame has no data.\n",
2563				       dev->name);
2564#endif
2565		} else {	/* If reception was no successful */
2566
2567			lp->stats.rx_errors++;
2568
2569#ifdef DEBUG_RX_INFO
2570			printk(KERN_DEBUG
2571			       "%s: wv_receive(): frame not received successfully (%X).\n",
2572			       dev->name, fd.fd_status);
2573#endif
2574
2575#ifdef DEBUG_RX_ERROR
2576			if ((fd.fd_status & FD_STATUS_S6) != 0)
2577				printk(KERN_INFO
2578				       "%s: wv_receive(): no EOF flag.\n",
2579				       dev->name);
2580#endif
2581
2582			if ((fd.fd_status & FD_STATUS_S7) != 0) {
2583				lp->stats.rx_length_errors++;
2584#ifdef DEBUG_RX_FAIL
2585				printk(KERN_DEBUG
2586				       "%s: wv_receive(): frame too short.\n",
2587				       dev->name);
2588#endif
2589			}
2590
2591			if ((fd.fd_status & FD_STATUS_S8) != 0) {
2592				lp->stats.rx_over_errors++;
2593#ifdef DEBUG_RX_FAIL
2594				printk(KERN_DEBUG
2595				       "%s: wv_receive(): rx DMA overrun.\n",
2596				       dev->name);
2597#endif
2598			}
2599
2600			if ((fd.fd_status & FD_STATUS_S9) != 0) {
2601				lp->stats.rx_fifo_errors++;
2602#ifdef DEBUG_RX_FAIL
2603				printk(KERN_DEBUG
2604				       "%s: wv_receive(): ran out of resources.\n",
2605				       dev->name);
2606#endif
2607			}
2608
2609			if ((fd.fd_status & FD_STATUS_S10) != 0) {
2610				lp->stats.rx_frame_errors++;
2611#ifdef DEBUG_RX_FAIL
2612				printk(KERN_DEBUG
2613				       "%s: wv_receive(): alignment error.\n",
2614				       dev->name);
2615#endif
2616			}
2617
2618			if ((fd.fd_status & FD_STATUS_S11) != 0) {
2619				lp->stats.rx_crc_errors++;
2620#ifdef DEBUG_RX_FAIL
2621				printk(KERN_DEBUG
2622				       "%s: wv_receive(): CRC error.\n",
2623				       dev->name);
2624#endif
2625			}
2626		}
2627
2628		fd.fd_status = 0;
2629		obram_write(ioaddr, fdoff(lp->rx_head, fd_status),
2630			    (unsigned char *) &fd.fd_status,
2631			    sizeof(fd.fd_status));
2632
2633		fd.fd_command = FD_COMMAND_EL;
2634		obram_write(ioaddr, fdoff(lp->rx_head, fd_command),
2635			    (unsigned char *) &fd.fd_command,
2636			    sizeof(fd.fd_command));
2637
2638		fd.fd_command = 0;
2639		obram_write(ioaddr, fdoff(lp->rx_last, fd_command),
2640			    (unsigned char *) &fd.fd_command,
2641			    sizeof(fd.fd_command));
2642
2643		lp->rx_last = lp->rx_head;
2644		lp->rx_head = fd.fd_link_offset;
2645	}			/* for(;;) -> loop on all frames */
2646
2647#ifdef DEBUG_RX_INFO
2648	if (nreaped > 1)
2649		printk(KERN_DEBUG "%s: wv_receive(): reaped %d\n",
2650		       dev->name, nreaped);
2651#endif
2652#ifdef DEBUG_RX_TRACE
2653	printk(KERN_DEBUG "%s: <-wv_receive()\n", dev->name);
2654#endif
2655}
2656
2657/*********************** PACKET TRANSMISSION ***********************/
2658/*
2659 * This part deals with sending packets through the WaveLAN.
2660 *
2661 */
2662
2663/*------------------------------------------------------------------*/
2664/*
2665 * This routine fills in the appropriate registers and memory
2666 * locations on the WaveLAN card and starts the card off on
2667 * the transmit.
2668 *
2669 * The principle:
2670 * Each block contains a transmit command, a NOP command,
2671 * a transmit block descriptor and a buffer.
2672 * The CU read the transmit block which point to the tbd,
2673 * read the tbd and the content of the buffer.
2674 * When it has finish with it, it goes to the next command
2675 * which in our case is the NOP. The NOP points on itself,
2676 * so the CU stop here.
2677 * When we add the next block, we modify the previous nop
2678 * to make it point on the new tx command.
2679 * Simple, isn't it ?
2680 *
2681 * (called in wavelan_packet_xmit())
2682 */
2683static inline int wv_packet_write(device * dev, void *buf, short length)
2684{
2685	net_local *lp = (net_local *) dev->priv;
2686	unsigned long ioaddr = dev->base_addr;
2687	unsigned short txblock;
2688	unsigned short txpred;
2689	unsigned short tx_addr;
2690	unsigned short nop_addr;
2691	unsigned short tbd_addr;
2692	unsigned short buf_addr;
2693	ac_tx_t tx;
2694	ac_nop_t nop;
2695	tbd_t tbd;
2696	int clen = length;
2697	unsigned long flags;
2698
2699#ifdef DEBUG_TX_TRACE
2700	printk(KERN_DEBUG "%s: ->wv_packet_write(%d)\n", dev->name,
2701	       length);
2702#endif
2703
2704	/* Do we need some padding? */
2705	if (clen < ETH_ZLEN)
2706		clen = ETH_ZLEN;
2707
2708	wv_splhi(lp, &flags);
2709
2710	/* Check nothing bad has happened */
2711	if (lp->tx_n_in_use == (NTXBLOCKS - 1)) {
2712#ifdef DEBUG_TX_ERROR
2713		printk(KERN_INFO "%s: wv_packet_write(): Tx queue full.\n",
2714		       dev->name);
2715#endif
2716		wv_splx(lp, &flags);
2717		return 1;
2718	}
2719
2720	/* Calculate addresses of next block and previous block. */
2721	txblock = lp->tx_first_free;
2722	txpred = txblock - TXBLOCKZ;
2723	if (txpred < OFFSET_CU)
2724		txpred += NTXBLOCKS * TXBLOCKZ;
2725	lp->tx_first_free += TXBLOCKZ;
2726	if (lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
2727		lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
2728
2729	lp->tx_n_in_use++;
2730
2731	/* Calculate addresses of the different parts of the block. */
2732	tx_addr = txblock;
2733	nop_addr = tx_addr + sizeof(tx);
2734	tbd_addr = nop_addr + sizeof(nop);
2735	buf_addr = tbd_addr + sizeof(tbd);
2736
2737	/*
2738	 * Transmit command
2739	 */
2740	tx.tx_h.ac_status = 0;
2741	obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
2742		    (unsigned char *) &tx.tx_h.ac_status,
2743		    sizeof(tx.tx_h.ac_status));
2744
2745	/*
2746	 * NOP command
2747	 */
2748	nop.nop_h.ac_status = 0;
2749	obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
2750		    (unsigned char *) &nop.nop_h.ac_status,
2751		    sizeof(nop.nop_h.ac_status));
2752	nop.nop_h.ac_link = nop_addr;
2753	obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
2754		    (unsigned char *) &nop.nop_h.ac_link,
2755		    sizeof(nop.nop_h.ac_link));
2756
2757	/*
2758	 * Transmit buffer descriptor
2759	 */
2760	tbd.tbd_status = TBD_STATUS_EOF | (TBD_STATUS_ACNT & clen);
2761	tbd.tbd_next_bd_offset = I82586NULL;
2762	tbd.tbd_bufl = buf_addr;
2763	tbd.tbd_bufh = 0;
2764	obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd, sizeof(tbd));
2765
2766	/*
2767	 * Data
2768	 */
2769	obram_write(ioaddr, buf_addr, buf, length);
2770
2771	/*
2772	 * Overwrite the predecessor NOP link
2773	 * so that it points to this txblock.
2774	 */
2775	nop_addr = txpred + sizeof(tx);
2776	nop.nop_h.ac_status = 0;
2777	obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
2778		    (unsigned char *) &nop.nop_h.ac_status,
2779		    sizeof(nop.nop_h.ac_status));
2780	nop.nop_h.ac_link = txblock;
2781	obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
2782		    (unsigned char *) &nop.nop_h.ac_link,
2783		    sizeof(nop.nop_h.ac_link));
2784
2785	/* Make sure the watchdog will keep quiet for a while */
2786	dev->trans_start = jiffies;
2787
2788	/* Keep stats up to date. */
2789	lp->stats.tx_bytes += length;
2790
2791	if (lp->tx_first_in_use == I82586NULL)
2792		lp->tx_first_in_use = txblock;
2793
2794	if (lp->tx_n_in_use < NTXBLOCKS - 1)
2795		netif_wake_queue(dev);
2796
2797	wv_splx(lp, &flags);
2798
2799#ifdef DEBUG_TX_INFO
2800	wv_packet_info((u8 *) buf, length, dev->name,
2801		       "wv_packet_write");
2802#endif				/* DEBUG_TX_INFO */
2803
2804#ifdef DEBUG_TX_TRACE
2805	printk(KERN_DEBUG "%s: <-wv_packet_write()\n", dev->name);
2806#endif
2807
2808	return 0;
2809}
2810
2811/*------------------------------------------------------------------*/
2812/*
2813 * This routine is called when we want to send a packet (NET3 callback)
2814 * In this routine, we check if the harware is ready to accept
2815 * the packet.  We also prevent reentrance.  Then we call the function
2816 * to send the packet.
2817 */
2818static int wavelan_packet_xmit(struct sk_buff *skb, device * dev)
2819{
2820	net_local *lp = (net_local *) dev->priv;
2821	unsigned long flags;
2822
2823#ifdef DEBUG_TX_TRACE
2824	printk(KERN_DEBUG "%s: ->wavelan_packet_xmit(0x%X)\n", dev->name,
2825	       (unsigned) skb);
2826#endif
2827
2828	/*
2829	 * Block a timer-based transmit from overlapping.
2830	 * In other words, prevent reentering this routine.
2831	 */
2832	netif_stop_queue(dev);
2833
2834	/* If somebody has asked to reconfigure the controller,
2835	 * we can do it now.
2836	 */
2837	if (lp->reconfig_82586) {
2838		wv_splhi(lp, &flags);
2839		wv_82586_config(dev);
2840		wv_splx(lp, &flags);
2841		/* Check that we can continue */
2842		if (lp->tx_n_in_use == (NTXBLOCKS - 1))
2843			return 1;
2844	}
2845#ifdef DEBUG_TX_ERROR
2846	if (skb->next)
2847		printk(KERN_INFO "skb has next\n");
2848#endif
2849
2850	/* Write packet on the card */
2851	if(wv_packet_write(dev, skb->data, skb->len))
2852		return 1;	/* We failed */
2853
2854	dev_kfree_skb(skb);
2855
2856#ifdef DEBUG_TX_TRACE
2857	printk(KERN_DEBUG "%s: <-wavelan_packet_xmit()\n", dev->name);
2858#endif
2859	return 0;
2860}
2861
2862/*********************** HARDWARE CONFIGURATION ***********************/
2863/*
2864 * This part does the real job of starting and configuring the hardware.
2865 */
2866
2867/*--------------------------------------------------------------------*/
2868/*
2869 * Routine to initialize the Modem Management Controller.
2870 * (called by wv_hw_reset())
2871 */
2872static inline int wv_mmc_init(device * dev)
2873{
2874	unsigned long ioaddr = dev->base_addr;
2875	net_local *lp = (net_local *) dev->priv;
2876	psa_t psa;
2877	mmw_t m;
2878	int configured;
2879
2880#ifdef DEBUG_CONFIG_TRACE
2881	printk(KERN_DEBUG "%s: ->wv_mmc_init()\n", dev->name);
2882#endif
2883
2884	/* Read the parameter storage area. */
2885	psa_read(ioaddr, lp->hacr, 0, (unsigned char *) &psa, sizeof(psa));
2886
2887#ifdef USE_PSA_CONFIG
2888	configured = psa.psa_conf_status & 1;
2889#else
2890	configured = 0;
2891#endif
2892
2893	/* Is the PSA is not configured */
2894	if (!configured) {
2895		/* User will be able to configure NWID later (with iwconfig). */
2896		psa.psa_nwid[0] = 0;
2897		psa.psa_nwid[1] = 0;
2898
2899		/* no NWID checking since NWID is not set */
2900		psa.psa_nwid_select = 0;
2901
2902		/* Disable encryption */
2903		psa.psa_encryption_select = 0;
2904
2905		/* Set to standard values:
2906		 * 0x04 for AT,
2907		 * 0x01 for MCA,
2908		 * 0x04 for PCMCIA and 2.00 card (AT&T 407-024689/E document)
2909		 */
2910		if (psa.psa_comp_number & 1)
2911			psa.psa_thr_pre_set = 0x01;
2912		else
2913			psa.psa_thr_pre_set = 0x04;
2914		psa.psa_quality_thr = 0x03;
2915
2916		/* It is configured */
2917		psa.psa_conf_status |= 1;
2918
2919#ifdef USE_PSA_CONFIG
2920		/* Write the psa. */
2921		psa_write(ioaddr, lp->hacr,
2922			  (char *) psa.psa_nwid - (char *) &psa,
2923			  (unsigned char *) psa.psa_nwid, 4);
2924		psa_write(ioaddr, lp->hacr,
2925			  (char *) &psa.psa_thr_pre_set - (char *) &psa,
2926			  (unsigned char *) &psa.psa_thr_pre_set, 1);
2927		psa_write(ioaddr, lp->hacr,
2928			  (char *) &psa.psa_quality_thr - (char *) &psa,
2929			  (unsigned char *) &psa.psa_quality_thr, 1);
2930		psa_write(ioaddr, lp->hacr,
2931			  (char *) &psa.psa_conf_status - (char *) &psa,
2932			  (unsigned char *) &psa.psa_conf_status, 1);
2933		/* update the Wavelan checksum */
2934		update_psa_checksum(dev, ioaddr, lp->hacr);
2935#endif
2936	}
2937
2938	/* Zero the mmc structure. */
2939	memset(&m, 0x00, sizeof(m));
2940
2941	/* Copy PSA info to the mmc. */
2942	m.mmw_netw_id_l = psa.psa_nwid[1];
2943	m.mmw_netw_id_h = psa.psa_nwid[0];
2944
2945	if (psa.psa_nwid_select & 1)
2946		m.mmw_loopt_sel = 0x00;
2947	else
2948		m.mmw_loopt_sel = MMW_LOOPT_SEL_DIS_NWID;
2949
2950	memcpy(&m.mmw_encr_key, &psa.psa_encryption_key,
2951	       sizeof(m.mmw_encr_key));
2952
2953	if (psa.psa_encryption_select)
2954		m.mmw_encr_enable =
2955		    MMW_ENCR_ENABLE_EN | MMW_ENCR_ENABLE_MODE;
2956	else
2957		m.mmw_encr_enable = 0;
2958
2959	m.mmw_thr_pre_set = psa.psa_thr_pre_set & 0x3F;
2960	m.mmw_quality_thr = psa.psa_quality_thr & 0x0F;
2961
2962	/*
2963	 * Set default modem control parameters.
2964	 * See NCR document 407-0024326 Rev. A.
2965	 */
2966	m.mmw_jabber_enable = 0x01;
2967	m.mmw_freeze = 0;
2968	m.mmw_anten_sel = MMW_ANTEN_SEL_ALG_EN;
2969	m.mmw_ifs = 0x20;
2970	m.mmw_mod_delay = 0x04;
2971	m.mmw_jam_time = 0x38;
2972
2973	m.mmw_des_io_invert = 0;
2974	m.mmw_decay_prm = 0;
2975	m.mmw_decay_updat_prm = 0;
2976
2977	/* Write all info to MMC. */
2978	mmc_write(ioaddr, 0, (u8 *) & m, sizeof(m));
2979
2980	/* The following code starts the modem of the 2.00 frequency
2981	 * selectable cards at power on.  It's not strictly needed for the
2982	 * following boots.
2983	 * The original patch was by Joe Finney for the PCMCIA driver, but
2984	 * I've cleaned it up a bit and added documentation.
2985	 * Thanks to Loeke Brederveld from Lucent for the info.
2986	 */
2987
2988	/* Attempt to recognise 2.00 cards (2.4 GHz frequency selectable)
2989	 * Does it work for everybody, especially old cards? */
2990	/* Note: WFREQSEL verifies that it is able to read a sensible
2991	 * frequency from EEPROM (address 0x00) and that MMR_FEE_STATUS_ID
2992	 * is 0xA (Xilinx version) or 0xB (Ariadne version).
2993	 * My test is more crude but does work. */
2994	if (!(mmc_in(ioaddr, mmroff(0, mmr_fee_status)) &
2995	      (MMR_FEE_STATUS_DWLD | MMR_FEE_STATUS_BUSY))) {
2996		/* We must download the frequency parameters to the
2997		 * synthesizers (from the EEPROM - area 1)
2998		 * Note: as the EEPROM is automatically decremented, we set the end
2999		 * if the area... */
3000		m.mmw_fee_addr = 0x0F;
3001		m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3002		mmc_write(ioaddr, (char *) &m.mmw_fee_ctrl - (char *) &m,
3003			  (unsigned char *) &m.mmw_fee_ctrl, 2);
3004
3005		/* Wait until the download is finished. */
3006		fee_wait(ioaddr, 100, 100);
3007
3008#ifdef DEBUG_CONFIG_INFO
3009		/* The frequency was in the last word downloaded. */
3010		mmc_read(ioaddr, (char *) &m.mmw_fee_data_l - (char *) &m,
3011			 (unsigned char *) &m.mmw_fee_data_l, 2);
3012
3013		/* Print some info for the user. */
3014		printk(KERN_DEBUG
3015		       "%s: WaveLAN 2.00 recognised (frequency select).  Current frequency = %ld\n",
3016		       dev->name,
3017		       ((m.
3018			 mmw_fee_data_h << 4) | (m.mmw_fee_data_l >> 4)) *
3019		       5 / 2 + 24000L);
3020#endif
3021
3022		/* We must now download the power adjust value (gain) to
3023		 * the synthesizers (from the EEPROM - area 7 - DAC). */
3024		m.mmw_fee_addr = 0x61;
3025		m.mmw_fee_ctrl = MMW_FEE_CTRL_READ | MMW_FEE_CTRL_DWLD;
3026		mmc_write(ioaddr, (char *) &m.mmw_fee_ctrl - (char *) &m,
3027			  (unsigned char *) &m.mmw_fee_ctrl, 2);
3028
3029		/* Wait until the download is finished. */
3030	}
3031	/* if 2.00 card */
3032#ifdef DEBUG_CONFIG_TRACE
3033	printk(KERN_DEBUG "%s: <-wv_mmc_init()\n", dev->name);
3034#endif
3035	return 0;
3036}
3037
3038/*------------------------------------------------------------------*/
3039/*
3040 * Construct the fd and rbd structures.
3041 * Start the receive unit.
3042 * (called by wv_hw_reset())
3043 */
3044static inline int wv_ru_start(device * dev)
3045{
3046	net_local *lp = (net_local *) dev->priv;
3047	unsigned long ioaddr = dev->base_addr;
3048	u16 scb_cs;
3049	fd_t fd;
3050	rbd_t rbd;
3051	u16 rx;
3052	u16 rx_next;
3053	int i;
3054
3055#ifdef DEBUG_CONFIG_TRACE
3056	printk(KERN_DEBUG "%s: ->wv_ru_start()\n", dev->name);
3057#endif
3058
3059	obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
3060		   (unsigned char *) &scb_cs, sizeof(scb_cs));
3061	if ((scb_cs & SCB_ST_RUS) == SCB_ST_RUS_RDY)
3062		return 0;
3063
3064	lp->rx_head = OFFSET_RU;
3065
3066	for (i = 0, rx = lp->rx_head; i < NRXBLOCKS; i++, rx = rx_next) {
3067		rx_next =
3068		    (i == NRXBLOCKS - 1) ? lp->rx_head : rx + RXBLOCKZ;
3069
3070		fd.fd_status = 0;
3071		fd.fd_command = (i == NRXBLOCKS - 1) ? FD_COMMAND_EL : 0;
3072		fd.fd_link_offset = rx_next;
3073		fd.fd_rbd_offset = rx + sizeof(fd);
3074		obram_write(ioaddr, rx, (unsigned char *) &fd, sizeof(fd));
3075
3076		rbd.rbd_status = 0;
3077		rbd.rbd_next_rbd_offset = I82586NULL;
3078		rbd.rbd_bufl = rx + sizeof(fd) + sizeof(rbd);
3079		rbd.rbd_bufh = 0;
3080		rbd.rbd_el_size = RBD_EL | (RBD_SIZE & MAXDATAZ);
3081		obram_write(ioaddr, rx + sizeof(fd),
3082			    (unsigned char *) &rbd, sizeof(rbd));
3083
3084		lp->rx_last = rx;
3085	}
3086
3087	obram_write(ioaddr, scboff(OFFSET_SCB, scb_rfa_offset),
3088		    (unsigned char *) &lp->rx_head, sizeof(lp->rx_head));
3089
3090	scb_cs = SCB_CMD_RUC_GO;
3091	obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3092		    (unsigned char *) &scb_cs, sizeof(scb_cs));
3093
3094	set_chan_attn(ioaddr, lp->hacr);
3095
3096	for (i = 1000; i > 0; i--) {
3097		obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
3098			   (unsigned char *) &scb_cs, sizeof(scb_cs));
3099		if (scb_cs == 0)
3100			break;
3101
3102		udelay(10);
3103	}
3104
3105	if (i <= 0) {
3106#ifdef DEBUG_CONFIG_ERROR
3107		printk(KERN_INFO
3108		       "%s: wavelan_ru_start(): board not accepting command.\n",
3109		       dev->name);
3110#endif
3111		return -1;
3112	}
3113#ifdef DEBUG_CONFIG_TRACE
3114	printk(KERN_DEBUG "%s: <-wv_ru_start()\n", dev->name);
3115#endif
3116	return 0;
3117}
3118
3119/*------------------------------------------------------------------*/
3120/*
3121 * Initialise the transmit blocks.
3122 * Start the command unit executing the NOP
3123 * self-loop of the first transmit block.
3124 *
3125 * Here we create the list of send buffers used to transmit packets
3126 * between the PC and the command unit. For each buffer, we create a
3127 * buffer descriptor (pointing on the buffer), a transmit command
3128 * (pointing to the buffer descriptor) and a NOP command.
3129 * The transmit command is linked to the NOP, and the NOP to itself.
3130 * When we will have finished executing the transmit command, we will
3131 * then loop on the NOP. By releasing the NOP link to a new command,
3132 * we may send another buffer.
3133 *
3134 * (called by wv_hw_reset())
3135 */
3136static inline int wv_cu_start(device * dev)
3137{
3138	net_local *lp = (net_local *) dev->priv;
3139	unsigned long ioaddr = dev->base_addr;
3140	int i;
3141	u16 txblock;
3142	u16 first_nop;
3143	u16 scb_cs;
3144
3145#ifdef DEBUG_CONFIG_TRACE
3146	printk(KERN_DEBUG "%s: ->wv_cu_start()\n", dev->name);
3147#endif
3148
3149	lp->tx_first_free = OFFSET_CU;
3150	lp->tx_first_in_use = I82586NULL;
3151
3152	for (i = 0, txblock = OFFSET_CU;
3153	     i < NTXBLOCKS; i++, txblock += TXBLOCKZ) {
3154		ac_tx_t tx;
3155		ac_nop_t nop;
3156		tbd_t tbd;
3157		unsigned short tx_addr;
3158		unsigned short nop_addr;
3159		unsigned short tbd_addr;
3160		unsigned short buf_addr;
3161
3162		tx_addr = txblock;
3163		nop_addr = tx_addr + sizeof(tx);
3164		tbd_addr = nop_addr + sizeof(nop);
3165		buf_addr = tbd_addr + sizeof(tbd);
3166
3167		tx.tx_h.ac_status = 0;
3168		tx.tx_h.ac_command = acmd_transmit | AC_CFLD_I;
3169		tx.tx_h.ac_link = nop_addr;
3170		tx.tx_tbd_offset = tbd_addr;
3171		obram_write(ioaddr, tx_addr, (unsigned char *) &tx,
3172			    sizeof(tx));
3173
3174		nop.nop_h.ac_status = 0;
3175		nop.nop_h.ac_command = acmd_nop;
3176		nop.nop_h.ac_link = nop_addr;
3177		obram_write(ioaddr, nop_addr, (unsigned char *) &nop,
3178			    sizeof(nop));
3179
3180		tbd.tbd_status = TBD_STATUS_EOF;
3181		tbd.tbd_next_bd_offset = I82586NULL;
3182		tbd.tbd_bufl = buf_addr;
3183		tbd.tbd_bufh = 0;
3184		obram_write(ioaddr, tbd_addr, (unsigned char *) &tbd,
3185			    sizeof(tbd));
3186	}
3187
3188	first_nop =
3189	    OFFSET_CU + (NTXBLOCKS - 1) * TXBLOCKZ + sizeof(ac_tx_t);
3190	obram_write(ioaddr, scboff(OFFSET_SCB, scb_cbl_offset),
3191		    (unsigned char *) &first_nop, sizeof(first_nop));
3192
3193	scb_cs = SCB_CMD_CUC_GO;
3194	obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3195		    (unsigned char *) &scb_cs, sizeof(scb_cs));
3196
3197	set_chan_attn(ioaddr, lp->hacr);
3198
3199	for (i = 1000; i > 0; i--) {
3200		obram_read(ioaddr, scboff(OFFSET_SCB, scb_command),
3201			   (unsigned char *) &scb_cs, sizeof(scb_cs));
3202		if (scb_cs == 0)
3203			break;
3204
3205		udelay(10);
3206	}
3207
3208	if (i <= 0) {
3209#ifdef DEBUG_CONFIG_ERROR
3210		printk(KERN_INFO
3211		       "%s: wavelan_cu_start(): board not accepting command.\n",
3212		       dev->name);
3213#endif
3214		return -1;
3215	}
3216
3217	lp->tx_n_in_use = 0;
3218	netif_start_queue(dev);
3219#ifdef DEBUG_CONFIG_TRACE
3220	printk(KERN_DEBUG "%s: <-wv_cu_start()\n", dev->name);
3221#endif
3222	return 0;
3223}
3224
3225/*------------------------------------------------------------------*/
3226/*
3227 * This routine does a standard configuration of the WaveLAN
3228 * controller (i82586).
3229 *
3230 * It initialises the scp, iscp and scb structure
3231 * The first two are just pointers to the next.
3232 * The last one is used for basic configuration and for basic
3233 * communication (interrupt status).
3234 *
3235 * (called by wv_hw_reset())
3236 */
3237static inline int wv_82586_start(device * dev)
3238{
3239	net_local *lp = (net_local *) dev->priv;
3240	unsigned long ioaddr = dev->base_addr;
3241	scp_t scp;		/* system configuration pointer */
3242	iscp_t iscp;		/* intermediate scp */
3243	scb_t scb;		/* system control block */
3244	ach_t cb;		/* Action command header */
3245	u8 zeroes[512];
3246	int i;
3247
3248#ifdef DEBUG_CONFIG_TRACE
3249	printk(KERN_DEBUG "%s: ->wv_82586_start()\n", dev->name);
3250#endif
3251
3252	/*
3253	 * Clear the onboard RAM.
3254	 */
3255	memset(&zeroes[0], 0x00, sizeof(zeroes));
3256	for (i = 0; i < I82586_MEMZ; i += sizeof(zeroes))
3257		obram_write(ioaddr, i, &zeroes[0], sizeof(zeroes));
3258
3259	/*
3260	 * Construct the command unit structures:
3261	 * scp, iscp, scb, cb.
3262	 */
3263	memset(&scp, 0x00, sizeof(scp));
3264	scp.scp_sysbus = SCP_SY_16BBUS;
3265	scp.scp_iscpl = OFFSET_ISCP;
3266	obram_write(ioaddr, OFFSET_SCP, (unsigned char *) &scp,
3267		    sizeof(scp));
3268
3269	memset(&iscp, 0x00, sizeof(iscp));
3270	iscp.iscp_busy = 1;
3271	iscp.iscp_offset = OFFSET_SCB;
3272	obram_write(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp,
3273		    sizeof(iscp));
3274
3275	/* Our first command is to reset the i82586. */
3276	memset(&scb, 0x00, sizeof(scb));
3277	scb.scb_command = SCB_CMD_RESET;
3278	scb.scb_cbl_offset = OFFSET_CU;
3279	scb.scb_rfa_offset = OFFSET_RU;
3280	obram_write(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
3281		    sizeof(scb));
3282
3283	set_chan_attn(ioaddr, lp->hacr);
3284
3285	/* Wait for command to finish. */
3286	for (i = 1000; i > 0; i--) {
3287		obram_read(ioaddr, OFFSET_ISCP, (unsigned char *) &iscp,
3288			   sizeof(iscp));
3289
3290		if (iscp.iscp_busy == (unsigned short) 0)
3291			break;
3292
3293		udelay(10);
3294	}
3295
3296	if (i <= 0) {
3297#ifdef DEBUG_CONFIG_ERROR
3298		printk(KERN_INFO
3299		       "%s: wv_82586_start(): iscp_busy timeout.\n",
3300		       dev->name);
3301#endif
3302		return -1;
3303	}
3304
3305	/* Check command completion. */
3306	for (i = 15; i > 0; i--) {
3307		obram_read(ioaddr, OFFSET_SCB, (unsigned char *) &scb,
3308			   sizeof(scb));
3309
3310		if (scb.scb_status == (SCB_ST_CX | SCB_ST_CNA))
3311			break;
3312
3313		udelay(10);
3314	}
3315
3316	if (i <= 0) {
3317#ifdef DEBUG_CONFIG_ERROR
3318		printk(KERN_INFO
3319		       "%s: wv_82586_start(): status: expected 0x%02x, got 0x%02x.\n",
3320		       dev->name, SCB_ST_CX | SCB_ST_CNA, scb.scb_status);
3321#endif
3322		return -1;
3323	}
3324
3325	wv_ack(dev);
3326
3327	/* Set the action command header. */
3328	memset(&cb, 0x00, sizeof(cb));
3329	cb.ac_command = AC_CFLD_EL | (AC_CFLD_CMD & acmd_diagnose);
3330	cb.ac_link = OFFSET_CU;
3331	obram_write(ioaddr, OFFSET_CU, (unsigned char *) &cb, sizeof(cb));
3332
3333	if (wv_synchronous_cmd(dev, "diag()") == -1)
3334		return -1;
3335
3336	obram_read(ioaddr, OFFSET_CU, (unsigned char *) &cb, sizeof(cb));
3337	if (cb.ac_status & AC_SFLD_FAIL) {
3338#ifdef DEBUG_CONFIG_ERROR
3339		printk(KERN_INFO
3340		       "%s: wv_82586_start(): i82586 Self Test failed.\n",
3341		       dev->name);
3342#endif
3343		return -1;
3344	}
3345#ifdef DEBUG_I82586_SHOW
3346	wv_scb_show(ioaddr);
3347#endif
3348
3349#ifdef DEBUG_CONFIG_TRACE
3350	printk(KERN_DEBUG "%s: <-wv_82586_start()\n", dev->name);
3351#endif
3352	return 0;
3353}
3354
3355/*------------------------------------------------------------------*/
3356/*
3357 * This routine does a standard configuration of the WaveLAN
3358 * controller (i82586).
3359 *
3360 * This routine is a violent hack. We use the first free transmit block
3361 * to make our configuration. In the buffer area, we create the three
3362 * configuration commands (linked). We make the previous NOP point to
3363 * the beginning of the buffer instead of the tx command. After, we go
3364 * as usual to the NOP command.
3365 * Note that only the last command (mc_set) will generate an interrupt.
3366 *
3367 * (called by wv_hw_reset(), wv_82586_reconfig(), wavelan_packet_xmit())
3368 */
3369static void wv_82586_config(device * dev)
3370{
3371	net_local *lp = (net_local *) dev->priv;
3372	unsigned long ioaddr = dev->base_addr;
3373	unsigned short txblock;
3374	unsigned short txpred;
3375	unsigned short tx_addr;
3376	unsigned short nop_addr;
3377	unsigned short tbd_addr;
3378	unsigned short cfg_addr;
3379	unsigned short ias_addr;
3380	unsigned short mcs_addr;
3381	ac_tx_t tx;
3382	ac_nop_t nop;
3383	ac_cfg_t cfg;		/* Configure action */
3384	ac_ias_t ias;		/* IA-setup action */
3385	ac_mcs_t mcs;		/* Multicast setup */
3386	struct dev_mc_list *dmi;
3387
3388#ifdef DEBUG_CONFIG_TRACE
3389	printk(KERN_DEBUG "%s: ->wv_82586_config()\n", dev->name);
3390#endif
3391
3392	/* Check nothing bad has happened */
3393	if (lp->tx_n_in_use == (NTXBLOCKS - 1)) {
3394#ifdef DEBUG_CONFIG_ERROR
3395		printk(KERN_INFO "%s: wv_82586_config(): Tx queue full.\n",
3396		       dev->name);
3397#endif
3398		return;
3399	}
3400
3401	/* Calculate addresses of next block and previous block. */
3402	txblock = lp->tx_first_free;
3403	txpred = txblock - TXBLOCKZ;
3404	if (txpred < OFFSET_CU)
3405		txpred += NTXBLOCKS * TXBLOCKZ;
3406	lp->tx_first_free += TXBLOCKZ;
3407	if (lp->tx_first_free >= OFFSET_CU + NTXBLOCKS * TXBLOCKZ)
3408		lp->tx_first_free -= NTXBLOCKS * TXBLOCKZ;
3409
3410	lp->tx_n_in_use++;
3411
3412	/* Calculate addresses of the different parts of the block. */
3413	tx_addr = txblock;
3414	nop_addr = tx_addr + sizeof(tx);
3415	tbd_addr = nop_addr + sizeof(nop);
3416	cfg_addr = tbd_addr + sizeof(tbd_t);	/* beginning of the buffer */
3417	ias_addr = cfg_addr + sizeof(cfg);
3418	mcs_addr = ias_addr + sizeof(ias);
3419
3420	/*
3421	 * Transmit command
3422	 */
3423	tx.tx_h.ac_status = 0xFFFF;	/* Fake completion value */
3424	obram_write(ioaddr, toff(ac_tx_t, tx_addr, tx_h.ac_status),
3425		    (unsigned char *) &tx.tx_h.ac_status,
3426		    sizeof(tx.tx_h.ac_status));
3427
3428	/*
3429	 * NOP command
3430	 */
3431	nop.nop_h.ac_status = 0;
3432	obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
3433		    (unsigned char *) &nop.nop_h.ac_status,
3434		    sizeof(nop.nop_h.ac_status));
3435	nop.nop_h.ac_link = nop_addr;
3436	obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
3437		    (unsigned char *) &nop.nop_h.ac_link,
3438		    sizeof(nop.nop_h.ac_link));
3439
3440	/* Create a configure action. */
3441	memset(&cfg, 0x00, sizeof(cfg));
3442
3443	/*
3444	 * For Linux we invert AC_CFG_ALOC() so as to conform
3445	 * to the way that net packets reach us from above.
3446	 * (See also ac_tx_t.)
3447	 *
3448	 * Updated from Wavelan Manual WCIN085B
3449	 */
3450	cfg.cfg_byte_cnt =
3451	    AC_CFG_BYTE_CNT(sizeof(ac_cfg_t) - sizeof(ach_t));
3452	cfg.cfg_fifolim = AC_CFG_FIFOLIM(4);
3453	cfg.cfg_byte8 = AC_CFG_SAV_BF(1) | AC_CFG_SRDY(0);
3454	cfg.cfg_byte9 = AC_CFG_ELPBCK(0) |
3455	    AC_CFG_ILPBCK(0) |
3456	    AC_CFG_PRELEN(AC_CFG_PLEN_2) |
3457	    AC_CFG_ALOC(1) | AC_CFG_ADDRLEN(WAVELAN_ADDR_SIZE);
3458	cfg.cfg_byte10 = AC_CFG_BOFMET(1) |
3459	    AC_CFG_ACR(6) | AC_CFG_LINPRIO(0);
3460	cfg.cfg_ifs = 0x20;
3461	cfg.cfg_slotl = 0x0C;
3462	cfg.cfg_byte13 = AC_CFG_RETRYNUM(15) | AC_CFG_SLTTMHI(0);
3463	cfg.cfg_byte14 = AC_CFG_FLGPAD(0) |
3464	    AC_CFG_BTSTF(0) |
3465	    AC_CFG_CRC16(0) |
3466	    AC_CFG_NCRC(0) |
3467	    AC_CFG_TNCRS(1) |
3468	    AC_CFG_MANCH(0) |
3469	    AC_CFG_BCDIS(0) | AC_CFG_PRM(lp->promiscuous);
3470	cfg.cfg_byte15 = AC_CFG_ICDS(0) |
3471	    AC_CFG_CDTF(0) | AC_CFG_ICSS(0) | AC_CFG_CSTF(0);
3472/*
3473  cfg.cfg_min_frm_len = AC_CFG_MNFRM(64);
3474*/
3475	cfg.cfg_min_frm_len = AC_CFG_MNFRM(8);
3476
3477	cfg.cfg_h.ac_command = (AC_CFLD_CMD & acmd_configure);
3478	cfg.cfg_h.ac_link = ias_addr;
3479	obram_write(ioaddr, cfg_addr, (unsigned char *) &cfg, sizeof(cfg));
3480
3481	/* Set up the MAC address */
3482	memset(&ias, 0x00, sizeof(ias));
3483	ias.ias_h.ac_command = (AC_CFLD_CMD & acmd_ia_setup);
3484	ias.ias_h.ac_link = mcs_addr;
3485	memcpy(&ias.ias_addr[0], (unsigned char *) &dev->dev_addr[0],
3486	       sizeof(ias.ias_addr));
3487	obram_write(ioaddr, ias_addr, (unsigned char *) &ias, sizeof(ias));
3488
3489	/* Initialize adapter's Ethernet multicast addresses */
3490	memset(&mcs, 0x00, sizeof(mcs));
3491	mcs.mcs_h.ac_command = AC_CFLD_I | (AC_CFLD_CMD & acmd_mc_setup);
3492	mcs.mcs_h.ac_link = nop_addr;
3493	mcs.mcs_cnt = WAVELAN_ADDR_SIZE * lp->mc_count;
3494	obram_write(ioaddr, mcs_addr, (unsigned char *) &mcs, sizeof(mcs));
3495
3496	/* Any address to set? */
3497	if (lp->mc_count) {
3498		for (dmi = dev->mc_list; dmi; dmi = dmi->next)
3499			outsw(PIOP1(ioaddr), (u16 *) dmi->dmi_addr,
3500			      WAVELAN_ADDR_SIZE >> 1);
3501
3502#ifdef DEBUG_CONFIG_INFO
3503		printk(KERN_DEBUG
3504		       "%s: wv_82586_config(): set %d multicast addresses:\n",
3505		       dev->name, lp->mc_count);
3506		for (dmi = dev->mc_list; dmi; dmi = dmi->next)
3507			printk(KERN_DEBUG
3508			       " %02x:%02x:%02x:%02x:%02x:%02x\n",
3509			       dmi->dmi_addr[0], dmi->dmi_addr[1],
3510			       dmi->dmi_addr[2], dmi->dmi_addr[3],
3511			       dmi->dmi_addr[4], dmi->dmi_addr[5]);
3512#endif
3513	}
3514
3515	/*
3516	 * Overwrite the predecessor NOP link
3517	 * so that it points to the configure action.
3518	 */
3519	nop_addr = txpred + sizeof(tx);
3520	nop.nop_h.ac_status = 0;
3521	obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_status),
3522		    (unsigned char *) &nop.nop_h.ac_status,
3523		    sizeof(nop.nop_h.ac_status));
3524	nop.nop_h.ac_link = cfg_addr;
3525	obram_write(ioaddr, toff(ac_nop_t, nop_addr, nop_h.ac_link),
3526		    (unsigned char *) &nop.nop_h.ac_link,
3527		    sizeof(nop.nop_h.ac_link));
3528
3529	/* Job done, clear the flag */
3530	lp->reconfig_82586 = 0;
3531
3532	if (lp->tx_first_in_use == I82586NULL)
3533		lp->tx_first_in_use = txblock;
3534
3535	if (lp->tx_n_in_use == (NTXBLOCKS - 1))
3536		netif_stop_queue(dev);
3537
3538#ifdef DEBUG_CONFIG_TRACE
3539	printk(KERN_DEBUG "%s: <-wv_82586_config()\n", dev->name);
3540#endif
3541}
3542
3543/*------------------------------------------------------------------*/
3544/*
3545 * This routine, called by wavelan_close(), gracefully stops the
3546 * WaveLAN controller (i82586).
3547 * (called by wavelan_close())
3548 */
3549static inline void wv_82586_stop(device * dev)
3550{
3551	net_local *lp = (net_local *) dev->priv;
3552	unsigned long ioaddr = dev->base_addr;
3553	u16 scb_cmd;
3554
3555#ifdef DEBUG_CONFIG_TRACE
3556	printk(KERN_DEBUG "%s: ->wv_82586_stop()\n", dev->name);
3557#endif
3558
3559	/* Suspend both command unit and receive unit. */
3560	scb_cmd =
3561	    (SCB_CMD_CUC & SCB_CMD_CUC_SUS) | (SCB_CMD_RUC &
3562					       SCB_CMD_RUC_SUS);
3563	obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3564		    (unsigned char *) &scb_cmd, sizeof(scb_cmd));
3565	set_chan_attn(ioaddr, lp->hacr);
3566
3567	/* No more interrupts */
3568	wv_ints_off(dev);
3569
3570#ifdef DEBUG_CONFIG_TRACE
3571	printk(KERN_DEBUG "%s: <-wv_82586_stop()\n", dev->name);
3572#endif
3573}
3574
3575/*------------------------------------------------------------------*/
3576/*
3577 * Totally reset the WaveLAN and restart it.
3578 * Performs the following actions:
3579 *	1. A power reset (reset DMA)
3580 *	2. Initialize the radio modem (using wv_mmc_init)
3581 *	3. Reset & Configure LAN controller (using wv_82586_start)
3582 *	4. Start the LAN controller's command unit
3583 *	5. Start the LAN controller's receive unit
3584 * (called by wavelan_interrupt(), wavelan_watchdog() & wavelan_open())
3585 */
3586static int wv_hw_reset(device * dev)
3587{
3588	net_local *lp = (net_local *) dev->priv;
3589	unsigned long ioaddr = dev->base_addr;
3590
3591#ifdef DEBUG_CONFIG_TRACE
3592	printk(KERN_DEBUG "%s: ->wv_hw_reset(dev=0x%x)\n", dev->name,
3593	       (unsigned int) dev);
3594#endif
3595
3596	/* Increase the number of resets done. */
3597	lp->nresets++;
3598
3599	wv_hacr_reset(ioaddr);
3600	lp->hacr = HACR_DEFAULT;
3601
3602	if ((wv_mmc_init(dev) < 0) || (wv_82586_start(dev) < 0))
3603		return -1;
3604
3605	/* Enable the card to send interrupts. */
3606	wv_ints_on(dev);
3607
3608	/* Start card functions */
3609	if (wv_cu_start(dev) < 0)
3610		return -1;
3611
3612	/* Setup the controller and parameters */
3613	wv_82586_config(dev);
3614
3615	/* Finish configuration with the receive unit */
3616	if (wv_ru_start(dev) < 0)
3617		return -1;
3618
3619#ifdef DEBUG_CONFIG_TRACE
3620	printk(KERN_DEBUG "%s: <-wv_hw_reset()\n", dev->name);
3621#endif
3622	return 0;
3623}
3624
3625/*------------------------------------------------------------------*/
3626/*
3627 * Check if there is a WaveLAN at the specific base address.
3628 * As a side effect, this reads the MAC address.
3629 * (called in wavelan_probe() and init_module())
3630 */
3631static int wv_check_ioaddr(unsigned long ioaddr, u8 * mac)
3632{
3633	int i;			/* Loop counter */
3634
3635	/* Check if the base address if available. */
3636	if (check_region(ioaddr, sizeof(ha_t)))
3637		return -EADDRINUSE;	/* ioaddr already used */
3638
3639	/* Reset host interface */
3640	wv_hacr_reset(ioaddr);
3641
3642	/* Read the MAC address from the parameter storage area. */
3643	psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_univ_mac_addr),
3644		 mac, 6);
3645
3646	/*
3647	 * Check the first three octets of the address for the manufacturer's code.
3648	 * Note: if this can't find your WaveLAN card, you've got a
3649	 * non-NCR/AT&T/Lucent ISA card.  See wavelan.p.h for detail on
3650	 * how to configure your card.
3651	 */
3652	for (i = 0; i < (sizeof(MAC_ADDRESSES) / sizeof(char) / 3); i++)
3653		if ((mac[0] == MAC_ADDRESSES[i][0]) &&
3654		    (mac[1] == MAC_ADDRESSES[i][1]) &&
3655		    (mac[2] == MAC_ADDRESSES[i][2]))
3656			return 0;
3657
3658#ifdef DEBUG_CONFIG_INFO
3659	printk(KERN_WARNING
3660	       "WaveLAN (0x%3X): your MAC address might be %02X:%02X:%02X.\n",
3661	       ioaddr, mac[0], mac[1], mac[2]);
3662#endif
3663	return -ENODEV;
3664}
3665
3666/************************ INTERRUPT HANDLING ************************/
3667
3668/*
3669 * This function is the interrupt handler for the WaveLAN card. This
3670 * routine will be called whenever:
3671 */
3672static void wavelan_interrupt(int irq, void *dev_id, struct pt_regs *regs)
3673{
3674	device *dev;
3675	unsigned long ioaddr;
3676	net_local *lp;
3677	u16 hasr;
3678	u16 status;
3679	u16 ack_cmd;
3680
3681	dev = dev_id;
3682
3683#ifdef DEBUG_INTERRUPT_TRACE
3684	printk(KERN_DEBUG "%s: ->wavelan_interrupt()\n", dev->name);
3685#endif
3686
3687	lp = (net_local *) dev->priv;
3688	ioaddr = dev->base_addr;
3689
3690#ifdef DEBUG_INTERRUPT_INFO
3691	/* Check state of our spinlock */
3692	if(spin_is_locked(&lp->spinlock))
3693		printk(KERN_DEBUG
3694		       "%s: wavelan_interrupt(): spinlock is already locked !!!\n",
3695		       dev->name);
3696#endif
3697
3698	/* Prevent reentrancy. We need to do that because we may have
3699	 * multiple interrupt handler running concurrently.
3700	 * It is safe because wv_splhi() disables interrupts before acquiring
3701	 * the spinlock. */
3702	spin_lock(&lp->spinlock);
3703
3704	/* Check modem interrupt */
3705	if ((hasr = hasr_read(ioaddr)) & HASR_MMC_INTR) {
3706		u8 dce_status;
3707
3708		/*
3709		 * Interrupt from the modem management controller.
3710		 * This will clear it -- ignored for now.
3711		 */
3712		mmc_read(ioaddr, mmroff(0, mmr_dce_status), &dce_status,
3713			 sizeof(dce_status));
3714#ifdef DEBUG_INTERRUPT_ERROR
3715		printk(KERN_INFO
3716		       "%s: wavelan_interrupt(): unexpected mmc interrupt: status 0x%04x.\n",
3717		       dev->name, dce_status);
3718#endif
3719	}
3720
3721	/* Check if not controller interrupt */
3722	if ((hasr & HASR_82586_INTR) == 0) {
3723#ifdef DEBUG_INTERRUPT_ERROR
3724		printk(KERN_INFO
3725		       "%s: wavelan_interrupt(): interrupt not coming from i82586\n",
3726		       dev->name);
3727#endif
3728		spin_unlock (&lp->spinlock);
3729		return;
3730	}
3731
3732	/* Read interrupt data. */
3733	obram_read(ioaddr, scboff(OFFSET_SCB, scb_status),
3734		   (unsigned char *) &status, sizeof(status));
3735
3736	/*
3737	 * Acknowledge the interrupt(s).
3738	 */
3739	ack_cmd = status & SCB_ST_INT;
3740	obram_write(ioaddr, scboff(OFFSET_SCB, scb_command),
3741		    (unsigned char *) &ack_cmd, sizeof(ack_cmd));
3742	set_chan_attn(ioaddr, lp->hacr);
3743
3744#ifdef DEBUG_INTERRUPT_INFO
3745	printk(KERN_DEBUG "%s: wavelan_interrupt(): status 0x%04x.\n",
3746	       dev->name, status);
3747#endif
3748
3749	/* Command completed. */
3750	if ((status & SCB_ST_CX) == SCB_ST_CX) {
3751#ifdef DEBUG_INTERRUPT_INFO
3752		printk(KERN_DEBUG
3753		       "%s: wavelan_interrupt(): command completed.\n",
3754		       dev->name);
3755#endif
3756		wv_complete(dev, ioaddr, lp);
3757	}
3758
3759	/* Frame received. */
3760	if ((status & SCB_ST_FR) == SCB_ST_FR) {
3761#ifdef DEBUG_INTERRUPT_INFO
3762		printk(KERN_DEBUG
3763		       "%s: wavelan_interrupt(): received packet.\n",
3764		       dev->name);
3765#endif
3766		wv_receive(dev);
3767	}
3768
3769	/* Check the state of the command unit. */
3770	if (((status & SCB_ST_CNA) == SCB_ST_CNA) ||
3771	    (((status & SCB_ST_CUS) != SCB_ST_CUS_ACTV) &&
3772	     (netif_running(dev)))) {
3773#ifdef DEBUG_INTERRUPT_ERROR
3774		printk(KERN_INFO
3775		       "%s: wavelan_interrupt(): CU inactive -- restarting\n",
3776		       dev->name);
3777#endif
3778		wv_hw_reset(dev);
3779	}
3780
3781	/* Check the state of the command unit. */
3782	if (((status & SCB_ST_RNR) == SCB_ST_RNR) ||
3783	    (((status & SCB_ST_RUS) != SCB_ST_RUS_RDY) &&
3784	     (netif_running(dev)))) {
3785#ifdef DEBUG_INTERRUPT_ERROR
3786		printk(KERN_INFO
3787		       "%s: wavelan_interrupt(): RU not ready -- restarting\n",
3788		       dev->name);
3789#endif
3790		wv_hw_reset(dev);
3791	}
3792
3793	/* Release spinlock */
3794	spin_unlock (&lp->spinlock);
3795
3796#ifdef DEBUG_INTERRUPT_TRACE
3797	printk(KERN_DEBUG "%s: <-wavelan_interrupt()\n", dev->name);
3798#endif
3799}
3800
3801/*------------------------------------------------------------------*/
3802/*
3803 * Watchdog: when we start a transmission, a timer is set for us in the
3804 * kernel.  If the transmission completes, this timer is disabled. If
3805 * the timer expires, we are called and we try to unlock the hardware.
3806 */
3807static void wavelan_watchdog(device *	dev)
3808{
3809	net_local *	lp = (net_local *)dev->priv;
3810	u_long		ioaddr = dev->base_addr;
3811	unsigned long	flags;
3812	unsigned int	nreaped;
3813
3814#ifdef DEBUG_INTERRUPT_TRACE
3815	printk(KERN_DEBUG "%s: ->wavelan_watchdog()\n", dev->name);
3816#endif
3817
3818#ifdef DEBUG_INTERRUPT_ERROR
3819	printk(KERN_INFO "%s: wavelan_watchdog: watchdog timer expired\n",
3820	       dev->name);
3821#endif
3822
3823	/* Check that we came here for something */
3824	if (lp->tx_n_in_use <= 0) {
3825		return;
3826	}
3827
3828	wv_splhi(lp, &flags);
3829
3830	/* Try to see if some buffers are not free (in case we missed
3831	 * an interrupt */
3832	nreaped = wv_complete(dev, ioaddr, lp);
3833
3834#ifdef DEBUG_INTERRUPT_INFO
3835	printk(KERN_DEBUG
3836	       "%s: wavelan_watchdog(): %d reaped, %d remain.\n",
3837	       dev->name, nreaped, lp->tx_n_in_use);
3838#endif
3839
3840#ifdef DEBUG_PSA_SHOW
3841	{
3842		psa_t psa;
3843		psa_read(dev, 0, (unsigned char *) &psa, sizeof(psa));
3844		wv_psa_show(&psa);
3845	}
3846#endif
3847#ifdef DEBUG_MMC_SHOW
3848	wv_mmc_show(dev);
3849#endif
3850#ifdef DEBUG_I82586_SHOW
3851	wv_cu_show(dev);
3852#endif
3853
3854	/* If no buffer has been freed */
3855	if (nreaped == 0) {
3856#ifdef DEBUG_INTERRUPT_ERROR
3857		printk(KERN_INFO
3858		       "%s: wavelan_watchdog(): cleanup failed, trying reset\n",
3859		       dev->name);
3860#endif
3861		wv_hw_reset(dev);
3862	}
3863
3864	/* At this point, we should have some free Tx buffer ;-) */
3865	if (lp->tx_n_in_use < NTXBLOCKS - 1)
3866		netif_wake_queue(dev);
3867
3868	wv_splx(lp, &flags);
3869
3870#ifdef DEBUG_INTERRUPT_TRACE
3871	printk(KERN_DEBUG "%s: <-wavelan_watchdog()\n", dev->name);
3872#endif
3873}
3874
3875/********************* CONFIGURATION CALLBACKS *********************/
3876/*
3877 * Here are the functions called by the Linux networking code (NET3)
3878 * for initialization, configuration and deinstallations of the
3879 * WaveLAN ISA hardware.
3880 */
3881
3882/*------------------------------------------------------------------*/
3883/*
3884 * Configure and start up the WaveLAN PCMCIA adaptor.
3885 * Called by NET3 when it "opens" the device.
3886 */
3887static int wavelan_open(device * dev)
3888{
3889	net_local *	lp = (net_local *)dev->priv;
3890	unsigned long	flags;
3891
3892#ifdef DEBUG_CALLBACK_TRACE
3893	printk(KERN_DEBUG "%s: ->wavelan_open(dev=0x%x)\n", dev->name,
3894	       (unsigned int) dev);
3895#endif
3896
3897	/* Check irq */
3898	if (dev->irq == 0) {
3899#ifdef DEBUG_CONFIG_ERROR
3900		printk(KERN_WARNING "%s: wavelan_open(): no IRQ\n",
3901		       dev->name);
3902#endif
3903		return -ENXIO;
3904	}
3905
3906	if (request_irq(dev->irq, &wavelan_interrupt, 0, "WaveLAN", dev) != 0)
3907	{
3908#ifdef DEBUG_CONFIG_ERROR
3909		printk(KERN_WARNING "%s: wavelan_open(): invalid IRQ\n",
3910		       dev->name);
3911#endif
3912		return -EAGAIN;
3913	}
3914
3915	wv_splhi(lp, &flags);
3916
3917	if (wv_hw_reset(dev) != -1) {
3918		netif_start_queue(dev);
3919	} else {
3920		free_irq(dev->irq, dev);
3921#ifdef DEBUG_CONFIG_ERROR
3922		printk(KERN_INFO
3923		       "%s: wavelan_open(): impossible to start the card\n",
3924		       dev->name);
3925#endif
3926		wv_splx(lp, &flags);
3927		return -EAGAIN;
3928	}
3929	wv_splx(lp, &flags);
3930
3931#ifdef DEBUG_CALLBACK_TRACE
3932	printk(KERN_DEBUG "%s: <-wavelan_open()\n", dev->name);
3933#endif
3934	return 0;
3935}
3936
3937/*------------------------------------------------------------------*/
3938/*
3939 * Shut down the WaveLAN ISA card.
3940 * Called by NET3 when it "closes" the device.
3941 */
3942static int wavelan_close(device * dev)
3943{
3944	net_local *lp = (net_local *) dev->priv;
3945	unsigned long flags;
3946
3947#ifdef DEBUG_CALLBACK_TRACE
3948	printk(KERN_DEBUG "%s: ->wavelan_close(dev=0x%x)\n", dev->name,
3949	       (unsigned int) dev);
3950#endif
3951
3952	netif_stop_queue(dev);
3953
3954	/*
3955	 * Flush the Tx and disable Rx.
3956	 */
3957	wv_splhi(lp, &flags);
3958	wv_82586_stop(dev);
3959	wv_splx(lp, &flags);
3960
3961	free_irq(dev->irq, dev);
3962
3963#ifdef DEBUG_CALLBACK_TRACE
3964	printk(KERN_DEBUG "%s: <-wavelan_close()\n", dev->name);
3965#endif
3966	return 0;
3967}
3968
3969/*------------------------------------------------------------------*/
3970/*
3971 * Probe an I/O address, and if the WaveLAN is there configure the
3972 * device structure
3973 * (called by wavelan_probe() and via init_module()).
3974 */
3975static int __init wavelan_config(device * dev)
3976{
3977	unsigned long ioaddr = dev->base_addr;
3978	u8 irq_mask;
3979	int irq;
3980	net_local *lp;
3981
3982#ifdef DEBUG_CALLBACK_TRACE
3983	printk(KERN_DEBUG "%s: ->wavelan_config(dev=0x%x, ioaddr=0x%lx)\n",
3984	       dev->name, (unsigned int) dev, ioaddr);
3985#endif
3986
3987	/* Check IRQ argument on command line. */
3988	if (dev->irq != 0) {
3989		irq_mask = wv_irq_to_psa(dev->irq);
3990
3991		if (irq_mask == 0) {
3992#ifdef DEBUG_CONFIG_ERROR
3993			printk(KERN_WARNING
3994			       "%s: wavelan_config(): invalid IRQ %d ignored.\n",
3995			       dev->name, dev->irq);
3996#endif
3997			dev->irq = 0;
3998		} else {
3999#ifdef DEBUG_CONFIG_INFO
4000			printk(KERN_DEBUG
4001			       "%s: wavelan_config(): changing IRQ to %d\n",
4002			       dev->name, dev->irq);
4003#endif
4004			psa_write(ioaddr, HACR_DEFAULT,
4005				  psaoff(0, psa_int_req_no), &irq_mask, 1);
4006			/* update the Wavelan checksum */
4007			update_psa_checksum(dev, ioaddr, HACR_DEFAULT);
4008			wv_hacr_reset(ioaddr);
4009		}
4010	}
4011
4012	psa_read(ioaddr, HACR_DEFAULT, psaoff(0, psa_int_req_no),
4013		 &irq_mask, 1);
4014	if ((irq = wv_psa_to_irq(irq_mask)) == -1) {
4015#ifdef DEBUG_CONFIG_ERROR
4016		printk(KERN_INFO
4017		       "%s: wavelan_config(): could not wavelan_map_irq(%d).\n",
4018		       dev->name, irq_mask);
4019#endif
4020		return -EAGAIN;
4021	}
4022
4023	dev->irq = irq;
4024
4025	if (!request_region(ioaddr, sizeof(ha_t), "wavelan"))
4026		return -EBUSY;
4027
4028	dev->mem_start = 0x0000;
4029	dev->mem_end = 0x0000;
4030	dev->if_port = 0;
4031
4032	/* Initialize device structures */
4033	dev->priv = kmalloc(sizeof(net_local), GFP_KERNEL);
4034	if (dev->priv == NULL) {
4035		release_region(ioaddr, sizeof(ha_t));
4036		return -ENOMEM;
4037	}
4038	memset(dev->priv, 0x00, sizeof(net_local));
4039	lp = (net_local *) dev->priv;
4040
4041	/* Back link to the device structure. */
4042	lp->dev = dev;
4043	/* Add the device at the beginning of the linked list. */
4044	lp->next = wavelan_list;
4045	wavelan_list = lp;
4046
4047	lp->hacr = HACR_DEFAULT;
4048
4049	/* Multicast stuff */
4050	lp->promiscuous = 0;
4051	lp->mc_count = 0;
4052
4053	/* Init spinlock */
4054	spin_lock_init(&lp->spinlock);
4055
4056	/*
4057	 * Fill in the fields of the device structure
4058	 * with generic Ethernet values.
4059	 */
4060	ether_setup(dev);
4061
4062	SET_MODULE_OWNER(dev);
4063	dev->open = wavelan_open;
4064	dev->stop = wavelan_close;
4065	dev->hard_start_xmit = wavelan_packet_xmit;
4066	dev->get_stats = wavelan_get_stats;
4067	dev->set_multicast_list = &wavelan_set_multicast_list;
4068        dev->tx_timeout		= &wavelan_watchdog;
4069        dev->watchdog_timeo	= WATCHDOG_JIFFIES;
4070#ifdef SET_MAC_ADDRESS
4071	dev->set_mac_address = &wavelan_set_mac_address;
4072#endif				/* SET_MAC_ADDRESS */
4073
4074#ifdef WIRELESS_EXT		    /* if wireless extension exists in the kernel */
4075	dev->do_ioctl = wavelan_ioctl;
4076	dev->get_wireless_stats = wavelan_get_wireless_stats;
4077#endif
4078
4079	dev->mtu = WAVELAN_MTU;
4080
4081	/* Display nice information. */
4082	wv_init_info(dev);
4083
4084#ifdef DEBUG_CALLBACK_TRACE
4085	printk(KERN_DEBUG "%s: <-wavelan_config()\n", dev->name);
4086#endif
4087	return 0;
4088}
4089
4090/*------------------------------------------------------------------*/
4091/*
4092 * Check for a network adaptor of this type.  Return '0' iff one
4093 * exists.  There seem to be different interpretations of
4094 * the initial value of dev->base_addr.
4095 * We follow the example in drivers/net/ne.c.
4096 * (called in "Space.c")
4097 */
4098int __init wavelan_probe(device * dev)
4099{
4100	short base_addr;
4101	mac_addr mac;		/* MAC address (check existence of WaveLAN) */
4102	int i;
4103	int r;
4104
4105#ifdef DEBUG_CALLBACK_TRACE
4106	printk(KERN_DEBUG
4107	       "%s: ->wavelan_probe(dev=0x%x (base_addr=0x%x))\n",
4108	       dev->name, (unsigned int) dev,
4109	       (unsigned int) dev->base_addr);
4110#endif
4111
4112#ifdef	STRUCT_CHECK
4113	if (wv_struct_check() != (char *) NULL) {
4114		printk(KERN_WARNING
4115		       "%s: wavelan_probe(): structure/compiler botch: \"%s\"\n",
4116		       dev->name, wv_struct_check());
4117		return -ENODEV;
4118	}
4119#endif				/* STRUCT_CHECK */
4120
4121	/* Check the value of the command line parameter for base address. */
4122	base_addr = dev->base_addr;
4123
4124	/* Don't probe at all. */
4125	if (base_addr < 0) {
4126#ifdef DEBUG_CONFIG_ERROR
4127		printk(KERN_WARNING
4128		       "%s: wavelan_probe(): invalid base address\n",
4129		       dev->name);
4130#endif
4131		return -ENXIO;
4132	}
4133
4134	/* Check a single specified location. */
4135	if (base_addr > 0x100) {
4136		/* Check if there is something at this base address */
4137		if ((r = wv_check_ioaddr(base_addr, mac)) == 0) {
4138			memcpy(dev->dev_addr, mac, 6);	/* Copy MAC address. */
4139			r = wavelan_config(dev);
4140		}
4141#ifdef DEBUG_CONFIG_INFO
4142		if (r != 0)
4143			printk(KERN_DEBUG
4144			       "%s: wavelan_probe(): no device at specified base address (0x%X) or address already in use\n",
4145			       dev->name, base_addr);
4146#endif
4147
4148#ifdef DEBUG_CALLBACK_TRACE
4149		printk(KERN_DEBUG "%s: <-wavelan_probe()\n", dev->name);
4150#endif
4151		return r;
4152	}
4153
4154	/* Scan all possible addresses of the WaveLAN hardware. */
4155	for (i = 0; i < NELS(iobase); i++) {
4156		/* Check whether there is something at this base address. */
4157		if (wv_check_ioaddr(iobase[i], mac) == 0) {
4158			dev->base_addr = iobase[i];	/* Copy base address. */
4159			memcpy(dev->dev_addr, mac, 6);	/* Copy MAC address. */
4160			if (wavelan_config(dev) == 0) {
4161#ifdef DEBUG_CALLBACK_TRACE
4162				printk(KERN_DEBUG
4163				       "%s: <-wavelan_probe()\n",
4164				       dev->name);
4165#endif
4166				return 0;
4167			}
4168		}
4169	}
4170
4171	/* We may have touched base_addr.  Another driver may not like it. */
4172	dev->base_addr = base_addr;
4173
4174#ifdef DEBUG_CONFIG_INFO
4175	printk(KERN_DEBUG "%s: wavelan_probe(): no device found\n",
4176	       dev->name);
4177#endif
4178
4179	return -ENODEV;
4180}
4181
4182/****************************** MODULE ******************************/
4183/*
4184 * Module entry point: insertion and removal
4185 */
4186
4187#ifdef	MODULE
4188/*------------------------------------------------------------------*/
4189/*
4190 * Insertion of the module
4191 * I'm now quite proud of the multi-device support.
4192 */
4193int init_module(void)
4194{
4195	mac_addr mac;		/* MAC address (check WaveLAN existence) */
4196	int ret = -EIO;		/* Return error if no cards found */
4197	int i;
4198
4199#ifdef DEBUG_MODULE_TRACE
4200	printk(KERN_DEBUG "-> init_module()\n");
4201#endif
4202
4203	/* If probing is asked */
4204	if (io[0] == 0) {
4205#ifdef DEBUG_CONFIG_ERROR
4206		printk(KERN_WARNING
4207		       "WaveLAN init_module(): doing device probing (bad !)\n");
4208		printk(KERN_WARNING
4209		       "Specify base addresses while loading module to correct the problem\n");
4210#endif
4211
4212		/* Copy the basic set of address to be probed. */
4213		for (i = 0; i < NELS(iobase); i++)
4214			io[i] = iobase[i];
4215	}
4216
4217
4218	/* Loop on all possible base addresses. */
4219	i = -1;
4220	while ((io[++i] != 0) && (i < NELS(io))) {
4221		/* Check if there is something at this base address. */
4222		if (wv_check_ioaddr(io[i], mac) == 0) {
4223			device *dev;
4224
4225			/* Create device and set basic arguments. */
4226			dev =
4227			    kmalloc(sizeof(struct net_device), GFP_KERNEL);
4228			if (dev == NULL) {
4229				ret = -ENOMEM;
4230				break;
4231			}
4232			memset(dev, 0x00, sizeof(struct net_device));
4233			memcpy(dev->name, name[i], IFNAMSIZ);	/* Copy name */
4234			dev->base_addr = io[i];
4235			dev->irq = irq[i];
4236			dev->init = &wavelan_config;
4237			memcpy(dev->dev_addr, mac, 6);	/* Copy MAC address. */
4238
4239			/* Try to create the device. */
4240			if (register_netdev(dev) != 0) {
4241				/* Deallocate everything. */
4242				/* Note: if dev->priv is mallocated, there is no way to fail. */
4243				kfree(dev);
4244			} else {
4245				/* If at least one device OK, we do not fail */
4246				ret = 0;
4247			}
4248		}		/* if there is something at the address */
4249	}			/* Loop on all addresses. */
4250
4251#ifdef DEBUG_CONFIG_ERROR
4252	if (wavelan_list == (net_local *) NULL)
4253		printk(KERN_WARNING
4254		       "WaveLAN init_module(): no device found\n");
4255#endif
4256
4257#ifdef DEBUG_MODULE_TRACE
4258	printk(KERN_DEBUG "<- init_module()\n");
4259#endif
4260	return ret;
4261}
4262
4263/*------------------------------------------------------------------*/
4264/*
4265 * Removal of the module
4266 */
4267void cleanup_module(void)
4268{
4269#ifdef DEBUG_MODULE_TRACE
4270	printk(KERN_DEBUG "-> cleanup_module()\n");
4271#endif
4272
4273	/* Loop on all devices and release them. */
4274	while (wavelan_list != (net_local *) NULL) {
4275		device *dev = wavelan_list->dev;
4276
4277#ifdef DEBUG_CONFIG_INFO
4278		printk(KERN_DEBUG
4279		       "%s: cleanup_module(): removing device at 0x%x\n",
4280		       dev->name, (unsigned int) dev);
4281#endif
4282
4283		/* Release the ioport region. */
4284		release_region(dev->base_addr, sizeof(ha_t));
4285
4286		/* Definitely remove the device. */
4287		unregister_netdev(dev);
4288
4289		/* Unlink the device. */
4290		wavelan_list = wavelan_list->next;
4291
4292		/* Free pieces. */
4293		kfree(dev->priv);
4294		kfree(dev);
4295	}
4296
4297#ifdef DEBUG_MODULE_TRACE
4298	printk(KERN_DEBUG "<- cleanup_module()\n");
4299#endif
4300}
4301#endif				/* MODULE */
4302MODULE_LICENSE("GPL");
4303
4304/*
4305 * This software may only be used and distributed
4306 * according to the terms of the GNU General Public License.
4307 *
4308 * This software was developed as a component of the
4309 * Linux operating system.
4310 * It is based on other device drivers and information
4311 * either written or supplied by:
4312 *	Ajay Bakre (bakre@paul.rutgers.edu),
4313 *	Donald Becker (becker@scyld.com),
4314 *	Loeke Brederveld (Loeke.Brederveld@Utrecht.NCR.com),
4315 *	Anders Klemets (klemets@it.kth.se),
4316 *	Vladimir V. Kolpakov (w@stier.koenig.ru),
4317 *	Marc Meertens (Marc.Meertens@Utrecht.NCR.com),
4318 *	Pauline Middelink (middelin@polyware.iaf.nl),
4319 *	Robert Morris (rtm@das.harvard.edu),
4320 *	Jean Tourrilhes (jt@hplb.hpl.hp.com),
4321 *	Girish Welling (welling@paul.rutgers.edu),
4322 *
4323 * Thanks go also to:
4324 *	James Ashton (jaa101@syseng.anu.edu.au),
4325 *	Alan Cox (alan@redhat.com),
4326 *	Allan Creighton (allanc@cs.usyd.edu.au),
4327 *	Matthew Geier (matthew@cs.usyd.edu.au),
4328 *	Remo di Giovanni (remo@cs.usyd.edu.au),
4329 *	Eckhard Grah (grah@wrcs1.urz.uni-wuppertal.de),
4330 *	Vipul Gupta (vgupta@cs.binghamton.edu),
4331 *	Mark Hagan (mhagan@wtcpost.daytonoh.NCR.COM),
4332 *	Tim Nicholson (tim@cs.usyd.edu.au),
4333 *	Ian Parkin (ian@cs.usyd.edu.au),
4334 *	John Rosenberg (johnr@cs.usyd.edu.au),
4335 *	George Rossi (george@phm.gov.au),
4336 *	Arthur Scott (arthur@cs.usyd.edu.au),
4337 *	Peter Storey,
4338 * for their assistance and advice.
4339 *
4340 * Please send bug reports, updates, comments to:
4341 *
4342 * Bruce Janson                                    Email:  bruce@cs.usyd.edu.au
4343 * Basser Department of Computer Science           Phone:  +61-2-9351-3423
4344 * University of Sydney, N.S.W., 2006, AUSTRALIA   Fax:    +61-2-9351-3838
4345 */
4346