1 |
1626 |
jcastillo |
/* atp.c: Attached (pocket) ethernet adapter driver for linux. */
|
2 |
|
|
/*
|
3 |
|
|
This is a driver for commonly OEMed pocket (parallel port)
|
4 |
|
|
ethernet adapters based on the Realtek RTL8002 and RTL8012 chips.
|
5 |
|
|
|
6 |
|
|
Written 1993-95,1997 by Donald Becker.
|
7 |
|
|
|
8 |
|
|
Copyright 1993 United States Government as represented by the
|
9 |
|
|
Director, National Security Agency.
|
10 |
|
|
|
11 |
|
|
This software may be used and distributed according to the terms
|
12 |
|
|
of the GNU Public License, incorporated herein by reference.
|
13 |
|
|
|
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
|
17 |
|
|
|
18 |
|
|
The timer-based reset code was written by Bill Carlson, wwc@super.org.
|
19 |
|
|
*/
|
20 |
|
|
|
21 |
|
|
static const char *version =
|
22 |
|
|
"atp.c:v1.08 4/1/97 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n";
|
23 |
|
|
|
24 |
|
|
/* Operational parameters that may be safely changed. */
|
25 |
|
|
/* Time in jiffies before concluding the transmitter is hung. */
|
26 |
|
|
#define TX_TIMEOUT ((400*HZ)/1000)
|
27 |
|
|
|
28 |
|
|
/*
|
29 |
|
|
This file is a device driver for the RealTek (aka AT-Lan-Tec) pocket
|
30 |
|
|
ethernet adapter. This is a common low-cost OEM pocket ethernet
|
31 |
|
|
adapter, sold under many names.
|
32 |
|
|
|
33 |
|
|
Sources:
|
34 |
|
|
This driver was written from the packet driver assembly code provided by
|
35 |
|
|
Vincent Bono of AT-Lan-Tec. Ever try to figure out how a complicated
|
36 |
|
|
device works just from the assembly code? It ain't pretty. The following
|
37 |
|
|
description is written based on guesses and writing lots of special-purpose
|
38 |
|
|
code to test my theorized operation.
|
39 |
|
|
|
40 |
|
|
In 1997 Realtek made available the documentation for the second generation
|
41 |
|
|
RTL8012 chip, which has lead to several driver improvements.
|
42 |
|
|
http://www.realtek.com.tw/cn/cn.html
|
43 |
|
|
|
44 |
|
|
Theory of Operation
|
45 |
|
|
|
46 |
|
|
The RTL8002 adapter seems to be built around a custom spin of the SEEQ
|
47 |
|
|
controller core. It probably has a 16K or 64K internal packet buffer, of
|
48 |
|
|
which the first 4K is devoted to transmit and the rest to receive.
|
49 |
|
|
The controller maintains the queue of received packet and the packet buffer
|
50 |
|
|
access pointer internally, with only 'reset to beginning' and 'skip to next
|
51 |
|
|
packet' commands visible. The transmit packet queue holds two (or more?)
|
52 |
|
|
packets: both 'retransmit this packet' (due to collision) and 'transmit next
|
53 |
|
|
packet' commands must be started by hand.
|
54 |
|
|
|
55 |
|
|
The station address is stored in a standard bit-serial EEPROM which must be
|
56 |
|
|
read (ughh) by the device driver. (Provisions have been made for
|
57 |
|
|
substituting a 74S288 PROM, but I haven't gotten reports of any models
|
58 |
|
|
using it.) Unlike built-in devices, a pocket adapter can temporarily lose
|
59 |
|
|
power without indication to the device driver. The major effect is that
|
60 |
|
|
the station address, receive filter (promiscuous, etc.) and transceiver
|
61 |
|
|
must be reset.
|
62 |
|
|
|
63 |
|
|
The controller itself has 16 registers, some of which use only the lower
|
64 |
|
|
bits. The registers are read and written 4 bits at a time. The four bit
|
65 |
|
|
register address is presented on the data lines along with a few additional
|
66 |
|
|
timing and control bits. The data is then read from status port or written
|
67 |
|
|
to the data port.
|
68 |
|
|
|
69 |
|
|
Correction: the controller has two banks of 16 registers. The second
|
70 |
|
|
bank contains only the multicast filter table (now used) and the EEPROM
|
71 |
|
|
access registers.
|
72 |
|
|
|
73 |
|
|
Since the bulk data transfer of the actual packets through the slow
|
74 |
|
|
parallel port dominates the driver's running time, four distinct data
|
75 |
|
|
(non-register) transfer modes are provided by the adapter, two in each
|
76 |
|
|
direction. In the first mode timing for the nibble transfers is
|
77 |
|
|
provided through the data port. In the second mode the same timing is
|
78 |
|
|
provided through the control port. In either case the data is read from
|
79 |
|
|
the status port and written to the data port, just as it is accessing
|
80 |
|
|
registers.
|
81 |
|
|
|
82 |
|
|
In addition to the basic data transfer methods, several more are modes are
|
83 |
|
|
created by adding some delay by doing multiple reads of the data to allow
|
84 |
|
|
it to stabilize. This delay seems to be needed on most machines.
|
85 |
|
|
|
86 |
|
|
The data transfer mode is stored in the 'dev->if_port' field. Its default
|
87 |
|
|
value is '4'. It may be overridden at boot-time using the third parameter
|
88 |
|
|
to the "ether=..." initialization.
|
89 |
|
|
|
90 |
|
|
The header file <atp.h> provides inline functions that encapsulate the
|
91 |
|
|
register and data access methods. These functions are hand-tuned to
|
92 |
|
|
generate reasonable object code. This header file also documents my
|
93 |
|
|
interpretations of the device registers.
|
94 |
|
|
*/
|
95 |
|
|
#include <linux/config.h>
|
96 |
|
|
#ifdef MODULE
|
97 |
|
|
#include <linux/module.h>
|
98 |
|
|
#include <linux/version.h>
|
99 |
|
|
#else
|
100 |
|
|
#define MOD_INC_USE_COUNT
|
101 |
|
|
#define MOD_DEC_USE_COUNT
|
102 |
|
|
#endif
|
103 |
|
|
|
104 |
|
|
#include <linux/kernel.h>
|
105 |
|
|
#include <linux/sched.h>
|
106 |
|
|
#include <linux/types.h>
|
107 |
|
|
#include <linux/fcntl.h>
|
108 |
|
|
#include <linux/interrupt.h>
|
109 |
|
|
#include <linux/ptrace.h>
|
110 |
|
|
#include <linux/ioport.h>
|
111 |
|
|
#include <linux/in.h>
|
112 |
|
|
#include <linux/malloc.h>
|
113 |
|
|
#include <linux/string.h>
|
114 |
|
|
#include <asm/system.h>
|
115 |
|
|
#include <asm/bitops.h>
|
116 |
|
|
#include <asm/io.h>
|
117 |
|
|
#include <asm/dma.h>
|
118 |
|
|
#include <linux/errno.h>
|
119 |
|
|
|
120 |
|
|
#include <linux/netdevice.h>
|
121 |
|
|
#include <linux/etherdevice.h>
|
122 |
|
|
#include <linux/skbuff.h>
|
123 |
|
|
|
124 |
|
|
#include "atp.h"
|
125 |
|
|
|
126 |
|
|
/* Kernel compatibility defines, common to David Hind's PCMCIA package.
|
127 |
|
|
This is only in the support-all-kernels source code. */
|
128 |
|
|
#include <linux/version.h> /* Evil, but neccessary */
|
129 |
|
|
|
130 |
|
|
#if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE < 0x10300
|
131 |
|
|
#define RUN_AT(x) (x) /* What to put in timer->expires. */
|
132 |
|
|
#define DEV_ALLOC_SKB(len) alloc_skb(len, GFP_ATOMIC)
|
133 |
|
|
#define virt_to_bus(addr) ((unsigned long)addr)
|
134 |
|
|
#define bus_to_virt(addr) ((void*)addr)
|
135 |
|
|
|
136 |
|
|
#else /* 1.3.0 and later */
|
137 |
|
|
#define RUN_AT(x) (jiffies + (x))
|
138 |
|
|
#define DEV_ALLOC_SKB(len) dev_alloc_skb(len + 2)
|
139 |
|
|
#endif
|
140 |
|
|
#if defined (LINUX_VERSION_CODE) && LINUX_VERSION_CODE < 0x10338
|
141 |
|
|
#ifdef MODULE
|
142 |
|
|
#if !defined(CONFIG_MODVERSIONS) && !defined(__NO_VERSION__)
|
143 |
|
|
char kernel_version[] = UTS_RELEASE;
|
144 |
|
|
#endif
|
145 |
|
|
#else
|
146 |
|
|
#undef MOD_INC_USE_COUNT
|
147 |
|
|
#define MOD_INC_USE_COUNT
|
148 |
|
|
#undef MOD_DEC_USE_COUNT
|
149 |
|
|
#define MOD_DEC_USE_COUNT
|
150 |
|
|
#endif
|
151 |
|
|
#endif /* 1.3.38 */
|
152 |
|
|
|
153 |
|
|
#if (LINUX_VERSION_CODE >= 0x10344)
|
154 |
|
|
#define NEW_MULTICAST
|
155 |
|
|
#include <linux/delay.h>
|
156 |
|
|
#endif
|
157 |
|
|
|
158 |
|
|
#ifdef SA_SHIRQ
|
159 |
|
|
#define FREE_IRQ(irqnum, dev) free_irq(irqnum, dev)
|
160 |
|
|
#define REQUEST_IRQ(i,h,f,n, instance) request_irq(i,h,f,n, instance)
|
161 |
|
|
#define IRQ(irq, dev_id, pt_regs) (irq, dev_id, pt_regs)
|
162 |
|
|
#else
|
163 |
|
|
#define FREE_IRQ(irqnum, dev) free_irq(irqnum)
|
164 |
|
|
#define REQUEST_IRQ(i,h,f,n, instance) request_irq(i,h,f,n)
|
165 |
|
|
#define IRQ(irq, dev_id, pt_regs) (irq, pt_regs)
|
166 |
|
|
#endif
|
167 |
|
|
/* End of kernel compatibility defines. */
|
168 |
|
|
|
169 |
|
|
/* use 0 for production, 1 for verification, >2 for debug */
|
170 |
|
|
#ifndef NET_DEBUG
|
171 |
|
|
#define NET_DEBUG 1
|
172 |
|
|
#endif
|
173 |
|
|
static unsigned int net_debug = NET_DEBUG;
|
174 |
|
|
|
175 |
|
|
/* The number of low I/O ports used by the ethercard. */
|
176 |
|
|
#define ETHERCARD_TOTAL_SIZE 3
|
177 |
|
|
|
178 |
|
|
/* Sequence to switch an 8012 from printer mux to ethernet mode. */
|
179 |
|
|
static char mux_8012[] = { 0xff, 0xf7, 0xff, 0xfb, 0xf3, 0xfb, 0xff, 0xf7,};
|
180 |
|
|
|
181 |
|
|
/* This code, written by wwc@super.org, resets the adapter every
|
182 |
|
|
TIMED_CHECKER ticks. This recovers from an unknown error which
|
183 |
|
|
hangs the device. */
|
184 |
|
|
#define TIMED_CHECKER (HZ/4)
|
185 |
|
|
#ifdef TIMED_CHECKER
|
186 |
|
|
#include <linux/timer.h>
|
187 |
|
|
static void atp_timed_checker(unsigned long ignored);
|
188 |
|
|
#endif
|
189 |
|
|
|
190 |
|
|
/* Index to functions, as function prototypes. */
|
191 |
|
|
|
192 |
|
|
extern int atp_init(struct device *dev);
|
193 |
|
|
|
194 |
|
|
static int atp_probe1(struct device *dev, short ioaddr);
|
195 |
|
|
static void get_node_ID(struct device *dev);
|
196 |
|
|
static unsigned short eeprom_op(short ioaddr, unsigned int cmd);
|
197 |
|
|
static int net_open(struct device *dev);
|
198 |
|
|
static void hardware_init(struct device *dev);
|
199 |
|
|
static void write_packet(short ioaddr, int length, unsigned char *packet, int mode);
|
200 |
|
|
static void trigger_send(short ioaddr, int length);
|
201 |
|
|
static int net_send_packet(struct sk_buff *skb, struct device *dev);
|
202 |
|
|
static void net_interrupt IRQ(int irq, void *dev_id, struct pt_regs *regs);
|
203 |
|
|
static void net_rx(struct device *dev);
|
204 |
|
|
static void read_block(short ioaddr, int length, unsigned char *buffer, int data_mode);
|
205 |
|
|
static int net_close(struct device *dev);
|
206 |
|
|
static struct enet_statistics *net_get_stats(struct device *dev);
|
207 |
|
|
#ifdef NEW_MULTICAST
|
208 |
|
|
static void set_rx_mode_8002(struct device *dev);
|
209 |
|
|
static void set_rx_mode_8012(struct device *dev);
|
210 |
|
|
#else
|
211 |
|
|
static void set_rx_mode_8002(struct device *dev, int num_addrs, void *addrs);
|
212 |
|
|
static void set_rx_mode_8012(struct device *dev, int num_addrs, void *addrs);
|
213 |
|
|
#endif
|
214 |
|
|
|
215 |
|
|
|
216 |
|
|
/* A list of all installed ATP devices, for removing the driver module. */
|
217 |
|
|
static struct device *root_atp_dev = NULL;
|
218 |
|
|
|
219 |
|
|
/* Check for a network adapter of this type, and return '0' iff one exists.
|
220 |
|
|
If dev->base_addr == 0, probe all likely locations.
|
221 |
|
|
If dev->base_addr == 1, always return failure.
|
222 |
|
|
If dev->base_addr == 2, allocate space for the device and return success
|
223 |
|
|
(detachable devices only).
|
224 |
|
|
*/
|
225 |
|
|
int
|
226 |
|
|
atp_init(struct device *dev)
|
227 |
|
|
{
|
228 |
|
|
int *port, ports[] = {0x378, 0x278, 0x3bc, 0};
|
229 |
|
|
int base_addr = dev ? dev->base_addr : 0;
|
230 |
|
|
|
231 |
|
|
if (base_addr > 0x1ff) /* Check a single specified location. */
|
232 |
|
|
return atp_probe1(dev, base_addr);
|
233 |
|
|
else if (base_addr == 1) /* Don't probe at all. */
|
234 |
|
|
return ENXIO;
|
235 |
|
|
|
236 |
|
|
for (port = ports; *port; port++) {
|
237 |
|
|
int ioaddr = *port;
|
238 |
|
|
outb(0x57, ioaddr + PAR_DATA);
|
239 |
|
|
if (inb(ioaddr + PAR_DATA) != 0x57)
|
240 |
|
|
continue;
|
241 |
|
|
if (atp_probe1(dev, ioaddr) == 0)
|
242 |
|
|
return 0;
|
243 |
|
|
}
|
244 |
|
|
|
245 |
|
|
return ENODEV;
|
246 |
|
|
}
|
247 |
|
|
|
248 |
|
|
static int atp_probe1(struct device *dev, short ioaddr)
|
249 |
|
|
{
|
250 |
|
|
struct net_local *lp;
|
251 |
|
|
int saved_ctrl_reg, status, i;
|
252 |
|
|
|
253 |
|
|
outb(0xff, ioaddr + PAR_DATA);
|
254 |
|
|
/* Save the original value of the Control register, in case we guessed
|
255 |
|
|
wrong. */
|
256 |
|
|
saved_ctrl_reg = inb(ioaddr + PAR_CONTROL);
|
257 |
|
|
/* IRQEN=0, SLCTB=high INITB=high, AUTOFDB=high, STBB=high. */
|
258 |
|
|
outb(0x04, ioaddr + PAR_CONTROL);
|
259 |
|
|
/* Turn off the printer multiplexer on the 8012. */
|
260 |
|
|
for (i = 0; i < 8; i++)
|
261 |
|
|
outb(mux_8012[i], ioaddr + PAR_DATA);
|
262 |
|
|
write_reg_high(ioaddr, CMR1, CMR1h_RESET);
|
263 |
|
|
eeprom_delay(2048);
|
264 |
|
|
status = read_nibble(ioaddr, CMR1);
|
265 |
|
|
|
266 |
|
|
if ((status & 0x78) != 0x08) {
|
267 |
|
|
/* The pocket adapter probe failed, restore the control register. */
|
268 |
|
|
outb(saved_ctrl_reg, ioaddr + PAR_CONTROL);
|
269 |
|
|
return 1;
|
270 |
|
|
}
|
271 |
|
|
status = read_nibble(ioaddr, CMR2_h);
|
272 |
|
|
if ((status & 0x78) != 0x10) {
|
273 |
|
|
outb(saved_ctrl_reg, ioaddr + PAR_CONTROL);
|
274 |
|
|
return 1;
|
275 |
|
|
}
|
276 |
|
|
|
277 |
|
|
dev = init_etherdev(dev, sizeof(struct net_local));
|
278 |
|
|
|
279 |
|
|
/* Find the IRQ used by triggering an interrupt. */
|
280 |
|
|
write_reg_byte(ioaddr, CMR2, 0x01); /* No accept mode, IRQ out. */
|
281 |
|
|
write_reg_high(ioaddr, CMR1, CMR1h_RxENABLE | CMR1h_TxENABLE); /* Enable Tx and Rx. */
|
282 |
|
|
|
283 |
|
|
/* Omit autoIRQ routine for now. Use "table lookup" instead. Uhgggh. */
|
284 |
|
|
if (ioaddr == 0x378)
|
285 |
|
|
dev->irq = 7;
|
286 |
|
|
else
|
287 |
|
|
dev->irq = 5;
|
288 |
|
|
write_reg_high(ioaddr, CMR1, CMR1h_TxRxOFF); /* Disable Tx and Rx units. */
|
289 |
|
|
write_reg(ioaddr, CMR2, CMR2_NULL);
|
290 |
|
|
|
291 |
|
|
dev->base_addr = ioaddr;
|
292 |
|
|
|
293 |
|
|
/* Read the station address PROM. */
|
294 |
|
|
get_node_ID(dev);
|
295 |
|
|
|
296 |
|
|
printk("%s: Pocket adapter found at %#3lx, IRQ %d, SAPROM "
|
297 |
|
|
"%02X:%02X:%02X:%02X:%02X:%02X.\n", dev->name, dev->base_addr,
|
298 |
|
|
dev->irq, dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
|
299 |
|
|
dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
|
300 |
|
|
|
301 |
|
|
/* Reset the ethernet hardware and activate the printer pass-through. */
|
302 |
|
|
write_reg_high(ioaddr, CMR1, CMR1h_RESET | CMR1h_MUX);
|
303 |
|
|
|
304 |
|
|
if (net_debug)
|
305 |
|
|
printk(version);
|
306 |
|
|
|
307 |
|
|
/* Initialize the device structure. */
|
308 |
|
|
ether_setup(dev);
|
309 |
|
|
if (dev->priv == NULL)
|
310 |
|
|
dev->priv = kmalloc(sizeof(struct net_local), GFP_KERNEL);
|
311 |
|
|
if (dev->priv == NULL)
|
312 |
|
|
return -ENOMEM;
|
313 |
|
|
memset(dev->priv, 0, sizeof(struct net_local));
|
314 |
|
|
|
315 |
|
|
lp = (struct net_local *)dev->priv;
|
316 |
|
|
lp->chip_type = RTL8002;
|
317 |
|
|
lp->addr_mode = CMR2h_Normal;
|
318 |
|
|
|
319 |
|
|
lp->next_module = root_atp_dev;
|
320 |
|
|
root_atp_dev = dev;
|
321 |
|
|
|
322 |
|
|
/* For the ATP adapter the "if_port" is really the data transfer mode. */
|
323 |
|
|
dev->if_port = (dev->mem_start & 0xf) ? (dev->mem_start & 0x7) : 4;
|
324 |
|
|
if (dev->mem_end & 0xf)
|
325 |
|
|
net_debug = dev->mem_end & 7;
|
326 |
|
|
|
327 |
|
|
dev->open = net_open;
|
328 |
|
|
dev->stop = net_close;
|
329 |
|
|
dev->hard_start_xmit = net_send_packet;
|
330 |
|
|
dev->get_stats = net_get_stats;
|
331 |
|
|
dev->set_multicast_list =
|
332 |
|
|
lp->chip_type == RTL8002 ? &set_rx_mode_8002 : &set_rx_mode_8012;
|
333 |
|
|
|
334 |
|
|
return 0;
|
335 |
|
|
}
|
336 |
|
|
|
337 |
|
|
/* Read the station address PROM, usually a word-wide EEPROM. */
|
338 |
|
|
static void get_node_ID(struct device *dev)
|
339 |
|
|
{
|
340 |
|
|
short ioaddr = dev->base_addr;
|
341 |
|
|
int sa_offset = 0;
|
342 |
|
|
int i;
|
343 |
|
|
|
344 |
|
|
write_reg(ioaddr, CMR2, CMR2_EEPROM); /* Point to the EEPROM control registers. */
|
345 |
|
|
|
346 |
|
|
/* Some adapters have the station address at offset 15 instead of offset
|
347 |
|
|
zero. Check for it, and fix it if needed. */
|
348 |
|
|
if (eeprom_op(ioaddr, EE_READ(0)) == 0xffff)
|
349 |
|
|
sa_offset = 15;
|
350 |
|
|
|
351 |
|
|
for (i = 0; i < 3; i++)
|
352 |
|
|
((unsigned short *)dev->dev_addr)[i] =
|
353 |
|
|
ntohs(eeprom_op(ioaddr, EE_READ(sa_offset + i)));
|
354 |
|
|
|
355 |
|
|
write_reg(ioaddr, CMR2, CMR2_NULL);
|
356 |
|
|
}
|
357 |
|
|
|
358 |
|
|
/*
|
359 |
|
|
An EEPROM read command starts by shifting out 0x60+address, and then
|
360 |
|
|
shifting in the serial data. See the NatSemi databook for details.
|
361 |
|
|
* ________________
|
362 |
|
|
* CS : __|
|
363 |
|
|
* ___ ___
|
364 |
|
|
* CLK: ______| |___| |
|
365 |
|
|
* __ _______ _______
|
366 |
|
|
* DI : __X_______X_______X
|
367 |
|
|
* DO : _________X_______X
|
368 |
|
|
*/
|
369 |
|
|
|
370 |
|
|
static unsigned short eeprom_op(short ioaddr, unsigned int cmd)
|
371 |
|
|
{
|
372 |
|
|
unsigned eedata_out = 0;
|
373 |
|
|
int num_bits = EE_CMD_SIZE;
|
374 |
|
|
|
375 |
|
|
while (--num_bits >= 0) {
|
376 |
|
|
char outval = test_bit(num_bits, &cmd) ? EE_DATA_WRITE : 0;
|
377 |
|
|
write_reg_high(ioaddr, PROM_CMD, outval | EE_CLK_LOW);
|
378 |
|
|
eeprom_delay(5);
|
379 |
|
|
write_reg_high(ioaddr, PROM_CMD, outval | EE_CLK_HIGH);
|
380 |
|
|
eedata_out <<= 1;
|
381 |
|
|
if (read_nibble(ioaddr, PROM_DATA) & EE_DATA_READ)
|
382 |
|
|
eedata_out++;
|
383 |
|
|
eeprom_delay(5);
|
384 |
|
|
}
|
385 |
|
|
write_reg_high(ioaddr, PROM_CMD, EE_CLK_LOW & ~EE_CS);
|
386 |
|
|
return eedata_out;
|
387 |
|
|
}
|
388 |
|
|
|
389 |
|
|
|
390 |
|
|
/* Open/initialize the board. This is called (in the current kernel)
|
391 |
|
|
sometime after booting when the 'ifconfig' program is run.
|
392 |
|
|
|
393 |
|
|
This routine sets everything up anew at each open, even
|
394 |
|
|
registers that "should" only need to be set once at boot, so that
|
395 |
|
|
there is non-reboot way to recover if something goes wrong.
|
396 |
|
|
|
397 |
|
|
This is an attachable device: if there is no dev->priv entry then it wasn't
|
398 |
|
|
probed for at boot-time, and we need to probe for it again.
|
399 |
|
|
*/
|
400 |
|
|
static int net_open(struct device *dev)
|
401 |
|
|
{
|
402 |
|
|
struct net_local *lp = (struct net_local *)dev->priv;
|
403 |
|
|
|
404 |
|
|
/* The interrupt line is turned off (tri-stated) when the device isn't in
|
405 |
|
|
use. That's especially important for "attached" interfaces where the
|
406 |
|
|
port or interrupt may be shared. */
|
407 |
|
|
#ifndef SA_SHIRQ
|
408 |
|
|
if (irq2dev_map[dev->irq] != 0
|
409 |
|
|
|| (irq2dev_map[dev->irq] = dev) == 0
|
410 |
|
|
|| REQUEST_IRQ(dev->irq, &net_interrupt, 0, "ATP", dev)) {
|
411 |
|
|
return -EAGAIN;
|
412 |
|
|
}
|
413 |
|
|
#else
|
414 |
|
|
if (request_irq(dev->irq, &net_interrupt, 0, "ATP Ethernet", dev))
|
415 |
|
|
return -EAGAIN;
|
416 |
|
|
#endif
|
417 |
|
|
|
418 |
|
|
MOD_INC_USE_COUNT;
|
419 |
|
|
hardware_init(dev);
|
420 |
|
|
dev->start = 1;
|
421 |
|
|
|
422 |
|
|
init_timer(&lp->timer);
|
423 |
|
|
lp->timer.expires = RUN_AT(TIMED_CHECKER);
|
424 |
|
|
lp->timer.data = (unsigned long)dev;
|
425 |
|
|
lp->timer.function = &atp_timed_checker; /* timer handler */
|
426 |
|
|
add_timer(&lp->timer);
|
427 |
|
|
|
428 |
|
|
return 0;
|
429 |
|
|
}
|
430 |
|
|
|
431 |
|
|
/* This routine resets the hardware. We initialize everything, assuming that
|
432 |
|
|
the hardware may have been temporarily detached. */
|
433 |
|
|
static void hardware_init(struct device *dev)
|
434 |
|
|
{
|
435 |
|
|
struct net_local *lp = (struct net_local *)dev->priv;
|
436 |
|
|
int ioaddr = dev->base_addr;
|
437 |
|
|
int i;
|
438 |
|
|
|
439 |
|
|
/* Turn off the printer multiplexer on the 8012. */
|
440 |
|
|
for (i = 0; i < 8; i++)
|
441 |
|
|
outb(mux_8012[i], ioaddr + PAR_DATA);
|
442 |
|
|
write_reg_high(ioaddr, CMR1, CMR1h_RESET);
|
443 |
|
|
|
444 |
|
|
for (i = 0; i < 6; i++)
|
445 |
|
|
write_reg_byte(ioaddr, PAR0 + i, dev->dev_addr[i]);
|
446 |
|
|
|
447 |
|
|
write_reg_high(ioaddr, CMR2, lp->addr_mode);
|
448 |
|
|
|
449 |
|
|
if (net_debug > 2) {
|
450 |
|
|
printk("%s: Reset: current Rx mode %d.\n", dev->name,
|
451 |
|
|
(read_nibble(ioaddr, CMR2_h) >> 3) & 0x0f);
|
452 |
|
|
}
|
453 |
|
|
|
454 |
|
|
write_reg(ioaddr, CMR2, CMR2_IRQOUT);
|
455 |
|
|
write_reg_high(ioaddr, CMR1, CMR1h_RxENABLE | CMR1h_TxENABLE);
|
456 |
|
|
|
457 |
|
|
/* Enable the interrupt line from the serial port. */
|
458 |
|
|
outb(Ctrl_SelData + Ctrl_IRQEN, ioaddr + PAR_CONTROL);
|
459 |
|
|
|
460 |
|
|
/* Unmask the interesting interrupts. */
|
461 |
|
|
write_reg(ioaddr, IMR, ISR_RxOK | ISR_TxErr | ISR_TxOK);
|
462 |
|
|
write_reg_high(ioaddr, IMR, ISRh_RxErr);
|
463 |
|
|
|
464 |
|
|
lp->tx_unit_busy = 0;
|
465 |
|
|
lp->pac_cnt_in_tx_buf = 0;
|
466 |
|
|
lp->saved_tx_size = 0;
|
467 |
|
|
|
468 |
|
|
dev->tbusy = 0;
|
469 |
|
|
dev->interrupt = 0;
|
470 |
|
|
}
|
471 |
|
|
|
472 |
|
|
static void trigger_send(short ioaddr, int length)
|
473 |
|
|
{
|
474 |
|
|
write_reg_byte(ioaddr, TxCNT0, length & 0xff);
|
475 |
|
|
write_reg(ioaddr, TxCNT1, length >> 8);
|
476 |
|
|
write_reg(ioaddr, CMR1, CMR1_Xmit);
|
477 |
|
|
}
|
478 |
|
|
|
479 |
|
|
static void write_packet(short ioaddr, int length, unsigned char *packet, int data_mode)
|
480 |
|
|
{
|
481 |
|
|
length = (length + 1) & ~1; /* Round up to word length. */
|
482 |
|
|
outb(EOC+MAR, ioaddr + PAR_DATA);
|
483 |
|
|
if ((data_mode & 1) == 0) {
|
484 |
|
|
/* Write the packet out, starting with the write addr. */
|
485 |
|
|
outb(WrAddr+MAR, ioaddr + PAR_DATA);
|
486 |
|
|
do {
|
487 |
|
|
write_byte_mode0(ioaddr, *packet++);
|
488 |
|
|
} while (--length > 0) ;
|
489 |
|
|
} else {
|
490 |
|
|
/* Write the packet out in slow mode. */
|
491 |
|
|
unsigned char outbyte = *packet++;
|
492 |
|
|
|
493 |
|
|
outb(Ctrl_LNibWrite + Ctrl_IRQEN, ioaddr + PAR_CONTROL);
|
494 |
|
|
outb(WrAddr+MAR, ioaddr + PAR_DATA);
|
495 |
|
|
|
496 |
|
|
outb((outbyte & 0x0f)|0x40, ioaddr + PAR_DATA);
|
497 |
|
|
outb(outbyte & 0x0f, ioaddr + PAR_DATA);
|
498 |
|
|
outbyte >>= 4;
|
499 |
|
|
outb(outbyte & 0x0f, ioaddr + PAR_DATA);
|
500 |
|
|
outb(Ctrl_HNibWrite + Ctrl_IRQEN, ioaddr + PAR_CONTROL);
|
501 |
|
|
while (--length > 0)
|
502 |
|
|
write_byte_mode1(ioaddr, *packet++);
|
503 |
|
|
}
|
504 |
|
|
/* Terminate the Tx frame. End of write: ECB. */
|
505 |
|
|
outb(0xff, ioaddr + PAR_DATA);
|
506 |
|
|
outb(Ctrl_HNibWrite | Ctrl_SelData | Ctrl_IRQEN, ioaddr + PAR_CONTROL);
|
507 |
|
|
}
|
508 |
|
|
|
509 |
|
|
static int
|
510 |
|
|
net_send_packet(struct sk_buff *skb, struct device *dev)
|
511 |
|
|
{
|
512 |
|
|
struct net_local *lp = (struct net_local *)dev->priv;
|
513 |
|
|
int ioaddr = dev->base_addr;
|
514 |
|
|
|
515 |
|
|
#ifndef final_version
|
516 |
|
|
if (skb == NULL || skb->len <= 0) {
|
517 |
|
|
printk("%s: Obsolete driver layer request made: skbuff==NULL.\n",
|
518 |
|
|
dev->name);
|
519 |
|
|
dev_tint(dev);
|
520 |
|
|
return 0;
|
521 |
|
|
}
|
522 |
|
|
#endif
|
523 |
|
|
|
524 |
|
|
/* Use transmit-while-tbusy as a crude error timer. */
|
525 |
|
|
if (set_bit(0, (void*)&dev->tbusy) != 0) {
|
526 |
|
|
if (jiffies - dev->trans_start < TX_TIMEOUT)
|
527 |
|
|
return 1;
|
528 |
|
|
printk("%s: transmit timed out, %s?\n", dev->name,
|
529 |
|
|
inb(ioaddr + PAR_CONTROL) & 0x10 ? "network cable problem"
|
530 |
|
|
: "IRQ conflict");
|
531 |
|
|
lp->stats.tx_errors++;
|
532 |
|
|
/* Try to restart the adapter. */
|
533 |
|
|
hardware_init(dev);
|
534 |
|
|
dev->tbusy=0;
|
535 |
|
|
dev->trans_start = jiffies;
|
536 |
|
|
return 1;
|
537 |
|
|
} else {
|
538 |
|
|
short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
|
539 |
|
|
unsigned char *buf = skb->data;
|
540 |
|
|
int flags;
|
541 |
|
|
|
542 |
|
|
/* Disable interrupts by writing 0x00 to the Interrupt Mask Register.
|
543 |
|
|
This sequence must not be interrupted by an incoming packet. */
|
544 |
|
|
save_flags(flags);
|
545 |
|
|
cli();
|
546 |
|
|
write_reg(ioaddr, IMR, 0);
|
547 |
|
|
write_reg_high(ioaddr, IMR, 0);
|
548 |
|
|
restore_flags(flags);
|
549 |
|
|
|
550 |
|
|
write_packet(ioaddr, length, buf, dev->if_port);
|
551 |
|
|
|
552 |
|
|
lp->pac_cnt_in_tx_buf++;
|
553 |
|
|
if (lp->tx_unit_busy == 0) {
|
554 |
|
|
trigger_send(ioaddr, length);
|
555 |
|
|
lp->saved_tx_size = 0; /* Redundant */
|
556 |
|
|
lp->re_tx = 0;
|
557 |
|
|
lp->tx_unit_busy = 1;
|
558 |
|
|
} else
|
559 |
|
|
lp->saved_tx_size = length;
|
560 |
|
|
|
561 |
|
|
dev->trans_start = jiffies;
|
562 |
|
|
/* Re-enable the LPT interrupts. */
|
563 |
|
|
write_reg(ioaddr, IMR, ISR_RxOK | ISR_TxErr | ISR_TxOK);
|
564 |
|
|
write_reg_high(ioaddr, IMR, ISRh_RxErr);
|
565 |
|
|
}
|
566 |
|
|
|
567 |
|
|
dev_kfree_skb (skb, FREE_WRITE);
|
568 |
|
|
|
569 |
|
|
return 0;
|
570 |
|
|
}
|
571 |
|
|
|
572 |
|
|
/* The typical workload of the driver:
|
573 |
|
|
Handle the network interface interrupts. */
|
574 |
|
|
static void
|
575 |
|
|
net_interrupt IRQ(int irq, void *dev_instance, struct pt_regs * regs)
|
576 |
|
|
{
|
577 |
|
|
#ifdef SA_SHIRQ
|
578 |
|
|
struct device *dev = (struct device *)dev_instance;
|
579 |
|
|
#else
|
580 |
|
|
struct device *dev = (struct device *)(irq2dev_map[irq]);
|
581 |
|
|
#endif
|
582 |
|
|
struct net_local *lp;
|
583 |
|
|
int ioaddr, status, boguscount = 20;
|
584 |
|
|
static int num_tx_since_rx = 0;
|
585 |
|
|
|
586 |
|
|
if (dev == NULL) {
|
587 |
|
|
printk ("ATP_interrupt(): irq %d for unknown device.\n", irq);
|
588 |
|
|
return;
|
589 |
|
|
}
|
590 |
|
|
dev->interrupt = 1;
|
591 |
|
|
|
592 |
|
|
ioaddr = dev->base_addr;
|
593 |
|
|
lp = (struct net_local *)dev->priv;
|
594 |
|
|
|
595 |
|
|
/* Disable additional spurious interrupts. */
|
596 |
|
|
outb(Ctrl_SelData, ioaddr + PAR_CONTROL);
|
597 |
|
|
|
598 |
|
|
/* The adapter's output is currently the IRQ line, switch it to data. */
|
599 |
|
|
write_reg(ioaddr, CMR2, CMR2_NULL);
|
600 |
|
|
write_reg(ioaddr, IMR, 0);
|
601 |
|
|
|
602 |
|
|
if (net_debug > 5) printk("%s: In interrupt ", dev->name);
|
603 |
|
|
while (--boguscount > 0) {
|
604 |
|
|
status = read_nibble(ioaddr, ISR);
|
605 |
|
|
if (net_debug > 5) printk("loop status %02x..", status);
|
606 |
|
|
|
607 |
|
|
if (status & (ISR_RxOK<<3)) {
|
608 |
|
|
write_reg(ioaddr, ISR, ISR_RxOK); /* Clear the Rx interrupt. */
|
609 |
|
|
do {
|
610 |
|
|
int read_status = read_nibble(ioaddr, CMR1);
|
611 |
|
|
if (net_debug > 6)
|
612 |
|
|
printk("handling Rx packet %02x..", read_status);
|
613 |
|
|
/* We acknowledged the normal Rx interrupt, so if the interrupt
|
614 |
|
|
is still outstanding we must have a Rx error. */
|
615 |
|
|
if (read_status & (CMR1_IRQ << 3)) { /* Overrun. */
|
616 |
|
|
lp->stats.rx_over_errors++;
|
617 |
|
|
/* Set to no-accept mode long enough to remove a packet. */
|
618 |
|
|
write_reg_high(ioaddr, CMR2, CMR2h_OFF);
|
619 |
|
|
net_rx(dev);
|
620 |
|
|
/* Clear the interrupt and return to normal Rx mode. */
|
621 |
|
|
write_reg_high(ioaddr, ISR, ISRh_RxErr);
|
622 |
|
|
write_reg_high(ioaddr, CMR2, lp->addr_mode);
|
623 |
|
|
} else if ((read_status & (CMR1_BufEnb << 3)) == 0) {
|
624 |
|
|
net_rx(dev);
|
625 |
|
|
dev->last_rx = jiffies;
|
626 |
|
|
num_tx_since_rx = 0;
|
627 |
|
|
} else
|
628 |
|
|
break;
|
629 |
|
|
} while (--boguscount > 0);
|
630 |
|
|
} else if (status & ((ISR_TxErr + ISR_TxOK)<<3)) {
|
631 |
|
|
if (net_debug > 6) printk("handling Tx done..");
|
632 |
|
|
/* Clear the Tx interrupt. We should check for too many failures
|
633 |
|
|
and reinitialize the adapter. */
|
634 |
|
|
write_reg(ioaddr, ISR, ISR_TxErr + ISR_TxOK);
|
635 |
|
|
if (status & (ISR_TxErr<<3)) {
|
636 |
|
|
lp->stats.collisions++;
|
637 |
|
|
if (++lp->re_tx > 15) {
|
638 |
|
|
lp->stats.tx_aborted_errors++;
|
639 |
|
|
hardware_init(dev);
|
640 |
|
|
break;
|
641 |
|
|
}
|
642 |
|
|
/* Attempt to retransmit. */
|
643 |
|
|
if (net_debug > 6) printk("attempting to ReTx");
|
644 |
|
|
write_reg(ioaddr, CMR1, CMR1_ReXmit + CMR1_Xmit);
|
645 |
|
|
} else {
|
646 |
|
|
/* Finish up the transmit. */
|
647 |
|
|
lp->stats.tx_packets++;
|
648 |
|
|
lp->pac_cnt_in_tx_buf--;
|
649 |
|
|
if ( lp->saved_tx_size) {
|
650 |
|
|
trigger_send(ioaddr, lp->saved_tx_size);
|
651 |
|
|
lp->saved_tx_size = 0;
|
652 |
|
|
lp->re_tx = 0;
|
653 |
|
|
} else
|
654 |
|
|
lp->tx_unit_busy = 0;
|
655 |
|
|
dev->tbusy = 0;
|
656 |
|
|
mark_bh(NET_BH); /* Inform upper layers. */
|
657 |
|
|
}
|
658 |
|
|
num_tx_since_rx++;
|
659 |
|
|
} else if (num_tx_since_rx > 8
|
660 |
|
|
&& jiffies > dev->last_rx + 100) {
|
661 |
|
|
if (net_debug > 2)
|
662 |
|
|
printk("%s: Missed packet? No Rx after %d Tx and %ld jiffies"
|
663 |
|
|
" status %02x CMR1 %02x.\n", dev->name,
|
664 |
|
|
num_tx_since_rx, jiffies - dev->last_rx, status,
|
665 |
|
|
(read_nibble(ioaddr, CMR1) >> 3) & 15);
|
666 |
|
|
lp->stats.rx_missed_errors++;
|
667 |
|
|
hardware_init(dev);
|
668 |
|
|
num_tx_since_rx = 0;
|
669 |
|
|
break;
|
670 |
|
|
} else
|
671 |
|
|
break;
|
672 |
|
|
}
|
673 |
|
|
|
674 |
|
|
/* This following code fixes a rare (and very difficult to track down)
|
675 |
|
|
problem where the adapter forgets its ethernet address. */
|
676 |
|
|
{
|
677 |
|
|
int i;
|
678 |
|
|
for (i = 0; i < 6; i++)
|
679 |
|
|
write_reg_byte(ioaddr, PAR0 + i, dev->dev_addr[i]);
|
680 |
|
|
}
|
681 |
|
|
|
682 |
|
|
/* Tell the adapter that it can go back to using the output line as IRQ. */
|
683 |
|
|
write_reg(ioaddr, CMR2, CMR2_IRQOUT);
|
684 |
|
|
/* Enable the physical interrupt line, which is sure to be low until.. */
|
685 |
|
|
outb(Ctrl_SelData + Ctrl_IRQEN, ioaddr + PAR_CONTROL);
|
686 |
|
|
/* .. we enable the interrupt sources. */
|
687 |
|
|
write_reg(ioaddr, IMR, ISR_RxOK | ISR_TxErr | ISR_TxOK);
|
688 |
|
|
write_reg_high(ioaddr, IMR, ISRh_RxErr); /* Hmmm, really needed? */
|
689 |
|
|
|
690 |
|
|
if (net_debug > 5) printk("exiting interrupt.\n");
|
691 |
|
|
|
692 |
|
|
dev->interrupt = 0;
|
693 |
|
|
|
694 |
|
|
return;
|
695 |
|
|
}
|
696 |
|
|
|
697 |
|
|
#ifdef TIMED_CHECKER
|
698 |
|
|
/* This following code fixes a rare (and very difficult to track down)
|
699 |
|
|
problem where the adapter forgets its ethernet address. */
|
700 |
|
|
static void atp_timed_checker(unsigned long data)
|
701 |
|
|
{
|
702 |
|
|
struct device *dev = (struct device *)data;
|
703 |
|
|
int ioaddr = dev->base_addr;
|
704 |
|
|
struct net_local *lp = (struct net_local *)dev->priv;
|
705 |
|
|
int tickssofar = jiffies - lp->last_rx_time;
|
706 |
|
|
int i;
|
707 |
|
|
|
708 |
|
|
if (tickssofar > 2*HZ && dev->interrupt == 0) {
|
709 |
|
|
#if 1
|
710 |
|
|
for (i = 0; i < 6; i++)
|
711 |
|
|
write_reg_byte(ioaddr, PAR0 + i, dev->dev_addr[i]);
|
712 |
|
|
lp->last_rx_time = jiffies;
|
713 |
|
|
#else
|
714 |
|
|
for (i = 0; i < 6; i++)
|
715 |
|
|
if (read_cmd_byte(ioaddr, PAR0 + i) != atp_timed_dev->dev_addr[i])
|
716 |
|
|
{
|
717 |
|
|
struct net_local *lp = (struct net_local *)atp_timed_dev->priv;
|
718 |
|
|
write_reg_byte(ioaddr, PAR0 + i, atp_timed_dev->dev_addr[i]);
|
719 |
|
|
if (i == 2)
|
720 |
|
|
lp->stats.tx_errors++;
|
721 |
|
|
else if (i == 3)
|
722 |
|
|
lp->stats.tx_dropped++;
|
723 |
|
|
else if (i == 4)
|
724 |
|
|
lp->stats.collisions++;
|
725 |
|
|
else
|
726 |
|
|
lp->stats.rx_errors++;
|
727 |
|
|
}
|
728 |
|
|
#endif
|
729 |
|
|
}
|
730 |
|
|
lp->timer.expires = RUN_AT(TIMED_CHECKER);
|
731 |
|
|
add_timer(&lp->timer);
|
732 |
|
|
}
|
733 |
|
|
#endif
|
734 |
|
|
|
735 |
|
|
/* We have a good packet(s), get it/them out of the buffers. */
|
736 |
|
|
static void net_rx(struct device *dev)
|
737 |
|
|
{
|
738 |
|
|
struct net_local *lp = (struct net_local *)dev->priv;
|
739 |
|
|
int ioaddr = dev->base_addr;
|
740 |
|
|
struct rx_header rx_head;
|
741 |
|
|
|
742 |
|
|
/* Process the received packet. */
|
743 |
|
|
outb(EOC+MAR, ioaddr + PAR_DATA);
|
744 |
|
|
read_block(ioaddr, 8, (unsigned char*)&rx_head, dev->if_port);
|
745 |
|
|
if (net_debug > 5)
|
746 |
|
|
printk(" rx_count %04x %04x %04x %04x..", rx_head.pad,
|
747 |
|
|
rx_head.rx_count, rx_head.rx_status, rx_head.cur_addr);
|
748 |
|
|
if ((rx_head.rx_status & 0x77) != 0x01) {
|
749 |
|
|
lp->stats.rx_errors++;
|
750 |
|
|
if (rx_head.rx_status & 0x0004) lp->stats.rx_frame_errors++;
|
751 |
|
|
else if (rx_head.rx_status & 0x0002) lp->stats.rx_crc_errors++;
|
752 |
|
|
if (net_debug > 3) printk("%s: Unknown ATP Rx error %04x.\n",
|
753 |
|
|
dev->name, rx_head.rx_status);
|
754 |
|
|
if (rx_head.rx_status & 0x0020) {
|
755 |
|
|
lp->stats.rx_fifo_errors++;
|
756 |
|
|
write_reg_high(ioaddr, CMR1, CMR1h_TxENABLE);
|
757 |
|
|
write_reg_high(ioaddr, CMR1, CMR1h_RxENABLE | CMR1h_TxENABLE);
|
758 |
|
|
} else if (rx_head.rx_status & 0x0050)
|
759 |
|
|
hardware_init(dev);
|
760 |
|
|
return;
|
761 |
|
|
} else {
|
762 |
|
|
/* Malloc up new buffer. The "-4" is omits the FCS (CRC). */
|
763 |
|
|
int pkt_len = (rx_head.rx_count & 0x7ff) - 4;
|
764 |
|
|
struct sk_buff *skb;
|
765 |
|
|
|
766 |
|
|
skb = DEV_ALLOC_SKB(pkt_len + 2);
|
767 |
|
|
if (skb == NULL) {
|
768 |
|
|
printk("%s: Memory squeeze, dropping packet.\n", dev->name);
|
769 |
|
|
lp->stats.rx_dropped++;
|
770 |
|
|
goto done;
|
771 |
|
|
}
|
772 |
|
|
skb->dev = dev;
|
773 |
|
|
|
774 |
|
|
#if LINUX_VERSION_CODE >= 0x10300
|
775 |
|
|
skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
|
776 |
|
|
read_block(ioaddr, pkt_len, skb_put(skb,pkt_len), dev->if_port);
|
777 |
|
|
skb->protocol = eth_type_trans(skb, dev);
|
778 |
|
|
#else
|
779 |
|
|
read_block(ioaddr, pkt_len, skb->data, dev->if_port);
|
780 |
|
|
skb->len = pkt_len;
|
781 |
|
|
#endif
|
782 |
|
|
netif_rx(skb);
|
783 |
|
|
lp->stats.rx_packets++;
|
784 |
|
|
}
|
785 |
|
|
done:
|
786 |
|
|
write_reg(ioaddr, CMR1, CMR1_NextPkt);
|
787 |
|
|
lp->last_rx_time = jiffies;
|
788 |
|
|
return;
|
789 |
|
|
}
|
790 |
|
|
|
791 |
|
|
static void read_block(short ioaddr, int length, unsigned char *p, int data_mode)
|
792 |
|
|
{
|
793 |
|
|
|
794 |
|
|
if (data_mode <= 3) { /* Mode 0 or 1 */
|
795 |
|
|
outb(Ctrl_LNibRead, ioaddr + PAR_CONTROL);
|
796 |
|
|
outb(length == 8 ? RdAddr | HNib | MAR : RdAddr | MAR,
|
797 |
|
|
ioaddr + PAR_DATA);
|
798 |
|
|
if (data_mode <= 1) { /* Mode 0 or 1 */
|
799 |
|
|
do *p++ = read_byte_mode0(ioaddr); while (--length > 0);
|
800 |
|
|
} else /* Mode 2 or 3 */
|
801 |
|
|
do *p++ = read_byte_mode2(ioaddr); while (--length > 0);
|
802 |
|
|
} else if (data_mode <= 5)
|
803 |
|
|
do *p++ = read_byte_mode4(ioaddr); while (--length > 0);
|
804 |
|
|
else
|
805 |
|
|
do *p++ = read_byte_mode6(ioaddr); while (--length > 0);
|
806 |
|
|
|
807 |
|
|
outb(EOC+HNib+MAR, ioaddr + PAR_DATA);
|
808 |
|
|
outb(Ctrl_SelData, ioaddr + PAR_CONTROL);
|
809 |
|
|
}
|
810 |
|
|
|
811 |
|
|
/* The inverse routine to net_open(). */
|
812 |
|
|
static int
|
813 |
|
|
net_close(struct device *dev)
|
814 |
|
|
{
|
815 |
|
|
struct net_local *lp = (struct net_local *)dev->priv;
|
816 |
|
|
int ioaddr = dev->base_addr;
|
817 |
|
|
|
818 |
|
|
dev->tbusy = 1;
|
819 |
|
|
dev->start = 0;
|
820 |
|
|
|
821 |
|
|
del_timer(&lp->timer);
|
822 |
|
|
|
823 |
|
|
/* Flush the Tx and disable Rx here. */
|
824 |
|
|
lp->addr_mode = CMR2h_OFF;
|
825 |
|
|
write_reg_high(ioaddr, CMR2, CMR2h_OFF);
|
826 |
|
|
|
827 |
|
|
/* Free the IRQ line. */
|
828 |
|
|
outb(0x00, ioaddr + PAR_CONTROL);
|
829 |
|
|
FREE_IRQ(dev->irq, dev);
|
830 |
|
|
#ifndef SA_SHIRQ
|
831 |
|
|
irq2dev_map[dev->irq] = 0;
|
832 |
|
|
#endif
|
833 |
|
|
|
834 |
|
|
/* Reset the ethernet hardware and activate the printer pass-through. */
|
835 |
|
|
write_reg_high(ioaddr, CMR1, CMR1h_RESET | CMR1h_MUX);
|
836 |
|
|
|
837 |
|
|
MOD_DEC_USE_COUNT;
|
838 |
|
|
|
839 |
|
|
return 0;
|
840 |
|
|
}
|
841 |
|
|
|
842 |
|
|
/* Get the current statistics. This may be called with the card open or
|
843 |
|
|
closed. */
|
844 |
|
|
static struct enet_statistics *
|
845 |
|
|
net_get_stats(struct device *dev)
|
846 |
|
|
{
|
847 |
|
|
struct net_local *lp = (struct net_local *)dev->priv;
|
848 |
|
|
return &lp->stats;
|
849 |
|
|
}
|
850 |
|
|
|
851 |
|
|
/*
|
852 |
|
|
* Set or clear the multicast filter for this adapter.
|
853 |
|
|
*/
|
854 |
|
|
|
855 |
|
|
/* The little-endian AUTODIN32 ethernet CRC calculation.
|
856 |
|
|
This is common code and should be moved to net/core/crc.c */
|
857 |
|
|
static unsigned const ethernet_polynomial_le = 0xedb88320U;
|
858 |
|
|
static inline unsigned ether_crc_le(int length, unsigned char *data)
|
859 |
|
|
{
|
860 |
|
|
unsigned int crc = 0xffffffff; /* Initial value. */
|
861 |
|
|
while(--length >= 0) {
|
862 |
|
|
unsigned char current_octet = *data++;
|
863 |
|
|
int bit;
|
864 |
|
|
for (bit = 8; --bit >= 0; current_octet >>= 1) {
|
865 |
|
|
if ((crc ^ current_octet) & 1) {
|
866 |
|
|
crc >>= 1;
|
867 |
|
|
crc ^= ethernet_polynomial_le;
|
868 |
|
|
} else
|
869 |
|
|
crc >>= 1;
|
870 |
|
|
}
|
871 |
|
|
}
|
872 |
|
|
return crc;
|
873 |
|
|
}
|
874 |
|
|
|
875 |
|
|
static void
|
876 |
|
|
#ifdef NEW_MULTICAST
|
877 |
|
|
set_rx_mode_8002(struct device *dev)
|
878 |
|
|
#else
|
879 |
|
|
static void set_rx_mode_8002(struct device *dev, int num_addrs, void *addrs);
|
880 |
|
|
#endif
|
881 |
|
|
{
|
882 |
|
|
struct net_local *lp = (struct net_local *)dev->priv;
|
883 |
|
|
short ioaddr = dev->base_addr;
|
884 |
|
|
|
885 |
|
|
if ( dev->mc_count > 0 || (dev->flags & (IFF_ALLMULTI|IFF_PROMISC))) {
|
886 |
|
|
/* We must make the kernel realise we had to move
|
887 |
|
|
* into promisc mode or we start all out war on
|
888 |
|
|
* the cable. - AC
|
889 |
|
|
*/
|
890 |
|
|
dev->flags|=IFF_PROMISC;
|
891 |
|
|
lp->addr_mode = CMR2h_PROMISC;
|
892 |
|
|
} else
|
893 |
|
|
lp->addr_mode = CMR2h_Normal;
|
894 |
|
|
write_reg_high(ioaddr, CMR2, lp->addr_mode);
|
895 |
|
|
}
|
896 |
|
|
|
897 |
|
|
static void
|
898 |
|
|
#ifdef NEW_MULTICAST
|
899 |
|
|
set_rx_mode_8012(struct device *dev)
|
900 |
|
|
#else
|
901 |
|
|
static void set_rx_mode_8012(struct device *dev, int num_addrs, void *addrs);
|
902 |
|
|
#endif
|
903 |
|
|
{
|
904 |
|
|
struct net_local *lp = (struct net_local *)dev->priv;
|
905 |
|
|
short ioaddr = dev->base_addr;
|
906 |
|
|
unsigned char new_mode, mc_filter[8]; /* Multicast hash filter */
|
907 |
|
|
int i;
|
908 |
|
|
|
909 |
|
|
if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */
|
910 |
|
|
new_mode = CMR2h_PROMISC;
|
911 |
|
|
} else if ((dev->mc_count > 1000) || (dev->flags & IFF_ALLMULTI)) {
|
912 |
|
|
/* Too many to filter perfectly -- accept all multicasts. */
|
913 |
|
|
memset(mc_filter, 0xff, sizeof(mc_filter));
|
914 |
|
|
new_mode = CMR2h_Normal;
|
915 |
|
|
} else {
|
916 |
|
|
struct dev_mc_list *mclist;
|
917 |
|
|
|
918 |
|
|
memset(mc_filter, 0, sizeof(mc_filter));
|
919 |
|
|
for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count;
|
920 |
|
|
i++, mclist = mclist->next)
|
921 |
|
|
set_bit(ether_crc_le(ETH_ALEN, mclist->dmi_addr) & 0x3f,
|
922 |
|
|
mc_filter);
|
923 |
|
|
new_mode = CMR2h_Normal;
|
924 |
|
|
}
|
925 |
|
|
lp->addr_mode = new_mode;
|
926 |
|
|
write_reg(ioaddr, CMR2, CMR2_IRQOUT | 0x04); /* Switch to page 1. */
|
927 |
|
|
for (i = 0; i < 8; i++)
|
928 |
|
|
write_reg_byte(ioaddr, i, mc_filter[i]);
|
929 |
|
|
if (net_debug > 2 || 1) {
|
930 |
|
|
lp->addr_mode = 1;
|
931 |
|
|
printk("%s: Mode %d, setting multicast filter to",
|
932 |
|
|
dev->name, lp->addr_mode);
|
933 |
|
|
for (i = 0; i < 8; i++)
|
934 |
|
|
printk(" %2.2x", mc_filter[i]);
|
935 |
|
|
printk(".\n");
|
936 |
|
|
}
|
937 |
|
|
|
938 |
|
|
write_reg_high(ioaddr, CMR2, lp->addr_mode);
|
939 |
|
|
write_reg(ioaddr, CMR2, CMR2_IRQOUT); /* Switch back to page 0 */
|
940 |
|
|
}
|
941 |
|
|
|
942 |
|
|
#ifdef MODULE
|
943 |
|
|
static int debug = 1;
|
944 |
|
|
int
|
945 |
|
|
init_module(void)
|
946 |
|
|
{
|
947 |
|
|
net_debug = debug;
|
948 |
|
|
root_atp_dev = NULL;
|
949 |
|
|
atp_init(0);
|
950 |
|
|
return 0;
|
951 |
|
|
}
|
952 |
|
|
|
953 |
|
|
void
|
954 |
|
|
cleanup_module(void)
|
955 |
|
|
{
|
956 |
|
|
struct device *next_dev;
|
957 |
|
|
|
958 |
|
|
/* No need to check MOD_IN_USE, as sys_delete_module() checks. */
|
959 |
|
|
/* No need to release_region(), since we never snarf it. */
|
960 |
|
|
while (root_atp_dev) {
|
961 |
|
|
next_dev = ((struct net_local *)root_atp_dev->priv)->next_module;
|
962 |
|
|
unregister_netdev(root_atp_dev);
|
963 |
|
|
kfree(root_atp_dev);
|
964 |
|
|
root_atp_dev = next_dev;
|
965 |
|
|
}
|
966 |
|
|
}
|
967 |
|
|
#endif /* MODULE */
|
968 |
|
|
|
969 |
|
|
|
970 |
|
|
/*
|
971 |
|
|
* Local variables:
|
972 |
|
|
* compile-command: "gcc -DMODULE -D__KERNEL__ -I/usr/src/linux/net/inet -Wall -Wstrict-prototypes -O6 -c atp.c"
|
973 |
|
|
* version-control: t
|
974 |
|
|
* kept-new-versions: 5
|
975 |
|
|
* tab-width: 4
|
976 |
|
|
* End:
|
977 |
|
|
*/
|