Linux Audio

Check our new training course

Loading...
v6.13.7
  1/*
  2 * Linux ARCnet driver - "RIM I" (entirely mem-mapped) cards
  3 *
  4 * Written 1994-1999 by Avery Pennarun.
  5 * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
  6 * Derived from skeleton.c by Donald Becker.
  7 *
  8 * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
  9 *  for sponsoring the further development of this driver.
 10 *
 11 * **********************
 12 *
 13 * The original copyright of skeleton.c was as follows:
 14 *
 15 * skeleton.c Written 1993 by Donald Becker.
 16 * Copyright 1993 United States Government as represented by the
 17 * Director, National Security Agency.  This software may only be used
 18 * and distributed according to the terms of the GNU General Public License as
 19 * modified by SRC, incorporated herein by reference.
 20 *
 21 * **********************
 22 *
 23 * For more details, see drivers/net/arcnet.c
 24 *
 25 * **********************
 26 */
 27
 28#define pr_fmt(fmt) "arcnet:" KBUILD_MODNAME ": " fmt
 29
 30#include <linux/kernel.h>
 31#include <linux/module.h>
 32#include <linux/moduleparam.h>
 33#include <linux/ioport.h>
 34#include <linux/delay.h>
 35#include <linux/netdevice.h>
 36#include <linux/memblock.h>
 37#include <linux/init.h>
 38#include <linux/interrupt.h>
 39#include <linux/io.h>
 
 
 
 
 40
 41#include "arcdevice.h"
 42#include "com9026.h"
 43
 44/* Internal function declarations */
 45
 46static int arcrimi_probe(struct net_device *dev);
 47static int arcrimi_found(struct net_device *dev);
 48static void arcrimi_command(struct net_device *dev, int command);
 49static int arcrimi_status(struct net_device *dev);
 50static void arcrimi_setmask(struct net_device *dev, int mask);
 51static int arcrimi_reset(struct net_device *dev, int really_reset);
 52static void arcrimi_copy_to_card(struct net_device *dev, int bufnum, int offset,
 53				 void *buf, int count);
 54static void arcrimi_copy_from_card(struct net_device *dev, int bufnum,
 55				   int offset, void *buf, int count);
 56
 57/* Handy defines for ARCnet specific stuff */
 58
 59/* Amount of I/O memory used by the card */
 60#define BUFFER_SIZE	(512)
 61#define MIRROR_SIZE	(BUFFER_SIZE * 4)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 62
 63/* We cannot probe for a RIM I card; one reason is I don't know how to reset
 
 64 * them.  In fact, we can't even get their node ID automatically.  So, we
 65 * need to be passed a specific shmem address, IRQ, and node ID.
 66 */
 67static int __init arcrimi_probe(struct net_device *dev)
 68{
 69	if (BUGLVL(D_NORMAL)) {
 70		pr_info("%s\n", "RIM I (entirely mem-mapped) support");
 71		pr_info("E-mail me if you actually test the RIM I driver, please!\n");
 72		pr_info("Given: node %02Xh, shmem %lXh, irq %d\n",
 73			dev->dev_addr[0], dev->mem_start, dev->irq);
 74	}
 75
 76	if (dev->mem_start <= 0 || dev->irq <= 0) {
 77		if (BUGLVL(D_NORMAL))
 78			pr_err("No autoprobe for RIM I; you must specify the shmem and irq!\n");
 79		return -ENODEV;
 80	}
 81	if (dev->dev_addr[0] == 0) {
 82		if (BUGLVL(D_NORMAL))
 83			pr_err("You need to specify your card's station ID!\n");
 84		return -ENODEV;
 85	}
 86	/* Grab the memory region at mem_start for MIRROR_SIZE bytes.
 
 87	 * Later in arcrimi_found() the real size will be determined
 88	 * and this reserve will be released and the correct size
 89	 * will be taken.
 90	 */
 91	if (!request_mem_region(dev->mem_start, MIRROR_SIZE, "arcnet (90xx)")) {
 92		if (BUGLVL(D_NORMAL))
 93			pr_notice("Card memory already allocated\n");
 94		return -ENODEV;
 95	}
 96	return arcrimi_found(dev);
 97}
 98
 99static int check_mirror(unsigned long addr, size_t size)
