1 /* atp.c: Attached (pocket) ethernet adapter driver for linux. */
3 This is a driver for a commonly OEMed pocket (parallel port)
6 Written 1993,1994,1995 by Donald Becker.
8 Copyright 1993 United States Government as represented by the
9 Director, National Security Agency.
11 This software may be used and distributed according to the terms
12 of the GNU Public License, incorporated herein by reference.
14 The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
15 Center of Excellence in Space Data and Information Sciences
16 Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
18 The timer-based reset code was written by Bill Carlson, wwc@super.org.
21 static const char *version
=
22 "atp.c:v1.01 1/18/95 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
25 This file is a device driver for the RealTek (aka AT-Lan-Tec) pocket
26 ethernet adapter. This is a common low-cost OEM pocket ethernet
27 adapter, sold under many names.
30 This driver was written from the packet driver assembly code provided by
31 Vincent Bono of AT-Lan-Tec. Ever try to figure out how a complicated
32 device works just from the assembly code? It ain't pretty. The following
33 description is written based on guesses and writing lots of special-purpose
34 code to test my theorized operation.
38 The RTL8002 adapter seems to be built around a custom spin of the SEEQ
39 controller core. It probably has a 16K or 64K internal packet buffer, of
40 which the first 4K is devoted to transmit and the rest to receive.
41 The controller maintains the queue of received packet and the packet buffer
42 access pointer internally, with only 'reset to beginning' and 'skip to next
43 packet' commands visible. The transmit packet queue holds two (or more?)
44 packets: both 'retransmit this packet' (due to collision) and 'transmit next
45 packet' commands must be started by hand.
47 The station address is stored in a standard bit-serial EEPROM which must be
48 read (ughh) by the device driver. (Provisions have been made for
49 substituting a 74S288 PROM, but I haven't gotten reports of any models
50 using it.) Unlike built-in devices, a pocket adapter can temporarily lose
51 power without indication to the device driver. The major effect is that
52 the station address, receive filter (promiscuous, etc.) and transceiver
55 The controller itself has 16 registers, some of which use only the lower
56 bits. The registers are read and written 4 bits at a time. The four bit
57 register address is presented on the data lines along with a few additional
58 timing and control bits. The data is then read from status port or written
61 Since the bulk data transfer of the actual packets through the slow
62 parallel port dominates the driver's running time, four distinct data
63 (non-register) transfer modes are provided by the adapter, two in each
64 direction. In the first mode timing for the nibble transfers is
65 provided through the data port. In the second mode the same timing is
66 provided through the control port. In either case the data is read from
67 the status port and written to the data port, just as it is accessing
70 In addition to the basic data transfer methods, several more are modes are
71 created by adding some delay by doing multiple reads of the data to allow
72 it to stabilize. This delay seems to be needed on most machines.
74 The data transfer mode is stored in the 'dev->if_port' field. Its default
75 value is '4'. It may be overridden at boot-time using the third parameter
76 to the "ether=..." initialization.
78 The header file <atp.h> provides inline functions that encapsulate the
79 register and data access methods. These functions are hand-tuned to
80 generate reasonable object code. This header file also documents my
81 interpretations of the device registers.
84 #include <linux/kernel.h>
85 #include <linux/sched.h>
86 #include <linux/types.h>
87 #include <linux/fcntl.h>
88 #include <linux/interrupt.h>
89 #include <linux/ptrace.h>
90 #include <linux/ioport.h>
92 #include <linux/malloc.h>
93 #include <linux/string.h>
94 #include <asm/system.h>
95 #include <asm/bitops.h>
98 #include <linux/errno.h>
99 #include <linux/init.h>
101 #include <linux/netdevice.h>
102 #include <linux/etherdevice.h>
103 #include <linux/skbuff.h>
107 /* use 0 for production, 1 for verification, >2 for debug */
111 static unsigned int net_debug
= NET_DEBUG
;
113 /* The number of low I/O ports used by the ethercard. */
114 #define ETHERCARD_TOTAL_SIZE 3
116 /* This code, written by wwc@super.org, resets the adapter every
117 TIMED_CHECKER ticks. This recovers from an unknown error which
119 #define TIMED_CHECKER (HZ/4)
121 #include <linux/timer.h>
122 static void atp_timed_checker(unsigned long ignored
);
123 static struct net_device
*atp_timed_dev
;
124 static struct timer_list atp_timer
= {NULL
, NULL
, 0, 0, atp_timed_checker
};
127 /* Index to functions, as function prototypes. */
129 extern int atp_probe(struct net_device
*dev
);
131 static int atp_probe1(struct net_device
*dev
, short ioaddr
);
132 static void get_node_ID(struct net_device
*dev
);
133 static unsigned short eeprom_op(short ioaddr
, unsigned int cmd
);
134 static int net_open(struct net_device
*dev
);
135 static void hardware_init(struct net_device
*dev
);
136 static void write_packet(short ioaddr
, int length
, unsigned char *packet
, int mode
);
137 static void trigger_send(short ioaddr
, int length
);
138 static int net_send_packet(struct sk_buff
*skb
, struct net_device
*dev
);
139 static void net_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
140 static void net_rx(struct net_device
*dev
);
141 static void read_block(short ioaddr
, int length
, unsigned char *buffer
, int data_mode
);
142 static int net_close(struct net_device
*dev
);
143 static struct net_device_stats
*net_get_stats(struct net_device
*dev
);
144 static void set_multicast_list(struct net_device
*dev
);
147 /* Check for a network adapter of this type, and return '0' iff one exists.
148 If dev->base_addr == 0, probe all likely locations.
149 If dev->base_addr == 1, always return failure.
150 If dev->base_addr == 2, allocate space for the device and return success
151 (detachable devices only).
154 atp_init(struct net_device
*dev
)
156 int *port
, ports
[] = {0x378, 0x278, 0x3bc, 0};
157 int base_addr
= dev
->base_addr
;
159 if (base_addr
> 0x1ff) /* Check a single specified location. */
160 return atp_probe1(dev
, base_addr
);
161 else if (base_addr
== 1) /* Don't probe at all. */
164 for (port
= ports
; *port
; port
++) {
166 outb(0x57, ioaddr
+ PAR_DATA
);
167 if (inb(ioaddr
+ PAR_DATA
) != 0x57)
169 if (atp_probe1(dev
, ioaddr
) == 0)
176 static int __init
atp_probe1(struct net_device
*dev
, short ioaddr
)
178 int saved_ctrl_reg
, status
;
180 outb(0xff, ioaddr
+ PAR_DATA
);
181 /* Save the original value of the Control register, in case we guessed
183 saved_ctrl_reg
= inb(ioaddr
+ PAR_CONTROL
);
184 /* IRQEN=0, SLCTB=high INITB=high, AUTOFDB=high, STBB=high. */
185 outb(0x04, ioaddr
+ PAR_CONTROL
);
186 write_reg_high(ioaddr
, CMR1
, CMR1h_RESET
);
188 status
= read_nibble(ioaddr
, CMR1
);
190 if ((status
& 0x78) != 0x08) {
191 /* The pocket adapter probe failed, restore the control register. */
192 outb(saved_ctrl_reg
, ioaddr
+ PAR_CONTROL
);
195 status
= read_nibble(ioaddr
, CMR2_h
);
196 if ((status
& 0x78) != 0x10) {
197 outb(saved_ctrl_reg
, ioaddr
+ PAR_CONTROL
);
200 /* Find the IRQ used by triggering an interrupt. */
201 write_reg_byte(ioaddr
, CMR2
, 0x01); /* No accept mode, IRQ out. */
202 write_reg_high(ioaddr
, CMR1
, CMR1h_RxENABLE
| CMR1h_TxENABLE
); /* Enable Tx and Rx. */
204 /* Omit autoIRQ routine for now. Use "table lookup" instead. Uhgggh. */
209 write_reg_high(ioaddr
, CMR1
, CMR1h_TxRxOFF
); /* Disable Tx and Rx units. */
210 write_reg(ioaddr
, CMR2
, CMR2_NULL
);
212 dev
->base_addr
= ioaddr
;
214 /* Read the station address PROM. */
217 printk("%s: Pocket adapter found at %#3lx, IRQ %d, SAPROM "
218 "%02X:%02X:%02X:%02X:%02X:%02X.\n", dev
->name
, dev
->base_addr
,
219 dev
->irq
, dev
->dev_addr
[0], dev
->dev_addr
[1], dev
->dev_addr
[2],
220 dev
->dev_addr
[3], dev
->dev_addr
[4], dev
->dev_addr
[5]);
222 /* Leave the hardware in a reset state. */
223 write_reg_high(ioaddr
, CMR1
, CMR1h_RESET
);
228 /* Initialize the device structure. */
230 dev
->priv
= kmalloc(sizeof(struct net_local
), GFP_KERNEL
);
231 if (dev
->priv
== NULL
)
233 memset(dev
->priv
, 0, sizeof(struct net_local
));
237 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
238 lp
->addr_mode
= CMR2h_Normal
;
241 /* For the ATP adapter the "if_port" is really the data transfer mode. */
242 dev
->if_port
= (dev
->mem_start
& 0xf) ? dev
->mem_start
& 0x7 : 4;
243 if (dev
->mem_end
& 0xf)
244 net_debug
= dev
->mem_end
& 7;
246 dev
->open
= net_open
;
247 dev
->stop
= net_close
;
248 dev
->hard_start_xmit
= net_send_packet
;
249 dev
->get_stats
= net_get_stats
;
250 dev
->set_multicast_list
= &set_multicast_list
;
253 del_timer(&atp_timer
);
254 atp_timer
.expires
= jiffies
+ TIMED_CHECKER
;
256 add_timer(&atp_timer
);
261 /* Read the station address PROM, usually a word-wide EEPROM. */
262 static void __init
get_node_ID(struct net_device
*dev
)
264 short ioaddr
= dev
->base_addr
;
268 write_reg(ioaddr
, CMR2
, CMR2_EEPROM
); /* Point to the EEPROM control registers. */
270 /* Some adapters have the station address at offset 15 instead of offset
271 zero. Check for it, and fix it if needed. */
272 if (eeprom_op(ioaddr
, EE_READ(0)) == 0xffff)
275 for (i
= 0; i
< 3; i
++)
276 ((unsigned short *)dev
->dev_addr
)[i
] =
277 ntohs(eeprom_op(ioaddr
, EE_READ(sa_offset
+ i
)));
279 write_reg(ioaddr
, CMR2
, CMR2_NULL
);
283 An EEPROM read command starts by shifting out 0x60+address, and then
284 shifting in the serial data. See the NatSemi databook for details.
288 * CLK: ______| |___| |
290 * DI : __X_______X_______X
291 * DO : _________X_______X
294 static unsigned short __init
eeprom_op(short ioaddr
, unsigned int cmd
)
296 unsigned eedata_out
= 0;
297 int num_bits
= EE_CMD_SIZE
;
299 while (--num_bits
>= 0) {
300 char outval
= test_bit(num_bits
, &cmd
) ? EE_DATA_WRITE
: 0;
301 write_reg_high(ioaddr
, PROM_CMD
, outval
| EE_CLK_LOW
);
303 write_reg_high(ioaddr
, PROM_CMD
, outval
| EE_CLK_HIGH
);
305 if (read_nibble(ioaddr
, PROM_DATA
) & EE_DATA_READ
)
309 write_reg_high(ioaddr
, PROM_CMD
, EE_CLK_LOW
& ~EE_CS
);
314 /* Open/initialize the board. This is called (in the current kernel)
315 sometime after booting when the 'ifconfig' program is run.
317 This routine sets everything up anew at each open, even
318 registers that "should" only need to be set once at boot, so that
319 there is non-reboot way to recover if something goes wrong.
321 This is an attachable device: if there is no dev->priv entry then it wasn't
322 probed for at boot-time, and we need to probe for it again.
324 static int net_open(struct net_device
*dev
)
327 /* The interrupt line is turned off (tri-stated) when the device isn't in
328 use. That's especially important for "attached" interfaces where the
329 port or interrupt may be shared. */
330 if (request_irq(dev
->irq
, &net_interrupt
, 0, "ATP", dev
)) {
339 /* This routine resets the hardware. We initialize everything, assuming that
340 the hardware may have been temporarily detached. */
341 static void hardware_init(struct net_device
*dev
)
343 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
344 int ioaddr
= dev
->base_addr
;
347 write_reg_high(ioaddr
, CMR1
, CMR1h_RESET
);
349 for (i
= 0; i
< 6; i
++)
350 write_reg_byte(ioaddr
, PAR0
+ i
, dev
->dev_addr
[i
]);
352 write_reg_high(ioaddr
, CMR2
, lp
->addr_mode
);
355 printk("%s: Reset: current Rx mode %d.\n", dev
->name
,
356 (read_nibble(ioaddr
, CMR2_h
) >> 3) & 0x0f);
359 write_reg(ioaddr
, CMR2
, CMR2_IRQOUT
);
360 write_reg_high(ioaddr
, CMR1
, CMR1h_RxENABLE
| CMR1h_TxENABLE
);
362 /* Enable the interrupt line from the serial port. */
363 outb(Ctrl_SelData
+ Ctrl_IRQEN
, ioaddr
+ PAR_CONTROL
);
365 /* Unmask the interesting interrupts. */
366 write_reg(ioaddr
, IMR
, ISR_RxOK
| ISR_TxErr
| ISR_TxOK
);
367 write_reg_high(ioaddr
, IMR
, ISRh_RxErr
);
369 lp
->tx_unit_busy
= 0;
370 lp
->pac_cnt_in_tx_buf
= 0;
371 lp
->saved_tx_size
= 0;
377 static void trigger_send(short ioaddr
, int length
)
379 write_reg_byte(ioaddr
, TxCNT0
, length
& 0xff);
380 write_reg(ioaddr
, TxCNT1
, length
>> 8);
381 write_reg(ioaddr
, CMR1
, CMR1_Xmit
);
384 static void write_packet(short ioaddr
, int length
, unsigned char *packet
, int data_mode
)
386 length
= (length
+ 1) & ~1; /* Round up to word length. */
387 outb(EOC
+MAR
, ioaddr
+ PAR_DATA
);
388 if ((data_mode
& 1) == 0) {
389 /* Write the packet out, starting with the write addr. */
390 outb(WrAddr
+MAR
, ioaddr
+ PAR_DATA
);
392 write_byte_mode0(ioaddr
, *packet
++);
393 } while (--length
> 0) ;
395 /* Write the packet out in slow mode. */
396 unsigned char outbyte
= *packet
++;
398 outb(Ctrl_LNibWrite
+ Ctrl_IRQEN
, ioaddr
+ PAR_CONTROL
);
399 outb(WrAddr
+MAR
, ioaddr
+ PAR_DATA
);
401 outb((outbyte
& 0x0f)|0x40, ioaddr
+ PAR_DATA
);
402 outb(outbyte
& 0x0f, ioaddr
+ PAR_DATA
);
404 outb(outbyte
& 0x0f, ioaddr
+ PAR_DATA
);
405 outb(Ctrl_HNibWrite
+ Ctrl_IRQEN
, ioaddr
+ PAR_CONTROL
);
407 write_byte_mode1(ioaddr
, *packet
++);
409 /* Terminate the Tx frame. End of write: ECB. */
410 outb(0xff, ioaddr
+ PAR_DATA
);
411 outb(Ctrl_HNibWrite
| Ctrl_SelData
| Ctrl_IRQEN
, ioaddr
+ PAR_CONTROL
);
415 net_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
417 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
418 int ioaddr
= dev
->base_addr
;
421 /* If we get here, some higher level has decided we are broken.
422 There should really be a "kick me" function call instead. */
423 int tickssofar
= jiffies
- dev
->trans_start
;
426 printk("%s: transmit timed out, %s?\n", dev
->name
,
427 inb(ioaddr
+ PAR_CONTROL
) & 0x10 ? "network cable problem"
429 lp
->stats
.tx_errors
++;
430 /* Try to restart the adapter. */
433 dev
->trans_start
= jiffies
;
436 /* Block a timer-based transmit from overlapping. This could better be
437 done with atomic_swap(1, dev->tbusy), but set_bit() works as well. */
438 if (test_and_set_bit(0, (void*)&dev
->tbusy
) != 0)
439 printk("%s: Transmitter access conflict.\n", dev
->name
);
441 short length
= ETH_ZLEN
< skb
->len
? skb
->len
: ETH_ZLEN
;
442 unsigned char *buf
= skb
->data
;
445 /* Disable interrupts by writing 0x00 to the Interrupt Mask Register.
446 This sequence must not be interrupted by an incoming packet. */
449 write_reg(ioaddr
, IMR
, 0);
450 write_reg_high(ioaddr
, IMR
, 0);
451 restore_flags(flags
);
453 write_packet(ioaddr
, length
, buf
, dev
->if_port
);
455 lp
->pac_cnt_in_tx_buf
++;
456 if (lp
->tx_unit_busy
== 0) {
457 trigger_send(ioaddr
, length
);
458 lp
->saved_tx_size
= 0; /* Redundant */
460 lp
->tx_unit_busy
= 1;
462 lp
->saved_tx_size
= length
;
464 dev
->trans_start
= jiffies
;
465 /* Re-enable the LPT interrupts. */
466 write_reg(ioaddr
, IMR
, ISR_RxOK
| ISR_TxErr
| ISR_TxOK
);
467 write_reg_high(ioaddr
, IMR
, ISRh_RxErr
);
475 /* The typical workload of the driver:
476 Handle the network interface interrupts. */
478 net_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
480 struct net_device
*dev
= dev_id
;
481 struct net_local
*lp
;
482 int ioaddr
, status
, boguscount
= 20;
483 static int num_tx_since_rx
= 0;
486 printk ("ATP_interrupt(): irq %d for unknown device.\n", irq
);
491 ioaddr
= dev
->base_addr
;
492 lp
= (struct net_local
*)dev
->priv
;
494 /* Disable additional spurious interrupts. */
495 outb(Ctrl_SelData
, ioaddr
+ PAR_CONTROL
);
497 /* The adapter's output is currently the IRQ line, switch it to data. */
498 write_reg(ioaddr
, CMR2
, CMR2_NULL
);
499 write_reg(ioaddr
, IMR
, 0);
501 if (net_debug
> 5) printk("%s: In interrupt ", dev
->name
);
502 while (--boguscount
> 0) {
503 status
= read_nibble(ioaddr
, ISR
);
504 if (net_debug
> 5) printk("loop status %02x..", status
);
506 if (status
& (ISR_RxOK
<<3)) {
507 write_reg(ioaddr
, ISR
, ISR_RxOK
); /* Clear the Rx interrupt. */
509 int read_status
= read_nibble(ioaddr
, CMR1
);
511 printk("handling Rx packet %02x..", read_status
);
512 /* We acknowledged the normal Rx interrupt, so if the interrupt
513 is still outstanding we must have a Rx error. */
514 if (read_status
& (CMR1_IRQ
<< 3)) { /* Overrun. */
515 lp
->stats
.rx_over_errors
++;
516 /* Set to no-accept mode long enough to remove a packet. */
517 write_reg_high(ioaddr
, CMR2
, CMR2h_OFF
);
519 /* Clear the interrupt and return to normal Rx mode. */
520 write_reg_high(ioaddr
, ISR
, ISRh_RxErr
);
521 write_reg_high(ioaddr
, CMR2
, lp
->addr_mode
);
522 } else if ((read_status
& (CMR1_BufEnb
<< 3)) == 0) {
524 dev
->last_rx
= jiffies
;
528 } while (--boguscount
> 0);
529 } else if (status
& ((ISR_TxErr
+ ISR_TxOK
)<<3)) {
530 if (net_debug
> 6) printk("handling Tx done..");
531 /* Clear the Tx interrupt. We should check for too many failures
532 and reinitialize the adapter. */
533 write_reg(ioaddr
, ISR
, ISR_TxErr
+ ISR_TxOK
);
534 if (status
& (ISR_TxErr
<<3)) {
535 lp
->stats
.collisions
++;
536 if (++lp
->re_tx
> 15) {
537 lp
->stats
.tx_aborted_errors
++;
541 /* Attempt to retransmit. */
542 if (net_debug
> 6) printk("attempting to ReTx");
543 write_reg(ioaddr
, CMR1
, CMR1_ReXmit
+ CMR1_Xmit
);
545 /* Finish up the transmit. */
546 lp
->stats
.tx_packets
++;
547 lp
->pac_cnt_in_tx_buf
--;
548 if ( lp
->saved_tx_size
) {
549 trigger_send(ioaddr
, lp
->saved_tx_size
);
550 lp
->saved_tx_size
= 0;
553 lp
->tx_unit_busy
= 0;
555 mark_bh(NET_BH
); /* Inform upper layers. */
558 } else if (num_tx_since_rx
> 8
559 && jiffies
- dev
->last_rx
> 100) {
561 printk("%s: Missed packet? No Rx after %d Tx and %ld jiffies"
562 " status %02x CMR1 %02x.\n", dev
->name
,
563 num_tx_since_rx
, jiffies
- dev
->last_rx
, status
,
564 (read_nibble(ioaddr
, CMR1
) >> 3) & 15);
565 lp
->stats
.rx_missed_errors
++;
573 /* This following code fixes a rare (and very difficult to track down)
574 problem where the adapter forgets its ethernet address. */
577 for (i
= 0; i
< 6; i
++)
578 write_reg_byte(ioaddr
, PAR0
+ i
, dev
->dev_addr
[i
]);
580 del_timer(&atp_timer
);
581 atp_timer
.expires
= jiffies
+ TIMED_CHECKER
;
582 add_timer(&atp_timer
);
586 /* Tell the adapter that it can go back to using the output line as IRQ. */
587 write_reg(ioaddr
, CMR2
, CMR2_IRQOUT
);
588 /* Enable the physical interrupt line, which is sure to be low until.. */
589 outb(Ctrl_SelData
+ Ctrl_IRQEN
, ioaddr
+ PAR_CONTROL
);
590 /* .. we enable the interrupt sources. */
591 write_reg(ioaddr
, IMR
, ISR_RxOK
| ISR_TxErr
| ISR_TxOK
);
592 write_reg_high(ioaddr
, IMR
, ISRh_RxErr
); /* Hmmm, really needed? */
594 if (net_debug
> 5) printk("exiting interrupt.\n");
602 /* This following code fixes a rare (and very difficult to track down)
603 problem where the adapter forgets its ethernet address. */
604 static void atp_timed_checker(unsigned long ignored
)
607 int ioaddr
= atp_timed_dev
->base_addr
;
609 if (!atp_timed_dev
->interrupt
)
611 for (i
= 0; i
< 6; i
++)
613 if (read_cmd_byte(ioaddr
, PAR0
+ i
) != atp_timed_dev
->dev_addr
[i
])
615 struct net_local
*lp
= (struct net_local
*)atp_timed_dev
->priv
;
616 write_reg_byte(ioaddr
, PAR0
+ i
, atp_timed_dev
->dev_addr
[i
]);
618 lp
->stats
.tx_errors
++;
620 lp
->stats
.tx_dropped
++;
622 lp
->stats
.collisions
++;
624 lp
->stats
.rx_errors
++;
627 write_reg_byte(ioaddr
, PAR0
+ i
, atp_timed_dev
->dev_addr
[i
]);
630 del_timer(&atp_timer
);
631 atp_timer
.expires
= jiffies
+ TIMED_CHECKER
;
632 add_timer(&atp_timer
);
636 /* We have a good packet(s), get it/them out of the buffers. */
637 static void net_rx(struct net_device
*dev
)
639 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
640 int ioaddr
= dev
->base_addr
;
644 struct rx_header rx_head
;
647 /* Process the received packet. */
648 outb(EOC
+MAR
, ioaddr
+ PAR_DATA
);
649 read_block(ioaddr
, 8, (unsigned char*)&rx_head
, dev
->if_port
);
651 printk(" rx_count %04x %04x %04x %04x..", rx_head
.pad
,
652 rx_head
.rx_count
, rx_head
.rx_status
, rx_head
.cur_addr
);
653 if ((rx_head
.rx_status
& 0x77) != 0x01) {
654 lp
->stats
.rx_errors
++;
655 /* Ackkk! I don't have any documentation on what the error bits mean!
656 The best I can do is slap the device around a bit. */
657 if (net_debug
> 3) printk("%s: Unknown ATP Rx error %04x.\n",
658 dev
->name
, rx_head
.rx_status
);
662 /* Malloc up new buffer. */
663 int pkt_len
= (rx_head
.rx_count
& 0x7ff) - 4; /* The "-4" is omits the FCS (CRC). */
666 skb
= dev_alloc_skb(pkt_len
);
668 printk("%s: Memory squeeze, dropping packet.\n", dev
->name
);
669 lp
->stats
.rx_dropped
++;
674 read_block(ioaddr
, pkt_len
, skb_put(skb
,pkt_len
), dev
->if_port
);
677 unsigned char *data
= skb
->data
;
678 printk(" data %02x%02x%02x %02x%02x%02x %02x%02x%02x"
679 "%02x%02x%02x %02x%02x..",
680 data
[0], data
[1], data
[2], data
[3], data
[4], data
[5],
681 data
[6], data
[7], data
[8], data
[9], data
[10], data
[11],
685 skb
->protocol
=eth_type_trans(skb
,dev
);
687 lp
->stats
.rx_packets
++;
690 write_reg(ioaddr
, CMR1
, CMR1_NextPkt
);
694 static void read_block(short ioaddr
, int length
, unsigned char *p
, int data_mode
)
697 if (data_mode
<= 3) { /* Mode 0 or 1 */
698 outb(Ctrl_LNibRead
, ioaddr
+ PAR_CONTROL
);
699 outb(length
== 8 ? RdAddr
| HNib
| MAR
: RdAddr
| MAR
,
701 if (data_mode
<= 1) { /* Mode 0 or 1 */
702 do *p
++ = read_byte_mode0(ioaddr
); while (--length
> 0);
703 } else /* Mode 2 or 3 */
704 do *p
++ = read_byte_mode2(ioaddr
); while (--length
> 0);
705 } else if (data_mode
<= 5)
706 do *p
++ = read_byte_mode4(ioaddr
); while (--length
> 0);
708 do *p
++ = read_byte_mode6(ioaddr
); while (--length
> 0);
710 outb(EOC
+HNib
+MAR
, ioaddr
+ PAR_DATA
);
711 outb(Ctrl_SelData
, ioaddr
+ PAR_CONTROL
);
714 /* The inverse routine to net_open(). */
716 net_close(struct net_device
*dev
)
718 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
719 int ioaddr
= dev
->base_addr
;
724 /* Flush the Tx and disable Rx here. */
725 lp
->addr_mode
= CMR2h_OFF
;
726 write_reg_high(ioaddr
, CMR2
, CMR2h_OFF
);
728 /* Free the IRQ line. */
729 outb(0x00, ioaddr
+ PAR_CONTROL
);
730 free_irq(dev
->irq
, dev
);
732 /* Leave the hardware in a reset state. */
733 write_reg_high(ioaddr
, CMR1
, CMR1h_RESET
);
738 /* Get the current statistics. This may be called with the card open or
740 static struct net_device_stats
*net_get_stats(struct net_device
*dev
)
742 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
747 * Set or clear the multicast filter for this adapter.
750 static void set_multicast_list(struct net_device
*dev
)
752 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
753 short ioaddr
= dev
->base_addr
;
754 int num_addrs
=dev
->mc_count
;
756 if(dev
->flags
&(IFF_ALLMULTI
|IFF_PROMISC
))
759 * We must make the kernel realise we had to move
760 * into promisc mode or we start all out war on
764 dev
->flags
|=IFF_PROMISC
;
765 lp
->addr_mode
= num_addrs
? CMR2h_PROMISC
: CMR2h_Normal
;
766 write_reg_high(ioaddr
, CMR2
, lp
->addr_mode
);
771 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c atp.c"
773 * kept-new-versions: 5