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>
42 #include "arcdevice.h"
45 static const char * const clockrates
[] = {
46 "XXXXXXX", "XXXXXXXX", "XXXXXX", "2.5 Mb/s",
47 "1.25Mb/s", "625 Kb/s", "312.5 Kb/s", "156.25 Kb/s",
48 "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 arcnet_outb((ofs
>> 8) | RDDATAflag
| AUTOINCflag
,
69 ioaddr
, COM20020_REG_W_ADDR_HI
);
70 arcnet_outb(ofs
& 0xff, ioaddr
, COM20020_REG_W_ADDR_LO
);
73 TIME(dev
, "insb", count
,
74 arcnet_insb(ioaddr
, COM20020_REG_RW_MEMDATA
, buf
, count
));
77 static void com20020_copy_to_card(struct net_device
*dev
, int bufnum
,
78 int offset
, void *buf
, int count
)
80 int ioaddr
= dev
->base_addr
, ofs
= 512 * bufnum
+ offset
;
82 /* set up the address register */
83 arcnet_outb((ofs
>> 8) | AUTOINCflag
, ioaddr
, COM20020_REG_W_ADDR_HI
);
84 arcnet_outb(ofs
& 0xff, ioaddr
, COM20020_REG_W_ADDR_LO
);
87 TIME(dev
, "outsb", count
,
88 arcnet_outsb(ioaddr
, COM20020_REG_RW_MEMDATA
, buf
, count
));
91 /* Reset the card and check some basic stuff during the detection stage. */
92 int com20020_check(struct net_device
*dev
)
94 int ioaddr
= dev
->base_addr
, status
;
95 struct arcnet_local
*lp
= netdev_priv(dev
);
97 arcnet_outb(XTOcfg(3) | RESETcfg
, ioaddr
, COM20020_REG_W_CONFIG
);
99 arcnet_outb(XTOcfg(3), ioaddr
, COM20020_REG_W_CONFIG
);
102 lp
->setup
= lp
->clockm
? 0 : (lp
->clockp
<< 1);
103 lp
->setup2
= (lp
->clockm
<< 4) | 8;
105 /* CHECK: should we do this for SOHARD cards ? */
106 /* Enable P1Mode for backplane mode */
107 lp
->setup
= lp
->setup
| P1MODE
;
109 com20020_set_subaddress(lp
, ioaddr
, SUB_SETUP1
);
110 arcnet_outb(lp
->setup
, ioaddr
, COM20020_REG_W_XREG
);
112 if (lp
->clockm
!= 0) {
113 com20020_set_subaddress(lp
, ioaddr
, SUB_SETUP2
);
114 arcnet_outb(lp
->setup2
, ioaddr
, COM20020_REG_W_XREG
);
116 /* must now write the magic "restart operation" command */
118 arcnet_outb(STARTIOcmd
, ioaddr
, COM20020_REG_W_COMMAND
);
121 lp
->config
= TXENcfg
| (lp
->timeout
<< 3) | (lp
->backplane
<< 2) | SUB_NODE
;
122 /* set node ID to 0x42 (but transmitter is disabled, so it's okay) */
123 arcnet_outb(lp
->config
, ioaddr
, COM20020_REG_W_CONFIG
);
124 arcnet_outb(0x42, ioaddr
, COM20020_REG_W_XREG
);
126 status
= arcnet_inb(ioaddr
, COM20020_REG_R_STATUS
);
128 if ((status
& 0x99) != (NORXflag
| TXFREEflag
| RESETflag
)) {
129 arc_printk(D_NORMAL
, dev
, "status invalid (%Xh).\n", status
);
132 arc_printk(D_INIT_REASONS
, dev
, "status after reset: %X\n", status
);
135 lp
->config
|= TXENcfg
;
136 arcnet_outb(lp
->config
, ioaddr
, COM20020_REG_W_CONFIG
);
137 arcnet_outb(arcnet_inb(ioaddr
, 8), ioaddr
, COM20020_REG_W_XREG
);
139 arcnet_outb(CFLAGScmd
| RESETclear
| CONFIGclear
,
140 ioaddr
, COM20020_REG_W_COMMAND
);
141 status
= arcnet_inb(ioaddr
, COM20020_REG_R_STATUS
);
142 arc_printk(D_INIT_REASONS
, dev
, "status after reset acknowledged: %X\n",
145 /* Read first location of memory */
146 arcnet_outb(0 | RDDATAflag
| AUTOINCflag
,
147 ioaddr
, COM20020_REG_W_ADDR_HI
);
148 arcnet_outb(0, ioaddr
, COM20020_REG_W_ADDR_LO
);
150 status
= arcnet_inb(ioaddr
, COM20020_REG_RW_MEMDATA
);
151 if (status
!= TESTvalue
) {
152 arc_printk(D_NORMAL
, dev
, "Signature byte not found (%02Xh != D1h).\n",
159 static int com20020_set_hwaddr(struct net_device
*dev
, void *addr
)
161 int ioaddr
= dev
->base_addr
;
162 struct arcnet_local
*lp
= netdev_priv(dev
);
163 struct sockaddr
*hwaddr
= addr
;
165 memcpy(dev
->dev_addr
, hwaddr
->sa_data
, 1);
166 com20020_set_subaddress(lp
, ioaddr
, SUB_NODE
);
167 arcnet_outb(dev
->dev_addr
[0], ioaddr
, COM20020_REG_W_XREG
);
172 const struct net_device_ops com20020_netdev_ops
= {
173 .ndo_open
= arcnet_open
,
174 .ndo_stop
= arcnet_close
,
175 .ndo_start_xmit
= arcnet_send_packet
,
176 .ndo_tx_timeout
= arcnet_timeout
,
177 .ndo_set_mac_address
= com20020_set_hwaddr
,
178 .ndo_set_rx_mode
= com20020_set_mc_list
,
181 /* Set up the struct net_device associated with this card. Called after
184 int com20020_found(struct net_device
*dev
, int shared
)
186 struct arcnet_local
*lp
;
187 int ioaddr
= dev
->base_addr
;
189 /* Initialize the rest of the device structure. */
191 lp
= netdev_priv(dev
);
193 lp
->hw
.owner
= THIS_MODULE
;
194 lp
->hw
.command
= com20020_command
;
195 lp
->hw
.status
= com20020_status
;
196 lp
->hw
.intmask
= com20020_setmask
;
197 lp
->hw
.reset
= com20020_reset
;
198 lp
->hw
.copy_to_card
= com20020_copy_to_card
;
199 lp
->hw
.copy_from_card
= com20020_copy_from_card
;
200 lp
->hw
.close
= com20020_close
;
202 /* FIXME: do this some other way! */
203 if (!dev
->dev_addr
[0])
204 dev
->dev_addr
[0] = arcnet_inb(ioaddr
, 8);
206 com20020_set_subaddress(lp
, ioaddr
, SUB_SETUP1
);
207 arcnet_outb(lp
->setup
, ioaddr
, COM20020_REG_W_XREG
);
209 if (lp
->card_flags
& ARC_CAN_10MBIT
) {
210 com20020_set_subaddress(lp
, ioaddr
, SUB_SETUP2
);
211 arcnet_outb(lp
->setup2
, ioaddr
, COM20020_REG_W_XREG
);
213 /* must now write the magic "restart operation" command */
215 arcnet_outb(STARTIOcmd
, ioaddr
, COM20020_REG_W_COMMAND
);
218 lp
->config
= TXENcfg
| (lp
->timeout
<< 3) | (lp
->backplane
<< 2) | SUB_NODE
;
219 /* Default 0x38 + register: Node ID */
220 arcnet_outb(lp
->config
, ioaddr
, COM20020_REG_W_CONFIG
);
221 arcnet_outb(dev
->dev_addr
[0], ioaddr
, COM20020_REG_W_XREG
);
223 /* reserve the irq */
224 if (request_irq(dev
->irq
, arcnet_interrupt
, shared
,
225 "arcnet (COM20020)", dev
)) {
226 arc_printk(D_NORMAL
, dev
, "Can't get IRQ %d!\n", dev
->irq
);
230 dev
->base_addr
= ioaddr
;
232 arc_printk(D_NORMAL
, dev
, "%s: station %02Xh found at %03lXh, IRQ %d.\n",
233 lp
->card_name
, dev
->dev_addr
[0], dev
->base_addr
, dev
->irq
);
236 arc_printk(D_NORMAL
, dev
, "Using backplane mode.\n");
238 if (lp
->timeout
!= 3)
239 arc_printk(D_NORMAL
, dev
, "Using extended timeout value of %d\n",
242 arc_printk(D_NORMAL
, dev
, "Using CKP %d - data rate %s\n",
245 ((lp
->setup2
& 0xF0) >> 4) +
246 ((lp
->setup
& 0x0F) >> 1)]);
247 /* The clockrates array index looks very fragile.
248 * It seems like it could have negative indexing.
251 if (register_netdev(dev
)) {
252 free_irq(dev
->irq
, dev
);
258 /* Do a hardware reset on the card, and set up necessary registers.
260 * This should be called as little as possible, because it disrupts the
261 * token on the network (causes a RECON) and requires a significant delay.
263 * However, it does make sure the card is in a defined state.
265 static int com20020_reset(struct net_device
*dev
, int really_reset
)
267 struct arcnet_local
*lp
= netdev_priv(dev
);
268 u_int ioaddr
= dev
->base_addr
;
271 arc_printk(D_DEBUG
, dev
, "%s: %d: %s: dev: %p, lp: %p, dev->name: %s\n",
272 __FILE__
, __LINE__
, __func__
, dev
, lp
, dev
->name
);
273 arc_printk(D_INIT
, dev
, "Resetting %s (status=%02Xh)\n",
274 dev
->name
, arcnet_inb(ioaddr
, COM20020_REG_R_STATUS
));
276 arc_printk(D_DEBUG
, dev
, "%s: %d: %s\n", __FILE__
, __LINE__
, __func__
);
277 lp
->config
= TXENcfg
| (lp
->timeout
<< 3) | (lp
->backplane
<< 2);
278 /* power-up defaults */
279 arcnet_outb(lp
->config
, ioaddr
, COM20020_REG_W_CONFIG
);
280 arc_printk(D_DEBUG
, dev
, "%s: %d: %s\n", __FILE__
, __LINE__
, __func__
);
284 arcnet_outb(lp
->config
| RESETcfg
, ioaddr
, COM20020_REG_W_CONFIG
);
286 arcnet_outb(lp
->config
, ioaddr
, COM20020_REG_W_CONFIG
);
287 mdelay(RESETtime
* 2);
288 /* COM20020 seems to be slower sometimes */
290 /* clear flags & end reset */
291 arc_printk(D_DEBUG
, dev
, "%s: %d: %s\n", __FILE__
, __LINE__
, __func__
);
292 arcnet_outb(CFLAGScmd
| RESETclear
| CONFIGclear
,
293 ioaddr
, COM20020_REG_W_COMMAND
);
295 /* verify that the ARCnet signature byte is present */
296 arc_printk(D_DEBUG
, dev
, "%s: %d: %s\n", __FILE__
, __LINE__
, __func__
);
298 com20020_copy_from_card(dev
, 0, 0, &inbyte
, 1);
299 arc_printk(D_DEBUG
, dev
, "%s: %d: %s\n", __FILE__
, __LINE__
, __func__
);
300 if (inbyte
!= TESTvalue
) {
301 arc_printk(D_DEBUG
, dev
, "%s: %d: %s\n",
302 __FILE__
, __LINE__
, __func__
);
303 arc_printk(D_NORMAL
, dev
, "reset failed: TESTvalue not present.\n");
306 /* enable extended (512-byte) packets */
307 arcnet_outb(CONFIGcmd
| EXTconf
, ioaddr
, COM20020_REG_W_COMMAND
);
309 arc_printk(D_DEBUG
, dev
, "%s: %d: %s\n", __FILE__
, __LINE__
, __func__
);
311 /* done! return success. */
315 static void com20020_setmask(struct net_device
*dev
, int mask
)
317 u_int ioaddr
= dev
->base_addr
;
319 arc_printk(D_DURING
, dev
, "Setting mask to %x at %x\n", mask
, ioaddr
);
320 arcnet_outb(mask
, ioaddr
, COM20020_REG_W_INTMASK
);
323 static void com20020_command(struct net_device
*dev
, int cmd
)
325 u_int ioaddr
= dev
->base_addr
;
327 arcnet_outb(cmd
, ioaddr
, COM20020_REG_W_COMMAND
);
330 static int com20020_status(struct net_device
*dev
)
332 u_int ioaddr
= dev
->base_addr
;
334 return arcnet_inb(ioaddr
, COM20020_REG_R_STATUS
) +
335 (arcnet_inb(ioaddr
, COM20020_REG_R_DIAGSTAT
) << 8);
338 static void com20020_close(struct net_device
*dev
)
340 struct arcnet_local
*lp
= netdev_priv(dev
);
341 int ioaddr
= dev
->base_addr
;
343 /* disable transmitter */
344 lp
->config
&= ~TXENcfg
;
345 arcnet_outb(lp
->config
, ioaddr
, COM20020_REG_W_CONFIG
);
348 /* Set or clear the multicast filter for this adaptor.
349 * num_addrs == -1 Promiscuous mode, receive all packets
350 * num_addrs == 0 Normal mode, clear multicast list
351 * num_addrs > 0 Multicast mode, receive normal and MC packets, and do
352 * best-effort filtering.
353 * FIXME - do multicast stuff, not just promiscuous.
355 static void com20020_set_mc_list(struct net_device
*dev
)
357 struct arcnet_local
*lp
= netdev_priv(dev
);
358 int ioaddr
= dev
->base_addr
;
360 if ((dev
->flags
& IFF_PROMISC
) && (dev
->flags
& IFF_UP
)) {
361 /* Enable promiscuous mode */
362 if (!(lp
->setup
& PROMISCset
))
363 arc_printk(D_NORMAL
, dev
, "Setting promiscuous flag...\n");
364 com20020_set_subaddress(lp
, ioaddr
, SUB_SETUP1
);
365 lp
->setup
|= PROMISCset
;
366 arcnet_outb(lp
->setup
, ioaddr
, COM20020_REG_W_XREG
);
368 /* Disable promiscuous mode, use normal mode */
369 if ((lp
->setup
& PROMISCset
))
370 arc_printk(D_NORMAL
, dev
, "Resetting promiscuous flag...\n");
371 com20020_set_subaddress(lp
, ioaddr
, SUB_SETUP1
);
372 lp
->setup
&= ~PROMISCset
;
373 arcnet_outb(lp
->setup
, ioaddr
, COM20020_REG_W_XREG
);
377 #if defined(CONFIG_ARCNET_COM20020_PCI_MODULE) || \
378 defined(CONFIG_ARCNET_COM20020_ISA_MODULE) || \
379 defined(CONFIG_ARCNET_COM20020_CS_MODULE)
380 EXPORT_SYMBOL(com20020_check
);
381 EXPORT_SYMBOL(com20020_found
);
382 EXPORT_SYMBOL(com20020_netdev_ops
);
385 MODULE_LICENSE("GPL");
389 static int __init
com20020_module_init(void)
391 if (BUGLVL(D_NORMAL
))
392 pr_info("%s\n", "COM20020 chipset support (by David Woodhouse et al.)");
396 static void __exit
com20020_module_exit(void)
399 module_init(com20020_module_init
);
400 module_exit(com20020_module_exit
);