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#undef NETWAVE_STATS
39
40#include <linux/module.h>
41#include <linux/kernel.h>
42#include <linux/init.h>
43#include <linux/types.h>
44#include <linux/fcntl.h>
45#include <linux/interrupt.h>
46#include <linux/ptrace.h>
47#include <linux/ioport.h>
48#include <linux/in.h>
49#include <linux/slab.h>
50#include <linux/string.h>
51#include <linux/timer.h>
52#include <linux/errno.h>
53#include <linux/netdevice.h>
54#include <linux/etherdevice.h>
55#include <linux/skbuff.h>
56#include <linux/bitops.h>
57#include <linux/wireless.h>
58#include <net/iw_handler.h>
59
60#include <pcmcia/cs_types.h>
61#include <pcmcia/cs.h>
62#include <pcmcia/cistpl.h>
63#include <pcmcia/cisreg.h>
64#include <pcmcia/ds.h>
65#include <pcmcia/mem_op.h>
66
67#include <asm/system.h>
68#include <asm/io.h>
69#include <asm/dma.h>
70
71#define NETWAVE_REGOFF 0x8000
72
73#define NETWAVE_REG_COR 0x0
74#define NETWAVE_REG_CCSR 0x2
75#define NETWAVE_REG_ASR 0x4
76#define NETWAVE_REG_IMR 0xa
77#define NETWAVE_REG_PMR 0xc
78#define NETWAVE_REG_IOLOW 0x6
79#define NETWAVE_REG_IOHI 0x7
80#define NETWAVE_REG_IOCONTROL 0x8
81#define NETWAVE_REG_DATA 0xf
82
83#define NETWAVE_EREG_ASCC 0x114
84#define NETWAVE_EREG_RSER 0x120
85#define NETWAVE_EREG_RSERW 0x124
86#define NETWAVE_EREG_TSER 0x130
87#define NETWAVE_EREG_TSERW 0x134
88#define NETWAVE_EREG_CB 0x100
89#define NETWAVE_EREG_SPCQ 0x154
90#define NETWAVE_EREG_SPU 0x155
91#define NETWAVE_EREG_LIF 0x14e
92#define NETWAVE_EREG_ISPLQ 0x156
93#define NETWAVE_EREG_HHC 0x158
94#define NETWAVE_EREG_NI 0x16e
95#define NETWAVE_EREG_MHS 0x16b
96#define NETWAVE_EREG_TDP 0x140
97#define NETWAVE_EREG_RDP 0x150
98#define NETWAVE_EREG_PA 0x160
99#define NETWAVE_EREG_EC 0x180
100#define NETWAVE_EREG_CRBP 0x17a
101#define NETWAVE_EREG_ARW 0x166
102
103
104
105
106
107#define NETWAVE_CMD_NOP 0x00
108#define NETWAVE_CMD_SRC 0x01
109#define NETWAVE_CMD_STC 0x02
110#define NETWAVE_CMD_AMA 0x03
111#define NETWAVE_CMD_DMA 0x04
112#define NETWAVE_CMD_SAMA 0x05
113#define NETWAVE_CMD_ER 0x06
114#define NETWAVE_CMD_DR 0x07
115#define NETWAVE_CMD_TL 0x08
116#define NETWAVE_CMD_SRP 0x09
117#define NETWAVE_CMD_SSK 0x0a
118#define NETWAVE_CMD_SMD 0x0b
119#define NETWAVE_CMD_SAPD 0x0c
120#define NETWAVE_CMD_SSS 0x11
121
122#define NETWAVE_CMD_EOC 0x00
123
124
125#define NETWAVE_ASR_RXRDY 0x80
126#define NETWAVE_ASR_TXBA 0x01
127
128#define TX_TIMEOUT ((32*HZ)/100)
129
130static const unsigned int imrConfRFU1 = 0x10;
131static const unsigned int imrConfIENA = 0x02;
132
133static const unsigned int corConfIENA = 0x01;
134static const unsigned int corConfLVLREQ = 0x40;
135
136static const unsigned int rxConfRxEna = 0x80;
137static const unsigned int rxConfMAC = 0x20;
138static const unsigned int rxConfPro = 0x10;
139static const unsigned int rxConfAMP = 0x08;
140static const unsigned int rxConfBcast = 0x04;
141
142static const unsigned int txConfTxEna = 0x80;
143static const unsigned int txConfMAC = 0x20;
144static const unsigned int txConfEUD = 0x10;
145static const unsigned int txConfKey = 0x02;
146static const unsigned int txConfLoop = 0x01;
147
148
149
150
151
152
153
154
155
156#ifdef PCMCIA_DEBUG
157static int pc_debug = PCMCIA_DEBUG;
158module_param(pc_debug, int, 0);
159#define DEBUG(n, args...) if (pc_debug>(n)) printk(KERN_DEBUG args)
160static char *version =
161"netwave_cs.c 0.3.0 Thu Jul 17 14:36:02 1997 (John Markus Bjørndalen)\n";
162#else
163#define DEBUG(n, args...)
164#endif
165
166
167
168
169
170
171static u_int domain = 0x100;
172
173
174
175
176static u_int scramble_key = 0x0;
177
178
179
180
181
182
183static int mem_speed;
184
185module_param(domain, int, 0);
186module_param(scramble_key, int, 0);
187module_param(mem_speed, int, 0);
188
189
190
191
192static void netwave_release(struct pcmcia_device *link);
193static int netwave_pcmcia_config(struct pcmcia_device *arg);
194
195static void netwave_detach(struct pcmcia_device *p_dev);
196
197
198static void netwave_doreset(kio_addr_t iobase, u_char __iomem *ramBase);
199static void netwave_reset(struct net_device *dev);
200
201
202static int netwave_open(struct net_device *dev);
203static int netwave_close(struct net_device *dev);
204
205
206static int netwave_start_xmit( struct sk_buff *skb, struct net_device *dev);
207static int netwave_rx( struct net_device *dev);
208
209
210static irqreturn_t netwave_interrupt(int irq, void *dev_id);
211static void netwave_watchdog(struct net_device *);
212
213
214static void update_stats(struct net_device *dev);
215static struct net_device_stats *netwave_get_stats(struct net_device *dev);
216
217
218static struct iw_statistics* netwave_get_wireless_stats(struct net_device *dev);
219
220static void set_multicast_list(struct net_device *dev);
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239static const struct iw_handler_def netwave_handler_def;
240
241#define SIOCGIPSNAP SIOCIWFIRSTPRIV + 1
242
243#define MAX_ESA 10
244
245typedef struct net_addr {
246 u_char addr48[6];
247} net_addr;
248
249struct site_survey {
250 u_short length;
251 u_char struct_revision;
252 u_char roaming_state;
253
254 u_char sp_existsFlag;
255 u_char sp_link_quality;
256 u_char sp_max_link_quality;
257 u_char linkQualityGoodFairBoundary;
258 u_char linkQualityFairPoorBoundary;
259 u_char sp_utilization;
260 u_char sp_goodness;
261 u_char sp_hotheadcount;
262 u_char roaming_condition;
263
264 net_addr sp;
265 u_char numAPs;
266 net_addr nearByAccessPoints[MAX_ESA];
267};
268
269typedef struct netwave_private {
270 struct pcmcia_device *p_dev;
271 spinlock_t spinlock;
272 dev_node_t node;
273 u_char __iomem *ramBase;
274 int timeoutCounter;
275 int lastExec;
276 struct timer_list watchdog;
277 struct site_survey nss;
278 struct net_device_stats stats;
279 struct iw_statistics iw_stats;
280} netwave_private;
281
282#ifdef NETWAVE_STATS
283static struct net_device_stats *netwave_get_stats(struct net_device *dev);
284#endif
285
286
287
288
289
290static inline unsigned short get_uint16(u_char __iomem *staddr)
291{
292 return readw(staddr);
293}
294
295static inline short get_int16(u_char __iomem * staddr)
296{
297 return readw(staddr);
298}
299
300
301
302
303
304
305static inline void wait_WOC(unsigned int iobase)
306{
307
308 while ((inb(iobase + NETWAVE_REG_ASR) & 0x8) != 0x8) ;
309}
310
311static void netwave_snapshot(netwave_private *priv, u_char __iomem *ramBase,
312 kio_addr_t iobase) {
313 u_short resultBuffer;
314
315
316
317
318 if ( jiffies - priv->lastExec > 100) {
319
320
321
322 wait_WOC(iobase);
323 writeb(NETWAVE_CMD_SSS, ramBase + NETWAVE_EREG_CB + 0);
324 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
325 wait_WOC(iobase);
326
327
328 resultBuffer = readw(ramBase + NETWAVE_EREG_CRBP);
329 copy_from_pc( &priv->nss, ramBase+resultBuffer,
330 sizeof(struct site_survey));
331 }
332}
333
334
335
336
337
338
339
340static struct iw_statistics *netwave_get_wireless_stats(struct net_device *dev)
341{
342 unsigned long flags;
343 kio_addr_t iobase = dev->base_addr;
344 netwave_private *priv = netdev_priv(dev);
345 u_char __iomem *ramBase = priv->ramBase;
346 struct iw_statistics* wstats;
347
348 wstats = &priv->iw_stats;
349
350 spin_lock_irqsave(&priv->spinlock, flags);
351
352 netwave_snapshot( priv, ramBase, iobase);
353
354 wstats->status = priv->nss.roaming_state;
355 wstats->qual.qual = readb( ramBase + NETWAVE_EREG_SPCQ);
356 wstats->qual.level = readb( ramBase + NETWAVE_EREG_ISPLQ);
357 wstats->qual.noise = readb( ramBase + NETWAVE_EREG_SPU) & 0x3f;
358 wstats->discard.nwid = 0L;
359 wstats->discard.code = 0L;
360 wstats->discard.misc = 0L;
361
362 spin_unlock_irqrestore(&priv->spinlock, flags);
363
364 return &priv->iw_stats;
365}
366
367
368
369
370
371
372
373
374
375
376
377
378static int netwave_probe(struct pcmcia_device *link)
379{
380 struct net_device *dev;
381 netwave_private *priv;
382
383 DEBUG(0, "netwave_attach()\n");
384
385
386 dev = alloc_etherdev(sizeof(netwave_private));
387 if (!dev)
388 return -ENOMEM;
389 priv = netdev_priv(dev);
390 priv->p_dev = link;
391 link->priv = dev;
392
393
394 link->io.NumPorts1 = 16;
395 link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
396
397
398 link->io.IOAddrLines = 5;
399
400
401 link->irq.Attributes = IRQ_TYPE_EXCLUSIVE | IRQ_HANDLE_PRESENT;
402 link->irq.IRQInfo1 = IRQ_LEVEL_ID;
403 link->irq.Handler = &netwave_interrupt;
404
405
406 link->conf.Attributes = CONF_ENABLE_IRQ;
407 link->conf.IntType = INT_MEMORY_AND_IO;
408 link->conf.ConfigIndex = 1;
409
410
411
412 spin_lock_init(&priv->spinlock);
413
414
415 dev->hard_start_xmit = &netwave_start_xmit;
416 dev->get_stats = &netwave_get_stats;
417 dev->set_multicast_list = &set_multicast_list;
418
419 dev->wireless_handlers = (struct iw_handler_def *)&netwave_handler_def;
420
421 dev->tx_timeout = &netwave_watchdog;
422 dev->watchdog_timeo = TX_TIMEOUT;
423
424 dev->open = &netwave_open;
425 dev->stop = &netwave_close;
426 link->irq.Instance = dev;
427
428 return netwave_pcmcia_config( link);
429}
430
431
432
433
434
435
436
437
438
439static void netwave_detach(struct pcmcia_device *link)
440{
441 struct net_device *dev = link->priv;
442
443 DEBUG(0, "netwave_detach(0x%p)\n", link);
444
445 netwave_release(link);
446
447 if (link->dev_node)
448 unregister_netdev(dev);
449
450 free_netdev(dev);
451}
452
453
454
455
456static int netwave_get_name(struct net_device *dev,
457 struct iw_request_info *info,
458 union iwreq_data *wrqu,
459 char *extra)
460{
461 strcpy(wrqu->name, "Netwave");
462 return 0;
463}
464
465
466
467
468static int netwave_set_nwid(struct net_device *dev,
469 struct iw_request_info *info,
470 union iwreq_data *wrqu,
471 char *extra)
472{
473 unsigned long flags;
474 kio_addr_t iobase = dev->base_addr;
475 netwave_private *priv = netdev_priv(dev);
476 u_char __iomem *ramBase = priv->ramBase;
477
478
479 spin_lock_irqsave(&priv->spinlock, flags);
480
481 if(!wrqu->nwid.disabled) {
482 domain = wrqu->nwid.value;
483 printk( KERN_DEBUG "Setting domain to 0x%x%02x\n",
484 (domain >> 8) & 0x01, domain & 0xff);
485 wait_WOC(iobase);
486 writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
487 writeb( domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
488 writeb((domain >>8 ) & 0x01,ramBase + NETWAVE_EREG_CB+2);
489 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
490 }
491
492
493 spin_unlock_irqrestore(&priv->spinlock, flags);
494
495 return 0;
496}
497
498
499
500
501static int netwave_get_nwid(struct net_device *dev,
502 struct iw_request_info *info,
503 union iwreq_data *wrqu,
504 char *extra)
505{
506 wrqu->nwid.value = domain;
507 wrqu->nwid.disabled = 0;
508 wrqu->nwid.fixed = 1;
509 return 0;
510}
511
512
513
514
515static int netwave_set_scramble(struct net_device *dev,
516 struct iw_request_info *info,
517 union iwreq_data *wrqu,
518 char *key)
519{
520 unsigned long flags;
521 kio_addr_t iobase = dev->base_addr;
522 netwave_private *priv = netdev_priv(dev);
523 u_char __iomem *ramBase = priv->ramBase;
524
525
526 spin_lock_irqsave(&priv->spinlock, flags);
527
528 scramble_key = (key[0] << 8) | key[1];
529 wait_WOC(iobase);
530 writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
531 writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
532 writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
533 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
534
535
536 spin_unlock_irqrestore(&priv->spinlock, flags);
537
538 return 0;
539}
540
541
542
543
544static int netwave_get_scramble(struct net_device *dev,
545 struct iw_request_info *info,
546 union iwreq_data *wrqu,
547 char *key)
548{
549 key[1] = scramble_key & 0xff;
550 key[0] = (scramble_key>>8) & 0xff;
551 wrqu->encoding.flags = IW_ENCODE_ENABLED;
552 wrqu->encoding.length = 2;
553 return 0;
554}
555
556
557
558
559static int netwave_get_mode(struct net_device *dev,
560 struct iw_request_info *info,
561 union iwreq_data *wrqu,
562 char *extra)
563{
564 if(domain & 0x100)
565 wrqu->mode = IW_MODE_INFRA;
566 else
567 wrqu->mode = IW_MODE_ADHOC;
568
569 return 0;
570}
571
572
573
574
575static int netwave_get_range(struct net_device *dev,
576 struct iw_request_info *info,
577 union iwreq_data *wrqu,
578 char *extra)
579{
580 struct iw_range *range = (struct iw_range *) extra;
581 int ret = 0;
582
583
584 wrqu->data.length = sizeof(struct iw_range);
585
586
587 memset(range, 0, sizeof(struct iw_range));
588
589
590 range->we_version_compiled = WIRELESS_EXT;
591 range->we_version_source = 9;
592
593
594 range->throughput = 450 * 1000;
595 range->min_nwid = 0x0000;
596 range->max_nwid = 0x01FF;
597
598 range->num_channels = range->num_frequency = 0;
599
600 range->sensitivity = 0x3F;
601 range->max_qual.qual = 255;
602 range->max_qual.level = 255;
603 range->max_qual.noise = 0;
604
605 range->num_bitrates = 1;
606 range->bitrate[0] = 1000000;
607
608 range->encoding_size[0] = 2;
609 range->num_encoding_sizes = 1;
610 range->max_encoding_tokens = 1;
611
612 return ret;
613}
614
615
616
617
618static int netwave_get_snap(struct net_device *dev,
619 struct iw_request_info *info,
620 union iwreq_data *wrqu,
621 char *extra)
622{
623 unsigned long flags;
624 kio_addr_t iobase = dev->base_addr;
625 netwave_private *priv = netdev_priv(dev);
626 u_char __iomem *ramBase = priv->ramBase;
627
628
629 spin_lock_irqsave(&priv->spinlock, flags);
630
631
632 netwave_snapshot( priv, ramBase, iobase);
633 wrqu->data.length = priv->nss.length;
634 memcpy(extra, (u_char *) &priv->nss, sizeof( struct site_survey));
635
636 priv->lastExec = jiffies;
637
638
639 spin_unlock_irqrestore(&priv->spinlock, flags);
640
641 return(0);
642}
643
644
645
646
647
648
649static const struct iw_priv_args netwave_private_args[] = {
650
651 { SIOCGIPSNAP, 0,
652 IW_PRIV_TYPE_BYTE | IW_PRIV_SIZE_FIXED | sizeof(struct site_survey),
653 "getsitesurvey" },
654};
655
656static const iw_handler netwave_handler[] =
657{
658 NULL,
659 netwave_get_name,
660 netwave_set_nwid,
661 netwave_get_nwid,
662 NULL,
663 NULL,
664 NULL,
665 netwave_get_mode,
666 NULL,
667 NULL,
668 NULL,
669 netwave_get_range,
670 NULL,
671 NULL,
672 NULL,
673 NULL,
674 NULL,
675 NULL,
676 NULL,
677 NULL,
678 NULL,
679 NULL,
680 NULL,
681 NULL,
682 NULL,
683 NULL,
684 NULL,
685 NULL,
686 NULL,
687 NULL,
688 NULL,
689 NULL,
690 NULL,
691 NULL,
692 NULL,
693 NULL,
694 NULL,
695 NULL,
696 NULL,
697 NULL,
698 NULL,
699 NULL,
700 netwave_set_scramble,
701 netwave_get_scramble,
702};
703
704static const iw_handler netwave_private_handler[] =
705{
706 NULL,
707 netwave_get_snap,
708};
709
710static const struct iw_handler_def netwave_handler_def =
711{
712 .num_standard = ARRAY_SIZE(netwave_handler),
713 .num_private = ARRAY_SIZE(netwave_private_handler),
714 .num_private_args = ARRAY_SIZE(netwave_private_args),
715 .standard = (iw_handler *) netwave_handler,
716 .private = (iw_handler *) netwave_private_handler,
717 .private_args = (struct iw_priv_args *) netwave_private_args,
718 .get_wireless_stats = netwave_get_wireless_stats,
719};
720
721
722
723
724
725
726
727
728
729
730#define CS_CHECK(fn, ret) \
731do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
732
733static int netwave_pcmcia_config(struct pcmcia_device *link) {
734 struct net_device *dev = link->priv;
735 netwave_private *priv = netdev_priv(dev);
736 int i, j, last_ret, last_fn;
737 win_req_t req;
738 memreq_t mem;
739 u_char __iomem *ramBase = NULL;
740 DECLARE_MAC_BUF(mac);
741
742 DEBUG(0, "netwave_pcmcia_config(0x%p)\n", link);
743
744
745
746
747
748
749 for (i = j = 0x0; j < 0x400; j += 0x20) {
750 link->io.BasePort1 = j ^ 0x300;
751 i = pcmcia_request_io(link, &link->io);
752 if (i == CS_SUCCESS) break;
753 }
754 if (i != CS_SUCCESS) {
755 cs_error(link, RequestIO, i);
756 goto failed;
757 }
758
759
760
761
762
763 CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
764
765
766
767
768
769 CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
770
771
772
773
774
775
776
777 DEBUG(1, "Setting mem speed of %d\n", mem_speed);
778
779 req.Attributes = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_CM|WIN_ENABLE;
780 req.Base = 0; req.Size = 0x8000;
781 req.AccessSpeed = mem_speed;
782 CS_CHECK(RequestWindow, pcmcia_request_window(&link, &req, &link->win));
783 mem.CardOffset = 0x20000; mem.Page = 0;
784 CS_CHECK(MapMemPage, pcmcia_map_mem_page(link->win, &mem));
785
786
787 ramBase = ioremap(req.Base, 0x8000);
788 priv->ramBase = ramBase;
789
790 dev->irq = link->irq.AssignedIRQ;
791 dev->base_addr = link->io.BasePort1;
792 SET_NETDEV_DEV(dev, &handle_to_dev(link));
793
794 if (register_netdev(dev) != 0) {
795 printk(KERN_DEBUG "netwave_cs: register_netdev() failed\n");
796 goto failed;
797 }
798
799 strcpy(priv->node.dev_name, dev->name);
800 link->dev_node = &priv->node;
801
802
803 netwave_doreset(dev->base_addr, ramBase);
804
805
806 for (i = 0; i < 6; i++)
807 dev->dev_addr[i] = readb(ramBase + NETWAVE_EREG_PA + i);
808
809 printk(KERN_INFO "%s: Netwave: port %#3lx, irq %d, mem %lx, "
810 "id %c%c, hw_addr %s\n",
811 dev->name, dev->base_addr, dev->irq,
812 (u_long) ramBase,
813 (int) readb(ramBase+NETWAVE_EREG_NI),
814 (int) readb(ramBase+NETWAVE_EREG_NI+1),
815 print_mac(mac, dev->dev_addr));
816
817
818 printk(KERN_DEBUG "Netwave_reset: revision %04x %04x\n",
819 get_uint16(ramBase + NETWAVE_EREG_ARW),
820 get_uint16(ramBase + NETWAVE_EREG_ARW+2));
821 return 0;
822
823cs_failed:
824 cs_error(link, last_fn, last_ret);
825failed:
826 netwave_release(link);
827 return -ENODEV;
828}
829
830
831
832
833
834
835
836
837static void netwave_release(struct pcmcia_device *link)
838{
839 struct net_device *dev = link->priv;
840 netwave_private *priv = netdev_priv(dev);
841
842 DEBUG(0, "netwave_release(0x%p)\n", link);
843
844 pcmcia_disable_device(link);
845 if (link->win)
846 iounmap(priv->ramBase);
847}
848
849static int netwave_suspend(struct pcmcia_device *link)
850{
851 struct net_device *dev = link->priv;
852
853 if (link->open)
854 netif_device_detach(dev);
855
856 return 0;
857}
858
859static int netwave_resume(struct pcmcia_device *link)
860{
861 struct net_device *dev = link->priv;
862
863 if (link->open) {
864 netwave_reset(dev);
865 netif_device_attach(dev);
866 }
867
868 return 0;
869}
870
871
872
873
874
875
876
877static void netwave_doreset(kio_addr_t ioBase, u_char __iomem *ramBase)
878{
879
880 wait_WOC(ioBase);
881 outb(0x80, ioBase + NETWAVE_REG_PMR);
882 writeb(0x08, ramBase + NETWAVE_EREG_ASCC);
883 outb(0x0, ioBase + NETWAVE_REG_PMR);
884}
885
886
887
888
889
890
891static void netwave_reset(struct net_device *dev) {
892
893 netwave_private *priv = netdev_priv(dev);
894 u_char __iomem *ramBase = priv->ramBase;
895 kio_addr_t iobase = dev->base_addr;
896
897 DEBUG(0, "netwave_reset: Done with hardware reset\n");
898
899 priv->timeoutCounter = 0;
900
901
902 netwave_doreset(iobase, ramBase);
903 printk(KERN_DEBUG "netwave_reset: Done with hardware reset\n");
904
905
906 wait_WOC(iobase);
907 writeb(NETWAVE_CMD_NOP, ramBase + NETWAVE_EREG_CB + 0);
908 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
909
910
911 wait_WOC(iobase);
912 writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
913 writeb(rxConfRxEna + rxConfBcast, ramBase + NETWAVE_EREG_CB + 1);
914 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
915
916
917 wait_WOC(iobase);
918 writeb(NETWAVE_CMD_STC, ramBase + NETWAVE_EREG_CB + 0);
919 writeb(txConfTxEna, ramBase + NETWAVE_EREG_CB + 1);
920 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
921
922
923 printk(KERN_DEBUG "Setting domain to 0x%x%02x\n", (domain >> 8) & 0x01, domain & 0xff);
924 wait_WOC(iobase);
925 writeb(NETWAVE_CMD_SMD, ramBase + NETWAVE_EREG_CB + 0);
926 writeb(domain & 0xff, ramBase + NETWAVE_EREG_CB + 1);
927 writeb((domain>>8) & 0x01, ramBase + NETWAVE_EREG_CB + 2);
928 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
929
930
931 printk(KERN_DEBUG "Setting scramble key to 0x%x\n", scramble_key);
932 wait_WOC(iobase);
933 writeb(NETWAVE_CMD_SSK, ramBase + NETWAVE_EREG_CB + 0);
934 writeb(scramble_key & 0xff, ramBase + NETWAVE_EREG_CB + 1);
935 writeb((scramble_key>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
936 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
937
938
939
940
941
942
943 wait_WOC(iobase);
944 outb(imrConfIENA+imrConfRFU1, iobase + NETWAVE_REG_IMR);
945
946
947
948
949
950
951
952
953 wait_WOC(iobase);
954 writeb(NETWAVE_CMD_ER, ramBase + NETWAVE_EREG_CB + 0);
955 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
956
957
958 wait_WOC(iobase);
959 outb(corConfIENA + corConfLVLREQ, iobase + NETWAVE_REG_COR);
960}
961
962
963
964
965static int netwave_hw_xmit(unsigned char* data, int len,
966 struct net_device* dev) {
967 unsigned long flags;
968 unsigned int TxFreeList,
969 curBuff,
970 MaxData,
971 DataOffset;
972 int tmpcount;
973
974 netwave_private *priv = netdev_priv(dev);
975 u_char __iomem * ramBase = priv->ramBase;
976 kio_addr_t iobase = dev->base_addr;
977
978
979 spin_lock_irqsave(&priv->spinlock, flags);
980
981
982 wait_WOC(iobase);
983 if ((inb(iobase+NETWAVE_REG_ASR) & NETWAVE_ASR_TXBA) == 0) {
984
985 printk(KERN_DEBUG "netwave_hw_xmit: %s - no xmit buffers available.\n",
986 dev->name);
987 spin_unlock_irqrestore(&priv->spinlock, flags);
988 return 1;
989 }
990
991 priv->stats.tx_bytes += len;
992
993 DEBUG(3, "Transmitting with SPCQ %x SPU %x LIF %x ISPLQ %x\n",
994 readb(ramBase + NETWAVE_EREG_SPCQ),
995 readb(ramBase + NETWAVE_EREG_SPU),
996 readb(ramBase + NETWAVE_EREG_LIF),
997 readb(ramBase + NETWAVE_EREG_ISPLQ));
998
999
1000 wait_WOC(iobase);
1001 TxFreeList = get_uint16(ramBase + NETWAVE_EREG_TDP);
1002 MaxData = get_uint16(ramBase + NETWAVE_EREG_TDP+2);
1003 DataOffset = get_uint16(ramBase + NETWAVE_EREG_TDP+4);
1004
1005 DEBUG(3, "TxFreeList %x, MaxData %x, DataOffset %x\n",
1006 TxFreeList, MaxData, DataOffset);
1007
1008
1009 curBuff = TxFreeList;
1010 tmpcount = 0;
1011 while (tmpcount < len) {
1012 int tmplen = len - tmpcount;
1013 copy_to_pc(ramBase + curBuff + DataOffset, data + tmpcount,
1014 (tmplen < MaxData) ? tmplen : MaxData);
1015 tmpcount += MaxData;
1016
1017
1018 curBuff = get_uint16(ramBase + curBuff);
1019 }
1020
1021
1022 wait_WOC(iobase);
1023 writeb(NETWAVE_CMD_TL, ramBase + NETWAVE_EREG_CB + 0);
1024 writeb(len & 0xff, ramBase + NETWAVE_EREG_CB + 1);
1025 writeb((len>>8) & 0xff, ramBase + NETWAVE_EREG_CB + 2);
1026 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 3);
1027
1028 spin_unlock_irqrestore(&priv->spinlock, flags);
1029 return 0;
1030}
1031
1032static int netwave_start_xmit(struct sk_buff *skb, struct net_device *dev) {
1033
1034
1035
1036
1037
1038
1039 netif_stop_queue(dev);
1040
1041 {
1042 short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
1043 unsigned char* buf = skb->data;
1044
1045 if (netwave_hw_xmit( buf, length, dev) == 1) {
1046
1047 netif_start_queue(dev);
1048 }
1049 dev->trans_start = jiffies;
1050 }
1051 dev_kfree_skb(skb);
1052
1053 return 0;
1054}
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066static irqreturn_t netwave_interrupt(int irq, void* dev_id)
1067{
1068 kio_addr_t iobase;
1069 u_char __iomem *ramBase;
1070 struct net_device *dev = (struct net_device *)dev_id;
1071 struct netwave_private *priv = netdev_priv(dev);
1072 struct pcmcia_device *link = priv->p_dev;
1073 int i;
1074
1075 if (!netif_device_present(dev))
1076 return IRQ_NONE;
1077
1078 iobase = dev->base_addr;
1079 ramBase = priv->ramBase;
1080
1081
1082 for (i = 0; i < 10; i++) {
1083 u_char status;
1084
1085 wait_WOC(iobase);
1086 if (!(inb(iobase+NETWAVE_REG_CCSR) & 0x02))
1087 break;
1088
1089 status = inb(iobase + NETWAVE_REG_ASR);
1090
1091 if (!pcmcia_dev_present(link)) {
1092 DEBUG(1, "netwave_interrupt: Interrupt with status 0x%x "
1093 "from removed or suspended card!\n", status);
1094 break;
1095 }
1096
1097
1098 if (status & 0x80) {
1099 netwave_rx(dev);
1100
1101
1102 }
1103
1104 if (status & 0x40) {
1105 u_char rser;
1106
1107 rser = readb(ramBase + NETWAVE_EREG_RSER);
1108
1109 if (rser & 0x04) {
1110 ++priv->stats.rx_dropped;
1111 ++priv->stats.rx_crc_errors;
1112 }
1113 if (rser & 0x02)
1114 ++priv->stats.rx_frame_errors;
1115
1116
1117
1118
1119 wait_WOC(iobase);
1120 writeb(0x40 | (rser & 0x06), ramBase + NETWAVE_EREG_RSER + 4);
1121
1122
1123
1124
1125 wait_WOC(iobase);
1126 writeb(0x40, ramBase + NETWAVE_EREG_ASCC);
1127
1128
1129 ++priv->stats.rx_errors;
1130 }
1131
1132 if (status & 0x20) {
1133 int txStatus;
1134
1135 txStatus = readb(ramBase + NETWAVE_EREG_TSER);
1136 DEBUG(3, "Transmit done. TSER = %x id %x\n",
1137 txStatus, readb(ramBase + NETWAVE_EREG_TSER + 1));
1138
1139 if (txStatus & 0x20) {
1140
1141 wait_WOC(iobase);
1142 writeb(0x2f, ramBase + NETWAVE_EREG_TSER + 4);
1143 ++priv->stats.tx_packets;
1144 }
1145
1146 if (txStatus & 0xd0) {
1147 if (txStatus & 0x80) {
1148 ++priv->stats.collisions;
1149
1150
1151 }
1152 if (txStatus & 0x40)
1153 ++priv->stats.tx_carrier_errors;
1154
1155
1156
1157
1158
1159
1160 DEBUG(3, "netwave_interrupt: TxDN with error status %x\n",
1161 txStatus);
1162
1163
1164 wait_WOC(iobase);
1165 writeb(0xdf & txStatus, ramBase+NETWAVE_EREG_TSER+4);
1166 ++priv->stats.tx_errors;
1167 }
1168 DEBUG(3, "New status is TSER %x ASR %x\n",
1169 readb(ramBase + NETWAVE_EREG_TSER),
1170 inb(iobase + NETWAVE_REG_ASR));
1171
1172 netif_wake_queue(dev);
1173 }
1174
1175
1176
1177
1178
1179 }
1180
1181 return IRQ_RETVAL(i);
1182}
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192static void netwave_watchdog(struct net_device *dev) {
1193
1194 DEBUG(1, "%s: netwave_watchdog: watchdog timer expired\n", dev->name);
1195 netwave_reset(dev);
1196 dev->trans_start = jiffies;
1197 netif_wake_queue(dev);
1198}
1199
1200static struct net_device_stats *netwave_get_stats(struct net_device *dev) {
1201 netwave_private *priv = netdev_priv(dev);
1202
1203 update_stats(dev);
1204
1205 DEBUG(2, "netwave: SPCQ %x SPU %x LIF %x ISPLQ %x MHS %x rxtx %x"
1206 " %x tx %x %x %x %x\n",
1207 readb(priv->ramBase + NETWAVE_EREG_SPCQ),
1208 readb(priv->ramBase + NETWAVE_EREG_SPU),
1209 readb(priv->ramBase + NETWAVE_EREG_LIF),
1210 readb(priv->ramBase + NETWAVE_EREG_ISPLQ),
1211 readb(priv->ramBase + NETWAVE_EREG_MHS),
1212 readb(priv->ramBase + NETWAVE_EREG_EC + 0xe),
1213 readb(priv->ramBase + NETWAVE_EREG_EC + 0xf),
1214 readb(priv->ramBase + NETWAVE_EREG_EC + 0x18),
1215 readb(priv->ramBase + NETWAVE_EREG_EC + 0x19),
1216 readb(priv->ramBase + NETWAVE_EREG_EC + 0x1a),
1217 readb(priv->ramBase + NETWAVE_EREG_EC + 0x1b));
1218
1219 return &priv->stats;
1220}
1221
1222static void update_stats(struct net_device *dev) {
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232}
1233
1234static int netwave_rx(struct net_device *dev)
1235{
1236 netwave_private *priv = netdev_priv(dev);
1237 u_char __iomem *ramBase = priv->ramBase;
1238 kio_addr_t iobase = dev->base_addr;
1239 u_char rxStatus;
1240 struct sk_buff *skb = NULL;
1241 unsigned int curBuffer,
1242 rcvList;
1243 int rcvLen;
1244 int tmpcount = 0;
1245 int dataCount, dataOffset;
1246 int i;
1247 u_char *ptr;
1248
1249 DEBUG(3, "xinw_rx: Receiving ... \n");
1250
1251
1252 for (i = 0; i < 10; i++) {
1253
1254 wait_WOC(iobase);
1255 rxStatus = readb(ramBase + NETWAVE_EREG_RSER);
1256 if ( !( rxStatus & 0x80))
1257 break;
1258
1259
1260
1261
1262
1263 wait_WOC(iobase);
1264 rcvLen = get_int16( ramBase + NETWAVE_EREG_RDP);
1265 rcvList = get_uint16( ramBase + NETWAVE_EREG_RDP + 2);
1266
1267 if (rcvLen < 0) {
1268 printk(KERN_DEBUG "netwave_rx: Receive packet with len %d\n",
1269 rcvLen);
1270 return 0;
1271 }
1272
1273 skb = dev_alloc_skb(rcvLen+5);
1274 if (skb == NULL) {
1275 DEBUG(1, "netwave_rx: Could not allocate an sk_buff of "
1276 "length %d\n", rcvLen);
1277 ++priv->stats.rx_dropped;
1278
1279 wait_WOC(iobase);
1280 writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1281 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1282 return 0;
1283 }
1284
1285 skb_reserve( skb, 2);
1286 skb_put( skb, rcvLen);
1287
1288
1289 ptr = (u_char*) skb->data;
1290 curBuffer = rcvList;
1291 tmpcount = 0;
1292 while ( tmpcount < rcvLen) {
1293
1294 dataCount = get_uint16( ramBase+curBuffer+2);
1295 dataOffset = get_uint16( ramBase+curBuffer+4);
1296
1297 copy_from_pc( ptr + tmpcount,
1298 ramBase+curBuffer+dataOffset, dataCount);
1299
1300 tmpcount += dataCount;
1301
1302
1303 curBuffer = get_uint16(ramBase + curBuffer);
1304 }
1305
1306 skb->protocol = eth_type_trans(skb,dev);
1307
1308 netif_rx(skb);
1309
1310 dev->last_rx = jiffies;
1311 priv->stats.rx_packets++;
1312 priv->stats.rx_bytes += rcvLen;
1313
1314
1315 wait_WOC(iobase);
1316 writeb(NETWAVE_CMD_SRP, ramBase + NETWAVE_EREG_CB + 0);
1317 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 1);
1318 DEBUG(3, "Packet reception ok\n");
1319 }
1320 return 0;
1321}
1322
1323static int netwave_open(struct net_device *dev) {
1324 netwave_private *priv = netdev_priv(dev);
1325 struct pcmcia_device *link = priv->p_dev;
1326
1327 DEBUG(1, "netwave_open: starting.\n");
1328
1329 if (!pcmcia_dev_present(link))
1330 return -ENODEV;
1331
1332 link->open++;
1333
1334 netif_start_queue(dev);
1335 netwave_reset(dev);
1336
1337 return 0;
1338}
1339
1340static int netwave_close(struct net_device *dev) {
1341 netwave_private *priv = netdev_priv(dev);
1342 struct pcmcia_device *link = priv->p_dev;
1343
1344 DEBUG(1, "netwave_close: finishing.\n");
1345
1346 link->open--;
1347 netif_stop_queue(dev);
1348
1349 return 0;
1350}
1351
1352static struct pcmcia_device_id netwave_ids[] = {
1353 PCMCIA_DEVICE_PROD_ID12("Xircom", "CreditCard Netwave", 0x2e3ee845, 0x54e28a28),
1354 PCMCIA_DEVICE_NULL,
1355};
1356MODULE_DEVICE_TABLE(pcmcia, netwave_ids);
1357
1358static struct pcmcia_driver netwave_driver = {
1359 .owner = THIS_MODULE,
1360 .drv = {
1361 .name = "netwave_cs",
1362 },
1363 .probe = netwave_probe,
1364 .remove = netwave_detach,
1365 .id_table = netwave_ids,
1366 .suspend = netwave_suspend,
1367 .resume = netwave_resume,
1368};
1369
1370static int __init init_netwave_cs(void)
1371{
1372 return pcmcia_register_driver(&netwave_driver);
1373}
1374
1375static void __exit exit_netwave_cs(void)
1376{
1377 pcmcia_unregister_driver(&netwave_driver);
1378}
1379
1380module_init(init_netwave_cs);
1381module_exit(exit_netwave_cs);
1382
1383
1384
1385
1386
1387
1388
1389static void set_multicast_list(struct net_device *dev)
1390{
1391 kio_addr_t iobase = dev->base_addr;
1392 netwave_private *priv = netdev_priv(dev);
1393 u_char __iomem * ramBase = priv->ramBase;
1394 u_char rcvMode = 0;
1395
1396#ifdef PCMCIA_DEBUG
1397 if (pc_debug > 2) {
1398 static int old;
1399 if (old != dev->mc_count) {
1400 old = dev->mc_count;
1401 DEBUG(0, "%s: setting Rx mode to %d addresses.\n",
1402 dev->name, dev->mc_count);
1403 }
1404 }
1405#endif
1406
1407 if (dev->mc_count || (dev->flags & IFF_ALLMULTI)) {
1408
1409 rcvMode = rxConfRxEna + rxConfAMP + rxConfBcast;
1410 } else if (dev->flags & IFF_PROMISC) {
1411
1412 rcvMode = rxConfRxEna + rxConfPro + rxConfAMP + rxConfBcast;
1413 } else {
1414
1415 rcvMode = rxConfRxEna + rxConfBcast;
1416 }
1417
1418
1419
1420 wait_WOC(iobase);
1421 writeb(NETWAVE_CMD_SRC, ramBase + NETWAVE_EREG_CB + 0);
1422 writeb(rcvMode, ramBase + NETWAVE_EREG_CB + 1);
1423 writeb(NETWAVE_CMD_EOC, ramBase + NETWAVE_EREG_CB + 2);
1424}
1425MODULE_LICENSE("GPL");
1426