-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetwave_cs.c
More file actions
1694 lines (1435 loc) · 49.7 KB
/
netwave_cs.c
File metadata and controls
1694 lines (1435 loc) · 49.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*********************************************************************
*
* Filename: netwave_cs.c
* Version: 0.4.1
* Description: Netwave AirSurfer Wireless LAN PC Card driver
* Status: Experimental.
* Authors: John Markus Bjørndalen <johnm@cs.uit.no>
* Dag Brattli <dagb@cs.uit.no>
* David Hinds <dhinds@hyper.stanford.edu>
* Created at: A long time ago!
* Modified at: Mon Nov 10 11:54:37 1997
* Modified by: Dag Brattli <dagb@cs.uit.no>
*
* Copyright (c) 1997 University of Tromsø, Norway
*
* Revision History:
*
* 08-Nov-97 15:14:47 John Markus Bjørndalen <johnm@cs.uit.no>
* - Fixed some bugs in netwave_rx and cleaned it up a bit.
* (One of the bugs would have destroyed packets when receiving
* multiple packets per interrupt).
* - Cleaned up parts of newave_hw_xmit.
* - A few general cleanups.
* 24-Oct-97 13:17:36 Dag Brattli <dagb@cs.uit.no>
* - Fixed netwave_rx receive function (got updated docs)
* Others:
* - Changed name from xircnw to netwave, take a look at
* http://www.netwave-wireless.com
* - Some reorganizing of the code
* - Removed possible race condition between interrupt handler and transmit
* function
* - Started to add wireless extensions, but still needs some coding
* - Added watchdog for better handling of transmission timeouts
* (hopefully this works better)
********************************************************************/
/* To have statistics (just packets sent) define this */
#undef NETWAVE_STATS
#include <pcmcia/config.h>
#include <pcmcia/k_compat.h>
#include <linux/kernel.h>
#include <linux/sched.h>
#include <linux/types.h>
#include <linux/fcntl.h>
#include <linux/interrupt.h>
#include <linux/ptrace.h>
#include <linux/ioport.h>
#include <linux/in.h>
#include <linux/malloc.h>
#include <linux/string.h>
#include <linux/timer.h>
#include <asm/system.h>
#include <asm/bitops.h>
#include <asm/io.h>
#include <asm/dma.h>
#include <linux/errno.h>
#include <linux/netdevice.h>
#include <linux/etherdevice.h>
#include <linux/skbuff.h>
#ifdef HAS_WIRELESS_EXTENSIONS
#include <linux/wireless.h>
#endif
#include <pcmcia/version.h>
#include <pcmcia/cs_types.h>
#include <pcmcia/cs.h>
#include <pcmcia/cistpl.h>
#include <pcmcia/cisreg.h>
#include <pcmcia/ds.h>
#include <pcmcia/mem_op.h>
#define NETWAVE_REGOFF 0x8000
/* The Netwave IO registers, offsets to iobase */
#define NETWAVE_REG_COR 0x0
#define NETWAVE_REG_CCSR 0x2
#define NETWAVE_REG_ASR 0x4
#define NETWAVE_REG_IMR 0xa
#define NETWAVE_REG_PMR 0xc
#define NETWAVE_REG_IOLOW 0x6
#define NETWAVE_REG_IOHI 0x7
#define NETWAVE_REG_IOCONTROL 0x8
#define NETWAVE_REG_DATA 0xf
/* The Netwave Extended IO registers, offsets to RamBase */
#define NETWAVE_EREG_ASCC 0x114
#define NETWAVE_EREG_RSER 0x120
#define NETWAVE_EREG_RSERW 0x124
#define NETWAVE_EREG_TSER 0x130
#define NETWAVE_EREG_TSERW 0x134
#define NETWAVE_EREG_CB 0x100
#define NETWAVE_EREG_SPCQ 0x154
#define NETWAVE_EREG_SPU 0x155
#define NETWAVE_EREG_LIF 0x14e
#define NETWAVE_EREG_ISPLQ 0x156
#define NETWAVE_EREG_HHC 0x158
#define NETWAVE_EREG_NI 0x16e
#define NETWAVE_EREG_MHS 0x16b
#define NETWAVE_EREG_TDP 0x140
#define NETWAVE_EREG_RDP 0x150
#define NETWAVE_EREG_PA 0x160
#define NETWAVE_EREG_EC 0x180
#define NETWAVE_EREG_CRBP 0x17a
#define NETWAVE_EREG_ARW 0x166
/*
* Commands used in the extended command buffer
* NETWAVE_EREG_CB (0x100-0x10F)
*/
#define NETWAVE_CMD_NOP 0x00
#define NETWAVE_CMD_SRC 0x01
#define NETWAVE_CMD_STC 0x02
#define NETWAVE_CMD_AMA 0x03
#define NETWAVE_CMD_DMA 0x04
#define NETWAVE_CMD_SAMA 0x05
#define NETWAVE_CMD_ER 0x06
#define NETWAVE_CMD_DR 0x07
#define NETWAVE_CMD_TL 0x08
#define NETWAVE_CMD_SRP 0x09
#define NETWAVE_CMD_SSK 0x0a
#define NETWAVE_CMD_SMD 0x0b
#define NETWAVE_CMD_SAPD 0x0c
#define NETWAVE_CMD_SSS 0x11
/* End of Command marker */
#define NETWAVE_CMD_EOC 0x00
/* ASR register bits */
#define NETWAVE_ASR_RXRDY 0x80
#define NETWAVE_ASR_TXBA 0x01
#define TX_TIMEOUT 20
#define WATCHDOG_JIFFIES 32
static const unsigned int imrConfRFU1 = 0x10; /* RFU interrupt mask, keep high */
static const unsigned int imrConfIENA = 0x02; /* Interrupt enable */
static const unsigned int corConfIENA = 0x01; /* Interrupt enable */
static const unsigned int corConfLVLREQ = 0x40; /* Keep high */
static const unsigned int rxConfRxEna = 0x80; /* Receive Enable */
static const unsigned int rxConfMAC = 0x20; /* MAC host receive mode*/
static const unsigned int rxConfPro = 0x10; /* Promiscuous */
static const unsigned int rxConfAMP = 0x08; /* Accept Multicast Packets */
static const unsigned int rxConfBcast = 0x04; /* Accept Broadcast Packets */
static const unsigned int txConfTxEna = 0x80; /* Transmit Enable */
static const unsigned int txConfMAC = 0x20; /* Host sends MAC mode */
static const unsigned int txConfEUD = 0x10; /* Enable Uni-Data packets */
static const unsigned int txConfKey = 0x02; /* Scramble data packets */
static const unsigned int txConfLoop = 0x01; /* Loopback mode */
/*static int netwave_debug = 0;*/
/*
All the PCMCIA modules use PCMCIA_DEBUG to control debugging. If
you do not define PCMCIA_DEBUG at all, all the debug code will be
left out. If you compile with PCMCIA_DEBUG=0, the debug code will
be present but disabled -- but it can then be enabled for specific
modules at load time with a 'pc_debug=#' option to insmod.
*/
#ifdef PCMCIA_DEBUG
static int pc_debug = PCMCIA_DEBUG;
MODULE_PARM(pc_debug, "i");
#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
static char *version =
"netwave_cs.c 0.3.0 Thu Jul 17 14:36:02 1997 (John Markus Bjørndalen)\n";
#else
#define DEBUG(n, args...)
#endif
static dev_info_t dev_info = "netwave_cs";
/*====================================================================*/
/* Parameters that can be set with 'insmod' */
/* Choose the domain, default is 0x100 */
static u_int domain = 0x100;
/* Scramble key, range from 0x0 to 0xffff.
* 0x0 is no scrambling.
*/
static u_int scramble_key = 0x0;
/* Shared memory speed, in ns. The documentation states that
* the card should not be read faster than every 400ns.
* This timing should be provided by the HBA. If it becomes a
* problem, try setting mem_speed to 400.
*/
static int mem_speed = 0;
/* Bit map of interrupts to choose from */
/* This means pick from 15, 14, 12, 11, 10, 9, 7, 5, 4, and 3 */
static u_int irq_mask = 0xdeb8;
static int irq_list[4] = { -1 };
MODULE_PARM(domain, "i");
MODULE_PARM(scramble_key, "i");
MODULE_PARM(mem_speed, "i");
MODULE_PARM(irq_mask, "i");
MODULE_PARM(irq_list, "1-4i");
/*====================================================================*/
/* PCMCIA (Card Services) related functions */
static void netwave_release(u_long arg); /* Card removal */
static int netwave_event(event_t event, int priority,
event_callback_args_t *args);
static void netwave_pcmcia_config(dev_link_t *arg); /* Runs after card
insertion */
static dev_link_t *netwave_attach(void); /* Create instance */
static void netwave_detach(dev_link_t *); /* Destroy instance */
/* Hardware configuration */
static void netwave_doreset(unsigned long iobase, u_char* ramBase);
static void netwave_reset(struct device *dev);
/* Misc device stuff */
static int netwave_open(struct device *dev); /* Open the device */
static int netwave_close(struct device *dev); /* Close the device */
static int netwave_config(struct device *dev, struct ifmap *map);
/* Packet transmission and Packet reception */
static int netwave_start_xmit( struct sk_buff *skb, struct device *dev);
static int netwave_rx( struct device *dev);
/* Interrupt routines */
static void netwave_interrupt IRQ(int irq, void *dev_id, struct pt_regs *regs);
static void netwave_watchdog(u_long); /* Transmission watchdog */
/* Statistics */
static void update_stats(struct device *dev);
static struct enet_statistics *netwave_get_stats(struct device *dev);
/* Wireless extensions */
#ifdef WIRELESS_EXT
static struct iw_statistics* netwave_get_wireless_stats(struct device *dev);
#endif
static int netwave_ioctl(struct device *, struct ifreq *, int);
#ifdef NEW_MULTICAST
static void set_multicast_list(struct device *dev);
#else
static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
#endif
/*
A linked list of "instances" of the skeleton device. Each actual
PCMCIA card corresponds to one device instance, and is described
by one dev_link_t structure (defined in ds.h).
You may not want to use a linked list for this -- for example, the
memory card driver uses an array of dev_link_t pointers, where minor
device numbers are used to derive the corresponding array index.
*/
static dev_link_t *dev_list = NULL;
/*
A dev_link_t structure has fields for most things that are needed
to keep track of a socket, but there will usually be some device
specific information that also needs to be kept track of. The
'priv' pointer in a dev_link_t structure can be used to point to
a device-specific private data structure, like this.
A driver needs to provide a dev_node_t structure for each device
on a card. In some cases, there is only one device per card (for
example, ethernet cards, modems). In other cases, there may be
many actual or logical devices (SCSI adapters, memory cards with
multiple partitions). The dev_node_t structures need to be kept
in a linked list starting at the 'dev' field of a dev_link_t
structure. We allocate them in the card's private data structure,
because they generally can't be allocated dynamically.
*/
#define SIOCGIPSNAP SIOCDEVPRIVATE /* Site Survey Snapshot */
/*#define SIOCGIPQTHR SIOCDEVPRIVATE + 1*/
#define MAX_ESA 10
typedef struct net_addr {
u_char addr48[6];
} net_addr;
struct site_survey {
u_short length;
u_char struct_revision;
u_char roaming_state;
u_char sp_existsFlag;
u_char sp_link_quality;
u_char sp_max_link_quality;
u_char linkQualityGoodFairBoundary;
u_char linkQualityFairPoorBoundary;
u_char sp_utilization;
u_char sp_goodness;
u_char sp_hotheadcount;
u_char roaming_condition;
net_addr sp;
u_char numAPs;
net_addr nearByAccessPoints[MAX_ESA];
};
typedef struct netwave_private {
dev_node_t node;
u_char *ramBase;
int timeoutCounter;
int lastExec;
struct timer_list watchdog; /* To avoid blocking state */
struct site_survey nss;
struct enet_statistics stats;
#ifdef WIRELESS_EXT
struct iw_statistics iw_stats; /* Wireless stats */
#endif
} netwave_private;
#ifdef NETWAVE_STATS
static struct enet_statistics *netwave_get_stats(struct device *dev);
#endif
/*
* The Netwave card is little-endian, so won't work for big endian
* systems.
*/
static inline unsigned short get_uint16(u_char* staddr)
{
return readw(staddr); /* Return only 16 bits */
}
static inline short get_int16(u_char* staddr)
{
return readw(staddr);
}
/**************************************************************************/
static void cs_error(client_handle_t handle, int func, int ret)
{
error_info_t err = { func, ret };
CardServices(ReportError, handle, &err);
}
/*
* Wait until the WOC (Write Operation Complete) bit in the
* ASR (Adapter Status Register) is asserted.
* This should have aborted if it takes too long time.
*/
static inline void wait_WOC(unsigned int iobase)
{
/* Spin lock */
while ((inb(iobase + NETWAVE_REG_ASR) & 0x8) != 0x8) ;
}
#ifdef WIRELESS_EXT
static void netwave_snapshot(netwave_private *priv, u_char *ramBase,
unsigned short iobase) {
u_short resultBuffer;
/* if time since last snapshot is > 1 sec. (100 jiffies?) then take
* new snapshot, else return cached data. This is the recommended rate.
*/
if ( jiffies - priv->lastExec > 100) {
/* Take site survey snapshot */
/*printk( KERN_DEBUG "Taking new snapshot. %ld\n", jiffies -
priv->lastExec); */
wait_WOC(iobase);
writeb(NETWAVE_CMD_SSS, ramBase + NETWAVE_EREG_CB + 0);
writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
wait_WOC(iobase);
/* Get result and copy to cach */
resultBuffer = readw(ramBase + NETWAVE_EREG_CRBP);
copy_from_pc( &priv->nss, ramBase+resultBuffer,
sizeof(struct site_survey));
}
}
#endif
#ifdef WIRELESS_EXT
/*
* Function netwave_get_wireless_stats (dev)
*
* Wireless extensions statistics
*
*/
static struct iw_statistics *netwave_get_wireless_stats(struct device *dev)
{
unsigned long flags;
unsigned short iobase = dev->base_addr;
netwave_private *priv = (netwave_private *) dev->priv;
u_char *ramBase = priv->ramBase;
struct iw_statistics* wstats;
wstats = &priv->iw_stats;
save_flags(flags);
cli();
netwave_snapshot( priv, ramBase, iobase);
wstats->status = priv->nss.roaming_state;
wstats->qual.qual = readb( ramBase + NETWAVE_EREG_SPCQ);
wstats->qual.level = readb( ramBase + NETWAVE_EREG_ISPLQ);
wstats->qual.noise = readb( ramBase + NETWAVE_EREG_SPU) & 0x3f;
wstats->discard.nwid = 0L;
wstats->discard.code = 0L;
wstats->discard.misc = 0L;
restore_flags(flags);
return &priv->iw_stats;
}
#endif
/*
* Function netwave_init (dev)
*
* We never need to do anything when a device is "initialized"
* by the net software, because we only register already-found cards.
*/
int netwave_init(struct device *dev)
{
/* We do all the initialization of this in netwave_attach instead */
return 0;
}
/*
* Function netwave_attach (void)
*
* Creates an "instance" of the driver, allocating local data
* structures for one device. The device is registered with Card
* Services.
*
* The dev_link structure is initialized, but we don't actually
* configure the card at this point -- we wait until we receive a
* card insertion event.
*/
static dev_link_t *netwave_attach(void)
{
client_reg_t client_reg;
dev_link_t *link;
struct device *dev;
netwave_private *priv;
int i, ret;
DEBUG(0, "netwave_attach()\n");
/* Initialize the dev_link_t structure */
link = kmalloc(sizeof(struct dev_link_t), GFP_KERNEL);
memset(link, 0, sizeof(struct dev_link_t));
link->release.function = &netwave_release;
link->release.data = (u_long)link;
/* The io structure describes IO port mapping */
link->io.NumPorts1 = 16;
link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
/* link->io.NumPorts2 = 16;
link->io.Attributes2 = IO_DATA_PATH_WIDTH_16; */
link->io.IOAddrLines = 5;
/* Interrupt setup */
link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
link->irq.IRQInfo1 = IRQ_INFO2_VALID|IRQ_LEVEL_ID;
if (irq_list[0] == -1)
link->irq.IRQInfo2 = irq_mask;
else
for (i = 0; i < 4; i++)
link->irq.IRQInfo2 |= 1 << irq_list[i];
link->irq.Handler = &netwave_interrupt;
/* General socket configuration */
link->conf.Attributes = CONF_ENABLE_IRQ;
link->conf.Vcc = 50;
link->conf.IntType = INT_MEMORY_AND_IO;
link->conf.ConfigIndex = 1;
link->conf.Present = PRESENT_OPTION;
/* Allocate space for private device-specific data */
dev = kmalloc(sizeof(struct device), GFP_KERNEL);
memset(dev, 0, sizeof(struct device));
dev->priv = kmalloc(sizeof(netwave_private), GFP_KERNEL);
memset(dev->priv, 0, sizeof(netwave_private));
/* Set the watchdog timer */
priv = (netwave_private *) dev->priv;
priv->watchdog.function = &netwave_watchdog;
priv->watchdog.data = (unsigned long) dev;
/* Netwave specific entries in the device structure */
dev->hard_start_xmit = &netwave_start_xmit;
dev->set_config = &netwave_config;
dev->get_stats = &netwave_get_stats;
dev->set_multicast_list = &set_multicast_list;
/* wireless extensions */
#ifdef WIRELESS_EXT
dev->get_wireless_stats = &netwave_get_wireless_stats;
#endif
dev->do_ioctl = &netwave_ioctl;
ether_setup(dev);
dev->name = ((struct netwave_private *)dev->priv)->node.dev_name;
dev->init = &netwave_init;
dev->open = &netwave_open;
dev->stop = &netwave_close;
dev->tbusy = 1;
link->priv = link->irq.Instance = dev;
/* Register with Card Services */
link->next = dev_list;
dev_list = link;
client_reg.dev_info = &dev_info;
client_reg.Attributes = INFO_IO_CLIENT | INFO_CARD_SHARE;
client_reg.EventMask =
CS_EVENT_CARD_INSERTION | CS_EVENT_CARD_REMOVAL |
CS_EVENT_RESET_PHYSICAL | CS_EVENT_CARD_RESET |
CS_EVENT_PM_SUSPEND | CS_EVENT_PM_RESUME;
client_reg.event_handler = &netwave_event;
client_reg.Version = 0x0210;
client_reg.event_callback_args.client_data = link;
ret = CardServices(RegisterClient, &link->handle, &client_reg);
if (ret != 0) {
cs_error(link->handle, RegisterClient, ret);
netwave_detach(link);
return NULL;
}
return link;
} /* netwave_attach */
/*
* Function netwave_detach (link)
*
* This deletes a driver "instance". The device is de-registered
* with Card Services. If it has been released, all local data
* structures are freed. Otherwise, the structures will be freed
* when the device is released.
*/
static void netwave_detach(dev_link_t *link)
{
dev_link_t **linkp;
long flags;
DEBUG(0, "netwave_detach(0x%p)\n", link);
/* Locate device structure */
for (linkp = &dev_list; *linkp; linkp = &(*linkp)->next)
if (*linkp == link) break;
if (*linkp == NULL)
return;
save_flags(flags);
if (link->state & DEV_RELEASE_PENDING) {
del_timer(&link->release);
link->state &= ~DEV_RELEASE_PENDING;
}
cli();
restore_flags(flags);
/*
If the device is currently configured and active, we won't
actually delete it yet. Instead, it is marked so that when
the release() function is called, that will trigger a proper
detach().
*/
if (link->state & DEV_CONFIG) {
netwave_release((u_long) link);
if (link->state & DEV_STALE_CONFIG) {
DEBUG(1, "netwave_cs: detach postponed, '%s' still "
"locked\n", link->dev->dev_name);
link->state |= DEV_STALE_LINK;
return;
}
}
/* Break the link with Card Services */
if (link->handle)
CardServices(DeregisterClient, link->handle);
/* Unlink device structure, free pieces */
*linkp = link->next;
if (link->priv) {
struct device *dev = link->priv;
if (dev->priv)
kfree_s(dev->priv, sizeof(netwave_private));
kfree_s(link->priv, sizeof(struct device));
}
kfree_s(link, sizeof(struct dev_link_t));
} /* netwave_detach */
/*
* Function netwave_ioctl (dev, rq, cmd)
*
* Perform ioctl : config & info stuff
* This is the stuff that are treated the wireless extensions (iwconfig)
*
*/
static int netwave_ioctl(struct device *dev, /* ioctl device */
struct ifreq *rq, /* Data passed */
int cmd) /* Ioctl number */
{
unsigned long flags;
int ret = 0;
#ifdef WIRELESS_EXT
unsigned short iobase = dev->base_addr;
netwave_private *priv = (netwave_private *) dev->priv;
u_char *ramBase = priv->ramBase;
struct iwreq *wrq = (struct iwreq *) rq;
#endif
DEBUG( 0, "%s: ->netwave_ioctl(cmd=0x%X)\n", dev->name, cmd);
/* Disable interrupts & save flags */
save_flags(flags);
cli();
/* Look what is the request */
switch(cmd) {
/* --------------- WIRELESS EXTENSIONS --------------- */
#ifdef WIRELESS_EXT
case SIOCGIWNAME:
/* Get name */
strcpy(wrq->u.name, "Netwave");
break;
case SIOCSIWNWID:
/* Set domain */
if(wrq->u.nwid.on) {
domain = wrq->u.nwid.nwid;
printk( KERN_DEBUG "Setting domain to 0x%x%02x\n",
(domain >> 8) & 0x01, domain & 0xff);
wait_WOC(iobase);
writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
writeb( domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
writeb((domain >>8 ) & 0x01,ramBase + NETWAVE_EREG_CB+2);
writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
} break;
case SIOCGIWNWID:
/* Read domain*/
wrq->u.nwid.nwid = domain;
wrq->u.nwid.on = 1;
break;
case SIOCGIWENCODE:
/* Get scramble key */
wrq->u.encoding.code = scramble_key;
wrq->u.encoding.method = 1;
break;
case SIOCSIWENCODE:
/* Set scramble key */
scramble_key = wrq->u.encoding.code;
wait_WOC(iobase);
writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
break;
case SIOCGIWRANGE:
/* Basic checking... */
if(wrq->u.data.pointer != (caddr_t) 0) {
struct iw_range range;
/* Verify the user buffer */
ret = verify_area(VERIFY_WRITE, wrq->u.data.pointer,
sizeof(struct iw_range));
if(ret)
break;
/* Set the length (useless : its constant...) */
wrq->u.data.length = sizeof(struct iw_range);
/* Set information in the range struct */
range.throughput = 1.6 * 1024 * 1024; /* don't argue on this ! */
range.min_nwid = 0x0000;
range.max_nwid = 0x01FF;
range.num_channels = range.num_frequency = 0;
range.sensitivity = 0x3F;
range.max_qual.qual = 255;
range.max_qual.level = 255;
range.max_qual.noise = 0;
/* Copy structure to the user buffer */
copy_to_user(wrq->u.data.pointer, &range,
sizeof(struct iw_range));
}
break;
case SIOCGIWPRIV:
/* Basic checking... */
if(wrq->u.data.pointer != (caddr_t) 0) {
struct iw_priv_args priv[] =
{ /* cmd, set_args, get_args, name */
{ SIOCGIPSNAP, IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | 0,
sizeof(struct site_survey),
"getsitesurvey" },
};
/* Verify the user buffer */
ret = verify_area(VERIFY_WRITE, wrq->u.data.pointer,
sizeof(priv));
if(ret)
break;
/* Set the number of ioctl available */
wrq->u.data.length = 1;
/* Copy structure to the user buffer */
copy_to_user(wrq->u.data.pointer, (u_char *) priv,
sizeof(priv));
}
break;
case SIOCGIPSNAP:
if(wrq->u.data.pointer != (caddr_t) 0) {
/* Take snapshot of environment */
netwave_snapshot( priv, ramBase, iobase);
/* Verify the user buffer */
ret = verify_area(VERIFY_WRITE, wrq->u.data.pointer,
sizeof(struct site_survey));
if(ret) {
printk(KERN_DEBUG "Bad buffer!\n");
break;
}
wrq->u.data.length = priv->nss.length;
/* Copy structure to the user buffer */
copy_to_user(wrq->u.data.pointer,
(u_char *) &priv->nss,
sizeof( struct site_survey));
priv->lastExec = jiffies;
}
break;
#endif
default:
ret = -EOPNOTSUPP;
}
/* ReEnable interrupts & restore flags */
restore_flags(flags);
return ret;
}
/*
* Function netwave_pcmcia_config (link)
*
* netwave_pcmcia_config() is scheduled to run after a CARD_INSERTION
* event is received, to configure the PCMCIA socket, and to make the
* device available to the system.
*
*/
#define CS_CHECK(fn, args...) \
while ((last_ret=CardServices(last_fn=(fn), args))!=0) goto cs_failed
static void netwave_pcmcia_config(dev_link_t *link) {
client_handle_t handle;
tuple_t tuple;
cisparse_t parse;
struct device *dev;
int i, j, last_ret, last_fn;
u_char buf[64];
win_req_t req;
memreq_t mem;
u_char *ramBase = NULL;
/* modwin_t mod;
short iobase, *phys_addr;
*/
handle = link->handle;
dev = link->priv;
DEBUG(0, "netwave_pcmcia_config(0x%p)\n", link);
/*
This reads the card's CONFIG tuple to find its configuration
registers.
*/
tuple.Attributes = 0;
tuple.TupleData = (cisdata_t *) buf;
tuple.TupleDataMax = 64;
tuple.TupleOffset = 0;
tuple.DesiredTuple = CISTPL_CONFIG;
CS_CHECK(GetFirstTuple, handle, &tuple);
CS_CHECK(GetTupleData, handle, &tuple);
CS_CHECK(ParseTuple, handle, &tuple, &parse);
link->conf.ConfigBase = parse.config.base;
link->conf.Present = parse.config.rmask[0];
/* Configure card */
link->state |= DEV_CONFIG;
/*
* Try allocating IO ports. This tries a few fixed addresses.
* If you want, you can also read the card's config table to
* pick addresses -- see the serial driver for an example.
*/
for (j = 0x0; j < 0x400; j += 0x20) {
link->io.BasePort1 = j ^ 0x300;
i = CardServices(RequestIO, link->handle, &link->io);
if (i == CS_SUCCESS) break;
}
if (i != CS_SUCCESS) {
cs_error(link->handle, RequestIO, i);
goto failed;
}
/*
* Now allocate an interrupt line. Note that this does not
* actually assign a handler to the interrupt.
*/
CS_CHECK(RequestIRQ, handle, &link->irq);
/*
* This actually configures the PCMCIA socket -- setting up
* the I/O windows and the interrupt mapping.
*/
CS_CHECK(RequestConfiguration, handle, &link->conf);
/*
* Allocate a 32K memory window. Note that the dev_link_t
* structure provides space for one window handle -- if your
* device needs several windows, you'll need to keep track of
* the handles in your private data structure, link->priv.
*/
DEBUG(1, "Setting mem speed of %d\n", mem_speed);
req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
req.Base = 0; req.Size = 0x8000;
req.AccessSpeed = mem_speed;
link->win = (window_handle_t)link->handle;
CS_CHECK(RequestWindow, &link->win, &req);
mem.CardOffset = 0x20000; mem.Page = 0;
CS_CHECK(MapMemPage, link->win, &mem);
/* Store base address of the common window frame */
ramBase = ioremap(req.Base, 0x8000);
((netwave_private*)dev->priv)->ramBase = ramBase;
dev->irq = link->irq.AssignedIRQ;
dev->base_addr = link->io.BasePort1;
dev->tbusy = 0;
if (register_netdev(dev) != 0) {
printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n");
goto failed;
}
link->state &= ~DEV_CONFIG_PENDING;
link->dev = &((netwave_private *)dev->priv)->node;
/* Reset card before reading physical address */
netwave_doreset(dev->base_addr, ramBase);
/* Read the ethernet address and fill in the Netwave registers. */
for (i = 0; i < 6; i++)
dev->dev_addr[i] = readb(ramBase + NETWAVE_EREG_PA + i);
printk(KERN_INFO "%s: Netwave: port %#3lx, irq %d, mem %lx id "
"%c%c, hw_addr ", dev->name, dev->base_addr, dev->irq,
(u_long) ramBase, (int) readb(ramBase+NETWAVE_EREG_NI),
(int) readb(ramBase+NETWAVE_EREG_NI+1));
for (i = 0; i < 6; i++)
printk("%02X%s", dev->dev_addr[i], ((i<5) ? ":" : "\n"));
/* get revision words */
printk(KERN_DEBUG "Netwave_reset: revision %04x %04x\n",
get_uint16(ramBase + NETWAVE_EREG_ARW),
get_uint16(ramBase + NETWAVE_EREG_ARW+2));
return;
cs_failed:
cs_error(link->handle, last_fn, last_ret);
failed:
netwave_release((u_long)link);
return;
} /* netwave_pcmcia_config */
/*
* Function netwave_release (arg)
*
* After a card is removed, netwave_release() will unregister the net
* device, and release the PCMCIA configuration. If the device is
* still open, this will be postponed until it is closed.
*/
static void netwave_release(u_long arg) {
dev_link_t *link = (dev_link_t *)arg;
struct device *dev = link->priv;
DEBUG(0, "netwave_release(0x%p)\n", link);
/*
If the device is currently in use, we won't release until it
is actually closed.
*/
if (link->open) {
printk(KERN_DEBUG "netwave_cs: release postponed, '%s' still open\n",
link->dev->dev_name);
link->state |= DEV_STALE_CONFIG;
return;
}
if (link->dev != '\0')
unregister_netdev(dev);
/* Unlink the device chain */
link->dev = NULL;
/* Don't bother checking to see if these succeed or not */
if (link->win) {
iounmap(((netwave_private *)dev->priv)->ramBase);
CardServices(ReleaseWindow, link->win);
}
CardServices(ReleaseConfiguration, link->handle);
CardServices(ReleaseIO, link->handle, &link->io);
CardServices(ReleaseIRQ, link->handle, &link->irq);
link->state &= ~DEV_CONFIG;
if (link->state & DEV_STALE_LINK)
netwave_detach(link);
} /* netwave_release */
/*
* Function netwave_event (event, priority, args)
*
* The card status event handler. Mostly, this schedules other
* stuff to run after an event is received. A CARD_REMOVAL event
* also sets some flags to discourage the net drivers from trying
* to talk to the card any more.
*
* When a CARD_REMOVAL event is received, we immediately set a flag
* to block future accesses to this device. All the functions that
* actually access the device should check this flag to make sure
* the card is still present.
*
*/
static int netwave_event(event_t event, int priority,
event_callback_args_t *args) {
dev_link_t *link = args->client_data;
struct device *dev = link->priv;
DEBUG(1, "netwave_event(0x%06x)\n", event);
switch (event) {
case CS_EVENT_REGISTRATION_COMPLETE:
DEBUG(0, "netwave_cs: registration complete\n");
break;
case CS_EVENT_CARD_REMOVAL:
link->state &= ~DEV_PRESENT;
if (link->state & DEV_CONFIG) {
dev->tbusy = 1; dev->start = 0;
/* ((netwave_private *)link->priv)->block = 1; */
link->release.expires = RUN_AT(5);
add_timer(&link->release);
}
break;
case CS_EVENT_CARD_INSERTION:
link->state |= DEV_PRESENT | DEV_CONFIG_PENDING;
netwave_pcmcia_config( link);
break;
case CS_EVENT_PM_SUSPEND:
link->state |= DEV_SUSPEND;
/* Fall through... */
case CS_EVENT_RESET_PHYSICAL:
if (link->state & DEV_CONFIG) {
if (link->open) {
dev->tbusy = 1; dev->start = 0;
}
CardServices(ReleaseConfiguration, link->handle);
}
break;
case CS_EVENT_PM_RESUME:
link->state &= ~DEV_SUSPEND;
/* Fall through... */
case CS_EVENT_CARD_RESET:
if (link->state & DEV_CONFIG) {
CardServices(RequestConfiguration, link->handle, &link->conf);
if (link->open) {
netwave_reset(dev);
dev->tbusy = 0; dev->start = 1;
}
}
break;
}
return 0;
} /* netwave_event */
/*
* Function netwave_doreset (ioBase, ramBase)
*
* Proper hardware reset of the card.
*/
static void netwave_doreset(unsigned long ioBase, u_char* ramBase) {
/* Reset card */