diff options
author | Jeff Kirsher <jeffrey.t.kirsher@intel.com> | 2011-06-11 04:13:22 -0400 |
---|---|---|
committer | Jeff Kirsher <jeffrey.t.kirsher@intel.com> | 2011-08-12 03:22:08 -0400 |
commit | 5346ebf6db077d963e9d81af9df290d7f5532492 (patch) | |
tree | 599c964dc98a13be7af437172b1002b5bf2cbf71 /drivers/net/ethernet | |
parent | f2148a472883ddf77626fff52b070655a8a0a788 (diff) |
eth16i: Move the Allied Telesis/Fujitsu drivers
Move the Allied Telesis/Fujitsu drivers into drivers/net/ethernet/fujitsu/
and make the necessary Kconfig and Makefile changes.
CC: Shingo Fujimoto <shingo@flab.fujitsu.co.jp>
CC: Yutaka Tamiya <tamy@flab.fujitsu.co.jp>
CC: Rene Schmit <rene@bss.lu>
CC: Mika Kuoppala <miku@iki.fi>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
Diffstat (limited to 'drivers/net/ethernet')
-rw-r--r-- | drivers/net/ethernet/Kconfig | 1 | ||||
-rw-r--r-- | drivers/net/ethernet/Makefile | 1 | ||||
-rw-r--r-- | drivers/net/ethernet/fujitsu/Kconfig | 53 | ||||
-rw-r--r-- | drivers/net/ethernet/fujitsu/Makefile | 7 | ||||
-rw-r--r-- | drivers/net/ethernet/fujitsu/at1700.c | 900 | ||||
-rw-r--r-- | drivers/net/ethernet/fujitsu/eth16i.c | 1484 | ||||
-rw-r--r-- | drivers/net/ethernet/fujitsu/fmvj18x_cs.c | 1187 |
7 files changed, 3633 insertions, 0 deletions
diff --git a/drivers/net/ethernet/Kconfig b/drivers/net/ethernet/Kconfig index bdc0df873daf..d3aff7456bae 100644 --- a/drivers/net/ethernet/Kconfig +++ b/drivers/net/ethernet/Kconfig | |||
@@ -24,6 +24,7 @@ source "drivers/net/ethernet/dlink/Kconfig" | |||
24 | source "drivers/net/ethernet/emulex/Kconfig" | 24 | source "drivers/net/ethernet/emulex/Kconfig" |
25 | source "drivers/net/ethernet/neterion/Kconfig" | 25 | source "drivers/net/ethernet/neterion/Kconfig" |
26 | source "drivers/net/ethernet/faraday/Kconfig" | 26 | source "drivers/net/ethernet/faraday/Kconfig" |
27 | source "drivers/net/ethernet/fujitsu/Kconfig" | ||
27 | source "drivers/net/ethernet/ibm/Kconfig" | 28 | source "drivers/net/ethernet/ibm/Kconfig" |
28 | source "drivers/net/ethernet/intel/Kconfig" | 29 | source "drivers/net/ethernet/intel/Kconfig" |
29 | source "drivers/net/ethernet/i825xx/Kconfig" | 30 | source "drivers/net/ethernet/i825xx/Kconfig" |
diff --git a/drivers/net/ethernet/Makefile b/drivers/net/ethernet/Makefile index ac60ac9026bb..b098c5e1fa2c 100644 --- a/drivers/net/ethernet/Makefile +++ b/drivers/net/ethernet/Makefile | |||
@@ -16,6 +16,7 @@ obj-$(CONFIG_NET_VENDOR_DLINK) += dlink/ | |||
16 | obj-$(CONFIG_NET_VENDOR_EMULEX) += emulex/ | 16 | obj-$(CONFIG_NET_VENDOR_EMULEX) += emulex/ |
17 | obj-$(CONFIG_NET_VENDOR_EXAR) += neterion/ | 17 | obj-$(CONFIG_NET_VENDOR_EXAR) += neterion/ |
18 | obj-$(CONFIG_NET_VENDOR_FARADAY) += faraday/ | 18 | obj-$(CONFIG_NET_VENDOR_FARADAY) += faraday/ |
19 | obj-$(CONFIG_NET_VENDOR_FUJITSU) += fujitsu/ | ||
19 | obj-$(CONFIG_NET_VENDOR_IBM) += ibm/ | 20 | obj-$(CONFIG_NET_VENDOR_IBM) += ibm/ |
20 | obj-$(CONFIG_NET_VENDOR_INTEL) += intel/ | 21 | obj-$(CONFIG_NET_VENDOR_INTEL) += intel/ |
21 | obj-$(CONFIG_NET_VENDOR_I825XX) += i825xx/ | 22 | obj-$(CONFIG_NET_VENDOR_I825XX) += i825xx/ |
diff --git a/drivers/net/ethernet/fujitsu/Kconfig b/drivers/net/ethernet/fujitsu/Kconfig new file mode 100644 index 000000000000..2cd968edb733 --- /dev/null +++ b/drivers/net/ethernet/fujitsu/Kconfig | |||
@@ -0,0 +1,53 @@ | |||
1 | # | ||
2 | # Fujitsu Network device configuration | ||
3 | # | ||
4 | |||
5 | config NET_VENDOR_FUJITSU | ||
6 | bool "Fujitsu devices" | ||
7 | depends on ISA || PCMCIA || ((ISA || MCA_LEGACY) && EXPERIMENTAL) | ||
8 | ---help--- | ||
9 | If you have a network (Ethernet) card belonging to this class, say Y | ||
10 | and read the Ethernet-HOWTO, available from | ||
11 | <http://www.tldp.org/docs.html#howto>. | ||
12 | |||
13 | Note that the answer to this question doesn't directly affect the | ||
14 | the questions about Fujitsu cards. If you say Y, you will be asked for | ||
15 | your specific card in the following questions. | ||
16 | |||
17 | if NET_VENDOR_FUJITSU | ||
18 | |||
19 | config AT1700 | ||
20 | tristate "AT1700/1720 support (EXPERIMENTAL)" | ||
21 | depends on (ISA || MCA_LEGACY) && EXPERIMENTAL | ||
22 | select CRC32 | ||
23 | ---help--- | ||
24 | If you have a network (Ethernet) card of this type, say Y and read | ||
25 | the Ethernet-HOWTO, available from | ||
26 | <http://www.tldp.org/docs.html#howto>. | ||
27 | |||
28 | To compile this driver as a module, choose M here. The module | ||
29 | will be called at1700. | ||
30 | |||
31 | config PCMCIA_FMVJ18X | ||
32 | tristate "Fujitsu FMV-J18x PCMCIA support" | ||
33 | depends on PCMCIA | ||
34 | select CRC32 | ||
35 | ---help--- | ||
36 | Say Y here if you intend to attach a Fujitsu FMV-J18x or compatible | ||
37 | PCMCIA (PC-card) Ethernet card to your computer. | ||
38 | |||
39 | To compile this driver as a module, choose M here: the module will be | ||
40 | called fmvj18x_cs. If unsure, say N. | ||
41 | |||
42 | config ETH16I | ||
43 | tristate "ICL EtherTeam 16i/32 support" | ||
44 | depends on ISA | ||
45 | ---help--- | ||
46 | If you have a network (Ethernet) card of this type, say Y and read | ||
47 | the Ethernet-HOWTO, available from | ||
48 | <http://www.tldp.org/docs.html#howto>. | ||
49 | |||
50 | To compile this driver as a module, choose M here. The module | ||
51 | will be called eth16i. | ||
52 | |||
53 | endif # NET_VENDOR_FUJITSU | ||
diff --git a/drivers/net/ethernet/fujitsu/Makefile b/drivers/net/ethernet/fujitsu/Makefile new file mode 100644 index 000000000000..2730ae67d3aa --- /dev/null +++ b/drivers/net/ethernet/fujitsu/Makefile | |||
@@ -0,0 +1,7 @@ | |||
1 | # | ||
2 | # Makefile for the Fujitsu network device drivers. | ||
3 | # | ||
4 | |||
5 | obj-$(CONFIG_AT1700) += at1700.o | ||
6 | obj-$(CONFIG_ETH16I) += eth16i.o | ||
7 | obj-$(CONFIG_PCMCIA_FMVJ18X) += fmvj18x_cs.o | ||
diff --git a/drivers/net/ethernet/fujitsu/at1700.c b/drivers/net/ethernet/fujitsu/at1700.c new file mode 100644 index 000000000000..65a78f965dd2 --- /dev/null +++ b/drivers/net/ethernet/fujitsu/at1700.c | |||
@@ -0,0 +1,900 @@ | |||
1 | /* at1700.c: A network device driver for the Allied Telesis AT1700. | ||
2 | |||
3 | Written 1993-98 by Donald Becker. | ||
4 | |||
5 | Copyright 1993 United States Government as represented by the | ||
6 | Director, National Security Agency. | ||
7 | |||
8 | This software may be used and distributed according to the terms | ||
9 | of the GNU General Public License, incorporated herein by reference. | ||
10 | |||
11 | The author may be reached as becker@scyld.com, or C/O | ||
12 | Scyld Computing Corporation | ||
13 | 410 Severn Ave., Suite 210 | ||
14 | Annapolis MD 21403 | ||
15 | |||
16 | This is a device driver for the Allied Telesis AT1700, and | ||
17 | Fujitsu FMV-181/182/181A/182A/183/184/183A/184A, which are | ||
18 | straight-forward Fujitsu MB86965 implementations. | ||
19 | |||
20 | Modification for Fujitsu FMV-18X cards is done by Yutaka Tamiya | ||
21 | (tamy@flab.fujitsu.co.jp). | ||
22 | |||
23 | Sources: | ||
24 | The Fujitsu MB86965 datasheet. | ||
25 | |||
26 | After the initial version of this driver was written Gerry Sawkins of | ||
27 | ATI provided their EEPROM configuration code header file. | ||
28 | Thanks to NIIBE Yutaka <gniibe@mri.co.jp> for bug fixes. | ||
29 | |||
30 | MCA bus (AT1720) support by Rene Schmit <rene@bss.lu> | ||
31 | |||
32 | Bugs: | ||
33 | The MB86965 has a design flaw that makes all probes unreliable. Not | ||
34 | only is it difficult to detect, it also moves around in I/O space in | ||
35 | response to inb()s from other device probes! | ||
36 | */ | ||
37 | |||
38 | #include <linux/errno.h> | ||
39 | #include <linux/netdevice.h> | ||
40 | #include <linux/etherdevice.h> | ||
41 | #include <linux/mca-legacy.h> | ||
42 | #include <linux/module.h> | ||
43 | #include <linux/kernel.h> | ||
44 | #include <linux/types.h> | ||
45 | #include <linux/fcntl.h> | ||
46 | #include <linux/interrupt.h> | ||
47 | #include <linux/ioport.h> | ||
48 | #include <linux/in.h> | ||
49 | #include <linux/skbuff.h> | ||
50 | #include <linux/string.h> | ||
51 | #include <linux/init.h> | ||
52 | #include <linux/crc32.h> | ||
53 | #include <linux/bitops.h> | ||
54 | |||
55 | #include <asm/system.h> | ||
56 | #include <asm/io.h> | ||
57 | #include <asm/dma.h> | ||
58 | |||
59 | static char version[] __initdata = | ||
60 | "at1700.c:v1.16 9/11/06 Donald Becker (becker@cesdis.gsfc.nasa.gov)\n"; | ||
61 | |||
62 | #define DRV_NAME "at1700" | ||
63 | |||
64 | /* Tunable parameters. */ | ||
65 | |||
66 | /* When to switch from the 64-entry multicast filter to Rx-all-multicast. */ | ||
67 | #define MC_FILTERBREAK 64 | ||
68 | |||
69 | /* These unusual address orders are used to verify the CONFIG register. */ | ||
70 | |||
71 | static int fmv18x_probe_list[] __initdata = { | ||
72 | 0x220, 0x240, 0x260, 0x280, 0x2a0, 0x2c0, 0x300, 0x340, 0 | ||
73 | }; | ||
74 | |||
75 | /* | ||
76 | * ISA | ||
77 | */ | ||
78 | |||
79 | static unsigned at1700_probe_list[] __initdata = { | ||
80 | 0x260, 0x280, 0x2a0, 0x240, 0x340, 0x320, 0x380, 0x300, 0 | ||
81 | }; | ||
82 | |||
83 | /* | ||
84 | * MCA | ||
85 | */ | ||
86 | #ifdef CONFIG_MCA_LEGACY | ||
87 | static int at1700_ioaddr_pattern[] __initdata = { | ||
88 | 0x00, 0x04, 0x01, 0x05, 0x02, 0x06, 0x03, 0x07 | ||
89 | }; | ||
90 | |||
91 | static int at1700_mca_probe_list[] __initdata = { | ||
92 | 0x400, 0x1400, 0x2400, 0x3400, 0x4400, 0x5400, 0x6400, 0x7400, 0 | ||
93 | }; | ||
94 | |||
95 | static int at1700_irq_pattern[] __initdata = { | ||
96 | 0x00, 0x00, 0x00, 0x30, 0x70, 0xb0, 0x00, 0x00, | ||
97 | 0x00, 0xf0, 0x34, 0x74, 0xb4, 0x00, 0x00, 0xf4, 0x00 | ||
98 | }; | ||
99 | #endif | ||
100 | |||
101 | /* use 0 for production, 1 for verification, >2 for debug */ | ||
102 | #ifndef NET_DEBUG | ||
103 | #define NET_DEBUG 1 | ||
104 | #endif | ||
105 | static unsigned int net_debug = NET_DEBUG; | ||
106 | |||
107 | typedef unsigned char uchar; | ||
108 | |||
109 | /* Information that need to be kept for each board. */ | ||
110 | struct net_local { | ||
111 | spinlock_t lock; | ||
112 | unsigned char mc_filter[8]; | ||
113 | uint jumpered:1; /* Set iff the board has jumper config. */ | ||
114 | uint tx_started:1; /* Packets are on the Tx queue. */ | ||
115 | uint tx_queue_ready:1; /* Tx queue is ready to be sent. */ | ||
116 | uint rx_started:1; /* Packets are Rxing. */ | ||
117 | uchar tx_queue; /* Number of packet on the Tx queue. */ | ||
118 | char mca_slot; /* -1 means ISA */ | ||
119 | ushort tx_queue_len; /* Current length of the Tx queue. */ | ||
120 | }; | ||
121 | |||
122 | |||
123 | /* Offsets from the base address. */ | ||
124 | #define STATUS 0 | ||
125 | #define TX_STATUS 0 | ||
126 | #define RX_STATUS 1 | ||
127 | #define TX_INTR 2 /* Bit-mapped interrupt enable registers. */ | ||
128 | #define RX_INTR 3 | ||
129 | #define TX_MODE 4 | ||
130 | #define RX_MODE 5 | ||
131 | #define CONFIG_0 6 /* Misc. configuration settings. */ | ||
132 | #define CONFIG_1 7 | ||
133 | /* Run-time register bank 2 definitions. */ | ||
134 | #define DATAPORT 8 /* Word-wide DMA or programmed-I/O dataport. */ | ||
135 | #define TX_START 10 | ||
136 | #define COL16CNTL 11 /* Control Reg for 16 collisions */ | ||
137 | #define MODE13 13 | ||
138 | #define RX_CTRL 14 | ||
139 | /* Configuration registers only on the '865A/B chips. */ | ||
140 | #define EEPROM_Ctrl 16 | ||
141 | #define EEPROM_Data 17 | ||
142 | #define CARDSTATUS 16 /* FMV-18x Card Status */ | ||
143 | #define CARDSTATUS1 17 /* FMV-18x Card Status */ | ||
144 | #define IOCONFIG 18 /* Either read the jumper, or move the I/O. */ | ||
145 | #define IOCONFIG1 19 | ||
146 | #define SAPROM 20 /* The station address PROM, if no EEPROM. */ | ||
147 | #define MODE24 24 | ||
148 | #define RESET 31 /* Write to reset some parts of the chip. */ | ||
149 | #define AT1700_IO_EXTENT 32 | ||
150 | #define PORT_OFFSET(o) (o) | ||
151 | |||
152 | |||
153 | #define TX_TIMEOUT (HZ/10) | ||
154 | |||
155 | |||
156 | /* Index to functions, as function prototypes. */ | ||
157 | |||
158 | static int at1700_probe1(struct net_device *dev, int ioaddr); | ||
159 | static int read_eeprom(long ioaddr, int location); | ||
160 | static int net_open(struct net_device *dev); | ||
161 | static netdev_tx_t net_send_packet(struct sk_buff *skb, | ||
162 | struct net_device *dev); | ||
163 | static irqreturn_t net_interrupt(int irq, void *dev_id); | ||
164 | static void net_rx(struct net_device *dev); | ||
165 | static int net_close(struct net_device *dev); | ||
166 | static void set_rx_mode(struct net_device *dev); | ||
167 | static void net_tx_timeout (struct net_device *dev); | ||
168 | |||
169 | |||
170 | #ifdef CONFIG_MCA_LEGACY | ||
171 | struct at1720_mca_adapters_struct { | ||
172 | char* name; | ||
173 | int id; | ||
174 | }; | ||
175 | /* rEnE : maybe there are others I don't know off... */ | ||
176 | |||
177 | static struct at1720_mca_adapters_struct at1720_mca_adapters[] __initdata = { | ||
178 | { "Allied Telesys AT1720AT", 0x6410 }, | ||
179 | { "Allied Telesys AT1720BT", 0x6413 }, | ||
180 | { "Allied Telesys AT1720T", 0x6416 }, | ||
181 | { NULL, 0 }, | ||
182 | }; | ||
183 | #endif | ||
184 | |||
185 | /* Check for a network adaptor of this type, and return '0' iff one exists. | ||
186 | If dev->base_addr == 0, probe all likely locations. | ||
187 | If dev->base_addr == 1, always return failure. | ||
188 | If dev->base_addr == 2, allocate space for the device and return success | ||
189 | (detachable devices only). | ||
190 | */ | ||
191 | |||
192 | static int io = 0x260; | ||
193 | |||
194 | static int irq; | ||
195 | |||
196 | static void cleanup_card(struct net_device *dev) | ||
197 | { | ||
198 | #ifdef CONFIG_MCA_LEGACY | ||
199 | struct net_local *lp = netdev_priv(dev); | ||
200 | if (lp->mca_slot >= 0) | ||
201 | mca_mark_as_unused(lp->mca_slot); | ||
202 | #endif | ||
203 | free_irq(dev->irq, NULL); | ||
204 | release_region(dev->base_addr, AT1700_IO_EXTENT); | ||
205 | } | ||
206 | |||
207 | struct net_device * __init at1700_probe(int unit) | ||
208 | { | ||
209 | struct net_device *dev = alloc_etherdev(sizeof(struct net_local)); | ||
210 | unsigned *port; | ||
211 | int err = 0; | ||
212 | |||
213 | if (!dev) | ||
214 | return ERR_PTR(-ENODEV); | ||
215 | |||
216 | if (unit >= 0) { | ||
217 | sprintf(dev->name, "eth%d", unit); | ||
218 | netdev_boot_setup_check(dev); | ||
219 | io = dev->base_addr; | ||
220 | irq = dev->irq; | ||
221 | } else { | ||
222 | dev->base_addr = io; | ||
223 | dev->irq = irq; | ||
224 | } | ||
225 | |||
226 | if (io > 0x1ff) { /* Check a single specified location. */ | ||
227 | err = at1700_probe1(dev, io); | ||
228 | } else if (io != 0) { /* Don't probe at all. */ | ||
229 | err = -ENXIO; | ||
230 | } else { | ||
231 | for (port = at1700_probe_list; *port; port++) { | ||
232 | if (at1700_probe1(dev, *port) == 0) | ||
233 | break; | ||
234 | dev->irq = irq; | ||
235 | } | ||
236 | if (!*port) | ||
237 | err = -ENODEV; | ||
238 | } | ||
239 | if (err) | ||
240 | goto out; | ||
241 | err = register_netdev(dev); | ||
242 | if (err) | ||
243 | goto out1; | ||
244 | return dev; | ||
245 | out1: | ||
246 | cleanup_card(dev); | ||
247 | out: | ||
248 | free_netdev(dev); | ||
249 | return ERR_PTR(err); | ||
250 | } | ||
251 | |||
252 | static const struct net_device_ops at1700_netdev_ops = { | ||
253 | .ndo_open = net_open, | ||
254 | .ndo_stop = net_close, | ||
255 | .ndo_start_xmit = net_send_packet, | ||
256 | .ndo_set_multicast_list = set_rx_mode, | ||
257 | .ndo_tx_timeout = net_tx_timeout, | ||
258 | .ndo_change_mtu = eth_change_mtu, | ||
259 | .ndo_set_mac_address = eth_mac_addr, | ||
260 | .ndo_validate_addr = eth_validate_addr, | ||
261 | }; | ||
262 | |||
263 | /* The Fujitsu datasheet suggests that the NIC be probed for by checking its | ||
264 | "signature", the default bit pattern after a reset. This *doesn't* work -- | ||
265 | there is no way to reset the bus interface without a complete power-cycle! | ||
266 | |||
267 | It turns out that ATI came to the same conclusion I did: the only thing | ||
268 | that can be done is checking a few bits and then diving right into an | ||
269 | EEPROM read. */ | ||
270 | |||
271 | static int __init at1700_probe1(struct net_device *dev, int ioaddr) | ||
272 | { | ||
273 | static const char fmv_irqmap[4] = {3, 7, 10, 15}; | ||
274 | static const char fmv_irqmap_pnp[8] = {3, 4, 5, 7, 9, 10, 11, 15}; | ||
275 | static const char at1700_irqmap[8] = {3, 4, 5, 9, 10, 11, 14, 15}; | ||
276 | unsigned int i, irq, is_fmv18x = 0, is_at1700 = 0; | ||
277 | int slot, ret = -ENODEV; | ||
278 | struct net_local *lp = netdev_priv(dev); | ||
279 | |||
280 | if (!request_region(ioaddr, AT1700_IO_EXTENT, DRV_NAME)) | ||
281 | return -EBUSY; | ||
282 | |||
283 | /* Resetting the chip doesn't reset the ISA interface, so don't bother. | ||
284 | That means we have to be careful with the register values we probe | ||
285 | for. | ||
286 | */ | ||
287 | #ifdef notdef | ||
288 | printk("at1700 probe at %#x, eeprom is %4.4x %4.4x %4.4x ctrl %4.4x.\n", | ||
289 | ioaddr, read_eeprom(ioaddr, 4), read_eeprom(ioaddr, 5), | ||
290 | read_eeprom(ioaddr, 6), inw(ioaddr + EEPROM_Ctrl)); | ||
291 | #endif | ||
292 | |||
293 | #ifdef CONFIG_MCA_LEGACY | ||
294 | /* rEnE (rene@bss.lu): got this from 3c509 driver source , adapted for AT1720 */ | ||
295 | |||
296 | /* Based on Erik Nygren's (nygren@mit.edu) 3c529 patch, heavily | ||
297 | modified by Chris Beauregard (cpbeaure@csclub.uwaterloo.ca) | ||
298 | to support standard MCA probing. */ | ||
299 | |||
300 | /* redone for multi-card detection by ZP Gu (zpg@castle.net) */ | ||
301 | /* now works as a module */ | ||
302 | |||
303 | if (MCA_bus) { | ||
304 | int j; | ||
305 | int l_i; | ||
306 | u_char pos3, pos4; | ||
307 | |||
308 | for (j = 0; at1720_mca_adapters[j].name != NULL; j ++) { | ||
309 | slot = 0; | ||
310 | while (slot != MCA_NOTFOUND) { | ||
311 | |||
312 | slot = mca_find_unused_adapter( at1720_mca_adapters[j].id, slot ); | ||
313 | if (slot == MCA_NOTFOUND) break; | ||
314 | |||
315 | /* if we get this far, an adapter has been detected and is | ||
316 | enabled */ | ||
317 | |||
318 | pos3 = mca_read_stored_pos( slot, 3 ); | ||
319 | pos4 = mca_read_stored_pos( slot, 4 ); | ||
320 | |||
321 | for (l_i = 0; l_i < 8; l_i++) | ||
322 | if (( pos3 & 0x07) == at1700_ioaddr_pattern[l_i]) | ||
323 | break; | ||
324 | ioaddr = at1700_mca_probe_list[l_i]; | ||
325 | |||
326 | for (irq = 0; irq < 0x10; irq++) | ||
327 | if (((((pos4>>4) & 0x0f) | (pos3 & 0xf0)) & 0xff) == at1700_irq_pattern[irq]) | ||
328 | break; | ||
329 | |||
330 | /* probing for a card at a particular IO/IRQ */ | ||
331 | if ((dev->irq && dev->irq != irq) || | ||
332 | (dev->base_addr && dev->base_addr != ioaddr)) { | ||
333 | slot++; /* probing next slot */ | ||
334 | continue; | ||
335 | } | ||
336 | |||
337 | dev->irq = irq; | ||
338 | |||
339 | /* claim the slot */ | ||
340 | mca_set_adapter_name( slot, at1720_mca_adapters[j].name ); | ||
341 | mca_mark_as_used(slot); | ||
342 | |||
343 | goto found; | ||
344 | } | ||
345 | } | ||
346 | /* if we get here, we didn't find an MCA adapter - try ISA */ | ||
347 | } | ||
348 | #endif | ||
349 | slot = -1; | ||
350 | /* We must check for the EEPROM-config boards first, else accessing | ||
351 | IOCONFIG0 will move the board! */ | ||
352 | if (at1700_probe_list[inb(ioaddr + IOCONFIG1) & 0x07] == ioaddr && | ||
353 | read_eeprom(ioaddr, 4) == 0x0000 && | ||
354 | (read_eeprom(ioaddr, 5) & 0xff00) == 0xF400) | ||
355 | is_at1700 = 1; | ||
356 | else if (inb(ioaddr + SAPROM ) == 0x00 && | ||
357 | inb(ioaddr + SAPROM + 1) == 0x00 && | ||
358 | inb(ioaddr + SAPROM + 2) == 0x0e) | ||
359 | is_fmv18x = 1; | ||
360 | else { | ||
361 | goto err_out; | ||
362 | } | ||
363 | |||
364 | #ifdef CONFIG_MCA_LEGACY | ||
365 | found: | ||
366 | #endif | ||
367 | |||
368 | /* Reset the internal state machines. */ | ||
369 | outb(0, ioaddr + RESET); | ||
370 | |||
371 | if (is_at1700) { | ||
372 | irq = at1700_irqmap[(read_eeprom(ioaddr, 12)&0x04) | ||
373 | | (read_eeprom(ioaddr, 0)>>14)]; | ||
374 | } else { | ||
375 | /* Check PnP mode for FMV-183/184/183A/184A. */ | ||
376 | /* This PnP routine is very poor. IO and IRQ should be known. */ | ||
377 | if (inb(ioaddr + CARDSTATUS1) & 0x20) { | ||
378 | irq = dev->irq; | ||
379 | for (i = 0; i < 8; i++) { | ||
380 | if (irq == fmv_irqmap_pnp[i]) | ||
381 | break; | ||
382 | } | ||
383 | if (i == 8) { | ||
384 | goto err_mca; | ||
385 | } | ||
386 | } else { | ||
387 | if (fmv18x_probe_list[inb(ioaddr + IOCONFIG) & 0x07] != ioaddr) | ||
388 | goto err_mca; | ||
389 | irq = fmv_irqmap[(inb(ioaddr + IOCONFIG)>>6) & 0x03]; | ||
390 | } | ||
391 | } | ||
392 | |||
393 | printk("%s: %s found at %#3x, IRQ %d, address ", dev->name, | ||
394 | is_at1700 ? "AT1700" : "FMV-18X", ioaddr, irq); | ||
395 | |||
396 | dev->base_addr = ioaddr; | ||
397 | dev->irq = irq; | ||
398 | |||
399 | if (is_at1700) { | ||
400 | for(i = 0; i < 3; i++) { | ||
401 | unsigned short eeprom_val = read_eeprom(ioaddr, 4+i); | ||
402 | ((unsigned short *)dev->dev_addr)[i] = ntohs(eeprom_val); | ||
403 | } | ||
404 | } else { | ||
405 | for(i = 0; i < 6; i++) { | ||
406 | unsigned char val = inb(ioaddr + SAPROM + i); | ||
407 | dev->dev_addr[i] = val; | ||
408 | } | ||
409 | } | ||
410 | printk("%pM", dev->dev_addr); | ||
411 | |||
412 | /* The EEPROM word 12 bit 0x0400 means use regular 100 ohm 10baseT signals, | ||
413 | rather than 150 ohm shielded twisted pair compensation. | ||
414 | 0x0000 == auto-sense the interface | ||
415 | 0x0800 == use TP interface | ||
416 | 0x1800 == use coax interface | ||
417 | */ | ||
418 | { | ||
419 | const char *porttype[] = {"auto-sense", "10baseT", "auto-sense", "10base2"}; | ||
420 | if (is_at1700) { | ||
421 | ushort setup_value = read_eeprom(ioaddr, 12); | ||
422 | dev->if_port = setup_value >> 8; | ||
423 | } else { | ||
424 | ushort setup_value = inb(ioaddr + CARDSTATUS); | ||
425 | switch (setup_value & 0x07) { | ||
426 | case 0x01: /* 10base5 */ | ||
427 | case 0x02: /* 10base2 */ | ||
428 | dev->if_port = 0x18; break; | ||
429 | case 0x04: /* 10baseT */ | ||
430 | dev->if_port = 0x08; break; | ||
431 | default: /* auto-sense */ | ||
432 | dev->if_port = 0x00; break; | ||
433 | } | ||
434 | } | ||
435 | printk(" %s interface.\n", porttype[(dev->if_port>>3) & 3]); | ||
436 | } | ||
437 | |||
438 | /* Set the configuration register 0 to 32K 100ns. byte-wide memory, 16 bit | ||
439 | bus access, two 4K Tx queues, and disabled Tx and Rx. */ | ||
440 | outb(0xda, ioaddr + CONFIG_0); | ||
441 | |||
442 | /* Set the station address in bank zero. */ | ||
443 | outb(0x00, ioaddr + CONFIG_1); | ||
444 | for (i = 0; i < 6; i++) | ||
445 | outb(dev->dev_addr[i], ioaddr + PORT_OFFSET(8 + i)); | ||
446 | |||
447 | /* Switch to bank 1 and set the multicast table to accept none. */ | ||
448 | outb(0x04, ioaddr + CONFIG_1); | ||
449 | for (i = 0; i < 8; i++) | ||
450 | outb(0x00, ioaddr + PORT_OFFSET(8 + i)); | ||
451 | |||
452 | |||
453 | /* Switch to bank 2 */ | ||
454 | /* Lock our I/O address, and set manual processing mode for 16 collisions. */ | ||
455 | outb(0x08, ioaddr + CONFIG_1); | ||
456 | outb(dev->if_port, ioaddr + MODE13); | ||
457 | outb(0x00, ioaddr + COL16CNTL); | ||
458 | |||
459 | if (net_debug) | ||
460 | printk(version); | ||
461 | |||
462 | dev->netdev_ops = &at1700_netdev_ops; | ||
463 | dev->watchdog_timeo = TX_TIMEOUT; | ||
464 | |||
465 | spin_lock_init(&lp->lock); | ||
466 | |||
467 | lp->jumpered = is_fmv18x; | ||
468 | lp->mca_slot = slot; | ||
469 | /* Snarf the interrupt vector now. */ | ||
470 | ret = request_irq(irq, net_interrupt, 0, DRV_NAME, dev); | ||
471 | if (ret) { | ||
472 | printk(KERN_ERR "AT1700 at %#3x is unusable due to a " | ||
473 | "conflict on IRQ %d.\n", | ||
474 | ioaddr, irq); | ||
475 | goto err_mca; | ||
476 | } | ||
477 | |||
478 | return 0; | ||
479 | |||
480 | err_mca: | ||
481 | #ifdef CONFIG_MCA_LEGACY | ||
482 | if (slot >= 0) | ||
483 | mca_mark_as_unused(slot); | ||
484 | #endif | ||
485 | err_out: | ||
486 | release_region(ioaddr, AT1700_IO_EXTENT); | ||
487 | return ret; | ||
488 | } | ||
489 | |||
490 | |||
491 | /* EEPROM_Ctrl bits. */ | ||
492 | #define EE_SHIFT_CLK 0x40 /* EEPROM shift clock, in reg. 16. */ | ||
493 | #define EE_CS 0x20 /* EEPROM chip select, in reg. 16. */ | ||
494 | #define EE_DATA_WRITE 0x80 /* EEPROM chip data in, in reg. 17. */ | ||
495 | #define EE_DATA_READ 0x80 /* EEPROM chip data out, in reg. 17. */ | ||
496 | |||
497 | /* The EEPROM commands include the alway-set leading bit. */ | ||
498 | #define EE_WRITE_CMD (5 << 6) | ||
499 | #define EE_READ_CMD (6 << 6) | ||
500 | #define EE_ERASE_CMD (7 << 6) | ||
501 | |||
502 | static int __init read_eeprom(long ioaddr, int location) | ||
503 | { | ||
504 | int i; | ||
505 | unsigned short retval = 0; | ||
506 | long ee_addr = ioaddr + EEPROM_Ctrl; | ||
507 | long ee_daddr = ioaddr + EEPROM_Data; | ||
508 | int read_cmd = location | EE_READ_CMD; | ||
509 | |||
510 | /* Shift the read command bits out. */ | ||
511 | for (i = 9; i >= 0; i--) { | ||
512 | short dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0; | ||
513 | outb(EE_CS, ee_addr); | ||
514 | outb(dataval, ee_daddr); | ||
515 | outb(EE_CS | EE_SHIFT_CLK, ee_addr); /* EEPROM clock tick. */ | ||
516 | } | ||
517 | outb(EE_DATA_WRITE, ee_daddr); | ||
518 | for (i = 16; i > 0; i--) { | ||
519 | outb(EE_CS, ee_addr); | ||
520 | outb(EE_CS | EE_SHIFT_CLK, ee_addr); | ||
521 | retval = (retval << 1) | ((inb(ee_daddr) & EE_DATA_READ) ? 1 : 0); | ||
522 | } | ||
523 | |||
524 | /* Terminate the EEPROM access. */ | ||
525 | outb(EE_CS, ee_addr); | ||
526 | outb(EE_SHIFT_CLK, ee_addr); | ||
527 | outb(0, ee_addr); | ||
528 | return retval; | ||
529 | } | ||
530 | |||
531 | |||
532 | |||
533 | static int net_open(struct net_device *dev) | ||
534 | { | ||
535 | struct net_local *lp = netdev_priv(dev); | ||
536 | int ioaddr = dev->base_addr; | ||
537 | |||
538 | /* Set the configuration register 0 to 32K 100ns. byte-wide memory, 16 bit | ||
539 | bus access, and two 4K Tx queues. */ | ||
540 | outb(0x5a, ioaddr + CONFIG_0); | ||
541 | |||
542 | /* Powerup, switch to register bank 2, and enable the Rx and Tx. */ | ||
543 | outb(0xe8, ioaddr + CONFIG_1); | ||
544 | |||
545 | lp->tx_started = 0; | ||
546 | lp->tx_queue_ready = 1; | ||
547 | lp->rx_started = 0; | ||
548 | lp->tx_queue = 0; | ||
549 | lp->tx_queue_len = 0; | ||
550 | |||
551 | /* Turn on hardware Tx and Rx interrupts. */ | ||
552 | outb(0x82, ioaddr + TX_INTR); | ||
553 | outb(0x81, ioaddr + RX_INTR); | ||
554 | |||
555 | /* Enable the IRQ on boards of fmv18x it is feasible. */ | ||
556 | if (lp->jumpered) { | ||
557 | outb(0x80, ioaddr + IOCONFIG1); | ||
558 | } | ||
559 | |||
560 | netif_start_queue(dev); | ||
561 | return 0; | ||
562 | } | ||
563 | |||
564 | static void net_tx_timeout (struct net_device *dev) | ||
565 | { | ||
566 | struct net_local *lp = netdev_priv(dev); | ||
567 | int ioaddr = dev->base_addr; | ||
568 | |||
569 | printk ("%s: transmit timed out with status %04x, %s?\n", dev->name, | ||
570 | inw (ioaddr + STATUS), inb (ioaddr + TX_STATUS) & 0x80 | ||
571 | ? "IRQ conflict" : "network cable problem"); | ||
572 | printk ("%s: timeout registers: %04x %04x %04x %04x %04x %04x %04x %04x.\n", | ||
573 | dev->name, inw(ioaddr + TX_STATUS), inw(ioaddr + TX_INTR), inw(ioaddr + TX_MODE), | ||
574 | inw(ioaddr + CONFIG_0), inw(ioaddr + DATAPORT), inw(ioaddr + TX_START), | ||
575 | inw(ioaddr + MODE13 - 1), inw(ioaddr + RX_CTRL)); | ||
576 | dev->stats.tx_errors++; | ||
577 | /* ToDo: We should try to restart the adaptor... */ | ||
578 | outw(0xffff, ioaddr + MODE24); | ||
579 | outw (0xffff, ioaddr + TX_STATUS); | ||
580 | outb (0x5a, ioaddr + CONFIG_0); | ||
581 | outb (0xe8, ioaddr + CONFIG_1); | ||
582 | outw (0x8182, ioaddr + TX_INTR); | ||
583 | outb (0x00, ioaddr + TX_START); | ||
584 | outb (0x03, ioaddr + COL16CNTL); | ||
585 | |||
586 | dev->trans_start = jiffies; /* prevent tx timeout */ | ||
587 | |||
588 | lp->tx_started = 0; | ||
589 | lp->tx_queue_ready = 1; | ||
590 | lp->rx_started = 0; | ||
591 | lp->tx_queue = 0; | ||
592 | lp->tx_queue_len = 0; | ||
593 | |||
594 | netif_wake_queue(dev); | ||
595 | } | ||
596 | |||
597 | |||
598 | static netdev_tx_t net_send_packet (struct sk_buff *skb, | ||
599 | struct net_device *dev) | ||
600 | { | ||
601 | struct net_local *lp = netdev_priv(dev); | ||
602 | int ioaddr = dev->base_addr; | ||
603 | short length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN; | ||
604 | short len = skb->len; | ||
605 | unsigned char *buf = skb->data; | ||
606 | static u8 pad[ETH_ZLEN]; | ||
607 | |||
608 | netif_stop_queue (dev); | ||
609 | |||
610 | /* We may not start transmitting unless we finish transferring | ||
611 | a packet into the Tx queue. During executing the following | ||
612 | codes we possibly catch a Tx interrupt. Thus we flag off | ||
613 | tx_queue_ready, so that we prevent the interrupt routine | ||
614 | (net_interrupt) to start transmitting. */ | ||
615 | lp->tx_queue_ready = 0; | ||
616 | { | ||
617 | outw (length, ioaddr + DATAPORT); | ||
618 | /* Packet data */ | ||
619 | outsw (ioaddr + DATAPORT, buf, len >> 1); | ||
620 | /* Check for dribble byte */ | ||
621 | if (len & 1) { | ||
622 | outw(skb->data[skb->len-1], ioaddr + DATAPORT); | ||
623 | len++; | ||
624 | } | ||
625 | /* Check for packet padding */ | ||
626 | if (length != skb->len) | ||
627 | outsw(ioaddr + DATAPORT, pad, (length - len + 1) >> 1); | ||
628 | |||
629 | lp->tx_queue++; | ||
630 | lp->tx_queue_len += length + 2; | ||
631 | } | ||
632 | lp->tx_queue_ready = 1; | ||
633 | |||
634 | if (lp->tx_started == 0) { | ||
635 | /* If the Tx is idle, always trigger a transmit. */ | ||
636 | outb (0x80 | lp->tx_queue, ioaddr + TX_START); | ||
637 | lp->tx_queue = 0; | ||
638 | lp->tx_queue_len = 0; | ||
639 | lp->tx_started = 1; | ||
640 | netif_start_queue (dev); | ||
641 | } else if (lp->tx_queue_len < 4096 - 1502) | ||
642 | /* Yes, there is room for one more packet. */ | ||
643 | netif_start_queue (dev); | ||
644 | dev_kfree_skb (skb); | ||
645 | |||
646 | return NETDEV_TX_OK; | ||
647 | } | ||
648 | |||
649 | /* The typical workload of the driver: | ||
650 | Handle the network interface interrupts. */ | ||
651 | static irqreturn_t net_interrupt(int irq, void *dev_id) | ||
652 | { | ||
653 | struct net_device *dev = dev_id; | ||
654 | struct net_local *lp; | ||
655 | int ioaddr, status; | ||
656 | int handled = 0; | ||
657 | |||
658 | if (dev == NULL) { | ||
659 | printk ("at1700_interrupt(): irq %d for unknown device.\n", irq); | ||
660 | return IRQ_NONE; | ||
661 | } | ||
662 | |||
663 | ioaddr = dev->base_addr; | ||
664 | lp = netdev_priv(dev); | ||
665 | |||
666 | spin_lock (&lp->lock); | ||
667 | |||
668 | status = inw(ioaddr + TX_STATUS); | ||
669 | outw(status, ioaddr + TX_STATUS); | ||
670 | |||
671 | if (net_debug > 4) | ||
672 | printk("%s: Interrupt with status %04x.\n", dev->name, status); | ||
673 | if (lp->rx_started == 0 && | ||
674 | (status & 0xff00 || (inb(ioaddr + RX_MODE) & 0x40) == 0)) { | ||
675 | /* Got a packet(s). | ||
676 | We cannot execute net_rx more than once at the same time for | ||
677 | the same device. During executing net_rx, we possibly catch a | ||
678 | Tx interrupt. Thus we flag on rx_started, so that we prevent | ||
679 | the interrupt routine (net_interrupt) to dive into net_rx | ||
680 | again. */ | ||
681 | handled = 1; | ||
682 | lp->rx_started = 1; | ||
683 | outb(0x00, ioaddr + RX_INTR); /* Disable RX intr. */ | ||
684 | net_rx(dev); | ||
685 | outb(0x81, ioaddr + RX_INTR); /* Enable RX intr. */ | ||
686 | lp->rx_started = 0; | ||
687 | } | ||
688 | if (status & 0x00ff) { | ||
689 | handled = 1; | ||
690 | if (status & 0x02) { | ||
691 | /* More than 16 collisions occurred */ | ||
692 | if (net_debug > 4) | ||
693 | printk("%s: 16 Collision occur during Txing.\n", dev->name); | ||
694 | /* Cancel sending a packet. */ | ||
695 | outb(0x03, ioaddr + COL16CNTL); | ||
696 | dev->stats.collisions++; | ||
697 | } | ||
698 | if (status & 0x82) { | ||
699 | dev->stats.tx_packets++; | ||
700 | /* The Tx queue has any packets and is not being | ||
701 | transferred a packet from the host, start | ||
702 | transmitting. */ | ||
703 | if (lp->tx_queue && lp->tx_queue_ready) { | ||
704 | outb(0x80 | lp->tx_queue, ioaddr + TX_START); | ||
705 | lp->tx_queue = 0; | ||
706 | lp->tx_queue_len = 0; | ||
707 | dev->trans_start = jiffies; | ||
708 | netif_wake_queue (dev); | ||
709 | } else { | ||
710 | lp->tx_started = 0; | ||
711 | netif_wake_queue (dev); | ||
712 | } | ||
713 | } | ||
714 | } | ||
715 | |||
716 | spin_unlock (&lp->lock); | ||
717 | return IRQ_RETVAL(handled); | ||
718 | } | ||
719 | |||
720 | /* We have a good packet(s), get it/them out of the buffers. */ | ||
721 | static void | ||
722 | net_rx(struct net_device *dev) | ||
723 | { | ||
724 | int ioaddr = dev->base_addr; | ||
725 | int boguscount = 5; | ||
726 | |||
727 | while ((inb(ioaddr + RX_MODE) & 0x40) == 0) { | ||
728 | ushort status = inw(ioaddr + DATAPORT); | ||
729 | ushort pkt_len = inw(ioaddr + DATAPORT); | ||
730 | |||
731 | if (net_debug > 4) | ||
732 | printk("%s: Rxing packet mode %02x status %04x.\n", | ||
733 | dev->name, inb(ioaddr + RX_MODE), status); | ||
734 | #ifndef final_version | ||
735 | if (status == 0) { | ||
736 | outb(0x05, ioaddr + RX_CTRL); | ||
737 | break; | ||
738 | } | ||
739 | #endif | ||
740 | |||
741 | if ((status & 0xF0) != 0x20) { /* There was an error. */ | ||
742 | dev->stats.rx_errors++; | ||
743 | if (status & 0x08) dev->stats.rx_length_errors++; | ||
744 | if (status & 0x04) dev->stats.rx_frame_errors++; | ||
745 | if (status & 0x02) dev->stats.rx_crc_errors++; | ||
746 | if (status & 0x01) dev->stats.rx_over_errors++; | ||
747 | } else { | ||
748 | /* Malloc up new buffer. */ | ||
749 | struct sk_buff *skb; | ||
750 | |||
751 | if (pkt_len > 1550) { | ||
752 | printk("%s: The AT1700 claimed a very large packet, size %d.\n", | ||
753 | dev->name, pkt_len); | ||
754 | /* Prime the FIFO and then flush the packet. */ | ||
755 | inw(ioaddr + DATAPORT); inw(ioaddr + DATAPORT); | ||
756 | outb(0x05, ioaddr + RX_CTRL); | ||
757 | dev->stats.rx_errors++; | ||
758 | break; | ||
759 | } | ||
760 | skb = dev_alloc_skb(pkt_len+3); | ||
761 | if (skb == NULL) { | ||
762 | printk("%s: Memory squeeze, dropping packet (len %d).\n", | ||
763 | dev->name, pkt_len); | ||
764 | /* Prime the FIFO and then flush the packet. */ | ||
765 | inw(ioaddr + DATAPORT); inw(ioaddr + DATAPORT); | ||
766 | outb(0x05, ioaddr + RX_CTRL); | ||
767 | dev->stats.rx_dropped++; | ||
768 | break; | ||
769 | } | ||
770 | skb_reserve(skb,2); | ||
771 | |||
772 | insw(ioaddr + DATAPORT, skb_put(skb,pkt_len), (pkt_len + 1) >> 1); | ||
773 | skb->protocol=eth_type_trans(skb, dev); | ||
774 | netif_rx(skb); | ||
775 | dev->stats.rx_packets++; | ||
776 | dev->stats.rx_bytes += pkt_len; | ||
777 | } | ||
778 | if (--boguscount <= 0) | ||
779 | break; | ||
780 | } | ||
781 | |||
782 | /* If any worth-while packets have been received, dev_rint() | ||
783 | has done a mark_bh(NET_BH) for us and will work on them | ||
784 | when we get to the bottom-half routine. */ | ||
785 | { | ||
786 | int i; | ||
787 | for (i = 0; i < 20; i++) { | ||
788 | if ((inb(ioaddr + RX_MODE) & 0x40) == 0x40) | ||
789 | break; | ||
790 | inw(ioaddr + DATAPORT); /* dummy status read */ | ||
791 | outb(0x05, ioaddr + RX_CTRL); | ||
792 | } | ||
793 | |||
794 | if (net_debug > 5) | ||
795 | printk("%s: Exint Rx packet with mode %02x after %d ticks.\n", | ||
796 | dev->name, inb(ioaddr + RX_MODE), i); | ||
797 | } | ||
798 | } | ||
799 | |||
800 | /* The inverse routine to net_open(). */ | ||
801 | static int net_close(struct net_device *dev) | ||
802 | { | ||
803 | struct net_local *lp = netdev_priv(dev); | ||
804 | int ioaddr = dev->base_addr; | ||
805 | |||
806 | netif_stop_queue(dev); | ||
807 | |||
808 | /* Set configuration register 0 to disable Tx and Rx. */ | ||
809 | outb(0xda, ioaddr + CONFIG_0); | ||
810 | |||
811 | /* No statistic counters on the chip to update. */ | ||
812 | |||
813 | /* Disable the IRQ on boards of fmv18x where it is feasible. */ | ||
814 | if (lp->jumpered) | ||
815 | outb(0x00, ioaddr + IOCONFIG1); | ||
816 | |||
817 | /* Power-down the chip. Green, green, green! */ | ||
818 | outb(0x00, ioaddr + CONFIG_1); | ||
819 | return 0; | ||
820 | } | ||
821 | |||
822 | /* | ||
823 | Set the multicast/promiscuous mode for this adaptor. | ||
824 | */ | ||
825 | |||
826 | static void | ||
827 | set_rx_mode(struct net_device *dev) | ||
828 | { | ||
829 | int ioaddr = dev->base_addr; | ||
830 | struct net_local *lp = netdev_priv(dev); | ||
831 | unsigned char mc_filter[8]; /* Multicast hash filter */ | ||
832 | unsigned long flags; | ||
833 | |||
834 | if (dev->flags & IFF_PROMISC) { | ||
835 | memset(mc_filter, 0xff, sizeof(mc_filter)); | ||
836 | outb(3, ioaddr + RX_MODE); /* Enable promiscuous mode */ | ||
837 | } else if (netdev_mc_count(dev) > MC_FILTERBREAK || | ||
838 | (dev->flags & IFF_ALLMULTI)) { | ||
839 | /* Too many to filter perfectly -- accept all multicasts. */ | ||
840 | memset(mc_filter, 0xff, sizeof(mc_filter)); | ||
841 | outb(2, ioaddr + RX_MODE); /* Use normal mode. */ | ||
842 | } else if (netdev_mc_empty(dev)) { | ||
843 | memset(mc_filter, 0x00, sizeof(mc_filter)); | ||
844 | outb(1, ioaddr + RX_MODE); /* Ignore almost all multicasts. */ | ||
845 | } else { | ||
846 | struct netdev_hw_addr *ha; | ||
847 | |||
848 | memset(mc_filter, 0, sizeof(mc_filter)); | ||
849 | netdev_for_each_mc_addr(ha, dev) { | ||
850 | unsigned int bit = | ||
851 | ether_crc_le(ETH_ALEN, ha->addr) >> 26; | ||
852 | mc_filter[bit >> 3] |= (1 << bit); | ||
853 | } | ||
854 | outb(0x02, ioaddr + RX_MODE); /* Use normal mode. */ | ||
855 | } | ||
856 | |||
857 | spin_lock_irqsave (&lp->lock, flags); | ||
858 | if (memcmp(mc_filter, lp->mc_filter, sizeof(mc_filter))) { | ||
859 | int i; | ||
860 | int saved_bank = inw(ioaddr + CONFIG_0); | ||
861 | /* Switch to bank 1 and set the multicast table. */ | ||
862 | outw((saved_bank & ~0x0C00) | 0x0480, ioaddr + CONFIG_0); | ||
863 | for (i = 0; i < 8; i++) | ||
864 | outb(mc_filter[i], ioaddr + PORT_OFFSET(8 + i)); | ||
865 | memcpy(lp->mc_filter, mc_filter, sizeof(mc_filter)); | ||
866 | outw(saved_bank, ioaddr + CONFIG_0); | ||
867 | } | ||
868 | spin_unlock_irqrestore (&lp->lock, flags); | ||
869 | } | ||
870 | |||
871 | #ifdef MODULE | ||
872 | static struct net_device *dev_at1700; | ||
873 | |||
874 | module_param(io, int, 0); | ||
875 | module_param(irq, int, 0); | ||
876 | module_param(net_debug, int, 0); | ||
877 | MODULE_PARM_DESC(io, "AT1700/FMV18X I/O base address"); | ||
878 | MODULE_PARM_DESC(irq, "AT1700/FMV18X IRQ number"); | ||
879 | MODULE_PARM_DESC(net_debug, "AT1700/FMV18X debug level (0-6)"); | ||
880 | |||
881 | static int __init at1700_module_init(void) | ||
882 | { | ||
883 | if (io == 0) | ||
884 | printk("at1700: You should not use auto-probing with insmod!\n"); | ||
885 | dev_at1700 = at1700_probe(-1); | ||
886 | if (IS_ERR(dev_at1700)) | ||
887 | return PTR_ERR(dev_at1700); | ||
888 | return 0; | ||
889 | } | ||
890 | |||
891 | static void __exit at1700_module_exit(void) | ||
892 | { | ||
893 | unregister_netdev(dev_at1700); | ||
894 | cleanup_card(dev_at1700); | ||
895 | free_netdev(dev_at1700); | ||
896 | } | ||
897 | module_init(at1700_module_init); | ||
898 | module_exit(at1700_module_exit); | ||
899 | #endif /* MODULE */ | ||
900 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/net/ethernet/fujitsu/eth16i.c b/drivers/net/ethernet/fujitsu/eth16i.c new file mode 100644 index 000000000000..12d28e9d0cb7 --- /dev/null +++ b/drivers/net/ethernet/fujitsu/eth16i.c | |||
@@ -0,0 +1,1484 @@ | |||
1 | /* eth16i.c An ICL EtherTeam 16i and 32 EISA ethernet driver for Linux | ||
2 | |||
3 | Written 1994-1999 by Mika Kuoppala | ||
4 | |||
5 | Copyright (C) 1994-1999 by Mika Kuoppala | ||
6 | Based on skeleton.c and heavily on at1700.c by Donald Becker | ||
7 | |||
8 | This software may be used and distributed according to the terms | ||
9 | of the GNU General Public License, incorporated herein by reference. | ||
10 | |||
11 | The author may be reached as miku@iki.fi | ||
12 | |||
13 | This driver supports following cards : | ||
14 | - ICL EtherTeam 16i | ||
15 | - ICL EtherTeam 32 EISA | ||
16 | (Uses true 32 bit transfers rather than 16i compatibility mode) | ||
17 | |||
18 | Example Module usage: | ||
19 | insmod eth16i.o io=0x2a0 mediatype=bnc | ||
20 | |||
21 | mediatype can be one of the following: bnc,tp,dix,auto,eprom | ||
22 | |||
23 | 'auto' will try to autoprobe mediatype. | ||
24 | 'eprom' will use whatever type defined in eprom. | ||
25 | |||
26 | I have benchmarked driver with PII/300Mhz as a ftp client | ||
27 | and 486/33Mhz as a ftp server. Top speed was 1128.37 kilobytes/sec. | ||
28 | |||
29 | Sources: | ||
30 | - skeleton.c a sample network driver core for linux, | ||
31 | written by Donald Becker <becker@scyld.com> | ||
32 | - at1700.c a driver for Allied Telesis AT1700, written | ||
33 | by Donald Becker. | ||
34 | - e16iSRV.asm a Netware 3.X Server Driver for ICL EtherTeam16i | ||
35 | written by Markku Viima | ||
36 | - The Fujitsu MB86965 databook. | ||
37 | |||
38 | Author thanks following persons due to their valueble assistance: | ||
39 | Markku Viima (ICL) | ||
40 | Ari Valve (ICL) | ||
41 | Donald Becker | ||
42 | Kurt Huwig <kurt@huwig.de> | ||
43 | |||
44 | Revision history: | ||
45 | |||
46 | Version Date Description | ||
47 | |||
48 | 0.01 15.12-94 Initial version (card detection) | ||
49 | 0.02 23.01-95 Interrupt is now hooked correctly | ||
50 | 0.03 01.02-95 Rewrote initialization part | ||
51 | 0.04 07.02-95 Base skeleton done... | ||
52 | Made a few changes to signature checking | ||
53 | to make it a bit reliable. | ||
54 | - fixed bug in tx_buf mapping | ||
55 | - fixed bug in initialization (DLC_EN | ||
56 | wasn't enabled when initialization | ||
57 | was done.) | ||
58 | 0.05 08.02-95 If there were more than one packet to send, | ||
59 | transmit was jammed due to invalid | ||
60 | register write...now fixed | ||
61 | 0.06 19.02-95 Rewrote interrupt handling | ||
62 | 0.07 13.04-95 Wrote EEPROM read routines | ||
63 | Card configuration now set according to | ||
64 | data read from EEPROM | ||
65 | 0.08 23.06-95 Wrote part that tries to probe used interface | ||
66 | port if AUTO is selected | ||
67 | |||
68 | 0.09 01.09-95 Added module support | ||
69 | |||
70 | 0.10 04.09-95 Fixed receive packet allocation to work | ||
71 | with kernels > 1.3.x | ||
72 | |||
73 | 0.20 20.09-95 Added support for EtherTeam32 EISA | ||
74 | |||
75 | 0.21 17.10-95 Removed the unnecessary extern | ||
76 | init_etherdev() declaration. Some | ||
77 | other cleanups. | ||
78 | |||
79 | 0.22 22.02-96 Receive buffer was not flushed | ||
80 | correctly when faulty packet was | ||
81 | received. Now fixed. | ||
82 | |||
83 | 0.23 26.02-96 Made resetting the adapter | ||
84 | more reliable. | ||
85 | |||
86 | 0.24 27.02-96 Rewrote faulty packet handling in eth16i_rx | ||
87 | |||
88 | 0.25 22.05-96 kfree() was missing from cleanup_module. | ||
89 | |||
90 | 0.26 11.06-96 Sometimes card was not found by | ||
91 | check_signature(). Now made more reliable. | ||
92 | |||
93 | 0.27 23.06-96 Oops. 16 consecutive collisions halted | ||
94 | adapter. Now will try to retransmit | ||
95 | MAX_COL_16 times before finally giving up. | ||
96 | |||
97 | 0.28 28.10-97 Added dev_id parameter (NULL) for free_irq | ||
98 | |||
99 | 0.29 29.10-97 Multiple card support for module users | ||
100 | |||
101 | 0.30 30.10-97 Fixed irq allocation bug. | ||
102 | (request_irq moved from probe to open) | ||
103 | |||
104 | 0.30a 21.08-98 Card detection made more relaxed. Driver | ||
105 | had problems with some TCP/IP-PROM boots | ||
106 | to find the card. Suggested by | ||
107 | Kurt Huwig <kurt@huwig.de> | ||
108 | |||
109 | 0.31 28.08-98 Media interface port can now be selected | ||
110 | with module parameters or kernel | ||
111 | boot parameters. | ||
112 | |||
113 | 0.32 31.08-98 IRQ was never freed if open/close | ||
114 | pair wasn't called. Now fixed. | ||
115 | |||
116 | 0.33 10.09-98 When eth16i_open() was called after | ||
117 | eth16i_close() chip never recovered. | ||
118 | Now more shallow reset is made on | ||
119 | close. | ||
120 | |||
121 | 0.34 29.06-99 Fixed one bad #ifdef. | ||
122 | Changed ioaddr -> io for consistency | ||
123 | |||
124 | 0.35 01.07-99 transmit,-receive bytes were never | ||
125 | updated in stats. | ||
126 | |||
127 | Bugs: | ||
128 | In some cases the media interface autoprobing code doesn't find | ||
129 | the correct interface type. In this case you can | ||
130 | manually choose the interface type in DOS with E16IC.EXE which is | ||
131 | configuration software for EtherTeam16i and EtherTeam32 cards. | ||
132 | This is also true for IRQ setting. You cannot use module | ||
133 | parameter to configure IRQ of the card (yet). | ||
134 | |||
135 | To do: | ||
136 | - Real multicast support | ||
137 | - Rewrite the media interface autoprobing code. Its _horrible_ ! | ||
138 | - Possibly merge all the MB86965 specific code to external | ||
139 | module for use by eth16.c and Donald's at1700.c | ||
140 | - IRQ configuration with module parameter. I will do | ||
141 | this when i will get enough info about setting | ||
142 | irq without configuration utility. | ||
143 | */ | ||
144 | |||
145 | static char *version = | ||
146 | "eth16i.c: v0.35 01-Jul-1999 Mika Kuoppala (miku@iki.fi)\n"; | ||
147 | |||
148 | #include <linux/module.h> | ||
149 | #include <linux/kernel.h> | ||
150 | #include <linux/types.h> | ||
151 | #include <linux/fcntl.h> | ||
152 | #include <linux/interrupt.h> | ||
153 | #include <linux/ioport.h> | ||
154 | #include <linux/in.h> | ||
155 | #include <linux/string.h> | ||
156 | #include <linux/errno.h> | ||
157 | #include <linux/init.h> | ||
158 | #include <linux/spinlock.h> | ||
159 | #include <linux/netdevice.h> | ||
160 | #include <linux/etherdevice.h> | ||
161 | #include <linux/skbuff.h> | ||
162 | #include <linux/bitops.h> | ||
163 | #include <linux/jiffies.h> | ||
164 | #include <linux/io.h> | ||
165 | |||
166 | #include <asm/system.h> | ||
167 | #include <asm/dma.h> | ||
168 | |||
169 | |||
170 | |||
171 | /* Few macros */ | ||
172 | #define BITSET(ioaddr, bnum) ((outb(((inb(ioaddr)) | (bnum)), ioaddr))) | ||
173 | #define BITCLR(ioaddr, bnum) ((outb(((inb(ioaddr)) & (~(bnum))), ioaddr))) | ||
174 | |||
175 | /* This is the I/O address space for Etherteam 16i adapter. */ | ||
176 | #define ETH16I_IO_EXTENT 32 | ||
177 | |||
178 | /* Ticks before deciding that transmit has timed out */ | ||
179 | #define TX_TIMEOUT (400*HZ/1000) | ||
180 | |||
181 | /* Maximum loop count when receiving packets */ | ||
182 | #define MAX_RX_LOOP 20 | ||
183 | |||
184 | /* Some interrupt masks */ | ||
185 | #define ETH16I_INTR_ON 0xef8a /* Higher is receive mask */ | ||
186 | #define ETH16I_INTR_OFF 0x0000 | ||
187 | |||
188 | /* Buffers header status byte meanings */ | ||
189 | #define PKT_GOOD BIT(5) | ||
190 | #define PKT_GOOD_RMT BIT(4) | ||
191 | #define PKT_SHORT BIT(3) | ||
192 | #define PKT_ALIGN_ERR BIT(2) | ||
193 | #define PKT_CRC_ERR BIT(1) | ||
194 | #define PKT_RX_BUF_OVERFLOW BIT(0) | ||
195 | |||
196 | /* Transmit status register (DLCR0) */ | ||
197 | #define TX_STATUS_REG 0 | ||
198 | #define TX_DONE BIT(7) | ||
199 | #define NET_BUSY BIT(6) | ||
200 | #define TX_PKT_RCD BIT(5) | ||
201 | #define CR_LOST BIT(4) | ||
202 | #define TX_JABBER_ERR BIT(3) | ||
203 | #define COLLISION BIT(2) | ||
204 | #define COLLISIONS_16 BIT(1) | ||
205 | |||
206 | /* Receive status register (DLCR1) */ | ||
207 | #define RX_STATUS_REG 1 | ||
208 | #define RX_PKT BIT(7) /* Packet received */ | ||
209 | #define BUS_RD_ERR BIT(6) | ||
210 | #define SHORT_PKT_ERR BIT(3) | ||
211 | #define ALIGN_ERR BIT(2) | ||
212 | #define CRC_ERR BIT(1) | ||
213 | #define RX_BUF_OVERFLOW BIT(0) | ||
214 | |||
215 | /* Transmit Interrupt Enable Register (DLCR2) */ | ||
216 | #define TX_INTR_REG 2 | ||
217 | #define TX_INTR_DONE BIT(7) | ||
218 | #define TX_INTR_COL BIT(2) | ||
219 | #define TX_INTR_16_COL BIT(1) | ||
220 | |||
221 | /* Receive Interrupt Enable Register (DLCR3) */ | ||
222 | #define RX_INTR_REG 3 | ||
223 | #define RX_INTR_RECEIVE BIT(7) | ||
224 | #define RX_INTR_SHORT_PKT BIT(3) | ||
225 | #define RX_INTR_CRC_ERR BIT(1) | ||
226 | #define RX_INTR_BUF_OVERFLOW BIT(0) | ||
227 | |||
228 | /* Transmit Mode Register (DLCR4) */ | ||
229 | #define TRANSMIT_MODE_REG 4 | ||
230 | #define LOOPBACK_CONTROL BIT(1) | ||
231 | #define CONTROL_OUTPUT BIT(2) | ||
232 | |||
233 | /* Receive Mode Register (DLCR5) */ | ||
234 | #define RECEIVE_MODE_REG 5 | ||
235 | #define RX_BUFFER_EMPTY BIT(6) | ||
236 | #define ACCEPT_BAD_PACKETS BIT(5) | ||
237 | #define RECEIVE_SHORT_ADDR BIT(4) | ||
238 | #define ACCEPT_SHORT_PACKETS BIT(3) | ||
239 | #define REMOTE_RESET BIT(2) | ||
240 | |||
241 | #define ADDRESS_FILTER_MODE BIT(1) | BIT(0) | ||
242 | #define REJECT_ALL 0 | ||
243 | #define ACCEPT_ALL 3 | ||
244 | #define MODE_1 1 /* NODE ID, BC, MC, 2-24th bit */ | ||
245 | #define MODE_2 2 /* NODE ID, BC, MC, Hash Table */ | ||
246 | |||
247 | /* Configuration Register 0 (DLCR6) */ | ||
248 | #define CONFIG_REG_0 6 | ||
249 | #define DLC_EN BIT(7) | ||
250 | #define SRAM_CYCLE_TIME_100NS BIT(6) | ||
251 | #define SYSTEM_BUS_WIDTH_8 BIT(5) /* 1 = 8bit, 0 = 16bit */ | ||
252 | #define BUFFER_WIDTH_8 BIT(4) /* 1 = 8bit, 0 = 16bit */ | ||
253 | #define TBS1 BIT(3) | ||
254 | #define TBS0 BIT(2) | ||
255 | #define SRAM_BS1 BIT(1) /* 00=8kb, 01=16kb */ | ||
256 | #define SRAM_BS0 BIT(0) /* 10=32kb, 11=64kb */ | ||
257 | |||
258 | #ifndef ETH16I_TX_BUF_SIZE /* 0 = 2kb, 1 = 4kb */ | ||
259 | #define ETH16I_TX_BUF_SIZE 3 /* 2 = 8kb, 3 = 16kb */ | ||
260 | #endif | ||
261 | #define TX_BUF_1x2048 0 | ||
262 | #define TX_BUF_2x2048 1 | ||
263 | #define TX_BUF_2x4098 2 | ||
264 | #define TX_BUF_2x8192 3 | ||
265 | |||
266 | /* Configuration Register 1 (DLCR7) */ | ||
267 | #define CONFIG_REG_1 7 | ||
268 | #define POWERUP BIT(5) | ||
269 | |||
270 | /* Transmit start register */ | ||
271 | #define TRANSMIT_START_REG 10 | ||
272 | #define TRANSMIT_START_RB 2 | ||
273 | #define TX_START BIT(7) /* Rest of register bit indicate*/ | ||
274 | /* number of packets in tx buffer*/ | ||
275 | /* Node ID registers (DLCR8-13) */ | ||
276 | #define NODE_ID_0 8 | ||
277 | #define NODE_ID_RB 0 | ||
278 | |||
279 | /* Hash Table registers (HT8-15) */ | ||
280 | #define HASH_TABLE_0 8 | ||
281 | #define HASH_TABLE_RB 1 | ||
282 | |||
283 | /* Buffer memory ports */ | ||
284 | #define BUFFER_MEM_PORT_LB 8 | ||
285 | #define DATAPORT BUFFER_MEM_PORT_LB | ||
286 | #define BUFFER_MEM_PORT_HB 9 | ||
287 | |||
288 | /* 16 Collision control register (BMPR11) */ | ||
289 | #define COL_16_REG 11 | ||
290 | #define HALT_ON_16 0x00 | ||
291 | #define RETRANS_AND_HALT_ON_16 0x02 | ||
292 | |||
293 | /* Maximum number of attempts to send after 16 concecutive collisions */ | ||
294 | #define MAX_COL_16 10 | ||
295 | |||
296 | /* DMA Burst and Transceiver Mode Register (BMPR13) */ | ||
297 | #define TRANSCEIVER_MODE_REG 13 | ||
298 | #define TRANSCEIVER_MODE_RB 2 | ||
299 | #define IO_BASE_UNLOCK BIT(7) | ||
300 | #define LOWER_SQUELCH_TRESH BIT(6) | ||
301 | #define LINK_TEST_DISABLE BIT(5) | ||
302 | #define AUI_SELECT BIT(4) | ||
303 | #define DIS_AUTO_PORT_SEL BIT(3) | ||
304 | |||
305 | /* Filter Self Receive Register (BMPR14) */ | ||
306 | #define FILTER_SELF_RX_REG 14 | ||
307 | #define SKIP_RX_PACKET BIT(2) | ||
308 | #define FILTER_SELF_RECEIVE BIT(0) | ||
309 | |||
310 | /* EEPROM Control Register (BMPR 16) */ | ||
311 | #define EEPROM_CTRL_REG 16 | ||
312 | |||
313 | /* EEPROM Data Register (BMPR 17) */ | ||
314 | #define EEPROM_DATA_REG 17 | ||
315 | |||
316 | /* NMC93CSx6 EEPROM Control Bits */ | ||
317 | #define CS_0 0x00 | ||
318 | #define CS_1 0x20 | ||
319 | #define SK_0 0x00 | ||
320 | #define SK_1 0x40 | ||
321 | #define DI_0 0x00 | ||
322 | #define DI_1 0x80 | ||
323 | |||
324 | /* NMC93CSx6 EEPROM Instructions */ | ||
325 | #define EEPROM_READ 0x80 | ||
326 | |||
327 | /* NMC93CSx6 EEPROM Addresses */ | ||
328 | #define E_NODEID_0 0x02 | ||
329 | #define E_NODEID_1 0x03 | ||
330 | #define E_NODEID_2 0x04 | ||
331 | #define E_PORT_SELECT 0x14 | ||
332 | #define E_PORT_BNC 0x00 | ||
333 | #define E_PORT_DIX 0x01 | ||
334 | #define E_PORT_TP 0x02 | ||
335 | #define E_PORT_AUTO 0x03 | ||
336 | #define E_PORT_FROM_EPROM 0x04 | ||
337 | #define E_PRODUCT_CFG 0x30 | ||
338 | |||
339 | |||
340 | /* Macro to slow down io between EEPROM clock transitions */ | ||
341 | #define eeprom_slow_io() do { int _i = 40; while(--_i > 0) { inb(0x80); }}while(0) | ||
342 | |||
343 | /* Jumperless Configuration Register (BMPR19) */ | ||
344 | #define JUMPERLESS_CONFIG 19 | ||
345 | |||
346 | /* ID ROM registers, writing to them also resets some parts of chip */ | ||
347 | #define ID_ROM_0 24 | ||
348 | #define ID_ROM_7 31 | ||
349 | #define RESET ID_ROM_0 | ||
350 | |||
351 | /* This is the I/O address list to be probed when seeking the card */ | ||
352 | static unsigned int eth16i_portlist[] __initdata = { | ||
353 | 0x260, 0x280, 0x2A0, 0x240, 0x340, 0x320, 0x380, 0x300, 0 | ||
354 | }; | ||
355 | |||
356 | static unsigned int eth32i_portlist[] __initdata = { | ||
357 | 0x1000, 0x2000, 0x3000, 0x4000, 0x5000, 0x6000, 0x7000, 0x8000, | ||
358 | 0x9000, 0xA000, 0xB000, 0xC000, 0xD000, 0xE000, 0xF000, 0 | ||
359 | }; | ||
360 | |||
361 | /* This is the Interrupt lookup table for Eth16i card */ | ||
362 | static unsigned int eth16i_irqmap[] __initdata = { 9, 10, 5, 15, 0 }; | ||
363 | #define NUM_OF_ISA_IRQS 4 | ||
364 | |||
365 | /* This is the Interrupt lookup table for Eth32i card */ | ||
366 | static unsigned int eth32i_irqmap[] __initdata = { 3, 5, 7, 9, 10, 11, 12, 15, 0 }; | ||
367 | #define EISA_IRQ_REG 0xc89 | ||
368 | #define NUM_OF_EISA_IRQS 8 | ||
369 | |||
370 | static unsigned int eth16i_tx_buf_map[] = { 2048, 2048, 4096, 8192 }; | ||
371 | |||
372 | /* Use 0 for production, 1 for verification, >2 for debug */ | ||
373 | #ifndef ETH16I_DEBUG | ||
374 | #define ETH16I_DEBUG 0 | ||
375 | #endif | ||
376 | static unsigned int eth16i_debug = ETH16I_DEBUG; | ||
377 | |||
378 | /* Information for each board */ | ||
379 | |||
380 | struct eth16i_local { | ||
381 | unsigned char tx_started; | ||
382 | unsigned char tx_buf_busy; | ||
383 | unsigned short tx_queue; /* Number of packets in transmit buffer */ | ||
384 | unsigned short tx_queue_len; | ||
385 | unsigned int tx_buf_size; | ||
386 | unsigned long open_time; | ||
387 | unsigned long tx_buffered_packets; | ||
388 | unsigned long tx_buffered_bytes; | ||
389 | unsigned long col_16; | ||
390 | spinlock_t lock; | ||
391 | }; | ||
392 | |||
393 | /* Function prototypes */ | ||
394 | |||
395 | static int eth16i_probe1(struct net_device *dev, int ioaddr); | ||
396 | static int eth16i_check_signature(int ioaddr); | ||
397 | static int eth16i_probe_port(int ioaddr); | ||
398 | static void eth16i_set_port(int ioaddr, int porttype); | ||
399 | static int eth16i_send_probe_packet(int ioaddr, unsigned char *b, int l); | ||
400 | static int eth16i_receive_probe_packet(int ioaddr); | ||
401 | static int eth16i_get_irq(int ioaddr); | ||
402 | static int eth16i_read_eeprom(int ioaddr, int offset); | ||
403 | static int eth16i_read_eeprom_word(int ioaddr); | ||
404 | static void eth16i_eeprom_cmd(int ioaddr, unsigned char command); | ||
405 | static int eth16i_open(struct net_device *dev); | ||
406 | static int eth16i_close(struct net_device *dev); | ||
407 | static netdev_tx_t eth16i_tx(struct sk_buff *skb, struct net_device *dev); | ||
408 | static void eth16i_rx(struct net_device *dev); | ||
409 | static void eth16i_timeout(struct net_device *dev); | ||
410 | static irqreturn_t eth16i_interrupt(int irq, void *dev_id); | ||
411 | static void eth16i_reset(struct net_device *dev); | ||
412 | static void eth16i_timeout(struct net_device *dev); | ||
413 | static void eth16i_skip_packet(struct net_device *dev); | ||
414 | static void eth16i_multicast(struct net_device *dev); | ||
415 | static void eth16i_select_regbank(unsigned char regbank, int ioaddr); | ||
416 | static void eth16i_initialize(struct net_device *dev, int boot); | ||
417 | |||
418 | #if 0 | ||
419 | static int eth16i_set_irq(struct net_device *dev); | ||
420 | #endif | ||
421 | |||
422 | #ifdef MODULE | ||
423 | static ushort eth16i_parse_mediatype(const char* s); | ||
424 | #endif | ||
425 | |||
426 | static char cardname[] __initdata = "ICL EtherTeam 16i/32"; | ||
427 | |||
428 | static int __init do_eth16i_probe(struct net_device *dev) | ||
429 | { | ||
430 | int i; | ||
431 | int ioaddr; | ||
432 | int base_addr = dev->base_addr; | ||
433 | |||
434 | if(eth16i_debug > 4) | ||
435 | printk(KERN_DEBUG "Probing started for %s\n", cardname); | ||
436 | |||
437 | if(base_addr > 0x1ff) /* Check only single location */ | ||
438 | return eth16i_probe1(dev, base_addr); | ||
439 | else if(base_addr != 0) /* Don't probe at all */ | ||
440 | return -ENXIO; | ||
441 | |||
442 | /* Seek card from the ISA io address space */ | ||
443 | for(i = 0; (ioaddr = eth16i_portlist[i]) ; i++) | ||
444 | if(eth16i_probe1(dev, ioaddr) == 0) | ||
445 | return 0; | ||
446 | |||
447 | /* Seek card from the EISA io address space */ | ||
448 | for(i = 0; (ioaddr = eth32i_portlist[i]) ; i++) | ||
449 | if(eth16i_probe1(dev, ioaddr) == 0) | ||
450 | return 0; | ||
451 | |||
452 | return -ENODEV; | ||
453 | } | ||
454 | |||
455 | #ifndef MODULE | ||
456 | struct net_device * __init eth16i_probe(int unit) | ||
457 | { | ||
458 | struct net_device *dev = alloc_etherdev(sizeof(struct eth16i_local)); | ||
459 | int err; | ||
460 | |||
461 | if (!dev) | ||
462 | return ERR_PTR(-ENOMEM); | ||
463 | |||
464 | sprintf(dev->name, "eth%d", unit); | ||
465 | netdev_boot_setup_check(dev); | ||
466 | |||
467 | err = do_eth16i_probe(dev); | ||
468 | if (err) | ||
469 | goto out; | ||
470 | return dev; | ||
471 | out: | ||
472 | free_netdev(dev); | ||
473 | return ERR_PTR(err); | ||
474 | } | ||
475 | #endif | ||
476 | |||
477 | static const struct net_device_ops eth16i_netdev_ops = { | ||
478 | .ndo_open = eth16i_open, | ||
479 | .ndo_stop = eth16i_close, | ||
480 | .ndo_start_xmit = eth16i_tx, | ||
481 | .ndo_set_multicast_list = eth16i_multicast, | ||
482 | .ndo_tx_timeout = eth16i_timeout, | ||
483 | .ndo_change_mtu = eth_change_mtu, | ||
484 | .ndo_set_mac_address = eth_mac_addr, | ||
485 | .ndo_validate_addr = eth_validate_addr, | ||
486 | }; | ||
487 | |||
488 | static int __init eth16i_probe1(struct net_device *dev, int ioaddr) | ||
489 | { | ||
490 | struct eth16i_local *lp = netdev_priv(dev); | ||
491 | static unsigned version_printed; | ||
492 | int retval; | ||
493 | |||
494 | /* Let's grab the region */ | ||
495 | if (!request_region(ioaddr, ETH16I_IO_EXTENT, cardname)) | ||
496 | return -EBUSY; | ||
497 | |||
498 | /* | ||
499 | The MB86985 chip has on register which holds information in which | ||
500 | io address the chip lies. First read this register and compare | ||
501 | it to our current io address and if match then this could | ||
502 | be our chip. | ||
503 | */ | ||
504 | |||
505 | if(ioaddr < 0x1000) { | ||
506 | if(eth16i_portlist[(inb(ioaddr + JUMPERLESS_CONFIG) & 0x07)] | ||
507 | != ioaddr) { | ||
508 | retval = -ENODEV; | ||
509 | goto out; | ||
510 | } | ||
511 | } | ||
512 | |||
513 | /* Now we will go a bit deeper and try to find the chip's signature */ | ||
514 | |||
515 | if(eth16i_check_signature(ioaddr) != 0) { | ||
516 | retval = -ENODEV; | ||
517 | goto out; | ||
518 | } | ||
519 | |||
520 | /* | ||
521 | Now it seems that we have found a ethernet chip in this particular | ||
522 | ioaddr. The MB86985 chip has this feature, that when you read a | ||
523 | certain register it will increase it's io base address to next | ||
524 | configurable slot. Now when we have found the chip, first thing is | ||
525 | to make sure that the chip's ioaddr will hold still here. | ||
526 | */ | ||
527 | |||
528 | eth16i_select_regbank(TRANSCEIVER_MODE_RB, ioaddr); | ||
529 | outb(0x00, ioaddr + TRANSCEIVER_MODE_REG); | ||
530 | |||
531 | outb(0x00, ioaddr + RESET); /* Reset some parts of chip */ | ||
532 | BITSET(ioaddr + CONFIG_REG_0, BIT(7)); /* Disable the data link */ | ||
533 | |||
534 | if( (eth16i_debug & version_printed++) == 0) | ||
535 | printk(KERN_INFO "%s", version); | ||
536 | |||
537 | dev->base_addr = ioaddr; | ||
538 | dev->irq = eth16i_get_irq(ioaddr); | ||
539 | |||
540 | /* Try to obtain interrupt vector */ | ||
541 | |||
542 | if ((retval = request_irq(dev->irq, (void *)ð16i_interrupt, 0, cardname, dev))) { | ||
543 | printk(KERN_WARNING "%s at %#3x, but is unusable due to conflicting IRQ %d.\n", | ||
544 | cardname, ioaddr, dev->irq); | ||
545 | goto out; | ||
546 | } | ||
547 | |||
548 | printk(KERN_INFO "%s: %s at %#3x, IRQ %d, ", | ||
549 | dev->name, cardname, ioaddr, dev->irq); | ||
550 | |||
551 | |||
552 | /* Now we will have to lock the chip's io address */ | ||
553 | eth16i_select_regbank(TRANSCEIVER_MODE_RB, ioaddr); | ||
554 | outb(0x38, ioaddr + TRANSCEIVER_MODE_REG); | ||
555 | |||
556 | eth16i_initialize(dev, 1); /* Initialize rest of the chip's registers */ | ||
557 | |||
558 | /* Now let's same some energy by shutting down the chip ;) */ | ||
559 | BITCLR(ioaddr + CONFIG_REG_1, POWERUP); | ||
560 | |||
561 | /* Initialize the device structure */ | ||
562 | dev->netdev_ops = ð16i_netdev_ops; | ||
563 | dev->watchdog_timeo = TX_TIMEOUT; | ||
564 | spin_lock_init(&lp->lock); | ||
565 | |||
566 | retval = register_netdev(dev); | ||
567 | if (retval) | ||
568 | goto out1; | ||
569 | return 0; | ||
570 | out1: | ||
571 | free_irq(dev->irq, dev); | ||
572 | out: | ||
573 | release_region(ioaddr, ETH16I_IO_EXTENT); | ||
574 | return retval; | ||
575 | } | ||
576 | |||
577 | |||
578 | static void eth16i_initialize(struct net_device *dev, int boot) | ||
579 | { | ||
580 | int ioaddr = dev->base_addr; | ||
581 | int i, node_w = 0; | ||
582 | unsigned char node_byte = 0; | ||
583 | |||
584 | /* Setup station address */ | ||
585 | eth16i_select_regbank(NODE_ID_RB, ioaddr); | ||
586 | for(i = 0 ; i < 3 ; i++) { | ||
587 | unsigned short node_val = eth16i_read_eeprom(ioaddr, E_NODEID_0 + i); | ||
588 | ((unsigned short *)dev->dev_addr)[i] = ntohs(node_val); | ||
589 | } | ||
590 | |||
591 | for(i = 0; i < 6; i++) { | ||
592 | outb( ((unsigned char *)dev->dev_addr)[i], ioaddr + NODE_ID_0 + i); | ||
593 | if(boot) { | ||
594 | printk("%02x", inb(ioaddr + NODE_ID_0 + i)); | ||
595 | if(i != 5) | ||
596 | printk(":"); | ||
597 | } | ||
598 | } | ||
599 | |||
600 | /* Now we will set multicast addresses to accept none */ | ||
601 | eth16i_select_regbank(HASH_TABLE_RB, ioaddr); | ||
602 | for(i = 0; i < 8; i++) | ||
603 | outb(0x00, ioaddr + HASH_TABLE_0 + i); | ||
604 | |||
605 | /* | ||
606 | Now let's disable the transmitter and receiver, set the buffer ram | ||
607 | cycle time, bus width and buffer data path width. Also we shall | ||
608 | set transmit buffer size and total buffer size. | ||
609 | */ | ||
610 | |||
611 | eth16i_select_regbank(2, ioaddr); | ||
612 | |||
613 | node_byte = 0; | ||
614 | node_w = eth16i_read_eeprom(ioaddr, E_PRODUCT_CFG); | ||
615 | |||
616 | if( (node_w & 0xFF00) == 0x0800) | ||
617 | node_byte |= BUFFER_WIDTH_8; | ||
618 | |||
619 | node_byte |= SRAM_BS1; | ||
620 | |||
621 | if( (node_w & 0x00FF) == 64) | ||
622 | node_byte |= SRAM_BS0; | ||
623 | |||
624 | node_byte |= DLC_EN | SRAM_CYCLE_TIME_100NS | (ETH16I_TX_BUF_SIZE << 2); | ||
625 | |||
626 | outb(node_byte, ioaddr + CONFIG_REG_0); | ||
627 | |||
628 | /* We shall halt the transmitting, if 16 collisions are detected */ | ||
629 | outb(HALT_ON_16, ioaddr + COL_16_REG); | ||
630 | |||
631 | #ifdef MODULE | ||
632 | /* if_port already set by init_module() */ | ||
633 | #else | ||
634 | dev->if_port = (dev->mem_start < E_PORT_FROM_EPROM) ? | ||
635 | dev->mem_start : E_PORT_FROM_EPROM; | ||
636 | #endif | ||
637 | |||
638 | /* Set interface port type */ | ||
639 | if(boot) { | ||
640 | static const char * const porttype[] = { | ||
641 | "BNC", "DIX", "TP", "AUTO", "FROM_EPROM" | ||
642 | }; | ||
643 | |||
644 | switch(dev->if_port) | ||
645 | { | ||
646 | |||
647 | case E_PORT_FROM_EPROM: | ||
648 | dev->if_port = eth16i_read_eeprom(ioaddr, E_PORT_SELECT); | ||
649 | break; | ||
650 | |||
651 | case E_PORT_AUTO: | ||
652 | dev->if_port = eth16i_probe_port(ioaddr); | ||
653 | break; | ||
654 | |||
655 | case E_PORT_BNC: | ||
656 | case E_PORT_TP: | ||
657 | case E_PORT_DIX: | ||
658 | break; | ||
659 | } | ||
660 | |||
661 | printk(" %s interface.\n", porttype[dev->if_port]); | ||
662 | |||
663 | eth16i_set_port(ioaddr, dev->if_port); | ||
664 | } | ||
665 | |||
666 | /* Set Receive Mode to normal operation */ | ||
667 | outb(MODE_2, ioaddr + RECEIVE_MODE_REG); | ||
668 | } | ||
669 | |||
670 | static int eth16i_probe_port(int ioaddr) | ||
671 | { | ||
672 | int i; | ||
673 | int retcode; | ||
674 | unsigned char dummy_packet[64]; | ||
675 | |||
676 | /* Powerup the chip */ | ||
677 | outb(0xc0 | POWERUP, ioaddr + CONFIG_REG_1); | ||
678 | |||
679 | BITSET(ioaddr + CONFIG_REG_0, DLC_EN); | ||
680 | |||
681 | eth16i_select_regbank(NODE_ID_RB, ioaddr); | ||
682 | |||
683 | for(i = 0; i < 6; i++) { | ||
684 | dummy_packet[i] = inb(ioaddr + NODE_ID_0 + i); | ||
685 | dummy_packet[i+6] = inb(ioaddr + NODE_ID_0 + i); | ||
686 | } | ||
687 | |||
688 | dummy_packet[12] = 0x00; | ||
689 | dummy_packet[13] = 0x04; | ||
690 | memset(dummy_packet + 14, 0, sizeof(dummy_packet) - 14); | ||
691 | |||
692 | eth16i_select_regbank(2, ioaddr); | ||
693 | |||
694 | for(i = 0; i < 3; i++) { | ||
695 | BITSET(ioaddr + CONFIG_REG_0, DLC_EN); | ||
696 | BITCLR(ioaddr + CONFIG_REG_0, DLC_EN); | ||
697 | eth16i_set_port(ioaddr, i); | ||
698 | |||
699 | if(eth16i_debug > 1) | ||
700 | printk(KERN_DEBUG "Set port number %d\n", i); | ||
701 | |||
702 | retcode = eth16i_send_probe_packet(ioaddr, dummy_packet, 64); | ||
703 | if(retcode == 0) { | ||
704 | retcode = eth16i_receive_probe_packet(ioaddr); | ||
705 | if(retcode != -1) { | ||
706 | if(eth16i_debug > 1) | ||
707 | printk(KERN_DEBUG "Eth16i interface port found at %d\n", i); | ||
708 | return i; | ||
709 | } | ||
710 | } | ||
711 | else { | ||
712 | if(eth16i_debug > 1) | ||
713 | printk(KERN_DEBUG "TRANSMIT_DONE timeout when probing interface port\n"); | ||
714 | } | ||
715 | } | ||
716 | |||
717 | if( eth16i_debug > 1) | ||
718 | printk(KERN_DEBUG "Using default port\n"); | ||
719 | |||
720 | return E_PORT_BNC; | ||
721 | } | ||
722 | |||
723 | static void eth16i_set_port(int ioaddr, int porttype) | ||
724 | { | ||
725 | unsigned short temp = 0; | ||
726 | |||
727 | eth16i_select_regbank(TRANSCEIVER_MODE_RB, ioaddr); | ||
728 | outb(LOOPBACK_CONTROL, ioaddr + TRANSMIT_MODE_REG); | ||
729 | |||
730 | temp |= DIS_AUTO_PORT_SEL; | ||
731 | |||
732 | switch(porttype) { | ||
733 | |||
734 | case E_PORT_BNC : | ||
735 | temp |= AUI_SELECT; | ||
736 | break; | ||
737 | |||
738 | case E_PORT_TP : | ||
739 | break; | ||
740 | |||
741 | case E_PORT_DIX : | ||
742 | temp |= AUI_SELECT; | ||
743 | BITSET(ioaddr + TRANSMIT_MODE_REG, CONTROL_OUTPUT); | ||
744 | break; | ||
745 | } | ||
746 | |||
747 | outb(temp, ioaddr + TRANSCEIVER_MODE_REG); | ||
748 | |||
749 | if(eth16i_debug > 1) { | ||
750 | printk(KERN_DEBUG "TRANSMIT_MODE_REG = %x\n", inb(ioaddr + TRANSMIT_MODE_REG)); | ||
751 | printk(KERN_DEBUG "TRANSCEIVER_MODE_REG = %x\n", | ||
752 | inb(ioaddr+TRANSCEIVER_MODE_REG)); | ||
753 | } | ||
754 | } | ||
755 | |||
756 | static int eth16i_send_probe_packet(int ioaddr, unsigned char *b, int l) | ||
757 | { | ||
758 | unsigned long starttime; | ||
759 | |||
760 | outb(0xff, ioaddr + TX_STATUS_REG); | ||
761 | |||
762 | outw(l, ioaddr + DATAPORT); | ||
763 | outsw(ioaddr + DATAPORT, (unsigned short *)b, (l + 1) >> 1); | ||
764 | |||
765 | starttime = jiffies; | ||
766 | outb(TX_START | 1, ioaddr + TRANSMIT_START_REG); | ||
767 | |||
768 | while( (inb(ioaddr + TX_STATUS_REG) & 0x80) == 0) { | ||
769 | if( time_after(jiffies, starttime + TX_TIMEOUT)) { | ||
770 | return -1; | ||
771 | } | ||
772 | } | ||
773 | |||
774 | return 0; | ||
775 | } | ||
776 | |||
777 | static int eth16i_receive_probe_packet(int ioaddr) | ||
778 | { | ||
779 | unsigned long starttime; | ||
780 | |||
781 | starttime = jiffies; | ||
782 | |||
783 | while((inb(ioaddr + TX_STATUS_REG) & 0x20) == 0) { | ||
784 | if( time_after(jiffies, starttime + TX_TIMEOUT)) { | ||
785 | |||
786 | if(eth16i_debug > 1) | ||
787 | printk(KERN_DEBUG "Timeout occurred waiting transmit packet received\n"); | ||
788 | starttime = jiffies; | ||
789 | while((inb(ioaddr + RX_STATUS_REG) & 0x80) == 0) { | ||
790 | if( time_after(jiffies, starttime + TX_TIMEOUT)) { | ||
791 | if(eth16i_debug > 1) | ||
792 | printk(KERN_DEBUG "Timeout occurred waiting receive packet\n"); | ||
793 | return -1; | ||
794 | } | ||
795 | } | ||
796 | |||
797 | if(eth16i_debug > 1) | ||
798 | printk(KERN_DEBUG "RECEIVE_PACKET\n"); | ||
799 | return 0; /* Found receive packet */ | ||
800 | } | ||
801 | } | ||
802 | |||
803 | if(eth16i_debug > 1) { | ||
804 | printk(KERN_DEBUG "TRANSMIT_PACKET_RECEIVED %x\n", inb(ioaddr + TX_STATUS_REG)); | ||
805 | printk(KERN_DEBUG "RX_STATUS_REG = %x\n", inb(ioaddr + RX_STATUS_REG)); | ||
806 | } | ||
807 | |||
808 | return 0; /* Return success */ | ||
809 | } | ||
810 | |||
811 | #if 0 | ||
812 | static int eth16i_set_irq(struct net_device* dev) | ||
813 | { | ||
814 | const int ioaddr = dev->base_addr; | ||
815 | const int irq = dev->irq; | ||
816 | int i = 0; | ||
817 | |||
818 | if(ioaddr < 0x1000) { | ||
819 | while(eth16i_irqmap[i] && eth16i_irqmap[i] != irq) | ||
820 | i++; | ||
821 | |||
822 | if(i < NUM_OF_ISA_IRQS) { | ||
823 | u8 cbyte = inb(ioaddr + JUMPERLESS_CONFIG); | ||
824 | cbyte = (cbyte & 0x3F) | (i << 6); | ||
825 | outb(cbyte, ioaddr + JUMPERLESS_CONFIG); | ||
826 | return 0; | ||
827 | } | ||
828 | } | ||
829 | else { | ||
830 | printk(KERN_NOTICE "%s: EISA Interrupt cannot be set. Use EISA Configuration utility.\n", dev->name); | ||
831 | } | ||
832 | |||
833 | return -1; | ||
834 | |||
835 | } | ||
836 | #endif | ||
837 | |||
838 | static int __init eth16i_get_irq(int ioaddr) | ||
839 | { | ||
840 | unsigned char cbyte; | ||
841 | |||
842 | if( ioaddr < 0x1000) { | ||
843 | cbyte = inb(ioaddr + JUMPERLESS_CONFIG); | ||
844 | return eth16i_irqmap[((cbyte & 0xC0) >> 6)]; | ||
845 | } else { /* Oh..the card is EISA so method getting IRQ different */ | ||
846 | unsigned short index = 0; | ||
847 | cbyte = inb(ioaddr + EISA_IRQ_REG); | ||
848 | while( (cbyte & 0x01) == 0) { | ||
849 | cbyte = cbyte >> 1; | ||
850 | index++; | ||
851 | } | ||
852 | return eth32i_irqmap[index]; | ||
853 | } | ||
854 | } | ||
855 | |||
856 | static int __init eth16i_check_signature(int ioaddr) | ||
857 | { | ||
858 | int i; | ||
859 | unsigned char creg[4] = { 0 }; | ||
860 | |||
861 | for(i = 0; i < 4 ; i++) { | ||
862 | |||
863 | creg[i] = inb(ioaddr + TRANSMIT_MODE_REG + i); | ||
864 | |||
865 | if(eth16i_debug > 1) | ||
866 | printk("eth16i: read signature byte %x at %x\n", | ||
867 | creg[i], | ||
868 | ioaddr + TRANSMIT_MODE_REG + i); | ||
869 | } | ||
870 | |||
871 | creg[0] &= 0x0F; /* Mask collision cnr */ | ||
872 | creg[2] &= 0x7F; /* Mask DCLEN bit */ | ||
873 | |||
874 | #if 0 | ||
875 | /* | ||
876 | This was removed because the card was sometimes left to state | ||
877 | from which it couldn't be find anymore. If there is need | ||
878 | to more strict check still this have to be fixed. | ||
879 | */ | ||
880 | if( ! ((creg[0] == 0x06) && (creg[1] == 0x41)) ) { | ||
881 | if(creg[1] != 0x42) | ||
882 | return -1; | ||
883 | } | ||
884 | #endif | ||
885 | |||
886 | if( !((creg[2] == 0x36) && (creg[3] == 0xE0)) ) { | ||
887 | creg[2] &= 0x40; | ||
888 | creg[3] &= 0x03; | ||
889 | |||
890 | if( !((creg[2] == 0x40) && (creg[3] == 0x00)) ) | ||
891 | return -1; | ||
892 | } | ||
893 | |||
894 | if(eth16i_read_eeprom(ioaddr, E_NODEID_0) != 0) | ||
895 | return -1; | ||
896 | |||
897 | if((eth16i_read_eeprom(ioaddr, E_NODEID_1) & 0xFF00) != 0x4B00) | ||
898 | return -1; | ||
899 | |||
900 | return 0; | ||
901 | } | ||
902 | |||
903 | static int eth16i_read_eeprom(int ioaddr, int offset) | ||
904 | { | ||
905 | int data = 0; | ||
906 | |||
907 | eth16i_eeprom_cmd(ioaddr, EEPROM_READ | offset); | ||
908 | outb(CS_1, ioaddr + EEPROM_CTRL_REG); | ||
909 | data = eth16i_read_eeprom_word(ioaddr); | ||
910 | outb(CS_0 | SK_0, ioaddr + EEPROM_CTRL_REG); | ||
911 | |||
912 | return data; | ||
913 | } | ||
914 | |||
915 | static int eth16i_read_eeprom_word(int ioaddr) | ||
916 | { | ||
917 | int i; | ||
918 | int data = 0; | ||
919 | |||
920 | for(i = 16; i > 0; i--) { | ||
921 | outb(CS_1 | SK_0, ioaddr + EEPROM_CTRL_REG); | ||
922 | eeprom_slow_io(); | ||
923 | outb(CS_1 | SK_1, ioaddr + EEPROM_CTRL_REG); | ||
924 | eeprom_slow_io(); | ||
925 | data = (data << 1) | | ||
926 | ((inb(ioaddr + EEPROM_DATA_REG) & DI_1) ? 1 : 0); | ||
927 | |||
928 | eeprom_slow_io(); | ||
929 | } | ||
930 | |||
931 | return data; | ||
932 | } | ||
933 | |||
934 | static void eth16i_eeprom_cmd(int ioaddr, unsigned char command) | ||
935 | { | ||
936 | int i; | ||
937 | |||
938 | outb(CS_0 | SK_0, ioaddr + EEPROM_CTRL_REG); | ||
939 | outb(DI_0, ioaddr + EEPROM_DATA_REG); | ||
940 | outb(CS_1 | SK_0, ioaddr + EEPROM_CTRL_REG); | ||
941 | outb(DI_1, ioaddr + EEPROM_DATA_REG); | ||
942 | outb(CS_1 | SK_1, ioaddr + EEPROM_CTRL_REG); | ||
943 | |||
944 | for(i = 7; i >= 0; i--) { | ||
945 | short cmd = ( (command & (1 << i)) ? DI_1 : DI_0 ); | ||
946 | outb(cmd, ioaddr + EEPROM_DATA_REG); | ||
947 | outb(CS_1 | SK_0, ioaddr + EEPROM_CTRL_REG); | ||
948 | eeprom_slow_io(); | ||
949 | outb(CS_1 | SK_1, ioaddr + EEPROM_CTRL_REG); | ||
950 | eeprom_slow_io(); | ||
951 | } | ||
952 | } | ||
953 | |||
954 | static int eth16i_open(struct net_device *dev) | ||
955 | { | ||
956 | struct eth16i_local *lp = netdev_priv(dev); | ||
957 | int ioaddr = dev->base_addr; | ||
958 | |||
959 | /* Powerup the chip */ | ||
960 | outb(0xc0 | POWERUP, ioaddr + CONFIG_REG_1); | ||
961 | |||
962 | /* Initialize the chip */ | ||
963 | eth16i_initialize(dev, 0); | ||
964 | |||
965 | /* Set the transmit buffer size */ | ||
966 | lp->tx_buf_size = eth16i_tx_buf_map[ETH16I_TX_BUF_SIZE & 0x03]; | ||
967 | |||
968 | if(eth16i_debug > 0) | ||
969 | printk(KERN_DEBUG "%s: transmit buffer size %d\n", | ||
970 | dev->name, lp->tx_buf_size); | ||
971 | |||
972 | /* Now enable Transmitter and Receiver sections */ | ||
973 | BITCLR(ioaddr + CONFIG_REG_0, DLC_EN); | ||
974 | |||
975 | /* Now switch to register bank 2, for run time operation */ | ||
976 | eth16i_select_regbank(2, ioaddr); | ||
977 | |||
978 | lp->open_time = jiffies; | ||
979 | lp->tx_started = 0; | ||
980 | lp->tx_queue = 0; | ||
981 | lp->tx_queue_len = 0; | ||
982 | |||
983 | /* Turn on interrupts*/ | ||
984 | outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG); | ||
985 | |||
986 | netif_start_queue(dev); | ||
987 | return 0; | ||
988 | } | ||
989 | |||
990 | static int eth16i_close(struct net_device *dev) | ||
991 | { | ||
992 | struct eth16i_local *lp = netdev_priv(dev); | ||
993 | int ioaddr = dev->base_addr; | ||
994 | |||
995 | eth16i_reset(dev); | ||
996 | |||
997 | /* Turn off interrupts*/ | ||
998 | outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG); | ||
999 | |||
1000 | netif_stop_queue(dev); | ||
1001 | |||
1002 | lp->open_time = 0; | ||
1003 | |||
1004 | /* Disable transmit and receive */ | ||
1005 | BITSET(ioaddr + CONFIG_REG_0, DLC_EN); | ||
1006 | |||
1007 | /* Reset the chip */ | ||
1008 | /* outb(0xff, ioaddr + RESET); */ | ||
1009 | /* outw(0xffff, ioaddr + TX_STATUS_REG); */ | ||
1010 | |||
1011 | outb(0x00, ioaddr + CONFIG_REG_1); | ||
1012 | |||
1013 | return 0; | ||
1014 | } | ||
1015 | |||
1016 | static void eth16i_timeout(struct net_device *dev) | ||
1017 | { | ||
1018 | struct eth16i_local *lp = netdev_priv(dev); | ||
1019 | int ioaddr = dev->base_addr; | ||
1020 | /* | ||
1021 | If we get here, some higher level has decided that | ||
1022 | we are broken. There should really be a "kick me" | ||
1023 | function call instead. | ||
1024 | */ | ||
1025 | |||
1026 | outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG); | ||
1027 | printk(KERN_WARNING "%s: transmit timed out with status %04x, %s ?\n", | ||
1028 | dev->name, | ||
1029 | inw(ioaddr + TX_STATUS_REG), (inb(ioaddr + TX_STATUS_REG) & TX_DONE) ? | ||
1030 | "IRQ conflict" : "network cable problem"); | ||
1031 | |||
1032 | dev->trans_start = jiffies; /* prevent tx timeout */ | ||
1033 | |||
1034 | /* Let's dump all registers */ | ||
1035 | if(eth16i_debug > 0) { | ||
1036 | printk(KERN_DEBUG "%s: timeout: %02x %02x %02x %02x %02x %02x %02x %02x.\n", | ||
1037 | dev->name, inb(ioaddr + 0), | ||
1038 | inb(ioaddr + 1), inb(ioaddr + 2), | ||
1039 | inb(ioaddr + 3), inb(ioaddr + 4), | ||
1040 | inb(ioaddr + 5), | ||
1041 | inb(ioaddr + 6), inb(ioaddr + 7)); | ||
1042 | |||
1043 | printk(KERN_DEBUG "%s: transmit start reg: %02x. collision reg %02x\n", | ||
1044 | dev->name, inb(ioaddr + TRANSMIT_START_REG), | ||
1045 | inb(ioaddr + COL_16_REG)); | ||
1046 | printk(KERN_DEBUG "lp->tx_queue = %d\n", lp->tx_queue); | ||
1047 | printk(KERN_DEBUG "lp->tx_queue_len = %d\n", lp->tx_queue_len); | ||
1048 | printk(KERN_DEBUG "lp->tx_started = %d\n", lp->tx_started); | ||
1049 | } | ||
1050 | dev->stats.tx_errors++; | ||
1051 | eth16i_reset(dev); | ||
1052 | dev->trans_start = jiffies; /* prevent tx timeout */ | ||
1053 | outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG); | ||
1054 | netif_wake_queue(dev); | ||
1055 | } | ||
1056 | |||
1057 | static netdev_tx_t eth16i_tx(struct sk_buff *skb, struct net_device *dev) | ||
1058 | { | ||
1059 | struct eth16i_local *lp = netdev_priv(dev); | ||
1060 | int ioaddr = dev->base_addr; | ||
1061 | int status = 0; | ||
1062 | ushort length = skb->len; | ||
1063 | unsigned char *buf; | ||
1064 | unsigned long flags; | ||
1065 | |||
1066 | if (length < ETH_ZLEN) { | ||
1067 | if (skb_padto(skb, ETH_ZLEN)) | ||
1068 | return NETDEV_TX_OK; | ||
1069 | length = ETH_ZLEN; | ||
1070 | } | ||
1071 | buf = skb->data; | ||
1072 | |||
1073 | netif_stop_queue(dev); | ||
1074 | |||
1075 | /* Turn off TX interrupts */ | ||
1076 | outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG); | ||
1077 | |||
1078 | /* We would be better doing the disable_irq tricks the 3c509 does, | ||
1079 | that would make this suck a lot less */ | ||
1080 | |||
1081 | spin_lock_irqsave(&lp->lock, flags); | ||
1082 | |||
1083 | if( (length + 2) > (lp->tx_buf_size - lp->tx_queue_len)) { | ||
1084 | if(eth16i_debug > 0) | ||
1085 | printk(KERN_WARNING "%s: Transmit buffer full.\n", dev->name); | ||
1086 | } | ||
1087 | else { | ||
1088 | outw(length, ioaddr + DATAPORT); | ||
1089 | |||
1090 | if( ioaddr < 0x1000 ) | ||
1091 | outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1); | ||
1092 | else { | ||
1093 | unsigned char frag = length % 4; | ||
1094 | outsl(ioaddr + DATAPORT, buf, length >> 2); | ||
1095 | if( frag != 0 ) { | ||
1096 | outsw(ioaddr + DATAPORT, (buf + (length & 0xFFFC)), 1); | ||
1097 | if( frag == 3 ) | ||
1098 | outsw(ioaddr + DATAPORT, | ||
1099 | (buf + (length & 0xFFFC) + 2), 1); | ||
1100 | } | ||
1101 | } | ||
1102 | lp->tx_buffered_packets++; | ||
1103 | lp->tx_buffered_bytes = length; | ||
1104 | lp->tx_queue++; | ||
1105 | lp->tx_queue_len += length + 2; | ||
1106 | } | ||
1107 | lp->tx_buf_busy = 0; | ||
1108 | |||
1109 | if(lp->tx_started == 0) { | ||
1110 | /* If the transmitter is idle..always trigger a transmit */ | ||
1111 | outb(TX_START | lp->tx_queue, ioaddr + TRANSMIT_START_REG); | ||
1112 | lp->tx_queue = 0; | ||
1113 | lp->tx_queue_len = 0; | ||
1114 | lp->tx_started = 1; | ||
1115 | netif_wake_queue(dev); | ||
1116 | } | ||
1117 | else if(lp->tx_queue_len < lp->tx_buf_size - (ETH_FRAME_LEN + 2)) { | ||
1118 | /* There is still more room for one more packet in tx buffer */ | ||
1119 | netif_wake_queue(dev); | ||
1120 | } | ||
1121 | |||
1122 | spin_unlock_irqrestore(&lp->lock, flags); | ||
1123 | |||
1124 | outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG); | ||
1125 | /* Turn TX interrupts back on */ | ||
1126 | /* outb(TX_INTR_DONE | TX_INTR_16_COL, ioaddr + TX_INTR_REG); */ | ||
1127 | status = 0; | ||
1128 | dev_kfree_skb(skb); | ||
1129 | return NETDEV_TX_OK; | ||
1130 | } | ||
1131 | |||
1132 | static void eth16i_rx(struct net_device *dev) | ||
1133 | { | ||
1134 | int ioaddr = dev->base_addr; | ||
1135 | int boguscount = MAX_RX_LOOP; | ||
1136 | |||
1137 | /* Loop until all packets have been read */ | ||
1138 | while( (inb(ioaddr + RECEIVE_MODE_REG) & RX_BUFFER_EMPTY) == 0) { | ||
1139 | |||
1140 | /* Read status byte from receive buffer */ | ||
1141 | ushort status = inw(ioaddr + DATAPORT); | ||
1142 | |||
1143 | /* Get the size of the packet from receive buffer */ | ||
1144 | ushort pkt_len = inw(ioaddr + DATAPORT); | ||
1145 | |||
1146 | if(eth16i_debug > 4) | ||
1147 | printk(KERN_DEBUG "%s: Receiving packet mode %02x status %04x.\n", | ||
1148 | dev->name, | ||
1149 | inb(ioaddr + RECEIVE_MODE_REG), status); | ||
1150 | |||
1151 | if( !(status & PKT_GOOD) ) { | ||
1152 | dev->stats.rx_errors++; | ||
1153 | |||
1154 | if( (pkt_len < ETH_ZLEN) || (pkt_len > ETH_FRAME_LEN) ) { | ||
1155 | dev->stats.rx_length_errors++; | ||
1156 | eth16i_reset(dev); | ||
1157 | return; | ||
1158 | } | ||
1159 | else { | ||
1160 | eth16i_skip_packet(dev); | ||
1161 | dev->stats.rx_dropped++; | ||
1162 | } | ||
1163 | } | ||
1164 | else { /* Ok so now we should have a good packet */ | ||
1165 | struct sk_buff *skb; | ||
1166 | |||
1167 | skb = dev_alloc_skb(pkt_len + 3); | ||
1168 | if( skb == NULL ) { | ||
1169 | printk(KERN_WARNING "%s: Could'n allocate memory for packet (len %d)\n", | ||
1170 | dev->name, pkt_len); | ||
1171 | eth16i_skip_packet(dev); | ||
1172 | dev->stats.rx_dropped++; | ||
1173 | break; | ||
1174 | } | ||
1175 | |||
1176 | skb_reserve(skb,2); | ||
1177 | |||
1178 | /* | ||
1179 | Now let's get the packet out of buffer. | ||
1180 | size is (pkt_len + 1) >> 1, cause we are now reading words | ||
1181 | and it have to be even aligned. | ||
1182 | */ | ||
1183 | |||
1184 | if(ioaddr < 0x1000) | ||
1185 | insw(ioaddr + DATAPORT, skb_put(skb, pkt_len), | ||
1186 | (pkt_len + 1) >> 1); | ||
1187 | else { | ||
1188 | unsigned char *buf = skb_put(skb, pkt_len); | ||
1189 | unsigned char frag = pkt_len % 4; | ||
1190 | |||
1191 | insl(ioaddr + DATAPORT, buf, pkt_len >> 2); | ||
1192 | |||
1193 | if(frag != 0) { | ||
1194 | unsigned short rest[2]; | ||
1195 | rest[0] = inw( ioaddr + DATAPORT ); | ||
1196 | if(frag == 3) | ||
1197 | rest[1] = inw( ioaddr + DATAPORT ); | ||
1198 | |||
1199 | memcpy(buf + (pkt_len & 0xfffc), (char *)rest, frag); | ||
1200 | } | ||
1201 | } | ||
1202 | |||
1203 | skb->protocol=eth_type_trans(skb, dev); | ||
1204 | |||
1205 | if( eth16i_debug > 5 ) { | ||
1206 | int i; | ||
1207 | printk(KERN_DEBUG "%s: Received packet of length %d.\n", | ||
1208 | dev->name, pkt_len); | ||
1209 | for(i = 0; i < 14; i++) | ||
1210 | printk(KERN_DEBUG " %02x", skb->data[i]); | ||
1211 | printk(KERN_DEBUG ".\n"); | ||
1212 | } | ||
1213 | netif_rx(skb); | ||
1214 | dev->stats.rx_packets++; | ||
1215 | dev->stats.rx_bytes += pkt_len; | ||
1216 | |||
1217 | } /* else */ | ||
1218 | |||
1219 | if(--boguscount <= 0) | ||
1220 | break; | ||
1221 | |||
1222 | } /* while */ | ||
1223 | } | ||
1224 | |||
1225 | static irqreturn_t eth16i_interrupt(int irq, void *dev_id) | ||
1226 | { | ||
1227 | struct net_device *dev = dev_id; | ||
1228 | struct eth16i_local *lp; | ||
1229 | int ioaddr = 0, status; | ||
1230 | int handled = 0; | ||
1231 | |||
1232 | ioaddr = dev->base_addr; | ||
1233 | lp = netdev_priv(dev); | ||
1234 | |||
1235 | /* Turn off all interrupts from adapter */ | ||
1236 | outw(ETH16I_INTR_OFF, ioaddr + TX_INTR_REG); | ||
1237 | |||
1238 | /* eth16i_tx won't be called */ | ||
1239 | spin_lock(&lp->lock); | ||
1240 | |||
1241 | status = inw(ioaddr + TX_STATUS_REG); /* Get the status */ | ||
1242 | outw(status, ioaddr + TX_STATUS_REG); /* Clear status bits */ | ||
1243 | |||
1244 | if (status) | ||
1245 | handled = 1; | ||
1246 | |||
1247 | if(eth16i_debug > 3) | ||
1248 | printk(KERN_DEBUG "%s: Interrupt with status %04x.\n", dev->name, status); | ||
1249 | |||
1250 | if( status & 0x7f00 ) { | ||
1251 | |||
1252 | dev->stats.rx_errors++; | ||
1253 | |||
1254 | if(status & (BUS_RD_ERR << 8) ) | ||
1255 | printk(KERN_WARNING "%s: Bus read error.\n",dev->name); | ||
1256 | if(status & (SHORT_PKT_ERR << 8) ) dev->stats.rx_length_errors++; | ||
1257 | if(status & (ALIGN_ERR << 8) ) dev->stats.rx_frame_errors++; | ||
1258 | if(status & (CRC_ERR << 8) ) dev->stats.rx_crc_errors++; | ||
1259 | if(status & (RX_BUF_OVERFLOW << 8) ) dev->stats.rx_over_errors++; | ||
1260 | } | ||
1261 | if( status & 0x001a) { | ||
1262 | |||
1263 | dev->stats.tx_errors++; | ||
1264 | |||
1265 | if(status & CR_LOST) dev->stats.tx_carrier_errors++; | ||
1266 | if(status & TX_JABBER_ERR) dev->stats.tx_window_errors++; | ||
1267 | |||
1268 | #if 0 | ||
1269 | if(status & COLLISION) { | ||
1270 | dev->stats.collisions += | ||
1271 | ((inb(ioaddr+TRANSMIT_MODE_REG) & 0xF0) >> 4); | ||
1272 | } | ||
1273 | #endif | ||
1274 | if(status & COLLISIONS_16) { | ||
1275 | if(lp->col_16 < MAX_COL_16) { | ||
1276 | lp->col_16++; | ||
1277 | dev->stats.collisions++; | ||
1278 | /* Resume transmitting, skip failed packet */ | ||
1279 | outb(0x02, ioaddr + COL_16_REG); | ||
1280 | } | ||
1281 | else { | ||
1282 | printk(KERN_WARNING "%s: bailing out due to many consecutive 16-in-a-row collisions. Network cable problem?\n", dev->name); | ||
1283 | } | ||
1284 | } | ||
1285 | } | ||
1286 | |||
1287 | if( status & 0x00ff ) { /* Let's check the transmit status reg */ | ||
1288 | |||
1289 | if(status & TX_DONE) { /* The transmit has been done */ | ||
1290 | dev->stats.tx_packets = lp->tx_buffered_packets; | ||
1291 | dev->stats.tx_bytes += lp->tx_buffered_bytes; | ||
1292 | lp->col_16 = 0; | ||
1293 | |||
1294 | if(lp->tx_queue) { /* Is there still packets ? */ | ||
1295 | /* There was packet(s) so start transmitting and write also | ||
1296 | how many packets there is to be sended */ | ||
1297 | outb(TX_START | lp->tx_queue, ioaddr + TRANSMIT_START_REG); | ||
1298 | lp->tx_queue = 0; | ||
1299 | lp->tx_queue_len = 0; | ||
1300 | lp->tx_started = 1; | ||
1301 | } | ||
1302 | else { | ||
1303 | lp->tx_started = 0; | ||
1304 | } | ||
1305 | netif_wake_queue(dev); | ||
1306 | } | ||
1307 | } | ||
1308 | |||
1309 | if( ( status & 0x8000 ) || | ||
1310 | ( (inb(ioaddr + RECEIVE_MODE_REG) & RX_BUFFER_EMPTY) == 0) ) { | ||
1311 | eth16i_rx(dev); /* We have packet in receive buffer */ | ||
1312 | } | ||
1313 | |||
1314 | /* Turn interrupts back on */ | ||
1315 | outw(ETH16I_INTR_ON, ioaddr + TX_INTR_REG); | ||
1316 | |||
1317 | if(lp->tx_queue_len < lp->tx_buf_size - (ETH_FRAME_LEN + 2)) { | ||
1318 | /* There is still more room for one more packet in tx buffer */ | ||
1319 | netif_wake_queue(dev); | ||
1320 | } | ||
1321 | |||
1322 | spin_unlock(&lp->lock); | ||
1323 | |||
1324 | return IRQ_RETVAL(handled); | ||
1325 | } | ||
1326 | |||
1327 | static void eth16i_skip_packet(struct net_device *dev) | ||
1328 | { | ||
1329 | int ioaddr = dev->base_addr; | ||
1330 | |||
1331 | inw(ioaddr + DATAPORT); | ||
1332 | inw(ioaddr + DATAPORT); | ||
1333 | inw(ioaddr + DATAPORT); | ||
1334 | |||
1335 | outb(SKIP_RX_PACKET, ioaddr + FILTER_SELF_RX_REG); | ||
1336 | while( inb( ioaddr + FILTER_SELF_RX_REG ) != 0); | ||
1337 | } | ||
1338 | |||
1339 | static void eth16i_reset(struct net_device *dev) | ||
1340 | { | ||
1341 | struct eth16i_local *lp = netdev_priv(dev); | ||
1342 | int ioaddr = dev->base_addr; | ||
1343 | |||
1344 | if(eth16i_debug > 1) | ||
1345 | printk(KERN_DEBUG "%s: Resetting device.\n", dev->name); | ||
1346 | |||
1347 | BITSET(ioaddr + CONFIG_REG_0, DLC_EN); | ||
1348 | outw(0xffff, ioaddr + TX_STATUS_REG); | ||
1349 | eth16i_select_regbank(2, ioaddr); | ||
1350 | |||
1351 | lp->tx_started = 0; | ||
1352 | lp->tx_buf_busy = 0; | ||
1353 | lp->tx_queue = 0; | ||
1354 | lp->tx_queue_len = 0; | ||
1355 | BITCLR(ioaddr + CONFIG_REG_0, DLC_EN); | ||
1356 | } | ||
1357 | |||
1358 | static void eth16i_multicast(struct net_device *dev) | ||
1359 | { | ||
1360 | int ioaddr = dev->base_addr; | ||
1361 | |||
1362 | if (!netdev_mc_empty(dev) || dev->flags&(IFF_ALLMULTI|IFF_PROMISC)) | ||
1363 | { | ||
1364 | outb(3, ioaddr + RECEIVE_MODE_REG); | ||
1365 | } else { | ||
1366 | outb(2, ioaddr + RECEIVE_MODE_REG); | ||
1367 | } | ||
1368 | } | ||
1369 | |||
1370 | static void eth16i_select_regbank(unsigned char banknbr, int ioaddr) | ||
1371 | { | ||
1372 | unsigned char data; | ||
1373 | |||
1374 | data = inb(ioaddr + CONFIG_REG_1); | ||
1375 | outb( ((data & 0xF3) | ( (banknbr & 0x03) << 2)), ioaddr + CONFIG_REG_1); | ||
1376 | } | ||
1377 | |||
1378 | #ifdef MODULE | ||
1379 | |||
1380 | static ushort eth16i_parse_mediatype(const char* s) | ||
1381 | { | ||
1382 | if(!s) | ||
1383 | return E_PORT_FROM_EPROM; | ||
1384 | |||
1385 | if (!strncmp(s, "bnc", 3)) | ||
1386 | return E_PORT_BNC; | ||
1387 | else if (!strncmp(s, "tp", 2)) | ||
1388 | return E_PORT_TP; | ||
1389 | else if (!strncmp(s, "dix", 3)) | ||
1390 | return E_PORT_DIX; | ||
1391 | else if (!strncmp(s, "auto", 4)) | ||
1392 | return E_PORT_AUTO; | ||
1393 | else | ||
1394 | return E_PORT_FROM_EPROM; | ||
1395 | } | ||
1396 | |||
1397 | #define MAX_ETH16I_CARDS 4 /* Max number of Eth16i cards per module */ | ||
1398 | |||
1399 | static struct net_device *dev_eth16i[MAX_ETH16I_CARDS]; | ||
1400 | static int io[MAX_ETH16I_CARDS]; | ||
1401 | #if 0 | ||
1402 | static int irq[MAX_ETH16I_CARDS]; | ||
1403 | #endif | ||
1404 | static char* mediatype[MAX_ETH16I_CARDS]; | ||
1405 | static int debug = -1; | ||
1406 | |||
1407 | MODULE_AUTHOR("Mika Kuoppala <miku@iki.fi>"); | ||
1408 | MODULE_DESCRIPTION("ICL EtherTeam 16i/32 driver"); | ||
1409 | MODULE_LICENSE("GPL"); | ||
1410 | |||
1411 | |||
1412 | module_param_array(io, int, NULL, 0); | ||
1413 | MODULE_PARM_DESC(io, "eth16i I/O base address(es)"); | ||
1414 | |||
1415 | #if 0 | ||
1416 | module_param_array(irq, int, NULL, 0); | ||
1417 | MODULE_PARM_DESC(irq, "eth16i interrupt request number"); | ||
1418 | #endif | ||
1419 | |||
1420 | module_param_array(mediatype, charp, NULL, 0); | ||
1421 | MODULE_PARM_DESC(mediatype, "eth16i media type of interface(s) (bnc,tp,dix,auto,eprom)"); | ||
1422 | |||
1423 | module_param(debug, int, 0); | ||
1424 | MODULE_PARM_DESC(debug, "eth16i debug level (0-6)"); | ||
1425 | |||
1426 | int __init init_module(void) | ||
1427 | { | ||
1428 | int this_dev, found = 0; | ||
1429 | struct net_device *dev; | ||
1430 | |||
1431 | for (this_dev = 0; this_dev < MAX_ETH16I_CARDS; this_dev++) { | ||
1432 | dev = alloc_etherdev(sizeof(struct eth16i_local)); | ||
1433 | if (!dev) | ||
1434 | break; | ||
1435 | |||
1436 | dev->base_addr = io[this_dev]; | ||
1437 | |||
1438 | if(debug != -1) | ||
1439 | eth16i_debug = debug; | ||
1440 | |||
1441 | if(eth16i_debug > 1) | ||
1442 | printk(KERN_NOTICE "eth16i(%d): interface type %s\n", this_dev, mediatype[this_dev] ? mediatype[this_dev] : "none" ); | ||
1443 | |||
1444 | dev->if_port = eth16i_parse_mediatype(mediatype[this_dev]); | ||
1445 | |||
1446 | if(io[this_dev] == 0) { | ||
1447 | if (this_dev != 0) { /* Only autoprobe 1st one */ | ||
1448 | free_netdev(dev); | ||
1449 | break; | ||
1450 | } | ||
1451 | |||
1452 | printk(KERN_NOTICE "eth16i.c: Presently autoprobing (not recommended) for a single card.\n"); | ||
1453 | } | ||
1454 | |||
1455 | if (do_eth16i_probe(dev) == 0) { | ||
1456 | dev_eth16i[found++] = dev; | ||
1457 | continue; | ||
1458 | } | ||
1459 | printk(KERN_WARNING "eth16i.c No Eth16i card found (i/o = 0x%x).\n", | ||
1460 | io[this_dev]); | ||
1461 | free_netdev(dev); | ||
1462 | break; | ||
1463 | } | ||
1464 | if (found) | ||
1465 | return 0; | ||
1466 | return -ENXIO; | ||
1467 | } | ||
1468 | |||
1469 | void __exit cleanup_module(void) | ||
1470 | { | ||
1471 | int this_dev; | ||
1472 | |||
1473 | for(this_dev = 0; this_dev < MAX_ETH16I_CARDS; this_dev++) { | ||
1474 | struct net_device *dev = dev_eth16i[this_dev]; | ||
1475 | |||
1476 | if (netdev_priv(dev)) { | ||
1477 | unregister_netdev(dev); | ||
1478 | free_irq(dev->irq, dev); | ||
1479 | release_region(dev->base_addr, ETH16I_IO_EXTENT); | ||
1480 | free_netdev(dev); | ||
1481 | } | ||
1482 | } | ||
1483 | } | ||
1484 | #endif /* MODULE */ | ||
diff --git a/drivers/net/ethernet/fujitsu/fmvj18x_cs.c b/drivers/net/ethernet/fujitsu/fmvj18x_cs.c new file mode 100644 index 000000000000..723815e7a997 --- /dev/null +++ b/drivers/net/ethernet/fujitsu/fmvj18x_cs.c | |||
@@ -0,0 +1,1187 @@ | |||
1 | /*====================================================================== | ||
2 | fmvj18x_cs.c 2.8 2002/03/23 | ||
3 | |||
4 | A fmvj18x (and its compatibles) PCMCIA client driver | ||
5 | |||
6 | Contributed by Shingo Fujimoto, shingo@flab.fujitsu.co.jp | ||
7 | |||
8 | TDK LAK-CD021 and CONTEC C-NET(PC)C support added by | ||
9 | Nobuhiro Katayama, kata-n@po.iijnet.or.jp | ||
10 | |||
11 | The PCMCIA client code is based on code written by David Hinds. | ||
12 | Network code is based on the "FMV-18x driver" by Yutaka TAMIYA | ||
13 | but is actually largely Donald Becker's AT1700 driver, which | ||
14 | carries the following attribution: | ||
15 | |||
16 | Written 1993-94 by Donald Becker. | ||
17 | |||
18 | Copyright 1993 United States Government as represented by the | ||
19 | Director, National Security Agency. | ||
20 | |||
21 | This software may be used and distributed according to the terms | ||
22 | of the GNU General Public License, incorporated herein by reference. | ||
23 | |||
24 | The author may be reached as becker@scyld.com, or C/O | ||
25 | Scyld Computing Corporation | ||
26 | 410 Severn Ave., Suite 210 | ||
27 | Annapolis MD 21403 | ||
28 | |||
29 | ======================================================================*/ | ||
30 | |||
31 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
32 | |||
33 | #define DRV_NAME "fmvj18x_cs" | ||
34 | #define DRV_VERSION "2.9" | ||
35 | |||
36 | #include <linux/module.h> | ||
37 | #include <linux/kernel.h> | ||
38 | #include <linux/init.h> | ||
39 | #include <linux/ptrace.h> | ||
40 | #include <linux/slab.h> | ||
41 | #include <linux/string.h> | ||
42 | #include <linux/timer.h> | ||
43 | #include <linux/interrupt.h> | ||
44 | #include <linux/in.h> | ||
45 | #include <linux/delay.h> | ||
46 | #include <linux/ethtool.h> | ||
47 | #include <linux/netdevice.h> | ||
48 | #include <linux/etherdevice.h> | ||
49 | #include <linux/skbuff.h> | ||
50 | #include <linux/if_arp.h> | ||
51 | #include <linux/ioport.h> | ||
52 | #include <linux/crc32.h> | ||
53 | |||
54 | #include <pcmcia/cistpl.h> | ||
55 | #include <pcmcia/ciscode.h> | ||
56 | #include <pcmcia/ds.h> | ||
57 | |||
58 | #include <asm/uaccess.h> | ||
59 | #include <asm/io.h> | ||
60 | #include <asm/system.h> | ||
61 | |||
62 | /*====================================================================*/ | ||
63 | |||
64 | /* Module parameters */ | ||
65 | |||
66 | MODULE_DESCRIPTION("fmvj18x and compatible PCMCIA ethernet driver"); | ||
67 | MODULE_LICENSE("GPL"); | ||
68 | |||
69 | #define INT_MODULE_PARM(n, v) static int n = v; module_param(n, int, 0) | ||
70 | |||
71 | /* SRAM configuration */ | ||
72 | /* 0:4KB*2 TX buffer else:8KB*2 TX buffer */ | ||
73 | INT_MODULE_PARM(sram_config, 0); | ||
74 | |||
75 | |||
76 | /*====================================================================*/ | ||
77 | /* | ||
78 | PCMCIA event handlers | ||
79 | */ | ||
80 | static int fmvj18x_config(struct pcmcia_device *link); | ||
81 | static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id); | ||
82 | static int fmvj18x_setup_mfc(struct pcmcia_device *link); | ||
83 | static void fmvj18x_release(struct pcmcia_device *link); | ||
84 | static void fmvj18x_detach(struct pcmcia_device *p_dev); | ||
85 | |||
86 | /* | ||
87 | LAN controller(MBH86960A) specific routines | ||
88 | */ | ||
89 | static int fjn_config(struct net_device *dev, struct ifmap *map); | ||
90 | static int fjn_open(struct net_device *dev); | ||
91 | static int fjn_close(struct net_device *dev); | ||
92 | static netdev_tx_t fjn_start_xmit(struct sk_buff *skb, | ||
93 | struct net_device *dev); | ||
94 | static irqreturn_t fjn_interrupt(int irq, void *dev_id); | ||
95 | static void fjn_rx(struct net_device *dev); | ||
96 | static void fjn_reset(struct net_device *dev); | ||
97 | static void set_rx_mode(struct net_device *dev); | ||
98 | static void fjn_tx_timeout(struct net_device *dev); | ||
99 | static const struct ethtool_ops netdev_ethtool_ops; | ||
100 | |||
101 | /* | ||
102 | card type | ||
103 | */ | ||
104 | typedef enum { MBH10302, MBH10304, TDK, CONTEC, LA501, UNGERMANN, | ||
105 | XXX10304, NEC, KME | ||
106 | } cardtype_t; | ||
107 | |||
108 | /* | ||
109 | driver specific data structure | ||
110 | */ | ||
111 | typedef struct local_info_t { | ||
112 | struct pcmcia_device *p_dev; | ||
113 | long open_time; | ||
114 | uint tx_started:1; | ||
115 | uint tx_queue; | ||
116 | u_short tx_queue_len; | ||
117 | cardtype_t cardtype; | ||
118 | u_short sent; | ||
119 | u_char __iomem *base; | ||
120 | } local_info_t; | ||
121 | |||
122 | #define MC_FILTERBREAK 64 | ||
123 | |||
124 | /*====================================================================*/ | ||
125 | /* | ||
126 | ioport offset from the base address | ||
127 | */ | ||
128 | #define TX_STATUS 0 /* transmit status register */ | ||
129 | #define RX_STATUS 1 /* receive status register */ | ||
130 | #define TX_INTR 2 /* transmit interrupt mask register */ | ||
131 | #define RX_INTR 3 /* receive interrupt mask register */ | ||
132 | #define TX_MODE 4 /* transmit mode register */ | ||
133 | #define RX_MODE 5 /* receive mode register */ | ||
134 | #define CONFIG_0 6 /* configuration register 0 */ | ||
135 | #define CONFIG_1 7 /* configuration register 1 */ | ||
136 | |||
137 | #define NODE_ID 8 /* node ID register (bank 0) */ | ||
138 | #define MAR_ADR 8 /* multicast address registers (bank 1) */ | ||
139 | |||
140 | #define DATAPORT 8 /* buffer mem port registers (bank 2) */ | ||
141 | #define TX_START 10 /* transmit start register */ | ||
142 | #define COL_CTRL 11 /* 16 collision control register */ | ||
143 | #define BMPR12 12 /* reserved */ | ||
144 | #define BMPR13 13 /* reserved */ | ||
145 | #define RX_SKIP 14 /* skip received packet register */ | ||
146 | |||
147 | #define LAN_CTRL 16 /* LAN card control register */ | ||
148 | |||
149 | #define MAC_ID 0x1a /* hardware address */ | ||
150 | #define UNGERMANN_MAC_ID 0x18 /* UNGERMANN-BASS hardware address */ | ||
151 | |||
152 | /* | ||
153 | control bits | ||
154 | */ | ||
155 | #define ENA_TMT_OK 0x80 | ||
156 | #define ENA_TMT_REC 0x20 | ||
157 | #define ENA_COL 0x04 | ||
158 | #define ENA_16_COL 0x02 | ||
159 | #define ENA_TBUS_ERR 0x01 | ||
160 | |||
161 | #define ENA_PKT_RDY 0x80 | ||
162 | #define ENA_BUS_ERR 0x40 | ||
163 | #define ENA_LEN_ERR 0x08 | ||
164 | #define ENA_ALG_ERR 0x04 | ||
165 | #define ENA_CRC_ERR 0x02 | ||
166 | #define ENA_OVR_FLO 0x01 | ||
167 | |||
168 | /* flags */ | ||
169 | #define F_TMT_RDY 0x80 /* can accept new packet */ | ||
170 | #define F_NET_BSY 0x40 /* carrier is detected */ | ||
171 | #define F_TMT_OK 0x20 /* send packet successfully */ | ||
172 | #define F_SRT_PKT 0x10 /* short packet error */ | ||
173 | #define F_COL_ERR 0x04 /* collision error */ | ||
174 | #define F_16_COL 0x02 /* 16 collision error */ | ||
175 | #define F_TBUS_ERR 0x01 /* bus read error */ | ||
176 | |||
177 | #define F_PKT_RDY 0x80 /* packet(s) in buffer */ | ||
178 | #define F_BUS_ERR 0x40 /* bus read error */ | ||
179 | #define F_LEN_ERR 0x08 /* short packet */ | ||
180 | #define F_ALG_ERR 0x04 /* frame error */ | ||
181 | #define F_CRC_ERR 0x02 /* CRC error */ | ||
182 | #define F_OVR_FLO 0x01 /* overflow error */ | ||
183 | |||
184 | #define F_BUF_EMP 0x40 /* receive buffer is empty */ | ||
185 | |||
186 | #define F_SKP_PKT 0x05 /* drop packet in buffer */ | ||
187 | |||
188 | /* default bitmaps */ | ||
189 | #define D_TX_INTR ( ENA_TMT_OK ) | ||
190 | #define D_RX_INTR ( ENA_PKT_RDY | ENA_LEN_ERR \ | ||
191 | | ENA_ALG_ERR | ENA_CRC_ERR | ENA_OVR_FLO ) | ||
192 | #define TX_STAT_M ( F_TMT_RDY ) | ||
193 | #define RX_STAT_M ( F_PKT_RDY | F_LEN_ERR \ | ||
194 | | F_ALG_ERR | F_CRC_ERR | F_OVR_FLO ) | ||
195 | |||
196 | /* commands */ | ||
197 | #define D_TX_MODE 0x06 /* no tests, detect carrier */ | ||
198 | #define ID_MATCHED 0x02 /* (RX_MODE) */ | ||
199 | #define RECV_ALL 0x03 /* (RX_MODE) */ | ||
200 | #define CONFIG0_DFL 0x5a /* 16bit bus, 4K x 2 Tx queues */ | ||
201 | #define CONFIG0_DFL_1 0x5e /* 16bit bus, 8K x 2 Tx queues */ | ||
202 | #define CONFIG0_RST 0xda /* Data Link Controller off (CONFIG_0) */ | ||
203 | #define CONFIG0_RST_1 0xde /* Data Link Controller off (CONFIG_0) */ | ||
204 | #define BANK_0 0xa0 /* bank 0 (CONFIG_1) */ | ||
205 | #define BANK_1 0xa4 /* bank 1 (CONFIG_1) */ | ||
206 | #define BANK_2 0xa8 /* bank 2 (CONFIG_1) */ | ||
207 | #define CHIP_OFF 0x80 /* contrl chip power off (CONFIG_1) */ | ||
208 | #define DO_TX 0x80 /* do transmit packet */ | ||
209 | #define SEND_PKT 0x81 /* send a packet */ | ||
210 | #define AUTO_MODE 0x07 /* Auto skip packet on 16 col detected */ | ||
211 | #define MANU_MODE 0x03 /* Stop and skip packet on 16 col */ | ||
212 | #define TDK_AUTO_MODE 0x47 /* Auto skip packet on 16 col detected */ | ||
213 | #define TDK_MANU_MODE 0x43 /* Stop and skip packet on 16 col */ | ||
214 | #define INTR_OFF 0x0d /* LAN controller ignores interrupts */ | ||
215 | #define INTR_ON 0x1d /* LAN controller will catch interrupts */ | ||
216 | |||
217 | #define TX_TIMEOUT ((400*HZ)/1000) | ||
218 | |||
219 | #define BANK_0U 0x20 /* bank 0 (CONFIG_1) */ | ||
220 | #define BANK_1U 0x24 /* bank 1 (CONFIG_1) */ | ||
221 | #define BANK_2U 0x28 /* bank 2 (CONFIG_1) */ | ||
222 | |||
223 | static const struct net_device_ops fjn_netdev_ops = { | ||
224 | .ndo_open = fjn_open, | ||
225 | .ndo_stop = fjn_close, | ||
226 | .ndo_start_xmit = fjn_start_xmit, | ||
227 | .ndo_tx_timeout = fjn_tx_timeout, | ||
228 | .ndo_set_config = fjn_config, | ||
229 | .ndo_set_multicast_list = set_rx_mode, | ||
230 | .ndo_change_mtu = eth_change_mtu, | ||
231 | .ndo_set_mac_address = eth_mac_addr, | ||
232 | .ndo_validate_addr = eth_validate_addr, | ||
233 | }; | ||
234 | |||
235 | static int fmvj18x_probe(struct pcmcia_device *link) | ||
236 | { | ||
237 | local_info_t *lp; | ||
238 | struct net_device *dev; | ||
239 | |||
240 | dev_dbg(&link->dev, "fmvj18x_attach()\n"); | ||
241 | |||
242 | /* Make up a FMVJ18x specific data structure */ | ||
243 | dev = alloc_etherdev(sizeof(local_info_t)); | ||
244 | if (!dev) | ||
245 | return -ENOMEM; | ||
246 | lp = netdev_priv(dev); | ||
247 | link->priv = dev; | ||
248 | lp->p_dev = link; | ||
249 | lp->base = NULL; | ||
250 | |||
251 | /* The io structure describes IO port mapping */ | ||
252 | link->resource[0]->end = 32; | ||
253 | link->resource[0]->flags |= IO_DATA_PATH_WIDTH_AUTO; | ||
254 | |||
255 | /* General socket configuration */ | ||
256 | link->config_flags |= CONF_ENABLE_IRQ; | ||
257 | |||
258 | dev->netdev_ops = &fjn_netdev_ops; | ||
259 | dev->watchdog_timeo = TX_TIMEOUT; | ||
260 | |||
261 | SET_ETHTOOL_OPS(dev, &netdev_ethtool_ops); | ||
262 | |||
263 | return fmvj18x_config(link); | ||
264 | } /* fmvj18x_attach */ | ||
265 | |||
266 | /*====================================================================*/ | ||
267 | |||
268 | static void fmvj18x_detach(struct pcmcia_device *link) | ||
269 | { | ||
270 | struct net_device *dev = link->priv; | ||
271 | |||
272 | dev_dbg(&link->dev, "fmvj18x_detach\n"); | ||
273 | |||
274 | unregister_netdev(dev); | ||
275 | |||
276 | fmvj18x_release(link); | ||
277 | |||
278 | free_netdev(dev); | ||
279 | } /* fmvj18x_detach */ | ||
280 | |||
281 | /*====================================================================*/ | ||
282 | |||
283 | static int mfc_try_io_port(struct pcmcia_device *link) | ||
284 | { | ||
285 | int i, ret; | ||
286 | static const unsigned int serial_base[5] = | ||
287 | { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 }; | ||
288 | |||
289 | for (i = 0; i < 5; i++) { | ||
290 | link->resource[1]->start = serial_base[i]; | ||
291 | link->resource[1]->flags |= IO_DATA_PATH_WIDTH_8; | ||
292 | if (link->resource[1]->start == 0) { | ||
293 | link->resource[1]->end = 0; | ||
294 | pr_notice("out of resource for serial\n"); | ||
295 | } | ||
296 | ret = pcmcia_request_io(link); | ||
297 | if (ret == 0) | ||
298 | return ret; | ||
299 | } | ||
300 | return ret; | ||
301 | } | ||
302 | |||
303 | static int ungermann_try_io_port(struct pcmcia_device *link) | ||
304 | { | ||
305 | int ret; | ||
306 | unsigned int ioaddr; | ||
307 | /* | ||
308 | Ungermann-Bass Access/CARD accepts 0x300,0x320,0x340,0x360 | ||
309 | 0x380,0x3c0 only for ioport. | ||
310 | */ | ||
311 | for (ioaddr = 0x300; ioaddr < 0x3e0; ioaddr += 0x20) { | ||
312 | link->resource[0]->start = ioaddr; | ||
313 | ret = pcmcia_request_io(link); | ||
314 | if (ret == 0) { | ||
315 | /* calculate ConfigIndex value */ | ||
316 | link->config_index = | ||
317 | ((link->resource[0]->start & 0x0f0) >> 3) | 0x22; | ||
318 | return ret; | ||
319 | } | ||
320 | } | ||
321 | return ret; /* RequestIO failed */ | ||
322 | } | ||
323 | |||
324 | static int fmvj18x_ioprobe(struct pcmcia_device *p_dev, void *priv_data) | ||
325 | { | ||
326 | return 0; /* strange, but that's what the code did already before... */ | ||
327 | } | ||
328 | |||
329 | static int fmvj18x_config(struct pcmcia_device *link) | ||
330 | { | ||
331 | struct net_device *dev = link->priv; | ||
332 | local_info_t *lp = netdev_priv(dev); | ||
333 | int i, ret; | ||
334 | unsigned int ioaddr; | ||
335 | cardtype_t cardtype; | ||
336 | char *card_name = "unknown"; | ||
337 | u8 *buf; | ||
338 | size_t len; | ||
339 | u_char buggybuf[32]; | ||
340 | |||
341 | dev_dbg(&link->dev, "fmvj18x_config\n"); | ||
342 | |||
343 | link->io_lines = 5; | ||
344 | |||
345 | len = pcmcia_get_tuple(link, CISTPL_FUNCE, &buf); | ||
346 | kfree(buf); | ||
347 | |||
348 | if (len) { | ||
349 | /* Yes, I have CISTPL_FUNCE. Let's check CISTPL_MANFID */ | ||
350 | ret = pcmcia_loop_config(link, fmvj18x_ioprobe, NULL); | ||
351 | if (ret != 0) | ||
352 | goto failed; | ||
353 | |||
354 | switch (link->manf_id) { | ||
355 | case MANFID_TDK: | ||
356 | cardtype = TDK; | ||
357 | if (link->card_id == PRODID_TDK_GN3410 || | ||
358 | link->card_id == PRODID_TDK_NP9610 || | ||
359 | link->card_id == PRODID_TDK_MN3200) { | ||
360 | /* MultiFunction Card */ | ||
361 | link->config_base = 0x800; | ||
362 | link->config_index = 0x47; | ||
363 | link->resource[1]->end = 8; | ||
364 | } | ||
365 | break; | ||
366 | case MANFID_NEC: | ||
367 | cardtype = NEC; /* MultiFunction Card */ | ||
368 | link->config_base = 0x800; | ||
369 | link->config_index = 0x47; | ||
370 | link->resource[1]->end = 8; | ||
371 | break; | ||
372 | case MANFID_KME: | ||
373 | cardtype = KME; /* MultiFunction Card */ | ||
374 | link->config_base = 0x800; | ||
375 | link->config_index = 0x47; | ||
376 | link->resource[1]->end = 8; | ||
377 | break; | ||
378 | case MANFID_CONTEC: | ||
379 | cardtype = CONTEC; | ||
380 | break; | ||
381 | case MANFID_FUJITSU: | ||
382 | if (link->config_base == 0x0fe0) | ||
383 | cardtype = MBH10302; | ||
384 | else if (link->card_id == PRODID_FUJITSU_MBH10302) | ||
385 | /* RATOC REX-5588/9822/4886's PRODID are 0004(=MBH10302), | ||
386 | but these are MBH10304 based card. */ | ||
387 | cardtype = MBH10304; | ||
388 | else if (link->card_id == PRODID_FUJITSU_MBH10304) | ||
389 | cardtype = MBH10304; | ||
390 | else | ||
391 | cardtype = LA501; | ||
392 | break; | ||
393 | default: | ||
394 | cardtype = MBH10304; | ||
395 | } | ||
396 | } else { | ||
397 | /* old type card */ | ||
398 | switch (link->manf_id) { | ||
399 | case MANFID_FUJITSU: | ||
400 | if (link->card_id == PRODID_FUJITSU_MBH10304) { | ||
401 | cardtype = XXX10304; /* MBH10304 with buggy CIS */ | ||
402 | link->config_index = 0x20; | ||
403 | } else { | ||
404 | cardtype = MBH10302; /* NextCom NC5310, etc. */ | ||
405 | link->config_index = 1; | ||
406 | } | ||
407 | break; | ||
408 | case MANFID_UNGERMANN: | ||
409 | cardtype = UNGERMANN; | ||
410 | break; | ||
411 | default: | ||
412 | cardtype = MBH10302; | ||
413 | link->config_index = 1; | ||
414 | } | ||
415 | } | ||
416 | |||
417 | if (link->resource[1]->end != 0) { | ||
418 | ret = mfc_try_io_port(link); | ||
419 | if (ret != 0) goto failed; | ||
420 | } else if (cardtype == UNGERMANN) { | ||
421 | ret = ungermann_try_io_port(link); | ||
422 | if (ret != 0) goto failed; | ||
423 | } else { | ||
424 | ret = pcmcia_request_io(link); | ||
425 | if (ret) | ||
426 | goto failed; | ||
427 | } | ||
428 | ret = pcmcia_request_irq(link, fjn_interrupt); | ||
429 | if (ret) | ||
430 | goto failed; | ||
431 | ret = pcmcia_enable_device(link); | ||
432 | if (ret) | ||
433 | goto failed; | ||
434 | |||
435 | dev->irq = link->irq; | ||
436 | dev->base_addr = link->resource[0]->start; | ||
437 | |||
438 | if (resource_size(link->resource[1]) != 0) { | ||
439 | ret = fmvj18x_setup_mfc(link); | ||
440 | if (ret != 0) goto failed; | ||
441 | } | ||
442 | |||
443 | ioaddr = dev->base_addr; | ||
444 | |||
445 | /* Reset controller */ | ||
446 | if (sram_config == 0) | ||
447 | outb(CONFIG0_RST, ioaddr + CONFIG_0); | ||
448 | else | ||
449 | outb(CONFIG0_RST_1, ioaddr + CONFIG_0); | ||
450 | |||
451 | /* Power On chip and select bank 0 */ | ||
452 | if (cardtype == MBH10302) | ||
453 | outb(BANK_0, ioaddr + CONFIG_1); | ||
454 | else | ||
455 | outb(BANK_0U, ioaddr + CONFIG_1); | ||
456 | |||
457 | /* Set hardware address */ | ||
458 | switch (cardtype) { | ||
459 | case MBH10304: | ||
460 | case TDK: | ||
461 | case LA501: | ||
462 | case CONTEC: | ||
463 | case NEC: | ||
464 | case KME: | ||
465 | if (cardtype == MBH10304) { | ||
466 | card_name = "FMV-J182"; | ||
467 | |||
468 | len = pcmcia_get_tuple(link, CISTPL_FUNCE, &buf); | ||
469 | if (len < 11) { | ||
470 | kfree(buf); | ||
471 | goto failed; | ||
472 | } | ||
473 | /* Read MACID from CIS */ | ||
474 | for (i = 5; i < 11; i++) | ||
475 | dev->dev_addr[i] = buf[i]; | ||
476 | kfree(buf); | ||
477 | } else { | ||
478 | if (pcmcia_get_mac_from_cis(link, dev)) | ||
479 | goto failed; | ||
480 | if( cardtype == TDK ) { | ||
481 | card_name = "TDK LAK-CD021"; | ||
482 | } else if( cardtype == LA501 ) { | ||
483 | card_name = "LA501"; | ||
484 | } else if( cardtype == NEC ) { | ||
485 | card_name = "PK-UG-J001"; | ||
486 | } else if( cardtype == KME ) { | ||
487 | card_name = "Panasonic"; | ||
488 | } else { | ||
489 | card_name = "C-NET(PC)C"; | ||
490 | } | ||
491 | } | ||
492 | break; | ||
493 | case UNGERMANN: | ||
494 | /* Read MACID from register */ | ||
495 | for (i = 0; i < 6; i++) | ||
496 | dev->dev_addr[i] = inb(ioaddr + UNGERMANN_MAC_ID + i); | ||
497 | card_name = "Access/CARD"; | ||
498 | break; | ||
499 | case XXX10304: | ||
500 | /* Read MACID from Buggy CIS */ | ||
501 | if (fmvj18x_get_hwinfo(link, buggybuf) == -1) { | ||
502 | pr_notice("unable to read hardware net address\n"); | ||
503 | goto failed; | ||
504 | } | ||
505 | for (i = 0 ; i < 6; i++) { | ||
506 | dev->dev_addr[i] = buggybuf[i]; | ||
507 | } | ||
508 | card_name = "FMV-J182"; | ||
509 | break; | ||
510 | case MBH10302: | ||
511 | default: | ||
512 | /* Read MACID from register */ | ||
513 | for (i = 0; i < 6; i++) | ||
514 | dev->dev_addr[i] = inb(ioaddr + MAC_ID + i); | ||
515 | card_name = "FMV-J181"; | ||
516 | break; | ||
517 | } | ||
518 | |||
519 | lp->cardtype = cardtype; | ||
520 | SET_NETDEV_DEV(dev, &link->dev); | ||
521 | |||
522 | if (register_netdev(dev) != 0) { | ||
523 | pr_notice("register_netdev() failed\n"); | ||
524 | goto failed; | ||
525 | } | ||
526 | |||
527 | /* print current configuration */ | ||
528 | netdev_info(dev, "%s, sram %s, port %#3lx, irq %d, hw_addr %pM\n", | ||
529 | card_name, sram_config == 0 ? "4K TX*2" : "8K TX*2", | ||
530 | dev->base_addr, dev->irq, dev->dev_addr); | ||
531 | |||
532 | return 0; | ||
533 | |||
534 | failed: | ||
535 | fmvj18x_release(link); | ||
536 | return -ENODEV; | ||
537 | } /* fmvj18x_config */ | ||
538 | /*====================================================================*/ | ||
539 | |||
540 | static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id) | ||
541 | { | ||
542 | u_char __iomem *base; | ||
543 | int i, j; | ||
544 | |||
545 | /* Allocate a small memory window */ | ||
546 | link->resource[2]->flags |= WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; | ||
547 | link->resource[2]->start = 0; link->resource[2]->end = 0; | ||
548 | i = pcmcia_request_window(link, link->resource[2], 0); | ||
549 | if (i != 0) | ||
550 | return -1; | ||
551 | |||
552 | base = ioremap(link->resource[2]->start, resource_size(link->resource[2])); | ||
553 | pcmcia_map_mem_page(link, link->resource[2], 0); | ||
554 | |||
555 | /* | ||
556 | * MBH10304 CISTPL_FUNCE_LAN_NODE_ID format | ||
557 | * 22 0d xx xx xx 04 06 yy yy yy yy yy yy ff | ||
558 | * 'xx' is garbage. | ||
559 | * 'yy' is MAC address. | ||
560 | */ | ||
561 | for (i = 0; i < 0x200; i++) { | ||
562 | if (readb(base+i*2) == 0x22) { | ||
563 | if (readb(base+(i-1)*2) == 0xff && | ||
564 | readb(base+(i+5)*2) == 0x04 && | ||
565 | readb(base+(i+6)*2) == 0x06 && | ||
566 | readb(base+(i+13)*2) == 0xff) | ||
567 | break; | ||
568 | } | ||
569 | } | ||
570 | |||
571 | if (i != 0x200) { | ||
572 | for (j = 0 ; j < 6; j++,i++) { | ||
573 | node_id[j] = readb(base+(i+7)*2); | ||
574 | } | ||
575 | } | ||
576 | |||
577 | iounmap(base); | ||
578 | j = pcmcia_release_window(link, link->resource[2]); | ||
579 | return (i != 0x200) ? 0 : -1; | ||
580 | |||
581 | } /* fmvj18x_get_hwinfo */ | ||
582 | /*====================================================================*/ | ||
583 | |||
584 | static int fmvj18x_setup_mfc(struct pcmcia_device *link) | ||
585 | { | ||
586 | int i; | ||
587 | struct net_device *dev = link->priv; | ||
588 | unsigned int ioaddr; | ||
589 | local_info_t *lp = netdev_priv(dev); | ||
590 | |||
591 | /* Allocate a small memory window */ | ||
592 | link->resource[3]->flags = WIN_DATA_WIDTH_8|WIN_MEMORY_TYPE_AM|WIN_ENABLE; | ||
593 | link->resource[3]->start = link->resource[3]->end = 0; | ||
594 | i = pcmcia_request_window(link, link->resource[3], 0); | ||
595 | if (i != 0) | ||
596 | return -1; | ||
597 | |||
598 | lp->base = ioremap(link->resource[3]->start, | ||
599 | resource_size(link->resource[3])); | ||
600 | if (lp->base == NULL) { | ||
601 | netdev_notice(dev, "ioremap failed\n"); | ||
602 | return -1; | ||
603 | } | ||
604 | |||
605 | i = pcmcia_map_mem_page(link, link->resource[3], 0); | ||
606 | if (i != 0) { | ||
607 | iounmap(lp->base); | ||
608 | lp->base = NULL; | ||
609 | return -1; | ||
610 | } | ||
611 | |||
612 | ioaddr = dev->base_addr; | ||
613 | writeb(0x47, lp->base+0x800); /* Config Option Register of LAN */ | ||
614 | writeb(0x0, lp->base+0x802); /* Config and Status Register */ | ||
615 | |||
616 | writeb(ioaddr & 0xff, lp->base+0x80a); /* I/O Base(Low) of LAN */ | ||
617 | writeb((ioaddr >> 8) & 0xff, lp->base+0x80c); /* I/O Base(High) of LAN */ | ||
618 | |||
619 | writeb(0x45, lp->base+0x820); /* Config Option Register of Modem */ | ||
620 | writeb(0x8, lp->base+0x822); /* Config and Status Register */ | ||
621 | |||
622 | return 0; | ||
623 | |||
624 | } | ||
625 | /*====================================================================*/ | ||
626 | |||
627 | static void fmvj18x_release(struct pcmcia_device *link) | ||
628 | { | ||
629 | |||
630 | struct net_device *dev = link->priv; | ||
631 | local_info_t *lp = netdev_priv(dev); | ||
632 | u_char __iomem *tmp; | ||
633 | |||
634 | dev_dbg(&link->dev, "fmvj18x_release\n"); | ||
635 | |||
636 | if (lp->base != NULL) { | ||
637 | tmp = lp->base; | ||
638 | lp->base = NULL; /* set NULL before iounmap */ | ||
639 | iounmap(tmp); | ||
640 | } | ||
641 | |||
642 | pcmcia_disable_device(link); | ||
643 | |||
644 | } | ||
645 | |||
646 | static int fmvj18x_suspend(struct pcmcia_device *link) | ||
647 | { | ||
648 | struct net_device *dev = link->priv; | ||
649 | |||
650 | if (link->open) | ||
651 | netif_device_detach(dev); | ||
652 | |||
653 | return 0; | ||
654 | } | ||
655 | |||
656 | static int fmvj18x_resume(struct pcmcia_device *link) | ||
657 | { | ||
658 | struct net_device *dev = link->priv; | ||
659 | |||
660 | if (link->open) { | ||
661 | fjn_reset(dev); | ||
662 | netif_device_attach(dev); | ||
663 | } | ||
664 | |||
665 | return 0; | ||
666 | } | ||
667 | |||
668 | /*====================================================================*/ | ||
669 | |||
670 | static const struct pcmcia_device_id fmvj18x_ids[] = { | ||
671 | PCMCIA_DEVICE_MANF_CARD(0x0004, 0x0004), | ||
672 | PCMCIA_DEVICE_PROD_ID12("EAGLE Technology", "NE200 ETHERNET LAN MBH10302 04", 0x528c88c4, 0x74f91e59), | ||
673 | PCMCIA_DEVICE_PROD_ID12("Eiger Labs,Inc", "EPX-10BT PC Card Ethernet 10BT", 0x53af556e, 0x877f9922), | ||
674 | PCMCIA_DEVICE_PROD_ID12("Eiger labs,Inc.", "EPX-10BT PC Card Ethernet 10BT", 0xf47e6c66, 0x877f9922), | ||
675 | PCMCIA_DEVICE_PROD_ID12("FUJITSU", "LAN Card(FMV-J182)", 0x6ee5a3d8, 0x5baf31db), | ||
676 | PCMCIA_DEVICE_PROD_ID12("FUJITSU", "MBH10308", 0x6ee5a3d8, 0x3f04875e), | ||
677 | PCMCIA_DEVICE_PROD_ID12("FUJITSU TOWA", "LA501", 0xb8451188, 0x12939ba2), | ||
678 | PCMCIA_DEVICE_PROD_ID12("HITACHI", "HT-4840-11", 0xf4f43949, 0x773910f4), | ||
679 | PCMCIA_DEVICE_PROD_ID12("NextComK.K.", "NC5310B Ver1.0 ", 0x8cef4d3a, 0x075fc7b6), | ||
680 | PCMCIA_DEVICE_PROD_ID12("NextComK.K.", "NC5310 Ver1.0 ", 0x8cef4d3a, 0xbccf43e6), | ||
681 | PCMCIA_DEVICE_PROD_ID12("RATOC System Inc.", "10BASE_T CARD R280", 0x85c10e17, 0xd9413666), | ||
682 | PCMCIA_DEVICE_PROD_ID12("TDK", "LAC-CD02x", 0x1eae9475, 0x8fa0ee70), | ||
683 | PCMCIA_DEVICE_PROD_ID12("TDK", "LAC-CF010", 0x1eae9475, 0x7683bc9a), | ||
684 | PCMCIA_DEVICE_PROD_ID1("CONTEC Co.,Ltd.", 0x58d8fee2), | ||
685 | PCMCIA_DEVICE_PROD_ID1("PCMCIA LAN MBH10304 ES", 0x2599f454), | ||
686 | PCMCIA_DEVICE_PROD_ID1("PCMCIA MBH10302", 0x8f4005da), | ||
687 | PCMCIA_DEVICE_PROD_ID1("UBKK,V2.0", 0x90888080), | ||
688 | PCMCIA_PFC_DEVICE_PROD_ID12(0, "TDK", "GlobalNetworker 3410/3412", 0x1eae9475, 0xd9a93bed), | ||
689 | PCMCIA_PFC_DEVICE_PROD_ID12(0, "NEC", "PK-UG-J001" ,0x18df0ba0 ,0x831b1064), | ||
690 | PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0d0a), | ||
691 | PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0105, 0x0e0a), | ||
692 | PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x0e01), | ||
693 | PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x0a05), | ||
694 | PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x0b05), | ||
695 | PCMCIA_PFC_DEVICE_MANF_CARD(0, 0x0032, 0x1101), | ||
696 | PCMCIA_DEVICE_NULL, | ||
697 | }; | ||
698 | MODULE_DEVICE_TABLE(pcmcia, fmvj18x_ids); | ||
699 | |||
700 | static struct pcmcia_driver fmvj18x_cs_driver = { | ||
701 | .owner = THIS_MODULE, | ||
702 | .name = "fmvj18x_cs", | ||
703 | .probe = fmvj18x_probe, | ||
704 | .remove = fmvj18x_detach, | ||
705 | .id_table = fmvj18x_ids, | ||
706 | .suspend = fmvj18x_suspend, | ||
707 | .resume = fmvj18x_resume, | ||
708 | }; | ||
709 | |||
710 | static int __init init_fmvj18x_cs(void) | ||
711 | { | ||
712 | return pcmcia_register_driver(&fmvj18x_cs_driver); | ||
713 | } | ||
714 | |||
715 | static void __exit exit_fmvj18x_cs(void) | ||
716 | { | ||
717 | pcmcia_unregister_driver(&fmvj18x_cs_driver); | ||
718 | } | ||
719 | |||
720 | module_init(init_fmvj18x_cs); | ||
721 | module_exit(exit_fmvj18x_cs); | ||
722 | |||
723 | /*====================================================================*/ | ||
724 | |||
725 | static irqreturn_t fjn_interrupt(int dummy, void *dev_id) | ||
726 | { | ||
727 | struct net_device *dev = dev_id; | ||
728 | local_info_t *lp = netdev_priv(dev); | ||
729 | unsigned int ioaddr; | ||
730 | unsigned short tx_stat, rx_stat; | ||
731 | |||
732 | ioaddr = dev->base_addr; | ||
733 | |||
734 | /* avoid multiple interrupts */ | ||
735 | outw(0x0000, ioaddr + TX_INTR); | ||
736 | |||
737 | /* wait for a while */ | ||
738 | udelay(1); | ||
739 | |||
740 | /* get status */ | ||
741 | tx_stat = inb(ioaddr + TX_STATUS); | ||
742 | rx_stat = inb(ioaddr + RX_STATUS); | ||
743 | |||
744 | /* clear status */ | ||
745 | outb(tx_stat, ioaddr + TX_STATUS); | ||
746 | outb(rx_stat, ioaddr + RX_STATUS); | ||
747 | |||
748 | pr_debug("%s: interrupt, rx_status %02x.\n", dev->name, rx_stat); | ||
749 | pr_debug(" tx_status %02x.\n", tx_stat); | ||
750 | |||
751 | if (rx_stat || (inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) { | ||
752 | /* there is packet(s) in rx buffer */ | ||
753 | fjn_rx(dev); | ||
754 | } | ||
755 | if (tx_stat & F_TMT_RDY) { | ||
756 | dev->stats.tx_packets += lp->sent ; | ||
757 | lp->sent = 0 ; | ||
758 | if (lp->tx_queue) { | ||
759 | outb(DO_TX | lp->tx_queue, ioaddr + TX_START); | ||
760 | lp->sent = lp->tx_queue ; | ||
761 | lp->tx_queue = 0; | ||
762 | lp->tx_queue_len = 0; | ||
763 | dev->trans_start = jiffies; | ||
764 | } else { | ||
765 | lp->tx_started = 0; | ||
766 | } | ||
767 | netif_wake_queue(dev); | ||
768 | } | ||
769 | pr_debug("%s: exiting interrupt,\n", dev->name); | ||
770 | pr_debug(" tx_status %02x, rx_status %02x.\n", tx_stat, rx_stat); | ||
771 | |||
772 | outb(D_TX_INTR, ioaddr + TX_INTR); | ||
773 | outb(D_RX_INTR, ioaddr + RX_INTR); | ||
774 | |||
775 | if (lp->base != NULL) { | ||
776 | /* Ack interrupt for multifunction card */ | ||
777 | writeb(0x01, lp->base+0x802); | ||
778 | writeb(0x09, lp->base+0x822); | ||
779 | } | ||
780 | |||
781 | return IRQ_HANDLED; | ||
782 | |||
783 | } /* fjn_interrupt */ | ||
784 | |||
785 | /*====================================================================*/ | ||
786 | |||
787 | static void fjn_tx_timeout(struct net_device *dev) | ||
788 | { | ||
789 | struct local_info_t *lp = netdev_priv(dev); | ||
790 | unsigned int ioaddr = dev->base_addr; | ||
791 | |||
792 | netdev_notice(dev, "transmit timed out with status %04x, %s?\n", | ||
793 | htons(inw(ioaddr + TX_STATUS)), | ||
794 | inb(ioaddr + TX_STATUS) & F_TMT_RDY | ||
795 | ? "IRQ conflict" : "network cable problem"); | ||
796 | netdev_notice(dev, "timeout registers: %04x %04x %04x " | ||
797 | "%04x %04x %04x %04x %04x.\n", | ||
798 | htons(inw(ioaddr + 0)), htons(inw(ioaddr + 2)), | ||
799 | htons(inw(ioaddr + 4)), htons(inw(ioaddr + 6)), | ||
800 | htons(inw(ioaddr + 8)), htons(inw(ioaddr + 10)), | ||
801 | htons(inw(ioaddr + 12)), htons(inw(ioaddr + 14))); | ||
802 | dev->stats.tx_errors++; | ||
803 | /* ToDo: We should try to restart the adaptor... */ | ||
804 | local_irq_disable(); | ||
805 | fjn_reset(dev); | ||
806 | |||
807 | lp->tx_started = 0; | ||
808 | lp->tx_queue = 0; | ||
809 | lp->tx_queue_len = 0; | ||
810 | lp->sent = 0; | ||
811 | lp->open_time = jiffies; | ||
812 | local_irq_enable(); | ||
813 | netif_wake_queue(dev); | ||
814 | } | ||
815 | |||
816 | static netdev_tx_t fjn_start_xmit(struct sk_buff *skb, | ||
817 | struct net_device *dev) | ||
818 | { | ||
819 | struct local_info_t *lp = netdev_priv(dev); | ||
820 | unsigned int ioaddr = dev->base_addr; | ||
821 | short length = skb->len; | ||
822 | |||
823 | if (length < ETH_ZLEN) | ||
824 | { | ||
825 | if (skb_padto(skb, ETH_ZLEN)) | ||
826 | return NETDEV_TX_OK; | ||
827 | length = ETH_ZLEN; | ||
828 | } | ||
829 | |||
830 | netif_stop_queue(dev); | ||
831 | |||
832 | { | ||
833 | unsigned char *buf = skb->data; | ||
834 | |||
835 | if (length > ETH_FRAME_LEN) { | ||
836 | netdev_notice(dev, "Attempting to send a large packet (%d bytes)\n", | ||
837 | length); | ||
838 | return NETDEV_TX_BUSY; | ||
839 | } | ||
840 | |||
841 | netdev_dbg(dev, "Transmitting a packet of length %lu\n", | ||
842 | (unsigned long)skb->len); | ||
843 | dev->stats.tx_bytes += skb->len; | ||
844 | |||
845 | /* Disable both interrupts. */ | ||
846 | outw(0x0000, ioaddr + TX_INTR); | ||
847 | |||
848 | /* wait for a while */ | ||
849 | udelay(1); | ||
850 | |||
851 | outw(length, ioaddr + DATAPORT); | ||
852 | outsw(ioaddr + DATAPORT, buf, (length + 1) >> 1); | ||
853 | |||
854 | lp->tx_queue++; | ||
855 | lp->tx_queue_len += ((length+3) & ~1); | ||
856 | |||
857 | if (lp->tx_started == 0) { | ||
858 | /* If the Tx is idle, always trigger a transmit. */ | ||
859 | outb(DO_TX | lp->tx_queue, ioaddr + TX_START); | ||
860 | lp->sent = lp->tx_queue ; | ||
861 | lp->tx_queue = 0; | ||
862 | lp->tx_queue_len = 0; | ||
863 | lp->tx_started = 1; | ||
864 | netif_start_queue(dev); | ||
865 | } else { | ||
866 | if( sram_config == 0 ) { | ||
867 | if (lp->tx_queue_len < (4096 - (ETH_FRAME_LEN +2)) ) | ||
868 | /* Yes, there is room for one more packet. */ | ||
869 | netif_start_queue(dev); | ||
870 | } else { | ||
871 | if (lp->tx_queue_len < (8192 - (ETH_FRAME_LEN +2)) && | ||
872 | lp->tx_queue < 127 ) | ||
873 | /* Yes, there is room for one more packet. */ | ||
874 | netif_start_queue(dev); | ||
875 | } | ||
876 | } | ||
877 | |||
878 | /* Re-enable interrupts */ | ||
879 | outb(D_TX_INTR, ioaddr + TX_INTR); | ||
880 | outb(D_RX_INTR, ioaddr + RX_INTR); | ||
881 | } | ||
882 | dev_kfree_skb (skb); | ||
883 | |||
884 | return NETDEV_TX_OK; | ||
885 | } /* fjn_start_xmit */ | ||
886 | |||
887 | /*====================================================================*/ | ||
888 | |||
889 | static void fjn_reset(struct net_device *dev) | ||
890 | { | ||
891 | struct local_info_t *lp = netdev_priv(dev); | ||
892 | unsigned int ioaddr = dev->base_addr; | ||
893 | int i; | ||
894 | |||
895 | netdev_dbg(dev, "fjn_reset() called\n"); | ||
896 | |||
897 | /* Reset controller */ | ||
898 | if( sram_config == 0 ) | ||
899 | outb(CONFIG0_RST, ioaddr + CONFIG_0); | ||
900 | else | ||
901 | outb(CONFIG0_RST_1, ioaddr + CONFIG_0); | ||
902 | |||
903 | /* Power On chip and select bank 0 */ | ||
904 | if (lp->cardtype == MBH10302) | ||
905 | outb(BANK_0, ioaddr + CONFIG_1); | ||
906 | else | ||
907 | outb(BANK_0U, ioaddr + CONFIG_1); | ||
908 | |||
909 | /* Set Tx modes */ | ||
910 | outb(D_TX_MODE, ioaddr + TX_MODE); | ||
911 | /* set Rx modes */ | ||
912 | outb(ID_MATCHED, ioaddr + RX_MODE); | ||
913 | |||
914 | /* Set hardware address */ | ||
915 | for (i = 0; i < 6; i++) | ||
916 | outb(dev->dev_addr[i], ioaddr + NODE_ID + i); | ||
917 | |||
918 | /* (re)initialize the multicast table */ | ||
919 | set_rx_mode(dev); | ||
920 | |||
921 | /* Switch to bank 2 (runtime mode) */ | ||
922 | if (lp->cardtype == MBH10302) | ||
923 | outb(BANK_2, ioaddr + CONFIG_1); | ||
924 | else | ||
925 | outb(BANK_2U, ioaddr + CONFIG_1); | ||
926 | |||
927 | /* set 16col ctrl bits */ | ||
928 | if( lp->cardtype == TDK || lp->cardtype == CONTEC) | ||
929 | outb(TDK_AUTO_MODE, ioaddr + COL_CTRL); | ||
930 | else | ||
931 | outb(AUTO_MODE, ioaddr + COL_CTRL); | ||
932 | |||
933 | /* clear Reserved Regs */ | ||
934 | outb(0x00, ioaddr + BMPR12); | ||
935 | outb(0x00, ioaddr + BMPR13); | ||
936 | |||
937 | /* reset Skip packet reg. */ | ||
938 | outb(0x01, ioaddr + RX_SKIP); | ||
939 | |||
940 | /* Enable Tx and Rx */ | ||
941 | if( sram_config == 0 ) | ||
942 | outb(CONFIG0_DFL, ioaddr + CONFIG_0); | ||
943 | else | ||
944 | outb(CONFIG0_DFL_1, ioaddr + CONFIG_0); | ||
945 | |||
946 | /* Init receive pointer ? */ | ||
947 | inw(ioaddr + DATAPORT); | ||
948 | inw(ioaddr + DATAPORT); | ||
949 | |||
950 | /* Clear all status */ | ||
951 | outb(0xff, ioaddr + TX_STATUS); | ||
952 | outb(0xff, ioaddr + RX_STATUS); | ||
953 | |||
954 | if (lp->cardtype == MBH10302) | ||
955 | outb(INTR_OFF, ioaddr + LAN_CTRL); | ||
956 | |||
957 | /* Turn on Rx interrupts */ | ||
958 | outb(D_TX_INTR, ioaddr + TX_INTR); | ||
959 | outb(D_RX_INTR, ioaddr + RX_INTR); | ||
960 | |||
961 | /* Turn on interrupts from LAN card controller */ | ||
962 | if (lp->cardtype == MBH10302) | ||
963 | outb(INTR_ON, ioaddr + LAN_CTRL); | ||
964 | } /* fjn_reset */ | ||
965 | |||
966 | /*====================================================================*/ | ||
967 | |||
968 | static void fjn_rx(struct net_device *dev) | ||
969 | { | ||
970 | unsigned int ioaddr = dev->base_addr; | ||
971 | int boguscount = 10; /* 5 -> 10: by agy 19940922 */ | ||
972 | |||
973 | pr_debug("%s: in rx_packet(), rx_status %02x.\n", | ||
974 | dev->name, inb(ioaddr + RX_STATUS)); | ||
975 | |||
976 | while ((inb(ioaddr + RX_MODE) & F_BUF_EMP) == 0) { | ||
977 | u_short status = inw(ioaddr + DATAPORT); | ||
978 | |||
979 | netdev_dbg(dev, "Rxing packet mode %02x status %04x.\n", | ||
980 | inb(ioaddr + RX_MODE), status); | ||
981 | #ifndef final_version | ||
982 | if (status == 0) { | ||
983 | outb(F_SKP_PKT, ioaddr + RX_SKIP); | ||
984 | break; | ||
985 | } | ||
986 | #endif | ||
987 | if ((status & 0xF0) != 0x20) { /* There was an error. */ | ||
988 | dev->stats.rx_errors++; | ||
989 | if (status & F_LEN_ERR) dev->stats.rx_length_errors++; | ||
990 | if (status & F_ALG_ERR) dev->stats.rx_frame_errors++; | ||
991 | if (status & F_CRC_ERR) dev->stats.rx_crc_errors++; | ||
992 | if (status & F_OVR_FLO) dev->stats.rx_over_errors++; | ||
993 | } else { | ||
994 | u_short pkt_len = inw(ioaddr + DATAPORT); | ||
995 | /* Malloc up new buffer. */ | ||
996 | struct sk_buff *skb; | ||
997 | |||
998 | if (pkt_len > 1550) { | ||
999 | netdev_notice(dev, "The FMV-18x claimed a very large packet, size %d\n", | ||
1000 | pkt_len); | ||
1001 | outb(F_SKP_PKT, ioaddr + RX_SKIP); | ||
1002 | dev->stats.rx_errors++; | ||
1003 | break; | ||
1004 | } | ||
1005 | skb = dev_alloc_skb(pkt_len+2); | ||
1006 | if (skb == NULL) { | ||
1007 | netdev_notice(dev, "Memory squeeze, dropping packet (len %d)\n", | ||
1008 | pkt_len); | ||
1009 | outb(F_SKP_PKT, ioaddr + RX_SKIP); | ||
1010 | dev->stats.rx_dropped++; | ||
1011 | break; | ||
1012 | } | ||
1013 | |||
1014 | skb_reserve(skb, 2); | ||
1015 | insw(ioaddr + DATAPORT, skb_put(skb, pkt_len), | ||
1016 | (pkt_len + 1) >> 1); | ||
1017 | skb->protocol = eth_type_trans(skb, dev); | ||
1018 | |||
1019 | { | ||
1020 | int i; | ||
1021 | pr_debug("%s: Rxed packet of length %d: ", | ||
1022 | dev->name, pkt_len); | ||
1023 | for (i = 0; i < 14; i++) | ||
1024 | pr_debug(" %02x", skb->data[i]); | ||
1025 | pr_debug(".\n"); | ||
1026 | } | ||
1027 | |||
1028 | netif_rx(skb); | ||
1029 | dev->stats.rx_packets++; | ||
1030 | dev->stats.rx_bytes += pkt_len; | ||
1031 | } | ||
1032 | if (--boguscount <= 0) | ||
1033 | break; | ||
1034 | } | ||
1035 | |||
1036 | /* If any worth-while packets have been received, dev_rint() | ||
1037 | has done a netif_wake_queue() for us and will work on them | ||
1038 | when we get to the bottom-half routine. */ | ||
1039 | /* | ||
1040 | if (lp->cardtype != TDK) { | ||
1041 | int i; | ||
1042 | for (i = 0; i < 20; i++) { | ||
1043 | if ((inb(ioaddr + RX_MODE) & F_BUF_EMP) == F_BUF_EMP) | ||
1044 | break; | ||
1045 | (void)inw(ioaddr + DATAPORT); /+ dummy status read +/ | ||
1046 | outb(F_SKP_PKT, ioaddr + RX_SKIP); | ||
1047 | } | ||
1048 | |||
1049 | if (i > 0) | ||
1050 | pr_debug("%s: Exint Rx packet with mode %02x after " | ||
1051 | "%d ticks.\n", dev->name, inb(ioaddr + RX_MODE), i); | ||
1052 | } | ||
1053 | */ | ||
1054 | } /* fjn_rx */ | ||
1055 | |||
1056 | /*====================================================================*/ | ||
1057 | |||
1058 | static void netdev_get_drvinfo(struct net_device *dev, | ||
1059 | struct ethtool_drvinfo *info) | ||
1060 | { | ||
1061 | strcpy(info->driver, DRV_NAME); | ||
1062 | strcpy(info->version, DRV_VERSION); | ||
1063 | sprintf(info->bus_info, "PCMCIA 0x%lx", dev->base_addr); | ||
1064 | } | ||
1065 | |||
1066 | static const struct ethtool_ops netdev_ethtool_ops = { | ||
1067 | .get_drvinfo = netdev_get_drvinfo, | ||
1068 | }; | ||
1069 | |||
1070 | static int fjn_config(struct net_device *dev, struct ifmap *map){ | ||
1071 | return 0; | ||
1072 | } | ||
1073 | |||
1074 | static int fjn_open(struct net_device *dev) | ||
1075 | { | ||
1076 | struct local_info_t *lp = netdev_priv(dev); | ||
1077 | struct pcmcia_device *link = lp->p_dev; | ||
1078 | |||
1079 | pr_debug("fjn_open('%s').\n", dev->name); | ||
1080 | |||
1081 | if (!pcmcia_dev_present(link)) | ||
1082 | return -ENODEV; | ||
1083 | |||
1084 | link->open++; | ||
1085 | |||
1086 | fjn_reset(dev); | ||
1087 | |||
1088 | lp->tx_started = 0; | ||
1089 | lp->tx_queue = 0; | ||
1090 | lp->tx_queue_len = 0; | ||
1091 | lp->open_time = jiffies; | ||
1092 | netif_start_queue(dev); | ||
1093 | |||
1094 | return 0; | ||
1095 | } /* fjn_open */ | ||
1096 | |||
1097 | /*====================================================================*/ | ||
1098 | |||
1099 | static int fjn_close(struct net_device *dev) | ||
1100 | { | ||
1101 | struct local_info_t *lp = netdev_priv(dev); | ||
1102 | struct pcmcia_device *link = lp->p_dev; | ||
1103 | unsigned int ioaddr = dev->base_addr; | ||
1104 | |||
1105 | pr_debug("fjn_close('%s').\n", dev->name); | ||
1106 | |||
1107 | lp->open_time = 0; | ||
1108 | netif_stop_queue(dev); | ||
1109 | |||
1110 | /* Set configuration register 0 to disable Tx and Rx. */ | ||
1111 | if( sram_config == 0 ) | ||
1112 | outb(CONFIG0_RST ,ioaddr + CONFIG_0); | ||
1113 | else | ||
1114 | outb(CONFIG0_RST_1 ,ioaddr + CONFIG_0); | ||
1115 | |||
1116 | /* Update the statistics -- ToDo. */ | ||
1117 | |||
1118 | /* Power-down the chip. Green, green, green! */ | ||
1119 | outb(CHIP_OFF ,ioaddr + CONFIG_1); | ||
1120 | |||
1121 | /* Set the ethernet adaptor disable IRQ */ | ||
1122 | if (lp->cardtype == MBH10302) | ||
1123 | outb(INTR_OFF, ioaddr + LAN_CTRL); | ||
1124 | |||
1125 | link->open--; | ||
1126 | |||
1127 | return 0; | ||
1128 | } /* fjn_close */ | ||
1129 | |||
1130 | /*====================================================================*/ | ||
1131 | |||
1132 | /* | ||
1133 | Set the multicast/promiscuous mode for this adaptor. | ||
1134 | */ | ||
1135 | |||
1136 | static void set_rx_mode(struct net_device *dev) | ||
1137 | { | ||
1138 | unsigned int ioaddr = dev->base_addr; | ||
1139 | u_char mc_filter[8]; /* Multicast hash filter */ | ||
1140 | u_long flags; | ||
1141 | int i; | ||
1142 | |||
1143 | int saved_bank; | ||
1144 | int saved_config_0 = inb(ioaddr + CONFIG_0); | ||
1145 | |||
1146 | local_irq_save(flags); | ||
1147 | |||
1148 | /* Disable Tx and Rx */ | ||
1149 | if (sram_config == 0) | ||
1150 | outb(CONFIG0_RST, ioaddr + CONFIG_0); | ||
1151 | else | ||
1152 | outb(CONFIG0_RST_1, ioaddr + CONFIG_0); | ||
1153 | |||
1154 | if (dev->flags & IFF_PROMISC) { | ||
1155 | memset(mc_filter, 0xff, sizeof(mc_filter)); | ||
1156 | outb(3, ioaddr + RX_MODE); /* Enable promiscuous mode */ | ||
1157 | } else if (netdev_mc_count(dev) > MC_FILTERBREAK || | ||
1158 | (dev->flags & IFF_ALLMULTI)) { | ||
1159 | /* Too many to filter perfectly -- accept all multicasts. */ | ||
1160 | memset(mc_filter, 0xff, sizeof(mc_filter)); | ||
1161 | outb(2, ioaddr + RX_MODE); /* Use normal mode. */ | ||
1162 | } else if (netdev_mc_empty(dev)) { | ||
1163 | memset(mc_filter, 0x00, sizeof(mc_filter)); | ||
1164 | outb(1, ioaddr + RX_MODE); /* Ignore almost all multicasts. */ | ||
1165 | } else { | ||
1166 | struct netdev_hw_addr *ha; | ||
1167 | |||
1168 | memset(mc_filter, 0, sizeof(mc_filter)); | ||
1169 | netdev_for_each_mc_addr(ha, dev) { | ||
1170 | unsigned int bit = ether_crc_le(ETH_ALEN, ha->addr) >> 26; | ||
1171 | mc_filter[bit >> 3] |= (1 << (bit & 7)); | ||
1172 | } | ||
1173 | outb(2, ioaddr + RX_MODE); /* Use normal mode. */ | ||
1174 | } | ||
1175 | |||
1176 | /* Switch to bank 1 and set the multicast table. */ | ||
1177 | saved_bank = inb(ioaddr + CONFIG_1); | ||
1178 | outb(0xe4, ioaddr + CONFIG_1); | ||
1179 | |||
1180 | for (i = 0; i < 8; i++) | ||
1181 | outb(mc_filter[i], ioaddr + MAR_ADR + i); | ||
1182 | outb(saved_bank, ioaddr + CONFIG_1); | ||
1183 | |||
1184 | outb(saved_config_0, ioaddr + CONFIG_0); | ||
1185 | |||
1186 | local_irq_restore(flags); | ||
1187 | } | ||