OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rc203soc/] [sw/] [uClinux/] [drivers/] [net/] [wavelan.c] - Blame information for rev 1772

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.