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 * **********************
29 #define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
31 #include <linux/module.h>
32 #include <linux/kernel.h>
33 #include <linux/types.h>
34 #include <linux/ioport.h>
35 #include <linux/errno.h>
36 #include <linux/delay.h>
37 #include <linux/netdevice.h>
38 #include <linux/init.h>
39 #include <linux/interrupt.h>
40 #include <linux/arcdevice.h>
41 #include <linux/com20020.h>
45 static char *clockrates[] = {
46 "XXXXXXX", "XXXXXXXX", "XXXXXX",
47 "2.5 Mb/s", "1.25Mb/s", "625 Kb/s", "312.5 Kb/s",
48 "156.25 Kb/s", "Reserved", "Reserved", "Reserved"
51 static void com20020_command(struct net_device *dev, int command);
52 static int com20020_status(struct net_device *dev);
53 static void com20020_setmask(struct net_device *dev, int mask);
54 static int com20020_reset(struct net_device *dev, int really_reset);
55 static void com20020_copy_to_card(struct net_device *dev, int bufnum,
56 int offset, void *buf, int count);
57 static void com20020_copy_from_card(struct net_device *dev, int bufnum,
58 int offset, void *buf, int count);
59 static void com20020_set_mc_list(struct net_device *dev);
60 static void com20020_close(struct net_device *);
62 static void com20020_copy_from_card(struct net_device *dev, int bufnum,
63 int offset, void *buf, int count)
65 int ioaddr = dev->base_addr, ofs = 512 * bufnum + offset;
67 /* set up the address register */
68 outb((ofs >> 8) | RDDATAflag | AUTOINCflag, _ADDR_HI);
69 outb(ofs & 0xff, _ADDR_LO);
72 TIME(dev, "insb", count, insb(_MEMDATA, buf, count));
75 static void com20020_copy_to_card(struct net_device *dev, int bufnum,
76 int offset, void *buf, int count)
78 int ioaddr = dev->base_addr, ofs = 512 * bufnum + offset;
80 /* set up the address register */
81 outb((ofs >> 8) | AUTOINCflag, _ADDR_HI);
82 outb(ofs & 0xff, _ADDR_LO);
85 TIME(dev, "outsb", count, outsb(_MEMDATA, buf, count));
88 /* Reset the card and check some basic stuff during the detection stage. */
89 int com20020_check(struct net_device *dev)
91 int ioaddr = dev->base_addr, status;
92 struct arcnet_local *lp = netdev_priv(dev);
97 lp->setup = lp->clockm ? 0 : (lp->clockp << 1);
98 lp->setup2 = (lp->clockm << 4) | 8;
100 /* CHECK: should we do this for SOHARD cards ? */
101 /* Enable P1Mode for backplane mode */
102 lp->setup = lp->setup | P1MODE;
104 SET_SUBADR(SUB_SETUP1);
105 outb(lp->setup, _XREG);
107 if (lp->clockm != 0) {
108 SET_SUBADR(SUB_SETUP2);
109 outb(lp->setup2, _XREG);
111 /* must now write the magic "restart operation" command */
113 outb(0x18, _COMMAND);
116 lp->config = 0x21 | (lp->timeout << 3) | (lp->backplane << 2);
117 /* set node ID to 0x42 (but transmitter is disabled, so it's okay) */
119 outb(0x42, ioaddr + BUS_ALIGN * 7);
123 if ((status & 0x99) != (NORXflag | TXFREEflag | RESETflag)) {
124 arc_printk(D_NORMAL, dev, "status invalid (%Xh).\n", status);
127 arc_printk(D_INIT_REASONS, dev, "status after reset: %X\n", status);
131 outb(inb(ioaddr + BUS_ALIGN * 8), ioaddr + BUS_ALIGN * 7);
133 ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear);
136 arc_printk(D_INIT_REASONS, dev, "status after reset acknowledged: %X\n",
139 /* Read first location of memory */
140 outb(0 | RDDATAflag | AUTOINCflag, _ADDR_HI);
143 if ((status = inb(_MEMDATA)) != TESTvalue) {
144 arc_printk(D_NORMAL, dev, "Signature byte not found (%02Xh != D1h).\n",
151 static int com20020_set_hwaddr(struct net_device *dev, void *addr)
153 int ioaddr = dev->base_addr;
154 struct arcnet_local *lp = netdev_priv(dev);
155 struct sockaddr *hwaddr = addr;
157 memcpy(dev->dev_addr, hwaddr->sa_data, 1);
158 SET_SUBADR(SUB_NODE);
159 outb(dev->dev_addr[0], _XREG);
164 const struct net_device_ops com20020_netdev_ops = {
165 .ndo_open = arcnet_open,
166 .ndo_stop = arcnet_close,
167 .ndo_start_xmit = arcnet_send_packet,
168 .ndo_tx_timeout = arcnet_timeout,
169 .ndo_set_mac_address = com20020_set_hwaddr,
170 .ndo_set_rx_mode = com20020_set_mc_list,
173 /* Set up the struct net_device associated with this card. Called after
176 int com20020_found(struct net_device *dev, int shared)
178 struct arcnet_local *lp;
179 int ioaddr = dev->base_addr;
181 /* Initialize the rest of the device structure. */
183 lp = netdev_priv(dev);
185 lp->hw.owner = THIS_MODULE;
186 lp->hw.command = com20020_command;
187 lp->hw.status = com20020_status;
188 lp->hw.intmask = com20020_setmask;
189 lp->hw.reset = com20020_reset;
190 lp->hw.copy_to_card = com20020_copy_to_card;
191 lp->hw.copy_from_card = com20020_copy_from_card;
192 lp->hw.close = com20020_close;
194 if (!dev->dev_addr[0])
195 dev->dev_addr[0] = inb(ioaddr + BUS_ALIGN * 8); /* FIXME: do this some other way! */
197 SET_SUBADR(SUB_SETUP1);
198 outb(lp->setup, _XREG);
200 if (lp->card_flags & ARC_CAN_10MBIT) {
201 SET_SUBADR(SUB_SETUP2);
202 outb(lp->setup2, _XREG);
204 /* must now write the magic "restart operation" command */
206 outb(0x18, _COMMAND);
209 lp->config = 0x20 | (lp->timeout << 3) | (lp->backplane << 2) | 1;
210 /* Default 0x38 + register: Node ID */
212 outb(dev->dev_addr[0], _XREG);
214 /* reserve the irq */
215 if (request_irq(dev->irq, arcnet_interrupt, shared,
216 "arcnet (COM20020)", dev)) {
217 arc_printk(D_NORMAL, dev, "Can't get IRQ %d!\n", dev->irq);
221 dev->base_addr = ioaddr;
223 arc_printk(D_NORMAL, dev, "%s: station %02Xh found at %03lXh, IRQ %d.\n",
224 lp->card_name, dev->dev_addr[0], dev->base_addr, dev->irq);
227 arc_printk(D_NORMAL, dev, "Using backplane mode.\n");
229 if (lp->timeout != 3)
230 arc_printk(D_NORMAL, dev, "Using extended timeout value of %d\n",
233 arc_printk(D_NORMAL, dev, "Using CKP %d - data rate %s\n",
235 clockrates[3 - ((lp->setup2 & 0xF0) >> 4) + ((lp->setup & 0x0F) >> 1)]);
237 if (register_netdev(dev)) {
238 free_irq(dev->irq, dev);
244 /* Do a hardware reset on the card, and set up necessary registers.
246 * This should be called as little as possible, because it disrupts the
247 * token on the network (causes a RECON) and requires a significant delay.
249 * However, it does make sure the card is in a defined state.
251 static int com20020_reset(struct net_device *dev, int really_reset)
253 struct arcnet_local *lp = netdev_priv(dev);
254 u_int ioaddr = dev->base_addr;
257 arc_printk(D_DEBUG, dev, "%s: %d: %s: dev: %p, lp: %p, dev->name: %s\n",
258 __FILE__, __LINE__, __func__, dev, lp, dev->name);
259 arc_printk(D_INIT, dev, "Resetting %s (status=%02Xh)\n",
260 dev->name, ASTATUS());
262 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
263 lp->config = TXENcfg | (lp->timeout << 3) | (lp->backplane << 2);
264 /* power-up defaults */
266 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
271 mdelay(RESETtime * 2); /* COM20020 seems to be slower sometimes */
273 /* clear flags & end reset */
274 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
275 ACOMMAND(CFLAGScmd | RESETclear | CONFIGclear);
277 /* verify that the ARCnet signature byte is present */
278 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
280 com20020_copy_from_card(dev, 0, 0, &inbyte, 1);
281 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
282 if (inbyte != TESTvalue) {
283 arc_printk(D_DEBUG, dev, "%s: %d: %s\n",
284 __FILE__, __LINE__, __func__);
285 arc_printk(D_NORMAL, dev, "reset failed: TESTvalue not present.\n");
288 /* enable extended (512-byte) packets */
289 ACOMMAND(CONFIGcmd | EXTconf);
290 arc_printk(D_DEBUG, dev, "%s: %d: %s\n", __FILE__, __LINE__, __func__);
292 /* done! return success. */
296 static void com20020_setmask(struct net_device *dev, int mask)
298 u_int ioaddr = dev->base_addr;
300 arc_printk(D_DURING, dev, "Setting mask to %x at %x\n", mask, ioaddr);
304 static void com20020_command(struct net_device *dev, int cmd)
306 u_int ioaddr = dev->base_addr;
311 static int com20020_status(struct net_device *dev)
313 u_int ioaddr = dev->base_addr;
315 return ASTATUS() + (ADIAGSTATUS() << 8);
318 static void com20020_close(struct net_device *dev)
320 struct arcnet_local *lp = netdev_priv(dev);
321 int ioaddr = dev->base_addr;
323 /* disable transmitter */
324 lp->config &= ~TXENcfg;
328 /* Set or clear the multicast filter for this adaptor.
329 * num_addrs == -1 Promiscuous mode, receive all packets
330 * num_addrs == 0 Normal mode, clear multicast list
331 * num_addrs > 0 Multicast mode, receive normal and MC packets, and do
332 * best-effort filtering.
333 * FIXME - do multicast stuff, not just promiscuous.
335 static void com20020_set_mc_list(struct net_device *dev)
337 struct arcnet_local *lp = netdev_priv(dev);
338 int ioaddr = dev->base_addr;
340 if ((dev->flags & IFF_PROMISC) && (dev->flags & IFF_UP)) { /* Enable promiscuous mode */
341 if (!(lp->setup & PROMISCset))
342 arc_printk(D_NORMAL, dev, "Setting promiscuous flag...\n");
343 SET_SUBADR(SUB_SETUP1);
344 lp->setup |= PROMISCset;
345 outb(lp->setup, _XREG);
347 /* Disable promiscuous mode, use normal mode */
349 if ((lp->setup & PROMISCset))
350 arc_printk(D_NORMAL, dev, "Resetting promiscuous flag...\n");
351 SET_SUBADR(SUB_SETUP1);
352 lp->setup &= ~PROMISCset;
353 outb(lp->setup, _XREG);
357 #if defined(CONFIG_ARCNET_COM20020_PCI_MODULE) || \
358 defined(CONFIG_ARCNET_COM20020_ISA_MODULE) || \
359 defined(CONFIG_ARCNET_COM20020_CS_MODULE)
360 EXPORT_SYMBOL(com20020_check);
361 EXPORT_SYMBOL(com20020_found);
362 EXPORT_SYMBOL(com20020_netdev_ops);
365 MODULE_LICENSE("GPL");
369 static int __init com20020_module_init(void)
371 if (BUGLVL(D_NORMAL))
372 pr_info("%s\n", "COM20020 chipset support (by David Woodhouse et al.)\n");
376 static void __exit com20020_module_exit(void)
379 module_init(com20020_module_init);
380 module_exit(com20020_module_exit);