This source file includes following definitions.
- de600_read_status
- de600_read_byte
- de600_open
- de600_close
- get_stats
- trigger_interrupt
- de600_start_xmit
- de600_interrupt
- de600_tx_intr
- de600_rx_intr
- de600_probe
- adapter_init
- de600_rspace
- init_module
- cleanup_module
1 static char *version =
2 "de600.c: $Revision: 1.35 $, Bjorn Ekwall (bj0rn@blox.se)\n";
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 #define DE600_SLOW_DOWN SLOW_DOWN_IO; SLOW_DOWN_IO; SLOW_DOWN_IO
44
45
46
47
48
49
50 #define SLOW_IO_BY_JUMPING
51
52
53
54
55
56
57
58 #ifdef DE600_DEBUG
59 #define PRINTK(x) if (de600_debug >= 2) printk x
60 #else
61 #define DE600_DEBUG 0
62 #define PRINTK(x)
63 #endif
64 static unsigned int de600_debug = DE600_DEBUG;
65
66 #include <linux/config.h>
67 #include <linux/kernel.h>
68 #include <linux/sched.h>
69 #include <linux/types.h>
70 #include <linux/fcntl.h>
71 #include <linux/string.h>
72 #include <linux/interrupt.h>
73 #include <asm/io.h>
74 #include <netinet/in.h>
75 #include <linux/ptrace.h>
76 #include <asm/system.h>
77 #include <errno.h>
78
79 #include <linux/inet.h>
80 #include <linux/netdevice.h>
81 #include <linux/etherdevice.h>
82 #include <linux/skbuff.h>
83
84 #ifdef MODULE
85 #include <linux/module.h>
86 #include "../../tools/version.h"
87 #endif
88
89 #define netstats enet_statistics
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108 #ifndef DE600_IO
109 #define DE600_IO 0x378
110 #endif
111
112 #define DATA_PORT (DE600_IO)
113 #define STATUS_PORT (DE600_IO + 1)
114 #define COMMAND_PORT (DE600_IO + 2)
115
116 #ifndef DE600_IRQ
117 #define DE600_IRQ 7
118 #endif
119
120
121
122
123
124
125
126
127
128
129
130
131 #define SELECT_NIC 0x04
132 #define SELECT_PRN 0x1c
133 #define NML_PRN 0xec
134 #define IRQEN 0x10
135
136
137
138
139 #define RX_BUSY 0x80
140 #define RX_GOOD 0x40
141 #define TX_FAILED16 0x10
142 #define TX_BUSY 0x08
143
144
145
146
147
148
149
150 #define WRITE_DATA 0x00
151 #define READ_DATA 0x01
152 #define STATUS 0x02
153 #define COMMAND 0x03
154 #define NULL_COMMAND 0x04
155 #define RX_LEN 0x05
156 #define TX_ADDR 0x06
157 #define RW_ADDR 0x07
158 #define HI_NIBBLE 0x08
159
160
161
162
163
164 #define RX_ALL 0x01
165 #define RX_BP 0x02
166 #define RX_MBP 0x03
167
168 #define TX_ENABLE 0x04
169 #define RX_ENABLE 0x08
170
171 #define RESET 0x80
172 #define STOP_RESET 0x00
173
174
175
176
177
178 #define RX_PAGE2_SELECT 0x10
179 #define RX_BASE_PAGE 0x20
180 #define FLIP_IRQ 0x40
181
182
183
184
185
186
187
188
189
190
191
192
193 #define MEM_2K 0x0800
194 #define MEM_4K 0x1000
195 #define MEM_6K 0x1800
196 #define NODE_ADDRESS 0x2000
197
198 #define RUNT 60
199
200
201
202
203
204
205
206
207
208
209 #if 0
210
211 static unsigned long de600_rspace(struct sock *sk);
212 #endif
213
214
215 static int de600_read_status(struct device *dev);
216 static unsigned char de600_read_byte(unsigned char type, struct device *dev);
217
218
219 static int de600_open(struct device *dev);
220 static int de600_close(struct device *dev);
221 static struct netstats *get_stats(struct device *dev);
222 static int de600_start_xmit(struct sk_buff *skb, struct device *dev);
223
224
225 static void de600_interrupt(int reg_ptr);
226 static int de600_tx_intr(struct device *dev, int irq_status);
227 static void de600_rx_intr(struct device *dev);
228
229
230 static void trigger_interrupt(struct device *dev);
231 int de600_probe(struct device *dev);
232 static void adapter_init(struct device *dev);
233
234
235
236
237 extern struct device *irq2dev_map[16];
238 static volatile int rx_page = 0;
239
240 #define TX_PAGES 2
241 static volatile int tx_fifo[TX_PAGES];
242 static volatile int tx_fifo_in = 0;
243 static volatile int tx_fifo_out = 0;
244 static volatile int free_tx_pages = TX_PAGES;
245
246
247
248
249
250 #define select_prn() outb_p(SELECT_PRN, COMMAND_PORT); DE600_SLOW_DOWN
251 #define select_nic() outb_p(SELECT_NIC, COMMAND_PORT); DE600_SLOW_DOWN
252
253
254 #define de600_put_byte(data) ( \
255 outb_p(((data) << 4) | WRITE_DATA , DATA_PORT), \
256 outb_p(((data) & 0xf0) | WRITE_DATA | HI_NIBBLE, DATA_PORT))
257
258
259
260
261
262 #define de600_put_command(cmd) ( \
263 outb_p(( rx_page << 4) | COMMAND , DATA_PORT), \
264 outb_p(( rx_page & 0xf0) | COMMAND | HI_NIBBLE, DATA_PORT), \
265 outb_p(((rx_page | cmd) << 4) | COMMAND , DATA_PORT), \
266 outb_p(((rx_page | cmd) & 0xf0) | COMMAND | HI_NIBBLE, DATA_PORT))
267
268 #define de600_setup_address(addr,type) ( \
269 outb_p((((addr) << 4) & 0xf0) | type , DATA_PORT), \
270 outb_p(( (addr) & 0xf0) | type | HI_NIBBLE, DATA_PORT), \
271 outb_p((((addr) >> 4) & 0xf0) | type , DATA_PORT), \
272 outb_p((((addr) >> 8) & 0xf0) | type | HI_NIBBLE, DATA_PORT))
273
274 #define rx_page_adr() ((rx_page & RX_PAGE2_SELECT)?(MEM_6K):(MEM_4K))
275
276
277 #define next_rx_page() (rx_page ^= RX_PAGE2_SELECT)
278
279 #define tx_page_adr(a) (((a) + 1) * MEM_2K)
280
281 static inline int
282 de600_read_status(struct device *dev)
283 {
284 int status;
285
286 outb_p(STATUS, DATA_PORT);
287 status = inb(STATUS_PORT);
288 outb_p(NULL_COMMAND | HI_NIBBLE, DATA_PORT);
289
290 return status;
291 }
292
293 static inline unsigned char
294 de600_read_byte(unsigned char type, struct device *dev) {
295 unsigned char lo;
296
297 (void)outb_p((type), DATA_PORT);
298 lo = ((unsigned char)inb(STATUS_PORT)) >> 4;
299 (void)outb_p((type) | HI_NIBBLE, DATA_PORT);
300 return ((unsigned char)inb(STATUS_PORT) & (unsigned char)0xf0) | lo;
301 }
302
303
304
305
306
307
308
309
310
311 static int
312 de600_open(struct device *dev)
313 {
314 #if 0
315 extern struct proto tcp_prot;
316 #endif
317
318 if (request_irq(DE600_IRQ, de600_interrupt)) {
319 printk ("%s: unable to get IRQ %d\n", dev->name, DE600_IRQ);
320 return 1;
321 }
322 irq2dev_map[DE600_IRQ] = dev;
323
324 #ifdef MODULE
325 MOD_INC_USE_COUNT;
326 #endif
327 adapter_init(dev);
328
329
330
331
332
333
334
335
336
337
338 #if 0
339 tcp_prot.rspace = de600_rspace;
340 #endif
341
342
343 return 0;
344 }
345
346
347
348
349 static int
350 de600_close(struct device *dev)
351 {
352 select_nic();
353 rx_page = 0;
354 de600_put_command(RESET);
355 de600_put_command(STOP_RESET);
356 de600_put_command(0);
357 select_prn();
358
359 free_irq(DE600_IRQ);
360 irq2dev_map[DE600_IRQ] = NULL;
361 dev->start = 0;
362 #ifdef MODULE
363 MOD_DEC_USE_COUNT;
364 #endif
365 #if 0
366 tcp_prot.rspace = sock_rspace;
367 #endif
368 return 0;
369 }
370
371 static struct netstats *
372 get_stats(struct device *dev)
373 {
374 return (struct netstats *)(dev->priv);
375 }
376
377 static inline void
378 trigger_interrupt(struct device *dev)
379 {
380 de600_put_command(FLIP_IRQ);
381 select_prn();
382 DE600_SLOW_DOWN;
383 select_nic();
384 de600_put_command(0);
385 }
386
387
388
389
390
391 static int
392 de600_start_xmit(struct sk_buff *skb, struct device *dev)
393 {
394 int transmit_from;
395 int len;
396 int tickssofar;
397 unsigned char *buffer = skb->data;
398
399
400
401
402
403
404
405 if (skb == NULL) {
406 dev_tint(dev);
407 return 0;
408 }
409
410 if (free_tx_pages <= 0) {
411 tickssofar = jiffies - dev->trans_start;
412
413 if (tickssofar < 5)
414 return 1;
415
416
417 printk("%s: transmit timed out (%d), %s?\n",
418 dev->name,
419 tickssofar,
420 "network cable problem"
421 );
422
423 adapter_init(dev);
424 }
425
426
427 PRINTK(("de600_start_xmit:len=%d, page %d/%d\n", skb->len, tx_fifo_in, free_tx_pages));
428
429 if ((len = skb->len) < RUNT)
430 len = RUNT;
431
432 cli();
433 select_nic();
434
435 tx_fifo[tx_fifo_in] = transmit_from = tx_page_adr(tx_fifo_in) - len;
436 tx_fifo_in = (tx_fifo_in + 1) % TX_PAGES;
437
438 de600_setup_address(transmit_from, RW_ADDR);
439 for ( ; len > 0; --len, ++buffer)
440 de600_put_byte(*buffer);
441
442 if (free_tx_pages-- == TX_PAGES) {
443 dev->trans_start = jiffies;
444 dev->tbusy = 0;
445
446 de600_setup_address(transmit_from, TX_ADDR);
447 de600_put_command(TX_ENABLE);
448 }
449 else {
450 dev->tbusy = !free_tx_pages;
451 select_prn();
452 }
453
454 sti();
455
456 if (skb->free)
457 kfree_skb (skb, FREE_WRITE);
458
459 return 0;
460 }
461
462
463
464
465
466 static void
467 de600_interrupt(int reg_ptr)
468 {
469 int irq = -(((struct pt_regs *)reg_ptr)->orig_eax+2);
470 struct device *dev = irq2dev_map[irq];
471 unsigned char irq_status;
472 int retrig = 0;
473 int boguscount = 0;
474
475
476 if ((dev == NULL) || (dev->start == 0) || (DE600_IRQ != irq)) {
477 printk("%s: bogus interrupt %d\n", dev?dev->name:"DE-600", irq);
478 return;
479 }
480
481 dev->interrupt = 1;
482 select_nic();
483 irq_status = de600_read_status(dev);
484
485 do {
486 PRINTK(("de600_interrupt (%2.2X)\n", irq_status));
487
488 if (irq_status & RX_GOOD)
489 de600_rx_intr(dev);
490 else if (!(irq_status & RX_BUSY))
491 de600_put_command(RX_ENABLE);
492
493
494 if (free_tx_pages < TX_PAGES)
495 retrig = de600_tx_intr(dev, irq_status);
496 else
497 retrig = 0;
498
499 irq_status = de600_read_status(dev);
500 } while ( (irq_status & RX_GOOD) || ((++boguscount < 10) && retrig) );
501
502
503
504
505
506
507
508 dev->interrupt = 0;
509 select_prn();
510
511 if (retrig)
512 trigger_interrupt(dev);
513
514 sti();
515 return;
516 }
517
518 static int
519 de600_tx_intr(struct device *dev, int irq_status)
520 {
521
522
523
524
525 mark_bh(NET_BH);
526
527 if (irq_status & TX_BUSY)
528 return 1;
529
530
531
532 if (!(irq_status & TX_FAILED16)) {
533 tx_fifo_out = (tx_fifo_out + 1) % TX_PAGES;
534 ++free_tx_pages;
535 ((struct netstats *)(dev->priv))->tx_packets++;
536 dev->tbusy = 0;
537 }
538
539
540 if ((free_tx_pages < TX_PAGES) || (irq_status & TX_FAILED16)) {
541 dev->trans_start = jiffies;
542 de600_setup_address(tx_fifo[tx_fifo_out], TX_ADDR);
543 de600_put_command(TX_ENABLE);
544 return 1;
545 }
546
547
548 return 0;
549 }
550
551
552
553
554 static void
555 de600_rx_intr(struct device *dev)
556 {
557 struct sk_buff *skb;
558 int i;
559 int read_from;
560 int size;
561 register unsigned char *buffer;
562
563 cli();
564
565 size = de600_read_byte(RX_LEN, dev);
566 size += (de600_read_byte(RX_LEN, dev) << 8);
567 size -= 4;
568
569
570 read_from = rx_page_adr();
571 next_rx_page();
572 de600_put_command(RX_ENABLE);
573 sti();
574
575 if ((size < 32) || (size > 1535))
576 printk("%s: Bogus packet size %d.\n", dev->name, size);
577
578 skb = alloc_skb(size, GFP_ATOMIC);
579 sti();
580 if (skb == NULL) {
581 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
582 dev->name, size);
583 return;
584 }
585
586
587 skb->lock = 0;
588
589 buffer = skb->data;
590
591
592 de600_setup_address(read_from, RW_ADDR);
593 for (i = size; i > 0; --i, ++buffer)
594 *buffer = de600_read_byte(READ_DATA, dev);
595
596 ((struct netstats *)(dev->priv))->rx_packets++;
597
598 if (dev_rint((unsigned char *)skb, size, IN_SKBUFF, dev))
599 printk("%s: receive buffers full.\n", dev->name);
600
601
602
603
604
605 }
606
607 int
608 de600_probe(struct device *dev)
609 {
610 int i;
611 static struct netstats de600_netstats;
612
613
614 printk("%s: D-Link DE-600 pocket adapter", dev->name);
615
616 if (de600_debug > 1)
617 printk(version);
618
619
620 rx_page = 0;
621 select_nic();
622 (void)de600_read_status(dev);
623 de600_put_command(RESET);
624 de600_put_command(STOP_RESET);
625 if (de600_read_status(dev) & 0xf0) {
626 printk(": not at I/O %#3x.\n", DATA_PORT);
627 return ENODEV;
628 }
629
630
631
632
633
634
635
636 de600_setup_address(NODE_ADDRESS, RW_ADDR);
637 for (i = 0; i < ETH_ALEN; i++) {
638 dev->dev_addr[i] = de600_read_byte(READ_DATA, dev);
639 dev->broadcast[i] = 0xff;
640 }
641
642
643 if ((dev->dev_addr[1] == 0xde) && (dev->dev_addr[2] == 0x15)) {
644
645 dev->dev_addr[0] = 0x00;
646 dev->dev_addr[1] = 0x80;
647 dev->dev_addr[2] = 0xc8;
648 dev->dev_addr[3] &= 0x0f;
649 dev->dev_addr[3] |= 0x70;
650 } else {
651 printk(" not identified in the printer port\n");
652 return ENODEV;
653 }
654
655 printk(", Ethernet Address: %2.2X", dev->dev_addr[0]);
656 for (i = 1; i < ETH_ALEN; i++)
657 printk(":%2.2X",dev->dev_addr[i]);
658 printk("\n");
659
660
661
662 dev->priv = &de600_netstats;
663
664 memset(dev->priv, 0, sizeof(struct netstats));
665 dev->get_stats = get_stats;
666
667 dev->open = de600_open;
668 dev->stop = de600_close;
669 dev->hard_start_xmit = &de600_start_xmit;
670
671 ether_setup(dev);
672
673 select_prn();
674 return 0;
675 }
676
677 static void
678 adapter_init(struct device *dev)
679 {
680 int i;
681
682 cli();
683 dev->tbusy = 0;
684 dev->interrupt = 0;
685 dev->start = 1;
686
687 select_nic();
688 rx_page = 0;
689 de600_put_command(RESET);
690 de600_put_command(STOP_RESET);
691
692 tx_fifo_in = 0;
693 tx_fifo_out = 0;
694 free_tx_pages = TX_PAGES;
695
696
697 de600_setup_address(NODE_ADDRESS, RW_ADDR);
698 for (i = 0; i < ETH_ALEN; i++)
699 de600_put_byte(dev->dev_addr[i]);
700
701
702 rx_page = RX_BP | RX_BASE_PAGE;
703 de600_setup_address(MEM_4K, RW_ADDR);
704
705 de600_put_command(RX_ENABLE);
706 select_prn();
707 sti();
708 }
709
710 #if 0
711
712
713
714 #define DE600_MIN_WINDOW 1024
715 #define DE600_MAX_WINDOW 2048
716 #define DE600_TCP_WINDOW_DIFF 1024
717
718
719
720
721
722
723
724
725
726
727
728
729 #define min(a,b) ((a)<(b)?(a):(b))
730 static unsigned long
731 de600_rspace(struct sock *sk)
732 {
733 int amt;
734
735 if (sk != NULL) {
736
737
738
739
740 sk->max_unacked = DE600_MAX_WINDOW - DE600_TCP_WINDOW_DIFF;
741
742 if (sk->rmem_alloc >= SK_RMEM_MAX-2*DE600_MIN_WINDOW) return(0);
743 amt = min((SK_RMEM_MAX-sk->rmem_alloc)/2-DE600_MIN_WINDOW, DE600_MAX_WINDOW);
744 if (amt < 0) return(0);
745 return(amt);
746 }
747 return(0);
748 }
749 #endif
750
751 #ifdef MODULE
752 char kernel_version[] = UTS_RELEASE;
753 static struct device de600_dev = {
754 "" , 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, de600_probe };
755
756 int
757 init_module(void)
758 {
759 if (register_netdev(&de600_dev) != 0)
760 return -EIO;
761 return 0;
762 }
763
764 void
765 cleanup_module(void)
766 {
767 if (MOD_IN_USE)
768 printk("de600: device busy, remove delayed\n");
769 else
770 unregister_netdev(&de600_dev);
771 }
772 #endif