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