100{
101	void __iomem *p;
102	int res = -1;
103
104	if (!request_mem_region(addr, size, "arcnet (90xx)"))
105		return -1;
106
107	p = ioremap(addr, size);
108	if (p) {
109		if (arcnet_readb(p, COM9026_REG_R_STATUS) == TESTvalue)
110			res = 1;
111		else
112			res = 0;
113		iounmap(p);
114	}
115
116	release_mem_region(addr, size);
117	return res;
118}
119
120/* Set up the struct net_device associated with this card.
121 * Called after probing succeeds.
 
122 */
123static int __init arcrimi_found(struct net_device *dev)
124{
125	struct arcnet_local *lp;
126	unsigned long first_mirror, last_mirror, shmem;
127	void __iomem *p;
128	int mirror_size;
129	int err;
130
131	p = ioremap(dev->mem_start, MIRROR_SIZE);
132	if (!p) {
133		release_mem_region(dev->mem_start, MIRROR_SIZE);
134		arc_printk(D_NORMAL, dev, "Can't ioremap\n");
135		return -ENODEV;
136	}
137
138	/* reserve the irq */
139	if (request_irq(dev->irq, arcnet_interrupt, 0, "arcnet (RIM I)", dev)) {
140		iounmap(p);
141		release_mem_region(dev->mem_start, MIRROR_SIZE);
142		arc_printk(D_NORMAL, dev, "Can't get IRQ %d!\n", dev->irq);
143		return -ENODEV;
144	}
145
146	shmem = dev->mem_start;
147	arcnet_writeb(TESTvalue, p, COM9026_REG_W_INTMASK);
148	arcnet_writeb(TESTvalue, p, COM9026_REG_W_COMMAND);
149					/* actually the station/node ID */
150
151	/* find the real shared memory start/end points, including mirrors */
152
153	/* guess the actual size of one "memory mirror" - the number of
154	 * bytes between copies of the shared memory.  On most cards, it's
155	 * 2k (or there are no mirrors at all) but on some, it's 4k.
156	 */
157	mirror_size = MIRROR_SIZE;
158	if (arcnet_readb(p, COM9026_REG_R_STATUS) == TESTvalue &&
159	    check_mirror(shmem - MIRROR_SIZE, MIRROR_SIZE) == 0 &&
160	    check_mirror(shmem - 2 * MIRROR_SIZE, MIRROR_SIZE) == 1)
161		mirror_size = 2 * MIRROR_SIZE;
162
163	first_mirror = shmem - mirror_size;
164	while (check_mirror(first_mirror, mirror_size) == 1)
165		first_mirror -= mirror_size;
166	first_mirror += mirror_size;
167
168	last_mirror = shmem + mirror_size;
169	while (check_mirror(last_mirror, mirror_size) == 1)
170		last_mirror += mirror_size;
171	last_mirror -= mirror_size;
172
173	dev->mem_start = first_mirror;
174	dev->mem_end = last_mirror + MIRROR_SIZE - 1;
175
176	/* initialize the rest of the device structure. */
177
178	lp = netdev_priv(dev);
179	lp->card_name = "RIM I";
180	lp->hw.command = arcrimi_command;
181	lp->hw.status = arcrimi_status;
182	lp->hw.intmask = arcrimi_setmask;
183	lp->hw.reset = arcrimi_reset;
184	lp->hw.owner = THIS_MODULE;
185	lp->hw.copy_to_card = arcrimi_copy_to_card;
186	lp->hw.copy_from_card = arcrimi_copy_from_card;
187
188	/* re-reserve the memory region - arcrimi_probe() alloced this reqion
 
189	 * but didn't know the real size.  Free that region and then re-get
190	 * with the correct size.  There is a VERY slim chance this could
191	 * fail.
192	 */
193	iounmap(p);
194	release_mem_region(shmem, MIRROR_SIZE);
195	if (!request_mem_region(dev->mem_start,
196				dev->mem_end - dev->mem_start + 1,
197				"arcnet (90xx)")) {
198		arc_printk(D_NORMAL, dev, "Card memory already allocated\n");
199		goto err_free_irq;
200	}
201
202	lp->mem_start = ioremap(dev->mem_start,
203				dev->mem_end - dev->mem_start + 1);
204	if (!lp->mem_start) {
205		arc_printk(D_NORMAL, dev, "Can't remap device memory!\n");
206		goto err_release_mem;
207	}
208
209	/* get and check the station ID from offset 1 in shmem */
210	arcnet_set_addr(dev, arcnet_readb(lp->mem_start,
211					  COM9026_REG_R_STATION));
212
213	arc_printk(D_NORMAL, dev, "ARCnet RIM I: station %02Xh found at IRQ %d, ShMem %lXh (%ld*%d bytes)\n",
214		   dev->dev_addr[0],
215		   dev->irq, dev->mem_start,
216		   (dev->mem_end - dev->mem_start + 1) / mirror_size,
217		   mirror_size);
218
219	err = register_netdev(dev);
220	if (err)
221		goto err_unmap;
222
223	return 0;
224
225err_unmap:
226	iounmap(lp->mem_start);
227err_release_mem:
228	release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1);
229err_free_irq:
230	free_irq(dev->irq, dev);
231	return -EIO;
232}
233
234/* Do a hardware reset on the card, and set up necessary registers.
 
 
235 *
236 * This should be called as little as possible, because it disrupts the
237 * token on the network (causes a RECON) and requires a significant delay.
238 *
239 * However, it does make sure the card is in a defined state.
240 */
241static int arcrimi_reset(struct net_device *dev, int really_reset)
242{
243	struct arcnet_local *lp = netdev_priv(dev);
244	void __iomem *ioaddr = lp->mem_start + 0x800;
245
246	arc_printk(D_INIT, dev, "Resetting %s (status=%02Xh)\n",
247		   dev->name, arcnet_readb(ioaddr, COM9026_REG_R_STATUS));
248
249	if (really_reset) {
250		arcnet_writeb(TESTvalue, ioaddr, -0x800);	/* fake reset */
251		return 0;
252	}
253	/* clear flags & end reset */
254	arcnet_writeb(CFLAGScmd | RESETclear, ioaddr, COM9026_REG_W_COMMAND);
255	arcnet_writeb(CFLAGScmd | CONFIGclear, ioaddr, COM9026_REG_W_COMMAND);
256
257	/* enable extended (512-byte) packets */
258	arcnet_writeb(CONFIGcmd | EXTconf, ioaddr, COM9026_REG_W_COMMAND);
259
260	/* done!  return success. */
261	return 0;
262}
263
264static void arcrimi_setmask(struct net_device *dev, int mask)
265{
266	struct arcnet_local *lp = netdev_priv(dev);
267	void __iomem *ioaddr = lp->mem_start + 0x800;
268
269	arcnet_writeb(mask, ioaddr, COM9026_REG_W_INTMASK);
270}
271
272static int arcrimi_status(struct net_device *dev)
273{
274	struct arcnet_local *lp = netdev_priv(dev);
275	void __iomem *ioaddr = lp->mem_start + 0x800;
276
277	return arcnet_readb(ioaddr, COM9026_REG_R_STATUS);
278}
279
280static void arcrimi_command(struct net_device *dev, int cmd)
281{
282	struct arcnet_local *lp = netdev_priv(dev);
283	void __iomem *ioaddr = lp->mem_start + 0x800;
284
285	arcnet_writeb(cmd, ioaddr, COM9026_REG_W_COMMAND);
286}
287
288static void arcrimi_copy_to_card(struct net_device *dev, int bufnum, int offset,
289				 void *buf, int count)
290{
291	struct arcnet_local *lp = netdev_priv(dev);
292	void __iomem *memaddr = lp->mem_start + 0x800 + bufnum * 512 + offset;
293
294	TIME(dev, "memcpy_toio", count, memcpy_toio(memaddr, buf, count));
295}
296
297static void arcrimi_copy_from_card(struct net_device *dev, int bufnum,
298				   int offset, void *buf, int count)
 
