2 * Linux ARCnet driver - COM20020 chipset support
4 * Written 1997 by David Woodhouse.
5 * Written 1994-1999 by Avery Pennarun.
6 * Written 1999 by Martin Mares <mj@ucw.cz>.
7 * Derived from skeleton.c by Donald Becker.
9 * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
10 * for sponsoring the further development of this driver.
12 * **********************
14 * The original copyright of skeleton.c was as follows:
16 * skeleton.c Written 1993 by Donald Becker.
17 * Copyright 1993 United States Government as represented by the
18 * Director, National Security Agency. This software may only be used
19 * and distributed according to the terms of the GNU General Public License as
20 * modified by SRC, incorporated herein by reference.
22 * **********************
24 * For more details, see drivers/net/arcnet.c
26 * **********************
28 #include <linux/module.h>
29 #include <linux/kernel.h>
30 #include <linux/types.h>
31 #include <linux/ioport.h>
32 #include <linux/errno.h>
33 #include <linux/delay.h>
34 #include <linux/netdevice.h>
35 #include <linux/init.h>
36 #include <linux/interrupt.h>
37 #include <linux/arcdevice.h>
38 #include <linux/com20020.h>
42 #define VERSION "arcnet: COM20020 chipset support (by David Woodhouse et al.)\n"
44 static char *clockrates[] = {
45 "XXXXXXX", "XXXXXXXX", "XXXXXX",
46 "2.5 Mb/s", "1.25Mb/s", "625 Kb/s", "312.5 Kb/s",
47 "156.25 Kb/s", "Reserved", "Reserved", "Reserved"
50 static void com20020_command(struct net_device *dev, int command);
51 static int com20020_status(struct net_device *dev);
52 static void com20020_setmask(struct net_device *dev, int mask);
53 static int com20020_reset(struct net_device *dev, int really_reset);
54 static void com20020_copy_to_card(struct net_device *dev, int bufnum,
55 int offset, void *buf, int count);
56 static void com20020_copy_from_card(struct net_device *dev, int bufnum,
57 int offset, void *buf, int count);
58 static void com20020_set_mc_list(struct net_device *dev);
59 static void com20020_close(struct net_device *);
61 static void com20020_copy_from_card(struct net_device *dev, int bufnum,
62 int offset, void *buf, int count)
64 int ioaddr = dev->base_addr, ofs = 512 * bufnum + offset;
66 /* set up the address register */
67 outb((ofs >> 8) | RDDATAflag | AUTOINCflag, _ADDR_HI);
68 outb(ofs & 0xff, _ADDR_LO);
71 TIME("insb", count, insb(_MEMDATA, buf, count));
74 static void com20020_copy_to_card(struct net_device *dev, int bufnum,
75 int offset, void *buf, int count)
77 int ioaddr = dev->base_addr, ofs = 512 * bufnum + offset;
79 /* set up the address register */
80 outb((ofs >> 8) | AUTOINCflag, _ADDR_HI);
81 outb(ofs & 0xff, _ADDR_LO);
84 TIME("outsb", count, outsb(_MEMDATA, buf, count));
87 /* Reset the card and check some basic stuff during the detection stage. */
88 int com20020_check(struct net_device *dev)
90 int ioaddr = dev->base_addr, status;
91 struct arcnet_local *lp = netdev_priv(dev);
96 lp->setup = lp->clockm ? 0 : (lp->clockp << 1);
97 lp->setup2 = (lp->clockm << 4) | 8;
99 /* CHECK: should we do this for SOHARD cards ? */
100 /* Enable P1Mode for backplane mode */
101 lp->setup = lp->setup | P1MODE;
103 SET_SUBADR(SUB_SETUP1);
104 outb(lp->setup, _XREG);
106 if (lp->clockm != 0) {
107 SET_SUBADR(SUB_SETUP2);
108 outb(lp->setup2, _XREG);
110 /* must now write the magic "restart operation" command */
112 outb(0x18, _COMMAND);
115 lp->config = 0x21 | (lp->timeout << 3) | (lp->backplane << 2);
116 /* set node ID to 0x42 (but transmitter is disabled, so it's okay) */
118 outb(0x42, ioaddr + BUS_ALIGN * 7);
122 if ((status & 0x99) != (NORXflag | TXFREEflag | RESETflag)) {
123 BUGMSG(D_NORMAL, "status invalid (%Xh).\n", status);
126 BUGMSG(D_INIT_REASONS, "status after reset: %X\n", status);
130 outb(inb(ioaddr + BUS_ALIGN * 8), ioaddr + BUS_ALIGN * 7);
132 ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear);
135 BUGMSG(D_INIT_REASONS, "status after reset acknowledged: %X\n",
138 /* Read first location of memory */
139 outb(0 | RDDATAflag | AUTOINCflag, _ADDR_HI);
142 if ((status = inb(_MEMDATA)) != TESTvalue) {
143 BUGMSG(D_NORMAL, "Signature byte not found (%02Xh != D1h).\n",
150 static int com20020_set_hwaddr(struct net_device *dev, void *addr)
152 int ioaddr = dev->base_addr;
153 struct arcnet_local *lp = netdev_priv(dev);
154 struct sockaddr *hwaddr = addr;
156 memcpy(dev->dev_addr, hwaddr->sa_data, 1);
157 SET_SUBADR(SUB_NODE);
158 outb(dev->dev_addr[0], _XREG);
163 const struct net_device_ops com20020_netdev_ops = {
164 .ndo_open = arcnet_open,
165 .ndo_stop = arcnet_close,
166 .ndo_start_xmit = arcnet_send_packet,
167 .ndo_tx_timeout = arcnet_timeout,
168 .ndo_set_mac_address = com20020_set_hwaddr,
169 .ndo_set_rx_mode = com20020_set_mc_list,
172 /* Set up the struct net_device associated with this card. Called after
175 int com20020_found(struct net_device *dev, int shared)
177 struct arcnet_local *lp;
178 int ioaddr = dev->base_addr;
180 /* Initialize the rest of the device structure. */
182 lp = netdev_priv(dev);
184 lp->hw.owner = THIS_MODULE;
185 lp->hw.command = com20020_command;
186 lp->hw.status = com20020_status;
187 lp->hw.intmask = com20020_setmask;
188 lp->hw.reset = com20020_reset;
189 lp->hw.copy_to_card = com20020_copy_to_card;
190 lp->hw.copy_from_card = com20020_copy_from_card;
191 lp->hw.close = com20020_close;
193 if (!dev->dev_addr[0])
194 dev->dev_addr[0] = inb(ioaddr + BUS_ALIGN * 8); /* FIXME: do this some other way! */
196 SET_SUBADR(SUB_SETUP1);
197 outb(lp->setup, _XREG);
199 if (lp->card_flags & ARC_CAN_10MBIT) {
200 SET_SUBADR(SUB_SETUP2);
201 outb(lp->setup2, _XREG);
203 /* must now write the magic "restart operation" command */
205 outb(0x18, _COMMAND);
208 lp->config = 0x20 | (lp->timeout << 3) | (lp->backplane << 2) | 1;
209 /* Default 0x38 + register: Node ID */
211 outb(dev->dev_addr[0], _XREG);
213 /* reserve the irq */
214 if (request_irq(dev->irq, arcnet_interrupt, shared,
215 "arcnet (COM20020)", dev)) {
216 BUGMSG(D_NORMAL, "Can't get IRQ %d!\n", dev->irq);
220 dev->base_addr = ioaddr;
222 BUGMSG(D_NORMAL, "%s: station %02Xh found at %03lXh, IRQ %d.\n",
223 lp->card_name, dev->dev_addr[0], dev->base_addr, dev->irq);
226 BUGMSG(D_NORMAL, "Using backplane mode.\n");
228 if (lp->timeout != 3)
229 BUGMSG(D_NORMAL, "Using extended timeout value of %d.\n", lp->timeout);
231 BUGMSG(D_NORMAL, "Using CKP %d - data rate %s.\n",
233 clockrates[3 - ((lp->setup2 & 0xF0) >> 4) + ((lp->setup & 0x0F) >> 1)]);
235 if (register_netdev(dev)) {
236 free_irq(dev->irq, dev);
243 * Do a hardware reset on the card, and set up necessary registers.
245 * This should be called as little as possible, because it disrupts the
246 * token on the network (causes a RECON) and requires a significant delay.
248 * However, it does make sure the card is in a defined state.
250 static int com20020_reset(struct net_device *dev, int really_reset)
252 struct arcnet_local *lp = netdev_priv(dev);
253 u_int ioaddr = dev->base_addr;
256 BUGMSG(D_DEBUG, "%s: %d: %s: dev: %p, lp: %p, dev->name: %s\n",
257 __FILE__, __LINE__, __func__, dev, lp, dev->name);
258 BUGMSG(D_INIT, "Resetting %s (status=%02Xh)\n",
259 dev->name, ASTATUS());
261 BUGMSG(D_DEBUG, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
262 lp->config = TXENcfg | (lp->timeout << 3) | (lp->backplane << 2);
263 /* power-up defaults */
265 BUGMSG(D_DEBUG, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
270 mdelay(RESETtime * 2); /* COM20020 seems to be slower sometimes */
272 /* clear flags & end reset */
273 BUGMSG(D_DEBUG, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
274 ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear);
276 /* verify that the ARCnet signature byte is present */
277 BUGMSG(D_DEBUG, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
279 com20020_copy_from_card(dev, 0, 0, &inbyte, 1);
280 BUGMSG(D_DEBUG, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
281 if (inbyte != TESTvalue) {
282 BUGMSG(D_DEBUG, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
283 BUGMSG(D_NORMAL, "reset failed: TESTvalue not present.\n");
286 /* enable extended (512-byte) packets */
287 ACOMMAND(CONFIGcmd | EXTconf);
288 BUGMSG(D_DEBUG, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
290 /* done! return success. */
294 static void com20020_setmask(struct net_device *dev, int mask)
296 u_int ioaddr = dev->base_addr;
298 BUGMSG(D_DURING, "Setting mask to %x at %x\n", mask, ioaddr);
302 static void com20020_command(struct net_device *dev, int cmd)
304 u_int ioaddr = dev->base_addr;
309 static int com20020_status(struct net_device *dev)
311 u_int ioaddr = dev->base_addr;
313 return ASTATUS() + (ADIAGSTATUS() << 8);
316 static void com20020_close(struct net_device *dev)
318 struct arcnet_local *lp = netdev_priv(dev);
319 int ioaddr = dev->base_addr;
321 /* disable transmitter */
322 lp->config &= ~TXENcfg;
326 /* Set or clear the multicast filter for this adaptor.
327 * num_addrs == -1 Promiscuous mode, receive all packets
328 * num_addrs == 0 Normal mode, clear multicast list
329 * num_addrs > 0 Multicast mode, receive normal and MC packets, and do
330 * best-effort filtering.
331 * FIXME - do multicast stuff, not just promiscuous.
333 static void com20020_set_mc_list(struct net_device *dev)
335 struct arcnet_local *lp = netdev_priv(dev);
336 int ioaddr = dev->base_addr;
338 if ((dev->flags & IFF_PROMISC) && (dev->flags & IFF_UP)) { /* Enable promiscuous mode */
339 if (!(lp->setup & PROMISCset))
340 BUGMSG(D_NORMAL, "Setting promiscuous flag...\n");
341 SET_SUBADR(SUB_SETUP1);
342 lp->setup |= PROMISCset;
343 outb(lp->setup, _XREG);
345 /* Disable promiscuous mode, use normal mode */
347 if ((lp->setup & PROMISCset))
348 BUGMSG(D_NORMAL, "Resetting promiscuous flag...\n");
349 SET_SUBADR(SUB_SETUP1);
350 lp->setup &= ~PROMISCset;
351 outb(lp->setup, _XREG);
355 #if defined(CONFIG_ARCNET_COM20020_PCI_MODULE) || \
356 defined(CONFIG_ARCNET_COM20020_ISA_MODULE) || \
357 defined(CONFIG_ARCNET_COM20020_CS_MODULE)
358 EXPORT_SYMBOL(com20020_check);
359 EXPORT_SYMBOL(com20020_found);
360 EXPORT_SYMBOL(com20020_netdev_ops);
363 MODULE_LICENSE("GPL");
367 static int __init com20020_module_init(void)
369 BUGLVL(D_NORMAL) printk(VERSION);
373 static void __exit com20020_module_exit(void)
376 module_init(com20020_module_init);
377 module_exit(com20020_module_exit);