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.
20 Modular support/softnet added by Alan Cox.
23 static const char *version
=
24 "atp.c:v1.01 1/18/95 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
27 This file is a device driver for the RealTek (aka AT-Lan-Tec) pocket
28 ethernet adapter. This is a common low-cost OEM pocket ethernet
29 adapter, sold under many names.
32 This driver was written from the packet driver assembly code provided by
33 Vincent Bono of AT-Lan-Tec. Ever try to figure out how a complicated
34 device works just from the assembly code? It ain't pretty. The following
35 description is written based on guesses and writing lots of special-purpose
36 code to test my theorized operation.
40 The RTL8002 adapter seems to be built around a custom spin of the SEEQ
41 controller core. It probably has a 16K or 64K internal packet buffer, of
42 which the first 4K is devoted to transmit and the rest to receive.
43 The controller maintains the queue of received packet and the packet buffer
44 access pointer internally, with only 'reset to beginning' and 'skip to next
45 packet' commands visible. The transmit packet queue holds two (or more?)
46 packets: both 'retransmit this packet' (due to collision) and 'transmit next
47 packet' commands must be started by hand.
49 The station address is stored in a standard bit-serial EEPROM which must be
50 read (ughh) by the device driver. (Provisions have been made for
51 substituting a 74S288 PROM, but I haven't gotten reports of any models
52 using it.) Unlike built-in devices, a pocket adapter can temporarily lose
53 power without indication to the device driver. The major effect is that
54 the station address, receive filter (promiscuous, etc.) and transceiver
57 The controller itself has 16 registers, some of which use only the lower
58 bits. The registers are read and written 4 bits at a time. The four bit
59 register address is presented on the data lines along with a few additional
60 timing and control bits. The data is then read from status port or written
63 Since the bulk data transfer of the actual packets through the slow
64 parallel port dominates the driver's running time, four distinct data
65 (non-register) transfer modes are provided by the adapter, two in each
66 direction. In the first mode timing for the nibble transfers is
67 provided through the data port. In the second mode the same timing is
68 provided through the control port. In either case the data is read from
69 the status port and written to the data port, just as it is accessing
72 In addition to the basic data transfer methods, several more are modes are
73 created by adding some delay by doing multiple reads of the data to allow
74 it to stabilize. This delay seems to be needed on most machines.
76 The data transfer mode is stored in the 'dev->if_port' field. Its default
77 value is '4'. It may be overridden at boot-time using the third parameter
78 to the "ether=..." initialization.
80 The header file <atp.h> provides inline functions that encapsulate the
81 register and data access methods. These functions are hand-tuned to
82 generate reasonable object code. This header file also documents my
83 interpretations of the device registers.
86 #include <linux/kernel.h>
87 #include <linux/module.h>
88 #include <linux/sched.h>
89 #include <linux/types.h>
90 #include <linux/fcntl.h>
91 #include <linux/interrupt.h>
92 #include <linux/ptrace.h>
93 #include <linux/ioport.h>
95 #include <linux/malloc.h>
96 #include <linux/string.h>
97 #include <asm/system.h>
98 #include <asm/bitops.h>
101 #include <linux/errno.h>
102 #include <linux/init.h>
104 #include <linux/netdevice.h>
105 #include <linux/etherdevice.h>
106 #include <linux/skbuff.h>
107 #include <linux/spinlock.h>
111 /* use 0 for production, 1 for verification, >2 for debug */
115 static unsigned int net_debug
= NET_DEBUG
;
117 /* The number of low I/O ports used by the ethercard. */
118 #define ETHERCARD_TOTAL_SIZE 3
120 /* This code, written by wwc@super.org, resets the adapter every
121 TIMED_CHECKER ticks. This recovers from an unknown error which
123 #define TIMED_CHECKER (HZ/4)
125 #include <linux/timer.h>
126 static void atp_timed_checker(unsigned long ignored
);
127 static struct net_device
*atp_timed_dev
;
128 static struct timer_list atp_timer
= { function
: atp_timed_checker
};
131 /* Index to functions, as function prototypes. */
133 static int atp_probe1(struct net_device
*dev
, short ioaddr
);
134 static void get_node_ID(struct net_device
*dev
);
135 static unsigned short eeprom_op(short ioaddr
, unsigned int cmd
);
136 static int net_open(struct net_device
*dev
);
137 static void hardware_init(struct net_device
*dev
);
138 static void tx_timeout(struct net_device
*dev
);
139 static void write_packet(short ioaddr
, int length
, unsigned char *packet
, int mode
);
140 static void trigger_send(short ioaddr
, int length
);
141 static int net_send_packet(struct sk_buff
*skb
, struct net_device
*dev
);
142 static void net_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
143 static void net_rx(struct net_device
*dev
);
144 static void read_block(short ioaddr
, int length
, unsigned char *buffer
, int data_mode
);
145 static int net_close(struct net_device
*dev
);
146 static struct net_device_stats
*net_get_stats(struct net_device
*dev
);
147 static void set_multicast_list(struct net_device
*dev
);
150 /* Check for a network adapter of this type, and return '0' iff one exists.
151 If dev->base_addr == 0, probe all likely locations.
152 If dev->base_addr == 1, always return failure.
153 If dev->base_addr == 2, allocate space for the device and return success
154 (detachable devices only).
157 int __init
atp_init(struct net_device
*dev
)
159 int *port
, ports
[] = {0x378, 0x278, 0x3bc, 0};
160 int base_addr
= dev
->base_addr
;
162 if (base_addr
> 0x1ff) /* Check a single specified location. */
163 return atp_probe1(dev
, base_addr
);
164 else if (base_addr
== 1) /* Don't probe at all. */
167 for (port
= ports
; *port
; port
++) {
169 outb(0x57, ioaddr
+ PAR_DATA
);
170 if (inb(ioaddr
+ PAR_DATA
) != 0x57)
172 if (atp_probe1(dev
, ioaddr
) == 0)
179 static int __init
atp_probe1(struct net_device
*dev
, short ioaddr
)
181 int saved_ctrl_reg
, status
;
183 outb(0xff, ioaddr
+ PAR_DATA
);
184 /* Save the original value of the Control register, in case we guessed
186 saved_ctrl_reg
= inb(ioaddr
+ PAR_CONTROL
);
187 /* IRQEN=0, SLCTB=high INITB=high, AUTOFDB=high, STBB=high. */
188 outb(0x04, ioaddr
+ PAR_CONTROL
);
189 write_reg_high(ioaddr
, CMR1
, CMR1h_RESET
);
191 status
= read_nibble(ioaddr
, CMR1
);
193 if ((status
& 0x78) != 0x08) {
194 /* The pocket adapter probe failed, restore the control register. */
195 outb(saved_ctrl_reg
, ioaddr
+ PAR_CONTROL
);
198 status
= read_nibble(ioaddr
, CMR2_h
);
199 if ((status
& 0x78) != 0x10) {
200 outb(saved_ctrl_reg
, ioaddr
+ PAR_CONTROL
);
203 /* Find the IRQ used by triggering an interrupt. */
204 write_reg_byte(ioaddr
, CMR2
, 0x01); /* No accept mode, IRQ out. */
205 write_reg_high(ioaddr
, CMR1
, CMR1h_RxENABLE
| CMR1h_TxENABLE
); /* Enable Tx and Rx. */
207 /* Omit autoIRQ routine for now. Use "table lookup" instead. Uhgggh. */
212 write_reg_high(ioaddr
, CMR1
, CMR1h_TxRxOFF
); /* Disable Tx and Rx units. */
213 write_reg(ioaddr
, CMR2
, CMR2_NULL
);
215 dev
->base_addr
= ioaddr
;
217 /* Read the station address PROM. */
220 printk("%s: Pocket adapter found at %#3lx, IRQ %d, SAPROM "
221 "%02X:%02X:%02X:%02X:%02X:%02X.\n", dev
->name
, dev
->base_addr
,
222 dev
->irq
, dev
->dev_addr
[0], dev
->dev_addr
[1], dev
->dev_addr
[2],
223 dev
->dev_addr
[3], dev
->dev_addr
[4], dev
->dev_addr
[5]);
225 /* Leave the hardware in a reset state. */
226 write_reg_high(ioaddr
, CMR1
, CMR1h_RESET
);
231 /* Initialize the device structure. */
233 dev
->priv
= kmalloc(sizeof(struct net_local
), GFP_KERNEL
);
234 if (dev
->priv
== NULL
)
236 memset(dev
->priv
, 0, sizeof(struct net_local
));
238 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
239 lp
->addr_mode
= CMR2h_Normal
;
240 spin_lock_init(&lp
->lock
);
243 /* For the ATP adapter the "if_port" is really the data transfer mode. */
244 dev
->if_port
= (dev
->mem_start
& 0xf) ? dev
->mem_start
& 0x7 : 4;
245 if (dev
->mem_end
& 0xf)
246 net_debug
= dev
->mem_end
& 7;
248 dev
->open
= net_open
;
249 dev
->stop
= net_close
;
250 dev
->hard_start_xmit
= net_send_packet
;
251 dev
->get_stats
= net_get_stats
;
252 dev
->set_multicast_list
= set_multicast_list
;
253 dev
->tx_timeout
= tx_timeout
;
254 dev
->watchdog_timeo
= HZ
/20;
257 del_timer(&atp_timer
);
258 atp_timer
.expires
= jiffies
+ TIMED_CHECKER
;
260 add_timer(&atp_timer
);
265 /* Read the station address PROM, usually a word-wide EEPROM. */
266 static void __init
get_node_ID(struct net_device
*dev
)
268 short ioaddr
= dev
->base_addr
;
272 write_reg(ioaddr
, CMR2
, CMR2_EEPROM
); /* Point to the EEPROM control registers. */
274 /* Some adapters have the station address at offset 15 instead of offset
275 zero. Check for it, and fix it if needed. */
276 if (eeprom_op(ioaddr
, EE_READ(0)) == 0xffff)
279 for (i
= 0; i
< 3; i
++)
280 ((unsigned short *)dev
->dev_addr
)[i
] =
281 ntohs(eeprom_op(ioaddr
, EE_READ(sa_offset
+ i
)));
283 write_reg(ioaddr
, CMR2
, CMR2_NULL
);
287 An EEPROM read command starts by shifting out 0x60+address, and then
288 shifting in the serial data. See the NatSemi databook for details.
292 * CLK: ______| |___| |
294 * DI : __X_______X_______X
295 * DO : _________X_______X
298 static unsigned short __init
eeprom_op(short ioaddr
, unsigned int cmd
)
300 unsigned eedata_out
= 0;
301 int num_bits
= EE_CMD_SIZE
;
303 while (--num_bits
>= 0) {
304 char outval
= test_bit(num_bits
, &cmd
) ? EE_DATA_WRITE
: 0;
305 write_reg_high(ioaddr
, PROM_CMD
, outval
| EE_CLK_LOW
);
307 write_reg_high(ioaddr
, PROM_CMD
, outval
| EE_CLK_HIGH
);
309 if (read_nibble(ioaddr
, PROM_DATA
) & EE_DATA_READ
)
313 write_reg_high(ioaddr
, PROM_CMD
, EE_CLK_LOW
& ~EE_CS
);
318 /* Open/initialize the board. This is called (in the current kernel)
319 sometime after booting when the 'ifconfig' program is run.
321 This routine sets everything up anew at each open, even
322 registers that "should" only need to be set once at boot, so that
323 there is non-reboot way to recover if something goes wrong.
325 This is an attachable device: if there is no dev->priv entry then it wasn't
326 probed for at boot-time, and we need to probe for it again.
328 static int net_open(struct net_device
*dev
)
331 /* The interrupt line is turned off (tri-stated) when the device isn't in
332 use. That's especially important for "attached" interfaces where the
333 port or interrupt may be shared. */
335 if (request_irq(dev
->irq
, &net_interrupt
, 0, "ATP", dev
)) {
339 netif_start_queue(dev
);
343 /* This routine resets the hardware. We initialize everything, assuming that
344 the hardware may have been temporarily detached. */
345 static void hardware_init(struct net_device
*dev
)
347 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
348 int ioaddr
= dev
->base_addr
;
351 write_reg_high(ioaddr
, CMR1
, CMR1h_RESET
);
353 for (i
= 0; i
< 6; i
++)
354 write_reg_byte(ioaddr
, PAR0
+ i
, dev
->dev_addr
[i
]);
356 write_reg_high(ioaddr
, CMR2
, lp
->addr_mode
);
359 printk("%s: Reset: current Rx mode %d.\n", dev
->name
,
360 (read_nibble(ioaddr
, CMR2_h
) >> 3) & 0x0f);
363 write_reg(ioaddr
, CMR2
, CMR2_IRQOUT
);
364 write_reg_high(ioaddr
, CMR1
, CMR1h_RxENABLE
| CMR1h_TxENABLE
);
366 /* Enable the interrupt line from the serial port. */
367 outb(Ctrl_SelData
+ Ctrl_IRQEN
, ioaddr
+ PAR_CONTROL
);
369 /* Unmask the interesting interrupts. */
370 write_reg(ioaddr
, IMR
, ISR_RxOK
| ISR_TxErr
| ISR_TxOK
);
371 write_reg_high(ioaddr
, IMR
, ISRh_RxErr
);
373 lp
->tx_unit_busy
= 0;
374 lp
->pac_cnt_in_tx_buf
= 0;
375 lp
->saved_tx_size
= 0;
378 static void trigger_send(short ioaddr
, int length
)
380 write_reg_byte(ioaddr
, TxCNT0
, length
& 0xff);
381 write_reg(ioaddr
, TxCNT1
, length
>> 8);
382 write_reg(ioaddr
, CMR1
, CMR1_Xmit
);
385 static void write_packet(short ioaddr
, int length
, unsigned char *packet
, int data_mode
)
387 length
= (length
+ 1) & ~1; /* Round up to word length. */
388 outb(EOC
+MAR
, ioaddr
+ PAR_DATA
);
389 if ((data_mode
& 1) == 0) {
390 /* Write the packet out, starting with the write addr. */
391 outb(WrAddr
+MAR
, ioaddr
+ PAR_DATA
);
393 write_byte_mode0(ioaddr
, *packet
++);
394 } while (--length
> 0) ;
396 /* Write the packet out in slow mode. */
397 unsigned char outbyte
= *packet
++;
399 outb(Ctrl_LNibWrite
+ Ctrl_IRQEN
, ioaddr
+ PAR_CONTROL
);
400 outb(WrAddr
+MAR
, ioaddr
+ PAR_DATA
);
402 outb((outbyte
& 0x0f)|0x40, ioaddr
+ PAR_DATA
);
403 outb(outbyte
& 0x0f, ioaddr
+ PAR_DATA
);
405 outb(outbyte
& 0x0f, ioaddr
+ PAR_DATA
);
406 outb(Ctrl_HNibWrite
+ Ctrl_IRQEN
, ioaddr
+ PAR_CONTROL
);
408 write_byte_mode1(ioaddr
, *packet
++);
410 /* Terminate the Tx frame. End of write: ECB. */
411 outb(0xff, ioaddr
+ PAR_DATA
);
412 outb(Ctrl_HNibWrite
| Ctrl_SelData
| Ctrl_IRQEN
, ioaddr
+ PAR_CONTROL
);
415 static void tx_timeout(struct net_device
*dev
)
417 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
418 int ioaddr
= dev
->base_addr
;
419 /* If we get here, some higher level has decided we are broken. */
420 printk(KERN_WARNING
"%s: transmit timed out, %s?\n", dev
->name
,
421 inb(ioaddr
+ PAR_CONTROL
) & 0x10 ? "network cable problem"
423 lp
->stats
.tx_errors
++;
424 /* Try to restart the adapter. */
426 dev
->trans_start
= jiffies
;
427 netif_wake_queue(dev
);
430 static int net_send_packet(struct sk_buff
*skb
, struct net_device
*dev
)
432 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
433 int ioaddr
= dev
->base_addr
;
434 short length
= ETH_ZLEN
< skb
->len
? skb
->len
: ETH_ZLEN
;
435 unsigned char *buf
= skb
->data
;
438 netif_stop_queue(dev
);
440 /* Disable interrupts by writing 0x00 to the Interrupt Mask Register.
441 This sequence must not be interrupted by an incoming packet. */
443 spin_lock_irqsave(&lp
->lock
, flags
);
444 write_reg(ioaddr
, IMR
, 0);
445 write_reg_high(ioaddr
, IMR
, 0);
446 spin_unlock_irqrestore(&lp
->lock
, flags
);
448 write_packet(ioaddr
, length
, buf
, dev
->if_port
);
450 lp
->pac_cnt_in_tx_buf
++;
451 if (lp
->tx_unit_busy
== 0) {
452 trigger_send(ioaddr
, length
);
453 lp
->saved_tx_size
= 0; /* Redundant */
455 lp
->tx_unit_busy
= 1;
457 lp
->saved_tx_size
= length
;
459 dev
->trans_start
= jiffies
;
460 /* Re-enable the LPT interrupts. */
461 write_reg(ioaddr
, IMR
, ISR_RxOK
| ISR_TxErr
| ISR_TxOK
);
462 write_reg_high(ioaddr
, IMR
, ISRh_RxErr
);
467 /* The typical workload of the driver:
468 Handle the network interface interrupts. */
470 net_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
472 struct net_device
*dev
= dev_id
;
473 struct net_local
*lp
;
474 int ioaddr
, status
, boguscount
= 20;
475 static int num_tx_since_rx
= 0;
477 ioaddr
= dev
->base_addr
;
478 lp
= (struct net_local
*)dev
->priv
;
480 spin_lock(&lp
->lock
);
482 /* Disable additional spurious interrupts. */
483 outb(Ctrl_SelData
, ioaddr
+ PAR_CONTROL
);
485 /* The adapter's output is currently the IRQ line, switch it to data. */
486 write_reg(ioaddr
, CMR2
, CMR2_NULL
);
487 write_reg(ioaddr
, IMR
, 0);
490 printk("%s: In interrupt ", dev
->name
);
492 while (--boguscount
> 0)
494 status
= read_nibble(ioaddr
, ISR
);
496 printk("loop status %02x..", status
);
498 if (status
& (ISR_RxOK
<<3)) {
499 write_reg(ioaddr
, ISR
, ISR_RxOK
); /* Clear the Rx interrupt. */
501 int read_status
= read_nibble(ioaddr
, CMR1
);
503 printk("handling Rx packet %02x..", read_status
);
504 /* We acknowledged the normal Rx interrupt, so if the interrupt
505 is still outstanding we must have a Rx error. */
506 if (read_status
& (CMR1_IRQ
<< 3)) { /* Overrun. */
507 lp
->stats
.rx_over_errors
++;
508 /* Set to no-accept mode long enough to remove a packet. */
509 write_reg_high(ioaddr
, CMR2
, CMR2h_OFF
);
511 /* Clear the interrupt and return to normal Rx mode. */
512 write_reg_high(ioaddr
, ISR
, ISRh_RxErr
);
513 write_reg_high(ioaddr
, CMR2
, lp
->addr_mode
);
514 } else if ((read_status
& (CMR1_BufEnb
<< 3)) == 0) {
516 dev
->last_rx
= jiffies
;
520 } while (--boguscount
> 0);
521 } else if (status
& ((ISR_TxErr
+ ISR_TxOK
)<<3)) {
522 if (net_debug
> 6) printk("handling Tx done..");
523 /* Clear the Tx interrupt. We should check for too many failures
524 and reinitialize the adapter. */
525 write_reg(ioaddr
, ISR
, ISR_TxErr
+ ISR_TxOK
);
526 if (status
& (ISR_TxErr
<<3)) {
527 lp
->stats
.collisions
++;
528 if (++lp
->re_tx
> 15) {
529 lp
->stats
.tx_aborted_errors
++;
533 /* Attempt to retransmit. */
535 printk("attempting to ReTx");
536 write_reg(ioaddr
, CMR1
, CMR1_ReXmit
+ CMR1_Xmit
);
538 /* Finish up the transmit. */
539 lp
->stats
.tx_packets
++;
540 lp
->pac_cnt_in_tx_buf
--;
541 if ( lp
->saved_tx_size
) {
542 trigger_send(ioaddr
, lp
->saved_tx_size
);
543 lp
->saved_tx_size
= 0;
546 lp
->tx_unit_busy
= 0;
547 netif_wake_queue(dev
); /* Inform upper layers. */
550 } else if (num_tx_since_rx
> 8
551 && jiffies
- dev
->last_rx
> 100) {
553 printk("%s: Missed packet? No Rx after %d Tx and %ld jiffies"
554 " status %02x CMR1 %02x.\n", dev
->name
,
555 num_tx_since_rx
, jiffies
- dev
->last_rx
, status
,
556 (read_nibble(ioaddr
, CMR1
) >> 3) & 15);
557 lp
->stats
.rx_missed_errors
++;
565 /* This following code fixes a rare (and very difficult to track down)
566 problem where the adapter forgets its ethernet address. */
569 for (i
= 0; i
< 6; i
++)
570 write_reg_byte(ioaddr
, PAR0
+ i
, dev
->dev_addr
[i
]);
572 mod_timer(&atp_timer
, jiffies
+TIMED_CHECKER
);
576 /* Tell the adapter that it can go back to using the output line as IRQ. */
577 write_reg(ioaddr
, CMR2
, CMR2_IRQOUT
);
578 /* Enable the physical interrupt line, which is sure to be low until.. */
579 outb(Ctrl_SelData
+ Ctrl_IRQEN
, ioaddr
+ PAR_CONTROL
);
580 /* .. we enable the interrupt sources. */
581 write_reg(ioaddr
, IMR
, ISR_RxOK
| ISR_TxErr
| ISR_TxOK
);
582 write_reg_high(ioaddr
, IMR
, ISRh_RxErr
); /* Hmmm, really needed? */
585 printk("exiting interrupt.\n");
587 spin_unlock(&lp
->lock
);
592 /* This following code fixes a rare (and very difficult to track down)
593 problem where the adapter forgets its ethernet address. */
594 static void atp_timed_checker(unsigned long ignored
)
597 struct net_local
*lp
= (struct net_local
*)atp_timed_dev
->priv
;
598 int ioaddr
= atp_timed_dev
->base_addr
;
600 spin_lock(&lp
->lock
);
601 for (i
= 0; i
< 6; i
++)
602 write_reg_byte(ioaddr
, PAR0
+ i
, atp_timed_dev
->dev_addr
[i
]);
603 spin_unlock(&lp
->lock
);
604 mod_timer(&atp_timer
, jiffies
+TIMED_CHECKER
);
608 /* We have a good packet(s), get it/them out of the buffers. */
609 static void net_rx(struct net_device
*dev
)
611 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
612 int ioaddr
= dev
->base_addr
;
616 struct rx_header rx_head
;
619 /* Process the received packet. */
620 outb(EOC
+MAR
, ioaddr
+ PAR_DATA
);
621 read_block(ioaddr
, 8, (unsigned char*)&rx_head
, dev
->if_port
);
623 printk(" rx_count %04x %04x %04x %04x..", rx_head
.pad
,
624 rx_head
.rx_count
, rx_head
.rx_status
, rx_head
.cur_addr
);
625 if ((rx_head
.rx_status
& 0x77) != 0x01) {
626 lp
->stats
.rx_errors
++;
627 /* Ackkk! I don't have any documentation on what the error bits mean!
628 The best I can do is slap the device around a bit. */
629 if (net_debug
> 3) printk("%s: Unknown ATP Rx error %04x.\n",
630 dev
->name
, rx_head
.rx_status
);
634 /* Malloc up new buffer. */
635 int pkt_len
= (rx_head
.rx_count
& 0x7ff) - 4; /* The "-4" is omits the FCS (CRC). */
638 skb
= dev_alloc_skb(pkt_len
);
640 printk("%s: Memory squeeze, dropping packet.\n", dev
->name
);
641 lp
->stats
.rx_dropped
++;
646 read_block(ioaddr
, pkt_len
, skb_put(skb
,pkt_len
), dev
->if_port
);
649 unsigned char *data
= skb
->data
;
650 printk(" data %02x%02x%02x %02x%02x%02x %02x%02x%02x"
651 "%02x%02x%02x %02x%02x..",
652 data
[0], data
[1], data
[2], data
[3], data
[4], data
[5],
653 data
[6], data
[7], data
[8], data
[9], data
[10], data
[11],
657 skb
->protocol
=eth_type_trans(skb
,dev
);
659 lp
->stats
.rx_packets
++;
662 write_reg(ioaddr
, CMR1
, CMR1_NextPkt
);
666 static void read_block(short ioaddr
, int length
, unsigned char *p
, int data_mode
)
669 if (data_mode
<= 3) { /* Mode 0 or 1 */
670 outb(Ctrl_LNibRead
, ioaddr
+ PAR_CONTROL
);
671 outb(length
== 8 ? RdAddr
| HNib
| MAR
: RdAddr
| MAR
,
673 if (data_mode
<= 1) { /* Mode 0 or 1 */
674 do *p
++ = read_byte_mode0(ioaddr
); while (--length
> 0);
675 } else /* Mode 2 or 3 */
676 do *p
++ = read_byte_mode2(ioaddr
); while (--length
> 0);
677 } else if (data_mode
<= 5)
678 do *p
++ = read_byte_mode4(ioaddr
); while (--length
> 0);
680 do *p
++ = read_byte_mode6(ioaddr
); while (--length
> 0);
682 outb(EOC
+HNib
+MAR
, ioaddr
+ PAR_DATA
);
683 outb(Ctrl_SelData
, ioaddr
+ PAR_CONTROL
);
686 /* The inverse routine to net_open(). */
687 static int net_close(struct net_device
*dev
)
689 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
690 int ioaddr
= dev
->base_addr
;
692 netif_stop_queue(dev
);
694 /* Flush the Tx and disable Rx here. */
695 lp
->addr_mode
= CMR2h_OFF
;
696 write_reg_high(ioaddr
, CMR2
, CMR2h_OFF
);
698 /* Free the IRQ line. */
699 outb(0x00, ioaddr
+ PAR_CONTROL
);
700 free_irq(dev
->irq
, dev
);
702 /* Leave the hardware in a reset state. */
703 write_reg_high(ioaddr
, CMR1
, CMR1h_RESET
);
708 /* Get the current statistics. This may be called with the card open or
710 static struct net_device_stats
*net_get_stats(struct net_device
*dev
)
712 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
717 * Set or clear the multicast filter for this adapter.
720 static void set_multicast_list(struct net_device
*dev
)
722 struct net_local
*lp
= (struct net_local
*)dev
->priv
;
723 short ioaddr
= dev
->base_addr
;
724 int num_addrs
=dev
->mc_count
;
726 if(dev
->flags
&(IFF_ALLMULTI
|IFF_PROMISC
))
729 * We must make the kernel realise we had to move
730 * into promisc mode or we start all out war on
734 dev
->flags
|=IFF_PROMISC
;
735 lp
->addr_mode
= num_addrs
? CMR2h_PROMISC
: CMR2h_Normal
;
736 write_reg_high(ioaddr
, CMR2
, lp
->addr_mode
);
741 * compile-command: "gcc -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -m486 -c atp.c"
743 * kept-new-versions: 5
751 static struct net_device atp_dev
= {
752 "", 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL
, atp_init
};
754 MODULE_PARM(io
, "I/O port of the pocket adapter");
756 int init_module(void)
758 atp_dev
.base_addr
= io
;
759 if (register_netdev(&atp_dev
) != 0)
764 void cleanup_module(void)
766 unregister_netdev(&atp_dev
);