299{
300	struct arcnet_local *lp = netdev_priv(dev);
301	void __iomem *memaddr = lp->mem_start + 0x800 + bufnum * 512 + offset;
302
303	TIME(dev, "memcpy_fromio", count, memcpy_fromio(buf, memaddr, count));
304}
305
306static int node;
307static int io;			/* use the insmod io= irq= node= options */
308static int irq;
309static char device[9];		/* use eg. device=arc1 to change name */
310
311module_param(node, int, 0);
312module_param(io, int, 0);
313module_param(irq, int, 0);
314module_param_string(device, device, sizeof(device), 0);
315MODULE_DESCRIPTION("ARCnet COM90xx RIM I chipset driver");
316MODULE_LICENSE("GPL");
317
318static struct net_device *my_dev;
319
320static int __init arc_rimi_init(void)
321{
322	struct net_device *dev;
323
324	dev = alloc_arcdev(device);
325	if (!dev)
326		return -ENOMEM;
327
328	if (node && node != 0xff)
329		arcnet_set_addr(dev, node);
330
331	dev->mem_start = io;
332	dev->irq = irq;
333	if (dev->irq == 2)
334		dev->irq = 9;
335
336	if (arcrimi_probe(dev)) {
337		free_arcdev(dev);
338		return -EIO;
339	}
340
341	my_dev = dev;
342	return 0;
343}
344
345static void __exit arc_rimi_exit(void)
346{
347	struct net_device *dev = my_dev;
348	struct arcnet_local *lp = netdev_priv(dev);
349
350	unregister_netdev(dev);
351	iounmap(lp->mem_start);
352	release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1);
353	free_irq(dev->irq, dev);
354	free_arcdev(dev);
355}
356
357#ifndef MODULE
358static int __init arcrimi_setup(char *s)
359{
360	int ints[8];
361
362	s = get_options(s, 8, ints);
363	if (!ints[0])
364		return 1;
365	switch (ints[0]) {
366	default:		/* ERROR */
367		pr_err("Too many arguments\n");
368		fallthrough;
369	case 3:		/* Node ID */
370		node = ints[3];
371		fallthrough;
372	case 2:		/* IRQ */
373		irq = ints[2];
374		fallthrough;
375	case 1:		/* IO address */
376		io = ints[1];
377	}
378	if (*s)
379		snprintf(device, sizeof(device), "%s", s);
380	return 1;
381}
382__setup("arcrimi=", arcrimi_setup);
383#endif				/* MODULE */
384
385module_init(arc_rimi_init)
386module_exit(arc_rimi_exit)
v3.1
  1/*
  2 * Linux ARCnet driver - "RIM I" (entirely mem-mapped) cards
  3 * 
  4 * Written 1994-1999 by Avery Pennarun.
  5 * Written 1999-2000 by Martin Mares <mj@ucw.cz>.
  6 * Derived from skeleton.c by Donald Becker.
  7 *
  8 * Special thanks to Contemporary Controls, Inc. (www.ccontrols.com)
  9 *  for sponsoring the further development of this driver.
 10 *
 11 * **********************
 12 *
 13 * The original copyright of skeleton.c was as follows:
 14 *
 15 * skeleton.c Written 1993 by Donald Becker.
 16 * Copyright 1993 United States Government as represented by the
 17 * Director, National Security Agency.  This software may only be used
 18 * and distributed according to the terms of the GNU General Public License as
 19 * modified by SRC, incorporated herein by reference.
 20 *
 21 * **********************
 22 *
 23 * For more details, see drivers/net/arcnet.c
 24 *
 25 * **********************
 26 */
 
 
 
 27#include <linux/kernel.h>
 28#include <linux/module.h>
 29#include <linux/moduleparam.h>
 30#include <linux/ioport.h>
 31#include <linux/delay.h>
 32#include <linux/netdevice.h>
 33#include <linux/bootmem.h>
 34#include <linux/init.h>
 35#include <linux/interrupt.h>
 36#include <asm/io.h>
 37#include <linux/arcdevice.h>
 38
 39
 40#define VERSION "arcnet: RIM I (entirely mem-mapped) support\n"
 41
 
 
 42
 43/* Internal function declarations */
 44
 45static int arcrimi_probe(struct net_device *dev);
 46static int arcrimi_found(struct net_device *dev);
 47static void arcrimi_command(struct net_device *dev, int command);
 48static int arcrimi_status(struct net_device *dev);
 49static void arcrimi_setmask(struct net_device *dev, int mask);
 50static int arcrimi_reset(struct net_device *dev, int really_reset);
 51static void arcrimi_copy_to_card(struct net_device *dev, int bufnum, int offset,
 52				 void *buf, int count);
 53static void arcrimi_copy_from_card(struct net_device *dev, int bufnum, int offset,
 54				   void *buf, int count);
 55
 56/* Handy defines for ARCnet specific stuff */
 57
 58/* Amount of I/O memory used by the card */
 59#define BUFFER_SIZE (512)
 60#define MIRROR_SIZE (BUFFER_SIZE*4)
 61
 62/* COM 9026 controller chip --> ARCnet register addresses */
 63#define _INTMASK (ioaddr+0)	/* writable */
 64#define _STATUS  (ioaddr+0)	/* readable */
 65#define _COMMAND (ioaddr+1)	/* writable, returns random vals on read (?) */
 66#define _RESET  (ioaddr+8)	/* software reset (on read) */
 67#define _MEMDATA  (ioaddr+12)	/* Data port for IO-mapped memory */
 68#define _ADDR_HI  (ioaddr+15)	/* Control registers for said */
 69#define _ADDR_LO  (ioaddr+14)
 70#define _CONFIG  (ioaddr+2)	/* Configuration register */
 71
 72#undef ASTATUS
 73#undef ACOMMAND
 74#undef AINTMASK
 75
 76#define ASTATUS()	readb(_STATUS)
 77#define ACOMMAND(cmd)	writeb((cmd),_COMMAND)
 78#define AINTMASK(msk)	writeb((msk),_INTMASK)
 79#define SETCONF()	writeb(lp->config,_CONFIG)
 80
 81
 82/*
 83 * We cannot probe for a RIM I card; one reason is I don't know how to reset
 84 * them.  In fact, we can't even get their node ID automatically.  So, we
 85 * need to be passed a specific shmem address, IRQ, and node ID.
 86 */
 87static int __init arcrimi_probe(struct net_device *dev)
 88{
 89	BUGLVL(D_NORMAL) printk(VERSION);
 90	BUGLVL(D_NORMAL) printk("E-mail me if you actually test the RIM I driver, please!\n");
 91
 92	BUGMSG(D_NORMAL, "Given: node %02Xh, shmem %lXh, irq %d\n",
 93	       dev->dev_addr[0], dev->mem_start, dev->irq);
 
 94
 95	if (dev->mem_start <= 0 || dev->irq <= 0) {
 96		BUGMSG(D_NORMAL, "No autoprobe for RIM I; you "
 97		       "must specify the shmem and irq!\n");
 98		return -ENODEV;
 99	}
100	if (dev->dev_addr[0] == 0) {
101		BUGMSG(D_NORMAL, "You need to specify your card's station "
102		       "ID!\n");
103		return -ENODEV;
104	}
105	/*
106	 * Grab the memory region at mem_start for MIRROR_SIZE bytes.
107	 * Later in arcrimi_found() the real size will be determined
108	 * and this reserve will be released and the correct size
109	 * will be taken.
110	 */
111	if (!request_mem_region(dev->mem_start, MIRROR_SIZE, "arcnet (90xx)")) {
112		BUGMSG(D_NORMAL, "Card memory already allocated\n");
 
113		return -ENODEV;
114	}
115	return arcrimi_found(dev);
116}
117
118static int check_mirror(unsigned long addr, size_t size)
119{
120	void __iomem *p;
121	int res = -1;
122
123	if (!request_mem_region(addr, size, "arcnet (90xx)"))
124		return -1;
125
126	p = ioremap(addr, size);
127	if (p) {
128		if (readb(p) == TESTvalue)
129			res = 1;
130		else
131			res = 0;
132		iounmap(p);
133	}
134
135	release_mem_region(addr, size);
136	return res;
137}
138
139/*
140 * Set up the struct net_device associated with this card.  Called after
141 * probing succeeds.
142 */
143static int __init arcrimi_found(struct net_device *dev)
144{
145	struct arcnet_local *lp;
146	unsigned long first_mirror, last_mirror, shmem;
147	void __iomem *p;
148	int mirror_size;
149	int err;
150
151	p = ioremap(dev->mem_start, MIRROR_SIZE);
152	if (!p) {
153		release_mem_region(dev->mem_start, MIRROR_SIZE);
154		BUGMSG(D_NORMAL, "Can't ioremap\n");
155		return -ENODEV;
156	}
157
158	/* reserve the irq */
159	if (request_irq(dev->irq, arcnet_interrupt, 0, "arcnet (RIM I)", dev)) {
160		iounmap(p);
161		release_mem_region(dev->mem_start, MIRROR_SIZE);
162		BUGMSG(D_NORMAL, "Can't get IRQ %d!\n", dev->irq);
163		return -ENODEV;
164	}
165
166	shmem = dev->mem_start;
167	writeb(TESTvalue, p);
168	writeb(dev->dev_addr[0], p + 1);	/* actually the node ID */
 
169
170	/* find the real shared memory start/end points, including mirrors */
171
172	/* guess the actual size of one "memory mirror" - the number of
173	 * bytes between copies of the shared memory.  On most cards, it's
174	 * 2k (or there are no mirrors at all) but on some, it's 4k.
175	 */
176	mirror_size = MIRROR_SIZE;
177	if (readb(p) == TESTvalue &&
178	    check_mirror(shmem - MIRROR_SIZE, MIRROR_SIZE) == 0 &&
179	    check_mirror(shmem - 2 * MIRROR_SIZE, MIRROR_SIZE) == 1)
180		mirror_size = 2 * MIRROR_SIZE;
181
182	first_mirror = shmem - mirror_size;
183	while (check_mirror(first_mirror, mirror_size) == 1)
184		first_mirror -= mirror_size;
185	first_mirror += mirror_size;
186
187	last_mirror = shmem + mirror_size;
188	while (check_mirror(last_mirror, mirror_size) == 1)
189		last_mirror += mirror_size;
190	last_mirror -= mirror_size;
191
192	dev->mem_start = first_mirror;
193	dev->mem_end = last_mirror + MIRROR_SIZE - 1;
194
195	/* initialize the rest of the device structure. */
196
197	lp = netdev_priv(dev);
198	lp->card_name = "RIM I";
199	lp->hw.command = arcrimi_command;
200	lp->hw.status = arcrimi_status;
201	lp->hw.intmask = arcrimi_setmask;
202	lp->hw.reset = arcrimi_reset;
203	lp->hw.owner = THIS_MODULE;
204	lp->hw.copy_to_card = arcrimi_copy_to_card;
205	lp->hw.copy_from_card = arcrimi_copy_from_card;
206
207	/*
208	 * re-reserve the memory region - arcrimi_probe() alloced this reqion
209	 * but didn't know the real size.  Free that region and then re-get
210	 * with the correct size.  There is a VERY slim chance this could
211	 * fail.
212	 */
213	iounmap(p);
214	release_mem_region(shmem, MIRROR_SIZE);
215	if (!request_mem_region(dev->mem_start,
216				dev->mem_end - dev->mem_start + 1,
217				"arcnet (90xx)")) {
218		BUGMSG(D_NORMAL, "Card memory already allocated\n");
219		goto err_free_irq;
220	}
221
222	lp->mem_start = ioremap(dev->mem_start, dev->mem_end - dev->mem_start + 1);
 
223	if (!lp->mem_start) {
224		BUGMSG(D_NORMAL, "Can't remap device memory!\n");
225		goto err_release_mem;
226	}
227
228	/* get and check the station ID from offset 1 in shmem */
229	dev->dev_addr[0] = readb(lp->mem_start + 1);
 
230
231	BUGMSG(D_NORMAL, "ARCnet RIM I: station %02Xh found at IRQ %d, "
232	       "ShMem %lXh (%ld*%d bytes).\n",
233	       dev->dev_addr[0],
234	       dev->irq, dev->mem_start,
235	 (dev->mem_end - dev->mem_start + 1) / mirror_size, mirror_size);
236
237	err = register_netdev(dev);
238	if (err)
239		goto err_unmap;
240
241	return 0;
242
243err_unmap:
244	iounmap(lp->mem_start);
245err_release_mem:
246	release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1);
247err_free_irq:
248	free_irq(dev->irq, dev);
249	return -EIO;
250}
251
252
253/*
254 * Do a hardware reset on the card, and set up necessary registers.
255 *
256 * This should be called as little as possible, because it disrupts the
257 * token on the network (causes a RECON) and requires a significant delay.
258 *
259 * However, it does make sure the card is in a defined state.
260 */
261static int arcrimi_reset(struct net_device *dev, int really_reset)
262{
263	struct arcnet_local *lp = netdev_priv(dev);
264	void __iomem *ioaddr = lp->mem_start + 0x800;
265
266	BUGMSG(D_INIT, "Resetting %s (status=%02Xh)\n", dev->name, ASTATUS());
 
267
268	if (really_reset) {
269		writeb(TESTvalue, ioaddr - 0x800);	/* fake reset */
270		return 0;
271	}
272	ACOMMAND(CFLAGScmd | RESETclear);	/* clear flags & end reset */
273	ACOMMAND(CFLAGScmd | CONFIGclear);
 
274
275	/* enable extended (512-byte) packets */
276	ACOMMAND(CONFIGcmd | EXTconf);
277
278	/* done!  return success. */
279	return 0;
280}
281
282static void arcrimi_setmask(struct net_device *dev, int mask)
283{
284	struct arcnet_local *lp = netdev_priv(dev);
285	void __iomem *ioaddr = lp->mem_start + 0x800;
286
287	AINTMASK(mask);
288}
289
290static int arcrimi_status(struct net_device *dev)
291{
292	struct arcnet_local *lp = netdev_priv(dev);
293	void __iomem *ioaddr = lp->mem_start + 0x800;
294
295	return ASTATUS();
296}
297
298static void arcrimi_command(struct net_device *dev, int cmd)
299{
300	struct arcnet_local *lp = netdev_priv(dev);
301	void __iomem *ioaddr = lp->mem_start + 0x800;
302
303	ACOMMAND(cmd);
304}
305
306static void arcrimi_copy_to_card(struct net_device *dev, int bufnum, int offset,
307				 void *buf, int count)
308{
309	struct arcnet_local *lp = netdev_priv(dev);
310	void __iomem *memaddr = lp->mem_start + 0x800 + bufnum * 512 + offset;
311	TIME("memcpy_toio", count, memcpy_toio(memaddr, buf, count));
 
312}
313
314
315static void arcrimi_copy_from_card(struct net_device *dev, int bufnum, int offset,
316				   void *buf, int count)
317{
318	struct arcnet_local *lp = netdev_priv(dev);
319	void __iomem *memaddr = lp->mem_start + 0x800 + bufnum * 512 + offset;
320	TIME("memcpy_fromio", count, memcpy_fromio(buf, memaddr, count));
 
321}
322
323static int node;
324static int io;			/* use the insmod io= irq= node= options */
325static int irq;
326static char device[9];		/* use eg. device=arc1 to change name */
327
328module_param(node, int, 0);
329module_param(io, int, 0);
330module_param(irq, int, 0);
331module_param_string(device, device, sizeof(device), 0);
 
332MODULE_LICENSE("GPL");
333
334static struct net_device *my_dev;
335
336static int __init arc_rimi_init(void)
337{
338	struct net_device *dev;
339
340	dev = alloc_arcdev(device);
341	if (!dev)
342		return -ENOMEM;
343
344	if (node && node != 0xff)
345		dev->dev_addr[0] = node;
346
347	dev->mem_start = io;
348	dev->irq = irq;
349	if (dev->irq == 2)
350		dev->irq = 9;
351
352	if (arcrimi_probe(dev)) {
353		free_netdev(dev);
354		return -EIO;
355	}
356
357	my_dev = dev;
358	return 0;
359}
360
361static void __exit arc_rimi_exit(void)
362{
363	struct net_device *dev = my_dev;
364	struct arcnet_local *lp = netdev_priv(dev);
365
366	unregister_netdev(dev);
367	iounmap(lp->mem_start);
368	release_mem_region(dev->mem_start, dev->mem_end - dev->mem_start + 1);
369	free_irq(dev->irq, dev);
370	free_netdev(dev);
371}
372
373#ifndef MODULE
374static int __init arcrimi_setup(char *s)
375{
376	int ints[8];
 
377	s = get_options(s, 8, ints);
378	if (!ints[0])
379		return 1;
380	switch (ints[0]) {
381	default:		/* ERROR */
382		printk("arcrimi: Too many arguments.\n");
 
383	case 3:		/* Node ID */
384		node = ints[3];
 
385	case 2:		/* IRQ */
386		irq = ints[2];
 
387	case 1:		/* IO address */
388		io = ints[1];
389	}
390	if (*s)
391		snprintf(device, sizeof(device), "%s", s);
392	return 1;
393}
394__setup("arcrimi=", arcrimi_setup);
395#endif				/* MODULE */
396
397module_init(arc_rimi_init)
398module_exit(arc_rimi_exit)